]> git.sur5r.net Git - cc65/blob - libsrc/c128/joy/c128-stdjoy.s
Fixed _textcolor definition.
[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 ; Jump table.
34
35         .addr   INSTALL
36         .addr   UNINSTALL
37         .addr   COUNT
38         .addr   READ
39
40 ; ------------------------------------------------------------------------
41 ; Constants
42
43 JOY_COUNT       = 2             ; Number of joysticks we support
44
45
46 ; ------------------------------------------------------------------------
47 ; Data.
48
49
50 .code
51
52 ; ------------------------------------------------------------------------
53 ; INSTALL routine. Is called after the driver is loaded into memory. If
54 ; possible, check if the hardware is present and determine the amount of
55 ; memory available.
56 ; Must return an JOY_ERR_xx code in a/x.
57 ;
58
59 INSTALL:
60         lda     #<JOY_ERR_OK
61         ldx     #>JOY_ERR_OK
62 ;       rts                     ; Run into UNINSTALL instead
63
64 ; ------------------------------------------------------------------------
65 ; UNINSTALL routine. Is called before the driver is removed from memory.
66 ; Can do cleanup or whatever. Must not return anything.
67 ;
68
69 UNINSTALL:
70         rts
71
72
73 ; ------------------------------------------------------------------------
74 ; COUNT: Return the total number of available joysticks in a/x.
75 ;
76
77 COUNT:
78         lda     #<JOY_COUNT
79         ldx     #>JOY_COUNT
80         rts
81
82 ; ------------------------------------------------------------------------
83 ; READ: Read a particular joystick passed in A.
84 ;
85
86 READ:   tax                     ; Joystick number into X
87         bne     joy2
88
89 ; Read joystick 1
90
91 joy1:   lda     #$7F
92         sei
93         sta     CIA1_PRA
94         lda     CIA1_PRB
95 back:   cli
96         and     #$1F
97         eor     #$1F
98         rts
99
100 ; Read joystick 2
101
102 joy2:   ldx     #0
103         lda     #$E0
104         ldy     #$FF
105         sei
106         sta     CIA1_DDRA
107         lda     CIA1_PRA
108         sty     CIA1_DDRA
109         jmp     back