PMFS 136, the Master Compact pointer and mouse driver

Updated 10 Nov 2026

← All Acorn Master Compact Mouse Driver (PMFS) versions

PMFS 136

Sideways ROM header — language-entry slot (3 bytes)

MOS dispatches JMP &8000 on language startup.

Service-only ROM (rom_type bit 6 clear). Per-byte detail is inline.

Reason code in A on entry:

A Meaning
0 No language available — MOS calling Tube ROM
1 Normal startup
2 Request next byte of softkey expansion (Electron)
3 Request length of softkey expansion (Electron)
8000 .language_entry
EQUB &00 ; no-language sentinel (rom_type bit 6 clear)
8001 EQUB &00, &00 ; unused padding

Service-entry slot (3 bytes)

MOS calls JMP &8003 for service-call dispatch — unrecognised * commands, OSWORDs, OSBYTEs, *HELP, filing-system init / select, paged-ROM scans, and many other events. The reason code arrives in A.

8003 .service_entry
JMP service_handler ; Service entry: every service call comes here
8006 .rom_type
; ROM type byte
; ┌─────┬───────┬─────────────────────────────┐
; │ Bit │ Value │ Meaning │
; ├─────┼───────┼─────────────────────────────┤
; │ 7 │ 1 │ Service entry present │
; │ 6 │ 0 │ No language entry │
; │ 5 │ 0 │ No Tube relocation │
; │ 4 │ 0 │ No Electron firmkey │
; │ 3-0 │ 0010 │ Processor: 6502 (non-BASIC) │
; └─────┴───────┴─────────────────────────────┘
EQUB %10000010 ; ROM type
8007 .copyright_offset
EQUB copyright - language_entry ; Offset of NUL preceding copyright (= &11 → copyright at &8011)
8008 .binary_version
EQUB &01 ; Binary version: &01 (informational, not used by MOS)
8009 .title
EQUS "PMFS"
800D EQUB &00 ; NUL terminator
800E .version
EQUS "136"
8011 .copyright
EQUB &00 ; NUL preceding copyright string
8012 .copyright_string
EQUS "(C)1986 PMF"
801D EQUB &00 ; NUL terminator

Service call handler

Entered through the service entry for every service call, with the reason code in A and the ROM number in X.

On every call it first sets the ROM's entry in rom_workspace_table to &91, so that its private workspace is taken to be page &91 of its own bank; the drawing and workspace routines find their pages from that entry.

Calls handled:

A Call Action
&04 Unrecognised star command Decode and run a PMFS command (service_command)
&07 Unrecognised OSBYTE Claim OSBYTE &A3 with X=&F3: set the desktop colours
&15 Polling interrupt Move the pointer, redraw it, read the buttons
&27 Reset Clear the driver state

Calls &04 and &15 are dispatched by dispatch_service; the others are handled here. Every exit goes through return_from_service, which puts the ROM number back in X.

The reset call clears driver_on, pointer_shown, button_pending and device_mode with direct stores, without first exchanging the workspace (see exchange_workspace). device_mode lies outside the exchanged area and is cleared, but the other three are in it, so the stores reach the copy at &9000, not the copy at &9440 that the driver uses on its next call.

On EntryAservice call number
Xthis ROM's number
Yservice call parameter
On ExitA0 if the call was claimed, otherwise preserved
Xthis ROM's number
801E .service_handler←1← 8003 JMP
PHA ; Save the service call number
801F LDA #pmfs_workspace_page ; Private workspace page &91, in this bank...
8021 STA rom_workspace_table,x ; ...goes in this ROM's workspace table entry
8024 PLA ; Recover the service call number
8025 JSR dispatch_service ; Handle a command (&04) or a poll (&15)
8028 PHA ; Save the (possibly claimed) call number again
8029 CMP #service_reset ; Reset?
802B BEQ reset_driver_state ; Yes: clear the driver state
802D CMP #service_unrecognised_osbyte ; Unrecognised OSBYTE?
802F BNE return_from_service ; No: return the call as it is
8031 PHX ; Keep X...
8032 PHY ; ...and Y for the OSBYTE caller
8033 LDA osbyte_a ; Is the OSBYTE number &A3...
8035 CMP #osbyte_application ; ...(application OSBYTE)?
8037 BNE not_pmfs_osbyte ; No: not ours
8039 LDA osbyte_x ; And is X &F3...
803B CMP #osbyte_a3_pmfs_colours ; ...the PMFS sub-call?
803D BNE not_pmfs_osbyte ; No: not ours
803F JSR set_desktop_colours ; Set the desktop colours from Y
8042 LDA #0 ; A=0: claim the call
8044 PLY ; Restore Y...
8045 PLX ; ...and X
8046 BRA return_from_service ; Return the call claimed
8048 .not_pmfs_osbyte←2← 8037 BNE← 803D BNE
LDA #service_unrecognised_osbyte ; A=7: leave the OSBYTE call unclaimed
804A PLY ; Restore Y...
804B PLX ; ...and X
804C BRA return_from_service ; Return the call unclaimed
804E .reset_driver_state←1← 802B BEQ
STZ driver_on ; Driver off, in the copy at &9000 (see banner)
8051 STZ pointer_shown ; Pointer not shown, in the copy at &9000
8054 STZ button_pending ; No button change pending, in the copy at &9000
8057 STZ device_mode ; Device mode back to mouse
805A BRA return_from_service ; Return the call unclaimed
805C .return_from_service←4← 802F BNE← 8046 BRA← 804C BRA← 805A BRA
LDX romsel_copy ; Restore X: this ROM's number
805E PLA ; A = the call number, or 0 if claimed
805F RTS ; Return to the MOS
8060 EQUB &EA ; Unused (a NOP opcode)

Find the screen address of the top left of the pointer

Turn the top left corner of the pointer image, pointer_left and pointer_top in graphics units, into a screen address and a shift.

Graphics Y runs up the screen from 0 to 1023 in steps of 4 per pixel row, so pointer_top / 4 is a pixel row counted up from the bottom, and that / 8 is a character row counted up from the bottom. The character row indexes a table of row start addresses for the screen format (mode012_row_addr or mode45_row_addr), which counts up from the bottom row too and has two extra entries above the top of the screen. The pixel row within the character row is inverted (EOR 7) because screen rows run downwards.

The byte column is pointer_left / 16 in MODEs 0-2 and pointer_left / 32 in MODEs 4 and 5, which is a screen offset of 8 bytes per column. A negative pointer_left (the pointer partly off the left edge) is handled without signed arithmetic: 1280 is added, which moves it to the right-hand end of the row below, and the row is moved up one to compensate.

The shift is which quarter of a screen byte the image starts at, 0-3, used to choose one of the four shifted copies of the image.

Rows above the top of the screen (pointer_top of 1024 or more) take the two extra table entries. Their addresses are below the start of screen memory, so the drawing routines skip them.

On EntryPOINTER_LEFTX of the left edge of the image
POINTER_TOPY of the top edge of the image
On ExitZP_SCREEN_PTRscreen address of the top left byte
Xshift, 0-3 (which shifted copy of the image to use)
POINTER_TOPpixel row (Y / 4), possibly inverted
Acorrupted
Ypreserved
8061 .calc_pointer_screen_address←1← 847E JSR
LDA pointer_top_hi ; Pixel row = pointer_top / 4: take the high byte
8064 STA zp_screen_ptr ; ...into a scratch byte
8066 LDA pointer_top ; and the low byte
8069 LSR zp_screen_ptr ; Divide by 2...
806B ROR ; ...through both bytes
806C LSR zp_screen_ptr ; and by 2 again
806E ROR ; ...(carry bit 8 of the row stays in zp_screen_ptr)
806F STA pointer_top ; Keep the pixel row, 0-255 on the screen
8072 LSR ; Character row = pixel row / 8...
8073 LSR ; ...
8074 LSR ; ...counted up from the bottom
8075 TAX ; X = character row, indexing the row tables
8076 LDA pointer_left_hi ; Is the image's left edge negative?
8079 BPL check_above_screen ; No
807B INX ; Yes: one row up, to undo the +1280 applied below
807C .check_above_screen←1← 8079 BPL
LDA zp_screen_ptr ; Is the pixel row 256 or more (above the screen)?
807E BEQ look_up_row_address ; No
8080 TXA ; Yes: use the extra table entries above the top...
8081 CLC ; ...
8082 ADC #&20 ; ...32 rows up
8084 TAX ; ...
8085 LDA pointer_top ; and invert the pixel row within the character
8088 EOR #7 ; row, so that the EOR below cancels it out
808A STA pointer_top ; ...
808D .look_up_row_address←1← 807E BEQ
LDA screen_format ; Which screen format?
8090 CMP #3 ; MODEs 4 and 5 (formats 3 and 4)?
8092 BCS look_up_mode45_row_address ; Yes: use the 320-byte row table
8094 LDA mode012_row_addr_hi,x ; MODEs 0-2: row address high byte...
8097 STA zp_screen_ptr_hi ; ...
8099 LDA mode012_row_addr_lo,x ; and low byte, from the 640-byte row table
809C STA zp_screen_ptr ; ...
809E BRA add_column_offset ; Go and add the column
80A0 .look_up_mode45_row_address←1← 8092 BCS
LDA mode45_row_addr_hi,x ; MODEs 4 and 5: row address high byte...
80A3 STA zp_screen_ptr_hi ; ...
80A5 LDA mode45_row_addr_lo,x ; and low byte
80A8 STA zp_screen_ptr ; ...
80AA .add_column_offset←1← 809E BRA
LDA pointer_left_hi ; High byte of the left edge
80AD BPL store_column_offset_hi ; Positive: use it as it is
80AF CLC ; Negative: add 1280 (&500), wrapping to the right
80B0 ADC #5 ; end of the row below
80B2 .store_column_offset_hi←1← 80AD BPL
STA zp_temp ; Keep the high byte
80B4 LDA pointer_left ; Low byte of the left edge
80B7 LDX screen_format ; Which screen format?
80BA CPX #3 ; MODEs 4 and 5?
80BC BCC halve_column_offset ; No: 16 units a byte, so offset = X / 2
80BE LSR zp_temp ; Yes: 32 units a byte, so offset = X / 4:
80C0 ROR ; one extra halving
80C1 .halve_column_offset←1← 80BC BCC
LSR zp_temp ; Halve the left edge...
80C3 ROR ; ...
80C4 AND #&f8 ; Round down to a whole byte column (8 bytes each)
80C6 CLC ; Add the column offset...
80C7 ADC zp_screen_ptr ; ...to the row address
80C9 STA zp_screen_ptr ; ...
80CB LDA zp_temp ; and the high byte
80CD ADC zp_screen_ptr_hi ; ...
80CF STA zp_screen_ptr_hi ; ...
80D1 LDA pointer_top ; Pixel row within the character row...
80D4 AND #7 ; ...
80D6 EOR #7 ; ...counted down from the top of it
80D8 ORA zp_screen_ptr ; is the byte within the character cell
80DA STA zp_screen_ptr ; ...
80DC LDA pointer_left ; Left edge again, for the shift
80DF LDX screen_format ; Which screen format?
80E2 CPX #3 ; MODEs 4 and 5?
80E4 BCC calc_shift ; No: shift = (X / 4) MOD 4
80E6 LSR ; Yes: shift = (X / 8) MOD 4
80E7 .calc_shift←1← 80E4 BCC
LSR ; Quarter-byte steps...
80E8 LSR ; ...
80E9 AND #3 ; ...within the byte
80EB TAX ; X = shift, 0-3
80EC RTS ; Return

*SETPAL: set the desktop colours

Send VDU 19,0,c0,0,0,0 and VDU 19,1,c1,0,0,0, setting logical colours 0 and 1 to the physical colours in desktop_colours, which OSBYTE &A3,&F3 chooses. The command takes no arguments, and it works whether or not the driver is on.

On ExitAcorrupted
80ED .cmd_setpal
LDA #vdu_set_palette ; VDU 19: define a logical colour...
80EF JSR oswrch ; ...
80F2 LDA #0 ; logical colour 0...
80F4 JSR oswrch ; ...
80F7 LDA desktop_colours ; physical colour: desktop colour 0...
80FA JSR oswrch ; ...
80FD LDA #0 ; and three zero bytes...
80FF JSR oswrch ; ...
8102 JSR oswrch ; ...
8105 JSR oswrch ; ...
8108 LDA #vdu_set_palette ; VDU 19 again...
810A JSR oswrch ; ...
810D LDA #1 ; logical colour 1...
810F JSR oswrch ; ...
8112 LDA desktop_colour_1 ; physical colour: desktop colour 1...
8115 JSR oswrch ; ...
8118 LDA #0 ; and three zero bytes...
811A JSR oswrch ; ...
811D JSR oswrch ; ...
8120 JSR oswrch ; ...
8123 RTS ; Return

Set the default desktop colours

Set desktop colour 0 to 6 (cyan) and desktop colour 1 to 4 (blue). Reached from set_desktop_colours when bit 7 of Y is set.

8124 .reset_desktop_colours←1← 814A BCS
LDA #6 ; Colour 0 = 6, cyan
8126 STA desktop_colours ; ...
8129 LDA #4 ; Colour 1 = 4, blue
812B STA desktop_colour_1 ; ...
812E RTS ; Return

Step a desktop colour to the next physical colour

Advance the desktop colour chosen by bit 3 of Y to the next physical colour, 0-7, wrapping round, and skipping the colour the other desktop colour has, so that the two never match. Reached from set_desktop_colours when bit 6 of Y is set.

On EntryYbit 3: which colour to step (0 or 1)
812F .step_desktop_colour←1← 814D BCS
TYA ; Bit 3 of Y...
8130 LSR ; ...
8131 LSR ; ...
8132 LSR ; ...
8133 AND #1 ; ...selects the colour to step
8135 TAX ; X = that colour
8136 EOR #1 ; Y = the other one
8138 TAY ; ...
8139 LDA desktop_colours,x ; Current physical colour
813C .try_next_colour←1← 8142 BEQ
INC ; Next physical colour...
813D AND #7 ; ...modulo 8
813F CMP desktop_colours,y ; Same as the other desktop colour?
8142 BEQ try_next_colour ; Yes: skip it
8144 STA desktop_colours,x ; Store the new colour
8147 RTS ; Return

OSBYTE &A3,&F3: set the desktop colours

Handle OSBYTE &A3 with X=&F3, according to Y:

Y Effect
bit 7 set Reset both colours to the defaults (6 and 4)
bit 6 set Step colour (Y bit 3) to the next physical colour
otherwise Set colour (Y bit 3) to physical colour Y AND 7

The colours are only stored; *SETPAL sends them to the VDU. service_handler returns X and Y to the OSBYTE caller unchanged.

On EntryYthe OSBYTE's Y parameter
On ExitAcorrupted
Xcorrupted
Ycorrupted
8148 .set_desktop_colours←1← 803F JSR
TYA ; Bit 7 of Y...
8149 ROL ; ...into carry
814A BCS reset_desktop_colours ; Set: reset both colours
814C ROL ; Bit 6 into carry
814D BCS step_desktop_colour ; Set: step a colour
814F TYA ; Bit 3 of Y...
8150 LSR ; ...
8151 LSR ; ...
8152 LSR ; ...
8153 AND #1 ; ...selects the colour
8155 TAX ; ...
8156 TYA ; Bits 0-2...
8157 AND #7 ; ...are the physical colour
8159 STA desktop_colours,x ; Store it
815C RTS ; Return

Handle the polling and star command service calls

Called from service_handler with the service call number in A. On a poll (&15), move the pointer for the joystick or keys, then redraw it and read the buttons; the call is not claimed. On an unrecognised star command (&04), decode it. Other calls return at once.

On EntryAservice call number
Yfor &04, the offset of the command at (os_text_ptr)
On ExitA0 if a command was run, otherwise preserved
Xpreserved
Ypreserved
815D .dispatch_service←1← 8025 JSR
CMP #service_polling_interrupt ; Polling interrupt?
815F BNE service_command ; No
8161 JSR poll_move_pointer ; Yes: move the pointer for joystick or keys
8164 JMP poll_redraw_and_buttons ; then redraw and read the buttons, and return
fall through ↓

Decode a star command

Service call &04. Match the command at (os_text_ptr),Y against command_table, ignoring case. A name may be abbreviated with a full stop after at least one letter; otherwise the name must be followed by a space or the end of the line. The first table entry that matches is run; if the whole name matched but is followed by anything else, the command is left for other ROMs without trying further entries.

On a match, cmd_ptr is moved past the name and any spaces or commas, interrupts are disabled, the driver's workspace is brought in (enter_driver), the handler is called with Y=0, and the workspace is put back (leave_driver). The call is then claimed. The handler runs with interrupts disabled throughout; the caller's flags are restored on return.

When moving cmd_ptr past the name, a carry out of the low byte increments the low byte instead of the high byte, so a command whose arguments start on a later page than its name is read from the wrong place.

8167 .service_command←1← 815F BNE
CMP #service_unrecognised_command ; Unrecognised star command?
8169 BNE return_from_dispatch ; No: return
816B PHP ; Save the flags
816C PHA ; and the registers
816D PHX ; ...
816E PHY ; ...
816F TYA ; cmd_ptr = os_text_ptr + Y,
8170 CLC ; the start of the command
8171 ADC os_text_ptr ; ...
8173 STA cmd_ptr ; ...
8175 LDA os_text_ptr_hi ; ...
8177 ADC #0 ; ...
8179 STA cmd_ptr_hi ; ...
817B LDY #0 ; From its first character
817D JSR skip_separators ; skip leading spaces and commas
8180 LDX #0 ; X = offset into command_table
8182 STY cmd_start_offset ; Remember where the name starts
8185 .match_command_char←2← 81A7 BPL← 81B0 BNE
LDA (cmd_ptr),y ; Next character of the command...
8187 AND #&df ; ...in upper case
8189 CMP command_table,x ; Same as the table?
818C BEQ next_command_char ; Yes: compare the next one
818E LDA (cmd_ptr),y ; No: is it a full stop (an abbreviation)?
8190 CMP #&2e ; ...
8192 BEQ command_abbreviated ; Yes: accept the name so far
8194 LDA command_table,x ; Has the table name ended (address byte)?
8197 BMI command_name_matched ; Yes: the whole name matched
8199 LDY cmd_start_offset ; No match: back to the start of the command
819C .skip_to_next_command←1← 81A0 BPL
INX ; Skip the rest of this table name...
819D LDA command_table,x ; ...up to its address byte
81A0 BPL skip_to_next_command ; ...
81A2 INX ; and the two address bytes
81A3 INX ; ...
81A4 LDA command_table,x ; End of the table (&FF)?
81A7 BPL match_command_char ; No: try this entry

