all repos — mgba @ de065be15c1308aca3827a5c5953ede501c3b50a

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 mAVStream;
 45struct GB {
 46	struct mCPUComponent d;
 47
 48	struct LR35902Core* cpu;
 49	struct GBMemory memory;
 50	struct GBVideo video;
 51	struct GBTimer timer;
 52	struct GBAudio audio;
 53
 54	struct mCoreSync* sync;
 55
 56	uint8_t* keySource;
 57
 58	void* pristineRom;
 59	size_t pristineRomSize;
 60	size_t yankedRomSize;
 61	uint32_t romCrc32;
 62	struct VFile* romVf;
 63	struct VFile* sramVf;
 64
 65	struct mAVStream* stream;
 66
 67	int32_t eiPending;
 68};
 69
 70struct GBCartridge {
 71	uint8_t entry[4];
 72	uint8_t logo[48];
 73	union {
 74		char titleLong[16];
 75		struct {
 76			char titleShort[11];
 77			char maker[4];
 78			uint8_t cgb;
 79		};
 80	};
 81	char licensee[2];
 82	uint8_t sgb;
 83	uint8_t type;
 84	uint8_t romSize;
 85	uint8_t ramSize;
 86	uint8_t region;
 87	uint8_t oldLicensee;
 88	uint8_t version;
 89	uint8_t headerChecksum;
 90	uint16_t globalChecksum;
 91	// And ROM data...
 92};
 93
 94void GBCreate(struct GB* gb);
 95void GBDestroy(struct GB* gb);
 96
 97void GBReset(struct LR35902Core* cpu);
 98
 99void GBUpdateIRQs(struct GB* gb);
100void GBHalt(struct LR35902Core* cpu);
101void GBStop(struct LR35902Core* cpu);
102
103struct VFile;
104bool GBLoadROM(struct GB* gb, struct VFile* vf);
105bool GBLoadSave(struct GB* gb, struct VFile* vf);
106void GBYankROM(struct GB* gb);
107void GBUnloadROM(struct GB* gb);
108
109struct Patch;
110void GBApplyPatch(struct GB* gb, struct Patch* patch);
111
112bool GBIsROM(struct VFile* vf);
113void GBGetGameTitle(struct GB* gba, char* out);
114
115void GBFrameStarted(struct GB* gb);
116void GBFrameEnded(struct GB* gb);
117
118#endif