]> git.sur5r.net Git - cc65/blob - libsrc/pet/joy/pet-ptvjoy.s
Replaced whole bunch for Makefiles with a single generic Makefile.
[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 ; Button state masks (8 values)
28
29         .byte   $01                     ; JOY_UP
30         .byte   $02                     ; JOY_DOWN
31         .byte   $04                     ; JOY_LEFT
32         .byte   $08                     ; JOY_RIGHT
33         .byte   $10                     ; JOY_FIRE
34         .byte   $00                     ; JOY_FIRE2 unavailable
35         .byte   $00                     ; Future expansion
36         .byte   $00                     ; Future expansion
37
38 ; Jump table.
39
40         .addr   INSTALL
41         .addr   UNINSTALL
42         .addr   COUNT
43         .addr   READ
44         .addr   0                       ; IRQ entry unused
45
46 ; ------------------------------------------------------------------------
47 ; Constants
48
49 JOY_COUNT       = 2             ; Number of joysticks we support
50
51
52 .code
53
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
57 ; memory available.
58 ; Must return an JOY_ERR_xx code in a/x.
59 ;
60
61 INSTALL:
62         lda     #<JOY_ERR_OK
63         ldx     #>JOY_ERR_OK
64 ;       rts                     ; Run into UNINSTALL instead
65
66 ; ------------------------------------------------------------------------
67 ; UNINSTALL routine. Is called before the driver is removed from memory.
68 ; Can do cleanup or whatever. Must not return anything.
69 ;
70
71 UNINSTALL:
72         rts
73
74
75 ; ------------------------------------------------------------------------
76 ; COUNT: Return the total number of available joysticks in a/x.
77 ;
78
79 COUNT:
80         lda     #<JOY_COUNT
81         ldx     #>JOY_COUNT
82         rts
83
84 ; ------------------------------------------------------------------------
85 ; READ: Read a particular joystick passed in A.
86 ;
87
88 READ:   lda     #%10000000      ; via port A Data-Direction
89         sta     VIA_DDRA        ; bit 7: out    bit 6-0: in
90
91         tax                     ; Joystick number into X
92         bne     joy2
93
94 ; Read joystick 1
95
96 joy1:   lda     #$80            ; via port A read/write
97         sta     VIA_PRA         ; (output one at PA7)
98
99         lda     VIA_PRA         ; via port A read/write
100         and     #$1f            ; get bit 4-0 (PA4-PA0)
101         eor     #$1f
102         rts
103
104 ; Read joystick 2
105
106 joy2:   lda     #$00            ; via port A read/write
107         sta     VIA_PRA         ; (output zero at PA7)
108
109         lda     VIA_PRA         ; via port A read/write
110         and     #$0f            ; get bit 3-0 (PA3-PA0)
111         sta     tmp1            ; joy 4 directions
112
113         lda     VIA_PRA         ; via port A read/write
114         and     #%00100000      ; get bit 5 (PA5)
115         lsr
116         ora     tmp1
117         eor     #$1f
118
119         ldx     #0
120         rts