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

Go from lowly lizard to wicked Wyvern in...
Do you like questing, and do you like dragons? If not then boy is this not the announcement for you, as Loongcheer Game has unveiled Quest Dragon: Idle Mobile Game. Yes, it is amazing Square Enix hasn’t sued them for copyright infringement, but... | Read more »
Aether Gazer unveils Chapter 16 of its m...
After a bit of maintenance, Aether Gazer has released Chapter 16 of its main storyline, titled Night Parade of the Beasts. This big update brings a new character, a special outfit, some special limited-time events, and, of course, an engaging... | Read more »
Challenge those pesky wyverns to a dance...
After recently having you do battle against your foes by wildly flailing Hello Kitty and friends at them, GungHo Online has whipped out another surprising collaboration for Puzzle & Dragons. It is now time to beat your opponents by cha-cha... | Read more »
Pack a magnifying glass and practice you...
Somehow it has already been a year since Torchlight: Infinite launched, and XD Games is celebrating by blending in what sounds like a truly fantastic new update. Fans of Cthulhu rejoice, as Whispering Mist brings some horror elements, and tests... | Read more »
Summon your guild and prepare for war in...
Netmarble is making some pretty big moves with their latest update for Seven Knights Idle Adventure, with a bunch of interesting additions. Two new heroes enter the battle, there are events and bosses abound, and perhaps most interesting, a huge... | Read more »
Make the passage of time your plaything...
While some of us are still waiting for a chance to get our hands on Ash Prime - yes, don’t remind me I could currently buy him this month I’m barely hanging on - Digital Extremes has announced its next anticipated Prime Form for Warframe. Starting... | Read more »
If you can find it and fit through the d...
The holy trinity of amazing company names have come together, to release their equally amazing and adorable mobile game, Hamster Inn. Published by HyperBeard Games, and co-developed by Mum Not Proud and Little Sasquatch Studios, it's time to... | Read more »
Amikin Survival opens for pre-orders on...
Join me on the wonderful trip down the inspiration rabbit hole; much as Palworld seemingly “borrowed” many aspects from the hit Pokemon franchise, it is time for the heavily armed animal survival to also spawn some illegitimate children as Helio... | Read more »
PUBG Mobile teams up with global phenome...
Since launching in 2019, SpyxFamily has exploded to damn near catastrophic popularity, so it was only a matter of time before a mobile game snapped up a collaboration. Enter PUBG Mobile. Until May 12th, players will be able to collect a host of... | Read more »
Embark into the frozen tundra of certain...
Chucklefish, developers of hit action-adventure sandbox game Starbound and owner of one of the cutest logos in gaming, has released their roguelike deck-builder Wildfrost. Created alongside developers Gaziter and Deadpan Games, Wildfrost will... | Read more »

Price Scanner via MacPrices.net

13-inch M2 MacBook Airs in stock today at App...
Apple has 13″ M2 MacBook Airs available for only $849 today in their Certified Refurbished store. These are the cheapest M2-powered MacBooks for sale at Apple. Apple’s one-year warranty is included,... Read more
New today at Apple: Series 9 Watches availabl...
Apple is now offering Certified Refurbished Apple Watch Series 9 models on their online store for up to $80 off MSRP, starting at $339. Each Watch includes Apple’s standard one-year warranty, a new... Read more
The latest Apple iPhone deals from wireless c...
We’ve updated our iPhone Price Tracker with the latest carrier deals on Apple’s iPhone 15 family of smartphones as well as previous models including the iPhone 14, 13, 12, 11, and SE. Use our price... Read more
Boost Mobile will sell you an iPhone 11 for $...
Boost Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering an iPhone 11 for $149.99 when purchased with their $40 Unlimited service plan (12GB of premium data). No trade-in is required... Read more
Free iPhone 15 plus Unlimited service for $60...
Boost Infinite, part of MVNO Boost Mobile using AT&T and T-Mobile’s networks, is offering a free 128GB iPhone 15 for $60 per month including their Unlimited service plan (30GB of premium data).... Read more
$300 off any new iPhone with service at Red P...
Red Pocket Mobile has new Apple iPhones on sale for $300 off MSRP when you switch and open up a new line of service. Red Pocket Mobile is a nationwide MVNO using all the major wireless carrier... Read more
Clearance 13-inch M1 MacBook Airs available a...
Apple has clearance 13″ M1 MacBook Airs, Certified Refurbished, available for $759 for 8-Core CPU/7-Core GPU/256GB models and $929 for 8-Core CPU/8-Core GPU/512GB models. Apple’s one-year warranty is... Read more
Updated Apple MacBook Price Trackers
Our Apple award-winning MacBook Price Trackers are continually updated with the latest information on prices, bundles, and availability for 16″ and 14″ MacBook Pros along with 13″ and 15″ MacBook... Read more
Every model of Apple’s 13-inch M3 MacBook Air...
Best Buy has Apple 13″ MacBook Airs with M3 CPUs in stock and on sale today for $100 off MSRP. Prices start at $999. Their prices are the lowest currently available for new 13″ M3 MacBook Airs among... Read more
Sunday Sale: Apple iPad Magic Keyboards for 1...
Walmart has Apple Magic Keyboards for 12.9″ iPad Pros, in Black, on sale for $150 off MSRP on their online store. Sale price for online orders only, in-store price may vary. Order online and choose... Read more

Jobs Board

Solutions Engineer - *Apple* - SHI (United...
**Job Summary** An Apple Solution Engineer's primary role is tosupport SHI customers in their efforts to select, deploy, and manage Apple operating systems and Read more
DMR Technician - *Apple* /iOS Systems - Haml...
…relevant point-of-need technology self-help aids are available as appropriate. ** Apple Systems Administration** **:** Develops solutions for supporting, deploying, Read more
Omnichannel Associate - *Apple* Blossom Mal...
Omnichannel Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Operations Associate - *Apple* Blossom Mall...
Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.