]> git.sur5r.net Git - cc65/blob - libsrc/nes/joy/nes-stdjoy.s
Fixed _textcolor definition.
[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
39 ; ------------------------------------------------------------------------
40 ; Constants
41
42 JOY_COUNT       = 2             ; Number of joysticks we support
43
44
45 .code
46
47 ; ------------------------------------------------------------------------
48 ; INSTALL routine. Is called after the driver is loaded into memory. If
49 ; possible, check if the hardware is present and determine the amount of
50 ; memory available.
51 ; Must return an JOY_ERR_xx code in a/x.
52 ;
53
54 INSTALL:
55         lda     #JOY_ERR_OK
56         ldx     #0
57 ;       rts                     ; Run into UNINSTALL instead
58
59 ; ------------------------------------------------------------------------
60 ; UNINSTALL routine. Is called before the driver is removed from memory.
61 ; Can do cleanup or whatever. Must not return anything.
62 ;
63
64 UNINSTALL:
65         rts
66
67
68 ; ------------------------------------------------------------------------
69 ; COUNT: Return the total number of available joysticks in a/x.
70 ;
71
72 COUNT:
73         lda     #JOY_COUNT
74         ldx     #0
75         rts
76
77 ; ------------------------------------------------------------------------
78 ; READ: Read a particular joystick passed in A.
79 ;
80
81 READJOY:
82         and     #$01            ; Fix joystick number
83         tay                     ; Joystick number (0,1) into Y
84
85         lda     #1
86         sta     APU_PAD1
87         lda     #0
88         sta     APU_PAD1
89
90 ; Read joystick
91
92         ldx     #8
93 @Loop:  lda     APU_PAD1,y
94         ror     a
95         ror     tmp1
96         dex
97         bne     @Loop
98
99         lda     tmp1
100 ;       ldx     #$00            ; X implicitly fixed
101         rts