foxygit / fake-08-xbox360 Log in
commit d5b77071e4c437255e3b522ec38c105586f66ead
Author:     jtothebell <j.to.the.bell@gmail.com>
AuthorDate: Sat Nov 21 21:00:02 2020 -0700
Commit:     jtothebell <j.to.the.bell@gmail.com>
CommitDate: Sat Nov 21 21:00:02 2020 -0700

    WIP refactor to allow _update_buttons call
---
 platform/SDL2/source/SDL2Host.cpp | 134 +++++++++++++++-----------------------
 source/host.h                     |   7 +-
 source/hostVmShared.h             |   5 ++
 source/main.cpp                   |  20 +++---
 source/picoluaapi.cpp             |   6 ++
 source/picoluaapi.h               |   1 +
 source/vm.cpp                     |  19 ++++--
 source/vm.h                       |  12 ++--
 test/Makefile                     |   9 +--
 test/endtoendtests.cpp            |  54 +++++++--------
 test/stubhost.cpp                 |  91 ++++++++++++++++++++++++++
 test/stubhost.h                   |   9 +++
 test/vmtests.cpp                  |  16 +++--
 13 files changed, 242 insertions(+), 141 deletions(-)

diff --git a/platform/SDL2/source/SDL2Host.cpp b/platform/SDL2/source/SDL2Host.cpp
index d41d491..cb61245 100644
--- a/platform/SDL2/source/SDL2Host.cpp
+++ b/platform/SDL2/source/SDL2Host.cpp
@@ -98,8 +98,6 @@ void audioSetup(){

 }

-
-
 Host::Host() { }


@@ -150,44 +148,67 @@ void Host::setTargetFps(int targetFps){
 }

 void Host::changeStretch(){
-    /*
-    if (currKDown & KEY_R) {
-        if (stretch == PixelPerfect) {
-            stretch = PixelPerfectStretch;
-        }
-        else if (stretch == PixelPerfectStretch) {
-            stretch = PixelPerfect;
+}
+InputState_t Host::scanInput(){
+    currKDown = 0;
+    currKHeld = 0;
+
+    while (SDL_PollEvent(&event)) {
+        switch (event.type) {
+            case SDL_KEYDOWN:
+                switch (event.key.keysym.sym)
+                {
+                    case SDLK_ESCAPE:currKDown |= P8_KEY_PAUSE; break;
+                    case SDLK_LEFT:  currKDown |= P8_KEY_LEFT; break;
+                    case SDLK_RIGHT: currKDown |= P8_KEY_RIGHT; break;
+                    case SDLK_UP:    currKDown |= P8_KEY_UP; break;
+                    case SDLK_DOWN:  currKDown |= P8_KEY_DOWN; break;
+                    case SDLK_z:     currKDown |= P8_KEY_X; break;
+                    case SDLK_x:     currKDown |= P8_KEY_O; break;
+                    case SDLK_c:     currKDown |= P8_KEY_X; break;
+                }
+                break;
+            case SDL_QUIT:
+                done = SDL_TRUE;
+                break;
         }
     }
-    */
-}

-void Host::scanInput(){
-    //hidScanInput();
+    const Uint8* keystate = SDL_GetKeyboardState(NULL);

-    //currKDown = hidKeysDown(CONTROLLER_P1_AUTO);
-    //currKHeld = hidKeysHeld(CONTROLLER_P1_AUTO);
+    //continuous-response keys
+    if(keystate[SDL_SCANCODE_LEFT]){
+        currKHeld |= P8_KEY_LEFT;
+    }
+    if(keystate[SDL_SCANCODE_RIGHT]){
+        currKHeld |= P8_KEY_RIGHT;;
+    }
+    if(keystate[SDL_SCANCODE_UP]){
+        currKHeld |= P8_KEY_UP;
+    }
+    if(keystate[SDL_SCANCODE_DOWN]){
+        currKHeld |= P8_KEY_DOWN;
+    }
+    if(keystate[SDL_SCANCODE_Z]){
+        currKHeld |= P8_KEY_X;
+    }
+    if(keystate[SDL_SCANCODE_X]){
+        currKHeld |= P8_KEY_O;
+    }
+    if(keystate[SDL_SCANCODE_C]){
+        currKHeld |= P8_KEY_X;
+    }

+    return InputState_t {
+        currKDown,
+        currKHeld
+    };
 }

