]> git.sur5r.net Git - cc65/blob - libsrc/atmos/joy/atmos-pase.s
637571c0461d2eece93190faf66b0be61c761f61
[cc65] / libsrc / atmos / joy / atmos-pase.s
1 ;
2 ; P.A.S.E. joystick driver for the Atmos
3 ; Can be used multiple times when statically linked to the application.
4 ;
5 ; 2002-12-20, Based on Ullrich von Bassewitz's code.
6 ; 2009-12-21, Stefan Haubenthal
7 ; 2013-07-15, Greg King
8 ;
9
10         .include        "joy-kernel.inc"
11         .include        "joy-error.inc"
12         .include        "atmos.inc"
13
14         .macpack        module
15
16
17 ; ------------------------------------------------------------------------
18 ; Header. Includes jump table
19
20         module_header   _atmos_pase_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 ; ------------------------------------------------------------------------
45 ; Data.
46
47 .bss
48 temp1:  .byte   $00
49 temp2:  .byte   $00
50
51 .code
52
53 ; ------------------------------------------------------------------------
54 ; INSTALL routine. Is called after the driver is loaded into memory. If
55 ; possible, check if the hardware is present and determine the amount of
56 ; memory available.
57 ; Must return an JOY_ERR_xx code in a/x.
58 ;
59
60 INSTALL:
61         lda     #JOY_ERR_OK
62         ldx     #0
63 ;       rts                     ; Run into UNINSTALL instead
64
65 ; ------------------------------------------------------------------------
66 ; UNINSTALL routine. Is called before the driver is removed from memory.
67 ; Can do cleanup or whatever. Must not return anything.
68 ;
69
70 UNINSTALL:
71         rts
72
73
74 ; ------------------------------------------------------------------------
75 ; COUNT: Return the total number of available joysticks in a/x.
76 ;
77
78 COUNT:
79         lda     #JOY_COUNT
80         ldx     #0
81         rts
82
83 ; ------------------------------------------------------------------------
84 ; READ: Read a particular joystick passed in A.
85 ;
86
87 READ:
88         tay
89
90         lda     VIA::PRA
91         pha
92         lda     VIA::DDRA
93         pha
94         lda     #%11000000
95         sta     VIA::DDRA
96         lda     #%10000000
97         sta     VIA::PRA2
98         lda     VIA::PRA2
99         sta     temp1
100         lda     #%01000000
101         sta     VIA::PRA2
102         lda     VIA::PRA
103         sta     temp2
104         pla
105         sta     VIA::DDRA
106         pla
107         sta     VIA::PRA2
108
109         ldx     #0
110         tya
111         bne     @L1
112         lda     temp1
113         eor     #$FF
114         rts
115 @L1:    lda     temp2
116         eor     #$FF
117         rts