Restore the registers and flags and return

Pull Y, X, A and the flags, pushed in that order's reverse by the caller, and return. Used to leave service_command without claiming the call, and as the common exit of irq_handler, poll_move_pointer and poll_redraw_and_buttons.

On ExitArestored
Xrestored
Yrestored
FLAGSrestored
81A9 .restore_registers_and_return←4← 81BE BNE← 8841 JMP← 88D6 JMP← 8A2A JMP
PLY ; Restore Y
81AA PLX ; X
81AB PLA ; A
81AC PLP ; and the flags
81AD .return_from_dispatch←1← 8169 BNE
RTS ; Return
81AE .next_command_char←1← 818C BEQ
INX ; Next table character
81AF INY ; and next command character
81B0 BNE match_command_char ; Always taken (Y does not wrap)
81B2 .command_abbreviated←1← 8192 BEQ
INY ; Step past the full stop
81B3 BNE find_handler_address ; Always taken: no terminator check after a stop
81B5 .command_name_matched←1← 8197 BMI
DEX ; Back onto the last name character
81B6 LDA (cmd_ptr),y ; The name must be followed by...
81B8 CMP #' ' ; ...a space
81BA BEQ find_handler_address ; ...
81BC CMP #key_return ; ...or the end of the line
81BE BNE restore_registers_and_return ; Neither: not a PMFS command after all
81C0 .find_handler_address←3← 81B3 BNE← 81BA BEQ← 81C4 BPL
INX ; Find the address bytes after the name
81C1 LDA command_table,x ; ...
81C4 BPL find_handler_address ; ...
81C6 CPX #&4b ; Index &4B: no entry's address is here, so this
81C8 BEQ advance_to_arguments ; never branches
81CA JSR skip_separators ; Skip spaces and commas before the arguments
81CD .advance_to_arguments←1← 81C8 BEQ
TYA ; cmd_ptr += Y: point at the arguments
81CE CLC ; ...
81CF ADC cmd_ptr ; ...
81D1 STA cmd_ptr ; ...
81D3 BCC call_command_handler ; ...
81D5 INC cmd_ptr ; Carry: increments the low byte, not the high byte
81D7 .call_command_handler←1← 81D3 BCC
LDA command_table,x ; Handler address, high byte first...
81DA STA cmd_handler_ptr_hi ; ...
81DC LDA command_table + 1,x ; then low byte
81DF STA cmd_handler_ptr ; ...
81E1 SEI ; Interrupts off while the workspace is in use
81E2 JSR enter_driver ; Bring in the workspace, save zero page
81E5 JSR jump_to_command_handler ; Run the command
81E8 JSR leave_driver ; Put back zero page and the workspace
81EB PLY ; Restore Y
81EC PLX ; and X
81ED PLA ; Discard the saved call number
81EE LDA #0 ; A=0: claim the call
81F0 PLP ; Restore the caller's flags
81F1 RTS ; Return

Jump to the command handler

Called by service_command so that the handler's RTS returns to it.

81F2 .jump_to_command_handler←1← 81E5 JSR
JMP (cmd_handler_ptr) ; Jump to the handler at cmd_handler_ptr

Star command table

Each entry is a command name in upper case, followed by the address of its handler, high byte first. The high byte has bit 7 set, which ends the name; the table ends with &FF. *MOUSE and *TRACKERBALL share a handler. TSET's low address byte happens to be &48, the code for "H".

Command Handler
*KEYS cmd_keys
*DIGITAL cmd_digital
*JOYSTICK cmd_joystick
*MOUSE cmd_mouse
*POINTER cmd_pointer
*TMAX cmd_tmax
*TRACKERBALL cmd_mouse
*TSET cmd_tset
*SETPAL cmd_setpal

Entries are tried in order, so an abbreviation takes the first command it fits: *T. is *TMAX and *M. is *MOUSE.

81F5 .command_table←1Used as index base by← 8189 CMP
EQUS "KEYS" ; *KEYS
81F9 EQUB >(cmd_keys) ; Handler cmd_keys, high byte (bit 7 ends the name)
81FA EQUB <(cmd_keys) ; and low byte
81FB EQUS "DIGITAL" ; *DIGITAL
8202 EQUB >(cmd_digital) ; Handler cmd_digital, high byte (bit 7 ends the name)
8203 EQUB <(cmd_digital) ; and low byte
8204 EQUS "JOYSTICK" ; *JOYSTICK
820C EQUB >(cmd_joystick) ; Handler cmd_joystick, high byte (bit 7 ends the name)
820D EQUB <(cmd_joystick) ; and low byte
820E EQUS "MOUSE" ; *MOUSE
8213 EQUB >(cmd_mouse) ; Handler cmd_mouse, high byte (bit 7 ends the name)
8214 EQUB <(cmd_mouse) ; and low byte
8215 EQUS "POINTER" ; *POINTER
821C EQUB >(cmd_pointer) ; Handler cmd_pointer, high byte (bit 7 ends the name)
821D EQUB <(cmd_pointer) ; and low byte
821E EQUS "TMAX" ; *TMAX
8222 EQUB >(cmd_tmax) ; Handler cmd_tmax, high byte (bit 7 ends the name)
8223 EQUB <(cmd_tmax) ; and low byte
8224 EQUS "TRACKERBALL" ; *TRACKERBALL
822F EQUB >(cmd_mouse) ; Handler cmd_mouse, high byte (bit 7 ends the name)
8230 EQUB <(cmd_mouse) ; and low byte
8231 EQUS "TSET" ; *TSET
8235 EQUB >(cmd_tset) ; Handler cmd_tset, high byte (bit 7 ends the name)
8236 EQUB <(cmd_tset) ; and low byte
8237 EQUS "SETPAL" ; *SETPAL
823D EQUB >(cmd_setpal) ; Handler cmd_setpal, high byte (bit 7 ends the name)
823E EQUB <(cmd_setpal) ; and low byte
823F EQUB &FF ; End of the table

Point Y at the first argument

Set Y=0, the first character at cmd_ptr, which service_command has left pointing at the command's arguments.

On ExitY0
8240 .reset_argument_index←4← 82C3 JSR← 83A4 JSR← 8C0B JSR← 8C48 JSR
LDY #0 ; Offset 0 from cmd_ptr
8242 RTS ; Return

Check that a character is a decimal digit

Return if A is "0"-"9"; otherwise raise error &DC, "Bad number".

On EntryAcharacter
On ExitApreserved
FLAGSC set
8243 .check_digit←1← 8BB7 JSR
CMP #'0' ; Below "0"?
8245 BCC bad_number_error ; Yes: bad number
8247 CMP #':' ; Above "9"?
8249 BCS bad_number_error ; Yes: bad number
824B RTS ; A digit: return

Error &DC, "Bad number"

A BRK error block, raised by falling into it from check_digit, or by jumping to it from *TMAX and *TSET.

824C .bad_number_error←3← 8245 BCC← 8249 BCS← 8C45 JMP
BRK ; BRK: raise an error
824D EQUB err_bad_number ; Error number
824E EQUS "Bad number" ; Error message
8258 EQUB &00 ; End of the message

Skip spaces and commas

Advance Y past any spaces and commas at (cmd_ptr),Y.

On EntryYoffset into the command line
On ExitYoffset of the next other character
Athat character
8259 .skip_separators←5← 817D JSR← 81CA JSR← 8264 BNE← 8C1B JSR← 8C58 JSR
LDA (cmd_ptr),y ; Next character
825B CMP #',' ; A comma?
825D BEQ skip_separator ; Yes: skip it
825F CMP #' ' ; A space?
8261 BNE return_from_skip_separators ; No: done
8263 .skip_separator←1← 825D BEQ
INY ; Step past it
8264 BNE skip_separators ; Always taken (Y does not wrap)
8266 .return_from_skip_separators←1← 8261 BNE
RTS ; Return

Turn the driver off

Reached from select_device when a device command's argument is 0 (for example *MOUSE 0). If the driver is on: put back the IRQ1V and BYTEV values saved when it was turned on, stop the polling service calls (OSBYTE &17), disable the mouse interrupts, remove the pointer, and mark the driver off. The extended vector table entries it set are left as they are. device_mode is not changed.

8267 .turn_driver_off←1← 82CA BEQ
LDA driver_on ; Is the driver on?
826A BEQ return_from_device_command ; No: nothing to do
826C PHP ; Interrupts off while the vectors change
826D SEI ; ...
826E LDA saved_irq1v ; Put back the old IRQ1V...
8271 STA irq1v ; ...
8274 LDA saved_irq1v_hi ; ...
8277 STA irq1v + 1 ; ...
827A LDA saved_bytev ; and the old BYTEV
827D STA bytev ; ...
8280 LDA saved_bytev_hi ; ...
8283 STA bytev + 1 ; ...
8286 PLP ; Interrupts back as they were
8287 LDA #osbyte_decrement_polling_semaphore ; OSBYTE &17: decrement the ROM polling semaphore,
8289 JSR osbyte ; ending the polling service calls Electron and Master: Decrement polling semaphore
828C JSR remove_pointer_and_mouse ; Disable the mouse interrupts, remove the pointer
828F STZ driver_on ; The driver is off
8292 .return_from_device_command←2← 826A BEQ← 82CF BNE
RTS ; Return

*KEYS: steer the pointer with the cursor keys

Select device mode &20. *FX4,2 makes the cursor keys act as function keys, and *FX226,0 makes the MOS ignore SHIFT with the function keys, so that the cursor keys, now steering the pointer, are not seen as cursor editing. Neither setting is undone when another device is chosen or the driver is turned off. Continues at select_device.

8293 .cmd_keys
LDA #device_mode_keys ; Device mode: cursor keys
8295 STA device_mode ; ...
8298 LDA #osbyte_set_cursor_editing ; OSBYTE 4 with X=2:
829A LDX #2 ; cursor keys act as function keys
829C LDY #0 ; ...
829E JSR osbyte ; ... Set cursor editing keys
82A1 LDA #osbyte_shift_fkey_status ; OSBYTE &E2 with X=0, Y=0:
82A3 LDX #0 ; SHIFT with a function key is ignored
82A5 LDY #0 ; ...
82A7 JSR osbyte ; ... osbyte: shift fkey status
82AA BRA select_device ; Go on to select the device
fall through ↓

*DIGITAL: steer the pointer with a digital joystick

Select device mode &40, in which the pointer follows the direction bits the MOS returns from ADVAL(0). Continues at select_device.

82AC .cmd_digital
LDA #device_mode_digital ; Device mode: digital joystick
82AE STA device_mode ; ...
82B1 BRA select_device ; Go on to select the device
fall through ↓

*JOYSTICK: steer the pointer with an analogue joystick

Select device mode &80, in which the pointer follows ADVAL(1) and ADVAL(2). Continues at select_device.

82B3 .cmd_joystick
LDA #device_mode_joystick ; Device mode: analogue joystick
82B5 STA device_mode ; ...
82B8 BRA select_device ; Go on to select the device
fall through ↓

*MOUSE and *TRACKERBALL: move the pointer with a mouse

Select device mode 0, in which the pointer is moved by the User VIA's CB1 and CB2 interrupts (irq_handler). Falls into select_device.

82BA .cmd_mouse
STZ device_mode ; Device mode: mouse or trackerball

Select a device, and turn the driver on or off

Common tail of the device commands, with device_mode already set. The joystick and key speeds are reset. If the argument starts with "0" the driver is turned off (turn_driver_off). Otherwise, if the driver is already on, nothing more is done: only the device mode has changed. In particular the mouse interrupts are not enabled or disabled to suit the new mode until *POINTER shows the pointer again, which is why software switches devices with, for example, *DIGITAL 0 then *MOUSE.

If the driver is off, it is turned on:

  • driver_on is set, the pointer is marked not shown, and no button change is pending;
  • OSBYTE &16 starts the polling service calls;
  • the mouse pinout is marked as not yet detected;
  • in mouse mode the User VIA is set up for the mouse: CB1 and CB2 interrupt on a falling edge, port latching off, CB1 and CB2 interrupts enabled and port B all inputs; in other modes the CB1 and CB2 interrupts are disabled;
  • the pointer is put in the middle of the screen, at (640, 512);
  • BYTEV is pointed at the extended vector entry for BYTEV, and the extended vector table entry at bytev_handler in this ROM;
  • IRQ1V is pointed at irq1v_trampoline, which is built here, and the extended vector table entry for IRQ1V is pointed at irq_handler in this ROM. IRQ1V does not point at that entry itself: the trampoline calls it, so that when irq_handler returns, the previous ROM is paged back in and the trampoline continues to the old IRQ1V handler.

In both cases the low byte of the extended vector entry point (&0F, &06) is also the offset of the vector's entry in the table, three times the vector number, so one register load serves for both.

The pointer is not shown; that takes *POINTER.

82BD .select_device←3← 82AA BRA← 82B1 BRA← 82B8 BRA
JSR reset_x_speed ; Horizontal speed back to the start
82C0 JSR reset_y_speed ; Vertical speed back to the start
82C3 JSR reset_argument_index ; First argument character
82C6 LDA (cmd_ptr),y ; ...
82C8 CMP #'0' ; Is it "0"?
82CA BEQ turn_driver_off ; Yes: turn the driver off
82CC LDX driver_on ; Is the driver already on?
82CF BNE return_from_device_command ; Yes: just the mode has changed
82D1 STX button_pending ; X=0: no button change pending
82D4 STX pointer_shown ; pointer not shown
82D7 DEX ; X=&FF...
82D8 STX driver_on ; ...the driver is on
82DB LDA #osbyte_increment_polling_semaphore ; OSBYTE &16: increment the ROM polling semaphore,
82DD JSR osbyte ; so that the MOS issues service call &15 every 10 ms Electron and Master: Increment polling semaphore
82E0 PHP ; Interrupts off while the hardware and vectors
82E1 SEI ; are set up
82E2 LDA #&ff ; Mouse pinout not yet detected
82E4 STA pinout_index ; ...
82E7 LDA device_mode ; Mouse mode?
82EA BNE disable_mouse_interrupts ; No: disable the mouse interrupts
82EC LDA user_via_pcr ; User VIA PCR: clear bits 4-7, so CB1 and CB2
82EF AND #&0f ; are inputs that interrupt on a falling edge
82F1 STA user_via_pcr ; ...
82F4 LDA user_via_acr ; User VIA ACR: clear bits 0-1,
82F7 AND #&fc ; port A and B latching off
82F9 STA user_via_acr ; ...
82FC LDA #via_ier_enable_cb1_cb2 ; IER: enable the CB1 and CB2 interrupts
82FE STA user_via_ier ; ...
8301 LDA #0 ; DDRB = 0: port B all inputs
8303 STA user_via_ddrb ; ...
8306 BRA centre_pointer ; Go on to place the pointer
8308 .disable_mouse_interrupts←1← 82EA BNE
LDA #via_ier_disable_cb1_cb2 ; IER: disable the CB1 and CB2 interrupts
830A STA user_via_ier ; ...
830D .centre_pointer←1← 8306 BRA
LDA #<(pointer_x_centre) ; Pointer X = 640 (&280)
830F STA pointer_x ; ...
8312 LDA #>(pointer_x_centre) ; ...
8314 STA pointer_x_hi ; ...
8317 LDA #<(pointer_y_centre) ; Pointer Y = 512 (&200)
8319 STA pointer_y ; ...
831C LDA #>(pointer_y_centre) ; ...
831E STA pointer_y_hi ; ...
8321 LDA #osbyte_read_rom_ptr_table_low ; OSBYTE &A8: read the address of the extended
8323 LDX #0 ; vector table
8325 LDY #&ff ; ...
8327 JSR osbyte ; ... Read low byte of ROM pointer table address
832A STX cmd_ptr ; Keep it in cmd_ptr
832C STY cmd_ptr_hi ; ...
832E LDA bytev ; Save the current BYTEV...
8331 STA saved_bytev ; ...
8334 LDA bytev + 1 ; ...
8337 STA saved_bytev_hi ; ...
833A LDY #<(bytev_extended_entry) ; BYTEV = &FF0F, the extended vector entry for
833C STY bytev ; BYTEV; &0F is also its offset in the table
833F LDX #>(bytev_extended_entry) ; ...
8341 STX bytev + 1 ; ...
8344 LDA #<(bytev_handler) ; Table entry for BYTEV: address of bytev_handler
8346 STA (cmd_ptr),y ; ...
8348 LDA #>(bytev_handler) ; ...
834A INY ; ...
834B STA (cmd_ptr),y ; ...
834D INY ; and the ROM number, this ROM
834E LDA romsel_copy ; ...
8350 STA (cmd_ptr),y ; ...
8352 LDA irq1v ; Save the current IRQ1V; it is also the operand
8355 STA saved_irq1v ; of the JMP ending the trampoline
8358 LDA irq1v + 1 ; ...
835B STA saved_irq1v_hi ; ...
835E LDA #opcode_jsr ; Build the trampoline: JSR...
8360 STA irq1v_trampoline ; ...
8363 LDY #<(irq1v_extended_entry) ; &FF06, the extended vector entry for IRQ1V;
8365 STY irq1v_trampoline_target ; &06 is also its offset in the table
8368 LDA #>(irq1v_extended_entry) ; ...
836A STA irq1v_trampoline_target_hi ; ...
836D LDA #opcode_jmp ; then JMP (to the old IRQ1V handler)
836F STA irq1v_trampoline_jmp ; ...
8372 LDA #<(irq1v_trampoline) ; IRQ1V = the trampoline
8374 STA irq1v ; ...
8377 LDA #>(irq1v_trampoline) ; ...
8379 STA irq1v + 1 ; ...
837C LDA #<(irq_handler) ; Table entry for IRQ1V: address of irq_handler
837E STA (cmd_ptr),y ; ...
8380 INY ; ...
8381 LDA #>(irq_handler) ; ...
8383 STA (cmd_ptr),y ; ...
8385 INY ; ...
8386 LDA romsel_copy ; and the ROM number, this ROM
8388 STA (cmd_ptr),y ; ...
838A PLP ; Interrupts back as they were
838B RTS ; Return

