2 ; Default mouse callbacks for the Apple II
4 ; Oliver Schmidt, 22.09.2005
6 ; All functions in this module should be interrupt safe, because they may
7 ; be called from an interrupt handler
10 .export _mouse_def_callbacks
14 ; ------------------------------------------------------------------------
21 ; ------------------------------------------------------------------------
34 ; ------------------------------------------------------------------------
39 cursor = 'B' ; MouseText character
41 cursor = '+' | $40 ; Flashing crosshair
46 bit RD80VID ; In 80 column mode?
47 bpl column ; No, skip bank switching
48 switch: bit LOWSCR ; Patched at runtime
50 column: ldx #$00 ; Patched at runtime
51 getscr: lda $0400,x ; Patched at runtime
57 setscr: sta $0400,x ; Patched at runtime
59 bit LOWSCR ; Doesn't hurt in 40 column mode
63 ; ------------------------------------------------------------------------
69 bit LOWSCR ; Doesn't hurt in 40 column mode
73 ; Hide the mouse cursor.
78 ; Prepare to move the mouse cursor.
80 jsr getcursor ; Cursor visible at current position?
81 bne done ; No, we're done
82 lda backup ; Get character at cursor position
83 jmp setscr ; Draw character
85 ; Show the mouse cursor.
90 ; Draw the mouse cursor.
94 jsr getcursor ; Cursor visible at current position?
95 beq done ; Yes, we're done
96 sta backup ; Save character at cursor position
97 jmp setcursor ; Draw cursor
99 ; Move the mouse cursor x position to the value in A/X.
101 dex ; Is position [256..279]?
102 bmi :+ ; No, start with column 0
104 adc #$0100 .MOD 7 ; Bias position
105 ldx #$0100 / 7 - 1 ; Bias column
107 : sbc #7 ; 280 positions / 40 columns
112 adc #7 / 2 ; Left or right half of 40-col column?
113 ldx #<LOWSCR ; Columns 1,3,5..79
115 .assert LOWSCR + 1 = HISCR, error
116 inx ; Columns 0,2,4..78
121 ; Move the mouse cursor y position to the value in A/X.
129 and #%00000011 ; 000000CD
130 ora #>$0400 ; 000001CD
135 and #%11100000 ; EAB00000
136 ora getscr+1 ; EABABCDE
137 and #%11111000 ; EABAB000