坑 - NES模拟器(1) - 读 ROM

本文档详细介绍了开发NES模拟器的过程,首篇重点聚焦于读取和解析ROM文件,探讨了NES游戏的内部结构及其在模拟器中的实现。
摘要由CSDN通过智能技术生成

NES.hpp

#ifndef _WXWIDGETS_NES_
#define _WXWIDGETS_NES_

#include <wx\file.h>
#include "MyMarco.h"
#include "mapper.hpp"

#define PRG_BLOCK_SIZE	0x4000
#define PAT_BLOCK_SIZE	0x2000

#define	FETCH_CYCLES	0x8

typedef struct tagNESCONFIG
{
	float BaseClock;		// NTSC:21477270.0  PAL:21281364.0
	float CpuClock;			// NTSC: 1789772.5  PAL: 1773447.0
	int TotalScanlines;		// NTSC: 262  PAL: 312
	int	ScanlineCycles;		// NTSC:1364  PAL:1362
	int	HDrawCycles;		// NTSC:1024  PAL:1024
	int	HBlankCycles;		// NTSC: 340  PAL: 338
	int	ScanlineEndCycles;	// NTSC:   4  PAL:   2
	int	FrameCycles;		// NTSC:29829.52  PAL:35468.94
	int	FrameIrqCycles;		// NTSC:29829.52  PAL:35468.94
	int	FrameRate;			// NTSC:60(59.94) PAL:50
	float	FramePeriod;	// NTSC:16.683    PAL:20.0
} NESCONFIG,*LPNESCONFIG;

NESCONFIG NESCONFIG_NTSC =
{
	21477270.0f,	// Base clock
	1789772.5f,		// Cpu clock
	262,			// Total scanlines
	1364,			// Scanline total cycles(15.75KHz)
	1024,			// H-Draw cycles
	340,			// H-Blank cycles
	4,				// End cycles
	1364 * 262,		// Frame cycles
	29830,			// FrameIRQ cycles
	60,				// Frame rate(Be originally 59.94Hz)
	1000.0f / 60.0f	// Frame period(ms)
};

NESCONFIG NESCONFIG_PAL =
{
	21281364.0f,    // Base clock
	1773447.0f,		// Cpu clock
	312,			// Total scanlines
	1362,			// Scanline total cycles(15.625KHz)
	1024,			// H-Draw cycles
	338,			// H-Blank cycles
	2,				// End cycles
	1362 * 312,		// Frame cycles
	35469,			// FrameIRQ cycles
	50,				// Frame rate(Hz)
	1000.0f / 50.0f	// Frame period(ms)
};

RGBQUAD rgbQuard[64] =
{	
	{0x7F, 0x7F, 0x7F, 0}, {0xB0, 0x00, 0x20, 0}, {0xB8, 0x00, 0x28, 0}, {0xA0, 0x10, 0x60, 0},
	{0x78, 0x20, 0x98, 0}, {0x30, 0x10, 0xB0, 0}, {0x00, 0x30, 0xA0, 0}, {0x00, 0x40, 0x78, 0},
	{0x00, 0x58, 0x48, 0}, {0x00, 0x68, 0x38, 0}, {0x00, 0x6C, 0x38, 0}, {0x40, 0x60, 0x30, 0},
	{0x80, 0x50, 0x30, 0}, {0x00, 0x00, 0x00, 0}, {0x00, 0x00, 0x00, 0}, {0x00, 0x00, 0x00, 0},

	{0xBC, 0xBC, 0xBC, 0}, {0xF8, 0x60, 0x40, 0}, {0xFF, 0x40, 0x40, 0}, {0xF0, 0x40, 0x90, 0},
	{0xC0, 0x40, 0xD8, 0}, {0x60, 0x40, 0xD8, 0}, {0x00, 0x50, 0xE0, 0}, {0x00, 0x70, 0xC0, 0},
	{0x00, 0x88, 0x88, 0}, {0x00, 0xA0, 0x50, 0}, {0x10, 0xA8, 0x48, 0}, {0x68, 0xA0, 0x48, 0},
	{0xC0, 0x90, 0x40, 0}, {0x00, 0x00, 0x00, 0}, {0x00, 0x00, 0x00, 0}, {0x00, 0x00, 0x00, 0},

	{0xFF, 0xFF, 0xFF, 0}, {0xFF, 0xA0, 0x60, 0}, {0xFF, 0x80, 0x50, 0}, {0xFF, 0x70, 0xA0, 0},
	{0xFF, 0x60, 0xF0, 0}, {0xB0, 0x60, 0xFF, 0}, {0x30, 0x78, 0xFF, 0}, {0x00, 0xA0, 0xFF, 0},
	{0x20, 0
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值