; -----------------------------------------------------------------------------
; IEEEFS 0.02 (c) Intelligent Interfaces Ltd. 1986
; reverse engineered by Eelco Huininga
; Filename     : NIEEEFS-0.2.rom
; Load address : 00008000
; Exec address : 0000D9CD
; Length       : 00002000
; -----------------------------------------------------------------------------

; -----------------------------------------------------------------------------
; Filing system temporary work space
; -----------------------------------------------------------------------------
pwrkspc            = &B0                          ; &B0-&B1: Pointer to the private workspace (as reserved by ROM service call &02)
memadr             = &B2                          ; &B2-&B5: Pointer to memory location (used by data transfers)
length             = &B6                          ; &B6-&B8: Length of bytes to transfer (used by OSWORD &80 commands &36-&3F)
intflag            = &B9                          ; &B9    : Interrupt flag
timer              = &BA                          ; &BA-&BD: 32-bit timer

; -----------------------------------------------------------------------------
; TMS9914A registers
; -----------------------------------------------------------------------------
intstatus0         = &FC20                        ; (read)  Interrupt Status Register 0
intstatus1         = &FC24                        ; (read)  Interrupt Status Register 1
addrstatus         = &FC22                        ; (read)  Address Status Register
busstatus          = &FC26                        ; (read)  Bus Status Register
cmdpassthru        = &FC23                        ; (read)  Command Pass Through Register
datin              = &FC27                        ; (read)  Data In Register

intmask0           = &FC20                        ; (write) Interrupt Mask Register 0
intmask1           = &FC24                        ; (write) Interrupt Mask Register 1
auxcmd             = &FC26                        ; (write) Auxiliary Command Register
address            = &FC21                        ; (write) Address Register
serpoll            = &FC25                        ; (write) Serial Poll Register
parpoll            = &FC23                        ; (write) Parallel Poll Register
datout             = &FC27                        ; (write) Data Out Register

; -----------------------------------------------------------------------------
; TMS9914 Auxiliary commands
; -----------------------------------------------------------------------------
set                = &80                          ; Set flag
clr                = &00                          ; Clear flag

swrst              = &00                          ; Software reset
dacr               = &01                          ; Release DAC (Data Accepted) holdoff
rhdf               = &02                          ; Release RFD (Ready For Data) holdoff
hdfa               = &03                          ; Holfoff on all data
hdfe               = &04                          ; Holfoff on EOI (End or Identify) only
nbaf               = &05                          ; New byte available false
fget               = &06                          ; Force group execute trigger
rtl                = &07                          ; Return to local
feoi               = &08                          ; Send EOI (End or Identify) with next byte
lon                = &09                          ; Listen only
ton                = &0A                          ; Talk only
gts                = &0B                          ; Go to standby
tca                = &0C                          ; Take control asynchronously
tcs                = &0D                          ; Take control synchronously
rpp                = &0E                          ; Request parallel poll
sic                = &0F                          ; Send interface clear
sre                = &10                          ; Send remote enable
rqc                = &11                          ; Request control
rlc                = &12                          ; Release control
dai                = &13                          ; Disable all interrupts
pts                = &14                          ; Pass through next secondary
stdl               = &15                          ; Short T1 settling time
shdw               = &16                          ; Shadow handshake
vstdl              = &17                          ; Very short T1 delay
rsv2               = &18                          ; Request service bit 2

; -----------------------------------------------------------------------------
; TUBE ULA registers
; -----------------------------------------------------------------------------
tubedat            = &FEE5

tubeid             = &F                           ; When claiming the TUBE, we'll use ID &F

; -----------------------------------------------------------------------------
; OS call addresses
; -----------------------------------------------------------------------------
tubecontrol        = &0406                        ; TUBE control (claim/data transfer/release)
osasci             = &FFE3                        ; OSASCI Write character routine
osnewl             = &FFE7                        ; OSNEWL Write a new-line routine
osbyte             = &FFF4                        ; OSBYTE Various OS routines


; -----------------------------------------------------------------------------
; Start of code
; -----------------------------------------------------------------------------
8000  4C 4E 80     LN.   JMP language             ; Language entry
8003  4C 4F 80     LO.   JMP service              ; Service entry
8006  82           .     EQUB &82                 ; ROM type; bit 7   = 1    : Has a service entry
                                                  ;           bit 6   = 0    : Doesn't have a language entry
                                                  ;           bit 5   = 0    : Isn't relocatable to the second processor
                                                  ;           bit 4   = 0    : No Electron firm key expansions availabe
                                                  ;           bit 3-0 = 0010 : 6502 code (not BASIC)
8007  1A           .     EQUB copyright-1         ; Copyright offset
8008  02           .     EQUB &02                 ; Version 2

.title
8009  49 45 45 45  IEEE  EQUS "IEEE488 INTERFACE" ; Title string
      34 38 38 20  488 
      49 4E 54 45  INTE
      52 46 41 43  RFAC
      45           E
801A  00           .     EQUB &00                 ; Title termination byte

.copyright
801B  28 43 29 20 (C)    EQUS "(C) COPYRIGHT INTELLIGENT INTERFACES LTD 1986"
      43 4F 50 59 COPY                            ; Copyright string
      52 49 47 48 RIGH
      54 20 49 4E T IN
      54 45 4C 4C TELL
      49 47 45 4E IGEN
      54 20 49 4E T IN
      54 45 52 46 TERF
      41 43 45 53 ACES
      20 4C 54 44  LTD
      20 31 39 38  198
      36          6
8048  00           .     EQUB &00                 ; Copyright termination byte

.version
8049  30 2E 30 32  0.02  EQUS "0.02"              ; Version string
804D  00           .     EQUB &00                 ; Version termination byte

; -----------------------------------------------------------------------------
; Language entry point
; -----------------------------------------------------------------------------
.language
804E  60           `     RTS

; -----------------------------------------------------------------------------
; Service entry point
; -----------------------------------------------------------------------------
.service
804F  08           .     PHP                      ; Push the status register
8050  48           H     PHA                      ; Push the accumulator
8051  8A           .     TXA
8052  48           H     PHA                      ; Push the X register
8053  98           .     TYA
8054  48           H     PHA                      ; Push the Y register
8055  BA           .     TSX
8056  BD 03 01     ...   LDA &0103,X
8059  AA           .     TAX
805A  E8           .     INX
805B  E8           .     INX
805C  BD 65 80     .e.   LDA &8065,X              ; Get the MSB of the service call's procedure
805F  48           H     PHA                      ; Push it to the stack
8060  BD 93 80     ...   LDA &8093,X              ; Get the MSB of the service call's procedure
8063  48           H     PHA                      ; Push it to the stack
8064  60           `     RTS                      ; Jump to the procedure

; -----------------------------------------------------------------------------
; Service calls lookup table, MSB
; -----------------------------------------------------------------------------
.
8065  80           .     EQUB &80                 ; (&80C7) &FE Post initialisation TUBE system call
8066  80           .     EQUB &80                 ; (&80C7) &FF Tube system main initialisation
8067  80           .     EQUB &80                 ; (&80C7) &00 No operation
8068  80           .     EQUB &80                 ; (&80C7) &01 Absolute public workspace claim
8069  80           .     EQUB &80                 ; (&80CE) &02 Relative space claim
806A  80           .     EQUB &80                 ; (&80C7) &03 Auto-boot call
806B  80           .     EQUB &80                 ; (&80C7) &04 Unrecognized * command
806C  81           .     EQUB &81                 ; (&8133) &05 Unknown interrupt
806D  80           .     EQUB &80                 ; (&80C7) &06 BRK has been executed
806E  80           .     EQUB &80                 ; (&80C7) &07 Unrecognized OSBYTE call
806F  82           .     EQUB &82                 ; (&8275) &08 Unrecognized OSWORD call
8070  83           .     EQUB &83                 ; (&83D7) &09 *HELP command interception
8071  80           .     EQUB &80                 ; (&80C7) &0A Claim absolute workspace
8072  80           .     EQUB &80                 ; (&80C7) &0B NMI repeased
8073  80           .     EQUB &80                 ; (&80C7) &0C NMI claim
8074  80           .     EQUB &80                 ; (&80C7) &0D ROM filing system initialise
8075  80           .     EQUB &80                 ; (&80C7) &0E ROM filing system get byte
8076  80           .     EQUB &80                 ; (&80C7) &0F Vectors claimed
8077  80           .     EQUB &80                 ; (&80C7) &10 Close any *SPOOL or *EXEC files
8078  80           .     EQUB &80                 ; (&80C7) &11 Font implosion/explosion warning
8079  80           .     EQUB &80                 ; (&80C7) &12 Initialise filing system
807A  80           .     EQUB &80                 ; (&80C7) &13 Character placed in RS423 buffer
807B  80           .     EQUB &80                 ; (&80C7) &14 Character placed in printer buffer
807C  80           .     EQUB &80                 ; (&80C7) &15 100Hz poll
807D  80           .     EQUB &80                 ; (&80C7) &16 A BEL request has been made
807E  80           .     EQUB &80                 ; (&80C7) &17 SOUND buffer purged
807F  80           .     EQUB &80                 ; (&80C7) &18 Interactive *HELP request
8080  80           .     EQUB &80                 ; (&80C7) &19 (unused)
8081  80           .     EQUB &80                 ; (&80C7) &1A (unused)
8082  80           .     EQUB &80                 ; (&80C7) &1B (unused)
8083  80           .     EQUB &80                 ; (&80C7) &1C (unused)
8084  80           .     EQUB &80                 ; (&80C7) &1D (unused)
8085  80           .     EQUB &80                 ; (&80C7) &1E (unused)
8086  80           .     EQUB &80                 ; (&80C7) &1F (unused)
8087  80           .     EQUB &80                 ; (&80C7) &20 (unused)
8088  80           .     EQUB &80                 ; (&80C7) &21 Claim private workspace in Hazel
8089  84           .     EQUB &84                 ; (&8417) &22 Claim absolute workspace in Hazel
808A  80           .     EQUB &80                 ; (&80C7) &23 Reports top of private workspace
808B  84           .     EQUB &84                 ; (&8427) &24 Absolute workspace in Hazel count
808C  80           .     EQUB &80                 ; (&80C7) &25 Return filing system information
808D  80           .     EQUB &80                 ; (&80C7) &26 *SHUT command issued
808E  80           .     EQUB &80                 ; (&80C7) &27 Hard reset call
808F  80           .     EQUB &80                 ; (&80C7) &28 Unknown *CONFIGURE command
8090  80           .     EQUB &80                 ; (&80C7) &29 Unknown *STATUS command
8091  80           .     EQUB &80                 ; (&80C7) &2A Language about to be initialised
8092  80           .     EQUB &80                 ; (&80C7) &2B (unused)

; -----------------------------------------------------------------------------
; Service calls lookup table, LSB
; -----------------------------------------------------------------------------
.
8093  C6           .     EQUB &C6
8094  C6           .     EQUB &C6
8095  C6           .     EQUB &C6
8096  C6           .     EQUB &C6
8097  CD           .     EQUB &CD
8098  C6           .     EQUB &C6
8099  C6           .     EQUB &C6
809A  32                 EQUB &32
809B  C6           .     EQUB &C6
809C  C6           .     EQUB &C6
809D  74           t     EQUB &74
809E  D6           .     EQUB &D6
809F  C6           .     EQUB &C6
80A0  C6           .     EQUB &C6
80A1  C6           .     EQUB &C6
80A2  C6           .     EQUB &C6
80A3  C6           .     EQUB &C6
80A4  C6           .     EQUB &C6
80A5  C6           .     EQUB &C6
80A6  C6           .     EQUB &C6
80A7  C6           .     EQUB &C6
80A8  C6           .     EQUB &C6
80A9  C6           .     EQUB &C6
80AA  C6           .     EQUB &C6
80AB  C6           .     EQUB &C6
80AC  C6           .     EQUB &C6
80AD  C6           .     EQUB &C6
80AE  C6           .     EQUB &C6
80AF  C6           .     EQUB &C6
80B0  C6           .     EQUB &C6
80B1  C6           .     EQUB &C6
80B2  C6           .     EQUB &C6
80B3  C6           .     EQUB &C6
80B4  C6           .     EQUB &C6
80B5  C6           .     EQUB &C6
80B6  C6           .     EQUB &C6
80B7  16           .     EQUB &16
80B8  C6           .     EQUB &C6
80B9  26           &     EQUB &26
80BA  C6           .     EQUB &C6
80BB  C6           .     EQUB &C6
80BC  C6           .     EQUB &C6
80BD  C6           .     EQUB &C6
80BE  C6           .     EQUB &C6
80BF  C6           .     EQUB &C6
80C0  C6           .     EQUB &C6

; -----------------------------------------------------------------------------
;
; -----------------------------------------------------------------------------
.
80C1  BA           .     TSX
80C2  A9 00        ..    LDA #&00                 ; Set A to &00 when exiting this ROM to notify that the call has been handled
80C4  9D 03 01     ...   STA &0103,X

; -----------------------------------------------------------------------------
; Service call &xx : Entry for all other unused service calls
; -----------------------------------------------------------------------------
.
80C7  68           h     PLA
80C8  A8           .     TAY                      ; Restore Y register
80C9  68           h     PLA
80CA  AA           .     TAX                      ; Restore X register
80CB  68           h     PLA                      ; Restore accumulator
80CC  28           (     PLP                      ; Restore status register
80CD  60           `     RTS                      ; Exit

; -----------------------------------------------------------------------------
; Service call &02 : Relative space claim
; -----------------------------------------------------------------------------
.
80CE  20 67 84     g.    JSR checkos              ; Check if Hazel memory is available
80D1  B0 0D        ..    BCS &80E0                ; Yes? Then exit (Memory claim will be handled by Service call &22 at &8417)
80D3  A6 F4        ..    LDX &F4                  ; No? Then claim some normal memory
80D5  68           h     PLA
80D6  A8           .     TAY                      ; Restore Y register (which contains the value of the first available page)
80D7  9D F0 0D     ...   STA &0DF0,X              ; Store it in the ROM workspace table
80DA  C8           .     INY                      ; Increase Y by the number of pages we need (one)
80DB  98           .     TYA
80DC  48           H     PHA                      ; And push it back on the stack
80DD  20 E3 80      ..   JSR initwrkspc           ; Initialise the workspace
.
80E0  4C C7 80     L..   JMP &80C7                ; Jump to the exit routine

; -----------------------------------------------------------------------------
; Initialise the workspace
; -----------------------------------------------------------------------------
.initwrkspc
80E3  A5 B0        ..    LDA pwrkspc              ; Push the original contents &B0 to the stack
80E5  48           H     PHA
80E6  A5 B1        ..    LDA pwrkspc+1            ; Push the original contents &B1 to the stack
80E8  48           H     PHA
80E9  A9 00        ..    LDA #&00                 ; LSB of pointer to private workspace is &00
80EB  85 B0        ..    STA pwrkspc
80ED  88           .     DEY                      ; Y contains the value of the first available page
80EE  84 B1        ..    STY &B1                  ; MSB of pointer to private workspace is Y-1 (we want 2(???) pages)
80F0  A0 09        ..    LDY #&09
.
80F2  B9 0B 81     ...   LDA &810B,Y              ; Initialise the lower part of the private workspace
80F5  91 B0        ..    STA (pwrkspc),Y
80F7  88           .     DEY
80F8  10 F8        ..    BPL &80F2
80FA  A0 EC        ..    LDY #&EC
.
80FC  B9 2A 80     .*.   LDA &802A,Y              ; Initialise the upper part of the private workspace
80FF  91 B0        ..    STA (pwrkspc),Y
8101  C8           .     INY
8102  D0 F8        ..    BNE &80FC
8104  68           h     PLA
8105  85 B1        ..    STA pwrkspc+1            ; Restore the original contents of &B1
8107  68           h     PLA
8108  85 B0        ..    STA pwrkspc              ; Restore the original contents of &B0
810A  60           `     RTS                      ; Exit

; -----------------------------------------------------------------------------
;
; -----------------------------------------------------------------------------
.
810B  40           @     EQUB &40                 ; &00
810C  20                 EQUB &20                 ; &01
810D  00           .     EQUB &00                 ; &02
810E  00           .     EQUB &00                 ; &03
810F  00           .     EQUB &00                 ; &04
8110  00           .     EQUB &00                 ; &05
8111  00           .     EQUB &00                 ; &06
8112  00           .     EQUB &00                 ; &07
8113  00           .     EQUB &00                 ; &08
8114  00           .     EQUB &00                 ; &09
8115  00           .     EQUB &00                 ; &0A

; -----------------------------------------------------------------------------
;
; -----------------------------------------------------------------------------
.
8116  00           .     EQUB &00                 ; &EC
8117  0A           .     EQUB &0A                 ; &ED
8118  0A           .     EQUB &0A                 ; &EE
8119  4D           M     EQUB &4D                 ; &EF
811A  80           .     EQUB &80                 ; &F0
811B  4D           M     EQUB &4D                 ; &F1
811C  80           .     EQUB &80                 ; &F2
811D  4D           M     EQUB &4D                 ; &F3
811E  80           .     EQUB &80                 ; &F4
811F  00           .     EQUB &00                 ; &F5
8120  00           .     EQUB &00                 ; &F6
8121  00           .     EQUB &00                 ; &F7
8122  0A           .     EQUB &0A                 ; &F8
8123  0A           .     EQUB &0A                 ; &F9
8124  00           .     EQUB &00                 ; &FA
8125  00           .     EQUB &00                 ; &FB
8126  F9           .     EQUB &F9                 ; &FC
8127  FF           .     EQUB &FF                 ; &FD
8128  00           .     EQUB &00                 ; &FE
8129  00           .     EQUB &00                 ; &FF

; -----------------------------------------------------------------------------
; Service call &05 : Unknown interrupt
; -----------------------------------------------------------------------------
.
812A  68           h     PLA
812B  85 B1        ..    STA pwrkspc+1            ; Restore the LSB of the private workspace pointer
812D  68           h     PLA
812E  85 B0        ..    STA pwrkspc              ; Restore the MSB of the private workspace pointer
8130  4C C7 80     L..   JMP &80C7                ; It wasn't our interrupt, so exit with A=&05

.                                                 ; Entry point
8133  A5 B0        ..    LDA pwrkspc              ; Push &B0 to the stack
8135  48           H     PHA
8136  A5 B1        ..    LDA pwrkspc+1            ; Push &B1 to the stack
8138  48           H     PHA
8139  A9 00        ..    LDA #&00                 ; LSB of pointer to private workspace is &00
813B  85 B0        ..    STA pwrkspc
813D  A6 F4        ..    LDX &F4
813F  BD F0 0D     ...   LDA &0DF0,X              ; Get the page number of our private workspace from the ROM workspace table
8142  85 B1        ..    STA pwrkspc+1            ; MSB of pointer to private workspace
8144  A0 04        ..    LDY #&04
8146  B1 B0        ..    LDA (pwrkspc),Y
8148  F0 E0        ..    BEQ &812A                ; Exit if the 'Allow interrupts' flag isn't set
814A  AD 24 FC     .$.   LDA intstatus1           ; Load the TMS9144A's Interrupt status register 1...
814D  29 EB        ).    AND #&EB                 ; and check if either IFC (bit 7), SRQ (bit 6), MA (bit 5), APT (bit 3), ERR (bit 1) or GET (bit 0) is set
814F  F0 D9        ..    BEQ &812A                ; If not, exit
8151  AA           .     TAX
8152  A5 B2        ..    LDA memadr+0
8154  48           H     PHA                      ; Save the contents of memadr+0 for now
8155  86 B2        ..    STX memadr+0             ; ... and use memadr+0 for the contents of the Interrupt status register 1
8157  8A           .     TXA
8158  29 01        ).    AND #&01                 ; Is the GET bit (bit 0) set?
815A  F0 17        ..    BEQ &8173                ; No? Then go to &8173
815C  20 3D 84      =.   JSR &843D                ; ?(pwrkspc+&06) = #&00
815F  A0 FF        ..    LDY #&FF
8161  B1 B0        ..    LDA (pwrkspc),Y
8163  F0 06        ..    BEQ &816B
8165  A9 81        ..    LDA #&81                 ; Set bits 7 and 0 of &B9
8167  05 B9        ..    ORA intflag
8169  85 B9        ..    STA intflag
.
816B  A0 03        ..    LDY #&03                 ; Set bits 7 and 0 of pwrkspc+3
816D  A9 81        ..    LDA #&81
816F  11 B0        ..    ORA (pwrkspc),Y
8171  91 B0        ..    STA (pwrkspc),Y
.
8173  A5 B2        ..    LDA memadr+0
8175  29 40        )@    AND #&40                 ; Is the SRQ bit (bit 6) set?
8177  F0 14        ..    BEQ &818D                ; No? Then go to &818D
8179  A0 FF        ..    LDY #&FF
817B  B1 B0        ..    LDA (pwrkspc),Y
817D  F0 06        ..    BEQ &8185
817F  A9 C0        ..    LDA #&C0                 ; Set bits 7 and 6 of &B9
8181  05 B9        ..    ORA intflag
8183  85 B9        ..    STA intflag
.
8185  A0 03        ..    LDY #&03                 ; Set bits 7 and 6 of pwrkspc+3
8187  A9 C0        ..    LDA #&C0
8189  11 B0        ..    ORA (pwrkspc),Y
818B  91 B0        ..    STA (pwrkspc),Y
.
818D  A5 B2        ..    LDA memadr+0
818F  29 20        )     AND #&20                 ; Is the MA bit (bit 5) set?
8191  F0 68        .h    BEQ &81FB                ; No? Then go to &81FB
8193  AD 23 FC     .#.   LDA cmdpassthru
8196  C9 09        ..    CMP #&09                 ; TCT (Take Control)
8198  D0 0B        ..    BNE &81A5
819A  A9 11        ..    LDA #rqc                 ; Load the mnemonic for the 'Request control' function
819C  8D 26 FC     .&.   STA auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
819F  20 52 84      R.   JSR &8452                ; Set the 'this controller is the active controller' flag
81A2  4C 49 82     LI.   JMP &8249
.
81A5  C9 05        ..    CMP #&05                 ; PPC (Parallel Poll Configure)
81A7  D0 08        ..    BNE &81B1
81A9  A9 14        ..    LDA #pts                 ; Load the mnemonic for the 'Pass through next secondary' function
81AB  8D 26 FC     .&.   STA auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
81AE  4C 49 82     LI.   JMP &8249
.
81B1  C9 15        ..    CMP #&15                 ; PPU (Parallel Poll Unconfigure)
81B3  D0 0C        ..    BNE &81C1
81B5  A0 08        ..    LDY #&08
81B7  A9 00        ..    LDA #&00
81B9  91 B0        ..    STA (pwrkspc),Y          ; ?(pwrkspc+&08) = #&00
81BB  8D 23 FC     .#.   STA parpoll
81BE  4C 49 82     LI.   JMP &8249
.
81C1  29 F0        ).    AND #&F0
81C3  C9 60        .`    CMP #&60                 ; PPE (Parallel Poll Enable
81C5  D0 24        .$    BNE &81EB
81C7  AD 23 FC     .#.   LDA cmdpassthru
81CA  29 08        ).    AND #&08                 ; Mask out the S-bit (sense bit)
81CC  A0 09        ..    LDY #&09
81CE  91 B0        ..    STA (pwrkspc),Y          ; Store the S-bit in (pwrkspc),&09
81D0  AD 23 FC     .#.   LDA cmdpassthru
81D3  29 07        ).    AND #&07                 ; Mask out the P1, P2 and P3 bits
81D5  AA           .     TAX
81D6  BD E3 81     ...   LDA &81E3,X
81D9  A0 08        ..    LDY #&08
81DB  91 B0        ..    STA (pwrkspc),Y          ; Set (pwrkspc),&08 to the desired parallel poll response
81DD  20 5A 82      Z.   JSR &825A
81E0  4C 49 82     LI.   JMP &8249
.
81E3  01           .     EQUB &01
81E4  02           .     EQUB &02
81E5  04           .     EQUB &04
81E6  08           .     EQUB &08
81E7  10           .     EQUB &10
81E8  20                 EQUB &20
81E9  40           @     EQUB &40
81EA  80           .     EQUB &80
.
81EB  C9 70        .p    CMP #&70                 ; PPD (Parallel Poll Disable)
81ED  D0 5A        .Z    BNE &8249
81EF  A0 08        ..    LDY #&08
81F1  A9 00        ..    LDA #&00
81F3  91 B0        ..    STA (pwrkspc),Y          ; (pwrkspc),&08 = #&00
81F5  8D 23 FC     .#.   STA parpoll
81F8  4C 49 82     LI.   JMP &8249
.
81FB  A9 08        ..    LDA #&08                 ; mask: 00001000
81FD  25 B2        %.    AND memadr+0             ; Is the APT bit (bit 3) set?
81FF  F0 16        ..    BEQ &8217                ; No? Then go to &8217
8201  A0 02        ..    LDY #&02
8203  11 B0        ..    ORA (pwrkspc),Y          ; set bit 3 of pwrkspc+2
8205  91 B0        ..    STA (pwrkspc),Y
8207  A9 82        ..    LDA #&82
8209  48           H     PHA                      ; Push the MSB of the return address (&8249) to the stack
820A  A9 48        .H    LDA #&48
820C  48           H     PHA                      ; Push the LSB of the return address (&8249) to the stack
820D  A0 F0        ..    LDY #&F0
820F  B1 B0        ..    LDA (pwrkspc),Y          ; Get the MSB of this interrupt's subroutine's vector. Default is &804E (RTS)
8211  48           H     PHA                      ; Push it to the stack
8212  88           .     DEY
8213  B1 B0        ..    LDA (pwrkspc),Y          ; Get the LSB of this interrupt's subroutine's vector. Default is &804E (RTS)
8215  48           H     PHA                      ; Push it to the stack
8216  60           `     RTS                      ; Jump to the subroutine
.
8217  A9 80        ..    LDA #&80                 ; mask: 10000000
8219  25 B2        %.    AND memadr+0             ; Is the IFC bit (bit 7) set?
821B  F0 16        ..    BEQ &8233                ; No? Then go to &8233
821D  A0 02        ..    LDY #&02
821F  11 B0        ..    ORA (pwrkspc),Y          ; set bit 7 of pwrkspc+2
8221  91 B0        ..    STA (pwrkspc),Y
8223  A9 82        ..    LDA #&82
8225  48           H     PHA                      ; Push the MSB of the return address (&8249) to the stack
8226  A9 48        .H    LDA #&48
8228  48           H     PHA                      ; Push the LSB of the return address (&8249) to the stack
8229  A0 F2        ..    LDY #&F2
822B  B1 B0        ..    LDA (pwrkspc),Y          ; Get the MSB of this interrupt's subroutine's vector. Default is &804E (RTS)
822D  48           H     PHA                      ; Push it to the stack
822E  88           .     DEY
822F  B1 B0        ..    LDA (pwrkspc),Y          ; Get the LSB of this interrupt's subroutine's vector. Default is &804E (RTS)
8231  48           H     PHA                      ; Push it to the stack
8232  60           `     RTS                      ; Jump to the subroutine
.
8233  A9 02        ..    LDA #&02                 ; mask: 00000010
8235  25 B2        %.    AND memadr+0             ; Is the ERR bit (bit 1) set?
8237  F0 15        ..    BEQ &824E                ; No? Then go to &824E (Note: this should never happen since all bits have been handled; it should have been intercepted at &814F)
8239  A9 82        ..    LDA #&82
823B  48           H     PHA                      ; Push the MSB of the return address (&824E) to the stack
823C  A9 4D        .M    LDA #&4D
823E  48           H     PHA                      ; Push the LSB of the return address (&824E) to the stack
823F  A0 F4        ..    LDY #&F4
8241  B1 B0        ..    LDA (pwrkspc),Y          ; Get the MSB of this interrupt's subroutine's vector. Default is &804E (RTS)
8243  48           H     PHA                      ; Push it to the stack
8244  88           .     DEY
8245  B1 B0        ..    LDA (pwrkspc),Y          ; Get the LSB of this interrupt's subroutine's vector. Default is &804E (RTS)
8247  48           H     PHA                      ; Push it to the stack
8248  60           `     RTS                      ; Jump to the subroutine
.
8249  A9 01        ..    LDA #clr+dacr            ; Load the mnemonic for the 'Clear Release DAC holdoff' function
824B  8D 26 FC     .&.   STA auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
.
824E  68           h     PLA
824F  85 B2        ..    STA memadr+0             ; Restore memadr+0
8251  68           h     PLA
8252  85 B1        ..    STA pwrkspc+1            ; and the LSB of the private workspace pointer
8254  68           h     PLA
8255  85 B0        ..    STA pwrkspc              ; and the MSB of the private workspace pointer
8257  4C C1 80     L..   JMP &80C1                ; We've handled the interrupt, so exit with A=&00

; -----------------------------------------------------------------------------
;
; -----------------------------------------------------------------------------
.
825A  A0 F5        ..    LDY #&F5
825C  B1 B0        ..    LDA (pwrkspc),Y
825E  A0 09        ..    LDY #&09
8260  D1 B0        ..    CMP (pwrkspc),Y
8262  D0 08        ..    BNE &826C
8264  A0 08        ..    LDY #&08
8266  B1 B0        ..    LDA (pwrkspc),Y
8268  8D 23 FC     .#.   STA parpoll
826B  60           `     RTS
.
826C  A9 00        ..    LDA #&00
826E  8D 23 FC     .#.   STA parpoll
8271  60           `     RTS

