]> git.sur5r.net Git - cc65/blob - libsrc/geos-cbm/drivers/geos-stdjoy.s
Ignore only top level directories.
[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 ; COUNT: Return the total number of available joysticks in a/x.
75 ;
76
77 COUNT:
78         lda #<JOY_COUNT
79         ldx #>JOY_COUNT
80         rts
81
82 ; ------------------------------------------------------------------------
83 ; READ: Read a particular joystick passed in A.
84 ;
85
86 READ:
87         tax
88         php
89         sei                     ; disable IRQ
90         lda $01
91         pha
92         lda #$35
93         sta $01                 ; enable I/O
94
95         txa                     ; Joystick number into X
96         bne joy2
97
98 ; Read joystick 1
99
100 joy1:
101         lda #$7F
102         sta cia1base
103         lda cia1base+1
104 back:   tay
105         pla
106         sta $01
107         plp
108         tya
109         and #$1F
110         eor #$1F
111         rts
112
113 ; Read joystick 2
114
115 joy2:   ldx #0
116         lda #$E0
117         ldy #$FF
118         sta cia1base+2
119         lda cia1base+1
120         sty cia1base+2
121         jmp back