]> git.sur5r.net Git - cc65/blob - include/nes.h
Adds test code for the Atari (xex) linker file format.
[cc65] / include / nes.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                   nes.h                                   */
4 /*                                                                           */
5 /*                      NES system specific definitions                      */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2002-2003 Groepaz/Hitmen                                              */
10 /*                                                                           */
11 /*                                                                           */
12 /* This software is provided 'as-is', without any expressed or implied       */
13 /* warranty.  In no event will the authors be held liable for any damages    */
14 /* arising from the use of this software.                                    */
15 /*                                                                           */
16 /* Permission is granted to anyone to use this software for any purpose,     */
17 /* including commercial applications, and to alter it and redistribute it    */
18 /* freely, subject to the following restrictions:                            */
19 /*                                                                           */
20 /* 1. The origin of this software must not be misrepresented; you must not   */
21 /*    claim that you wrote the original software. If you use this software   */
22 /*    in a product, an acknowledgment in the product documentation would be  */
23 /*    appreciated but is not required.                                       */
24 /* 2. Altered source versions must be plainly marked as such, and must not   */
25 /*    be misrepresented as being the original software.                      */
26 /* 3. This notice may not be removed or altered from any source              */
27 /*    distribution.                                                          */
28 /*                                                                           */
29 /*****************************************************************************/
30
31
32
33 #ifndef _NES_H
34 #define _NES_H
35
36
37
38 /* Check for errors */
39 #if !defined(__NES__)
40 #  error This module may only be used when compiling for the NES!
41 #endif
42
43
44
45 /* Key and character defines */
46 #define CH_ENTER                '\n'
47 #define CH_CURS_UP              0x01
48 #define CH_CURS_DOWN            0x02
49 #define CH_CURS_LEFT            0x03
50 #define CH_CURS_RIGHT           0x04
51 #define CH_ESC                  8
52 #define CH_DEL                  20
53
54 #define CH_CROSS                0x10
55 #define CH_RTEE                 0x17
56 #define CH_LTEE                 0x0f
57 #define CH_TTEE                 0x16
58 #define CH_BTEE                 0x15
59 #define CH_HLINE                0x0b
60 #define CH_VLINE                0x0e
61 #define CH_ULCORNER             0x14
62 #define CH_URCORNER             0x12
63 #define CH_LLCORNER             0x11
64 #define CH_LRCORNER             0x08
65 #define CH_PI                   0x05
66
67 /* Color defines */
68 #define COLOR_BLACK             0x00
69 #define COLOR_WHITE             0x01
70 #define COLOR_RED               0x02
71 #define COLOR_CYAN              0x03
72 #define COLOR_VIOLET            0x04
73 #define COLOR_GREEN             0x05
74 #define COLOR_BLUE              0x06
75 #define COLOR_YELLOW            0x07
76 #define COLOR_ORANGE            0x08
77 #define COLOR_BROWN             0x09
78 #define COLOR_LIGHTRED          0x0A
79 #define COLOR_GRAY1             0x0B
80 #define COLOR_GRAY2             0x0C
81 #define COLOR_LIGHTGREEN        0x0D
82 #define COLOR_LIGHTBLUE         0x0E
83 #define COLOR_GRAY3             0x0F
84
85 /* Masks for joy_read */
86 #define JOY_UP_MASK     0x10
87 #define JOY_DOWN_MASK   0x20
88 #define JOY_LEFT_MASK   0x40
89 #define JOY_RIGHT_MASK  0x80
90 #define JOY_BTN_1_MASK  0x01
91 #define JOY_BTN_2_MASK  0x02
92 #define JOY_BTN_3_MASK  0x04
93 #define JOY_BTN_4_MASK  0x08
94
95 #define JOY_BTN_A_MASK  JOY_BTN_1_MASK
96 #define JOY_BTN_B_MASK  JOY_BTN_2_MASK
97 #define JOY_SELECT_MASK JOY_BTN_3_MASK
98 #define JOY_START_MASK  JOY_BTN_4_MASK
99
100 #define JOY_BTN_A(v)    ((v) & JOY_BTN_A_MASK)
101 #define JOY_BTN_B(v)    ((v) & JOY_BTN_B_MASK)
102 #define JOY_SELECT(v)   ((v) & JOY_SELECT_MASK)
103 #define JOY_START(v)    ((v) & JOY_START_MASK)
104
105 /* Return codes of get_tv */
106 #define TV_NTSC         0
107 #define TV_PAL          1
108 #define TV_OTHER        2
109
110 /* No support for dynamically loadable drivers */
111 #define DYN_DRV         0
112
113 /* Define hardware */
114
115 /* Picture Processing Unit */
116 struct __ppu {
117     unsigned char control;
118     unsigned char mask;                 /* color; show sprites, background */
119       signed char volatile const status;
120     struct {
121         unsigned char address;
122         unsigned char data;
123     } sprite;
124     unsigned char scroll;
125     struct {
126         unsigned char address;
127         unsigned char data;
128     } vram;
129 };
130 #define PPU             (*(struct __ppu*)0x2000)
131 #define SPRITE_DMA      (APU.sprite.dma)
132
133 /* Audio Processing Unit */
134 struct __apu {
135     struct {
136         unsigned char control;          /* duty, counter halt, volume/envelope */
137         unsigned char ramp;
138         unsigned char period_low;       /* timing */
139         unsigned char len_period_high;  /* length, timing */
140     } pulse[2];
141     struct {
142         unsigned char counter;          /* counter halt, linear counter */
143         unsigned char unused;
144         unsigned char period_low;       /* timing */
145         unsigned char len_period_high;  /* length, timing */
146     } triangle;
147     struct {
148         unsigned char control;          /* counter halt, volume/envelope */
149         unsigned char unused;
150         unsigned char period;           /* loop, timing */
151         unsigned char len;              /* length */
152     } noise;
153     struct {
154         unsigned char control;          /* IRQ, loop, rate */
155         unsigned char output;           /* output value */
156         unsigned char address;
157         unsigned char length;
158     } delta_mod;                        /* delta pulse-code modulation */
159     struct {
160         unsigned char dma;
161     } sprite;
162       signed char volatile status;
163     unsigned char unused;
164     unsigned char fcontrol;
165 };
166 #define APU             (*(struct __apu*)0x4000)
167
168 #define JOYPAD          ((unsigned char volatile[2])0x4016)
169
170 /* The addresses of the static drivers */
171 extern void nes_stdjoy_joy[];       /* Referred to by joy_static_stddrv[] */
172 extern void nes_64_56_2_tgi[];      /* Referred to by tgi_static_stddrv[] */
173
174
175
176 void waitvsync (void);
177 /* Wait for start of the next frame */
178
179 unsigned char get_tv (void);
180 /* Return the video mode the machine is using. */
181
182
183
184 /* End of nes.h */
185 #endif