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"
19 ; ------------------------------------------------------------------------
20 ; Header. Includes jump table
22 module_header _vic20_ptvjoy_joy
26 .byte $6A, $6F, $79 ; "joy"
27 .byte JOY_API_VERSION ; Driver API version number
33 ; Button state masks (8 values)
40 .byte $00 ; JOY_FIRE2 unavailable
41 .byte $00 ; Future expansion
42 .byte $00 ; Future expansion
50 .addr 0 ; IRQ entry unused
52 ; ------------------------------------------------------------------------
55 VIA1_PRB := VIA1 ; User port register
56 JOY_COUNT = 3 ; Number of joysticks we support
61 ; ------------------------------------------------------------------------
62 ; INSTALL routine. Is called after the driver is loaded into memory. If
63 ; possible, check if the hardware is present and determine the amount of
65 ; Must return an JOY_ERR_xx code in a/x.
71 ; rts ; Run into UNINSTALL instead
73 ; ------------------------------------------------------------------------
74 ; UNINSTALL routine. Is called before the driver is removed from memory.
75 ; Can do cleanup or whatever. Must not return anything.
82 ; ------------------------------------------------------------------------
83 ; COUNT: Return the total number of available joysticks in a/x.
91 ; ------------------------------------------------------------------------
92 ; READ: Read a particular joystick passed in A.
95 READ: tax ; Joystick number into X
100 joy1: lda #$7F ; mask for VIA2 JOYBIT: sw3
101 ldx #$C3 ; mask for VIA1 JOYBITS: sw0,sw1,sw2,sw4
104 ldy VIA2_DDRB ; remember the date of DDRB
105 sta VIA2_DDRB ; set JOYBITS on this VIA for input
106 lda VIA2_JOY ; read JOYBIT: sw3
107 sty VIA2_DDRB ; restore the state of DDRB
108 asl ; Shift sw3 into carry
110 ldy VIA1_DDRA ; remember the state of DDRA
111 stx VIA1_DDRA ; set JOYBITS on this VIA for input
112 lda VIA1_JOY ; read JOYBITS: sw0,sw1,sw2,sw4
113 sty VIA1_DDRA ; restore the state of DDRA
116 ror ; Shift sw3 into bit 7
117 and #$9E ; Mask relevant bits
118 eor #$9E ; Active states are inverted
124 joy2: lda #%10000000 ; via port B Data-Direction
125 sta VIA1_DDRB ; bit 7: out bit 6-0: in
130 lda #$80 ; via port B read/write
131 sta VIA1_PRB ; (output one at PB7)
133 lda VIA1_PRB ; via port B read/write
134 and #$1f ; get bit 4-0 (PB4-PB0)
140 joy3: lda #$00 ; via port B read/write
141 sta VIA1_PRB ; (output zero at PB7)
143 lda VIA1_PRB ; via port B read/write
144 and #$0f ; get bit 3-0 (PB3-PB0)
145 sta tmp1 ; joy 4 directions
147 lda VIA1_PRB ; via port B read/write
148 and #%00100000 ; get bit 5 (PB5)