Atom Kernel Routines part 1

Constants

STX	=	$02	; (CTRL-B, 2)  Start printer
ETX	=	$03	; (CTRL-C, 3) End printer
ACK	=	$06	; (CTRL-F, 6)	Start screen* 
BELL	=	$07	; (CTRL-G, 7)	Bleep
BS	=	$08	; (CTRL-H, 8)	Backspace
HT	=	$09	; (CTRL-I, 9)	Horizontal tab
LF	=	$0a	; (CTRL-J, 10)	Linefeed
VT	=	$0b	; (CTRL-K, 11)	Vertical tab. Moves the cursor up one line.
FF	=	$0c	; (CTRL-L, 12)	Formfeed	Clears the screen, moves the cursor to the top left-hand corner, 
			;		and sets the VDU to character mode.
CR	=	$0d	; (CTRL-M, 13)	Return	Moves the cursor to the start of the current line.
SO	=	$0e	; (CTRL-N, 14)	Page mode on
SI	=	$0f	; (CTRL-O, 15)	Page mode off *
NAK 	=	$15	; (CTRL-U, 21)	End screen
CAN	=	$18	; (CTRL-X, 24)	Cancel
ESC	=	$1b	; (CTRL-[, 27)	Escape
RS	=	$1e	; (CTRL-^, 30)	Home cursor
SP	=	$20	; space
characters_per_line	=	32;
lines_per_screen	=	16;
FF6C 06 0c 0f ??? ; Data from $FF6F to $FFC6 (88 bytes) 
FF6F .BYTE "ACORN ATOM"
FF79 .BYTE 0a, 0a, 0d, a9, 82, 85, 12, 58, a9, 55 ; .......X.U 
FF83 .BYTE 8d, 01, 29, cd, 01, 29, d0, 0c, 0a, 8d ; ..)..).... 

Block 0 RAM

Advanced programmers may find the following table useful as it shows the contents of important block zero RAM locations used by BASIC or the Cassette Operating System. Locations marked as miscellaneous working space tend to have multiple uses. For example, B0 to DB are used by COS for different purposes at different times, and 16 to 59 are usually but not always used as 4-byte integer arithmetic registers.

Note that many of these explanations are not formally supported by Acorn, so they may change in future ROMs.

Page 0 RAM

Address   
.org	$0000
	.byte	ERR_NUM	;	00 Error number 
01-02 Current Line number (binary) 
03 Pointer to character being investigated in statement being interpreted. 
04 Temp. for X 
05-06 Address of start of statement being interpreted 
07 Print Column counter 
08-0C Random number seed 
0D 0E Top (binary) 
10 11 Address of BASIC error handler, normally C9E7, 
12 Text space pointer; normally 82 or 89 
16- 59 Misc. BASIC working space 
V5A_plot_x_lsb, V5A_plot_x_msb	;	X ordinate for point plot routine 
V5C_plot_y_lsb; V5D_plot_y_msb	;	Y ordinate for point plot routine 
5E Data for point plot routine. 1=set, 2=invert, else clear 
5F 60 Point plot routine workspace 
61 6F Misc. BASIC working space 
70 7F FP. BASIC working space 
80 AF Free 
B0 DB Misc. COS working space 
DC Tape read/write checksum 
DD Fload flag; bit 7 = 1 to ignore block numbers 
VDE_p_start_of_line_containing_cursor	= $DE	; DE should be 00, 20, 40 ... E0, DF should be 80 or 81 
VE0_cursor_position_in_VDU_line		= $E0	;	 00 to 3F (or is that 1F?) 
VE1_cursor_on				= $E1	; 0=cursor off, 1 = cursor on 
VE6_lines_remaining_if_VDU_in_page_mode	= $E6	; 
E2 E5 Misc. Workspace 
E6 Number of lines remaining (1-16) if VDU in page mode, 
bit 7 = 1 if not in page mode. 
E7 Bits 5,6,= 1 for shift lock, else 0 
VE7_shift_lock	= $E7	; Bits 5,6,= 1 for shift lock, else 0 
VE8_misc_1	= $E8
VE9_misc_2	= $E9
VEA_nomon	= $EA
EB FD Misc. Workspace for COS 
VFE_char_not_printed	=	FE Character not sent to printer (normally 0A = Line Feed) 

Page 1 RAM

INPUT_LINE_BUFFER	=	$0100 ; 0100 013F Input line buffer 
140 17F String processing area 
180 1FF Stack 

Page 2 and 3 RAM

NMIVEC	= $0200 ; 
BRKVEC	= $0202 ; 
IRQVEC	= $0204 ; $A000
COMVEC	= $0206 ; 
WRCVEC	= $0208 ; 
RDCVEC	= $020A ; 
LODVEC	= $020C ; 
SAVVEC	= $020E ; 
RDRVEC	= $0210 ; $c2ac ERROR
STRVEC	= $0212 ; $c2ac ERROR
BGTVEC	= $0214 ; 
BPTVEC	= $0216 ; 
FNDVEC	= $0218 ; Ptr. to PrintTapeMessage routine, normally 
SHTVEC	= $021A ;DUMMY
21C 23F Free 
240 2EA Misc. Workspace for BASIC 
2EB 320 Pointers to arrays: 
P_array_space	$02EB
P_AA_H	=	$02EB	;	points to array AA
P_BB_H	=	$02EC	;	points to array BB
P_AA_L	=	$0306	;	points to array AA
P_BB_L	=	$0307	;	points to array BB
321 Integer Variable 
322 33C Low byte of variables A-Z 
33E 357 2nd byte of variables A-Z 
359 371 3rd byte of variables A-Z 
373 38C High byte of variables A-Z 
38D 3C0 Labels; 38D, 38E is RAM address of label a,
38F, 340 is RAM address of label b, etc. 
3C1 3FD Misc. Workspace for BASIC 
3FE 3FF Ptr. to point plot routine F6E2 for mode 0,
F73B for mode 1,
F754 for mode 2,
F76D for mode 3,
F7AA for mode 4, 

