TweetFollow Us on Twitter

Jan 90 Letters
Volume Number:6
Issue Number:1
Column Tag:Letters

INITs First

By David E. Smith, Editor & Publisher, MacTutor

INITs in Pascal or C

Steve Brecher

Sunnyvale, CA

There are some problems in the advice and code provided in the October 1989 issue’s Pascal Procedures and C Workshop, which discuss writing INITs in the respective languages.

The VBL task shown in Pascal Procedures calls GetGDevice without checking whether Color QuickDraw is available. It assumes that the current GDevice is the monitor the mouse is on. Multiple-monitor users may be surprised to find the mouse jumping from the middle of one monitor to the opposite edge of another when they press Option for some application purpose. The code also assumes, in its reference to QuickDraw globals through CurrentA5, that QuickDraw has been initialized for the currently executing application. This is not necessarily true.

The following comments apply to the C Workshop article.

The author does not understand the function of the ioNamePtr field in File Manager parameter blocks. This field contains either a pointer to a caller- allocated string buffer or nil if the caller chooses not to pass or receive a filename string. The File Manager does not allocate a string buffer for the caller.

INIT 31 does not necessarily expand the system heap by the amount specified in your ‘sysz’ 0 resource, and it certainly does not “collapse” the heap to undo any previous expansions--CompactMem collects free blocks together; it does not shrink a heap. What INIT 31 does is expand the system heap if necessary to assure that a contiguous block of the size specified in the ‘sysz’ 0 resource is available at the time the first (and usually only) INIT resource in an INIT/

cdev/RDEV is executed. Any space gained by heap expansion that is not used by the INIT will remain free when the INIT exits--but may be sopped up by subsequent INITs or system activity.

The author unduly discounts the dangers of tail patching. A tail patch is a trap patch that calls (JSRs to) the original patch instead of JMPing to it. A tail patch may nullify an Apple-supplied ROM code patch. Such Apple patches operate by comparing their return address on the stack with certain hard-coded ROM addresses. By JSRing to the original trap code, one assures that such a comparison will always fail since the Apple patch will see one’s own return address rather than that of the original trap caller. In some cases tail patching is necessary; my own products do it. But one should at least check the latest System release to make sure that one’s tail patches do not nullify ROM code patches. And in some cases one can eat one’s cake and have it too by JSRing to the original trap code, doing necessary post-processing, and then JMPing to the original code. The original code will be executed twice, and the second execution will invoke any ROM patch code that may be installed. The JMP requires assembly language.

The example INIT ignores the fact that Resource Manager traps preserve all registers except D0/A0 (except LoadResource, which preserves all including D0/A0)--IM I-113. It also uses the Dialog Manager with no assurance that it has been intialized, not to mention QuickDraw, etc.

Writing Inits in Pascal

Roland van Straten

Dutch Macintosh Developer

Perhaps this is not the right way to inform you about bugs, but sending a letter takes a while and it has no way to send real program listings. So if this is not the way you prefer, let me know.

I’ve read the article about “Writing INITs in Pascal”, MacTutor Oct 89, Page 51, and after some study of the source code I noticed two bugs. Maybe Steve Kiene’s system and/or compiler do something special or he forgot to test it, I don’t know.

1. The MTemp location has a counterpart: RawMouse. It’s the next LongInt in Low Memory. If RawMouse is equal to MTemp the mouse handler will think the move has to be made absolute. Otherwise the move will be treated as relative (Steve Kiene’s program).

2. The CrsrNew location is a Byte value. Steve Kiene’s program declares a pointer to a Byte (^Byte). This is a two byte value. Look at IM vol1, pag 86. In order to fix this I used a standard type Ptr (^SignedByte) and exchanged $FF for -1.

Apart from these little bugs I enjoyed the article very much and found it useful. The article appeared at the time I was writing a VBL task that moves the mouse “outside” the screen (don’t ask me for the reason of this).

 
UNIT CursorWrap;

{MacTutor ©1989, issue October 1989, page 51, “Writing INITs in Pascal” 
by Steve Kiene}

{MPW 3.0 version - October 1989 - ROLAnd van Straten - ALink HOL0027}

INTERFACE

USES
 MemTypes,QuickDraw,OSIntf,ToolIntf;

PROCEDURE SETUPVBL;
PROCEDURE Wrap;

IMPLEMENTATION

PROCEDURE SETUPVBL;
VAR
 theVBL : VBLTask;
 myQElem: QElemPtr;
 myErr  : OSErr;
 SaveZone : THz;
 SizeNeeded:LongInt;
 PatchPtr : Ptr;
 theCode: Handle;
 thePtr : ^LongInt;

BEGIN
 theCode:= Get1Resource(‘INIT’,1);
 SaveZone := GetZone;
 SetZone(SystemZone);
 
 SizeNeeded := SizeResource(theCode) - (LongInt(@SetUpVBL) - LongInt(theCode^)) 
