all repos — mgba @ 90d280026d282df09036c6b1ff2ed1c636912466

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