From c4ecb61d8bcc021810193d4a31931cbd1fb80019 Mon Sep 17 00:00:00 2001 From: gdr-ftp Date: Tue, 3 Feb 1998 07:54:12 +0000 Subject: [PATCH] Initial checkin of SIM sources. This includes both simlib and SIM, itself. --- sys/sim/Makefile | 17 +++++ sys/sim/rom3 | 84 ++++++++++++++++++++++ sys/sim/sim.asm | 1 + sys/sim/sim.doc | 104 +++++++++++++++++++++++++++ sys/sim/sim.h | 1 + sys/sim/sim.mac | 152 +++++++++++++++++++++++++++++++++++++++ sys/sim/simequates.equ | 1 + sys/sim/simlib.asm | 1 + sys/sim/simlib.mac | 158 +++++++++++++++++++++++++++++++++++++++++ sys/sim/test.c | 1 + 10 files changed, 520 insertions(+) create mode 100644 sys/sim/Makefile create mode 100644 sys/sim/rom3 create mode 100644 sys/sim/sim.asm create mode 100644 sys/sim/sim.doc create mode 100644 sys/sim/sim.h create mode 100644 sys/sim/sim.mac create mode 100644 sys/sim/simequates.equ create mode 100644 sys/sim/simlib.asm create mode 100644 sys/sim/simlib.mac create mode 100644 sys/sim/test.c diff --git a/sys/sim/Makefile b/sys/sim/Makefile new file mode 100644 index 0000000..e82c3c0 --- /dev/null +++ b/sys/sim/Makefile @@ -0,0 +1,17 @@ +sim.root: sim.asm sim.mac simequates.equ + compile sim.asm keep=sim + +sim: sim.root + link sim keep=sim + chtyp -t \$B6 sim + +simlib.root: simlib.asm simlib.mac simequates.equ + compile simlib.asm keep=simlib + +libsim: simlib.root + rm -f libsim + makelib libsim +simlib.root +simlib.a + +test: test.c libsim + compile test.c keep=test + link test libsim keep=test diff --git a/sys/sim/rom3 b/sys/sim/rom3 new file mode 100644 index 0000000..47acd9c --- /dev/null +++ b/sys/sim/rom3 @@ -0,0 +1,84 @@ +Joe, + +This is a primitive disassembly of the ROM 03 interrupt handler +firmware. You need to fix this up to look like the ROM 01 version +I have in SIM.ASM. + +MasterIntHandler clc (E1/0010 JMPs here, FF/BC6C) + xce + LONG I,M + php + phb + Assume B=00E1 + pea $E1E1 + plb + sta |ASave ($108) + lda SHADOW shadow register + sta |ShadSave ($119) + ora #$8000 + and #$9F3E + sta SHADOW shadow register + stx |XSave ($10a) + sty |YSave ($10c) + tdc + sta |DPSave ($110) + lda #$0000 + tcd + SHORT I,M + bcc NotSure ; check emulation mode + lda $04,s + and #$10 + adc #$70 +NotSure bvs hmm2 + lda #$03 + sta SCCAREG SCC channel A cmd register + lda SCCAREG SCC channel A cmd register + bit |ATlkFlag + beq SerInt2 + pha + and #$07 + bne ChanB + lda SCCADATA SCC channel A data register + sta |SerIntData + lda SCCADATA SCC channel A data register + sta |SerIntData+1 + jsl >IRQ_ATalk + bra Next +ChanB lda SCCBDATA SCC channel B data register + sta |SerIntData + lda SCCBDATA SCC channel B data register + sta |SerIntData+1 + jsl >IRQ_ATalk +Next lda >$010101 + sta |EmulStakSave + lda #$00 + ror a + sta |$E10101 + pla + bra Next2 +SerInt2 pha + lda >$010101 + sta |EmulStakSave + stz |$E10101 + jsl >$E1021C MIDI? + pla + bcc $BD0C + clc +Next2 pha + and |SerFlag + beq NoSerial + jsl >IRQ_Serial + ror |$E10101 + pla + lda |$E10101 + bne NoMoreSer + LONG I,M + plb + jmp Exit +NoSerial pla + bne $BD07 +NoMoreSer clv +hmm2 lda >$010101 + sta |EmulStakSave + LONG I,M + .... diff --git a/sys/sim/sim.asm b/sys/sim/sim.asm new file mode 100644 index 0000000..a4ecd57 --- /dev/null +++ b/sys/sim/sim.asm @@ -0,0 +1 @@ +* Serial Interrupt Manager Permanent INIT file case on mcopy sim.mac ************************************************************************ * Global Firmware Equates v_Main gequ $E10010 v_AppleTalk gequ $E10020 v_Serial gequ $E10024 * Address of SerFlag is same for all three ROM revisions of the IIGS SerFlag gequ $E10104 * This value determines whether SIM is installed as a user tool or * as a system tool. sysFlag gequ 0 make '$8000' to install as user tool * This value determines not only which tool set number SIM should be * installed as, but also the error codes that are returned toolNum gequ $4000 change to $0400 for user tool * Current version of SIM in tool version format Version gequ $0100 copy simequates.equ * Request proc dataOut map Gcount gequ 0 Gerror gequ 2 Gversion gequ 4 * Input buffer data structure for Install and Remove calls SIMport gequ 0 SIMaddress gequ 2 ************************************************************************ * Install our RequestProc, and install the new interrupt handlers, etc. SIMINIT START using SIMData phb phk plb lda #0 sta IntVectPrinter indicate that no vectors are sta IntVectPrinter+2 installed sta IntVectModem sta IntVectModem+2 sta ExtVect1 sta ExtVect1+2 sta ExtVect2 sta ExtVect2+2 sta ourSerFlag no SCC interrupts are handled * Turn off interrupts while we do the dirty deed php sei * set the IIGS main interrupt vector to point to our version of this * routine. This code only works on a ROM 01 at this point due to the * different code locations. * We check the ROM version here and install the appropriate routine jsr GetROMVersion cmp #0 beq doRom0 cmp #1 beq doRom0 lda jmpit3 sta >v_Main lda jmpit3+2 sta >v_Main+2 bra donePatch doRom0 lda jmpit1 sta >v_Main lda jmpit1+2 sta >v_Main+2 donePatch plp ph4 #SIMName pha _MMStartUp pla sta SIMuserID pha ph4 #SIMRequest _AcceptRequests jsl CheckPort plb rtl jmpit1 jmp >ROM01IntVect jmpit3 jmp >ROM03IntVect END ROM03IntVect START using SIMData clc (E1/0010 JMPs here, FF/BC6C) xce long mx php phb ; Assume B=00E1 pea $E1E1 plb sta |$0108 ; ASave lda |$C035 ; shadow register sta |$0119 ; ShadSave ora #$8000 and #$9F3E sta |$C035 ; shadow register stx |$010A ; XSave sty |$010C ; YSave tdc sta |$0110 ; DPSave lda #$0000 tcd short mx bcc NotSure ; check emulation mode lda $04,s ; and check for brk and #$10 adc #$70 NotSure bvc hmm3 * $$$ ROM DEPENDENT ENTRY POINT $$$ jmp >$FFBD16 hmm3 lda #$03 sta |$C039 SCCAREG lda |$C039 SCCAREG bit |$0103 ATlkFlag beq SerInt2 pha and #$07 bne ChanB lda |$C03B SCCADATA sta |$0105 SerIntData lda |$C03B SCCADATA sta |$0106 SerIntData+1 jsl >v_AppleTalk bra Next ChanB lda $C03A SCCBDATA sta |$0105 SerIntData lda $C03A SCCBDATA sta |$0106 SerIntData+1 jsl >v_AppleTalk IRQ_ATalk Next lda >$010101 sta |$011C lda #$00 ror a sta |$E10101 pla bra Next2 not appletalk? SerInt2 pha lda >$010101 sta |$011C stz |$E10101 jsl >$E1021C MIDI? pla bcc handledIt was a midi interrupt, exit intr clc Next2 anop pha and >ourSerFlag beq notOurSerIntr lda 1,s bit #%00000111 beq doPortPrinter jsl >IntVectModem rol $0101 doPortPrinter anop lda 1,s and >ourSerFlag beq notOurSerIntr1 bit #%00111000 beq notOurSerIntr1 jsl >IntVectPrinter rol $0101 notOurSerIntr1 pla lda $0101 beq handledIt * $$$ ROM DEPENDENT ENTRY POINT $$$ * was a SCC interrupt, but we didn't install it! jmp >$FFBD15 notOurSerIntr anop * $$$ ROM DEPENDENT ENTRY POINT * check for 'external' interrupts here jsr checkExternal bcs handledIt1 lda 1,s jmp >$FFBCFA ; Back to the real intr handler handledIt1 pla handledIt long mx plb * $$$ ROM DEPENDENT ENTRY POINT $$$ jmp >$FFBF58 ; Exit END ROM01IntVect START using SIMData clc xce long mx php phb pea $E1E1 plb sta $0108 lda $C035 sta $0119 ora #$8000 and #$9F1E sta $C035 stx $010A sty $010C tdc sta $0110 lda #0 tcd short mx bcc sw2 emulation mode? lda 4,s yes check to see if this intr is a BRK and #$10 adc #$70 sw2 bvc switch1 * $$$ ROM DEPENDENT ENTRY POINT jmp >$FFB85F it was a BRK, let the firmware handle it switch1 lda #3 sta $C039 lda $C039 bit $0103 beq X_B83F pha and #$07 bne X_B826 lda $C03B sta $0105 lda $C03B sta $0106 jsl >v_AppleTalk bra X_B836 X_B826 lda $C03A sta $0105 lda $C03A sta $0106 jsl >v_AppleTalk X_B836 lda #0 ror a sta $0101 pla bra X_B842 X_B83F stz $0101 X_B842 pha and >ourSerFlag beq notOurSerIntr lda 1,s bit #%00000111 beq doPortPrinter jsl >IntVectModem rol $0101 doPortPrinter anop lda 1,s and >ourSerFlag beq notOurSerIntr1 bit #%00111000 beq notOurSerIntr1 jsl >IntVectPrinter rol $0101 notOurSerIntr1 pla lda $0101 beq handledIt * $$$ ROM DEPENDENT ENTRY POINT jmp >$FFB85E handledIt1 pla handledIt long mx plb * $$$ ROM DEPENDENT ENTRY POINT jmp >$FFBA86 notOurSerIntr anop * $$$ ROM DEPENDENT ENTRY POINT * check 'external' interrupt sources here jsr checkExternal bcs handledIt1 lda 1,s jmp >$FFB843 ; Back to the real intr handler END SIMRequest START using SIMData misc equ 3 result equ 14+misc reqCode equ 12+misc dataIn equ 8+misc dataOut equ 4+misc rtl equ 1+misc phb phk plb phd tsc tcd lda reqCode cmp #$8003 jcs exitRequestErr cmp #$8000 jcc exitRequestErr and #$00FF asl a tax jmp (requestProcs,X) requestProcs dc a2'doInstall' dc a2'doRemove' dc a2'doVersion' doInstall anop ldy #SIMport lda [dataIn],y jsr ValidatePort bcs notValidPort cmp |ApTalkPort is appletalk running on this port? beq ohNoItsATalk cmp #3 ; external port? bcs installExt dec a asl a asl a tax lda IntVectPrinter,x ora IntVectPrinter+2,x bne intInstalled * Turn off interrupts, so we don't get caught with our pants down php sei * install the new vector in our interrupt handler table lda #$5C sta IntVectPrinter,x ldy #SIMaddress lda [dataIn],y sta IntVectPrinter+1,x ldy #SIMaddress+1 lda [dataIn],y sta IntVectPrinter+2,x * Now set OurSerFlag to indicate that we now have a handler on that * port ldx #%00000111 ldy #SIMport lda [dataIn],y cmp #2 beq port2 ldx #%00111000 port2 txa ora ourSerFlag sta ourSerFlag * And reset the firmware's SerFlag to indicate we're in control ldx #%11111000 ldy #SIMport lda [dataIn],y cmp #SIMModemPort beq port2a ldx #%11000111 port2a txa and >SerFlag sta >SerFlag * Restore interrupts plp okayno1 lda #SIMNoError bra goodbye ohNoItsATalk lda #SIMATalkActive bra goodbye notValidPort lda #SIMInvalidPort bra goodbye intInstalled lda #SIMAlreadyInst a handler is already installed goodbye anop ldy #Gerror sta [dataOut],y jmp exitRequest installExt dec a dec a dec a asl a asl a tax lda ExtVect1,x cmp ExtVect1+2,x bne intInstalled php sei lda #$5C sta ExtVect1,x ldy #SIMaddress lda [dataIn],y sta ExtVect1+1,x ldy #SIMaddress+1 lda [dataIn],y sta ExtVect1+2,x plp bra okayno1 doRemove anop * Calculate index into our handler list by quadrupling "port" ldy #SIMport lda [dataIn],y jsr ValidatePort bcs notValidPort cmp #3 jcs removeExternal dec a asl a asl a tax * If there is no handler installed on that port, return an error lda IntVectPrinter,x ora IntVectPrinter+2,x beq noIntInstalled * If the handler on the port isn't the one the application claims, * return an error lda IntVectPrinter+1,x ldy #SIMaddress cmp [dataIn],y bne notSameVect lda IntVectPrinter+2,x ldy #SIMaddress+1 cmp [dataIn],y bne notSameVect * otherwise, we're cool, so zero out the handler vector php sei lda #0 sta IntVectPrinter,x sta IntVectPrinter+2,x * and modify serFlag to say "no handlers here, bub!" ldx #%11111000 ldy #SIMport lda [dataIn],y cmp #SIMModemPort beq port3 ldx #%11000111 port3 txa and ourSerFlag sta ourSerFlag * We don't re-enable the firmware's SerFlag because there is nobody * installed now! plp noerrgoaway lda #0 bra goodbye2 notSameVect lda #SIMInvalidAddr jmp goodbye noIntInstalled lda #SIMNotInstalled goodbye2 ldy #Gerror sta [dataOut],y jmp exitRequest removeExternal anop dec a dec a dec a asl a asl a tax * if no handler is installed, signal an error lda ExtVect1,x ora ExtVect1+2,x beq noIntInstalled * if handler is not the same as is there, signal an error lda ExtVect1+1,x ldy #SIMaddress cmp [dataIn],y bne notSameVect lda ExtVect1+2,x ldy #SIMaddress+1 cmp [dataIn],y bne notSameVect php sei lda #0 sta ExtVect1,X sta ExtVect1+2,X plp bra noerrgoaway doVersion anop lda #Version ldy #Gversion sta [dataOut],y lda #SIMNoError ldy #Gerror sta [dataOut],y bra exitRequest exitRequestErr anop lda #0 sta result bra exitRequest1 exitRequest lda #$8000 sta result exitRequest1 anop pld plb lda 2,s sta 12,s lda 1,s sta 11,s ply ply ply ply ply rtl END * Does not modify the port number in A ValidatePort START cmp #1 bcc bad cmp #7 bcs bad clc rts bad sec rts END GetROMVersion START pha pha pha pha lda #0 pha pha pha pea $FE1F _FWEntry ply pla pla pla tya rts END ; ; This routine checks to see which serial port, if any, AppleTalk is using. ; The routine sets a flag byte, ApTalkPort, and the accumulator to indicate ; which port (if any) AppleTalk is using. ; $0000 = AppleTalk is not using a serial port ; $0001 = AppleTalk is using serial port 1 (printer port) ; $0002 = AppleTalk is using serial port 2 (modem port) ; Note: This method should be used under GS/OS only. ; ; Enter routine in native 16 bit mode ; longa on longi on CheckPort START GetPort equ $8001 The .AppleTalk DStatus subcall to get ; the port number AppleTalk is currently ; using. phb save data bank phk data bank = code bank plb lda #$0001 start with device #1 sta DIdevNum FindATDriver anop _DInfoGS DInfoParms call Dinfo bcs DIError stop searching if error lda DIdeviceIDNum cmp #$001D is it the AppleTalk main driver? beq ATDriverFound yes inc DIdevNum check the bra FindATDriver next device number ATDriverFound anop lda DIdevNum store device number sta DSdevNum in the DStatus parm list _DStatusGS DStatusParms call DStatus lda portNum get the port number sta ApTalkPort bra Exit DIError anop cmp #$0011 invalid device number, so the beq NotFound AppleTalk main driver wasn't found ; ; Add your code to handle any other errors from DInfo here, because the ; end of the device list was not found. NotFound stz ApTalkPort neither port is in use bra Exit Exit anop lda ApTalkPort plb restore data bank rtl return to caller ApTalkPort entry ds 2 will be 0, 1, or 2 DInfoParms anop dc i2'8' pCount = 8 parameters DIdevNum dc i2'1' devNum dc a4'NameBuffer' devName ds 2 characteristics ds 4 totalBlocks ds 2 slotNum ds 2 unitNum ds 2 version DIdeviceIDNum ds 2 deviceIDNum NameBuffer anop dc i2'31' Class 1 input string. Max Length=31 ds 33 DStatusParms anop dc i2'5' pCount = 5 parameters DSdevNum ds 2 devNum dc i2'GetPort' statusCode = GetPort dc a4'GetPortSList' statusList = GetPortSList dc i4'2' requestCount = 2 ds 4 transferCount GetPortSList anop the GetPort subcall's statusList portNum ds 2 Port appletalk is using dc i2'0' END SIMData DATA SIMName str 'SerialIntrMgr~Entry~' userID dc i2'0' ourSerFlag dc i2'0' SIMuserID dc i2'0' IntVectPrinter ENTRY dc i4'0' IntVectModem dc i4'0' ExtVect1 ENTRY dc i4'0' dc i4'0' dc i4'0' dc i4'0' END checkExternal START * check first external vector lda >ExtVect1 ora >ExtVect1+2 beq checksecond jsl ExtVect1 bcs gotit checksecond lda >ExtVect2 ora >ExtVect2+2 beq neither jsl ExtVect2 gotit rts neither clc rts END \ No newline at end of file diff --git a/sys/sim/sim.doc b/sys/sim/sim.doc new file mode 100644 index 0000000..014dc31 --- /dev/null +++ b/sys/sim/sim.doc @@ -0,0 +1,104 @@ +Serial Interrupt Manager Tool Set +--------------------------------- + +The Serial Interrupt Manager (SIM) is a code module that is installed by +a permanent init (PIF) file residing in the *:System:System.Setup +directory of an Apple IIGS. SIM arbitrates serial interrupt vector +'patches' by providing a simple interface for applications and device +drivers to handle serial interrupts (from the IIGS's built-in SCC 8530) +in a manner completely consistent with Apple's guidelines on the subject. + +SIM replaces the first quarter or so of the IIGS' main interrupt handler. +Most of the code is identical to that found in the ROM, with the +following notable exception: non-MIDI asynchronous serial interrupts +are handled by dispatching to routines that can be installed by using +the SIM tool. + +SCC interrupt handlers installed through SIM are called, according +to Apple guidelines, immediately _after_ checking for AppleTalk and MIDI +interrupts. This prevents AppleTalk or MIDI data loss, and provides the +lowest allowable overhead in processing asynchronous serial interrupts. +Data rates of up to 57600 baud are possible with no resulting data loss. + +Since SIM handles serial interrupts through its own vector, and not +the $E10024 vector, the IIGS Serial Firmware can be used in combination +with SIM; SIM always has priority over the standard firmware handlers, +and if the firmware is used to initialize a port which is already being +handled by a SIM handler a crash may result. Any suggestions for better +arbitration of the firmware are welcome. (SIM could possibly check to see +if the firmware's SerFlag has been set, and automatically uninstall +the SIM handler and queue a warning dialog in the Scheduler.) + +------------------------------------------------------------------------ +SIM consists of a number of routines which are accessed via the +System 6.0 SendRequest IPC mechanism. To reduce development times, SIM +comes with a library that can be used to access SIM in a language- +independent manner. + +The following call descriptions show the various SIM calls in C format. +The calls expect their arguments in C order (i.e., pushing parameters +right to left). + +The return value of the calls is either zero, indicating that no error +occurred, or a non-zero integer indicating the error number. All of the +calls can return SIMNotFound in the event the SIM tool could not be located. + +--------------------- +int SIMVersion(void) + +Returns the version number (in tool version format) of the SIM tool. + +Errors: +SIMNotFound - indicates that the SIM tool could not be located +($0006) Upon receiving this error, the application should + terminate attempting to install an interrupt + handler and should notify the user that the port + could not be opened. + +--------------------- +int InstallIntVect(word port, longword address) + +InstallIntVect installs a serial handler routine into SIM's interrupt +dispatch code. 'address' is a pointer to an interrupt handler which +conforms to the serial interrupt handlers described in the Apple IIGS +Firmware Reference (which are called through the $E10024 vector). + +The following steps should be taken to install a SIM handler: + + Initialize SCC, but do not enable interrupts + call InstallIntVect + Enable SCC Interrupts + +Errors: +SIMInvalidPort An invalid port number was specified. The only port numbers +($0005) currently supported are SIMModemPort (2) and SIMPrinterPort (1) + +SIMATalkActive The specified port is already in use by AppleTalk, and thus +($0003) cannot be used. + +SIMAlreadyInst Some other system component (a driver or application) already +($0001) has an interrupt handler installed for that port. + +In the last two cases, an application should notify the user that the port +is busy and cannot be used, and drivers should return an error code +appropriate to the condition. + +--------------------- +int RemoveIntVect(word port, longword address) + +RemoveIntVect is used to uninstall a previously installed interrupt handler. +The port number and address of the handler must be specified. This prevents +a program from trying to forcibly uninstall some other program's interrupt +handler, an approach which is not acceptable. + +The procedure for uninstalling an interrupt handler should be as follows: + + Turn of SCC interrupts and shutdown SCC chip if desired + Call RemoveIntVect + +Errors: +SIMInvalidAddr The address passed to RemoveIntVect does not match the + actual address of the handler on the specified port. + +SIMNotInstalled There is no handler currently installed for the specified + port. diff --git a/sys/sim/sim.h b/sys/sim/sim.h new file mode 100644 index 0000000..07b7386 --- /dev/null +++ b/sys/sim/sim.h @@ -0,0 +1 @@ +/* * Serial Interrupt Manager * C Interface File * Copyright 1993, Procyon Enterprises Incorporated * Free distribution is hereby granted for use with the * SIM tool */ #ifdef __ORCAC__ /* * ORCA/C Prototypes */ extern int SIMVERSION(int *versionPtr); extern int INSTALLINTVECT(int port, unsigned long address); extern int REMOVEINTVECT(int port, unsigned long address); #else /* * APW C/other prototypes */ int SIMVERSION(); int INSTALLINTVECT(); int REMOVEINTVECT(); #endif #define SIMVersion SIMVERSION #define InstallIntVect INSTALLINTVECT #define RemoveIntVect REMOVEINTVECT #define SIMPrinterPort 1 #define SIMModemPort 2 #define SIMNoError 0 #define SIMAlreadyInst 1 #define SIMInvalidAddr 2 #define SIMATalkActive 3 #define SIMNotInstalled 4 #define SIMInvalidPort 5 #define SIMNotFound 6 \ No newline at end of file diff --git a/sys/sim/sim.mac b/sys/sim/sim.mac new file mode 100644 index 0000000..628becb --- /dev/null +++ b/sys/sim/sim.mac @@ -0,0 +1,152 @@ + MACRO +&lab long &stat +&lab anop + lcla &t + lcla &len + lclc &ch +&t seta 0 +&len seta l:&stat +.a + aif &len=0,.b +&ch amid &stat,&len,1 + aif ("&ch"="x").or.("&ch"="y").or.("&ch"="i"),.i + aif ("&ch"="a").or.("&ch"="m"),.m +.c +&len seta &len-1 + ago ^a +.i + longi on +&t seta &t+16 + ago ^c +.m + longa on +&t seta &t+32 + ago ^c +.b + aif &t=0,.d + rep #&t +.d + mend + MACRO +&lab short &stat +&lab anop + lcla &t + lcla &len + lclc &ch +&t seta 0 +&len seta l:&stat +.a + aif &len=0,.b +&ch amid &stat,&len,1 + aif ("&ch"="x").or.("&ch"="y").or.("&ch"="i"),.i + aif ("&ch"="a").or.("&ch"="m"),.m +.c +&len seta &len-1 + ago ^a +.i + longi off +&t seta &t+16 + ago ^c +.m + longa off +&t seta &t+32 + ago ^c +.b + aif &t=0,.d + sep #&t +.d + mend + MACRO +&lab str &string +&lab dc i1'l:&string',c'&string' + MEND + macro +&lab ph4 &n1 + aif "&n1"="*",.f + lclc &c +&lab anop +&c amid &n1,1,1 + aif "&c"="#",.d + aif s:longa=1,.a + rep #%00100000 +.a + aif "&c"<>"{",.b +&c amid &n1,l:&n1,1 + aif "&c"<>"}",.g +&n1 amid &n1,2,l:&n1-2 + ldy #2 + lda (&n1),y + pha + lda (&n1) + pha + ago .e +.b + aif "&c"<>"[",.c + ldy #2 + lda &n1,y + pha + lda &n1 + pha + ago .e +.c + aif "&c"<>"<",.c1 +&n1 amid &n1,2,l:&n1-1 + pei &n1+2 + pei &n1 + ago .e +.c1 + lda &n1+2 + pha + lda &n1 + pha + ago .e +.d +&n1 amid &n1,2,l:&n1-1 + pea +(&n1)|-16 + pea &n1 + ago .f +.e + aif s:longa=1,.f + sep #%00100000 +.f + mexit +.g + mnote "Missing closing '}'",16 + mend + MACRO +&lab _MMStartUp +&lab ldx #$0202 + jsl $E10000 + MEND + MACRO +&lab _AcceptRequests +&lab ldx #$1B01 + jsl $E10000 + MEND + MACRO +&lab jcs &loc +&lab bcc *+5 + jmp &loc + mend + MACRO +&lab jcc &loc +&lab bcs *+5 + jmp &loc + mend + MACRO +&lab _FWEntry +&lab ldx #$2403 + jsl $E10000 + MEND + MACRO +&lab _DInfoGS ¶ms +&lab jsl $E100A8 + dc i2"$202C" + dc i4"¶ms" + MEND + MACRO +&lab _DStatusGS ¶ms +&lab jsl $E100A8 + dc i2"$202D" + dc i4"¶ms" + MEND diff --git a/sys/sim/simequates.equ b/sys/sim/simequates.equ new file mode 100644 index 0000000..b027ac2 --- /dev/null +++ b/sys/sim/simequates.equ @@ -0,0 +1 @@ +SIMInstallHand gequ $8000 SIMRemoveHand gequ $8001 SIMGetVersion gequ $8002 * SIM Error codes SIMNoError gequ 0 SIMAlreadyInst gequ 1 SIMInvalidAddr gequ 2 SIMATalkActive gequ 3 SIMNotInstalled gequ 4 SIMInvalidPort gequ 5 SIMNotFound gequ 6 * SIM Port codes SIMModemPort gequ 2 SIMPrinterPort gequ 1 \ No newline at end of file diff --git a/sys/sim/simlib.asm b/sys/sim/simlib.asm new file mode 100644 index 0000000..05feebc --- /dev/null +++ b/sys/sim/simlib.asm @@ -0,0 +1 @@ + mcopy simlib.mac copy simequates.equ * High-level access library for SIM tool InstallIntVect START using SIMLibData result equ 0 subroutine (4:address,2:port),2 lda port sta SIMport lda address sta SIMaddress lda address+2 sta SIMaddress+2 lda #SIMInstallHand jsr DoSIMCall lda |Gerror sta result return 2:result END RemoveIntVect START using SIMLibData result equ 0 subroutine (4:address,2:port),2 lda port sta SIMport lda address sta SIMaddress lda address+2 sta SIMaddress+2 lda #SIMRemoveHand jsr DoSIMCall lda |Gerror sta result return 2:result END SIMVersion START using SIMLibData result equ 0 subroutine (4:versionPtr),2 lda #SIMGetVersion jsr DoSIMCall lda |Gerror sta result bne goodbye if an error, don't copy version lda Gversion sta [versionPtr] goodbye return 2:result END DoSIMCall START using SIMLibData pha push request code pea 1 how to flag ph4 #SIMName ph4 #SIMInData ph4 #pBlock _SendRequest bcc noToolErr cmp #$0120 ; nobody accepted the request beq noAccept rts noAccept lda #SIMNotFound sta |Gerror noToolErr rts END SIMLibData DATA SIMName str 'SerialIntrMgr~Entry~' pBlock dc i2'0' ; count field Gerror dc i2'0' ; error code Gversion dc i2'0' ; version number SIMInData ENTRY SIMport dc i2'0' SIMaddress dc i4'0' END \ No newline at end of file diff --git a/sys/sim/simlib.mac b/sys/sim/simlib.mac new file mode 100644 index 0000000..94d89a1 --- /dev/null +++ b/sys/sim/simlib.mac @@ -0,0 +1,158 @@ + MACRO +&lab str &string +&lab dc i1'l:&string',c'&string' + MEND + macro +&lab ph4 &n1 + aif "&n1"="*",.f + lclc &c +&lab anop +&c amid &n1,1,1 + aif "&c"="#",.d + aif s:longa=1,.a + rep #%00100000 +.a + aif "&c"<>"{",.b +&c amid &n1,l:&n1,1 + aif "&c"<>"}",.g +&n1 amid &n1,2,l:&n1-2 + ldy #2 + lda (&n1),y + pha + lda (&n1) + pha + ago .e +.b + aif "&c"<>"[",.c + ldy #2 + lda &n1,y + pha + lda &n1 + pha + ago .e +.c + aif "&c"<>"<",.c1 +&n1 amid &n1,2,l:&n1-1 + pei &n1+2 + pei &n1 + ago .e +.c1 + lda &n1+2 + pha + lda &n1 + pha + ago .e +.d +&n1 amid &n1,2,l:&n1-1 + pea +(&n1)|-16 + pea &n1 + ago .f +.e + aif s:longa=1,.f + sep #%00100000 +.f + mexit +.g + mnote "Missing closing '}'",16 + mend + MACRO +&lab subroutine &parms,&work +&lab anop + aif c:&work,.a + lclc &work +&work setc 0 +.a + gbla &totallen + gbla &worklen +&worklen seta &work +&totallen seta 0 + aif c:&parms=0,.e + lclc &len + lclc &p + lcla &i +&i seta c:&parms +.b +&p setc &parms(&i) +&len amid &p,2,1 + aif "&len"=":",.c +&len amid &p,1,2 +&p amid &p,4,l:&p-3 + ago .d +.c +&len amid &p,1,1 +&p amid &p,3,l:&p-2 +.d +&p equ &totallen+3+&work +&totallen seta &totallen+&len +&i seta &i-1 + aif &i,^b +.e + tsc + sec + sbc #&work + tcs + inc a + phd + tcd + phb + phk + plb + mend + MACRO +&lab return &r +&lab anop + lclc &len + aif c:&r,.a + lclc &r +&r setc 0 +&len setc 0 + ago .h +.a +&len amid &r,2,1 + aif "&len"=":",.b +&len amid &r,1,2 +&r amid &r,4,l:&r-3 + ago .c +.b +&len amid &r,1,1 +&r amid &r,3,l:&r-2 +.c + aif &len<>2,.d + ldy &r + ago .h +.d + aif &len<>4,.e + ldx &r+2 + ldy &r + ago .h +.e + aif &len<>10,.g + ldy #&r + ldx #^&r + ago .h +.g + mnote 'Not a valid return length',16 + mexit +.h + aif &totallen=0,.i + lda &worklen+1 + sta &worklen+&totallen+1 + lda &worklen + sta &worklen+&totallen +.i + plb + pld + tsc + clc + adc #&worklen+&totallen + tcs + aif &len=0,.j + tya +.j + rtl + mend + MACRO +&lab _SendRequest +&lab ldx #$1C01 + jsl $E10000 + MEND diff --git a/sys/sim/test.c b/sys/sim/test.c new file mode 100644 index 0000000..1a10c1e --- /dev/null +++ b/sys/sim/test.c @@ -0,0 +1 @@ +#include #include "sim.h" #pragma optimize 9 asm void TestHandler() { sec rtl } int main(int argc, char *argv[]) { int v,e; e = SIMVersion(&v); if (e) { printf("SIM Error Code: %d\n",e); exit(1); } printf("SIM Version Code: %04X\n",v); e = InstallIntVect(2,(unsigned long) TestHandler); if (e) { printf("(Install) SIM Error Code: %d\n",e); exit(1); } e = RemoveIntVect(2,(unsigned long) TestHandler); if (e) { printf("(Remove) SIM Error Code: %d\n",e); exit(1); } } \ No newline at end of file