The following addresses (except for C2F2, C8E6, FFFA, FFFC and FFFE) are the entry points for some useful routines in BASIC and COS. Note that most are not documented by Acorn, and so may change in future ROMs.

VRAM		=	$8000
PPI		=	$B000
PPI_PA		=	PPI+0
PPI_PB		=	PPI+1
PPI_PC		=	PPI+2
PPI_CTRL	=	PPI+3
VIA_R0	=	$ B800
VIA_R1	=	$ B801
VIA_R2	=	$ B802
VIA_R3	=	$ B803
VIA_RC	=	$ B80C
VIA_R3	=	$ B803
; AODIS
; Copyright © 1997,98 Xaviar
; Version 0.31, Apr. 21, 1998
; HTML Disassembly of file AKERNEL.ROM
; File size is 4096 bytes, loaded at $F000-$FFFF
; Reset: $FF3F, nmi: $FFC7, brk/irq: $FFB2
; Data included
; Data from $F000 to $FFC6 (4039 bytes)
;F000
  .BYTE "PLOT", f5,
 .byte 4e	; 'N'
F006
  .BYTE "DRAW", f5, 'B'
F00C
  .BYTE "MOVE", f5,  'F' 
F012
  .Byte	"CLEAR", f6, 7b, 

FXXX
	.byte	"DIM",	f0, ae
F01E  .BYTE 5b, f2, a1
F021  .BYTE "OLD"
	, f5, 31, 
F026	.byte	"WAIT"
F02A  f1 4c     sbc ($4C),Y
F02C  c5 50     cmp $50
F02E  a4 5e     ldy $5E
F030  b1 05     lda ($05),Y
F032  c9 40     cmp #$40
F034  90 12     bcc $F048
F036  c9 5b     cmp #$5B
F038  b0 0e     bcs $F048
F03A  c8        iny 
F03B  d1 05     cmp ($05),Y
F03D  d0 09     bne $F048
F03F  20 8b f0  jsr $F08B
F042  20 4f c9  jsr $C94F
F045  4c 62 c9  jmp $C962
F048  4c 24 ca  jmp $CA24
F04B  a2 ff     ldx #$FF
F04D  a4 5e     ldy $5E
F04F  c6 5e     dec $5E
F051  b1 05     lda ($05),Y
F053  c9 40     cmp #$40
F055  90 09     bcc $F060
F057  c9 5b     cmp #$5B
F059  b0 05     bcs $F060
F05B  c8        iny 
F05C  d1 05     cmp ($05),Y
F05E  f0 25     beq $F085
F060  a4 5e     ldy $5E
F062  e8        inx 
F063  c8        iny 
F064  bd 00 f0  lda $F000,X	; points to "PLOT"
F067  30 0c     bmi $F075
F069  d1 05     cmp ($05),Y
F06B  f0 f5     beq $F062
F06D  e8        inx 
F06E  bd ff ef  lda $EFFF,X
F071  10 fa     bpl $F06D
F073  d0 eb     bne $F060
F075  85 53     sta $53
F077  bd 01 f0  lda $F001,X	; points to "PLOT" plus 1
F07A  85 52     sta $52
F07C  84 03     sty $03
F07E  a6 04     ldx $04
F080  e6 5e     inc $5E
F082  6c 52 00  jmp ($0052)
F085  20 8b f0  jsr $F08B
F088  4c f1 c3  jmp $C3F1
F08B  c8        iny 
F08C  84 03     sty $03
F08E  e9 40     sbc #$40
F090  48        pha 
F091  20 bc c8  jsr $C8BC
F094  68        pla 
F095  a8        tay 
F096  b5 15     lda $15,X
F098  0a        asl A
F099  36 24     rol $24,X
F09B  0a        asl A
F09C  36 24     rol $24,X
F09E  18        clc 
F09F  79 eb 02  adc $02EB,Y
F0A2  95 15     sta $15,X
F0A4  b5 24     lda $24,X
F0A6  79 06 03  adc $0306,Y
F0A9  95 24     sta $24,X
F0AB  b0 d7     bcs $F084	; jumps to a 00 nopcode = break?
F0AD  60        rts 
F0AE  a5 01     lda $01
F0B0  05 02     ora $02
F0B2  f0 22     beq $F0D6	; to break
F0B4  20 34 c4  jsr $C434
F0B7  90 1e     bcc $F0D7
F0B9  20 bc c8  jsr $C8BC
F0BC  ca        dex 
F0BD  ca        dex 
F0BE  86 04     stx $04
F0C0  b4 16     ldy $16,X
F0C2  38        sec 
F0C3  a5 23     lda $23
F0C5  99 21 03  sta $0321,Y
F0C8  75 17     adc $17,X
F0CA  85 23     sta $23
F0CC  a5 24     lda $24
F0CE  99 3c 03  sta $033C,Y
F0D1  75 26     adc $26,X
F0D3  4c 19 f1  jmp $F119
F0D6  00        brk 
F0D7  a4 03     ldy $03
F0D9  b1 05     lda ($05),Y
F0DB  c9 40     cmp #$40
F0DD  90 f7     bcc $F0D6	; to break
F0DF  c9 5b     cmp #$5B
F0E1  b0 f3     bcs $F0D6	; to break
F0E3  c8        iny 
F0E4  d1 05     cmp ($05),Y
F0E6  d0 ee     bne $F0D6	; to break
F0E8  e9 40     sbc #$40
F0EA  48        pha 
F0EB  c8        iny 
F0EC  84 03     sty $03
F0EE  20 bc c8  jsr $C8BC
F0F1  68        pla 
F0F2  a8        tay 
F0F3  a5 23     lda $23
F0F5  99 eb 02  sta $02EB,Y
F0F8  a5 24     lda $24
F0FA  99 06 03  sta $0306,Y
F0FD  ca        dex 
F0FE  86 04     stx $04
F100  b4 16     ldy $16,X
F102  c8        iny 
F103  d0 02     bne $F107
F105  f6 25     inc $25,X
F107  98        tya 
F108  0a        asl A
F109  36 25     rol $25,X
F10B  0a        asl A
F10C  36 25     rol $25,X
F10E  18        clc 
F10F  65 23     adc $23
F111  85 23     sta $23
F113  b5 25     lda $25,X
F115  65 24     adc $24
F117  b0 bd     bcs $F0D6	; to break
F119  85 24     sta $24
F11B  a0 00     ldy #$00
F11D  a9 aa     lda #$AA
F11F  91 23     sta ($23),Y
F121  d1 23     cmp ($23),Y
F123  d0 f7     bne $F11C
F125  4a        lsr A
F126  91 23     sta ($23),Y
F128  d1 23     cmp ($23),Y
F12A  d0 f0     bne $F11C
F12C  20 34 c4  jsr $C434
F12F  b0 a5     bcs $F0D6	; to break
F131  a4 03     ldy $03
F133  b1 05     lda ($05),Y
F135  c9 2c     cmp #$2C
F137  d0 05     bne $F13E
F139  e6 03     inc $03
F13B  4c ae f0  jmp $F0AE
F13E  4c 58 c5  jmp $C558
F141  a5 0d     lda $0D
F143  85 23     sta $23
F145  a5 0e     lda $0E
F147  85 24     sta $24
F149  4c 83 ce  jmp $CE83
F14C  20 e4 c4  jsr $C4E4
F14F  20 66 fe  jsr $FE66
F152  4c 5b c5  jmp $C55B
; looks like data because disassembly looks duff
; Data from $F155 to $F158 (4 bytes)
F155  .BYTE 1c, 8a, 1c, 23                          ; ...#
F159  5d 8b 1b  eor $1B8B,X
F15C  a1 9d     lda ($9D,X)
F15E  8a        txa 
F15F  1d 23 9d  ora $9D23,X
F162  8b        ??? 
F163  1d a1 00  ora $00A1,X
F166  29 19     and #$19
F168  ae 69 a8  ldx $A869
F16B  19 23 24  ora $2423,Y
F16E  53        ??? 
F170  23        ??? 
F171  24 53     bit $53
F173  19 a1 00  ora $00A1,Y
F176  1a        ???
F177  5b        ??? 
; Data from $F178 to $F186 (15 bytes)
F178  .BYTE 5b, a5, 69, 24, 24, ae, ae, a8, ad, 29  ; [.i$$....)
F182  .BYTE 00, 7c, 00, 15, 9c                      ; .|...

