]> git.sur5r.net Git - cc65/blob - libsrc/lynx/lynx-stdjoy.s
2bc32e88ee7c36e3e483ce10de0b9a117645d61b
[cc65] / libsrc / lynx / lynx-stdjoy.s
1 ;
2 ; Standard joystick driver for the Atari Lynx.
3 ; The Lynx has two fire buttons. So it is not quite "standard".
4 ;
5 ; Modified by Karri Kaksonen, 2004-09-16
6 ; Ullrich von Bassewitz, 2002-12-20
7 ; Using code from Steve Schmidtke
8 ;
9
10         .include        "zeropage.inc"
11
12         .include        "joy-kernel.inc"
13         .include        "joy-error.inc"
14         .include        "lynx.inc"
15         .include        "extzp.inc"
16
17         .macpack        generic
18
19
20 ; ------------------------------------------------------------------------
21 ; Header. Includes jump table
22
23 .segment        "JUMPTABLE"
24
25 ; Driver signature
26
27         .byte   $6A, $6F, $79           ; "joy"
28         .byte   JOY_API_VERSION         ; Driver API version number
29
30 ; Button state masks (8 values)
31
32 joy_mask:
33         .byte   $80                     ; JOY_UP
34         .byte   $40                     ; JOY_DOWN
35         .byte   $20                     ; JOY_LEFT
36         .byte   $10                     ; JOY_RIGHT
37         .byte   $01                     ; JOY_FIRE
38         .byte   $02                     ; JOY_FIRE1
39         .byte   $00                     ;
40         .byte   $00                     ;
41
42 ; Jump table.
43
44         .addr   INSTALL
45         .addr   UNINSTALL
46         .addr   COUNT
47         .addr   READ
48         .addr   0                       ; IRQ entry unused
49
50 ; ------------------------------------------------------------------------
51 ; Constants
52
53 JOY_COUNT       = 1             ; Number of joysticks we support
54
55
56 ; ------------------------------------------------------------------------
57 ; Data.
58
59
60 .code
61
62 ; ------------------------------------------------------------------------
63 ; INSTALL routine. Is called after the driver is loaded into memory. If
64 ; possible, check if the hardware is present and determine the amount of
65 ; memory available.
66 ; Must return an JOY_ERR_xx code in a/x.
67 ;
68 ; Here we also flip the joypad in case the display is flipped.
69 ; This install routine should be called after you send the flip code
70 ; to the display hardware.
71
72 INSTALL:
73         lda     __viddma        ; Process flipped displays
74         and     #2
75         beq     @L2
76
77 ; Set joypad for flipped display
78
79         lda     #$10
80         ldx     #$00
81 @L1:    sta     joy_mask,x
82         inx
83         asl     a
84         bcc     @L1
85         bra     @L4
86
87 ; Set joypad for normal display
88
89 @L2:    lda     #$10
90         ldx     #$03
91 @L3:    sta     joy_mask,x
92         dex
93         asl     a
94         bcc     @L3
95
96 ; Done
97
98 @L4:    lda     #<JOY_ERR_OK
99         ldx     #>JOY_ERR_OK
100 ;       rts                     ; Run into UNINSTALL instead
101
102 ; ------------------------------------------------------------------------
103 ; UNINSTALL routine. Is called before the driver is removed from memory.
104 ; Can do cleanup or whatever. Must not return anything.
105 ;
106
107 UNINSTALL:
108         rts
109
110
111 ; ------------------------------------------------------------------------
112 ; COUNT: Return the total number of available joysticks in a/x.
113 ;
114
115 COUNT:
116         lda     #<JOY_COUNT
117         ldx     #>JOY_COUNT
118         rts
119
120 ; ------------------------------------------------------------------------
121 ; READ: Read a particular joystick passed in A.
122
123 READ:
124         ldx     #$00            ; Clear high byte
125         lda     JOYSTICK        ; Read joystick
126         and     #$F3            ; Mask relevant keys
127         rts
128
129