]> git.sur5r.net Git - cc65/blob - libsrc/geos-cbm/devel/geos-stdjoy.s
'setoserror' is used by routines residing both 'disk' and 'file'. Therefore move...
[cc65] / libsrc / geos-cbm / devel / 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
10         .include        "joy-kernel.inc"
11         .include        "joy-error.inc"
12         .include        "geossym.inc"
13
14         .macpack        generic
15
16
17 ; ------------------------------------------------------------------------
18 ; Header. Includes jump table
19
20 .segment        "JUMPTABLE"
21                                              
22 ; Driver signature
23
24         .byte   $6A, $6F, $79           ; "joy"
25         .byte   JOY_API_VERSION         ; Driver API version number
26
27 ; Button state masks (8 values)
28
29         .byte   $01                     ; JOY_UP
30         .byte   $02                     ; JOY_DOWN
31         .byte   $04                     ; JOY_LEFT
32         .byte   $08                     ; JOY_RIGHT
33         .byte   $10                     ; JOY_FIRE
34         .byte   $00                     ; Future expansion
35         .byte   $00                     ; Future expansion
36         .byte   $00                     ; Future expansion
37
38 ; Jump table.
39
40         .word   INSTALL
41         .word   UNINSTALL
42         .word   COUNT
43         .word   READ
44
45 ; ------------------------------------------------------------------------
46 ; Constants
47
48 JOY_COUNT       = 2             ; Number of joysticks we support
49
50
51 ; ------------------------------------------------------------------------
52 ; Data.
53
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 ; ------------------------------------------------------------------------
79 ; COUNT: Return the total number of available joysticks in a/x.
80 ;
81
82 COUNT:
83         lda     #<JOY_COUNT
84         ldx     #>JOY_COUNT
85         rts
86
87 ; ------------------------------------------------------------------------
88 ; READ: Read a particular joystick passed in A.
89 ;
90
91 READ:
92         tax
93         php
94         sei                     ; disable IRQ
95         lda     $01
96         pha
97         lda     #$35
98         sta     $01             ; enable I/O
99
100         txa                     ; Joystick number into X
101         bne     joy2
102
103 ; Read joystick 1
104
105 joy1:
106         lda     #$7F
107         sta     cia1base
108         lda     cia1base+1
109 back:   tay
110         pla
111         sta     $01
112         plp
113         tya
114         and     #$1F
115         eor     #$1F
116         rts
117
118 ; Read joystick 2
119
120 joy2:   ldx     #0
121         lda     #$E0
122         ldy     #$FF
123         sta     cia1base+2
124         lda     cia1base+1
125         sty     cia1base+2
126         jmp     back