From 2835db2ebfe5e91da3f332f1eef2624f3aea3f68 Mon Sep 17 00:00:00 2001 From: Stephen Simpson Date: Thu, 3 Nov 2011 00:40:37 -0500 Subject: cleaned up codehandler to allow for better changes later --- NewerCodehandler.yaml | 8 +- codehandler.yaml | 2 +- src/codehandler.cpp | 439 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/codehandler.s | 368 ++++++++++++++++++++++++++++++++++++++++++ tools/mapfile_tool.py | 1 + 5 files changed, 815 insertions(+), 3 deletions(-) create mode 100644 src/codehandler.cpp create mode 100644 src/codehandler.s diff --git a/NewerCodehandler.yaml b/NewerCodehandler.yaml index 38060fe..732d297 100644 --- a/NewerCodehandler.yaml +++ b/NewerCodehandler.yaml @@ -10,8 +10,6 @@ modules: - processed/levelspecial.yaml - processed/mrsun.yaml - processed/firelaser.yaml - - processed/bossFuzzyBear.yaml - - processed/bossThwompaDomp.yaml - processed/spritetex.yaml # - processed/gakenoko.yaml - processed/poweruphax.yaml @@ -33,4 +31,10 @@ modules: - processed/blocksnake.yaml # - processed/classic_controller.yaml - processed/bossMegaGoomba.yaml + - processed/bossFuzzyBear.yaml + - processed/bossThwompaDomp.yaml + - processed/bossRamboo.yaml + - processed/bossBalboaWrench.yaml + - processed/effectVideo.yaml - processed/codehandler.yaml + - processed/fakeStarCoin.yaml diff --git a/codehandler.yaml b/codehandler.yaml index cfbeb9e..a8b8a0f 100644 --- a/codehandler.yaml +++ b/codehandler.yaml @@ -1,4 +1,4 @@ -source_files: [../src/codehandler.o] +source_files: [../src/codehandler.s, ../src/codehandler.cpp] hooks: - name: CodeHandlerHook type: branch_insn diff --git a/src/codehandler.cpp b/src/codehandler.cpp new file mode 100644 index 0000000..b1d67d2 --- /dev/null +++ b/src/codehandler.cpp @@ -0,0 +1,439 @@ +#include + +u8 frozen_value = 0; +u32 regbuffer[72] = {0}; +u32 dwordbuffer[2] = {0}; +u32 bpbuffer[4] = {0}; +u8 cmd; + +/*FIXME + * u32 register_to_match = 0; + * u32 register_value = 0; + * u32 bplist[40] = {0}; + */ + +#define PACKET_SIZE 0xF800 + +extern "C" void writebranch(u32 source, u32 destination); +extern "C" void bphandler(); + +// return true if remainder +bool _packetdivide(u32 memrange, u32 size, u32* full, u32* remainder) { + *full = memrange / size; + *remainder = memrange % size; + return (*remainder) ? true : false; +} + +u32 checkexisend(u32 EXI_command) { + //OSReport("checkexisend(0x%08x);\n", EXI_command); + *(u32*)0xCD006814 = 0xD0; + *(u32*)0xCD006824 = EXI_command; + *(u32*)0xCD006820 = 0x19; + + u32 exi_chan1cr = 1; + while((exi_chan1cr)&1) { + exi_chan1cr = *(u32*)0xCD006820; + exi_chan1cr &= 1; + } + + *(u32*)0xCD006814 = exi_chan1cr; + return *(u32*)0xCD006824; +} + +struct exidata { + unsigned bits0to3 : 4; + unsigned bit4 : 1; + unsigned bit5 : 1; + unsigned bit6 : 1; + unsigned bit7 : 1; + unsigned data : 8; + unsigned bottom : 16; +}; + +bool exichecktx() { + *(u32*)0xCD006814 = 0xD0; + *(u32*)0xCD006824 = 0xC0000000; + *(u32*)0xCD006820 = 0x09; + + u32 exi_chan1cr = 1; + while((exi_chan1cr)&1) { + exi_chan1cr = *(u32*)0xCD006820; + exi_chan1cr &= 1; + } + + *(u32*)0xCD006814 = exi_chan1cr; + u32 ret = *(u32*)0xCD006824; + struct exidata* dat = (exidata*)&ret; + return (dat->bit5) ? true : false; +} + +bool exireceivebyte(u8* byte) { + //OSReport("exireceivebyte()\n"); + u32 ret = checkexisend(0xA0000000); + struct exidata * dat = (exidata*)&ret; + *byte = dat->data; + return (dat->bit4) ? true : false; +} + +bool exicheckreceive() { + bool ret = false; + while(!ret) { + u32 foo = checkexisend(0xD0000000); + struct exidata* dat = (exidata*)&foo; + ret = dat->bit5; + } + return ret; +} + +void exireceivebuffer(u32 counter, u8* buffer) { + for(u32 ii=0; iibit5) ? true : false; +} + +void exisendbuffer(u32 counter, u8* buffer) { + bool ret = false; + for(u32 ii=0; ii