-
Notifications
You must be signed in to change notification settings - Fork 10
/
mouse_gs.s
108 lines (100 loc) · 2.43 KB
/
mouse_gs.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
;===============================
; Polled GS Mouse driver
; by John Brooks 3/6/1988
;
; Modified 3/4/2018 for:
; 1) 65816 emulation mode
; 2) Cvt pixel pos to 80-col txt pos
; 3) Add comments
;
; Modified 2018/05/03
; by Peter Ferrie for:
; 1) CC65 compatible
; 2) extensions for WeeGUI
;===============================
.setcpu "65816"
IoMouseStatus = $C027
IoMouseData = $C024
;-------------------------------
; If GS mouse state has changed
; then update:
; MousePixX,Y
; MouseTxtX,Y
; MouseDownX,Y
;
; Entry: e=1, DP=$0000
; Exit: e=1, DP=$0000, AXY=?
;-------------------------------
GsPollMouse:
lda IoMouseStatus ;Any new mouse data?
bpl GS_Mouse_Exit
and #2 ;If data reg is misaligned, realign with deltaX=2
bne GS_Mouse_OnlyY
lda IoMouseData ;Read deltaX
GS_Mouse_OnlyY:
jsr WGUndrawPointer ; Erase the old mouse pointer
ldy IoMouseData ;Read deltaY
clc
xce ;65816 native mode
GS_Mouse_CheckX:
rep #$30 ;16-bit A,X,Y
.a16
.i16
ldx #MousePixX
jsr GS_Mouse_AddDelta ;Cvt to signed word, add to pixPos & range clamp
sta MouseTxtX-MousePixX,x ;16-bit store overwrites Y
GS_Mouse_CheckY:
tya ;a=DeltaY
inx
inx ;x=MousePixY ptr
jsr GS_Mouse_AddDelta ;Cvt to signed word, add to pixPos & range clamp
sep #$21 ;8-bit acc, set carry
.a8
sta MouseTxtY-MousePixY,x
tya
eor MouseBtn0-MousePixY,x ;Detect button0 up/down
bpl GS_Mouse_NoDownEdge
eor MouseBtn0-MousePixY,x ;Remove old button0
sta MouseBtn0-MousePixY,x ;Save new button0
bmi GS_Mouse_NoDownEdge
ldy MouseTxtX-MousePixY,x
sty MouseDownX ;Set WG_MOUSECLICK_X & WG_MOUSECLICK_Y
GS_Mouse_NoDownEdge:
xce ;65816 emulation mode: 8-bit A,X,Y
jmp WGDrawPointer ; Redraw the pointer
;-------------------------------
GS_Mouse_AddDelta:
.a16
.i16
ora #$ff80 ;Extend neg 6-bit delta in anticipation of delta
bit #$0040 ;Check sign of delta
bne GS_Mouse_GotDelta
GS_Mouse_Pos:
and #$003f ;Strip b7 button state from positive 6-bit delta
GS_Mouse_GotDelta:
clc
adc 0,x ;Apply delta to X or Y pixel position
bpl GS_Mouse_NoMinClamp
tdc ;Clamp neg position to zero
GS_Mouse_NoMinClamp:
cmp MouseMaxX-MousePixX,x
bcc GS_Mouse_NoMaxClamp
lda MouseMaxX-MousePixX,x
dec
GS_Mouse_NoMaxClamp:
sta 0,x ;Store mouse pixel position
lsr ;TextPos = PixelPos / 8
lsr
lsr
GS_Mouse_Exit:
rts
.a8
.i8
GsDisableMouse:
pla
pla ; discard return address
stz WG_MOUSEACTIVE
jsr WGUndrawPointer ; Be nice if we're disabled during a program
pla
rts
;-------------------------------