all repos — mgba @ fc0109282b81c5fac6a108b4636192d8efe2b345

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