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