all repos — mgba @ 68859f9fd80fe362613c0cc74a6d1f42450b8668

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