]> git.sur5r.net Git - cc65/blob - libsrc/vic20/joy/vic20-stdjoy.s
db1a0beccae9ccb0061457048a1289dfa907170b
[cc65] / libsrc / vic20 / joy / vic20-stdjoy.s
1 ;
2 ; Standard joystick driver for the VIC20. May be used multiple times when linked
3 ; to the statically application.
4 ;
5 ; Ullrich von Bassewitz, 2002-12-20
6 ; Using code from Steve Schmidtke
7 ;
8
9         .include        "zeropage.inc"
10
11         .include        "joy-kernel.inc"
12         .include        "joy-error.inc"
13         .include        "vic20.inc"
14
15         .macpack        generic
16
17
18 ; ------------------------------------------------------------------------
19 ; Header. Includes jump table
20
21 .segment        "HEADER"
22
23 ; Driver signature
24
25         .byte   $6A, $6F, $79           ; "joy"
26         .byte   JOY_API_VERSION         ; Driver API version number
27
28 ; Library reference
29
30         .addr   $0000
31
32 ; Button state masks (8 values)
33
34         .byte   $02                     ; JOY_UP
35         .byte   $04                     ; JOY_DOWN
36         .byte   $08                     ; JOY_LEFT
37         .byte   $80                     ; JOY_RIGHT
38         .byte   $10                     ; JOY_FIRE
39         .byte   $00                     ; JOY_FIRE2 unavailable
40         .byte   $00                     ; Future expansion
41         .byte   $00                     ; Future expansion
42
43 ; Jump table.
44
45         .addr   INSTALL
46         .addr   UNINSTALL
47         .addr   COUNT
48         .addr   READ
49         .addr   0                       ; IRQ entry unused
50
51 ; ------------------------------------------------------------------------
52 ; Constants
53
54 JOY_COUNT       = 1             ; Number of joysticks we support
55
56
57 ; ------------------------------------------------------------------------
58 ; Data.
59
60
61 .code
62
63 ; ------------------------------------------------------------------------
64 ; INSTALL routine. Is called after the driver is loaded into memory. If
65 ; possible, check if the hardware is present and determine the amount of
66 ; memory available.
67 ; Must return an JOY_ERR_xx code in a/x.
68 ;
69
70 INSTALL:
71         lda     #<JOY_ERR_OK
72         ldx     #>JOY_ERR_OK
73 ;       rts                     ; Run into UNINSTALL instead
74
75 ; ------------------------------------------------------------------------
76 ; UNINSTALL routine. Is called before the driver is removed from memory.
77 ; Can do cleanup or whatever. Must not return anything.
78 ;
79
80 UNINSTALL:
81         rts
82
83
84 ; ------------------------------------------------------------------------
85 ; COUNT: Return the total number of available joysticks in a/x.
86 ;
87
88 COUNT:
89         lda     #<JOY_COUNT
90         ldx     #>JOY_COUNT
91         rts
92
93 ; ------------------------------------------------------------------------
94 ; READ: Read a particular joystick passed in A.
95 ; The current implemenation will ignore the joystick number because we do only
96 ; have one joystick
97
98 READ:   lda     #$7F            ; mask for VIA2 JOYBIT: sw3
99         ldx     #$C3            ; mask for VIA1 JOYBITS: sw0,sw1,sw2,sw4
100         sei                     ; necessary?
101
102         ldy     VIA2_DDRB       ; remember the date of DDRB
103         sta     VIA2_DDRB       ; set JOYBITS on this VIA for input
104         lda     VIA2_JOY        ; read JOYBIT: sw3
105         sty     VIA2_DDRB       ; restore the state of DDRB
106         asl                     ; Shift sw3 into carry
107
108         ldy     VIA1_DDRA       ; remember the state of DDRA
109         stx     VIA1_DDRA       ; set JOYBITS on this VIA for input
110         lda     VIA1_JOY        ; read JOYBITS: sw0,sw1,sw2,sw4
111         sty     VIA1_DDRA       ; restore the state of DDRA
112
113         cli                     ; necessary?
114         ror                     ; Shift sw3 into bit 7
115         and     #$9E            ; Mask relevant bits
116         eor     #$9E            ; Active states are inverted
117
118         rts
119
120