]> git.sur5r.net Git - cc65/blob - libsrc/pet/joy/pet-ptvjoy.s
3bb36835576dd9880d5fe9602a7a3b9b902c8aba
[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
14         .macpack module
15
16
17 ; ------------------------------------------------------------------------
18 ; Header. Includes jump table
19
20         module_header   _pet_ptvjoy_joy
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 ; Jump table.
32
33         .addr   INSTALL
34         .addr   UNINSTALL
35         .addr   COUNT
36         .addr   READ
37         .addr   0                       ; IRQ entry unused
38
39 ; ------------------------------------------------------------------------
40 ; Constants
41
42 JOY_COUNT       = 2                     ; Number of joysticks we support
43
44 VIA_PRA         := $E841                ; Port register A
45 VIA_DDRA        := $E843                ; Data direction register A
46
47
48 .code
49
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
53 ; memory available.
54 ; Must return an JOY_ERR_xx code in a/x.
55 ;
56
57 INSTALL:
58         lda     #<JOY_ERR_OK
59         ldx     #>JOY_ERR_OK
60 ;       rts                     ; Run into UNINSTALL instead
61
62 ; ------------------------------------------------------------------------
63 ; UNINSTALL routine. Is called before the driver is removed from memory.
64 ; Can do cleanup or whatever. Must not return anything.
65 ;
66
67 UNINSTALL:
68         rts
69
70
71 ; ------------------------------------------------------------------------
72 ; COUNT: Return the total number of available joysticks in a/x.
73 ;
74
75 COUNT:
76         lda     #<JOY_COUNT
77         ldx     #>JOY_COUNT
78         rts
79
80 ; ------------------------------------------------------------------------
81 ; READ: Read a particular joystick passed in A.
82 ;
83
84 READ:   lda     #%10000000      ; via port A Data-Direction
85         sta     VIA_DDRA        ; bit 7: out    bit 6-0: in
86
87         tax                     ; Joystick number into X
88         bne     joy2
89
90 ; Read joystick 1
91
92 joy1:   lda     #$80            ; via port A read/write
93         sta     VIA_PRA         ; (output one at PA7)
94
95         lda     VIA_PRA         ; via port A read/write
96         and     #$1f            ; get bit 4-0 (PA4-PA0)
97         eor     #$1f
98         rts
99
100 ; Read joystick 2
101
102 joy2:   lda     #$00            ; via port A read/write
103         sta     VIA_PRA         ; (output zero at PA7)
104
105         lda     VIA_PRA         ; via port A read/write
106         and     #$0f            ; get bit 3-0 (PA3-PA0)
107         sta     tmp1            ; joy 4 directions
108
109         lda     VIA_PRA         ; via port A read/write
110         and     #%00100000      ; get bit 5 (PA5)
111         lsr
112         ora     tmp1
113         eor     #$1f
114
115         ldx     #0
116         rts