all repos — mgba @ d7d8dacaa86c8d39cd63fc728f7dd13f9fe5e4aa

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