; -----------------------------------------------------------------------------
; Service call &08 : Unrecognised OSWORD call
; -----------------------------------------------------------------------------
.
8272  4C C7 80     L..   JMP &80C7                ; This isn't an OSWORD call for us, so exit without setting A to &00
.                                                 ; Entry point
8275  A5 EF        ..    LDA &EF                  ; Get the OSWORD call number
8277  C9 80        ..    CMP #&80                 ; Is it &80?
8279  D0 F7        ..    BNE &8272                ; If not, then exit
827B  A0 02        ..    LDY #&02                 ;
827D  B1 F0        ..    LDA (&F0),Y              ; Get XY+2
827F  C9 40        .@    CMP #&40                 ; Is it < &40 ?
8281  B0 EF        ..    BCS &8272                ; No? Then exit
8283  AA           .     TAX                      ; Yes? X = function code
8284  A5 B0        ..    LDA pwrkspc              ; Push the contents of zeropage &B0-&BF (the filesystem's temporary workspace)
8286  48           H     PHA
8287  A5 B1        ..    LDA pwrkspc+1
8289  48           H     PHA
828A  A5 B2        ..    LDA memadr+0
828C  48           H     PHA
828D  A5 B3        ..    LDA memadr+1
828F  48           H     PHA
8290  A5 B4        ..    LDA memadr+2
8292  48           H     PHA
8293  A5 B5        ..    LDA memadr+3
8295  48           H     PHA
8296  A5 B6        ..    LDA length+0
8298  48           H     PHA
8299  A5 B7        ..    LDA length+1
829B  48           H     PHA
829C  A5 B8        ..    LDA length+2
829E  48           H     PHA
829F  A5 B9        ..    LDA intflag
82A1  48           H     PHA
82A2  A5 BA        ..    LDA timer+0
82A4  48           H     PHA
82A5  A5 BB        ..    LDA timer+1
82A7  48           H     PHA
82A8  A5 BC        ..    LDA timer+2
82AA  48           H     PHA
82AB  A5 BD        ..    LDA timer+3
82AD  48           H     PHA
82AE  A5 BE        ..    LDA &BE
82B0  48           H     PHA
82B1  A5 BF        ..    LDA &BF
82B3  48           H     PHA
82B4  BD DD 82     ...   LDA &82DD,X              ; Get the LSB of the OSWORD &80 command's procedure
82B7  48           H     PHA                      ; Push it to the stack
82B8  BD 1D 83     ...   LDA &831D,X              ; Get the MSB of the OSWORD &80 command's procedure
82BB  48           H     PHA                      ; Push it to the stack
82BC  C8           .     INY
82BD  A9 00        ..    LDA #&00
82BF  91 F0        ..    STA (&F0),Y              ; set XY+3 = &00
82C1  85 B0        ..    STA pwrkspc              ; LSB of pointer to private workspace is &00
82C3  A6 F4        ..    LDX &F4                  ; ROM number
82C5  BD F0 0D     ...   LDA &0DF0,X              ; Get the page number of our private workspace from the ROM workspace table
82C8  85 B1        ..    STA pwrkspc+1            ; MSB of pointer to private workspace
82CA  BA           .     TSX
82CB  E8           .     INX
82CC  E8           .     INX
82CD  8A           .     TXA
82CE  A0 EC        ..    LDY #&EC
82D0  91 B0        ..    STA (pwrkspc),Y          ; Preserve the stackpointer
82D2  A0 03        ..    LDY #&03
82D4  B1 B0        ..    LDA (pwrkspc),Y
82D6  85 B9        ..    STA intflag
82D8  20 59 84      Y.   JSR &8459                ; ?(pwrkspc+&FF) = #&FF
82DB  58           X     CLI                      ; Set IRQ state back to normal
82DC  60           `     RTS

; -----------------------------------------------------------------------------
; OSWORD &80 call command lookup table MSB
; -----------------------------------------------------------------------------
.
82DD  84           .     EQUB &84                 ; (&84A1) command &00
82DE  84           .     EQUB &84                 ; (&8500) command &01
82DF  85           .     EQUB &85                 ; (&850B) command &02
82E0  85           .     EQUB &85                 ; (&8516) command &03
82E1  85           .     EQUB &85                 ; (&854A) command &04
82E2  85           .     EQUB &85                 ; (&85A8) command &05
82E3  85           .     EQUB &85                 ; (&85E6) command &06
82E4  85           .     EQUB &85                 ; (&85EC) command &07
82E5  86           .     EQUB &86                 ; (&8612) command &08
82E6  86           .     EQUB &86                 ; (&8630) command &09
82E7  86           .     EQUB &86                 ; (&8651) command &0A
82E8  86           .     EQUB &86                 ; (&86C8) command &0B
82E9  86           .     EQUB &86                 ; (&86D1) command &0C
82EA  87           .     EQUB &87                 ; (&8707) command &0D
82EB  86           .     EQUB &86                 ; (&86DA) command &0E
82EC  86           .     EQUB &86                 ; (&86E3) command &0F
82ED  87           .     EQUB &87                 ; (&871C) command &10
82EE  87           .     EQUB &87                 ; (&872C) command &11
82EF  87           .     EQUB &87                 ; (&8742) command &12
82F0  87           .     EQUB &87                 ; (&8776) command &13
82F1  87           .     EQUB &87                 ; (&87AA) command &14
82F2  87           .     EQUB &87                 ; (&87EF) command &15
82F3  87           .     EQUB &87                 ; (&87FB) command &16
82F4  88           .     EQUB &88                 ; (&8807) command &17
82F5  88           .     EQUB &88                 ; (&883B) command &18
82F6  88           .     EQUB &88                 ; (&886F) command &19
82F7  88           .     EQUB &88                 ; (&889B) command &1A
82F8  88           .     EQUB &88                 ; (&8889) command &1B
82F9  88           .     EQUB &88                 ; (&88AD) command &1C
82FA  88           .     EQUB &88                 ; (&88BC) command &1D
82FB  88           .     EQUB &88                 ; (&88CB) command &1E
82FC  88           .     EQUB &88                 ; (&88DA) command &1F
82FD  89           .     EQUB &89                 ; (&89E6) command &20
82FE  89           .     EQUB &89                 ; (&89E6) command &21
82FF  89           .     EQUB &89                 ; (&89E6) command &22
8300  8A           .     EQUB &8A                 ; (&8A30) command &23
8301  8A           .     EQUB &8A                 ; (&8A30) command &24
8302  8A           .     EQUB &8A                 ; (&8A30) command &25
8303  8A           .     EQUB &8A                 ; (&8A48) command &26
8304  8A           .     EQUB &8A                 ; (&8A74) command &27
8305  8A           .     EQUB &8A                 ; (&8A84) command &28
8306  8A           .     EQUB &8A                 ; (&8A93) command &29
8307  8A           .     EQUB &8A                 ; (&8AA9) command &2A
8308  8A           .     EQUB &8A                 ; (&8AC7) command &2B
8309  8B           .     EQUB &8B                 ; (&8B09) command &2C
830A  8B           .     EQUB &8B                 ; (&8B18) command &2D
830B  8B           .     EQUB &8B                 ; (&8B2C) command &2E
830C  8B           .     EQUB &8B                 ; (&8B3C) command &2F
830D  8B           .     EQUB &8B                 ; (&8B73) command &30
830E  8B           .     EQUB &8B                 ; (&8B96) command &31
830F  8B           .     EQUB &8B                 ; (&8BBB) command &32
8310  8B           .     EQUB &8B                 ; (&8BD9) command &33
8311  86           .     EQUB &86                 ; (&864E) command &34
8312  86           .     EQUB &86                 ; (&864E) command &35
8313  8B           .     EQUB &8B                 ; (&8BF7) command &36
8314  93           .     EQUB &93                 ; (&9328) command &37
8315  8C           .     EQUB &8C                 ; (&8C78) command &38
8316  93           .     EQUB &93                 ; (&9348) command &39
8317  8C           .     EQUB &8C                 ; (&8C93) command &3A
8318  93           .     EQUB &93                 ; (&9360) command &3B
8319  8C           .     EQUB &8C                 ; (&8CAE) command &3C
831A  93           .     EQUB &93                 ; (&9378) command &3D
831B  8C           .     EQUB &8C                 ; (&8CCF) command &3E
831C  93           .     EQUB &93                 ; (&9396) command &3F

; -----------------------------------------------------------------------------
; OSWORD &80 call command lookup table LSB
; -----------------------------------------------------------------------------
.
831D  A0           .     EQUB &A0
831E  FF           .     EQUB &FF
831F  0A           .     EQUB &0A
8320  15           .     EQUB &15
8321  49           I     EQUB &49
8322  A7           .     EQUB &A7
8323  E5           .     EQUB &E5
8324  EB           .     EQUB &EB
8325  11           .     EQUB &11
8326  2F           /     EQUB &2F
8327  50           P     EQUB &50
8328  C7           .     EQUB &C7
8329  D0           .     EQUB &D0
832A  06           .     EQUB &06
832B  D9           .     EQUB &D9
832C  E2           .     EQUB &E2
832D  1B           .     EQUB &1B
832E  2B           +     EQUB &2B
832F  41           A     EQUB &41
8330  75           u     EQUB &75
8331  A9           .     EQUB &A9
8332  EE           .     EQUB &EE
8333  FA           .     EQUB &FA
8334  06           .     EQUB &06
8335  3A           :     EQUB &3A
8336  6E           n     EQUB &6E
8337  9A           .     EQUB &9A
8338  88           .     EQUB &88
8339  AC           .     EQUB &AC
833A  BB           .     EQUB &BB
833B  CA           .     EQUB &CA
833C  D9           .     EQUB &D9
833D  E5           .     EQUB &E5
833E  E5           .     EQUB &E5
833F  E5           .     EQUB &E5
8340  2F           /     EQUB &2F
8341  2F           /     EQUB &2F
8342  2F           /     EQUB &2F
8343  47           G     EQUB &47
8344  73           s     EQUB &73
8345  83           .     EQUB &83
8346  92           .     EQUB &92
8347  A8           .     EQUB &A8
8348  C6           .     EQUB &C6
8349  08           .     EQUB &08
834A  17           .     EQUB &17
834B  2B           +     EQUB &2B
834C  3B           ;     EQUB &3B
834D  72           r     EQUB &72
834E  95           .     EQUB &95
834F  BA           .     EQUB &BA
8350  D8           .     EQUB &D8
8351  4D           M     EQUB &4D
8352  4D           M     EQUB &4D
8353  F6           .     EQUB &F6
8354  27           '     EQUB &27
8355  77           w     EQUB &77
8356  47           G     EQUB &47
8357  92           .     EQUB &92
8358  5F           _     EQUB &5F
8359  AD           .     EQUB &AD
835A  77           w     EQUB &77
835B  CE           .     EQUB &CE
835C  95           .     EQUB &95

; ------------------------------------------------------------------------------
; OSWORD &80 exit procedure
; ------------------------------------------------------------------------------
.
835D  78           x     SEI                      ; No IRQ's, please
835E  20 60 84      `.   JSR &8460                ; ?(pwrkspc+&FF) = #&00
8361  68           h     PLA                      ; Restore the contents of zeropage &B0-&BF (the filesystem's temporary workspace)
8362  85 BF        ..    STA &BF
8364  68           h     PLA
8365  85 BE        ..    STA &BE
8367  68           h     PLA
8368  85 BD        ..    STA timer+3
836A  68           h     PLA
836B  85 BC        ..    STA timer+2
836D  68           h     PLA
836E  85 BB        ..    STA timer+1
8370  68           h     PLA
8371  85 BA        ..    STA timer+0
8373  68           h     PLA
8374  85 B9        ..    STA intflag
8376  68           h     PLA
8377  85 B8        ..    STA length+2
8379  68           h     PLA
837A  85 B7        ..    STA length+1
837C  68           h     PLA
837D  85 B6        ..    STA length+0
837F  68           h     PLA
8380  85 B5        ..    STA memadr+3
8382  68           h     PLA
8383  85 B4        ..    STA memadr+2
8385  68           h     PLA
8386  85 B3        ..    STA memadr+1
8388  68           h     PLA
8389  85 B2        ..    STA memadr+0
838B  68           h     PLA
838C  85 B1        ..    STA pwrkspc+1
838E  68           h     PLA
838F  85 B0        ..    STA pwrkspc
8391  4C C1 80     L..   JMP &80C1                ; We've handled the call, so exit with A=&00

; ------------------------------------------------------------------------------
; Exit with error code A
; ------------------------------------------------------------------------------
.
8394  48           H     PHA                      ; X = Y
8395  98           .     TYA
8396  AA           .     TAX
8397  68           h     PLA
8398  A0 03        ..    LDY #&03
839A  91 F0        ..    STA (&F0),Y              ; XY+&03 = A
839C  A0 02        ..    LDY #&02
839E  B1 F0        ..    LDA (&F0),Y
83A0  C9 36        .6    CMP #&36                 ; Is it command 36-3F?
83A2  90 21        .!    BCC &83C5                ; Jump if OSWORD &80 command < &36
83A4  29 01        ).    AND #&01                 ; mask: 00000001
83A6  D0 06        ..    BNE &83AE                ; Branch if command is &37/&39/&3B/&3D/&3F (Read)
83A8  20 3A 8D      :.   JSR &8D3A                ; Command &36/&38/&3A/&3C/&3E (Write) : Store the number of bytes written in XY+&0A-&0D
83AB  4C C5 83     L..   JMP &83C5
.
83AE  A0 F6        ..    LDY #&F6
83B0  B1 B0        ..    LDA (pwrkspc),Y
83B2  29 04        ).    AND #&04                 ; Is the TUBE-active flag set in the read mode flag?
83B4  D0 0C        ..    BNE &83C2                ; Jump if it is
83B6  18           .     CLC                      ; \
83B7  8A           .     TXA                      ;  \
83B8  65 B2        e.    ADC memadr+0             ;   \
83BA  85 B2        ..    STA memadr+0             ;    memadr += X
83BC  A9 00        ..    LDA #&00                 ;   /
83BE  65 B3        e.    ADC memadr+1             ;  /
83C0  85 B3        ..    STA memadr+1             ; /
.
83C2  20 B4 93      ..   JSR &93B4                ; Store the number of bytes read in XY+&0A-&0D
.
83C5  A0 0A        ..    LDY #&0A
83C7  B1 B0        ..    LDA (pwrkspc),Y
83C9  F0 03        ..    BEQ &83CE                ; Check if the TUBE has been claimed
83CB  20 F9 92      ..   JSR reltube              ; If so, release the TUBE
.
83CE  A0 EC        ..    LDY #&EC                 ; Restore the stack pointer
83D0  B1 B0        ..    LDA (pwrkspc),Y
83D2  AA           .     TAX
83D3  9A           .     TXS
83D4  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; Service call &09 : *HELP command interception
; -----------------------------------------------------------------------------
.
83D7  68           h     PLA                      ; Pull Y register from stack
83D8  48           H     PHA                      ; Push it back for later use
83D9  A8           .     TAY                      ; 
.
83DA  B1 F2        ..    LDA (&F2),Y              ; Get the rest of the *HELP command
83DC  C8           .     INY                      ;
83DD  C9 20        .     CMP #&20                 ; Is it equal to SPACE?
83DF  F0 F9        ..    BEQ &83DA                ; Then get the next byte
83E1  C9 0D        ..    CMP #&0D                 ; Is it equal to CR?
83E3  D0 03        ..    BNE &83E8                ; Then exit
83E5  20 EB 83      ..   JSR &83EB                ; Else, display the help message
.
83E8  4C C7 80     L..   JMP &80C7                ; Jump to the exit routine
.
83EB  20 E7 FF      ..   JSR osnewl               ; Write a LF and CR to the output stream
83EE  A2 00        ..    LDX #&00                 ;
83F0  4C F7 83     L..   JMP &83F7                ; ...and start the display title routine
.
83F3  20 E3 FF      ..   JSR osasci               ; Display the character
83F6  E8           .     INX                      ;
.
83F7  BD 09 80     ...   LDA &8009,X              ; Load a character from the title string
83FA  C9 00        ..    CMP #&00                 ; Is it the end of the string?
83FC  D0 F5        ..    BNE &83F3                ; No? Then write it to the output stream
83FE  A9 20        .     LDA #&20                 ; Yes? Then write a SPACE to the output stream
8400  20 E3 FF      ..   JSR osasci
8403  A2 00        ..    LDX #&00
8405  4C 0C 84     L..   JMP &840C                ; ...and start the display version routine
.
8408  20 E3 FF      ..   JSR osasci               ; Display the character
840B  E8           .     INX
.
840C  BD 49 80     .I.   LDA &8049,X              ; Load a character from the version string
840F  C9 00        ..    CMP #&00                 ; Is it the end of the string?
8411  D0 F5        ..    BNE &8408                ; No? Then write it to the output stream
8413  20 E7 FF      ..   JSR osnewl               ; Yes? Then write a LF and CR to the output stream
8416  60           `     RTS                      ; And exit this subroutine

; -----------------------------------------------------------------------------
; Service call &22 : Claim absolute workspace in Hazel
; -----------------------------------------------------------------------------
.
8417  A6 F4        ..    LDX &F4                  ; X = this ROM number
8419  68           h     PLA
841A  A8           .     TAY                      ; Restore Y register (which contains the value of the first available page)
841B  9D F0 0D     ...   STA &0DF0,X              ; Store it in the ROM workspace table
841E  C8           .     INY                      ; Increase Y by the number of pages we need (one)
841F  98           .     TYA
8420  48           H     PHA                      ; And push it back on the stack
8421  20 E3 80      ..   JSR initwrkspc           ; Initialise the workspace
8424  4C C7 80     L..   JMP &80C7                ; Jump to the exit routine

; -----------------------------------------------------------------------------
; Service call &24 : Absolute workspace in Hazel count
; -----------------------------------------------------------------------------
.
8427  68           h     PLA
8428  A8           .     TAY
8429  88           .     DEY
842A  98           .     TYA
842B  48           H     PHA
842C  4C C7 80     L..   JMP &80C7                ; Jump to the exit routine

; -----------------------------------------------------------------------------
; Clear the 'Allow interrupts' flag                (procedure is never used???)
; -----------------------------------------------------------------------------
.
842F  A0 04        ..    LDY #&04
8431  A9 00        ..    LDA #&00
8433  91 B0        ..    STA (pwrkspc),Y
8435  60           `     RTS

; -----------------------------------------------------------------------------
; ?(pwrkspc+&05) = #&00
; -----------------------------------------------------------------------------
.
8436  A0 05        ..    LDY #&05
8438  A9 00        ..    LDA #&00
843A  91 B0        ..    STA (pwrkspc),Y
843C  60           `     RTS

; -----------------------------------------------------------------------------
; Clear the 'this controller is the active controller' flag
; -----------------------------------------------------------------------------
.
843D  A0 06        ..    LDY #&06
843F  A9 00        ..    LDA #&00
8441  91 B0        ..    STA (pwrkspc),Y
8443  60           `     RTS

; -----------------------------------------------------------------------------
; Set the 'Allow interrupts' flag
; -----------------------------------------------------------------------------
.
8444  A0 04        ..    LDY #&04
8446  A9 FF        ..    LDA #&FF
8448  91 B0        ..    STA (pwrkspc),Y
844A  60           `     RTS

; -----------------------------------------------------------------------------
; ?(pwrkspc+&05) = #&FF
; -----------------------------------------------------------------------------
.
844B  A0 05        ..    LDY #&05
844D  A9 FF        ..    LDA #&FF
844F  91 B0        ..    STA (pwrkspc),Y
8451  60           `     RTS

; -----------------------------------------------------------------------------
; Set the 'this controller is the active controller' flag
; -----------------------------------------------------------------------------
.
8452  A0 06        ..    LDY #&06
8454  A9 FF        ..    LDA #&FF
8456  91 B0        ..    STA (pwrkspc),Y
8458  60           `     RTS

; -----------------------------------------------------------------------------
; -----------------------------------------------------------------------------
.                                                 ; ?(pwrkspc+&FF) = #&FF
8459  A0 FF        ..    LDY #&FF
845B  A9 FF        ..    LDA #&FF
.
845D  91 B0        ..    STA (pwrkspc),Y
845F  60           `     RTS

; -----------------------------------------------------------------------------
; ?(pwrkspc+&FF) = #&00
; -----------------------------------------------------------------------------
.
8460  A0 FF        ..    LDY #&FF
8462  A9 00        ..    LDA #&00
8464  91 B0        ..    STA (pwrkspc),Y
8466  60           `     RTS

; -----------------------------------------------------------------------------
; Check if the OS version is valid
; -----------------------------------------------------------------------------
.checkos
8467  A2 01        ..    LDX #&01                 ; X = &01
8469  A9 00        ..    LDA #&00                 ; A = &00
846B  20 F4 FF     ..    JSR osbyte               ; Get the OS version
846E  E0 03        ..    CPX #&03                 ; Electrons, BBC's, BBC+'s  and Master 128's are okay
8470  60           `     RTS

; -----------------------------------------------------------------------------
; If (pwrkspc),&04 = &00 then exit with error code &01
; -----------------------------------------------------------------------------
.
8471  A0 04        ..    LDY #&04
8473  B1 B0        ..    LDA (pwrkspc),Y          ; Is the 'Allow interrupts' flag set?
8475  D0 05        ..    BNE &847C
8477  A9 01        ..    LDA #&01                 ; No? Then...
8479  4C 94 83     L..   JMP &8394                ; Exit with error code &01
847C  60           `     RTS                      ; Exit

; -----------------------------------------------------------------------------
; If (pwrkspc),&05 = &00 then exit with error code &02
; -----------------------------------------------------------------------------
.
847D  A0 05        ..    LDY #&05
847F  B1 B0        ..    LDA (pwrkspc),Y          ; Is (pwrkspc),&05 set to &00?
8481  D0 05        ..    BNE &8488
8483  A9 02        ..    LDA #&02                 ; Yes? Then...
8485  4C 94 83     L..   JMP &8394                ; Exit with error code &02
8488  60           `     RTS                      ; Exit

; -----------------------------------------------------------------------------
; Check if this controller is the active controller on the GPIB bus
; -----------------------------------------------------------------------------
.
8489  A0 06        ..    LDY #&06
848B  B1 B0        ..    LDA (pwrkspc),Y          ; Is (pwrkspc),&06 set to &00?
848D  D0 05        ..    BNE &8494
848F  A9 03        ..    LDA #&03                 ; Yes? Then...
8491  4C 94 83     L..   JMP &8394                ; Exit with error code &03
.
8494  60           `     RTS                      ; Exit

; -----------------------------------------------------------------------------
; Check if this controller is NOT the active controller on the GPIB bus
; -----------------------------------------------------------------------------
.
8495  A0 06        ..    LDY #&06
8497  B1 B0        ..    LDA (pwrkspc),Y          ; Is (pwrkspc),&06 not set to &00?
8499  F0 05        ..    BEQ &84A0
849B  A9 04        ..    LDA #&04                 ; No? Then...
849D  4C 94 83     L..   JMP &8394                ; Exit with error code &04
.
84A0  60           `     RTS                      ; Exit

; -----------------------------------------------------------------------------
; OSWORD call &80 command &00
; -----------------------------------------------------------------------------
.
84A1  78           x     SEI                      ; No IRQ's, please
84A2  A0 04        ..    LDY #&04
84A4  B1 B0        ..    LDA (pwrkspc),Y
84A6  A0 0D        ..    LDY #&0D
84A8  91 F0        ..    STA (&F0),Y              ; XY+&0D = 'Allow interrupts' flag
84AA  A0 05        ..    LDY #&05
84AC  B1 B0        ..    LDA (pwrkspc),Y
84AE  A0 0C        ..    LDY #&0C
84B0  91 F0        ..    STA (&F0),Y              ; XY+&0C = pwrkspc+&05
84B2  A0 06        ..    LDY #&06
84B4  B1 B0        ..    LDA (pwrkspc),Y
84B6  A0 0B        ..    LDY #&0B
84B8  91 F0        ..    STA (&F0),Y              ; XY+&0B = pwrkspc+&06
84BA  A0 F6        ..    LDY #&F6
84BC  B1 B0        ..    LDA (pwrkspc),Y
84BE  A0 05        ..    LDY #&05
84C0  91 F0        ..    STA (&F0),Y              ; XY+&05 = pwrkspc+&F6
84C2  A0 F7        ..    LDY #&F7
84C4  B1 B0        ..    LDA (pwrkspc),Y
84C6  A0 04        ..    LDY #&04
84C8  91 F0        ..    STA (&F0),Y              ; XY+&04 = pwrkspc+&F7
84CA  A0 03        ..    LDY #&03
84CC  B1 B0        ..    LDA (pwrkspc),Y
84CE  AA           .     TAX                      ; Temporary store pwrkspc+3 in X
84CF  A9 00        ..    LDA #&00
84D1  91 B0        ..    STA (pwrkspc),Y          ; pwrkspc+3 = &00
84D3  A0 09        ..    LDY #&09
84D5  8A           .     TXA                      ; Restore pwrkspc+3
84D6  91 F0        ..    STA (&F0),Y              ; XY+&09 = pwrkspc+3
84D8  A0 02        ..    LDY #&02
84DA  B1 B0        ..    LDA (pwrkspc),Y
84DC  AA           .     TAX                      ; Temporary store pwrkspc + 2 in X
84DD  A9 00        ..    LDA #&00
84DF  91 B0        ..    STA (pwrkspc),Y          ; pwrkspc + 2 = &00
84E1  A0 08        ..    LDY #&08
84E3  8A           .     TXA                      ; Restore pwrkspc+2
84E4  91 F0        ..    STA (&F0),Y              ; XY+&08 = pwrkspc+2
84E6  A0 07        ..    LDY #&07
84E8  AD 22 FC     .".   LDA addrstatus
84EB  91 F0        ..    STA (&F0),Y              ; XY+&07 = Address Status Register
84ED  A0 06        ..    LDY #&06
84EF  AD 26 FC     .&.   LDA busstatus
84F2  91 F0        ..    STA (&F0),Y              ; XY+&06 = Bus Status Register
84F4  A0 FE        ..    LDY #&FE
84F6  B1 B0        ..    LDA (pwrkspc),Y
84F8  A0 0A        ..    LDY #&0A
84FA  91 F0        ..    STA (&F0),Y              ; XY+&0A = pwrkspc + &FE
84FC  58           X     CLI                      ; Set IRQ state back to normal
84FD  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; OSWORD call &80 command &01
; -----------------------------------------------------------------------------
.
8500  A0 04        ..    LDY #&04
8502  B1 F0        ..    LDA (&F0),Y
8504  A0 FE        ..    LDY #&FE
8506  91 B0        ..    STA (pwrkspc),Y          ; pwrkspc+&FE = XY+&04
8508  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; OSWORD call &80 command &02
; -----------------------------------------------------------------------------
.
850B  A0 FE        ..    LDY #&FE
850D  B1 B0        ..    LDA (pwrkspc),Y
850F  A0 04        ..    LDY #&04
8511  91 F0        ..    STA (&F0),Y              ; XY+&04 = pwrkspc+&FE
8513  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; OSWORD call &80 command &03
; -----------------------------------------------------------------------------
.
8516  A0 00        ..    LDY #&00
8518  B1 F0        ..    LDA (&F0),Y
851A  C9 06        ..    CMP #&06                 ; Is XY+&00 = #&06?
851C  F0 15        ..    BEQ &8533                ; Yes? Then go to &8533
851E  C9 05        ..    CMP #&05                 ; Is XY+&00 = #&05?
8520  D0 25        .%    BNE &8547                ; No? Then exit the OSWORD &80 call
8522  20 7E 85      ~.   JSR &857E                ; ?&BE = ?(XY+&04)
8525  20 8C 85      ..   JSR &858C                ; ?(pwrkspc+&ED) = ?&BE
8528  A0 F7        ..    LDY #&F7
852A  B1 B0        ..    LDA (pwrkspc),Y
852C  29 FE        ).    AND #&FE
852E  91 B0        ..    STA (pwrkspc),Y          ; Clear bit 0 of pwrkspc+&F7
8530  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call
.
8533  20 7E 85      ~.   JSR &857E                ; ?&BE = ?(XY+&04)
8536  20 85 85      ..   JSR &8585                ; ?&BF = ?(XY+&05)
8539  20 8C 85      ..   JSR &858C                ; ?(pwrkspc+&ED) = ?&BE
853C  20 93 85      ..   JSR &8593                ; ?(pwrkspc+&EE) = ?&BF
853F  A0 F7        ..    LDY #&F7
8541  B1 B0        ..    LDA (pwrkspc),Y
8543  09 01        ..    ORA #&01
8545  91 B0        ..    STA (pwrkspc),Y          ; Set bit 0 of pwrkspc+&F7
.
8547  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; OSWORD call &80 command &04
; -----------------------------------------------------------------------------
854A  A0 00        ..    LDY #&00
854C  B1 F0        ..    LDA (&F0),Y
854E  C9 06        ..    CMP #&06
8550  F0 15        ..    BEQ &8567
8552  C9 05        ..    CMP #&05
8554  D0 25        .%    BNE &857B                ; Execute this code if XY+&00 = #&05
8556  20 7E 85      ~.   JSR &857E                ; ?&BE = ?(XY+&04)
8559  20 9A 85      ..   JSR &859A                ; ?(pwrkspc+&F8) = ?&BE
855C  A0 F6        ..    LDY #&F6
855E  B1 B0        ..    LDA (pwrkspc),Y
8560  29 FE        ).    AND #&FE
8562  91 B0        ..    STA (pwrkspc),Y          ; Clear bit 0 of pwrkspc+&F6
8564  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call
.                                                 ; Execute this code if XY+&00 = #&06
8567  20 7E 85      ~.   JSR &857E                ; ?&BE = ?(XY+&04)
856A  20 85 85      ..   JSR &8585                ; ?&BF = ?(XY+&05)
856D  20 9A 85      ..   JSR &859A                ; ?(pwrkspc+&F8) = ?&BE
8570  20 A1 85      ..   JSR &85A1                ; ?(pwrkspc+&F9) = ?&BF
8573  A0 F6        ..    LDY #&F6
8575  B1 B0        ..    LDA (pwrkspc),Y
8577  09 01        ..    ORA #&01
8579  91 B0        ..    STA (pwrkspc),Y          ; Set bit 0 of pwrkspc+&F6
.
857B  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; ?&BE = ?(XY+&04)
; -----------------------------------------------------------------------------
.
857E  A0 04        ..    LDY #&04
8580  B1 F0        ..    LDA (&F0),Y
8582  85 BE        ..    STA &BE
8584  60           `     RTS

; -----------------------------------------------------------------------------
; ?&BF = ?(XY+&05)
; -----------------------------------------------------------------------------
.
8585  A0 05        ..    LDY #&05
8587  B1 F0        ..    LDA (&F0),Y
8589  85 BF        ..    STA &BF
858B  60           `     RTS

; -----------------------------------------------------------------------------
; ?(pwrkspc+&ED) = ?&BE
; -----------------------------------------------------------------------------
.
858C  A0 ED        ..    LDY #&ED
858E  A5 BE        ..    LDA &BE
8590  91 B0        ..    STA (pwrkspc),Y
8592  60           `     RTS

; -----------------------------------------------------------------------------
; ?(pwrkspc+&EE) = ?&BF
; -----------------------------------------------------------------------------
.
8593  A0 EE        ..    LDY #&EE
8595  A5 BF        ..    LDA &BF
8597  91 B0        ..    STA (pwrkspc),Y
8599  60           `     RTS

; -----------------------------------------------------------------------------
; ?(pwrkspc+&F8) = ?&BE
; -----------------------------------------------------------------------------
.
859A  A0 F8        ..    LDY #&F8
859C  A5 BE        ..    LDA &BE
859E  91 B0        ..    STA (pwrkspc),Y
85A0  60           `     RTS

; -----------------------------------------------------------------------------
; ?(pwrkspc+&F9) = ?&BF
; -----------------------------------------------------------------------------
.
85A1  A0 F9        ..    LDY #&F9
85A3  A5 BF        ..    LDA &BF
85A5  91 B0        ..    STA (pwrkspc),Y
85A7  60           `     RTS

; -----------------------------------------------------------------------------
; OSWORD call &80 command &05
; -----------------------------------------------------------------------------
.
85A8  20 B1 85      ..   JSR &85B1
85AB  20 D0 85      ..   JSR &85D0
85AE  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; 
; -----------------------------------------------------------------------------
.
85B1  A0 04        ..    LDY #&04
85B3  38           8     SEC
85B4  A9 00        ..    LDA #&00
85B6  F1 F0        ..    SBC (&F0),Y
85B8  85 BA        ..    STA timer+0
85BA  C8           .     INY
85BB  A9 00        ..    LDA #&00
85BD  F1 F0        ..    SBC (&F0),Y
85BF  85 BB        ..    STA timer+1
85C1  C8           .     INY
85C2  A9 00        ..    LDA #&00
85C4  F1 F0        ..    SBC (&F0),Y
85C6  85 BC        ..    STA timer+2
85C8  C8           .     INY
85C9  A9 00        ..    LDA #&00
85CB  F1 F0        ..    SBC (&F0),Y
85CD  85 BD        ..    STA timer+3
85CF  60           `     RTS

; -----------------------------------------------------------------------------
; 
; -----------------------------------------------------------------------------
.
85D0  A0 FA        ..    LDY #&FA
85D2  A5 BA        ..    LDA timer+0
85D4  91 B0        ..    STA (pwrkspc),Y
85D6  C8           .     INY
85D7  A5 BB        ..    LDA timer+1
85D9  91 B0        ..    STA (pwrkspc),Y
85DB  C8           .     INY
85DC  A5 BC        ..    LDA timer+2
85DE  91 B0        ..    STA (pwrkspc),Y
85E0  C8           .     INY
85E1  A5 BD        ..    LDA timer+3
85E3  91 B0        ..    STA (pwrkspc),Y
85E5  60           `     RTS

; -----------------------------------------------------------------------------
; OSWORD call &80 command &06
; -----------------------------------------------------------------------------
.
85E6  20 F2 85     ..    JSR &85F2
85E9  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; OSWORD call &80 command &07
; -----------------------------------------------------------------------------
.
85EC  20 02 86      ..   JSR &8602
85EF  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; 
; -----------------------------------------------------------------------------
.
85F2  A0 F6        ..    LDY #&F6
85F4  B1 B0        ..    LDA (pwrkspc),Y
85F6  09 02        ..    ORA #&02                 ; Set bit 1 of (pwrkspc),&F6
85F8  91 B0        ..    STA (pwrkspc),Y
85FA  C8           .     INY
85FB  B1 B0        ..    LDA (pwrkspc),Y
85FD  09 02        ..    ORA #&02                 ; Set bit 1 of (pwrkspc),&F7
85FF  91 B0        ..    STA (pwrkspc),Y
8601  60           `     RTS

; -----------------------------------------------------------------------------
; 
; -----------------------------------------------------------------------------
.
8602  A0 F6        ..    LDY #&F6
8604  B1 B0        ..    LDA (pwrkspc),Y
8606  29 FD        ).    AND #&FD                 ; Clear bit 1 of (pwrkspc),&F6
8608  91 B0        ..    STA (pwrkspc),Y
860A  C8           .     INY
860B  B1 B0        ..    LDA (pwrkspc),Y
860D  29 FD        ).    AND #&FD                 ; Clear bit 1 of (pwrkspc),&F7
860F  91 B0        ..    STA (pwrkspc),Y
8611  60           `     RTS

