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