foxygit / fake-08-xbox360 Log in
commit ab96d92f0780b0f4ae7bf5d5c4927eda88a64f5a
Author:     DPS2004 <dpsophinos@gmail.com>
AuthorDate: Mon Feb 28 11:03:10 2022 -0500
Commit:     DPS2004 <dpsophinos@gmail.com>
CommitDate: Mon Apr 11 11:28:35 2022 -0400

    stat(30) implemented
---
 platform/windows/source/WindowsHost.cpp | 36 +++++++++++++++++++++++++++++++--
 source/Input.cpp                        |  9 +++++++++
 source/Input.h                          |  5 +++++
 source/host.h                           |  3 +++
 source/hostVmShared.h                   |  1 +
 source/picoluaapi.cpp                   |  6 +++---
 source/vm.cpp                           |  2 ++
 7 files changed, 57 insertions(+), 5 deletions(-)

diff --git a/platform/windows/source/WindowsHost.cpp b/platform/windows/source/WindowsHost.cpp
index 38f7c60..2b50a27 100644
--- a/platform/windows/source/WindowsHost.cpp
+++ b/platform/windows/source/WindowsHost.cpp
@@ -28,6 +28,12 @@ using namespace std;
 #define RENDERER_FLAGS SDL_RENDERER_ACCELERATED
 #define PIXEL_FORMAT SDL_PIXELFORMAT_ARGB8888

+#define KB_ENABLED true
+
+
+
+
+
 SDL_Event event;

 string _windowsAppData = SDL_GetPrefPath("FAKE-08", "FAKE-08");
@@ -39,6 +45,10 @@ string _desktopSdl2customBiosLua = "cartpath = \"AppData\"\n"
         "exitbtn = \"close window\"\n"
         "sizebtn = \"\"";

+
+
+
+
 Host::Host()
 {
     struct stat st = {0};
@@ -53,6 +63,9 @@ Host::Host()
         res = mkdir(cartdatadir.c_str(), 0777);
     }

+	#if KB_ENABLED
+	SDL_StartTextInput();
+	#endif

     std::string home = _windowsAppData; // C:\Users\(username)\AppData\Roaming\FAKE-08\FAKE-08\p8carts

@@ -77,9 +90,23 @@ InputState_t Host::scanInput(){
     currKDown = 0;
     currKHeld = 0;
     stretchKeyPressed = false;
-
+
+	currKBDown = false;
+
     while (SDL_PollEvent(&event)) {
         switch (event.type) {
+
+			#if KB_ENABLED
+			case SDL_TEXTINPUT:
+				//Logger_Write(event.text.text);
+				//Logger_Write("\n");
+
+				currKBDown = true;
+
+				break;
+			#endif
+
+
             case SDL_KEYDOWN:
                 switch (event.key.keysym.sym)
                 {
@@ -144,13 +171,18 @@ InputState_t Host::scanInput(){
     if(keystate[SDL_SCANCODE_C]){
         currKHeld |= P8_KEY_X;
     }
+
+	//keyboard stuff
+
+

     return InputState_t {
         currKDown,
         currKHeld,
         (int16_t)mouseX,
         (int16_t)mouseY,
-        picoMouseState
+        picoMouseState,
+		currKBDown
     };
 }

diff --git a/source/Input.cpp b/source/Input.cpp
index f5e3643..8549b81 100644
--- a/source/Input.cpp
+++ b/source/Input.cpp
@@ -56,6 +56,11 @@ void Input::SetMouse(int16_t mouseX, int16_t mouseY, uint8_t mouseBtnState){
     _mouseBtnState = mouseBtnState;
 }

+void Input::SetKeyboard(bool kbDown){
+	_kbDown = kbDown;
+
+}
+
 uint8_t Input::btn(){
     return _memory->hwState.buttonStates[0];
 }
@@ -96,3 +101,7 @@ int16_t Input::getMouseY() {
 uint8_t Input::getMouseBtnState() {
     return _mouseBtnState;
 }
+
+bool Input::getKeyDown() {
+    return _kbDown;
+}
diff --git a/source/Input.h b/source/Input.h
index 2e49d47..b708d64 100644
--- a/source/Input.h
+++ b/source/Input.h
@@ -12,11 +12,14 @@ class Input{
     int16_t _mouseX;
     int16_t _mouseY;
     uint8_t _mouseBtnState;
+	bool _kbDown;

     public:
     Input(PicoRam* memory);
     void SetState(uint8_t kdown, uint8_t kheld);
     void SetMouse(int16_t mouseX, int16_t mouseY, uint8_t mouseBtnState);
+
+    void SetKeyboard(bool kbdown);

 	uint8_t btn();
     uint8_t btnp();
@@ -30,4 +33,6 @@ class Input{
     int16_t getMouseX();
     int16_t getMouseY();
     uint8_t getMouseBtnState();
+
+    bool getKeyDown();
 };
\ No newline at end of file
diff --git a/source/host.h b/source/host.h
index a40aefb..9888e29 100644
--- a/source/host.h
+++ b/source/host.h
@@ -28,6 +28,9 @@ enum PackinLoadOption {
 class Host {
     uint8_t currKDown;
     uint8_t currKHeld;
+
+    bool currKBDown = false;
+
     bool lDown = false;
     bool rDown = false;
     bool stretchKeyPressed = false;
diff --git a/source/hostVmShared.h b/source/hostVmShared.h
index 00aee38..6c9107e 100644
--- a/source/hostVmShared.h
+++ b/source/hostVmShared.h
@@ -72,6 +72,7 @@ struct InputState_t {
 	int16_t mouseX;
 	int16_t mouseY;
 	uint8_t mouseBtnState;
+	bool KBdown;
 };

 enum PrintMode_t
diff --git a/source/picoluaapi.cpp b/source/picoluaapi.cpp
index 53a9fcb..a1307ca 100644
--- a/source/picoluaapi.cpp
+++ b/source/picoluaapi.cpp
@@ -861,12 +861,12 @@ int stat(lua_State *L) {
             lua_pushnumber(L, _audioForLuaApi->getMusicTickCount());
             return 1;
         break;
-        //was a key pressed (always false)
+        //was a key pressed
         case 30:
-            lua_pushboolean(L, false);
+            lua_pushboolean(L, _inputForLuaApi->getKeyDown());
             return 1;
         break;
-        //string of key pressed
+        //string of key pressed (blank for now)
         case 31:
             lua_pushstring(L, "");
             return 1;
diff --git a/source/vm.cpp b/source/vm.cpp
index 92c32dd..80b8b8f 100644
--- a/source/vm.cpp
+++ b/source/vm.cpp
@@ -862,9 +862,11 @@ void Vm::update_buttons() {
     _input->SetState(inputState.KDown, inputState.KHeld);
     if (_memory->drawState.devkitMode) {
         _input->SetMouse(inputState.mouseX, inputState.mouseY, inputState.mouseBtnState);
+		_input->SetKeyboard(inputState.KBdown);
     }
     else {
         _input->SetMouse(0, 0, 0);
+        _input->SetKeyboard(false);
     }
 }