; -----------------------------------------------------------------------------
; OSWORD call &80 command &08
; -----------------------------------------------------------------------------
.
8612  A0 04        ..    LDY #&04
8614  B1 F0        ..    LDA (&F0),Y
8616  20 1C 86      ..   JSR &861C
8619  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; 
; -----------------------------------------------------------------------------
.
861C  29 03        ).    AND #&03                 ; 00000011
861E  AA           .     TAX
861F  A0 F7        ..    LDY #&F7
8621  B1 B0        ..    LDA (pwrkspc),Y
8623  29 07        ).    AND #&07                 ; 00000111
8625  91 B0        ..    STA (pwrkspc),Y
8627  8A           .     TXA
8628  0A           .     ASL A
8629  0A           .     ASL A
862A  0A           .     ASL A
862B  11 B0        ..    ORA (pwrkspc),Y
862D  91 B0        ..    STA (pwrkspc),Y
862F  60           `     RTS

; -----------------------------------------------------------------------------
; OSWORD call &80 command &09
; -----------------------------------------------------------------------------
.
8630  A0 04        ..    LDY #&04
8632  B1 F0        ..    LDA (&F0),Y
8634  20 3A 86      :.   JSR &863A
8637  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call


; -----------------------------------------------------------------------------
; 
; -----------------------------------------------------------------------------
.
863A  29 03        ).    AND #&03                 ; 00000011
863C  AA           .     TAX
863D  A0 F6        ..    LDY #&F6
863F  B1 B0        ..    LDA (pwrkspc),Y
8641  29 07        ).    AND #&07                 ; 00000111
8643  91 B0        ..    STA (pwrkspc),Y
8645  8A           .     TXA
8646  0A           .     ASL A
8647  0A           .     ASL A
8648  0A           .     ASL A
8649  11 B0        ..    ORA (pwrkspc),Y
864B  91 B0        ..    STA (pwrkspc),Y
864D  60           `     RTS

; -----------------------------------------------------------------------------
; OSWORD call &80 command &34/&35
; -----------------------------------------------------------------------------
.
864E  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; OSWORD call &80 command &0A
; -----------------------------------------------------------------------------
.
8651  20 57 86      W.   JSR &8657                ; Perform soft-reset and initialise controller and workspace
8654  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; Perform soft-reset and initialise controller and workspace
; -----------------------------------------------------------------------------
.
8657  A2 00        ..    LDX #&00                 ; X = &00
8659  A0 FF        ..    LDY #&FF                 ; Y = &FF
865B  A9 EA        ..    LDA #&EA                 ; A = &EA
865D  20 F4 FF      ..   JSR osbyte               ; Check if the TUBE is active
8660  8A           .     TXA
8661  F0 02        ..    BEQ &8665                ; Nope, it's not active
8663  A9 04        ..    LDA #&04                 ; Yes, it's active
.
8665  AA           .     TAX
8666  A0 F6        ..    LDY #&F6
8668  11 B0        ..    ORA (pwrkspc),Y          ; Set bit 2 of (pwrkspc),&F6 if the tube is active
866A  91 B0        ..    STA (pwrkspc),Y
866C  8A           .     TXA
866D  C8           .     INY
866E  11 B0        ..    ORA (pwrkspc),Y          ; Set bit 2 of (pwrkspc),&F7 if the tube is active
8670  91 B0        ..    STA (pwrkspc),Y
8672  78           x     SEI                      ; No IRQ's, please
8673  A9 80        ..    LDA #set+swrst           ; Load the mnemonic for the 'Software reset' function
8675  8D 26 FC     .&.   STA auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
8678  A0 0A        ..    LDY #&0A
.
867A  B9 0B 81     ...   LDA &810B,Y
867D  91 B0        ..    STA (pwrkspc),Y
867F  88           .     DEY
8680  10 F8        ..    BPL &867A
8682  A9 00        ..    LDA #&00                 ; 00000000: No interrupts from the Interrupt Register 0 please
8684  8D 20 FC     . .   STA intmask0
8687  A9 EB        ..    LDA #&EB                 ; 11101011: Interrupts are allowed for the IFC, SQR, MA, APT, ERR and GET flags from the Interrupt Register 1
8689  8D 24 FC     .$.   STA intmask1
868C  A9 00        ..    LDA #&00
868E  8D 25 FC     .%.   STA serpoll
8691  8D 23 FC     .#.   STA parpoll
8694  A9 83        ..    LDA #set+hdfa            ; Load the mnemonic for the 'Set Holdoff on all data' function
8696  8D 26 FC     .&.   STA auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
8699  A0 FE        ..    LDY #&FE
869B  B1 B0        ..    LDA (pwrkspc),Y          ; Load A with the primary address for the TMS9914A
869D  AA           .     TAX
869E  29 1F        ).    AND #&1F                 ; 00011111
86A0  8D 21 FC     .!.   STA address
86A3  09 40        .@    ORA #&40                 ; 01000000
86A5  A0 00        ..    LDY #&00
86A7  91 B0        ..    STA (pwrkspc),Y          ; MTA (My Talk Address)
86A9  8A           .     TXA
86AA  29 1F        ).    AND #&1F
86AC  09 20        .     ORA #&20                 ; 00100000
86AE  A0 01        ..    LDY #&01
86B0  91 B0        ..    STA (pwrkspc),Y          ; MLA (My Listen Address)
86B2  8A           .     TXA
86B3  30 06        0.    BMI &86BB                ; Branch if bit 7 of (pwrkspc),&FE was set
86B5  20 36 84      6.   JSR &8436                ; ?(pwrkspc+&05) = #&00
86B8  4C BE 86     L..   JMP &86BE
.
86BB  20 4B 84      K.   JSR &844B                ; ?(pwrkspc+&05) = #&FF
.
86BE  20 44 84      D.   JSR &8444                ; Set the 'Allow interrupts' flag
86C1  A9 00        ..    LDA #clr+swrst           ; Load the mnemonic for the 'Clear Software reset' function
86C3  8D 26 FC     .&.   STA auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
86C6  58           X     CLI                      ; Set IRQ state back to normal
86C7  60           `     RTS

; -----------------------------------------------------------------------------
; OSWORD call &80 command &0B
; -----------------------------------------------------------------------------
.
86C8  20 7D 84      }.   JSR &847D                ; If (pwrkspc),&05 = &00 then exit with error code &02
86CB  20 EC 86      ..   JSR &86EC                ; Set Send interface clear
86CE  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; OSWORD call &80 command &0C
; -----------------------------------------------------------------------------
.
86D1  20 7D 84      }.   JSR &847D                ; If (pwrkspc),&05 = &00 then exit with error code &02
86D4  20 F5 86      ..   JSR &86F5                ; Clear Send interface clear
86D7  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; OSWORD call &80 command &0E
; -----------------------------------------------------------------------------
.
86DA  20 7D 84      }.   JSR &847D                ; If (pwrkspc),&05 = &00 then exit with error code &02
86DD  20 FB 86      ..   JSR &86FB                ; Set Send remote enable
86E0  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; OSWORD call &80 command &0F
; -----------------------------------------------------------------------------
.
86E3  20 7D 84      }.   JSR &847D                ; If (pwrkspc),&05 = &00 then exit with error code &02
86E6  20 01 87      ..   JSR &8701                ; Clear Send remote enable
86E9  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; Set Send interface clear
; -----------------------------------------------------------------------------
.
86EC  A9 8F        ..    LDA #set+sic             ; Load the mnemonic for the 'Set Send interface clear' function
86EE  8D 26 FC     .&.   STA auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
86F1  20 52 84      R.   JSR &8452                ; Set the 'this controller is the active controller' flag
86F4  60           `     RTS

; -----------------------------------------------------------------------------
; Clear Send interface clear
; -----------------------------------------------------------------------------
.
86F5  A9 0F        ..    LDA #clr+sic             ; Load the mnemonic for the 'Clear Send interface clear' function
86F7  8D 26 FC     .&.   STA auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
86FA  60           `     RTS

; -----------------------------------------------------------------------------
; Set Send remote enable
; -----------------------------------------------------------------------------
.
86FB  A9 90        ..    LDA #set+sre             ; Load the mnemonic for the 'Set Send remote enable' function
86FD  8D 26 FC     .&.   STA auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
8700  60           `     RTS

; -----------------------------------------------------------------------------
; Clear Send remote enable
; -----------------------------------------------------------------------------
.
8701  A9 10        ..    LDA #clr+sre             ; Load the mnemonic for the 'Clear Send remote enable' function
8703  8D 26 FC     .&.   STA auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
8706  60           `     RTS

; -----------------------------------------------------------------------------
; OSWORD call &80 command &0D
; -----------------------------------------------------------------------------
.
8707  20 7D 84      }.   JSR &847D                ; If (pwrkspc),&05 = &00 then exit with error code &02
870A  20 10 87      ..   JSR &8710                ; Strobe Set interface clear
870D  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; Strobe Set interface clear
; -----------------------------------------------------------------------------
.
8710  20 EC 86      ..   JSR &86EC                ; Set Send interface clear
8713  A2 FF        ..    LDX #&FF
.                                                 ; delay 256 * (2+3) = 1280 clockcycles
8715  CA           .     DEX                      ; 2 clockcycles
8716  D0 FD        ..    BNE &8715                ; 3 clockcycles
8718  20 F5 86      ..   JSR &86F5                ; Clear Send interface clear
871B  60           `     RTS

; -----------------------------------------------------------------------------
; OSWORD call &80 command &10
; -----------------------------------------------------------------------------
.
871C  A0 04        ..    LDY #&04
871E  B1 F0        ..    LDA (&F0),Y
8720  29 7F        )    AND #&7F                 ; 01111111
8722  A0 FE        ..    LDY #&FE
8724  91 B0        ..    STA (pwrkspc),Y
8726  20 57 86      W.   JSR &8657                ; Perform soft-reset and initialise controller and workspace
8729  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; OSWORD call &80 command &11
; -----------------------------------------------------------------------------
.
872C  A0 04        ..    LDY #&04
872E  B1 F0        ..    LDA (&F0),Y
8730  09 80        ..    ORA #&80                 ; 10000000
8732  A0 FE        ..    LDY #&FE
8734  91 B0        ..    STA (pwrkspc),Y
8736  20 57 86      W.   JSR &8657                ; Perform soft-reset and initialise controller and workspace
8739  20 FB 86      ..   JSR &86FB                ; Set Send remote enable
873C  20 10 87      ..   JSR &8710                ; Strobe Set interface clear
873F  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; OSWORD call &80 command &12
; -----------------------------------------------------------------------------
.
8742  20 89 84      ..   JSR &8489                ; Check if this controller is the active controller on the GPIB bus
8745  20 4B 87      K.   JSR &874B                ; Call OSWORD &80 command &12
8748  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; 
; -----------------------------------------------------------------------------
.
874B  AD 26 FC     .&.   LDA busstatus
874E  29 80        ).    AND #&80                 ; Is the REN bit (bit 7) set in the TMS9914A's Bus Status register?
8750  D0 23        .#    BNE &8775
8752  AD 22 FC     .".   LDA addrstatus
8755  29 0A        ).    AND #&0A
8757  D0 14        ..    BNE &876D                ; Branch if either the LPAS bit (bit 3) or the LLO bit (bit 1) are set
8759  A9 0C        ..    LDA #clr+tca             ; Load the mnemonic for the 'Take control asynchronously' function
875B  8D 26 FC     .&.   STA auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
875E  AD 22 FC     .".   LDA addrstatus
8761  29 14        ).    AND #&14
8763  D0 10        ..    BNE &8775                ; Branch if either the LADS bit (bit 5) or the ATN bit (bit 2) are set
8765  A9 16        ..    LDA #clr+shdw            ; Load the mnemonic for the 'Clear Shadow handshake' function
8767  8D 26 FC     .&.   STA auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
876A  4C 75 87     Lu.   JMP &8775
.
876D  20 93 92      ..   JSR &9293                ; Wait for END with or without timer (if (pwrkspc),&F7bit1=1 then with timer, else without timer)
8770  A9 0C        ..    LDA #clr+tca             ; Load the mnemonic for the 'Take control asynchronously' function
8772  8D 26 FC     .&.   STA auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
.
8775  60           `     RTS

; -----------------------------------------------------------------------------
; OSWORD call &80 command &13
; -----------------------------------------------------------------------------
.
8776  20 89 84      ..   JSR &8489                ; Check if this controller is the active controller on the GPIB bus
8779  20 7F 87      .   JSR &877F
877C  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; 
; -----------------------------------------------------------------------------
.
877F  AD 26 FC     .&.   LDA busstatus
8782  29 80        ).    AND #&80                 ; Is the REN bit (bit 7) set in the TMS9914A's Bus Status register?
8784  D0 23        .#    BNE &87A9
8786  AD 22 FC     .".   LDA addrstatus
8789  29 0A        ).    AND #&0A
878B  D0 14        ..    BNE &87A1                ; Branch if either the LPAS bit (bit 3) or the LLO bit (bit 1) are set
878D  A9 0D        ..    LDA #clr+tcs             ; Load the mnemonic for the 'Take control synchronously' function
878F  8D 26 FC     .&.   STA auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
8792  AD 22 FC     .".   LDA addrstatus
8795  29 14        ).    AND #&14                 ; Branch if either the TPAS bit (bit 4) or the ATN bit (bit 2) are set
8797  D0 10        ..    BNE &87A9
8799  A9 16        ..    LDA #clr+shdw            ; Load the mnemonic for the 'Clear Shadow handshake' function
879B  8D 26 FC     .&.   STA auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
879E  4C A9 87     L..   JMP &87A9
.
87A1  20 93 92      ..   JSR &9293                ; Wait for END with or without timer (if (pwrkspc),&F7bit1=1 then with timer, else without timer)
87A4  A9 0C        ..    LDA #clr+tca             ; Load the mnemonic for the 'Take control asynchronously' function
87A6  8D 26 FC     .&.   STA auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
.
87A9  60           `     RTS

; -----------------------------------------------------------------------------
; OSWORD call &80 command &14
; -----------------------------------------------------------------------------
.
87AA  20 89 84      ..   JSR &8489                ; Check if this controller is the active controller on the GPIB bus
87AD  20 4B 87      K.   JSR &874B                ; Call OSWORD &80 command &12
87B0  A0 00        ..    LDY #&00
87B2  B1 F0        ..    LDA (&F0),Y
87B4  AA           .     TAX
87B5  CA           .     DEX
87B6  CA           .     DEX
87B7  CA           .     DEX
87B8  CA           .     DEX
87B9  F0 2A        .*    BEQ &87E5
87BB  A0 04        ..    LDY #&04
.
87BD  8A           .     TXA
87BE  48           H     PHA
87BF  98           .     TYA
87C0  48           H     PHA
87C1  B1 F0        ..    LDA (&F0),Y
87C3  AA           .     TAX
87C4  29 E0        ).    AND #&E0                 ; 11100000
87C6  C9 20        .     CMP #&20                 ; 00100000
87C8  F0 0A        ..    BEQ &87D4
87CA  C9 40        .@    CMP #&40                 ; 01000000
87CC  F0 0C        ..    BEQ &87DA
87CE  20 E8 87      ..   JSR &87E8                ; bit 7 is set
87D1  4C DD 87     L..   JMP &87DD
.
87D4  20 A2 89      ..   JSR &89A2                ; bit 5 is set
87D7  4C DD 87     L..   JMP &87DD
.
87DA  20 6D 89      m.   JSR &896D                ; bit 6 is set
.
87DD  68           h     PLA
87DE  A8           .     TAY
87DF  68           h     PLA
87E0  AA           .     TAX
87E1  C8           .     INY
87E2  CA           .     DEX
87E3  D0 D8        ..    BNE &87BD
.
87E5  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; 
; -----------------------------------------------------------------------------
.
87E8  20 93 92      ..   JSR &9293                ; Wait for END with or without timer (if (pwrkspc),&F7bit1=1 then with timer, else without timer)
87EB  8E 27 FC     .'.   STX datout               ; Send X to the TMS9914A's Data Out Register
87EE  60           `     RTS

; -----------------------------------------------------------------------------
; OSWORD call &80 command &15
; -----------------------------------------------------------------------------
.
87EF  20 89 84      ..   JSR &8489                ; Check if this controller is the active controller on the GPIB bus
87F2  20 D4 89      ..   JSR &89D4                ; X = XY+&04
87F5  20 13 88      ..   JSR &8813
87F8  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; OSWORD call &80 command &16
; -----------------------------------------------------------------------------
.
87FB  20 89 84      ..   JSR &8489                ; Check if this controller is the active controller on the GPIB bus
87FE  20 DA 89      ..   JSR &89DA                ; X = XY+&04, A = XY+&O5
8801  20 22 88      ".   JSR &8822
8804  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; OSWORD call &80 command &17
; -----------------------------------------------------------------------------
.
8807  20 89 84      ..   JSR &8489                ; Check if this controller is the active controller on the GPIB bus
880A  20 D4 89      ..   JSR &89D4                ; X = XY+&04
880D  20 47 88      G.   JSR &8847
8810  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; 
; -----------------------------------------------------------------------------
.
8813  8A           .     TXA
8814  48           H     PHA
8815  20 4B 87      K.   JSR &874B                ; Call OSWORD &80 command &12
8818  68           h     PLA
8819  29 1F        ).    AND #&1F                 ; 00011111
881B  09 20        .     ORA #&20                 ; 00100000 (Set bit 5)
881D  AA           .     TAX
881E  20 A2 89      ..   JSR &89A2                ; MLA (My Listen Address)
8821  60           `     RTS

; -----------------------------------------------------------------------------
; 
; -----------------------------------------------------------------------------
.
8822  48           H     PHA
8823  8A           .     TXA
8824  48           H     PHA
8825  20 4B 87      K.   JSR &874B                ; Call OSWORD &80 command &12
8828  68           h     PLA
8829  29 1F        ).    AND #&1F                 ; 00011111
882B  09 20        .     ORA #&20                 ; 00100000 (Set bit 5)
882D  AA           .     TAX
882E  20 A2 89      ..   JSR &89A2                ; MLA (My Listen Address)
8831  68           h     PLA
8832  29 1F        ).    AND #&1F                 ; 00011111
8834  09 60        .`    ORA #&60                 ; 01100000 (Set bits 6 and 5)
8836  AA           .     TAX
8837  20 E8 87      ..   JSR &87E8                ; MSA (My Secondary Address)
883A  60           `     RTS

; -----------------------------------------------------------------------------
; OSWORD call &80 command &18
; -----------------------------------------------------------------------------
.
883B  20 89 84      ..   JSR &8489                ; Check if this controller is the active controller on the GPIB bus
883E  20 DA 89      ..   JSR &89DA                ; X = XY+&04, A = XY+&O5
8841  20 56 88      V.   JSR &8856
8844  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; 
; -----------------------------------------------------------------------------
.
8847  8A           .     TXA
8848  48           H     PHA
8849  20 4B 87      K.   JSR &874B                ; Call OSWORD &80 command &12
884C  68           h     PLA
884D  29 1F        ).    AND #&1F                 ; 00011111
884F  09 40        .@    ORA #&40                 ; 01000000 (Set bit 6)
8851  AA           .     TAX
8852  20 6D 89      m.   JSR &896D                ; MTA (My Talk Address)
8855  60           `     RTS

; -----------------------------------------------------------------------------
; 
; -----------------------------------------------------------------------------
.
8856  48           H     PHA
8857  8A           .     TXA
8858  48           H     PHA
8859  20 4B 87      K.   JSR &874B                ; Call OSWORD &80 command &12
885C  68           h     PLA
885D  29 1F        ).    AND #&1F                 ; 00011111
885F  09 40        .@    ORA #&40                 ; 01000000 (Set bit 6)
8861  AA           .     TAX
8862  20 6D 89      m.   JSR &896D                ; MTA (My Talk Address)
8865  68           h     PLA
8866  29 1F        ).    AND #&1F                 ; 00011111
8868  09 60        .`    ORA #&60                 ; 01100000 (Set bit 6)
886A  AA           .     TAX
886B  20 E8 87      ..   JSR &87E8                ; MSA (My Secondary Address)
886E  60           `     RTS

; -----------------------------------------------------------------------------
; OSWORD call &80 command &19
; -----------------------------------------------------------------------------
.
886F  20 89 84      ..   JSR &8489                ; Check if this controller is the active controller on the GPIB bus
8872  20 E1 89      ..   JSR &89E1                ; A = XY+&O5
8875  20 7B 88      {.   JSR &887B
8878  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; 
; -----------------------------------------------------------------------------
.
887B  48           H     PHA
887C  20 4B 87      K.   JSR &874B                ; Call OSWORD &80 command &12
887F  68           h     PLA
8880  29 1F        ).    AND #&1F                 ; 00011111
8882  09 60        .`    ORA #&60                 ; 01100000
8884  AA           .     TAX
8885  20 E8 87      ..   JSR &87E8                ; MSA (My Secondary Address)
8888  60           `     RTS

; -----------------------------------------------------------------------------
; OSWORD call &80 command &1B
; -----------------------------------------------------------------------------
.
8889  20 89 84      ..   JSR &8489                ; Check if this controller is the active controller on the GPIB bus
888C  20 92 88      ..   JSR &8892                ; Send UNT
888F  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; Send UNT
; -----------------------------------------------------------------------------
.
8892  20 4B 87      K.   JSR &874B                ; Call OSWORD &80 command &12
8895  A2 5F        ._    LDX #&5F                 ; UNT (Untalk)
8897  20 6D 89      m.   JSR &896D
889A  60           `     RTS

; -----------------------------------------------------------------------------
; OSWORD call &80 command &1A
; -----------------------------------------------------------------------------
.
889B  20 89 84      ..   JSR &8489                ; Check if this controller is the active controller on the GPIB bus
889E  20 A4 88      ..   JSR &88A4                ; Send UNL
88A1  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; Send UNL
; -----------------------------------------------------------------------------
.
88A4  20 4B 87      K.   JSR &874B                ; Call OSWORD &80 command &12
88A7  A2 3F        .?    LDX #&3F                 ; UNL (Unlisten)
88A9  20 A2 89      ..   JSR &89A2
88AC  60           `     RTS

; -----------------------------------------------------------------------------
; OSWORD call &80 command &1C
; -----------------------------------------------------------------------------
.
88AD  20 89 84      ..   JSR &8489                ; Check if this controller is the active controller on the GPIB bus
88B0  20 D4 89      ..   JSR &89D4                ; X = XY+&04
88B3  20 E9 88      ..   JSR &88E9                ; Send UNL, MTA (pwrkspc,&00) and MLA (X)
88B6  20 51 8A      Q.   JSR &8A51                ; Conditional GTS (Go To Standby)
88B9  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; OSWORD call &80 command &1D
; -----------------------------------------------------------------------------
.
88BC  20 89 84      ..   JSR &8489                ; Check if this controller is the active controller on the GPIB bus
88BF  20 DA 89      ..   JSR &89DA                ; X = XY+&04, A = XY+&O5
88C2  20 05 89      ..   JSR &8905                ; Send UNL, MTA (pwrkspc,&00), MLA (X) and MSA (A)
88C5  20 51 8A      Q.   JSR &8A51                ; Conditional GTS (Go To Standby)
88C8  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; OSWORD call &80 command &1E
; -----------------------------------------------------------------------------
.
88CB  20 89 84      ..   JSR &8489                ; Check if this controller is the active controller on the GPIB bus
88CE  20 D4 89      ..   JSR &89D4                ; X = XY+&04
88D1  20 2B 89      +.   JSR &892B                ; Send UNL, MLA (pwrkspc,&01) and MTA (X)
88D4  20 51 8A      Q.   JSR &8A51                ; Conditional GTS (Go To Standby)
88D7  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; OSWORD call &80 command &1F
; -----------------------------------------------------------------------------
.
88DA  20 89 84      ..   JSR &8489                ; Check if this controller is the active controller on the GPIB bus
88DD  20 DA 89      ..   JSR &89DA                ; X = XY+&04, A = XY+&O5
88E0  20 47 89      G.   JSR &8947                ; Send UNL, MLA (pwrkspc,&01), MTA (X) and MSA (A)
88E3  20 51 8A      Q.   JSR &8A51                ; Conditional GTS (Go To Standby)
88E6  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; 
; -----------------------------------------------------------------------------
.
88E9  8A           .     TXA
88EA  48           H     PHA
88EB  20 4B 87      K.   JSR &874B                ; Call OSWORD &80 command &12
88EE  A2 3F        .?    LDX #&3F                 ; UNL (Unlisten)
88F0  20 A2 89      ..   JSR &89A2
88F3  A0 00        ..    LDY #&00
88F5  B1 B0        ..    LDA (pwrkspc),Y
88F7  AA           .     TAX
88F8  20 6D 89      m.   JSR &896D                ; MTA (My Talk Address)
88FB  68           h     PLA
88FC  29 1F        ).    AND #&1F                 ; 00011111
88FE  09 20        .     ORA #&20                 ; 00100000
8900  AA           .     TAX
8901  20 A2 89      ..   JSR &89A2                ; MLA (My Listen Address)
8904  60           `     RTS

; -----------------------------------------------------------------------------
; 
; -----------------------------------------------------------------------------
.
8905  48           H     PHA
8906  8A           .     TXA
8907  48           H     PHA
8908  20 4B 87      K.   JSR &874B                ; Call OSWORD &80 command &12
890B  A2 3F        .?    LDX #&3F                 ; UNL (Unlisten)
890D  20 A2 89      ..   JSR &89A2
8910  A0 00        ..    LDY #&00
8912  B1 B0        ..    LDA (pwrkspc),Y
8914  AA           .     TAX
8915  20 6D 89      m.   JSR &896D                ; MTA (My Talk Address)
8918  68           h     PLA
8919  29 1F        ).    AND #&1F                 ; 00011111
891B  09 20        .     ORA #&20                 ; 00100000
891D  AA           .     TAX
891E  20 A2 89      ..   JSR &89A2                ; MLA (My Listen Address)
8921  68           h     PLA
8922  29 1F        ).    AND #&1F                 ; 00011111
8924  09 60        .`    ORA #&60                 ; 01100000
8926  AA           .     TAX
8927  20 E8 87      ..   JSR &87E8                ; MSA (My Secondary Address)
892A  60           `     RTS

; -----------------------------------------------------------------------------
; 
; -----------------------------------------------------------------------------
.
892B  8A           .     TXA
892C  48           H     PHA
892D  20 4B 87      K.   JSR &874B                ; Call OSWORD &80 command &12
8930  A2 3F        .?    LDX #&3F                 ; UNL (Unlisten)
8932  20 A2 89      ..   JSR &89A2
8935  A0 01        ..    LDY #&01
8937  B1 B0        ..    LDA (pwrkspc),Y
8939  AA           .     TAX
893A  20 A2 89      ..   JSR &89A2                ; MLA (My Listen Address)
893D  68           h     PLA
893E  29 1F        ).    AND #&1F                 ; 00011111
8940  09 40        .@    ORA #&40                 ; 01000000
8942  AA           .     TAX
8943  20 6D 89      m.   JSR &896D                ; MTA (My Talk Address)
8946  60           `     RTS

; -----------------------------------------------------------------------------
; 
; -----------------------------------------------------------------------------
.
8947  48           H     PHA
8948  8A           .     TXA
8949  48           H     PHA
894A  20 4B 87      K.   JSR &874B                ; Call OSWORD &80 command &12
894D  A2 3F        .?    LDX #&3F                 ; UNL (Unlisten)
894F  20 A2 89      ..   JSR &89A2
8952  A0 01        ..    LDY #&01
8954  B1 B0        ..    LDA (pwrkspc),Y
8956  AA           .     TAX
8957  20 A2 89      ..   JSR &89A2                ; MLA (My Listen Address)
895A  68           h     PLA
895B  29 1F        ).    AND #&1F
895D  09 40        .@    ORA #&40
895F  AA           .     TAX
8960  20 6D 89      m.   JSR &896D                ; MTA (My Talk Address)
8963  68           h     PLA
8964  29 1F        ).    AND #&1F
8966  09 60        .`    ORA #&60
8968  AA           .     TAX
8969  20 E8 87      ..   JSR &87E8                ; MSA (My Secondary Address)
896C  60           `     RTS

; -----------------------------------------------------------------------------
; 
; -----------------------------------------------------------------------------
.
896D  AD 22 FC     .".   LDA addrstatus
8970  29 0A        ).    AND #&0A                 ; 00001010
8972  D0 1B        ..    BNE &898F                ; Branch if either the LPAS bit (bit 3) or the LLO bit (bit 1) are set
8974  A0 00        ..    LDY #&00
8976  8A           .     TXA
8977  D1 B0        ..    CMP (pwrkspc),Y          ; Compare A with MTA (My Talk Address)
8979  D0 20        .     BNE &899B
897B  AD 22 FC     .".   LDA addrstatus
897E  29 14        ).    AND #&14                 ; 00010100
8980  F0 05        ..    BEQ &8987                ; Branch if the LADS bit (bit 4) and the ATN bit (bit 2) are both clear
8982  A9 09        ..    LDA #clr+lon             ; Load the mnemonic for the 'Clear Listen only' function
8984  8D 26 FC     .&.   STA auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
.
8987  A9 8A        ..    LDA #set+ton             ; Load the mnemonic for the 'Set Talk Only' function
8989  8D 26 FC     .&.   STA auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
898C  4C 9B 89     L..   JMP &899B
.
898F  A0 00        ..    LDY #&00
8991  8A           .     TXA
8992  D1 B0        ..    CMP (pwrkspc),Y          ; Compare A with MTA (My Talk Address)
8994  F0 05        ..    BEQ &899B
8996  A9 0A        ..    LDA #clr+ton             ; Load the mnemonic for the 'Clear Talk only' function
8998  8D 26 FC     .&.   STA auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
.
899B  20 93 92      ..   JSR &9293                ; Wait for END with or without timer (if (pwrkspc),&F7bit1=1 then with timer, else without timer)
899E  8E 27 FC     .'.   STX datout               ; Send X to the TMS9914A's Data Out Register
89A1  60           `     RTS

; -----------------------------------------------------------------------------
; 
; -----------------------------------------------------------------------------
.
89A2  AD 22 FC     .".   LDA addrstatus
89A5  29 14        ).    AND #&14                 ; 00010100
89A7  D0 1B        ..    BNE &89C4                ; Branch if either the LADS bit (bit 4) or the ATN bit (bit 2) are set
89A9  A0 01        ..    LDY #&01
89AB  8A           .     TXA
89AC  D1 B0        ..    CMP (pwrkspc),Y          ; Compare A with MLA (My Listen Address)
89AE  D0 1D        ..    BNE &89CD
89B0  AD 22 FC     .".   LDA addrstatus
89B3  29 0A        ).    AND #&0A                 ; 00001010
89B5  F0 05        ..    BEQ &89BC                ; Branch if the LPAS bit (bit 3) and the LLO bit (bit 1) are both clear
89B7  A9 0A        ..    LDA #clr+ton             ; Load the mnemonic for the 'Clear Talk only' function
89B9  8D 26 FC     .&.   STA auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
.
89BC  A9 89        ..    LDA #set+lon             ; Load the mnemonic for the 'Set Listen only' function
89BE  8D 26 FC     .&.   STA auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
89C1  4C CD 89     L..   JMP &89CD
.
89C4  E0 3F        .?    CPX #&3F                 ; Is the command UNL (Unlisten)?
89C6  D0 05        ..    BNE &89CD
89C8  A9 09        ..    LDA #clr+lon             ; Load the mnemonic for the 'Clear Listen only' function
89CA  8D 26 FC     .&.   STA auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
.
89CD  20 93 92      ..   JSR &9293                ; Wait for END with or without timer (if (pwrkspc),&F7bit1=1 then with timer, else without timer)
89D0  8E 27 FC     .'.   STX datout               ; Send X to the TMS9914A's Data Out Register
89D3  60           `     RTS

; -----------------------------------------------------------------------------
; X=XY+&04 
; -----------------------------------------------------------------------------
.
89D4  A0 04        ..    LDY #&04
89D6  B1 F0        ..    LDA (&F0),Y
89D8  AA           .     TAX
89D9  60           `     RTS

