all repos — mgba @ 498aa541fc660c8755cda99cf8889171b3bd5381

mGBA Game Boy Advance Emulator

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