]> git.sur5r.net Git - cc65/blob - libsrc/geos/mousesprite/mouse.s
fixed bug on C64 GEOS (I/O was not enabled when reading joystick)
[cc65] / libsrc / geos / mousesprite / mouse.s
1 ;
2 ; Maciej 'YTM/Elysium' Witkowiak
3 ;
4 ; 2.7.2001
5 ;
6 ; Wrapper for GEOS standard input device interface
7 ;
8                                          
9         .export         _mouse_init, _mouse_done
10         .export         _mouse_hide, _mouse_show
11         .export         _mouse_box
12         .export         _mouse_pos, _mouse_info
13         .export         _mouse_move, _mouse_buttons
14
15         .import         popsreg, addysp1
16         .importzp       sp, sreg, ptr1
17
18         .include "../inc/const.inc"
19         .include "../inc/jumptab.inc"
20         .include "../inc/geossym.inc"
21
22
23 .code
24
25 ; --------------------------------------------------------------------------
26 ;
27 ; unsigned char __fastcall__ mouse_init (unsigned char type);
28 ;
29
30 _mouse_init:
31         jsr     StartMouseMode
32         jsr     MouseOff
33
34         lda     #0
35         sta     mouseTop
36         sta     mouseLeft
37         sta     mouseLeft+1
38         lda     #199
39         sta     mouseBottom
40         lda     graphMode
41         bpl     _mse_screen320
42
43         lda     #<639                   ; 80 columns on C128
44         ldx     #>639
45         bne     _mse_storex
46 _mse_screen320:
47         lda     #<319                   ; 40 columns on C64/C128
48         ldx     #>319
49 _mse_storex:
50         sta     mouseRight
51         stx     mouseRight+1
52 _mse_initend:
53         lda     #0
54 ; --------------------------------------------------------------------------
55 ;
56 ; void mouse_done (void);
57 ;
58 _mouse_done:
59         rts
60
61 ; --------------------------------------------------------------------------
62 ;
63 ; void mouse_hide (void);
64 ;
65
66 _mouse_hide = MouseOff
67
68 ; --------------------------------------------------------------------------
69 ;
70 ; void mouse_show (void);
71 ;
72
73 _mouse_show = MouseUp
74
75 ; --------------------------------------------------------------------------
76 ;
77 ; void __fastcall__ mouse_box (int minx, int miny, int maxx, int maxy);
78 ;
79
80 _mouse_box:
81         ldy     #0                      ; Stack offset
82
83         sta     mouseBottom
84
85         lda     (sp),y
86         sta     mouseRight
87         iny
88         lda     (sp),y
89         sta     mouseRight+1            ; maxx
90
91         iny
92         lda     (sp),y
93         sta     mouseTop
94         iny                             ; Skip high byte
95
96         iny
97         lda     (sp),y
98         sta     mouseLeft
99         iny
100         lda     (sp),y
101         sta     mouseLeft+1             ; minx
102
103         jmp     addysp1                 ; Drop params, return
104
105 ; --------------------------------------------------------------------------
106 ;
107 ; void __fastcall__ mouse_pos (struct mouse_pos* pos);
108 ; /* Return the current mouse position */
109 ;
110
111 _mouse_pos:
112         sta     ptr1
113         stx     ptr1+1                  ; Remember the argument pointer
114
115         ldy     #0                      ; Structure offset
116
117         php
118         sei                             ; Disable interrupts
119
120         lda     mouseXPos               ; Transfer the position
121         sta     (ptr1),y
122         lda     mouseXPos+1
123         iny
124         sta     (ptr1),y
125         lda     mouseYPos
126         iny
127         sta     (ptr1),y
128         lda     #$00
129         iny
130         sta     (ptr1),y
131
132         plp                             ; Reenable interrupts
133         rts                             ; Done
134
135 ; --------------------------------------------------------------------------
136 ;
137 ; void __fastcall__ mouse_info (struct mouse_info* info);
138 ; /* Return the state of the mouse buttons and the position of the mouse */
139 ;
140
141 _mouse_info:
142
143 ; We're cheating here to keep the code smaller: The first fields of the
144 ; mouse_info struct are identical to the mouse_pos struct, so we will just
145 ; call _mouse_pos to initialize the struct pointer and fill the position
146 ; fields.
147
148         jsr     _mouse_pos
149
150 ; Fill in the button state
151
152         jsr     _mouse_buttons          ; Will not touch ptr1
153         iny
154         sta     (ptr1),y
155
156         rts
157
158 ; --------------------------------------------------------------------------
159 ;
160 ; void __fastcall__ mouse_move (int x, int y);
161 ;
162
163 _mouse_move:
164         jsr     popsreg                 ; Get X
165         php
166         sei                             ; Disable interrupts
167         sta     mouseYPos
168         lda     sreg
169         ldx     sreg+1
170         sta     mouseXPos
171         stx     mouseXPos+1
172         plp                             ; Enable interrupts
173         rts
174
175 ; --------------------------------------------------------------------------
176 ;
177 ; unsigned char mouse_buttons (void);
178 ;
179
180 _mouse_buttons:
181         lda     pressFlag
182         and     #SET_MOUSE
183         lsr
184         rts
185