1 ;--------------------------------------------------------------------
2 ; Atari 8-bit mouse routines -- 05/07/2000 Freddy Offenga
3 ; Some changes by Christian Groessler
5 ; The following devices are supported:
10 ; Mouse checks are done in the timer 1 IRQ and the mouse arrow is
11 ; drawn in player 0 during the vertical blank
12 ;--------------------------------------------------------------------
14 .export _mouse_init, _mouse_done, _mouse_box
15 .export _mouse_show, _mouse_hide, _mouse_move
16 .export _mouse_buttons
18 .import popa,popax,mouse_pm0
22 TRAK_BALL = 0 ; device Atari trak-ball
23 ST_MOUSE = 1 ; device ST mouse
24 AMIGA_MOUSE = 2 ; device Amiga mouse
25 MAX_TYPE = 3 ; first illegal device type
27 ; the default values force the mouse cursor inside the test screen (no access to border)
28 defxmin = 48 ; default x minimum
29 defymin = 32 ; default y minimum
30 defxmax = 204 ; default x maximum
31 defymax = 211 ; default y maximum
33 pmsize = 16 ; y size pm shape
35 xinit = defxmin ; init. x pos.
36 yinit = defymin ; init. y pos.
38 ;--------------------------------------------------------------------
39 ; Initialize mouse routines
40 ; void __fastcall__ mouse_init (unsigned char port, unsigned char sprite, unsigned char type);
43 pha ; remember mouse type
44 jsr popa ; ignore sprite / pm for now
47 pla ; get mouse type again
52 ifail: lda #0 ; init. failed
86 ora #%00000001 ; timer 1 enable
109 ;--------------------------------------------------------------------
110 ; Finish mouse routines
111 ; void mouse_done(void)
116 and #%11111110 ; timer 1 disable
140 ;--------------------------------------------------------------------
142 ; void __fastcall__ mouse_box(int xmin, int ymin, int xmax, int ymax)
146 jsr popax ; always ignore high byte
154 ;--------------------------------------------------------------------
156 ; void __fastcall__ mouse_move(int xpos, int ypos)
159 sta mousey ; always ignore high byte
164 ;--------------------------------------------------------------------
166 ; void mouse_show(void)
173 ;--------------------------------------------------------------------
175 ; void mouse_hide(void)
182 ;--------------------------------------------------------------------
184 ; unsigned char mouse_buttons(void)
199 ;--------------------------------------------------------------------
200 ; Atari trak-ball check, A,Y = 4-bit port value
233 ;--------------------------------------------------------------------
234 ; ST mouse check, A,Y = 4-bit port value
244 dec mousex ; 1 = left
246 xist: inc mousex ; 0 = right
258 yst: inc mousey ; 1 = down
274 ;--------------------------------------------------------------------
275 ; Amiga mouse check, A,Y = 4-bit port value
287 dec mousex ; 0 = left
289 xiami: inc mousex ; 1 = right
302 yiami: inc mousey ; 1 = down
315 ;--------------------------------------------------------------------
316 ; timer 1 IRQ routine - check mouse
329 lsr ; even number 0/2
345 jsr st_check ; will be modified; won't be ROMmable
354 ;--------------------------------------------------------------------
355 ; VBI - check mouse limits and display mouse arrow
359 bcs ok1 ; xmin <= mousex
365 bcs ok2 ; ymin <= mousey
371 bcs ok3 ; xmax >= mousex
377 bcs ok4 ; ymax >= mousey
397 jmp SYSVBV ; will be modified; won't be ROMmable
399 ;--------------------------------------------------------------------
400 ; initialize mouse pm
402 pminit: lda mouse_pm0
410 clpm: sta $1000,x ; will be patched
430 ;--------------------------------------------------------------------
442 sta $1000,x ; will be patched
449 ;--------------------------------------------------------------------
458 fmp1: sta $1000,x ; will be patched
465 ;--------------------------------------------------------------------
468 ; mouse arrow - pm shape
470 mskpm: .byte %00000000
490 ; ST mouse lookup table
492 sttab: .byte $FF,$01,$00,$01
493 .byte $00,$FF,$00,$01
494 .byte $01,$00,$FF,$00
495 .byte $01,$00,$01,$FF
497 ; Amiga mouse lookup table
499 amitab: .byte $FF,$01,$00,$FF
500 .byte $00,$FF,$FF,$01
501 .byte $01,$FF,$FF,$00
502 .byte $FF,$00,$01,$FF
507 .byte <trak_check, <st_check, <amiga_check
509 .byte >trak_check, >st_check, >amiga_check
521 ;--------------------------------------------------------------------
526 old_t1: .res 2 ; old timer interrupt vector
527 oldval: .res 1 ; used by trakball routines
530 omy: .res 1 ; old y pos