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

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 »
MoreFun Studios has announced Season 4,...
Tension has escalated in the ever-volatile world of Arena Breakout, as your old pal Randall Fisher and bosses Fred and Perrero continue to lob insults and explosives at each other, bringing us to a new phase of warfare. Season 4, Into The Fog of... | Read more »
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 below... | Read more »
Marvel Future Fight celebrates nine year...
Announced alongside an advertising image I can only assume was aimed squarely at myself with the prominent Deadpool and Odin featured on it, Netmarble has revealed their celebrations for the 9th anniversary of Marvel Future Fight. The Countdown... | Read more »
HoYoFair 2024 prepares to showcase over...
To say Genshin Impact took the world by storm when it was released would be an understatement. However, I think the most surprising part of the launch was just how much further it went than gaming. There have been concerts, art shows, massive... | Read more »
Explore some of BBCs' most iconic s...
Despite your personal opinion on the BBC at a managerial level, it is undeniable that it has overseen some fantastic British shows in the past, and now thanks to a partnership with Roblox, players will be able to interact with some of these... | Read more »
Play Together teams up with Sanrio to br...
I was quite surprised to learn that the massive social network game Play Together had never collaborated with the globally popular Sanrio IP, it seems like the perfect team. Well, this glaring omission has now been rectified, as that instantly... | Read more »
Dark and Darker Mobile gets a new teaser...
Bluehole Studio and KRAFTON have released a new teaser trailer for their upcoming loot extravaganza Dark and Darker Mobile. Alongside this look into the underside of treasure hunting, we have received a few pieces of information about gameplay... | Read more »

Price Scanner via MacPrices.net

14-inch M3 MacBook Pro with 16GB of RAM avail...
Apple has the 14″ M3 MacBook Pro with 16GB of RAM and 1TB of storage, Certified Refurbished, available for $300 off MSRP. Each MacBook Pro features a new outer case, shipping is free, and an Apple 1-... Read more
Apple M2 Mac minis on sale for up to $150 off...
Amazon has Apple’s M2-powered Mac minis in stock and on sale for $100-$150 off MSRP, each including free delivery: – Mac mini M2/256GB SSD: $499, save $100 – Mac mini M2/512GB SSD: $699, save $100 –... Read more
Amazon is offering a $200 discount on 14-inch...
Amazon has 14-inch M3 MacBook Pros in stock and on sale for $200 off MSRP. Shipping is free. Note that Amazon’s stock tends to come and go: – 14″ M3 MacBook Pro (8GB RAM/512GB SSD): $1399.99, $200... Read more
Sunday Sale: 13-inch M3 MacBook Air for $999,...
Several Apple retailers have the new 13″ MacBook Air with an M3 CPU in stock and on sale today for only $999 in Midnight. These are the lowest prices currently available for new 13″ M3 MacBook Airs... Read more
Multiple Apple retailers are offering 13-inch...
Several Apple retailers have 13″ MacBook Airs with M2 CPUs in stock and on sale this weekend starting at only $849 in Space Gray, Silver, Starlight, and Midnight colors. These are the lowest prices... Read more
Roundup of Verizon’s April Apple iPhone Promo...
Verizon is offering a number of iPhone deals for the month of April. Switch, and open a new of service, and you can qualify for a free iPhone 15 or heavy monthly discounts on other models: – 128GB... Read more
B&H has 16-inch MacBook Pros on sale for...
Apple 16″ MacBook Pros with M3 Pro and M3 Max CPUs are in stock and on sale today for $200-$300 off MSRP at B&H Photo. Their prices are among the lowest currently available for these models. B... Read more
Updated Mac Desktop Price Trackers
Our Apple award-winning Mac desktop price trackers are the best place to look for the lowest prices and latest sales on all the latest computers. Scan our price trackers for the latest information on... Read more
9th-generation iPads on sale for $80 off MSRP...
Best Buy has Apple’s 9th generation 10.2″ WiFi iPads on sale for $80 off MSRP on their online store for a limited time. Prices start at only $249. Sale prices for online orders only, in-store prices... Read more
15-inch M3 MacBook Airs on sale for $100 off...
Best Buy has Apple 15″ MacBook Airs with M3 CPUs on sale for $100 off MSRP on their online store. Prices valid for online orders only, in-store prices may vary. Order online and choose free shipping... Read more

Jobs Board

Sublease Associate Optometrist- *Apple* Val...
Sublease Associate Optometrist- Apple Valley, CA- Target Optical Date: Mar 22, 2024 Brand: Target Optical Location: Apple Valley, CA, US, 92307 **Requisition Read more
Early Preschool Teacher - Glenda Drive/ *Appl...
Early Preschool Teacher - Glenda Drive/ Apple ValleyTeacher Share by Email Share on LinkedIn Share on Twitter Read more
Retail Assistant Manager- *Apple* Blossom Ma...
Retail Assistant Manager- APPLE BLOSSOM MALL Brand: Bath & Body Works Location: Winchester, VA, US Location Type: On-site Job ID: 04225 Job Area: Store: Management Read more
Housekeeper, *Apple* Valley Village - Cassi...
Apple Valley Village Health Care Center, a senior care campus, is hiring a Part-Time Housekeeper to join our team! We will train you for this position! In this role, Read more
Sonographer - *Apple* Hill Imaging Center -...
Sonographer - Apple Hill Imaging Center - Evenings Location: York Hospital, York, PA Schedule: Full Time Sign-On Bonus Eligible Remote/Hybrid Regular Apply Now See Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.