]> git.sur5r.net Git - cc65/blob - libsrc/nes/joy/nes-stdjoy.s
3032e9330083bc5f10b43fc0f9781b0ddff5eac0
[cc65] / libsrc / nes / joy / nes-stdjoy.s
1 ;
2 ; Standard joypad driver for the NES. May be used multiple times when
3 ; linked to the statically application.
4 ;
5 ; Ullrich von Bassewitz, 2003-05-02
6 ; Stefan Haubenthal, 2004-10-05
7 ;
8
9         .include        "zeropage.inc"
10
11         .include        "joy-kernel.inc"
12         .include        "joy-error.inc"
13         .include        "nes.inc"
14
15         .macpack        module
16
17
18 ; ------------------------------------------------------------------------
19 ; Header. Includes jump table
20
21         module_header   _nes_stdjoy_joy
22
23 ; Driver signature
24
25         .byte   $6A, $6F, $79           ; "joy"
26         .byte   JOY_API_VERSION         ; Driver API version number
27
28 ; Library reference
29
30         .addr   $0000
31
32 ; Jump table.
33
34         .addr   INSTALL
35         .addr   UNINSTALL
36         .addr   COUNT
37         .addr   READJOY
38         .addr   0                       ; IRQ entry unused
39
40 ; ------------------------------------------------------------------------
41 ; Constants
42
43 JOY_COUNT       = 2             ; Number of joysticks we support
44
45
46 .code
47
48 ; ------------------------------------------------------------------------
49 ; INSTALL routine. Is called after the driver is loaded into memory. If
50 ; possible, check if the hardware is present and determine the amount of
51 ; memory available.
52 ; Must return an JOY_ERR_xx code in a/x.
53 ;
54
55 INSTALL:
56         lda     #JOY_ERR_OK
57         ldx     #0
58 ;       rts                     ; Run into UNINSTALL instead
59
60 ; ------------------------------------------------------------------------
61 ; UNINSTALL routine. Is called before the driver is removed from memory.
62 ; Can do cleanup or whatever. Must not return anything.
63 ;
64
65 UNINSTALL:
66         rts
67
68
69 ; ------------------------------------------------------------------------
70 ; COUNT: Return the total number of available joysticks in a/x.
71 ;
72
73 COUNT:
74         lda     #JOY_COUNT
75         ldx     #0
76         rts
77
78 ; ------------------------------------------------------------------------
79 ; READ: Read a particular joystick passed in A.
80 ;
81
82 READJOY:
83         and     #$01            ; Fix joystick number
84         tay                     ; Joystick number (0,1) into Y
85
86         lda     #1
87         sta     APU_PAD1
88         lda     #0
89         sta     APU_PAD1
90
91 ; Read joystick
92
93         ldx     #8
94 @Loop:  lda     APU_PAD1,y
95         ror     a
96         ror     tmp1
97         dex
98         bne     @Loop
99
100         lda     tmp1
101 ;       ldx     #$00            ; X implicitly fixed
102         rts