bobc@tikal.UUCP (Bob Campbell) (05/14/86)
# The rest of this file is a shell script which will extract: # SYSTEMX.MOD ScrapManager.MOD Storage.MOD Streams.MOD echo x - SYSTEMX.MOD cat >SYSTEMX.MOD <<'!Funky!Stuff!' IMPLEMENTATION MODULE SYSTEMX; FROM SYSTEM IMPORT ADDRESS,CODE,SETREG,REGISTER,ADR,PROCESS; CONST FADDS = 01000H; FSUBS = 01002H; FMULS = 01004H; FDIVS = 01006H; FCMPS = 01008H; FTINTX = 00016H; FX2S = 01010H; FS2X = 0100EH; FX2L = 02810H; FL2X = 0280EH; (*$P-*) PROCEDURE DoCASE; BEGIN CODE(0205FH); (* MOVEA.L (A7)+,A0 *) CODE(09090H); (* SUB.L (A0),DO *) CODE(0B0A8H);CODE(00004H); (* CMP.L 0004(A0),D0 *) CODE(0620CH); (* BHI $1 {+12} *) CODE(0E380H); (* ASL.L #1,D0 *) CODE(0D0A8H);CODE(00008H); (* ADD.L 0008(A0),D0 *) CODE(0D0F0H);CODE(00800H); (* ADDA.L 00(A0,DO.W),A0 *) CODE(04ED0H); (* JMP (A0) *) (* $1 *) CODE(0D1E8H);CODE(00008H); (* ADDA.L 0008(A0),A0 *) CODE(05988H); (* SUBQ.L #4,A0 *) CODE(04ED0H); (* JMP (A0) *) END DoCASE; PROCEDURE DoHALT; (*$P-*) BEGIN CODE(0A9FFH); (* CALL DEBUGGER *) CODE(04E75H); END DoHALT; PROCEDURE CheckStack; (*$P-*) BEGIN (* STUBED OUT FOR NOW! *) CODE(04E75H); (* RTS *) END CheckStack; PROCEDURE SYSProc20; (*$P-*) BEGIN (* 0000 MOVEQ.L #0007,D0 *) CODE(07007H); DoHALT; END SYSProc20; PROCEDURE NEWPROCESS; (*$P-*) BEGIN CODE(0700AH); (* MOVEQ.L #000A,D0 *) DoHALT; END NEWPROCESS; PROCEDURE TRANSFER; (*$P-*) BEGIN CODE(0700BH); (* MOVEQ.L #000B,DO *) DoHALT; END TRANSFER; PROCEDURE SYSProc21; (*$P-*) BEGIN (* * Procedure Code Proc # 21 * Entry Point 0000, number of bytes = 40 *) (* 0000 MOVE.W #2700,SR *) CODE(046FCH);CODE(02700); (* 0004 MOVE.L A6,-(A7) *) CODE(02F0EH); (* 0006 MOVE.L USP,A6 *) CODE(04E6EH); (* 0008 MOVE.L A5,-(A6) *) CODE(02D0DH); (* 000A LEA A6,FFCC(A6) *) CODE(04DEEH); CODE(0FFCCH); (* 000E MOVE.L (A7)+,-(A6) *) CODE(02D1FH); (* 0010 MOVE.W (A7)+,-(A6) *) CODE(03D1FH); (* 0012 MOVE.L (A7)+,-(A6) *) CODE(02D1FH); (* 0014 MOVE.L A6,(A0) *) CODE(0208EH); (* 0016 MOVEA.L (A1),A6 *) CODE(02C51H); (* 0018 MOVE.L (A6)+,-(A7) *) CODE(02F1EH); (* 001A MOVE.W (A6)+,-(A7) *) CODE(03F1EH); (* 001C MOVE.L (A6)+,-(A7) *) CODE(02F1EH); (* 001E MOVEM.L D0-A5,(A6)+ *) CODE(04CDEH); CODE(03FFFH); (* 0022 MOVE.L A6,USP *) CODE(04E66H); (* 0024 MOVEA.L (A7)+,A6 *) CODE(02C5FH); (* 0026 RTE *) CODE(04E73H); END SYSProc21; PROCEDURE IOTRANSFER(p1,p2:PROCESS; via:ADDRESS); (*$P-*) BEGIN CODE(0700CH); (* MOVEQ.L #000C,DO *) DoHALT; END IOTRANSFER; PROCEDURE SYSProc7; (* IF D0 = 2 THEN LISTEN ELSIF D0 = 3 THEN SYSRESET END *) (*$P-*) BEGIN CODE(0700DH); DoHALT; END SYSProc7; PROCEDURE SYSLongMult; (*$P-*) BEGIN CODE(04E56H);CODE(00000H); (* LINK A6,#0000 *) CODE(048E7H);CODE(07C00H); (* MOVEM.L D5-D1,-(A7) *) CODE(0222EH);CODE(00008H); (* MOVE.L 0008(A6),D1 *) CODE(0242EH);CODE(0000CH); (* MOVE.L 000C(A6),D2 *) CODE(02601H); (* MOVE.L D1,D3 *) CODE(02801H); (* MOVE.L D1,D4 *) CODE(02A02H); (* MOVE.L D2,D5 *) CODE(04844H); (* SWAP D4 *) CODE(04845H); (* SWAP D5 *) CODE(0C2C2H); (* MULU.W D2,D1 *) CODE(0C4C4H); (* MULU.W D4,D2 *) CODE(0C6C5H); (* MULU.W D5,D3 *) CODE(0C8C5H); (* MULU.W D5,D4 *) CODE(04841H); (* SWAP D1 *) CODE(0D242H); (* ADD.W D2,D1 *) CODE(04285H); (* CLR.L D5 *) CODE(0D985H); (* ADDX.L D5,D4 *) CODE(0D243H); (* ADD.W D3,D1 *) CODE(0D985H); (* ADDX.L D5,D4 *) CODE(04841H); (* SWAP D1 *) CODE(04242H); (* CLR.W D2 *) CODE(04243H); (* CLR.W D3 *) CODE(04842H); (* SWAP D2 *) CODE(04843H); (* SWAP D3 *) CODE(0D483H); (* ADD.L D3,D2 *) CODE(0D484H); (* ADD.L D4,D2 *) CODE(02D41H);CODE(0000CH); (* MOVE.L D1,000C(A6) *) CODE(04CDFH);CODE(00008H); (* MOVE.L D2,0008(A6) *) CODE(04E5EH); (* UNLK A6 *) CODE(04E75H); (* RTS *) END SYSLongMult; PROCEDURE SYSLongDivMod; (*$P-*) BEGIN CODE(04E56H);CODE(00000H); (* LINK A6,#0000 *) CODE(048E7H);CODE(07800H); (* MOVEM.L D4-D1,-(A7) *) CODE(0222EH);CODE(0000CH); (* MOVE.L 000C(A6),D1 *) CODE(0242EH);CODE(00008H); (* MOVE.L 0008(A6),D2 *) CODE(0B4BCH);CODE(00000H); CODE(0FFFFH); (* CMP.L #0000FFFF,D2 *) CODE(0621EH); (* BHI $1 {+30} *) CODE(04243H); (* CLR.W D3 *) CODE(082C2H); (* DIVU.W D2,D1 *) CODE(0680EH); (* BVC $2 {+14} *) CODE(03801H); (* MOVE.W D1,D4 *) CODE(04241H); (* CLR.W D1 *) CODE(04841H); (* SWAP D1 *) CODE(082C2H); (* DIVU.W D2,D1 *) CODE(03601H); (* MOVE.W D1,D3 *) CODE(03204H); (* MOVE.W D4,D1 *) CODE(082C2H); (* DIVU.W D2,D1 *) (* $2: *) CODE(04843H); (* SWAP D3 *) CODE(03601H); (* MOVE.W D1,D3 *) CODE(04241H); (* CLR.W D1 *) CODE(04841H); (* SWAP D1 *) CODE(0601EH); (* BRA $3 {+30} *) (* $1: *) CODE(04283H); (* CLR.L D3 *) CODE(03601H); (* MOVE.W D1,D3 *) CODE(04843H); (* SWAP D3 *) CODE(04241H); (* CLR.W D1 *) CODE(04841H); (* SWAP D1 *) CODE(0383CH);CODE(0000FH); (* MOVE.W #000F,D4 *) (* $5: *) CODE(0E38BH); (* LSL.L #1,D3 *) CODE(0E391H); (* ROXL.L #1,D1 *) CODE(0B282H); (* CMP.L D2,D1 *) CODE(06504H); (* BCS $4 {+4} *) CODE(09282H); (* SUB.L D2,D1 *) CODE(05243H); (* ADDQ.W #1,D3 *) (* $4: *) CODE(051CCH);CODE(0FFF2H); (* DBF D4,$5 {-14} *) (* $3: *) CODE(02D43H);CODE(0000CH); (* MOVE.L D3,000C(A6) *) CODE(02D41H);CODE(00008H); (* MOVE.L D1,0008(A6) *) CODE(04CDFH);CODE(0001EH); (* MOVEM.L D1-D4,(A7)+ *) CODE(04E5EH); (* UNLK A6 *) CODE(04E75H); (* RTS *) END SYSLongDivMod; PROCEDURE SYSLongIntMult; (*$P-*) BEGIN (* Procedure Code Proc # 10 *) (* Entry Point 0000, number of bytes = 92 *) (* 0000 LINK A6,#0000 *) CODE(04E56H); CODE(00000H); (* 0004 MOVEM.L D7-D1,-(A7) *) CODE(048E7H); CODE(07F00H); (* 0008 MOVE.L 0008(A6),D1 *) CODE(0222EH); CODE(00008H); (* 000C MOVE.L 000C(A6),D2 *) CODE(0242EH); CODE(0000CH); (* 0010 MOVE.L D1,D3 *) CODE(02601H); (* 0012 MOVE.L D1,D4 *) CODE(02801H); (* 0014 MOVE.L D2,D5 *) CODE(02A02H); (* 0016 MOVE.L D1,D6 *) CODE(02C01H); (* 0018 CLR.L D7 *) CODE(04287H); (* 001A SWAP D4 *) CODE(04844H); (* 001C SWAP D5 *) CODE(04845H); (* 001E MULU.W D2,D1 *) CODE(0C2C2H); (* 0020 MULU.W D4,D2 *) CODE(0C4C4H); (* 0022 MULU.W D5,D3 *) CODE(0C6C5H); (* 0024 MULU.W D5,D4 *) CODE(0C8C5H); (* 0026 SWAP D1 *) CODE(04841H); (* 0028 ADD.W D2,D1 *) CODE(0D987H); (* 002A ADDX.L D7,D4 *) CODE(0D987H); (* 002C ADD.W D3,D1 *) CODE(0D243H); (* 002E ADDX.L D7,D4 *) CODE(0D987H); (* 0030 SWAP D1 *) CODE(04841H); (* 0032 CLR.W D2 *) CODE(04242H); (* 0034 CLR.W D3 *) CODE(04243H); (* 0036 SWAP D2 *) CODE(04842H); (* 0038 SWAP D3 *) CODE(04843H); (* 003A ADD.L D3,D2 *) CODE(0D483H); (* 003C ADD.L D4,D2 *) CODE(0D484H); (* 003E SWAP D5 *) CODE(04845H); (* 0040 TST.L D6 *) CODE(04A86H); (* 0042 BPI 2 {0046} *) CODE(06A02H); (* 0044 SUB.L D5,D2 *) CODE(09485H); (* 0046 TST.L D5 *) CODE(04A85H); (* 0048 BPI 2 {004C} *) CODE(06A02H); (* 004A SUB.L D6,D2 *) CODE(09486H); (* 004C MOVE.L D1,000C(A6) *) CODE(02D41H); CODE(0000CH); (* 0050 MOVE.L D2,0008(A6) *) CODE(02D42H); CODE(00008H); (* 0054 MOVEM.L D1-D7,(A7)+ *) CODE(04CDFH); CODE(000FEH); (* 0058 UNLK A6 *) CODE(04E5EH); (* 005A RTS *) CODE(04E75H); END SYSLongIntMult; PROCEDURE SYSProc11; (*$P-*) BEGIN (*Procedure Code Proc # 11 *) (* Entry Point 0000, number of bytes = 16*) (* 0000 LINK A6,#0000 *) CODE(04E56H); CODE(00000H); (* 0004 MOVEQ.L #0008,D0 *) CODE(07008H); DoHALT; (* 000C UNLK A6 *) CODE(04E5EH); (* 000E RTS *) CODE(04E75H); END SYSProc11; PROCEDURE SYSRealAdd; (*$P-*) BEGIN (* LEA -12(SP),SP ;TMP *) CODE(04FEFH);CODE(0FFF4H); (* PEA 20(SP) ;DEST *) CODE(0486FH);CODE(20); (* PEA 4(SP) ;ADR(TMP) *) CODE(0486FH);CODE(4); (* MOVE #FS2X,-(SP) *) CODE(03F3CH);CODE(FS2X); (* _FP68K ; A9EB *) CODE(0A9EBH); (* PEA 16(SP) ;SRC *) CODE(0486FH);CODE(16); (* PEA 4(SP) ;ADR(TMP) *) CODE(0486FH);CODE(4); (* MOVE #FADDS,-(SP) *) CODE(03F3CH);CODE(FADDS); (* _FP68K ; A9EB *) CODE(0A9EBH); (* PEA (SP) ;TMP *) CODE(04857H); (* PEA 24(SP) ;DEST *) CODE(0486FH);CODE(24); (* MOVE #FX2S,-(SP) *) CODE(03F3CH);CODE(FX2S); (* _FP68K ; A9EB *) CODE(0A9EBH); (* LEA 12(SP),SP *) CODE(04FEFH);CODE(12); (* RTS *) CODE(04E75H); END SYSRealAdd; PROCEDURE SYSRealSub; (*$P-*) BEGIN (* LEA -12(SP),SP ;TMP *) CODE(04FEFH);CODE(0FFF4H); (* PEA 20(SP) ;DEST *) CODE(0486FH);CODE(20); (* PEA 4(SP) ;ADR(TMP) *) CODE(0486FH);CODE(4); (* MOVE #FS2X,-(SP) *) CODE(03F3CH);CODE(FS2X); (* _FP68K ; A9EB *) CODE(0A9EBH); (* PEA 16(SP) ;SRC *) CODE(0486FH);CODE(16); (* PEA 4(SP) ;ADR(TMP) *) CODE(0486FH);CODE(4); (* MOVE #FSUBS,-(SP) *) CODE(03F3CH);CODE(FSUBS); (* _FP68K ; A9EB *) CODE(0A9EBH); (* PEA (SP) ;TMP *) CODE(04857H); (* PEA 24(SP) ;DEST *) CODE(0486FH);CODE(24); (* MOVE #FX2S,-(SP) *) CODE(03F3CH);CODE(FX2S); (* _FP68K ; A9EB *) CODE(0A9EBH); (* LEA 12(SP),SP *) CODE(04FEFH);CODE(12); (* RTS *) CODE(04E75H); END SYSRealSub; PROCEDURE SYSRealMult; (*$P-*) BEGIN (* LEA -12(SP),SP ;TMP *) CODE(04FEFH);CODE(0FFF4H); (* PEA 20(SP) ;DEST *) CODE(0486FH);CODE(20); (* PEA 4(SP) ;ADR(TMP) *) CODE(0486FH);CODE(4); (* MOVE #FS2X,-(SP) *) CODE(03F3CH);CODE(FS2X); (* _FP68K ; A9EB *) CODE(0A9EBH); (* PEA 16(SP) ;SRC *) CODE(0486FH);CODE(16); (* PEA 4(SP) ;ADR(TMP) *) CODE(0486FH);CODE(4); (* MOVE #FMULS,-(SP) *) CODE(03F3CH);CODE(FMULS); (* _FP68K ; A9EB *) CODE(0A9EBH); (* PEA (SP) ;TMP *) CODE(04857H); (* PEA 24(SP) ;DEST *) CODE(0486FH);CODE(24); (* MOVE #FX2S,-(SP) *) CODE(03F3CH);CODE(FX2S); (* _FP68K ; A9EB *) CODE(0A9EBH); (* LEA 12(SP),SP *) CODE(04FEFH);CODE(12); (* RTS *) CODE(04E75H); END SYSRealMult; PROCEDURE SYSRealDiv; (*$P-*) BEGIN (* DEST := DEST / SRC *) (* LEA -12(SP),SP ;TMP *) CODE(04FEFH);CODE(0FFF4H); (* PEA 20(SP) ;DEST *) CODE(0486FH);CODE(20); (* PEA 4(SP) ;ADR(TMP) *) CODE(0486FH);CODE(4); (* MOVE #FS2X,-(SP) *) CODE(03F3CH);CODE(FS2X); (* _FP68K ; A9EB *) CODE(0A9EBH); (* PEA 16(SP) ;SRC *) CODE(0486FH);CODE(16); (* PEA 4(SP) ;ADR(TMP) *) CODE(0486FH);CODE(4); (* MOVE #FDIVS,-(SP) *) CODE(03F3CH);CODE(FDIVS); (* _FP68K ; A9EB *) CODE(0A9EBH); (* PEA (SP) ;TMP *) CODE(04857H); (* PEA 24(SP) ;DEST *) CODE(0486FH);CODE(24); (* MOVE #FX2S *) CODE(03F3CH);CODE(FX2S); (* _FP68K ; A9EB *) CODE(0A9EBH); (* LEA 12(SP),SP *) CODE(04FEFH);CODE(12); (* RTS *) CODE(04E75H); END SYSRealDiv; PROCEDURE SYSRealCMP; (*Procedure Code Proc # 16 *) (* Entry Point 0000, number of bytes = 66 *) (*$P-*) BEGIN (* LEA -12(SP),SP ;TMP *) CODE(04FEFH);CODE(0FFF4H); (* PEA 20(SP) ;SRC *) CODE(0486FH);CODE(20); (* PEA 4(SP) ;ADR(TMP) *) CODE(0486FH);CODE(4); (* MOVE #FS2X,-(SP) *) CODE(03F3CH);CODE(FS2X); (* _FP68K ; A9EB *) CODE(0A9EBH); (* PEA 16(SP) ;DEST *) CODE(0486FH);CODE(16); (* PEA 4(SP) ;ADR(TMP) *) CODE(0486FH);CODE(4); (* MOVE #FCMPS,-(SP) *) CODE(03F3CH);CODE(FCMPS); (* _FP68K ; A9EB *) CODE(0A9EBH); (* LEA 12(SP),SP *) CODE(04FEFH);CODE(12); (* RTS *) CODE(04E75H); END SYSRealCMP; PROCEDURE SYSRealTST; (*$P-*) BEGIN (* CLR.L -(SP) *) CODE(042A7H); (* LEA -12(SP),SP ;TMP *) CODE(04FEFH);CODE(0FFF4H); (* PEA 12(SP) ;SRC *) CODE(0486FH);CODE(12); (* PEA 4(SP) ;ADR(TMP) *) CODE(0486FH);CODE(4); (* MOVE #FS2X,-(SP) *) CODE(03F3CH);CODE(FS2X); (* _FP68K ; A9EB *) CODE(0A9EBH); (* PEA 20(SP) ;DEST *) CODE(0486FH);CODE(20); (* PEA 4(SP) ;ADR(TMP) *) CODE(0486FH);CODE(4); (* MOVE #FCMPS,-(SP) *) CODE(03F3CH);CODE(FCMPS); (* _FP68K ; A9EB *) CODE(0A9EBH); (* LEA 16(SP),SP *) CODE(04FEFH);CODE(16); (* RTS *) CODE(04E75H); END SYSRealTST; PROCEDURE SYSRealFLOAT; (*$P-*) BEGIN (* LEA -12(SP),SP ;TMP *) CODE(04FEFH);CODE(0FFF4H); (* PEA 16(SP) ;SRC *) CODE(0486FH);CODE(16); (* PEA 4(SP) ;ADR(TMP) *) CODE(0486FH);CODE(4); (* MOVE #FL2X,-(SP) *) CODE(03F3CH);CODE(FL2X); (* _FP68K ; A9EB *) CODE(0A9EBH); (* PEA (SP) ;TMP *) CODE(04857H); (* PEA 20(SP) ;RETURN *) CODE(0486FH);CODE(20); (* MOVE #FX2S *) CODE(03F3CH);CODE(FX2S); (* _FP68K ; A9EB *) CODE(0A9EBH); (* LEA 12(SP),SP *) CODE(04FEFH);CODE(12); (* RTS *) CODE(04E75H); END SYSRealFLOAT; PROCEDURE SYSRealTRUNC; (*$P-*) BEGIN (* LEA -12(SP),SP ;TMP *) CODE(04FEFH);CODE(0FFF4H); (* PEA 16(SP) ;SRC *) CODE(0486FH);CODE(16); (* PEA 4(SP) ;ADR(TMP) *) CODE(0486FH);CODE(4); (* MOVE #FS2X,-(SP) *) CODE(03F3CH);CODE(FS2X); (* _FP68K ; A9EB *) CODE(0A9EBH); (* PEA (SP) ;TMP *) CODE(04857H); (* MOVE #FTINTX,-(SP) *) CODE(03F3CH);CODE(FTINTX); (* _FP68K ; A9EB *) CODE(0A9EBH); (* PEA (SP) ;TMP *) CODE(04857H); (* PEA 20(SP) ;RETURN *) CODE(0486FH);CODE(20); (* MOVE #FX2L,-(SP) *) CODE(03F3CH);CODE(FX2L); (* _FP68K ; A9EB *) CODE(0A9EBH); (* LEA 12(SP),SP *) CODE(04FEFH);CODE(12); (* RTS *) CODE(04E75H); END SYSRealTRUNC; (*$P-*) END SYSTEMX. !Funky!Stuff! echo x - ScrapManager.MOD cat >ScrapManager.MOD <<'!Funky!Stuff!' IMPLEMENTATION MODULE ScrapManager; FROM SYSTEM IMPORT ADDRESS,CODE,ADR; FROM MacSYSTEM IMPORT LONGINT,Handle; FROM QuickDraw IMPORT Str255; FROM ResourceManager IMPORT ResType; CONST GetRet = 0285FH; (* MOVEA (A7)+,A4 *) Return = 04ED4H; (* JMP A4 *) SaveA7 = 0264FH; (* MOVEA A7,A3 *) RestoreA7 = 02E4BH; (* MOVEA A3,A7 *) PROCEDURE InfoScrap():PScrapStuff; (*$P+*)(*$S-*) BEGIN RETURN(PScrapStuff(0960H)) END InfoScrap; PROCEDURE UnloadScrap():LONGINT; (*$P-*) BEGIN CODE(GetRet); CODE(SaveA7); CODE(0A9FAH); CODE(RestoreA7); CODE(Return); END UnloadScrap; PROCEDURE LoadScrap():LONGINT; (*$P-*) BEGIN CODE(GetRet); CODE(SaveA7); CODE(0A9FBH); CODE(RestoreA7); CODE(Return); END LoadScrap; PROCEDURE xGetScrap(hDest:Handle;theType:LONGINT;VAR offset:LONGINT):LONGINT; (*$P-*) BEGIN CODE(GetRet); CODE(SaveA7); CODE(0A9FDH); CODE(RestoreA7); CODE(Return); END xGetScrap; TYPE Converter = RECORD CASE INTEGER OF 0: r:ResType; | 1: l:LONGINT END END; PROCEDURE GetScrap(hDest:Handle;theType:ResType;VAR offset:LONGINT):LONGINT; (*$P+*)(*$S-*) VAR c:Converter; BEGIN c.r := theType; RETURN(xGetScrap(hDest,c.l,offset)); END GetScrap; PROCEDURE ZeroScrap():LONGINT; (*$P-*) BEGIN CODE(GetRet); CODE(SaveA7); CODE(0A9FCH); CODE(RestoreA7); CODE(Return); END ZeroScrap; PROCEDURE xPutScrap(length:LONGINT;theType:LONGINT;source:ADDRESS):LONGINT; (*$P-*) BEGIN CODE(GetRet); CODE(SaveA7); CODE(0A9FEH); CODE(RestoreA7); CODE(Return); END xPutScrap; PROCEDURE PutScrap(length:LONGINT;theType:ResType;source:ADDRESS):LONGINT; (*$P+*)(*$S-*) VAR c:Converter; BEGIN c.r := theType; RETURN(xPutScrap(length,c.l,source)) END PutScrap END ScrapManager. !Funky!Stuff! echo x - Storage.MOD cat >Storage.MOD <<'!Funky!Stuff!' IMPLEMENTATION MODULE Storage; (*$S-*) (* Because the stack checking is turned off in the SYSTEMX.MOD file it is * Turned off here also. *) (* Created for standalone MacIntosh Code By Bob Campbell 10.02.86 * The Implementation now used the A-Line calls to the memory manager * All of the storage allocated is set to zero. The Calls CreateHeap, * and DestroyHeap have been removed. *) FROM SYSTEM IMPORT ADDRESS,CODE,ADR,REGISTER,SETREG; CONST GetRet = 0285FH; (* MOVEA (A7)+,A4 *) Return = 04ED4H; (* JMP A4 *) SaveA7 = 0264FH; (* MOVEA A7,A3 *) RestoreA7 = 02E4BH; (* MOVEA A3,A7 *) noErr = 0; PROCEDURE ALLOCATE (VAR addr : ADDRESS; amount : CARDINAL); (* allocates the requested amount of memory (in bytes) and returns the *) (* starting address . Return NIL if the amount is not available *) (* Note that the memory is cleared by the trap call *) BEGIN SETREG(0,amount); CODE(0A31EH); IF (REGISTER(0) # noErr) THEN addr := NIL ELSE addr := REGISTER(8) END END ALLOCATE; PROCEDURE DEALLOCATE (VAR addr : ADDRESS; amount : CARDINAL); (* deallocates the given amount of memory (in bytes). *) (*$S-*) BEGIN SETREG(8,addr); CODE(0A01FH); END DEALLOCATE; PROCEDURE Available (amount : CARDINAL) : BOOLEAN; (* returns TRUE if an ALLOCATE of the specified amount (in bytes) *) (* of memory would be possible *) BEGIN SETREG(0,amount); CODE(0A040H); RETURN(INTEGER(REGISTER(0)) = 0) END Available; END Storage. !Funky!Stuff! echo x - Streams.MOD cat >Streams.MOD <<'!Funky!Stuff!' IMPLEMENTATION MODULE Streams; (* * Modified from the book "PROGRAMMING IN * MODULA-2" by Miklaus Wirth Edited by * David Gries pages 103 and 104. *) FROM SYSTEM IMPORT ADR,REGISTER,SETREG,CODE,ADDRESS,WORD; FROM MacSYSTEM IMPORT LONGINT,OSErr,noErr; FROM Storage IMPORT ALLOCATE,DEALLOCATE; FROM FileTypes IMPORT OSType,ParamBlkPtr,ParamBlockRec,ParamBlkType,FInfo, fsAtMark,fsFromStart,fsFromMark,fsCurPerm, fsRdPerm,fsWrPerm,fsRdWrPerm, badMDBErr,bdNamErr,dirFulErr,dskFulErr,dupFNErr,eofErr,extFSErr, fBsyErr,fLckdErr,fnfErr,fnOpnErr,fsRnErr,ioErr,mFulErr,nsDrvErr, noMacDskErr,nsvErr,opWrErr,paramErr,permErr,posErr,rfNumErr, tmfoErr,volOffLinErr,volOnLinErr,vLckdErr,wrPermErr,wPrErr; FROM PascalStrings IMPORT MakeModulaString,MakePascalString; CONST OpenTrap = 0A000H; CloseTrap = 0A001H; ReadTrap = 0A002H; WriteTrap = 0A003H; CreateTrap = 0A008H; DeleteTrap = 0A009H; GetFileInfoTrap = 0A00CH; SetFileInfoTrap = 0A00DH; GetEOFTrap = 0A011H; SetEOFTrap = 0A012H; GetFPosTrap = 0A018H; SetFPosTrap = 0A044H; TYPE (* Changing Information About Files *) PROCEDURE GetFInfo(VAR File:ARRAY OF CHAR;vRef:INTEGER;VAR fndr:FInfo); VAR PB:ParamBlockRec; Str:ARRAY[0..255] OF CHAR; BEGIN PB.ioCompletion := ADDRESS(0); MakePascalString(File,Str); PB.ioNamePtr := ADR(Str); PB.ioVRefNum := vRef; PB.ioVersNum := 0C; PB.ioFDirIndex := 0; SETREG(8,ADR(PB)); (* A0 := ADR(PB) *) CODE(GetFileInfoTrap); IF (PB.ioResult = noErr) THEN fndr := PB.ioFlFndrInfo END; END GetFInfo; PROCEDURE SetFInfo(VAR File:ARRAY OF CHAR;vRef:INTEGER;fndrInfo:FInfo); VAR PB:ParamBlockRec; Str:ARRAY[0..255] OF CHAR; BEGIN PB.ioCompletion := ADDRESS(0); MakePascalString(File,Str); PB.ioNamePtr := ADR(Str); PB.ioVRefNum := vRef; PB.ioVersNum := 0C; PB.ioFDirIndex := 0; SETREG(8,ADR(PB)); (* A0 := ADR(PB) *) CODE(GetFileInfoTrap); (* get create/modification times *) PB.ioFlFndrInfo := fndrInfo; SETREG(8,ADR(PB)); (* A0 := ADR(PB) *) CODE(SetFileInfoTrap); END SetFInfo; PROCEDURE Open(VAR File:STREAM; VAR Name:ARRAY OF CHAR;vRef:INTEGER; Mode:OpenMode); VAR Str: POINTER TO ARRAY[0..255] OF CHAR; BEGIN NEW(File); IF (File = NIL) THEN RETURN END; WITH File^ DO IsOpen := FALSE; EOSPos := 0; CurrentPos := 0; ALLOCATE(Str,HIGH(Name) + 2); IF (Str = NIL) THEN DISPOSE(File); File := NIL; RETURN END; ALLOCATE(Buffer,524); IF (Buffer = NIL) THEN DISPOSE(File); DEALLOCATE(Str,HIGH(Name) + 2); File := NIL; RETURN END; PB.ioCompletion := ADDRESS(0); MakePascalString(Name,Str^); PB.ioNamePtr := ADDRESS(Str); PB.ioVRefNum := vRef; PB.ioVersNum := 0C; CASE Mode OF ReadOnly: PB.ioPermssn := fsRdPerm | WriteOnly: PB.ioPermssn := fsWrPerm | ReadWrite: PB.ioPermssn := fsRdWrPerm END; PB.ioMisc := Buffer; SETREG(8,ADR(PB)); (* A0 := ADR(PB) *) CODE(OpenTrap); FileNum := PB.ioRefNum; IF (PB.ioResult = opWrErr) THEN DEALLOCATE(Buffer,524); (* File is already open *) Buffer := NIL; (* using other buffer *) IF Mode = WriteOnly THEN SetEOF(File,0) END; GetEOF(File,EOSPos); CurrentPos := 0; ELSIF NOT(PB.ioResult = noErr) THEN DEALLOCATE(PB.ioMisc,524); DEALLOCATE(Str,HIGH(Name) + 2); DISPOSE(File); File := NIL; ELSE IsOpen := TRUE; IF Mode = WriteOnly THEN SetEOF(File,0) END; GetEOF(File,EOSPos); CurrentPos := 0; END; END (* WITH *) END Open; PROCEDURE Close(File:STREAM); BEGIN WITH File^ DO PB.ioCompletion := ADDRESS(0); PB.ioRefNum := FileNum; SETREG(8,ADR(PB)); (* A0 := ADR(PB) *) CODE(CloseTrap); DEALLOCATE(PB.ioNamePtr,ORD(PB.ioNamePtr^[0])+1); IF (Buffer # NIL) THEN DEALLOCATE(Buffer,524); END; IsOpen := FALSE; END END Close; PROCEDURE Create(VAR Name:ARRAY OF CHAR;vRef:INTEGER; creator,type:OSType); VAR PB:ParamBlockRec; Str:ARRAY[0..255] OF CHAR; f:FInfo; ret : OSErr; BEGIN PB.ioCompletion := ADDRESS(0); MakePascalString(Name,Str); PB.ioNamePtr := ADR(Str); PB.ioVRefNum := vRef; PB.ioFVersNum := 0C; SETREG(8,ADR(PB)); (* A0 := ADR(PB) *) CODE(CreateTrap); GetFInfo(Name,vRef,f); f.fdType := type; f.fdCreator := creator; SetFInfo(Name,vRef,f); END Create; PROCEDURE WriteWord(File:STREAM;w:WORD); BEGIN WITH File^ DO PB.ioReqCount := 2; PB.ioPosMode := 0; PB.ioPosOffset := 0; PB.ioBuffer := ADR(w); SETREG(8,ADR(PB)); (* A0 := ADR(PB) *) CODE(WriteTrap); CurrentPos := PB.ioPosOffset; IF PB.ioResult # noErr THEN EOSPos := 0 ELSE GetEOF(File,EOSPos) END END END WriteWord; PROCEDURE WriteChar(File:STREAM;c:CHAR); BEGIN WITH File^ DO PB.ioReqCount := 1; PB.ioPosMode := 0; PB.ioPosOffset := 0; PB.ioBuffer := ADR(c); SETREG(8,ADR(PB)); (* A0 := ADR(PB) *) CODE(WriteTrap); CurrentPos := PB.ioPosOffset; IF PB.ioResult # noErr THEN EOSPos := 0 ELSE GetEOF(File,EOSPos) END END END WriteChar; PROCEDURE WriteBuffer(File:STREAM;b:ADDRESS;len:LONGINT):LONGINT; BEGIN WITH File^ DO PB.ioReqCount := len; PB.ioPosMode := 0; PB.ioPosOffset := 0; PB.ioBuffer := b; SETREG(8,ADR(PB)); (* A0 := ADR(PB) *) CODE(WriteTrap); CurrentPos := PB.ioPosOffset; IF PB.ioResult # noErr THEN EOSPos := 0; RETURN(0) ELSE GetEOF(File,EOSPos) END; RETURN(PB.ioActCount); END END WriteBuffer; PROCEDURE ReadWord(File:STREAM;VAR w:WORD); BEGIN WITH File^ DO PB.ioReqCount := 2; PB.ioPosMode := 0; PB.ioPosOffset := 0; PB.ioBuffer := ADR(w); SETREG(8,ADR(PB)); (* A0 := ADR(PB) *) CODE(ReadTrap); CurrentPos := PB.ioPosOffset; IF PB.ioResult # noErr THEN w := WORD(0); EOSPos := 0 END END END ReadWord; PROCEDURE ReadChar(File:STREAM;VAR c:CHAR); BEGIN WITH File^ DO PB.ioReqCount := 1; PB.ioPosMode := 0; PB.ioPosOffset := 0; PB.ioBuffer := ADR(c); SETREG(8,ADR(PB)); (* A0 := ADR(PB) *) CODE(ReadTrap); CurrentPos := PB.ioPosOffset; IF PB.ioResult # noErr THEN c := 0C; EOSPos := 0 END END END ReadChar; PROCEDURE ReadBuffer(File:STREAM;buff:ADDRESS;count:LONGINT):LONGINT; VAR BEGIN WITH File^ DO IF (count = 0) THEN RETURN(0) END; PB.ioCompletion := ADDRESS(0); PB.ioRefNum := FileNum; PB.ioReqCount := count; PB.ioPosMode := 0; PB.ioPosOffset := 0; PB.ioBuffer := buff; SETREG(8,ADR(PB)); (* A0 := ADR(PB) *) CODE(ReadTrap); CurrentPos := PB.ioPosOffset; IF PB.ioResult # noErr THEN EOSPos := 0; RETURN(0) ELSE RETURN(PB.ioActCount) END END END ReadBuffer; PROCEDURE EOS(s:STREAM):BOOLEAN; BEGIN RETURN(s^.CurrentPos >= s^.EOSPos); END EOS; PROCEDURE Reset(s:STREAM); BEGIN SetPos(s,0); END Reset; PROCEDURE GetPos(File:STREAM;VAR FilePos:LONGINT); BEGIN WITH File^ DO SETREG(8,ADR(PB)); (* A0 := ADR(PB) *) CODE(GetFPosTrap); FilePos := PB.ioPosOffset; END END GetPos; PROCEDURE SetPos(File:STREAM;posOff:LONGINT); BEGIN WITH File^ DO PB.ioPosMode := fsFromStart; PB.ioPosOffset := posOff; SETREG(8,ADR(PB)); (* A0 := ADR(PB) *) CODE(SetFPosTrap); CurrentPos := PB.ioPosOffset; END END SetPos; PROCEDURE GetEOF(File:STREAM;VAR logEOF:LONGINT); BEGIN WITH File^ DO SETREG(8,ADR(PB)); (* A0 := ADR(PB) *) CODE(GetEOFTrap); logEOF := PB.ioMisc; END END GetEOF; PROCEDURE SetEOF(File:STREAM;logEOF:LONGINT); BEGIN WITH File^ DO PB.ioMisc := ADDRESS(logEOF); SETREG(8,ADR(PB)); (* A0 := ADR(PB) *) CODE(SetEOFTrap); END END SetEOF; END Streams. !Funky!Stuff! # The rest of this file is a shell script which will extract: # SYSTEMX.MOD ScrapManager.MOD Storage.MOD Streams.MOD echo x - SYSTEMX.MOD cat >SYSTEMX.MOD <<'!Funky!Stuff!' IMPLEMENTATION MODULE SYSTEMX; FROM SYSTEM IMPORT ADDRESS,CODE,SETREG,REGISTER,ADR,PROCESS; CONST FADDS = 01000H; FSUBS = 01002H; FMULS = 01004H; FDIVS = 01006H; FCMPS = 01008H; FTINTX = 00016H; FX2S = 01010H; FS2X = 0100EH; FX2L = 02810H; FL2X = 0280EH; (*$P-*) PROCEDURE DoCASE; BEGIN CODE(0205FH); (* MOVEA.L (A7)+,A0 *) CODE(09090H); (* SUB.L (A0),DO *) CODE(0B0A8H);CODE(00004H); (* CMP.L 0004(A0),D0 *) CODE(0620CH); (* BHI $1 {+12} *) CODE(0E380H); (* ASL.L #1,D0 *) CODE(0D0A8H);CODE(00008H); (* ADD.L 0008(A0),D0 *) CODE(0D0F0H);CODE(00800H); (* ADDA.L 00(A0,DO.W),A0 *) CODE(04ED0H); (* JMP (A0) *) (* $1 *) CODE(0D1E8H);CODE(00008H); (* ADDA.L 0008(A0),A0 *) CODE(05988H); (* SUBQ.L #4,A0 *) CODE(04ED0H); (* JMP (A0) *) END DoCASE; PROCEDURE DoHALT; (*$P-*) BEGIN CODE(0A9FFH); (* CALL DEBUGGER *) CODE(04E75H); END DoHALT; PROCEDURE CheckStack; (*$P-*) BEGIN (* STUBED OUT FOR NOW! *) CODE(04E75H); (* RTS *) END CheckStack; PROCEDURE SYSProc20; (*$P-*) BEGIN (* 0000 MOVEQ.L #0007,D0 *) CODE(07007H); DoHALT; END SYSProc20; PROCEDURE NEWPROCESS; (*$P-*) BEGIN CODE(0700AH); (* MOVEQ.L #000A,D0 *) DoHALT; END NEWPROCESS; PROCEDURE TRANSFER; (*$P-*) BEGIN CODE(0700BH); (* MOVEQ.L #000B,DO *) DoHALT; END TRANSFER; PROCEDURE SYSProc21; (*$P-*) BEGIN (* * Procedure Code Proc # 21 * Entry Point 0000, number of bytes = 40 *) (* 0000 MOVE.W #2700,SR *) CODE(046FCH);CODE(02700); (* 0004 MOVE.L A6,-(A7) *) CODE(02F0EH); (* 0006 MOVE.L USP,A6 *) CODE(04E6EH); (* 0008 MOVE.L A5,-(A6) *) CODE(02D0DH); (* 000A LEA A6,FFCC(A6) *) CODE(04DEEH); CODE(0FFCCH); (* 000E MOVE.L (A7)+,-(A6) *) CODE(02D1FH); (* 0010 MOVE.W (A7)+,-(A6) *) CODE(03D1FH); (* 0012 MOVE.L (A7)+,-(A6) *) CODE(02D1FH); (* 0014 MOVE.L A6,(A0) *) CODE(0208EH); (* 0016 MOVEA.L (A1),A6 *) CODE(02C51H); (* 0018 MOVE.L (A6)+,-(A7) *) CODE(02F1EH); (* 001A MOVE.W (A6)+,-(A7) *) CODE(03F1EH); (* 001C MOVE.L (A6)+,-(A7) *) CODE(02F1EH); (* 001E MOVEM.L D0-A5,(A6)+ *) CODE(04CDEH); CODE(03FFFH); (* 0022 MOVE.L A6,USP *) CODE(04E66H); (* 0024 MOVEA.L (A7)+,A6 *) CODE(02C5FH); (* 0026 RTE *) CODE(04E73H); END SYSProc21; PROCEDURE IOTRANSFER(p1,p2:PROCESS; via:ADDRESS); (*$P-*) BEGIN CODE(0700CH); (* MOVEQ.L #000C,DO *) DoHALT; END IOTRANSFER; PROCEDURE SYSProc7; (* IF D0 = 2 THEN LISTEN ELSIF D0 = 3 THEN SYSRESET END *) (*$P-*) BEGIN CODE(0700DH); DoHALT; END SYSProc7; PROCEDURE SYSLongMult; (*$P-*) BEGIN CODE(04E56H);CODE(00000H); (* LINK A6,#0000 *) CODE(048E7H);CODE(07C00H); (* MOVEM.L D5-D1,-(A7) *) CODE(0222EH);CODE(00008H); (* MOVE.L 0008(A6),D1 *) CODE(0242EH);CODE(0000CH); (* MOVE.L 000C(A6),D2 *) CODE(02601H); (* MOVE.L D1,D3 *) CODE(02801H); (* MOVE.L D1,D4 *) CODE(02A02H); (* MOVE.L D2,D5 *) CODE(04844H); (* SWAP D4 *) CODE(04845H); (* SWAP D5 *) CODE(0C2C2H); (* MULU.W D2,D1 *) CODE(0C4C4H); (* MULU.W D4,D2 *) CODE(0C6C5H); (* MULU.W D5,D3 *) CODE(0C8C5H); (* MULU.W D5,D4 *) CODE(04841H); (* SWAP D1 *) CODE(0D242H); (* ADD.W D2,D1 *) CODE(04285H); (* CLR.L D5 *) CODE(0D985H); (* ADDX.L D5,D4 *) CODE(0D243H); (* ADD.W D3,D1 *) CODE(0D985H); (* ADDX.L D5,D4 *) CODE(04841H); (* SWAP D1 *) CODE(04242H); (* CLR.W D2 *) CODE(04243H); (* CLR.W D3 *) CODE(04842H); (* SWAP D2 *) CODE(04843H); (* SWAP D3 *) CODE(0D483H); (* ADD.L D3,D2 *) CODE(0D484H); (* ADD.L D4,D2 *) CODE(02D41H);CODE(0000CH); (* MOVE.L D1,000C(A6) *) CODE(04CDFH);CODE(00008H); (* MOVE.L D2,0008(A6) *) CODE(04E5EH); (* UNLK A6 *) CODE(04E75H); (* RTS *) END SYSLongMult; PROCEDURE SYSLongDivMod; (*$P-*) BEGIN CODE(04E56H);CODE(00000H); (* LINK A6,#0000 *) CODE(048E7H);CODE(07800H); (* MOVEM.L D4-D1,-(A7) *) CODE(0222EH);CODE(0000CH); (* MOVE.L 000C(A6),D1 *) CODE(0242EH);CODE(00008H); (* MOVE.L 0008(A6),D2 *) CODE(0B4BCH);CODE(00000H); CODE(0FFFFH); (* CMP.L #0000FFFF,D2 *) CODE(0621EH); (* BHI $1 {+30} *) CODE(04243H); (* CLR.W D3 *) CODE(082C2H); (* DIVU.W D2,D1 *) CODE(0680EH); (* BVC $2 {+14} *) CODE(03801H); (* MOVE.W D1,D4 *) CODE(04241H); (* CLR.W D1 *) CODE(04841H); (* SWAP D1 *) CODE(082C2H); (* DIVU.W D2,D1 *) CODE(03601H); (* MOVE.W D1,D3 *) CODE(03204H); (* MOVE.W D4,D1 *) CODE(082C2H); (* DIVU.W D2,D1 *) (* $2: *) CODE(04843H); (* SWAP D3 *) CODE(03601H); (* MOVE.W D1,D3 *) CODE(04241H); (* CLR.W D1 *) CODE(04841H); (* SWAP D1 *) CODE(0601EH); (* BRA $3 {+30} *) (* $1: *) CODE(04283H); (* CLR.L D3 *) CODE(03601H); (* MOVE.W D1,D3 *) CODE(04843H); (* SWAP D3 *) CODE(04241H); (* CLR.W D1 *) CODE(04841H); (* SWAP D1 *) CODE(0383CH);CODE(0000FH); (* MOVE.W #000F,D4 *) (* $5: *) CODE(0E38BH); (* LSL.L #1,D3 *) CODE(0E391H); (* ROXL.L #1,D1 *) CODE(0B282H); (* CMP.L D2,D1 *) CODE(06504H); (* BCS $4 {+4} *) CODE(09282H); (* SUB.L D2,D1 *) CODE(05243H); (* ADDQ.W #1,D3 *) (* $4: *) CODE(051CCH);CODE(0FFF2H); (* DBF D4,$5 {-14} *) (* $3: *) CODE(02D43H);CODE(0000CH); (* MOVE.L D3,000C(A6) *) CODE(02D41H);CODE(00008H); (* MOVE.L D1,0008(A6) *) CODE(04CDFH);CODE(0001EH); (* MOVEM.L D1-D4,(A7)+ *) CODE(04E5EH); (* UNLK A6 *) CODE(04E75H); (* RTS *) END SYSLongDivMod; PROCEDURE SYSLongIntMult; (*$P-*) BEGIN (* Procedure Code Proc # 10 *) (* Entry Point 0000, number of bytes = 92 *) (* 0000 LINK A6,#0000 *) CODE(04E56H); CODE(00000H); (* 0004 MOVEM.L D7-D1,-(A7) *) CODE(048E7H); CODE(07F00H); (* 0008 MOVE.L 0008(A6),D1 *) CODE(0222EH); CODE(00008H); (* 000C MOVE.L 000C(A6),D2 *) CODE(0242EH); CODE(0000CH); (* 0010 MOVE.L D1,D3 *) CODE(02601H); (* 0012 MOVE.L D1,D4 *) CODE(02801H); (* 0014 MOVE.L D2,D5 *) CODE(02A02H); (* 0016 MOVE.L D1,D6 *) CODE(02C01H); (* 0018 CLR.L D7 *) CODE(04287H); (* 001A SWAP D4 *) CODE(04844H); (* 001C SWAP D5 *) CODE(04845H); (* 001E MULU.W D2,D1 *) CODE(0C2C2H); (* 0020 MULU.W D4,D2 *) CODE(0C4C4H); (* 0022 MULU.W D5,D3 *) CODE(0C6C5H); (* 0024 MULU.W D5,D4 *) CODE(0C8C5H); (* 0026 SWAP D1 *) CODE(04841H); (* 0028 ADD.W D2,D1 *) CODE(0D987H); (* 002A ADDX.L D7,D4 *) CODE(0D987H); (* 002C ADD.W D3,D1 *) CODE(0D243H); (* 002E ADDX.L D7,D4 *) CODE(0D987H); (* 0030 SWAP D1 *) CODE(04841H); (* 0032 CLR.W D2 *) CODE(04242H); (* 0034 CLR.W D3 *) CODE(04243H); (* 0036 SWAP D2 *) CODE(04842H); (* 0038 SWAP D3 *) CODE(04843H); (* 003A ADD.L D3,D2 *) CODE(0D483H); (* 003C ADD.L D4,D2 *) CODE(0D484H); (* 003E SWAP D5 *) CODE(04845H); (* 0040 TST.L D6 *) CODE(04A86H); (* 0042 BPI 2 {0046} *) CODE(06A02H); (* 0044 SUB.L D5,D2 *) CODE(09485H); (* 0046 TST.L D5 *) CODE(04A85H); (* 0048 BPI 2 {004C} *) CODE(06A02H); (* 004A SUB.L D6,D2 *) CODE(09486H); (* 004C MOVE.L D1,000C(A6) *) CODE(02D41H); CODE(0000CH); (* 0050 MOVE.L D2,0008(A6) *) CODE(02D42H); CODE(00008H); (* 0054 MOVEM.L D1-D7,(A7)+ *) CODE(04CDFH); CODE(000FEH); (* 0058 UNLK A6 *) CODE(04E5EH); (* 005A RTS *) CODE(04E75H); END SYSLongIntMult; PROCEDURE SYSProc11; (*$P-*) BEGIN (*Procedure Code Proc # 11 *) (* Entry Point 0000, number of bytes = 16*) (* 0000 LINK A6,#0000 *) CODE(04E56H); CODE(00000H); (* 0004 MOVEQ.L #0008,D0 *) CODE(07008H); DoHALT; (* 000C UNLK A6 *) CODE(04E5EH); (* 000E RTS *) CODE(04E75H); END SYSProc11; PROCEDURE SYSRealAdd; (*$P-*) BEGIN (* LEA -12(SP),SP ;TMP *) CODE(04FEFH);CODE(0FFF4H); (* PEA 20(SP) ;DEST *) CODE(0486FH);CODE(20); (* PEA 4(SP) ;ADR(TMP) *) CODE(0486FH);CODE(4); (* MOVE #FS2X,-(SP) *) CODE(03F3CH);CODE(FS2X); (* _FP68K ; A9EB *) CODE(0A9EBH); (* PEA 16(SP) ;SRC *) CODE(0486FH);CODE(16); (* PEA 4(SP) ;ADR(TMP) *) CODE(0486FH);CODE(4); (* MOVE #FADDS,-(SP) *) CODE(03F3CH);CODE(FADDS); (* _FP68K ; A9EB *) CODE(0A9EBH); (* PEA (SP) ;TMP *) CODE(04857H); (* PEA 24(SP) ;DEST *) CODE(0486FH);CODE(24); (* MOVE #FX2S,-(SP) *) CODE(03F3CH);CODE(FX2S); (* _FP68K ; A9EB *) CODE(0A9EBH); (* LEA 12(SP),SP *) CODE(04FEFH);CODE(12); (* RTS *) CODE(04E75H); END SYSRealAdd; PROCEDURE SYSRealSub; (*$P-*) BEGIN (* LEA -12(SP),SP ;TMP *) CODE(04FEFH);CODE(0FFF4H); (* PEA 20(SP) ;DEST *) CODE(0486FH);CODE(20); (* PEA 4(SP) ;ADR(TMP) *) CODE(0486FH);CODE(4); (* MOVE #FS2X,-(SP) *) CODE(03F3CH);CODE(FS2X); (* _FP68K ; A9EB *) CODE(0A9EBH); (* PEA 16(SP) ;SRC *) CODE(0486FH);CODE(16); (* PEA 4(SP) ;ADR(TMP) *) CODE(0486FH);CODE(4); (* MOVE #FSUBS,-(SP) *) CODE(03F3CH);CODE(FSUBS); (* _FP68K ; A9EB *) CODE(0A9EBH); (* PEA (SP) ;TMP *) CODE(04857H); (* PEA 24(SP) ;DEST *) CODE(0486FH);CODE(24); (* MOVE #FX2S,-(SP) *) CODE(03F3CH);CODE(FX2S); (* _FP68K ; A9EB *) CODE(0A9EBH); (* LEA 12(SP),SP *) CODE(04FEFH);CODE(12); (* RTS *) CODE(04E75H); END SYSRealSub; PROCEDURE SYSRealMult; (*$P-*) BEGIN (* LEA -12(SP),SP ;TMP *) CODE(04FEFH);CODE(0FFF4H); (* PEA 20(SP) ;DEST *) CODE(0486FH);CODE(20); (* PEA 4(SP) ;ADR(TMP) *) CODE(0486FH);CODE(4); (* MOVE #FS2X,-(SP) *) CODE(03F3CH);CODE(FS2X); (* _FP68K ; A9EB *) CODE(0A9EBH); (* PEA 16(SP) ;SRC *) CODE(0486FH);CODE(16); (* PEA 4(SP) ;ADR(TMP) *) CODE(0486FH);CODE(4); (* MOVE #FMULS,-(SP) *) CODE(03F3CH);CODE(FMULS); (* _FP68K ; A9EB *) CODE(0A9EBH); (* PEA (SP) ;TMP *) CODE(04857H); (* PEA 24(SP) ;DEST *) CODE(0486FH);CODE(24); (* MOVE #FX2S,-(SP) *) CODE(03F3CH);CODE(FX2S); (* _FP68K ; A9EB *) CODE(0A9EBH); (* LEA 12(SP),SP *) CODE(04FEFH);CODE(12); (* RTS *) CODE(04E75H); END SYSRealMult; PROCEDURE SYSRealDiv; (*$P-*) BEGIN (* DEST := DEST / SRC *) (* LEA -12(SP),SP ;TMP *) CODE(04FEFH);CODE(0FFF4H); (* PEA 20(SP) ;DEST *) CODE(0486FH);CODE(20); (* PEA 4(SP) ;ADR(TMP) *) CODE(0486FH);CODE(4); (* MOVE #FS2X,-(SP) *) CODE(03F3CH);CODE(FS2X); (* _FP68K ; A9EB *) CODE(0A9EBH); (* PEA 16(SP) ;SRC *) CODE(0486FH);CODE(16); (* PEA 4(SP) ;ADR(TMP) *) CODE(0486FH);CODE(4); (* MOVE #FDIVS,-(SP) *) CODE(03F3CH);CODE(FDIVS); (* _FP68K ; A9EB *) CODE(0A9EBH); (* PEA (SP) ;TMP *) CODE(04857H); (* PEA 24(SP) ;DEST *) CODE(0486FH);CODE(24); (* MOVE #FX2S *) CODE(03F3CH);CODE(FX2S); (* _FP68K ; A9EB *) CODE(0A9EBH); (* LEA 12(SP),SP *) CODE(04FEFH);CODE(12); (* RTS *) CODE(04E75H); END SYSRealDiv; PROCEDURE SYSRealCMP; (*Procedure Code Proc # 16 *) (* Entry Point 0000, number of bytes = 66 *) (*$P-*) BEGIN (* LEA -12(SP),SP ;TMP *) CODE(04FEFH);CODE(0FFF4H); (* PEA 20(SP) ;SRC *) CODE(0486FH);CODE(20); (* PEA 4(SP) ;ADR(TMP) *) CODE(0486FH);CODE(4); (* MOVE #FS2X,-(SP) *) CODE(03F3CH);CODE(FS2X); (* _FP68K ; A9EB *) CODE(0A9EBH); (* PEA 16(SP) ;DEST *) CODE(0486FH);CODE(16); (* PEA 4(SP) ;ADR(TMP) *) CODE(0486FH);CODE(4); (* MOVE #FCMPS,-(SP) *) CODE(03F3CH);CODE(FCMPS); (* _FP68K ; A9EB *) CODE(0A9EBH); (* LEA 12(SP),SP *) CODE(04FEFH);CODE(12); (* RTS *) CODE(04E75H); END SYSRealCMP; PROCEDURE SYSRealTST; (*$P-*) BEGIN (* CLR.L -(SP) *) CODE(042A7H); (* LEA -12(SP),SP ;TMP *) CODE(04FEFH);CODE(0FFF4H); (* PEA 12(SP) ;SRC *) CODE(0486FH);CODE(12); (* PEA 4(SP) ;ADR(TMP) *) CODE(0486FH);CODE(4); (* MOVE #FS2X,-(SP) *) CODE(03F3CH);CODE(FS2X); (* _FP68K ; A9EB *) CODE(0A9EBH); (* PEA 20(SP) ;DEST *) CODE(0486FH);CODE(20); (* PEA 4(SP) ;ADR(TMP) *) CODE(0486FH);CODE(4); (* MOVE #FCMPS,-(SP) *) CODE(03F3CH);CODE(FCMPS); (* _FP68K ; A9EB *) CODE(0A9EBH); (* LEA 16(SP),SP *) CODE(04FEFH);CODE(16); (* RTS *) CODE(04E75H); END SYSRealTST; PROCEDURE SYSRealFLOAT; (*$P-*) BEGIN (* LEA -12(SP),SP ;TMP *) CODE(04FEFH);CODE(0FFF4H); (* PEA 16(SP) ;SRC *) CODE(0486FH);CODE(16); (* PEA 4(SP) ;ADR(TMP) *) CODE(0486FH);CODE(4); (* MOVE #FL2X,-(SP) *) CODE(03F3CH);CODE(FL2X); (* _FP68K ; A9EB *) CODE(0A9EBH); (* PEA (SP) ;TMP *) CODE(04857H); (* PEA 20(SP) ;RETURN *) CODE(0486FH);CODE(20); (* MOVE #FX2S *) CODE(03F3CH);CODE(FX2S); (* _FP68K ; A9EB *) CODE(0A9EBH); (* LEA 12(SP),SP *) CODE(04FEFH);CODE(12); (* RTS *) CODE(04E75H); END SYSRealFLOAT; PROCEDURE SYSRealTRUNC; (*$P-*) BEGIN (* LEA -12(SP),SP ;TMP *) CODE(04FEFH);CODE(0FFF4H); (* PEA 16(SP) ;SRC *) CODE(0486FH);CODE(16); (* PEA 4(SP) ;ADR(TMP) *) CODE(0486FH);CODE(4); (* MOVE #FS2X,-(SP) *) CODE(03F3CH);CODE(FS2X); (* _FP68K ; A9EB *) CODE(0A9EBH); (* PEA (SP) ;TMP *) CODE(04857H); (* MOVE #FTINTX,-(SP) *) CODE(03F3CH);CODE(FTINTX); (* _FP68K ; A9EB *) CODE(0A9EBH); (* PEA (SP) ;TMP *) CODE(04857H); (* PEA 20(SP) ;RETURN *) CODE(0486FH);CODE(20); (* MOVE #FX2L,-(SP) *) CODE(03F3CH);CODE(FX2L); (* _FP68K ; A9EB *) CODE(0A9EBH); (* LEA 12(SP),SP *) CODE(04FEFH);CODE(12); (* RTS *) CODE(04E75H); END SYSRealTRUNC; (*$P-*) END SYSTEMX. !Funky!Stuff! echo x - ScrapManager.MOD cat >ScrapManager.MOD <<'!Funky!Stuff!' IMPLEMENTATION MODULE ScrapManager; FROM SYSTEM IMPORT ADDRESS,CODE,ADR; FROM MacSYSTEM IMPORT LONGINT,Handle; FROM QuickDraw IMPORT Str255; FROM ResourceManager IMPORT ResType; CONST GetRet = 0285FH; (* MOVEA (A7)+,A4 *) Return = 04ED4H; (* JMP A4 *) SaveA7 = 0264FH; (* MOVEA A7,A3 *) RestoreA7 = 02E4BH; (* MOVEA A3,A7 *) PROCEDURE InfoScrap():PScrapStuff; (*$P+*)(*$S-*) BEGIN RETURN(PScrapStuff(0960H)) END InfoScrap; PROCEDURE UnloadScrap():LONGINT; (*$P-*) BEGIN CODE(GetRet); CODE(SaveA7); CODE(0A9FAH); CODE(RestoreA7); CODE(Return); END UnloadScrap; PROCEDURE LoadScrap():LONGINT; (*$P-*) BEGIN CODE(GetRet); CODE(SaveA7); CODE(0A9FBH); CODE(RestoreA7); CODE(Return); END LoadScrap; PROCEDURE xGetScrap(hDest:Handle;theType:LONGINT;VAR offset:LONGINT):LONGINT; (*$P-*) BEGIN CODE(GetRet); CODE(SaveA7); CODE(0A9FDH); CODE(RestoreA7); CODE(Return); END xGetScrap; TYPE Converter = RECORD CASE INTEGER OF 0: r:ResType; | 1: l:LONGINT END END; PROCEDURE GetScrap(hDest:Handle;theType:ResType;VAR offset:LONGINT):LONGINT; (*$P+*)(*$S-*) VAR c:Converter; BEGIN c.r := theType; RETURN(xGetScrap(hDest,c.l,offset)); END GetScrap; PROCEDURE ZeroScrap():LONGINT; (*$P-*) BEGIN CODE(GetRet); CODE(SaveA7); CODE(0A9FCH); CODE(RestoreA7); CODE(Return); END ZeroScrap; PROCEDURE xPutScrap(length:LONGINT;theType:LONGINT;source:ADDRESS):LONGINT; (*$P-*) BEGIN CODE(GetRet); CODE(SaveA7); CODE(0A9FEH); CODE(RestoreA7); CODE(Return); END xPutScrap; PROCEDURE PutScrap(length:LONGINT;theType:ResType;source:ADDRESS):LONGINT; (*$P+*)(*$S-*) VAR c:Converter; BEGIN c.r := theType; RETURN(xPutScrap(length,c.l,source)) END PutScrap END ScrapManager. !Funky!Stuff! echo x - Storage.MOD cat >Storage.MOD <<'!Funky!Stuff!' IMPLEMENTATION MODULE Storage; (*$S-*) (* Because the stack checking is turned off in the SYSTEMX.MOD file it is * Turned off here also. *) (* Created for standalone MacIntosh Code By Bob Campbell 10.02.86 * The Implementation now used the A-Line calls to the memory manager * All of the storage allocated is set to zero. The Calls CreateHeap, * and DestroyHeap have been removed. *) FROM SYSTEM IMPORT ADDRESS,CODE,ADR,REGISTER,SETREG; CONST GetRet = 0285FH; (* MOVEA (A7)+,A4 *) Return = 04ED4H; (* JMP A4 *) SaveA7 = 0264FH; (* MOVEA A7,A3 *) RestoreA7 = 02E4BH; (* MOVEA A3,A7 *) noErr = 0; PROCEDURE ALLOCATE (VAR addr : ADDRESS; amount : CARDINAL); (* allocates the requested amount of memory (in bytes) and returns the *) (* starting address . Return NIL if the amount is not available *) (* Note that the memory is cleared by the trap call *) BEGIN SETREG(0,amount); CODE(0A31EH); IF (REGISTER(0) # noErr) THEN addr := NIL ELSE addr := REGISTER(8) END END ALLOCATE; PROCEDURE DEALLOCATE (VAR addr : ADDRESS; amount : CARDINAL); (* deallocates the given amount of memory (in bytes). *) (*$S-*) BEGIN SETREG(8,addr); CODE(0A01FH); END DEALLOCATE; PROCEDURE Available (amount : CARDINAL) : BOOLEAN; (* returns TRUE if an ALLOCATE of the specified amount (in bytes) *) (* of memory would be possible *) BEGIN SETREG(0,amount); CODE(0A040H); RETURN(INTEGER(REGISTER(0)) = 0) END Available; END Storage. !Funky!Stuff! echo x - Streams.MOD cat >Streams.MOD <<'!Funky!Stuff!' IMPLEMENTATION MODULE Streams; (* * Modified from the book "PROGRAMMING IN * MODULA-2" by Miklaus Wirth Edited by * David Gries pages 103 and 104. *) FROM SYSTEM IMPORT ADR,REGISTER,SETREG,CODE,ADDRESS,WORD; FROM MacSYSTEM IMPORT LONGINT,OSErr,noErr; FROM Storage IMPORT ALLOCATE,DEALLOCATE; FROM FileTypes IMPORT OSType,ParamBlkPtr,ParamBlockRec,ParamBlkType,FInfo, fsAtMark,fsFromStart,fsFromMark,fsCurPerm, fsRdPerm,fsWrPerm,fsRdWrPerm, badMDBErr,bdNamErr,dirFulErr,dskFulErr,dupFNErr,eofErr,extFSErr, fBsyErr,fLckdErr,fnfErr,fnOpnErr,fsRnErr,ioErr,mFulErr,nsDrvErr, noMacDskErr,nsvErr,opWrErr,paramErr,permErr,posErr,rfNumErr, tmfoErr,volOffLinErr,volOnLinErr,vLckdErr,wrPermErr,wPrErr; FROM PascalStrings IMPORT MakeModulaString,MakePascalString; CONST OpenTrap = 0A000H; CloseTrap = 0A001H; ReadTrap = 0A002H; WriteTrap = 0A003H; CreateTrap = 0A008H; DeleteTrap = 0A009H; GetFileInfoTrap = 0A00CH; SetFileInfoTrap = 0A00DH; GetEOFTrap = 0A011H; SetEOFTrap = 0A012H; GetFPosTrap = 0A018H; SetFPosTrap = 0A044H; TYPE (* Changing Information About Files *) PROCEDURE GetFInfo(VAR File:ARRAY OF CHAR;vRef:INTEGER;VAR fndr:FInfo); VAR PB:ParamBlockRec; Str:ARRAY[0..255] OF CHAR; BEGIN PB.ioCompletion := ADDRESS(0); MakePascalString(File,Str); PB.ioNamePtr := ADR(Str); PB.ioVRefNum := vRef; PB.ioVersNum := 0C; PB.ioFDirIndex := 0; SETREG(8,ADR(PB)); (* A0 := ADR(PB) *) CODE(GetFileInfoTrap); IF (PB.ioResult = noErr) THEN fndr := PB.ioFlFndrInfo END; END GetFInfo; PROCEDURE SetFInfo(VAR File:ARRAY OF CHAR;vRef:INTEGER;fndrInfo:FInfo); VAR PB:ParamBlockRec; Str:ARRAY[0..255] OF CHAR; BEGIN PB.ioCompletion := ADDRESS(0); MakePascalString(File,Str); PB.ioNamePtr := ADR(Str); PB.ioVRefNum := vRef; PB.ioVersNum := 0C; PB.ioFDirIndex := 0; SETREG(8,ADR(PB)); (* A0 := ADR(PB) *) CODE(GetFileInfoTrap); (* get create/modification times *) PB.ioFlFndrInfo := fndrInfo; SETREG(8,ADR(PB)); (* A0 := ADR(PB) *) CODE(SetFileInfoTrap); END SetFInfo; PROCEDURE Open(VAR File:STREAM; VAR Name:ARRAY OF CHAR;vRef:INTEGER; Mode:OpenMode); VAR Str: POINTER TO ARRAY[0..255] OF CHAR; BEGIN NEW(File); IF (File = NIL) THEN RETURN END; WITH File^ DO IsOpen := FALSE; EOSPos := 0; CurrentPos := 0; ALLOCATE(Str,HIGH(Name) + 2); IF (Str = NIL) THEN DISPOSE(File); File := NIL; RETURN END; ALLOCATE(Buffer,524); IF (Buffer = NIL) THEN DISPOSE(File); DEALLOCATE(Str,HIGH(Name) + 2); File := NIL; RETURN END; PB.ioCompletion := ADDRESS(0); MakePascalString(Name,Str^); PB.ioNamePtr := ADDRESS(Str); PB.ioVRefNum := vRef; PB.ioVersNum := 0C; CASE Mode OF ReadOnly: PB.ioPermssn := fsRdPerm | WriteOnly: PB.ioPermssn := fsWrPerm | ReadWrite: PB.ioPermssn := fsRdWrPerm END; PB.ioMisc := Buffer; SETREG(8,ADR(PB)); (* A0 := ADR(PB) *) CODE(OpenTrap); FileNum := PB.ioRefNum; IF (PB.ioResult = opWrErr) THEN DEALLOCATE(Buffer,524); (* File is already open *) Buffer := NIL; (* using other buffer *) IF Mode = WriteOnly THEN SetEOF(File,0) END; GetEOF(File,EOSPos); CurrentPos := 0; ELSIF NOT(PB.ioResult = noErr) THEN DEALLOCATE(PB.ioMisc,524); DEALLOCATE(Str,HIGH(Name) + 2); DISPOSE(File); File := NIL; ELSE IsOpen := TRUE; IF Mode = WriteOnly THEN SetEOF(File,0) END; GetEOF(File,EOSPos); CurrentPos := 0; END; END (* WITH *) END Open; PROCEDURE Close(File:STREAM); BEGIN WITH File^ DO PB.ioCompletion := ADDRESS(0); PB.ioRefNum := FileNum; SETREG(8,ADR(PB)); (* A0 := ADR(PB) *) CODE(CloseTrap); DEALLOCATE(PB.ioNamePtr,ORD(PB.ioNamePtr^[0])+1); IF (Buffer # NIL) THEN DEALLOCATE(Buffer,524); END; IsOpen := FALSE; END END Close; PROCEDURE Create(VAR Name:ARRAY OF CHAR;vRef:INTEGER; creator,type:OSType); VAR PB:ParamBlockRec; Str:ARRAY[0..255] OF CHAR; f:FInfo; ret : OSErr; BEGIN PB.ioCompletion := ADDRESS(0); MakePascalString(Name,Str); PB.ioNamePtr := ADR(Str); PB.ioVRefNum := vRef; PB.ioFVersNum := 0C; SETREG(8,ADR(PB)); (* A0 := ADR(PB) *) CODE(CreateTrap); GetFInfo(Name,vRef,f); f.fdType := type; f.fdCreator := creator; SetFInfo(Name,vRef,f); END Create; PROCEDURE WriteWord(File:STREAM;w:WORD); BEGIN WITH File^ DO PB.ioReqCount := 2; PB.ioPosMode := 0; PB.ioPosOffset := 0; PB.ioBuffer := ADR(w); SETREG(8,ADR(PB)); (* A0 := ADR(PB) *) CODE(WriteTrap); CurrentPos := PB.ioPosOffset; IF PB.ioResult # noErr THEN EOSPos := 0 ELSE GetEOF(File,EOSPos) END END END WriteWord; PROCEDURE WriteChar(File:STREAM;c:CHAR); BEGIN WITH File^ DO PB.ioReqCount := 1; PB.ioPosMode := 0; PB.ioPosOffset := 0; PB.ioBuffer := ADR(c); SETREG(8,ADR(PB)); (* A0 := ADR(PB) *) CODE(WriteTrap); CurrentPos := PB.ioPosOffset; IF PB.ioResult # noErr THEN EOSPos := 0 ELSE GetEOF(File,EOSPos) END END END WriteChar; PROCEDURE WriteBuffer(File:STREAM;b:ADDRESS;len:LONGINT):LONGINT; BEGIN WITH File^ DO PB.ioReqCount := len; PB.ioPosMode := 0; PB.ioPosOffset := 0; PB.ioBuffer := b; SETREG(8,ADR(PB)); (* A0 := ADR(PB) *) CODE(WriteTrap); CurrentPos := PB.ioPosOffset; IF PB.ioResult # noErr THEN EOSPos := 0; RETURN(0) ELSE GetEOF(File,EOSPos) END; RETURN(PB.ioActCount); END END WriteBuffer; PROCEDURE ReadWord(File:STREAM;VAR w:WORD); BEGIN WITH File^ DO PB.ioReqCount := 2; PB.ioPosMode := 0; PB.ioPosOffset := 0; PB.ioBuffer := ADR(w); SETREG(8,ADR(PB)); (* A0 := ADR(PB) *) CODE(ReadTrap); CurrentPos := PB.ioPosOffset; IF PB.ioResult # noErr THEN w := WORD(0); EOSPos := 0 END END END ReadWord; PROCEDURE ReadChar(File:STREAM;VAR c:CHAR); BEGIN WITH File^ DO PB.ioReqCount := 1; PB.ioPosMode := 0; PB.ioPosOffset := 0; PB.ioBuffer := ADR(c); SETREG(8,ADR(PB)); (* A0 := ADR(PB) *) CODE(ReadTrap); CurrentPos := PB.ioPosOffset; IF PB.ioResult # noErr THEN c := 0C; EOSPos := 0 END END END ReadChar; PROCEDURE ReadBuffer(File:STREAM;buff:ADDRESS;count:LONGINT):LONGINT; VAR BEGIN WITH File^ DO IF (count = 0) THEN RETURN(0) END; PB.ioCompletion := ADDRESS(0); PB.ioRefNum := FileNum; PB.ioReqCount := count; PB.ioPosMode := 0; PB.ioPosOffset := 0; PB.ioBuffer := buff; SETREG(8,ADR(PB)); (* A0 := ADR(PB) *) CODE(ReadTrap); CurrentPos := PB.ioPosOffset; IF PB.ioResult # noErr THEN EOSPos := 0; RETURN(0) ELSE RETURN(PB.ioActCount) END END END ReadBuffer; PROCEDURE EOS(s:STREAM):BOOLEAN; BEGIN RETURN(s^.CurrentPos >= s^.EOSPos); END EOS; PROCEDURE Reset(s:STREAM); BEGIN SetPos(s,0); END Reset; PROCEDURE GetPos(File:STREAM;VAR FilePos:LONGINT); BEGIN WITH File^ DO SETREG(8,ADR(PB)); (* A0 := ADR(PB) *) CODE(GetFPosTrap); FilePos := PB.ioPosOffset; END END GetPos; PROCEDURE SetPos(File:STREAM;posOff:LONGINT); BEGIN WITH File^ DO PB.ioPosMode := fsFromStart; PB.ioPosOffset := posOff; SETREG(8,ADR(PB)); (* A0 := ADR(PB) *) CODE(SetFPosTrap); CurrentPos := PB.ioPosOffset; END END SetPos; PROCEDURE GetEOF(File:STREAM;VAR logEOF:LONGINT); BEGIN WITH File^ DO SETREG(8,ADR(PB)); (* A0 := ADR(PB) *) CODE(GetEOFTrap); logEOF := PB.ioMisc; END END GetEOF; PROCEDURE SetEOF(File:STREAM;logEOF:LONGINT); BEGIN WITH File^ DO PB.ioMisc := ADDRESS(logEOF); SETREG(8,ADR(PB)); (* A0 := ADR(PB) *) CODE(SetEOFTrap); END END SetEOF; END Streams. !Funky!Stuff! # The rest of this file is a shell script which will extract: # SYSTEMX.MOD ScrapManager.MOD Storage.MOD Streams.MOD echo x - SYSTEMX.MOD cat >SYSTEMX.MOD <<'!Funky!Stuff!' IMPLEMENTATION MODULE SYSTEMX; FROM SYSTEM IMPORT ADDRESS,CODE,SETREG,REGISTER,ADR,PROCESS; CONST FADDS = 01000H; FSUBS = 01002H; FMULS = 01004H; FDIVS = 01006H; FCMPS = 01008H; FTINTX = 00016H; FX2S = 01010H; FS2X = 0100EH; FX2L = 02810H; FL2X = 0280EH; (*$P-*) PROCEDURE DoCASE; BEGIN CODE(0205FH); (* MOVEA.L (A7)+,A0 *) CODE(09090H); (* SUB.L (A0),DO *) CODE(0B0A8H);CODE(00004H); (* CMP.L 0004(A0),D0 *) CODE(0620CH); (* BHI $1 {+12} *) CODE(0E380H); (* ASL.L #1,D0 *) CODE(0D0A8H);CODE(00008H); (* ADD.L 0008(A0),D0 *) CODE(0D0F0H);CODE(00800H); (* ADDA.L 00(A0,DO.W),A0 *) CODE(04ED0H); (* JMP (A0) *) (* $1 *) CODE(0D1E8H);CODE(00008H); (* ADDA.L 0008(A0),A0 *) CODE(05988H); (* SUBQ.L #4,A0 *) CODE(04ED0H); (* JMP (A0) *) END DoCASE; PROCEDURE DoHALT; (*$P-*) BEGIN CODE(0A9FFH); (* CALL DEBUGGER *) CODE(04E75H); END DoHALT; PROCEDURE CheckStack; (*$P-*) BEGIN (* STUBED OUT FOR NOW! *) CODE(04E75H); (* RTS *) END CheckStack; PROCEDURE SYSProc20; (*$P-*) BEGIN (* 0000 MOVEQ.L #0007,D0 *) CODE(07007H); DoHALT; END SYSProc20; PROCEDURE NEWPROCESS; (*$P-*) BEGIN CODE(0700AH); (* MOVEQ.L #000A,D0 *) DoHALT; END NEWPROCESS; PROCEDURE TRANSFER; (*$P-*) BEGIN CODE(0700BH); (* MOVEQ.L #000B,DO *) DoHALT; END TRANSFER; PROCEDURE SYSProc21; (*$P-*) BEGIN (* * Procedure Code Proc # 21 * Entry Point 0000, number of bytes = 40 *) (* 0000 MOVE.W #2700,SR *) CODE(046FCH);CODE(02700); (* 0004 MOVE.L A6,-(A7) *) CODE(02F0EH); (* 0006 MOVE.L USP,A6 *) CODE(04E6EH); (* 0008 MOVE.L A5,-(A6) *) CODE(02D0DH); (* 000A LEA A6,FFCC(A6) *) CODE(04DEEH); CODE(0FFCCH); (* 000E MOVE.L (A7)+,-(A6) *) CODE(02D1FH); (* 0010 MOVE.W (A7)+,-(A6) *) CODE(03D1FH); (* 0012 MOVE.L (A7)+,-(A6) *) CODE(02D1FH); (* 0014 MOVE.L A6,(A0) *) CODE(0208EH); (* 0016 MOVEA.L (A1),A6 *) CODE(02C51H); (* 0018 MOVE.L (A6)+,-(A7) *) CODE(02F1EH); (* 001A MOVE.W (A6)+,-(A7) *) CODE(03F1EH); (* 001C MOVE.L (A6)+,-(A7) *) CODE(02F1EH); (* 001E MOVEM.L D0-A5,(A6)+ *) CODE(04CDEH); CODE(03FFFH); (* 0022 MOVE.L A6,USP *) CODE(04E66H); (* 0024 MOVEA.L (A7)+,A6 *) CODE(02C5FH); (* 0026 RTE *) CODE(04E73H); END SYSProc21; PROCEDURE IOTRANSFER(p1,p2:PROCESS; via:ADDRESS); (*$P-*) BEGIN CODE(0700CH); (* MOVEQ.L #000C,DO *) DoHALT; END IOTRANSFER; PROCEDURE SYSProc7; (* IF D0 = 2 THEN LISTEN ELSIF D0 = 3 THEN SYSRESET END *) (*$P-*) BEGIN CODE(0700DH); DoHALT; END SYSProc7; PROCEDURE SYSLongMult; (*$P-*) BEGIN CODE(04E56H);CODE(00000H); (* LINK A6,#0000 *) CODE(048E7H);CODE(07C00H); (* MOVEM.L D5-D1,-(A7) *) CODE(0222EH);CODE(00008H); (* MOVE.L 0008(A6),D1 *) CODE(0242EH);CODE(0000CH); (* MOVE.L 000C(A6),D2 *) CODE(02601H); (* MOVE.L D1,D3 *) CODE(02801H); (* MOVE.L D1,D4 *) CODE(02A02H); (* MOVE.L D2,D5 *) CODE(04844H); (* SWAP D4 *) CODE(04845H); (* SWAP D5 *) CODE(0C2C2H); (* MULU.W D2,D1 *) CODE(0C4C4H); (* MULU.W D4,D2 *) CODE(0C6C5H); (* MULU.W D5,D3 *) CODE(0C8C5H); (* MULU.W D5,D4 *) CODE(04841H); (* SWAP D1 *) CODE(0D242H); (* ADD.W D2,D1 *) CODE(04285H); (* CLR.L D5 *) CODE(0D985H); (* ADDX.L D5,D4 *) CODE(0D243H); (* ADD.W D3,D1 *) CODE(0D985H); (* ADDX.L D5,D4 *) CODE(04841H); (* SWAP D1 *) CODE(04242H); (* CLR.W D2 *) CODE(04243H); (* CLR.W D3 *) CODE(04842H); (* SWAP D2 *) CODE(04843H); (* SWAP D3 *) CODE(0D483H); (* ADD.L D3,D2 *) CODE(0D484H); (* ADD.L D4,D2 *) CODE(02D41H);CODE(0000CH); (* MOVE.L D1,000C(A6) *) CODE(04CDFH);CODE(00008H); (* MOVE.L D2,0008(A6) *) CODE(04E5EH); (* UNLK A6 *) CODE(04E75H); (* RTS *) END SYSLongMult; PROCEDURE SYSLongDivMod; (*$P-*) BEGIN CODE(04E56H);CODE(00000H); (* LINK A6,#0000 *) CODE(048E7H);CODE(07800H); (* MOVEM.L D4-D1,-(A7) *) CODE(0222EH);CODE(0000CH); (* MOVE.L 000C(A6),D1 *) CODE(0242EH);CODE(00008H); (* MOVE.L 0008(A6),D2 *) CODE(0B4BCH);CODE(00000H); CODE(0FFFFH); (* CMP.L #0000FFFF,D2 *) CODE(0621EH); (* BHI $1 {+30} *) CODE(04243H); (* CLR.W D3 *) CODE(082C2H); (* DIVU.W D2,D1 *) CODE(0680EH); (* BVC $2 {+14} *) CODE(03801H); (* MOVE.W D1,D4 *) CODE(04241H); (* CLR.W D1 *) CODE(04841H); (* SWAP D1 *) CODE(082C2H); (* DIVU.W D2,D1 *) CODE(03601H); (* MOVE.W D1,D3 *) CODE(03204H); (* MOVE.W D4,D1 *) CODE(082C2H); (* DIVU.W D2,D1 *) (* $2: *) CODE(04843H); (* SWAP D3 *) CODE(03601H); (* MOVE.W D1,D3 *) CODE(04241H); (* CLR.W D1 *) CODE(04841H); (* SWAP D1 *) CODE(0601EH); (* BRA $3 {+30} *) (* $1: *) CODE(04283H); (* CLR.L D3 *) CODE(03601H); (* MOVE.W D1,D3 *) CODE(04843H); (* SWAP D3 *) CODE(04241H); (* CLR.W D1 *) CODE(04841H); (* SWAP D1 *) CODE(0383CH);CODE(0000FH); (* MOVE.W #000F,D4 *) (* $5: *) CODE(0E38BH); (* LSL.L #1,D3 *) CODE(0E391H); (* ROXL.L #1,D1 *) CODE(0B282H); (* CMP.L D2,D1 *) CODE(06504H); (* BCS $4 {+4} *) CODE(09282H); (* SUB.L D2,D1 *) CODE(05243H); (* ADDQ.W #1,D3 *) (* $4: *) CODE(051CCH);CODE(0FFF2H); (* DBF D4,$5 {-14} *) (* $3: *) CODE(02D43H);CODE(0000CH); (* MOVE.L D3,000C(A6) *) CODE(02D41H);CODE(00008H); (* MOVE.L D1,0008(A6) *) CODE(04CDFH);CODE(0001EH); (* MOVEM.L D1-D4,(A7)+ *) CODE(04E5EH); (* UNLK A6 *) CODE(04E75H); (* RTS *) END SYSLongDivMod; PROCEDURE SYSLongIntMult; (*$P-*) BEGIN (* Procedure Code Proc # 10 *) (* Entry Point 0000, number of bytes = 92 *) (* 0000 LINK A6,#0000 *) CODE(04E56H); CODE(00000H); (* 0004 MOVEM.L D7-D1,-(A7) *) CODE(048E7H); CODE(07F00H); (* 0008 MOVE.L 0008(A6),D1 *) CODE(0222EH); CODE(00008H); (* 000C MOVE.L 000C(A6),D2 *) CODE(0242EH); CODE(0000CH); (* 0010 MOVE.L D1,D3 *) CODE(02601H); (* 0012 MOVE.L D1,D4 *) CODE(02801H); (* 0014 MOVE.L D2,D5 *) CODE(02A02H); (* 0016 MOVE.L D1,D6 *) CODE(02C01H); (* 0018 CLR.L D7 *) CODE(04287H); (* 001A SWAP D4 *) CODE(04844H); (* 001C SWAP D5 *) CODE(04845H); (* 001E MULU.W D2,D1 *) CODE(0C2C2H); (* 0020 MULU.W D4,D2 *) CODE(0C4C4H); (* 0022 MULU.W D5,D3 *) CODE(0C6C5H); (* 0024 MULU.W D5,D4 *) CODE(0C8C5H); (* 0026 SWAP D1 *) CODE(04841H); (* 0028 ADD.W D2,D1 *) CODE(0D987H); (* 002A ADDX.L D7,D4 *) CODE(0D987H); (* 002C ADD.W D3,D1 *) CODE(0D243H); (* 002E ADDX.L D7,D4 *) CODE(0D987H); (* 0030 SWAP D1 *) CODE(04841H); (* 0032 CLR.W D2 *) CODE(04242H); (* 0034 CLR.W D3 *) CODE(04243H); (* 0036 SWAP D2 *) CODE(04842H); (* 0038 SWAP D3 *) CODE(04843H); (* 003A ADD.L D3,D2 *) CODE(0D483H); (* 003C ADD.L D4,D2 *) CODE(0D484H); (* 003E SWAP D5 *) CODE(04845H); (* 0040 TST.L D6 *) CODE(04A86H); (* 0042 BPI 2 {0046} *) CODE(06A02H); (* 0044 SUB.L D5,D2 *) CODE(09485H); (* 0046 TST.L D5 *) CODE(04A85H); (* 0048 BPI 2 {004C} *) CODE(06A02H); (* 004A SUB.L D6,D2 *) CODE(09486H); (* 004C MOVE.L D1,000C(A6) *) CODE(02D41H); CODE(0000CH); (* 0050 MOVE.L D2,0008(A6) *) CODE(02D42H); CODE(00008H); (* 0054 MOVEM.L D1-D7,(A7)+ *) CODE(04CDFH); CODE(000FEH); (* 0058 UNLK A6 *) CODE(04E5EH); (* 005A RTS *) CODE(04E75H); END SYSLongIntMult; PROCEDURE SYSProc11; (*$P-*) BEGIN (*Procedure Code Proc # 11 *) (* Entry Point 0000, number of bytes = 16*) (* 0000 LINK A6,#0000 *) CODE(04E56H); CODE(00000H); (* 0004 MOVEQ.L #0008,D0 *) CODE(07008H); DoHALT; (* 000C UNLK A6 *) CODE(04E5EH); (* 000E RTS *) CODE(04E75H); END SYSProc11; PROCEDURE SYSRealAdd; (*$P-*) BEGIN (* LEA -12(SP),SP ;TMP *) CODE(04FEFH);CODE(0FFF4H); (* PEA 20(SP) ;DEST *) CODE(0486FH);CODE(20); (* PEA 4(SP) ;ADR(TMP) *) CODE(0486FH);CODE(4); (* MOVE #FS2X,-(SP) *) CODE(03F3CH);CODE(FS2X); (* _FP68K ; A9EB *) CODE(0A9EBH); (* PEA 16(SP) ;SRC *) CODE(0486FH);CODE(16); (* PEA 4(SP) ;ADR(TMP) *) CODE(0486FH);CODE(4); (* MOVE #FADDS,-(SP) *) CODE(03F3CH);CODE(FADDS); (* _FP68K ; A9EB *) CODE(0A9EBH); (* PEA (SP) ;TMP *) CODE(04857H); (* PEA 24(SP) ;DEST *) CODE(0486FH);CODE(24); (* MOVE #FX2S,-(SP) *) CODE(03F3CH);CODE(FX2S); (* _FP68K ; A9EB *) CODE(0A9EBH); (* LEA 12(SP),SP *) CODE(04FEFH);CODE(12); (* RTS *) CODE(04E75H); END SYSRealAdd; PROCEDURE SYSRealSub; (*$P-*) BEGIN (* LEA -12(SP),SP ;TMP *) CODE(04FEFH);CODE(0FFF4H); (* PEA 20(SP) ;DEST *) CODE(0486FH);CODE(20); (* PEA 4(SP) ;ADR(TMP) *) CODE(0486FH);CODE(4); (* MOVE #FS2X,-(SP) *) CODE(03F3CH);CODE(FS2X); (* _FP68K ; A9EB *) CODE(0A9EBH); (* PEA 16(SP) ;SRC *) CODE(0486FH);CODE(16); (* PEA 4(SP) ;ADR(TMP) *) CODE(0486FH);CODE(4); (* MOVE #FSUBS,-(SP) *) CODE(03F3CH);CODE(FSUBS); (* _FP68K ; A9EB *) CODE(0A9EBH); (* PEA (SP) ;TMP *) CODE(04857H); (* PEA 24(SP) ;DEST *) CODE(0486FH);CODE(24); (* MOVE #FX2S,-(SP) *) CODE(03F3CH);CODE(FX2S); (* _FP68K ; A9EB *) CODE(0A9EBH); (* LEA 12(SP),SP *) CODE(04FEFH);CODE(12); (* RTS *) CODE(04E75H); END SYSRealSub; PROCEDURE SYSRealMult; (*$P-*) BEGIN (* LEA -12(SP),SP ;TMP *) CODE(04FEFH);CODE(0FFF4H); (* PEA 20(SP) ;DEST *) CODE(0486FH);CODE(20); (* PEA 4(SP) ;ADR(TMP) *) CODE(0486FH);CODE(4); (* MOVE #FS2X,-(SP) *) CODE(03F3CH);CODE(FS2X); (* _FP68K ; A9EB *) CODE(0A9EBH); (* PEA 16(SP) ;SRC *) CODE(0486FH);CODE(16); (* PEA 4(SP) ;ADR(TMP) *) CODE(0486FH);CODE(4); (* MOVE #FMULS,-(SP) *) CODE(03F3CH);CODE(FMULS); (* _FP68K ; A9EB *) CODE(0A9EBH); (* PEA (SP) ;TMP *) CODE(04857H); (* PEA 24(SP) ;DEST *) CODE(0486FH);CODE(24); (* MOVE #FX2S,-(SP) *) CODE(03F3CH);CODE(FX2S); (* _FP68K ; A9EB *) CODE(0A9EBH); (* LEA 12(SP),SP *) CODE(04FEFH);CODE(12); (* RTS *) CODE(04E75H); END SYSRealMult; PROCEDURE SYSRealDiv; (*$P-*) BEGIN (* DEST := DEST / SRC *) (* LEA -12(SP),SP ;TMP *) CODE(04FEFH);CODE(0FFF4H); (* PEA 20(SP) ;DEST *) CODE(0486FH);CODE(20); (* PEA 4(SP) ;ADR(TMP) *) CODE(0486FH);CODE(4); (* MOVE #FS2X,-(SP) *) CODE(03F3CH);CODE(FS2X); (* _FP68K ; A9EB *) CODE(0A9EBH); (* PEA 16(SP) ;SRC *) CODE(0486FH);CODE(16); (* PEA 4(SP) ;ADR(TMP) *) CODE(0486FH);CODE(4); (* MOVE #FDIVS,-(SP) *) CODE(03F3CH);CODE(FDIVS); (* _FP68K ; A9EB *) CODE(0A9EBH); (* PEA (SP) ;TMP *) CODE(04857H); (* PEA 24(SP) ;DEST *) CODE(0486FH);CODE(24); (* MOVE #FX2S *) CODE(03F3CH);CODE(FX2S); (* _FP68K ; A9EB *) CODE(0A9EBH); (* LEA 12(SP),SP *) CODE(04FEFH);CODE(12); (* RTS *) CODE(04E75H); END SYSRealDiv; PROCEDURE SYSRealCMP; (*Procedure Code Proc # 16 *) (* Entry Point 0000, number of bytes = 66 *) (*$P-*) BEGIN (* LEA -12(SP),SP ;TMP *) CODE(04FEFH);CODE(0FFF4H); (* PEA 20(SP) ;SRC *) CODE(0486FH);CODE(20); (* PEA 4(SP) ;ADR(TMP) *) CODE(0486FH);CODE(4); (* MOVE #FS2X,-(SP) *) CODE(03F3CH);CODE(FS2X); (* _FP68K ; A9EB *) CODE(0A9EBH); (* PEA 16(SP) ;DEST *) CODE(0486FH);CODE(16); (* PEA 4(SP) ;ADR(TMP) *) CODE(0486FH);CODE(4); (* MOVE #FCMPS,-(SP) *) CODE(03F3CH);CODE(FCMPS); (* _FP68K ; A9EB *) CODE(0A9EBH); (* LEA 12(SP),SP *) CODE(04FEFH);CODE(12); (* RTS *) CODE(04E75H); END SYSRealCMP; PROCEDURE SYSRealTST; (*$P-*) BEGIN (* CLR.L -(SP) *) CODE(042A7H); (* LEA -12(SP),SP ;TMP *) CODE(04FEFH);CODE(0FFF4H); (* PEA 12(SP) ;SRC *) CODE(0486FH);CODE(12); (* PEA 4(SP) ;ADR(TMP) *) CODE(0486FH);CODE(4); (* MOVE #FS2X,-(SP) *) CODE(03F3CH);CODE(FS2X); (* _FP68K ; A9EB *) CODE(0A9EBH); (* PEA 20(SP) ;DEST *) CODE(0486FH);CODE(20); (* PEA 4(SP) ;ADR(TMP) *) CODE(0486FH);CODE(4); (* MOVE #FCMPS,-(SP) *) CODE(03F3CH);CODE(FCMPS); (* _FP68K ; A9EB *) CODE(0A9EBH); (* LEA 16(SP),SP *) CODE(04FEFH);CODE(16); (* RTS *) CODE(04E75H); END SYSRealTST; PROCEDURE SYSRealFLOAT; (*$P-*) BEGIN (* LEA -12(SP),SP ;TMP *) CODE(04FEFH);CODE(0FFF4H); (* PEA 16(SP) ;SRC *) CODE(0486FH);CODE(16); (* PEA 4(SP) ;ADR(TMP) *) CODE(0486FH);CODE(4); (* MOVE #FL2X,-(SP) *) CODE(03F3CH);CODE(FL2X); (* _FP68K ; A9EB *) CODE(0A9EBH); (* PEA (SP) ;TMP *) CODE(04857H); (* PEA 20(SP) ;RETURN *) CODE(0486FH);CODE(20); (* MOVE #FX2S *) CODE(03F3CH);CODE(FX2S); (* _FP68K ; A9EB *) CODE(0A9EBH); (* LEA 12(SP),SP *) CODE(04FEFH);CODE(12); (* RTS *) CODE(04E75H); END SYSRealFLOAT; PROCEDURE SYSRealTRUNC; (*$P-*) BEGIN (* LEA -12(SP),SP ;TMP *) CODE(04FEFH);CODE(0FFF4H); (* PEA 16(SP) ;SRC *) CODE(0486FH);CODE(16); (* PEA 4(SP) ;ADR(TMP) *) CODE(0486FH);CODE(4); (* MOVE #FS2X,-(SP) *) CODE(03F3CH);CODE(FS2X); (* _FP68K ; A9EB *) CODE(0A9EBH); (* PEA (SP) ;TMP *) CODE(04857H); (* MOVE #FTINTX,-(SP) *) CODE(03F3CH);CODE(FTINTX); (* _FP68K ; A9EB *) CODE(0A9EBH); (* PEA (SP) ;TMP *) CODE(04857H); (* PEA 20(SP) ;RETURN *) CODE(0486FH);CODE(20); (* MOVE #FX2L,-(SP) *) CODE(03F3CH);CODE(FX2L); (* _FP68K ; A9EB *) CODE(0A9EBH); (* LEA 12(SP),SP *) CODE(04FEFH);CODE(12); (* RTS *) CODE(04E75H); END SYSRealTRUNC; (*$P-*) END SYSTEMX. !Funky!Stuff! echo x - ScrapManager.MOD cat >ScrapManager.MOD <<'!Funky!Stuff!' IMPLEMENTATION MODULE ScrapManager; FROM SYSTEM IMPORT ADDRESS,CODE,ADR; FROM MacSYSTEM IMPORT LONGINT,Handle; FROM QuickDraw IMPORT Str255; FROM ResourceManager IMPORT ResType; CONST GetRet = 0285FH; (* MOVEA (A7)+,A4 *) Return = 04ED4H; (* JMP A4 *) SaveA7 = 0264FH; (* MOVEA A7,A3 *) RestoreA7 = 02E4BH; (* MOVEA A3,A7 *) PROCEDURE InfoScrap():PScrapStuff; (*$P+*)(*$S-*) BEGIN RETURN(PScrapStuff(0960H)) END InfoScrap; PROCEDURE UnloadScrap():LONGINT; (*$P-*) BEGIN CODE(GetRet); CODE(SaveA7); CODE(0A9FAH); CODE(RestoreA7); CODE(Return); END UnloadScrap; PROCEDURE LoadScrap():LONGINT; (*$P-*) BEGIN CODE(GetRet); CODE(SaveA7); CODE(0A9FBH); CODE(RestoreA7); CODE(Return); END LoadScrap; PROCEDURE xGetScrap(hDest:Handle;theType:LONGINT;VAR offset:LONGINT):LONGINT; (*$P-*) BEGIN CODE(GetRet); CODE(SaveA7); CODE(0A9FDH); CODE(RestoreA7); CODE(Return); END xGetScrap; TYPE Converter = RECORD CASE INTEGER OF 0: r:ResType; | 1: l:LONGINT END END; PROCEDURE GetScrap(hDest:Handle;theType:ResType;VAR offset:LONGINT):LONGINT; (*$P+*)(*$S-*) VAR c:Converter; BEGIN c.r := theType; RETURN(xGetScrap(hDest,c.l,offset)); END GetScrap; PROCEDURE ZeroScrap():LONGINT; (*$P-*) BEGIN CODE(GetRet); CODE(SaveA7); CODE(0A9FCH); CODE(RestoreA7); CODE(Return); END ZeroScrap; PROCEDURE xPutScrap(length:LONGINT;theType:LONGINT;source:ADDRESS):LONGINT; (*$P-*) BEGIN CODE(GetRet); CODE(SaveA7); CODE(0A9FEH); CODE(RestoreA7); CODE(Return); END xPutScrap; PROCEDURE PutScrap(length:LONGINT;theType:ResType;source:ADDRESS):LONGINT; (*$P+*)(*$S-*) VAR c:Converter; BEGIN c.r := theType; RETURN(xPutScrap(length,c.l,source)) END PutScrap END ScrapManager. !Funky!Stuff! echo x - Storage.MOD cat >Storage.MOD <<'!Funky!Stuff!' IMPLEMENTATION MODULE Storage; (*$S-*) (* Because the stack checking is turned off in the SYSTEMX.MOD file it is * Turned off here also. *) (* Created for standalone MacIntosh Code By Bob Campbell 10.02.86 * The Implementation now used the A-Line calls to the memory manager * All of the storage allocated is set to zero. The Calls CreateHeap, * and DestroyHeap have been removed. *) FROM SYSTEM IMPORT ADDRESS,CODE,ADR,REGISTER,SETREG; CONST GetRet = 0285FH; (* MOVEA (A7)+,A4 *) Return = 04ED4H; (* JMP A4 *) SaveA7 = 0264FH; (* MOVEA A7,A3 *) RestoreA7 = 02E4BH; (* MOVEA A3,A7 *) noErr = 0; PROCEDURE ALLOCATE (VAR addr : ADDRESS; amount : CARDINAL); (* allocates the requested amount of memory (in bytes) and returns the *) (* starting address . Return NIL if the amount is not available *) (* Note that the memory is cleared by the trap call *) VAR zero:ADDRESS; BEGIN CODE(04280H); (* CLR D0 *) SETREG(0,amount); CODE(0A31EH); IF (REGISTER(0) # noErr) THEN addr := NIL ELSE addr := REGISTER(8) END END ALLOCATE; PROCEDURE DEALLOCATE (VAR addr : ADDRESS; amount : CARDINAL); (* deallocates the given amount of memory (in bytes). *) (*$S-*) BEGIN SETREG(8,addr); CODE(0A01FH); END DEALLOCATE; PROCEDURE Available (amount : CARDINAL) : BOOLEAN; (* returns TRUE if an ALLOCATE of the specified amount (in bytes) *) (* of memory would be possible *) BEGIN CODE(04280H); (* CLR D0 *) SETREG(0,amount); CODE(0A040H); RETURN(INTEGER(REGISTER(0)) = 0) END Available; END Storage. !Funky!Stuff! echo x - Streams.MOD cat >Streams.MOD <<'!Funky!Stuff!' IMPLEMENTATION MODULE Streams; (* * Modified from the book "PROGRAMMING IN * MODULA-2" by Miklaus Wirth Edited by * David Gries pages 103 and 104. *) FROM SYSTEM IMPORT ADR,REGISTER,SETREG,CODE,ADDRESS,WORD; FROM MacSYSTEM IMPORT LONGINT,OSErr,noErr; FROM Storage IMPORT ALLOCATE,DEALLOCATE; FROM FileTypes IMPORT OSType,ParamBlkPtr,ParamBlockRec,ParamBlkType,FInfo, fsAtMark,fsFromStart,fsFromMark,fsCurPerm, fsRdPerm,fsWrPerm,fsRdWrPerm, badMDBErr,bdNamErr,dirFulErr,dskFulErr,dupFNErr,eofErr,extFSErr, fBsyErr,fLckdErr,fnfErr,fnOpnErr,fsRnErr,ioErr,mFulErr,nsDrvErr, noMacDskErr,nsvErr,opWrErr,paramErr,permErr,posErr,rfNumErr, tmfoErr,volOffLinErr,volOnLinErr,vLckdErr,wrPermErr,wPrErr; FROM PascalStrings IMPORT MakeModulaString,MakePascalString; CONST OpenTrap = 0A000H; CloseTrap = 0A001H; ReadTrap = 0A002H; WriteTrap = 0A003H; CreateTrap = 0A008H; DeleteTrap = 0A009H; GetFileInfoTrap = 0A00CH; SetFileInfoTrap = 0A00DH; GetEOFTrap = 0A011H; SetEOFTrap = 0A012H; GetFPosTrap = 0A018H; SetFPosTrap = 0A044H; TYPE (* Changing Information About Files *) PROCEDURE GetFInfo(VAR File:ARRAY OF CHAR;vRef:INTEGER;VAR fndr:FInfo); VAR PB:ParamBlockRec; Str:ARRAY[0..255] OF CHAR; BEGIN PB.ioCompletion := ADDRESS(0); MakePascalString(File,Str); PB.ioNamePtr := ADR(Str); PB.ioVRefNum := vRef; PB.ioVersNum := 0C; PB.ioFDirIndex := 0; SETREG(8,ADR(PB)); (* A0 := ADR(PB) *) CODE(GetFileInfoTrap); IF (PB.ioResult = noErr) THEN fndr := PB.ioFlFndrInfo END; END GetFInfo; PROCEDURE SetFInfo(VAR File:ARRAY OF CHAR;vRef:INTEGER;fndrInfo:FInfo); VAR PB:ParamBlockRec; Str:ARRAY[0..255] OF CHAR; BEGIN PB.ioCompletion := ADDRESS(0); MakePascalString(File,Str); PB.ioNamePtr := ADR(Str); PB.ioVRefNum := vRef; PB.ioVersNum := 0C; PB.ioFDirIndex := 0; SETREG(8,ADR(PB)); (* A0 := ADR(PB) *) CODE(GetFileInfoTrap); (* get create/modification times *) PB.ioFlFndrInfo := fndrInfo; SETREG(8,ADR(PB)); (* A0 := ADR(PB) *) CODE(SetFileInfoTrap); END SetFInfo; PROCEDURE Open(VAR File:STREAM; VAR Name:ARRAY OF CHAR;vRef:INTEGER; Mode:OpenMode); VAR Str: POINTER TO ARRAY[0..255] OF CHAR; BEGIN NEW(File); IF (File = NIL) THEN RETURN END; WITH File^ DO IsOpen := FALSE; EOSPos := 0; CurrentPos := 0; ALLOCATE(Str,HIGH(Name) + 2); IF (Str = NIL) THEN DISPOSE(File); File := NIL; RETURN END; ALLOCATE(Buffer,524); IF (Buffer = NIL) THEN DISPOSE(File); DEALLOCATE(Str,HIGH(Name) + 2); File := NIL; RETURN END; PB.ioCompletion := ADDRESS(0); MakePascalString(Name,Str^); PB.ioNamePtr := ADDRESS(Str); PB.ioVRefNum := vRef; PB.ioVersNum := 0C; CASE Mode OF ReadOnly: PB.ioPermssn := fsRdPerm | WriteOnly: PB.ioPermssn := fsWrPerm | ReadWrite: PB.ioPermssn := fsRdWrPerm END; PB.ioMisc := Buffer; SETREG(8,ADR(PB)); (* A0 := ADR(PB) *) CODE(OpenTrap); FileNum := PB.ioRefNum; IF (PB.ioResult = opWrErr) THEN DEALLOCATE(Buffer,524); (* File is already open *) Buffer := NIL; (* using other buffer *) IF Mode = WriteOnly THEN SetEOF(File,0) END; GetEOF(File,EOSPos); CurrentPos := 0; ELSIF NOT(PB.ioResult = noErr) THEN DEALLOCATE(PB.ioMisc,524); DEALLOCATE(Str,HIGH(Name) + 2); DISPOSE(File); File := NIL; ELSE IsOpen := TRUE; IF Mode = WriteOnly THEN SetEOF(File,0) END; GetEOF(File,EOSPos); CurrentPos := 0; END; END (* WITH *) END Open; PROCEDURE Close(File:STREAM); BEGIN WITH File^ DO PB.ioCompletion := ADDRESS(0); PB.ioRefNum := FileNum; SETREG(8,ADR(PB)); (* A0 := ADR(PB) *) CODE(CloseTrap); DEALLOCATE(PB.ioNamePtr,ORD(PB.ioNamePtr^[0])+1); IF (Buffer # NIL) THEN DEALLOCATE(Buffer,524); END; IsOpen := FALSE; END END Close; PROCEDURE Create(VAR Name:ARRAY OF CHAR;vRef:INTEGER; creator,type:OSType); VAR PB:ParamBlockRec; Str:ARRAY[0..255] OF CHAR; f:FInfo; ret : OSErr; BEGIN PB.ioCompletion := ADDRESS(0); MakePascalString(Name,Str); PB.ioNamePtr := ADR(Str); PB.ioVRefNum := vRef; PB.ioFVersNum := 0C; SETREG(8,ADR(PB)); (* A0 := ADR(PB) *) CODE(CreateTrap); GetFInfo(Name,vRef,f); f.fdType := type; f.fdCreator := creator; SetFInfo(Name,vRef,f); END Create; PROCEDURE WriteWord(File:STREAM;w:WORD); BEGIN WITH File^ DO PB.ioReqCount := 2; PB.ioPosMode := 0; PB.ioPosOffset := 0; PB.ioBuffer := ADR(w); SETREG(8,ADR(PB)); (* A0 := ADR(PB) *) CODE(WriteTrap); CurrentPos := PB.ioPosOffset; IF PB.ioResult # noErr THEN EOSPos := 0 ELSE GetEOF(File,EOSPos) END END END WriteWord; PROCEDURE WriteChar(File:STREAM;c:CHAR); BEGIN WITH File^ DO PB.ioReqCount := 1; PB.ioPosMode := 0; PB.ioPosOffset := 0; PB.ioBuffer := ADR(c); SETREG(8,ADR(PB)); (* A0 := ADR(PB) *) CODE(WriteTrap); CurrentPos := PB.ioPosOffset; IF PB.ioResult # noErr THEN EOSPos := 0 ELSE GetEOF(File,EOSPos) END END END WriteChar; PROCEDURE WriteBuffer(File:STREAM;b:ADDRESS;len:LONGINT):LONGINT; BEGIN WITH File^ DO PB.ioReqCount := len; PB.ioPosMode := 0; PB.ioPosOffset := 0; PB.ioBuffer := b; SETREG(8,ADR(PB)); (* A0 := ADR(PB) *) CODE(WriteTrap); CurrentPos := PB.ioPosOffset; IF PB.ioResult # noErr THEN EOSPos := 0; RETURN(0) ELSE GetEOF(File,EOSPos) END; RETURN(PB.ioActCount); END END WriteBuffer; PROCEDURE ReadWord(File:STREAM;VAR w:WORD); BEGIN WITH File^ DO PB.ioReqCount := 2; PB.ioPosMode := 0; PB.ioPosOffset := 0; PB.ioBuffer := ADR(w); SETREG(8,ADR(PB)); (* A0 := ADR(PB) *) CODE(ReadTrap); CurrentPos := PB.ioPosOffset; IF PB.ioResult # noErr THEN w := WORD(0); EOSPos := 0 END END END ReadWord; PROCEDURE ReadChar(File:STREAM;VAR c:CHAR); BEGIN WITH File^ DO PB.ioReqCount := 1; PB.ioPosMode := 0; PB.ioPosOffset := 0; PB.ioBuffer := ADR(c); SETREG(8,ADR(PB)); (* A0 := ADR(PB) *) CODE(ReadTrap); CurrentPos := PB.ioPosOffset; IF PB.ioResult # noErr THEN c := 0C; EOSPos := 0 END END END ReadChar; PROCEDURE ReadBuffer(File:STREAM;buff:ADDRESS;count:LONGINT):LONGINT; VAR BEGIN WITH File^ DO IF (count = 0) THEN RETURN(0) END; PB.ioCompletion := ADDRESS(0); PB.ioRefNum := FileNum; PB.ioReqCount := count; PB.ioPosMode := 0; PB.ioPosOffset := 0; PB.ioBuffer := buff; SETREG(8,ADR(PB)); (* A0 := ADR(PB) *) CODE(ReadTrap); CurrentPos := PB.ioPosOffset; IF PB.ioResult # noErr THEN EOSPos := 0; RETURN(0) ELSE RETURN(PB.ioActCount) END END END ReadBuffer; PROCEDURE EOS(s:STREAM):BOOLEAN; BEGIN RETURN(s^.CurrentPos >= s^.EOSPos); END EOS; PROCEDURE Reset(s:STREAM); BEGIN SetPos(s,0); END Reset; PROCEDURE GetPos(File:STREAM;VAR FilePos:LONGINT); BEGIN WITH File^ DO SETREG(8,ADR(PB)); (* A0 := ADR(PB) *) CODE(GetFPosTrap); FilePos := PB.ioPosOffset; END END GetPos; PROCEDURE SetPos(File:STREAM;posOff:LONGINT); BEGIN WITH File^ DO PB.ioPosMode := fsFromStart; PB.ioPosOffset := posOff; SETREG(8,ADR(PB)); (* A0 := ADR(PB) *) CODE(SetFPosTrap); CurrentPos := PB.ioPosOffset; END END SetPos; PROCEDURE GetEOF(File:STREAM;VAR logEOF:LONGINT); BEGIN WITH File^ DO SETREG(8,ADR(PB)); (* A0 := ADR(PB) *) CODE(GetEOFTrap); logEOF := PB.ioMisc; END END GetEOF; PROCEDURE SetEOF(File:STREAM;logEOF:LONGINT); BEGIN WITH File^ DO PB.ioMisc := ADDRESS(logEOF); SETREG(8,ADR(PB)); (* A0 := ADR(PB) *) CODE(SetEOFTrap); END END SetEOF; END Streams. !Funky!Stuff!