Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.3 4.3bsd-beta 6/6/85; site ucbvax.BERKELEY.EDU Path: utzoo!watmath!clyde!burl!ulysses!ucbvax!ernie!shebanow From: shebanow@ernie.BERKELEY.EDU (Mike Shebanow) Newsgroups: net.sources.mac Subject: IMLib Source (Part 3 of 4) Message-ID: <11107@ucbvax.BERKELEY.EDU> Date: Thu, 28-Nov-85 01:55:13 EST Article-I.D.: ucbvax.11107 Posted: Thu Nov 28 01:55:13 1985 Date-Received: Fri, 29-Nov-85 00:18:52 EST Sender: usenet@ucbvax.BERKELEY.EDU Reply-To: shebanow@ernie.BERKELEY.EDU (Mike Shebanow) Organization: University of California, Berkeley Lines: 622 (beware the line eater) =========================EventMgr.Asm============================== * * EventMgr.asm Andrew G. Shebanow 11/27/85 * * Glue code for the Event Manager (both Toolbox and OS level). * Implements the [Pascal Only] calls defined in Inside Mac. * * For the IMLib library, using Mac C calling conventions. * * Copyright 1985 HyperSoft All Rights Reserved * * Standard includes INCLUDE SysEquX.D * Defined here: XDEF GetCaretTime XDEF GetDblTime XDEF GetEvQHdr XDEF SetEventMask * * long GetCaretTime() * Module 'GetCaretTime' GetCaretTime MOVE.L CaretTime,D0 ; just get it RTS * * long GetDblTime() * Module 'GetDblTime' GetDblTime MOVE.L DoubleTime,D0 ; just get it RTS * * QHdrPtr GetEvQHdr() * Module 'GetEvQHdr' GetEvQHdr MOVE.L EventQueue,A0 ; This is defined as a 10 byte ; area. Assuming that the first ; longword is the QHdrPtr value. ; Hopefully this is actually ; the correct pointer to return. RTS * * SetEventMask(theMask) * short theMask; (D0.W) * Module 'SetEventMask' SetEventMask MOVE.L A0,-(SP) ; save A0 MOVE.L #SysEvtMask,A0 ; A0 -> the os global variable MOVE.W D0,(A0) ; store mask MOVE.L (SP)+,A0 ; restore A0 RTS END ************************* end of EventMgr.asm ************************* =========================FinderParms.c============================== /* * FinderParms.c Andrew G. Shebanow 8/31/85 * * Routines to emulate the Pascal calls which return finder information * (e.g., file arguments, open or print, etc). Written to * interface to Consulair's MacC compiler. * * In addition, several additional calls have been added to the library. * These routines let applications manipulate the application parms for * another application prior to a Launch call. * * Copyright 1985 HyperSoft All Rights Reserved * * Modification History * * 9/9/85 Moved to C version (AGS) * 9/9/85 Added code to set finder parms (AGS) */ #include "memory.h" /* this is a library of routines */ #Options M /* finder message open files or print files */ #define appOpen 0 #define appPrint 1 /* finder application parameter info */ typedef struct { short vRefNum; unsigned long fType; short versNum; Str255 fName; } AppFile; #define APPPARMHANDLE 0x0aec typedef struct { short message; short count; AppFile files[4]; /* actually open ended */ } AppParms; short AddAppFile(appFile) AppFile *appFile; { Handle appParmH; AppParms *appParmPtr; AppFile *newAppFile; unsigned long appHsize, appFsize; unsigned long newSize; appParmH = (Handle) APPPARMHANDLE; appParmH = (Handle) *appParmH; appHsize = GetHandleSize(appParmH); appFsize = (unsigned long) appFile->fName.count; appFsize++; if ((appFsize & 0x01) != 0) appFsize++; appFsize += 8; newSize = appFsize + appHsize; if (SetHandleSize(appParmH,newSize) != 0) return(1); appParmPtr = (AppParms *) *appParmH; newAppFile = &(appParmPtr->files[appParmPtr->count]); BlockMove(appFile,newAppFile,appFsize); appParmPtr->count += 1; return(0); } static asmprocs() { #asm INCLUDE MACTRAPS.D INCLUDE SYSEQU.D INCLUDE TOOLEQU.D ; Routines declared here: XDEF CountAppFiles XDEF GetAppFiles XDEF ClrAppFiles XDEF ZeroAppFiles XDEF SetAppMessage XDEF GetAppName XDEF GetFndrName XDEF SetFndrName XDEF LOCFindIndex SModule 'FindIndex' ; LOCFindIndex ; ; finds the nth AppFile record. ; ; INPUT: ; A0.L pointer to AppParms ; D0.W index (1..count) ; OUTPUT: ; A1.L pointer to AppFile data or 0 if not found LOCFindIndex MOVEM.L A2-A4,-(SP) ; save regs MOVE.L 0,A1 ; set result to 0 TST D0 ; test for legal index BLE FindXit CMP 2(A0),D0 BGT FindXit LEA 4(A0),A2 ; start of first AppFile MOVE D0,D1 ; D1 is loop counter @1 SUBQ #1,D1 ; index from 0 BEQ @2 ; if 0 we are done ADD.L #8,A2 ; start of filename string MOVE.B (A2),D2 ; D2 gets filename size AND.L #$0FF,D2 ; mask off high bits ADDQ.L #1,D2 ; plus one more for size byte BTST #0,D2 ; test for pad byte BEQ @3 ; if odd count, we must pad ADDQ.L #1,D2 ; add one for pad byte @3 ADD.L D2,A2 ; add string size to address BRA @1 @2 MOVE.L A2,A1 ; store in result FindXit MOVEM.L (SP)+,A2-A4 ; restore regs RTS SModule 'CountAppFiles' ; void CountAppFiles(message,count) ; short *message; (D0) ; short *count; (D1) CountAppFiles: MOVEM.L A0-A2,-(SP) ; save regs MOVE.L AppParmHandle,A0 MOVE.L (A0),A0 ; A0 points to AppParms MOVE.L D0,A1 ; A1 points to message MOVE.L D1,A2 ; A2 points to count MOVE (A0),(A1) ; save into message MOVE 2(A0),(A2) ; save into count MOVEM.L (SP)+,A0-A2 ; restore regs RTS SModule 'GetAppFiles' ; void GetAppFiles(index,appFile) ; short index; (D0) ; AppFile *appFile; (D1) GetAppFiles: MOVEM.L A0-A2,-(SP) ; save regs MOVE.L AppParmHandle,A0 MOVE.L (A0),A0 ; A0 points to AppParms MOVE.L D1,A2 ; A2 points to appFile JSR LOCFindIndex ; find index CMP.L #0,A1 BEQ @1 ; if couldn't find, handle error ; copy AppFile data from A1 to appFile MOVE.L A1,A0 ; source ptr MOVE.L A2,A1 ; dest ptr MOVE.L 8(A0),D0 ; put str len in D0 AND.L #$0FF,D0 ; mask hight bytes ADDQ.L #1,D0 BTST #0,D0 BEQ @2 ; if odd number of bytes... ADDQ.L #1,D0 ; pad with additional byte @2 ADD.L #8,D0 ; add space for other data _BlockMove @1 MOVEM.L (SP)+,A0-A2 ; restore regs RTS SModule 'ClrAppFiles' ; void ClrAppFiles(index) ; short index; (D0) ClrAppFiles: MOVEM.L A0-A1,-(SP) ; save regs MOVE.L AppParmHandle,A0 MOVE.L (A0),A0 ; A0 points to AppParms JSR LOCFindIndex ; find index CMP.L #0,A1 BEQ @1 MOVE.L #0,2(A1) ; clear out fType field @1 MOVEM.L (SP)+,A0-A1 ; restore regs RTS SModule 'ZeroAppFiles' ; void ZeroAppFiles() ZeroAppFiles MOVEM.L A0-A1,-(SP) ; save regs MOVE.L AppParmHandle,A0 MOVE.L (A0),A1 ; A1 points to AppParms CLR.L (A1) ; set message & count to 0 MOVEQ.L #4,D0 ; set handle size to 4 _SetHandleSize MOVEM.L (SP)+,A0-A1 ; restore regs RTS SModule 'SetAppMessage' ; void SetAppMessage(message) ; short message; (D0) SetAppMessage MOVE.L A0,-(SP) ; save regs MOVE.L AppParmHandle,A0 MOVE.L (A0),A1 ; A1 points to AppParms MOVE.W D0,(A0) ; move message into app parm area MOVE.L (SP)+,A0 ; restore regs RTS SModule 'GetAppName' ; void GetAppName(appName) ; StringPtr appName; (D0) ; ; return name of current application GetAppName MOVEM.L A0-A1,-(SP) TST.L D0 BEQ @1 ; if string pointer is null, return LEA CurApName,A0 ; src <- CurApName global MOVE.L D0,A1 ; dst <- appName MOVE.B (A0),D0 ; get string size AND.L #$0FF,D0 ADDQ.L #1,D0 ; add 1 for size byte _BlockMove ; copy the string @1 MOVEM.L (SP)+,A0-A1 RTS SModule 'GetFndrName' ; GetFndrName(fndrName) ; StringPtr fndrName; (D0) ; ; return name of current finder. ; GetFndrName MOVEM.L A0-A1,-(SP) TST.L D0 BEQ @1 ; if string pointer is null, return LEA FinderName,A0 ; src <- FinderName MOVE.L D0,A1 ; dst <- fndrName MOVE.B (A0),D0 ; get string size AND.L #$0FF,D0 ADDQ.L #1,D0 ; add 1 for size byte _BlockMove ; copy the string @1 MOVEM.L (SP)+,A0-A1 RTS SModule 'SetFndrName' ; SetFndrName(fndrName) ; StringPtr fndrName; (D0) ; ; set current finder. ; SetFndrName MOVEM.L A0-A1,-(SP) TST.L D0 BEQ @1 ; if string pointer is null, return MOVE.L D0,A0 ; src <- fndrName LEA FinderName,A1 ; dst <- FinderName global MOVE.B (A0),D0 ; get string size CMP.B #15,D0 BGT @1 ; if string to big, do nothing AND.L #$0FF,D0 ADDQ.L #1,D0 ; add 1 for size byte _BlockMove ; copy the string @1 MOVEM.L (SP)+,A0-A1 RTS #endasm } /********************* end of FinderParms.c *********************/ =========================MemoryMgr.Asm============================== ; ; MemoryMgr.Asm Andrew G. Shebanow 9/1/85 ; ; Routines to emulate the [NO TRAP MACRO] routines documented in ; the Memory Manager section of Inside Mac. ; ; The routine MaxApplZone was taken from the 8/85 issue of MacTutor Magazine ; and is copyrighted by MacTutor Magazine. ; ; Copyright 1985 HyperSoft All Rights Reserved ; ; Modifications: ; ; 10/18/85 Made MemError return value of variable in ; Low Memory ; INCLUDE MacTraps.D INCLUDE SysEquX.D ; Declared here: XDEF MaxApplZone XDEF SystemZone XDEF ApplicZone XDEF GZCritical XDEF GZSaveHnd XDEF TopMem XDEF MemError ; MaxApplZone() ; ; This routine from 8/85 issue of MacTutor magazine ; ; "MaxApplZone expands the application heap zone to the application heap ; limit without purging any blocks currently in the zone. If the zone ; already extends to the limit, it won't be changed" ; Inside Macintosh spec of MaxApplZone MinBlkSize EQU 12 ; minimum physical size of block MaxApplZone MOVEM.L A0-A1,-(SP) ; save regs MOVE.L ApplLimit,A0 ; A0 = application heap limit (ptr) MOVE.L HeapEnd,A1 ; A1 = addr of cur zone trailer MOVE.L A0,D0 SUB.L A1,D0 ; D0 = size of unused space (incl trailer) MOVEQ #MinBlkSize,D1 ; D1 = min phys size of a block CMP.L D1,D0 ; unused space < min block size? BLO.S @0 ; if so, can't expand zone, bye-bye MOVE.L A0,HeapEnd ; update HeapEnd to heap limit MOVE.L D0,(A1) ; unused space = free block (header = size) MOVE.L ApplZone,A1 ; A1 points to zone header MOVE.L A0,(A1) ; ApplicZone->bkLim = heap limit MOVE.L D1,(A0) ; make new zone trailer (free, size = min) ADD.L D0,zcbFree(A1) ; update count of free bytes in zone MOVEM.L (SP)+,A0-A1 ; restore regs @0 RTS ; THz SystemZone() SystemZone MOVE.L SysZone,A0 ; SysZone is a pointer to system zone RTS ; THz ApplicZone() ApplicZone MOVE.L ApplZone,A0 ; ApplZone is a pointer to applic zone RTS ; char GZCritical() GZCritical MOVE.L #1,D0 ; default return is TRUE MOVE.L GZMoveHnd,D1 BEQ.S @0 MOVE.L GZRootHnd,D1 BEQ.S @0 MOVE.B #0,D0 ; return false @0 RTS ; Handle GZSaveHnd() GZSaveHnd MOVE.L GZRootHnd,A0 RTS ; Ptr TopMem() TopMem MOVE.L MemTop,A0 RTS ; OSErr MemError() ; ; Apple's document LoAlpha.TXT (from the Software Supplement) ; specifies address $220 as the location of the last memory manager ; error. However, this location is NOT part of SysEqu.TXT, and it may be ; used by Apple's memory manager glue routine to STORE the error instead ; of simply reading from it. No guarantee of valid results. MemError MOVE.W $220,D0 RTS END =========================OSUtils.Asm============================== * * OSUtils.asm Andrew G. Shebanow 11/27/85 * * Routines to emulate the [Pascal Only] calls defined * in the OS Utilities section of Inside Macintosh for Consulair C. * Also includes one routine for Vertical Retrace Manager. * * Copyright 1985 HyperSoft All Rights Reserved * * Standard Includes: INCLUDE SysEquX.D INCLUDE MacTraps.D * Defined here: XDEF Environs XDEF Restart XDEF SetUpA5 XDEF RestoreA5 XDEF GetTime XDEF SetTime XDEF GetDateTime XDEF GetSysPPtr XDEF GetVBLQHdr * * Environs(rom,machine) * short *rom; (D0.L) * short *machine; (D1.L) * ; these constants are defined by Macintsoh Tech Note #16: MacWorks XL RomVers EQU $400008 Machine EQU $400009 Module 'Environs' Environs MOVEM.L A0-A1,-(SP) ; save regs MOVE.L D0,A0 MOVE.L D1,A0 CLR.W (A0) CLR.W (A1) MOVE.B RomVers,1(A0) ; save version into lsb of var MOVE.B Machine,1(A1) ; save machine into lsb of var MOVEM.L (SP)+,A0-A1 ; restore regs RTS * * Restart() * Module 'Restart' Restart RTS * * SetUpA5() * Module 'A5SetupRestore' SavedA5 DS.L 1 SetUpA5 MOVE.L A4,-(SP) ; save regs MOVE.L A5,A4 ; save old (and possibly wrong) A5 MOVE.L CurrentA5,A5 ; get real A5 FIRST MOVE.L A4,SavedA5(A5) ; NOW use as index to global MOVE.L (SP)+,A4 ; restore regs RTS * * RestoreA5() * RestoreA5 MOVE.L CurrentA5,A5 ; make sure we are valid FIRST MOVE.L SavedA5(A5),A5 ; set to old value RTS * * GetTime(date) * DateTimeRec *date; (D0.L) * Module 'GetTime' GetTime MOVEM.L D0/A0,-(SP) ; save regs MOVE.L D0,A0 MOVE.L Time,D0 _Secs2Date ; call trap MOVEM.L (SP)+,D0/A0 ; restore regs RTS * * SetTime(date) * DateTimeRec *date; (D0.L) * Module 'SetTime' SetTime MOVEM.L D0/A0,-(SP) ; save regs MOVE.L D0,A0 _Date2Secs ; call trap _SetDateTime ; store that time MOVEM.L (SP)+,D0/A0 ; restore regs RTS * * GetDateTime(secs) * long *secs; (D0.L) * Module 'GetDateTime' GetDateTime MOVE.L A0,-(SP) ; save A0 MOVE.L D0,A0 MOVE.L Time,(A0) ; get value of variable MOVE.L (SP)+,A0 ; restore A0 RTS * * SysPPtr GetSysPPtr() * Module 'GetSysPPtr' GetSysPPtr MOVE.L #SysParam,A0 ; store pointer in A0 RTS * * QHdrPtr GetVBLQHdr() * Module 'GetVBLQhdr' GetVBLQHdr MOVE.L vblQueue,A0 ; get address of queue ptr RTS END *********************** end of OSUtils.ASM **************************