all repos — mgba @ b5e706981fc1798163f9612441eae4df893b8192

mGBA Game Boy Advance Emulator

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