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