; -----------------------------------------------------------------------------
; X=XY+&04, A=XY+&05
; -----------------------------------------------------------------------------
.
89DA  20 D4 89      ..   JSR &89D4                ; X = XY+&04
89DD  20 E1 89      ..   JSR &89E1                ; A = XY+&O5
89E0  60           `     RTS

; -----------------------------------------------------------------------------
; A=XY+&05
; -----------------------------------------------------------------------------
.
89E1  A0 05        ..    LDY #&05
89E3  B1 F0        ..    LDA (&F0),Y
89E5  60           `     RTS

; -----------------------------------------------------------------------------
; OSWORD call &80 command &20/&21/&22
; -----------------------------------------------------------------------------
.
89E6  20 89 84      ..   JSR &8489                ; Check if this controller is the active controller on the GPIB bus
89E9  A0 00        ..    LDY #&00
89EB  B1 F0        ..    LDA (&F0),Y
89ED  AA           .     TAX
89EE  CA           .     DEX
89EF  CA           .     DEX
89F0  CA           .     DEX
89F1  CA           .     DEX
89F2  F0 36        .6    BEQ &8A2A                ; Jump if there weren't any parameters given
89F4  A0 04        ..    LDY #&04
89F6  8A           .     TXA
89F7  48           H     PHA
89F8  98           .     TYA
89F9  48           H     PHA
89FA  B1 F0        ..    LDA (&F0),Y
89FC  AA           .     TAX
89FD  20 E9 88      ..   JSR &88E9                ; Send UNL, MTA (pwrkspc,&00) and MLA (X)
8A00  68           h     PLA
8A01  A8           .     TAY
8A02  68           h     PLA
8A03  AA           .     TAX
8A04  C8           .     INY
8A05  CA           .     DEX
8A06  F0 16        ..    BEQ &8A1E
.
8A08  8A           .     TXA
8A09  48           H     PHA
8A0A  98           .     TYA
8A0B  48           H     PHA
8A0C  B1 F0        ..    LDA (&F0),Y
8A0E  29 1F        ).    AND #&1F                 ; 00011111
8A10  09 20        .     ORA #&20                 ; 00100000 (Set bit 5)
8A12  AA           .     TAX
8A13  20 A2 89      ..   JSR &89A2                ; MLA (My Listen Address)
8A16  68           h     PLA
8A17  A8           .     TAY
8A18  68           h     PLA
8A19  AA           .     TAX
8A1A  C8           .     INY
8A1B  CA           .     DEX
8A1C  D0 EA        ..    BNE &8A08
.
8A1E  A0 02        ..    LDY #&02
8A20  B1 F0        ..    LDA (&F0),Y
8A22  AA           .     TAX
8A23  BD 0D 8A     ...   LDA &8A0D,X
8A26  AA           .     TAX
8A27  20 E8 87      ..   JSR &87E8
.
8A2A  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call
.
8A2D  01           .     EQUB &01                 ; X = 01 (GTL; Go To Local) at 8A27 when OSWORD &80 command &20 is called
8A2E  04           .     EQUB &04                 ; X = 04 (SDC; Selected Device Clear) at 8A27 when OSWORD &80 command &21 is called
8A2F  08           .     EQUB &08                 ; X = 08 (GET; Group Execute Trigger) at 8A27 when OSWORD &80 command &22 is called

; -----------------------------------------------------------------------------
; OSWORD call &80 command &23/&24/&25
; -----------------------------------------------------------------------------
.
8A30  20 89 84      ..   JSR &8489                ; Check if this controller is the active controller on the GPIB bus
8A33  20 4B 87      K.   JSR &874B                ; Call OSWORD &80 command &12
8A36  A0 02        ..    LDY #&02
8A38  B1 F0        ..    LDA (&F0),Y
8A3A  AA           .     TAX
8A3B  BD 22 8A     .".   LDA &8A22,X
8A3E  AA           .     TAX
8A3F  20 E8 87      ..   JSR &87E8
8A42  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

.
8A45  11           .     EQUB &11                 ; X = 11 (LLO; Local Lockout) at 8A3F when OSWORD &80 command &23 is called
8A46  14           .     EQUB &14                 ; X = 14 (DCL; Device Clear) at 8A3F when OSWORD &80 command &24 is called
8A47  15           .     EQUB &15                 ; X = 15 (PPU; Parallel Poll Unconfigure) at 8A3F when OSWORD &80 command &25 is called

; -----------------------------------------------------------------------------
; OSWORD call &80 command &26
; -----------------------------------------------------------------------------
.
8A48  20 89 84      ..   JSR &8489                ; Check if this controller is the active controller on the GPIB bus
8A4B  20 51 8A      .Q   JSR &8A51                ; Conditional GTS (Go To Standby)
8A4E  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; 
; -----------------------------------------------------------------------------
.
8A51  AD 26 FC     .&.   LDA busstatus
8A54  29 80        ).    AND #&80                 ; Is bit 2 (REN) set in the TMS9914A's Bus Status register?
8A56  F0 1B        ..    BEQ &8A73
8A58  AD 22 FC     .".   LDA addrstatus
8A5B  29 0A        ).    AND #&0A
8A5D  D0 0C        ..    BNE &8A6B                ; Branch if either the LPAS bit (bit 3) or the LLO bit (bit 1) are set
8A5F  AD 22 FC     .".   LDA addrstatus
8A62  29 14        ).    AND #&14
8A64  D0 05        ..    BNE &8A6B                ; Branch if either the LADS bit (bit 4) or the ATN bit (bit 2) are set
8A66  A9 96        ..    LDA #set+shdw            ; Load the mnemonic for the 'Set Shadow handshake' function
8A68  8D 26 FC     .&.   STA auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
.
8A6B  20 93 92      ..   JSR &9293                ; Wait for END with or without timer (if (pwrkspc),&F7bit1=1 then with timer, else without timer)
8A6E  A9 0B        ..    LDA #clr+gts             ; Load the mnemonic for the 'Go to standby' function
8A70  8D 26 FC     .&.   STA auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
.
8A73  60           `     RTS

; -----------------------------------------------------------------------------
; OSWORD call &80 command &27
; -----------------------------------------------------------------------------
.
8A74  A0 04        ..    LDY #&04
8A76  B1 F0        ..    LDA (&F0),Y
8A78  20 7E 8A      ~.   JSR &8A7E
8A7B  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; 
; -----------------------------------------------------------------------------
.
8A7E  29 BF        ).    AND #&BF                 ; 10111111
8A80  8D 25 FC     .%.   STA serpoll
8A83  60           `     RTS

; -----------------------------------------------------------------------------
; OSWORD call &80 command &28
; -----------------------------------------------------------------------------
.
8A84  20 95 84      ..   JSR &8495                ; Check if this controller is NOT the active controller on the GPIB bus
8A87  20 8D 8A      ..   JSR &8A8D                ; Send the mnemonic Set Request service bit 2 to the TMS9914A's Auxiliary Command Register
8A8A  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; 
; -----------------------------------------------------------------------------
.
8A8D  A9 98        ..    LDA #set+rsv2            ; Load the mnemonic for the 'Set Request service bit 2' function
8A8F  8D 26 FC     .&.   STA auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
8A92  60           `     RTS

; -----------------------------------------------------------------------------
; OSWORD call &80 command &29
; -----------------------------------------------------------------------------
.
8A93  20 95 84      ..   JSR &8495                ; Check if this controller is NOT the active controller on the GPIB bus
8A96  A0 04        ..    LDY #&04
8A98  B1 F0        ..    LDA (&F0),Y
8A9A  48           H     PHA
8A9B  20 7E 8A      ~.   JSR &8A7E
8A9E  68           h     PLA
8A9F  29 40        )@    AND #&40                 ; Is bit 6 of XY+&04 set?
8AA1  F0 03        ..    BEQ &8AA6
8AA3  20 8D 8A      ..   JSR &8A8D                ; Send the mnemonic Set Request service bit 2 to the TMS9914A's Auxiliary Command Register
.
8AA6  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; OSWORD call &80 command &2A
; -----------------------------------------------------------------------------
.
8AA9  A0 05        ..    LDY #&05
8AAB  B1 F0        ..    LDA (&F0),Y
8AAD  AA           .     TAX                      ; X = XY+&05
8AAE  88           .     DEY
8AAF  B1 F0        ..    LDA (&F0),Y              ; A = XY+&04
8AB1  20 B7 8A      ..   JSR &8AB7
8AB4  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; 
; -----------------------------------------------------------------------------
.
8AB7  78           x     SEI                      ; No IRQ's, please
8AB8  38           8     SEC
8AB9  A0 F3        ..    LDY #&F3
8ABB  E9 01        ..    SBC #&01
8ABD  91 B0        ..    STA (pwrkspc),Y          ; (pwrkspc),&F3 = A - 1
8ABF  8A           .     TXA
8AC0  C8           .     INY
8AC1  E9 00        ..    SBC #&00
8AC3  91 B0        ..    STA (pwrkspc),Y          ; (pwrkspc),&F4 = X - C
8AC5  58           X     CLI                      ; Set IRQ state back to normal
8AC6  60           `     RTS

; -----------------------------------------------------------------------------
; OSWORD call &80 command &2B
; -----------------------------------------------------------------------------
.
8AC7  20 89 84      ..   JSR &8489                ; Check if this controller is the active controller on the GPIB bus
8ACA  20 D4 89      ..   JSR &89D4                ; X = XY+&04
8ACD  20 D7 8A      ..   JSR &8AD7
8AD0  A0 05        ..    LDY #&05
8AD2  91 F0        ..    STA (&F0),Y              ; Store result in XY+&05
8AD4  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; 
; -----------------------------------------------------------------------------
.
8AD7  20 2B 89      +.   JSR &892B                ; Send UNL, MLA (pwrkspc,&01) and MTA (X)
8ADA  A2 18        ..    LDX #&18                 ; SPE (Serial Poll Enable)
8ADC  20 E8 87      ..   JSR &87E8
8ADF  20 51 8A      Q.   JSR &8A51                ; Conditional GTS (Go To Standby)
8AE2  20 1F 9C      ..   JSR &9C1F
8AE5  A0 F6        ..    LDY #&F6
8AE7  B1 B0        ..    LDA (pwrkspc),Y
8AE9  29 02        ).    AND #&02                 ; Is bit 1 of (pwrkspc),&F6 set?
8AEB  D0 06        ..    BNE &8AF3                ; Yes, then jump
8AED  20 51 9B      Q.   JSR &9B51                ; Wait for SPAS without timer
8AF0  4C F6 8A     L..   JMP &8AF6
.
8AF3  20 83 9B      ..   JSR &9B83                ; Wait for SPAS with timer
.
8AF6  AD 27 FC     .'.   LDA datin
8AF9  48           H     PHA
8AFA  20 4B 87      K.   JSR &874B                ; Call OSWORD &80 command &12
8AFD  A2 19        ..    LDX #&19                 ; SPD (Serial Poll Disable)
8AFF  20 E8 87      ..   JSR &87E8
8B02  A2 5F        ._    LDX #&5F                 ; UNT (Untalk)
8B04  20 6D 89      m.   JSR &896D
8B07  68           h     PLA
8B08  60           `     RTS

; -----------------------------------------------------------------------------
; OSWORD call &80 command &2C
; -----------------------------------------------------------------------------
.
8B09  20 13 8B      ..   JSR &8B13                ; A = (pwrkspc),&09
8B0C  A0 04        ..    LDY #&04
8B0E  91 F0        ..    STA (&F0),Y
8B10  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; 
; -----------------------------------------------------------------------------
.
8B13  A0 09        ..    LDY #&09
8B15  B1 B0        ..    LDA (pwrkspc),Y
8B17  60           `     RTS

; -----------------------------------------------------------------------------
; OSWORD call &80 command &2D
; -----------------------------------------------------------------------------
.
8B18  A0 04        ..    LDY #&04
8B1A  B1 F0        ..    LDA (&F0),Y
8B1C  29 08        ).    AND #&08                 ; Mask-out bit 3
8B1E  20 24 8B      $.   JSR &8B24                ; 
8B21  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; 
; -----------------------------------------------------------------------------
.
8B24  A0 F5        ..    LDY #&F5
8B26  91 B0        ..    STA (pwrkspc),Y
8B28  20 5A 82      Z.   JSR &825A
8B2B  60           `     RTS

; -----------------------------------------------------------------------------
; OSWORD call &80 command &2E
; -----------------------------------------------------------------------------
.
8B2C  20 89 84      ..   JSR &8489                ; Check if this controller is the active controller on the GPIB bus
8B2F  20 D4 89      ..   JSR &89D4                ; X = XY+&04
8B32  A0 05        ..    LDY #&05
8B34  B1 F0        ..    LDA (&F0),Y              ; A = XY+&05
8B36  20 48 8B      H.   JSR &8B48
8B39  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; OSWORD call &80 command &2F
; -----------------------------------------------------------------------------
.
8B3C  20 89 84      ..   JSR &8489                ; Check if this controller is the active controller on the GPIB bus
8B3F  20 D4 89      ..   JSR &89D4                ; X = XY+&04
8B42  20 60 8B      `.   JSR &8B60
8B45  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; 
; -----------------------------------------------------------------------------
.
8B48  48           H     PHA
8B49  20 E9 88      ..   JSR &88E9                ; Send UNL, MTA (pwrkspc,&00) and MLA (X)
8B4C  A2 05        ..    LDX #&05                 ; PPC (Parallel Poll Configure)
8B4E  20 E8 87      ..   JSR &87E8
8B51  68           h     PLA
8B52  29 0F        ).    AND #&0F                 ; 00001111
8B54  09 60        .`    ORA #&60                 ; 01100000
8B56  AA           .     TAX
8B57  20 E8 87      ..   JSR &87E8                ; PPE (Parallel Poll Enable)
8B5A  A2 3F        .?    LDX #&3F                 ; UNL (Unlisten)
8B5C  20 A2 89      ..   JSR &89A2
8B5F  60           `     RTS

; -----------------------------------------------------------------------------
; 
; -----------------------------------------------------------------------------
.
8B60  20 E9 88      ..   JSR &88E9                ; Send UNL, MTA (pwrkspc,&00) and MLA (X)
8B63  A2 05        ..    LDX #&05
8B65  20 E8 87      ..   JSR &87E8                ; PPC (Parallel Poll Configure)
8B68  A2 70        .p    LDX #&70
8B6A  20 E8 87      ..   JSR &87E8                ; PPD (Parallel Poll Disable
8B6D  A2 3F        .?    LDX #&3F                 ; UNL (Unlisten)
8B6F  20 A2 89      ..   JSR &89A2
8B72  60           `     RTS

; -----------------------------------------------------------------------------
; OSWORD call &80 command &30
; -----------------------------------------------------------------------------
.
8B73  20 89 84      ..   JSR &8489                ; Check if this controller is the active controller on the GPIB bus
8B76  20 80 8B      ..   JSR &8B80
8B79  A0 04        ..    LDY #&04
8B7B  91 F0        ..    STA (&F0),Y
8B7D  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; 
; -----------------------------------------------------------------------------
.
8B80  20 4B 87      K.   JSR &874B                ; Call OSWORD &80 command &12
8B83  20 93 92      ..   JSR &9293                ; Wait for END with or without timer (if (pwrkspc),&F7bit1=1 then with timer, else without timer)
8B86  A9 8E        ..    LDA #set+rpp             ; Load the mnemonic for the 'Set Request parallel poll' function
8B88  8D 26 FC     .&.   STA auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
8B8B  EA           .     NOP                      ; Wait at least 2æs
8B8C  EA           .     NOP                      ; 1 NOP = 2 clockcycles
8B8D  AD 23 FC     .#.   LDA cmdpassthru
8B90  A2 0E        ..    LDX #clr+rpp             ; Load the mnemonic for the 'Clear Request parallel poll' function
8B92  8E 26 FC     .&.   STX auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
8B95  60           `     RTS

; -----------------------------------------------------------------------------
; OSWORD call &80 command &31
; -----------------------------------------------------------------------------
.
8B96  20 89 84      ..   JSR &8489                ; Check if this controller is the active controller on the GPIB bus
8B99  20 D4 89      ..   JSR &89D4                ; X = XY+&04
8B9C  20 A2 8B      ..   JSR &8BA2
8B9F  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; 
; -----------------------------------------------------------------------------
.
8BA2  20 2B 89      +.   JSR &892B                ; Send UNL, MLA (pwrkspc,&01) and MTA (X)
8BA5  A2 3F        .?    LDX #&3F                 ; UNL (Unlisten)
8BA7  20 A2 89      ..   JSR &89A2
8BAA  A2 09        ..    LDX #&09
8BAC  20 E8 87      ..   JSR &87E8                ; SPD (Serial Poll Disable)
8BAF  20 93 92      ..   JSR &9293                ; Wait for END with or without timer (if (pwrkspc),&F7bit1=1 then with timer, else without timer)
8BB2  A9 12        ..    LDA #rlc                 ; Load the mnemonic for the 'Release control' function
8BB4  8D 26 FC     .&.   STA auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
8BB7  20 3D 84      =.   JSR &843D                ; ?(pwrkspc+&06) = #&00
8BBA  60           `     RTS

; -----------------------------------------------------------------------------
; OSWORD call &80 command &32
; -----------------------------------------------------------------------------
.
8BBB  A0 05        ..    LDY #&05
8BBD  B1 F0        ..    LDA (&F0),Y
8BBF  AA           .     TAX                      ; X = XY+&05
8BC0  88           .     DEY
8BC1  B1 F0        ..    LDA (&F0),Y              ; A = XY+&04
8BC3  20 C9 8B      ..   JSR &8BC9
8BC6  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; 
; -----------------------------------------------------------------------------
.
8BC9  78           x     SEI                      ; No IRQ's, please
8BCA  38           8     SEC
8BCB  A0 EF        ..    LDY #&EF
8BCD  E9 01        ..    SBC #&01
8BCF  91 B0        ..    STA (pwrkspc),Y
8BD1  8A           .     TXA
8BD2  C8           .     INY
8BD3  E9 00        ..    SBC #&00
8BD5  91 B0        ..    STA (pwrkspc),Y
8BD7  58           X     CLI                      ; Set IRQ state back to normal
8BD8  60           `     RTS

; -----------------------------------------------------------------------------
; OSWORD call &80 command &33
; -----------------------------------------------------------------------------
.
8BD9  A0 05        ..    LDY #&05
8BDB  B1 F0        ..    LDA (&F0),Y
8BDD  AA           .     TAX
8BDE  88           .     DEY
8BDF  B1 F0        ..    LDA (&F0),Y
8BE1  20 E7 8B      ..   JSR &8BE7
8BE4  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; 
; -----------------------------------------------------------------------------
.
8BE7  78           x     SEI                      ; No IRQ's, please
8BE8  38           8     SEC
8BE9  A0 F1        ..    LDY #&F1
8BEB  E9 01        ..    SBC #&01
8BED  91 B0        ..    STA (pwrkspc),Y
8BEF  8A           .     TXA
8BF0  C8           .     INY
8BF1  E9 00        ..    SBC #&00
8BF3  91 B0        ..    STA (pwrkspc),Y
8BF5  58           X     CLI                      ; Set IRQ state back to normal
8BF6  60           `     RTS

; -----------------------------------------------------------------------------
; OSWORD call &80 command &36
; -----------------------------------------------------------------------------
.
8BF7  20 F0 8C      ..   JSR &8CF0                ; Transfer XY+&06-&09 to 'memadr' and XY+&0A-&0C to 'length'
8BFA  20 AE 8D      ..   JSR &8DAE                ; Check if nr. of bytes to be transferred > 0
8BFD  20 71 84      q.   JSR &8471                ; If (pwrkspc),&04 = &00 then exit with error code &01
8C00  A0 F7        ..    LDY #&F7
8C02  B1 B0        ..    LDA (pwrkspc),Y
8C04  29 02        ).    AND #&02                 ; Is bit 1 set?
8C06  F0 06        ..    BEQ &8C0E
8C08  20 34 8C      4.   JSR &8C34                ; Wait for REN=0 with timer
8C0B  4C 11 8C     L..   JMP &8C11
.
8C0E  20 1A 8C      ..   JSR &8C1A                ; Wait for REN=0 without timer
.
8C11  20 60 8D      `.   JSR &8D60                ; OSWORD &80 commands &36/&38/&3A/&3C/&3E (Write) Jump to subroutine
8C14  20 3A 8D      :.   JSR &8D3A                ; Store the number of bytes written in XY+&0A-&0D
8C17  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; Wait for REN=0 without timer
; -----------------------------------------------------------------------------
.
8C1A  A5 B9        ..    LDA intflag
8C1C  D0 08        ..    BNE &8C26                ; Is &B9 = 0?
8C1E  AD 26 FC     .&.   LDA busstatus            ; Yes, it is
8C21  29 80        ).    AND #&80                 ; Is the REN bit (bit 7) set in the TMS9914A's Bus Status register?
8C23  D0 F5        ..    BNE &8C1A
8C25  60           `     RTS
.
8C26  29 01        ).    AND #&01                 ; Is bit 0 of &B9 set?
8C28  D0 05        ..    BNE &8C2F
8C2A  A9 06        ..    LDA #&06
8C2C  4C 94 83     L..   JMP &8394                ; No, then exit with error code &06
.
8C2F  A9 05        ..    LDA #&05
8C31  4C 94 83     L..   JMP &8394                ; Yes, then exit with error code &05

; -----------------------------------------------------------------------------
; Wait for REN=0 with timer
; -----------------------------------------------------------------------------
.
8C34  A0 FA        ..    LDY #&FA
8C36  B1 B0        ..    LDA (pwrkspc),Y
8C38  85 BA        ..    STA timer+0              ; timer+0 = (pwrkspc),&FA
8C3A  C8           .     INY
8C3B  B1 B0        ..    LDA (pwrkspc),Y
8C3D  85 BB        ..    STA timer+1              ; timer+1 = (pwrkspc),&FB
8C3F  C8           .     INY
8C40  B1 B0        ..    LDA (pwrkspc),Y
8C42  85 BC        ..    STA timer+2              ; timer+2 = (pwrkspc),&FC
8C44  C8           .     INY
8C45  B1 B0        ..    LDA (pwrkspc),Y
8C47  85 BD        ..    STA timer+3              ; timer+3 = (pwrkspc),&FD
.
8C49  E6 BA         ..   INC timer+0
8C4B  D0 11        ..    BNE &8C5E
8C4D  E6 BB         ..   INC timer+1
8C4F  D0 0D        ..    BNE &8C5E
8C51  E6 BC         ..   INC timer+2
8C53  D0 09        ..    BNE &8C5E
8C55  E6 BD         ..   INC timer+3
8C57  D0 05        ..    BNE &8C5E
8C59  A9 07         ..   LDA #&07                 ; Timer has timed out
8C5B  4C 94 83     L..   JMP &8394                ; Exit with error code &07
.
8C5E  A5 B9        ..    LDA intflag
8C60  D0 08        ..    BNE &8C6A                ; Is &B9 = 0?
8C62  AD 26 FC     .&.   LDA busstatus            ; Yes, it is
8C65  29 80        ).    AND #&80                 ; Is the REN bit (bit 7) set in the TMS9914A's Bus Status register?
8C67  D0 E0        ..    BNE &8C49
8C69  60           `     RTS
.
8C6A  29 01        ).    AND #&01                 ; Is bit 0 of &B9 set?
8C6C  D0 05        ..    BNE &8C73
8C6E  A9 06        ..    LDA #&06
8C70  4C 94 83     L..   JMP &8394                ; No, then exit with error code &06
.
8C73  A9 05        ..    LDA #&05
8C75  4C 94 83     L..   JMP &8394                ; Yes, then exit with error code &05

; -----------------------------------------------------------------------------
; OSWORD call &80 command &38
; -----------------------------------------------------------------------------
.
8C78  20 F0 8C      ..   JSR &8CF0                ; Transfer XY+&06-&09 to 'memadr' and XY+&0A-&0C to 'length'
8C7B  20 AE 8D      ..   JSR &8DAE                ; Check if nr. of bytes to be transferred > 0
8C7E  20 89 84      ..   JSR &8489                ; Check if this controller is the active controller on the GPIB bus
8C81  20 D4 89      ..   JSR &89D4                ; X = XY+&04
8C84  20 E9 88      ..   JSR &88E9                ; Send UNL, MTA (pwrkspc,&00) and MLA (X)
8C87  20 51 8A      Q.   JSR &8A51                ; Conditional GTS (Go To Standby)
8C8A  20 60 8D      `.   JSR &8D60                ; OSWORD &80 commands &36/&38/&3A/&3C/&3E (Write) Jump to subroutine
8C8D  20 3A 8D      :.   JSR &8D3A                ; Store the number of bytes written in XY+&0A-&0D
8C90  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; OSWORD call &80 command &3A
; -----------------------------------------------------------------------------
.
8C93  20 F0 8C      ..   JSR &8CF0                ; Transfer XY+&06-&09 to 'memadr' and XY+&0A-&0C to 'length'
8C96  20 AE 8D      ..   JSR &8DAE                ; Check if nr. of bytes to be transferred > 0
8C99  20 89 84      ..   JSR &8489                ; Check if this controller is the active controller on the GPIB bus
8C9C  20 DA 89      ..   JSR &89DA                ; X = XY+&04, A = XY+&O5
8C9F  20 05 89      ..   JSR &8905                ; Send UNL, MTA (pwrkspc,&00), MLA (X) and MSA (A)
8CA2  20 51 8A      Q.   JSR &8A51                ; Conditional GTS (Go To Standby)
8CA5  20 60 8D      `.   JSR &8D60                ; OSWORD &80 commands &36/&38/&3A/&3C/&3E (Write) Jump to subroutine
8CA8  20 3A 8D      :.   JSR &8D3A                ; Store the number of bytes written in XY+&0A-&0D
8CAB  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; OSWORD call &80 command &3C
; -----------------------------------------------------------------------------
.
8CAE  20 F0 8C      ..   JSR &8CF0                ; Transfer XY+&06-&09 to 'memadr' and XY+&0A-&0C to 'length'
8CB1  20 AE 8D      ..   JSR &8DAE                ; Check if nr. of bytes to be transferred > 0
8CB4  20 89 84      ..   JSR &8489                ; Check if this controller is the active controller on the GPIB bus
8CB7  20 D4 89      ..   JSR &89D4                ; X = XY+&04
8CBA  20 E9 88      ..   JSR &88E9                ; Send UNL, MTA (pwrkspc,&00) and MLA (X)
8CBD  20 51 8A      Q.   JSR &8A51                ; Conditional GTS (Go To Standby)
8CC0  20 60 8D      `.   JSR &8D60                ; OSWORD &80 commands &36/&38/&3A/&3C/&3E (Write) Jump to subroutine
8CC3  20 3A 8D      :.   JSR &8D3A                ; Store the number of bytes written in XY+&0A-&0D
8CC6  20 A4 88      ..   JSR &88A4                ; Send UNL
8CC9  20 51 8A      Q.   JSR &8A51                ; Conditional GTS (Go To Standby)
8CCC  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; OSWORD call &80 command &3E
; -----------------------------------------------------------------------------
.
8CCF  20 F0 8C      ..   JSR &8CF0                ; Transfer XY+&06-&09 to 'memadr' and XY+&0A-&0C to 'length'
8CD2  20 AE 8D      ..   JSR &8DAE                ; Check if nr. of bytes to be transferred > 0
8CD5  20 89 84      ..   JSR &8489                ; Check if this controller is the active controller on the GPIB bus
8CD8  20 DA 89      ..   JSR &89DA                ; X = XY+&04, A = XY+&O5
8CDB  20 05 89      ..   JSR &8905                ; Send UNL, MTA (pwrkspc,&00), MLA (X) and MSA (A)
8CDE  20 51 8A      Q.   JSR &8A51                ; Conditional GTS (Go To Standby)
8CE1  20 60 8D      `.   JSR &8D60                ; OSWORD &80 commands &36/&38/&3A/&3C/&3E (Write) Jump to subroutine
8CE4  20 3A 8D      :.   JSR &8D3A                ; Store the number of bytes written in XY+&0A-&0D
8CE7  20 A4 88      ..   JSR &88A4                ; Send UNL
8CEA  20 51 8A      Q.   JSR &8A51                ; Conditional GTS (Go To Standby)
8CED  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; Transfer XY+&06-&09 to 'memadr' and XY+&0A-&0C to 'length'
; -----------------------------------------------------------------------------
.
8CF0  A0 06        ..    LDY #&06
8CF2  B1 F0        ..    LDA (&F0),Y
8CF4  85 B2        ..    STA memadr+0             ; memadr+0 = XY+&06
8CF6  C8           .     INY
8CF7  B1 F0        ..    LDA (&F0),Y
8CF9  85 B3        ..    STA memadr+1             ; memadr+1 = XY+&07
8CFB  C8           .     INY
8CFC  B1 F0        ..    LDA (&F0),Y
8CFE  85 B4        ..    STA memadr+2             ; memadr+2 = XY+&08
8D00  C8           .     INY
8D01  B1 F0        ..    LDA (&F0),Y
8D03  85 B5        ..    STA memadr+3             ; memadr+3 = XY+&09
8D05  A0 F7        ..    LDY #&F7
8D07  B1 B0        ..    LDA (pwrkspc),Y
8D09  29 04        ).    AND #&04                 ; Is the TUBE-active flag set in the write mode flag?
8D0B  D0 15        ..    BNE &8D22
8D0D  A0 0A        ..    LDY #&0A                 ; TUBE is not active
8D0F  38           8     SEC
8D10  A9 00        ..    LDA #&00
8D12  F1 F0        ..    SBC (&F0),Y
8D14  85 B6        ..    STA length+0             ; &B6 = 0 - XY+&0A
8D16  C8           .     INY
8D17  A9 00        ..    LDA #&00
8D19  F1 F0        ..    SBC (&F0),Y
8D1B  85 B7        ..    STA length+1             ; &B7 = 0 - XY+&0B - C
8D1D  A9 00        ..    LDA #&00
8D1F  85 B8        ..    STA length+2             ; &B8 = 0
8D21  60           `     RTS
.                                                 ; TUBE is active
8D22  A0 0A        ..    LDY #&0A
8D24  38           8     SEC
8D25  A9 00        ..    LDA #&00
8D27  F1 F0        ..    SBC (&F0),Y
8D29  85 B6        ..    STA length+0             ; &B6 = 0 - XY+&0A
8D2B  C8           .     INY
8D2C  A9 00        ..    LDA #&00
8D2E  F1 F0        ..    SBC (&F0),Y
8D30  85 B7        ..    STA length+1             ; &B7 = 0 - XY+&0B - C
8D32  C8           .     INY
8D33  A9 00        ..    LDA #&00
8D35  F1 F0        ..    SBC (&F0),Y
8D37  85 B8        ..    STA length+2             ; &B8 = 0 - XY+&0C - C
8D39  60           `     RTS

; -----------------------------------------------------------------------------
; Store the number of bytes written in XY+&0A-&0D
; -----------------------------------------------------------------------------
.                                                 ; Add &B6-&B8 to XY+&0A-&0C and store it in XY+&0E-&11
8D3A  18           .     CLC
8D3B  A0 0A        ..    LDY #&0A
8D3D  B1 F0        ..    LDA (&F0),Y
8D3F  65 B6        e.    ADC length+0
8D41  A0 0E         ..   LDY #&0E
8D43  91 F0        ..    STA (&F0),Y              ; XY+&0E = XY+&0A + ?&B6
8D45  A0 0B        ..    LDY #&0B
8D47  B1 F0        ..    LDA (&F0),Y
8D49  65 B7        e.    ADC length+1
8D4B  A0 0F         ..   LDY #&0F
8D4D  91 F0        ..    STA (&F0),Y              ; XY+&0F = XY+&0B + ?&B7 + C
8D4F  A0 0C        ..    LDY #&0C
8D51  B1 F0        ..    LDA (&F0),Y
8D53  65 B8        e.    ADC length+2
8D55  A0 10         ..   LDY #&10
8D57  91 F0        ..    STA (&F0),Y              ; XY+&10 = XY+&0C + ?&B8 + C
8D59  A0 11         ..   LDY #&11
8D5B  A9 00        ..    LDA #&00
8D5D  91 F0        ..    STA (&F0),Y              ; XY+&11 = #&00
8D5F  60           `     RTS                      ; Exit

; -----------------------------------------------------------------------------
; OSWORD &80 commands &36/&38/&3A/&3C/&3E (Write) Jump to subroutine
; -----------------------------------------------------------------------------
.
8D60  A0 F7        ..    LDY #&F7
8D62  B1 B0        ..    LDA (pwrkspc),Y
8D64  AA           .     TAX
8D65  BD 6E 8D     .n.   LDA &8D6E,X
8D68  48           H     PHA
8D69  BD 8E 8D     ...   LDA &8D8E,X
8D6C  48           H     PHA
8D6D  60           `     RTS