F187  6d 9c a5  adc $A59C
F18A  69 29     adc #$29
F18C  53        ??? 

; Data from $F18D to $F196 (10 bytes)
F18D  .BYTE 84, 13, 34, 11, a5, 69, 23, 
; table of data:
F194	.byte	a0, d8, 62, 5a
F198  .BYTE 48, 26, 62, 94, 88, 54, 44, c8, 54, 68 
F1A2  .BYTE 44, e8, 94, 00, b4

F1A7  08        php 
F1A8  84 74     sty $74
F1AA  b4 28     ldy $28,X
F1AC  6e 74 f4  ror $F474
F1AF  cc 4a 72  cpy $724A
F1B2  f2        ??? 
F1B3  a4 8a     ldy $8A
F1B5  00        brk 
F1B6  aa        tax 
F1B7  a2 a2     ldx #$A2
F1B9  74        ??? 
F1BA  .BYTE 74, 74, 72, 44, 68, b2, 32, b2
F1C2  .BYTE 00, 22, 00, 1a, 1a, 26, 26, 72, 72, 88
F1CC  .BYTE c8, c4, ca, 26, 48, 44, 44, a2, c8, 
; table of data, 15 bytes
F1D5	.byte 00, 02, 00, 08, f2, ff, 80, 01, c0, e2, c0, c0, ff, 00, 00
; table of data, 15 bytes
F1E4	.byte 08, 00, 10, 80, 40, c0, 00, c0, 00, 40, 00, 00, e4, 20, 80
; table of data, 15 bytes
F1F3	.BYTE 00, fc, 00, 08, 08, f8, fc, f4, 0c, 10, 04, f4, 00, 20, 
;table of data
F201	.byte	10
;table of data
F202	.byte 00, 00, 0f, 01, 01, 01, 11, 11, 02, 02, 11, 11, 02, 12, 02, 00 
F212	.BYTE 08, 10, 18, 20, 28, 30, 38, 40, 48, 50, 58, 60, 68, 70, 78, 80 
F222	.BYTE 88, 90, 98, a0, a8, b0, b8, c0, c8, d0, d8, e0, e8, f0, f8, 0c 
F232	.BYTE 2c, 4c, 4c, 8c, ac, cc, ec, 8a, 9a, aa, ba, ca, da, ea, fa, 0e
F242	.BYTE 2e, 4e, 6e, 8e, ae, ce, ee, 0d, 2d, 4d, 6d, 8d, ad, cd, 
;table of data
F250	.byte ed, 0d, 0d, 0c, 0d, 0e, 0d, 0c, 0d, 0d, 0d, 0c, 0d, 0d, 0d, 0c 
F260	.BYTE 0d, 0f, 0d, 0c, 0d, 09, 0d, 0c, 0d, 08, 0d, 0c, 0d, 08, 0d, 0c 
F270	.BYTE 0d, 0f, 06, 0b, 0b, 04, 0a, 08, 08, 0d, 0d, 0d, 0d, 0d, 0f, 0d 
F280	.BYTE 0f, 07, 07, 07, 07, 05, 09, 03, 03, 01, 01, 01, 01, 02, 01, 01
F291	.byte 01
F291  a4 03     ldy $03
F293  b1 05     lda ($05),Y
F295  e6 03     inc $03
F297  c9 20     cmp #$20
F299  f0 f6     beq $F291
F29B  60        rts 
F29C  e6 03     inc $03
F29E  4c 1b c3  jmp $C31B
F2A1  b1 05     lda ($05),Y
F2A3  c9 5d     cmp #$5D
F2A5  f0 f5     beq $F29C
F2A7  20 f6 c4  jsr $C4F6
F2AA  c6 03     dec $03
F2AC  20 8e f3  jsr $F38E
F2AF  c6 03     dec $03
F2B1  a5 52     lda $52
F2B3  48        pha 
F2B4  a5 53     lda $53
F2B6  48        pha 
F2B7  ad 21 03  lda $0321
F2BA  48        pha 
F2BB  a9 00     lda #$00
F2BD  85 34     sta $34
F2BF  85 43     sta $43
F2C1  a9 05     lda #$05
F2C3  8d 21 03  sta $0321
F2C6  a5 01     lda $01
F2C8  85 16     sta $16
F2CA  a5 02     lda $02
F2CC  85 25     sta $25
F2CE  20 89 c5  jsr $C589
F2D1  20 79 f3  jsr $F379
F2D4  68        pla 
F2D5  8d 21 03  sta $0321
F2D8  68        pla 
F2D9  20 7e f3  jsr $F37E
F2DC  68        pla 
F2DD  20 76 f3  jsr $F376
F2E0  a0 00     ldy #$00
F2E2  c4 00     cpy $00
F2E4  f0 09     beq $F2EF
F2E6  b9 66 00  lda $0066,Y
F2E9  20 76 f3  jsr $F376
F2EC  c8        iny 
F2ED  d0 f3     bne $F2E2
F2EF  c0 03     cpy #$03
F2F1  f0 0c     beq $F2FF
F2F3  20 79 f3  jsr $F379
F2F6  20 4c ca  jsr $CA4C
F2F9  20 4c ca  jsr $CA4C
F2FC  c8        iny 
F2FD  d0 f0     bne $F2EF
F2FF  a0 00     ldy #$00
F301  b1 05     lda ($05),Y
F303  c9 3b     cmp #$3B
F305  f0 0a     beq $F311
F307  c9 0d     cmp #$0D
F309  f0 06     beq $F311
F30B  20 4c ca  jsr $CA4C
F30E  c8        iny 
F30F  d0 f0     bne $F301
F311  20 54 cd  jsr $CD54
F314  20 e4 c4  jsr $C4E4
F317  88        dey 
F318  b1 05     lda ($05),Y
F31A  c8        iny 
F31B  c9 3b     cmp #$3B
F31D  f0 0c     beq $F32B
F31F  a5 06     lda $06
F321  c9 01     cmp #$01
F323  d0 03     bne $F328
F325  4c cf c2  jmp $C2CF
F328  20 1d c5  jsr $C51D
F32B  4c a1 f2  jmp $F2A1
F32E  20 91 f2  jsr $F291
F331  85 66     sta $66
F333  20 91 f2  jsr $F291
F336  c5 66     cmp $66
F338  d0 10     bne $F34A	; to brk opcode (in data)
F33A  c9 40     cmp #$40
F33C  90 0c     bcc $F34A	; to brk opcode (in data)
F33E  c9 5b     cmp #$5B
F340  b0 08     bcs $F34A	; to brk opcode (in data)
F342  38        sec 
F343  20 8e f0  jsr $F08E
F346  20 cb c3  jsr $C3CB
F349  a0 00     ldy #$00
F34B  ad 31 03  lda $0331
F34E  91 52     sta ($52),Y
F350  ad 4c 03  lda $034C
F353  c8        iny 
F354  91 52     sta ($52),Y
F356  a9 00     lda #$00
F358  c8        iny 
F359  91 52     sta ($52),Y
F35B  c8        iny 
F35C  91 52     sta ($52),Y
F35E  d0 36     bne $F396
F360  20 91 f2  jsr $F291
F363  c9 3b     cmp #$3B
F365  f0 04     beq $F36B
F367  c9 0d     cmp #$0D
F369  d0 f5     bne $F360
F36B  ad 31 03  lda $0331
F36E  85 52     sta $52
F370  ad 4c 03  lda $034C
F373  85 53     sta $53
F375  60        rts 
F376  20 7e f3  jsr $F37E
F379  a9 20     lda #$20
F37B  4c 4c ca  jmp $CA4C
F37E  a2 ff     ldx #$FF
F380  48        pha 
F381  4a        lsr A
F382  4a        lsr A
F383  4a        lsr A
F384  4a        lsr A
F385  20 f9 c5  jsr $C5F9
F388  68        pla 
F389  29 0f     and #$0F
F38B  4c f9 c5  jmp $C5F9
F38E  a2 00     ldx #$00
F390  86 00     stx $00
F392  86 64     stx $64
F394  86 65     stx $65
F396  20 91 f2  jsr $F291
F399  c9 3a     cmp #$3A
F39B  f0 91     beq $F32E
F39D  c9 3b     cmp #$3B
F39F  f0 ca     beq $F36B
F3A1  c9 0d     cmp #$0D
F3A3  f0 c6     beq $F36B
F3A5  c9 5c     cmp #$5C
F3A7  f0 b7     beq $F360
F3A9  a0 05     ldy #$05
F3AB  38        sec 
F3AC  69 00     adc #$00
F3AE  0a        asl A
F3AF  0a        asl A
F3B0  0a        asl A
F3B1  0a        asl A
F3B2  26 6a     rol $6A
F3B4  26 69     rol $69
F3B6  88        dey 
F3B7  d0 f8     bne $F3B1
F3B9  e8        inx 
F3BA  e0 03     cpx #$03
F3BC  d0 d8     bne $F396
F3BE  06 6a     asl $6A
F3C0  26 69     rol $69
F3C2  a2 40     ldx #$40
F3C4  a5 69     lda $69
F3C6  dd 54 f1  cmp $F154,X
F3C9  f0 04     beq $F3CF
F3CB  ca        dex 
F3CC  d0 f8     bne $F3C6
F3CE  00        brk 
F3CF  bc 94 f1  ldy $F194,X
F3D2  c4 6a     cpy $6A
F3D4  d0 f5     bne $F3CB
F3D6  bd 10 f2  lda $F210,X	; table of data
F3D9  85 66     sta $66
F3DB  bc 50 f2  ldy $F250,X
F3DE  84 0f     sty $0F
F3E0  66 64     ror $64
F3E2  66 65     ror $65
F3E4  88        dey 
F3E5  d0 f9     bne $F3E0
F3E7  a4 0f     ldy $0F
F3E9  c0 0d     cpy #$0D
F3EB  d0 05     bne $F3F2
F3ED  a2 00     ldx #$00
F3EF  4c 9b f4  jmp $F49B
F3F2  20 91 f2  jsr $F291
F3F5  c9 40     cmp #$40
F3F7  f0 5b     beq $F454
F3F9  c9 28     cmp #$28
F3FB  f0 65     beq $F462
F3FD  a2 01     ldx #$01
F3FF  c9 41     cmp #$41
F401  f0 ec     beq $F3EF
F403  c6 03     dec $03
F405  20 8b c7  jsr $C78B
F408  20 91 f2  jsr $F291
F40B  c9 2c     cmp #$2C
F40D  d0 31     bne $F440
F40F  20 91 f2  jsr $F291
F412  a4 25     ldy $25
F414  f0 15     beq $F42B
F416  a2 09     ldx #$09
F418  c9 58     cmp #$58
F41A  f0 7f     beq $F49B
F41C  ca        dex 
F41D  c9 59     cmp #$59
F41F  d0 79     bne $F49A
F421  a5 0f     lda $0F
F423  c9 09     cmp #$09
F425  d0 74     bne $F49B
F427  a2 0e     ldx #$0E
F429  d0 70     bne $F49B
F42B  a2 04     ldx #$04
F42D  c9 58     cmp #$58
F42F  f0 6a     beq $F49B
F431  c9 59     cmp #$59
F433  d0 65     bne $F49A
F435  ca        dex 
F436  a4 0f     ldy $0F
F438  c0 03     cpy #$03
F43A  b0 5f     bcs $F49B
F43C  a2 08     ldx #$08
F43E  d0 5b     bne $F49B
F440  c6 03     dec $03
F442  a2 02     ldx #$02
F444  a4 0f     ldy $0F
F446  c0 0c     cpy #$0C
F448  f0 51     beq $F49B
F44A  a2 05     ldx #$05
F44C  a5 25     lda $25
F44E  f0 4b     beq $F49B
F450  a2 0c     ldx #$0C
F452  d0 47     bne $F49B
F454  20 8b c7  jsr $C78B
F457  a5 0f     lda $0F
F459  a2 06     ldx #$06
F45B  c9 01     cmp #$01
F45D  f0 3c     beq $F49B
F45F  e8        inx 
F460  d0 39     bne $F49B
F462  20 8b c7  jsr $C78B
F465  20 91 f2  jsr $F291
F468  c9 29     cmp #$29
F46A  f0 16     beq $F482
F46C  c9 2c     cmp #$2C
F46E  d0 2a     bne $F49A
F470  20 91 f2  jsr $F291
F473  c9 58     cmp #$58
F475  d0 23     bne $F49A
F477  20 91 f2  jsr $F291
F47A  c9 29     cmp #$29
F47C  d0 1c     bne $F49A
F47E  a2 0b     ldx #$0B
F480  d0 19     bne $F49B
F482  a2 0d     ldx #$0D
F484  a5 0f     lda $0F
F486  c9 0b     cmp #$0B
F488  f0 11     beq $F49B
F48A  a2 0a     ldx #$0A
F48C  20 91 f2  jsr $F291
F48F  c9 2c     cmp #$2C
F491  d0 07     bne $F49A
F493  20 91 f2  jsr $F291
F496  c9 59     cmp #$59
F498  f0 01     beq $F49B
F49A  00        brk 
F49B  20 60 f3  jsr $F360
F49E  bd d5 f1  lda $F1D5,X	; table of data
F4A1  f0 04     beq $F4A7
F4A3  25 64     and $64
F4A5  d0 07     bne $F4AE
F4A7  bd e4 f1  lda $F1E4,X
F4AA  25 65     and $65
F4AC  f0 ec     beq $F49A
F4AE  18        clc 
F4AF  bd f3 f1  lda $F1F3,X
F4B2  65 66     adc $66
F4B4  85 66     sta $66
F4B6  bd 02 f2  lda $F202,X
F4B9  a2 00     ldx #$00
F4BB  86 04     stx $04
F4BD  a4 16     ldy $16
F4BF  84 67     sty $67
F4C1  a4 25     ldy $25
F4C3  84 68     sty $68
F4C5  c9 0f     cmp #$0F
F4C7  f0 23     beq $F4EC
F4C9  29 0f     and #$0F
F4CB  a8        tay 
F4CC  c8        iny 
F4CD  84 00     sty $00
F4CF  c0 02     cpy #$02
F4D1  d0 04     bne $F4D7
F4D3  a4 68     ldy $68
F4D5  d0 c3     bne $F49A
F4D7  a0 00     ldy #$00
F4D9  b9 66 00  lda $0066,Y
F4DC  91 52     sta ($52),Y
F4DE  c8        iny 
F4DF  ee 31 03  inc $0331
F4E2  d0 03     bne $F4E7
F4E4  ee 4c 03  inc $034C
F4E7  c4 00     cpy $00
F4E9  d0 ee     bne $F4D9
F4EB  60        rts 
F4EC  a9 02     lda #$02
F4EE  85 00     sta $00
F4F0  38        sec 
F4F1  a5 67     lda $67
F4F3  ed 31 03  sbc $0331
F4F6  85 67     sta $67
F4F8  a5 68     lda $68
F4FA  ed 4c 03  sbc $034C
F4FD  85 68     sta $68
F4FF  38        sec 
F500  a5 67     lda $67
F502  e9 02     sbc #$02
F504  85 67     sta $67
F506  a8        tay 
F507  a5 68     lda $68
F509  e9 00     sbc #$00
F50B  f0 1f     beq $F52C
F50D  c9 ff     cmp #$FF
F50F  f0 16     beq $F527
F511  20 d1 f7  jsr $F7D1
F514  .BYTE "OUT OF RANGE:" 0a, 0d
F523  84 67     sty $67
F525  30 b0     bmi $F4D7
F527  98        tya 
F528  30 ad     bmi $F4D7
F52A  10 e5     bpl $F511
F52C  98        tya 
F52D  10 a8     bpl $F4D7
F52F  30 e0     bmi $F511
F531  20 e4 c4  jsr $C4E4
F534  88        dey 
F535  84 52     sty $52
F537  a5 12     lda $12
F539  85 53     sta $53
F53B  98        tya 
F53C  c8        iny 
F53D  91 52     sta ($52),Y
F53F  4c 9b cd  jmp $CD9B
F542  a2 05     ldx #$05
F544  d0 02     bne $F548
F546  a2 0c     ldx #$0C
F548  86 16     stx $16
F54A  e6 04     inc $04
F54C  d0 06     bne $F554
F54E  20 bc c8  jsr $C8BC
F551  20 31 c2  jsr $C231
F554  20 bc c8  jsr $C8BC
F557  20 31 c2  jsr $C231
F55A  20 bc c8  jsr $C8BC
F55D  20 e4 c4  jsr $C4E4
F560  b5 15     lda $15,X
F562  85 5c     sta $5C
F564  b5 24     lda $24,X
F566  85 5d     sta $5D
F568  b5 14     lda $14,X
F56A  85 5a     sta $5A
F56C  b5 23     lda $23,X
F56E  85 5b     sta $5B
F570  a2 00     ldx #$00
F572  86 04     stx $04
F574  a2 03     ldx #$03
F576  bd c1 03  lda $03C1,X
F579  95 52     sta $52,X
F57B  ca        dex 
F57C  10 f8     bpl $F576
F57E  a5 16     lda $16
F580  29 04     and #$04
F582  d0 13     bne $F597
F584  a2 02     ldx #$02
F586  18        clc 
F587  b5 5a     lda $5A,X
F589  75 52     adc $52,X
F58B  95 5a     sta $5A,X
F58D  b5 5b     lda $5B,X
F58F  75 53     adc $53,X
F591  95 5b     sta $5B,X
F593  ca        dex 
F594  ca        dex 
F595  10 ef     bpl $F586
F597  a2 03     ldx #$03
F599  b5 5a     lda $5A,X
F59B  9d c1 03  sta $03C1,X
F59E  ca        dex 
F59F  10 f8     bpl $F599
F5A1  a5 16     lda $16
F5A3  29 03     and #$03
F5A5  f0 0b     beq $F5B2
F5A7  85 5e     sta $5E
F5A9  a5 16     lda $16
F5AB  29 08     and #$08
F5AD  f0 06     beq $F5B5
F5AF  20 78 f6  jsr $F678
F5B2  4c 5b c5  jmp $C55B
F5B5  a2 02     ldx #$02
F5B7  38        sec 
F5B8  b5 5a     lda $5A,X
F5BA  f5 52     sbc $52,X
F5BC  b4 52     ldy $52,X
F5BE  94 5a     sty $5A,X
F5C0  95 52     sta $52,X
F5C2  b4 53     ldy $53,X
F5C4  b5 5b     lda $5B,X
F5C6  f5 53     sbc $53,X
F5C8  94 5b     sty $5B,X
F5CA  95 53     sta $53,X
F5CC  95 56     sta $56,X
F5CE  10 0d     bpl $F5DD
F5D0  a9 00     lda #$00
F5D2  38        sec 
F5D3  f5 52     sbc $52,X
F5D5  95 52     sta $52,X
F5D7  a9 00     lda #$00
F5D9  f5 53     sbc $53,X
F5DB  95 53     sta $53,X
F5DD  ca        dex 
F5DE  ca        dex 
F5DF  10 d6     bpl $F5B7
F5E1  a5 54     lda $54
F5E3  c5 52     cmp $52
F5E5  a5 55     lda $55
F5E7  e5 53     sbc $53
F5E9  90 31     bcc $F61C
F5EB  a9 00     lda #$00
F5ED  e5 54     sbc $54
F5EF  85 57     sta $57
F5F1  a9 00     lda #$00
F5F3  e5 55     sbc $55
F5F5  38        sec 
F5F6  6a        ror A
F5F7  85 59     sta $59
F5F9  66 57     ror $57
F5FB  20 78 f6  jsr $F678
F5FE  a5 5c     lda $5C
F600  cd c3 03  cmp $03C3
F603  d0 0a     bne $F60F
F605  a5 5d     lda $5D
F607  cd c4 03  cmp $03C4
F60A  d0 03     bne $F60F
F60C  4c 5b c5  jmp $C55B
F60F  20 55 f6  jsr $F655
F612  a5 59     lda $59
F614  30 e5     bmi $F5FB
F616  20 44 f6  jsr $F644
F619  4c fb f5  jmp $F5FB
F61C  a5 53     lda $53
F61E  4a        lsr A
F61F  85 59     sta $59
F621  a5 52     lda $52
F623  6a        ror A
F624  85 57     sta $57
F626  20 78 f6  jsr $F678
F629  a5 5a     lda $5A
F62B  cd c1 03  cmp $03C1
F62E  d0 07     bne $F637
F630  a5 5b     lda $5B
F632  cd c2 03  cmp $03C2
F635  f0 d5     beq $F60C
F637  20 44 f6  jsr $F644
F63A  a5 59     lda $59
F63C  10 e8     bpl $F626
F63E  20 55 f6  jsr $F655
F641  4c 26 f6  jmp $F626
F644  38        sec 
F645  a5 57     lda $57
F647  e5 54     sbc $54
F649  85 57     sta $57
F64B  a5 59     lda $59
F64D  e5 55     sbc $55
F64F  85 59     sta $59
F651  a2 00     ldx #$00
F653  f0 0f     beq $F664
F655  18        clc 
F656  a5 57     lda $57
F658  65 52     adc $52
F65A  85 57     sta $57
F65C  a5 59     lda $59
F65E  65 53     adc $53
F660  85 59     sta $59
F662  a2 02     ldx #$02
F664  b5 56     lda $56,X
F666  10 09     bpl $F671
F668  b5 5a     lda $5A,X
F66A  d0 02     bne $F66E
F66C  d6 5b     dec $5B,X
F66E  d6 5a     dec $5A,X
F670  60        rts 
F671  f6 5a     inc $5A,X
F673  d0 fb     bne $F670
F675  f6 5b     inc $5B,X
F677  60        rts 
F678  6c fe 03  jmp ($03FE)
F67B  20 c8 c3  jsr $C3C8
F67E  a0 00     ldy #$00
F680  a5 52     lda $52
F682  f0 3e     beq $F6C2
F684  c9 05     cmp #$05
F686  90 02     bcc $F68A
F688  a9 04     lda #$04
F68A  a2 80     ldx #$80
F68C  86 54     stx $54
F68E  84 53     sty $53
F690  85 52     sta $52
F692  aa        tax 
F693  bd ce f6  lda $F6CE,X
F696  a6 12     ldx $12
F698  10 04     bpl $F69E
F69A  c5 12     cmp $12
F69C  b0 e1     bcs $F67F
F69E  aa        tax 
F69F  98        tya 
F6A0  91 53     sta ($53),Y
F6A2  88        dey 
F6A3  d0 fb     bne $F6A0
F6A5  e6 54     inc $54
F6A7  e4 54     cpx $54
F6A9  d0 f5     bne $F6A0
F6AB  a4 52     ldy $52
F6AD  b9 d8 f6  lda $F6D8,Y
F6B0  8d ff 03  sta $03FF
F6B3  b9 d3 f6  lda $F6D3,Y
F6B6  8d fe 03  sta $03FE
F6B9  b9 dd f6  lda $F6DD,Y
F6BC  8d 00 b0  sta $B000
F6BF  4c 58 c5  jmp $C558
F6C2  a9 40     lda #$40	; fill with 
F6C4  99 00 80  sta $8000,Y	; first  256 bytes
F6C7  99 00 81  sta $8100,Y	; second 256 bytes
F6CA  88        dey 
F6CB  d0 f7     bne $F6C4
F6CD  f0 dc     beq $F6AB
; one pointer starts to F6CE, one byte before the start of this table
; tables of data
F6CF	.byte	84, 86, 8c, 98, e2, f7, 
		f0, dc, 84, 86, 8c, 98, 
