My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes  
Changes to /trunk/execfun.asm
r42 vs. r44 Compare: vs.  Format:
Revision r44
Go to: 
Project members, sign in to write a code review
/trunk/execfun.asm   r42 /trunk/execfun.asm   r44
1 ; execfun.asm 1 ; execfun.asm
2 ; event handler for controls 2 ; event handler for controls
3 3
4 .include "common.inc" 4 .include "common.inc"
5 .include "global.inc" 5 .include "global.inc"
6 .include "window.inc" 6 .include "window.inc"
7 .include "cursor.inc" 7 .include "cursor.inc"
8 .include "drawfun.inc" 8 .include "drawfun.inc"
9 .include "util.inc" 9 .include "util.inc"
10 .include "screen.inc" 10 .include "screen.inc"
11 11
12 .export ex_screen 12 .export ex_screen
13 .export ex_window 13 .export ex_window
14 .export ex_button 14 .export ex_button
15 .export ex_edit 15 .export ex_edit
16 .export ex_titlebar 16 .export ex_titlebar
17 17
18 .import edrawbeam 18 .import edrawbeam
19 .import dodraw 19 .import dodraw
20 20
21 .segment "DATA" 21 .segment "DATA"
22 22
23 eftyp: .byte $00 23 eftyp: .byte $00
24 24
25 .segment "CODE" 25 .segment "CODE"
26 26
27 ex_screen: ldx #CURSOR_CROSS 27 ex_screen: ldx #CURSOR_CROSS
28 jmp commonex 28 jmp commonex
29 29
30 ex_window: ldx #CURSOR_ARROW 30 ex_window: ldx #CURSOR_ARROW
31 jsr commonex 31 jsr commonex
32 jmp parevent 32 jmp parevent
33 33
34 ex_button: ldx #CURSOR_HAND 34 ex_button: ldx #CURSOR_HAND
35 exbutton1: jsr commonex 35 exbutton1: jsr commonex
36 bcs @chkenter 36 bcs @chkenter
37 beq @nomouse 37 beq @nomouse
38 @noenter: lda eftyp 38 @noenter: lda eftyp
39 cmp #EVT_MOUSE_LEAVE 39 cmp #EVT_MOUSE_LEAVE
40 bne @noleave 40 bne @noleave
41 jsr win_getstate 41 jsr win_getstate
42 cmp #BSTATE_DOWN 42 cmp #BSTATE_DOWN
43 bne @endexb 43 bne @endexb
44 beq @mup 44 beq @mup
45 @noleave: cmp #EVT_MOUSE_DOWN 45 @noleave: cmp #EVT_MOUSE_DOWN
46 bne @nodn 46 bne @nodn
47 ; down 47 ; down
48 @btndn: lda #BSTATE_DOWN 48 @btndn: lda #BSTATE_DOWN
49 bne @bsetst 49 bne @bsetst
50 @nodn: cmp #EVT_MOUSE_UP 50 @nodn: cmp #EVT_MOUSE_UP
51 bne @endexb 51 bne @endexb
52 ; up 52 ; up
53 @mup: lda #BSTATE_UP 53 @mup: lda #BSTATE_UP
54 @bsetst: jmp upd_btnst 54 @bsetst: jmp upd_btnst
55 @chkenter: lda eftyp 55 @chkenter: lda eftyp
56 cmp #EVT_MOUSE_ENTER 56 cmp #EVT_MOUSE_ENTER
57 bne @endexb 57 bne @endexb
58 ldy #MouseEvent::btn 58 ldy #MouseEvent::btn
59 lda (reg2), y 59 lda (reg2), y
60 bne @btndn 60 bne @btndn
61 @endexb: rts 61 @endexb: rts
62 @nomouse: jmp parevent 62 @nomouse: jmp parevent
63 63
64 ex_edit: ldx #CURSOR_BEAM 64 ex_edit: ldx #CURSOR_BEAM
65 jsr commonex 65 jsr commonex
66 bne @done 66 bne @done
67 lda #KEY_EVENT 67 lda #KEY_EVENT
68 bit eftyp 68 bit eftyp
69 bne @edo_keys 69 bne @edo_keys
70 lda eftyp 70 lda eftyp
71 cmp #EVT_WIN_SETFOCUS 71 cmp #EVT_WIN_SETFOCUS
72 bne @chkkill 72 bne @chkkill
73 jsr win_getstate ; set focus 73 jsr win_getstate ; set focus
74 eor #EDIT_HAS_FOCUS 74 eor #EDIT_HAS_FOCUS
75 bpl @done 75 bpl @done
76 jsr win_setstate 76 jsr win_setstate
77 jmp @updbeam 77 jmp @updbeam
78 @chkkill: cmp #EVT_WIN_KILLFOCUS 78 @chkkill: cmp #EVT_WIN_KILLFOCUS
79 bne @done 79 bne @done
80 jsr win_getstate ; kill focus 80 jsr win_getstate ; kill focus
81 and #~EDIT_HAS_FOCUS 81 and #~EDIT_HAS_FOCUS
82 jsr win_setstate 82 jsr win_setstate
83 @updbeam: jmp edrawbeam 83 @updbeam: jmp edrawbeam
84 @done: rts 84 @done: rts
85 @edo_keys: ; handle keys 85 @edo_keys: ; handle keys
86 lda eftyp 86 lda eftyp
87 cmp #EVT_KEY_DOWN 87 cmp #EVT_KEY_DOWN
88 bne @done 88 bne @done
89 ldy #KeyEvent::petscii 89 ldy #KeyEvent::petscii
90 lda (reg2), y 90 lda (reg2), y
91 bpl @chkascii 91 bpl @chkascii
92 cmp #$A0 92 cmp #$A0
93 bcc @ectrl 93 bcc @ectrl
94 bcs @eprint 94 bcs @eprint
95 @chkascii: cmp #$20 95 @chkascii: cmp #$20
96 bcc @ectrl 96 bcc @ectrl
97 @eprint: ldy #KeyEvent::scrcode 97 @eprint: ldy #KeyEvent::scrcode
98 lda (reg2), y 98 lda (reg2), y
99 jmp eputch 99 jmp eputch
100 @ectrl: cmp #$13 ; HOME 100 @ectrl: cmp #$13 ; HOME
101 beq @dohome 101 beq @dohome
102 cmp #$14 ; DEL 102 cmp #$14 ; DEL
103 beq @dodel 103 beq @dodel
104 cmp #$93 ; CLR 104 cmp #$93 ; CLR
105 beq @doclr 105 beq @doclr
106 cmp #$94 ; INS 106 cmp #$94 ; INS
107 beq @doins 107 beq @doins
108 cmp #$1D ; CRSR R 108 cmp #$1D ; CRSR R
109 beq @docrsrr 109 beq @docrsrr
110 cmp #$9D ; CRSR L 110 cmp #$9D ; CRSR L
111 beq @docrsrl 111 beq @docrsrl
112 jmp escalate 112 jmp escalate
113 113
114 @dohome: jmp ehome 114 @dohome: jmp ehome
115 @doclr: jmp eclr 115 @doclr: jmp eclr
116 @dodel: jmp edel 116 @dodel: jmp edel
117 @doins: jmp eins 117 @doins: jmp eins
118 @docrsrr: jmp ecrsrr 118 @docrsrr: jmp ecrsrr
119 @docrsrl: jmp ecrsrl 119 @docrsrl: jmp ecrsrl
120 120
121 ex_titlebar: 121 ex_titlebar:
122 jsr win_getparent 122 jsr win_getparent
123 beq @done_ext 123 beq @done_ext
124 jsr win_isfront 124 jsr win_isfront
125 bcs ex_movebar 125 bcs ex_movebar
126 ldx #CURSOR_ACTIVATE 126 ldx #CURSOR_ACTIVATE
127 jsr exbutton1 127 jsr exbutton1
128 lda eftyp 128 lda eftyp
129 cmp #EVT_MOUSE_UP 129 cmp #EVT_MOUSE_UP
130 bne @done_ext 130 bne @done_ext
131 jsr win_getparent 131 jsr win_getparent
132 jsr win_show 132 jsr win_show
133 @done_ext: rts 133 @done_ext: rts
134 134
135 ex_movebar: ldx #CURSOR_MOVE 135 ex_movebar: ldx #CURSOR_MOVE
136 jsr exbutton1 136 jsr exbutton1
137 lda eftyp 137 lda eftyp
138 cmp #EVT_MOUSE_DOWN 138 cmp #EVT_MOUSE_DOWN
139 beq @begmove 139 beq @begmove
140 cmp #EVT_MOUSE_UP 140 cmp #EVT_MOUSE_UP
141 beq @endmove 141 beq @endmove
142 cmp #EVT_MOUSE_MOVE 142 cmp #EVT_MOUSE_MOVE
143 beq @domove 143 beq @domove
144 rts 144 rts
145 145
146 @begmove: inc inmove 146 @begmove: inc inmove
147 ldy #MouseEvent::mx 147 ldy #MouseEvent::mx
148 lda (reg2), y 148 lda (reg2), y
149 sta moveorgx 149 sta moveorgx
150 ldy #MouseEvent::my 150 ldy #MouseEvent::my
151 lda (reg2), y 151 lda (reg2), y
152 sta moveorgy 152 sta moveorgy
153 jmp set_capture 153 jmp set_capture
154 154
155 @endmove: dec inmove 155 @endmove: dec inmove
156 jmp rel_capture 156 jmp rel_capture
157 157
158 @notinmove: rts 158 @notinmove: rts
159 159
160 @domove: lda inmove 160 @domove: lda inmove
161 beq @notinmove 161 beq @notinmove
162 lda #0 162 lda #0
163 sta ismove 163 sta ismove
164 ldy #MouseEvent::mx 164 ldy #MouseEvent::mx
165 lda (reg2), y 165 lda (reg2), y
166 sec 166 sec
167 sbc moveorgx 167 sbc moveorgx
168 sta movedx 168 sta movedx
169 tax 169 tax
170 bpl @xpos 170 bpl @xpos
171 eor #$FF 171 eor #$FF
172 tax 172 tax
173 inx 173 inx
174 @xpos: cpx #8 174 @xpos: cpx #8
175 bcc @nomovex 175 bcc @nomovex
176 inc ismove 176 inc ismove
177 @nomovex: ldy #MouseEvent::my 177 @nomovex: ldy #MouseEvent::my
178 lda (reg2), y 178 lda (reg2), y
179 sec 179 sec
180 sbc moveorgy 180 sbc moveorgy
181 sta movedy 181 sta movedy
182 tay 182 tay
183 bpl @ypos 183 bpl @ypos
184 eor #$FF 184 eor #$FF
185 tay 185 tay
186 iny 186 iny
187 @ypos: cpy #16 187 @ypos: cpy #16
188 bcc @nomovey 188 bcc @nomovey
189 inc ismove 189 inc ismove
190 @nomovey: lda ismove 190 @nomovey: lda ismove
191 beq @donemv 191 beq @donemv
192 192
193 lda movedx 193 lda movedx
194 and #$F8 194 and #$F8
195 sta movedx 195 sta movedx
196 clc 196 clc
197 adc moveorgx 197 adc moveorgx
198 sta moveorgx 198 sta moveorgx
199 lda movedy 199 lda movedy
200 and #$F0 200 and #$F0
201 sta movedy 201 sta movedy
202 clc
202 adc moveorgy 203 adc moveorgy
203 sta moveorgy 204 sta moveorgy
204 205
205 jsr win_getfrm 206 jsr win_getfrm
206 sta mfrm 207 sta mfrm
207 jsr frm_getpos 208 jsr frm_getpos
208 txa 209 txa
209 clc 210 clc
210 adc movedx 211 adc movedx
211 cmp scr_dim_x 212 cmp scr_dim_x
212 bcs @nochngx 213 bcs @nochngx
213 tax 214 tax
214 @nochngx: lda movedy 215 @nochngx: lda movedy
215 bpl @noovfl 216 bpl @noovfl
216 tya 217 tya
217 beq @nochngy 218 beq @nochngy
218 @noovfl: tya 219 @noovfl: tya
219 clc 220 clc
220 adc movedy 221 adc movedy
221 cmp scr_dim_y 222 cmp scr_dim_y
222 bcs @nochngy 223 bcs @nochngy
223 tay 224 tay
224 @nochngy: lda mfrm 225 @nochngy: lda mfrm
225 jsr frm_setpos 226 jsr frm_setpos
226 jsr cur_hide 227 jsr cur_hide
227 jsr redraw_screen 228 jsr redraw_screen
228 jsr cur_show 229 jsr cur_show
229 @donemv: rts 230 @donemv: rts
230 231
231 .segment "DATA" 232 .segment "DATA"
232 233
233 inmove: .byte 0 234 inmove: .byte 0
234 mfrm: .byte 0 235 mfrm: .byte 0
235 ismove: .byte 0 236 ismove: .byte 0
236 moveorgx: .byte 0 237 moveorgx: .byte 0
237 moveorgy: .byte 0 238 moveorgy: .byte 0
238 movedx: .byte 0 239 movedx: .byte 0
239 movedy: .byte 0 240 movedy: .byte 0
240 ytmp: .byte 0 241 ytmp: .byte 0
241 242
242 .segment "CODE" 243 .segment "CODE"
243 244
244 commonex: ldy #Event::type 245 commonex: ldy #Event::type
245 lda (reg2), y 246 lda (reg2), y
246 sta eftyp 247 sta eftyp
247 and #MOUSE_EVENT 248 and #MOUSE_EVENT
248 beq @nothandled 249 beq @nothandled
249 ; mouse move -> change cursor 250 ; mouse move -> change cursor
250 lda eftyp 251 lda eftyp
251 cmp #EVT_MOUSE_ENTER 252 cmp #EVT_MOUSE_ENTER
252 bne @nothandled 253 bne @nothandled
253 txa 254 txa
254 pha 255 pha
255 jsr win_isactive 256 jsr win_isactive
256 pla 257 pla
257 bcs @setcur 258 bcs @setcur
258 lda #CURSOR_WINDOW 259 lda #CURSOR_WINDOW
259 @setcur: jsr cur_set 260 @setcur: jsr cur_set
260 sec 261 sec
261 bcs @endex 262 bcs @endex
262 @nothandled: 263 @nothandled:
263 clc 264 clc
264 @endex: lda eftyp 265 @endex: lda eftyp
265 and #MOUSE_EVENT 266 and #MOUSE_EVENT
266 rts 267 rts
267 268
268 parevent: lda #KEY_EVENT 269 parevent: lda #KEY_EVENT
269 bit eftyp 270 bit eftyp
270 bne @doesc 271 bne @doesc
271 rts 272 rts
272 @doesc: jmp escalate 273 @doesc: jmp escalate
273 274
274 .segment "DATA" 275 .segment "DATA"
275 276
276 esccode: .byte $00 277 esccode: .byte $00
277 emaxch: .byte $00 278 emaxch: .byte $00
278 estate: .byte $00 279 estate: .byte $00
279 epos: .byte $00 280 epos: .byte $00
280 281
281 .segment "CODE" 282 .segment "CODE"
282 283
283 seltxt: sta esccode 284 seltxt: sta esccode
284 jsr win_gettext 285 jsr win_gettext
285 sta reg2 286 sta reg2
286 stx reg2+1 287 stx reg2+1
287 ldy #0 288 ldy #0
288 lda (reg2), y 289 lda (reg2), y
289 sta emaxch 290 sta emaxch
290 jsr win_getstate 291 jsr win_getstate
291 tax 292 tax
292 and #~EDIT_POS_MASK 293 and #~EDIT_POS_MASK
293 sta estate 294 sta estate
294 txa 295 txa
295 and #EDIT_POS_MASK 296 and #EDIT_POS_MASK
296 rts 297 rts
297 298
298 eputch: sta esccode 299 eputch: sta esccode
299 jsr seltxt 300 jsr seltxt
300 cmp emaxch 301 cmp emaxch
301 bcs invinput 302 bcs invinput
302 tay 303 tay
303 iny 304 iny
304 lda esccode 305 lda esccode
305 sta (reg2), y 306 sta (reg2), y
306 showpos: tya 307 showpos: tya
307 ora estate 308 ora estate
308 jsr win_setstate 309 jsr win_setstate
309 showpos1: jsr cur_hide 310 showpos1: jsr cur_hide
310 jsr dodraw 311 jsr dodraw
311 jmp cur_show 312 jmp cur_show
312 313
313 invinput: rts ; TODO: beep 314 invinput: rts ; TODO: beep
314 315
315 edel: jsr seltxt 316 edel: jsr seltxt
316 beq invinput 317 beq invinput
317 tay 318 tay
318 sta epos 319 sta epos
319 ldy emaxch 320 ldy emaxch
320 ldx #$20 ; space 321 ldx #$20 ; space
321 @mvloop: lda (reg2), y 322 @mvloop: lda (reg2), y
322 pha 323 pha
323 txa 324 txa
324 sta (reg2), y 325 sta (reg2), y
325 pla 326 pla
326 tax 327 tax
327 dey 328 dey
328 cpy epos 329 cpy epos
329 bcs @mvloop 330 bcs @mvloop
330 jmp showpos 331 jmp showpos
331 332
332 eins: jsr seltxt 333 eins: jsr seltxt
333 cmp emaxch 334 cmp emaxch
334 bcs invinput 335 bcs invinput
335 tay 336 tay
336 ldx #$20 ; space 337 ldx #$20 ; space
337 @mvloop: iny 338 @mvloop: iny
338 lda (reg2), y 339 lda (reg2), y
339 pha 340 pha
340 txa 341 txa
341 sta (reg2), y 342 sta (reg2), y
342 pla 343 pla
343 tax 344 tax
344 cpy emaxch 345 cpy emaxch
345 bcc @mvloop 346 bcc @mvloop
346 jmp showpos1 347 jmp showpos1
347 348
348 ecrsrl: jsr seltxt 349 ecrsrl: jsr seltxt
349 beq invinput 350 beq invinput
350 tay 351 tay
351 dey 352 dey
352 jmp showpos 353 jmp showpos
353 354
354 ecrsrr: jsr seltxt 355 ecrsrr: jsr seltxt
355 cmp emaxch 356 cmp emaxch
356 bcs invinput 357 bcs invinput
357 tay 358 tay
358 iny 359 iny
359 jmp showpos 360 jmp showpos
360 361
361 ehome: jsr seltxt 362 ehome: jsr seltxt
362 beq invinput 363 beq invinput
363 ldy #0 364 ldy #0
364 jmp showpos 365 jmp showpos
365 366
366 eclr: jsr seltxt 367 eclr: jsr seltxt
367 ldy emaxch 368 ldy emaxch
368 lda #$20 ; space 369 lda #$20 ; space
369 @clrloop: sta (reg2), y 370 @clrloop: sta (reg2), y
370 dey 371 dey
371 bne @clrloop 372 bne @clrloop
372 jmp showpos 373 jmp showpos
Powered by Google Project Hosting