all repos — mgba @ 84844232ecc9175dc90e2ab2ccff380c6edd502d

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	int32_t eiPending;
 82	unsigned doubleSpeed;
 83};
 84
 85struct GBCartridge {
 86	uint8_t entry[4];
 87	uint8_t logo[48];
 88	union {
 89		char titleLong[16];
 90		struct {
 91			char titleShort[11];
 92			char maker[4];
 93			uint8_t cgb;
 94		};
 95	};
 96	char licensee[2];
 97	uint8_t sgb;
 98	uint8_t type;
 99	uint8_t romSize;
100	uint8_t ramSize;
101	uint8_t region;
102	uint8_t oldLicensee;
103	uint8_t version;
104	uint8_t headerChecksum;
105	uint16_t globalChecksum;
106	// And ROM data...
107};
108
109void GBCreate(struct GB* gb);
110void GBDestroy(struct GB* gb);
111
112void GBReset(struct LR35902Core* cpu);
113void GBDetectModel(struct GB* gb);
114
115void GBUpdateIRQs(struct GB* gb);
116void GBHalt(struct LR35902Core* cpu);
117
118struct VFile;
119bool GBLoadROM(struct GB* gb, struct VFile* vf);
120bool GBLoadSave(struct GB* gb, struct VFile* vf);
121void GBYankROM(struct GB* gb);
122void GBUnloadROM(struct GB* gb);
123void GBSynthesizeROM(struct VFile* vf);
124
125bool GBIsBIOS(struct VFile* vf);
126void GBLoadBIOS(struct GB* gb, struct VFile* vf);
127
128void GBSramClean(struct GB* gb, uint32_t frameCount);
129void GBResizeSram(struct GB* gb, size_t size);
130void GBSavedataMask(struct GB* gb, struct VFile* vf, bool writeback);
131void GBSavedataUnmask(struct GB* gb);
132
133struct Patch;
134void GBApplyPatch(struct GB* gb, struct Patch* patch);
135
136bool GBIsROM(struct VFile* vf);
137void GBGetGameTitle(const struct GB* gba, char* out);
138void GBGetGameCode(const struct GB* gba, char* out);
139
140void GBFrameEnded(struct GB* gb);
141
142#endif