]> git.sur5r.net Git - cc65/blob - libsrc/pce/pce-stdjoy.s
added compiler/assembler target, lib compiles
[cc65] / libsrc / pce / pce-stdjoy.s
1
2 ;
3 ; Standard joystick driver for the PCEngine
4 ;
5 ; Ullrich von Bassewitz, 2002-12-20
6 ;
7
8                 ;;.include      "zeropage.inc"
9
10         ;;.include      "joy-kernel.inc"
11         
12                 ;;.include    "joy-error.inc"
13                 JOY_ERR_OK=0;
14         .include    "pcengine.inc"
15
16         .macpack        generic
17
18 ; ------------------------------------------------------------------------
19 ; Header. Includes jump table
20
21 .segment        "CODE"
22
23 ; Driver signature
24
25 ;;        .byte   $6A, $6F, $79         ; "joy"
26 ;;        .byte   $00                     ; Driver API version number
27
28 ; Button state masks (8 values)
29
30 ;extern const unsigned char joy_masks[8];
31
32                 .export _joy_masks
33
34 _joy_masks:
35         .byte   $10                     ; JOY_UP
36         .byte   $40                     ; JOY_DOWN
37         .byte   $80                     ; JOY_LEFT
38         .byte   $20                     ; JOY_RIGHT
39         .byte   $04                     ; ? JOY_FIRE
40         .byte   $02                     ; ? Future expansion
41         .byte   $01                     ; ? Future expansion
42         .byte   $08                     ; ? Future expansion
43
44 ; Jump table.
45
46 ;;        .word   INSTALL
47 ;;        .word   DEINSTALL
48 ;;        .word   COUNT
49 ;;        .word   READ
50
51 ; ------------------------------------------------------------------------
52 ; Constants
53
54 JOY_COUNT       = 4             ; Number of joysticks we support
55
56
57 ; ------------------------------------------------------------------------
58 ; Data.
59
60
61 .code
62
63
64 ;extern const char joy_stddrv[];
65
66                 .export _joy_stddrv
67 _joy_stddrv:
68                 .byte 0
69
70
71                 .export _joy_load_driver
72                 .export _joy_unload
73
74 ;unsigned char __fastcall__ joy_unload (void);
75 ;unsigned char __fastcall__ joy_load_driver (const char* driver);
76 _joy_load_driver:
77 _joy_unload:
78
79 ; ------------------------------------------------------------------------
80 ; INSTALL routine. Is called after the driver is loaded into memory. If
81 ; possible, check if the hardware is present and determine the amount of
82 ; memory available.
83 ; Must return an JOY_ERR_xx code in a/x.
84 ;
85
86 INSTALL:
87         lda     #<JOY_ERR_OK
88         ldx     #>JOY_ERR_OK
89
90 ;       rts                     ; Run into DEINSTALL instead
91
92 ; ------------------------------------------------------------------------
93 ; DEINSTALL routine. Is called before the driver is removed from memory.
94 ; Can do cleanup or whatever. Must not return anything.
95 ;
96
97 DEINSTALL:
98         rts
99
100
101 ; ------------------------------------------------------------------------
102 ; COUNT: Return the total number of available joysticks in a/x.
103 ;
104 ;unsigned char __fastcall__ joy_count (void);
105
106                 .export _joy_count
107
108 _joy_count:
109 COUNT:
110         lda     #<JOY_COUNT
111         ldx     #>JOY_COUNT
112         rts
113
114 ; ------------------------------------------------------------------------
115 ; READ: Read a particular joystick passed in A.
116 ;
117 ;unsigned char __fastcall__ joy_read (unsigned char joystick);
118
119                 .export _joy_read
120
121 _joy_read:
122 READ:
123                 pha
124         jsr read_joy
125         pla
126                 tax             ; Joystick number into X
127
128         ; return value from buffer
129
130 joy1:
131         lda padbuffer,x
132                 ldx #0
133         rts
134
135 .code
136
137 read_joy:
138         ; reset multitap counter
139         lda     #$01
140         sta     $1000
141         pha
142         pla
143         nop
144         nop
145
146         lda     #$03
147         sta     $1000
148         pha
149         pla
150         nop
151         nop
152
153         cly
154 nextpad:
155         lda     #$01
156         sta     $1000   ; sel = 1
157         pha
158         pla
159         nop
160         nop
161
162         lda     $1000
163         asl     a
164         asl     a
165         asl     a
166         asl     a
167         sta     padbuffer, y     ; store new value
168
169         stz     $1000
170         pha
171         pla
172         nop
173         nop
174
175         lda     $1000
176         and     #$0F
177         ora     padbuffer, y     ; second half of new value
178
179         eor     #$FF
180         sta     padbuffer, y     ; store new value
181
182         iny
183         cpy     #$05
184         bcc     nextpad
185         rts
186
187 .bss
188
189 padbuffer:
190         .res 4
191