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