; -----------------------------------------------------------------------------
; OSWORD &80 commands &36/&38/&3A/&3C/&3E (Write) lookup table MSB
; -----------------------------------------------------------------------------
.
8D6E  8D           .     EQUB &8D                 ; (&8DCA) &00 From host, without timer, 1 EOS byte, no EOI with last byte
8D6F  8E           .     EQUB &8E                 ; (&8E0C) &01 From host, without timer, 2 EOS bytes, no EOI with last byte
8F70  8F           .     EQUB &8F                 ; (&8F41) &02 From host, with timer, 1 EOS byte, no EOI with last byte
8D71  8F           .     EQUB &8F                 ; (&8F5F) &03 From host, with timer, 2 closing byte, no EOI with last byte
8D72  8F           .     EQUB &8F                 ; (&8FDF) &04 From co-pro, without timer, 1 EOS byte, no EOI with last byte
8D73  90           .     EQUB &90                 ; (&9006) &05 From co-pro, without timer, 2 closing byte, no EOI with last byte
8D74  90           .     EQUB &90                 ; (&90AA) &06 From co-pro, with timer, 1 EOS byte, no EOI with last byte
8D75  90           .     EQUB &90                 ; (&90CE) &07 From co-pro, with timer, 2 closing byte, no EOI with last byte
8D76  91           .     EQUB &91                 ; (&9174) &08 From host, without timer, no EOS bytes, send EOI with last byte
8D77  91           .     EQUB &91                 ; (&9174) &09 From host, without timer, no EOS bytes, send EOI with last byte
8D78  91           .     EQUB &91                 ; (&91B3) &0A From host, with timer, no EOS bytes, send EOI with last byte
8D79  91           .     EQUB &91                 ; (&91B3) &0B From host, with timer, no EOS bytes, send EOI with last byte
8D7A  91           .     EQUB &91                 ; (&91D7) &0C From co-pro, without timer, no EOS bytes, send EOI with last byte
8D7B  91           .     EQUB &91                 ; (&91D7) &0D From co-pro, without timer, no EOS bytes, send EOI with last byte
8D7C  92           .     EQUB &92                 ; (&9208) &0E From co-pro, with timer, no EOS bytes, send EOI with last byte
8D7D  92           .     EQUB &92                 ; (&9208) &0F From co-pro, with timer, no EOS bytes, send EOI with last byte
8D7E  8F           .     EQUB &8F                 ; (&8F02) &10 From host, without timer, no EOS bytes, no EOI with last byte
8D7F  8F           .     EQUB &8F                 ; (&8F02) &11 From host, without timer, no EOS bytes, no EOI with last byte
8D80  8F           .     EQUB &8F                 ; (&8FC9) &12 From host, with timer, no EOS bytes, no EOI with last byte
8D81  8F           .     EQUB &8F                 ; (&8FC9) &13 From host, with timer, no EOS bytes, no EOI with last byte
8D82  90           .     EQUB &90                 ; (&908B) &14 From co-pro, without timer, no EOS bytes, no EOI with last byte
8D83  90           .     EQUB &90                 ; (&908B) &15 From co-pro, without timer, no EOS bytes, no EOI with last byte
8D84  91           .     EQUB &91                 ; (&914A) &16 From co-pro, with timer, no EOS bytes, no EOI with last byte
8D85  91           .     EQUB &91                 ; (&914A) &17 From co-pro, with timer, no EOS bytes, no EOI with last byte
8D86  8E           .     EQUB &8E                 ; (&8E61) &18 From host, without timer, 1 closing bytes, send EOI with last byte
8D87  8E           .     EQUB &8E                 ; (&8EA8) &19 From host, without timer, 2 EOS bytes, send EOI with last byte
8D88  8F           .     EQUB &8F                 ; (&8F85) &1A From host, with timer, 1 closing bytes, send EOI with last byte
8D89  8F           .     EQUB &8F                 ; (&8FA3) &1B From host, with timer, 2 EOS bytes, send EOI with last byte
8D8A  90           .     EQUB &90                 ; (&9035) &1C From co-pro, without timer, 1 closing bytes, send EOI with last byte
8D8B  90           .     EQUB &90                 ; (&905C) &1D From co-pro, without timer, 2 EOS bytes, send EOI with last byte
8D8C  90           .     EQUB &90                 ; (&90FA) &1E From co-pro, with timer, 1 EOS byte, send EOI with last byte
8D8D  91           .     EQUB &91                 ; (&911E) &1F From co-pro, with timer, 2 closing byte, send EOI with last byte

; -----------------------------------------------------------------------------
; OSWORD &80 commands &36/&38/&3A/&3C/&3E (Write) lookup table LSB
; -----------------------------------------------------------------------------
.
8D8E  C9           .     EQUB &C9                   
8D8F  0B           .     EQUB &0B                   
8D90  40           @     EQUB &40                   
8D91  5E           .     EQUB &5E                   
8D92  DE           .     EQUB &DE                   
8D93  05           .     EQUB &05                   
8D94  A9           .     EQUB &A9                   
8D95  CD           .     EQUB &CD                   
8D96  73           .     EQUB &73                   
8D97  73           .     EQUB &73                   
8D98  B2           .     EQUB &B2                   
8D99  B2           .     EQUB &B2                   
8D9A  D6           .     EQUB &D6                   
8D9B  D6           .     EQUB &D6                   
8D9C  07           .     EQUB &07                   
8D9D  07           .     EQUB &07                   
8D9E  01           .     EQUB &01                   
8D9F  01           .     EQUB &01                   
8DA0  C8           .     EQUB &C8                   
8DA1  C8           .     EQUB &C8                   
8DA2  8A           .     EQUB &8A                   
8DA3  8A           .     EQUB &8A                   
8DA4  49           .     EQUB &49                   
8DA5  49           .     EQUB &49                   
8DA6  60           .     EQUB &60                   
8DA7  A7           .     EQUB &A7                   
8DA8  84           .     EQUB &84                   
8DA9  A2           .     EQUB &A2                   
8DAA  34           .     EQUB &34                   
8DAB  5B           .     EQUB &5B                   
8DAC  F9           .     EQUB &F9                   
8DAD  1D           .     EQUB &1D                   

; -----------------------------------------------------------------------------
; Check if nr. of bytes to be transferred > 0
; -----------------------------------------------------------------------------
.
8DAE  A5 B6        ..    LDA length+0
8DB0  05 B7        ..    ORA length+1
8DB2  05 B8        ..    ORA length+2
8DB4  F0 01        ..    BEQ &0DB7
8DB6  60           `     RTS
.
8DB7  A9 08        ..    LDA #&08
8DB9  4C 94 83     L..   JMP &8394                ; Exit with error code &08

; -----------------------------------------------------------------------------
; Write &00 : From host, without timer, 1 EOS byte, no EOI with last byte
; -----------------------------------------------------------------------------
.
8DBC  29 01        ).    AND #&01                 ; 00000001
8DBE  D0 05        ..    BNE &8DC5
8DC0  A9 06        ..    LDA #&06
8DC2  4C 94 83     L..   JMP &8394                ; Exit with error code &06
.
8DC5  A9 05        ..    LDA #&05
8DC7  4C 94 83     L..   JMP &8394                ; Exit with error code &05

.                                                 ; Entry point
8DCA  A0 00        ..    LDY #&00
.
8DCC  B1 B2        ..    LDA (memadr),Y
8DCE  AA           .     TAX
.                                                 ; Wait for END without timer
8DCF  A5 B9        ..    LDA intflag
8DD1  D0 E9        ..    BNE &8DBC
8DD3  AD 20 FC     . .   LDA intstatus0           ; Load the TMS9914A's Interrupt Status Register 0
8DD6  29 10        ).    AND #&10                 ; Check if bit4 is set (END flag)
8DD8  F0 F5        ..    BEQ &8DCF                ; If not, then repeat
8DDA  8E 27 FC     .'.   STX datout               ; Send X to the TMS9914A's Data Out Register
8DDD  C8           .     INY
8DDE  D0 02        ..    BNE &8DE2
8DE0  E6 B3        ..    INC memadr+1
.
8DE2  E6 B6        ..    INC length+0
8DE4  D0 E6        ..    BNE &8DCC
8DE6  E6 B7        ..    INC length+1
8DE8  D0 E2        ..    BNE &8DCC
8DEA  A0 ED        ..    LDY #&ED
8DEC  B1 B0        ..    LDA (pwrkspc),Y
8DEE  AA           .     TAX
.
8DEF  A5 B9        ..    LDA intflag
8DF1  D0 C9        ..    BNE &8DBC
8DF3  AD 20 FC     . .   LDA intstatus0           ; Load the TMS9914A's Interrupt Status Register 0
8DF6  29 10        ).    AND #&10                 ; Check if bit4 is set (END flag)
8DF8  F0 F5        ..    BEQ &8DEF                ; If not, then repeat
8DFA  8E 27 FC     .'.   STX datout               ; Send X to the TMS9914A's Data Out Register
8DFD  60           `     RTS

; -----------------------------------------------------------------------------
; Write &01 : From host, without timer, 2 EOS bytes, no EOI with last byte
; -----------------------------------------------------------------------------
.
8DFE  29 01        ).    AND #&01
8E00  D0 05        ..    BNE &8E07
8E02  A9 06        ..    LDA #&06
8E04  4C 94 83     L..   JMP &8394                ; Exit with error code &06
.
8E07  A9 05        ..    LDA #&05
8E09  4C 94 83     L..   JMP &8394                ; Exit with error code &05
.                                                 ; Entry point
8E0C  A0 00        ..    LDY #&00
.
8E0E  B1 B2        ..    LDA (memadr),Y
8E10  AA           .     TAX
.                                                 ; Wait for END without timer
8E11  A5 B9        ..    LDA intflag
8E13  D0 E9        ..    BNE &8DFE
8E15  AD 20 FC     . .   LDA intstatus0           ; Load the TMS9914A's Interrupt Status Register 0
8E18  29 10        ).    AND #&10                 ; Check if bit4 is set (END flag)
8E1A  F0 F5        ..    BEQ &8E11                ; If not, then repeat
8E1C  8E 27 FC     .'.   STX datout               ; Send X to the TMS9914A's Data Out Register
8E1F  C8           .     INY
8E20  D0 02        ..    BNE &8E24
8E22  E6 B3        ..    INC memadr+1
.
8E24  E6 B6        ..    INC length+0
8E26  D0 E6        ..    BNE &8E0E
8E28  E6 B7        ..    INC length+1
8E2A  D0 E2        ..    BNE &8E0E
8E2C  A0 ED        ..    LDY #&ED
8E2E  B1 B0        ..    LDA (pwrkspc),Y
8E30  AA           .     TAX
.                                                 ; Wait for END without timer
8E31  A5 B9        ..    LDA intflag
8E33  D0 C9        ..    BNE &8DFE
8E35  AD 20 FC     . .   LDA intstatus0           ; Load the TMS9914A's Interrupt Status Register 0
8E38  29 10        ).    AND #&10                 ; Check if bit4 is set (END flag)
8E3A  F0 F5        ..    BEQ &8E31                ; If not, then repeat
8E3C  8E 27 FC     .'.   STX datout               ; Send X to the TMS9914A's Data Out Register
8E3F  A0 EE         ..   LDY #&EE
8E41  B1 B0        ..    LDA (pwrkspc),Y
8E43  AA           .     TAX
.
8E44  A5 B9        ..    LDA intflag
8E46  D0 B6        ..    BNE &8DFE
8E48  AD 20 FC     . .   LDA intstatus0           ; Load the TMS9914A's Interrupt Status Register 0
8E4B  29 10        ).    AND #&10                 ; Check if bit4 is set (END flag)
8E4D  F0 F5        ..    BEQ &8E44                ; If not, then repeat
8E4F  8E 27 FC     .'.   STX datout               ; Send X to the TMS9914A's Data Out Register
8E52  60           `     RTS

; -----------------------------------------------------------------------------
; Write &18 : From host, without timer, 1 closing bytes, send EOI with last byte
; -----------------------------------------------------------------------------
.
8E53  29 01        ).    AND #&01
8E55  D0 05        ..    BNE &8E5C
8E57  A9 06        ..    LDA #&06
8E59  4C 94 83     L..   JMP &8394                ; Exit with error code &06
.
8E5C  A9 05        ..    LDA #&05
8E5E  4C 94 83     L..   JMP &8394                ; Exit with error code &05
.                                                 ; Entry point
8E61  A0 00        ..    LDY #&00
.
8E63  B1 B2        ..    LDA (memadr),Y
8E65  AA           .     TAX
.                                                 ; Wait for END without timer
8E66  A5 B9        ..    LDA intflag
8E68  D0 E9        ..    BNE &8E53
8E6A  AD 20 FC     . .   LDA intstatus0           ; Load the TMS9914A's Interrupt Status Register 0
8E6D  29 10        ).    AND #&10                 ; Check if bit4 is set (END flag)
8E6F  F0 F5        ..    BEQ &8E66                ; If not, then repeat
8E71  8E 27 FC     .'.   STX datout               ; Send X to the TMS9914A's Data Out Register
8E74  C8           .     INY
8E75  D0 02        ..    BNE &8E79
8E77  E6 B3        ..    INC memadr+1
.
8E79  E6 B6        ..    INC length+0
8E7B  D0 E6        ..    BNE &8E63
8E7D  E6 B7        ..    INC length+1
8E7F  D0 E2        ..    BNE &8E63
8E81  A0 ED        ..    LDY #&ED
8E83  B1 B0        ..    LDA (pwrkspc),Y
8E85  AA           .     TAX
.
8E86  A5 B9        ..    LDA intflag
8E88  D0 C9        ..    BNE &8E53
8E8A  AD 20 FC     . .   LDA intstatus0           ; Load the TMS9914A's Interrupt Status Register 0
8E8D  29 10        ).    AND #&10                 ; Check if bit4 is set (END flag)
8E8F  F0 F5        ..    BEQ &8E86                ; If not, then repeat
8E91  A9 08        ..    LDA #feoi                ; Load the mnemonic for the 'Send EOI with next byte' function
8E93  8D 26 FC     .&.   STA auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
8E96  8E 27 FC     .'.   STX datout               ; Send X to the TMS9914A's Data Out Register
8E99  60           `     RTS

; -----------------------------------------------------------------------------
; Write &19 : From host, without timer, 2 EOS bytes, send EOI with last byte
; -----------------------------------------------------------------------------
.
8E9A  29 01        ).    AND #&01
8E9C  D0 05        ..    BNE &8EA3
8E9E  A9 06        ..    LDA #&06
8EA0  4C 94 83     L..   JMP &8394                ; Exit with error code &06
.
8EA3  A9 05        ..    LDA #&05
8EA5  4C 94 83     L..   JMP &8394                ; Exit with error code &05
.                                                 ; Entry point
8EA8  A0 00        ..    LDY #&00
.
8EAA  B1 B2        ..    LDA (memadr),Y
8EAC  AA           .     TAX
.                                                 ; Wait for END without timer
8EAD  A5 B9        ..    LDA intflag
8EAF  D0 E9        ..    BNE &8E9A
8EB1  AD 20 FC     . .   LDA intstatus0           ; Load the TMS9914A's Interrupt Status Register 0
8EB4  29 10        ).    AND #&10                 ; Check if bit4 is set (END flag)
8EB6  F0 F5        ..    BEQ &8EAD                ; If not, then repeat
8EB8  8E 27 FC     .'.   STX datout               ; Send X to the TMS9914A's Data Out Register
8EBB  C8           .     INY
8EBC  D0 02        ..    BNE &8EC0
8EBE  E6 B3        ..    INC memadr+1
.
8EC0  E6 B6        ..    INC length+0
8EC2  D0 E6        ..    BNE &8EAA
8EC4  E6 B7        ..    INC length+1
8EC6  D0 E2        ..    BNE &8EAA
8EC8  A0 ED        ..    LDY #&ED
8ECA  B1 B0        ..    LDA (pwrkspc),Y
8ECC  AA           .     TAX
.                                                 ; Wait for END without timer
8ECD  A5 B9        ..    LDA intflag
8ECF  D0 C9        ..    BNE &8E9A
8ED1  AD 20 FC     . .   LDA intstatus0           ; Load the TMS9914A's Interrupt Status Register 0
8ED4  29 10        ).    AND #&10                 ; Check if bit4 is set (END flag)
8ED6  F0 F5        ..    BEQ &8ECD                ; If not, then repeat
8ED8  8E 27 FC     .'.   STX datout               ; Send X to the TMS9914A's Data Out Register
8EDB  A0 EE         ..   LDY #&EE
8EDD  B1 B0        ..    LDA (pwrkspc),Y
8EDF  AA           .     TAX
.
8EE0  A5 B9        ..    LDA intflag
8EE2  D0 B6        ..    BNE &8E9A
8EE4  AD 20 FC     . .   LDA intstatus0           ; Load the TMS9914A's Interrupt Status Register 0
8EE7  29 10        ).    AND #&10                 ; Check if bit4 is set (END flag)
8EE9  F0 F5        ..    BEQ &8EE0                ; If not, then repeat
8EEB  A9 08        ..    LDA #feoi                ; Load the mnemonic for the 'Send EOI with next byte' function
8EED  8D 26 FC     .&.   STA auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
8EF0  8E 27 FC     .'.   STX datout               ; Send X to the TMS9914A's Data Out Register
8EF3  60           `     RTS

; -----------------------------------------------------------------------------
; Write &10/&11 : From host, without timer, no EOS bytes, no EOI with last byte
; -----------------------------------------------------------------------------
.
8EF4  29 01        ).    AND #&01
8EF6  D0 05        ..    BNE &8EFD
8EF8  A9 06        ..    LDA #&06
8EFA  4C 94 83     L..   JMP &8394                ; Exit with error code &06
.
8EFD  A9 05        ..    LDA #&05
8EFF  4C 94 83     L..   JMP &8394                ; Exit with error code &05
.                                                 ; Entry point
8F02  A0 00        ..    LDY #&00
.
8F04  B1 B2        ..    LDA (memadr),Y
8F06  AA           .     TAX
.                                                 ; Wait for END without timer
8F07  A5 B9        ..    LDA intflag
8F09  D0 E9        ..    BNE &8EF4
8F0B  AD 20 FC     . .   LDA intstatus0           ; Load the TMS9914A's Interrupt Status Register 0
8F0E  29 10        ).    AND #&10                 ; Check if bit4 is set (END flag)
8F10  F0 F5        ..    BEQ &8F07                ; If not, then repeat
8F12  8E 27 FC     .'.   STX datout               ; Send X to the TMS9914A's Data Out Register
8F15  C8           .     INY
8F16  D0 02        ..    BNE &8F1A
8F18  E6 B3        ..    INC memadr+1
.
8F1A  E6 B6        ..    INC length+0
8F1C  D0 E6        ..    BNE &8F04
8F1E  E6 B7        ..    INC length+1
8F20  D0 E2        ..    BNE &8F04
8F22  60           `     RTS

; -----------------------------------------------------------------------------
; Unknown procedure: this procedure is never called!!! (From host, without timer, 1 EOS byte, no EOI with last byte)
; -----------------------------------------------------------------------------
.

8F23  A0 00        ..    LDY #&00
.
8F25  B1 B2        ..    LDA (memadr),Y
8F27  AA           .     TAX
8F28  20 78 92      x.   JSR &9278                ; Wait for END with timer, then send X to Data Out register
8F2B  C8           .     INY
8F2C  D0 02        ..    BNE &8F30
8F2E  E6 B3        ..    INC memadr+1
.
8F30  E6 B6        ..    INC length+0
8F32  D0 F1        ..    BNE &8F25
8F34  E6 B7        ..    INC length+1
8F36  D0 ED        ..    BNE &8F25
8F38  A0 ED        ..    LDY #&ED
8F3A  B1 B0        ..    LDA (pwrkspc),Y
8F3C  AA           .     TAX
8F3D  20 78 92      x.   JSR &9278                ; Wait for END with timer, then send X to Data Out register
8F40  60           `     RTS

; -----------------------------------------------------------------------------
; Write &02 : From host, with timer, 1 EOS byte, no EOI with last byte
; -----------------------------------------------------------------------------
.                                                 ; Entry point
8F41  A0 00        ..    LDY #&00
.
8F43  B1 B2        ..    LDA (memadr),Y
8F45  AA           .     TAX
8F46  20 78 92      x.   JSR &9278                ; Wait for END with timer, then send X to Data Out register
8F49  C8           .     INY
8F4A  D0 02        ..    BNE &8F4E
8F4C  E6 B3        ..    INC memadr+1
.
8F4E  E6 B6        ..    INC length+0
8F50  D0 F1        ..    BNE &8F43
8F52  E6 B7        ..    INC length+1
8F54  D0 ED        ..    BNE &8F43
8F56  A0 ED        ..    LDY #&ED
8F58  B1 B0        ..    LDA (pwrkspc),Y
8F5A  AA           .     TAX
8F5B  20 78 92      x.   JSR &9278                ; Wait for END with timer, then send X to Data Out register
8F5E  60           `     RTS

; -----------------------------------------------------------------------------
; Write &03 : From host, with timer, 2 closing byte, no EOI with last byte
; -----------------------------------------------------------------------------
.                                                 ; Entry point
8F5F  A0 00        ..    LDY #&00
.
8F61  B1 B2        ..    LDA (memadr),Y
8F63  AA           .     TAX
8F64  20 78 92      x.   JSR &9278                ; Wait for END with timer, then send X to Data Out register
8F67  C8           .     INY
8F68  D0 02        ..    BNE &8F6C
8F6A  E6 B3        ..    INC memadr+1
.
8F6C  E6 B6        ..    INC length+0
8F6E  D0 F1        ..    BNE &8F61
8F70  E6 B7        ..    INC length+1
8F72  D0 ED        ..    BNE &8F61
8F74  A0 ED        ..    LDY #&ED
8F76  B1 B0        ..    LDA (pwrkspc),Y
8F78  AA           .     TAX
8F79  20 78 92      x.   JSR &9278                ; Wait for END with timer, then send X to Data Out register
8F7C  A0 EE         ..   LDY #&EE
8F7E  B1 B0        ..    LDA (pwrkspc),Y
8F80  AA           .     TAX
8F81  20 78 92      x.   JSR &9278                ; Wait for END with timer, then send X to Data Out register
8F84  60           `     RTS

; -----------------------------------------------------------------------------
; Write &1A : From host, with timer, 1 closing bytes, send EOI with last byte
; -----------------------------------------------------------------------------
.                                                 ; Entry point
8F85  A0 00        ..    LDY #&00
.
8F87  B1 B2        ..    LDA (memadr),Y
8F89  AA           .     TAX
8F8A  20 78 92      x.   JSR &9278                ; Wait for END with timer, then send X to Data Out register
8F8D  C8           .     INY
8F8E  D0 02        ..    BNE &8F92
8F90  E6 B3        ..    INC memadr+1
.
8F92  E6 B6        ..    INC length+0
8F94  D0 F1        ..    BNE &8F87
8F96  E6 B7        ..    INC length+1
8F98  D0 ED        ..    BNE &8F87
8F9A  A0 ED        ..    LDY #&ED
8F9C  B1 B0        ..    LDA (pwrkspc),Y
8F9E  AA           .     TAX
8F9F  20 83 92      ..   JSR &9283                ; Wait for END with timer, then send X with EOI to Data Out register
8FA2  60           `     RTS

; -----------------------------------------------------------------------------
; Write &1B : From host, with timer, 2 EOS bytes, send EOI with last byte
; -----------------------------------------------------------------------------
.                                                 ; Entry point
8FA3  A0 00        ..    LDY #&00
.
8FA5  B1 B2        ..    LDA (memadr),Y
8FA7  AA           .     TAX
8FA8  20 78 92      x.   JSR &9278                ; Wait for END with timer, then send X to Data Out register
8FAB  C8           .     INY
8FAC  D0 02        ..    BNE &8FB0
8FAE  E6 B3        ..    INC memadr+1
.
8FB0  E6 B6        ..    INC length+0
8FB2  D0 F1        ..    BNE &8FA5
8FB4  E6 B7        ..    INC length+1
8FB6  D0 ED        ..    BNE &8FA5
8FB8  A0 ED        ..    LDY #&ED
8FBA  B1 B0        ..    LDA (pwrkspc),Y
8FBC  AA           .     TAX
8FBD  20 78 92      x.   JSR &9278                ; Wait for END with timer, then send X to Data Out register
8FC0  A0 EE         ..   LDY #&EE
8FC2  B1 B0        ..    LDA (pwrkspc),Y
8FC4  AA           .     TAX
8FC5  20 83 92      ..   JSR &9283                ; Wait for END with timer, then send X with EOI to Data Out register
8FC8  60           `     RTS

; -----------------------------------------------------------------------------
; Write &12/&13 : From host, with timer, no EOS bytes, no EOI with last byte
; -----------------------------------------------------------------------------
.                                                 ; Entry point
8FC9  A0 00        ..    LDY #&00
.
8FCB  B1 B2        ..    LDA (memadr),Y
8FCD  AA           .     TAX
8FCE  20 78 92      x.   JSR &9278                ; Wait for END with timer, then send X to Data Out register
8FD1  C8           .     INY
8FD2  D0 02        ..    BNE &8FD6
8FD4  E6 B3        ..    INC memadr+1
.
8FD6  E6 B6        ..    INC length+0
8FD8  D0 F1        ..    BNE &8FCB
8FDA  E6 B7        ..    INC length+1
8FDC  D0 ED        ..    BNE &8FCB
8FDE  60           `     RTS

; -----------------------------------------------------------------------------
; Write &04 : From co-pro, without timer, 1 EOS byte, no EOI with last byte
; -----------------------------------------------------------------------------
.                                                 ; Entry point
8FDF  20 EB 92      ..   JSR claimtube            ; Claim the TUBE
8FE2  20 16 93      ..   JSR &initcotoio          ; Prepare for data transfer from parasite (co-processor) to host (i/o)
.
8FE5  AE E5 FE     ...   LDX tubedat
8FE8  20 36 92      6.   JSR &9236                ; Wait for END without timer, then send X to Data Out register
8FEB  EA           .     NOP                      ; 1 NOP = 2 clockcycles
8FEC  EA           .     NOP
8FED  EA           .     NOP
8FEE  E6 B6        ..    INC length+0
8FF0  D0 F3        ..    BNE &8FE5
8FF2  E6 B7        ..    INC length+1
8FF4  D0 EF        ..    BNE &8FE5
8FF6  E6 B8        ..    INC length+2
8FF8  D0 EB        ..    BNE &8FE5
8FFA  A0 ED        ..    LDY #&ED
8FFC  B1 B0        ..    LDA (pwrkspc),Y
8FFE  AA           .     TAX
8FFF  20 36 92      6.   JSR &9236                ; Wait for END without timer, then send X to Data Out register
9002  20 F9 92      ..   JSR reltube              ; Release the TUBE
9005  60           `     RTS

; -----------------------------------------------------------------------------
; Write &05 : From co-pro, without timer, 2 closing byte, no EOI with last byte
; -----------------------------------------------------------------------------
.                                                 ; Entry point
9006  20 EB 92      ..   JSR claimtube            ; Claim the TUBE
9009  20 16 93      ..   JSR &initcotoio          ; Prepare for data transfer from parasite (co-processor) to host (i/o)
.
900C  AE E5 FE     ...   LDX tubedat
900F  20 36 92      6.   JSR &9236                ; Wait for END without timer, then send X to Data Out register
9012  EA           .     NOP                      ; 1 NOP = 2 clockcycles
9013  EA           .     NOP
9014  EA           .     NOP
9015  E6 B6        ..    INC length+0
9017  D0 F3        ..    BNE &900C
9019  E6 B7        ..    INC length+1
901B  D0 EF        ..    BNE &900C
901D  E6 B8        ..    INC length+2
901F  D0 EB        ..    BNE &900C
9021  A0 ED        ..    LDY #&ED
9023  B1 B0        ..    LDA (pwrkspc),Y
9025  AA           .     TAX
9026  20 36 92      6.   JSR &9236                ; Wait for END without timer, then send X to Data Out register
9029  A0 EE         ..   LDY #&EE
902B  B1 B0        ..    LDA (pwrkspc),Y
902D  AA           .     TAX
902E  20 36 92      6.   JSR &9236                ; Wait for END without timer, then send X to Data Out register
9031  20 F9 92      ..   JSR reltube              ; Release the TUBE
9034  60           `     RTS

; -----------------------------------------------------------------------------
; Write &1C : From co-pro, without timer, 1 closing bytes, send EOI with last byte
; -----------------------------------------------------------------------------
.                                                 ; Entry point
9035  20 EB 92      ..   JSR claimtube            ; Claim the TUBE
9038  20 16 93      ..   JSR &initcotoio          ; Prepare for data transfer from parasite (co-processor) to host (i/o)
.
903B  AE E5 FE     ...   LDX tubedat
903E  20 36 92      6.   JSR &9236                ; Wait for END without timer, then send X to Data Out register
9041  EA           .     NOP                      ; 1 NOP = 2 clockcycles
9042  EA           .     NOP
9043  EA           .     NOP
9044  E6 B6        ..    INC length+0
9046  D0 F3        ..    BNE &903B
9048  E6 B7        ..    INC length+1
904A  D0 EF        ..    BNE &903B
904C  E6 B8        ..    INC length+2
904E  D0 EB        ..    BNE &903B
9050  A0 ED        ..    LDY #&ED
9052  B1 B0        ..    LDA (pwrkspc),Y
9054  AA           .     TAX
9055  20 56 92      V.   JSR &9256                ; Wait for END without timer, then send X with EOI to Data Out register
9058  20 F9 92      ..   JSR reltube              ; Release the TUBE
905B  60           `     RTS

; -----------------------------------------------------------------------------
; Write &1D : From co-pro, without timer, 2 EOS bytes, send EOI with last byte
; -----------------------------------------------------------------------------
.                                                 ; Entry point
905C  20 EB 92      ..   JSR claimtube            ; Claim the TUBE
905F  20 16 93      ..   JSR &initcotoio          ; Prepare for data transfer from parasite (co-processor) to host (i/o)
.
9062  AE E5 FE     ...   LDX tubedat
9065  20 36 92      6.   JSR &9236                ; Wait for END without timer, then send X to Data Out register
9068  EA           .     NOP                      ; 1 NOP = 2 clockcycles
9069  EA           .     NOP
906A  EA           .     NOP
906B  E6 B6        ..    INC length+0
906D  D0 F3        ..    BNE &9062
906F  E6 B7        ..    INC length+1
9071  D0 EF        ..    BNE &9062
9073  E6 B8        ..    INC length+2
9075  D0 EB        ..    BNE &9062
9077  A0 ED        ..    LDY #&ED
9079  B1 B0        ..    LDA (pwrkspc),Y
907B  AA           .     TAX
907C  20 36 92      6.   JSR &9236                ; Wait for END without timer, then send X to Data Out register
907F  A0 EE         ..   LDY #&EE
9081  B1 B0        ..    LDA (pwrkspc),Y
9083  AA           .     TAX
9084  20 56 92      V.   JSR &9256                ; Wait for END without timer, then send X with EOI to Data Out register
9087  20 F9 92      ..   JSR reltube              ; Release the TUBE
908A  60           `     RTS