*POINTER: show or remove the pointer

Record the screen format for the current mode, then act on the first argument character:

Argument Effect
0 Remove the pointer
2 Disable the mouse interrupts and remove the pointer
anything else, or none Show the pointer

The screen format is 0, 1 or 2 in MODEs 0, 1 and 2, and 3 or 4 in MODEs 4 and 5 (a shadow mode counts as its non-shadow equivalent). In MODEs 3, 6 and 7, which have no pointer images, the command does nothing.

Showing the pointer needs the driver to be on, and does nothing if the pointer is already shown. It enables the mouse interrupts if the device is the mouse and disables them otherwise, builds the four shifted copies of the pointer image and mask for the screen format, and draws the pointer.

838C .cmd_pointer
LDA #osbyte_read_char_at_cursor ; OSBYTE &87: read the screen mode into Y
838E JSR osbyte ; ... Read character at text cursor position and current screen MODE
8391 TYA ; Mode number...
8392 AND #7 ; ...ignoring the shadow bit
8394 CMP #3 ; MODE 0, 1 or 2?
8396 BCC set_screen_format ; Yes: screen format = mode
8398 CMP #3 ; MODE 3?
839A BEQ return_from_pointer ; Yes: no pointer in a text mode
839C CMP #6 ; MODE 6 or 7?
839E BCS return_from_pointer ; Yes: no pointer in a text mode
83A0 DEC ; MODE 4 or 5: screen format 3 or 4
83A1 .set_screen_format←1← 8396 BCC
STA screen_format ; Record the screen format
83A4 JSR reset_argument_index ; First argument character...
83A7 LDA (cmd_ptr),y ; ...
83A9 SEC ; as a digit
83AA SBC #'0' ; ...
83AC BEQ remove_pointer ; 0: remove the pointer
83AE CMP #2 ; 2?
83B0 BEQ remove_pointer_and_mouse ; Yes: disable the mouse, remove the pointer
83B2 LDA driver_on ; Show it: is the driver on?
83B5 BEQ return_from_pointer ; No: nothing to do
83B7 LDA pointer_shown ; Is the pointer already shown?
83BA BNE return_from_pointer ; Yes: nothing to do
83BC LDA driver_on ; &FF...
83BF STA pointer_shown ; ...the pointer is shown
83C2 STA zp_drawn_ptr_hi ; and nothing has been drawn yet (bit 7 set)
83C4 LDA device_mode ; Mouse mode?
83C7 BNE pointer_mouse_interrupts_off ; No: disable the mouse interrupts
83C9 LDA #via_ier_enable_cb1_cb2 ; Yes: enable them
83CB BRA set_mouse_interrupts ; ...
83CD .pointer_mouse_interrupts_off←1← 83C7 BNE
LDA #via_ier_disable_cb1_cb2 ; Disable the CB1 and CB2 interrupts
83CF .set_mouse_interrupts←1← 83CB BRA
STA user_via_ier ; ...
83D2 LDA #0 ; Build the shifted pointer images and masks
83D4 JSR build_pointer_images ; ...
83D7 LDY pointer_x ; Make drawn_x differ from pointer_x...
83DA DEY ; ...
83DB STY drawn_x ; ...so that the pointer is drawn
83DE JMP update_pointer ; Draw it
83E1 .return_from_pointer←6← 839A BEQ← 839E BCS← 83B5 BEQ← 83BA BNE← 83EA BEQ← 842D BEQ
RTS ; Return

Disable the mouse interrupts and remove the pointer

Disable the User VIA's CB1 and CB2 interrupts, then remove the pointer (remove_pointer).

83E2 .remove_pointer_and_mouse←2← 828C JSR← 83B0 BEQ
LDA #via_ier_disable_cb1_cb2 ; Disable the CB1 and CB2 interrupts
83E4 STA user_via_ier ; ...
fall through ↓

Remove the pointer from the screen

If the pointer is shown, put back the screen bytes it covers and mark it not shown. Main-memory accesses are pointed at the same RAM as the VDU drivers while this is done (see update_pointer), and ACCCON is then restored.

83E7 .remove_pointer←1← 83AC BEQ
LDA pointer_shown ; Is the pointer shown?
83EA BEQ return_from_pointer ; No: nothing to do
83EC LDA acccon ; Save ACCCON
83EF STA saved_acccon ; ...
83F2 AND #&fb ; Clear X (main memory, not shadow, at &3000)
83F4 BIT #acccon_e ; Are the VDU drivers using shadow RAM (E)?
83F6 BEQ remove_pointer_set_acccon ; No
83F8 ORA #acccon_x ; Yes: access shadow RAM too (set X)
83FA .remove_pointer_set_acccon←1← 83F6 BEQ
STA acccon ; ...
83FD JSR restore_screen_under_pointer ; Put back the screen under the pointer
8400 LDA saved_acccon ; Restore ACCCON
8403 STA acccon ; ...
8406 STZ pointer_shown ; The pointer is not shown
8409 RTS ; Return

Redraw the pointer if it has moved

Restart the redraw countdown, and if the pointer has moved since it was last drawn, move it: put back the screen under it at the old position, then draw it at the new one.

The pointer image is 4 screen bytes wide and 16 pixel rows high, held as 4 columns of 16 bytes. Its top left corner is the hot spot (hotspot_x, hotspot_y) left of and above (pointer_x, pointer_y). The image used is the one of the four shifted copies (see build_pointer_images) that matches how far into a screen byte the left edge falls, so the pointer moves in steps finer than a byte.

Each screen byte is saved in screen_under_pointer, then ANDed with the mask and ORed with the image. Columns left of the screen or bytes below its bottom are skipped; drawing stops at the first column right of the screen; rows above the top of the screen are skipped.

During drawing, main-memory accesses are switched to the RAM the VDU drivers are using: ACCCON bit X (main memory at &3000-&7FFF is shadow RAM) is set to match bit E (VDU driver accesses go to shadow RAM), so the pointer is drawn on the screen being written in both shadow and normal modes. ACCCON is restored afterwards, through saved_acccon, which is also the last byte of saved_zero_page (see the workspace notes).

Called from cmd_pointer, and from poll_redraw_and_buttons when the countdown expires.

On ExitAcorrupted
Xcorrupted
Ycorrupted
840A .update_pointer←2← 83DE JMP← 8A21 JSR
LDA #redraw_interval ; Next redraw in 10 polls
840C STA redraw_countdown ; ...
840F LDA pointer_x ; Has the pointer moved since it was drawn?
8412 CMP drawn_x ; ...
8415 BNE move_pointer_on_screen ; Yes
8417 LDA pointer_y ; ...
841A CMP drawn_y ; ...
841D BNE move_pointer_on_screen ; Yes
841F LDA pointer_x_hi ; ...
8422 CMP drawn_x_hi ; ...
8425 BNE move_pointer_on_screen ; Yes
8427 LDA pointer_y_hi ; ...
842A CMP drawn_y_hi ; ...
842D BEQ return_from_pointer ; No: nothing to do
842F .move_pointer_on_screen←3← 8415 BNE← 841D BNE← 8425 BNE
LDA acccon ; Save ACCCON
8432 STA saved_acccon ; ...
8435 AND #&fb ; Clear X (main memory, not shadow, at &3000)
8437 BIT #acccon_e ; Are the VDU drivers using shadow RAM (E)?
8439 BEQ draw_set_acccon ; No
843B ORA #acccon_x ; Yes: access shadow RAM too (set X)
843D .draw_set_acccon←1← 8439 BEQ
STA acccon ; ...
8440 LDA pointer_y ; Record the position being drawn...
8443 STA drawn_y ; ...
8446 LDA pointer_y_hi ; ...
8449 STA drawn_y_hi ; ...
844C LDA pointer_x ; ...
844F STA drawn_x ; ...
8452 LDA pointer_x_hi ; ...
8455 STA drawn_x_hi ; ...
8458 LDX #0 ; (X is set again below)
845A LDA pointer_x ; Left edge = pointer_x - hot spot X
845D SEC ; ...
845E SBC hotspot_x ; ...
8461 STA pointer_left ; ...
8464 LDA pointer_x_hi ; ...
8467 SBC #0 ; ...
8469 STA pointer_left_hi ; ...
846C LDA hotspot_y ; Top edge = pointer_y + hot spot Y
846F CLC ; ...
8470 ADC pointer_y ; ...
8473 STA pointer_top ; ...
8476 LDA pointer_y_hi ; ...
8479 ADC #0 ; ...
847B STA pointer_top_hi ; ...
847E JSR calc_pointer_screen_address ; Screen address of the top left, and the shift
8481 LDY romsel_copy ; zp_image_ptr = the image copy for the shift:
8483 LDA rom_workspace_table,y ; page +1 of the workspace...
8486 INC ; ...
8487 STA zp_image_ptr_hi ; ...
8489 LDA shifted_copy_offsets,x ; plus the copy's offset
848C STA zp_image_ptr ; ...
848E JSR restore_screen_under_pointer ; Put back the screen under the old pointer
8491 LDA pointer_left ; Remember the new left edge for removing it
8494 STA drawn_left ; ...
8497 LDA pointer_left_hi ; ...
849A STA drawn_left_hi ; ...
849D LDA zp_screen_ptr_hi ; Push the screen address twice: the top copy
849F PHA ; steps along the columns, the bottom one is
84A0 LDA zp_screen_ptr ; kept as the address of the drawn pointer
84A2 PHA ; ...
84A3 LDA zp_screen_ptr_hi ; ...
84A5 PHA ; ...
84A6 LDA zp_screen_ptr ; ...
84A8 PHA ; ...
84A9 LDX #0 ; Start at image byte 0
84AB STX zp_image_index ; ...
84AD .draw_char_row←2← 84FE BRA← 853B JMP
LDY #0 ; Start at the address's own pixel row
84AF STY zp_row_in_cell ; ...
84B1 LDA zp_screen_ptr_hi ; Address &8000 or above (below the screen)?
84B3 BMI draw_skip_column ; Yes: skip the rest of this column
84B5 CMP vdu_screen_start_hi ; Below the start of screen memory (above it)?
84B8 BCC draw_skip_rows_above_screen ; Yes: skip rows to the next character row
84BA LDA pointer_left_hi ; Is this column left of the screen?
84BD BMI draw_skip_column ; Yes: skip the column
84BF CMP #5 ; Is it right of the screen (X >= 1280)?
84C1 BCS finish_drawing ; Yes: stop drawing
84C3 .draw_pixel_row←1← 84E8 BNE
LDY zp_row_in_cell ; Screen byte...
84C5 LDA (zp_screen_ptr),y ; ...
84C7 LDY zp_image_index ; saved in the buffer
84C9 STA (zp_under_ptr),y ; ...
84CB INC zp_image_ptr_hi ; AND with the mask, one page above the image
84CD AND (zp_image_ptr),y ; ...
84CF DEC zp_image_ptr_hi ; ...
84D1 ORA (zp_image_ptr),y ; OR in the image
84D3 LDY zp_row_in_cell ; and put it on the screen
84D5 STA (zp_screen_ptr),y ; ...
84D7 INC zp_image_index ; Next image byte
84D9 LDA zp_image_index ; All 16 rows of this column done?
84DB AND #&0f ; ...
84DD BEQ draw_next_column ; Yes: next column
84DF INC zp_row_in_cell ; Next pixel row down
84E1 LDA zp_row_in_cell ; Still in the same character row?
84E3 CLC ; ...
84E4 ADC zp_screen_ptr ; ...
84E6 AND #7 ; ...
84E8 BNE draw_pixel_row ; Yes: draw it
84EA .draw_next_char_row←1← 8509 BRA
LDY screen_format ; Down a character row: back to its top byte...
84ED LDA zp_screen_ptr ; ...
84EF AND #&f8 ; ...
84F1 CLC ; ...
84F2 ADC char_row_bytes_lo,y ; plus the bytes in a character row
84F5 STA zp_screen_ptr ; ...
84F7 LDA zp_screen_ptr_hi ; ...
84F9 ADC char_row_bytes_hi,y ; ...
84FC STA zp_screen_ptr_hi ; ...
84FE BRA draw_char_row ; Draw that row
8500 .draw_skip_rows_above_screen←1← 84B8 BCC
LDA zp_screen_ptr ; Above the screen: skip as many image rows as
8502 AND #7 ; the address's pixel row within the character
8504 CLC ; ...
8505 ADC zp_image_index ; ...
8507 STA zp_image_index ; ...
8509 BRA draw_next_char_row ; and try the next character row
850B .draw_skip_column←2← 84B3 BMI← 84BD BMI
LDA zp_image_index ; Skip to the next column of the image
850D AND #&f0 ; ...
850F CLC ; ...
8510 ADC #&10 ; ...
8512 STA zp_image_index ; ...
8514 .draw_next_column←1← 84DD BEQ
LDY screen_format ; Move the left edge right one screen byte
8517 LDA pointer_left ; ...
851A CLC ; ...
851B ADC units_per_screen_byte,y ; ...
851E STA pointer_left ; ...
8521 BCC draw_next_column_address ; ...
8523 INC pointer_left_hi ; ...
8526 .draw_next_column_address←1← 8521 BCC
PLA ; Next column's screen address: 8 bytes on
8527 CLC ; ...
8528 ADC #8 ; ...
852A STA zp_screen_ptr ; ...
852C PLA ; ...
852D ADC #0 ; ...
852F STA zp_screen_ptr_hi ; ...
8531 PHA ; kept on the stack
8532 LDA zp_screen_ptr ; ...
8534 PHA ; ...
8535 LDA zp_image_index ; All four columns done?
8537 CMP #&40 ; ...
8539 BEQ finish_drawing ; Yes: finish
853B JMP draw_char_row ; No: draw the next column
853E .finish_drawing←2← 84C1 BCS← 8539 BEQ
PLA ; Drop the column address
853F PLA ; ...
8540 PLA ; The pointer is now drawn at the address...
8541 STA zp_drawn_ptr ; ...
8543 PLA ; ...
8544 STA zp_drawn_ptr_hi ; ...
8546 LDA saved_acccon ; Restore ACCCON
8549 STA acccon ; ...
854C RTS ; Return

Leave the driver: restore zero page and store the workspace

The partner of enter_driver. Keep zp_drawn_ptr in saved_drawn_ptr, restore the caller's zero page &84-&90 from saved_zero_page, and fall into exchange_workspace to store the workspace at &9440.

The 13th byte restored, &90, is saved_acccon, so if the pointer was drawn or removed since enter_driver, &90 is left holding ACCCON.

On ExitAcorrupted
Xcorrupted
Ypreserved
854D .leave_driver←3← 81E8 JSR← 88D3 JSR← 8A27 JSR
LDA zp_drawn_ptr ; Keep the drawn pointer's address
854F STA saved_drawn_ptr ; ...
8552 LDA zp_drawn_ptr_hi ; ...
8554 STA saved_drawn_ptr_hi ; ...
8557 LDX #&0c ; Restore zero page &84-&90
8559 .restore_zero_page←1← 855F BPL
LDA saved_zero_page,x ; ...
855C STA zp_image_ptr,x ; ...
855E DEX ; ...
855F BPL restore_zero_page ; ...
fall through ↓

Exchange the working and stored copies of the workspace

Swap the 48 bytes at &9000-&902F with the 48 bytes at offset &40 in page +3 of the private workspace (rom_workspace_table, set to &91, so &9440-&946F).

Every way into the driver calls this on the way in and again on the way out, so the driver's state is at &9000 while it runs and at &9440 in between. enter_driver and leave_driver do this for the commands and the polls; bytev_handler calls it directly; irq_handler exchanges only the first ten bytes (exchange_position_workspace).

&9030-&9037 (the device mode, the speeds and the desktop colours) are not exchanged.

On ExitApreserved
Xpreserved
Ypreserved
8561 .exchange_workspace←5← 8592 JSR← 87D4 JSR← 87E5 JSR← 87F5 JSR← 881D JSR
PHA ; Save A
8562 PHX ; X
8563 PHY ; and Y
8564 LDA zp_image_ptr ; and the zero page pointer used
8566 PHA ; ...
8567 LDA zp_image_ptr_hi ; ...
8569 PHA ; ...
856A LDX romsel_copy ; Point it at the stored copy: page +3...
856C LDA rom_workspace_table,x ; ...
856F CLC ; ...
8570 ADC #3 ; ...
8572 STA zp_image_ptr_hi ; ...
8574 LDA #&40 ; offset &40
8576 STA zp_image_ptr ; ...
8578 LDY #&2f ; 48 bytes, from the last
857A .exchange_workspace_byte←1← 8586 BPL
LDX tmax_x,y ; Working byte
857D LDA (zp_image_ptr),y ; Stored byte...
857F STA tmax_x,y ; ...becomes the working byte
8582 TXA ; Working byte...
8583 STA (zp_image_ptr),y ; ...becomes the stored byte
8585 DEY ; Next
8586 BPL exchange_workspace_byte ; ...
8588 PLA ; Restore the zero page pointer
8589 STA zp_image_ptr_hi ; ...
858B PLA ; ...
858C STA zp_image_ptr ; ...
858E PLY ; Restore Y
858F PLX ; X
8590 PLA ; and A
8591 RTS ; Return

Enter the driver: bring in the workspace and save zero page

Bring the stored workspace into &9000 (exchange_workspace), save the caller's zero page &84-&90 in saved_zero_page, and load zp_drawn_ptr from saved_drawn_ptr. Called with interrupts disabled. leave_driver undoes it.

On ExitAcorrupted
Xcorrupted
Ypreserved
8592 .enter_driver←3← 81E2 JSR← 8849 JSR← 8A14 JSR
JSR exchange_workspace ; Bring in the workspace
8595 LDX #&0c ; Save zero page &84-&90
8597 .save_zero_page←1← 859D BPL
LDA zp_image_ptr,x ; ...
8599 STA saved_zero_page,x ; ...
859C DEX ; ...
859D BPL save_zero_page ; ...
859F LDA saved_drawn_ptr ; Load the drawn pointer's address
85A2 STA zp_drawn_ptr ; ...
85A4 LDA saved_drawn_ptr_hi ; ...
85A7 STA zp_drawn_ptr_hi ; ...
85A9 .return_from_enter_driver←1← 85B8 BMI
RTS ; Return

