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
39 .addr 0 ; IRQ entry unused
41 ; ------------------------------------------------------------------------
44 VIA1_PRB := VIA1 ; User port register
45 JOY_COUNT = 3 ; Number of joysticks we support
50 ; ------------------------------------------------------------------------
51 ; INSTALL routine. Is called after the driver is loaded into memory. If
52 ; possible, check if the hardware is present and determine the amount of
54 ; Must return an JOY_ERR_xx code in a/x.
60 ; rts ; Run into UNINSTALL instead
62 ; ------------------------------------------------------------------------
63 ; UNINSTALL routine. Is called before the driver is removed from memory.
64 ; Can do cleanup or whatever. Must not return anything.
71 ; ------------------------------------------------------------------------
72 ; COUNT: Return the total number of available joysticks in a/x.
80 ; ------------------------------------------------------------------------
81 ; READ: Read a particular joystick passed in A.
84 READ: tax ; Joystick number into X
89 joy1: lda #$7F ; mask for VIA2 JOYBIT: sw3
90 ldx #$C3 ; mask for VIA1 JOYBITS: sw0,sw1,sw2,sw4
93 ldy VIA2_DDRB ; remember the date of DDRB
94 sta VIA2_DDRB ; set JOYBITS on this VIA for input
95 lda VIA2_JOY ; read JOYBIT: sw3
96 sty VIA2_DDRB ; restore the state of DDRB
97 asl ; Shift sw3 into carry
99 ldy VIA1_DDRA ; remember the state of DDRA
100 stx VIA1_DDRA ; set JOYBITS on this VIA for input
101 lda VIA1_JOY ; read JOYBITS: sw0,sw1,sw2,sw4
102 sty VIA1_DDRA ; restore the state of DDRA
105 ror ; Shift sw3 into bit 7
106 and #$9E ; Mask relevant bits
107 eor #$9E ; Active states are inverted
113 joy2: lda #%10000000 ; via port B Data-Direction
114 sta VIA1_DDRB ; bit 7: out bit 6-0: in
119 lda #$80 ; via port B read/write
120 sta VIA1_PRB ; (output one at PB7)
122 lda VIA1_PRB ; via port B read/write
123 and #$1f ; get bit 4-0 (PB4-PB0)
129 joy3: lda #$00 ; via port B read/write
130 sta VIA1_PRB ; (output zero at PB7)
132 lda VIA1_PRB ; via port B read/write
133 and #$0f ; get bit 3-0 (PB3-PB0)
134 sta tmp1 ; joy 4 directions
136 lda VIA1_PRB ; via port B read/write
137 and #%00100000 ; get bit 5 (PB5)