F6D3	.byte	e2, 3b, 54, 6d, aa, 
F6D8	.byte	f6, f7, f7, f7, f7, 
F6DD	.byte	00, 30, 70, b0, f0, 

Plot mode 0

F6E2  a5 5b     lda V5B_plot_x_msb
F6E4  05 5d     ora V5D_plot_y_msb
F6E6  d0 52     bne $F73A_return_from_plotting	; return if not equal
F6E8  a5 5a     lda V5A_plot_x_lsb
F6EA  c9 40     cmp #$40
F6EC  b0 4c     bcs $F73A_return_from_plotting
F6EE  4a        lsr A
F6EF  85 5f     sta $5F
F6F1  a9 2f     lda #$2F
F6F3  38        sec 
F6F4  e5 5c     sbc V5C_plot_y_lsb
F6F6  c9 30     cmp #$30
F6F8  b0 40     bcs $F73A_return_from_plotting	; return if carry set
F6FA  a2 ff     ldx #$FF
F6FC  38        sec 
F6FD  e8        inx 
F6FE  e9 03     sbc #$03
F700  b0 fb     bcs $F6FD
F702  69 03     adc #$03
F704  85 61     sta $61
F706  8a        txa 
F707  0a        asl A
F708  0a        asl A
F709  0a        asl A
F70A  0a        asl A
F70B  0a        asl A
F70C  05 5f     ora $5F
F70E  85 5f     sta $5F
F710  a9 80     lda #$80
F712  69 00     adc #$00
F714  85 60     sta $60
F716  a5 5a     lda V5A_plot_x_lsb
F718  4a        lsr A
F719  a5 61     lda $61
F71B  2a        rol A
F71C  a8        tay 
F71D  b9 cb f7  lda $F7CB,Y
F720  a0 00     ldy #$00
F722  a6 5e     ldx V5E_plot_n
F724  ca        dex 
F725  f0 0f     beq $F736
F727  ca        dex 
F728  f0 07     beq $F731
F72A  49 ff     eor #$FF	; this clears pixels
F72C  31 5f     and ($5F),Y
F72E  91 5f     sta ($5F),Y
F730  60        rts 

