-
Notifications
You must be signed in to change notification settings - Fork 1
/
mouse.asm
294 lines (176 loc) · 6.16 KB
/
mouse.asm
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
; extra MACRO files need to go here
include "myMacros.inc"
.assume adl=1 ; ez80 ADL memory mode
.org $40000 ; load code here
jp start_here ; jump to start of code
.align 64 ; MOS header
.db "MOS",0,1
start_here:
push af ; store all the registers
push bc
push de
push ix
push iy
; ------------------
; This is our actual code
; prepare the screen
SET_MODE 8 ; mode 8 is 320x240 pixels, 64 colours
; enable mouse command
ld a, 23
rst.lil $10
ld a, 0
rst.lil $10
ld a, 89h
rst.lil $10
ld a, 0 ; 0=enable, 1=disable
rst.lil $10
; set mouse icon style
ld a, 23
rst.lil $10
ld a, 0
rst.lil $10
ld a, 89h
rst.lil $10
ld a, 3 ; setCursor
rst.lil $10
ld a, 5 ; fab-gl style number, or my own defined ones
rst.lil $10
ld a, 0 ; 0 as 16 bit number
rst.lil $10
; Sending an initialising VDU byte stream
ld hl, VDUdata ; address of string to use
ld bc, endVDUdata - VDUdata ; length of string
rst.lil $18 ; Call the MOS API to send data to VDP
; ------------------
MOUSE_IS_UP_LOOP: ; loop here until we hit ESC key
MOSCALL $1E ; load IX with keymap address
ld a, (ix + $0E)
bit 0, a ; index $0E, bit 0 is for ESC key in matrix
jp nz, EXIT_HERE ; if pressed, ESC key to exit
MOSCALL $08 ; get IX pointer to sysvars
ld a, (ix + $2D) ; + $2D is mouse buttons status
and 00000001b ; bit 0 is left mouse button
cp 1 ; check if pressed
jp z, DO_MOUSE_DOWN ; if so, then jump to mouse down routines
jp MOUSE_IS_UP_LOOP
; ---------------
DO_MOUSE_DOWN:
; set start position
ld a, (ix + $29) ; mouse x position
ld (mouse_start_x), a
ld a, (ix + $2A) ; mouse x position
ld (mouse_start_x + 1), a
ld a, (ix + $2B) ; mouse y position
ld (mouse_start_y), a
ld a, (ix + $2C) ; mouse y position
ld (mouse_start_y + 1), a
call plotStart
jp MOUSE_STILLDOWN_LOOP
; ------------------
plotStart:
ld hl, plot ; address of string to use
ld bc, endPlot - plot ; length of string
rst.lil $18 ; Call the MOS API to send data to VDP
ret
plot:
.db 25, 69 ; PLOT point at...
mouse_start_x: .dw 0 ; x
mouse_start_y: .dw 0 ; y
endPlot:
; ------------------
MOUSE_STILLDOWN_LOOP:
MOSCALL $1E ; load IX with keymap address
ld a, (ix + $0E)
bit 0, a ; index $0E, bit 0 is for ESC key in matrix
jp nz, EXIT_HERE ; if pressed, ESC key to exit
MOSCALL $08 ; get IX pointer to sysvars
ld a, (ix + $2D) ; +$2D is mouse buttons status
and 00000001b
cp 0
jp z, MOUSE_IS_UP_LOOP
ld a, (ix + $29) ; mouse x position
ld (mouse_pos_x), a
ld a, (ix + $2A) ; mouse x position
ld (mouse_pos_x + 1), a
ld a, (ix + $2B) ; mouse y position
ld (mouse_pos_y), a
ld a, (ix + $2C) ; mouse y position
ld (mouse_pos_y + 1), a
call drawLine
jp MOUSE_STILLDOWN_LOOP
; ------------------
drawLine:
ld hl, line ; address of string to use
ld bc, endLine - line ; length of string
rst.lil $18 ; Call the MOS API to send data to VDP
ret
line:
.db 25, 5 ; PLOT line from last position to...
mouse_pos_x: .dw 0 ; x
mouse_pos_y: .dw 0 ; y
endLine:
; ------------------
; This is where we exit the program
EXIT_HERE:
CLS
; disable mouse command
ld a, 23
rst.lil $10
ld a, 0
rst.lil $10
ld a, 89h
rst.lil $10
ld a, 1 ; 0=enable, 1=disable
rst.lil $10
pop iy ; Pop all registers back from the stack
pop ix
pop de
pop bc
pop af
ld hl,0 ; Load the MOS API return code (0) for no errors.
ret ; Return to MOS
; ------------------
; This is the data we send to VDP
VDUdata:
.db 23, 0, 192, 0 ; set to non-scaled graphics
endVDUdata:
; ------------------
; Cursor styles
; 0 CursorPointerAmigaLike
; 11x11 Amiga like colored mouse pointer
; 1 CursorPointerSimpleReduced
; 10x15 mouse pointer
; 2 CursorPointerSimple
; 11x19 mouse pointer
; 3 CursorPointerShadowed
; 11x19 shadowed mouse pointer
; 4 CursorPointer
; 12x17 mouse pointer
; 5 CursorPen
; 16x16 pen
; 6 CursorCross1
; 9x9 cross
; 7 CursorCross2
; 11x11 cross
; 8 CursorPoint
; 5x5 point
; 9 CursorLeftArrow
; 11x11 left arrow
; 10 CursorRightArrow
; 11x11 right arrow
; 11 CursorDownArrow
; 11x11 down arrow
; 12 CursorUpArrow
; 11x11 up arrow
; 13 CursorMove
; 19x19 move
; 14 CursorResize1
; 12x12 resize orientation 1
; 15 CursorResize2
; 12x12 resize orientation 2
; 16 CursorResize3
; 11x17 resize orientation 3
; 17 CursorResize4
; 17x11 resize orientation 4
; 18 CursorTextInput
; 7x15 text input