]> git.sur5r.net Git - cc65/blob - libsrc/geos-cbm/joy/geos-stdjoy.s
Renamed JUMPTABLE and cleaned up module.cfg.
[cc65] / libsrc / geos-cbm / joy / 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        "HEADER"
19                                              
20 ; Driver signature
21
22         .byte $6A, $6F, $79     ; "joy"
23         .byte JOY_API_VERSION   ; Driver API version number
24
25 ; Library reference
26
27         .addr   $0000
28
29 ; Button state masks (8 values)
30
31         .byte $01               ; JOY_UP
32         .byte $02               ; JOY_DOWN
33         .byte $04               ; JOY_LEFT
34         .byte $08               ; JOY_RIGHT
35         .byte $10               ; JOY_FIRE
36         .byte $00               ; Future expansion
37         .byte $00               ; Future expansion
38         .byte $00               ; Future expansion
39
40 ; Jump table.
41
42         .word INSTALL
43         .word UNINSTALL
44         .word COUNT
45         .word READ
46
47 ; ------------------------------------------------------------------------
48 ; Constants
49
50 JOY_COUNT       = 2             ; Number of joysticks we support
51
52 ; ------------------------------------------------------------------------
53 ; Data.
54
55 .code
56
57 ; ------------------------------------------------------------------------
58 ; INSTALL routine. Is called after the driver is loaded into memory. If
59 ; possible, check if the hardware is present and determine the amount of
60 ; memory available.
61 ; Must return an JOY_ERR_xx code in a/x.
62 ;
63
64 INSTALL:
65         lda #<JOY_ERR_OK
66         ldx #>JOY_ERR_OK
67 ;       rts                     ; Run into UNINSTALL instead
68
69 ; ------------------------------------------------------------------------
70 ; UNINSTALL routine. Is called before the driver is removed from memory.
71 ; Can do cleanup or whatever. Must not return anything.
72 ;
73
74 UNINSTALL:
75         rts
76
77 ; ------------------------------------------------------------------------
78 ; COUNT: Return the total number of available joysticks in a/x.
79 ;
80
81 COUNT:
82         lda #<JOY_COUNT
83         ldx #>JOY_COUNT
84         rts
85
86 ; ------------------------------------------------------------------------
87 ; READ: Read a particular joystick passed in A.
88 ;
89
90 READ:
91         tax
92         php
93         sei                     ; disable IRQ
94         lda $01
95         pha
96         lda #$35
97         sta $01                 ; enable I/O
98
99         txa                     ; Joystick number into X
100         bne joy2
101
102 ; Read joystick 1
103
104 joy1:
105         lda #$7F
106         sta cia1base
107         lda cia1base+1
108 back:   tay
109         pla
110         sta $01
111         plp
112         tya
113         and #$1F
114         eor #$1F
115         rts
116
117 ; Read joystick 2
118
119 joy2:   ldx #0
120         lda #$E0
121         ldy #$FF
122         sta cia1base+2
123         lda cia1base+1
124         sty cia1base+2
125         jmp back