; -----------------------------------------------------------------------------
; 6502 Second Processor OS v1.10 (c) Acorn
; reverse engineered by Eelco Huininga
; DOS Filename   : 6502_110.rom
; Acorn filename : Unknown
; Load address   : 0000F000
; Exec address   : 0000F800
; Length         : 00001000
; -----------------------------------------------------------------------------

; Zero page usage
; &00-&ED Available for user programs
; &EE-&EF 16-bit pointer (Start of language ROM)
; &F0-&F1 16-bit pointer (*GO execute address)
; &F2     HIMEM LSB
; &F3     HIMEM MSB
; &F4-&F5 16-bit pointer
; &F6-&F7 16-bit pointer (NMI handler pointer?)
; &F8-&F9 General 16-bit pointer (used by OSWORD
; &FA-&FB General 16-bit pointer (used by OSFILE, OSGBPB and the print message to output stream)
; &FC     Interrupt accumulator save register
; &FD-&FE Point tot the byte after the last BRK instruction
; &FF     ESCAPE flag (bit 7)
;
; &0100-&01FF 6502 stack
;
; &0200-&0235 OS vectors
; &0236-&02FF Input buffer for OSWORD &00 calls
;             Buffer for storing error messages generated in host (i/o) processor
;
; &0300-&F7FF Free RAM
; &F800-&FFFF Second Processor OS


; -----------------------------------------------------------------------------
; TUBE ULA registers
; -----------------------------------------------------------------------------
r1status            = &FEF8
r1data              = &FEF9
r2status            = &FEFA
r2data              = &FEFB
r3status            = &FEFC
r3data              = &FEFD
r4status            = &FEFE
r4data              = &FEFF

; -----------------------------------------------------------------------------
; OS call addresses
; -----------------------------------------------------------------------------
brkv               = &0202                        ; BRKV BRK vector
irq1v              = &0204                        ; IRQ1V Primary interrupt vector
irq2v              = &0206                        ; IRQ2V Unrecognised IRQ vector
cliv               = &0208                        ; CLIV Command line interpreter
bytev              = &020A                        ; BYTEV *FX/OSBYTE call
wordv              = &020C                        ; WORDV OSWORD call
wrchv              = &020E                        ; WRCHV Write character
rdchv              = &0210                        ; RDCHV Read character
filev              = &0212                        ; FILEV Load/Save file
argsv              = &0214                        ; ARGSV Load/Save file data
bgetv              = &0216                        ; BGETV Get byte from file
bputv              = &0218                        ; BPUTV Put byte in file
gbpbv              = &021A                        ; GBPBV Multiple BGET/BPUT
findv              = &021C                        ; FINDV Open or close file
evntv              = &0220                        ; EVNTV Event vector


; -----------------------------------------------------------------------------
; Start of code
; -----------------------------------------------------------------------------

; -----------------------------------------------------------------------------
; Reset entry
; -----------------------------------------------------------------------------
.
F800  A2 00        ..    LDX #&00
.
F802  BD 00 FF     ...   LDA &FF00,X              ; Move &FF00-&FFFF to RAM
F805  9D 00 FF     ...   STA &FF00,X
F808  CA           .     DEX
F809  D0 F7        ..    BNE &F802
F80B  A2 36        .6    LDX #&36
.
F80D  BD 80 FF     ...   LDA &FF80,X              ; Move &FF80-&FFB6 to &0200-&0235
F810  9D 00 02     ...   STA &0200,X
F813  CA           .     DEX
F814  10 F7        ..    BPL &F80D
F816  9A           .     TXS                      ; Set stack pointer to &FF
F817  A2 F0        ..    LDX #&F0
.
F819  BD FF FD     ...   LDA &FDFF,X              ; Move &FE00-&FEEF to RAM
F81C  9D FF FD     ...   STA &FDFF,X
F81F  CA           .     DEX
F820  D0 F7        ..    BNE &F819
F822  A0 00        ..    LDY #&F800 MOD 256
F824  84 F8        ..    STY &F8
F826  A9 F8        ..    LDA #&F800 DIV 256
F828  85 F9        ..    STA &F9
.
F82A  B1 F8        ..    LDA (&F8),Y
F82C  91 F8        ..    STA (&F8),Y              ; Move &F800-&FDFF to RAM
F82E  C8           .     INY
F82F  D0 F9        ..    BNE &F82A
F831  E6 F9        ..    INC &F9
F833  A5 F9        ..    LDA &F9
F835  C9 FE        ..    CMP #&FE
F837  D0 F1        ..    BNE &F82A
F839  A2 10        ..    LDX #&10
.
F83B  BD 59 F8     .Y.   LDA &F859,X              ; Move &F859-&F869 to &0100-&0110
F83E  9D 00 01     ...   STA &0100,X
F841  CA           .     DEX
F842  10 F7        ..    BPL &F83B
F844  A5 EE        ..    LDA &EE
F846  85 F6        ..    STA &F6
F848  A5 EF        ..    LDA &EF
F84A  85 F7        ..    STA &F7
F84C  A9 00        ..    LDA #&00
F84E  85 FF        ..    STA &FF                  ; Reset the ESCAPE flag
F850  85 F2        ..    STA &F2                  ; LSB of HIMEM: set to &F800
F852  A9 F8        ..    LDA #&F8
F854  85 F3        ..    STA &F3                  ; MSB of HIMEM: set to &F800
F856  4C 00 01     L..   JMP &0100
.
F859  AD F8 FE     ...   LDA r1status             ; Switch off the EPROM and use RAM
F85C  58           X     CLI
F85D  4C 60 F8     L`.   JMP &F860
.
F860  20 98 FE      ..   JSR &FE98                ; Print message to output stream

F863  0A           .     DB 10                    ; Linefeed
F864  41 63 6F 72  Acor  DB "Acorn TUBE 6502 64K" ;
      6E 20 54 55  n TU
      42 45 20 36  BE 6
      35 30 32 20  502 
      36 34 4B     64K
F877  0A           .     DB 10                    ; Linefeed
F878  0A           .     DB 10                    ; Linefeed
F879  0D           .     DB 13                    ; CR
F87A  00           .     DB 0                     ; String terminator

F87B  EA           .     NOP
F87C  A9 8D        ..    LDA #&F88D MOD 256
F87E  8D 5E F8     .^.   STA &F85E
F881  A9 F8        ..    LDA #&F88D DIV 256
F883  8D 5F F8     ._.   STA &F85F
F886  20 75 F9      u.   JSR &F975                ; Wait for data in TUBE ULA Data register 2 and return it in A
F889  C9 80        ..    CMP #&80
F88B  F0 28        .(    BEQ enter_language_rom   ; Check copyright message and ROM type and enter language ROM
.
F88D  A9 2A        .*    LDA #ASC"*"              ; * Prompt
F88F  20 EE FF      ..   JSR oswrch
F892  A2 5D        .]    LDX #&F95D MOD 256       ; XY points to OSWORD &00 parameter block
F894  A0 F9        ..    LDY #&F95D DIV 256
F896  A9 00        ..    LDA #&00                 ; OSWORD &00: Read line from input
F898  20 F1 FF      ..   JSR osword
F89B  B0 0A        ..    BCS &F8A7                ; Jump if user pressed ESCAPE
F89D  A2 36        .6    LDX #&0236 MOD 256       ; XY points to the line read by the OSWORD &00 call
F89F  A0 02        ..    LDY #&0236 DIV 256
F8A1  20 F7 FF      ..   JSR oscli
F8A4  4C 8D F8     L..   JMP &F88D
.
F8A7  A9 7E        .~    LDA #&7E                 ; OSBYTE $7E: Acknowledge detection of an ESCAPE condition
F8A9  20 F4 FF      ..   JSR osbyte

F8AC  00           .     BRK
F8AD  11
F8AE  45 73 63 61  Esca  DB "Escape"
      70 65        pe
F8B4  00           .

; -----------------------------------------------------------------------------
; Check copyright message and ROM type and enter language ROM
; -----------------------------------------------------------------------------
.enter_language_rom
F8B5  A5 F6        ..    LDA &F6
F8B7  85 EE        ..    STA &EE
F8B9  85 F2        ..    STA &F2                  ; LSB of HIMEM
F8BB  A5 F7        ..    LDA &F7
F8BD  85 EF        ..    STA &EF
F8BF  85 F3        ..    STA &F3                  ; MSB of HIMEM
F8C1  A0 07        ..    LDY #&07                 ; Copyright offset in paged ROM
F8C3  B1 EE        ..    LDA (&EE),Y
F8C5  D8           .     CLD
F8C6  18           .     CLC
F8C7  65 EE        e.    ADC &EE
F8C9  85 FD        ..    STA &FD
F8CB  A9 00        ..    LDA #&00
F8CD  65 EF        e.    ADC &EF
F8CF  85 FE        ..    STA &FE
F8D1  A0 00        ..    LDY #&00
F8D3  B1 FD        ..    LDA (&FD),Y
F8D5  D0 23        .#    BNE &F8FA                ; First byte of the copyright string must be zero
F8D7  C8           .     INY
F8D8  B1 FD        ..    LDA (&FD),Y
F8DA  C9 28        .(    CMP #ASC"("
F8DC  D0 1C        ..    BNE &F8FA                ; Next three bytes must be (C)
F8DE  C8           .     INY
F8DF  B1 FD        ..    LDA (&FD),Y
F8E1  C9 43        .C    CMP #ASC"C"
F8E3  D0 15        ..    BNE &F8FA
F8E5  C8           .     INY
F8E6  B1 FD        ..    LDA (&FD),Y
F8E8  C9 29        .)    CMP #ASC")"
F8EA  D0 0E        ..    BNE &F8FA
F8EC  A0 06        ..    LDY #&06
F8EE  B1 EE        ..    LDA (&EE),Y              ; ROM type of paged ROM
F8F0  29 4F        )O    AND #%01001111           ; Mask out the 'Language ROM'-bit
F8F2  C9 40        .@    CMP #&40                 ; Is it a language and 6502 BASIC code?
F8F4  90 09        ..    BCC &F8FF
F8F6  29 0D        ).    AND #%00001101           ; Is it not a language, but still 6502 code?
F8F8  D0 28        .(    BNE &F922                ; If not, then display "I cannot run this code"
.
F8FA  A9 01        ..    LDA #&01                 ; Initialise language ROM flag
F8FC  6C F2 00     l..   JMP (&00F2)              ; And enter the paged ROM at the language entry
.
F8FF  A9 45        .E    LDA #_brkv MOD 256
F901  8D 02 02     ...   STA brkv
F904  A9 F9        ..    LDA #_brkv DIV 256
F906  8D 03 02     ...   STA brkv+1

F909  00           .     BRK
F90A  00           .     BRK
F90B  54 68 69 73  This  DB "This is not a language"
      20 69 73 20   is 
      6E 6F 74 20  not 
      61 20 6C 61  a la
      6E 67 75 61  ngua
      67 65        ge
F921  00           .     BRK

.
F922  A9 45        .E    LDA #_brkv MOD 256
F924  8D 02 02     ...   STA brkv
F927  A9 F9        ..    LDA #_brkv DIV 256
F929  8D 03 02     ...   STA brkv+1

F92C  00           .     BRK
F92D  00           .     BRK
F92E  49 20 63 61  I ca  DB "I cannot run this code"
      6E 6E 6F 74  nnot
F936  20 72 75 6E   run
      20 74 68 69   thi
      73 20 63 6F  s co
      64 65        de
F944  00           .     BRK

; -----------------------------------------------------------------------------
; BRK: BRK handler
; -----------------------------------------------------------------------------
._brkv
F945  A2 FF        ..    LDX #&FF
F947  9A           .     TXS                      ; Reset stack pointer
F948  20 E7 FF      ..   JSR osnewl
F94B  A0 01        ..    LDY #&01
.
F94D  B1 FD        ..    LDA (&FD),Y
F94F  F0 06        ..    BEQ &F957
F951  20 EE FF      ..   JSR oswrch
F954  C8           .     INY
F955  D0 F6        ..    BNE &F94D
.
F957  20 E7 FF      ..   JSR osnewl
F95A  4C 8D F8     L..   JMP &F88D                ; Return to the prompt

; -----------------------------------------------------------------------------
; OSWORD &00 parameter block
; -----------------------------------------------------------------------------
.osword_00_parameterblock
F95D  36 02        6.    DW &0236                 ; Buffer address at &0236
F95F  CA           .     DB 202                   ; Maximum line length is 202
F960  20                 DB ASC" "                ; Minimum acceptable ASCII value
F961  FF           .     DB &FF                   ; Maximum acceptable ASCII value

; -----------------------------------------------------------------------------
; WRCH: Write character to output stream
; -----------------------------------------------------------------------------
.wrch
F962  2C F8 FE     ,..   BIT r1status             ; Check the NF1 flag of TUBE ULA Status register 1 (1st data register not filled)
F965  EA           .     NOP
F966  50 FA        P.    BVC &F962                ; Loop until TUBE ULA Data register 1 is empty
F968  8D F9 FE     ...   STA r1data
F96B  60           `     RTS

; -----------------------------------------------------------------------------
; RDCH: Read character from input stream
; -----------------------------------------------------------------------------
.rdch
F96C  A9 00        ..    LDA #&00
F96E  20 4A FC      J.   JSR &FC4A                ; Wait for TUBE ULA Data register 2 to be clear and send A to Data register 2
.rdch1
F971  20 75 F9      u.   JSR &F975                ; Wait for data in TUBE ULA Data register 2 and return it in A
F974  0A           .     ASL A                    ; Move bit 7 to carry flag

; -----------------------------------------------------------------------------
; Wait for data in TUBE ULA Data register 2 and return it in A
; -----------------------------------------------------------------------------
.read_from_r2data
F975  2C FA FE     ,..   BIT r2status             ; Check the DA2 flag of TUBE ULA Status register 2 (Data present in 2st register)
F978  10 FB        ..    BPL &F975                ; No? Then wait
F97A  AD FB FE     ...   LDA r2data
.                                                 ; EVNTV handler
F97D  60           `     RTS

; -----------------------------------------------------------------------------
; Loop until (&F8),Y isn't ASCII value 32 (space)
; -----------------------------------------------------------------------------
.
F97E  C8           .     INY
.
F97F  B1 F8        ..    LDA (&F8),Y
F981  C9 20        .     CMP #ASC" "
F983  F0 F9        ..    BEQ &F97E
F985  60           `     RTS

; -----------------------------------------------------------------------------
; Return hex value of string at (&F8),Y in &F0-&F1
; -----------------------------------------------------------------------------
.
F986  A2 00        ..    LDX #&00
F988  86 F0        ..    STX &F0
F98A  86 F1        ..    STX &F1
.
F98C  B1 F8        ..    LDA (&F8),Y
F98E  C9 30        .0    CMP #ASC"0"
F990  90 1F        ..    BCC &F9B1
F992  C9 3A        .:    CMP #ASC"9"+1
F994  90 0A        ..    BCC &F9A0
F996  29 DF        ).    AND #&DF                 ; Make character upper-case
F998  E9 07        ..    SBC #&07
F99A  90 15        ..    BCC &F9B1
F99C  C9 40        .@    CMP #ASC"A"-1
F99E  B0 11        ..    BCS &F9B1
.
F9A0  0A           .     ASL A
F9A1  0A           .     ASL A
F9A2  0A           .     ASL A
F9A3  0A           .     ASL A
F9A4  A2 03        ..    LDX #&03
.
F9A6  0A           .     ASL A
F9A7  26 F0        &.    ROL &F0
F9A9  26 F1        &.    ROL &F1
F9AB  CA           .     DEX
F9AC  10 F8        ..    BPL &F9A6
F9AE  C8           .     INY
F9AF  D0 DB        ..    BNE &F98C
.
F9B1  60           `     RTS

; -----------------------------------------------------------------------------
; Send string at XY through TUBE ULA Data register 2
; -----------------------------------------------------------------------------
.write_string_to_r2data
F9B2  86 F8        ..    STX &F8
F9B4  84 F9        ..    STY &F9
.
F9B6  A0 00        ..    LDY #&00
.
F9B8  2C FA FE     ,..   BIT r2status             ; Check the NF2 flag of TUBE ULA Status register 2 (2nd data register not filled)
F9BB  50 FB        P.    BVC &F9B8                ; Loop until TUBE ULA Data register 2 is empty
F9BD  B1 F8        ..    LDA (&F8),Y
F9BF  8D FB FE     ...   STA r2data               ; Send byte to TUBE ULA Data register 2
F9C2  C8           .     INY
F9C3  C9 0D        ..    CMP #&0D                 ; Has the end of the string been reached (CR) ?
F9C5  D0 F1        ..    BNE &F9B8
F9C7  A4 F9        ..    LDY &F9
F9C9  60           `     RTS

