all repos — mgba @ 92c6b90b03f8c04b53312bf2273d86a9783ee073

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
 13#include "lr35902/lr35902.h"
 14
 15#include "gb/audio.h"
 16#include "gb/memory.h"
 17#include "gb/timer.h"
 18#include "gb/video.h"
 19
 20extern const uint32_t DMG_LR35902_FREQUENCY;
 21extern const uint32_t CGB_LR35902_FREQUENCY;
 22extern const uint32_t SGB_LR35902_FREQUENCY;
 23
 24mLOG_DECLARE_CATEGORY(GB);
 25
 26// TODO: Prefix GBAIRQ
 27enum GBIRQ {
 28	GB_IRQ_VBLANK = 0x0,
 29	GB_IRQ_LCDSTAT = 0x1,
 30	GB_IRQ_TIMER = 0x2,
 31	GB_IRQ_SIO = 0x3,
 32	GB_IRQ_KEYPAD = 0x4,
 33};
 34
 35enum GBIRQVector {
 36	GB_VECTOR_VBLANK = 0x40,
 37	GB_VECTOR_LCDSTAT = 0x48,
 38	GB_VECTOR_TIMER = 0x50,
 39	GB_VECTOR_SIO = 0x58,
 40	GB_VECTOR_KEYPAD = 0x60,
 41};
 42
 43struct mCoreSync;
 44struct GB {
 45	struct LR35902Component d;
 46
 47	struct LR35902Core* cpu;
 48	struct GBMemory memory;
 49	struct GBVideo video;
 50	struct GBTimer timer;
 51	struct GBAudio audio;
 52
 53	struct mCoreSync* sync;
 54
 55	uint8_t* keySource;
 56
 57	void* pristineRom;
 58	size_t pristineRomSize;
 59	size_t yankedRomSize;
 60	uint32_t romCrc32;
 61	struct VFile* romVf;
 62	struct VFile* sramVf;
 63
 64	const char* activeFile;
 65
 66	bool diPending;
 67};
 68
 69struct GBCartridge {
 70	uint8_t entry[4];
 71	uint8_t logo[48];
 72	union {
 73		char titleLong[16];
 74		struct {
 75			char titleShort[11];
 76			char maker[4];
 77			uint8_t cgb;
 78		};
 79	};
 80	char licensee[2];
 81	uint8_t sgb;
 82	uint8_t type;
 83	uint8_t romSize;
 84	uint8_t ramSize;
 85	uint8_t region;
 86	uint8_t oldLicensee;
 87	uint8_t version;
 88	uint8_t headerChecksum;
 89	uint16_t globalChecksum;
 90	// And ROM data...
 91};
 92
 93void GBCreate(struct GB* gb);
 94void GBDestroy(struct GB* gb);
 95
 96void GBReset(struct LR35902Core* cpu);
 97
 98void GBUpdateIRQs(struct GB* gb);
 99void GBHalt(struct LR35902Core* cpu);
100void GBStop(struct LR35902Core* cpu);
101
102struct VFile;
103bool GBLoadROM(struct GB* gb, struct VFile* vf, struct VFile* sav, const char* fname);
104void GBYankROM(struct GB* gb);
105void GBUnloadROM(struct GB* gb);
106
107struct Patch;
108void GBApplyPatch(struct GB* gb, struct Patch* patch);
109
110bool GBIsROM(struct VFile* vf);
111
112void GBFrameStarted(struct GB* gb);
113void GBFrameEnded(struct GB* gb);
114
115#endif