Some proper cleanup in ActionReplay and corrected some changes that didn't make sense.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@3201 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
omegadox 2009-05-11 18:15:29 +00:00
parent b8fe20e84e
commit 90e345e40b
2 changed files with 116 additions and 147 deletions

View File

@ -47,13 +47,32 @@ namespace ActionReplay
{ {
enum enum
{ {
EQUAL = 0, // Zero Code Types
NOT_EQUAL, ZCODE_END = 0x00,
LESS_THAN_SIGNED, ZCODE_NORM = 0x02,
GREATER_THAN_SIGNED, ZCODE_ROW = 0x03,
LESS_THAN_UNSIGNED, ZCODE_MEM_COPY = 0x04,
GREATER_THAN_UNSIGNED,
LOGICAL_AND // Conditonal Codes
CONDTIONAL_IF_EQUAL = 0x01,
CONDTIONAL_IF_NOT_EQUAL = 0x02,
CONDTIONAL_IF_LESS_THAN_SIGNED = 0x03,
CONDTIONAL_IF_GREATER_THAN_SIGNED = 0x04,
CONDTIONAL_IF_LESS_THAN_UNSIGNED = 0x05,
CONDTIONAL_IF_GREATER_THAN_UNSIGNED = 0x06,
CONDTIONAL_IF_AND = 0x07,
// Data Types
DATATYPE_8BIT = 0x00,
DATATYPE_16BIT = 0x01,
DATATYPE_32BIT = 0x02,
DATATYPE_32BIT_FLOAT = 0x03,
// Normal Code 0 Subtypes
SUB_RAM_WRITE = 0x00,
SUB_WRITE_POINTER = 0x01,
SUB_ADD_CODE = 0x02,
SUB_MASTER_CODE = 0x03,
}; };
static std::vector<AREntry>::const_iterator iter; static std::vector<AREntry>::const_iterator iter;
@ -308,20 +327,21 @@ bool RunCode(const ARCode &arcode) {
LogInfo("Doing Zero Code %08x", zcode); LogInfo("Doing Zero Code %08x", zcode);
switch (zcode) switch (zcode)
{ {
case AR_ZCODE_END: // END OF CODES case ZCODE_END: // END OF CODES
LogInfo("ZCode: End Of Codes"); LogInfo("ZCode: End Of Codes");
return true; return true;
case AR_ZCODE_NORM: // Normal execution of codes case ZCODE_NORM: // Normal execution of codes
// Todo: Set register 1BB4 to 0 // Todo: Set register 1BB4 to 0
LogInfo("ZCode: Normal execution of codes, set register 1BB4 to 0 (zcode not supported)"); LogInfo("ZCode: Normal execution of codes, set register 1BB4 to 0 (zcode not supported)");
break; break;
case AR_ZCODE_ROW: // Executes all codes in the same row case ZCODE_ROW: // Executes all codes in the same row
// Todo: Set register 1BB4 to 1 // Todo: Set register 1BB4 to 1
LogInfo("ZCode: Executes all codes in the same row, Set register 1BB4 to 1 (zcode not supported)"); LogInfo("ZCode: Executes all codes in the same row, Set register 1BB4 to 1 (zcode not supported)");
PanicAlert("Zero 3 code not supported"); PanicAlert("Zero 3 code not supported");
return false; return false;
case AR_ZCODE_MEM_COPY: // Fill & Slide or Memory Copy case ZCODE_MEM_COPY: // Fill & Slide or Memory Copy
if (((addr >> 25) & 0x03) == 0x3) { if (((addr >> 25) & 0x03) == 0x3)
{
LogInfo("ZCode: Memory Copy"); LogInfo("ZCode: Memory Copy");
doMemoryCopy = true; doMemoryCopy = true;
addr_last = addr; addr_last = addr;
@ -346,54 +366,22 @@ bool RunCode(const ARCode &arcode) {
u8 subtype = ((addr >> 30) & 0x03); u8 subtype = ((addr >> 30) & 0x03);
LogInfo("Doing Normal Code %08x", type); LogInfo("Doing Normal Code %08x", type);
LogInfo("Subtype: %08x", subtype); LogInfo("Subtype: %08x", subtype);
if (type >= 1 && type <= 7) { if (type == 0x00)
cond = true;
LogInfo("This Normal Code is a Conditional Code");
}
switch (type)
{ {
case 0x0:
if (!NormalCode(subtype, addr, data)) if (!NormalCode(subtype, addr, data))
return false; return false;
continue; }
case AR_CODE_IF_EQUAL: else if (type >= 1 && type <= 7)
LogInfo("Type 1: If Equal"); {
if (!ConditionalCode(subtype, addr, data, &count, &skip, EQUAL)) cond = true;
LogInfo("This Normal Code is a Conditional Code");
if (!ConditionalCode(subtype, addr, data, &count, &skip, type))
return false; return false;
continue; }
case AR_CODE_IF_NOT_EQUAL: else
LogInfo("Type 2: If Not Equal"); {
if (!ConditionalCode(subtype, addr, data, &count, &skip, NOT_EQUAL))
return false;
continue;
case AR_CODE_IF_LESS_THAN_SIGNED:
LogInfo("Type 3: If Less Than (Signed)");
if (!ConditionalCode(subtype, addr, data, &count, &skip, LESS_THAN_SIGNED))
return false;
continue;
case AR_CODE_IF_GREATER_THAN_SIGNED:
LogInfo("Type 4: If Greater Than (Signed)");
if (!ConditionalCode(subtype, addr, data, &count, &skip, GREATER_THAN_SIGNED))
return false;
continue;
case AR_CODE_IF_LESS_THAN_UNSIGNED:
LogInfo("Type 5: If Less Than (Unsigned)");
if (!ConditionalCode(subtype, addr, data, &count, &skip, LESS_THAN_UNSIGNED))
return false;
continue;
case AR_CODE_IF_GREATER_THAN_UNSIGNED:
LogInfo("Type 6: If Greater Than (Unsigned)");
if (!ConditionalCode(subtype, addr, data, &count, &skip, GREATER_THAN_UNSIGNED))
return false;
continue;
case AR_CODE_IF_AND:
LogInfo("Type 7: If AND");
if (!ConditionalCode(subtype, addr, data, &count, &skip, LOGICAL_AND))
return false;
continue;
default:
LogInfo("Bad Normal Code type"); LogInfo("Bad Normal Code type");
PanicAlert("Action Replay: Invalid Normal Code Type %08x (%s)", type, code.name.c_str()); return false;
} }
} }
@ -464,9 +452,9 @@ bool Subtype_RamWriteAndFill(u32 addr, u32 data)
LogInfo("Size: %08x", size); LogInfo("Size: %08x", size);
switch (size) switch (size)
{ {
case AR_BYTE_WRITE: // Byte write case DATATYPE_8BIT:
{ {
LogInfo("Byte Write"); LogInfo("8-bit Write");
LogInfo("--------"); LogInfo("--------");
u8 repeat = data >> 8; u8 repeat = data >> 8;
for (int i = 0; i <= repeat; i++) { for (int i = 0; i <= repeat; i++) {
@ -477,9 +465,9 @@ bool Subtype_RamWriteAndFill(u32 addr, u32 data)
break; break;
} }
case AR_SHORT_WRITE: // Short write case DATATYPE_16BIT:
{ {
LogInfo("Short Write"); LogInfo("16-bit Write");
LogInfo("--------"); LogInfo("--------");
u16 repeat = data >> 16; u16 repeat = data >> 16;
for (int i = 0; i <= repeat; i++) { for (int i = 0; i <= repeat; i++) {
@ -489,10 +477,10 @@ bool Subtype_RamWriteAndFill(u32 addr, u32 data)
LogInfo("--------"); LogInfo("--------");
break; break;
} }
case 0x03: //some codes use 03, but its just the same as 02... case DATATYPE_32BIT_FLOAT: //some codes use 03, but its just the same as 02...
LogInfo("The odd size 3 code (we just decided to write a U32 for this)"); LogInfo("The odd size 3 code, could this really by floating point?");
case AR_DWORD_WRITE: // Dword write case DATATYPE_32BIT: // Dword write
LogInfo("Dword Write"); LogInfo("32bit Write");
LogInfo("--------"); LogInfo("--------");
Memory::Write_U32(data, new_addr); Memory::Write_U32(data, new_addr);
LogInfo("Wrote %08x to address %08x", data, new_addr); LogInfo("Wrote %08x to address %08x", data, new_addr);
@ -514,9 +502,9 @@ bool Subtype_WriteToPointer(u32 addr, u32 data)
LogInfo("Size: %08x", size); LogInfo("Size: %08x", size);
switch (size) switch (size)
{ {
case AR_BYTE_WRITE_POINTER: // Byte write to pointer [40] case DATATYPE_8BIT:
{ {
LogInfo("Write byte to pointer"); LogInfo("Write 8-bit to pointer");
LogInfo("--------"); LogInfo("--------");
u32 ptr = Memory::Read_U32(new_addr); u32 ptr = Memory::Read_U32(new_addr);
u8 thebyte = data & 0xFF; u8 thebyte = data & 0xFF;
@ -530,9 +518,9 @@ bool Subtype_WriteToPointer(u32 addr, u32 data)
break; break;
} }
case AR_SHORT_WRITE_POINTER: // Short write to pointer [42] case DATATYPE_16BIT:
{ {
LogInfo("Write short to pointer"); LogInfo("Write 16-bit to pointer");
LogInfo("--------"); LogInfo("--------");
u32 ptr = Memory::Read_U32(new_addr); u32 ptr = Memory::Read_U32(new_addr);
u16 theshort = data & 0xFFFF; u16 theshort = data & 0xFFFF;
@ -545,9 +533,9 @@ bool Subtype_WriteToPointer(u32 addr, u32 data)
LogInfo("--------"); LogInfo("--------");
break; break;
} }
case 0x03: case DATATYPE_32BIT_FLOAT:
case AR_DWORD_WRITE_POINTER: // Dword write to pointer [44] case DATATYPE_32BIT:
LogInfo("Write dword to pointer"); LogInfo("Write 32-bit to pointer");
LogInfo("--------"); LogInfo("--------");
Memory::Write_U32(data, Memory::Read_U32(new_addr)); Memory::Write_U32(data, Memory::Read_U32(new_addr));
LogInfo("Wrote %08x to address %08x", data, Memory::Read_U32(new_addr)); LogInfo("Wrote %08x to address %08x", data, Memory::Read_U32(new_addr));
@ -564,40 +552,44 @@ bool Subtype_WriteToPointer(u32 addr, u32 data)
bool Subtype_AddCode(u32 addr, u32 data) bool Subtype_AddCode(u32 addr, u32 data)
{ {
// Used to incrment a value in memory
u32 new_addr = (addr & 0x81FFFFFF); u32 new_addr = (addr & 0x81FFFFFF);
u8 size = ((addr >> 25) & 0x03); u8 size = ((addr >> 25) & 0x03);
LogInfo("Hardware Address: %08x", new_addr); LogInfo("Hardware Address: %08x", new_addr);
LogInfo("Size: %08x", size); LogInfo("Size: %08x", size);
switch (size) switch (size)
{ {
case AR_BYTE_ADD: // Byte add case DATATYPE_8BIT:
LogInfo("Byte Add"); LogInfo("8-bit Add");
LogInfo("--------"); LogInfo("--------");
Memory::Write_U8(Memory::Read_U8(new_addr) + (data & 0xFF), new_addr); Memory::Write_U8(Memory::Read_U8(new_addr) + (data & 0xFF), new_addr);
LogInfo("Wrote %08x to address %08x", Memory::Read_U8(new_addr) + (data & 0xFF), new_addr); LogInfo("Wrote %08x to address %08x", Memory::Read_U8(new_addr) + (data & 0xFF), new_addr);
LogInfo("--------"); LogInfo("--------");
break; break;
case AR_SHORT_ADD: // Short add case DATATYPE_16BIT:
LogInfo("Short Add"); LogInfo("16-bit Add");
LogInfo("--------"); LogInfo("--------");
Memory::Write_U16(Memory::Read_U16(new_addr) + (data & 0xFFFF), new_addr); Memory::Write_U16(Memory::Read_U16(new_addr) + (data & 0xFFFF), new_addr);
LogInfo("Wrote %08x to address %08x", Memory::Read_U16(new_addr) + (data & 0xFFFF), new_addr); LogInfo("Wrote %08x to address %08x", Memory::Read_U16(new_addr) + (data & 0xFFFF), new_addr);
LogInfo("--------"); LogInfo("--------");
break; break;
case AR_DWORD_ADD: // DWord add case DATATYPE_32BIT:
LogInfo("Dword Add"); LogInfo("32-bit Add");
LogInfo("--------"); LogInfo("--------");
Memory::Write_U32(Memory::Read_U32(new_addr) + data, new_addr); Memory::Write_U32(Memory::Read_U32(new_addr) + data, new_addr);
LogInfo("Wrote %08x to address %08x", Memory::Read_U32(new_addr) + data, new_addr); LogInfo("Wrote %08x to address %08x", Memory::Read_U32(new_addr) + data, new_addr);
LogInfo("--------"); LogInfo("--------");
break; break;
case AR_FLOAT_ADD: // Float add (not working?) case DATATYPE_32BIT_FLOAT:
{ {
LogInfo("Float Add"); LogInfo("32-bit floating Add");
LogInfo("--------"); LogInfo("--------");
float newval = (float)Memory::Read_U32(new_addr) + (float)data; union conv {float x; u32 y;};
Memory::Write_U32((u32)newval, new_addr); conv c1;
LogInfo("Wrote %08x to address %08x", (u32)newval, new_addr); c1.y = Memory::Read_U32(new_addr);
c1.x += (float)data;
Memory::Write_U32((u32)c1.x, new_addr);
LogInfo("Wrote %08x to address %08x", (u32)c1.x, new_addr);
LogInfo("--------"); LogInfo("--------");
break; break;
} }
@ -656,8 +648,8 @@ bool ZeroCode_FillAndSlide(u32 val_last, u32 addr, u32 data) // This needs more
switch (size) switch (size)
{ {
case AR_SIZE_BYTE_WRITE: // Byte case DATATYPE_8BIT:
LogInfo("Byte Write"); LogInfo("8-bit Write");
LogInfo("--------"); LogInfo("--------");
for (int i=0; i < write_num; i++) { for (int i=0; i < write_num; i++) {
Memory::Write_U8(val & 0xFF, curr_addr); Memory::Write_U8(val & 0xFF, curr_addr);
@ -671,8 +663,8 @@ bool ZeroCode_FillAndSlide(u32 val_last, u32 addr, u32 data) // This needs more
} }
LogInfo("--------"); LogInfo("--------");
break; break;
case AR_SIZE_SHORT_WRITE: // Halfword case DATATYPE_16BIT:
LogInfo("Short Write"); LogInfo("16-bit Write");
LogInfo("--------"); LogInfo("--------");
for (int i=0; i < write_num; i++) { for (int i=0; i < write_num; i++) {
Memory::Write_U16(val & 0xFFFF, curr_addr); Memory::Write_U16(val & 0xFFFF, curr_addr);
@ -686,8 +678,8 @@ bool ZeroCode_FillAndSlide(u32 val_last, u32 addr, u32 data) // This needs more
} }
LogInfo("--------"); LogInfo("--------");
break; break;
case AR_SIZE_WORD_WRITE: // Word case DATATYPE_32BIT:
LogInfo("Word Write"); LogInfo("32-bit Write");
LogInfo("--------"); LogInfo("--------");
for (int i = 0; i < write_num; i++) { for (int i = 0; i < write_num; i++) {
Memory::Write_U32(val, curr_addr); Memory::Write_U32(val, curr_addr);
@ -755,22 +747,22 @@ bool NormalCode(u8 subtype, u32 addr, u32 data)
{ {
switch (subtype) switch (subtype)
{ {
case AR_SUB_RAM_WRITE: // Ram write (and fill) case SUB_RAM_WRITE: // Ram write (and fill)
LogInfo("Doing Ram Write And Fill"); LogInfo("Doing Ram Write And Fill");
if (!Subtype_RamWriteAndFill(addr, data)) if (!Subtype_RamWriteAndFill(addr, data))
return false; return false;
break; break;
case AR_SUB_WRITE_POINTER: // Write to pointer case SUB_WRITE_POINTER: // Write to pointer
LogInfo("Doing Write To Pointer"); LogInfo("Doing Write To Pointer");
if (!Subtype_WriteToPointer(addr, data)) if (!Subtype_WriteToPointer(addr, data))
return false; return false;
break; break;
case AR_SUB_ADD_CODE: // Add code case SUB_ADD_CODE: // Increment Value
LogInfo("Doing Add Code"); LogInfo("Doing Add Code");
if (!Subtype_AddCode(addr, data)) if (!Subtype_AddCode(addr, data))
return false; return false;
break; break;
case AR_SUB_MASTER_CODE : // Master Code & Write to CCXXXXXX case SUB_MASTER_CODE : // Master Code & Write to CCXXXXXX
LogInfo("Doing Master Code And Write to CCXXXXXX (ncode not supported)"); LogInfo("Doing Master Code And Write to CCXXXXXX (ncode not supported)");
if (!Subtype_MasterCodeAndWriteToCCXXXXXX()) if (!Subtype_MasterCodeAndWriteToCCXXXXXX())
return false; return false;
@ -791,10 +783,10 @@ bool ConditionalCode(u8 subtype, u32 addr, u32 data, int *pCount, bool *pSkip, i
bool con = true; bool con = true;
switch (size) switch (size)
{ {
case 0x0: con = CompareValues((u32)Memory::Read_U8(new_addr), (data & 0xFF), compareType); break; case DATATYPE_8BIT: con = CompareValues((u32)Memory::Read_U8(new_addr), (data & 0xFF), compareType); break;
case 0x1: con = CompareValues((u32)Memory::Read_U16(new_addr), (data & 0xFFFF), compareType); break; case DATATYPE_16BIT: con = CompareValues((u32)Memory::Read_U16(new_addr), (data & 0xFFFF), compareType); break;
case 0x3: case DATATYPE_32BIT_FLOAT:
case 0x2: con = CompareValues(Memory::Read_U32(new_addr), data, compareType); break; case DATATYPE_32BIT: con = CompareValues(Memory::Read_U32(new_addr), data, compareType); break;
default: default:
LogInfo("Bad Size"); LogInfo("Bad Size");
PanicAlert("Action Replay: Conditional Code: Invalid Size %08x (%s)", size, code.name.c_str()); PanicAlert("Action Replay: Conditional Code: Invalid Size %08x (%s)", size, code.name.c_str());
@ -812,10 +804,10 @@ bool SetLineSkip(int codetype, u8 subtype, bool *pSkip, bool skip, int *pCount)
switch (subtype) switch (subtype)
{ {
case AR_SUB_RAM_WRITE: *pCount = 1; break; // 1 line case 0x00: *pCount = 1; break; // Skip 1 line
case AR_SUB_WRITE_POINTER: *pCount = 2; break; // 2 lines case 0x01: *pCount = 2; break; // Skip 2 lines
case AR_SUB_ADD_CODE: *pCount = -2; break; // all lines case 0x02: // skip all lines
case AR_SUB_MASTER_CODE : *pCount = -2; break; // While != : skip all codes ("infinite loop on the code" ?) case 0x03: *pCount = -2; break; // While != : no idea the purpose of this case
default: default:
LogInfo("Bad Subtype"); LogInfo("Bad Subtype");
PanicAlert("Action Replay: Normal Code %i: Invalid subtype %08x (%s)", codetype, subtype, code.name.c_str()); PanicAlert("Action Replay: Normal Code %i: Invalid subtype %08x (%s)", codetype, subtype, code.name.c_str());
@ -828,14 +820,30 @@ bool CompareValues(u32 val1, u32 val2, int type)
{ {
switch(type) switch(type)
{ {
case 0: return (val1 == val2); case CONDTIONAL_IF_EQUAL:
case 1: return (val1 != val2); LogInfo("Type 1: If Equal");
case 2: return ((int)val1 < (int)val2); return (val1 == val2);
case 3: return ((int)val1 > (int)val2); case CONDTIONAL_IF_NOT_EQUAL:
case 4: return (val1 < val2); LogInfo("Type 2: If Not Equal");
case 5: return (val1 > val2); return (val1 != val2);
case 6: return (val1 && val2); case CONDTIONAL_IF_LESS_THAN_SIGNED:
default: LogInfo("Unknown Compare type"); return false; LogInfo("Type 3: If Less Than (Signed)");
return ((int)val1 < (int)val2);
case CONDTIONAL_IF_GREATER_THAN_SIGNED:
LogInfo("Type 4: If Greater Than (Signed)");
return ((int)val1 > (int)val2);
case CONDTIONAL_IF_LESS_THAN_UNSIGNED:
LogInfo("Type 5: If Less Than (Unsigned)");
return (val1 < val2);
case CONDTIONAL_IF_GREATER_THAN_UNSIGNED:
LogInfo("Type 6: If Greater Than (Unsigned)");
return (val1 > val2);
case CONDTIONAL_IF_AND:
LogInfo("Type 7: If And");
return (val1 && val2);
default: LogInfo("Unknown Compare type");
PanicAlert("Action Replay: Invalid Normal Code Type %08x (%s)", type, code.name.c_str());
return false;
} }
} }
} // namespace ActionReplay } // namespace ActionReplay

View File

@ -20,45 +20,6 @@
#include "IniFile.h" #include "IniFile.h"
enum
{
//Start OF Zero Codes
AR_ZCODE_END = 0x00,
AR_ZCODE_NORM = 0x02,
AR_ZCODE_ROW = 0x03,
AR_ZCODE_MEM_COPY = 0x04,
//Start of normal Codes
AR_CODE_IF_EQUAL = 0x1,
AR_CODE_IF_NOT_EQUAL = 0x2,
AR_CODE_IF_LESS_THAN_SIGNED = 0x3,
AR_CODE_IF_GREATER_THAN_SIGNED = 0x4,
AR_CODE_IF_LESS_THAN_UNSIGNED = 0x5,
AR_CODE_IF_GREATER_THAN_UNSIGNED = 0x6,
AR_CODE_IF_AND = 0x7,
//Add Stuff
AR_BYTE_ADD = 0x0,
AR_SHORT_ADD = 0x1,
AR_DWORD_ADD = 0x2,
AR_FLOAT_ADD = 0x3,
//Write Stuff
AR_BYTE_WRITE = 0x00,
AR_SHORT_WRITE = 0x01,
AR_DWORD_WRITE = 0x02,
//More write Stuff
AR_SIZE_BYTE_WRITE = 0x0,
AR_SIZE_SHORT_WRITE = 0x1,
AR_SIZE_WORD_WRITE = 0x2,
//Write Pointer Stuff
AR_BYTE_WRITE_POINTER = 0x00,
AR_SHORT_WRITE_POINTER = 0x01,
AR_DWORD_WRITE_POINTER = 0x02,
//Subtype
AR_SUB_RAM_WRITE = 0x0,
AR_SUB_WRITE_POINTER = 0x1,
AR_SUB_ADD_CODE = 0x2,
AR_SUB_MASTER_CODE = 0x3,
};
namespace ActionReplay namespace ActionReplay
{ {