From 19971cdad71c0ae2d16c15ae5aa76078d2bb952a Mon Sep 17 00:00:00 2001 From: meepingsnesroms Date: Fri, 20 Jul 2018 16:43:22 -0700 Subject: [PATCH] Use rng in tests to verify that results arnt just a coincidence --- src/debug/sandbox.c | 36 +++++++++++++++++++++++++++++++----- tests/rngTouchTest.txt | 19 +++++++++++++++++++ 2 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 tests/rngTouchTest.txt diff --git a/src/debug/sandbox.c b/src/debug/sandbox.c index d924419..766d084 100644 --- a/src/debug/sandbox.c +++ b/src/debug/sandbox.c @@ -3,6 +3,7 @@ #include #include #include +#include #include "../m68k/m68k.h" #include "../emulator.h" @@ -63,6 +64,24 @@ static void logApiCalls(){ } } +static int64_t randomRange(int64_t start, int64_t end){ + static bool seedRng = true; + int64_t result; + + if(seedRng){ + srand(time(NULL)); + seedRng = false; + } + + result = rand(); + result <<= 32; + result |= rand(); + result %= llabs(end - start) + 1; + result += start; + + return result; +} + /* static uint32_t scanForPrivateFunctionAddress(const char* name){ //this is not 100% accurate, it scans memory for a function @@ -361,14 +380,21 @@ void sandboxTest(uint32_t test){ //since the sandbox can interrupt any running function(including ADC ones) this safeguard is needed if(ads7846BitsToNextControl == 0){ uint32_t point; - int16_t x; - int16_t y; + int16_t osX; + int16_t osY; + input_t oldInput = palmInput; + + palmInput.touchscreenTouched = true; + palmInput.touchscreenX = randomRange(0, 159); + palmInput.touchscreenY = randomRange(0, 219); //PrvBBGetXY on self dumped ROM callFunction(false, 0x100827CE, NULL, "v(L)", &point); - x = point >> 16; - y = point & 0xFFFF; - debugLog("Sandbox: Touch position is x:%d, y:%d\n", x, y); + osX = point >> 16; + osY = point & 0xFFFF; + debugLog("Sandbox: Real touch position is x:%d, y:%d\n", palmInput.touchscreenX, palmInput.touchscreenY); + debugLog("Sandbox: OS reported touch position is x:%d, y:%d\n", osX, osY); + palmInput = oldInput; } else{ debugLog("Sandbox: Unsafe to read touch position.\n"); diff --git a/tests/rngTouchTest.txt b/tests/rngTouchTest.txt new file mode 100644 index 0000000..9bb5e49 --- /dev/null +++ b/tests/rngTouchTest.txt @@ -0,0 +1,19 @@ +Sandbox: Test 1 started(printed 1 times) +SPI2 transfer, ENABLE:true, XCH:true, IRQ:false, IRQEN:false, BITCOUNT:5(printed 1 times) +SPI2 transfer, before:0x001B, after:0x0360, PC:0x1008119E(printed 1 times) +Accessed ADS7846 Ch:5, 8 bits, Diff Mode, Power Save:1, PC:0x10081208.(printed 1 times) +SPI2 transfer, ENABLE:true, XCH:true, IRQ:false, IRQEN:false, BITCOUNT:12(printed 1 times) +SPI2 transfer, before:0x0213, after:0x3059, PC:0x10081208(printed 1 times) +Accessed ADS7846 Ch:1, 8 bits, Diff Mode, Power Save:1, PC:0x10081208.(printed 1 times) +SPI2 transfer, ENABLE:true, XCH:true, IRQ:false, IRQEN:false, BITCOUNT:12(printed 1 times) +SPI2 transfer, before:0x021B, after:0xB017, PC:0x10081208(printed 1 times) +SPI2 transfer, ENABLE:true, XCH:true, IRQ:false, IRQEN:false, BITCOUNT:3(printed 1 times) +SPI2 transfer, before:0x0004, after:0x0020, PC:0x1008124C(printed 1 times) +Sandbox: Real touch position is x:108, y:211(printed 1 times) +Sandbox: OS reported touch position is x:89, y:23(printed 1 times) +Sandbox: Test 1 finished(printed 1 times) + +Results: +X Inaccuracy -19 +Y Inaccuracy +15(y seems to be inverted)(219 - 211 = 8)(23 - 8 = 15) +This is before the touch calibration screen. \ No newline at end of file