all repos — mgba @ bc90283998f2eed665ae9db09f412622137caf03

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	CHEAT_IF_BUTTON,
 35};
 36
 37struct mCheat {
 38	enum mCheatType type;
 39	int width;
 40	uint32_t address;
 41	uint32_t operand;
 42	uint32_t repeat;
 43	uint32_t negativeRepeat;
 44
 45	int32_t addressOffset;
 46	int32_t operandOffset;
 47};
 48
 49mLOG_DECLARE_CATEGORY(CHEATS);
 50
 51DECLARE_VECTOR(mCheatList, struct mCheat);
 52
 53struct mCheatDevice;
 54struct mCheatSet {
 55	struct mCheatList list;
 56
 57	void (*deinit)(struct mCheatSet* set);
 58	void (*add)(struct mCheatSet* set, struct mCheatDevice* device);
 59	void (*remove)(struct mCheatSet* set, struct mCheatDevice* device);
 60
 61	bool (*addLine)(struct mCheatSet* set, const char* cheat, int type);
 62	void (*copyProperties)(struct mCheatSet* set, struct mCheatSet* oldSet);
 63
 64	void (*parseDirectives)(struct mCheatSet* set, const struct StringList* directives);
 65	void (*dumpDirectives)(struct mCheatSet* set, struct StringList* directives);
 66
 67	void (*refresh)(struct mCheatSet* set, struct mCheatDevice* device);
 68
 69	char* name;
 70	bool enabled;
 71	struct StringList lines;
 72};
 73
 74DECLARE_VECTOR(mCheatSets, struct mCheatSet*);
 75
 76struct mCheatDevice {
 77	struct mCPUComponent d;
 78	struct mCore* p;
 79
 80	struct mCheatSet* (*createSet)(struct mCheatDevice*, const char* name);
 81
 82	struct mCheatSets cheats;
 83	bool autosave;
 84	bool buttonDown;
 85};
 86
 87struct VFile;
 88
 89void mCheatDeviceCreate(struct mCheatDevice*);
 90void mCheatDeviceDestroy(struct mCheatDevice*);
 91void mCheatDeviceClear(struct mCheatDevice*);
 92
 93void mCheatSetInit(struct mCheatSet*, const char* name);
 94void mCheatSetDeinit(struct mCheatSet*);
 95void mCheatSetRename(struct mCheatSet*, const char* name);
 96
 97bool mCheatAddLine(struct mCheatSet*, const char* line, int type);
 98
 99void mCheatAddSet(struct mCheatDevice*, struct mCheatSet*);
100void mCheatRemoveSet(struct mCheatDevice*, struct mCheatSet*);
101
102bool mCheatParseFile(struct mCheatDevice*, struct VFile*);
103bool mCheatSaveFile(struct mCheatDevice*, struct VFile*);
104void mCheatAutosave(struct mCheatDevice*);
105
106void mCheatRefresh(struct mCheatDevice*, struct mCheatSet*);
107void mCheatPressButton(struct mCheatDevice*, bool down);
108
109CXX_GUARD_END
110
111#endif