- fix EXXXXXXX code;
This commit is contained in:
mtabachenko 2009-12-20 13:46:46 +00:00
parent 6fe8d6bdc7
commit 039e177db6
6 changed files with 69 additions and 89 deletions

View File

@ -54,8 +54,8 @@ void CHEATS::init(char *path)
BOOL CHEATS::add(u8 size, u32 address, u32 val, char *description, BOOL enabled)
{
if (num == MAX_CHEAT_LIST) return FALSE;
list[num].hi[0] = address & 0x00FFFFFF;
list[num].lo[0] = val;
list[num].code[0][0] = address & 0x00FFFFFF;
list[num].code[0][1] = val;
list[num].num = 1;
list[num].type = 0;
list[num].size = size;
@ -68,8 +68,8 @@ BOOL CHEATS::add(u8 size, u32 address, u32 val, char *description, BOOL enabled)
BOOL CHEATS::update(u8 size, u32 address, u32 val, char *description, BOOL enabled, u32 pos)
{
if (pos > num) return FALSE;
list[pos].hi[0] = address & 0x00FFFFFF;
list[pos].lo[0] = val;
list[pos].code[0][0] = address & 0x00FFFFFF;
list[pos].code[0][1] = val;
list[pos].num = 1;
list[pos].type = 0;
list[pos].size = size;
@ -97,11 +97,11 @@ void CHEATS::ARparser(CHEATS_LIST list)
for (int i=0; i < list.num; i++)
{
type = list.hi[i] >> 28;
subtype = (list.hi[i] >> 24) & 0x0F;
type = list.code[i][0] >> 28;
subtype = (list.code[i][0] >> 24) & 0x0F;
hi = list.hi[i] & 0x0FFFFFFF;
lo = list.lo[i];
hi = list.code[i][0] & 0x0FFFFFFF;
lo = list.code[i][1];
if (if_flag > 0)
{
@ -368,7 +368,15 @@ void CHEATS::ARparser(CHEATS_LIST list)
case 0xE:
{
// TODO
u8 *tmp_code = (u8*)(list.code[i+1]);
u32 addr = hi+offset;
for (u32 t = 0; t < lo; t++)
{
u8 tmp = T1ReadByte(tmp_code, t);
T1WriteByte(MMU.MMU_MEM[ARMCPU_ARM9][addr>>20], addr & MMU.MMU_MASK[ARMCPU_ARM9][addr>>20], tmp);
addr++;
}
i += (lo / 8);
}
break;
@ -389,39 +397,16 @@ BOOL CHEATS::XXcodePreParser(CHEATS_LIST *list, char *code)
{
int count = 0;
u16 t = 0;
char tmp_buf[sizeof(list->hi)+sizeof(list->lo)];
char tmp_buf[sizeof(list->code)];
memset(tmp_buf, 0, sizeof(tmp_buf));
// remove wrong chars
for (unsigned int i=0; i < strlen(code); i++)
{
switch (code[i])
if (strchr(hexValid, code[i]))
{
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case 'A':
case 'a':
case 'B':
case 'b':
case 'C':
case 'c':
case 'D':
case 'd':
case 'E':
case 'e':
case 'F':
case 'f':
tmp_buf[t] = code[i];
t++;
break;
}
}
@ -434,9 +419,9 @@ BOOL CHEATS::XXcodePreParser(CHEATS_LIST *list, char *code)
{
char buf[8] = {0};
strncpy(buf, tmp_buf+(i*16), 8);
sscanf_s(buf, "%x", &list->hi[i]);
sscanf_s(buf, "%x", &list->code[i][0]);
strncpy(buf, tmp_buf+(i*16) + 8, 8);
sscanf_s(buf, "%x", &list->lo[i]);
sscanf_s(buf, "%x", &list->code[i][1]);
}
list->num = count;
@ -552,7 +537,7 @@ u32 CHEATS::getSize()
BOOL CHEATS::save()
{
char *types[] = {"DS", "AR", "CB"};
char buf[(sizeof(list[0].hi)+sizeof(list[0].lo)) * 2 + 200] = { 0 };
char buf[sizeof(list[0].code) * 2 + 200] = { 0 };
FILE *flist = fopen((char *)filename, "w");
if (flist)
@ -568,9 +553,9 @@ BOOL CHEATS::save()
for (int t = 0; t < list[i].num; t++)
{
char buf2[10] = { 0 };
sprintf(buf2, "%08X", list[i].hi[t]);
sprintf(buf2, "%08X", list[i].code[t][0]);
strcat(buf, buf2);
sprintf(buf2, "%08X", list[i].lo[t]);
sprintf(buf2, "%08X", list[i].code[t][1]);
strcat(buf, buf2);
if (t < (list[i].num - 1))
strcat(buf, ",");
@ -609,10 +594,10 @@ char *CHEATS::clearCode(char *s)
BOOL CHEATS::load()
{
FILE *flist = fopen((char *)filename, "r");
char buf[(sizeof(list[0].hi)+sizeof(list[0].lo)) * 2 + 200] = { 0 };
char buf[sizeof(list[0].code) * 2 + 200] = { 0 };
u32 last = 0;
CHEATS_LIST tmp_cht = { 0 };
char tmp_code[(sizeof(list[0].hi)+sizeof(list[0].lo)) * 2] = { 0 };
char tmp_code[sizeof(list[0].code) * 2] = { 0 };
u32 line = 0;
if (flist)
@ -660,20 +645,17 @@ BOOL CHEATS::load()
if (descr_pos != 0)
strcpy(tmp_cht.description, (buf + descr_pos + 1));
#if 1
// TODO: remove later (its old)
tmp_cht.num = strlen(tmp_code) / 16;
for (int i = 0; i < tmp_cht.num; i++)
{
char tmp_buf[9] = {0};
strncpy(tmp_buf, (char*)(tmp_code + (i*16)), 8);
sscanf_s(tmp_buf, "%x", &tmp_cht.hi[i]);
sscanf_s(tmp_buf, "%x", &tmp_cht.code[i][0]);
strncpy(tmp_buf, (char*)(tmp_code + (i*16) + 8), 8);
sscanf_s(tmp_buf, "%x", &tmp_cht.lo[i]);
sscanf_s(tmp_buf, "%x", &tmp_cht.code[i][1]);
}
#endif
memcpy(&list[last], &tmp_cht, sizeof(tmp_cht));
last++;
@ -724,20 +706,20 @@ void CHEATS::process()
switch (list[i].type)
{
case 0: // internal list system
//INFO("list at 0x02|%06X value %i (size %i)\n",list[i].hi[0], list[i].lo[0], list[i].size);
//INFO("list at 0x02|%06X value %i (size %i)\n",list[i].code[0], list[i].lo[0], list[i].size);
switch (list[i].size)
{
case 0: T1WriteByte(MMU.MMU_MEM[ARMCPU_ARM9][0x20], list[i].hi[0], list[i].lo[0]); break;
case 1: T1WriteWord(MMU.MMU_MEM[ARMCPU_ARM9][0x20], list[i].hi[0], list[i].lo[0]); break;
case 0: T1WriteByte(MMU.MMU_MEM[ARMCPU_ARM9][0x20], list[i].code[0][0], list[i].code[0][1]); break;
case 1: T1WriteWord(MMU.MMU_MEM[ARMCPU_ARM9][0x20], list[i].code[0][0], list[i].code[0][1]); break;
case 2:
{
u32 tmp = T1ReadLong(MMU.MMU_MEM[ARMCPU_ARM9][0x20], list[i].hi[0]);
u32 tmp = T1ReadLong(MMU.MMU_MEM[ARMCPU_ARM9][0x20], list[i].code[0][0]);
tmp &= 0xFF000000;
tmp |= (list[i].lo[0] & 0x00FFFFFF);
T1WriteLong(MMU.MMU_MEM[ARMCPU_ARM9][0x20], list[i].hi[0], tmp);
tmp |= (list[i].code[0][1] & 0x00FFFFFF);
T1WriteLong(MMU.MMU_MEM[ARMCPU_ARM9][0x20], list[i].code[0][0], tmp);
break;
}
case 3: T1WriteLong(MMU.MMU_MEM[ARMCPU_ARM9][0x20], list[i].hi[0], list[i].lo[0]); break;
case 3: T1WriteLong(MMU.MMU_MEM[ARMCPU_ARM9][0x20], list[i].code[0][0], list[i].code[0][1]); break;
}
break;
@ -757,7 +739,7 @@ void CHEATS::getXXcodeString(CHEATS_LIST list, char *res_buf)
for (int i=0; i < list.num; i++)
{
sprintf(buf, "%08X %08X\n", list.hi[i], list.lo[i]);
sprintf(buf, "%08X %08X\n", list.code[i][0], list.code[i][1]);
strcat(res_buf, buf);
}
}

View File

@ -34,9 +34,7 @@ typedef struct
// 1 - Action Replay
// 2 - Codebreakers
BOOL enabled;
//u32 code[MAX_XX_CODE][2];
u32 hi[MAX_XX_CODE];
u32 lo[MAX_XX_CODE];
u32 code[MAX_XX_CODE][2];
char description[75];
int num;
u8 size;

View File

@ -89,7 +89,7 @@ enabled_toggled(GtkCellRendererToggle * cell,
cheats->get(&cheat, ii);
cheats->update(cheat.size, cheat.hi[0], cheat.lo[0], cheat.description,
cheats->update(cheat.size, cheat.code[0][0], cheat.code[0][1], cheat.description,
enabled, ii);
gtk_list_store_set(GTK_LIST_STORE(model), &iter, COLUMN_ENABLED, enabled, -1);
@ -127,22 +127,22 @@ static void cheat_list_modify_cheat(GtkCellRendererText * cell,
u32 v = atoi(new_text);
switch (column) {
case COLUMN_SIZE:
cheats->update(v-1, cheat.hi[0], cheat.lo[0],
cheats->update(v-1, cheat.code[0][0], cheat.code[0][1],
cheat.description, cheat.enabled, ii);
break;
case COLUMN_HI:
cheats->update(cheat.size, v, cheat.lo[0], cheat.description,
cheats->update(cheat.size, v, cheat.code[0][1], cheat.description,
cheat.enabled, ii);
break;
case COLUMN_LO:
cheats->update(cheat.size, cheat.hi[0], v, cheat.description,
cheats->update(cheat.size, cheat.code[0][0], v, cheat.description,
cheat.enabled, ii);
break;
}
gtk_list_store_set(GTK_LIST_STORE(model), &iter, column,
atoi(new_text), -1);
} else if (column == COLUMN_DESC){
cheats->update(cheat.size, cheat.hi[0], cheat.lo[0],
cheats->update(cheat.size, cheat.code[0][0], cheat.code[0][1],
g_strdup(new_text), cheat.enabled, ii);
gtk_list_store_set(GTK_LIST_STORE(model), &iter, column,
g_strdup(new_text), -1);
@ -290,8 +290,8 @@ static GtkListStore *cheat_list_populate()
gtk_list_store_set(store, &iter,
COLUMN_ENABLED, cheat.enabled,
COLUMN_SIZE, cheat.size+1,
COLUMN_HI, cheat.hi[0],
COLUMN_LO, cheat.lo[0],
COLUMN_HI, cheat.code[0][0],
COLUMN_LO, cheat.code[0][1],
COLUMN_DESC, cheat.description,
-1);
}

View File

@ -392,10 +392,10 @@ INT_PTR CALLBACK CheatsEditProc(HWND dialog, UINT msg,WPARAM wparam,LPARAM lpara
memset(buf, 0, 100);
memset(buf2, 0, 100);
tempCheat.hi[0] &= 0x00FFFFFF;
wsprintf(buf, "%06X", tempCheat.hi[0]);
tempCheat.code[0][0] &= 0x00FFFFFF;
wsprintf(buf, "%06X", tempCheat.code[0][0]);
SetWindowText(GetDlgItem(dialog, IDC_EDIT1), buf);
wsprintf(buf, "%i", tempCheat.lo[0]);
wsprintf(buf, "%i", tempCheat.code[0][1]);
SetWindowText(GetDlgItem(dialog, IDC_EDIT2), buf);
strcpy(buf, tempCheat.description);
SetWindowText(GetDlgItem(dialog, IDC_EDIT3), buf);
@ -413,7 +413,7 @@ INT_PTR CALLBACK CheatsEditProc(HWND dialog, UINT msg,WPARAM wparam,LPARAM lpara
{
case IDOK:
{
if (cheats->update(tempCheat.size, tempCheat.hi[0], tempCheat.lo[0], tempCheat.description, tempCheat.enabled, cheatEditPos))
if (cheats->update(tempCheat.size, tempCheat.code[0][0], tempCheat.code[0][1], tempCheat.description, tempCheat.enabled, cheatEditPos))
{
oldEditProc = saveOldEditProc;
EndDialog(dialog, TRUE);
@ -447,7 +447,7 @@ INT_PTR CALLBACK CheatsEditProc(HWND dialog, UINT msg,WPARAM wparam,LPARAM lpara
return TRUE;
}
EnableWindow(GetDlgItem(dialog, IDOK), TRUE);
tempCheat.hi[0] = val;
tempCheat.code[0][0] = val;
}
return TRUE;
}
@ -486,7 +486,7 @@ INT_PTR CALLBACK CheatsEditProc(HWND dialog, UINT msg,WPARAM wparam,LPARAM lpara
return TRUE;
}
EnableWindow(GetDlgItem(dialog, IDOK), TRUE);
tempCheat.lo[0] = val;
tempCheat.code[0][1] = val;
}
return TRUE;
}
@ -557,9 +557,12 @@ INT_PTR CALLBACK CheatsAdd_XX_Proc(HWND dialog, UINT msg,WPARAM wparam,LPARAM lp
}
}
SendMessage(GetDlgItem(dialog, IDC_EDIT2), EM_SETLIMITTEXT, sizeof(tempCheat.code) * 1, 0);
SendMessage(GetDlgItem(dialog, IDC_EDIT3), EM_SETLIMITTEXT, sizeof(tempCheat.description), 0);
if (cheatXXaction != 0)
{
char buf[(sizeof(tempCheat.hi)+sizeof(tempCheat.lo)) * 2] = { 0 };
char buf[sizeof(tempCheat.code)*2] = { 0 };
memset(buf, 0, sizeof(buf));
cheats->getXXcodeString(tempCheat, buf);
@ -570,9 +573,6 @@ INT_PTR CALLBACK CheatsAdd_XX_Proc(HWND dialog, UINT msg,WPARAM wparam,LPARAM lp
SetWindowText(GetDlgItem(dialog, IDOK), "Update");
}
CheckDlgButton(dialog, IDC_CHECK1, tempCheat.enabled?BST_CHECKED:BST_UNCHECKED);
SendMessage(GetDlgItem(dialog, IDC_EDIT2), EM_SETLIMITTEXT, (sizeof(tempCheat.hi)+sizeof(tempCheat.lo)) * 2, 0);
SendMessage(GetDlgItem(dialog, IDC_EDIT3), EM_SETLIMITTEXT, sizeof(tempCheat.description), 0);
}
return TRUE;
@ -582,7 +582,7 @@ INT_PTR CALLBACK CheatsAdd_XX_Proc(HWND dialog, UINT msg,WPARAM wparam,LPARAM lp
{
case IDOK:
{
char buf[(sizeof(tempCheat.hi)+sizeof(tempCheat.lo)) * 2] = { 0 };
char buf[sizeof(tempCheat.code)*2] = { 0 };
memset(buf, 0, sizeof(buf));
GetWindowText(GetDlgItem(dialog, IDC_EDIT2), buf, sizeof(buf));
@ -640,7 +640,7 @@ INT_PTR CALLBACK CheatsAdd_XX_Proc(HWND dialog, UINT msg,WPARAM wparam,LPARAM lp
case IDC_EDIT2: // code
if (HIWORD(wparam) == EN_UPDATE)
{
char buf[(sizeof(tempCheat.hi)+sizeof(tempCheat.lo)) * 2] = { 0 };
char buf[sizeof(tempCheat.code)*2] = { 0 };
memset(buf, 0, sizeof(buf));
GetWindowText(GetDlgItem(dialog, IDC_EDIT2), buf, sizeof(buf));
@ -726,9 +726,9 @@ INT_PTR CALLBACK CheatsListBox_Proc(HWND dialog, UINT msg,WPARAM wparam,LPARAM l
case 0: // Internal
{
u32 row = ListView_InsertItem(cheatListView, &lvi);
wsprintf(buf, "0x02%06X", tempCheat.hi[0]);
wsprintf(buf, "0x02%06X", tempCheat.code[0][0]);
ListView_SetItemText(cheatListView, row, 1, buf);
ltoa(tempCheat.lo[0], buf, 10);
ltoa(tempCheat.code[0][1], buf, 10);
ListView_SetItemText(cheatListView, row, 2, buf);
ListView_SetItemText(cheatListView, row, 3, tempCheat.description);
break;
@ -772,7 +772,7 @@ INT_PTR CALLBACK CheatsListBox_Proc(HWND dialog, UINT msg,WPARAM wparam,LPARAM l
switch (tempCheat.type)
{
case 0: // internal
cheats->update(tempCheat.size, tempCheat.hi[0], tempCheat.lo[0], tempCheat.description, tempCheat.enabled, cheatEditPos);
cheats->update(tempCheat.size, tempCheat.code[0][0], tempCheat.code[0][1], tempCheat.description, tempCheat.enabled, cheatEditPos);
break;
case 1: // Action Replay
@ -918,9 +918,9 @@ INT_PTR CALLBACK CheatsListBox_Proc(HWND dialog, UINT msg,WPARAM wparam,LPARAM l
cheats->get(&tempCheat, cheatEditPos);
if (tempCheat.enabled)
ListView_SetItemText(cheatListView, cheatEditPos, 0, "X");
wsprintf(buf, "0x02%06X", tempCheat.hi[0]);
wsprintf(buf, "0x02%06X", tempCheat.code[0][0]);
ListView_SetItemText(cheatListView, cheatEditPos, 1, buf);
ltoa(tempCheat.lo[0], buf, 10);
ltoa(tempCheat.code[0][1], buf, 10);
ListView_SetItemText(cheatListView, cheatEditPos, 2, buf);
ListView_SetItemText(cheatListView, cheatEditPos, 3, tempCheat.description);
EnableWindow(GetDlgItem(dialog, IDOK), TRUE);
@ -1015,9 +1015,9 @@ void CheatsAddDialog(HWND parentHwnd, u32 address, u32 value, u8 size, const cha
//cheats->get(&tempCheat, cheatEditPos);
//if (tempCheat.enabled)
// ListView_SetItemText(cheatListView, cheatEditPos, 0, "X");
//wsprintf(buf, "0x02%06X", tempCheat.hi[0]);
//wsprintf(buf, "0x02%06X", tempCheat.code[0][0]);
//ListView_SetItemText(cheatListView, cheatEditPos, 1, buf);
//ltoa(tempCheat.lo[0], buf, 10);
//ltoa(tempCheat.code[0][1], buf, 10);
//ListView_SetItemText(cheatListView, cheatEditPos, 2, buf);
//ListView_SetItemText(cheatListView, cheatEditPos, 3, tempCheat.description);
}

View File

@ -1,5 +1,4 @@
/* Copyright (C) 2006 yopyop
Copyright (C) 2008 CrazyMax (mtabachenko)
/* Copyright 2008-2009 DeSmuME team
This file is part of DeSmuME
@ -15,8 +14,9 @@
You should have received a copy of the GNU General Public License
along with DeSmuME; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _CONSOLE_H_
#define _CONSOLE_H_
@ -28,7 +28,7 @@
#else
#define pringlog(...)
#define printlog(...)
#endif

View File

@ -22,7 +22,7 @@
#ifndef _COMMON_H__
#define _COMMON_H__
#if defined(_MSC_VER) || defined(__INTEL_COMPILER)
#if defined(_MSC_VER)
#pragma warning(disable: 4995)
#pragma warning(disable: 4996)
#endif
@ -95,6 +95,7 @@ char __forceinline *error()
return strdup((char*)lpMsgBuf);
}
#endif
u8 __forceinline read8(u8 *mem, u32 offset)
{
@ -120,6 +121,5 @@ u64 __forceinline read64(u8 *mem, u32 offset)
{
return (*(u64*)(mem + offset));
}
#endif
#endif