]> git.sur5r.net Git - cc65/blob - libsrc/geos-cbm/drivers/geos-stdjoy.s
Prepared infrastructure for a shared loadable generic mouse driver based the GEOS...
[cc65] / libsrc / geos-cbm / drivers / geos-stdjoy.s
1 ;
2 ; Standard joystick driver for the C64. May be used multiple times when linked
3 ; to the statically application.
4 ;
5 ; Ullrich von Bassewitz, 2002-12-20
6 ;
7
8             .include "zeropage.inc"
9             .include "joy-kernel.inc"
10             .include "joy-error.inc"
11             .include "geossym.inc"
12
13             .macpack generic
14
15 ; ------------------------------------------------------------------------
16 ; Header. Includes jump table
17
18 .segment        "JUMPTABLE"
19                                              
20 ; Driver signature
21
22         .byte $6A, $6F, $79     ; "joy"
23         .byte JOY_API_VERSION   ; Driver API version number
24
25 ; Button state masks (8 values)
26
27         .byte $01               ; JOY_UP
28         .byte $02               ; JOY_DOWN
29         .byte $04               ; JOY_LEFT
30         .byte $08               ; JOY_RIGHT
31         .byte $10               ; JOY_FIRE
32         .byte $00               ; Future expansion
33         .byte $00               ; Future expansion
34         .byte $00               ; Future expansion
35
36 ; Jump table.
37
38         .word INSTALL
39         .word UNINSTALL
40         .word COUNT
41         .word READ
42
43 ; ------------------------------------------------------------------------
44 ; Constants
45
46 JOY_COUNT       = 2             ; Number of joysticks we support
47
48 ; ------------------------------------------------------------------------
49 ; Data.
50
51 .code
52
53 ; ------------------------------------------------------------------------
54 ; INSTALL routine. Is called after the driver is loaded into memory. If
55 ; possible, check if the hardware is present and determine the amount of
56 ; memory available.
57 ; Must return an JOY_ERR_xx code in a/x.
58 ;
59
60 INSTALL:
61         lda #<JOY_ERR_OK
62         ldx #>JOY_ERR_OK
63 ;       rts                     ; Run into UNINSTALL instead
64
65 ; ------------------------------------------------------------------------
66 ; UNINSTALL routine. Is called before the driver is removed from memory.
67 ; Can do cleanup or whatever. Must not return anything.
68 ;
69
70 UNINSTALL:
71         rts
72
73
74 ; ------------------------------------------------------------------------
75 ; COUNT: Return the total number of available joysticks in a/x.
76 ;
77
78 COUNT:
79         lda #<JOY_COUNT
80         ldx #>JOY_COUNT
81         rts
82
83 ; ------------------------------------------------------------------------
84 ; READ: Read a particular joystick passed in A.
85 ;
86
87 READ:
88         tax
89         php
90         sei                     ; disable IRQ
91         lda $01
92         pha
93         lda #$35
94         sta $01                 ; enable I/O
95
96         txa                     ; Joystick number into X
97         bne joy2
98
99 ; Read joystick 1
100
101 joy1:
102         lda #$7F
103         sta cia1base
104         lda cia1base+1
105 back:   tay
106         pla
107         sta $01
108         plp
109         tya
110         and #$1F
111         eor #$1F
112         rts
113
114 ; Read joystick 2
115
116 joy2:   ldx #0
117         lda #$E0
118         ldy #$FF
119         sta cia1base+2
120         lda cia1base+1
121         sty cia1base+2
122         jmp back