comparison menu.s68 @ 909:e60eb88d7b09

Added mouse support to menu ROM
author Michael Pavone <pavone@retrodev.com>
date Sat, 05 Dec 2015 00:17:15 -0800
parents 7022ba865cfd
children c030e4af32b7
comparison
equal deleted inserted replaced
908:20e30ca7e8a2 909:e60eb88d7b09
173 base_cmd rs.l 1 173 base_cmd rs.l 1
174 sprite_list rs.l 160 174 sprite_list rs.l 160
175 page_index rs.l MAX_DISPLAY+1 175 page_index rs.l MAX_DISPLAY+1
176 page_stack rs.l 1 176 page_stack rs.l 1
177 page_pointers rs.l 1024 177 page_pointers rs.l 1024
178 mouse_sprite rs.l 1
179 mouse_x rs.w 1
178 num_sprites rs.b 1 180 num_sprites rs.b 1
179 last_pad rs.b 1 181 last_pad1 rs.b 1
182 last_pad2 rs.b 1
180 selected rs.b 1 183 selected rs.b 1
181 more_pages rs.b 1 184 more_pages rs.b 1
185 mouse_buf rs.b 3
186 mouse_shown rs.b 1
187 last_mbuttons rs.b 1
182 188
183 189
184 int_6: 190 int_6:
185 dmasrc sprite_list, DMA_SRC_68K 191 dmasrc sprite_list, DMA_SRC_68K
186 ;set DMA length 192 ;set DMA length
194 lsr.w #8, d1 200 lsr.w #8, d1
195 move.b d1, d0 201 move.b d1, d0
196 move.l d0, (a1) 202 move.l d0, (a1)
197 startdma $C000, VDP_VRAM_WRITE 203 startdma $C000, VDP_VRAM_WRITE
198 204
199 ;read gamepad in port 1 205 ;read gamepad/mouse in port 1
200 lea PAD1_DATA, a2 206 lea PAD1_DATA, a2
201 move.b #$40, (a2) 207
202 move.b (a2), d0 208 bsr io_read
203 and.b #$3F, d0 209
204 move.b d0, (a2) 210 cmp.b #3, d2
205 move.b (a2), d1 211 beq .mouse
206 and.b #$30, d1 212
207 add.b d1, d1 213 move.b last_pad1.w, d1
208 add.b d1, d1
209 or.b d1, d0
210 not.b d0 ;button state is inveterted
211 move.b (last_pad).w, d1
212 eor.b d0, d1 214 eor.b d0, d1
213 and.b d0, d1 215 and.b d0, d1
214 move.b d0, (last_pad).w 216 move.b d0, last_pad1.w
215 217
218 bsr handle_pad_buttons
219
220 bra pad2
221 .mouse
222 bsr handle_mouse
223
224 pad2:
225 ;read gamepad/mouse in port 2
226 lea PAD2_DATA, a2
227
228 bsr io_read
229
230 cmp.b #3, d2
231 beq .mouse
232
233 move.b last_pad2.w, d1
234 eor.b d0, d1
235 and.b d0, d1
236 move.b d0, last_pad2.w
237
238 bsr handle_pad_buttons
239 rte
240 .mouse
241 bsr handle_mouse
242 rte
243
244
245 ;d0 = SACBRLUD
246 ;d1 = newly pressed buttons
247 handle_pad_buttons:
216 moveq #16, d2 248 moveq #16, d2
217 ;d0 = SACBRLUD
218 ;d1 = newly pressed buttons
219 btst #1, d1 249 btst #1, d1
220 bne down 250 bne down
221 btst #0, d1 251 btst #0, d1
222 bne up 252 bne up
223 btst #3, d1 253 btst #3, d1
224 bne right 254 bne right
225 btst #2, d1 255 btst #2, d1
226 bne left 256 bne left
227 btst #7, d1 257 btst #7, d1
228 bne start_pressed 258 bne select_entry
229 int_done: 259 btst #5, d1
230 rte 260 bne select_entry
261 handle_done:
262 rts
231 263
232 down: 264 down:
233 ;check if we are already at the bottom of the page 265 ;check if we are already at the bottom of the page
234 moveq #1, d0 266 moveq #1, d0
235 add.b (selected).w, d0 267 add.b (selected).w, d0
236 move.w d0, d1 268 move.w d0, d1
237 add.w d0, d0 269 add.w d0, d0
238 add.w d0, d0 270 add.w d0, d0
239 lea page_index.w, a2 271 lea page_index.w, a2
240 tst.l (0, a2, d0.w) 272 tst.l (0, a2, d0.w)
241 beq int_done 273 beq handle_done
242 move.b d1, (selected).w 274 move.b d1, (selected).w
243 275
244 add.w d2, (sprite_list).w 276 add.w d2, (sprite_list).w
245 add.w d2, (sprite_list+8).w 277 add.w d2, (sprite_list+8).w
246 rte 278 rts
247 up: 279 up:
248 ;check if we are already at the top of the page 280 ;check if we are already at the top of the page
249 move.b (selected).w, d0 281 move.b (selected).w, d0
250 beq int_done 282 beq handle_done
251 subq #1, d0 283 subq #1, d0
252 move.b d0, (selected).w 284 move.b d0, (selected).w
253 285
254 sub.w d2, (sprite_list).w 286 sub.w d2, (sprite_list).w
255 sub.w d2, (sprite_list+8).w 287 sub.w d2, (sprite_list+8).w
256 rte 288 rts
257 289
258 right: 290 right:
259 ;check that we have another page to go to 291 ;check that we have another page to go to
260 tst.b more_pages.w 292 tst.b more_pages.w
261 beq int_done 293 beq handle_done
262 ;switch to the next page 294 ;switch to the next page
263 move.l page_stack.w, a6 295 move.l page_stack.w, a6
264 move.l (-4, a6), a6 296 move.l (-4, a6), a6
265 297
266 addq #6, a7 298 addq #6, a7
268 300
269 left: 301 left:
270 move.l page_stack.w, a5 302 move.l page_stack.w, a5
271 ;check if we're already on the first page 303 ;check if we're already on the first page
272 cmp.l #(page_pointers+8), a5 304 cmp.l #(page_pointers+8), a5
273 beq int_done 305 beq handle_done
274 ;switch to previous page 306 ;switch to previous page
275 lea (-12, a5), a5 307 lea (-12, a5), a5
276 move.l (a5)+, a6 308 move.l (a5)+, a6
277 move.l a5, page_stack.w 309 move.l a5, page_stack.w
278 310
279 addq #6, a7 311 addq #6, a7
280 bra render_page 312 bra render_page
281 313
282 start_pressed: 314 select_entry:
283 moveq #0, d0 315 moveq #0, d0
284 move.b (selected).w, d0 316 move.b (selected).w, d0
285 add.w d0, d0 317 add.w d0, d0
286 add.w d0, d0 318 add.w d0, d0
287 lea page_index.w, a2 319 lea page_index.w, a2
289 tst.b (-1, a2) 321 tst.b (-1, a2)
290 bne enter_dir 322 bne enter_dir
291 ;regular file 323 ;regular file
292 lea menu_port+8, a3 324 lea menu_port+8, a3
293 move.l a2, (a3) 325 move.l a2, (a3)
294 rte 326 rts
295 enter_dir: 327 enter_dir:
296 lea menu_port+4, a3 328 lea menu_port+4, a3
297 move.l a2, (a3) 329 move.l a2, (a3)
298 .wait_complete 330 .wait_complete
299 tst.w (a3) 331 tst.w (a3)
300 bne .wait_complete 332 bne .wait_complete
301 addq #6, a7 333 addq #6, a7
302 bra menu_start 334 bra menu_start
335
336 handle_mouse:
337 move.b last_mbuttons.w, d4
338 eor.b d3, d4
339 and.b d3, d4
340 move.b d3, last_mbuttons.w
341
342 move.b d0, d2
343 or.b d1, d2
344 beq .no_mouse_move
345
346
347 tst.b mouse_shown.w
348 bne .skip_show_check
349
350 moveq #0, d2
351 move.b num_sprites.w, d2
352 move.w d2, d4
353 lsl.w #3, d4
354 lea sprite_list.w, a2
355 move.b d2, (-5, a2, d4.w)
356 lea (0, a2, d4.w), a2
357 move.l a2, mouse_sprite.w
358 move.l #$01000500, (a2)+
359 move.w #$8083, (a2)
360 move.w #$100, mouse_x.w
361 addq #1, d2
362 move.b d2, num_sprites.w
363
364 move.b #1, mouse_shown.w
365
366 .skip_show_check
367 move.l mouse_sprite.w, a2
368 add.w d1, (a2)
369 add.w d0, mouse_x.w
370 move.w mouse_x.w, d0
371 asr.w #1, d0
372 move.w d0, (6, a2)
373 move.w (a2), d1
374 cmp.w #272, d1
375 blo .done
376 cmp.w #655, d1
377 bhi .done
378 and.w #$FFF0, d1
379 subq #8, d1
380 move.w d1, (sprite_list).w
381 move.w d1, (sprite_list+8).w
382
383 sub.w #264, d1
384 lsr.w #4, d1
385 move.b d1, selected.w
386 .no_mouse_move
387 btst #0, d4
388 bne select_entry
389 .done
390 rts
303 int_4: 391 int_4:
304 empty_handler: 392 empty_handler:
305 rte 393 rte
394
395 id_lookup:
396 dc.b $0, $1, $4, $5
397 dc.b $2, $3, $6, $7
398 dc.b $8, $9, $C, $D
399 dc.b $A, $B, $E, $F
400
401 io_read:
402 ;read TH=1
403 move.b (a2), d0
404 ;read TH=0
405 move.b #0, (a2)
406 nop
407 nop
408 move.b (a2), d1
409 ;reset TH to 1
410 move.b #$40, (a2)
411
412 moveq #0, d2 ;4
413
414 ;calculate Mega Drive peripheral ID
415 move.b d1, d2 ;4
416 lsr.b #1, d2 ;8, 12
417 or.b d1, d2 ;4, 16
418 and.b #5, d2 ;8, 24
419
420 move.b d0, d3 ;4
421 add.b d3, d3 ;4, 8
422 or.b d0, d3 ;4, 12
423 and.b #$A, d3 ;8, 20
424
425 or.b d3, d2 ;4
426 move.b (id_lookup, pc, d2.w), d2 ;14
427
428
429 cmp.b #$3, d2
430 beq .mouse
431
432 cmp.b #$D, d2
433 bne .not_pad
434
435 and.b #$3F, d0
436 and.b #$30, d1
437 add.b d1, d1
438 add.b d1, d1
439 or.b d1, d0
440 not.b d0
441 rts
442 .not_pad:
443 moveq #0, d0
444 rts
445
446 .mouse:
447
448 move.b #$60, (a2)
449 move.b #$60, (PAD1_CTRL-PAD1_DATA, a2)
450 move.b #$60, (a2)
451
452 moveq #$f, d4
453 wait_hi_init:
454 btst #4, (a2)
455 beq wait_hi_init
456 nop
457 nop
458 move.b #$20, (a2)
459 nop
460 nop
461 moveq #$f, d4
462 move.b #0, (a2)
463 .wait_lo
464 btst #4, (a2)
465 bne .wait_lo
466 moveq #$f, d4
467 move.b #$20, (a2)
468 .wait_hi
469 btst #4, (a2)
470 beq .wait_hi
471
472 lea mouse_buf.w, a3
473 move.l a3, a4
474 moveq #2, d3
475 moveq #0, d0
476 loop:
477 moveq #$f, d4
478 move.b #0, (a2)
479 .wait_lo
480 btst #4, (a2)
481 bne .wait_lo
482 move.b (a2), d0
483 lsl.b #4, d0
484 moveq #$f, d4
485 move.b #$20, (a2)
486 .wait_hi
487 btst #4, (a2)
488 beq .wait_hi
489 move.b (a2), d1
490 and.b #$f, d1
491 or.b d1, d0
492 move.b d0, (a3)+
493
494 dbra d3, loop
495
496 ;end request
497 move.b #$60, (a2)
498
499
500 ;massage data
501 moveq #0, d1
502 move.b d0, d1
503 move.b (a4)+, d3
504 move.b (a4), d0
505
506 btst #4, d3
507 beq xpos
508 neg.w d0
509 xpos
510 btst #5, d3
511 beq ypos
512 neg.w d1
513 ypos
514 ;set port config back to normal controller mode
515 move.b #$40, (PAD1_CTRL-PAD1_DATA, a2)
516 rts
306 517
307 518
308 519
309 initial_regs: 520 initial_regs:
310 vdpreg MODE_2, $4 ;Mode 5, everything turned off 521 vdpreg MODE_2, $4 ;Mode 5, everything turned off
320 vdpreg AUTOINC, 2 531 vdpreg AUTOINC, 2
321 vdpreg SCROLL, 1 ;64x32 scroll size 532 vdpreg SCROLL, 1 ;64x32 scroll size
322 end_initial_regs 533 end_initial_regs
323 534
324 start: 535 start:
536 lea $FF0000, a0
537 moveq #0, d0
538 move.w #($10000/8 - 1), d1
539 .clearloop:
540 move.l d0, (a0)+
541 move.l d0, (a0)+
542 dbra d1, .clearloop
543
325 lea $C00000, a0 544 lea $C00000, a0
326 lea $C00004, a1 545 lea $C00004, a1
327 546
328 moveq #(end_initial_regs-initial_regs-1), d0 547 moveq #(end_initial_regs-initial_regs-1), d0
329 lea initial_regs.w, a2 548 lea initial_regs.w, a2
342 move.w #4, (a0) 561 move.w #4, (a0)
343 562
344 ;load tiles 563 ;load tiles
345 vdpaccess $800, VDP_VRAM_WRITE 564 vdpaccess $800, VDP_VRAM_WRITE
346 lea font(pc), a2 565 lea font(pc), a2
347 move.w #((arrowend-font)/4 - 1), d0 566 move.w #((cursorend-font)/4 - 1), d0
348 tloop: 567 tloop:
349 move.l (a2)+, (a0) 568 move.l (a2)+, (a0)
350 dbra d0, tloop 569 dbra d0, tloop
351 570
352 571
438 657
439 ;null terminate page_index 658 ;null terminate page_index
440 moveq #0, d0 659 moveq #0, d0
441 move.l d0, (a3) 660 move.l d0, (a3)
442 661
443 ;setup gamepad in port 1 662 ;setup gamepads
444 move.b #$40, PAD1_CTRL 663 move.b #$40, PAD1_CTRL
664 move.b #$40, PAD2_CTRL
445 665
446 move.w #$8174, (a1) ;enable display, vertical interrupts, DMA 666 move.w #$8174, (a1) ;enable display, vertical interrupts, DMA
447 667
448 668
449 wait_forever 669 wait_forever
507 incbin font_interlace_variable.tiles 727 incbin font_interlace_variable.tiles
508 fontend 728 fontend
509 arrow: 729 arrow:
510 incbin arrow.tiles 730 incbin arrow.tiles
511 arrowend: 731 arrowend:
732 cursor:
733 incbin cursor.tiles
734 cursorend:
512 735
513 widths: 736 widths:
514 dc.b 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1 737 dc.b 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1
515 dc.b 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0 738 dc.b 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0
516 dc.b 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1 739 dc.b 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1