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 = 32 ; 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 port, unsigned char sprite, unsigned char type);
62 pha ; remember mouse type
63 jsr popa ; ignore sprite / pm for now
66 pla ; get mouse type again
71 ifail: lda #0 ; init. failed
105 ora #%00000001 ; timer 1 enable
128 ;--------------------------------------------------------------------
129 ; Finish mouse routines
130 ; void mouse_done(void)
135 and #%11111110 ; timer 1 disable
159 ;--------------------------------------------------------------------
161 ; void __fastcall__ mouse_box(int xmin, int ymin, int xmax, int ymax)
165 jsr popax ; always ignore high byte
173 ;--------------------------------------------------------------------
175 ; void __fastcall__ mouse_move(int xpos, int ypos)
178 sta mousey ; always ignore high byte
183 ;--------------------------------------------------------------------
185 ; void mouse_show(void)
191 ;--------------------------------------------------------------------
193 ; void mouse_hide(void)
201 ;--------------------------------------------------------------------
203 ; unsigned char mouse_buttons(void)
218 ;--------------------------------------------------------------------
219 ; Get the mouse position
220 ; void mouse_pos (struct mouse_pos* pos);
224 stx ptr1+1 ; Store argument pointer
226 lda mousex ; X position
231 lda mousey ; Y position
239 ;--------------------------------------------------------------------
240 ; Get the mouse position and button information
241 ; void mouse_info (struct mouse_info* info);
245 ; We're cheating here to keep the code smaller: The first fields of the
246 ; mouse_info struct are identical to the mouse_pos struct, so we will just
247 ; call _mouse_pos to initialize the struct pointer and fill the position
252 ; Fill in the button state
254 jsr _mouse_buttons ; Will not touch ptr1
260 ;--------------------------------------------------------------------
261 ; Atari trak-ball check, A,Y = 4-bit port value
294 ;--------------------------------------------------------------------
295 ; ST mouse check, A,Y = 4-bit port value
305 dec mousex ; 1 = left
307 xist: inc mousex ; 0 = right
319 yst: inc mousey ; 1 = down
335 ;--------------------------------------------------------------------
336 ; Amiga mouse check, A,Y = 4-bit port value
348 dec mousex ; 0 = left
350 xiami: inc mousex ; 1 = right
363 yiami: inc mousey ; 1 = down
376 ;--------------------------------------------------------------------
377 ; timer 1 IRQ routine - check mouse
390 lsr ; even number 0/2
406 jsr st_check ; will be modified; won't be ROMmable
415 ;--------------------------------------------------------------------
416 ; VBI - check mouse limits and display mouse arrow
420 bcs ok1 ; xmin <= mousex
426 bcs ok2 ; ymin <= mousey
432 bcs ok3 ; xmax >= mousex
438 bcs ok4 ; ymax >= mousey
458 jmp SYSVBV ; will be modified; won't be ROMmable
460 ;--------------------------------------------------------------------
461 ; initialize mouse pm
463 pminit: lda mouse_pm0
471 clpm: sta $1000,x ; will be patched
491 ;--------------------------------------------------------------------
503 sta $1000,x ; will be patched
510 ;--------------------------------------------------------------------
519 fmp1: sta $1000,x ; will be patched
526 ;--------------------------------------------------------------------
529 ; mouse arrow - pm shape
531 mskpm: .byte %00000000
551 ; ST mouse lookup table
553 sttab: .byte $FF,$01,$00,$01
554 .byte $00,$FF,$00,$01
555 .byte $01,$00,$FF,$00
556 .byte $01,$00,$01,$FF
558 ; Amiga mouse lookup table
560 amitab: .byte $FF,$01,$00,$FF
561 .byte $00,$FF,$FF,$01
562 .byte $01,$FF,$FF,$00
563 .byte $FF,$00,$01,$FF
568 .byte <trak_check, <st_check, <amiga_check
570 .byte >trak_check, >st_check, >amiga_check
582 ;--------------------------------------------------------------------
587 old_t1: .res 2 ; old timer interrupt vector
588 oldval: .res 1 ; used by trakball routines
591 omy: .res 1 ; old y pos