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