Put back the screen under the pointer

Copy the 64 bytes saved in screen_under_pointer back to the screen at zp_drawn_ptr, column by column, with the same clipping as update_pointer and using drawn_left for the column positions. Nothing is done if bit 7 of zp_drawn_ptr's high byte is set (no pointer drawn).

zp_drawn_ptr and drawn_left are stepped along as it works, so they no longer describe the pointer afterwards.

For rows above the top of the screen, the number of rows to skip is added to X instead of to the buffer index, so the index is not advanced. While pointer_y is within its range (at most 1020), the count is always 0 and this makes no difference.

On ExitAcorrupted
Xcorrupted
Ycorrupted
85AA .restore_screen_under_pointer←2← 83FD JSR← 848E JSR
LDY romsel_copy ; zp_under_ptr = the saved-screen buffer,
85AC LDA rom_workspace_table,y ; page +3 of the workspace
85AF CLC ; ...
85B0 ADC #3 ; ...
85B2 STA zp_under_ptr_hi ; ...
85B4 STZ zp_under_ptr ; ...
85B6 LDA zp_drawn_ptr_hi ; Is a pointer drawn?
85B8 BMI return_from_enter_driver ; No: nothing to put back
85BA PHA ; Push its screen address, to step along
85BB LDA zp_drawn_ptr ; the columns
85BD PHA ; ...
85BE LDY #0 ; Start at buffer byte 0
85C0 STY zp_image_index ; ...
85C2 .restore_char_row←2← 8607 JMP← 862F BNE
LDY #0 ; Start at the address's own pixel row
85C4 STY zp_row_in_cell ; ...
85C6 LDA zp_drawn_ptr_hi ; Address &8000 or above (below the screen)?
85C8 BMI restore_skip_column ; Yes: skip the rest of this column
85CA CMP vdu_screen_start_hi ; Below the start of screen memory (above it)?
85CD BCC restore_skip_rows_above_screen ; Yes: go to the next character row
85CF LDA drawn_left_hi ; Is this column left of the screen?
85D2 BMI restore_skip_column ; Yes: skip the column
85D4 CMP #5 ; Is it right of the screen (X >= 1280)?
85D6 BCS finish_restoring ; Yes: stop
85D8 .restore_pixel_row←1← 85F1 BNE
LDY zp_image_index ; Saved byte...
85DA LDA (zp_under_ptr),y ; ...
85DC LDY zp_row_in_cell ; ...back on the screen
85DE STA (zp_drawn_ptr),y ; ...
85E0 INC zp_image_index ; Next saved byte
85E2 LDA zp_image_index ; All 16 rows of this column done?
85E4 AND #&0f ; ...
85E6 BEQ restore_next_column ; Yes: next column
85E8 INC zp_row_in_cell ; Next pixel row down
85EA LDA zp_row_in_cell ; Still in the same character row?
85EC CLC ; ...
85ED ADC zp_drawn_ptr ; ...
85EF AND #7 ; ...
85F1 BNE restore_pixel_row ; Yes: put it back
85F3 .restore_next_char_row←1← 864B JMP
LDY screen_format ; Down a character row: back to its top byte...
85F6 LDA zp_drawn_ptr ; ...
85F8 AND #&f8 ; ...
85FA CLC ; ...
85FB ADC char_row_bytes_lo,y ; plus the bytes in a character row
85FE STA zp_drawn_ptr ; ...
8600 LDA zp_drawn_ptr_hi ; ...
8602 ADC char_row_bytes_hi,y ; ...
8605 STA zp_drawn_ptr_hi ; ...
8607 JMP restore_char_row ; Restore that row
860A .restore_next_column←2← 85E6 BEQ← 863D JMP
LDY screen_format ; Move the left edge right one screen byte
860D LDA drawn_left ; ...
8610 CLC ; ...
8611 ADC units_per_screen_byte,y ; ...
8614 STA drawn_left ; ...
8617 BCC restore_next_column_address ; ...
8619 INC drawn_left_hi ; ...
861C .restore_next_column_address←1← 8617 BCC
PLA ; Next column's screen address: 8 bytes on
861D CLC ; ...
861E ADC #8 ; ...
8620 STA zp_drawn_ptr ; ...
8622 PLA ; ...
8623 ADC #0 ; ...
8625 STA zp_drawn_ptr_hi ; ...
8627 PHA ; kept on the stack
8628 LDA zp_drawn_ptr ; ...
862A PHA ; ...
862B LDY zp_image_index ; All four columns done?
862D CPY #&40 ; ...
862F BNE restore_char_row ; No: restore the next column
8631 .finish_restoring←1← 85D6 BCS
PLA ; Drop the column address
8632 PLA ; ...
8633 RTS ; Return
8634 .restore_skip_column←2← 85C8 BMI← 85D2 BMI
LDA zp_image_index ; Skip to the next column of the buffer
8636 AND #&f0 ; ...
8638 CLC ; ...
8639 ADC #&10 ; ...
863B STA zp_image_index ; ...
863D JMP restore_next_column ; ...
8640 .restore_skip_rows_above_screen←1← 85CD BCC
LDA zp_drawn_ptr ; Above the screen: rows to skip = the pixel row
8642 AND #7 ; within the character row
8644 STA zp_skip_rows ; ...
8646 TXA ; added to X, which is not used: the buffer
8647 CLC ; index is not advanced
8648 ADC zp_skip_rows ; ...
864A TAX ; ...
864B JMP restore_next_char_row ; Try the next character row

Offsets of each screen format's pointer image and mask

Low and high bytes of the offset, from pointer_images and from pointer_masks, of the 64-byte image and mask for each screen format: &000, &040, &080, &0C0 and &100 for formats 0-4. The sixth entry (&140) is not used.

864E .pointer_format_offsets
EQUB &00, &40, &80, &C0, &00, &40 ; Low bytes, formats 0-5
8654 .pointer_format_offsets_hi
EQUB &00, &00, &00, &00, &01, &01 ; High bytes, formats 0-5

Build the shifted pointer images and masks

Copy the 64-byte pointer image and mask for the current screen format from the ROM into the bank, at pointer_image_copies (page +1 of the workspace) and pointer_mask_copies (page +2), then build three more copies of each after it, each shifted right by a further quarter of a screen byte (build_shifted_copies). update_pointer picks the copy that matches the pointer's position within a screen byte.

The images are laid out as 4 byte columns of 16 rows each. A selects a byte offset into the format's image and mask; cmd_pointer always passes 0.

On EntryAoffset into the image and mask (0)
SCREEN_FORMATwhich image and mask to use
On ExitAcorrupted
Xcorrupted
Ycorrupted
865A .build_pointer_images←1← 83D4 JSR
STA pointer_shape ; Record the offset
865D TAY ; ...
865E LDX screen_format ; For this screen format:
8661 LDA pointer_format_offsets,x ; source image = pointer_images + format offset
8664 CLC ; ...
8665 ADC #<(pointer_images) ; ...
8667 STA zp_image_ptr ; ...
8669 LDA pointer_format_offsets_hi,x ; ...
866C ADC #>(pointer_images) ; ...
866E STA zp_image_ptr_hi ; ...
8670 LDA pointer_format_offsets,x ; source mask = pointer_masks + format offset
8673 CLC ; ...
8674 ADC #<(pointer_masks) ; ...
8676 STA zp_under_ptr ; ...
8678 LDA pointer_format_offsets_hi,x ; ...
867B ADC #>(pointer_masks) ; ...
867D STA zp_under_ptr_hi ; ...
867F LDX romsel_copy ; Destination: page +1 of the workspace
8681 LDA rom_workspace_table,x ; ...
8684 INC ; ...
8685 STA zp_screen_ptr_hi ; ...
8687 STZ zp_screen_ptr ; ...
8689 STY zp_image_index ; Source index starts at the offset
868B LDY #0 ; Destination index starts at 0
868D STY zp_row_in_cell ; ...
868F .copy_image_and_mask_byte←1← 86AB BNE
LDY zp_image_index ; Image byte...
8691 LDA (zp_image_ptr),y ; ...
8693 LDY zp_row_in_cell ; ...to page +1
8695 STA (zp_screen_ptr),y ; ...
8697 LDY zp_image_index ; Mask byte...
8699 LDA (zp_under_ptr),y ; ...
869B LDY zp_row_in_cell ; ...
869D INC zp_screen_ptr_hi ; ...to page +2
869F STA (zp_screen_ptr),y ; ...
86A1 DEC zp_screen_ptr_hi ; ...
86A3 INC zp_image_index ; Next source byte
86A5 INC zp_row_in_cell ; Next destination byte
86A7 LDY zp_row_in_cell ; All 64 copied?
86A9 CPY #pointer_image_size ; ...
86AB BNE copy_image_and_mask_byte ; No: copy the next
86AD STZ zp_image_ptr ; Shift the image: from offset &00 of page +1...
86AF LDA #&40 ; to offset &40
86B1 STA zp_under_ptr ; ...
86B3 LDX romsel_copy ; ...
86B5 LDA rom_workspace_table,x ; ...
86B8 INC ; ...
86B9 STA zp_image_ptr_hi ; ...
86BB STA zp_under_ptr_hi ; ...
86BD LDA #0 ; shifting in 0 bits (transparent in an image)
86BF STA zp_temp ; ...
86C1 JSR build_shifted_copies ; Build the three shifted image copies
86C4 STZ zp_image_ptr ; Then the mask: from offset &00 of page +2...
86C6 LDA #&40 ; to offset &40
86C8 STA zp_under_ptr ; ...
86CA LDX romsel_copy ; ...
86CC LDA rom_workspace_table,x ; ...
86CF CLC ; ...
86D0 ADC #2 ; ...
86D2 STA zp_image_ptr_hi ; ...
86D4 STA zp_under_ptr_hi ; ...
86D6 DEC zp_temp ; shifting in 1 bits (transparent in a mask)
fall through ↓

Build three shifted copies of an image or mask

From the 64-byte copy at zp_image_ptr, build three copies, each a quarter of a screen byte further right, at zp_under_ptr, zp_under_ptr+&40 and zp_under_ptr+&80. Bits shifted in at the left are zp_temp's (0 for an image, 1 for a mask). How far a quarter byte is depends on the screen format:

Format MODE Pixels per byte Each copy is
0, 3 0, 4 8 2 pixels further right
1, 4 1, 5 4 1 pixel further right
2 2 2 half a pixel: copies are 0, 0, 1 and 1 pixel right
On EntryZP_IMAGE_PTRunshifted copy
ZP_UNDER_PTRwhere the first shifted copy goes
ZP_TEMP&00 (image) or &FF (mask)
86D8 .build_shifted_copies←1← 86C1 JSR
LDA screen_format ; Screen format 0 or 3 (two colours)?
86DB BEQ build_2colour_copies ; Yes
86DD CMP #3 ; ...
86DF BEQ build_2colour_copies ; ...
86E1 CMP #4 ; Format 1 or 4 (four colours)?
86E3 BEQ build_4colour_copies ; Yes
86E5 CMP #1 ; ...
86E7 BEQ build_4colour_copies ; ...
86E9 JMP build_16colour_copies ; Format 2 (sixteen colours)
fall through ↓

Build the shifted copies for MODEs 1 and 5

Three copies, each one pixel further right.

86EC .build_4colour_copies←2← 86E3 BEQ← 86E7 BEQ
JSR shift_4colour_copy ; First copy, 1 pixel right
86EF JSR shift_4colour_copy ; Second copy, 2 pixels right

Make the next copy one 4-colour pixel further right

Shift the 64-byte copy at zp_image_ptr right by one pixel into zp_under_ptr, for MODEs 1 and 5, where a byte holds 4 pixels with the two bits of pixel n in bits 7-n and 3-n. Each of the 16 rows is shifted across its 4 bytes, carrying the rightmost pixel of each byte into the leftmost of the next. Only the pixel's low colour bit is carried: for an image the high bit of the pixel shifted in is 0, for a mask it is a copy of the low bit, which is right for images drawn in colours 0 and 1 and for masks whose pixels are all-0 or all-1. Then step on to the next copy (advance_to_next_copy).

86F2 .shift_4colour_copy←2← 86EC JSR← 86EF JSR
LDX #0 ; Row 0
86F4 .shift_4colour_row←1← 8722 BNE
LDA zp_temp ; Carry = the fill bit: 1 for a mask...
86F6 CMP #&ff ; ...
86F8 LDA #0 ; Column 0
86FA PHP ; Carry into the first byte of the row
86FB .shift_4colour_byte←1← 871C BNE
STA zp_image_index ; Byte index = column * 16 + row
86FD TXA ; ...
86FE ORA zp_image_index ; ...
8700 TAY ; ...
8701 LDA (zp_image_ptr),y ; Source byte
8703 PLP ; Carry from the byte to the left
8704 BCS shift_4colour_set_bit4 ; Set: put it in bit 4 (becomes bit 3)
8706 AND #&ef ; Clear: clear bit 4
8708 BCC shift_4colour_high_bit ; Always taken (carry clear)
870A .shift_4colour_set_bit4←1← 8704 BCS
ORA #&10 ; ...
870C .shift_4colour_high_bit←1← 8708 BCC
BIT zp_temp ; Mask: keep the carry for bit 7
870E BMI shift_4colour_rotate ; ...
8710 CLC ; Image: bit 7 = 0
8711 .shift_4colour_rotate←1← 870E BMI
ROR ; Shift right one pixel; carry = old bit 0
8712 PHP ; Keep the carry for the next byte
8713 STA (zp_under_ptr),y ; Store the shifted byte
8715 LDA zp_image_index ; Next column...
8717 CLC ; ...
8718 ADC #&10 ; ...
871A CMP #&40 ; of the 4
871C BNE shift_4colour_byte ; ...
871E PLP ; Drop the last carry
871F INX ; Next row...
8720 CPX #&10 ; of the 16
8722 BNE shift_4colour_row ; ...
fall through ↓

Step on to the next shifted copy

Make the copy just built the source, and the next 64 bytes the destination.

8724 .advance_to_next_copy←3← 874A JMP← 87B2 JMP← 87BE JMP
LDA zp_image_ptr_hi ; Source = the copy just built...
8726 STA zp_under_ptr_hi ; ...
8728 LDA zp_under_ptr ; ...
872A STA zp_image_ptr ; ...
872C CLC ; Destination = 64 bytes further on
872D ADC #pointer_image_size ; ...
872F STA zp_under_ptr ; ...
8731 BCC return_from_shifting ; ...
8733 INC zp_under_ptr_hi ; ...
8735 .return_from_shifting←1← 8731 BCC
RTS ; Return
fall through ↓

Build the shifted copies for MODEs 0 and 4

Three copies, each two pixels further right.

8736 .build_2colour_copies←2← 86DB BEQ← 86DF BEQ
JSR shift_2colour_copy ; First copy, 2 pixels right
8739 JSR shift_2colour_copy ; Second copy, 4 pixels right

Make the next copy two 2-colour pixels further right

For MODEs 0 and 4, where a byte holds 8 pixels: shift the copy at zp_image_ptr right one pixel into zp_under_ptr, then shift that right one more pixel in place, then step on to the next copy.

873C .shift_2colour_copy←2← 8736 JSR← 8739 JSR
JSR shift_2colour_pixel ; Shift right one pixel into the destination
873F LDA zp_image_ptr_hi ; Then shift the destination in place...
8741 STA zp_under_ptr_hi ; ...
8743 LDA zp_under_ptr ; ...
8745 STA zp_image_ptr ; ...
8747 JSR shift_2colour_pixel ; by one more pixel
874A JMP advance_to_next_copy ; Step on to the next copy

Shift a 2-colour copy right one pixel

Shift each of the 16 rows of the copy at zp_image_ptr right one bit, across its 4 bytes, into zp_under_ptr, shifting in zp_temp's fill bit at the left.

874D .shift_2colour_pixel←2← 873C JSR← 8747 JSR
LDX #0 ; Row 0
874F .shift_2colour_row←1← 8770 BNE
LDA zp_temp ; Carry = the fill bit: 1 for a mask...
8751 CMP #&ff ; ...
8753 LDA #0 ; Column 0
8755 PHP ; Carry into the first byte of the row
8756 .shift_2colour_byte←1← 876A BNE
STA zp_image_index ; Byte index = column * 16 + row
8758 TXA ; ...
8759 ORA zp_image_index ; ...
875B TAY ; ...
875C LDA (zp_image_ptr),y ; Source byte
875E PLP ; Carry from the byte to the left
875F ROR ; Shift right one pixel
8760 PHP ; Keep the carry for the next byte
8761 STA (zp_under_ptr),y ; Store the shifted byte
8763 LDA zp_image_index ; Next column...
8765 CLC ; ...
8766 ADC #&10 ; ...
8768 CMP #&40 ; of the 4
876A BNE shift_2colour_byte ; ...
876C PLP ; Drop the last carry
876D INX ; Next row...
876E CPX #&10 ; of the 16
8770 BNE shift_2colour_row ; ...
8772 RTS ; Return

Build the shifted copies for MODE 2

A quarter of a screen byte is half a pixel, so the copies are the original, the original again, one pixel right, and that again.

8773 .build_16colour_copies←1← 86E9 JMP
JSR copy_unshifted ; First copy: unshifted
8776 JSR shift_16colour_copy ; Second copy: one pixel right
8779 JMP copy_unshifted ; Third copy: the same as the second

Make the next copy one 16-colour pixel further right

For MODE 2, where a byte holds 2 pixels with the bits of the left pixel in bits 7, 5, 3 and 1 and the right pixel in bits 6, 4, 2 and 0: move the left pixel of each byte to the right, and bring in the right pixel of the byte to the left as the new left pixel. Only that pixel's lowest colour bit is carried: if it is set, a mask's new pixel is all ones and an image's is colour 1; otherwise it is 0. The first byte of each row takes the fill bit. Then step on to the next copy.

