]> git.sur5r.net Git - cc65/blob - libsrc/atmos/atmos-pase.s
18ac7b88709551bcddf8705ee51acc5815da01f0
[cc65] / libsrc / atmos / atmos-pase.s
1 ;
2 ; P.A.S.E. joystick driver for the Atmos
3 ; May be used multiple times when linked to the statically application.
4 ;
5 ; Stefan Haubenthal, 2009-12-21
6 ; Based on Ullrich von Bassewitz, 2002-12-20
7 ;
8
9         .include        "joy-kernel.inc"
10         .include        "joy-error.inc"
11 ;       .include        "atmos.inc"
12
13
14 ; ------------------------------------------------------------------------
15 ; Header. Includes jump table
16
17 .segment        "JUMPTABLE"
18
19 ; Driver signature
20
21         .byte   $6A, $6F, $79           ; "joy"
22         .byte   JOY_API_VERSION         ; Driver API version number
23
24 ; Button state masks (8 values)
25
26         .byte   $10                     ; JOY_UP
27         .byte   $08                     ; JOY_DOWN
28         .byte   $01                     ; JOY_LEFT
29         .byte   $02                     ; JOY_RIGHT
30         .byte   $20                     ; JOY_FIRE
31         .byte   $00                     ; Future expansion
32         .byte   $00                     ; Future expansion
33         .byte   $00                     ; Future expansion
34
35 ; Jump table.
36
37         .addr   INSTALL
38         .addr   UNINSTALL
39         .addr   COUNT
40         .addr   READ
41         .addr   0                       ; IRQ entry unused
42
43 ; ------------------------------------------------------------------------
44 ; Constants
45
46 JOY_COUNT       = 2             ; Number of joysticks we support
47
48 PRA             = $0301
49 DDRA            = $0303
50 PRA2            = $030F
51
52 ; ------------------------------------------------------------------------
53 ; Data.
54
55 .bss
56 temp1:  .byte   $00
57 temp2:  .byte   $00
58
59 .code
60
61 ; ------------------------------------------------------------------------
62 ; INSTALL routine. Is called after the driver is loaded into memory. If
63 ; possible, check if the hardware is present and determine the amount of
64 ; memory available.
65 ; Must return an JOY_ERR_xx code in a/x.
66 ;
67
68 INSTALL:
69         lda     #JOY_ERR_OK
70         ldx     #0
71 ;       rts                     ; Run into UNINSTALL instead
72
73 ; ------------------------------------------------------------------------
74 ; UNINSTALL routine. Is called before the driver is removed from memory.
75 ; Can do cleanup or whatever. Must not return anything.
76 ;
77
78 UNINSTALL:
79         rts
80
81
82 ; ------------------------------------------------------------------------
83 ; COUNT: Return the total number of available joysticks in a/x.
84 ;
85
86 COUNT:
87         lda     #JOY_COUNT
88         ldx     #0
89         rts
90
91 ; ------------------------------------------------------------------------
92 ; READ: Read a particular joystick passed in A.
93 ;
94
95 READ:
96         tay
97
98         lda     PRA
99         pha
100         lda     DDRA
101         pha
102         lda     #%11000000
103         sta     DDRA
104         lda     #%10000000
105         sta     PRA2
106         lda     PRA2
107         sta     temp1
108         lda     #%01000000
109         sta     PRA2
110         lda     PRA
111         sta     temp2
112         pla
113         sta     DDRA
114         pla
115         sta     PRA2
116
117         ldx     #0
118         tya
119         bne     @L1
120         lda     temp1
121         eor     #$FF
122         rts
123 @L1:    lda     temp2
124         eor     #$FF
125         rts