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 --- src/codehandler.cpp | 439 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 439 insertions(+) create mode 100644 src/codehandler.cpp (limited to 'src/codehandler.cpp') 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