2 ; PTV-3 Player joystick driver for the VIC20
4 ; Stefan Haubenthal, 2005-05-25
5 ; Groepaz/Hitmen, 2002-12-23
6 ; obviously based on Ullrichs driver :)
7 ; Using code from Steve Schmidtke
10 .include "zeropage.inc"
12 .include "joy-kernel.inc"
13 .include "joy-error.inc"
16 ; ------------------------------------------------------------------------
17 ; Header. Includes jump table
23 .byte $6A, $6F, $79 ; "joy"
24 .byte JOY_API_VERSION ; Driver API version number
26 ; Button state masks (8 values)
33 .byte $00 ; JOY_FIRE2 unavailable
34 .byte $00 ; Future expansion
35 .byte $00 ; Future expansion
43 .addr 0 ; IRQ entry unused
45 ; ------------------------------------------------------------------------
48 VIA1_PRB := VIA1 ; User port register
49 JOY_COUNT = 3 ; Number of joysticks we support
54 ; ------------------------------------------------------------------------
55 ; INSTALL routine. Is called after the driver is loaded into memory. If
56 ; possible, check if the hardware is present and determine the amount of
58 ; Must return an JOY_ERR_xx code in a/x.
64 ; rts ; Run into UNINSTALL instead
66 ; ------------------------------------------------------------------------
67 ; UNINSTALL routine. Is called before the driver is removed from memory.
68 ; Can do cleanup or whatever. Must not return anything.
75 ; ------------------------------------------------------------------------
76 ; COUNT: Return the total number of available joysticks in a/x.
84 ; ------------------------------------------------------------------------
85 ; READ: Read a particular joystick passed in A.
88 READ: tax ; Joystick number into X
93 joy1: lda #$7F ; mask for VIA2 JOYBIT: sw3
94 ldx #$C3 ; mask for VIA1 JOYBITS: sw0,sw1,sw2,sw4
97 ldy VIA2_DDRB ; remember the date of DDRB
98 sta VIA2_DDRB ; set JOYBITS on this VIA for input
99 lda VIA2_JOY ; read JOYBIT: sw3
100 sty VIA2_DDRB ; restore the state of DDRB
101 asl ; Shift sw3 into carry
103 ldy VIA1_DDRA ; remember the state of DDRA
104 stx VIA1_DDRA ; set JOYBITS on this VIA for input
105 lda VIA1_JOY ; read JOYBITS: sw0,sw1,sw2,sw4
106 sty VIA1_DDRA ; restore the state of DDRA
109 ror ; Shift sw3 into bit 7
110 and #$9E ; Mask relevant bits
111 eor #$9E ; Active states are inverted
117 joy2: lda #%10000000 ; via port B Data-Direction
118 sta VIA1_DDRB ; bit 7: out bit 6-0: in
123 lda #$80 ; via port B read/write
124 sta VIA1_PRB ; (output one at PB7)
126 lda VIA1_PRB ; via port B read/write
127 and #$1f ; get bit 4-0 (PB4-PB0)
133 joy3: lda #$00 ; via port B read/write
134 sta VIA1_PRB ; (output zero at PB7)
136 lda VIA1_PRB ; via port B read/write
137 and #$0f ; get bit 3-0 (PB3-PB0)
138 sta tmp1 ; joy 4 directions
140 lda VIA1_PRB ; via port B read/write
141 and #%00100000 ; get bit 5 (PB5)