all repos — mgba @ c662b59e9942bfffd69ed6754cc334de86f89e63

mGBA Game Boy Advance Emulator

src/gb/gb.h (view raw)

  1/* Copyright (c) 2013-2016 Jeffrey Pfau
  2 *
  3 * This Source Code Form is subject to the terms of the Mozilla Public
  4 * License, v. 2.0. If a copy of the MPL was not distributed with this
  5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  6#ifndef GB_H
  7#define GB_H
  8
  9#include "util/common.h"
 10
 11#include "core/log.h"
 12#include "core/timing.h"
 13
 14#include "lr35902/lr35902.h"
 15
 16#include "gb/audio.h"
 17#include "gb/interface.h"
 18#include "gb/memory.h"
 19#include "gb/sio.h"
 20#include "gb/timer.h"
 21#include "gb/video.h"
 22
 23extern const uint32_t DMG_LR35902_FREQUENCY;
 24extern const uint32_t CGB_LR35902_FREQUENCY;
 25extern const uint32_t SGB_LR35902_FREQUENCY;
 26
 27mLOG_DECLARE_CATEGORY(GB);
 28
 29// TODO: Prefix GBAIRQ
 30enum GBIRQ {
 31	GB_IRQ_VBLANK = 0x0,
 32	GB_IRQ_LCDSTAT = 0x1,
 33	GB_IRQ_TIMER = 0x2,
 34	GB_IRQ_SIO = 0x3,
 35	GB_IRQ_KEYPAD = 0x4,
 36};
 37
 38enum GBIRQVector {
 39	GB_VECTOR_VBLANK = 0x40,
 40	GB_VECTOR_LCDSTAT = 0x48,
 41	GB_VECTOR_TIMER = 0x50,
 42	GB_VECTOR_SIO = 0x58,
 43	GB_VECTOR_KEYPAD = 0x60,
 44};
 45
 46struct mCoreSync;
 47struct mAVStream;
 48struct mCoreCallbacks;
 49struct GB {
 50	struct mCPUComponent d;
 51
 52	struct LR35902Core* cpu;
 53	struct GBMemory memory;
 54	struct GBVideo video;
 55	struct GBTimer timer;
 56	struct GBAudio audio;
 57	struct GBSIO sio;
 58	enum GBModel model;
 59
 60	struct mCoreSync* sync;
 61	struct mTiming timing;
 62
 63	uint8_t* keySource;
 64
 65	void* pristineRom;
 66	size_t pristineRomSize;
 67	size_t yankedRomSize;
 68	uint32_t romCrc32;
 69	struct VFile* romVf;
 70	struct VFile* biosVf;
 71	struct VFile* sramVf;
 72	struct VFile* sramRealVf;
 73	uint32_t sramSize;
 74	int sramDirty;
 75	int32_t sramDirtAge;
 76	bool sramMaskWriteback;
 77
 78	struct mCoreCallbacks* coreCallbacks;
 79	struct mAVStream* stream;
 80
 81	bool cpuBlocked;
 82	bool earlyExit;
 83	struct mTimingEvent eiPending;
 84	unsigned doubleSpeed;
 85};
 86
 87struct GBCartridge {
 88	uint8_t entry[4];
 89	uint8_t logo[48];
 90	union {
 91		char titleLong[16];
 92		struct {
 93			char titleShort[11];
 94			char maker[4];
 95			uint8_t cgb;
 96		};
 97	};
 98	char licensee[2];
 99	uint8_t sgb;
100	uint8_t type;
101	uint8_t romSize;
102	uint8_t ramSize;
103	uint8_t region;
104	uint8_t oldLicensee;
105	uint8_t version;
106	uint8_t headerChecksum;
107	uint16_t globalChecksum;
108	// And ROM data...
109};
110
111void GBCreate(struct GB* gb);
112void GBDestroy(struct GB* gb);
113
114void GBReset(struct LR35902Core* cpu);
115void GBDetectModel(struct GB* gb);
116
117void GBUpdateIRQs(struct GB* gb);
118void GBHalt(struct LR35902Core* cpu);
119
120struct VFile;
121bool GBLoadROM(struct GB* gb, struct VFile* vf);
122bool GBLoadSave(struct GB* gb, struct VFile* vf);
123void GBYankROM(struct GB* gb);
124void GBUnloadROM(struct GB* gb);
125void GBSynthesizeROM(struct VFile* vf);
126
127bool GBIsBIOS(struct VFile* vf);
128void GBLoadBIOS(struct GB* gb, struct VFile* vf);
129
130void GBSramClean(struct GB* gb, uint32_t frameCount);
131void GBResizeSram(struct GB* gb, size_t size);
132void GBSavedataMask(struct GB* gb, struct VFile* vf, bool writeback);
133void GBSavedataUnmask(struct GB* gb);
134
135struct Patch;
136void GBApplyPatch(struct GB* gb, struct Patch* patch);
137
138bool GBIsROM(struct VFile* vf);
139void GBGetGameTitle(const struct GB* gba, char* out);
140void GBGetGameCode(const struct GB* gba, char* out);
141
142void GBFrameEnded(struct GB* gb);
143
144#endif