F731  51 5f     eor ($5F),Y	; EOR inverts pixels
F733  91 5f     sta ($5F),Y
F735  60        rts 

F736  11 5f     ora ($5F),Y	; OR to set pixels
F738  91 5f     sta ($5F),Y
; F73A_return_from_plotting:
F73A  60        rts 

F73B_Plot_mode_1:

F73B  a5 5b     lda V5B_plot_x_msb
F73D  05 5d     ora V5D_plot_y_msb
F73F  d0 f9     bne $F73A_return_from_plotting	; return if not equal
F741  a5 5a     lda V5A_plot_x_lsb
F743  30 f5     bmi $F73A_return_from_plotting	; return if minus
F745  4a        lsr A	; divide by 8
F746  4a        lsr A
F747  4a        lsr A
F748  85 5f     sta $5F
F74A  a9 3f     lda #$3F
F74C  38        sec 
F74D  e5 5c     sbc V5C_plot_y_lsb
F74F  c9 40     cmp #$40
F751  90 32     bcc $F785
F753  60        rts 

F754_Plot_mode_2:

F754  a5 5b     lda V5B_plot_x_msb
F756  05 5d     ora V5D_plot_y_msb
F758  d0 e0     bne $F73A_return_from_plotting	; return if not equal
F75A  a5 5a     lda V5A_plot_x_lsb
F75C  30 dc     bmi $F73A_return_from_plotting	; return if minus
F75E  4a        lsr A
F75F  4a        lsr A
F760  4a        lsr A
F761  85 5f     sta $5F
F763  a9 5f     lda #$5F
F765  38        sec 
F766  e5 5c     sbc V5C_plot_y_lsb
F768  c9 60     cmp #$60
F76A  90 19     bcc $F785
F76C  60        rts 

