]> git.sur5r.net Git - cc65/blob - libsrc/pet/joy/pet-stdjoy.s
5847c2b094f44773a4a991f34ceacbc95c66ef0f
[cc65] / libsrc / pet / joy / pet-stdjoy.s
1 ;
2 ; Standard PET userport joystick driver for the PET
3 ;
4 ; Marco van den Heuvel, 2010-01-23
5 ;
6
7         .include        "zeropage.inc"
8
9         .include        "joy-kernel.inc"
10         .include        "joy-error.inc"
11         .include        "pet.inc"
12
13         .macpack        module
14
15
16 ; ------------------------------------------------------------------------
17 ; Header. Includes jump table
18
19         module_header   _pet_stdjoy_joy
20
21 ; Driver signature
22
23         .byte   $6A, $6F, $79           ; "joy"
24         .byte   JOY_API_VERSION         ; Driver API version number
25
26 ; Library reference
27
28         .addr   $0000
29
30 ; Button state masks (8 values)
31
32         .byte   $01             ; JOY_UP
33         .byte   $02             ; JOY_DOWN
34         .byte   $04             ; JOY_LEFT
35         .byte   $08             ; JOY_RIGHT
36         .byte   $10             ; JOY_FIRE
37         .byte   $00             ; JOY_FIRE2 unavailable
38         .byte   $00             ; Future expansion
39         .byte   $00             ; Future expansion
40
41 ; Jump table.
42
43         .addr   INSTALL
44         .addr   UNINSTALL
45         .addr   COUNT
46         .addr   READ
47         .addr   0               ; IRQ entry unused
48
49 ; ------------------------------------------------------------------------
50 ; Constants
51
52 JOY_COUNT       = 2             ; Number of joysticks we support
53
54
55 .code
56
57 ; ------------------------------------------------------------------------
58 ; INSTALL routine. Is called after the driver is loaded into memory. If
59 ; possible, check if the hardware is present and determine the amount of
60 ; memory available.
61 ; Must return an JOY_ERR_xx code in a/x.
62 ;
63
64 INSTALL:
65         lda     #<JOY_ERR_OK
66         ldx     #>JOY_ERR_OK
67 ;       rts                     ; Run into UNINSTALL instead
68
69 ; ------------------------------------------------------------------------
70 ; UNINSTALL routine. Is called before the driver is removed from memory.
71 ; Can do cleanup or whatever. Must not return anything.
72 ;
73
74 UNINSTALL:
75         rts
76
77
78 ; ------------------------------------------------------------------------
79 ; COUNT: Return the total number of available joysticks in a/x.
80 ;
81
82 COUNT:
83         lda     #<JOY_COUNT
84         ldx     #>JOY_COUNT
85         rts
86
87 ; ------------------------------------------------------------------------
88 ; READ: Read a particular joystick passed in A.
89 ;
90
91 READ:
92         tax                     ; Joystick number into X
93         bne     joy2
94
95 ; Read joystick 1
96
97 joy1:
98         lda     #0
99         sta     VIA_DDRA
100         lda     VIA_PRA
101         and     #$0f
102         cmp     #$0c
103         bne     @notc1
104         lda     #$0f
105         bne     @end1
106 @notc1:
107         ora     #$10
108 @end1:
109         eor     #$1f
110         rts
111
112 ; Read joystick 2
113
114 joy2:
115         lda     #0
116         sta     VIA_DDRA
117         lda     VIA_PRA
118         lsr
119         lsr
120         lsr
121         lsr
122         cmp     #$0c
123         bne     @notc2
124         lda     #$0f
125         bne     @end2
126 @notc2:
127         ora     #$10
128 @end2:
129         eor     #$1f
130         ldx     #0
131         rts