]> git.sur5r.net Git - cc65/blob - libsrc/c64/joy/c64-numpad.s
Adjusted to recent driver interface change.
[cc65] / libsrc / c64 / joy / c64-numpad.s
1 ;
2 ; Joystick driver using C128 number pad in 64 mode.
3 ; May be used multiple times when linked to the statically application.
4 ;
5 ; Stefan Haubenthal, 2004-01-26
6 ; Based on Ullrich von Bassewitz, 2002-12-20
7 ;
8
9         .include        "zeropage.inc"
10
11         .include        "joy-kernel.inc"
12         .include        "joy-error.inc"
13         .include        "c64.inc"
14
15         .macpack        generic
16         .macpack        module
17
18
19 ; ------------------------------------------------------------------------
20 ; Header. Includes jump table
21
22         module_header   _c64_numpad_joy
23
24 ; Driver signature
25
26         .byte   $6A, $6F, $79           ; "joy"
27         .byte   JOY_API_VERSION         ; Driver API version number
28
29 ; Library reference
30
31         .addr   $0000
32
33 ; Jump table.
34
35         .addr   INSTALL
36         .addr   UNINSTALL
37         .addr   COUNT
38         .addr   READ
39         .addr   0                       ; IRQ entry unused
40
41 ; ------------------------------------------------------------------------
42 ; Constants
43
44 JOY_COUNT       = 1             ; Number of joysticks we support
45
46
47 ; ------------------------------------------------------------------------
48 ; Data.
49
50 .rodata
51
52 ; <U>p      '8' key
53 ; <D>own    '2' key
54 ; <L>eft    '4' key
55 ; <R>ight   '6' key
56 ; <B>utton  '5' or ENTER key
57
58 masktable:
59         ; Input:  LDRBU
60         ; Output: BRLDU
61         .byte %00000000         ; $00
62         .byte %00000001         ; $01
63         .byte %00010000         ; $02
64         .byte %00010001         ; $03
65         .byte %00001000         ; $04
66         .byte %00001001         ; $05
67         .byte %00011000         ; $06
68         .byte %00011001         ; $07
69         .byte %00000010         ; $08
70         .byte %00000011         ; $09
71         .byte %00010010         ; $0A
72         .byte %00010011         ; $0B
73         .byte %00001010         ; $0C
74         .byte %00001011         ; $0D
75         .byte %00011010         ; $0E
76         .byte %00011011         ; $0F
77         .byte %00000100         ; $10
78         .byte %00000101         ; $11
79         .byte %00010100         ; $12
80         .byte %00010101         ; $13
81         .byte %00001100         ; $14
82         .byte %00001101         ; $15
83         .byte %00011100         ; $16
84         .byte %00011101         ; $17
85         .byte %00000110         ; $18
86         .byte %00000111         ; $19
87         .byte %00010110         ; $1A
88         .byte %00010111         ; $1B
89         .byte %00001110         ; $1C
90         .byte %00001111         ; $1D
91         .byte %00011110         ; $1E
92         .byte %00011111         ; $1F
93
94 .code
95
96 ; ------------------------------------------------------------------------
97 ; INSTALL routine. Is called after the driver is loaded into memory. If
98 ; possible, check if the hardware is present and determine the amount of
99 ; memory available.
100 ; Must return an JOY_ERR_xx code in a/x.
101 ;
102
103 INSTALL:
104         lda     #JOY_ERR_OK             ; Assume we have a joystick
105         ldx     VIC_CLK_128             ; Test for a C128
106         cpx     #$FF
107         bne     @C128                   ; Jump if we have one
108         lda     #JOY_ERR_NO_DEVICE      ; No C128 -> no numpad
109 @C128:  ldx     #0                      ; Set high byte
110
111 ;       rts                     ; Run into UNINSTALL instead
112
113 ; ------------------------------------------------------------------------
114 ; UNINSTALL routine. Is called before the driver is removed from memory.
115 ; Can do cleanup or whatever. Must not return anything.
116 ;
117
118 UNINSTALL:
119         rts
120
121
122 ; ------------------------------------------------------------------------
123 ; COUNT: Return the total number of available joysticks in a/x.
124 ;
125
126 COUNT:  lda     #JOY_COUNT
127         ldx     #0
128         rts
129
130 ; ------------------------------------------------------------------------
131 ; READ: Read a particular joystick passed in A.
132 ;
133
134 READ:   tax                     ; Clear high byte
135         lda     #$FD            ; For ENTER and '6'
136         ldy     #$FE            ; For '8', '5', '2', '4'
137         sei
138         sta     VIC_KBD_128
139         lda     CIA1_PRB
140         and     #%00110000
141         eor     #%00110000
142         lsr                     ; Map ENTER ...
143         lsr                     ; ... onto '5'
144         sty     VIC_KBD_128
145         eor     CIA1_PRB
146         iny
147         sty     VIC_KBD_128     ; Reset to $FF
148         cli
149         and     #%00111110
150         eor     #%00111110
151         lsr
152         tay
153         lda     masktable,y     ; Convert LDRBU to BRLDU
154         rts