; -----------------------------------------------------------------------------
; CLI handler
; -----------------------------------------------------------------------------
.cli
F9CA  48           H     PHA
F9CB  86 F8        ..    STX &F8
F9CD  84 F9        ..    STY &F9
F9CF  A0 00        ..    LDY #&00
.cli1
F9D1  20 7F F9      .   JSR &F97F                ; Loop until (&F8),Y isn't ASCII value 32 (space)
F9D4  C8           .     INY
F9D5  C9 2A        .*    CMP #ASC"*"
F9D7  F0 F8        ..    BEQ &F9D1
F9D9  29 DF        ).    AND #&DF                 ; Make character upper-case
F9DB  AA           .     TAX
F9DC  B1 F8        ..    LDA (&F8),Y
F9DE  E0 47        .G    CPX #ASC "G"
F9E0  F0 5C        .\    BEQ &FA3E                ; Check for *GO
F9E2  E0 48        .H    CPX #ASC "H"
F9E4  D0 47        .G    BNE &FA2D
F9E6  C9 2E        ..    CMP #ASC "."
F9E8  F0 2D        .-    BEQ &FA17
F9EA  29 DF        ).    AND #&DF                 ; Make character upper-case
F9EC  C9 45        .E    CMP #ASC "E"
F9EE  D0 3D        .=    BNE &FA2D
F9F0  C8           .     INY
F9F1  B1 F8        ..    LDA (&F8),Y
F9F3  C9 2E        ..    CMP #ASC "."
F9F5  F0 20        .     BEQ &FA17
F9F7  29 DF        ).    AND #&DF                 ; Make character upper-case
F9F9  C9 4C        .L    CMP #ASC "L"
F9FB  D0 30        .0    BNE &FA2D
F9FD  C8           .     INY
F9FE  B1 F8        ..    LDA (&F8),Y
FA00  C9 2E        ..    CMP #ASC "."
FA02  F0 13        ..    BEQ &FA17
FA04  29 DF        ).    AND #&DF                 ; Make character upper-case
FA06  C9 50        .P    CMP #ASC "P"
FA08  D0 23        .#    BNE &FA2D
FA0A  C8           .     INY
FA0B  B1 F8        ..    LDA (&F8),Y
FA0D  29 DF        ).    AND #&DF                 ; Make character upper-case
FA0F  C9 41        .A    CMP #ASC "A"
FA11  90 04        ..    BCC &FA17
FA13  C9 5B        .[    CMP #ASC "Z"+1
FA15  90 16        ..    BCC &FA2D
.help                                             ; *HELP message
FA17  20 98 FE      ..   JSR &FE98                ; Print message to output stream

FA1A  0A           .     DB 10                    ; Linefeed
FA1B  0D           .     DB 13                    ; Carriage return
FA1C  36 35 30 32  6502  DB "6502 TUBE 1.10"
      20 54 55 42   TUB
      45 20 31 2E  E 1.
      31 30        10
FA2A  0A           .     DB 10                    ; Linefeed
FA2B  0D           .     DB 13                    ; Carriage return
FA2C  EA           .     NOP
.                                                 ; No *GO or *HELP
FA2D  A9           ..    LDA #&02                 ; Send command &02: OSCLI
FA2F  20 4A FC      J.   JSR &FC4A                ; Wait for TUBE ULA Data register 2 to be clear and send A to Data register 2
FA32  20 B6 F9      ..   JSR &F9B6                ; Send command string at (&F8)
.                                                 ; OSBYTE &8E handler (Enter language ROM)
FA35  20 75 F9      u.   JSR &F975                ; Wait for data in TUBE ULA Data register 2 and return it in A
FA38  C9 80        ..    CMP #&80                 ; Language ROM to be entered
FA3A  F0 20        .     BEQ &FA5C
FA3C  68           h     PLA
FA3D  60           `     RTS

; -----------------------------------------------------------------------------
; *GO
; -----------------------------------------------------------------------------
.go
FA3E  29 DF        ).    AND #&DF                 ; Make character upper-case
FA40  C9 4F        .O    CMP #ASC"O"              ; Is it *GO ?
FA42  D0 E9        ..    BNE &FA2D
FA44  20 7E F9      ~.   JSR &F97E                ; Loop until (&F8),Y isn't ASCII value 32 (space)
FA47  20 86 F9      ..   JSR &F986                ; Return hex value of string at (&F8),Y in &F0-&F1
FA4A  20 7F F9      .   JSR &F97F                ; Loop until (&F8),Y isn't ASCII value 32 (space)
FA4D  C9 0D        ..    CMP #&0D                 ; Carriage return
FA4F  D0 DC        ..    BNE &FA2D
FA51  8A           .     TXA
FA52  F0 08        ..    BEQ &FA5C                ; This should never happen, since X = ASC"G"
FA54  A5 F0        ..    LDA &F0
FA56  85 F6        ..    STA &F6
FA58  A5 F1        ..    LDA &F1
FA5A  85 F7        ..    STA &F7
.
FA5C  A5 EF        ..    LDA &EF                  ; Save current program
FA5E  48           H     PHA
FA5F  A5 EE        ..    LDA &EE
FA61  48           H     PHA
FA62  20 B5 F8      ..   JSR &F8B5                ; Check copyright message and ROM type and enter language ROM
FA65  68           h     PLA
FA66  85 EE        ..    STA &EE
FA68  85 F2        ..    STA &F2                  ; LSB of HIMEM
FA6A  68           h     PLA
FA6B  85 EF        ..    STA &EF
FA6D  85 F3        ..    STA &F3                  ; MSB of HIMEM
FA6F  68           h     PLA
FA70  60           `     RTS

; -----------------------------------------------------------------------------
; OSBYTE handler
; -----------------------------------------------------------------------------
.                                                 ; OSBYTE &8E handler (Enter language ROM)
FA71  F0 C2        ..    BEQ &FA35
.byte
FA73  C9 80        ..    CMP #&80
FA75  B0 25        .%    BCS &FA9C                ; Jump if it's OSBYTE &80-&FF
FA77  48           H     PHA
FA78  A9 04        ..    LDA #&04                 ; Code &04 for OSBYTE &00-&7F
.
FA7A  2C FA FE     ,..   BIT r2status             ; Check the NF2 flag of TUBE ULA Status register 2 (2nd data register not filled)
FA7D  50 FB        P.    BVC &FA7A                ; Loop until TUBE ULA Data register 2 is empty
FA7F  8D FB FE     ...   STA r2data
.
FA82  2C FA FE     ,..   BIT r2status             ; Check the NF2 flag of TUBE ULA Status register 2 (2nd data register not filled)
FA85  50 FB        P.    BVC &FA82                ; Loop until TUBE ULA Data register 2 is empty
FA87  8E FB FE     ...   STX r2data
FA8A  68           h     PLA
.
FA8B  2C FA FE     ,..   BIT r2status             ; Check the NF2 flag of TUBE ULA Status register 2 (2nd data register not filled)
FA8E  50 FB        P.    BVC &FA8B                ; Loop until TUBE ULA Data register 2 is empty
FA90  8D FB FE     ...   STA r2data
.
FA93  2C FA FE     ,..   BIT r2status             ; Check the DA2 flag of TUBE ULA Status register 2 (Data present in 2nd data register)
FA96  10 FB        ..    BPL &FA93
FA98  AE FB FE     ...   LDX r2data
FA9B  60           `     RTS
.
FA9C  C9 82        ..    CMP #&82                 ; Is it OSBYTE &82? (Read machine high order address)
FA9E  F0 5A        .Z    BEQ &FAFA
FAA0  C9 83        ..    CMP #&83                 ; Is it OSBYTE &83? (Read top of operating system RAM address (OSHWM)
FAA2  F0 51        .Q    BEQ &FAF5
FAA4  C9 84        ..    CMP #&84                 ; Is it OSBYTE &84? (Read bottom of display RAM address (HIMEM)
FAA6  F0 48        .H    BEQ &FAF0
FAA8  48           H     PHA
FAA9  A9 06        ..    LDA #&06                 ; Code &06 for OSBYTE &80-&81, &85-&FF
.
FAAB  2C FA FE     ,..   BIT r2status             ; Check the NF2 flag of TUBE ULA Status register 2 (2nd data register not filled)
FAAE  50 FB        P.    BVC &FAAB                ; Loop until TUBE ULA Data register 2 is empty
FAB0  8D FB FE     ...   STA r2data
.
FAB3  2C FA FE     ,..   BIT r2status             ; Check the NF2 flag of TUBE ULA Status register 2 (2nd data register not filled)
FAB6  50 FB        P.    BVC &FAB3                ; Loop until TUBE ULA Data register 2 is empty
FAB8  8E FB FE     ...   STX r2data
.
FABB  2C FA FE     ,..   BIT r2status             ; Check the NF2 flag of TUBE ULA Status register 2 (2nd data register not filled)
FABE  50 FB        P.    BVC &FABB                ; Loop until TUBE ULA Data register 2 is empty
FAC0  8C FB FE     ...   STY r2data
FAC3  68           h     PLA
.
FAC4  2C FA FE     ,..   BIT r2status             ; Check the NF2 flag of TUBE ULA Status register 2 (2nd data register not filled)
FAC7  50 FB        P.    BVC &FAC4                ; Loop until TUBE ULA Data register 2 is empty
FAC9  8D FB FE     ...   STA r2data
FACC  C9 8E        ..    CMP #&8E                 ; Is it OSBYTE &8E? (Enter language ROM)
FACE  F0 A1        ..    BEQ &FA71
FAD0  C9 9D        ..    CMP #&9D                 ; Is it OSBYTE &9D? (Fast TUBE BPUT)
FAD2  F0 1B        ..    BEQ &FAEF
FAD4  48           H     PHA
.
FAD5  2C FA FE     ,..   BIT r2status             ; Check the DA2 flag of TUBE ULA Status register 2 (Data present in 2nd data register)
FAD8  10 FB        ..    BPL &FAD5                ; Loop until data is present in TUBE ULA Data register 2
FADA  AD FB FE     ...   LDA r2data               ; Retrieve carry flag
FADD  0A           .     ASL A                    ; Carry flag = bit 7 of accumulator
FADE  68           h     PLA
.
FADF  2C FA FE     ,..   BIT r2status             ; Check the DA2 flag of TUBE ULA Status register 2 (Data present in 2nd data register)
FAE2  10 FB        ..    BPL &FADF                ; Loop until data is present in TUBE ULA Data register 2
FAE4  AC FB FE     ...   LDY r2data
.
FAE7  2C FA FE     ,..   BIT r2status             ; Check the DA2 flag of TUBE ULA Status register 2 (Data present in 2st register)
FAEA  10 FB        ..    BPL &FAE7
FAEC  AE FB FE     ...   LDX r2data
.                                                ; OSBYTE &9D handler (Fast TUBE BPUT)
FAEF  60           `     RTS

.osbyte_84                                        ; OSBYTE &84 handler (Read bottom of display RAM address (HIMEM)
FAF0  A6 F2        ..    LDX &F2                  ; LSB of HIMEM
FAF2  A4 F3        ..    LDY &F3                  ; MSB of HIMEM
FAF4  60           `     RTS

.osbyte_83                                        ; OSBYTE &83 handler (Read top of operating system RAM address (OSHWM)
FAF5  A2 00        ..    LDX #&0800 MOD 256
FAF7  A0 08        ..    LDY #&0800 DIV 256
FAF9  60           `     RTS

.osbyte_82                                        ; OSBYTE &82 handler (Read machine high order address)
FAFA  A2 00        ..    LDX #&0000 MOD 256
FAFC  A0 00        ..    LDY #&0000 DIV 256
FAFE  60           `     RTS

; -----------------------------------------------------------------------------
; OSWORD handler
; -----------------------------------------------------------------------------
.
FAFF  86 F8        ..    STX &F8
FB01  84 F9        ..    STY &F9
FB03  A8           .     TAY                      ; Set appropiate flags
FB04  F0 71        .q    BEQ &FB77                ; Jump if it's OSWORD &00: Read line from input stream
FB06  48           H     PHA
FB07  A0 08        ..    LDY #&08                 ; Code &08 for OSWORD &01-&FF calls
.
FB09  2C FA FE     ,..   BIT r2status             ; Check the NF2 flag of TUBE ULA Status register 2 (2nd data register not filled)
FB0C  50 FB        P.    BVC &FB09                ; Loop until TUBE ULA Data register 2 is empty
FB0E  8C FB FE     ...   STY r2data               ; Send Y to the host processor
.
FB11  2C FA FE     ,..   BIT r2status             ; Check the NF2 flag of TUBE ULA Status register 2 (2nd data register not filled)
FB14  50 FB        P.    BVC &FB11                ; Loop until TUBE ULA Data register 2 is empty
FB16  8D FB FE     ...   STA r2data               ; Send A to the host processor
FB19  AA           .     TAX                      ; Set appropiate flags
FB1A  10 08        ..    BPL &FB24
FB1C  A0 00        ..    LDY #&00                 ; OSWORD &80-&FF calls
FB1E  B1 F8        ..    LDA (&F8),Y              ; Length of parameter block to be send
FB20  A8           .     TAY
FB21  4C 2D FB     L-.   JMP &FB2D
.
FB24  BC BC FC     ...   LDY &FCBC,X              ; Get the length of the parameterblock from the table for OSWORD &01-&14
FB27  E0 15        ..    CPX #&15
FB29  90 02        ..    BCC &FB2D                ; Jump if it's an OSWORD &01-&14 call
FB2B  A0 10        ..    LDY #&10                 ; Set length of the parameterblock to &10 for OSWORD &15-&7F
.
FB2D  2C FA FE     ,..   BIT r2status             ; Check the NF2 flag of TUBE ULA Status register 2 (2nd data register not filled)
FB30  50 FB        P.    BVC &FB2D                ; Loop until TUBE ULA Data register 2 is empty
FB32  8C FB FE     ...   STY r2data               ; Send length of parameter block to the host processor
FB35  88           .     DEY
FB36  30 0D        0.    BMI &FB45                ; Jump if no parameters are to be sended
.
FB38  2C FA FE     ,..   BIT r2status             ; Check the NF2 flag of TUBE ULA Status register 2 (2nd data register not filled)
FB3B  50 FB        P.    BVC &FB38                ; Loop until TUBE ULA Data register 2 is empty
FB3D  B1 F8        ..    LDA (&F8),Y
FB3F  8D FB FE     ...   STA r2data               ; Send the parameter block to the host processor
FB42  88           .     DEY
FB43  10 F3        ..    BPL &FB38
.
FB45  8A           .     TXA                      ; Set appropiate flags
FB46  10 08        ..    BPL &FB50
FB48  A0 01        ..    LDY #&01                 ; OSWORD &80-&FF calls
FB4A  B1 F8        ..    LDA (&F8),Y              ; Length of parameterblock to be received
FB4C  A8           .     TAY
FB4D  4C 59 FB     LY.   JMP &FB59
.
FB50  BC D0 FC     ...   LDY &FCD0,X              ; Get the length of the parameterblock from the table for OSWORD &01-&14
FB53  E0 15        ..    CPX #&15
FB55  90 02        ..    BCC &FB59
FB57  A0 10        ..    LDY #&10                 ; Set length of the parameterblock to &10 for OSWORD &15-&7F
.
FB59  2C FA FE     ,..   BIT r2status             ; Check the NF2 flag of TUBE ULA Status register 2 (2nd data register not filled)
FB5C  50 FB        P.    BVC &FB59                ; Loop until TUBE ULA Data register 2 is empty
FB5E  8C FB FE     ...   STY r2data               ; Send length of parameter block to the host processor
FB61  88           .     DEY
FB62  30 0D        0.    BMI &FB71                ; Jump if no parameters are to be received
.
FB64  2C FA FE     ,..   BIT r2status             ; Check the DA2 flag of TUBE ULA Status register 2 (Data present in 2st register)
FB67  10 FB        ..    BPL &FB64                ; Loop until the DA2 flag is set
FB69  AD FB FE     ...   LDA r2data
FB6C  91 F8        ..    STA (&F8),Y              ; Get the parameter and store it in the parameterblock
FB6E  88           .     DEY
FB6F  10 F3        ..    BPL &FB64
.
FB71  A4 F9        ..    LDY &F9                  ; Set Y to MSB of parameterblock
FB73  A6 F8        ..    LDX &F8                  ; Set X to LSB of parameterblock
FB75  68           h     PLA
FB76  60           `     RTS

.                                                 ; OSWORD &00 handler
FB77  A9 0A        ..    LDA #&0A                 ; Code &0A for OSWORD &00
FB79  20 4A FC      J.   JSR &FC4A                ; Wait for TUBE ULA Data register 2 to be clear and send A to Data register 2
FB7C  A0 04        ..    LDY #&04
.
FB7E  2C FA FE     ,..   BIT r2status             ; Check the NF2 flag of TUBE ULA Status register 2 (2nd data register not filled)
FB81  50 FB        P.    BVC &FB7E                ; Loop until TUBE ULA Data register 2 is empty
FB83  B1 F8        ..    LDA (&F8),Y
FB85  8D FB FE     ...   STA r2data               ; Send parameters &04, &03 and &02 to the host processor
FB88  88           .     DEY
FB89  C0 01        ..    CPY #&01
FB8B  D0 F1        ..    BNE &FB7E
FB8D  A9 07        ..    LDA #&07
FB8F  20 4A FC      J.   JSR &FC4A                ; Wait for TUBE ULA Data register 2 to be clear and send A to Data register 2
FB92  B1 F8        ..    LDA (&F8),Y              ; MSB of address to store string
FB94  48           H     PHA
FB95  88           .     DEY                      ; Y = 0
.
FB96  2C FA FE     ,..   BIT r2status             ; Check the NF2 flag of TUBE ULA Status register 2 (2nd data register not filled)
FB99  50 FB        P.    BVC &FB96                ; Loop until TUBE ULA Data register 2 is empty
FB9B  8C FB FE     ...   STY r2data
FB9E  B1 F8        ..    LDA (&F8),Y              ; LSB of address to store string
FBA0  48           H     PHA
FBA1  A2 FF        ..    LDX #&FF
FBA3  20 75 F9      u.   JSR &F975                ; Wait for data in TUBE ULA Data register 2 and return it in A
FBA6  C9 80        ..    CMP #&80                 ; Was ESCAPE pressed?
FBA8  B0 1D        ..    BCS &FBC7                ; Yes, then jump (C = 1 now)
FBAA  68           h     PLA
FBAB  85 F8        ..    STA &F8
FBAD  68           h     PLA
FBAE  85 F9        ..    STA &F9
FBB0  A0 00        ..    LDY #&00
.
FBB2  2C FA FE     ,..   BIT r2status             ; Check the DA2 flag of TUBE ULA Status register 2 (Data present in 2st register)
FBB5  10 FB        ..    BPL &FBB2                ; Loop until the DA2 flag is set
FBB7  AD FB FE     ...   LDA r2data
FBBA  91 F8        ..    STA (&F8),Y              ; Read string from host processor
FBBC  C8           .     INY
FBBD  C9 0D        ..    CMP #&0D
FBBF  D0 F1        ..    BNE &FBB2
FBC1  A9 00        ..    LDA #&00
FBC3  88           .     DEY                      ; Length of string
FBC4  18           .     CLC                      ; String was read correctly, so clear carry
FBC5  E8           .     INX                      ; And set X to 0
FBC6  60           `     RTS
.                                                 ; ESCAPE was pressed, so exit with carry set and X = &FF
FBC7  68           h     PLA
FBC8  68           h     PLA
FBC9  A9 00        ..    LDA #&00
FBCB  60           `     RTS

; -----------------------------------------------------------------------------
; OSARGS: Read or write a file's attributes
; -----------------------------------------------------------------------------
.
FBCC  48           H     PHA
FBCD  A9 0C        ..    LDA #&0C                 ; Code &0C for OSARGS
FBCF  20 4A FC      J.   JSR &FC4A                ; Wait for TUBE ULA Data register 2 to be clear and send A to Data register 2
.
FBD2  2C FA FE     ,..   BIT r2status             ; Check the NF2 flag of TUBE ULA Status register 2 (2nd data register not filled)
FBD5  50 FB        P.    BVC &FBD2                ; Loop until TUBE ULA Data register 2 is empty
FBD7  8C FB FE     ...   STY r2data               ; File handle
FBDA  B5 03        ..    LDA &03,X
FBDC  20 4A FC      J.   JSR &FC4A                ; Wait for TUBE ULA Data register 2 to be clear and send A to Data register 2
FBDF  B5 02        ..    LDA &02,X
FBE1  20 4A FC      J.   JSR &FC4A                ; Wait for TUBE ULA Data register 2 to be clear and send A to Data register 2
FBE4  B5 01        ..    LDA &01,X
FBE6  20 4A FC      J.   JSR &FC4A                ; Wait for TUBE ULA Data register 2 to be clear and send A to Data register 2
FBE9  B5 00        ..    LDA &00,X
FBEB  20 4A FC      J.   JSR &FC4A                ; Wait for TUBE ULA Data register 2 to be clear and send A to Data register 2
FBEE  68           h     PLA
FBEF  20 4A FC      J.   JSR &FC4A                ; Wait for TUBE ULA Data register 2 to be clear and send A to Data register 2
FBF2  20 75 F9      u.   JSR &F975                ; Wait for data in TUBE ULA Data register 2 and return it in A
FBF5  48           H     PHA
FBF6  20 75 F9      u.   JSR &F975                ; Wait for data in TUBE ULA Data register 2 and return it in A
FBF9  95 03        ..    STA &03,X
FBFB  20 75 F9      u.   JSR &F975                ; Wait for data in TUBE ULA Data register 2 and return it in A
FBFE  95 02        ..    STA &02,X
FC00  20 75 F9      u.   JSR &F975                ; Wait for data in TUBE ULA Data register 2 and return it in A
FC03  95 01        ..    STA &01,X
FC05  20 75 F9      u.   JSR &F975                ; Wait for data in TUBE ULA Data register 2 and return it in A
FC08  95 00        ..    STA &00,X
FC0A  68           h     PLA
FC0B  60           `     RTS

; -----------------------------------------------------------------------------
; OSFIND: Open or close a file for random or sequential access
; -----------------------------------------------------------------------------
.find
FC0C  48           H     PHA
FC0D  A9 12        ..    LDA #&12                 ; Code &12 for OSFIND
FC0F  20 4A FC      J.   JSR &FC4A                ; Wait for TUBE ULA Data register 2 to be clear and send A to Data register 2
FC12  68           h     PLA
FC13  20 4A FC      J.   JSR &FC4A                ; Wait for TUBE ULA Data register 2 to be clear and send A to Data register 2
FC16  C9 00        ..    CMP #&00                 ; Should the file be closed?
FC18  D0 0A        ..    BNE &FC24                ; No? Then jump.
FC1A  48           H     PHA
FC1B  98           .     TYA
FC1C  20 4A FC      J.   JSR &FC4A                ; Wait for TUBE ULA Data register 2 to be clear and send A to Data register 2
FC1F  20 75 F9      u.   JSR &F975                ; Wait for data in TUBE ULA Data register 2 and return it in A
FC22  68           h     PLA
FC23  60           `     RTS
.
FC24  20 B2 F9      ..   JSR &F9B2                ; Send string at XY through TUBE ULA Data register 2
FC27  4C 75 F9     Lu.   JMP &F975                ; Wait for data in TUBE ULA Data register 2 and return it in A

; -----------------------------------------------------------------------------
; BGET: Read a single byte from an open file
; -----------------------------------------------------------------------------
.bget
FC2A  A9 0E        ..    LDA #&0E                 ; Code &0E for BGET
FC2C  20 4A FC      J.   JSR &FC4A                ; Wait for TUBE ULA Data register 2 to be clear and send A to Data register 2
FC2F  98           .     TYA                      ; File handle
FC30  20 4A FC      J.   JSR &FC4A                ; Wait for TUBE ULA Data register 2 to be clear and send A to Data register 2
FC33  4C 71 F9     Lq.   JMP &F971

; -----------------------------------------------------------------------------
; BPUT: Write a single byte to an open file
; -----------------------------------------------------------------------------
.bput
FC36  48           H     PHA
FC37  A9 10        ..    LDA #&10                 ; Code &10 for OSBPUT
FC39  20 4A FC      J.   JSR &FC4A                ; Wait for TUBE ULA Data register 2 to be clear and send A to Data register 2
FC3C  98           .     TYA                      ; File handle
FC3D  20 4A FC      J.   JSR &FC4A                ; Wait for TUBE ULA Data register 2 to be clear and send A to Data register 2
FC40  68           h     PLA                      ; Byte to be written
FC41  20 4A FC      J.   JSR &FC4A                ; Wait for TUBE ULA Data register 2 to be clear and send A to Data register 2
FC44  48           H     PHA
FC45  20 75 F9      u.   JSR &F975                ; Wait for data in TUBE ULA Data register 2 and return it in A
FC48  68           h     PLA
FC49  60           `     RTS

; -----------------------------------------------------------------------------
; Wait for TUBE ULA Data register 2 to be clear and send A to Data register 2
; -----------------------------------------------------------------------------
.write_to_r2data
FC4A  2C FA FE     ,..   BIT r2status             ; Check the NF2 flag of TUBE ULA Status register 2 (2nd data register not filled)
FC4D  50 FB        P.    BVC &FC4A                ; Loop until TUBE ULA Data register 2 is empty
FC4F  8D FB FE     ...   STA r2data
FC52  60           `     RTS

; -----------------------------------------------------------------------------
; FILE: Read or write a whole file or its attributes
; -----------------------------------------------------------------------------
.file
FC53  84 FB        ..    STY &FB
FC55  86 FA        ..    STX &FA
FC57  48           H     PHA
FC58  A9 14        ..    LDA #&14                 ; Code &14 for OSFILE
FC5A  20 4A FC      J.   JSR &FC4A                ; Wait for TUBE ULA Data register 2 to be clear and send A to Data register 2
FC5D  A0 11        ..    LDY #&11
.
FC5F  B1 FA        ..    LDA (&FA),Y              ; Send XY+17 to XY+2 to the host
FC61  20 4A FC      J.   JSR &FC4A                ; Wait for TUBE ULA Data register 2 to be clear and send A to Data register 2
FC64  88           .     DEY
FC65  C0 01        ..    CPY #&01
FC67  D0 F6        ..    BNE &FC5F
FC69  88           .     DEY
FC6A  B1 FA        ..    LDA (&FA),Y
FC6C  AA           .     TAX
FC6D  C8           .     INY
FC6E  B1 FA        ..    LDA (&FA),Y
FC70  A8           .     TAY
FC71  20 B2 F9      ..   JSR &F9B2                ; Send string at XY through TUBE ULA Data register 2
FC74  68           h     PLA
FC75  20 4A FC      J.   JSR &FC4A                ; Wait for TUBE ULA Data register 2 to be clear and send A to Data register 2
FC78  20 75 F9      u.   JSR &F975                ; Wait for data in TUBE ULA Data register 2 and return it in A
FC7B  48           H     PHA                      ; Result code
FC7C  A0 11        ..    LDY #&11
.
FC7E  20 75 F9      u.   JSR &F975                ; Wait for data in TUBE ULA Data register 2 and return it in A
FC81  91 FA        ..    STA (&FA),Y              ; Read the resulting parameter block and put it at XY
FC83  88           .     DEY
FC84  C0 01        ..    CPY #&01
FC86  D0 F6        ..    BNE &FC7E
FC88  A4 FB        ..    LDY &FB
FC8A  A6 FA        ..    LDX &FA
FC8C  68           h     PLA
FC8D  60           `     RTS

; -----------------------------------------------------------------------------
; OSGBPB handler
; -----------------------------------------------------------------------------
.gbpb
FC8E  84 FB        ..    STY &FB
FC90  86 FA        ..    STX &FA
FC92  48           H     PHA
FC93  A9 16        ..    LDA #&16                 ; Code &16 for OSGBPB
FC95  20 4A FC      J.   JSR &FC4A                ; Wait for TUBE ULA Data register 2 to be clear and send A to Data register 2
FC98  A0 0C        ..    LDY #&0C
.
FC9A  B1 FA        ..    LDA (&FA),Y              ; Send parameterblock to the host
FC9C  20 4A FC      J.   JSR &FC4A                ; Wait for TUBE ULA Data register 2 to be clear and send A to Data register 2
FC9F  88           .     DEY
FCA0  10 F8        ..    BPL &FC9A
FCA2  68           h     PLA
FCA3  20 4A FC      J.   JSR &FC4A                ; Wait for TUBE ULA Data register 2 to be clear and send A to Data register 2
FCA6  A0 0C        ..    LDY #&0C
.
FCA8  20 75 F9      u.   JSR &F975                ; Wait for data in TUBE ULA Data register 2 and return it in A
FCAB  91 FA        ..    STA (&FA),Y              ; Read parameterblock from the host
FCAD  88           .     DEY
FCAE  10 F8        ..    BPL &FCA8
FCB0  A4 FB        ..    LDY &FB
FCB2  A6 FA        ..    LDX &FA
FCB4  4C 71 F9     Lq.   JMP &F971

; -----------------------------------------------------------------------------
; USERV / IRQ2V handler
; -----------------------------------------------------------------------------
.
FCB7  00           .     BRK
FCB8  FF           .     ...                      ; Error number &FF
FCB9  42 61 64     Bad   DB "Bad"
FCBC  00           .     DB &00                   ; String terminator

; -----------------------------------------------------------------------------
; Table which specifies OSWORD call parameter block length
; -----------------------------------------------------------------------------
.                                                 ; Length of parameterblock to be send to the host processor
FCBD  00           .     DB &00                   ; OSWORD &01: Parameter block length = &00
FCBE  05           .     DB &05                   ; OSWORD &02: Parameter block length = &05
FCBF  00           .     DB &00                   ; OSWORD &03: Parameter block length = &00
FCC0  05           .     DB &05                   ; OSWORD &04: Parameter block length = &05
FCC1  02           .     DB &02                   ; OSWORD &05: Parameter block length = &02
FCC2  05           .     DB &05                   ; OSWORD &06: Parameter block length = &05
FCC3  08           .     DB &08                   ; OSWORD &07: Parameter block length = &08
FCC4  0E           .     DB &0E                   ; OSWORD &08: Parameter block length = &0E
FCC5  04           .     DB &04                   ; OSWORD &09: Parameter block length = &04
FCC6  01           .     DB &01                   ; OSWORD &0A: Parameter block length = &01
FCC7  01           .     DB &01                   ; OSWORD &0B: Parameter block length = &01
FCC8  05           .     DB &05                   ; OSWORD &0C: Parameter block length = &05
FCC9  00           .     DB &00                   ; OSWORD &0D: Parameter block length = &00
FCCA  01           .     DB &01                   ; OSWORD &0E: Parameter block length = &01
FCCB  20                 DB &20                   ; OSWORD &0F: Parameter block length = &20
FCCC  10           .     DB &10                   ; OSWORD &10: Parameter block length = &10
FCCD  0D           .     DB &0D                   ; OSWORD &11: Parameter block length = &0D
FCCE  00           .     DB &00                   ; OSWORD &12: Parameter block length = &00
FCCF  04           .     DB &04                   ; OSWORD &13: Parameter block length = &04
FCD0  80           .     DB &80                   ; OSWORD &14: Parameter block length = &80

.                                                 ; Length of parameterblock to be received from the host processor
FCD1  05           .     DB &05                   ; OSWORD &01: Parameter block length = &05
FCD2  00           .     DB &00                   ; OSWORD &02: Parameter block length = &00
FCD3  05           .     DB &05                   ; OSWORD &03: Parameter block length = &05
FCD4  00           .     DB &00                   ; OSWORD &04: Parameter block length = &00
FCD5  05           .     DB &05                   ; OSWORD &05: Parameter block length = &05
FCD6  00           .     DB &00                   ; OSWORD &06: Parameter block length = &00
FCD7  00           .     DB &00                   ; OSWORD &07: Parameter block length = &00
FCD8  00           .     DB &00                   ; OSWORD &08: Parameter block length = &00
FCD9  05           .     DB &05                   ; OSWORD &09: Parameter block length = &05
FCDA  09           .     DB &09                   ; OSWORD &0A: Parameter block length = &09
FCDB  05           .     DB &05                   ; OSWORD &0B: Parameter block length = &05
FCDC  00           .     DB &00                   ; OSWORD &0C: Parameter block length = &00
FCDD  08           .     DB &08                   ; OSWORD &0D: Parameter block length = &08
FCDE  18           .     DB &18                   ; OSWORD &0E: Parameter block length = &18
FCDF  00           .     DB &00                   ; OSWORD &0F: Parameter block length = &00
FCE0  01           .     DB &01                   ; OSWORD &10: Parameter block length = &01
FCE1  0D           .     DB &0D                   ; OSWORD &11: Parameter block length = &0D
FCE2  80           .     DB &80                   ; OSWORD &12: Parameter block length = &80
FCE3  04           .     DB &04                   ; OSWORD &13: Parameter block length = &04
FCE4  80           .     DB &80                   ; OSWORD &14: Parameter block length = &80

; -----------------------------------------------------------------------------
; IRQ/BRK entry
; -----------------------------------------------------------------------------
.irqbrk
FCE5  85 FC        ..    STA &FC                  ; Save accumulator for now
FCE7  68           h     PLA                      ; Pull status register from the stack
FCE8  48           H     PHA
FCE9  29 10        ).    AND #%00010000           ; Mask out the Break flag
FCEB  D0 10        ..    BNE &FCFD
FCED  6C 04 02     l..   JMP (irq1v)              ; Jump if the interrupt was caused by a BRK instruction

; -----------------------------------------------------------------------------
; IRQ1V handler
; -----------------------------------------------------------------------------
.irq1v
FCF0  2C FE FE     ,..   BIT r4status             ; Check the DA4 flag of TUBE ULA Status register 4 (Data present in 4th register)
FCF3  30 4A        0J    BMI &FD3F                ; Jump if DA4 flag is set
FCF5  2C F8 FE     ,..   BIT r1status             ; Check the DA1 flag of TUBE ULA Status register 1 (Data present in 1st register)
FCF8  30 1E        0.    BMI &FD18                ; Jump if DA1 flag is set
FCFA  6C 06 02     l..   JMP (irq2v)

.irqbrk1                                          ; A BRK occurred
FCFD  8A           .     TXA
FCFE  48           H     PHA
FCFF  BA           .     TSX
FD00  BD 03 01     ...   LDA &0103,X
FD03  D8           .     CLD
FD04  38           8     SEC
FD05  E9 01        ..    SBC #&01
FD07  85 FD        ..    STA &FD                  ; Location of last BRK instruction LSB
FD09  BD 04 01     ...   LDA &0104,X
FD0C  E9 00        ..    SBC #&00
FD0E  85 FE        ..    STA &FE                  ; Location of last BRK instruction MSB
FD10  68           h     PLA
FD11  AA           .     TAX
FD12  A5 FC        ..    LDA &FC                  ; Restore accumulator
FD14  58           X     CLI
FD15  6C 02 02     l..   JMP (brkv)               ; Jump to the BRK handler

.irq_events                                       ; IRQ because the host wrote something in the TUBE ULA Data register 1
FD18  AD F9 FE     ...   LDA r1data               ; Was it an event or an ESCAPE flag change?
FD1B  30 1C        0.    BMI &FD39                ; Jump if it's an ESCAPE flag change
FD1D  98           .     TYA
FD1E  48           H     PHA                      ; Save Y
FD1F  8A           .     TXA
FD20  48           H     PHA                      ; Save X
FD21  20 80 FE      ..   JSR &FE80                ; Get data from TUBE ULA Data register 1 (Y)
FD24  A8           .     TAY
FD25  20 80 FE      ..   JSR &FE80                ; Get data from TUBE ULA Data register 1 (X)
FD28  AA           .     TAX
FD29  20 80 FE      ..   JSR &FE80                ; Get data from TUBE ULA Data register 1 (A)
FD2C  20 36 FD      6.   JSR &FD36                ; Jump to the EVENT vector
FD2F  68           h     PLA                      ; Restore X
FD30  AA           .     TAX
FD31  68           h     PLA                      ; Restore Y
FD32  A8           .     TAY
FD33  A5 FC        ..    LDA &FC                  ; Restore accumulator
FD35  40           @     RTI
.
FD36  6C 20 02     l .   JMP (evntv)

.irq_escape                                       ; ESCAPE flag change
FD39  0A           .     ASL A
FD3A  85 FF        ..    STA &FF                  ; Save new ESCAPE flag
FD3C  A5 FC        ..    LDA &FC                  ; Restore accumulator
FD3E  40           @     RTI

.irq_transfer                                     ; IRQ because the host wrote something in the TUBE ULA Data register 4
FD3F  AD FF FE     ...   LDA r4data
FD42  10 21        .!    BPL &FD65
FD44  58           X     CLI
.                                                 ; A BRK instruction was executed in the host processor
FD45  2C FA FE     ,..   BIT r2status             ; Check the DA2 flag of TUBE ULA Status register 2 (Data present in 2st register)
FD48  10 FB        ..    BPL &FD45                ; Loop until data is present in TUBE ULA Data register 2
FD4A  AD FB FE     ...   LDA r2data               ; Retrieve byte and discard it
FD4D  A9 00        ..    LDA #&00                 ; BRK instruction
FD4F  8D 36 02     .6.   STA &0236
FD52  A8           .     TAY
FD53  20 75 F9      u.   JSR &F975                ; Wait for data in TUBE ULA Data register 2 and return it in A
FD56  8D 37 02     .7.   STA &0237                ; Error code
.
FD59  C8           .     INY
FD5A  20 75 F9      u.   JSR &F975                ; Wait for data in TUBE ULA Data register 2 and return it in A
FD5D  99 37 02     .7.   STA &0237,Y              ; Error message
FD60  D0 F7        ..    BNE &FD59
FD62  4C 36 02     L6.   JMP &0236                ; Generate error (BRK)

.irq_data_transfer                                ; Start data transfer or execution of code in parasite
FD65  8D FA FF     ...   STA &FFFA                ; Temporary store A (Reason Code)
FD68  98           .     TYA
FD69  48           H     PHA
FD6A  AC FA FF     ...   LDY &FFFA
FD6D  B9 70 FE     .p.   LDA &FE70,Y
FD70  8D FA FF     ...   STA &FFFA                ; New NMI vector (LSB)
FD73  B9 78 FE     .x.   LDA &FE78,Y
FD76  8D FB FF     ...   STA &FFFB                ; New NMI vector (MSB)
FD79  B9 60 FE     .`.   LDA &FE60,Y
FD7C  85 F4        ..    STA &F4
FD7E  B9 68 FE     .h.   LDA &FE68,Y
FD81  85 F5        ..    STA &F5
.
FD83  2C FE FE     ,..   BIT r4status             ; Check the DA4 flag of TUBE ULA Status register 4 (Data present in 4th register)
FD86  10 FB        ..    BPL &FD83                ; Loop until data is present in TUBE ULA Data register 4
FD88  AD FF FE     ...   LDA r4data               ; Get first parameter from TUBE ULA (Tube ID?: discarded?)
FD8B  C0 05        ..    CPY #&05                 ; Was it reason code &05 (Release TUBE) ?
FD8D  F0 58        .X    BEQ &FDE7
FD8F  98           .     TYA
FD90  48           H     PHA
FD91  A0 01        ..    LDY #&01
.
FD93  2C FE FE     ,..   BIT r4status             ; Check the DA4 flag of TUBE ULA Status register 4 (Data present in 4st register)
FD96  10 FB        ..    BPL &FD93                ; Loop until data is present in TUBE ULA Data register 4
FD98  AD FF FE     ...   LDA r4data               ; Get second parameter from TUBE ULA (address MSB; discarded since this is a 2nd processor unit with 16-bit wide address space)
.
FD9B  2C FE FE     ,..   BIT r4status             ; Check the DA4 flag of TUBE ULA Status register 4 (Data present in 4st register)
FD9E  10 FB        ..    BPL &FD9B                ; Loop until data is present in TUBE ULA Data register 4
FDA0  AD FF FE     ...   LDA r4data               ; Get third parameter from TUBE ULA (discarded)
.
FDA3  2C FE FE     ,..   BIT r4status             ; Check the DA4 flag of TUBE ULA Status register 4 (Data present in 4st register)
FDA6  10 FB        ..    BPL &FDA3                ; Loop until data is present in TUBE ULA Data register 4
FDA8  AD FF FE     ...   LDA r4data               ; Get fourth parameter from TUBE ULA
FDAB  91 F4        ..    STA (&F4),Y
FDAD  88           .     DEY
.
FDAE  2C FE FE     ,..   BIT r4status             ; Check the DA4 flag of TUBE ULA Status register 4 (Data present in 4st register)
FDB1  10 FB        ..    BPL &FDAE                ; Loop until data is present in TUBE ULA Data register 4
FDB3  AD FF FE     ...   LDA r4data               ; Get fifth parameter from TUBE ULA (address LSB)
FDB6  91 F4        ..    STA (&F4),Y
FDB8  2C FD FE     ,..   BIT r3data               ; Read from Tube R3 twice to clear FIFO
FDBB  2C FD FE     ,..   BIT r3data
.
FDBE  2C FE FE     ,..   BIT r4status             ; Check the DA4 flag of TUBE ULA Status register 4 (Data present in 4st register)
FDC1  10 FB        ..    BPL &FDBE                ; Loop until data is present in TUBE ULA Data register 4
FDC3  AD FF FE     ...   LDA r4data               ; Get sync byte
FDC6  68           h     PLA
FDC7  C9 06        ..    CMP #&06
FDC9  90 1C        ..    BCC &FDE7                ; Jump if it's reason code &00-&05
FDCB  D0 1F        ..    BNE &FDEC                ; Jump if it's not reason code &06
FDCD  A0 00        ..    LDY #&00                 ; Reason code &07 handler
.
FDCF  AD FC FE     ...   LDA r3status             ; Check the DA3 flag of TUBE ULA Status register 3 (Data present in 3rd register)
FDD2  29 80        ).    AND #%10000000
FDD4  10 F9        ..    BPL &FDCF                ; Loop until data is present in TUBE ULA Data register 3
FDD6  B9 FF FF     ...   LDA &FFFF,Y
FDD9  8D FD FE     ...   STA r3data
FDDC  C8           .     INY
FDDD  D0 F0        ..    BNE &FDCF
.
FDDF  2C FC FE     ,..   BIT r3status             ; Check the DA3 flag of TUBE ULA Status register 3 (Data present in 3rd register)
FDE2  10 FB        ..    BPL &FDDF
FDE4  8D FD FE     ...   STA r3data

.                                                 ; Reason code &00-&05 handler
FDE7  68           h     PLA
FDE8  A8           .     TAY
FDE9  A5 FC        ..    LDA &FC                  ; Restore accumulator
FDEB  40           @     RTI

.                                                 ; Reason code &06 handler
FDEC  A0 00        ..    LDY #&00
.
FDEE  AD FC FE     ...   LDA r3status             ; Check the DA3 flag of TUBE ULA Status register 3 (Data present in 3rd register)
FDF1  29 80        ).    AND #%10000000
FDF3  10 F9        ..    BPL &FDEE                ; Loop until data is present in TUBE ULA Data register 3
FDF5  AD FD FE     ...   LDA r3data               ; Read byte from host
FDF8  99 FF FF     ...   STA &FFFF,Y              ; And store it in the parasite's memory
FDFB  C8           .     INY
FDFC  D0 F0        ..    BNE &FDEE
FDFE  F0 E7        ..    BEQ &FDE7

