all repos — mgba @ e019c54aad2e28e7035868bb9e0f14a1b9369e2c

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