1 ;--------------------------------------------------------------------
2 ; Atari 8-bit mouse routines -- 05/07/2000 Freddy Offenga
3 ; Some changes by Christian Groessler, Ullrich von Bassewitz
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, _mouse_pos, _mouse_info
17 .constructor initmouse,27
24 TRAK_BALL = 0 ; device Atari trak-ball
25 ST_MOUSE = 1 ; device ST mouse
26 AMIGA_MOUSE = 2 ; device Amiga mouse
27 MAX_TYPE = 3 ; first illegal device type
29 ; the default values force the mouse cursor inside the test screen (no access to border)
30 defxmin = 48 ; default x minimum
31 defymin = 31 ; default y minimum
32 defxmax = 204 ; default x maximum
33 defymax = 211 ; default y maximum
35 pmsize = 16 ; y size pm shape
37 xinit = defxmin ; init. x pos.
38 yinit = defymin ; init. y pos.
40 ;--------------------------------------------------------------------
41 ; reserve memory for the mouse pointer
45 and #%11111000 ; make 2k aligned
47 sbc #%00001000 ; reserve 2k
49 adc #3 ; add 4 (C = 1)
57 ;--------------------------------------------------------------------
58 ; Initialize mouse routines
59 ; void __fastcall__ mouse_init (unsigned char type);
62 cmp #MAX_TYPE+1 ; Check for a valid type
65 ifail: lda #0 ; init. failed
99 ora #%00000001 ; timer 1 enable
122 ;--------------------------------------------------------------------
123 ; Finish mouse routines
124 ; void mouse_done(void)
129 and #%11111110 ; timer 1 disable
154 ;--------------------------------------------------------------------
156 ; void __fastcall__ mouse_box(int xmin, int ymin, int xmax, int ymax)
160 jsr popax ; always ignore high byte
168 ;--------------------------------------------------------------------
170 ; void __fastcall__ mouse_move(int xpos, int ypos)
173 sta mousey ; always ignore high byte
178 ;--------------------------------------------------------------------
180 ; void mouse_show(void)
183 lda mouse_off ; Already on?
188 ;--------------------------------------------------------------------
190 ; void mouse_hide(void)
196 ;--------------------------------------------------------------------
198 ; unsigned char mouse_buttons(void)
211 ;--------------------------------------------------------------------
212 ; Get the mouse position
213 ; void mouse_pos (struct mouse_pos* pos);
217 stx ptr1+1 ; Store argument pointer
219 lda mousex ; X position
224 lda mousey ; Y position
232 ;--------------------------------------------------------------------
233 ; Get the mouse position and button information
234 ; void mouse_info (struct mouse_info* info);
238 ; We're cheating here to keep the code smaller: The first fields of the
239 ; mouse_info struct are identical to the mouse_pos struct, so we will just
240 ; call _mouse_pos to initialize the struct pointer and fill the position
245 ; Fill in the button state
247 jsr _mouse_buttons ; Will not touch ptr1
253 ;--------------------------------------------------------------------
254 ; Atari trak-ball check, A,Y = 4-bit port value
287 ;--------------------------------------------------------------------
288 ; ST mouse check, A,Y = 4-bit port value
298 dec mousex ; 1 = left
300 xist: inc mousex ; 0 = right
312 yst: inc mousey ; 1 = down
328 ;--------------------------------------------------------------------
329 ; Amiga mouse check, A,Y = 4-bit port value
341 dec mousex ; 0 = left
343 xiami: inc mousex ; 1 = right
356 yiami: inc mousey ; 1 = down
369 ;--------------------------------------------------------------------
370 ; timer 1 IRQ routine - check mouse
386 jsr st_check ; will be modified; won't be ROMmable
395 ;--------------------------------------------------------------------
396 ; VBI - check mouse limits and display mouse arrow
400 bcs ok1 ; xmin <= mousex
406 bcs ok2 ; ymin <= mousey
412 bcs ok3 ; xmax >= mousex
418 bcs ok4 ; ymax >= mousey
438 jmp SYSVBV ; will be modified; won't be ROMmable
440 ;--------------------------------------------------------------------
441 ; initialize mouse pm
443 pminit: lda mouse_pm0
451 clpm: sta $1000,x ; will be patched
471 ;--------------------------------------------------------------------
483 sta $1000,x ; will be patched
490 ;--------------------------------------------------------------------
499 fmp1: sta $1000,x ; will be patched
506 ;--------------------------------------------------------------------
509 ; mouse arrow - pm shape
511 mskpm: .byte %00000000
531 ; ST mouse lookup table
533 sttab: .byte $FF,$01,$00,$01
534 .byte $00,$FF,$00,$01
535 .byte $01,$00,$FF,$00
536 .byte $01,$00,$01,$FF
538 ; Amiga mouse lookup table
540 amitab: .byte $FF,$01,$00,$FF
541 .byte $00,$FF,$FF,$01
542 .byte $01,$FF,$FF,$00
543 .byte $FF,$00,$01,$FF
548 .byte <trak_check, <st_check, <amiga_check
550 .byte >trak_check, >st_check, >amiga_check
562 ;--------------------------------------------------------------------
567 old_t1: .res 2 ; old timer interrupt vector
568 oldval: .res 1 ; used by trakball routines
571 omy: .res 1 ; old y pos