; -----------------------------------------------------------------------------
; Reason code &00 NMI handler (Multiple single byte transfer from parasite to host)
; -----------------------------------------------------------------------------
.
FE00  48           H     PHA
FE01  AD FF FF     ...   LDA &FFFF
FE04  8D FD FE     ...   STA r3data
FE07  EE 02 FE     ...   INC &FE02
FE0A  D0 03        ..    BNE &FE0F
FE0C  EE 03 FE     ...   INC &FE03
.
FE0F  68           h     PLA
FE10  40           @     RTI

; -----------------------------------------------------------------------------
; Reason code &01 NMI handler (Multiple single byte transfer from host to parasite)
; -----------------------------------------------------------------------------
.
FE11  48           H     PHA
FE12  AD FD FE     ...   LDA r3data
FE15  8D FF FF     ...   STA &FFFF
FE18  EE 16 FE     ...   INC &FE16
FE1B  D0 03        ..    BNE &FE20
FE1D  EE 17 FE     ...   INC &FE17
.
FE20  68           h     PLA
FE21  40           @     RTI

; -----------------------------------------------------------------------------
; Reason code &02 NMI handler (Multiple double byte transfer from parasite to host)
; -----------------------------------------------------------------------------
.
FE22  48           H     PHA
FE23  98           .     TYA
FE24  48           H     PHA
FE25  A0 00        ..    LDY #&00
FE27  B1 F6        ..    LDA (&F6),Y
FE29  8D FD FE     ...   STA r3data
FE2C  E6 F6        ..    INC &F6
FE2E  D0 02        ..    BNE &FE32
FE30  E6 F7        ..    INC &F7
.
FE32  B1 F6        ..    LDA (&F6),Y
FE34  8D FD FE     ...   STA r3data
FE37  E6 F6        ..    INC &F6
FE39  D0 02        ..    BNE &FE3D
FE3B  E6 F7        ..    INC &F7
.
FE3D  68           h     PLA
FE3E  A8           .     TAY
FE3F  68           h     PLA
FE40  40           @     RTI