877C .shift_16colour_copy←1← 8776 JSR
LDX #0 ; Row 0
877E .shift_16colour_row←1← 87B0 BNE
LDA zp_temp ; Carry = the fill bit: 1 for a mask...
8780 CMP #&ff ; ...
8782 LDA #0 ; Column 0
8784 PHP ; Carry into the first byte of the row
8785 .shift_16colour_byte←1← 87AA BNE
STA zp_image_index ; Byte index = column * 16 + row
8787 TXA ; ...
8788 ORA zp_image_index ; ...
878A TAY ; ...
878B LDA (zp_image_ptr),y ; Source byte: its left pixel...
878D AND #&aa ; ...
878F LSR ; ...moves to the right
8790 PLP ; Was the left neighbour's right pixel set?
8791 BCC shift_16colour_store ; No: new left pixel is 0
8793 BIT zp_temp ; Yes: for a mask...
8795 BPL shift_16colour_set_pixel ; ...
8797 ORA #&aa ; ...the new left pixel is all ones
8799 .shift_16colour_set_pixel←1← 8795 BPL
ORA #2 ; For an image, colour 1
879B .shift_16colour_store←1← 8791 BCC
STA (zp_under_ptr),y ; Store the shifted byte
879D LDA (zp_image_ptr),y ; This byte's right pixel...
879F AND #&55 ; ...
87A1 LSR ; ...lowest bit into the carry
87A2 PHP ; Keep it for the next byte
87A3 LDA zp_image_index ; Next column...
87A5 CLC ; ...
87A6 ADC #&10 ; ...
87A8 CMP #&40 ; of the 4
87AA BNE shift_16colour_byte ; ...
87AC PLP ; Drop the last carry
87AD INX ; Next row...
87AE CPX #&10 ; of the 16
87B0 BNE shift_16colour_row ; ...
87B2 JMP advance_to_next_copy ; Step on to the next copy

Make the next copy the same as the last

Copy the 64 bytes at zp_image_ptr to zp_under_ptr, then step on to the next copy. Used in MODE 2, where a quarter-byte step is half a pixel.

87B5 .copy_unshifted←2← 8773 JSR← 8779 JMP
LDY #&3f ; 64 bytes
87B7 .copy_unshifted_byte←1← 87BC BPL
LDA (zp_image_ptr),y ; Copy a byte
87B9 STA (zp_under_ptr),y ; ...
87BB DEY ; Next
87BC BPL copy_unshifted_byte ; ...
87BE JMP advance_to_next_copy ; Step on to the next copy

OSBYTE handler: ADVAL(5) to ADVAL(9)

Reached through BYTEV, by way of the extended vector entry, for every OSBYTE call while the driver is on. OSBYTE &80 (ADVAL) with X from 5 to 9 is answered here; every other call goes on to the previous BYTEV.

X ADVAL Returns in X (low) and Y (high)
5 ADVAL(5) *TMAX x
6 ADVAL(6) *TMAX y
7 ADVAL(7) pointer X, 0-1276
8 ADVAL(8) pointer Y, 0-1020
9 ADVAL(9) device mode (0, &20, &40 or &80)

ADVAL(0)-(4), and channels 10 and above, remain the MOS's.

For channels 5-8 the stored workspace is brought in to read the value and put back, with interrupts disabled. The device mode is outside the exchanged area and is read directly. Channels 5-8 return with A=&80 and V clear; channel 9 returns with A=&80 and V unchanged.

On EntryAOSBYTE number
Xfirst parameter (ADVAL channel)
On ExitA&80
Xvalue, low byte
Yvalue, high byte
87C1 .bytev_handler
CMP #osbyte_read_adc ; OSBYTE &80 (ADVAL)?
87C3 BEQ bytev_adval ; Yes
87C5 .pass_to_previous_bytev←2← 87CC BCS← 87D0 BCC
JMP (saved_bytev) ; No: on to the previous OSBYTE handler
87C8 .bytev_adval←1← 87C3 BEQ
CPX #9 ; ADVAL(9)?
87CA BEQ read_device_mode ; Yes: return the device mode
87CC BCS pass_to_previous_bytev ; Channel 10 and up (or negative): not ours
87CE CPX #5 ; Channel 4 or below?
87D0 BCC pass_to_previous_bytev ; Yes: not ours
87D2 PHP ; Save the flags and disable interrupts
87D3 SEI ; ...
87D4 JSR exchange_workspace ; Bring in the workspace
87D7 TXA ; Offset = 2 * channel - 10...
87D8 ASL ; ...(ASL leaves carry clear)
87D9 ADC #&f6 ; ...
87DB TAY ; ...
87DC LDA tmax_x,y ; Value low byte
87DF TAX ; ...into X
87E0 INY ; Value high byte
87E1 LDA tmax_x,y ; ...
87E4 TAY ; ...into Y
87E5 JSR exchange_workspace ; Put the workspace back
87E8 PLP ; Restore the flags
87E9 .return_adval←1← 8823 BEQ
LDA #&80 ; A = &80, as for OSBYTE &80
87EB CLV ; V clear
87EC RTS ; Return to the OSBYTE caller
87ED .read_device_mode←1← 87CA BEQ
LDY #0 ; High byte 0
87EF LDX device_mode ; Low byte: the device mode
87F2 RTS ; Return to the OSBYTE caller

Read the mouse buttons (not used)

Nothing in the ROM calls this routine or holds its address.

It reads the three mouse buttons from User VIA port B and returns them as an OSBYTE &80 result would be: A=&80, X = the buttons (bit set = pressed) and Y=0. If the pinout has not yet been detected, it is taken to be AMX if any of PB5-PB7 is low (a button is pressed), and recorded; otherwise the Compact pinout is used for this read only. With the AMX pinout, PB5-PB7 are rotated down to bits 0-2.

This is the button-reading form of ADVAL(9) used by other mouse drivers; in PMFS, ADVAL(9) returns the device mode instead.

On ExitA&80
Xbuttons, bits 0-2, 1 = pressed
Y0
87F3 .read_mouse_buttons
PHP ; Save the flags and disable interrupts
87F4 SEI ; ...
87F5 JSR exchange_workspace ; Bring in the workspace
87F8 LDX pinout_index ; Pinout detected?
87FB BPL read_mouse_buttons_port ; Yes
87FD LDX #0 ; Assume the Compact pinout
87FF LDA user_via_orb_irb ; Are PB5-PB7 all high...
8802 AND #&e0 ; ...
8804 CMP #&e0 ; ...(no AMX button pressed)?
8806 BEQ read_mouse_buttons_port ; Yes: Compact, for this read
8808 LDX #7 ; No: the AMX pinout...
880A STX pinout_index ; ...recorded
880D .read_mouse_buttons_port←2← 87FB BPL← 8806 BEQ
LDA user_via_orb_irb ; Read port B
8810 CPX #0 ; Compact pinout?
8812 BEQ read_mouse_buttons_bits ; Yes: buttons are PB0-PB2
8814 ROL ; AMX: rotate PB5-PB7...
8815 ROL ; ...through the carry...
8816 ROL ; ...
8817 ROL ; ...into bits 0-2
8818 .read_mouse_buttons_bits←1← 8812 BEQ
AND #7 ; Keep the three button bits
881A EOR #7 ; 1 = pressed (the inputs are low when pressed)
881C TAX ; X = buttons
881D JSR exchange_workspace ; Put the workspace back
8820 PLP ; Restore the flags
8821 LDY #0 ; Y = 0
8823 BEQ return_adval ; Always taken: return A=&80
fall through ↓

Interrupt handler: mouse movement

Reached on every interrupt while the driver is on: IRQ1V points at irq1v_trampoline, whose JSR to the IRQ1V extended vector entry pages in this ROM and calls here, and whose JMP then goes on to the previous IRQ1V handler. So the interrupt is never claimed; the MOS handles it too.

If the User VIA's CB1 or CB2 interrupt is enabled and either has occurred, the first ten bytes of the workspace (the pointer position, the pinout and the redraw countdown) are brought in, the pointer is moved (mouse_movement), and they are put back. The CB1 and CB2 interrupts are only enabled in mouse mode.

On ExitApreserved
Xpreserved
Ypreserved
FLAGSpreserved
8825 .irq_handler
PHP ; Save the flags
8826 PHA ; and the registers
8827 PHX ; ...
8828 PHY ; ...
8829 LDA user_via_ier ; Are CB1 or CB2 interrupts enabled?
882C AND #via_ier_disable_cb1_cb2 ; ...
882E BEQ irq_return ; No: not a mouse interrupt
8830 LDA user_via_ifr ; Has CB1 or CB2 interrupted?
8833 AND #via_ier_disable_cb1_cb2 ; ...
8835 BEQ irq_return ; No: not a mouse interrupt
8837 JSR exchange_position_workspace ; Bring in the position workspace
883A TAY ; Y = which of CB1 and CB2 interrupted
883B JSR mouse_movement ; Move the pointer
883E JSR exchange_position_workspace ; Put the position workspace back
8841 .irq_return←2← 882E BEQ← 8835 BEQ
JMP restore_registers_and_return ; Restore everything and return to the trampoline

Poll: move the pointer with the joystick or keys

The first half of the polling service call (&15), issued by the MOS every centisecond while the driver is on. Moves the pointer according to the device mode:

Mode Device Input Left / right Up / down
0 Mouse none here: irq_handler moves the pointer
&80 Analogue joystick ADVAL(1), ADVAL(2) high bytes ch 1 >= &C0 / < &40 ch 2 >= &C0 / < &40
&40 Digital joystick ADVAL(0) low byte bit 4 / bit 7 bit 6 / bit 5
&20 Cursor keys INKEY -26, -122, -58, -42 left / right up / down

When an axis is not moving, its speed is reset. With the cursor keys, holding SHIFT accelerates both speeds faster. Runs with interrupts disabled, inside enter_driver and leave_driver.

On ExitApreserved
Xpreserved
Ypreserved
FLAGSpreserved
8844 .poll_move_pointer←1← 8161 JSR
PHP ; Save the flags
8845 SEI ; Interrupts off while the workspace is in use
8846 PHA ; Save the registers
8847 PHX ; ...
8848 PHY ; ...
8849 JSR enter_driver ; Bring in the workspace, save zero page
884C LDA device_mode ; Device mode
884F BNE poll_not_mouse ; Not the mouse
8851 JMP finish_poll_move ; Mouse: nothing to do here
8854 .poll_not_mouse←1← 884F BNE
BPL poll_digital_or_keys ; Bit 7 clear: digital joystick or keys
8856 JMP poll_joystick ; Analogue joystick
8859 .poll_digital_or_keys←1← 8854 BPL
CMP #device_mode_digital ; Digital joystick?
885B BEQ poll_digital ; Yes
885D JMP poll_keys ; No: cursor keys
8860 .poll_digital←1← 885B BEQ
LDA #osbyte_read_adc_or_get_buffer_status ; OSBYTE &80 with X=0: ADVAL(0)...
8862 LDX #0 ; ...
8864 LDY #0 ; ...
8866 JSR osbyte ; ... Read ADC channel X or buffer status
8869 TXA ; Bit 4 of the low byte: left?
886A AND #&10 ; ...
886C BEQ poll_digital_right ; No
886E JSR move_pointer_left ; Yes: move left
8871 BRA poll_digital_vertical ; ...
8873 .poll_digital_right←1← 886C BEQ
TXA ; Bit 7: right?
8874 BPL poll_digital_x_still ; No
8876 JSR move_pointer_right ; Yes: move right
8879 BRA poll_digital_vertical ; ...
887B .poll_digital_x_still←1← 8874 BPL
JSR reset_x_speed ; Neither: reset the horizontal speed
887E .poll_digital_vertical←2← 8871 BRA← 8879 BRA
TXA ; Bit 6: up?
887F AND #&40 ; ...
8881 BEQ poll_digital_down ; No
8883 JSR move_pointer_up ; Yes: move up
8886 BRA poll_digital_done ; ...
8888 .poll_digital_down←1← 8881 BEQ
TXA ; Bit 5: down?
8889 AND #&20 ; ...
888B BEQ poll_digital_y_still ; No
888D JSR move_pointer_down ; Yes: move down
8890 BRA poll_digital_done ; ...
8892 .poll_digital_y_still←1← 888B BEQ
JSR reset_y_speed ; Neither: reset the vertical speed
8895 .poll_digital_done←2← 8886 BRA← 8890 BRA
BRA finish_poll_move ; Finish
8897 .poll_joystick←1← 8856 JMP
LDA #osbyte_read_adc_or_get_buffer_status ; OSBYTE &80 with X=1: ADVAL(1), horizontal
8899 LDX #1 ; ...
889B LDY #0 ; ...
889D JSR osbyte ; ... Read ADC channel X or buffer status
88A0 CPY #&c0 ; High byte &C0 or more: pushed left?
88A2 BCC poll_joystick_right ; No
88A4 JSR move_pointer_left ; Yes: move left
88A7 BRA poll_joystick_vertical ; ...
88A9 .poll_joystick_right←1← 88A2 BCC
CPY #&40 ; Below &40: pushed right?
88AB BCS poll_joystick_x_still ; No
88AD JSR move_pointer_right ; Yes: move right
88B0 BRA poll_joystick_vertical ; ...
88B2 .poll_joystick_x_still←1← 88AB BCS
JSR reset_x_speed ; Centred: reset the horizontal speed
88B5 .poll_joystick_vertical←2← 88A7 BRA← 88B0 BRA
LDA #osbyte_read_adc_or_get_buffer_status ; OSBYTE &80 with X=2: ADVAL(2), vertical
88B7 LDX #2 ; ...
88B9 LDY #0 ; ...
88BB JSR osbyte ; ... Read ADC channel X or buffer status
88BE CPY #&c0 ; High byte &C0 or more: pushed up?
88C0 BCC poll_joystick_down ; No
88C2 JSR move_pointer_up ; Yes: move up
88C5 BRA finish_poll_move ; ...
88C7 .poll_joystick_down←1← 88C0 BCC
CPY #&40 ; Below &40: pulled down?
88C9 BCS poll_joystick_y_still ; No
88CB JSR move_pointer_down ; Yes: move down
88CE BRA finish_poll_move ; ...
88D0 .poll_joystick_y_still←1← 88C9 BCS
JSR reset_y_speed ; Centred: reset the vertical speed
88D3 .finish_poll_move←5← 8851 JMP← 8895 BRA← 88C5 BRA← 88CE BRA← 894B BRA
JSR leave_driver ; Put back zero page and the workspace
88D6 JMP restore_registers_and_return ; Restore everything and return
fall through ↓

Poll the cursor keys

Device mode &20. SHIFT adds an extra &40 to both speeds, so the pointer accelerates five times as fast; then the cursor keys move it, each axis resetting its speed when neither of its keys is pressed.

88D9 .poll_keys←1← 885D JMP
LDA #osbyte_inkey ; OSBYTE &81 with X=-1: is SHIFT pressed?
88DB LDX #inkey_key_shift ; ...
88DD LDY #&ff ; ...
88DF JSR osbyte ; ... Test for shift key pressed
88E2 TXA ; X=&FF if pressed
88E3 BEQ poll_keys_left ; No
88E5 CLC ; Yes: add an extra &40 to the horizontal...
88E6 LDA #speed_shift_boost ; ...
88E8 ADC x_speed ; ...
88EB STA x_speed ; ...
88EE BCC poll_keys_boost_y ; ...
88F0 INC x_speed_hi ; ...
88F3 .poll_keys_boost_y←1← 88EE BCC
CLC ; and vertical speeds
88F4 LDA #speed_shift_boost ; ...
88F6 ADC y_speed ; ...
88F9 STA y_speed ; ...
88FC BCC poll_keys_left ; ...
88FE INC y_speed_hi ; ...
8901 .poll_keys_left←2← 88E3 BEQ← 88FC BCC
LDA #osbyte_inkey ; Cursor left pressed?
8903 LDX #inkey_key_left ; ...
8905 LDY #&ff ; ...
8907 JSR osbyte ; ... Test for left key pressed
890A TXA ; ...
890B BEQ poll_keys_right ; No
890D JSR move_pointer_left ; Yes: move left
8910 BRA poll_keys_up ; ...
8912 .poll_keys_right←1← 890B BEQ
LDA #osbyte_inkey ; Cursor right pressed?
8914 LDX #inkey_key_right ; ...
8916 LDY #&ff ; ...
8918 JSR osbyte ; ... Test for right key pressed
891B TXA ; ...
891C BEQ poll_keys_x_still ; No
891E JSR move_pointer_right ; Yes: move right
8921 BRA poll_keys_up ; ...
8923 .poll_keys_x_still←1← 891C BEQ
JSR reset_x_speed ; Neither: reset the horizontal speed
8926 .poll_keys_up←2← 8910 BRA← 8921 BRA
LDA #osbyte_inkey ; Cursor up pressed?
8928 LDX #inkey_key_up ; ...
892A LDY #&ff ; ...
892C JSR osbyte ; ... Test for up key pressed
892F TXA ; ...
8930 BEQ poll_keys_down ; No
8932 JSR move_pointer_up ; Yes: move up
8935 BRA poll_keys_done ; ...
8937 .poll_keys_down←1← 8930 BEQ
LDA #osbyte_inkey ; Cursor down pressed?
8939 LDX #inkey_key_down ; ...
893B LDY #&ff ; ...
893D JSR osbyte ; ... Test for down key pressed
8940 TXA ; ...
8941 BEQ poll_keys_y_still ; No
8943 JSR move_pointer_down ; Yes: move down
8946 BRA poll_keys_done ; ...
8948 .poll_keys_y_still←1← 8941 BEQ
JSR reset_y_speed ; Neither: reset the vertical speed
894B .poll_keys_done←2← 8935 BRA← 8946 BRA
BRA finish_poll_move ; Finish

Move the pointer left

Subtract the whole part of x_speed from pointer_x, stopping at 0, then accelerate: x_speed grows by &10 (1/16 of a graphics unit) each call.

