]> git.sur5r.net Git - cc65/blob - libsrc/pet/joy/pet-stdjoy.s
29c6de627c48db49ff0d157c0fa2e2173f8916a0
[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 ; Jump table.
31
32         .addr   INSTALL
33         .addr   UNINSTALL
34         .addr   COUNT
35         .addr   READ
36         .addr   0               ; IRQ entry unused
37
38 ; ------------------------------------------------------------------------
39 ; Constants
40
41 JOY_COUNT       = 2             ; Number of joysticks we support
42
43
44 .code
45
46 ; ------------------------------------------------------------------------
47 ; INSTALL routine. Is called after the driver is loaded into memory. If
48 ; possible, check if the hardware is present and determine the amount of
49 ; memory available.
50 ; Must return an JOY_ERR_xx code in a/x.
51 ;
52
53 INSTALL:
54         lda     #<JOY_ERR_OK
55         ldx     #>JOY_ERR_OK
56 ;       rts                     ; Run into UNINSTALL instead
57
58 ; ------------------------------------------------------------------------
59 ; UNINSTALL routine. Is called before the driver is removed from memory.
60 ; Can do cleanup or whatever. Must not return anything.
61 ;
62
63 UNINSTALL:
64         rts
65
66
67 ; ------------------------------------------------------------------------
68 ; COUNT: Return the total number of available joysticks in a/x.
69 ;
70
71 COUNT:
72         lda     #<JOY_COUNT
73         ldx     #>JOY_COUNT
74         rts
75
76 ; ------------------------------------------------------------------------
77 ; READ: Read a particular joystick passed in A.
78 ;
79
80 READ:
81         tax                     ; Joystick number into X
82         bne     joy2
83
84 ; Read joystick 1
85
86 joy1:
87         lda     #0
88         sta     VIA_DDRA
89         lda     VIA_PRA
90         and     #$0f
91         cmp     #$0c
92         bne     @notc1
93         lda     #$0f
94         bne     @end1
95 @notc1:
96         ora     #$10
97 @end1:
98         eor     #$1f
99         rts
100
101 ; Read joystick 2
102
103 joy2:
104         lda     #0
105         sta     VIA_DDRA
106         lda     VIA_PRA
107         lsr
108         lsr
109         lsr
110         lsr
111         cmp     #$0c
112         bne     @notc2
113         lda     #$0f
114         bne     @end2
115 @notc2:
116         ora     #$10
117 @end2:
118         eor     #$1f
119         ldx     #0
120         rts