-uint8_t Host::getKeysDown(){
-    return currKDown;
-}
-
-uint8_t Host::getKeysHeld(){
-    return currKHeld;
-}
-
-
 bool Host::shouldQuit() {
-    //bool lpressed = currKHeld & KEY_L;
-	//bool rpressed = currKDown & KEY_R;
-
-	//return lpressed && rpressed;
-    return false;
+    return done == SDL_TRUE;
 }

-
 void Host::waitForTargetFps(){
     now_time = SDL_GetTicks();
     frame_time = now_time - last_time;
@@ -252,60 +273,11 @@ void Host::playFilledAudioBuffer(){
 	fillBlock = !fillBlock;
 }

-bool Host::mainLoop(){
-    currKDown = 0;
-    currKHeld = 0;
-
-    while (SDL_PollEvent(&event)) {
-        switch (event.type) {
-            case SDL_KEYDOWN:
-                switch (event.key.keysym.sym)
-                {
-                    case SDLK_ESCAPE:currKDown |= P8_KEY_PAUSE; break;
-                    case SDLK_LEFT:  currKDown |= P8_KEY_LEFT; break;
-                    case SDLK_RIGHT: currKDown |= P8_KEY_RIGHT; break;
-                    case SDLK_UP:    currKDown |= P8_KEY_UP; break;
-                    case SDLK_DOWN:  currKDown |= P8_KEY_DOWN; break;
-                    case SDLK_z:     currKDown |= P8_KEY_X; break;
-                    case SDLK_x:     currKDown |= P8_KEY_O; break;
-                    case SDLK_c:     currKDown |= P8_KEY_X; break;
-                }
-                break;
-            case SDL_QUIT:
-                done = SDL_TRUE;
-                break;
-        }
-    }
-
-    if (done == SDL_TRUE){
+bool Host::shouldRunMainLoop(){
+    if (shouldQuit()){
         return false;
     }

-    const Uint8* keystate = SDL_GetKeyboardState(NULL);
-
-    //continuous-response keys
-    if(keystate[SDL_SCANCODE_LEFT]){
-        currKHeld |= P8_KEY_LEFT;
-    }
-    if(keystate[SDL_SCANCODE_RIGHT]){
-        currKHeld |= P8_KEY_RIGHT;;
-    }
-    if(keystate[SDL_SCANCODE_UP]){
-        currKHeld |= P8_KEY_UP;
-    }
-    if(keystate[SDL_SCANCODE_DOWN]){
-        currKHeld |= P8_KEY_DOWN;
-    }
-    if(keystate[SDL_SCANCODE_Z]){
-        currKHeld |= P8_KEY_X;
-    }
-    if(keystate[SDL_SCANCODE_X]){
-        currKHeld |= P8_KEY_O;
-    }
-    if(keystate[SDL_SCANCODE_C]){
-        currKHeld |= P8_KEY_X;
-    }
-
     return true;
 }

diff --git a/source/host.h b/source/host.h
index 6eaa8ec..4b78ec0 100644
--- a/source/host.h
+++ b/source/host.h
@@ -20,12 +20,9 @@ class Host {

     void setTargetFps(int targetFps);

-    bool mainLoop();
-
-    void scanInput();
-    uint8_t getKeysDown();
-    uint8_t getKeysHeld();
+    bool shouldRunMainLoop();

+    InputState_t scanInput();
     bool shouldQuit();

     void changeStretch();
diff --git a/source/hostVmShared.h b/source/hostVmShared.h
index 0bda3e6..b6a1749 100644
--- a/source/hostVmShared.h
+++ b/source/hostVmShared.h
@@ -27,3 +27,8 @@ struct Bgr24Col {
 	uint8_t Green;
 	uint8_t Red;
 };
+
+struct InputState_t {
+	uint8_t KDown;
+	uint8_t KHeld;
+};
diff --git a/source/main.cpp b/source/main.cpp
index 54d19af..4a9e948 100644
--- a/source/main.cpp
+++ b/source/main.cpp
@@ -16,9 +16,9 @@ int main(int argc, char* argv[])
 {
 	Logger::Initialize();

-	Vm *vm = new Vm();
-
 	Host *host = new Host();
+	Vm *vm = new Vm(host);
+
 	host->oneTimeSetup(vm->GetPaletteColors());

 	Logger::Write("initialized Vm and host\n");
@@ -33,23 +33,23 @@ int main(int argc, char* argv[])
 	// Main loop
 	Logger::Write("Starting main loop\n");

-	while (host->mainLoop())
+	while (host->shouldRunMainLoop())
 	{
 		int targetFps = vm->GetTargetFps();
+		//shouldn't need to set this every frame
 		host->setTargetFps(targetFps);

+		//is this better at the end of the loop?
 		host->waitForTargetFps();

-		host->scanInput();
-
 		if (host->shouldQuit()) break; // break in order to return to hbmenu
-
+		//this should probably be handled just in the host class
 		host->changeStretch();

-		uint8_t p8kDown = host->getKeysDown();
-		uint8_t p8kHeld = host->getKeysHeld();
-
-		vm->UpdateAndDraw(p8kDown, p8kHeld);
+		//update buttons needs to be callable from the cart, and also flip
+		//it should update call the pico part of scanInput and set the values in memory
+		//then we don't need to pass them in here
+		vm->UpdateAndDraw();

 		uint8_t* picoFb = vm->GetPicoInteralFb();
 		uint8_t* screenPaletteMap = vm->GetScreenPaletteMap();
diff --git a/source/picoluaapi.cpp b/source/picoluaapi.cpp
index aa52ae1..d1fdd84 100644
--- a/source/picoluaapi.cpp
+++ b/source/picoluaapi.cpp
@@ -777,6 +777,12 @@ int srand(lua_State *L) {
     return 0;
 }

+int _update_buttons(lua_State *L) {
+    _vmForLuaApi->update_buttons();
+
+    return 0;
+}
+
 int listcarts(lua_State *L) {
     //get cart list from VM (who should get it from host)
     vector<string> carts = _vmForLuaApi->GetCartList();
diff --git a/source/picoluaapi.h b/source/picoluaapi.h
index c9dee8a..e5f906c 100644
--- a/source/picoluaapi.h
+++ b/source/picoluaapi.h
@@ -97,6 +97,7 @@ int loadbioscart(lua_State *L);

 int rnd(lua_State *L);
 int srand(lua_State *L);
+int _update_buttons(lua_State *L);

 //api.tonum(val)

diff --git a/source/vm.cpp b/source/vm.cpp
index e2ae4cd..ebacfe5 100644
--- a/source/vm.cpp
+++ b/source/vm.cpp
@@ -26,6 +26,7 @@
 using namespace z8;

 Vm::Vm(
+    Host* host,
     PicoRam* memory,
     Graphics* graphics,
     Input* input,
@@ -42,6 +43,8 @@ Vm::Vm(
         _cartLoadError(""),
         _cartdataKey("")
 {
+    _host = host;
+
     if (memory == nullptr) {
         memory = new PicoRam();
         _cleanupDeps = true;
@@ -215,6 +218,7 @@ bool Vm::loadCart(Cart* cart) {
     //
     lua_register(_luaState, "printh", printh);
     lua_register(_luaState, "stat", stat);
+    lua_register(_luaState, "_update_buttons", _update_buttons);

     //rng
     lua_register(_luaState, "rnd", rnd);
@@ -306,11 +310,8 @@ void Vm::LoadCart(std::string filename){
 }


-void Vm::UpdateAndDraw(
-      uint8_t kdown,
-      uint8_t kheld)
-{
-    _input->SetState(kdown, kheld);
+void Vm::UpdateAndDraw() {
+    update_buttons();

     if (_hasUpdate){
         // Push the _update function on the top of the lua stack
@@ -339,7 +340,7 @@ void Vm::UpdateAndDraw(
     _picoFrameCount++;

     //todo: pause menu here, but for now just load bios
-    if (kdown & P8_KEY_PAUSE) {
+    if (_input->btnp(6)) {
         QueueCartChange("__FAKE08-BIOS.p8");
     }

@@ -613,3 +614,9 @@ void Vm::api_srand(fix32 seed)
     for (int i = 0; i < 32; ++i)
         update_prng();
 }
+
+void Vm::update_buttons() {
+    //get button states from hardware
+    auto inputState = _host->scanInput();
+    _input->SetState(inputState.KDown, inputState.KHeld);
+}
\ No newline at end of file
diff --git a/source/vm.h b/source/vm.h
index c4982be..c56c628 100644
--- a/source/vm.h
+++ b/source/vm.h
@@ -7,6 +7,7 @@ using namespace std;
 #include "cart.h"
 #include "Input.h"
 #include "Audio.h"
+#include "host.h"

 //extern "C" {
   #include <lua.h>
@@ -18,6 +19,7 @@ using namespace std;
 using namespace z8;

 class Vm {
+    Host* _host;
     PicoRam* _memory;

     Graphics* _graphics;
@@ -48,7 +50,9 @@ class Vm {
     void vm_reload(int destaddr, int sourceaddr, int len, Cart* cart);

     public:
-    Vm(PicoRam* memory = nullptr,
+    Vm(
+       Host* host,
+       PicoRam* memory = nullptr,
        Graphics* graphics = nullptr,
        Input* input = nullptr,
        Audio* audio = nullptr);
@@ -58,9 +62,7 @@ class Vm {

     void LoadCart(string filename);

-    void UpdateAndDraw(
-      uint8_t kdown,
-      uint8_t kheld);
+    void UpdateAndDraw();

     uint8_t* GetPicoInteralFb();
     uint8_t* GetScreenPaletteMap();
@@ -106,5 +108,7 @@ class Vm {
     fix32 api_rnd();
     fix32 api_rnd(fix32 inRange);
     void api_srand(fix32 seed);
+
+    void update_buttons();
 };

diff --git a/test/Makefile b/test/Makefile
index 67f7c72..ed2e441 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -17,7 +17,7 @@ testrunner.a: testroot.o \
 	cartPatcher.o cartpatchertests.o \
 	cart.o carttests.o nooplogger.o lodepng.o emojiconversion.o filehelpers.o utf8-util.o \
 	vm.o endtoendtests.o picoluaapi.o Input.o \
-	vmtests.o \
+	vmtests.o stubhost.o \
 	nibblehelpers.o nibblehelperstests.o \
 	-llua -ldl \
 	-o testrunner.a
@@ -77,15 +77,16 @@ carttests.o: carttests.cpp ../source/cart.cpp ../source/cart.h \
 endtoendtests.o: cartpatchertests.o carttests.o graphicstests.o audiotests.o \
 	endtoendtests.cpp \
 	../source/vm.cpp ../source/vm.h \
+	stubhost.cpp stubhost.h ../source/host.h \
 	../source/Input.cpp ../source/Input.h \
 	../source/picoluaapi.cpp ../source/picoluaapi.h
 	g++ $(CFLAGS) -I$(CURDIR)/include -L$(CURDIR)/lib \
-	endtoendtests.cpp ../source/vm.cpp  ../source/picoluaapi.cpp ../source/Input.cpp
+	endtoendtests.cpp stubhost.cpp ../source/vm.cpp  ../source/picoluaapi.cpp ../source/Input.cpp

 vmtests.o: endtoendtests.o \
-	vmtests.cpp
+	vmtests.cpp stubhost.cpp
 	g++ $(CFLAGS) -I$(CURDIR)/include -L$(CURDIR)/lib \
-	vmtests.cpp ../source/vm.cpp  ../source/picoluaapi.cpp ../source/Input.cpp
+	vmtests.cpp stubhost.cpp ../source/vm.cpp  ../source/picoluaapi.cpp ../source/Input.cpp



diff --git a/test/endtoendtests.cpp b/test/endtoendtests.cpp
index a332d8b..99d2e5f 100644
--- a/test/endtoendtests.cpp
+++ b/test/endtoendtests.cpp
@@ -7,6 +7,7 @@
 #include "../libs/lodepng/lodepng.h"

 #include "../source/vm.h"
+#include "../source/host.h"
 #include "../source/hostVmShared.h"
 #include "../source/nibblehelpers.h"

@@ -64,7 +65,8 @@ bool verifyScreenshot(Vm* vm, std::string screenshotFilename) {
 }

 TEST_CASE("Loading and running carts") {
-    Vm* vm = new Vm();
+    Host* host = new Host();
+    Vm* vm = new Vm(host);

     SUBCASE("Load simple cart"){
         vm->LoadCart("carts/cartparsetest.p8");
@@ -73,9 +75,9 @@ TEST_CASE("Loading and running carts") {
             CHECK(vm->GetBiosError() == "");
         }
         SUBCASE("Frame count updated with each UpdateAndDrawCall()"){
-            vm->UpdateAndDraw(0, 0);
-            vm->UpdateAndDraw(0, 0);
-            vm->UpdateAndDraw(0, 0);
+            vm->UpdateAndDraw();
+            vm->UpdateAndDraw();
+            vm->UpdateAndDraw();

             CHECK(vm->GetFrameCount() == 3);
         }
@@ -98,7 +100,7 @@ TEST_CASE("Loading and running carts") {
             CHECK(vm->GetBiosError() == "");
         }
         SUBCASE("sceen matches screenshot"){
-            vm->UpdateAndDraw(0, 0);
+            vm->UpdateAndDraw();

             CHECK(verifyScreenshot(vm, "carts/screenshots/pset00-test_f01.png"));
         }
@@ -112,7 +114,7 @@ TEST_CASE("Loading and running carts") {
             CHECK(vm->GetBiosError() == "");
         }
         SUBCASE("sceen matches screenshot"){
-            vm->UpdateAndDraw(0, 0);
+            vm->UpdateAndDraw();

             CHECK(verifyScreenshot(vm, "carts/screenshots/pset3pix_f01.png"));
         }
@@ -126,7 +128,7 @@ TEST_CASE("Loading and running carts") {
             CHECK(vm->GetBiosError() == "");
         }
         SUBCASE("sceen matches screenshot"){
-            vm->UpdateAndDraw(0, 0);
+            vm->UpdateAndDraw();

             CHECK(verifyScreenshot(vm, "carts/screenshots/psetall_f01.png"));
         }
@@ -140,7 +142,7 @@ TEST_CASE("Loading and running carts") {
             CHECK(vm->GetBiosError() == "");
         }
         SUBCASE("sceen matches screenshot"){
-            vm->UpdateAndDraw(0, 0);
+            vm->UpdateAndDraw();

             CHECK(verifyScreenshot(vm, "carts/screenshots/cliptest_f01.png"));
         }
@@ -154,7 +156,7 @@ TEST_CASE("Loading and running carts") {
             CHECK(vm->GetBiosError() == "");
         }
         SUBCASE("sceen matches screenshot"){
-            vm->UpdateAndDraw(0, 0);
+            vm->UpdateAndDraw();

             CHECK(verifyScreenshot(vm, "carts/screenshots/memorytest_f01.png"));
         }
@@ -168,7 +170,7 @@ TEST_CASE("Loading and running carts") {
             CHECK(vm->GetBiosError() == "");
         }
         SUBCASE("sceen matches screenshot"){
-            vm->UpdateAndDraw(0, 0);
+            vm->UpdateAndDraw();

             CHECK(verifyScreenshot(vm, "carts/screenshots/cartdatatest_f01.png"));
         }
@@ -179,7 +181,7 @@ TEST_CASE("Loading and running carts") {
         vm->LoadCart("carts/tonumtest2.p8");

         SUBCASE("can parse positive int"){
-            vm->UpdateAndDraw(0, 0);
+            vm->UpdateAndDraw();

             bool parsedCorrectly = vm->ExecuteLua(
                 "function r1test()\n"
@@ -190,7 +192,7 @@ TEST_CASE("Loading and running carts") {
             CHECK(parsedCorrectly);
         }
         SUBCASE("can parse negative decimal") {
-            vm->UpdateAndDraw(0, 0);
+            vm->UpdateAndDraw();

             bool parsedCorrectly = vm->ExecuteLua(
                 "function r2test()\n"
@@ -201,7 +203,7 @@ TEST_CASE("Loading and running carts") {
             CHECK(parsedCorrectly);
         }
         SUBCASE("can parse hex") {
-            vm->UpdateAndDraw(0, 0);
+            vm->UpdateAndDraw();

             bool parsedCorrectly = vm->ExecuteLua(
                 "function r3test()\n"
@@ -213,7 +215,7 @@ TEST_CASE("Loading and running carts") {
         }

        SUBCASE("can parse binary literal") {
-            vm->UpdateAndDraw(0, 0);
+            vm->UpdateAndDraw();

             bool parsedCorrectly = vm->ExecuteLua(
                 "function r5test()\n"
@@ -224,7 +226,7 @@ TEST_CASE("Loading and running carts") {
             CHECK(parsedCorrectly);
         }
         SUBCASE("can parse large positive number") {
-            vm->UpdateAndDraw(0, 0);
+            vm->UpdateAndDraw();

             bool parsedCorrectly = vm->ExecuteLua(
                 "function r6test()\n"
@@ -235,7 +237,7 @@ TEST_CASE("Loading and running carts") {
             CHECK(parsedCorrectly);
         }
         SUBCASE("unparseable string returns nil") {
-            vm->UpdateAndDraw(0, 0);
+            vm->UpdateAndDraw();

             bool parsedCorrectly = vm->ExecuteLua(
                 "function r8test()\n"
@@ -248,7 +250,7 @@ TEST_CASE("Loading and running carts") {

         //currently failing
         SUBCASE("can parse hex with decimal") {
-            vm->UpdateAndDraw(0, 0);
+            vm->UpdateAndDraw();

             bool parsedCorrectly = vm->ExecuteLua(
                 "function r4test()\n"
@@ -261,7 +263,7 @@ TEST_CASE("Loading and running carts") {
         }
         /*
         SUBCASE("too large int overflows") {
-            vm->UpdateAndDraw(0, 0);
+            vm->UpdateAndDraw();

             bool parsedCorrectly = vm->ExecuteLua(
                 "function r7test()\n"
@@ -282,7 +284,7 @@ TEST_CASE("Loading and running carts") {
             CHECK(vm->GetBiosError() == "");
         }
         SUBCASE("addition works"){
-            vm->UpdateAndDraw(0, 0);
+            vm->UpdateAndDraw();

             bool additionWorks = vm->ExecuteLua(
                 "function additiontest()\n"
@@ -293,7 +295,7 @@ TEST_CASE("Loading and running carts") {
             CHECK(additionWorks);
         }
         SUBCASE("multiplication works"){
-            vm->UpdateAndDraw(0, 0);
+            vm->UpdateAndDraw();

             bool multiplicationWorks = vm->ExecuteLua(
                 "function multiplicationtest()\n"
@@ -304,7 +306,7 @@ TEST_CASE("Loading and running carts") {
             CHECK(multiplicationWorks);
         }
         SUBCASE("division works"){
-            vm->UpdateAndDraw(0, 0);
+            vm->UpdateAndDraw();

             bool divisionWorks = vm->ExecuteLua(
                 "function divisiontest()\n"
@@ -315,7 +317,7 @@ TEST_CASE("Loading and running carts") {
             CHECK(divisionWorks);
         }
         SUBCASE("subtraction works"){
-            vm->UpdateAndDraw(0, 0);
+            vm->UpdateAndDraw();

             bool subtractionWorks = vm->ExecuteLua(
                 "function subtractiontest()\n"
@@ -326,7 +328,7 @@ TEST_CASE("Loading and running carts") {
             CHECK(subtractionWorks);
         }
         SUBCASE("rnd returns between 0 and 1, and can add"){
-            vm->UpdateAndDraw(0, 0);
+            vm->UpdateAndDraw();

             bool rndWorks = vm->ExecuteLua(
                 "function rndtest()\n"
@@ -337,7 +339,7 @@ TEST_CASE("Loading and running carts") {
             CHECK(rndWorks);
         }
         SUBCASE("rnd returns between 0 and 1 without calling srand first"){
-            vm->UpdateAndDraw(0, 0);
+            vm->UpdateAndDraw();

             bool rndWorks = vm->ExecuteLua(
                 "function firstrndtest()\n"
@@ -348,7 +350,7 @@ TEST_CASE("Loading and running carts") {
             CHECK(rndWorks);
         }
         SUBCASE("# returns count of array"){
-            vm->UpdateAndDraw(0, 0);
+            vm->UpdateAndDraw();

             bool rndWorks = vm->ExecuteLua(
                 "function counttest()\n"
@@ -359,7 +361,7 @@ TEST_CASE("Loading and running carts") {
             CHECK(rndWorks);
         }
         SUBCASE("ceil works"){
-            vm->UpdateAndDraw(0, 0);
+            vm->UpdateAndDraw();

             bool ceilWorks = vm->ExecuteLua(
                 "function ceiltest()\n"
diff --git a/test/stubhost.cpp b/test/stubhost.cpp
new file mode 100644
index 0000000..ce3a206
--- /dev/null
+++ b/test/stubhost.cpp
@@ -0,0 +1,91 @@
+
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+
+#include <fstream>
+#include <iostream>
+using namespace std;
+
+#include "../source/host.h"
+#include "../source/hostVmShared.h"
+#include "../source/nibblehelpers.h"
+#include "stubhost.h"
+
+
+
+static uint8_t currKDown;
+static uint8_t currKHeld;
+
+
+Host::Host() { }
+StubHost::StubHost() { }
+
+
+void Host::oneTimeSetup(Color* paletteColors){
+
+}
+
+void Host::oneTimeCleanup(){
+
+}
+
+void Host::setTargetFps(int targetFps){
+
+}
+
+void Host::changeStretch(){
+
+}
+
+void StubHost::stubInput(uint8_t kdown, uint8_t kheld) {
+    currKDown = kdown;
+    currKHeld = kheld;
+}
+
+InputState_t Host::scanInput(){
+    return InputState_t {currKDown, currKHeld};
+}
+
+bool Host::shouldQuit() {
+    return false;
+}
+
+void Host::waitForTargetFps(){
+
+}
+
+
+void Host::drawFrame(uint8_t* picoFb, uint8_t* screenPaletteMap){
+
+}
+
+bool Host::shouldFillAudioBuff(){
+    return false;
+}
+
+void* Host::getAudioBufferPointer(){
+    return nullptr;
+}
+
+size_t Host::getAudioBufferSize(){
+    return 0;
+}
+
+void Host::playFilledAudioBuffer(){
+
+}
+
+bool Host::shouldRunMainLoop(){
+    if (shouldQuit()){
+        return false;
+    }
+
+    return true;
+}
+
+vector<string> Host::listcarts(){
+    vector<string> carts;
+
+    return carts;
+}
diff --git a/test/stubhost.h b/test/stubhost.h
new file mode 100644
index 0000000..f461718
--- /dev/null
+++ b/test/stubhost.h
@@ -0,0 +1,9 @@
+#pragma once
+
+#include "../source/host.h"
+
+class StubHost : public Host {
+    public:
+    StubHost();
+    void stubInput(uint8_t kdown, uint8_t kheld);
+};
\ No newline at end of file
diff --git a/test/vmtests.cpp b/test/vmtests.cpp
index b942f48..ce95075 100644
--- a/test/vmtests.cpp
+++ b/test/vmtests.cpp
@@ -5,17 +5,20 @@

 #include "../source/vm.h"
 #include "../source/hostVmShared.h"
+#include "../source/host.h"
+#include "stubhost.h"

 #include "../source/fontdata.h"


 TEST_CASE("Vm memory functions") {
+    StubHost* stubHost = new StubHost();
     PicoRam* memory = new PicoRam();
     Graphics* graphics = new Graphics(get_font_data(), memory);
     Input* input = new Input(memory);
     Audio* audio = new Audio(memory);

-    Vm* vm = new Vm(memory, graphics, input, audio);
+    Vm* vm = new Vm(stubHost, memory, graphics, input, audio);

     SUBCASE("memory data stats with 0"){
         CHECK(memory->data[0] == 0);
@@ -390,7 +393,7 @@ TEST_CASE("Vm memory functions") {
         vm->LoadCart("carts/drillerinputtest.p8");

         SUBCASE("no buttons gives 0"){
-            vm->UpdateAndDraw(0, 0);
+            vm->UpdateAndDraw();
             bool btnbits = vm->ExecuteLua(
                 "function btnbitstest0()\n"
                 " return btnbits == 0\n"
@@ -400,7 +403,8 @@ TEST_CASE("Vm memory functions") {
             CHECK(btnbits);
         }
         SUBCASE("left pushed returns 1"){
-            vm->UpdateAndDraw(1, 1);
+            stubHost->stubInput(1, 1);
+            vm->UpdateAndDraw();
             bool btnbits = vm->ExecuteLua(
                 "function btnbitstest1()\n"
                 " printh(\"hello btnbits: \" .. btnbits .. \"\\\n\")"
@@ -411,7 +415,8 @@ TEST_CASE("Vm memory functions") {
             CHECK(btnbits);
         }
         SUBCASE("right pushed returns 2"){
-            vm->UpdateAndDraw(2, 2);
+            stubHost->stubInput(2, 2);
+            vm->UpdateAndDraw();
             bool btnbits = vm->ExecuteLua(
                 "function btnbitstest2()\n"
                 " return btnbits == 2\n"
@@ -421,7 +426,8 @@ TEST_CASE("Vm memory functions") {
             CHECK(btnbits);
         }
         SUBCASE("right pushed detected by band op"){
-            vm->UpdateAndDraw(2, 2);
+            stubHost->stubInput(2, 2);
+            vm->UpdateAndDraw();
             bool btnbits = vm->ExecuteLua(
                 "function rightbandtest()\n"
                 " return rightband == 2\n"