; -----------------------------------------------------------------------------
; Reason code &03 NMI handler (Multiple double byte transfer from host to parasite)
; -----------------------------------------------------------------------------
.
FE41  48           H     PHA
FE42  98           .     TYA
FE43  48           H     PHA
FE44  A0 00        ..    LDY #&00
FE46  AD FD FE     ...   LDA r3data
FE49  91 F6        ..    STA (&F6),Y
FE4B  E6 F6        ..    INC &F6
FE4D  D0 02        ..    BNE &FE51
FE4F  E6 F7        ..    INC &F7
.
FE51  AD FD FE     ...   LDA r3data
FE54  91 F6        ..    STA (&F6),Y
FE56  E6 F6        ..    INC &F6
FE58  D0 02        ..    BNE &FE5C
FE5A  E6 F7        ..    INC &F7
.
FE5C  68           h     PLA
FE5D  A8           .     TAY
FE5E  68           h     PLA
FE5F  40           @     RTI

; -----------------------------------------------------------------------------
; Pointers to where address should be put; used by data transfers
; -----------------------------------------------------------------------------
.
FE60  02           .     DB &FE02         ; Multiple single byte transfer from parasite to host
FE61  16           .     DB &FE16         ; Multiple single byte transfer from host to parasite
FE62  F6           .     DB &00F6         ; Multiple double byte transfer from parasite to host
FE63  F6           .     DB &00F6         ; Multiple double byte transfer from host to parasite
FE64  F6           .     DB &00F6         ; Execute code in parasite
FE65  F6           .     DB &00F6         ; Reserved
FE66  D7           .     DB &FDD7         ; 256 byte transfer from parasite to host
FE67  F9           .     DB &FDF9         ; 256 byte transfer from host to parasite
                                                                                               