; -----------------------------------------------------------------------------
; Write &14/&15 : From co-pro, without timer, no EOS bytes, no EOI with last byte
; -----------------------------------------------------------------------------
.                                                 ; Entry point
908B  20 EB 92      ..   JSR claimtube            ; Claim the TUBE
908E  20 16 93      ..   JSR &initcotoio          ; Prepare for data transfer from parasite (co-processor) to host (i/o)
.
9091  AE E5 FE     ...   LDX tubedat
9094  20 36 92      6.   JSR &9236                ; Wait for END without timer, then send X to Data Out register
9097  EA           .     NOP                      ; 1 NOP = 2 clockcycles
9098  EA           .     NOP
9099  EA           .     NOP
909A  E6 B6        ..    INC length+0
909C  D0 F3        ..    BNE &9091
909E  E6 B7        ..    INC length+1
90A0  D0 EF        ..    BNE &9091
90A2  E6 B8        ..    INC length+2
90A4  D0 EB        ..    BNE &9091
90A6  20 F9 92      ..   JSR reltube              ; Release the TUBE
90A9  60           `     RTS

; -----------------------------------------------------------------------------
; Write &06 : From co-pro, with timer, 1 EOS byte, no EOI with last byte
; -----------------------------------------------------------------------------
.                                                 ; Entry point
90AA  20 EB 92      ..   JSR claimtube            ; Claim the TUBE
90AD  20 16 93      ..   JSR &initcotoio          ; Prepare for data transfer from parasite (co-processor) to host (i/o)
.
90B0  AE E5 FE     ...   LDX tubedat
90B3  20 78 92      x.   JSR &9278                ; Wait for END with timer, then send X to Data Out register
90B6  E6 B6        ..    INC length+0
90B8  D0 F6        ..    BNE &90B0
90BA  E6 B7        ..    INC length+1
90BC  D0 F2        ..    BNE &90B0
90BE  E6 B8        ..    INC length+2
90C0  D0 EE        ..    BNE &90B0
90C2  A0 ED        ..    LDY #&ED
90C4  B1 B0        ..    LDA (pwrkspc),Y
90C6  AA           .     TAX
90C7  20 78 92      x.   JSR &9278                ; Wait for END with timer, then send X to Data Out register
90CA  20 F9 92      ..   JSR reltube              ; Release the TUBE
90CD  60           `     RTS

; -----------------------------------------------------------------------------
; Write &07 : From co-pro, with timer, 2 closing byte, no EOI with last byte
; -----------------------------------------------------------------------------
.                                                 ; Entry point
90CE  20 EB 92      ..   JSR claimtube            ; Claim the TUBE
90D1  20 16 93      ..   JSR &initcotoio          ; Prepare for data transfer from parasite (co-processor) to host (i/o)
.
90D4  AE E5 FE     ...   LDX tubedat
90D7  20 78 92      x.   JSR &9278                ; Wait for END with timer, then send X to Data Out register
90DA  E6 B6        ..    INC length+0
90DC  D0 F6        ..    BNE &90D4
90DE  E6 B7        ..    INC length+1
90E0  D0 F2        ..    BNE &90D4
90E2  E6 B8        ..    INC length+2
90E4  D0 EE        ..    BNE &90D4
90E6  A0 ED        ..    LDY #&ED
90E8  B1 B0        ..    LDA (pwrkspc),Y
90EA  AA           .     TAX
90EB  20 78 92      x.   JSR &9278                ; Wait for END with timer, then send X to Data Out register
90EE  A0 EE         ..   LDY #&EE
90F0  B1 B0        ..    LDA (pwrkspc),Y
90F2  AA           .     TAX
90F3  20 78 92      x.   JSR &9278                ; Wait for END with timer, then send X to Data Out register
90F6  20 F9 92      ..   JSR reltube              ; Release the TUBE
90F9  60           `     RTS

; -----------------------------------------------------------------------------
; Write &1E : From co-pro, with timer, 1 EOS byte, send EOI with last byte
; -----------------------------------------------------------------------------
.                                                 ; Entry point
90FA  20 EB 92      ..   JSR claimtube            ; Claim the TUBE
90FD  20 16 93      ..   JSR &initcotoio          ; Prepare for data transfer from parasite (co-processor) to host (i/o)
.
9100  AE E5 FE     ...   LDX tubedat
9103  20 78 92      x.   JSR &9278                ; Wait for END with timer, then send X to Data Out register
9106  E6 B6        ..    INC length+0
9108  D0 F6        ..    BNE &9100
910A  E6 B7        ..    INC length+1
910C  D0 F2        ..    BNE &9100
910E  E6 B8        ..    INC length+2
9110  D0 EE        ..    BNE &9100
9112  A0 ED        ..    LDY #&ED
9114  B1 B0        ..    LDA (pwrkspc),Y
9116  AA           .     TAX
9117  20 83 92      ..   JSR &9283                ; Wait for END with timer, then send X with EOI to Data Out register
911A  20 F9 92      ..   JSR reltube              ; Release the TUBE
911D  60           `     RTS

; -----------------------------------------------------------------------------
; Write &1F : From co-pro, with timer, 2 closing byte, send EOI with last byte
; -----------------------------------------------------------------------------
.                                                 ; Entry point
911E  20 EB 92      ..   JSR claimtube            ; Claim the TUBE
9121  20 16 93      ..   JSR &initcotoio          ; Prepare for data transfer from parasite (co-processor) to host (i/o)
.
9124  AE E5 FE     ...   LDX tubedat
9127  20 78 92      x.   JSR &9278                ; Wait for END with timer, then send X to Data Out register
912A  E6 B6        ..    INC length+0
912C  D0 F6        ..    BNE &9124
912E  E6 B7        ..    INC length+1
9130  D0 F2        ..    BNE &9124
9132  E6 B8        ..    INC length+2
9134  D0 EE        ..    BNE &9124
9136  A0 ED        ..    LDY #&ED
9138  B1 B0        ..    LDA (pwrkspc),Y
913A  AA           .     TAX
913B  20 78 92      x.   JSR &9278                ; Wait for END with timer, then send X to Data Out register
913E  A0 EE         ..   LDY #&EE
9140  B1 B0        ..    LDA (pwrkspc),Y
9142  AA           .     TAX
9143  20 83 92      ..   JSR &9283                ; Wait for END with timer, then send X with EOI to Data Out register
9146  20 F9 92      ..   JSR reltube              ; Release the TUBE
9149  60           `     RTS

; -----------------------------------------------------------------------------
; Write &16/&17 From co-pro, with timer, no EOS bytes, no EOI with last byte
; -----------------------------------------------------------------------------
.                                                 ; Entry point
914A  20 EB 92      ..   JSR claimtube            ; Claim the TUBE
914D  20 16 93      ..   JSR &initcotoio          ; Prepare for data transfer from parasite (co-processor) to host (i/o)
.
9150  AE E5 FE     ...   LDX tubedat
9153  20 78 92      x.   JSR &9278                ; Wait for END with timer, then send X to Data Out register
9156  E6 B6        ..    INC length+0
9158  D0 F6        ..    BNE &9150
915A  E6 B7        ..    INC length+1
915C  D0 F2        ..    BNE &9150
915E  E6 B8        ..    INC length+2
9160  D0 EE        ..    BNE &9150
9162  20 F9 92      ..   JSR reltube              ; Release the TUBE
9165  60           `     RTS

; -----------------------------------------------------------------------------
; Write &08/&09 From host, without timer, no EOS bytes, send EOI with last byte
; -----------------------------------------------------------------------------
.
9166  29 01        ).    AND #&01
9168  D0 05        ..    BNE &916F
916A  A9 06        ..    LDA #&06
916C  4C 94 83     L..   JMP &8394                ; Exit with error code &06
.
916F  A9 05        ..    LDA #&05
9171  4C 94 83     L..   JMP &8394                ; Exit with error code &05
.                                                 ; Entry point
9174  A0 00        ..    LDY #&00
9176  E6 B6        ..    INC length+0
9178  D0 04        ..    BNE &917E
917A  E6 B7        ..    INC length+1
917C  F0 1E        ..    BEQ &919C
.
917E  B1 B2        ..    LDA (memadr),Y
9180  AA           .     TAX
9181  A5 B9        ..    LDA intflag
9183  D0 E1        ..    BNE &9166
9185  AD 20 FC     . .   LDA intstatus0           ; Load the TMS9914A's Interrupt Status Register 0
9188  29 10        ).    AND #&10                 ; Check if bit4 is set (END flag)
918A  F0 F2        ..    BEQ &917E
918C  8E 27 FC     .'.   STX datout               ; Send X to the TMS9914A's Data Out Register
918F  C8           .     INY
9190  D0 02        ..    BNE &9194
9192  E6 B3        ..    INC memadr+1
.
9194  E6 B6        ..    INC length+0
9196  D0 E6        ..    BNE &917E
9198  E6 B7        ..    INC length+1
919A  D0 E2        ..    BNE &917E
.
919C  B1 B2        ..    LDA (memadr),Y
919E  AA           .     TAX
.
919F  A5 B9        ..    LDA intflag
91A1  D0 C3        ..    BNE &9166
91A3  AD 20 FC     . .   LDA intstatus0           ; Load the TMS9914A's Interrupt Status Register 0
91A6  29 10        ).    AND #&10                 ; Check if bit4 is set (END flag)
91A8  F0 F5        ..    BEQ &919F                ; If not, then repeat
91AA  A9 08        ..    LDA #feoi                ; Load the mnemonic for the 'Send EOI with next byte' function
91AC  8D 26 FC     .&.   STA auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
91AF  8E 27 FC     .'.   STX datout               ; Send X to the TMS9914A's Data Out Register
91B2  60           `     RTS

; -----------------------------------------------------------------------------
; Write &0A/&0B : From host, with timer, no EOS bytes, send EOI with last byte
; -----------------------------------------------------------------------------
.                                                 ; Entry point
91B3  A0 00        ..    LDY #&00
91B5  E6 B6        ..    INC length+0
91B7  D0 04        ..    BNE &91BD
91B9  E6 B7        ..    INC length+1
91BB  F0 13        ..    BEQ &91D0
.
91BD  B1 B2        ..    LDA (memadr),Y
91BF  AA           .     TAX
91C0  20 78 92      x.   JSR &9278                ; Wait for END with timer, then send X to Data Out register
91C3  C8           .     INY
91C4  D0 02        ..    BNE &91C8
91C6  E6 B3        ..    INC memadr+1
.
91C8  E6 B6        ..    INC length+0
91CA  D0 F1        ..    BNE &91BD
91CC  E6 B7        ..    INC length+1
91CE  D0 ED        ..    BNE &91BD
.
91D0  B1 B2        ..    LDA (memadr),Y
91D2  AA           .     TAX
91D3  20 83 92      ..   JSR &9283                ; Wait for END with timer, then send X with EOI to Data Out register
91D6  60           `     RTS

; -----------------------------------------------------------------------------
; Write &0C/&0D From co-pro, without timer, no EOS bytes, send EOI with last byte
; -----------------------------------------------------------------------------
.                                                 ; Entry point
91D7  20 EB 92      ..   JSR claimtube            ; Claim the TUBE
91DA  20 16 93      ..   JSR &initcotoio          ; Prepare for data transfer from parasite (co-processor) to host (i/o)
91DD  E6 B6        ..    INC length+0
91DF  D0 08        ..    BNE &91E9
91E1  E6 B7        ..    INC length+1
91E3  D0 04        ..    BNE &91E9
91E5  E6 B8        ..    INC length+2
91E7  F0 15        ..    BEQ &91FE
.
91E9  AE E5 FE     ...   LDX tubedat
91EC  20 36 92      6.   JSR &9236                ; Wait for END without timer, then send X to Data Out register
91EF  EA           .     NOP                      ; 1 NOP = 2 clockcycles
91F0  EA           .     NOP
91F1  EA           .     NOP
91F2  E6 B6        ..    INC length+0
91F4  D0 F3        ..    BNE &91E9
91F6  E6 B7        ..    INC length+1
91F8  D0 EF        ..    BNE &91E9
91FA  E6 B8        ..    INC length+2
91FC  D0 EB        ..    BNE &91E9
.
91FE  AE E5 FE     ...   LDX tubedat
9201  20 56 92      V.   JSR &9256                ; Wait for END without timer, then send X with EOI to Data Out register
9204  20 F9 92      ..   JSR reltube              ; Release the TUBE
9207  60           `     RTS

; -----------------------------------------------------------------------------
; Write &0E/&0F From co-pro, with timer, no EOS bytes, send EOI with last byte
; -----------------------------------------------------------------------------
.                                                 ; Entry point
9208  20 EB 92      ..   JSR claimtube            ; Claim the TUBE
920B  20 16 93      ..   JSR &initcotoio          ; Prepare for data transfer from parasite (co-processor) to host (i/o)
920E  E6 B6        ..    INC length+0
9210  D0 08        ..    BNE &921A
9212  E6 B7        ..    INC length+1
9214  D0 04        ..    BNE &921A
9216  E6 B8        ..    INC length+2
9218  F0 12        ..    BEQ &922C
.
921A  AE E5 FE     ...   LDX tubedat
921D  20 78 92      x.   JSR &9278                ; Wait for END with timer, then send X to Data Out register
9220  E6 B6        ..    INC length+0
9222  D0 F6        ..    BNE &921A
9224  E6 B7        ..    INC length+1
9226  D0 F2        ..    BNE &921A
9228  E6 B8        ..    INC length+2
922A  D0 EE        ..    BNE &921A
.
922C  AE E5 FE     ...   LDX tubedat
922F  20 83 92      ..   JSR &9283                ; Wait for END with timer, then send X with EOI to Data Out register
9232  20 F9 92      ..   JSR reltube              ; Release the TUBE
9235  60           `     RTS

; -----------------------------------------------------------------------------
; Wait for END without timer, then send X to Data Out register
; -----------------------------------------------------------------------------
.
9236  A5 B9        ..    LDA intflag
9238  D0 0E        ..    BNE &9248
923A  AD 20 FC     . .   LDA intstatus0           ; Load the TMS9914A's Interrupt Status Register 0
923D  29 10        ).    AND #&10                 ; Check if bit4 is set (END flag)
923F  F0 F5        ..    BEQ &9236                ; If not, then repeat
9241  8E 27 FC     .'.   STX datout               ; Send X to the TMS9914A's Data Out Register
9244  20 3C 9C      <.   JSR &9C3C                ; Wait 3 NOP's
9247  60           `     RTS
.
9248  29 01        ).    AND #&01
924A  D0 05        ..    BNE &9251
924C  A9 06        ..    LDA #&06
924E  4C 94 83     L..   JMP &8394                ; Exit with error code &06
.
9251  A9 05        ..    LDA #&05
9253  4C 94 83     L..   JMP &8394                ; Exit with error code &05

; -----------------------------------------------------------------------------
; Wait for END without timer, then send X with EOI to Data Out register
; -----------------------------------------------------------------------------
.
9256  A5 B9        ..    LDA intflag
9258  D0 10        ..    BNE &926A
925A  AD 20 FC     . .   LDA intstatus0           ; Load the TMS9914A's Interrupt Status Register 0
925D  29 10        ).    AND #&10                 ; Check if bit4 is set (END flag)
925F  F0 F5        ..    BEQ &9256                ; If not, then repeat
9261  A9 08        ..    LDA #feoi                ; Load the mnemonic for the 'Send EOI with next byte' function
9263  8D 26 FC     .&.   STA auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
9266  8E 27 FC     .'.   STX datout               ; Send X to the TMS9914A's Data Out Register
9269  60           `     RTS
.
926A  29 01        ).    AND #&01
926C  D0 05        ..    BNE &9273
926E  A9 06        ..    LDA #&06
9270  4C 94 83     L..   JMP &8394                ; Exit with error code &06
.
9273  A9 05        ..    LDA #&05
9275  4C 94 83     L..   JMP &8394                ; Exit with error code &05

; -----------------------------------------------------------------------------
; Wait for END with timer, then send X to Data Out register
; -----------------------------------------------------------------------------
.
9278  98           .     TYA
9279  48           H     PHA
927A  20 B5 92      ..   JSR &92B5                ; Wait for END with timer
927D  8E 27 FC     .'.   STX datout               ; Send X to the TMS9914A's Data Out Register
9280  68           h     PLA
9281  A8           .     TAY
9282  60           `     RTS

; -----------------------------------------------------------------------------
; Wait for END with timer, then send X with EOI to Data Out register
; -----------------------------------------------------------------------------
.
9283  98           .     TYA
9284  48           H     PHA
9285  20 B5 92      ..   JSR &92B5                ; Wait for END with timer
9288  A9 08        ..    LDA #feoi                ; Load the mnemonic for the 'Send EOI with next byte' function
928A  8D 26 FC     .&.   STA auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
928D  8E 27 FC     .'.   STX datout               ; Send X to the TMS9914A's Data Out Register
9290  68           h     PLA
9291  A8           .     TAY
9292  60           `     RTS

; -----------------------------------------------------------------------------
; Wait for END with or without timer (if (pwrkspc),&F7bit1=1 then with timer, else without timer)
; -----------------------------------------------------------------------------
.
9293  A0 F7        ..    LDY #&F7
9295  B1 B0        ..    LDA (pwrkspc),Y
9297  29 02        ).    AND #&02                 ; Is bit 1 set of (pwrkspc),&F7?
9299  D0 1A        ..    BNE &92B5                ; Wait for END with timer
.                                                 ; Wait for END without timer
929B  A5 B9        ..    LDA intflag
929D  D0 08        ..    BNE &92A7
929F  AD 20 FC     . .   LDA intstatus0           ; Load the TMS9914A's Interrupt Status Register 0
92A2  29 10        ).    AND #&10                 ; Check if bit4 is set (END flag)
92A4  F0 F5        ..    BEQ &929B                ; If not, then repeat
92A6  60           `     RTS
.
92A7  29 01        ).    AND #&01
92A9  D0 05        ..    BNE &92B0
92AB  A9 06        ..    LDA #&06
92AD  4C 94 83     L..   JMP &8394                ; Exit with error code &06
.
92B0  A9 05        ..    LDA #&05
92B2  4C 94 83     L..   JMP &8394                ; Exit with error code &05

; -----------------------------------------------------------------------------
; Wait for END with timer
; -----------------------------------------------------------------------------
.
92B5  A0 FA         ..   LDY #&FA
92B7  B1 B0        ..    LDA (pwrkspc),Y
92B9  85 BA        ..    STA timer+0              ; timer+0 = ?(pwrkspc+&FA)
92BB  C8           .     INY
92BC  B1 B0        ..    LDA (pwrkspc),Y
92BE  85 BB        ..    STA timer+1              ; timer+1 = ?(pwrkspc+&FB)
92C0  C8           .     INY
92C1  B1 B0        ..    LDA (pwrkspc),Y
92C3  85 BC        ..    STA timer+2              ; timer+2 = ?(pwrkspc+&FC)
92C5  C8           .     INY
92C6  B1 B0        ..    LDA (pwrkspc),Y
92C8  85 BD        ..    STA timer+3              ; timer+3 = ?(pwrkspc+&FD)
.
92CA  E6 BA         ..   INC timer+0
92CC  D0 11        ..    BNE &92DF
92CE  E6 BB         ..   INC timer+1
92D0  D0 0D        ..    BNE &92DF
92D2  E6 BC         ..   INC timer+2
92D4  D0 09        ..    BNE &92DF
92D6  E6 BD         ..   INC timer+3
92D8  D0 05        ..    BNE &92DF
92DA  A9 07         ..   LDA #&07                 ; Timer has timed out
92DC  4C 94 83     L..   JMP &8394                ; Exit with error code &07
.
92DF  A5 B9        ..    LDA intflag
92E1  D0 C4        ..    BNE &92A7
92E3  AD 20 FC     . .   LDA intstatus0           ; Load the TMS9914A's Interrupt Status Register 0
92E6  29 10        ).    AND #&10                 ; Check if bit4 is set (END flag)
92E8  F0 E0        ..    BEQ &92CA
92EA  60           `     RTS

; -----------------------------------------------------------------------------
; Claim the TUBE
; -----------------------------------------------------------------------------
.claimtube
92EB  A9 CF        ..    LDA #&C0+tubeid          ; ID code = &F
92ED  20 06 04      ..   JSR tubecontrol          ; Call the TUBE control subroutine
92F0  90 F9        ..    BCC &92EB                ; Repeat if TUBE not successfully claimed
92F2  A0 0A        ..    LDY #&0A
92F4  A9 FF         ..   LDA #&FF
92F6  91 B0        ..    STA (pwrkspc),Y
92F8  60           `     RTS

; -----------------------------------------------------------------------------
; Release the TUBE
; -----------------------------------------------------------------------------
.reltube
92F9  20 30 9C      0.   JSR &9C30
92FC  EA           .     NOP                      ; 1 NOP = 2 clockcycles
92FD  EA           .     NOP
92FE  EA           .     NOP
92FF  EA           .     NOP
9300  A9 8F        ..    LDA #&80+tubeid          ; ID code = &F
9302  20 06 04      ..   JSR tubecontrol          ; Call the TUBE control subroutine
9305  A0 0A        ..    LDY #&0A
9307  A9 00        ..    LDA #&00
9309  91 B0        ..    STA (pwrkspc),Y
930B  60           `     RTS

; -----------------------------------------------------------------------------
; Prepare for data transfer from parasite (co-processor) to host (i/o)
; -----------------------------------------------------------------------------
.initiotoco
930C  A2 B2        ..    LDX #&B2                 ; Parameter block is at &00B2
930E  A0 00        ..    LDY #&00
9310  A9 01        ..    LDA #&01                 ; Multiple single byte transfer from I/O to parasite
9312  20 06 04      ..   JSR tubecontrol          ; Call the TUBE control subroutine
9315  60           `     RTS

; -----------------------------------------------------------------------------
; Prepare for data transfer from parasite (co-processor) to host (i/o)
; -----------------------------------------------------------------------------
.initcotoio
9316  A2 B2        ..    LDX #&B2                 ; Parameter block is at &00B2
9318  A0 00        ..    LDY #&00
931A  A9 00        ..    LDA #&00                 ; Multiple single byte transfer from parasite to I/O
931C  20 06 04      ..   JSR tubecontrol          ; Call the TUBE control subroutine
931F  20 30 9C      0.   JSR &9C30
9322  EA           .     NOP                      ; 1 NOP = 2 clockcycles
9323  EA           .     NOP
9324  EA           .     NOP
9325  EA           .     NOP
9326  EA           .     NOP
9327  60           `     RTS

; -----------------------------------------------------------------------------
; OSWORD call &80 command &37
; -----------------------------------------------------------------------------
.
9328  20 F0 8C      ..   JSR &8CF0                ; Transfer XY+&06-&09 to 'memadr' and XY+&0A-&0C to 'length'
932B  20 71 84      q.   JSR &8471                ; If (pwrkspc),&04 = &00 then exit with error code &01
932E  A0 F6        ..    LDY #&F6
9330  B1 B0        ..    LDA (pwrkspc),Y
9332  29 02        ).    AND #&02
9334  F0 06        ..    BEQ &933C                ; Jump if bit 1 is not set
9336  20 34 8C      4.   JSR &8C34                ; Wait for REN=0 with timer
9339  4C 3F 93     L?.   JMP &933F
.
933C  20 1A 8C      ..   JSR &8C1A                ; Wait for REN=0 without timer
.
933F  20 DA 93      ..   JSR &93DA                ; OSWORD &80 commands &37/&39/&3B/&3D/&3F (Read) Jump to subroutine
9342  20 B4 93      ..   JSR &93B4                ; Store the number of bytes read in XY+&0A-&0D
9345  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; OSWORD call &80 command &39
; -----------------------------------------------------------------------------
.
9348  20 F0 8C      ..   JSR &8CF0                ; Transfer XY+&06-&09 to 'memadr' and XY+&0A-&0C to 'length'
934B  20 89 84      ..   JSR &8489                ; Check if this controller is the active controller on the GPIB bus
934E  20 D4 89      ..   JSR &89D4                ; X = XY+&04
9351  20 2B 89      +.   JSR &892B                ; Send UNL, MLA (pwrkspc,&01) and MTA (X)
9354  20 51 8A      Q.   JSR &8A51                ; Conditional GTS (Go To Standby)
9357  20 DA 93      ..   JSR &93DA                ; OSWORD &80 commands &37/&39/&3B/&3D/&3F (Read) Jump to subroutine
935A  20 B4 93      ..   JSR &93B4                ; Store the number of bytes read in XY+&0A-&0D
935D  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; OSWORD call &80 command &3B
; -----------------------------------------------------------------------------
.
9360  20 F0 8C      ..   JSR &8CF0                ; Transfer XY+&06-&09 to 'memadr' and XY+&0A-&0C to 'length'
9363  20 89 84      ..   JSR &8489                ; Check if this controller is the active controller on the GPIB bus
9366  20 DA 89      ..   JSR &89DA                ; X = XY+&04, A = XY+&O5
9369  20 47 89      G.   JSR &8947                ; Send UNL, MLA (pwrkspc,&01), MTA (X) and MSA (A)
936C  20 51 8A      Q.   JSR &8A51                ; Conditional GTS (Go To Standby)
936F  20 DA 93      ..   JSR &93DA                ; OSWORD &80 commands &37/&39/&3B/&3D/&3F (Read) Jump to subroutine
9372  20 B4 93      ..   JSR &93B4                ; Store the number of bytes read in XY+&0A-&0D
9375  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; OSWORD call &80 command &3D
; -----------------------------------------------------------------------------
.
9378  20 F0 8C      ..   JSR &8CF0                ; Transfer XY+&06-&09 to 'memadr' and XY+&0A-&0C to 'length'
937B  20 89 84      ..   JSR &8489                ; Check if this controller is the active controller on the GPIB bus
937E  20 D4 89      ..   JSR &89D4                ; X = XY+&04
9381  20 2B 89      +.   JSR &892B                ; Send UNL, MLA (pwrkspc,&01) and MTA (X)
9384  20 51 8A      Q.   JSR &8A51                ; Conditional GTS (Go To Standby)
9387  20 DA 93      ..   JSR &93DA                ; OSWORD &80 commands &37/&39/&3B/&3D/&3F (Read) Jump to subroutine
938A  20 B4 93      ..   JSR &93B4                ; Store the number of bytes read in XY+&0A-&0D
938D  20 92 88      ..   JSR &8892                ; Send UNT
9390  20 51 8A      Q.   JSR &8A51                ; Conditional GTS (Go To Standby)
9393  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; OSWORD call &80 command &3F
; -----------------------------------------------------------------------------
.
9396  20 F0 8C      ..   JSR &8CF0                ; Transfer XY+&06-&09 to 'memadr' and XY+&0A-&0C to 'length'
9399  20 89 84      ..   JSR &8489                ; Check if this controller is the active controller on the GPIB bus
939C  20 DA 89      ..   JSR &89DA                ; X = XY+&04, A = XY+&O5
939F  20 47 89      G.   JSR &8947                ; Send UNL, MLA (pwrkspc,&01), MTA (X) and MSA (A)
93A2  20 51 8A      Q.   JSR &8A51                ; Conditional GTS (Go To Standby)
93A5  20 DA 93      ..   JSR &93DA                ; OSWORD &80 commands &37/&39/&3B/&3D/&3F (Read) Jump to subroutine
93A8  20 B4 93      ..   JSR &93B4                ; Store the number of bytes read in XY+&0A-&0D
93AB  20 92 88      ..   JSR &8892                ; Send UNT
93AE  20 51 8A      Q.   JSR &8A51                ; Conditional GTS (Go To Standby)
93B1  4C 5D 83     L].   JMP &835D                ; Exit the OSWORD &80 call

; -----------------------------------------------------------------------------
; Store the number of bytes read in XY+&0A-&0D
; -----------------------------------------------------------------------------
.
93B4  38           8     SEC
93B5  A0 06        ..    LDY #&06
93B7  A5 B2        ..    LDA memadr+0
93B9  F1 F0        ..    SBC (&F0),Y
93BB  A0 0A        ..    LDY #&0A
93BD  91 F0        ..    STA (&F0),Y              ; XY+&0A = memadr+0 - XY+&06
93BF  A0 07        ..    LDY #&07
93C1  A5 B3        ..    LDA memadr+1
93C3  F1 F0        ..    SBC (&F0),Y
93C5  A0 0B        ..    LDY #&0B
93C7  91 F0        ..    STA (&F0),Y              ; XY+&0B = memadr+1 - XY+&07 - C
93C9  A0 08        ..    LDY #&08
93CB  A5 B4        ..    LDA memadr+2
93CD  F1 F0        ..    SBC (&F0),Y
93CF  A0 0C        ..    LDY #&0C
93D1  91 F0        ..    STA (&F0),Y              ; XY+&0C = memadr+2 - XY+&08 - C
93D3  A0 0D        ..    LDY #&0D
93D5  A9 00        ..    LDA #&00
93D7  91 F0        ..    STA (&F0),Y              ; XY+&0D = 0
93D9  60           `     RTS

; -----------------------------------------------------------------------------
; OSWORD &80 commands &37/&39/&3B/&3D/&3F (Read) Jump to subroutine
; -----------------------------------------------------------------------------
.
93DA  20 1F 9C      ..   JSR &9C1F
93DD  A0 F6        ..    LDY #&F6
93DF  B1 B0        ..    LDA (pwrkspc),Y
93E1  AA           .     TAX
93E2  BD EB 93     ...   LDA &93EB,X
93E5  48           H     PHA
93E6  BD 0B 94     ...   LDA &940B,X
93E9  48           H     PHA
93EA  60           `     RTS

; -----------------------------------------------------------------------------
; OSWORD &80 commands &37/&39/&3B/&3D/&3F (Read) lookup table MSB
; -----------------------------------------------------------------------------
.
93EB  94           .     EQUB &94                 ; (&942B) &00
93EC  94           .     EQUB &94                 ; (&9463) &01
93ED  94           .     EQUB &94                 ; (&94B6) &02
93EE  94           .     EQUB &94                 ; (&94E1) &03
93EF  95           .     EQUB &95                 ; (&951F) &04
93F0  95           .     EQUB &95                 ; (&954E) &05
93F1  95           .     EQUB &95                 ; (&958E) &06
93F2  95           .     EQUB &95                 ; (&95BA) &07
93F3  95           .     EQUB &95                 ; (&95F7) &08
93F4  95           .     EQUB &95                 ; (&95F7) &09
93F5  96           .     EQUB &96                 ; (&963D) &0A
93F6  96           .     EQUB &96                 ; (&963D) &0B
93F7  96           .     EQUB &96                 ; (&966D) &0C
93F8  96           .     EQUB &96                 ; (&966D) &0D
93F9  96           .     EQUB &96                 ; (&96AC) &0E
93FA  96           .     EQUB &96                 ; (&96AC) &0F
93FB  96           .     EQUB &96                 ; (&96E3) &10
93FC  96           .     EQUB &96                 ; (&96E3) &11
93FD  97           .     EQUB &97                 ; (&9726) &12
93FE  97           .     EQUB &97                 ; (&9726) &13
93FF  97           .     EQUB &97                 ; (&975C) &14
9400  97           .     EQUB &97                 ; (&975C) &15
9401  97           .     EQUB &97                 ; (&97A0) &16
9402  97           .     EQUB &97                 ; (&97A0) &17
9403  97           .     EQUB &97                 ; (&97E1) &18
9404  98           .     EQUB &98                 ; (&9844) &19
9405  98           .     EQUB &98                 ; (&98E7) &1A
9406  99           .     EQUB &99                 ; (&992F) &1B
9407  99           .     EQUB &99                 ; (&99B0) &1C
9408  99           .     EQUB &99                 ; (&99FB) &1D
9409  9A           .     EQUB &9A                 ; (&9A85) &1E
940A  9A           .     EQUB &9A                 ; (&9ACB) &1F