F76D_Plot_mode_3:

F76D  a5 5b     lda V5B_plot_x_msb
F76F  05 5d     ora V5D_plot_y_msb
F771  d0 c7     bne $F73A_return_from_plotting	; return if not equal
F773  a5 5a     lda V5A_plot_x_lsb
F775  30 c3     bmi $F73A_return_from_plotting	; return if minus
F777  4a        lsr A
F778  4a        lsr A
F779  4a        lsr A
F77A  85 5f     sta $5F
F77C  a9 bf     lda #$BF
F77E  38        sec 
F77F  e5 5c     sbc V5C_plot_y_lsb
F781  c9 c0     cmp #$C0
F783  b0 b5     bcs $F73A_return_from_plotting	; return if carry set
F785  a0 00     ldy #$00
F787  84 60     sty $60
F789  0a        asl A
F78A  26 60     rol $60
F78C  0a        asl A
F78D  26 60     rol $60
F78F  0a        asl A
F790  26 60     rol $60
F792  0a        asl A
F793  26 60     rol $60
F795  65 5f     adc $5F
F797  85 5f     sta $5F
F799  a5 60     lda $60
F79B  69 80     adc #$80
F79D  85 60     sta $60
F79F  a5 5a     lda V5A_plot_x_lsb
F7A1  29 07     and #$07
F7A3  a8        tay 
F7A4  b9 c9 f7  lda $F7C9_one_bit_mask_array,Y
F7A7  4c 20 f7  jmp $F720