+ SizeOf(QElem);
 ResrvMem(SizeNeeded);
 IF MemError <> NoErr THEN BEGIN
 SysBeep(1); SetZone(SaveZone); Exit(SetUpVBL); END;
 
 PatchPtr := NewPtr(SizeNeeded + 4) ;{get ptr for our code}
 BlockMove(@Wrap, Pointer(ORD(PatchPtr)+4), SizeNeeded);
 myQElem := QElemPtr(NewPtr(SizeOf(QElem)));
 SetZone(SaveZone);
 
 {put vbl task ptr addr into ptr where our patch will be}
 thePtr := Pointer(PatchPtr);
 thePtr^ := LongInt(myQElem);
 
 WITH theVBL DO BEGIN
 qType  := ORD(vType);
 vblAddr  := Pointer(ORD(PatchPtr)+4);
 vblCount := 6;
 vblPhase := 0;
 END;
 myQElem^.vblQElem := theVBL;
 myErr := VInstall(myQElem);
END;

PROCEDURE Wrap;
{Wrap cursor when option key is down

 MTemp  has latest mouse value
 RawMouse has the un-jerked mouse value
 CrsrNew  must be set to “-1” to indentify “moved”
 
 If MTemp and RawMouse are different there only will be a relative change 
of the mouse position. This looks like unstable moves on the screen. 
 Fixed this bug by moving RawMouse into the arena.
 CrsrNew is a byte. The used pointer type was a ^Byte. This is in fact 
a two byte value (WRONG). Look in IM.1 pag 68 for details on this. So 
in order to fix this use the standard Ptr type and put the value -1 into 
the addressed byte.
}

CONST
 CurrentA5 = $904;
 MTemp  = $828;  {Low-level interrupt mouse location [long]}
 RawMouse = $82C; {un-jerked mouse coordinates [long]}
 CrsrNew= $8CE; {Cursor changed? [byte]}
 OptionKey= 58;

TYPE
 LPtr = ^LongInt;

VAR
 myQElem: QElemPtr;
 currGDevice: GDHandle;
 theMap : KeyMap;
 changed: Boolean;
 myRectPtr: ^Rect;
 mouseRect, myRect : Rect;
 myPtr,myPtr2    : LPtr;
 PPtr,P2Ptr : ^Point;

BEGIN
 GetKeys(theMap);
 IF theMap[OptionKey] THEN BEGIN
 changed := FALSE;
 currGDevice :=GetGDevice;
 IF currGDevice <> NIL THEN
 mouseRect := currGDevice^^.gdRect
 ELSE
 BEGIN {use A5 to get offset to screenbits.bounds}
 myPtr  := Pointer(CurrentA5);
 myPtr2 := Pointer(myPtr^);
 myRectPtr := Pointer(myPtr2^-116);
 mouseRect := myRectPtr^;
 END;
 InSetRect(mouseRect,1,1);
 
 PPtr := Pointer(MTemp); P2Ptr := Pointer(RawMouse);
 IF PPtr^.v <= mouseRect.top THEN BEGIN {check cursor pos for wrap}
 PPtr^.v  := mouseRect.bottom -1;
 P2Ptr^.v := mouseRect.bottom -1;
 changed  := TRUE; END
 ELSE
 IF PPtr^.v >= mouseRect.bottom THEN BEGIN
 PPtr^.v  := mouseRect.top +1;
 P2Ptr^.v := mouseRect.top +1;
 changed  := TRUE; END
 ELSE
 IF PPtr^.h <= mouseRect.left THEN BEGIN
 PPtr^.h  := mouseRect.right -1;
 P2Ptr^.h := mouseRect.right -1;
 changed  := TRUE; END
 ELSE
 IF PPtr^.h >= mouseRect.right THEN BEGIN
 PPtr^.h  := mouseRect.left +1;
 P2Ptr^.h := mouseRect.left +1;
 changed:= TRUE; END;
 
 IF changed THEN 
 Ptr(CrsrNew)^ := -1;{cursor has changed}
 
 END;
 
 myQElem := QElemPtr(LPtr(Pointer(ORD(@Wrap)-4))^);      {get ptr to 
vbl task, and reset it}
 myQElem^.vblQElem.vblCount := 6;
END;

END.

INIT Inhibition

David Dunham

Seattle, WA

Just a quick note about Peter Hoddie’s article on INITs. He suggests that INITs not install themselves when the mouse button is down.

In fact, there is a fairly standard method of inhibiting INITs: the shift key. Not all INITs use this, but probably half the ones I’m familiar with do. My own INITs also disable themselves when their initial letter (e.g. ‘f’ for Findswell) is held at boot time.

