]> git.sur5r.net Git - cc65/blob - libsrc/c128/c128-stdjoy.s
Joystick code conversion for C128
[cc65] / libsrc / c128 / c128-stdjoy.s
1 ;
2 ; Standard joystick driver for the C128
3 ;
4 ; Ullrich von Bassewitz, 2002-12-21
5 ;
6
7         .include        "zeropage.inc"
8
9         .include        "joy-kernel.inc"
10         .include        "joy-error.inc"
11         .include        "c128.inc"  
12
13         .macpack        generic
14
15
16 ; ------------------------------------------------------------------------
17 ; Header. Includes jump table
18
19 .segment        "JUMPTABLE"
20
21 ; Driver signature
22
23         .byte   $6A, $6F, $79           ; "joy"
24         .byte   $00                     ; Driver API version number
25
26 ; Button state masks (8 values)
27
28         .byte   $01                     ; JOY_UP
29         .byte   $02                     ; JOY_DOWN
30         .byte   $04                     ; JOY_LEFT
31         .byte   $08                     ; JOY_RIGHT
32         .byte   $10                     ; JOY_FIRE
33         .byte   $00                     ; Future expansion
34         .byte   $00                     ; Future expansion
35         .byte   $00                     ; Future expansion
36
37 ; Jump table.
38
39         .word   INSTALL
40         .word   DEINSTALL
41         .word   COUNT
42         .word   READ
43
44 ; ------------------------------------------------------------------------
45 ; Constants
46
47 JOY_COUNT       = 2             ; Number of joysticks we support
48
49
50 ; ------------------------------------------------------------------------
51 ; Data.
52
53
54 .code
55
56 ; ------------------------------------------------------------------------
57 ; INSTALL routine. Is called after the driver is loaded into memory. If
58 ; possible, check if the hardware is present and determine the amount of
59 ; memory available.
60 ; Must return an JOY_ERR_xx code in a/x.
61 ;
62
63 INSTALL:
64         lda     #<JOY_ERR_OK
65         ldx     #>JOY_ERR_OK
66
67 ;       rts                     ; Run into DEINSTALL instead
68
69 ; ------------------------------------------------------------------------
70 ; DEINSTALL routine. Is called before the driver is removed from memory.
71 ; Can do cleanup or whatever. Must not return anything.
72 ;
73
74 DEINSTALL:
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:   tax                     ; Joystick number into X
92         bne     joy2
93
94 ; Read joystick 1
95
96 joy1:   lda     #$7F
97         sei
98         sta     CIA1_PRA
99         lda     CIA1_PRB
100         cli
101         and     #$1F
102         eor     #$1F
103         rts
104
105 ; Read joystick 2
106
107 joy2:   ldx     #0
108         lda     #$E0
109         ldy     #$FF
110         sei
111         sta     CIA1_DDRA
112         lda     CIA1_PRA
113         sty     CIA1_DDRA
114         cli
115         and     #$1F
116         eor     #$1F
117         rts
118
119