FE68  FE           .     DB &FE02         ; Multiple single byte transfer from parasite to host
FE69  FE           .     DB &FE16         ; Multiple single byte transfer from host to parasite
FE6A  00           .     DB &00F6         ; Multiple double byte transfer from parasite to host
FE6B  00           .     DB &00F6         ; Multiple double byte transfer from host to parasite
FE6C  00           .     DB &00F6         ; Execute code in parasite
FE6D  00           .     DB &00F6         ; Reserved
FE6E  FD           .     DB &FDD7         ; 256 byte transfer from parasite to host
FE6F  FD           .     DB &FDF9         ; 256 byte transfer from host to parasite

; -----------------------------------------------------------------------------
; Pointers to NMI handlers; used by data transfers
; -----------------------------------------------------------------------------
.
FE70  00           .     DB &FE00 MOD 256         ; Multiple single byte transfer from parasite to host
FE71  11           .     DB &FE11 MOD 256         ; Multiple single byte transfer from host to parasite
FE72  22           "     DB &FE22 MOD 256         ; Multiple double byte transfer from parasite to host
FE73  41           A     DB &FE41 MOD 256         ; Multiple double byte transfer from host to parasite
FE74  B3           .     DB &FEB3 MOD 256         ; Execute code in parasite
FE75  B3           .     DB &FEB3 MOD 256         ; Release TUBE
FE76  B3           .     DB &FEB3 MOD 256         ; 256 byte transfer from parasite to host
FE77  B3           .     DB &FEB3 MOD 256         ; 256 byte transfer from host to parasite

