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