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
17 .constructor initmouse,27
23 TRAK_BALL = 0 ; device Atari trak-ball
24 ST_MOUSE = 1 ; device ST mouse
25 AMIGA_MOUSE = 2 ; device Amiga mouse
26 MAX_TYPE = 3 ; first illegal device type
28 ; the default values force the mouse cursor inside the test screen (no access to border)
29 defxmin = 48 ; default x minimum
30 defymin = 32 ; default y minimum
31 defxmax = 204 ; default x maximum
32 defymax = 211 ; default y maximum
34 pmsize = 16 ; y size pm shape
36 xinit = defxmin ; init. x pos.
37 yinit = defymin ; init. y pos.
39 ;--------------------------------------------------------------------
40 ; reserve memory for the mouse pointer
44 and #%11111000 ; make 2k aligned
46 sbc #%00001000 ; reserve 2k
48 adc #3 ; add 4 (C = 1)
56 ;--------------------------------------------------------------------
57 ; Initialize mouse routines
58 ; void __fastcall__ mouse_init (unsigned char port, unsigned char sprite, unsigned char type);
61 pha ; remember mouse type
62 jsr popa ; ignore sprite / pm for now
65 pla ; get mouse type again
70 ifail: lda #0 ; init. failed
104 ora #%00000001 ; timer 1 enable
127 ;--------------------------------------------------------------------
128 ; Finish mouse routines
129 ; void mouse_done(void)
134 and #%11111110 ; timer 1 disable
158 ;--------------------------------------------------------------------
160 ; void __fastcall__ mouse_box(int xmin, int ymin, int xmax, int ymax)
164 jsr popax ; always ignore high byte
172 ;--------------------------------------------------------------------
174 ; void __fastcall__ mouse_move(int xpos, int ypos)
177 sta mousey ; always ignore high byte
182 ;--------------------------------------------------------------------
184 ; void mouse_show(void)
191 ;--------------------------------------------------------------------
193 ; void mouse_hide(void)
200 ;--------------------------------------------------------------------
202 ; unsigned char mouse_buttons(void)
217 ;--------------------------------------------------------------------
218 ; Atari trak-ball check, A,Y = 4-bit port value
251 ;--------------------------------------------------------------------
252 ; ST mouse check, A,Y = 4-bit port value
262 dec mousex ; 1 = left
264 xist: inc mousex ; 0 = right
276 yst: inc mousey ; 1 = down
292 ;--------------------------------------------------------------------
293 ; Amiga mouse check, A,Y = 4-bit port value
305 dec mousex ; 0 = left
307 xiami: inc mousex ; 1 = right
320 yiami: inc mousey ; 1 = down
333 ;--------------------------------------------------------------------
334 ; timer 1 IRQ routine - check mouse
347 lsr ; even number 0/2
363 jsr st_check ; will be modified; won't be ROMmable
372 ;--------------------------------------------------------------------
373 ; VBI - check mouse limits and display mouse arrow
377 bcs ok1 ; xmin <= mousex
383 bcs ok2 ; ymin <= mousey
389 bcs ok3 ; xmax >= mousex
395 bcs ok4 ; ymax >= mousey
415 jmp SYSVBV ; will be modified; won't be ROMmable
417 ;--------------------------------------------------------------------
418 ; initialize mouse pm
420 pminit: lda mouse_pm0
428 clpm: sta $1000,x ; will be patched
448 ;--------------------------------------------------------------------
460 sta $1000,x ; will be patched
467 ;--------------------------------------------------------------------
476 fmp1: sta $1000,x ; will be patched
483 ;--------------------------------------------------------------------
486 ; mouse arrow - pm shape
488 mskpm: .byte %00000000
508 ; ST mouse lookup table
510 sttab: .byte $FF,$01,$00,$01
511 .byte $00,$FF,$00,$01
512 .byte $01,$00,$FF,$00
513 .byte $01,$00,$01,$FF
515 ; Amiga mouse lookup table
517 amitab: .byte $FF,$01,$00,$FF
518 .byte $00,$FF,$FF,$01
519 .byte $01,$FF,$FF,$00
520 .byte $FF,$00,$01,$FF
525 .byte <trak_check, <st_check, <amiga_check
527 .byte >trak_check, >st_check, >amiga_check
539 ;--------------------------------------------------------------------
544 old_t1: .res 2 ; old timer interrupt vector
545 oldval: .res 1 ; used by trakball routines
548 omy: .res 1 ; old y pos