F7AA_Plot_mode_4:

	; . See block zero RAM
F7AA  a5 5b     lda V5B_plot_x_msb
F7AC  05 5d     ora V5D_plot_y_msb
F7AE  d0 bc     bne $F76C	; return if not
F7B0  a5 5a     lda $5A		; take value
F7B2  4a        lsr A		; divide by 8 to get number of bytes
F7B3  4a        lsr A
F7B4  4a        lsr A
F7B5  85 5f     sta $5F
F7B7  a9 bf     lda #$BF	; 191
F7B9  38        sec 
F7BA  e5 5c     sbc V5C_plot_y_lsb
F7BC  c9 c0     cmp #192	; compare with lines per 256x192 graphic screen
F7BE  b0 ac     bcs $F76C	; return if carry set, else repeat
F7C0  a0 00     ldy #$00
F7C2  84 60     sty $60
F7C4  0a        asl A
F7C5  26 60     rol $60
F7C7  10 c0     bpl $F789	; would fall-through to data table, so branches always?

; table of data
F7C9_one_bit_mask_array
F7C9	.byte	80,	; 10000000
		40	; 01000000
F7CB	.BYTE	20,	; 00100000
		10,	; 00010000
		08,	; 00001000
		04,	; 00000100
		02,	; 00000010
		01	; 00000001

