]> git.sur5r.net Git - cc65/blob - libsrc/nes/joy/nes-stdjoy.s
Added library reference address to lightpen driver header.
[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
16 ; ------------------------------------------------------------------------
17 ; Header. Includes jump table
18
19 .segment        "JUMPTABLE"
20
21 ; Driver signature
22
23         .byte   $6A, $6F, $79           ; "joy"
24         .byte   JOY_API_VERSION         ; Driver API version number
25
26 ; Library reference
27
28         .addr   $0000
29
30 ; Button state masks (8 values)
31
32         .byte   $10                     ; JOY_UP
33         .byte   $20                     ; JOY_DOWN
34         .byte   $40                     ; JOY_LEFT
35         .byte   $80                     ; JOY_RIGHT
36         .byte   $01                     ; JOY_FIRE      (A)
37         .byte   $02                     ; JOY_FIRE2     (B)
38         .byte   $04                     ;               (Select)
39         .byte   $08                     ;               (Start)
40
41 ; Jump table.
42
43         .addr   INSTALL
44         .addr   UNINSTALL
45         .addr   COUNT
46         .addr   READJOY
47         .addr   0                       ; IRQ entry unused
48
49 ; ------------------------------------------------------------------------
50 ; Constants
51
52 JOY_COUNT       = 2             ; Number of joysticks we support
53
54
55 .code
56
57 ; ------------------------------------------------------------------------
58 ; INSTALL routine. Is called after the driver is loaded into memory. If
59 ; possible, check if the hardware is present and determine the amount of
60 ; memory available.
61 ; Must return an JOY_ERR_xx code in a/x.
62 ;
63
64 INSTALL:
65         lda     #JOY_ERR_OK
66         ldx     #0
67 ;       rts                     ; Run into UNINSTALL instead
68
69 ; ------------------------------------------------------------------------
70 ; UNINSTALL routine. Is called before the driver is removed from memory.
71 ; Can do cleanup or whatever. Must not return anything.
72 ;
73
74 UNINSTALL:
75         rts
76
77
78 ; ------------------------------------------------------------------------
79 ; COUNT: Return the total number of available joysticks in a/x.
80 ;
81
82 COUNT:
83         lda     #JOY_COUNT
84         ldx     #0
85         rts
86
87 ; ------------------------------------------------------------------------
88 ; READ: Read a particular joystick passed in A.
89 ;
90
91 READJOY:
92         and     #$01            ; Fix joystick number
93         tay                     ; Joystick number (0,1) into Y
94
95         lda     #1
96         sta     APU_PAD1,y
97         lda     #0
98         sta     APU_PAD1,y
99
100 ; Read joystick
101
102         ldx     #8
103 @Loop:  lda     APU_PAD1,y
104         ror     a
105         ror     tmp1
106         dex
107         bne     @Loop
108
109         lda     tmp1
110 ;       ldx     #$00            ; X implicitly fixed
111         rts