summaryrefslogtreecommitdiff
path: root/src/cheats2.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cheats2.c')
-rw-r--r--src/cheats2.c294
1 files changed, 147 insertions, 147 deletions
diff --git a/src/cheats2.c b/src/cheats2.c
index 3e8017e..7db113b 100644
--- a/src/cheats2.c
+++ b/src/cheats2.c
@@ -4,7 +4,7 @@
* (c) Copyright 1996 - 2001 Gary Henderson (gary.henderson@ntlworld.com) and
* Jerremy Koot (jkoot@snes9x.com)
*
- * Super FX C emulator code
+ * Super FX C emulator code
* (c) Copyright 1997 - 1999 Ivar (ivar@snes9x.com) and
* Gary Henderson.
* Super FX assembler emulator code (c) Copyright 1998 zsKnight and _Demo_.
@@ -47,186 +47,186 @@
extern SCheatData Cheat;
-void S9xInitCheatData ()
+void S9xInitCheatData()
{
- Cheat.RAM = Memory.RAM;
- Cheat.SRAM = SRAM;
- Cheat.FillRAM = Memory.FillRAM;
+ Cheat.RAM = Memory.RAM;
+ Cheat.SRAM = SRAM;
+ Cheat.FillRAM = Memory.FillRAM;
}
-void S9xAddCheat (bool8 enable, bool8 save_current_value,
- uint32 address, uint8 byte)
+void S9xAddCheat(bool8 enable, bool8 save_current_value,
+ uint32 address, uint8 byte)
{
- if (Cheat.num_cheats < sizeof (Cheat.c) / sizeof (Cheat. c [0]))
- {
- Cheat.c [Cheat.num_cheats].address = address;
- Cheat.c [Cheat.num_cheats].byte = byte;
- Cheat.c [Cheat.num_cheats].enabled = TRUE;
- if (save_current_value)
- {
- Cheat.c [Cheat.num_cheats].saved_byte = S9xGetByte (address);
- Cheat.c [Cheat.num_cheats].saved = TRUE;
- }
- Cheat.num_cheats++;
- }
+ if (Cheat.num_cheats < sizeof(Cheat.c) / sizeof(Cheat. c [0]))
+ {
+ Cheat.c [Cheat.num_cheats].address = address;
+ Cheat.c [Cheat.num_cheats].byte = byte;
+ Cheat.c [Cheat.num_cheats].enabled = TRUE;
+ if (save_current_value)
+ {
+ Cheat.c [Cheat.num_cheats].saved_byte = S9xGetByte(address);
+ Cheat.c [Cheat.num_cheats].saved = TRUE;
+ }
+ Cheat.num_cheats++;
+ }
}
-void S9xDeleteCheat (uint32 which1)
+void S9xDeleteCheat(uint32 which1)
{
- if (which1 < Cheat.num_cheats)
- {
- if (Cheat.c [which1].enabled)
- S9xRemoveCheat (which1);
-
- memmove (&Cheat.c [which1], &Cheat.c [which1 + 1],
- sizeof (Cheat.c [0]) * (Cheat.num_cheats - which1 - 1));
- Cheat.num_cheats = 0;
- }
+ if (which1 < Cheat.num_cheats)
+ {
+ if (Cheat.c [which1].enabled)
+ S9xRemoveCheat(which1);
+
+ memmove(&Cheat.c [which1], &Cheat.c [which1 + 1],
+ sizeof(Cheat.c [0]) * (Cheat.num_cheats - which1 - 1));
+ Cheat.num_cheats = 0;
+ }
}
-void S9xDeleteCheats ()
+void S9xDeleteCheats()
{
- S9xRemoveCheats ();
- Cheat.num_cheats = 0;
+ S9xRemoveCheats();
+ Cheat.num_cheats = 0;
}
-void S9xEnableCheat (uint32 which1)
+void S9xEnableCheat(uint32 which1)
{
- if (which1 < Cheat.num_cheats && !Cheat.c [which1].enabled)
- {
- Cheat.c [which1].enabled = TRUE;
- S9xApplyCheat (which1);
- }
+ if (which1 < Cheat.num_cheats && !Cheat.c [which1].enabled)
+ {
+ Cheat.c [which1].enabled = TRUE;
+ S9xApplyCheat(which1);
+ }
}
-void S9xDisableCheat (uint32 which1)
+void S9xDisableCheat(uint32 which1)
{
- if (which1 < Cheat.num_cheats && Cheat.c [which1].enabled)
- {
- S9xRemoveCheat (which1);
- Cheat.c [which1].enabled = FALSE;
- }
+ if (which1 < Cheat.num_cheats && Cheat.c [which1].enabled)
+ {
+ S9xRemoveCheat(which1);
+ Cheat.c [which1].enabled = FALSE;
+ }
}
-void S9xRemoveCheat (uint32 which1)
+void S9xRemoveCheat(uint32 which1)
{
- if (Cheat.c [which1].saved)
- {
- uint32 address = Cheat.c [which1].address;
-
- int block = (address >> MEMMAP_SHIFT) & MEMMAP_MASK;
- uint8 *ptr = Memory.Map [block];
-
- if (ptr >= (uint8 *) MAP_LAST)
- *(ptr + (address & 0xffff)) = Cheat.c [which1].saved_byte;
- else
- S9xSetByte (address, Cheat.c [which1].saved_byte);
- }
+ if (Cheat.c [which1].saved)
+ {
+ uint32 address = Cheat.c [which1].address;
+
+ int block = (address >> MEMMAP_SHIFT) & MEMMAP_MASK;
+ uint8* ptr = Memory.Map [block];
+
+ if (ptr >= (uint8*) MAP_LAST)
+ *(ptr + (address & 0xffff)) = Cheat.c [which1].saved_byte;
+ else
+ S9xSetByte(address, Cheat.c [which1].saved_byte);
+ }
}
-void S9xApplyCheat (uint32 which1)
+void S9xApplyCheat(uint32 which1)
{
- uint32 address = Cheat.c [which1].address;
-
- if (!Cheat.c [which1].saved)
- Cheat.c [which1].saved_byte = S9xGetByte (address);
-
- int block = (address >> MEMMAP_SHIFT) & MEMMAP_MASK;
- uint8 *ptr = Memory.Map [block];
-
- if (ptr >= (uint8 *) MAP_LAST)
- *(ptr + (address & 0xffff)) = Cheat.c [which1].byte;
- else
- S9xSetByte (address, Cheat.c [which1].byte);
- Cheat.c [which1].saved = TRUE;
+ uint32 address = Cheat.c [which1].address;
+
+ if (!Cheat.c [which1].saved)
+ Cheat.c [which1].saved_byte = S9xGetByte(address);
+
+ int block = (address >> MEMMAP_SHIFT) & MEMMAP_MASK;
+ uint8* ptr = Memory.Map [block];
+
+ if (ptr >= (uint8*) MAP_LAST)
+ *(ptr + (address & 0xffff)) = Cheat.c [which1].byte;
+ else
+ S9xSetByte(address, Cheat.c [which1].byte);
+ Cheat.c [which1].saved = TRUE;
}
-void S9xApplyCheats ()
+void S9xApplyCheats()
{
- if (Settings.ApplyCheats)
- {
- uint32 i;
- for (i = 0; i < Cheat.num_cheats; i++)
- if (Cheat.c [i].enabled)
- S9xApplyCheat (i);
- }
+ if (Settings.ApplyCheats)
+ {
+ uint32 i;
+ for (i = 0; i < Cheat.num_cheats; i++)
+ if (Cheat.c [i].enabled)
+ S9xApplyCheat(i);
+ }
}
-void S9xRemoveCheats ()
+void S9xRemoveCheats()
{
uint32 i;
- for (i = 0; i < Cheat.num_cheats; i++)
- if (Cheat.c [i].enabled)
- S9xRemoveCheat (i);
+ for (i = 0; i < Cheat.num_cheats; i++)
+ if (Cheat.c [i].enabled)
+ S9xRemoveCheat(i);
}
-bool8 S9xLoadCheatFile (const char *filename)
+bool8 S9xLoadCheatFile(const char* filename)
{
- Cheat.num_cheats = 0;
-
- FILE *fs = fopen (filename, "rb");
- uint8 data [28];
-
- if (!fs)
- return (FALSE);
-
- while (fread ((void *) data, 1, 28, fs) == 28)
- {
- Cheat.c [Cheat.num_cheats].enabled = (data [0] & 4) == 0;
- Cheat.c [Cheat.num_cheats].byte = data [1];
- Cheat.c [Cheat.num_cheats].address = data [2] | (data [3] << 8) | (data [4] << 16);
- Cheat.c [Cheat.num_cheats].saved_byte = data [5];
- Cheat.c [Cheat.num_cheats].saved = (data [0] & 8) != 0;
- memmove (Cheat.c [Cheat.num_cheats].name, &data [8], 20);
- Cheat.c [Cheat.num_cheats++].name [20] = 0;
- }
- fclose (fs);
-
- return (TRUE);
+ Cheat.num_cheats = 0;
+
+ FILE* fs = fopen(filename, "rb");
+ uint8 data [28];
+
+ if (!fs)
+ return (FALSE);
+
+ while (fread((void*) data, 1, 28, fs) == 28)
+ {
+ Cheat.c [Cheat.num_cheats].enabled = (data [0] & 4) == 0;
+ Cheat.c [Cheat.num_cheats].byte = data [1];
+ Cheat.c [Cheat.num_cheats].address = data [2] | (data [3] << 8) | (data [4] << 16);
+ Cheat.c [Cheat.num_cheats].saved_byte = data [5];
+ Cheat.c [Cheat.num_cheats].saved = (data [0] & 8) != 0;
+ memmove(Cheat.c [Cheat.num_cheats].name, &data [8], 20);
+ Cheat.c [Cheat.num_cheats++].name [20] = 0;
+ }
+ fclose(fs);
+
+ return (TRUE);
}
-bool8 S9xSaveCheatFile (const char *filename)
+bool8 S9xSaveCheatFile(const char* filename)
{
- if (Cheat.num_cheats == 0)
- {
- (void) remove (filename);
- return (TRUE);
- }
-
- FILE *fs = fopen (filename, "wb");
- uint8 data [28];
-
- if (!fs)
- return (FALSE);
-
- uint32 i;
- for (i = 0; i < Cheat.num_cheats; i++)
- {
- memset (data, 0, 28);
- if (i == 0)
- {
- data [6] = 254;
- data [7] = 252;
- }
- if (!Cheat.c [i].enabled)
- data [0] |= 4;
-
- if (Cheat.c [i].saved)
- data [0] |= 8;
-
- data [1] = Cheat.c [i].byte;
- data [2] = (uint8) Cheat.c [i].address;
- data [3] = (uint8) (Cheat.c [i].address >> 8);
- data [4] = (uint8) (Cheat.c [i].address >> 16);
- data [5] = Cheat.c [i].saved_byte;
-
- memmove (&data [8], Cheat.c [i].name, 19);
- if (fwrite (data, 28, 1, fs) != 1)
- {
- fclose (fs);
- return (FALSE);
- }
- }
- return (fclose (fs) == 0);
+ if (Cheat.num_cheats == 0)
+ {
+ (void) remove(filename);
+ return (TRUE);
+ }
+
+ FILE* fs = fopen(filename, "wb");
+ uint8 data [28];
+
+ if (!fs)
+ return (FALSE);
+
+ uint32 i;
+ for (i = 0; i < Cheat.num_cheats; i++)
+ {
+ memset(data, 0, 28);
+ if (i == 0)
+ {
+ data [6] = 254;
+ data [7] = 252;
+ }
+ if (!Cheat.c [i].enabled)
+ data [0] |= 4;
+
+ if (Cheat.c [i].saved)
+ data [0] |= 8;
+
+ data [1] = Cheat.c [i].byte;
+ data [2] = (uint8) Cheat.c [i].address;
+ data [3] = (uint8)(Cheat.c [i].address >> 8);
+ data [4] = (uint8)(Cheat.c [i].address >> 16);
+ data [5] = Cheat.c [i].saved_byte;
+
+ memmove(&data [8], Cheat.c [i].name, 19);
+ if (fwrite(data, 28, 1, fs) != 1)
+ {
+ fclose(fs);
+ return (FALSE);
+ }
+ }
+ return (fclose(fs) == 0);
}