📄 gb.h
字号:
/* Copyright 2001, ESS Technology, Inc. /* SCCSID @(#)gb.h 1.1 03/13/02 *//* Based on gb.h 1.6 11/12/01 *//* * $Log$ *//** VGB: portable GameBoy emulator ***************************//** **//** GB.h **//** **//** This file contains definitions for the GameBoy hardware **//** emulation. **//** **//** Copyright (C) Marat Fayzullin 1995-2001 **//** The contents of this file are property of Marat **//** Fayzullin and should only be used as agreed with **//** him. The file is confidential. Absolutely no **//** distribution allowed. **//*************************************************************/#ifndef GB_H#define GB_H#ifdef VGB#include "libmsdos.h"#include "z80.h" /* CPU emulation declarations */#include <stdio.h> /* Standard I/O stuff */#define NORAM 0x00 /* Byte to be returned from */ /* non-existing pages and ports */#define CPU_CLOCK 4194304 /* CPU clock frequency, Hz */#define CPU_HPERIOD 456 /* Horizontal refresh, cycles */#define CPU_VPERIOD 70224 /* Vertical refresh, cycles */#define CPU_VPHASE 30 #define CPU_HPHASE2 81#define CPU_HPHASE3(N) (175+123*(N)/10)#define CPU_HPHASE0(N) (CPU_HPERIOD-CPU_HPHASE2-CPU_HPHASE3(N))#define NORMAL_GB 0 /* Normal GameBoy mode */#define POCKET_GB 1 /* Pocket GameBoy mode */#define SUPER_GB 2 /* Super GameBoy mode */#define COLOR_GB 4 /* Color GameBoy mode */#define PRINTER_GB 8 /* Pocket Printer mode */#define VFLIP_ATTR 0x40 /* Color GameBoy chr. attributes */#define HFLIP_ATTR 0x20#define PAL_ATTR 0x07#define BANK_ATTR 0x08#define PRIOR_ATTR 0x80#define VBL_IFLAG 0x01 /* Event bits in IFLAGS */#define LCD_IFLAG 0x02#define TIM_IFLAG 0x04#define SIO_IFLAG 0x08#define EXT_IFLAG 0x10#define JOYPAD IO[0x100] /* Joystick: 1.1.P15.P14.P13.P12.P11.P10 */#define SIODATA IO[0x101] /* Serial IO data buffer */#define SIOCONT IO[0x102] /* Serial IO control register */#define DIVREG IO[0x104] /* Divider register (???) */#define TIMECNT IO[0x105] /* Timer counter. Gen. int. when it overflows */#define TIMEMOD IO[0x106] /* New value of TimeCount after it overflows */#define TIMEFRQ IO[0x107] /* Timer frequency and start/stop switch */#define IFLAGS IO[0x10F] /* Interrupt flags: 0.0.0.JST.SIO.TIM.LCD.VBL */#define ISWITCH IO[0x1FF] /* Switches to enable/disable interrupts */#define LCDCONT IO[0x140] /* LCD control register */#define LCDSTAT IO[0x141] /* LCD status register */#define SCROLLY IO[0x142] /* Starting Y position of the background */#define SCROLLX IO[0x143] /* Starting X position of the background */#define CURLINE IO[0x144] /* Current screen line being scanned */#define CMPLINE IO[0x145] /* Gen. int. when scan reaches this line */#define BGRDPAL IO[0x147] /* Background palette */#define SPR0PAL IO[0x148] /* Sprite palette #0 */#define SPR1PAL IO[0x149] /* Sprite palette #1 */#define WNDPOSY IO[0x14A] /* Window Y position */#define WNDPOSX IO[0x14B] /* Window X position */#define HIGHSPD IO[0x14D] /* ColorGB turbo mode switch */#define VRAMBNK IO[0x14F] /* ColorGB VRAM bank number */#define HDMA1 IO[0x151] /* ColorGB new DMA transfer register */#define HDMA2 IO[0x152] /* ColorGB new DMA transfer register */#define HDMA3 IO[0x153] /* ColorGB new DMA transfer register */#define HDMA4 IO[0x154] /* ColorGB new DMA transfer register */#define HDMA5 IO[0x155] /* ColorGB new DMA transfer register */#define BPALREG IO[0x168] /* Background palette register number */#define BPALDAT IO[0x169] /* Background palette register data */#define SPALREG IO[0x16A] /* Sprite palette register number */#define SPALDAT IO[0x16B] /* Sprite palette register data */#define WRAMBNK IO[0x170] /* ColorGB RAM bank number */#define SND(N) IO[0x110+N] /* Sound registers */ #define UPeriod 7 /* # of VBlanks per screen update */#define time_t int/** NOTE ****************************************************//** This data structure stores sound note. **//*************************************************************/typedef struct { int Model ; /* Model (Pocket/Super/Color GB) */ int WashedOut ; /* 1: "Washed out" ColorGB palette */ int ExitNow ; /* 1: Exit emulator NOW */ int RAMEnabled; /* MBC1/3/5 ERAM: 1 for enabled */ int MBC1Mode; /* MBC1 Mode: 1 for ERAM, 0 for ROM */ int MemoryIO; /* 1=MBC3, 2=Camera, 3=HuC3, 4=Tilt */ int WndLine; /* Currently scanned window line */ int RMBOn; /* Rumble pack switch */ int RMBKey; /* State of rumble pack vibrator */ int RTCLatch; /* MBC3 Clock latch trigger */ byte RTC[5]; /* MBC3 Clock latched registers */ int SGBLatch; /* Latch for SGB command bits */ int SGBByte; /* Byte counter for SGB packets */ int SGBBit; /* Bit mask counter for SGB packets */ int SGBPackets; /* # of packets for long commands */ int SGBPacket; /* Packet counter for long commands */ int SGBPad; /* # of SGB joypad currently read */ int SGBPadMask; /* Mask which determines # of pads */ int SGBPending; /* 1: There is a pending command */ int SGBDisplay; /* Display masking mode (MASK_EN) */#if 0 char *ColorNames[16]/* = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }*/;#endif time_t RTCBase; /* Current time base of the clock */ int ROMBank; /* Currently used 16kB ROM bank */ int ROMBanks; /* Total number of ROM banks */ int ROMMask; /* Mask for the ROM bank number */ int RAMBank; /* Currently used 8kB RAM bank */ int RAMBanks; /* Total number of RAM banks */ int RAMMask; /* Mask for the RAM bank number */ int WRAMBank; /* Currently used 4kB WRAM bank */ int WRAMBanks; /* Total number of WRAM banks */ int WRAMMask; /* Mask for the WRAM bank number */ int VRAMBank; /* Currently used 8kB VRAM bank */ int VRAMBanks; /* Total number of VRAM banks */ int VRAMMask; /* Mask for the VRAM bank number */ int TPFreqs[4]; int InitColors[3][4]; unsigned int BPChanged; /* Bitmap for BPalette changes */ unsigned int SPChanged; /* Bitmap for SPalette changes */ byte BPalette[64]; /* ColorGB palettes for background */ byte SPalette[64]; /* ColorGB palettes for sprites */ byte BPGroup,WPGroup; /* Palette groups (0/4/8/12) for */ byte SP0Group,SP1Group; /* Background, window, sprites */ byte SGBBuf[128]; /* Buffer for SGB command packets */ byte SGBColTab[20*18]; /* SGB Color Table of 20x18 char-rs */ byte Intensity[32]; byte Influence[3][3]; pixel XPal[128]; /* From Common.h */ pixel Pal0[16], Pal1[16]; int IPeriod[5]; } *GMBY;GMBY gmby;char *PCycles;char *PCyclesCB;char *PGBtoZ80;char *PZ80toGB;unsigned short *PDAATable;char *PHFlip;byte *IO;/** CPU and Memory *******************************************/extern GBZ80 CPU; /* GameBoy CPU registers and state */extern byte *VRAM; /* Internal 8kB or 16kB VRAM */extern byte *ROM; /* Cartridge ROM *//** Video ****************************************************/extern byte *ChrGen; /* Character Table */extern byte *BgdTab; /* Background Name Table */extern byte *WndTab; /* Window Name Table */extern byte *ColTab; /* Background Attribute Table (CGB) */extern byte BPal[4],WPal[4]; /* Background, Window, and */extern byte SPal0[4],SPal1[4]; /* Sprite palettes *//** SuperGameBoy *********************************************/extern byte *SGBChrGen; /* SGB Char Table of 256x32 bytes */extern byte *SGBChrTab; /* SGB Name Table of 20x18 char-rs *//** StartGB() ************************************************//** Allocate memory, load ROM images, initialize hardware, **//** CPU and start the emulation. This function returns 0 in **//** the case of failure. **//*************************************************************/int StartGB();/** TrashGB() ************************************************//** Free resources allocated by StartGB(). **//*************************************************************/void TrashGB(void);/** ResetGB() ************************************************//** Reset GameBoy CPU and other hardware. **//*************************************************************/void ResetGB(void);/** Washout() ************************************************//** Toggle washed out CGB palette on (1), off (0), or **//** inverse the state (2). **//*************************************************************/void Washout(int Switch);/** InitMachine() ********************************************//** Allocate resources needed by the machine-dependent code.**//************************************ TO BE WRITTEN BY USER **/int InitMachine(void);/** TrashMachine() *******************************************//** Deallocate all resources taken by InitMachine(). **//************************************ TO BE WRITTEN BY USER **/void TrashMachine(void);/** RefreshScreen() ******************************************//** Draw the screen. **//************************************ TO BE WRITTEN BY USER **/#define RefreshScreen(A,B,C,D,E) VGAPutImage(A,B,C,D,E)/** RefreshLine() ********************************************//** Refresh line Y [0-143], including sprites. **//************************************ TO BE WRITTEN BY USER **/void RefreshLine(register int Y,register int WY);/** CGBRefreshLine() *****************************************//** Refresh line Y [0-143] on a ColorGB, including sprites. **//************************************ TO BE WRITTEN BY USER **/void CGBRefreshLine(register int Y,register int WY);/** SetColor() ***********************************************//** Set color N to (R,G,B). There is total of 112 colors, **//** 16 for normal GameBoy, 16 for ColorGB, 80 for SuperGB. **//************************************ TO BE WRITTEN BY USER **/void SetColor(int N,int R,int G,int B);/** SGBBackdrop() ********************************************//** Show SuperGB backdrop. Called by SuperGB extension. **//************************************ TO BE WRITTEN BY USER **/void SGBBackdrop(void);/** Joystick() ***********************************************//** Get joystick state: START.SELECT.B.A.D.U.L.R for up to **//** four joysticks (lowest to highest bytes). **//************************************ TO BE WRITTEN BY USER **/unsigned int Joystick(void);/** Sound() **************************************************//** Set volume (0..255) and frequency (Hz) for a given **//** channel (0..3). **//************************************ TO BE WRITTEN BY USER **/void Sound(int Channel,int Freq,int Volume);/** SIOSend() ************************************************//** Send a word onto the serial line. Returns 1 on success, **//** 0 otherwise. **//************************************ TO BE WRITTEN BY USER **/int SIOSend(register int V);/** SIOReceive() *********************************************//** Receive a word from the serial line. Returns 1 on **//** success, 0 otherwise. **//************************************ TO BE WRITTEN BY USER **/int SIOReceive(register int *V);/** Print() **************************************************//** Print a 160xHeightx8 picture strip to a printer, making **//** margins as asked. Returns on success, 0 on failure. **//************************************ TO BE WRITTEN BY USER **/byte Print(register byte *Data,int UMargin,int Height,int LMargin);/** Rumble() *************************************************//** "Pull" or "release" the rumble pack vibrator, depending **//** on the argument value. **//************************************ TO BE WRITTEN BY USER **/void Rumble(register byte Pull);inline void GB_memset(byte *D, int value, int size);#endif/*VGB*/#endif /* GB_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -