]> git.sur5r.net Git - cc65/blob - libsrc/geos/mousesprite/mouse.s
interrupt flag is cleared/restored rather than cleared/set
[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         popax, 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 port,
28 ;                                        unsigned char sprite,
29 ;                                        unsigned char type);
30 ;
31
32 _mouse_init:
33         jsr     popax                   ; ignore all parameters
34
35         jsr     StartMouseMode
36         jsr     MouseOff
37
38         lda     #0
39         sta     mouseTop
40         sta     mouseLeft
41         sta     mouseLeft+1
42         lda     #199
43         sta     mouseBottom
44         lda     #<319
45         sta     mouseRight
46         lda     #>319
47         sta     mouseRight+1
48
49         lda     #0
50 ; --------------------------------------------------------------------------
51 ;
52 ; void mouse_done (void);
53 ;
54 _mouse_done:
55         rts
56
57 ; --------------------------------------------------------------------------
58 ;
59 ; void mouse_hide (void);
60 ;
61
62 _mouse_hide = MouseOff
63
64 ; --------------------------------------------------------------------------
65 ;
66 ; void mouse_show (void);
67 ;
68
69 _mouse_show = MouseUp
70
71 ; --------------------------------------------------------------------------
72 ;
73 ; void __fastcall__ mouse_box (int minx, int miny, int maxx, int maxy);
74 ;
75
76 _mouse_box:
77         ldy     #0                      ; Stack offset
78
79         sta     mouseBottom
80
81         lda     (sp),y
82         sta     mouseRight
83         iny
84         lda     (sp),y
85         sta     mouseRight+1            ; maxx
86
87         iny
88         lda     (sp),y
89         sta     mouseTop
90         iny                             ; Skip high byte
91
92         iny
93         lda     (sp),y
94         sta     mouseLeft
95         iny
96         lda     (sp),y
97         sta     mouseLeft+1             ; minx
98
99         jmp     addysp1                 ; Drop params, return
100
101 ; --------------------------------------------------------------------------
102 ;
103 ; void __fastcall__ mouse_pos (struct mouse_pos* pos);
104 ; /* Return the current mouse position */
105 ;
106
107 _mouse_pos:
108         sta     ptr1
109         stx     ptr1+1                  ; Remember the argument pointer
110
111         ldy     #0                      ; Structure offset
112
113         php
114         sei                             ; Disable interrupts
115
116         lda     mouseXPos               ; Transfer the position
117         sta     (ptr1),y
118         lda     mouseXPos+1
119         iny
120         sta     (ptr1),y
121         lda     mouseYPos
122         iny
123         sta     (ptr1),y
124         lda     #$00
125         iny
126         sta     (ptr1),y
127
128         plp                             ; Reenable interrupts
129         rts                             ; Done
130
131 ; --------------------------------------------------------------------------
132 ;
133 ; void __fastcall__ mouse_info (struct mouse_info* info);
134 ; /* Return the state of the mouse buttons and the position of the mouse */
135 ;
136
137 _mouse_info:
138
139 ; We're cheating here to keep the code smaller: The first fields of the
140 ; mouse_info struct are identical to the mouse_pos struct, so we will just
141 ; call _mouse_pos to initialize the struct pointer and fill the position
142 ; fields.
143
144         jsr     _mouse_pos
145
146 ; Fill in the button state
147
148         jsr     _mouse_buttons          ; Will not touch ptr1
149         iny
150         sta     (ptr1),y
151
152         rts
153
154 ; --------------------------------------------------------------------------
155 ;
156 ; void __fastcall__ mouse_move (int x, int y);
157 ;
158
159 _mouse_move:
160         jsr     popsreg                 ; Get X
161         php
162         sei                             ; Disable interrupts
163         sta     mouseYPos
164         lda     sreg
165         ldx     sreg+1
166         sta     mouseXPos
167         stx     mouseXPos+1
168         plp                             ; Enable interrupts
169         rts
170
171 ; --------------------------------------------------------------------------
172 ;
173 ; unsigned char mouse_buttons (void);
174 ;
175
176 _mouse_buttons:
177         lda     pressFlag
178         and     #SET_MOUSE
179         lsr
180         rts
181