]> git.sur5r.net Git - cc65/blob - libsrc/pet/joy/pet-ptvjoy.s
19c2ca87620cd3957b5bd317a07d9a2a92085c01
[cc65] / libsrc / pet / joy / pet-ptvjoy.s
1 ;
2 ; PTV-2 Player joystick driver for the PET
3 ;
4 ; Stefan Haubenthal, 2005-05-25
5 ; Groepaz/Hitmen, 2002-12-23
6 ; obviously based on Ullrichs driver :)
7 ;
8
9         .include "zeropage.inc"
10
11         .include "joy-kernel.inc"
12         .include "joy-error.inc"
13 ;       .include "pet.inc"
14 VIA_PRA         := $E841                ; Port register A
15 VIA_DDRA        := $E843                ; Data direction register A
16
17 ; ------------------------------------------------------------------------
18 ; Header. Includes jump table
19
20         .segment "JUMPTABLE"
21
22 ; Driver signature
23
24         .byte   $6A, $6F, $79   ; "joy"
25         .byte   JOY_API_VERSION ; Driver API version number
26
27 ; Library reference
28
29         .addr   $0000
30
31 ; Button state masks (8 values)
32
33         .byte   $01                     ; JOY_UP
34         .byte   $02                     ; JOY_DOWN
35         .byte   $04                     ; JOY_LEFT
36         .byte   $08                     ; JOY_RIGHT
37         .byte   $10                     ; JOY_FIRE
38         .byte   $00                     ; JOY_FIRE2 unavailable
39         .byte   $00                     ; Future expansion
40         .byte   $00                     ; Future expansion
41
42 ; Jump table.
43
44         .addr   INSTALL
45         .addr   UNINSTALL
46         .addr   COUNT
47         .addr   READ
48         .addr   0                       ; IRQ entry unused
49
50 ; ------------------------------------------------------------------------
51 ; Constants
52
53 JOY_COUNT       = 2             ; Number of joysticks we support
54
55
56 .code
57
58 ; ------------------------------------------------------------------------
59 ; INSTALL routine. Is called after the driver is loaded into memory. If
60 ; possible, check if the hardware is present and determine the amount of
61 ; memory available.
62 ; Must return an JOY_ERR_xx code in a/x.
63 ;
64
65 INSTALL:
66         lda     #<JOY_ERR_OK
67         ldx     #>JOY_ERR_OK
68 ;       rts                     ; Run into UNINSTALL instead
69
70 ; ------------------------------------------------------------------------
71 ; UNINSTALL routine. Is called before the driver is removed from memory.
72 ; Can do cleanup or whatever. Must not return anything.
73 ;
74
75 UNINSTALL:
76         rts
77
78
79 ; ------------------------------------------------------------------------
80 ; COUNT: Return the total number of available joysticks in a/x.
81 ;
82
83 COUNT:
84         lda     #<JOY_COUNT
85         ldx     #>JOY_COUNT
86         rts
87
88 ; ------------------------------------------------------------------------
89 ; READ: Read a particular joystick passed in A.
90 ;
91
92 READ:   lda     #%10000000      ; via port A Data-Direction
93         sta     VIA_DDRA        ; bit 7: out    bit 6-0: in
94
95         tax                     ; Joystick number into X
96         bne     joy2
97
98 ; Read joystick 1
99
100 joy1:   lda     #$80            ; via port A read/write
101         sta     VIA_PRA         ; (output one at PA7)
102
103         lda     VIA_PRA         ; via port A read/write
104         and     #$1f            ; get bit 4-0 (PA4-PA0)
105         eor     #$1f
106         rts
107
108 ; Read joystick 2
109
110 joy2:   lda     #$00            ; via port A read/write
111         sta     VIA_PRA         ; (output zero at PA7)
112
113         lda     VIA_PRA         ; via port A read/write
114         and     #$0f            ; get bit 3-0 (PA3-PA0)
115         sta     tmp1            ; joy 4 directions
116
117         lda     VIA_PRA         ; via port A read/write
118         and     #%00100000      ; get bit 5 (PA5)
119         lsr
120         ora     tmp1
121         eor     #$1f
122
123         ldx     #0
124         rts