From 2190722ac1f0732cf35e7b63572afa698a47789d Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Thu, 13 Jul 2017 20:38:04 -0400 Subject: Organized code more Now the link-specific stuff is abstracted into its own file, and the code for negotiating the "different" multiboot protocol is in its own file. Also, removed support for compiling for GC because eventually we will be using Wii-only features. Also put the main extractor code into a thread so that we can monitor for the user pressing the start button to exit. --- source/link.c | 157 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 149 insertions(+), 8 deletions(-) (limited to 'source/link.c') diff --git a/source/link.c b/source/link.c index 4178293..1091576 100644 --- a/source/link.c +++ b/source/link.c @@ -5,18 +5,159 @@ * of the MIT license. See the LICENSE file for details. */ #include "link.h" +#include +#include +#include +#include -u32 waitForButtons(u32 mask) +//from my tests 50us seems to be the lowest +//safe si transfer delay in between calls +#define SI_TRANS_DELAY 50 + +static u8* resbuf; +static u8* cmdbuf; + +void initLink() +{ + cmdbuf = memalign(32,32); + resbuf = memalign(32,32); +} + +static volatile u32 transval = 0; +void transcb(s32 chan, u32 ret) +{ + transval = 1; +} + +static volatile u32 resval = 0; +void acb(s32 res, u32 val) +{ + resval = val; +} + +void doreset() +{ + cmdbuf[0] = 0xFF; //reset + transval = 0; + SI_Transfer(1, cmdbuf, 1, resbuf, 3, transcb, SI_TRANS_DELAY); + + while (transval == 0); +} + +void getstatus() { - for (;;) + cmdbuf[0] = 0; //status + transval = 0; + SI_Transfer(1, cmdbuf, 1, resbuf, 3, transcb, SI_TRANS_DELAY); + + while (transval == 0); +} + +u32 recv() +{ + memset(resbuf,0,32); + cmdbuf[0]=0x14; //read + transval = 0; + SI_Transfer(1, cmdbuf, 1, resbuf, 5, transcb, SI_TRANS_DELAY); + + while (transval == 0); + printf("%08lx\n", *(vu32*)resbuf); + return *(vu32*)resbuf; +} + +void send(u32 msg) +{ + cmdbuf[0] = 0x15; + cmdbuf[1] = (msg >> 0) & 0xFF; + cmdbuf[2] = (msg >> 8) & 0xFF; + cmdbuf[3] = (msg >> 16) & 0xFF; + cmdbuf[4] = (msg >> 24) & 0xFF; + + transval = 0; + resbuf[0] = 0; + SI_Transfer(1, cmdbuf, 5, resbuf, 1, transcb, SI_TRANS_DELAY); + + while (transval == 0); +} + +u32 getMsg() +{ + u32 val = 0; + while (val == 0) { - PAD_ScanPads(); - VIDEO_WaitVSync(); + val = __builtin_bswap32(recv()); + sleep(1); + } - u32 btns = PAD_ButtonsDown(0); - if (btns & mask) + send(0); + while (recv()!=0) {sleep(1);} + send(0); + + return val; +} + +void getMsgArr(u32* arr, int len) +{ + for (int i=0; i 4)); +} + +void waitForGame() +{ + do + { + doreset(); + } while ((resbuf[0] != 0) || !(resbuf[2] & 0x10)); +} + +void waitForAck() +{ + while (recv() != 0) {sleep(1);}; + send(0); } -- cgit 1.4.1