]> git.sur5r.net Git - cc65/blob - libsrc/pce/joy/pce-stdjoy.s
style fixes
[cc65] / libsrc / pce / joy / pce-stdjoy.s
1
2 ;
3 ; Standard joystick driver for the PCEngine
4 ;
5
6         .include        "joy-kernel.inc"
7         .include        "joy-error.inc"
8         .include        "pce.inc"
9
10         .macpack        module
11
12
13 ; ------------------------------------------------------------------------
14 ; Header. Includes jump table
15
16         module_header   _pce_stdjoy_joy
17
18 ; Driver signature
19
20         .byte   $6A, $6F, $79           ; "joy"
21         .byte   JOY_API_VERSION         ; Driver API version number
22
23 ; Library reference
24
25         .addr   $0000
26
27 ; Button state masks (8 values)
28
29         .byte   $10                     ; JOY_UP
30         .byte   $40                     ; JOY_DOWN
31         .byte   $80                     ; JOY_LEFT
32         .byte   $20                     ; JOY_RIGHT
33         .byte   $01                     ; JOY_FIRE_A
34         .byte   $02                     ; JOY_FIRE_B
35         .byte   $04                     ; JOY_SELECT
36         .byte   $08                     ; JOY_RUN
37
38 ; Jump table.
39
40         .addr   INSTALL
41         .addr   UNINSTALL
42         .addr   COUNT
43         .addr   READJOY
44         .addr   0                       ; IRQ entry unused
45
46 ; ------------------------------------------------------------------------
47 ; Constants
48
49 JOY_COUNT       = 4             ; Number of joysticks we support
50
51
52 .code
53
54 ; ------------------------------------------------------------------------
55 ; INSTALL routine. Is called after the driver is loaded into memory. If
56 ; possible, check if the hardware is present and determine the amount of
57 ; memory available.
58 ; Must return an JOY_ERR_xx code in a/x.
59 ;
60
61 INSTALL:
62         lda     #<JOY_ERR_OK
63         ldx     #>JOY_ERR_OK
64
65 ;        rts                     ; Run into UNINSTALL instead
66
67 ; ------------------------------------------------------------------------
68 ; DEINSTALL routine. Is called before the driver is removed from memory.
69 ; Can do cleanup or whatever. Must not return anything.
70 ;
71
72 UNINSTALL:
73         rts
74
75
76 ; ------------------------------------------------------------------------
77 ; COUNT: Return the total number of available joysticks in a/x.
78 ;
79 ;unsigned char __fastcall__ joy_count (void);
80
81 COUNT:
82         lda     #<JOY_COUNT
83         ldx     #>JOY_COUNT
84         rts
85
86 ; ------------------------------------------------------------------------
87 ; READ: Read a particular joystick passed in A.
88 ;
89 ;unsigned char __fastcall__ joy_read (unsigned char joystick);
90
91 READJOY:
92         pha
93         jsr     read_joy
94         pla
95         tax                     ; Joystick number into X
96
97         ; return value from buffer
98
99 joy1:
100         lda     padbuffer,x
101         ldx     #0
102         rts
103
104 read_joy:
105         ; reset multitap counter
106         lda     #$01
107         sta     JOY_CTRL
108         pha
109         pla
110         nop
111         nop
112
113         lda     #$03
114         sta     JOY_CTRL
115         pha
116         pla
117         nop
118         nop
119
120         cly
121 nextpad:
122         lda     #$01
123         sta     JOY_CTRL           ; sel = 1
124         pha
125         pla
126         nop                     ; some delay is required
127         nop
128
129         lda     JOY_CTRL
130         asl     a
131         asl     a
132         asl     a
133         asl     a
134         sta     padbuffer, y     ; store new value
135
136         stz     JOY_CTRL
137         pha
138         pla
139
140         nop                     ; some delay is required
141         nop
142
143         lda     JOY_CTRL
144         and     #$0F
145         ora     padbuffer, y     ; second half of new value
146
147         eor     #$FF
148         sta     padbuffer, y     ; store new value
149
150         iny
151         cpy     #$05
152         bcc     nextpad
153         rts
154
155 .bss
156
157 padbuffer:
158         .res    4
159