]> git.sur5r.net Git - cc65/blob - libsrc/c128/joy/c128-stdjoy.s
shorter code
[cc65] / libsrc / c128 / joy / c128-stdjoy.s
1 ;
2 ; Standard joystick driver for the C128. May be used multiple times when linked
3 ; to the statically application.
4
5 ;
6 ; Ullrich von Bassewitz, 2002-12-21
7 ;
8
9         .include        "zeropage.inc"
10
11         .include        "joy-kernel.inc"
12         .include        "joy-error.inc"
13         .include        "c128.inc"
14
15         .macpack        generic
16         .macpack        module
17
18
19 ; ------------------------------------------------------------------------
20 ; Header. Includes jump table
21
22         module_header   _c128_stdjoy_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 ; Button state masks (8 values)
34
35         .byte   $01                     ; JOY_UP
36         .byte   $02                     ; JOY_DOWN
37         .byte   $04                     ; JOY_LEFT
38         .byte   $08                     ; JOY_RIGHT
39         .byte   $10                     ; JOY_FIRE
40         .byte   $00                     ; JOY_FIRE2 unavailable
41         .byte   $00                     ; Future expansion
42         .byte   $00                     ; Future expansion
43
44 ; Jump table.
45
46         .addr   INSTALL
47         .addr   UNINSTALL
48         .addr   COUNT
49         .addr   READ
50         .addr   0                       ; IRQ entry not used
51
52 ; ------------------------------------------------------------------------
53 ; Constants
54
55 JOY_COUNT       = 2             ; Number of joysticks we support
56
57
58 ; ------------------------------------------------------------------------
59 ; Data.
60
61
62 .code
63
64 ; ------------------------------------------------------------------------
65 ; INSTALL routine. Is called after the driver is loaded into memory. If
66 ; possible, check if the hardware is present and determine the amount of
67 ; memory available.
68 ; Must return an JOY_ERR_xx code in a/x.
69 ;
70
71 INSTALL:
72         lda     #<JOY_ERR_OK
73         ldx     #>JOY_ERR_OK
74 ;       rts                     ; Run into UNINSTALL instead
75
76 ; ------------------------------------------------------------------------
77 ; UNINSTALL routine. Is called before the driver is removed from memory.
78 ; Can do cleanup or whatever. Must not return anything.
79 ;
80
81 UNINSTALL:
82         rts
83
84
85 ; ------------------------------------------------------------------------
86 ; COUNT: Return the total number of available joysticks in a/x.
87 ;
88
89 COUNT:
90         lda     #<JOY_COUNT
91         ldx     #>JOY_COUNT
92         rts
93
94 ; ------------------------------------------------------------------------
95 ; READ: Read a particular joystick passed in A.
96 ;
97
98 READ:   tax                     ; Joystick number into X
99         bne     joy2
100
101 ; Read joystick 1
102
103 joy1:   lda     #$7F
104         sei
105         sta     CIA1_PRA
106         lda     CIA1_PRB
107 back:   cli
108         and     #$1F
109         eor     #$1F
110         rts
111
112 ; Read joystick 2
113
114 joy2:   ldx     #0
115         lda     #$E0
116         ldy     #$FF
117         sei
118         sta     CIA1_DDRA
119         lda     CIA1_PRA
120         sty     CIA1_DDRA
121         jmp     back