; F7D1 Output ASCII string from the calling routine following 'JSR F7D1'.
; Returns calling routine at first byte with bit 7 = 1. Uses A,X,Y.

Print_ASCII_string:

F7D1  68        pla		; pull string address from stack
F7D2  85 e8     sta $E8		; and store in pointer at $E8
F7D4  68        pla 
F7D5  85 e9     sta $E9
F7D7  a0 00     ldy #$00	; clear index
F7D9  e6 e8     inc $E8		; inc lsb
F7DB  d0 02     bne $F7DF	
F7DD  e6 e9     inc $E9		; inc msb
F7DF  b1 e8     lda ($E8),Y	; if character is > 7F,
F7E1  30 06     bmi $F7E9	; skip to end
F7E3  20 f4 ff  jsr $FFF4_OSWRCH	; call write character 
F7E6  4c d7 f7  jmp $F7D7		; do again
F7E9  6c e8 00  jmp ($00E8)	; vector to

; Data from $F7EC to $FF2A (1855 bytes)
; Data from $F7EC to $FB82 (919 bytes)
F7EC  .BYTE a2, d4, 20, f1, f7, b5, 01, 20, 02, f8  ; .. .... ..
F7F6  .BYTE e8, e8, b5, fe, 20, 02, f8 
F7FD  a9 20     lda #SP
F7FF  4c f4 ff  jmp $FFF4_OSWRCH