all repos — mgba @ 764acb7d6385fc9bf078f14effd9fc198943bb49

mGBA Game Boy Advance Emulator

include/mgba/core/cheats.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 CHEATS_H
  7#define CHEATS_H
  8
  9#include <mgba-util/common.h>
 10
 11CXX_GUARD_START
 12
 13#include <mgba/core/cpu.h>
 14#include <mgba/core/log.h>
 15#include <mgba-util/vector.h>
 16
 17#define MAX_ROM_PATCHES 4
 18
 19enum mCheatType {
 20	CHEAT_ASSIGN,
 21	CHEAT_ASSIGN_INDIRECT,
 22	CHEAT_AND,
 23	CHEAT_ADD,
 24	CHEAT_OR,
 25	CHEAT_IF_EQ,
 26	CHEAT_IF_NE,
 27	CHEAT_IF_LT,
 28	CHEAT_IF_GT,
 29	CHEAT_IF_ULT,
 30	CHEAT_IF_UGT,
 31	CHEAT_IF_AND,
 32	CHEAT_IF_LAND,
 33	CHEAT_IF_NAND
 34};
 35
 36struct mCheat {
 37	enum mCheatType type;
 38	int width;
 39	uint32_t address;
 40	uint32_t operand;
 41	uint32_t repeat;
 42	uint32_t negativeRepeat;
 43
 44	int32_t addressOffset;
 45	int32_t operandOffset;
 46};
 47
 48mLOG_DECLARE_CATEGORY(CHEATS);
 49
 50DECLARE_VECTOR(mCheatList, struct mCheat);
 51
 52struct mCheatDevice;
 53struct mCheatSet {
 54	struct mCheatList list;
 55
 56	void (*deinit)(struct mCheatSet* set);
 57	void (*add)(struct mCheatSet* set, struct mCheatDevice* device);
 58	void (*remove)(struct mCheatSet* set, struct mCheatDevice* device);
 59
 60	bool (*addLine)(struct mCheatSet* set, const char* cheat, int type);
 61	void (*copyProperties)(struct mCheatSet* set, struct mCheatSet* oldSet);
 62
 63	void (*parseDirectives)(struct mCheatSet* set, const struct StringList* directives);
 64	void (*dumpDirectives)(struct mCheatSet* set, struct StringList* directives);
 65
 66	void (*refresh)(struct mCheatSet* set, struct mCheatDevice* device);
 67
 68	char* name;
 69	bool enabled;
 70	struct StringList lines;
 71};
 72
 73DECLARE_VECTOR(mCheatSets, struct mCheatSet*);
 74
 75struct mCheatDevice {
 76	struct mCPUComponent d;
 77	struct mCore* p;
 78
 79	struct mCheatSet* (*createSet)(struct mCheatDevice*, const char* name);
 80
 81	struct mCheatSets cheats;
 82	bool autosave;
 83};
 84
 85struct VFile;
 86
 87void mCheatDeviceCreate(struct mCheatDevice*);
 88void mCheatDeviceDestroy(struct mCheatDevice*);
 89void mCheatDeviceClear(struct mCheatDevice*);
 90
 91void mCheatSetInit(struct mCheatSet*, const char* name);
 92void mCheatSetDeinit(struct mCheatSet*);
 93void mCheatSetRename(struct mCheatSet*, const char* name);
 94
 95bool mCheatAddLine(struct mCheatSet*, const char* line, int type);
 96
 97void mCheatAddSet(struct mCheatDevice*, struct mCheatSet*);
 98void mCheatRemoveSet(struct mCheatDevice*, struct mCheatSet*);
 99
100bool mCheatParseFile(struct mCheatDevice*, struct VFile*);
101bool mCheatSaveFile(struct mCheatDevice*, struct VFile*);
102void mCheatAutosave(struct mCheatDevice*);
103
104void mCheatRefresh(struct mCheatDevice*, struct mCheatSet*);
105
106CXX_GUARD_END
107
108#endif