On ExitAcorrupted
Xpreserved
Ypreserved
894D .move_pointer_left←3← 886E JSR← 88A4 JSR← 890D JSR
LDA pointer_x ; pointer_x -= whole part of the speed
8950 SEC ; ...
8951 SBC x_speed_hi ; ...
8954 STA pointer_x ; ...
8957 LDA pointer_x_hi ; ...
895A SBC #0 ; ...
895C STA pointer_x_hi ; ...
895F BPL accelerate_x_left ; Still 0 or more?
8961 STZ pointer_x_hi ; No: stop at 0
8964 STZ pointer_x ; ...
8967 .accelerate_x_left←1← 895F BPL
CLC ; x_speed += &10
8968 LDA #speed_acceleration ; ...
896A ADC x_speed ; ...
896D STA x_speed ; ...
8970 BCC return_from_move_left ; ...
8972 INC x_speed_hi ; ...
8975 .return_from_move_left←1← 8970 BCC
RTS ; Return

Move the pointer right

Add the whole part of x_speed to pointer_x, stopping at 1276 (&4FC), then accelerate: x_speed grows by &10 each call.

On ExitAcorrupted
Xpreserved
Ypreserved
8976 .move_pointer_right←3← 8876 JSR← 88AD JSR← 891E JSR
LDA pointer_x ; pointer_x += whole part of the speed
8979 CLC ; ...
897A ADC x_speed_hi ; ...
897D STA pointer_x ; ...
8980 LDA pointer_x_hi ; ...
8983 ADC #0 ; ...
8985 STA pointer_x_hi ; ...
8988 CMP #5 ; Beyond the right edge (high byte 5 or more)?
898A BCC accelerate_x_right ; No
898C LDA #>(pointer_x_max) ; Yes: stop at 1276 (&4FC)
898E STA pointer_x_hi ; ...
8991 LDA #<(pointer_x_max) ; ...
8993 STA pointer_x ; ...
8996 .accelerate_x_right←1← 898A BCC
CLC ; x_speed += &10
8997 LDA #speed_acceleration ; ...
8999 ADC x_speed ; ...
899C STA x_speed ; ...
899F BCC return_from_move_right ; ...
89A1 INC x_speed_hi ; ...
89A4 .return_from_move_right←1← 899F BCC
RTS ; Return

Move the pointer down

Subtract the whole part of y_speed from pointer_y, stopping at 0, then accelerate: y_speed grows by &10 each call.

On ExitAcorrupted
Xpreserved
Ypreserved
89A5 .move_pointer_down←3← 888D JSR← 88CB JSR← 8943 JSR
LDA pointer_y ; pointer_y -= whole part of the speed
89A8 SEC ; ...
89A9 SBC y_speed_hi ; ...
89AC STA pointer_y ; ...
89AF LDA pointer_y_hi ; ...
89B2 SBC #0 ; ...
89B4 STA pointer_y_hi ; ...
89B7 BPL accelerate_y_down ; Still 0 or more?
89B9 STZ pointer_y ; No: stop at 0
89BC STZ pointer_y_hi ; ...
89BF .accelerate_y_down←1← 89B7 BPL
CLC ; y_speed += &10
89C0 LDA #speed_acceleration ; ...
89C2 ADC y_speed ; ...
89C5 STA y_speed ; ...
89C8 BCC return_from_move_down ; ...
89CA INC y_speed_hi ; ...
89CD .return_from_move_down←1← 89C8 BCC
RTS ; Return

Move the pointer up

Add the whole part of y_speed to pointer_y, stopping at 1020 (&3FC), then accelerate: y_speed grows by &10 each call.

On ExitAcorrupted
Xpreserved
Ypreserved
89CE .move_pointer_up←3← 8883 JSR← 88C2 JSR← 8932 JSR
LDA pointer_y ; pointer_y += whole part of the speed
89D1 CLC ; ...
89D2 ADC y_speed_hi ; ...
89D5 STA pointer_y ; ...
89D8 LDA pointer_y_hi ; ...
89DB ADC #0 ; ...
89DD STA pointer_y_hi ; ...
89E0 CMP #4 ; Beyond the top (high byte 4 or more)?
89E2 BCC accelerate_y_up ; No
89E4 LDA #>(pointer_y_max) ; Yes: stop at 1020 (&3FC)
89E6 STA pointer_y_hi ; ...
89E9 LDA #<(pointer_y_max) ; ...
89EB STA pointer_y ; ...
89EE .accelerate_y_up←1← 89E2 BCC
CLC ; y_speed += &10
89EF LDA #speed_acceleration ; ...
89F1 ADC y_speed ; ...
89F4 STA y_speed ; ...
89F7 BCC return_from_move_up ; ...
89F9 INC y_speed_hi ; ...
89FC .return_from_move_up←1← 89F7 BCC
RTS ; Return

Reset the horizontal speed

Set x_speed to &0080, half a graphics unit: the first step after starting to move is 0, and steps grow by one unit every 16 polls.

89FD .reset_x_speed←4← 82BD JSR← 887B JSR← 88B2 JSR← 8923 JSR
STZ x_speed_hi ; Whole part 0
8A00 LDA #speed_initial ; Fraction one half
8A02 STA x_speed ; ...
8A05 RTS ; Return

Reset the vertical speed

Set y_speed to &0080, as reset_x_speed.

8A06 .reset_y_speed←4← 82C0 JSR← 8892 JSR← 88D0 JSR← 8948 JSR
STZ y_speed_hi ; Whole part 0
8A09 LDA #speed_initial ; Fraction one half
8A0B STA y_speed ; ...
8A0E RTS ; Return

Poll: redraw the pointer and read the buttons

The second half of the polling service call. If the pointer is shown, count down redraw_countdown and redraw the pointer when it goes negative (update_pointer, which only draws if the pointer has moved, and restarts the count at 10). Mouse interrupts also count it down, so a moving mouse is redrawn sooner. Then read the buttons (scan_buttons). Runs with interrupts disabled, inside enter_driver and leave_driver.

On ExitApreserved
Xpreserved
Ypreserved
FLAGSpreserved
8A0F .poll_redraw_and_buttons←1← 8164 JMP
PHP ; Save the flags
8A10 PHA ; and the registers
8A11 PHX ; ...
8A12 PHY ; ...
8A13 SEI ; Interrupts off while the workspace is in use
8A14 JSR enter_driver ; Bring in the workspace, save zero page
8A17 LDA pointer_shown ; Is the pointer shown?
8A1A BEQ poll_buttons ; No
8A1C DEC redraw_countdown ; Count down to the next redraw
8A1F BPL poll_buttons ; Not yet
8A21 JSR update_pointer ; Redraw it if it has moved
8A24 .poll_buttons←2← 8A1A BEQ← 8A1F BPL
JSR scan_buttons ; Read the buttons
8A27 JSR leave_driver ; Put back zero page and the workspace
8A2A JMP restore_registers_and_return ; Restore everything and return

Read the buttons and turn presses into keys

Read the buttons and, when a new button state has been seen on two polls running, put a key into the keyboard buffer (OSBYTE &99) for any button pressed in it:

Device Button Key
Mouse left (Compact PB0, AMX PB5) RETURN (&0D)
Mouse right (Compact PB2, AMX PB7) &C0
Mouse middle (Compact PB1, AMX PB6) the TAB key's code (OSBYTE &DB)
Joysticks fire button 1 (ADVAL(0) bit 0) RETURN (&0D)
Joysticks fire button 2 (ADVAL(0) bit 1) the TAB key's code
Keys none

One key is sent per change, with priority in the order listed. The mouse buttons are read from User VIA port B, where a pressed button reads low, through pinout_table. If the pinout is not yet known, it is taken to be AMX if any of PB5-PB7 is low, and recorded; otherwise the Compact pinout is used for this read only.

The debounce: button_state holds the last reading and button_pending a change waiting to be confirmed. A reading different from both is stored in both. A reading equal to button_pending is a confirmed change: the pending change is cleared and the keys are sent for button_state.

0 doubles as "nothing pending", so a reading of 0 (all three mouse buttons pressed, or both fire buttons) is never recorded: at every poll while it lasts it is taken as confirming a change, and the keys for button_state, the last other reading, are sent again.

On ExitAcorrupted
Xcorrupted
Ycorrupted
8A2D .scan_buttons←1← 8A24 JSR
LDX device_mode ; Device mode
8A30 BNE scan_joystick_buttons ; Not the mouse
8A32 LDX pinout_index ; Mouse: is the pinout known?
8A35 BPL scan_mouse_buttons ; Yes
8A37 LDX #0 ; Assume the Compact pinout
8A39 LDA user_via_orb_irb ; Are PB5-PB7 all high...
8A3C AND #&e0 ; ...
8A3E CMP #&e0 ; ...(no AMX button pressed)?
8A40 BEQ scan_mouse_buttons ; Yes: Compact, for this read
8A42 LDX #7 ; No: the AMX pinout...
8A44 STX pinout_index ; ...recorded
8A47 .scan_mouse_buttons←2← 8A35 BPL← 8A40 BEQ
LDA user_via_orb_irb ; Read port B...
8A4A AND pinout_table + 1,x ; ...keeping the button bits
8A4D CMP button_pending ; The pending change confirmed?
8A50 BEQ mouse_buttons_changed ; Yes: send the keys
8A52 CMP button_state ; Same as the last reading?
8A55 STA button_state ; Keep this reading
8A58 BEQ return_from_buttons ; Same: nothing to do
8A5A STA button_pending ; Changed: wait for the next poll to confirm it
8A5D .return_from_buttons←4← 8A58 BEQ← 8A7C BEQ← 8A8A BEQ← 8A9D BEQ
RTS ; Return
8A5E .scan_joystick_buttons←1← 8A30 BNE
CPX #device_mode_keys ; Cursor keys?
8A60 BNE read_fire_buttons ; No: joystick fire buttons
8A62 RTS ; Yes: no buttons
8A63 .read_fire_buttons←1← 8A60 BNE
LDA #osbyte_read_adc_or_get_buffer_status ; OSBYTE &80 with X=0: ADVAL(0)
8A65 LDX #0 ; ...
8A67 LDY #0 ; ...
8A69 JSR osbyte ; ... Read ADC channel X or buffer status
8A6C TXA ; The two fire button bits...
8A6D AND #3 ; ...
8A6F EOR #3 ; ...inverted, so 0 = pressed as for the mouse
8A71 CMP button_pending ; The pending change confirmed?
8A74 BEQ joystick_buttons_changed ; Yes: send the keys
8A76 CMP button_state ; Same as the last reading?
8A79 STA button_state ; Keep this reading
8A7C BEQ return_from_buttons ; Same: nothing to do
8A7E STA button_pending ; Changed: wait for the next poll to confirm it
8A81 RTS ; Return
8A82 .joystick_buttons_changed←1← 8A74 BEQ
STZ button_pending ; Nothing pending now
8A85 LDA button_state ; Both buttons released?
8A88 CMP #3 ; ...
8A8A BEQ return_from_buttons ; Yes: no key
8A8C LDY #key_return ; RETURN...
8A8E AND #1 ; ...if fire button 1 is pressed
8A90 BEQ insert_key ; ...
8A92 BRA insert_tab_key ; Otherwise fire button 2: TAB
8A94 .mouse_buttons_changed←1← 8A50 BEQ
STZ button_pending ; Nothing pending now
8A97 LDA button_state ; All buttons released?
8A9A CMP pinout_table + 1,x ; ...
8A9D BEQ return_from_buttons ; Yes: no key
8A9F LDY #key_return ; RETURN...
8AA1 AND pinout_table + 2,x ; ...if the left button is pressed
8AA4 BEQ insert_key ; ...
8AA6 LDA button_state ; &C0...
8AA9 LDY #key_right_button ; ...
8AAB AND pinout_table + 4,x ; ...if the right button is pressed
8AAE BEQ insert_key ; ...
8AB0 .insert_tab_key←1← 8A92 BRA
LDA #osbyte_tab_char ; Otherwise the middle button: OSBYTE &DB, the TAB key code
8AB2 LDX #0 ; X=0...
8AB4 LDY #&ff ; ...and Y=&FF: read it without changing it
8AB6 JSR osbyte ; ... osbyte: tab char
8AB9 TXA ; ...
8ABA TAY ; Y = that code
8ABB .insert_key←3← 8A90 BEQ← 8AA4 BEQ← 8AAE BEQ
LDA #osbyte_insert_input_buffer ; OSBYTE &99: put Y into the keyboard buffer
8ABD LDX #0 ; (buffer 0) as if typed, and return
8ABF JMP osbyte ; ... Insert byte Y into input buffer X

Move the pointer for a mouse interrupt

Called from irq_handler with the User VIA interrupt flags for CB1 and CB2 in Y. The mouse's two quadrature channels interrupt on CB1 (X) and CB2 (Y); at each interrupt the other signal of the channel, read from a port B bit, gives the direction:

Pinout X direction Y direction
Compact (joystick port) PB3 PB4
AMX (User Port) PB0 PB2

Each interrupt moves the pointer 4 graphics units, high meaning right or up and low left or down, clamped to 0-1276 and 0-1020. Only one edge of one signal per channel interrupts, so there is one step per quadrature cycle. Reading port B also clears the CB1 and CB2 interrupt flags.

If the pinout is not yet known, it is taken to be Compact if either of PB3 and PB4 is low, and recorded; otherwise the AMX pinout is used for this interrupt only. Each interrupt also counts down redraw_countdown.

On EntryYinterrupt flags: bit 4 CB1, bit 3 CB2
On ExitAcorrupted
Xcorrupted
Ypreserved
8AC2 .mouse_movement←1← 883B JSR
DEC redraw_countdown ; Bring the next redraw forward
8AC5 LDX pinout_index ; Is the pinout known?
8AC8 BPL mouse_movement_x ; Yes
8ACA LDX #7 ; Assume AMX
8ACC LDA user_via_orb_irb ; Are PB3 and PB4 both high?
8ACF AND #&18 ; ...
8AD1 CMP #&18 ; ...
8AD3 BEQ mouse_movement_x ; Yes: AMX, for this interrupt
8AD5 LDX #0 ; No: the Compact pinout...
8AD7 STX pinout_index ; ...recorded
8ADA .mouse_movement_x←2← 8AC8 BPL← 8AD3 BEQ
TYA ; Did CB1 (X) interrupt?
8ADB AND #via_int_cb1 ; ...
8ADD BEQ mouse_movement_y ; No: check Y
8ADF LDA user_via_orb_irb ; Read the X direction bit
8AE2 AND pinout_table + 6,x ; ...
8AE5 BEQ mouse_left ; Low: left
8AE7 LDA pointer_x_hi ; High: right. Already at 1276 (&4FC)?
8AEA CMP #4 ; ...
8AEC BNE mouse_right ; No
8AEE LDA pointer_x ; ...
8AF1 CMP #&fc ; ...
8AF3 BCS mouse_movement_y ; Yes: stay there
8AF5 .mouse_right←1← 8AEC BNE
LDA pointer_x ; pointer_x += 4 (carry clear from the CMP)
8AF8 ADC #4 ; ...
8AFA STA pointer_x ; ...
8AFD BCC mouse_x_done ; ...
8AFF INC pointer_x_hi ; ...
8B02 .mouse_x_done←1← 8AFD BCC
BRA mouse_movement_y ; Go on to Y
8B04 .mouse_left←1← 8AE5 BEQ
LDA pointer_x ; Already at 0?
8B07 BNE mouse_left_step ; No
8B09 LDA pointer_x_hi ; ...
8B0C BEQ mouse_movement_y ; Yes: stay there
8B0E LDA pointer_x ; ...
8B11 .mouse_left_step←1← 8B07 BNE
SEC ; pointer_x -= 4
8B12 SBC #4 ; ...
8B14 STA pointer_x ; ...
8B17 LDA pointer_x_hi ; ...
8B1A SBC #0 ; ...
8B1C STA pointer_x_hi ; ...
8B1F .mouse_movement_y←4← 8ADD BEQ← 8AF3 BCS← 8B02 BRA← 8B0C BEQ
TYA ; Did CB2 (Y) interrupt?
8B20 AND #via_int_cb2 ; ...
8B22 BEQ return_from_mouse_movement ; No: done
8B24 LDA user_via_orb_irb ; Read the Y direction bit
8B27 AND pinout_table + 5,x ; ...
8B2A BEQ mouse_down ; Low: down
8B2C LDA pointer_y_hi ; High: up. Already at 1020 (&3FC)?
8B2F CMP #3 ; ...
8B31 BNE mouse_up ; No
8B33 LDA pointer_y ; ...
8B36 CMP #&fc ; ...
8B38 BCS return_from_mouse_movement ; Yes: stay there
8B3A .mouse_up←1← 8B31 BNE
LDA pointer_y ; pointer_y += 4 (carry clear from the CMP)
8B3D ADC #4 ; ...
8B3F STA pointer_y ; ...
8B42 BNE return_from_mouse_up ; ...
8B44 INC pointer_y_hi ; ...
8B47 .return_from_mouse_up←1← 8B42 BNE
RTS ; Return
8B48 .mouse_down←1← 8B2A BEQ
LDA pointer_y ; Already at 0?
8B4B BNE mouse_down_step ; No
8B4D LDA pointer_y_hi ; ...
8B50 BEQ return_from_mouse_movement ; Yes: stay there
8B52 LDA pointer_y ; ...
8B55 .mouse_down_step←1← 8B4B BNE
SEC ; pointer_y -= 4
8B56 SBC #4 ; ...
8B58 STA pointer_y ; ...
8B5B LDA pointer_y_hi ; ...
8B5E SBC #0 ; ...
8B60 STA pointer_y_hi ; ...
8B63 .return_from_mouse_movement←3← 8B22 BEQ← 8B38 BCS← 8B50 BEQ
RTS ; Return

Mouse pinout table

Two 7-byte records of User VIA port B masks, one for each way of wiring a mouse, indexed by pinout_index (0 or 7):

Offset Use Compact (0) AMX (7)
+0 both direction bits (not read) &18: PB3, PB4 &05: PB0, PB2
+1 all three buttons &07: PB0-PB2 &E0: PB5-PB7
+2 left button &01: PB0 &20: PB5
+3 middle button (not read) &02: PB1 &40: PB6
+4 right button &04: PB2 &80: PB7
+5 Y direction &10: PB4 &04: PB2
+6 X direction &08: PB3 &01: PB0

The code reads offsets 1, 2, 4, 5 and 6; it tests the direction bits for pinout detection with a literal &18.

