-
Notifications
You must be signed in to change notification settings - Fork 0
/
InfoNES.h
320 lines (249 loc) · 8.06 KB
/
InfoNES.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
/*===================================================================*/
/* */
/* InfoNES.h : NES Emulator for Win32, Linux(x86), Linux(PS2) */
/* */
/* 2000/05/14 InfoNES Project ( based on pNesX ) */
/* */
/*===================================================================*/
#ifndef InfoNES_H_INCLUDED
#define InfoNES_H_INCLUDED
/*-------------------------------------------------------------------*/
/* Include files */
/*-------------------------------------------------------------------*/
#include "InfoNES_Types.h"
/*-------------------------------------------------------------------*/
/* NES resources */
/*-------------------------------------------------------------------*/
#define RAM_SIZE 0x2000
#define SRAM_SIZE 0x2000
#define PPURAM_SIZE 0x4000
#define SPRRAM_SIZE 256
/* RAM */
extern BYTE RAM[];
/* SRAM */
extern BYTE SRAM[];
/* ROM */
extern BYTE *ROM;
/* SRAM BANK ( 8Kb ) */
extern BYTE *SRAMBANK;
/* ROM BANK ( 8Kb * 4 ) */
extern BYTE *ROMBANK0;
extern BYTE *ROMBANK1;
extern BYTE *ROMBANK2;
extern BYTE *ROMBANK3;
/*-------------------------------------------------------------------*/
/* PPU resources */
/*-------------------------------------------------------------------*/
/* PPU RAM */
extern BYTE PPURAM[];
/* VROM */
extern BYTE *VROM;
/* PPU BANK ( 1Kb * 16 ) */
extern BYTE *PPUBANK[];
#define NAME_TABLE0 8
#define NAME_TABLE1 9
#define NAME_TABLE2 10
#define NAME_TABLE3 11
#define NAME_TABLE_V_MASK 2
#define NAME_TABLE_H_MASK 1
/* Sprite RAM */
extern BYTE SPRRAM[];
#define SPR_Y 0
#define SPR_CHR 1
#define SPR_ATTR 2
#define SPR_X 3
#define SPR_ATTR_COLOR 0x3
#define SPR_ATTR_V_FLIP 0x80
#define SPR_ATTR_H_FLIP 0x40
#define SPR_ATTR_PRI 0x20
/* PPU Register */
extern BYTE PPU_R0;
extern BYTE PPU_R1;
extern BYTE PPU_R2;
extern BYTE PPU_R3;
extern BYTE PPU_R7;
extern BYTE PPU_Scr_V;
extern BYTE PPU_Scr_V_Next;
extern BYTE PPU_Scr_V_Byte;
extern BYTE PPU_Scr_V_Byte_Next;
extern BYTE PPU_Scr_V_Bit;
extern BYTE PPU_Scr_V_Bit_Next;
extern BYTE PPU_Scr_H;
extern BYTE PPU_Scr_H_Next;
extern BYTE PPU_Scr_H_Byte;
extern BYTE PPU_Scr_H_Byte_Next;
extern BYTE PPU_Scr_H_Bit;
extern BYTE PPU_Scr_H_Bit_Next;
extern BYTE PPU_Latch_Flag;
extern WORD PPU_Addr;
extern WORD PPU_Temp;
extern WORD PPU_Increment;
extern BYTE PPU_Latch_Flag;
extern BYTE PPU_UpDown_Clip;
#define R0_NMI_VB 0x80
#define R0_NMI_SP 0x40
#define R0_SP_SIZE 0x20
#define R0_BG_ADDR 0x10
#define R0_SP_ADDR 0x08
#define R0_INC_ADDR 0x04
#define R0_NAME_ADDR 0x03
#define R1_BACKCOLOR 0xe0
#define R1_SHOW_SP 0x10
#define R1_SHOW_SCR 0x08
#define R1_CLIP_SP 0x04
#define R1_CLIP_BG 0x02
#define R1_MONOCHROME 0x01
#define R2_IN_VBLANK 0x80
#define R2_HIT_SP 0x40
#define R2_MAX_SP 0x20
#define R2_WRITE_FLAG 0x10
#define SCAN_TOP_OFF_SCREEN 0
#define SCAN_ON_SCREEN 1
#define SCAN_BOTTOM_OFF_SCREEN 2
#define SCAN_UNKNOWN 3
#define SCAN_VBLANK 4
#define SCAN_TOP_OFF_SCREEN_START 0
#define SCAN_ON_SCREEN_START 8
#define SCAN_BOTTOM_OFF_SCREEN_START 232
#define SCAN_UNKNOWN_START 240
#define SCAN_VBLANK_START 243
#define SCAN_VBLANK_END 262
#define STEP_PER_SCANLINE 113
#define STEP_PER_FRAME 29828
/* Develop Scroll Registers */
#define InfoNES_SetupScr() \
{ \
/* V-Scroll Register */ \
/* PPU_Scr_V_Byte_Next = ( BYTE )( ( PPU_Addr & 0x03e0 ) >> 5 ); */ \
/* PPU_Scr_V_Bit_Next = ( BYTE )( ( PPU_Addr & 0x7000 ) >> 12 ); */ \
/* H-Scroll Register */ \
/* PPU_Scr_H_Byte_Next = ( BYTE )( PPU_Addr & 0x001f ); */ \
/* NameTableBank */ \
PPU_NameTableBank = NAME_TABLE0 + ( ( PPU_Addr & 0x0C00 ) >> 10 ); \
}
/* Current Scanline */
extern WORD PPU_Scanline;
/* Scanline Table */
extern BYTE PPU_ScanTable[];
/* Name Table Bank */
extern BYTE PPU_NameTableBank;
/* BG Base Address */
extern BYTE *PPU_BG_Base;
/* Sprite Base Address */
extern BYTE *PPU_SP_Base;
/* Sprite Height */
extern WORD PPU_SP_Height;
/* NES display size */
#define NES_DISP_WIDTH 256
#define NES_DISP_HEIGHT 240
/* VRAM Write Enable ( 0: Disable, 1: Enable ) */
extern BYTE byVramWriteEnable;
/* Frame IRQ ( 0: Disabled, 1: Enabled )*/
extern BYTE FrameIRQ_Enable;
extern WORD FrameStep;
/*-------------------------------------------------------------------*/
/* Display and Others resouces */
/*-------------------------------------------------------------------*/
/* Frame Skip */
extern WORD FrameSkip;
extern WORD FrameCnt;
extern WORD FrameWait;
#if 0
extern WORD DoubleFrame[ 2 ][ NES_DISP_WIDTH * NES_DISP_HEIGHT ];
extern WORD *WorkFrame;
extern WORD WorkFrameIdx;
#else
extern WORD WorkFrame[ NES_DISP_WIDTH * NES_DISP_HEIGHT ];
#endif
extern BYTE ChrBuf[];
extern BYTE ChrBufUpdate;
extern WORD PalTable[];
/*-------------------------------------------------------------------*/
/* APU and Pad resources */
/*-------------------------------------------------------------------*/
extern BYTE APU_Reg[];
extern int APU_Mute;
extern DWORD PAD1_Latch;
extern DWORD PAD2_Latch;
extern DWORD PAD_System;
extern DWORD PAD1_Bit;
extern DWORD PAD2_Bit;
#define PAD_SYS_QUIT 1
#define PAD_SYS_OK 2
#define PAD_SYS_CANCEL 4
#define PAD_SYS_UP 8
#define PAD_SYS_DOWN 0x10
#define PAD_SYS_LEFT 0x20
#define PAD_SYS_RIGHT 0x40
#define PAD_PUSH(a,b) ( ( (a) & (b) ) != 0 )
/*-------------------------------------------------------------------*/
/* Mapper Function */
/*-------------------------------------------------------------------*/
/* Initialize Mapper */
extern void (*MapperInit)();
/* Write to Mapper */
extern void (*MapperWrite)( WORD wAddr, BYTE byData );
/* Write to SRAM */
extern void (*MapperSram)( WORD wAddr, BYTE byData );
/* Write to APU */
extern void (*MapperApu)( WORD wAddr, BYTE byData );
/* Read from Apu */
extern BYTE (*MapperReadApu)( WORD wAddr );
/* Callback at VSync */
extern void (*MapperVSync)();
/* Callback at HSync */
extern void (*MapperHSync)();
/* Callback at PPU read/write */
extern void (*MapperPPU)( WORD wAddr );
/* Callback at Rendering Screen 1:BG, 0:Sprite */
extern void (*MapperRenderScreen)( BYTE byMode );
/*-------------------------------------------------------------------*/
/* ROM information */
/*-------------------------------------------------------------------*/
/* .nes File Header */
struct NesHeader_tag
{
BYTE byID[ 4 ];
BYTE byRomSize;
BYTE byVRomSize;
BYTE byInfo1;
BYTE byInfo2;
BYTE byReserve[ 8 ];
};
/* .nes File Header */
extern struct NesHeader_tag NesHeader;
/* Mapper No. */
extern BYTE MapperNo;
/* Other */
extern BYTE ROM_Mirroring;
extern BYTE ROM_SRAM;
extern BYTE ROM_Trainer;
extern BYTE ROM_FourScr;
/*-------------------------------------------------------------------*/
/* Function prototypes */
/*-------------------------------------------------------------------*/
/* Initialize InfoNES */
void InfoNES_Init();
/* Completion treatment */
void InfoNES_Fin();
/* Load a cassette */
int InfoNES_Load( const char *pszFileName );
/* Reset InfoNES */
int InfoNES_Reset();
/* Initialize PPU */
void InfoNES_SetupPPU();
/* Set up a Mirroring of Name Table */
void InfoNES_Mirroring( int nType );
/* The main loop of InfoNES */
void InfoNES_Main();
/* The loop of emulation */
void InfoNES_Cycle();
/* A function in H-Sync */
int InfoNES_HSync();
/* Render a scanline */
void InfoNES_DrawLine();
/* Get a position of scanline hits sprite #0 */
void InfoNES_GetSprHitY();
/* Develop character data */
void InfoNES_SetupChr();
#endif /* !InfoNES_H_INCLUDED */