FE78  FE           .     DB &FE00 DIV 256         ; Multiple single byte transfer from parasite to host
FE79  FE           .     DB &FE11 DIV 256         ; Multiple single byte transfer from host to parasite
FE7A  FE           .     DB &FE22 DIV 256         ; Multiple double byte transfer from parasite to host
FE7B  FE           .     DB &FE41 DIV 256         ; Multiple double byte transfer from host to parasite
FE7C  FE           .     DB &FEB3 DIV 256         ; Execute code in parasite
FE7D  FE           .     DB &FEB3 DIV 256         ; Release TUBE
FE7E  FE           .     DB &FEB3 DIV 256         ; 256 byte transfer from parasite to host
FE7F  FE           .     DB &FEB3 DIV 256         ; 256 byte transfer from host to parasite

; -----------------------------------------------------------------------------
; Get data from TUBE ULA Data register 1
; -----------------------------------------------------------------------------
.
FE80  2C           ,     BIT r1status             ; Check the DA1 flag of TUBE ULA Status register 1 (Data present in 1st register)
FE83  30 0F        0.    BMI &FE94                ; Jump if the DA1 flag is set
FE85  2C FE FE     ,..   BIT r4status             ; Check the DA4 flag of TUBE ULA Status register 4 (Data present in 4th register)
FE88  10 F6        ..    BPL &FE80                ; Jump if the DA4 flag is clear
FE8A  A5 FC        ..    LDA &FC                  ; Restore accumulator
FE8C  08           .     PHP
FE8D  58           X     CLI
FE8E  28           (     PLP
FE8F  85 FC        ..    STA &FC
FE91  4C 80 FE     L..   JMP &FE80
.
FE94  AD F9 FE     ...   LDA r1data
FE97  60           `     RTS

; -----------------------------------------------------------------------------
; Print message to output stream
; -----------------------------------------------------------------------------
.
FE98  68           h     PLA
FE99  85 FA        ..    STA &FA
FE9B  68           h     PLA
FE9C  85 FB        ..    STA &FB
FE9E  A0 00        ..    LDY #&00
.
FEA0  E6 FA        ..    INC &FA
FEA2  D0 02        ..    BNE &FEA6
FEA4  E6 FB        ..    INC &FB
.
FEA6  B1 FA        ..    LDA (&FA),Y
FEA8  30 06        0.    BMI &FEB0
FEAA  20 EE FF      ..   JSR oswrch
FEAD  4C A0 FE     L..   JMP &FEA0
.
FEB0  6C FA 00     l..   JMP (&00FA)

; -----------------------------------------------------------------------------
; Default NMI entry
; -----------------------------------------------------------------------------
.
FEB3  8D FD FE     ...   STA r3data
FEB6  40           @     RTI

FEB7  FF           .     ...
FEB8  FF           .     ...
FEB9  FF           .     ...
FEBA  FF           .     ...
FEBB  FF           .     ...
FEBC  FF           .     ...
FEBD  FF           .     ...
FEBE  FF           .     ...
FEBF  FF           .     ...
FEC0  FF           .     ...
FEC1  FF           .     ...
FEC2  FF           .     ...
FEC3  FF           .     ...
FEC4  FF           .     ...
FEC5  FF           .     ...
FEC6  FF           .     ...
FEC7  FF           .     ...
FEC8  FF           .     ...
FEC9  FF           .     ...
FECA  FF           .     ...
FECB  FF           .     ...
FECC  FF           .     ...
FECD  FF           .     ...
FECE  FF           .     ...
FECF  FF           .     ...
FED0  FF           .     ...
FED1  FF           .     ...
FED2  FF           .     ...
FED3  FF           .     ...
FED4  FF           .     ...
FED5  FF           .     ...
FED6  FF           .     ...
FED7  FF           .     ...
FED8  FF           .     ...
FED9  FF           .     ...
FEDA  FF           .     ...
FEDB  FF           .     ...
FEDC  FF           .     ...
FEDD  FF           .     ...
FEDE  FF           .     ...
FEDF  FF           .     ...
FEE0  FF           .     ...
FEE1  FF           .     ...
FEE2  FF           .     ...
FEE3  FF           .     ...
FEE4  FF           .     ...
FEE5  FF           .     ...
FEE6  FF           .     ...
FEE7  FF           .     ...
FEE8  FF           .     ...
FEE9  FF           .     ...
FEEA  FF           .     ...
FEEB  FF           .     ...
FEEC  FF           .     ...
FEED  FF           .     ...
FEEE  FF           .     ...
FEEF  FF           .     ...
FEF0  FF           .     ...
FEF1  FF           .     ...
FEF2  FF           .     ...
FEF3  FF           .     ...
FEF4  FF           .     ...
FEF5  FF           .     ...
FEF6  FF           .     ...
FEF7  FF           .     ...

; -----------------------------------------------------------------------------
; TUBE ULA registers
; -----------------------------------------------------------------------------
.r1status                                         ; Parasite TUBE ULA: Status register 1
FEF8  FF           .     ...                      ; bit 7 (DA1) : Data present in 1st register
                                                  ; bit 6 (NF1) : 1st data register not filled
                                                  ; bit 5 (P)   : Set parasite active low
                                                  ; bit 4 (V)   : Enable 2 byte FIFO use of register 3
                                                  ; bit 3 (M)   : Enable parasite NMI from 3rd data register
                                                  ; bit 2 (J)   : Enable parasite IRQ from 4th data register
                                                  ; bit 1 (I)   : Enable parasite IRQ from 1st data register
                                                  ; bit 0 (Q)   : Enable host IRQ from 4th data register
.r1data                                           ; Parasite TUBE ULA: Data register 1. Used for OSWRCH, events and ESCAPE handling.
FEF9  FF           .     ...
.r2status                                         ; Parasite TUBE ULA: Status register 2
FEFA  FF           .     ...                      ; bit 7 (DA2) : Data present in 2nd register
                                                  ; bit 6 (NF2) : 2nd data register not filled
                                                  ; bit 5-0     : Not used
.r2data                                           ; Parasite TUBE ULA: Data register 2. Used by other operating system calls.
FEFB  FF           .     ...
.r3status                                         ; Parasite TUBE ULA: Status register 3
FEFC  FF           .     ...                      ; bit 7 (DA3) : Data present in 3rd register
                                                  ; bit 6 (NF3) : 3rd data register not filled
                                                  ; bit 5-0     : Not used
.r3data                                           ; Parasite TUBE ULA: Data register 3. User register for data transfer and I/O errors.
FEFD  FF           .     ...
.r4status                                         ; Parasite TUBE ULA: Status register 4
FEFE  FF           .     ...                      ; bit 7 (DA4) : Data present in 4nd register
                                                  ; bit 6 (NF4) : 4nd data register not filled
                                                  ; bit 5-0     : Not used
.r4data                                           ; Parasite TUBE ULA: Data register 4. System register used for control or data transfer.
FEFF  FF           .     ...

FF00  FF           .     ...
FF01  FF           .     ...
FF02  FF           .     ...
FF03  FF           .     ...
FF04  FF           .     ...
FF05  FF           .     ...
FF06  FF           .     ...
FF07  FF           .     ...
FF08  FF           .     ...
FF09  FF           .     ...
FF0A  FF           .     ...
FF0B  FF           .     ...
FF0C  FF           .     ...
FF0D  FF           .     ...
FF0E  FF           .     ...
FF0F  FF           .     ...
FF10  FF           .     ...
FF11  FF           .     ...
FF12  FF           .     ...
FF13  FF           .     ...
FF14  FF           .     ...
FF15  FF           .     ...
FF16  FF           .     ...
FF17  FF           .     ...
FF18  FF           .     ...
FF19  FF           .     ...
FF1A  FF           .     ...
FF1B  FF           .     ...
FF1C  FF           .     ...
FF1D  FF           .     ...
FF1E  FF           .     ...
FF1F  FF           .     ...
FF20  FF           .     ...
FF21  FF           .     ...
FF22  FF           .     ...
FF23  FF           .     ...
FF24  FF           .     ...
FF25  FF           .     ...
FF26  FF           .     ...
FF27  FF           .     ...
FF28  FF           .     ...
FF29  FF           .     ...
FF2A  FF           .     ...
FF2B  FF           .     ...
FF2C  FF           .     ...
FF2D  FF           .     ...
FF2E  FF           .     ...
FF2F  FF           .     ...
FF30  FF           .     ...
FF31  FF           .     ...
FF32  FF           .     ...
FF33  FF           .     ...
FF34  FF           .     ...
FF35  FF           .     ...
FF36  FF           .     ...
FF37  FF           .     ...
FF38  FF           .     ...
FF39  FF           .     ...
FF3A  FF           .     ...
FF3B  FF           .     ...
FF3C  FF           .     ...
FF3D  FF           .     ...
FF3E  FF           .     ...
FF3F  FF           .     ...
FF40  FF           .     ...
FF41  FF           .     ...
FF42  FF           .     ...
FF43  FF           .     ...
FF44  FF           .     ...
FF45  FF           .     ...
FF46  FF           .     ...
FF47  FF           .     ...
FF48  FF           .     ...
FF49  FF           .     ...
FF4A  FF           .     ...
FF4B  FF           .     ...
FF4C  FF           .     ...
FF4D  FF           .     ...
FF4E  FF           .     ...
FF4F  FF           .     ...
FF50  FF           .     ...
FF51  FF           .     ...
FF52  FF           .     ...
FF53  FF           .     ...
FF54  FF           .     ...
FF55  FF           .     ...
FF56  FF           .     ...
FF57  FF           .     ...
FF58  FF           .     ...
FF59  FF           .     ...
FF5A  FF           .     ...
FF5B  FF           .     ...
FF5C  FF           .     ...
FF5D  FF           .     ...
FF5E  FF           .     ...
FF5F  FF           .     ...
FF60  FF           .     ...
FF61  FF           .     ...
FF62  FF           .     ...
FF63  FF           .     ...
FF64  FF           .     ...
FF65  FF           .     ...
FF66  FF           .     ...
FF67  FF           .     ...
FF68  FF           .     ...
FF69  FF           .     ...
FF6A  FF           .     ...
FF6B  FF           .     ...
FF6C  FF           .     ...
FF6D  FF           .     ...
FF6E  FF           .     ...
FF6F  FF           .     ...
FF70  FF           .     ...
FF71  FF           .     ...
FF72  FF           .     ...
FF73  FF           .     ...
FF74  FF           .     ...
FF75  FF           .     ...
FF76  FF           .     ...
FF77  FF           .     ...
FF78  FF           .     ...
FF79  FF           .     ...
FF7A  FF           .     ...
FF7B  FF           .     ...
FF7C  FF           .     ...
FF7D  FF           .     ...
FF7E  FF           .     ...
FF7F  FF           .     ...
FF80  B7 FC        ..    DW &FCB7                 ; &0200 USERV (Not implemented)
FF82  45 F9        E.    DW _brkv                 ; &0202 BRKV
FF84  F0 FC        ..    DW &FCF0                 ; &0204 IRQ1V
FF86  B7 FC        ..    DW &FCB7                 ; &0206 IRQ2V (Not implemented)
FF88  CA F9        ..    DW &F9CA                 ; &0208 CLIV
FF8A  73 FA        s.    DW &FA73                 ; &020A BYTEV (TUBE ULA Data register 2 = &04/&06)
FF8C  FF FA        ..    DW &FAFF                 ; &020C WORDV (TUBE ULA Data register 2 = &08/&0A)
FF8E  62 F9        b.    DW &F962                 ; &020E WRCHV
FF90  6C F9        l.    DW &F96C                 ; &0210 RDCHV (TUBE ULA Data register 2 = &02)
FF92  53 FC        S.    DW &FC53                 ; &0212 FILEV (TUBE ULA Data register 2 = &14)
FF94  CC FB        ..    DW &FBCC                 ; &0214 ARGSV (TUBE ULA Data register 2 = &0C)
FF96  2A FC        *.    DW &FC2A                 ; &0216 BGETV (TUBE ULA Data register 2 = &0E)
FF98  36 FC        6.    DW &FC36                 ; &0218 BPUTV (TUBE ULA Data register 2 = &10)
FF9A  8E FC        ..    DW &FC8E                 ; &021A GBPBV (TUBE ULA Data register 2 = &16)
FF9C  0C FC        ..    DW &FC0C                 ; &021C FINDV (TUBE ULA Data register 2 = &12)
FF9E  B7 FC        ..    DW &FCB7                 ; &021E FSCV (Not implemented)
FFA0  7D F9        }.    DW &F97D                 ; &0220 EVNTV (RTS; Does nothing)
FFA2  B7 FC        ..    DW &FCB7                 ; &0222 UPTV (Not implemented)
FFA4  B7 FC        ..    DW &FCB7                 ; &0224 NETV (Not implemented)
FFA6  B7 FC        ..    DW &FCB7                 ; &0226 VDUV (Not implemented)
FFA8  B7 FC        ..    DW &FCB7                 ; &0228 KEYV (Not implemented)
FFAA  B7 FC        ..    DW &FCB7                 ; &022A INSV (Not implemented)
FFAC  B7 FC        ..    DW &FCB7                 ; &022C REMV (Not implemented)
FFAE  B7 FC        ..    DW &FCB7                 ; &022E CNPV (Not implemented)
FFB0  7D F9        }.    DW &F97D                 ; &0230 IND1V (RTS; Does nothing)
FFB2  7D F9        }.    DW &F97D                 ; &0232 IND2V (RTS; Does nothing)
FFB4  7D F9        }.    DW &F97D                 ; &0234 IND3V (RTS; Does nothing)

FFB6  36 80        6.    DW &8036
FFB8  FF           .     DB &FF

.osrdrm
FFB9  4C B7 FC     L..   JMP &FCB7
.vduchr
FFBC  4C B7 FC     L..   JMP &FCB7
.oseven
FFBF  4C B7 FC     L..   JMP &FCB7
.gsinit
FFC2  4C B7 FC     L..   JMP &FCB7
.gsread
FFC5  4C B7 FC     L..   JMP &FCB7
.nvwrch
FFC8  4C 6C F9     Ll.   JMP &F96C
.nvrdch
FFCB  4C 62 F9     Lb.   JMP &F962
.osfind
FFCE  6C 1C 02     l..   JMP (findv)
.osgbpb
FFD1  6C 1A 02     l..   JMP (gbpbv)
.osbput
FFD4  6C 18 02     l..   JMP (bputv)
.osbget
FFD7  6C 16 02     l..   JMP (bgetv)
.osargs
FFDA  6C 14 02     l..   JMP (argsv)
.osfile
FFDD  6C 12 02     l..   JMP (filev)
.osrdch
FFE0  6C 10 02     l..   JMP (rdchv)
.osasci
FFE3  C9 0D        ..    CMP #&0D
FFE5  D0 07        ..    BNE oswrch
.osnewl
FFE7  A9 0A        ..    LDA #&0A
FFE9  20 EE FF      ..   JSR oswrch
FFEC  A9 0D        ..    LDA #&0D
.oswrch
FFEE  6C 0E 02     l..   JMP (wrchv)
.osword
FFF1  6C 0C 02     l..   JMP (wordv)
.osbyte
FFF4  6C 0A 02     l..   JMP (bytev)
.oscli
FFF7  6C 08 02     l..   JMP (cliv)

FFFA  B3 FE        ..    DW &FEB3               ; NMI vector
FFFC  00 F8        ..    DW &F800               ; Reset vector
FFFE  E5 FC        ..    DW &FCE5               ; IRQ/BRK vector