8B64 .pinout_table
EQUB &18 ; Compact: direction bits
8B65 EQUB &07 ; Compact: buttons
8B66 EQUB &01 ; Compact: left button
8B67 EQUB &02 ; Compact: middle button
8B68 EQUB &04 ; Compact: right button
8B69 EQUB &10 ; Compact: Y direction
8B6A EQUB &08 ; Compact: X direction
8B6B EQUB &05 ; AMX: direction bits
8B6C EQUB &E0 ; AMX: buttons
8B6D EQUB &20 ; AMX: left button
8B6E EQUB &40 ; AMX: middle button
8B6F EQUB &80 ; AMX: right button
8B70 EQUB &04 ; AMX: Y direction
8B71 EQUB &01 ; AMX: X direction

Exchange the working and stored pointer position

As exchange_workspace, but for the first ten bytes only (&9000-&9009: the *TMAX values, the pointer position, the pinout and the redraw countdown), which is all the mouse interrupt needs.

On ExitApreserved
Xcorrupted
Ycorrupted
8B72 .exchange_position_workspace←2← 8837 JSR← 883E JSR
PHA ; Save A
8B73 LDA zp_image_ptr ; and the zero page pointer used
8B75 PHA ; ...
8B76 LDA zp_image_ptr_hi ; ...
8B78 PHA ; ...
8B79 LDX romsel_copy ; Point it at the stored copy: page +3...
8B7B LDA rom_workspace_table,x ; ...
8B7E CLC ; ...
8B7F ADC #3 ; ...
8B81 STA zp_image_ptr_hi ; ...
8B83 LDA #&40 ; offset &40
8B85 STA zp_image_ptr ; ...
8B87 LDY #9 ; 10 bytes, from the last
8B89 .exchange_position_byte←1← 8B95 BPL
LDX tmax_x,y ; Working byte
8B8C LDA (zp_image_ptr),y ; Stored byte...
8B8E STA tmax_x,y ; ...becomes the working byte
8B91 TXA ; Working byte...
8B92 STA (zp_image_ptr),y ; ...becomes the stored byte
8B94 DEY ; Next
8B95 BPL exchange_position_byte ; ...
8B97 PLA ; Restore the zero page pointer
8B98 STA zp_image_ptr_hi ; ...
8B9A PLA ; ...
8B9B STA zp_image_ptr ; ...
8B9D PLA ; Restore A
8B9E RTS ; Return

Read a decimal number from the command line

Read decimal digits at (cmd_ptr),Y into parsed_number, up to a space, comma or CR. Any other character raises "Bad number" (check_digit). Returns with carry set if there were no digits or the value exceeded 65535.

On EntryYoffset of the number
On ExitPARSED_NUMBERthe value
FLAGSC clear if a number was read, set otherwise
Yoffset of the terminator
Acorrupted
8B9F .parse_number←4← 8C0E JSR← 8C1E JSR← 8C4B JSR← 8C5B JSR
LDA #0 ; Value = 0
8BA1 STA parsed_number ; ...
8BA4 STA parsed_number_hi ; ...
8BA7 SEC ; Carry set on the stack: no digits yet
8BA8 PHP ; ...
8BA9 .parse_number_char←1← 8C04 BNE
LDA (cmd_ptr),y ; Next character
8BAB CMP #' ' ; Space?
8BAD BEQ parse_number_done ; Yes: end of the number
8BAF CMP #',' ; Comma?
8BB1 BEQ parse_number_done ; Yes: end of the number
8BB3 CMP #key_return ; CR?
8BB5 BEQ parse_number_done ; Yes: end of the number
8BB7 JSR check_digit ; Anything but a digit: "Bad number"
8BBA LDA parsed_number ; Copy the value so far
8BBD STA parse_temp ; ...
8BC0 LDA parsed_number_hi ; ...
8BC3 STA parse_temp_hi ; ...
8BC6 LDA parsed_number ; Value * 2...
8BC9 ASL ; ...
8BCA ROL parsed_number_hi ; ...
8BCD BCS parse_number_too_big ; Too big
8BCF ASL ; * 4...
8BD0 ROL parsed_number_hi ; ...
8BD3 BCS parse_number_too_big ; Too big
8BD5 ADC parse_temp ; + the copy = * 5...
8BD8 STA parsed_number ; ...
8BDB LDA parsed_number_hi ; ...
8BDE ADC parse_temp_hi ; ...
8BE1 BCS parse_number_too_big ; Too big
8BE3 STA parsed_number_hi ; ...
8BE6 ASL parsed_number ; * 2 = * 10
8BE9 ROL parsed_number_hi ; ...
8BEC BCS parse_number_too_big ; Too big
8BEE LDA (cmd_ptr),y ; Add the digit
8BF0 AND #&0f ; ...
8BF2 CLC ; ...
8BF3 ADC parsed_number ; ...
8BF6 STA parsed_number ; ...
8BF9 BCC parse_number_digit_done ; ...
8BFB INC parsed_number_hi ; ...
8BFE BEQ parse_number_too_big ; Too big
8C00 .parse_number_digit_done←1← 8BF9 BCC
PLP ; Carry clear on the stack: a digit was read
8C01 CLC ; ...
8C02 PHP ; ...
8C03 INY ; Next character
8C04 BNE parse_number_char ; Always taken (Y does not wrap)
8C06 .parse_number_too_big←5← 8BCD BCS← 8BD3 BCS← 8BE1 BCS← 8BEC BCS← 8BFE BEQ
PLP ; Carry set on the stack: failed
8C07 SEC ; ...
8C08 PHP ; ...
8C09 .parse_number_done←3← 8BAD BEQ← 8BB1 BEQ← 8BB5 BEQ
PLP ; Carry = the result
8C0A RTS ; Return

*TMAX x,y: set the values returned by ADVAL(5) and ADVAL(6)

Read two numbers, 0-65535, separated by spaces or commas, and store them in tmax_x and tmax_y. Nothing else in PMFS uses them; in particular the pointer is not limited by them. A missing, malformed or too-large number gives "Bad number".

8C0B .cmd_tmax
JSR reset_argument_index ; First argument
8C0E JSR parse_number ; Read x
8C11 BCS raise_bad_number ; None, or too big: "Bad number"
8C13 LDA parsed_number ; Keep x on the stack
8C16 PHA ; ...
8C17 LDA parsed_number_hi ; ...
8C1A PHA ; ...
8C1B JSR skip_separators ; Skip spaces and commas
8C1E JSR parse_number ; Read y
8C21 BCS discard_first_number ; None, or too big: "Bad number"
8C23 LDY #2 ; Store y in tmax_y
8C25 JSR store_parsed_number ; ...
8C28 PLA ; Recover x
8C29 STA parsed_number_hi ; ...
8C2C PLA ; ...
8C2D STA parsed_number ; ...
8C30 LDY #0 ; and store it in tmax_x
fall through ↓

Store parsed_number in the workspace

Store parsed_number at tmax_x+Y, with interrupts disabled.

On EntryYoffset from tmax_x: 0, 2, 4 or 6
On ExitYincremented
Acorrupted
8C32 .store_parsed_number←3← 8C25 JSR← 8C62 JSR← 8C6F JMP
LDA parsed_number ; Low byte
8C35 PHP ; Interrupts off
8C36 SEI ; ...
8C37 STA tmax_x,y ; ...
8C3A LDA parsed_number_hi ; High byte
8C3D INY ; ...
8C3E STA tmax_x,y ; ...
8C41 PLP ; Interrupts back as they were
8C42 RTS ; Return
8C43 .discard_first_number←2← 8C21 BCS← 8C5E BCS
PLA ; Drop the first number
8C44 PLA ; ...
8C45 .raise_bad_number←2← 8C11 BCS← 8C4E BCS
JMP bad_number_error ; "Bad number"

*TSET x,y: move the pointer

Read two numbers, as *TMAX, and store them in pointer_x and pointer_y. They are not clamped to the screen. The pointer is redrawn at the next poll that redraws it.

8C48 .cmd_tset
JSR reset_argument_index ; First argument
8C4B JSR parse_number ; Read x
8C4E BCS raise_bad_number ; None, or too big: "Bad number"
8C50 LDA parsed_number ; Keep x on the stack
8C53 PHA ; ...
8C54 LDA parsed_number_hi ; ...
8C57 PHA ; ...
8C58 JSR skip_separators ; Skip spaces and commas
8C5B JSR parse_number ; Read y
8C5E BCS discard_first_number ; None, or too big: "Bad number"
8C60 LDY #6 ; Store y in pointer_y
8C62 JSR store_parsed_number ; ...
8C65 PLA ; Recover x
8C66 STA parsed_number_hi ; ...
8C69 PLA ; ...
8C6A STA parsed_number ; ...
8C6D LDY #4 ; Store it in pointer_x and return
8C6F JMP store_parsed_number ; ...

Character row addresses for MODEs 0, 1 and 2, low bytes

Start addresses of the 32 character rows of a 640-byte-per-row screen starting at &3000, counted up from the bottom row, followed by two more rows above the top of the screen. Indexed by calc_pointer_screen_address. The addresses assume the screen has not been scrolled by hardware.

8C72 .mode012_row_addr_lo
EQUB <(&7d80) ; &7D80: row 0 from the bottom
8C73 EQUB <(&7b00) ; &7B00: row 1 from the bottom
8C74 EQUB <(&7880) ; &7880: row 2 from the bottom
8C75 EQUB <(&7600) ; &7600: row 3 from the bottom
8C76 EQUB <(&7380) ; &7380: row 4 from the bottom
8C77 EQUB <(&7100) ; &7100: row 5 from the bottom
8C78 EQUB <(&6e80) ; &6E80: row 6 from the bottom
8C79 EQUB <(&6c00) ; &6C00: row 7 from the bottom
8C7A EQUB <(&6980) ; &6980: row 8 from the bottom
8C7B EQUB <(&6700) ; &6700: row 9 from the bottom
8C7C EQUB <(&6480) ; &6480: row 10 from the bottom
8C7D EQUB <(&6200) ; &6200: row 11 from the bottom
8C7E EQUB <(&5f80) ; &5F80: row 12 from the bottom
8C7F EQUB <(&5d00) ; &5D00: row 13 from the bottom
8C80 EQUB <(&5a80) ; &5A80: row 14 from the bottom
8C81 EQUB <(&5800) ; &5800: row 15 from the bottom
8C82 EQUB <(&5580) ; &5580: row 16 from the bottom
8C83 EQUB <(&5300) ; &5300: row 17 from the bottom
8C84 EQUB <(&5080) ; &5080: row 18 from the bottom
8C85 EQUB <(&4e00) ; &4E00: row 19 from the bottom
8C86 EQUB <(&4b80) ; &4B80: row 20 from the bottom
8C87 EQUB <(&4900) ; &4900: row 21 from the bottom
8C88 EQUB <(&4680) ; &4680: row 22 from the bottom
8C89 EQUB <(&4400) ; &4400: row 23 from the bottom
8C8A EQUB <(&4180) ; &4180: row 24 from the bottom
8C8B EQUB <(&3f00) ; &3F00: row 25 from the bottom
8C8C EQUB <(&3c80) ; &3C80: row 26 from the bottom
8C8D EQUB <(&3a00) ; &3A00: row 27 from the bottom
8C8E EQUB <(&3780) ; &3780: row 28 from the bottom
8C8F EQUB <(&3500) ; &3500: row 29 from the bottom
8C90 EQUB <(&3280) ; &3280: row 30 from the bottom
8C91 EQUB <(&3000) ; &3000: row 31 from the bottom
8C92 EQUB <(&2d80) ; &2D80: above the screen
8C93 EQUB <(&2b00) ; &2B00: above the screen

Character row addresses for MODEs 0, 1 and 2, high bytes

8C94 .mode012_row_addr_hi
EQUB >(&7d80) ; &7D80: row 0 from the bottom
8C95 EQUB >(&7b00) ; &7B00: row 1 from the bottom
8C96 EQUB >(&7880) ; &7880: row 2 from the bottom
8C97 EQUB >(&7600) ; &7600: row 3 from the bottom
8C98 EQUB >(&7380) ; &7380: row 4 from the bottom
8C99 EQUB >(&7100) ; &7100: row 5 from the bottom
8C9A EQUB >(&6e80) ; &6E80: row 6 from the bottom
8C9B EQUB >(&6c00) ; &6C00: row 7 from the bottom
8C9C EQUB >(&6980) ; &6980: row 8 from the bottom
8C9D EQUB >(&6700) ; &6700: row 9 from the bottom
8C9E EQUB >(&6480) ; &6480: row 10 from the bottom
8C9F EQUB >(&6200) ; &6200: row 11 from the bottom
8CA0 EQUB >(&5f80) ; &5F80: row 12 from the bottom
8CA1 EQUB >(&5d00) ; &5D00: row 13 from the bottom
8CA2 EQUB >(&5a80) ; &5A80: row 14 from the bottom
8CA3 EQUB >(&5800) ; &5800: row 15 from the bottom
8CA4 EQUB >(&5580) ; &5580: row 16 from the bottom
8CA5 EQUB >(&5300) ; &5300: row 17 from the bottom
8CA6 EQUB >(&5080) ; &5080: row 18 from the bottom
8CA7 EQUB >(&4e00) ; &4E00: row 19 from the bottom
8CA8 EQUB >(&4b80) ; &4B80: row 20 from the bottom
8CA9 EQUB >(&4900) ; &4900: row 21 from the bottom
8CAA EQUB >(&4680) ; &4680: row 22 from the bottom
8CAB EQUB >(&4400) ; &4400: row 23 from the bottom
8CAC EQUB >(&4180) ; &4180: row 24 from the bottom
8CAD EQUB >(&3f00) ; &3F00: row 25 from the bottom
8CAE EQUB >(&3c80) ; &3C80: row 26 from the bottom
8CAF EQUB >(&3a00) ; &3A00: row 27 from the bottom
8CB0 EQUB >(&3780) ; &3780: row 28 from the bottom
8CB1 EQUB >(&3500) ; &3500: row 29 from the bottom
8CB2 EQUB >(&3280) ; &3280: row 30 from the bottom
8CB3 EQUB >(&3000) ; &3000: row 31 from the bottom
8CB4 EQUB >(&2d80) ; &2D80: above the screen
8CB5 EQUB >(&2b00) ; &2B00: above the screen

Character row addresses for MODEs 4 and 5, low bytes

Start addresses of the 32 character rows of a 320-byte-per-row screen starting at &5800, counted up from the bottom row, followed by two more rows above the top of the screen. Indexed by calc_pointer_screen_address. The addresses assume the screen has not been scrolled by hardware.

8CB6 .mode45_row_addr_lo
EQUB <(&7ec0) ; &7EC0: row 0 from the bottom
8CB7 EQUB <(&7d80) ; &7D80: row 1 from the bottom
8CB8 EQUB <(&7c40) ; &7C40: row 2 from the bottom
8CB9 EQUB <(&7b00) ; &7B00: row 3 from the bottom
8CBA EQUB <(&79c0) ; &79C0: row 4 from the bottom
8CBB EQUB <(&7880) ; &7880: row 5 from the bottom
8CBC EQUB <(&7740) ; &7740: row 6 from the bottom
8CBD EQUB <(&7600) ; &7600: row 7 from the bottom
8CBE EQUB <(&74c0) ; &74C0: row 8 from the bottom
8CBF EQUB <(&7380) ; &7380: row 9 from the bottom
8CC0 EQUB <(&7240) ; &7240: row 10 from the bottom
8CC1 EQUB <(&7100) ; &7100: row 11 from the bottom
8CC2 EQUB <(&6fc0) ; &6FC0: row 12 from the bottom
8CC3 EQUB <(&6e80) ; &6E80: row 13 from the bottom
8CC4 EQUB <(&6d40) ; &6D40: row 14 from the bottom
8CC5 EQUB <(&6c00) ; &6C00: row 15 from the bottom
8CC6 EQUB <(&6ac0) ; &6AC0: row 16 from the bottom
8CC7 EQUB <(&6980) ; &6980: row 17 from the bottom
8CC8 EQUB <(&6840) ; &6840: row 18 from the bottom
8CC9 EQUB <(&6700) ; &6700: row 19 from the bottom
8CCA EQUB <(&65c0) ; &65C0: row 20 from the bottom
8CCB EQUB <(&6480) ; &6480: row 21 from the bottom
8CCC EQUB <(&6340) ; &6340: row 22 from the bottom
8CCD EQUB <(&6200) ; &6200: row 23 from the bottom
8CCE EQUB <(&60c0) ; &60C0: row 24 from the bottom
8CCF EQUB <(&5f80) ; &5F80: row 25 from the bottom
8CD0 EQUB <(&5e40) ; &5E40: row 26 from the bottom
8CD1 EQUB <(&5d00) ; &5D00: row 27 from the bottom
8CD2 EQUB <(&5bc0) ; &5BC0: row 28 from the bottom
8CD3 EQUB <(&5a80) ; &5A80: row 29 from the bottom
8CD4 EQUB <(&5940) ; &5940: row 30 from the bottom
8CD5 EQUB <(&5800) ; &5800: row 31 from the bottom
8CD6 EQUB <(&56c0) ; &56C0: above the screen
8CD7 EQUB <(&5580) ; &5580: above the screen

Character row addresses for MODEs 4 and 5, high bytes

