all repos — mgba @ 86571c8496d3b9d1257aa449e5eebcee7137c297

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