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
13 .export _mouse_def_callbacks
17 ; ------------------------------------------------------------------------
23 ; ------------------------------------------------------------------------
34 ; ------------------------------------------------------------------------
40 lda ALTCHARSET ; Alternate charset switched in?
41 bpl :+ ; No, normal charset
42 lda #'B' ; MouseText character
48 ; ------------------------------------------------------------------------
54 bit RD80VID ; In 80 column mode?
55 bpl column ; No, skip bank switching
56 switch: bit LOWSCR ; Patched at runtime
58 column: ldx #$00 ; Patched at runtime
59 getscr: lda $0400,x ; Patched at runtime
60 cmpcur: cmp #'+' | $40 ; Possibly patched by initialization
64 getcur: lda #'+' | $40 ; Possibly patched by initialization
65 setscr: sta $0400,x ; Patched at runtime
67 bit LOWSCR ; Doesn't hurt in 40 column mode
71 ; ------------------------------------------------------------------------
77 bit LOWSCR ; Doesn't hurt in 40 column mode
81 ; Hide the mouse cursor.
83 jsr getcursor ; Cursor visible at current position?
84 bne done ; No, we're done
85 lda backup ; Get character at cursor position
86 jmp setscr ; Draw character
88 ; Show the mouse cursor.
90 jsr getcursor ; Cursor visible at current position?
91 beq done ; Yes, we're done
92 sta backup ; Save character at cursor position
93 jmp setcursor ; Draw cursor
95 ; Move the mouse cursor x position to the value in A/X.
97 dex ; Is position [256..279]?
98 bmi :+ ; No, start with column 0
100 adc #$0100 .MOD 7 ; Bias position
101 ldx #$0100 / 7 - 1 ; Bias column
103 : sbc #7 ; 280 positions / 40 columns
108 adc #7 / 2 ; Left or right half of 40-col column?
109 ldx #<LOWSCR ; Columns 1,3,5..79
111 .assert LOWSCR + 1 = HISCR, error
112 inx ; Columns 0,2,4..78
117 ; Move the mouse cursor y position to the value in A/X.
125 and #%00000011 ; 000000CD
126 ora #>$0400 ; 000001CD
131 and #%11100000 ; EAB00000
132 ora getscr+1 ; EABABCDE
133 and #%11111000 ; EABAB000