8CD8 .mode45_row_addr_hi
EQUB >(&7ec0) ; &7EC0: row 0 from the bottom
8CD9 EQUB >(&7d80) ; &7D80: row 1 from the bottom
8CDA EQUB >(&7c40) ; &7C40: row 2 from the bottom
8CDB EQUB >(&7b00) ; &7B00: row 3 from the bottom
8CDC EQUB >(&79c0) ; &79C0: row 4 from the bottom
8CDD EQUB >(&7880) ; &7880: row 5 from the bottom
8CDE EQUB >(&7740) ; &7740: row 6 from the bottom
8CDF EQUB >(&7600) ; &7600: row 7 from the bottom
8CE0 EQUB >(&74c0) ; &74C0: row 8 from the bottom
8CE1 EQUB >(&7380) ; &7380: row 9 from the bottom
8CE2 EQUB >(&7240) ; &7240: row 10 from the bottom
8CE3 EQUB >(&7100) ; &7100: row 11 from the bottom
8CE4 EQUB >(&6fc0) ; &6FC0: row 12 from the bottom
8CE5 EQUB >(&6e80) ; &6E80: row 13 from the bottom
8CE6 EQUB >(&6d40) ; &6D40: row 14 from the bottom
8CE7 EQUB >(&6c00) ; &6C00: row 15 from the bottom
8CE8 EQUB >(&6ac0) ; &6AC0: row 16 from the bottom
8CE9 EQUB >(&6980) ; &6980: row 17 from the bottom
8CEA EQUB >(&6840) ; &6840: row 18 from the bottom
8CEB EQUB >(&6700) ; &6700: row 19 from the bottom
8CEC EQUB >(&65c0) ; &65C0: row 20 from the bottom
8CED EQUB >(&6480) ; &6480: row 21 from the bottom
8CEE EQUB >(&6340) ; &6340: row 22 from the bottom
8CEF EQUB >(&6200) ; &6200: row 23 from the bottom
8CF0 EQUB >(&60c0) ; &60C0: row 24 from the bottom
8CF1 EQUB >(&5f80) ; &5F80: row 25 from the bottom
8CF2 EQUB >(&5e40) ; &5E40: row 26 from the bottom
8CF3 EQUB >(&5d00) ; &5D00: row 27 from the bottom
8CF4 EQUB >(&5bc0) ; &5BC0: row 28 from the bottom
8CF5 EQUB >(&5a80) ; &5A80: row 29 from the bottom
8CF6 EQUB >(&5940) ; &5940: row 30 from the bottom
8CF7 EQUB >(&5800) ; &5800: row 31 from the bottom
8CF8 EQUB >(&56c0) ; &56C0: above the screen
8CF9 EQUB >(&5580) ; &5580: above the screen

Graphics units per screen byte, by screen format

How far the left edge moves for each byte column: 16 graphics units in MODEs 0-2 (8, 4 or 2 pixels of 2, 4 or 8 units), 32 in MODEs 4 and 5.

8CFA .units_per_screen_byte
EQUB &10 ; Format 0, MODE 0
8CFB EQUB &10 ; Format 1, MODE 1
8CFC EQUB &10 ; Format 2, MODE 2
8CFD EQUB &20 ; Format 3, MODE 4
8CFE EQUB &20 ; Format 4, MODE 5

Bytes per character row, by screen format

Low bytes then high bytes: 640 (&280) in MODEs 0-2, 320 (&140) in MODEs 4 and 5.

8CFF .char_row_bytes_lo
EQUB &80 ; Format 0, MODE 0: low byte
8D00 EQUB &80 ; Format 1, MODE 1: low byte
8D01 EQUB &80 ; Format 2, MODE 2: low byte
8D02 EQUB &40 ; Format 3, MODE 4: low byte
8D03 EQUB &40 ; Format 4, MODE 5: low byte
8D04 .char_row_bytes_hi
EQUB &02 ; Format 0, MODE 0: high byte
8D05 EQUB &02 ; Format 1, MODE 1: high byte
8D06 EQUB &02 ; Format 2, MODE 2: high byte
8D07 EQUB &01 ; Format 3, MODE 4: high byte
8D08 EQUB &01 ; Format 4, MODE 5: high byte

Offsets of the four shifted pointer copies

Offset within pointer_image_copies of the copy for each shift, 0-3. The second four bytes repeat the first and are not read.

8D09 .shifted_copy_offsets
EQUB &00 ; Shift 0
8D0A EQUB &40 ; Shift 1
8D0B EQUB &80 ; Shift 2
8D0C EQUB &C0 ; Shift 3
8D0D EQUB &00 ; Not read
8D0E EQUB &40 ; Not read
8D0F EQUB &80 ; Not read
8D10 EQUB &C0 ; Not read

Pointer hot spot

How far the pointer's position is right of the left edge and below the top edge of the image, in graphics units: 4 and 4, which is the tip of the arrow.

8D11 .hotspot_x
EQUB &04 ; X: graphics units right of the left edge
8D12 .hotspot_y
EQUB &04 ; Y: graphics units below the top edge

Pointer images

One 64-byte image for each screen format, 0-4: 4 byte columns of 16 pixel rows each, column by column. Bits set are drawn in logical colour 1 (OR onto the screen). Together with the masks that follow, the pointer is an arrow outlined in colour 0. In MODE 0 ("#" image, "." outline in colour 0, blank transparent):

....
..##..
..####..
..######..
..########..
..##########..
..############..
..########....
..##..####..
........####..
      ..####..
        ..####..
        ..####..
          ..####..
          ..####..
            ....

The other formats have the same shape at their own pixel sizes, except at the left edge, where the outline is one pixel wide in MODE 4 and absent in MODE 5.

8D13 .pointer_images
EQUB &00, &30, &3C, &3F, &3F, &3F, &3F, &3F, &33, &00, &00, &00, &00, &00, &00, &00 ; MODE 0 image, column 0
8D23 EQUB &00, &00, &00, &00, &C0, &F0, &FC, &C0, &C0, &F0, &F0, &3C, &3C, &0F, &0F, &00 ; MODE 0 image, column 1
8D33 EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00 ; MODE 0 image, column 2
8D43 EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00 ; MODE 0 image, column 3
8D53 EQUB &00, &04, &06, &07, &07, &07, &07, &07, &05, &00, &00, &00, &00, &00, &00, &00 ; MODE 1 image, column 0
8D63 EQUB &00, &00, &00, &00, &08, &0C, &0E, &08, &08, &0C, &0C, &06, &06, &03, &03, &00 ; MODE 1 image, column 1
8D73 EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00 ; MODE 1 image, column 2
8D83 EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00 ; MODE 1 image, column 3
8D93 EQUB &00, &01, &01, &01, &01, &01, &01, &01, &01, &00, &00, &00, &00, &00, &00, &00 ; MODE 2 image, column 0
8DA3 EQUB &00, &00, &00, &02, &02, &03, &03, &02, &02, &01, &01, &01, &01, &00, &00, &00 ; MODE 2 image, column 1
8DB3 EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &02, &02, &00 ; MODE 2 image, column 2
8DC3 EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00 ; MODE 2 image, column 3
8DD3 EQUB &00, &70, &7C, &7F, &7F, &7F, &7F, &7F, &73, &40, &00, &00, &00, &00, &00, &00 ; MODE 4 image, column 0
8DE3 EQUB &00, &00, &00, &00, &C0, &F0, &FC, &C0, &C0, &F0, &F0, &3C, &3C, &0F, &0F, &00 ; MODE 4 image, column 1
8DF3 EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00 ; MODE 4 image, column 2
8E03 EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00 ; MODE 4 image, column 3
8E13 EQUB &08, &0C, &0E, &0F, &0F, &0F, &0F, &0F, &0D, &08, &00, &00, &00, &00, &00, &00 ; MODE 5 image, column 0
8E23 EQUB &00, &00, &00, &00, &08, &0C, &0E, &08, &08, &0C, &0C, &06, &06, &03, &03, &00 ; MODE 5 image, column 1
8E33 EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00 ; MODE 5 image, column 2
8E43 EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00 ; MODE 5 image, column 3

Pointer masks

One 64-byte mask for each screen format, laid out as the images. The screen is ANDed with the mask before the image is ORed in, so set bits leave the screen showing through and clear bits are the pointer's shape.

8E53 .pointer_masks
EQUB &0F, &03, &00, &00, &00, &00, &00, &00, &00, &00, &FC, &FF, &FF, &FF, &FF, &FF ; MODE 0 mask, column 0
8E63 EQUB &FF, &FF, &FF, &3F, &0F, &03, &00, &03, &0F, &03, &03, &00, &00, &C0, &C0, &F0 ; MODE 0 mask, column 1
8E73 EQUB &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &3F, &3F, &FF ; MODE 0 mask, column 2
8E83 EQUB &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF ; MODE 0 mask, column 3
8E93 EQUB &33, &11, &00, &00, &00, &00, &00, &00, &00, &00, &EE, &FF, &FF, &FF, &FF, &FF ; MODE 1 mask, column 0
8EA3 EQUB &FF, &FF, &FF, &77, &33, &11, &00, &11, &33, &11, &11, &00, &00, &88, &88, &CC ; MODE 1 mask, column 1
8EB3 EQUB &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &77, &77, &FF ; MODE 1 mask, column 2
8EC3 EQUB &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF ; MODE 1 mask, column 3
8ED3 EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &FF, &FF, &FF, &FF, &FF, &FF ; MODE 2 mask, column 0
8EE3 EQUB &FF, &55, &55, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &AA, &AA, &FF ; MODE 2 mask, column 1
8EF3 EQUB &FF, &FF, &FF, &FF, &FF, &55, &55, &FF, &FF, &55, &55, &55, &55, &00, &00, &55 ; MODE 2 mask, column 2
8F03 EQUB &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF ; MODE 2 mask, column 3
8F13 EQUB &0F, &03, &00, &00, &00, &00, &00, &00, &00, &00, &FC, &FF, &FF, &FF, &FF, &FF ; MODE 4 mask, column 0
8F23 EQUB &FF, &FF, &FF, &3F, &0F, &03, &00, &03, &0F, &03, &03, &00, &00, &C0, &C0, &F0 ; MODE 4 mask, column 1
8F33 EQUB &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &3F, &3F, &FF ; MODE 4 mask, column 2
8F43 EQUB &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF ; MODE 4 mask, column 3
8F53 EQUB &33, &11, &00, &00, &00, &00, &00, &00, &00, &00, &EE, &FF, &FF, &FF, &FF, &FF ; MODE 5 mask, column 0
8F63 EQUB &FF, &FF, &FF, &77, &33, &11, &00, &11, &33, &11, &11, &00, &00, &88, &88, &CC ; MODE 5 mask, column 1
8F73 EQUB &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &77, &77, &FF ; MODE 5 mask, column 2
8F83 EQUB &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF ; MODE 5 mask, column 3

Initials

Two sets of initials, JPG and PMF, after the code and data. Nothing refers to them. PMF also appears in the ROM's copyright string, (C)1986 PMF, and has been identified as Paul Fellows, who led Acornsoft's languages group and then the team that wrote Arthur. Who JPG is is not known.

8F93 .initials
EQUS "JPG,PMF" ; Not used by the code

Unused space and workspace

Zero to the end of the 8 KB image. The driver's RAM workspace is in this area: it runs from sideways RAM, and &9000 upwards in its own bank holds its variables (labelled from tmax_x), pointer_image_copies (&9200), pointer_mask_copies (&9300), screen_under_pointer (&9400) and stored_workspace (&9440). The image carries them as zero.

8F9A .unused_space
FILL 102 × &00 ; Unused

Driver workspace

&9000-&902F is the working copy of the driver's state, exchanged with stored_workspace on entry to and exit from the driver (exchange_workspace). &9030-&9037 is used in place. See each label for its use.

9000 .tmax_x←8Used as index base by← 857A LDX← 857F STA← 87DC LDA← 87E1 LDA← 8B89 LDX← 8B8E STA← 8C37 STA← 8C3E STA
EQUB &00
9001 .tmax_x_hi
EQUB &00
9002 .tmax_y
EQUB &00, &00
9004 .pointer_x←17← 830F STA← 83D7 LDY← 840F LDA← 844C LDA← 845A LDA← 894D LDA← 8954 STA← 8964 STZ← 8976 LDA← 897D STA← 8993 STA← 8AEE LDA← 8AF5 LDA← 8AFA STA← 8B04 LDA← 8B0E LDA← 8B14 STA
EQUB &00
9005 .pointer_x_hi←15← 8314 STA← 841F LDA← 8452 LDA← 8464 LDA← 8957 LDA← 895C STA← 8961 STZ← 8980 LDA← 8985 STA← 898E STA← 8AE7 LDA← 8AFF INC← 8B09 LDA← 8B17 LDA← 8B1C STA
EQUB &00
9006 .pointer_y←16← 8319 STA← 8417 LDA← 8440 LDA← 8470 ADC← 89A5 LDA← 89AC STA← 89B9 STZ← 89CE LDA← 89D5 STA← 89EB STA← 8B33 LDA← 8B3A LDA← 8B3F STA← 8B48 LDA← 8B52 LDA← 8B58 STA
EQUB &00
9007 .pointer_y_hi←15← 831E STA← 8427 LDA← 8446 LDA← 8476 LDA← 89AF LDA← 89B4 STA← 89BC STZ← 89D8 LDA← 89DD STA← 89E6 STA← 8B2C LDA← 8B44 INC← 8B4D LDA← 8B5B LDA← 8B60 STA
EQUB &00
9008 .pinout_index←7← 82E4 STA← 87F8 LDX← 880A STX← 8A32 LDX← 8A44 STX← 8AC5 LDX← 8AD7 STX
EQUB &00
9009 .redraw_countdown←3← 840C STA← 8A1C DEC← 8AC2 DEC
EQUB &00
900A .driver_on←7← 804E STZ← 8267 LDA← 828F STZ← 82CC LDX← 82D8 STX← 83B2 LDA← 83BC LDA
EQUB &00
900B .pointer_shown←7← 8051 STZ← 82D4 STX← 83B7 LDA← 83BF STA← 83E7 LDA← 8406 STZ← 8A17 LDA
EQUB &00
900C .parsed_number←12← 8BA1 STA← 8BBA LDA← 8BC6 LDA← 8BD8 STA← 8BE6 ASL← 8BF3 ADC← 8BF6 STA← 8C13 LDA← 8C2D STA← 8C32 LDA← 8C50 LDA← 8C6A STA
EQUB &00
900D .parsed_number_hi←13← 8BA4 STA← 8BC0 LDA← 8BCA ROL← 8BD0 ROL← 8BDB LDA← 8BE3 STA← 8BE9 ROL← 8BFB INC← 8C17 LDA← 8C29 STA← 8C3A LDA← 8C54 LDA← 8C66 STA
EQUB &00
900E .parse_temp←2← 8BBD STA← 8BD5 ADC
EQUB &00
900F .parse_temp_hi←2← 8BC3 STA← 8BDE ADC
EQUB &00
9010 FILL 2 × &00 ; Not used
9012 .screen_format←10← 808D LDA← 80B7 LDX← 80DF LDX← 83A1 STA← 84EA LDY← 8514 LDY← 85F3 LDY← 860A LDY← 865E LDX← 86D8 LDA
EQUB &00
9013 .pointer_shape←1← 865A STA
EQUB &00
9014 .button_state←7← 8A52 CMP← 8A55 STA← 8A76 CMP← 8A79 STA← 8A85 LDA← 8A97 LDA← 8AA6 LDA
EQUB &00
9015 .button_pending←8← 8054 STZ← 82D1 STX← 8A4D CMP← 8A5A STA← 8A71 CMP← 8A7E STA← 8A82 STZ← 8A94 STZ
EQUB &00
9016 .drawn_x←3← 83DB STY← 8412 CMP← 844F STA
EQUB &00
9017 .drawn_x_hi←2← 8422 CMP← 8455 STA
EQUB &00
9018 .drawn_y←2← 841A CMP← 8443 STA
EQUB &00
9019 .drawn_y_hi←2← 842A CMP← 8449 STA
EQUB &00
901A .pointer_left←6← 80B4 LDA← 80DC LDA← 8461 STA← 8491 LDA← 8517 LDA← 851E STA
EQUB &00
901B .pointer_left_hi←6← 8076 LDA← 80AA LDA← 8469 STA← 8497 LDA← 84BA LDA← 8523 INC
EQUB &00
901C .drawn_left←3← 8494 STA← 860D LDA← 8614 STA
EQUB &00
901D .drawn_left_hi←3← 849A STA← 85CF LDA← 8619 INC
EQUB &00
901E .pointer_top←6← 8066 LDA← 806F STA← 8085 LDA← 808A STA← 80D1 LDA← 8473 STA
EQUB &00
901F .pointer_top_hi←2← 8061 LDA← 847B STA
EQUB &00
9020 .saved_drawn_ptr←2← 854F STA← 859F LDA
EQUB &00
9021 .saved_drawn_ptr_hi←2← 8554 STA← 85A4 LDA
EQUB &00
9022 .saved_zero_page←2Used as index base by← 8559 LDA← 8599 STA
EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00
902E .saved_acccon←4← 83EF STA← 8400 LDA← 8432 STA← 8546 LDA
EQUB &00
902F FILL 1 × &00 ; Not used
9030 .cmd_start_offset←2← 8182 STY← 8199 LDY
EQUB &00
9031 .device_mode←10← 8057 STZ← 8295 STA← 82AE STA← 82B5 STA← 82BA STZ← 82E7 LDA← 83C4 LDA← 87EF LDX← 884C LDA← 8A2D LDX
EQUB &00
9032 .x_speed←7← 88E8 ADC← 88EB STA← 896A ADC← 896D STA← 8999 ADC← 899C STA← 8A02 STA
EQUB &00
9033 .x_speed_hi←6← 88F0 INC← 8951 SBC← 8972 INC← 897A ADC← 89A1 INC← 89FD STZ
EQUB &00
9034 .y_speed←7← 88F6 ADC← 88F9 STA← 89C2 ADC← 89C5 STA← 89F1 ADC← 89F4 STA← 8A0B STA
EQUB &00
9035 .y_speed_hi←6← 88FE INC← 89A9 SBC← 89CA INC← 89D2 ADC← 89F9 INC← 8A06 STZ
EQUB &00
9036 .desktop_colours←6Referenced by← 80F7 LDA← 8126 STAUsed as index base by← 8139 LDA← 813F CMP← 8144 STA← 8159 STA
EQUB &00
9037 .desktop_colour_1←2← 8112 LDA← 812B STA
EQUB &00
9038 FILL 456 × &00 ; Not used
9200 .pointer_image_copies
FILL 256 × &00 ; Pointer image copies (built at run time)
9300 .pointer_mask_copies
FILL 256 × &00 ; Pointer mask copies (built at run time)
9400 .screen_under_pointer
FILL 64 × &00 ; Screen under the pointer (at run time)
9440 .stored_workspace
FILL 48 × &00 ; Stored workspace (at run time)
9470 FILL 2960 × &00 ; Not used