; -----------------------------------------------------------------------------
; OSWORD &80 commands &37/&39/&3B/&3D/&3F (Read) lookup table LSB
; -----------------------------------------------------------------------------
.
940B  2A           .     EQUB &2A
940C  62           b     EQUB &62
940D  B5           .     EQUB &B5
940E  E0           .     EQUB &E0
940F  1E           .     EQUB &1E
9410  4D           M     EQUB &4D
9411  8D           .     EQUB &8D
9412  B9           .     EQUB &B9
9413  F6           .     EQUB &F6
9414  F6           .     EQUB &F6
9415  3C           <     EQUB &3C
9416  3C           <     EQUB &3C
9417  6C           l     EQUB &6C
9418  6C           l     EQUB &6C
9419  AB           .     EQUB &AB
941A  AB           .     EQUB &AB
941B  E2           .     EQUB &E2
941C  E2           .     EQUB &E2
941D  25           %     EQUB &25
941E  25           %     EQUB &25
941F  5B           [     EQUB &5B
9420  5B           [     EQUB &5B
9421  9F           .     EQUB &9F
9422  9F           .     EQUB &9F
9423  E0           .     EQUB &E0
9424  43           C     EQUB &43
9425  E6           .     EQUB &E6
9425  2E           .     EQUB &2E
9427  AF           .     EQUB &AF
9428  FA           .     EQUB &FA
9429  84           .     EQUB &84
942A  CA           .     EQUB &CA

; -----------------------------------------------------------------------------
; Read &00 : To host, without timer, 1 EOS byte, no EOI with last byte
; -----------------------------------------------------------------------------
.                                                 ; Entry point
942B  20 11 9C      ..   JSR &9C11                ; ?&BE = ?(pwrkspc+&F8)
942E  A0 00        ..    LDY #&00
9430  A2 02        ..    LDX #clr+rhdf            ; Load the mnemonic for the 'Clear Release RFD holdoff' function
9432  4C 3F 94     L?.   JMP &943F
.
9435  8E 26 FC     .&.   STX auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
9438  91 B2        ..    STA (memadr),Y
943A  C8           .     INY
943B  D0 02        ..    BNE &943F
943D  E6 B3        ..    INC memadr+1
.
943F  A9 20        .     LDA #&20                 ; 00100000
.                                                 ; Wait for SPAS without timer
9441  24 B9        $.    BIT intflag
9443  30 19        0.    BMI &945E                ; Exit this procedure when bit 7 of &B9 is set
9445  2C 20 FC     , .   BIT intstatus0
9448  F0 F7        ..    BEQ &9441                ; Wait for SPAS without timer
944A  AD 27 FC     .'.   LDA datin
944D  C5 BE        ..    CMP &BE
944F  D0 E4        ..    BNE &9435
9451  18           .     CLC
9452  98           .     TYA
9453  65 B2        e.    ADC memadr+0
9455  85 B2        ..    STA memadr+0
9457  A9 00        ..    LDA #&00
9459  65 B3        e.    ADC memadr+1
945B  85 B3        ..    STA memadr+1
945D  60           `     RTS
.
945E  A9 05        ..    LDA #&05
9460  4C 94 83     L..   JMP &8394                ; Exit with error code &05

; -----------------------------------------------------------------------------
; Read &01 : To host, without timer, 2 EOS bytes, no EOI with last byte
; -----------------------------------------------------------------------------
.                                                 ; Entry point
9463  20 11 9C      ..   JSR &9C11                ; ?&BE = ?(pwrkspc+&F8)
9466  20 18 9C      ..   JSR &9C18                ; ?&BF = ?(pwrkspc+&F9)
9469  A0 00        ..    LDY #&00
946B  A9 20        .     LDA #&20                 ; 00100000
.                                                 ; Wait for SPAS without timer
946D  24 B9        $.    BIT intflag
946F  30 40        0@    BMI &94B1                ; Exit this procedure when bit 7 of &B9 is set
9471  2C 20 FC     , .   BIT intstatus0
9474  F0 F7        ..    BEQ &946D                ; Wait for SPAS without timer
9476  AE 27 FC     .'.   LDX datin
9479  A9 02        ..    LDA #clr+rhdf            ; Load the mnemonic for the 'Clear Release RFD holdoff' function
947B  8D 26 FC     .&.   STA auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
947E  4C 8D 94     L..   JMP &948D
.
9481  91 B2        ..    STA (memadr),Y
9483  A9 02        ..    LDA #clr+rhdf            ; Load the mnemonic for the 'Clear Release RFD holdoff' function
9485  8D 26 FC     .&.   STA auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
9488  C8           .     INY
9489  D0 02        ..    BNE &948D
948B  E6 B3        ..    INC memadr+1
.
948D  A9 20        .     LDA #&20                 ; 00100000
.                                                 ; Wait for SPAS without timer
948F  24 B9        $.    BIT intflag
9491  30 1E        0.    BMI &94B1                ; Exit this procedure when bit 7 of &B9 is set
9493  2C 20 FC     , .   BIT intstatus0
9496  F0 F7        ..    BEQ &948F                ; Wait for SPAS without timer
9498  8A           .     TXA
9499  AE 27 FC     .'.   LDX datin
949C  E4 BF        ..    CPX &BF
949E  D0 E1        ..    BNE &9481
94A0  C5 BE        ..    CMP &BE
94A2  D0 DD        ..    BNE &9481
94A4  18           .     CLC
94A5  98           .     TYA
94A6  65 B2        e.    ADC memadr+0
94A8  85 B2        ..    STA memadr+0
94AA  A9 00        ..    LDA #&00
94AC  65 B3        e.    ADC memadr+1
94AE  85 B3        ..    STA memadr+1
94B0  60           `     RTS
.
94B1  A9 05        ..    LDA #&05
94B3  4C 94 83     L..   JMP &8394                ; Exit with error code &05

; -----------------------------------------------------------------------------
; Read &02 : To host, with timer, 1 EOS byte, no EOI with last byte
; -----------------------------------------------------------------------------
.                                                 ; Entry point
94B6  20 11 9C      ..   JSR &9C11                ; ?&BE = ?(pwrkspc+&F8)
94B9  A0 00        ..    LDY #&00
94BB  A2 02        ..    LDX #clr+rhdf            ; Load the mnemonic for the 'Clear Release RFD holdoff' function
94BD  4C CA 94     L..   JMP &94CA
.
94C0  8E 26 FC     .&.   STX auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
94C3  91 B2        ..    STA (memadr),Y
94C5  C8           .     INY
94C6  D0 02        ..    BNE &94CA
94C8  E6 B3        ..    INC memadr+1
.
94CA  20 83 9B      ..   JSR &9B83                ; Wait for SPAS with timer
94CD  AD 27 FC     .'.   LDA datin
94D0  C5 BE        ..    CMP &BE
94D2  D0 EC        ..    BNE &94C0
94D4  18           .     CLC
94D5  98           .     TYA
94D6  65 B2        e.    ADC memadr+0
94D8  85 B2        ..    STA memadr+0
94DA  A9 00        ..    LDA #&00
94DC  65 B3        e.    ADC memadr+1
94DE  85 B3        ..    STA memadr+1
94E0  60           `     RTS

; -----------------------------------------------------------------------------
; Read &03 : To host, with timer, 2 closing byte, no EOI with last byte
; -----------------------------------------------------------------------------
.                                                 ; Entry point
94E1  20 11 9C      ..   JSR &9C11                ; ?&BE = ?(pwrkspc+&F8)
94E4  20 18 9C      ..   JSR &9C18                ; ?&BF = ?(pwrkspc+&F9)
94E7  A0 00        ..    LDY #&00
94E9  20 83 9B      ..   JSR &9B83                ; Wait for SPAS with timer
94EC  AE 27 FC     .'.   LDX datin
94EF  A9 02        ..    LDA #clr+rhdf            ; Load the mnemonic for the 'Clear Release RFD holdoff' function
94F1  8D 26 FC     .&.   STA auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
94F4  4C 03 95     L..   JMP &9503
.
94F7  91 B2        ..    STA (memadr),Y
94F9  A9 02        ..    LDA #clr+rhdf            ; Load the mnemonic for the 'Clear Release RFD holdoff' function
94FB  8D 26 FC     .&.   STA auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
94FE  C8           .     INY
94FF  D0 02        ..    BNE &9503
9501  E6 B3        ..    INC memadr+1
.
9503  20 83 9B      ..   JSR &9B83                ; Wait for SPAS with timer
9506  8A           .     TXA
9507  AE 27 FC     .'.   LDX datin
950A  E4 BF        ..    CPX &BF
950C  D0 E9        ..    BNE &94F7
950E  C5 BE        ..    CMP &BE
9510  D0 E5        ..    BNE &94F7
9512  18           .     CLC
9513  98           .     TYA
9514  65 B2        e.    ADC memadr+0
9516  85 B2        ..    STA memadr+0
9518  A9 00        ..    LDA #&00
951A  65 B3        e.    ADC memadr+1
951C  85 B3        ..    STA memadr+1
951E  60           `     RTS

; -----------------------------------------------------------------------------
; Read &04 : To co-pro, without timer, 1 EOS byte, no EOI with last byte
; -----------------------------------------------------------------------------
.                                                 ; Entry point
951F  20 11 9C      ..   JSR &9C11                ; ?&BE = ?(pwrkspc+&F8)
9522  20 EB 92      ..   JSR claimtube            ; Claim the TUBE
9525  20 0C 93      ..   JSR initiotoco           ; Prepare for data transfer from host (i/o) to parasite (co-processor)
9528  A0 02        ..    LDY #clr+rhdf            ; Load the mnemonic for the 'Clear Release RFD holdoff' function
952A  4C 40 95     L@.   JMP &9540
.
952D  8C 26 FC     .&.   STY auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
9530  8E E5 FE     ...   STX tubedat
9533  20 3E 9C      >.   JSR &9C3E                ; Wait 1 NOP's
9536  E6 B2        ..    INC memadr+0
9538  D0 06        ..    BNE &9540
953A  E6 B3        ..    INC memadr+1
953C  D0 02        ..    BNE &9540
953E  E6 B4         ..   INC memadr+2
.
9540  20 51 9B      Q.   JSR &9B51                ; Wait for SPAS without timer
9543  AE 27 FC     .'.   LDX datin
9546  E4 BE        ..    CPX &BE
9548  D0 E3        ..    BNE &952D
954A  20 F9 92      ..   JSR reltube              ; Release the TUBE
954D  60           `     RTS

; -----------------------------------------------------------------------------
; Read &05 : To co-pro, without timer, 2 closing byte, no EOI with last byte
; -----------------------------------------------------------------------------
.                                                 ; Entry point
954E  20 11 9C      ..   JSR &9C11                ; ?&BE = ?(pwrkspc+&F8)
9551  20 18 9C      ..   JSR &9C18                ; ?&BF = ?(pwrkspc+&F9)
9554  20 EB 92      ..   JSR claimtube            ; Claim the TUBE
9557  20 0C 93      ..   JSR initiotoco           ; Prepare for data transfer from host (i/o) to parasite (co-processor)
955A  A0 02        ..    LDY #clr+rhdf            ; Load the mnemonic for the 'Clear Release RFD holdoff' function
955C  20 51 9B      Q.   JSR &9B51                ; Wait for SPAS without timer
955F  AE 27 FC     .'.   LDX datin
9562  8C 26 FC     .&.   STY auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
9565  4C 7B 95     L{.   JMP &957B
.
9568  8C 26 FC     .&.   STY auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
956B  8D E5 FE     ...   STA tubedat
956E  20 39 9C      9.   JSR &9C39
9571  E6 B2        ..    INC memadr+0
9573  D0 06        ..    BNE &957B
9575  E6 B3        ..    INC memadr+1
9577  D0 02        ..    BNE &957B
9579  E6 B4        ..    INC memadr+2
.
957B  20 51 9B      Q.   JSR &9B51                ; Wait for SPAS without timer
957E  8A           .     TXA
957F  AE 27 FC     .'.   LDX datin
9582  E4 BF        ..    CPX &BF
9584  D0 E2        ..    BNE &9568
9586  C5 BE        ..    CMP &BE
9588  D0 DE        ..    BNE &9568
958A  20 F9 92      ..   JSR reltube              ; Release the TUBE
958D  60           `     RTS

; -----------------------------------------------------------------------------
; Read &06 : To co-pro, with timer, 1 EOS byte, no EOI with last byte
; -----------------------------------------------------------------------------
.                                                 ; Entry point
958E  20 11 9C      ..   JSR &9C11                ; ?&BE = ?(pwrkspc+&F8)
9591  20 EB 92      ..   JSR claimtube            ; Claim the TUBE
9594  20 0C 93      ..   JSR initiotoco           ; Prepare for data transfer from host (i/o) to parasite (co-processor)
9597  A0 02        ..    LDY #clr+rhdf            ; Load the mnemonic for the 'Clear Release RFD holdoff' function
9599  4C AC 95     L..   JMP &95AC
.
959C  8C 26 FC     .&.   STY auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
959F  8E E5 FE     ...   STX tubedat
95A2  E6 B2        ..    INC memadr+0
95A4  D0 06        ..    BNE &95AC
95A6  E6 B3        ..    INC memadr+1
95A8  D0 02        ..    BNE &95AC
95AA  E6 B4        ..    INC memadr+2
.
95AC  20 83 9B      ..   JSR &9B83                ; Wait for SPAS with timer
95AF  AE 27 FC     .'.   LDX datin
95B2  E4 BE        ..    CPX &BE
95B4  D0 E6        ..    BNE &959C
95B6  20 F9 92      ..   JSR reltube              ; Release the TUBE
95B9  60           `     RTS

; -----------------------------------------------------------------------------
; Read &07 : co-pro, with timer, 2 closing byte, no EOI with last byte
; -----------------------------------------------------------------------------
.                                                 ; Entry point
95BA  20 11 9C      ..   JSR &9C11                ; ?&BE = ?(pwrkspc+&F8)
95BD  20 18 9C      ..   JSR &9C18                ; ?&BF = ?(pwrkspc+&F9)
95C0  20 EB 92      ..   JSR claimtube            ; Claim the TUBE
95C3  20 0C 93      ..   JSR initiotoco           ; Prepare for data transfer from host (i/o) to parasite (co-processor)
95C6  A0 02        ..    LDY #clr+rhdf            ; Load the mnemonic for the 'Clear Release RFD holdoff' function
95C8  20 83 9B      ..   JSR &9B83                ; Wait for SPAS with timer
95CB  AE 27 FC     .'.   LDX datin
95CE  8C 26 FC     .&.   STY auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
95D1  4C E4 95     L..   JMP &95E4
.
95D4  8C 26 FC     .&.   STY auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
95D7  8D E5 FE     ...   STA tubedat
95DA  E6 B2        ..    INC memadr+0
95DC  D0 06        ..    BNE &95E4
95DE  E6 B3        ..    INC memadr+1
95E0  D0 02        ..    BNE &95E4
95E2  E6 B4        ..    INC memadr+2
.
95E4  20 83 9B      ..   JSR &9B83                ; Wait for SPAS with timer
95E7  8A           .     TXA
95E8  AE 27 FC     .'.   LDX datin
95EB  E4 BF        ..    CPX &BF
95ED  D0 E5        ..    BNE &95D4
95EF  C5 BE        ..    CMP &BE
95F1  D0 E1        ..    BNE &95D4
95F3  20 F9 92      ..   JSR reltube              ; Release the TUBE
95F6  60           `     RTS

; -----------------------------------------------------------------------------
; Read &08/&09 : To host, without timer, no EOS bytes, last byte sent with EOI
; -----------------------------------------------------------------------------
.                                                 ; Entry point
95F7  A0 00        ..    LDY #&00
95F9  A2 02        ..    LDX #clr+rhdf            ; Load the mnemonic for the 'Clear Release RFD holdoff' function
95FB  4C 0B 96     L..   JMP &960B
.
95FE  AD 27 FC     .'.   LDA datin
9601  8E 26 FC     .&.   STX auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
9604  91 B2        ..    STA (memadr),Y
9606  C8           .     INY
9607  D0 02        ..    BNE &960B
9609  E6 B3        ..    INC memadr+1
.
960B  24 B9        $.    BIT intflag
960D  30 29        0)    BMI &9638                ; Exit this procedure when bit 7 of &B9 is set
960F  AD 20 FC     . .   LDA intstatus0           ; Load the TMS9914A's Interrupt Status Register 0
9612  29 28        )(    AND #&28                 ; Check if the SPAS bit (bit 5) and the BO (bit 3) are set
9614  F0 F5        ..    BEQ &960B                ; If not, then repeat
9616  C9 20        .     CMP #&20                 ; Is only the SPAS bit (bit 5) set?
9618  F0 E4        ..    BEQ &95FE
961A  C9 28        .(    CMP #&28                 ; Are both the SPAS bit (bit 5) and the BO bit (bit 3) set?
961C  F0 03        ..    BEQ &9621
961E  AD 20 FC     . .   LDA intstatus0           ; Clear bit2-7 in the TMS9914A's Interrupt Status Register 0
.
9621  AD 27 FC     .'.   LDA datin
9624  91 B2        ..    STA (memadr),Y
9626  C8           .     INY
9627  D0 02        ..    BNE &962B
9629  E6 B3        ..    INC memadr+1
.
962B  18           .     CLC
962C  98           .     TYA
962D  65 B2        e.    ADC memadr+0
962F  85 B2        ..    STA memadr+0
9631  A9 00        ..    LDA #&00
9633  65 B3        e.    ADC memadr+1
9635  85 B3        ..    STA memadr+1
9637  60           `     RTS
.
9638  A9 05        ..    LDA #&05
963A  4C 94 83     L..   JMP &8394                ; Exit with error code &05

; -----------------------------------------------------------------------------
; Read &0A/&0B : To host, with timer, no EOS bytes, last byte sent with EOI
; -----------------------------------------------------------------------------
.                                                 ; Entry point
963D  A0 00        ..    LDY #&00
963F  A2 02        ..    LDX #clr+rhdf            ; Load the mnemonic for the 'Clear Release RFD holdoff' function
9641  4C 51 96     LQ.   JMP &9651
.
9644  AD 27 FC     .'.   LDA datin
9647  8E 26 FC     .&.   STX auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
964A  91 B2        ..    STA (memadr),Y
964C  C8           .     INY
964D  D0 02        ..    BNE &9651
964F  E6 B3        ..    INC memadr+1
.
9651  20 C2 9B      ..   JSR waitBIretend
9654  F0 EE        ..    BEQ &9644
9656  AD 27 FC     .'.   LDA datin
9659  91 B2        ..    STA (memadr),Y
965B  C8           .     INY
965C  D0 02        ..    BNE &9660
965E  E6 B3        ..    INC memadr+1
.
9660  18           .     CLC
9661  98           .     TYA
9662  65 B2        e.    ADC memadr+0
9664  85 B2        ..    STA memadr+0
9666  A9 00        ..    LDA #&00
9668  65 B3        e.    ADC memadr+1
966A  85 B3        ..    STA memadr+1
966C  60           `     RTS


; -----------------------------------------------------------------------------
; Read &0C/&0D : co-pro, without timer, no EOS bytes, last byte sent with EOI
; -----------------------------------------------------------------------------
.rdcoend
966D  20 EB 92      ..   JSR claimtube            ; Claim the TUBE
9670  20 0C 93      ..   JSR initiotoco           ; Prepare for data transfer from host (i/o) to parasite (co-processor)
9673  A0 02        ..    LDY #clr+rhdf            ; Load the mnemonic for the 'Clear Release RFD holdoff' function
9675  4C 90 96     L..   JMP rdcoend1

.rdcoend2
9678  AD 27 FC     .'.   LDA datin
967B  8C 26 FC     .&.   STY auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
967E  8D E5 FE     ...   STA tubedat
9681  EA           .     NOP                      ; 1 NOP = 2 clockcycles
9682  EA           .     NOP
9683  EA           .     NOP
9684  EA           .     NOP
9685  EA           .     NOP
9686  E6 B2        ..    INC memadr+0
9688  D0 06        ..    BNE rdcoend1
968A  E6 B3        ..    INC memadr+1
968C  D0 02        ..    BNE rdcoend1
968E  E6 B4        ..    INC memadr+2

.rdcoend1
9690  20 62 9B      b.   JSR waitBIend
9693  F0 E3        ..    BEQ rdcoend2
9695  EA           .     NOP                      ; 1 NOP = 2 clockcycles
9696  EA           .     NOP
9697  EA           .     NOP
9698  AD 27 FC     .'.   LDA datin
969B  8D E5 FE     ...   STA tubedat
969E  E6 B2        ..    INC memadr+0
96A0  D0 06        ..    BNE rdcoend3
96A2  E6 B3        ..    INC memadr+1
96A4  D0 02        ..    BNE rdcoend3
96A6  E6 B4        ..    INC memadr+2

.rdcoend3
96A8  20 F9 92      ..   JSR reltube              ; Release the TUBE
96AB  60           `     RTS


; -----------------------------------------------------------------------------
; Read &0E/&0F : To co-pro, with timer, no EOS bytes, last byte sent with EOI
; -----------------------------------------------------------------------------
.rdcoretend
96AC  20 EB 92      ..   JSR claimtube            ; Claim the TUBE
96AF  20 0C 93      ..   JSR initiotoco           ; Prepare for data transfer from host (i/o) to parasite (co-processor)
96B2  A0 02        ..    LDY #clr+rhdf            ; Load the mnemonic for the 'Clear Release RFD holdoff' function
96B4  4C CA 96     L..   JMP rdcoretend1

.rdcoretend2
96B7  AD 27 FC     .'.   LDA datin
96BA  8C 26 FC     .&.   STY auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
96BD  8D E5 FE     ...   STA tubedat
96C0  E6 B2        ..    INC memadr+0
96C2  D0 06        ..    BNE rdcoretend1
96C4  E6 B3        ..    INC memadr+1
96C6  D0 02        ..    BNE rdcoretend1
96C8  E6 B4        ..    INC memadr+2

.rdcoretend1
96CA  20 C2 9B      ..   JSR waitBIretend
96CD  F0 E8        ..    BEQ rdcoretend2
96CF  AD 27 FC     .'.   LDA datin
96D2  8D E5 FE     ...   STA tubedat
96D5  E6 B2        ..    INC memadr+0
96D7  D0 06        ..    BNE rdcoretend3
96D9  E6 B3        ..    INC memadr+1
96DB  D0 02        ..    BNE rdcoretend3
96DD  E6 B4        ..    INC memadr+2

.rdcoretend3
96DF  20 F9 92      ..   JSR reltube              ; Release the TUBE
96E2  60           `     RTS

; -----------------------------------------------------------------------------
; Read &10/&11 : To host, without timer, no EOS bytes, no EOI with last byte
; -----------------------------------------------------------------------------
.                                                 ; Entry point
96E3  20 AE 8D      ..   JSR &8DAE                ; Check if nr. of bytes to be transferred > 0
96E6  A0 00        ..    LDY #&00
96E8  A2 02        ..    LDX #clr+rhdf            ; Load the mnemonic for the 'Clear Release RFD holdoff' function
96EA  4C F7 96     L..   JMP &96F7
.
96ED  8E 26 FC     .&.   STX auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
96F0  91 B2        ..    STA (memadr),Y
96F2  C8           .     INY
96F3  D0 02        ..    BNE &96F7
96F5  E6 B3        ..    INC memadr+1
.
96F7  A9 20        .     LDA #&20                 ; mask: 00100000
.                                                 ; Wait for SPAS without timer
96F9  24 B9        $.    BIT intflag
96FB  30 24        0$    BMI &9721                ; Exit this procedure when bit 7 of &B9 is set
96FD  2C 20 FC     , .   BIT intstatus0
9700  F0 F7        ..    BEQ &96F9                ; Wait for SPAS without timer
9702  AD 27 FC     .'.   LDA datin
9705  E6 B6        ..    INC length+0
9707  D0 E4        ..    BNE &96ED
9709  E6 B7        ..    INC length+1
970B  D0 E0        ..    BNE &96ED
970D  91 B2        ..    STA (memadr),Y
970F  C8           .     INY
9710  D0 02        ..    BNE &9714
9712  E6 B3        ..    INC memadr+1
.
9714  18           .     CLC
9715  98           .     TYA
9716  65 B2        e.    ADC memadr+0
9718  85 B2        ..    STA memadr+0
971A  A9 00        ..    LDA #&00
971C  65 B3        e.    ADC memadr+1
971E  85 B3        ..    STA memadr+1
9720  60           `     RTS
.
9721  A9 05        ..    LDA #&05
9723  4C 94 83     L..   JMP &8394                ; Exit with error code &05

; -----------------------------------------------------------------------------
; Read &12/&13 : To host, with timer, no EOS bytes, no EOI with last byte
; -----------------------------------------------------------------------------
.                                                 ; Entry point
9726  20 AE 8D      ..   JSR &8DAE                ; Check if nr. of bytes to be transferred > 0
9729  A0 00        ..    LDY #&00
972B  A2 02        ..    LDX #clr+rhdf            ; Load the mnemonic for the 'Clear Release RFD holdoff' function
972D  4C 3A 97     L:.   JMP &973A
.
9730  8E 26 FC     .&.   STX auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
9733  91 B2        ..    STA (memadr),Y
9735  C8           .     INY
9736  D0 02        ..    BNE &973A
9738  E6 B3        ..    INC memadr+1
.
973A  20 83 9B      ..   JSR &9B83                ; Wait for SPAS with timer
973D  AD 27 FC     .'.   LDA datin
9740  E6 B6        ..    INC length+0
9742  D0 EC        ..    BNE &9730
9744  E6 B7        ..    INC length+1
9746  D0 E8        ..    BNE &9730
9748  91 B2        ..    STA (memadr),Y
974A  C8           .     INY
974B  D0 02        ..    BNE &974F
974D  E6 B3        ..    INC memadr+1
.
974F  18           .     CLC
9750  98           .     TYA
9751  65 B2        e.    ADC memadr+0
9753  85 B2        ..    STA memadr+0
9755  A9 00        ..    LDA #&00
9757  65 B3        e.    ADC memadr+1
9759  85 B3        ..    STA memadr+1
975B  60           `     RTS

; -----------------------------------------------------------------------------
; Read &14/&15 : To co-pro, without timer, no EOS bytes, no EOI with last byte
; -----------------------------------------------------------------------------
.                                                 ; Entry point
975C  20 AE 8D      ..   JSR &8DAE                ; Check if nr. of bytes to be transferred > 0
975F  20 EB 92      ..   JSR claimtube            ; Claim the TUBE
9762  20 0C 93      ..   JSR initiotoco           ; Prepare for data transfer from host (i/o) to parasite (co-processor)
9765  A0 02        ..    LDY #clr+rhdf            ; Load the mnemonic for the 'Clear Release RFD holdoff' function
9767  4C 7D 97     L}.   JMP &977D
.
976A  8C 26 FC     .&.   STY auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
976D  8D E5 FE     ...   STA tubedat
9770  20 3D 9C      =.   JSR &9C3D
9773  E6 B2        ..    INC memadr+0
9775  D0 06        ..    BNE &977D
9777  E6 B3        ..    INC memadr+1
9779  D0 02        ..    BNE &977D
977B  E6 B4        ..    INC memadr+2
.
977D  20 51 9B      Q.   JSR &9B51                ; Wait for SPAS without timer
9780  AD 27 FC     .'.   LDA datin
9783  E6 B6        ..    INC length+0
9785  D0 E3        ..    BNE &976A
9787  E6 B7        ..    INC length+1
9789  D0 DF        ..    BNE &976A
978B  E6 B8        ..    INC length+2
978D  D0 DB        ..    BNE &976A
978F  8D E5 FE     ...   STA tubedat
9792  E6 B2        ..    INC memadr+0
9794  D0 06        ..    BNE &979C
9796  E6 B3        ..    INC memadr+1
9798  D0 02        ..    BNE &979C
979A  E6 B4        ..    INC memadr+2
.
979C  20 F9 92      ..   JSR reltube              ; Release the TUBE
979F  60           `     RTS

; -----------------------------------------------------------------------------
; Read &16/&17 : To co-pro, with timer, no EOS bytes, no EOI with last byte
; -----------------------------------------------------------------------------
.                                                 ; Entry point
97A0  20 AE 8D      ..   JSR &8DAE                ; Check if nr. of bytes to be transferred > 0
97A3  20 EB 92      ..   JSR claimtube            ; Claim the TUBE
97A6  20 0C 93      ..   JSR initiotoco           ; Prepare for data transfer from host (i/o) to parasite (co-processor)
97A9  A0 02        ..    LDY #clr+rhdf            ; Load the mnemonic for the 'Clear Release RFD holdoff' function
97AB  4C BE 97     L..   JMP &97BE
.
97AE  8C 26 FC     .&.   STY auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
97B1  8D E5 FE     ...   STA tubedat
97B4  E6 B2        ..    INC memadr+0
97B6  D0 06        ..    BNE &97BE
97B8  E6 B3        ..    INC memadr+1
97BA  D0 02        ..    BNE &97BE
97BC  E6 B4        ..    INC memadr+2
.
97BE  20 83 9B      ..   JSR &9B83                ; Wait for SPAS with timer
97C1  AD 27 FC     .'.   LDA datin
97C4  E6 B6        ..    INC length+0
97C6  D0 E6        ..    BNE &97AE
97C8  E6 B7        ..    INC length+1
97CA  D0 E2        ..    BNE &97AE
97CC  E6 B8        ..    INC length+2
97CE  D0 DE        ..    BNE &97AE
97D0  8D E5 FE     ...   STA tubedat
97D3  E6 B2        ..    INC memadr+0
97D5  D0 06        ..    BNE &97DD
97D7  E6 B3        ..    INC memadr+1
97D9  D0 02        ..    BNE &97DD
97DB  E6 B4        ..    INC memadr+2
.
97DD  20 F9 92      ..   JSR reltube              ; Release the TUBE
97E0  60           `     RTS

; -----------------------------------------------------------------------------
; Read &18 : To host, without timer, 1 closing bytes, last byte sent with EOI
; -----------------------------------------------------------------------------
.                                                 ; Entry point
97E1  20 11 9C      ..   JSR &9C11                ; ?&BE = ?(pwrkspc+&F8)
97E4  A0 00        ..    LDY #&00
97E6  A2 02        ..    LDX #clr+rhdf            ; Load the mnemonic for the 'Clear Release RFD holdoff' function
97E8  4C F5 97     L..   JMP &97F5
.
97EB  8E 26 FC     .&.   STX auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
97EE  91 B2        ..    STA (memadr),Y
97F0  C8           .     INY
97F1  D0 02        ..    BNE &97F5
97F3  E6 B3        ..    INC memadr+1
.                                                 ; Wait for SPAS and BO without timer
97F5  24 B9        $.    BIT intflag
97F7  30 41        0A    BMI &983A                ; Exit this procedure when bit 7 of &B9 is set
97F9  AD 20 FC     . .   LDA intstatus0           ; Load the TMS9914A's Interrupt Status Register 0
97FC  29 28        )(    AND #&28                 ; Check if the SPAS bit (bit 5) and the BO bit (bit 3) are set
97FE  F0 F5        ..    BEQ &97F5                ; If not, then repeat
9800  C9 20        .     CMP #&20                 ; Is only the SPAS bit (bit 5) set?
9802  D0 14        ..    BNE &9818
9804  AD 27 FC     .'.   LDA datin
9807  C5 BE        ..    CMP &BE
9809  D0 E0        ..    BNE &97EB
980B  18           .     CLC
980C  98           .     TYA
980D  65 B2        e.    ADC memadr+0
980F  85 B2        ..    STA memadr+0
9811  A9 00        ..    LDA #&00
9813  65 B3        e.    ADC memadr+1
9815  85 B3        ..    STA memadr+1
9817  60           `     RTS
.
9818  C9 28        .(    CMP #&28                 ; Are both the SPAS bit (bit 5) and the BO bit (bit 3) set?
981A  F0 03        ..    BEQ &981F
981C  AD 20 FC     . .   LDA intstatus0           ; Clear bit2-7 in the TMS9914A's Interrupt Status Register 0
.
981F  AD 27 FC     .'.   LDA datin
9822  C5 BE        ..    CMP &BE
9824  F0 07        ..    BEQ &982D
9826  91 B2        ..    STA (memadr),Y
9828  C8           .     INY
9829  D0 02        ..    BNE &982D
982B  E6 B3        ..    INC memadr+1
.
982D  18           .     CLC
982E  98           .     TYA
982F  65 B2        e.    ADC memadr+0
9831  85 B2        ..    STA memadr+0
9833  A9 00        ..    LDA #&00
9835  65 B3        e.    ADC memadr+1
9837  85 B3        ..    STA memadr+1
9839  60           `     RTS
.
983A  A9 05        ..    LDA #&05
983C  4C 94 83     L..   JMP &8394                ; Exit with error code &05

; -----------------------------------------------------------------------------
; Read &19 : host, without timer, 2 EOS bytes, last byte sent with EOI
; -----------------------------------------------------------------------------
.
983F  A9 05        ..    LDA #&05
9841  4C 94 83     L..   JMP &8394                ; Exit with error code &05

.                                                 ; Entry point
9844  20 11 9C      ..   JSR &9C11                ; ?&BE = ?(pwrkspc+&F8)
9847  20 18 9C      ..   JSR &9C18                ; ?&BF = ?(pwrkspc+&F9)
984A  A0 00        ..    LDY #&00
.                                                 ; Wait for SPAS and BO without timer
984C  24 B9        $.    BIT intflag
984E  30 EF        0.    BMI &983F                ; Exit this procedure when bit 7 of &B9 is set
9850  AD 20 FC     . .   LDA intstatus0           ; Load the TMS9914A's Interrupt Status Register 0
9853  29 28        )(    AND #&28                 ; Check if the SPAS bit (bit 5) and the BO bit (bit 3) are set
9855  F0 F5        ..    BEQ &984C                ; If not, then repeat
9857  C9 20        .     CMP #&20                 ; Is only the SPAS bit (bit 5) set?
9859  D0 6E        .n    BNE &98C9
985B  AE 27 FC     .'.   LDX datin
985E  A9 02        ..    LDA #clr+rhdf            ; Load the mnemonic for the 'Clear Release RFD holdoff' function
9860  8D 26 FC     .&.   STA auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
9863  4C 72 98     Lr.   JMP &9872
.
9866  91 B2        ..    STA (memadr),Y
9868  A9 02        ..    LDA #clr+rhdf            ; Load the mnemonic for the 'Clear Release RFD holdoff' function
986A  8D 26 FC     .&.   STA auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
986D  C8           .     INY
986E  D0 02        ..    BNE &9872
9870  E6 B3        ..    INC memadr+1
.                                                 ; Wait for SPAS and BO without timer
9872  24 B9        $.    BIT intflag
9874  30 C9        0.    BMI &983F                ; Exit this procedure when bit 7 of &B9 is set
9876  AD 20 FC     . .   LDA intstatus0           ; Load the TMS9914A's Interrupt Status Register 0
9879  29 28        )(    AND #&28                 ; Check if the SPAS bit (bit 5) and the BO bit (bit 3) are set
987B  F0 F5        ..    BEQ &9872                ; If not, then repeat
987D  C9 20        .     CMP #&20                 ; Is only the SPAS bit (bit 5) set?
987F  D0 19        ..    BNE &989A
9881  8A           .     TXA
9882  AE 27 FC     .'.   LDX datin
9885  E4 BF        ..    CPX &BF
9887  D0 DD        ..    BNE &9866
9889  C5 BE        ..    CMP &BE
988B  D0 D9        ..    BNE &9866
988D  18           .     CLC
988E  98           .     TYA
988F  65 B2        e.    ADC memadr+0
9891  85 B2        ..    STA memadr+0
9893  A9 00        ..    LDA #&00
9895  65 B3        e.    ADC memadr+1
9897  85 B3        ..    STA memadr+1
9899  60           `     RTS
.
989A  C9 28        .(    CMP #&28                 ; Are both the SPAS bit (bit 5) and the BO bit (bit 3) set?
989C  F0 03        ..    BEQ &98A1
989E  AD 20 FC     . .   LDA intstatus0           ; Clear bit2-7 in the TMS9914A's Interrupt Status Register 0
.
98A1  8A           .     TXA
98A2  AE 27 FC     .'.   LDX datin
98A5  E4 BF        ..    CPX &BF
98A7  D0 04        ..    BNE &98AD
98A9  C5 BE        ..    CMP &BE
98AB  F0 0F        ..    BEQ &98BC
.
98AD  91 B2        ..    STA (memadr),Y
98AF  C8           .     INY
98B0  D0 02        ..    BNE &98B4
98B2  E6 B3        ..    INC memadr+1
.
98B4  8A           .     TXA
98B5  91 B2        ..    STA (memadr),Y
98B7  C8           .     INY
98B8  D0 02        ..    BNE &98BC
98BA  E6 B3        ..    INC memadr+1
.
98BC  18           .     CLC
98BD  98           .     TYA
98BE  65 B2        e.    ADC memadr+0
98C0  85 B2        ..    STA memadr+0
98C2  A9 00        ..    LDA #&00
98C4  65 B3        e.    ADC memadr+1
98C6  85 B3        ..    STA memadr+1
98C8  60           `     RTS
.
98C9  C9 28        .(    CMP #&28                 ; Are both the SPAS bit (bit 5) and the BO bit (bit 3) set?
98CB  F0 03        ..    BEQ &98D0
98CD  AD 20 FC     . .   LDA intstatus0           ; Clear bit2-7 in the TMS9914A's Interrupt Status Register 0
.
98D0  AD 27 FC     .'.   LDA datin
98D3  91 B2        ..    STA (memadr),Y
98D5  C8           .     INY
98D6  D0 02        ..    BNE &98DA
98D8  E6 B3        ..    INC memadr+1
.
98DA  18           .     CLC
98DB  98           .     TYA
98DC  65 B2        e.    ADC memadr+0
98DE  85 B2        ..    STA memadr+0
98E0  A9 00        ..    LDA #&00
98E2  65 B3        e.    ADC memadr+1
98E4  85 B3        ..    STA memadr+1
98E6  60           `     RTS

; -----------------------------------------------------------------------------
; Read &1A : To host, with timer, 1 closing bytes, last byte sent with EOI
; -----------------------------------------------------------------------------
.                                                 ; Entry point
98E7  20 11 9C      ..   JSR &9C11                ; ?&BE = ?(pwrkspc+&F8)
98EA  A0 00        ..    LDY #&00
98EC  A2 02        ..    LDX #clr+rhdf            ; Load the mnemonic for the 'Clear Release RFD holdoff' function
98EE  4C FB 98     L..   JMP &98FB
.
98F1  8E 26 FC     .&.   STX auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
98F4  91 B2        ..    STA (memadr),Y
98F6  C8           .     INY
98F7  D0 02        ..    BNE &98FB
98F9  E6 B3        ..    INC memadr+1
.
98FB  20 C2 9B      ..   JSR waitBIretend
98FE  D0 14        ..    BNE &9914
9900  AD 27 FC     .'.   LDA datin
9903  C5 BE        ..    CMP &BE
9905  D0 EA        ..    BNE &98F1
9907  18           .     CLC
9908  98           .     TYA
9909  65 B2        e.    ADC memadr+0
990B  85 B2        ..    STA memadr+0
990D  A9 00        ..    LDA #&00
990F  65 B3        e.    ADC memadr+1
9911  85 B3        ..    STA memadr+1
9913  60           `     RTS
.
9914  AD 27 FC     .'.   LDA datin
9917  C5 BE        ..    CMP &BE
9919  F0 07        ..    BEQ &9922
991B  91 B2        ..    STA (memadr),Y
991D  C8           .     INY
991E  D0 02        ..    BNE &9922
9920  E6 B3        ..    INC memadr+1
.
9922  18           .     CLC
9923  98           .     TYA
9924  65 B2        e.    ADC memadr+0
9926  85 B2        ..    STA memadr+0
9928  A9 00        ..    LDA #&00
992A  65 B3        e.    ADC memadr+1
992C  85 B3        ..    STA memadr+1
992E  60           `     RTS

; -----------------------------------------------------------------------------
; Read &1B : To host, with timer, 2 EOS bytes, last byte sent with EOI
; -----------------------------------------------------------------------------
.                                                 ; Entry point
992F  20 11 9C      ..   JSR &9C11                ; ?&BE = ?(pwrkspc+&F8)
9932  20 18 9C      ..   JSR &9C18                ; ?&BF = ?(pwrkspc+&F9)
9935  A0 00        ..    LDY #&00
9937  20 C2 9B      ..   JSR waitBIretend
993A  D0 5D        .]    BNE &9999
993C  AE 27 FC     .'.   LDX datin
993F  A9 02        ..    LDA #clr+rhdf            ; Load the mnemonic for the 'Clear Release RFD holdoff' function
9941  8D 26 FC     .&.   STA auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
9944  4C 53 99     LS.   JMP &9953
.
9947  91 B2        ..    STA (memadr),Y
9949  A9 02        ..    LDA #clr+rhdf            ; Load the mnemonic for the 'Clear Release RFD holdoff' function
994B  8D 26 FC     .&.   STA auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
994E  C8           .     INY
994F  D0 02        ..    BNE &9953
9951  E6 B3        ..    INC memadr+1
.
9953  20 C2 9B      ..   JSR waitBIretend
9956  D0 19        ..    BNE &9971
9958  8A           .     TXA
9959  AE 27 FC     .'.   LDX datin
995C  E4 BF        ..    CPX &BF
995E  D0 E7        ..    BNE &9947
9960  C5 BE        ..    CMP &BE
9962  D0 E3        ..    BNE &9947
9964  18           .     CLC
9965  98           .     TYA
9966  65 B2        e.    ADC memadr+0
9968  85 B2        ..    STA memadr+0
996A  A9 00        ..    LDA #&00
996C  65 B3        e.    ADC memadr+1
996E  85 B3        ..    STA memadr+1
9970  60           `     RTS
.
9971  8A           .     TXA
9972  AE 27 FC     .'.   LDX datin
9975  E4 BF        ..    CPX &BF
9977  D0 04        ..    BNE &997D
9979  C5 BE        ..    CMP &BE
997B  F0 0F        ..    BEQ &998C
.
997D  91 B2        ..    STA (memadr),Y
997F  C8           .     INY
9980  D0 02        ..    BNE &9984
9982  E6 B3        ..    INC memadr+1
.
9984  8A           .     TXA
9985  91 B2        ..    STA (memadr),Y
9987  C8           .     INY
9988  D0 02        ..    BNE &998C
998A  E6 B3        ..    INC memadr+1
.
998C  18           .     CLC
998D  98           .     TYA
998E  65 B2        e.    ADC memadr+0
9990  85 B2        ..    STA memadr+0
9992  A9 00        ..    LDA #&00
9994  65 B3        e.    ADC memadr+1
9996  85 B3        ..    STA memadr+1
9998  60           `     RTS
.
9999  AD 27 FC     .'.   LDA datin
999C  91 B2        ..    STA (memadr),Y
999E  C8           .     INY
999F  D0 02        ..    BNE &99A3
99A1  E6 B3        ..    INC memadr+1
.
99A3  18           .     CLC
99A4  98           .     TYA
99A5  65 B2        e.    ADC memadr+0
99A7  85 B2        ..    STA memadr+0
99A9  A9 00        ..    LDA #&00
99AB  65 B3        e.    ADC memadr+1
99AD  85 B3        ..    STA memadr+1
99AF  60           `     RTS

; -----------------------------------------------------------------------------
; Read &1C : To co-pro, without timer, 1 closing bytes, last byte sent with EOI
; -----------------------------------------------------------------------------
.                                                 ; Entry point
99B0  20 11 9C      ..   JSR &9C11                ; ?&BE = ?(pwrkspc+&F8)
99B3  20 EB 92      ..   JSR claimtube            ; Claim the TUBE
99B6  20 0C 93      ..   JSR initiotoco           ; Prepare for data transfer from host (i/o) to parasite (co-processor)
99B9  A0 02        ..    LDY #clr+rhdf            ; Load the mnemonic for the 'Clear Release RFD holdoff' function
99BB  4C D1 99     L..   JMP &99D1
.
99BE  8C 26 FC     .&.   STY auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
99C1  8E E5 FE     ...   STX tubedat
99C4  EA           .     NOP                      ; 1 NOP = 2 clockcycles
99C5  EA           .     NOP
99C6  EA           .     NOP
99C7  E6 B2        ..    INC memadr+0
99C9  D0 06        ..    BNE &99D1
99CB  E6 B3        ..    INC memadr+1
99CD  D0 02        ..    BNE &99D1
99CF  E6 B4        ..    INC memadr+2
.
99D1  20 62 9B      b.   JSR waitBIend
99D4  D0 0B        ..    BNE &99E1
99D6  AE 27 FC     .'.   LDX datin
99D9  E4 BE        ..    CPX &BE
99DB  D0 E1        ..    BNE &99BE
99DD  20 F9 92      ..   JSR reltube              ; Release the TUBE
99E0  60           `     RTS
.
99E1  AE 27 FC     .'.   LDX datin
99E4  E4 BE        ..    CPX &BE
99E6  F0 0F        ..    BEQ &99F7
99E8  EA           .     NOP                      ; 1 NOP = 2 clockcycles
99E9  EA           .     NOP
99EA  8E E5 FE     ...   STX tubedat
99ED  E6 B2        ..    INC memadr+0
99EF  D0 06        ..    BNE &99F7
99F1  E6 B3        ..    INC memadr+1
99F3  D0 02        ..    BNE &99F7
99F5  E6 B4        ..    INC memadr+2
.
99F7  20 F9 92      ..   JSR reltube              ; Release the TUBE
99FA  60           `     RTS

; -----------------------------------------------------------------------------
; Read &1D : To co-pro, without timer, 2 EOS bytes, last byte sent with EOI
; -----------------------------------------------------------------------------
.                                                 ; Entry point
99FB  20 11 9C      ..   JSR &9C11                ; ?&BE = ?(pwrkspc+&F8)
99FE  20 18 9C      ..   JSR &9C18                ; ?&BF = ?(pwrkspc+&F9)
9A01  20 EB 92      ..   JSR claimtube            ; Claim the TUBE
9A04  20 0C 93      ..   JSR initiotoco           ; Prepare for data transfer from host (i/o) to parasite (co-processor)
9A07  A0 02        ..    LDY #clr+rhdf            ; Load the mnemonic for the 'Clear Release RFD holdoff' function
9A09  20 62 9B      b.   JSR waitBIend
9A0C  D0 63        .c    BNE &9A71
9A0E  AE 27 FC     .'.   LDX datin
9A11  8C 26 FC     .&.   STY auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
9A14  4C 29 9A     L).   JMP &9A29
.
9A17  8C 26 FC     .&.   STY auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
9A1A  8D E5 FE     ...   STA tubedat
9A1D  EA           .     NOP                      ; 1 NOP = 2 clockcycles
9A1E  EA           .     NOP
9A1F  E6 B2        ..    INC memadr+0
9A21  D0 06        ..    BNE &9A29
9A23  E6 B3        ..    INC memadr+1
9A25  D0 02        ..    BNE &9A29
9A27  E6 B4        ..    INC memadr+2
.
9A29  20 62 9B      b.   JSR waitBIend
9A2C  D0 10        ..    BNE &9A3E
9A2E  8A           .     TXA
9A2F  AE 27 FC     .'.   LDX datin
9A32  E4 BF        ..    CPX &BF
9A34  D0 E1        ..    BNE &9A17
9A36  C5 BE        ..    CMP &BE
9A38  D0 DD        ..    BNE &9A17
9A3A  20 F9 92      ..   JSR reltube              ; Release the TUBE
9A3D  60           `     RTS
.
9A3E  8A           .     TXA
9A3F  AE 27 FC     .'.   LDX datin
9A42  E4 BF        ..    CPX &BF
9A44  D0 04        ..    BNE &9A4A
9A46  C5 BE        ..    CMP &BE
9A48  F0 23        .#    BEQ &9A6D
.
9A4A  EA           .     NOP                      ; 1 NOP = 2 clockcycles
9A4B  EA           .     NOP
9A4C  8D E5 FE     ...   STA tubedat
9A4F  E6 B2        ..    INC memadr+0
9A51  D0 06        ..    BNE &9A59
9A53  E6 B3        ..    INC memadr+1
9A55  D0 02        ..    BNE &9A59
9A57  E6 B4        ..    INC memadr+2
.
9A59  20 30 9C      0.   JSR &9C30
9A5C  EA           .     NOP                      ; 1 NOP = 2 clockcycles
9A5D  EA           .     NOP
9A5E  EA           .     NOP
9A5F  EA           .     NOP
9A60  8E E5 FE     ...   STX tubedat
9A63  E6 B2        ..    INC memadr+0
9A65  D0 06        ..    BNE &9A6D
9A67  E6 B3        ..    INC memadr+1
9A69  D0 02        ..    BNE &9A6D
9A6B  E6 B4        ..    INC memadr+2
.
9A6D  20 F9 92      ..   JSR reltube              ; Release the TUBE
9A70  60           `     RTS
.
9A71  AD 27 FC     .'.   LDA datin
9A74  8D E5 FE     ...   STA tubedat
9A77  E6 B2        ..    INC memadr+0
9A79  D0 06        ..    BNE &9A81
9A7B  E6 B3        ..    INC memadr+1
9A7D  D0 02        ..    BNE &9A81
9A7F  E6 B4        ..    INC memadr+2
.
9A81  20 F9 92      ..   JSR reltube              ; Release the TUBE
9A84  60           `     RTS

; -----------------------------------------------------------------------------
; Read &1E : To co-pro, with timer, 1 EOS byte, last byte sent with EOI
; -----------------------------------------------------------------------------
.                                                 ; Entry point
9A85  20 11 9C      ..   JSR &9C11                ; ?&BE = ?(pwrkspc+&F8)
9A88  20 EB 92      ..   JSR claimtube            ; Claim the TUBE
9A8B  20 0C 93      ..   JSR initiotoco           ; Prepare for data transfer from host (i/o) to parasite (co-processor)
9A8E  A0 02        ..    LDY #clr+rhdf            ; Load the mnemonic for the 'Clear Release RFD holdoff' function
9A90  4C A3 9A     L..   JMP &9AA3
.
9A93  8C 26 FC     .&.   STY auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
9A96  8E E5 FE     ...   STX tubedat
9A99  E6 B2        ..    INC memadr+0
9A9B  D0 06        ..    BNE &9AA3
9A9D  E6 B3        ..    INC memadr+1
9A9F  D0 02        ..    BNE &9AA3
9AA1  E6 B4        ..    INC memadr+2
.
9AA3  20 C2 9B      ..   JSR waitBIretend
9AA6  D0 0B        ..    BNE &9AB3
9AA8  AE 27 FC     .'.   LDX datin
9AAB  E4 BE        ..    CPX &BE
9AAD  D0 E4        ..    BNE &9A93
9AAF  20 F9 92      ..   JSR reltube              ; Release the TUBE
9AB2  60           `     RTS
.
9AB3  AE 27 FC     .'.   LDX datin
9AB6  E4 BE        ..    CPX &BE
9AB8  F0 0D        ..    BEQ &9AC7
9ABA  8E E5 FE     ...   STX tubedat
9ABD  E6 B2        ..    INC memadr+0
9ABF  D0 06        ..    BNE &9AC7
9AC1  E6 B3        ..    INC memadr+1
9AC3  D0 02        ..    BNE &9AC7
9AC5  E6 B4        ..    INC memadr+2
.
9AC7  20 F9 92      ..   JSR reltube              ; Release the TUBE
9ACA  60           `     RTS

; -----------------------------------------------------------------------------
; Read &1F : To co-pro, with timer, 2 closing byte, last byte sent with EOI
; -----------------------------------------------------------------------------
.                                                 ; Entry point
9ACB  20 11 9C      ..   JSR &9C11                ; ?&BE = ?(pwrkspc+&F8)
9ACE  20 18 9C      ..   JSR &9C18                ; ?&BF = ?(pwrkspc+&F9)
9AD1  20 EB 92      ..   JSR claimtube            ; Claim the TUBE
9AD4  20 0C 93      ..   JSR initiotoco           ; Prepare for data transfer from host (i/o) to parasite (co-processor)
9AD7  A0 02        ..    LDY #clr+rhdf            ; Load the mnemonic for the 'Clear Release RFD holdoff' function
9AD9  20 C2 9B      ..   JSR waitBIretend
9ADC  D0 5F        ._    BNE &9B3D
9ADE  AE 27 FC     .'.   LDX datin
9AE1  8C 26 FC     .&.   STY auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
9AE4  4C F7 9A     L..   JMP &9AF7
.
9AE7  8C 26 FC     .&.   STY auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
9AEA  8D E5 FE     ...   STA tubedat
9AED  E6 B2        ..    INC memadr+0
9AEF  D0 06        ..    BNE &9AF7
9AF1  E6 B3        ..    INC memadr+1
9AF3  D0 02        ..    BNE &9AF7
9AF5  E6 B4        ..    INC memadr+2
.
9AF7  20 C2 9B      ..   JSR waitBIretend
9AFA  D0 10        ..    BNE &9B0C
9AFC  8A           .     TXA
9AFD  AE 27 FC     .'.   LDX datin
9B00  E4 BF        ..    CPX &BF
9B02  D0 E3        ..    BNE &9AE7
9B04  C5 BE        ..    CMP &BE
9B06  D0 DF        ..    BNE &9AE7
9B08  20 F9 92      ..   JSR reltube              ; Release the TUBE
9B0B  60           `     RTS
.
9B0C  8A           .     TXA
9B0D  AE 27 FC     .'.   LDX datin
9B10  E4 BF        ..    CPX &BF
9B12  D0 04        ..    BNE &9B18
9B14  C5 BE        ..    CMP &BE
9B16  F0 21        .!    BEQ &9B39
.
9B18  8D E5 FE     ...   STA tubedat
9B1B  E6 B2        ..    INC memadr+0
9B1D  D0 06        ..    BNE &9B25
9B1F  E6 B3        ..    INC memadr+1
9B21  D0 02        ..    BNE &9B25
9B23  E6 B4        ..    INC memadr+2
.
9B25  20 30 9C      0.   JSR &9C30
9B28  EA           .     NOP                      ; 1 NOP = 2 clockcycles
9B29  EA           .     NOP
9B2A  EA           .     NOP
9B2B  EA           .     NOP
9B2C  8E E5 FE     ...   STX tubedat
9B2F  E6 B2        ..    INC memadr+0
9B31  D0 06        ..    BNE &9B39
9B33  E6 B3        ..    INC memadr+1
9B35  D0 02        ..    BNE &9B39
9B37  E6 B4        ..    INC memadr+2
.
9B39  20 F9 92      ..   JSR reltube              ; Release the TUBE
9B3C  60           `     RTS
.
9B3D  AD 27 FC     .'.   LDA datin
9B40  8D E5 FE     ...   STA tubedat
9B43  E6 B2        ..    INC memadr+0
9B45  D0 06        ..    BNE &9B4D
9B47  E6 B3        ..    INC memadr+1
9B49  D0 02        ..    BNE &9B4D
9B4B  E6 B4        ..    INC memadr+2
.
9B4D  20 F9 92      ..   JSR reltube              ; Release the TUBE
9B50  60           `     RTS

; -----------------------------------------------------------------------------
; 
; -----------------------------------------------------------------------------
.waitSPASend                                      ; Wait for SPAS without timer
9B51  A9 20        .     LDA #&20                 ; mask: 00100000
.
9B53  24 B9        $.    BIT intflag
9B55  30 06        0.    BMI &9B5D                ; Exit this procedure when bit 7 of &B9 is set
9B57  2C 20 FC     , .   BIT intstatus0
9B5A  F0 F7        ..    BEQ &9B53                ; Repeat until the SPAS bit (bit 5) of the TMS9914A's Interrupt Status Register 0 is cleared
9B5C  60           `     RTS
.
9B5D  A9 05        ..    LDA #&05
9B5F  4C 94 83     L..   JMP &8394                ; Exit with error code &05

; -----------------------------------------------------------------------------
; 
; -----------------------------------------------------------------------------
.waitBIend
9B62  24 B9        $.    BIT intflag
9B64  30 18        0.    BMI &9B7E                ; Exit this procedure when bit 7 of &B9 is set
9B66  AD 20 FC     . .   LDA intstatus0           ; Load the TMS9914A's Interrupt Status Register 0
9B69  29 28        )(    AND #&28                 ; Check if the SPAS bit (bit 5) and the BO bit (bit 3) are set
9B6B  F0 F5        ..    BEQ waitBIend            ; If not, then repeat
9B6D  C9 20        .     CMP #&20                 ; Is only the SPAS bit (bit 5) set?
9B6F  D0 03        ..    BNE &9B74
9B71  A9 00        ..    LDA #&00
9B73  60           `     RTS
.
9B74  C9 28        .(    CMP #&28                 ; Are both the SPAS bit (bit 5) and the BO bit (bit 3) set?
9B76  F0 03        ..    BEQ &9B7B
9B78  AD 20 FC     . .   LDA intstatus0           ; Clear bit2-7 in the TMS9914A's Interrupt Status Register 0
.
9B7B  A9 FF        ..    LDA #&FF
9B7D  60           `     RTS
.
9B7E  A9 05        ..    LDA #&05
9B80  4C 94 83     L..   JMP &8394                ; Exit with error code &05

; -----------------------------------------------------------------------------
; 
; -----------------------------------------------------------------------------
.waitSPASretend                                   ; Wait for SPAS with timer
9B83  98           .     TYA
9B84  48           H     PHA
9B85  A0 FA        ..    LDY #&FA
9B87  B1 B0        ..    LDA (pwrkspc),Y
9B89  85 BA        ..    STA timer+0              ; timer+0 = ?(pwrkspc+&FA)
9B8B  C8           .     INY
9B8C  B1 B0        ..    LDA (pwrkspc),Y
9B8E  85 BB        ..    STA timer+1              ; timer+1 = ?(pwrkspc+&FB)
9B90  C8           .     INY
9B91  B1 B0        ..    LDA (pwrkspc),Y
9B93  85 BC        ..    STA timer+2              ; timer+2 = ?(pwrkspc+&FC)
9B95  C8           .     INY
9B96  B1 B0        ..    LDA (pwrkspc),Y
9B98  85 BD        ..    STA timer+3              ; timer+3 = ?(pwrkspc+&FD)
9B9A  68           h     PLA
9B9B  A8           .     TAY
.
9B9C  E6 BA        ..    INC timer+0
9B9E  D0 11        ..    BNE &9BB1
9BA0  E6 BB        ..    INC timer+1
9BA2  D0 0D        ..    BNE &9BB1
9BA4  E6 BC        ..    INC timer+2
9BA6  D0 09        ..    BNE &9BB1
9BA8  E6 BD        ..    INC timer+3
9BAA  D0 05        ..    BNE &9BB1
9BAC  A9 07        ..    LDA #&07                 ; Timer has timed out
9BAE  4C 94 83     L..   JMP &8394                ; Exit with error code &07
.
9BB1  A9 20        .     LDA #&20
9BB3  24 B9        $.    BIT intflag
9BB5  30 06        0.    BMI &9BBD                ; Exit this procedure when bit 7 of &B9 is set
9BB7  2C 20 FC     , .   BIT intstatus0
9BBA  F0 E0        ..    BEQ &9B9C                ; Repeat until the SPAS bit (bit 5) of the TMS9914A's Interrupt Status Register 0 is cleared
9BBC  60           `     RTS
.
9BBD  A9 05        ..    LDA #&05
9BBF  4C 94 83     L..   JMP &8394                ; Exit with error code &05

; -----------------------------------------------------------------------------
; 
; -----------------------------------------------------------------------------
.waitBIretend
9BC2  98           .     TYA
9BC3  48           H     PHA
9BC4  A0 FA        ..    LDY #&FA
9BC6  B1 B0        ..    LDA (pwrkspc),Y
9BC8  85 BA        ..    STA timer+0              ; timer+0 = ?(pwrkspc+&FA)
9BCA  C8           .     INY
9BCB  B1 B0        ..    LDA (pwrkspc),Y
9BCD  85 BB        ..    STA timer+1              ; timer+1 = ?(pwrkspc+&FB)
9BCF  C8           .     INY
9BD0  B1 B0        ..    LDA (pwrkspc),Y
9BD2  85 BC        ..    STA timer+2              ; timer+2 = ?(pwrkspc+&FC)
9BD4  C8           .     INY
9BD5  B1 B0        ..    LDA (pwrkspc),Y
9BD7  85 BD        ..    STA timer+3              ; timer+3 = ?(pwrkspc+&FD)
9BD9  68           h     PLA
9BDA  A8           .     TAY
.
9BDB  E6 BA        ..    INC timer+0
9BDD  D0 11        ..    BNE &9BF0
9BDF  E6 BB        ..    INC timer+1
9BE1  D0 0D        ..    BNE &9BF0
9BE3  E6 BC        ..    INC timer+2
9BE5  D0 09        ..    BNE &9BF0
9BE7  E6 BD        ..    INC timer+3
9BE9  D0 05        ..    BNE &9BF0
9BEB  A9 07        ..    LDA #&07                 ; Timer has timed out
9BED  4C 94 83     L..   JMP &8394                ; Exit with error code &07
.
9BF0  24 B9        $.    BIT intflag
9BF2  30 18        0.    BMI &9C0C                ; Exit this procedure when bit 7 of &B9 is set
9BF4  AD 20 FC     . .   LDA intstatus0           ; Load the TMS9914A's Interrupt Status Register 0
9BF7  29 28        )(    AND #&28                 ; Check if the SPAS bit (bit 5) and the BO bit (bit 3) are set
9BF9  F0 E0        ..    BEQ &9BDB
9BFB  C9 20        .     CMP #&20                 ; Is only the SPAS bit (bit 5) set?
9BFD  D0 03        ..    BNE &9C02
9BFF  A9 00        ..    LDA #&00
9C01  60           `     RTS
.
9C02  C9 28        .(    CMP #&28                 ; Are both the SPAS bit (bit 5) and the BO bit (bit 3) set?
9C04  F0 03        ..    BEQ &9C09
9C06  AD 20 FC     . .   LDA intstatus0           ; Clear bit2-7 in the TMS9914A's Interrupt Status Register 0
.
9C09  A9 FF        ..    LDA #&FF
9C0B  60           `     RTS
.
9C0C  A9 05        ..    LDA #&05
9C0E  4C 94 83     L..   JMP &8394                ; Exit with error code &05

.                                                 ; ?&BE = ?(pwrkspc+&F8)
9C11  A0 F8        ..    LDY #&F8
9C13  B1 B0        ..    LDA (pwrkspc),Y
9C15  85 BE        ..    STA &BE
9C17  60           `     RTS

.                                                 ; ?&BF = ?(pwrkspc+&F9)
9C18  A0 F9        ..    LDY #&F9
9C1A  B1 B0        ..    LDA (pwrkspc),Y
9C1C  85 BF        ..    STA &BF
9C1E  60           `     RTS

.
9C1F  A0 07        ..    LDY #&07
9C21  B1 B0        ..    LDA (pwrkspc),Y
9C23  F0 06        ..    BEQ &9C2B
9C25  A9 02        ..    LDA #clr+rhdf            ; Load the mnemonic for the 'Clear Release RFD holdoff' function
9C27  8D 26 FC     .&.   STA auxcmd               ; Send it to the TMS9914A's Auxiliary Command Register
9C2A  60           `     RTS
.
9C2B  A9 FF        ..    LDA #&FF
9C2D  91 B0        ..    STA (pwrkspc),Y
9C2F  60           `     RTS

; -----------------------------------------------------------------------------
; Wait loops (1 NOP = 2 clock cycles)
; -----------------------------------------------------------------------------

.
9C30  20 39 9C      9.   JSR &9C39
9C33  20 39 9C      9.   JSR &9C39
9C36  20 39 9C      9.   JSR &9C39
.
9C39  60           `     RTS

9C3A  EA           .     NOP                      ; No entry point!!!
9C3B  EA           .     NOP
.                                                 ; Wait 3 NOP's
9C3C  EA           .     NOP
9C3D  EA           .     NOP
.                                                 ; Wait 1 NOP's
9C3E  EA           .     NOP
9C3F  60           `     RTS

; -----------------------------------------------------------------------------
; End of code
; -----------------------------------------------------------------------------

madr+0
 6640STA memadr+0
 6650LDA #&00
 6660ADC memadr+1
 6670STA memadr+1
 6680RTS
 6690.rdcoend
 6700JSR claimtube
 6710JSR initiotoco
 6720LDY #rhdf
 6730JMP rdcoend1
 6740.rdcoend2
 6750LDA datin
 6760STY auxcmd
 6770STA tubedat
 6780NOP
 6790NOP
 6800NOP
 6810NOP
 6820NOP
 6830INC memadr+0
 6840BNE rdcoend1
 6850INC memadr+1
 6860BNE rdcoend1
 6870INC memadr+2
 6880.rdcoend1
 6890JSR waitBIend
 6900BEQ rdcoend2
 6910NOP
 6920NOP
 6930NOP
 6940LDA datin
 6950STA tubedat
 6960INC memadr+0
 6970BNE rdcoend3
 6980INC memadr+1
 6990BNE rdcoend3
 7000INC memadr+2
 7010.rdcoend3
 7020JSR reltube
 7030RTS
 7040.rdcoretend
 7050JSR claimtube
 7060JSR initiotoco
 7070LDY #rhdf
 7080JMP rdcoretend1
 7090.rdcoretend2
 7100LDA datin
 7110STY auxcmd
 7120STA tubedat
 7130INC memadr+0
 7140BNE rdcoretend1
 7150INC memadr+1
 7160BNE rdcoretend1
 7170INC memadr+2
 7180.rdcoretend1
 7190JSR waitBIretend
 7200BEQ rdcoretend2
 7210LDA datin
 7220STA tubedat
 7230INC memadr+0
 7240BNE rdcoretend3
 7250INC memadr+1
 7260BNE rdcoretend3
 7270INC memadr+2
 7280.rdcoretend3
 7290JSR reltube
 7300R
