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