The problem with using the mouse button is that it instructs the Mac to eject the internal disk at boot time. Disabling INITs shouldn’t be a matter of timing just when to click the mouse.

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Top Mobile Game Discounts
Every day, we pick out a curated list of the best mobile discounts on the App Store and post them here. This list won't be comprehensive, but it every game on it is recommended. Feel free to check out the coverage we did on them in the links... | Read more »
Price of Glory unleashes its 1.4 Alpha u...
As much as we all probably dislike Maths as a subject, we do have to hand it to geometry for giving us the good old Hexgrid, home of some of the best strategy games. One such example, Price of Glory, has dropped its 1.4 Alpha update, stocked full... | Read more »
The SLC 2025 kicks off this month to cro...
Ever since the Solo Leveling: Arise Championship 2025 was announced, I have been looking forward to it. The promotional clip they released a month or two back showed crowds going absolutely nuts for the previous competitions, so imagine the... | Read more »
Dive into some early Magicpunk fun as Cr...
Excellent news for fans of steampunk and magic; the Precursor Test for Magicpunk MMORPG Crystal of Atlan opens today. This rather fancy way of saying beta test will remain open until March 5th and is available for PC - boo - and Android devices -... | Read more »
Prepare to get your mind melted as Evang...
If you are a fan of sci-fi shooters and incredibly weird, mind-bending anime series, then you are in for a treat, as Goddess of Victory: Nikke is gearing up for its second collaboration with Evangelion. We were also treated to an upcoming... | Read more »
Square Enix gives with one hand and slap...
We have something of a mixed bag coming over from Square Enix HQ today. Two of their mobile games are revelling in life with new events keeping them alive, whilst another has been thrown onto the ever-growing discard pile Square is building. I... | Read more »
Let the world burn as you have some fest...
It is time to leave the world burning once again as you take a much-needed break from that whole “hero” lark and enjoy some celebrations in Genshin Impact. Version 5.4, Moonlight Amidst Dreams, will see you in Inazuma to attend the Mikawa Flower... | Read more »
Full Moon Over the Abyssal Sea lands on...
Aether Gazer has announced its latest major update, and it is one of the loveliest event names I have ever heard. Full Moon Over the Abyssal Sea is an amazing name, and it comes loaded with two side stories, a new S-grade Modifier, and some fancy... | Read more »
Open your own eatery for all the forest...
Very important question; when you read the title Zoo Restaurant, do you also immediately think of running a restaurant in which you cook Zoo animals as the course? I will just assume yes. Anyway, come June 23rd we will all be able to start up our... | Read more »
Crystal of Atlan opens registration for...
Nuverse was prominently featured in the last month for all the wrong reasons with the USA TikTok debacle, but now it is putting all that behind it and preparing for the Crystal of Atlan beta test. Taking place between February 18th and March 5th,... | Read more »

Price Scanner via MacPrices.net

AT&T is offering a 65% discount on the ne...
AT&T is offering the new iPhone 16e for up to 65% off their monthly finance fee with 36-months of service. No trade-in is required. Discount is applied via monthly bill credits over the 36 month... Read more
Use this code to get a free iPhone 13 at Visi...
For a limited time, use code SWEETDEAL to get a free 128GB iPhone 13 Visible, Verizon’s low-cost wireless cell service, Visible. Deal is valid when you purchase the Visible+ annual plan. Free... Read more
M4 Mac minis on sale for $50-$80 off MSRP at...
B&H Photo has M4 Mac minis in stock and on sale right now for $50 to $80 off Apple’s MSRP, each including free 1-2 day shipping to most US addresses: – M4 Mac mini (16GB/256GB): $549, $50 off... Read more
Buy an iPhone 16 at Boost Mobile and get one...
Boost Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering one year of free Unlimited service with the purchase of any iPhone 16. Purchase the iPhone at standard MSRP, and then choose... Read more
Get an iPhone 15 for only $299 at Boost Mobil...
Boost Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering the 128GB iPhone 15 for $299.99 including service with their Unlimited Premium plan (50GB of premium data, $60/month), or $20... Read more
Unreal Mobile is offering $100 off any new iP...
Unreal Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering a $100 discount on any new iPhone with service. This includes new iPhone 16 models as well as iPhone 15, 14, 13, and SE... Read more
Apple drops prices on clearance iPhone 14 mod...
With today’s introduction of the new iPhone 16e, Apple has discontinued the iPhone 14, 14 Pro, and SE. In response, Apple has dropped prices on unlocked, Certified Refurbished, iPhone 14 models to a... Read more
B&H has 16-inch M4 Max MacBook Pros on sa...
B&H Photo is offering a $360-$410 discount on new 16-inch MacBook Pros with M4 Max CPUs right now. B&H offers free 1-2 day shipping to most US addresses: – 16″ M4 Max MacBook Pro (36GB/1TB/... Read more
Amazon is offering a $100 discount on the M4...
Amazon has the M4 Pro Mac mini discounted $100 off MSRP right now. Shipping is free. Their price is the lowest currently available for this popular mini: – Mac mini M4 Pro (24GB/512GB): $1299, $100... Read more
B&H continues to offer $150-$220 discount...
B&H Photo has 14-inch M4 MacBook Pros on sale for $150-$220 off MSRP. B&H offers free 1-2 day shipping to most US addresses: – 14″ M4 MacBook Pro (16GB/512GB): $1449, $150 off MSRP – 14″ M4... Read more

Jobs Board

All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.