From af5a9f095114bcd0cb3bc6e26cea49aed965017f Mon Sep 17 00:00:00 2001 From: ManDude <7569514+ManDude@users.noreply.github.com> Date: Sat, 14 Aug 2021 01:06:16 +0100 Subject: [PATCH 01/23] minor gfx updates --- game/graphics/display.cpp | 8 ++++++-- game/graphics/display.h | 3 ++- game/graphics/gfx.cpp | 15 ++++++++++----- game/graphics/gfx.h | 30 +++++++++--------------------- game/graphics/pipelines/opengl.cpp | 11 ++++++++--- 5 files changed, 35 insertions(+), 32 deletions(-) diff --git a/game/graphics/display.cpp b/game/graphics/display.cpp index 273641e2d1..a737485381 100644 --- a/game/graphics/display.cpp +++ b/game/graphics/display.cpp @@ -109,6 +109,10 @@ int InitMainDisplay(int width, int height, const char* title, GfxSettings& setti return 0; } +void KillMainDisplay() { + KillDisplay(GetMainDisplay()); +} + void KillDisplay(std::shared_ptr display) { // lg::debug("kill display #x{:x}", (uintptr_t)display); if (!display->is_active()) { @@ -118,8 +122,8 @@ void KillDisplay(std::shared_ptr display) { if (GetMainDisplay() == display) { // killing the main display, kill all children displays too! - for (size_t i = 1; i < g_displays.size(); ++i) { - KillDisplay(g_displays.at(i)); + while (g_displays.size() > 1) { + KillDisplay(g_displays.at(1)); } } diff --git a/game/graphics/display.h b/game/graphics/display.h index da338e324d..d559ff6df2 100644 --- a/game/graphics/display.h +++ b/game/graphics/display.h @@ -33,7 +33,7 @@ class GfxDisplay { void set_renderer(GfxPipeline pipeline); void set_window(GLFWwindow* window); void set_title(const char* title); - const char* get_title() const { return m_title; } + const char* title() const { return m_title; } void render_graphics(); }; @@ -46,6 +46,7 @@ extern std::vector> g_displays; int InitMainDisplay(int width, int height, const char* title, GfxSettings& settings); void KillDisplay(std::shared_ptr display); +void KillMainDisplay(); std::shared_ptr GetMainDisplay(); diff --git a/game/graphics/gfx.cpp b/game/graphics/gfx.cpp index f266554709..0c9c830ecb 100644 --- a/game/graphics/gfx.cpp +++ b/game/graphics/gfx.cpp @@ -3,8 +3,9 @@ * Graphics component for the runtime. Abstraction layer for the main graphics routines. */ -#include "gfx.h" #include + +#include "gfx.h" #include "common/log/log.h" #include "game/runtime.h" #include "display.h" @@ -16,12 +17,18 @@ namespace { // initializes a gfx settings. // TODO save and load from file void InitSettings(GfxSettings& settings) { + // set the current settings version + settings.version = GfxSettings::CURRENT_VERSION; + // use opengl by default for now settings.renderer = Gfx::GetRenderer(GfxPipeline::OpenGL); // Gfx::renderers[0]; // 1 screen update per frame settings.vsync = 1; + // debug for now + settings.debug = true; + return; } @@ -29,8 +36,6 @@ void InitSettings(GfxSettings& settings) { namespace Gfx { -GfxVertex g_vertices_temp[VERTEX_BUFFER_LENGTH_TEMP]; - GfxSettings g_settings; // const std::vector renderers = {&moduleOpenGL}; @@ -53,7 +58,7 @@ u32 Init() { // initialize settings InitSettings(g_settings); - if (g_settings.renderer->init()) { + if (g_settings.renderer->init(g_settings)) { lg::error("Gfx::Init error"); return 1; } @@ -80,7 +85,7 @@ void Loop(std::function f) { u32 Exit() { lg::info("GFX Exit"); - Display::KillDisplay(Display::GetMainDisplay()); + Display::KillMainDisplay(); g_settings.renderer->exit(); return 0; } diff --git a/game/graphics/gfx.h b/game/graphics/gfx.h index 985ed182c3..54e2e7c077 100644 --- a/game/graphics/gfx.h +++ b/game/graphics/gfx.h @@ -19,11 +19,11 @@ enum class GfxPipeline { Invalid = 0, OpenGL }; // module for the different rendering pipelines struct GfxRendererModule { - std::function init; + std::function init; std::function(int w, int h, const char* title, GfxSettings& settings)> make_main_display; - std::function kill_display; - std::function render_display; + std::function kill_display; + std::function render_display; std::function exit; std::function vsync; std::function sync_path; @@ -37,30 +37,18 @@ struct GfxRendererModule { // store settings related to the gfx systems struct GfxSettings { + // current version of the settings. this should be set up so that newer versions are always higher + // than older versions + static constexpr u64 CURRENT_VERSION = 0x0000'0000'00001'0001; + + u64 version; // the version of this settings struct const GfxRendererModule* renderer; // which rendering pipeline to use. - int vsync; // (temp) number of screen update per frame -}; - -// struct for a single vertex. this should in theory be renderer-agnostic -struct GfxVertex { - // x y z - float x, y, z; - - // rgba or the full u32 thing. - union { - u32 rgba; - struct { - u8 r, g, b, a; - }; - }; + bool debug; // graphics debugging }; namespace Gfx { -static constexpr int VERTEX_BUFFER_LENGTH_TEMP = 4096; -extern GfxVertex g_vertices_temp[VERTEX_BUFFER_LENGTH_TEMP]; - extern GfxSettings g_settings; // extern const std::vector renderers; diff --git a/game/graphics/pipelines/opengl.cpp b/game/graphics/pipelines/opengl.cpp index 6fbc44b28d..0c5d81dcc6 100644 --- a/game/graphics/pipelines/opengl.cpp +++ b/game/graphics/pipelines/opengl.cpp @@ -67,7 +67,7 @@ bool HasError() { } // namespace static bool gl_inited = false; -static int gl_init() { +static int gl_init(GfxSettings& settings) { if (glfwSetErrorCallback(ErrorCallback) != NULL) { lg::warn("glfwSetErrorCallback has been re-set!"); } @@ -77,11 +77,16 @@ static int gl_init() { return 1; } - // request Debug OpenGL 3.3 Core + // request an OpenGL 3.3 Core glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // 3.3 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); - // glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE); // debug glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // core profile, not compat + // debug check + if (settings.debug) { + glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE); + } else { + glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_FALSE); + } return 0; } From af823cdb8250fa2ed76bd265f19cc3ce2dcad035 Mon Sep 17 00:00:00 2001 From: ManDude <7569514+ManDude@users.noreply.github.com> Date: Sat, 14 Aug 2021 21:00:50 +0100 Subject: [PATCH 02/23] implement cpad stuff --- game/CMakeLists.txt | 1 + game/graphics/display.cpp | 24 +++--- game/graphics/gfx.cpp | 25 +++++- game/graphics/gfx.h | 9 ++- game/graphics/pipelines/opengl.cpp | 3 + game/kernel/kmachine.cpp | 125 ++++++++++++++++++++++++++--- game/kernel/kmachine.h | 26 ++++-- game/sce/libcdvd_ee.h | 5 -- game/sce/libpad.cpp | 119 +++++++++++++++++++++++++++ game/sce/libpad.h | 57 ++++++++++++- game/system/newpad.cpp | 114 ++++++++++++++++++++++++++ game/system/newpad.h | 74 +++++++++++++++++ goal_src/engine/load/loader.gc | 1 - goal_src/engine/ps2/pad.gc | 45 ++++++++--- 14 files changed, 576 insertions(+), 52 deletions(-) create mode 100644 game/system/newpad.cpp create mode 100644 game/system/newpad.h diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index 01b51fad71..799179e797 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -34,6 +34,7 @@ set(RUNTIME_SOURCE system/IOP_Kernel.cpp system/iop_thread.cpp system/Deci2Server.cpp + system/newpad.cpp sce/libcdvd_ee.cpp sce/libscf.cpp sce/libdma.cpp diff --git a/game/graphics/display.cpp b/game/graphics/display.cpp index a737485381..1d0b50274d 100644 --- a/game/graphics/display.cpp +++ b/game/graphics/display.cpp @@ -8,9 +8,11 @@ #include "common/log/log.h" -/* ****************************** */ -/* Internal functions */ -/* ****************************** */ +/* +******************************** +* Internal functions +******************************** +*/ namespace { @@ -28,9 +30,11 @@ void set_main_display(std::shared_ptr display) { } // namespace -/* ****************************** */ -/* GfxDisplay */ -/* ****************************** */ +/* +******************************** +* GfxDisplay +******************************** +*/ GfxDisplay::GfxDisplay(GLFWwindow* a_window) { set_renderer(GfxPipeline::OpenGL); @@ -81,9 +85,11 @@ void GfxDisplay::render_graphics() { m_renderer->render_display(this); } -/* ****************************** */ -/* DISPLAY */ -/* ****************************** */ +/* +******************************** +* DISPLAY +******************************** +*/ namespace Display { diff --git a/game/graphics/gfx.cpp b/game/graphics/gfx.cpp index 0c9c830ecb..53bc0d58a0 100644 --- a/game/graphics/gfx.cpp +++ b/game/graphics/gfx.cpp @@ -6,11 +6,12 @@ #include #include "gfx.h" +#include "display.h" +#include "pipelines/opengl.h" + #include "common/log/log.h" #include "game/runtime.h" -#include "display.h" - -#include "pipelines/opengl.h" +#include "game/system/newpad.h" namespace { @@ -29,7 +30,14 @@ void InitSettings(GfxSettings& settings) { // debug for now settings.debug = true; - return; + // we're not setting controller info + settings.pad_mapping_info.input_mode = false; + // use buffered input mode + settings.pad_mapping_info.buffer_mode = true; + // debug input settings + settings.pad_mapping_info.debug = true; + // use a default mapping + Pad::DefaultMapping(settings.pad_mapping_info); } } // namespace @@ -57,6 +65,8 @@ u32 Init() { lg::info("GFX Init"); // initialize settings InitSettings(g_settings); + // guarantee we have no keys detected by pad + Pad::ForceClearKeys(); if (g_settings.renderer->init(g_settings)) { lg::error("Gfx::Init error"); @@ -75,6 +85,9 @@ u32 Init() { void Loop(std::function f) { lg::info("GFX Loop"); while (f()) { + // clean the inputs + Pad::ClearKeys(); + // check if we have a display if (Display::GetMainDisplay()) { // lg::debug("run display"); @@ -116,4 +129,8 @@ void texture_relocate(u32 destination, u32 source, u32 format) { } } +int PadIsPressed(Pad::Button button, int port) { + return Pad::IsPressed(g_settings.pad_mapping_info, button, port); +} + } // namespace Gfx diff --git a/game/graphics/gfx.h b/game/graphics/gfx.h index 54e2e7c077..aa81b4ed93 100644 --- a/game/graphics/gfx.h +++ b/game/graphics/gfx.h @@ -7,8 +7,10 @@ #include #include + #include "common/common_types.h" #include "game/kernel/kboot.h" +#include "game/system/newpad.h" // forward declarations struct GfxSettings; @@ -39,12 +41,15 @@ struct GfxRendererModule { struct GfxSettings { // current version of the settings. this should be set up so that newer versions are always higher // than older versions - static constexpr u64 CURRENT_VERSION = 0x0000'0000'00001'0001; + static constexpr u64 CURRENT_VERSION = 0x0000'0000'0002'0001; u64 version; // the version of this settings struct const GfxRendererModule* renderer; // which rendering pipeline to use. int vsync; // (temp) number of screen update per frame bool debug; // graphics debugging + + Pad::MappingInfo pad_mapping_info; // button mapping + Pad::MappingInfo pad_mapping_info_backup; // button mapping backup (see newpad.h) }; namespace Gfx { @@ -64,4 +69,6 @@ void send_chain(const void* data, u32 offset); void texture_upload_now(const u8* tpage, int mode, u32 s7_ptr); void texture_relocate(u32 destination, u32 source, u32 format); +int PadIsPressed(Pad::Button button, int port); + } // namespace Gfx diff --git a/game/graphics/pipelines/opengl.cpp b/game/graphics/pipelines/opengl.cpp index 0c5d81dcc6..e91b050698 100644 --- a/game/graphics/pipelines/opengl.cpp +++ b/game/graphics/pipelines/opengl.cpp @@ -14,6 +14,7 @@ #include "game/graphics/opengl_renderer/OpenGLRenderer.h" #include "game/graphics/texture/TexturePool.h" #include "game/graphics/dma/dma_copy.h" +#include "game/system/newpad.h" #include "common/log/log.h" #include "common/goal_constants.h" #include "game/runtime.h" @@ -50,8 +51,10 @@ void SetDisplayCallbacks(GLFWwindow* d) { glfwSetKeyCallback(d, [](GLFWwindow* /*window*/, int key, int scancode, int action, int mods) { if (action == GlfwKeyAction::Press) { lg::debug("KEY PRESS: key: {} scancode: {} mods: {:X}", key, scancode, mods); + Pad::OnKeyPress(key); } else if (action == GlfwKeyAction::Release) { lg::debug("KEY RELEASE: key: {} scancode: {} mods: {:X}", key, scancode, mods); + Pad::OnKeyRelease(key); } }); } diff --git a/game/kernel/kmachine.cpp b/game/kernel/kmachine.cpp index 7743d90e5e..08147155ad 100644 --- a/game/kernel/kmachine.cpp +++ b/game/kernel/kmachine.cpp @@ -409,27 +409,128 @@ void CacheFlush(void* mem, int size) { * Prints an error if it fails to open. */ u64 CPadOpen(u64 cpad_info, s32 pad_number) { - auto info = Ptr(cpad_info).c(); - if (info->cpad_file == 0) { + auto cpad = Ptr(cpad_info).c(); + if (cpad->cpad_file == 0) { // not open, so we will open it - info->cpad_file = + cpad->cpad_file = ee::scePadPortOpen(pad_number, 0, pad_dma_buf + pad_number * SCE_PAD_DMA_BUFFER_SIZE); - if (info->cpad_file < 1) { - MsgErr("dkernel: !open cpad #%d (%d)\n", pad_number, info->cpad_file); + if (cpad->cpad_file < 1) { + MsgErr("dkernel: !open cpad #%d (%d)\n", pad_number, cpad->cpad_file); } - info->new_pad = 1; - info->state = 0; + cpad->new_pad = 1; + cpad->state = 0; } return cpad_info; } // TODO CPadGetData -void CPadGetData() { - static bool warned = false; - if (!warned) { - lg::warn("ignoring calls to CPadGetData"); - warned = true; +Ptr CPadGetData(u64 cpad_info) { + auto cpad = Ptr(cpad_info).c(); + auto pad_state = scePadGetState(cpad->number, 0); + if (pad_state == scePadStateDiscon) { + cpad->state = 0; } + cpad->valid = pad_state | 0x80; + switch (cpad->state) { + // case 99: // functional + default: // controller is functioning as normal + if (pad_state == scePadStateStable || pad_state == scePadStateFindCTP1) { + scePadRead(cpad->number, 0, (u8*)cpad); + // ps2 controllers would send an enabled bit if the button was NOT pressed, but we don't do + // that here. removed code that flipped the bits. + + if (cpad->change_time != 0) { + scePadSetActDirect(cpad->number, 0, cpad->direct); + } + cpad->valid = pad_state; + } + break; + case 0: // unavailable + if (pad_state == scePadStateStable || pad_state == scePadStateFindCTP1) { + auto pad_mode = scePadInfoMode(cpad->number, 0, InfoModeCurID, 0); + if (pad_mode != 0) { + auto vibration_mode = scePadInfoMode(cpad->number, 0, InfoModeCurExID, 0); + if (vibration_mode > 0) { + // vibration supported + pad_mode = vibration_mode; + } + if (pad_mode == 4) { + // controller mode + cpad->state = 40; + } else if (pad_mode == 7) { + // dualshock mode + cpad->state = 70; + } else { + // who knows mode + cpad->state = 90; + } + } + } + break; + case 40: // controller mode - check for extra modes + cpad->change_time = 0; + if (scePadInfoMode(cpad->number, 0, InfoModeIdTable, -1) == 0) { + // no controller modes + cpad->state = 90; + return make_ptr(cpad); + } + cpad->state = 41; + case 41: // controller mode - change to dualshock mode! + // try to enter the 2nd controller mode (dualshock for ds2's) + if (scePadSetMainMode(cpad->number, 0, 1, 3) == 1) { + cpad->state = 42; + } + break; + case 42: // controller mode change check + if (scePadGetReqState(cpad->number, 0) == scePadReqStateFailed) { + // failed to change to DS2 + cpad->state = 41; + } + if (scePadGetReqState(cpad->number, 0) == scePadReqStateComplete) { + // change successful. go back to the beginning. + cpad->state = 0; + } + break; + case 70: // dualshock mode - check vibration + // get number of actuators (2 for DS2) + if (scePadInfoAct(cpad->number, 0, -1, 0) < 1) { + // no actuators means no vibration. skip to end! + cpad->change_time = 0; + cpad->state = 99; + } else { + // we have actuators to use. + cpad->change_time = 1; // remember to update vibration. + cpad->state = 75; + } + break; + case 75: // set actuator vib param info + if (scePadSetActAlign(cpad->number, 0, cpad->align) != 0) { + if (scePadInfoPressMode(cpad->number, 0) == 1) { + // pressure buttons supported + cpad->state = 76; + } else { + // no pressure buttons, done with controller setup + cpad->state = 99; + } + } + break; + case 76: // enter pressure mode + if (scePadEnterPressMode(cpad->number, 0) == 1) { + cpad->state = 78; + } + break; + case 78: // pressure mode request check + if (scePadGetReqState(cpad->number, 0) == 1) { + cpad->state = 76; + } + if (scePadGetReqState(cpad->number, 0) == 0) { + cpad->state = 99; + } + break; + case 90: + break; // unsupported controller. too bad! + } + return make_ptr(cpad); } // TODO InstallHandler diff --git a/game/kernel/kmachine.h b/game/kernel/kmachine.h index 6056c95e1f..092f8696b3 100644 --- a/game/kernel/kmachine.h +++ b/game/kernel/kmachine.h @@ -89,21 +89,33 @@ void CacheFlush(void* mem, int size); void InitMachineScheme(); //! Mirror of cpad-info -struct CpadInfo { +struct CPadInfo { u8 valid; u8 status; - s16 button0; - u8 rx; - u8 ry; - u8 lx; - u8 ly; + u16 button0; + u8 rightx; + u8 righty; + u8 leftx; + u8 lefty; u8 abutton[12]; u8 dummy[12]; s32 number; s32 cpad_file; - u8 _pad0[36]; + u32 button0_abs[3]; + u32 button0_shadow_abs[1]; + u32 button0_rel[3]; + float stick0_dir; + float stick0_speed; s32 new_pad; s32 state; + u8 align[6]; + u8 direct[6]; + u8 buzz_val[2]; + u8 __pad[2]; + u64 buzz_time[2]; + u32 buzz; + s32 buzz_act; + s32 change_time; // actually u64 in goal! }; struct FileStream { diff --git a/game/sce/libcdvd_ee.h b/game/sce/libcdvd_ee.h index 1fea511f7c..21b03278d1 100644 --- a/game/sce/libcdvd_ee.h +++ b/game/sce/libcdvd_ee.h @@ -5,9 +5,6 @@ * Stub implementation of the EE CD/DVD library */ -#ifndef JAK1_LIBCDVD_EE_H -#define JAK1_LIBCDVD_EE_H - // for sceCdInit #define SCECdINIT 0x00 @@ -34,5 +31,3 @@ int sceCdMmode(int media); int sceCdDiskReady(int mode); int sceCdGetDiskType(); } // namespace ee - -#endif // JAK1_LIBCDVD_EE_H diff --git a/game/sce/libpad.cpp b/game/sce/libpad.cpp index a263bb7028..5a8fee20a2 100644 --- a/game/sce/libpad.cpp +++ b/game/sce/libpad.cpp @@ -1,7 +1,16 @@ #include "common/util/assert.h" #include "libpad.h" +#include "game/kernel/kmachine.h" +#include "game/graphics/gfx.h" + +/*! + * @file libpad.h + * Stub implementation of the EE pad (controller) library + */ + namespace ee { + int scePadPortOpen(int port, int slot, void*) { // we are expected to return a non-zero file descriptor. // we return the port + 1 and succeed always. @@ -9,4 +18,114 @@ int scePadPortOpen(int port, int slot, void*) { assert(slot == 0); return port + 1; } + +int scePadGetState(int port, int slot) { + // pretend we always have a controller connected + return scePadStateStable; +} + +// controller mode array for DS2s +// the game will try very hard to force into dualshock mode so let's not even try +static const int libpad_DualShock2_ModeIDs[2] = { + (int)PadMode::Controller, // no vibration or pressure sensitive buttons + (int)PadMode::DualShock2 // vibration + pressure sensitive buttons +}; +int scePadInfoMode(int port, int slot, int term, int offs) { + if (term == InfoModeCurExID) { + // return vibration mode ID. that's just dualshock mode. + return libpad_DualShock2_ModeIDs[1]; + + } else if (term == InfoModeCurID) { + // return mode ID. just dualshock. + return libpad_DualShock2_ModeIDs[1]; + + } else if (term == InfoModeCurExOffs) { + // offset of current mode ID + return 1; + + } else if (term == InfoModeIdTable) { + if (offs == -1) + return 2; + + return libpad_DualShock2_ModeIDs[offs]; // ? + } + + // invalid controller or some other error + return 0; +} + +// order of pressure sensitive buttons in memory (not the same as their bit order...). +static const Pad::Button libpad_PadPressureButtons[] = { + Pad::Button::Right, Pad::Button::Left, Pad::Button::Up, Pad::Button::Down, + Pad::Button::Triangle, Pad::Button::Circle, Pad::Button::X, Pad::Button::Square, + Pad::Button::L1, Pad::Button::R1, Pad::Button::L2, Pad::Button::R2}; +// reads controller data and writes it to a buffer in rdata (must be at least 32 bytes large). +// returns buffer size (32) or 0 on error. +int scePadRead(int port, int slot, u8* rdata) { + auto cpad = (CPadInfo*)(rdata); + + cpad->valid = 0; // success + cpad->status = 0x70 /* (dualshock2) */ | (20 / 2); /* (dualshock2 data size) */ + + cpad->rightx = 0; + cpad->righty = 0; + cpad->leftx = 0; + cpad->lefty = 0; + + // pressure sensitivity. ignore for now. + for (int i = 0; i < 12; ++i) { + cpad->abutton[i] = Gfx::PadIsPressed(libpad_PadPressureButtons[i], port) * 255; + } + + cpad->button0 = 0; + for (int i = 0; i < 16; ++i) { + cpad->button0 |= Gfx::PadIsPressed((Pad::Button)i, port) << i; + } + + return 32; +} + +// buzzer control. We don't care right now, return success. +int scePadSetActDirect(int port, int slot, const u8* data) { + return 1; +} +int scePadSetActAlign(int port, int slot, const u8* data) { + return 1; +} + +// we also don't care +int scePadSetMainMode(int port, int slot, int offs, int lock) { + return 1; +} + +// async pad functions are gonna be synchronous so this always succeeds +int scePadGetReqState(int port, int slot) { + return scePadReqStateComplete; +} + +int scePadInfoAct(int port, int slot, int actno, int term) { + if (actno == -1) + return 2; // i think? + if (actno < 2) { + if (term == InfoActSub) { + return 1; // whatever + } else if (term == InfoActFunc) { + return 1; // whatever + } else if (term == InfoActSize) { + return 0; // whatever + } else if (term == InfoActCurr) { + return 1; // whatever + } + } + return 0; +} + +int scePadInfoPressMode(int port, int slot) { + return 0; // we do NOT support pressure sensitive buttons right now +} + +int scePadEnterPressMode(int port, int slot) { + return 1; // we dont support pressure button, but if we did this would work straight away +} + } // namespace ee diff --git a/game/sce/libpad.h b/game/sce/libpad.h index a2c80f60b7..04fa75dd01 100644 --- a/game/sce/libpad.h +++ b/game/sce/libpad.h @@ -1,7 +1,62 @@ #pragma once +/*! + * @file libpad.h + * Stub implementation of the EE pad (controller) library + */ + +#include "common/common_types.h" + #define SCE_PAD_DMA_BUFFER_SIZE 0x100 +// pad status +#define scePadStateDiscon 0 +#define scePadStateFindPad 1 +#define scePadStateFindCTP1 2 +#define scePadStateExecCmd 5 +#define scePadStateStable 6 +#define scePadStateError 7 +#define scePadStateClosed 99 + +// pad mode info checks +#define InfoModeCurID 1 +#define InfoModeCurExID 2 +#define InfoModeCurExOffs 3 +#define InfoModeIdTable 4 + +// pad async request states +#define scePadReqStateComplete 0 +#define scePadReqStateFaild 1 // lol +#define scePadReqStateFailed 1 +#define scePadReqStateBusy 2 + +// pad actuator info checks +#define InfoActFunc 1 +#define InfoActSub 2 +#define InfoActSize 3 +#define InfoActCurr 4 + namespace ee { + +// controller modes (not in the lib) +enum PadMode { + Controller = 4, + DualShock = 7, + DualShock2 = DualShock, + NeGcon = 2, + Joystick = 5, + NamcoGun = 6 +}; + int scePadPortOpen(int port, int slot, void* data); -} \ No newline at end of file +int scePadGetState(int port, int slot); +int scePadInfoMode(int port, int slot, int term, int offs); +int scePadRead(int port, int slot, u8* rdata); +int scePadSetActDirect(int port, int slot, const u8* data); +int scePadSetActAlign(int port, int slot, const u8* data); +int scePadSetMainMode(int port, int slot, int offs, int lock); +int scePadGetReqState(int port, int slot); +int scePadInfoAct(int port, int slot, int actno, int term); +int scePadInfoPressMode(int port, int slot); +int scePadEnterPressMode(int port, int slot); +} diff --git a/game/system/newpad.cpp b/game/system/newpad.cpp new file mode 100644 index 0000000000..834b962b20 --- /dev/null +++ b/game/system/newpad.cpp @@ -0,0 +1,114 @@ +/*! + * @file newpad.cpp + * PC-port specific cpad implementation on the C kernel. Monitors button inputs. + * Actual input detection is done through window events and is gfx pipeline-dependent. + */ + +#include "newpad.h" +#include "common/log/log.h" + +#include "game/graphics/pipelines/opengl.h" // for GLFW macros + +namespace Pad { + +/* +******************************** +* Key checking +******************************** +*/ + +std::unordered_map g_key_status; +std::unordered_map g_buffered_key_status; + +void ForceClearKeys() { + g_key_status.clear(); + g_buffered_key_status.clear(); +} + +void ClearKeys() { + for (auto& key : g_key_status) { + key.second = false; + } + for (auto& key : g_buffered_key_status) { + key.second = false; + } +} + +void OnKeyPress(int key) { + // set absolute key status + if (g_key_status.find(key) == g_key_status.end()) { + g_key_status.insert(std::make_pair(key, 1)); + } else { + g_key_status.at(key) = 1; + } + + // set buffered key status + if (g_buffered_key_status.find(key) == g_buffered_key_status.end()) { + g_buffered_key_status.insert(std::make_pair(key, 1)); + } else { + g_buffered_key_status.at(key) = 1; + } +} + +void OnKeyRelease(int key) { + // set absolute key status + // no bounds checking for now in order to catch bugs + g_key_status.at(key) = 0; +} + +/* +******************************** +* Pad checking +******************************** +*/ + +static int CheckPadIdx(int pad) { + if (pad < 0 || pad > CONTROLLER_COUNT) { + lg::error("Invalid pad {}, returning pad 0", pad); + } + return 0; +} + +// returns 1 if button is pressed. returns 0 if invalid or not pressed. +int IsPressed(MappingInfo& mapping, Button button, int pad = 0) { + auto key = mapping.pad_mapping[CheckPadIdx(pad)][(int)button]; + if (key == -1) + return 0; + auto& keymap = mapping.buffer_mode ? g_buffered_key_status : g_key_status; + if (keymap.find(key) == keymap.end()) + return 0; + return keymap.at(key); +} + +// map a button on a pad to a key +void MapButton(MappingInfo& mapping, Button button, int pad, int key) { + // check if pad is valid. dont map buttons with invalid pads. + if (CheckPadIdx(pad) != pad) + return; + + mapping.pad_mapping[pad][(int)button] = key; +} + +// reset button mappings +void DefaultMapping(MappingInfo& mapping) { + // make every button invalid + for (int p = 0; p < CONTROLLER_COUNT; ++p) { + for (int i = 0; i < (int)Button::Max; ++i) { + MapButton(mapping, (Button)i, p, -1); + } + } + + // face buttons + MapButton(mapping, Button::Ecks, 0, GLFW_KEY_Z); + MapButton(mapping, Button::Square, 0, GLFW_KEY_X); + MapButton(mapping, Button::Triangle, 0, GLFW_KEY_S); + MapButton(mapping, Button::Circle, 0, GLFW_KEY_A); + + // dpad + MapButton(mapping, Button::Up, 0, GLFW_KEY_UP); + MapButton(mapping, Button::Right, 0, GLFW_KEY_RIGHT); + MapButton(mapping, Button::Down, 0, GLFW_KEY_DOWN); + MapButton(mapping, Button::Left, 0, GLFW_KEY_LEFT); +} + +}; // namespace Pad diff --git a/game/system/newpad.h b/game/system/newpad.h new file mode 100644 index 0000000000..7d0d9b7e9a --- /dev/null +++ b/game/system/newpad.h @@ -0,0 +1,74 @@ +#pragma once + +/*! + * @file newpad.h + * PC-port specific cpad implementation on the C kernel. Monitors button inputs. + * Actual input detection is done through window events and is gfx pipeline-dependent. + */ + +/* NOTE ABOUT KEY VALUES! + * I am using the renderer-dependent key value macros here (at least for now). This means that the + * button mapping may be renderer-dependent. When changing renderers, make sure to backup the + * original button mapping or something so that the user can reset it afterwards. Eventually we + * should fix this (or maybe it's not even a problem). + */ + +#include + +namespace Pad { + +static constexpr int CONTROLLER_COUNT = 2; // support 2 controllers. + +// mirrors goal enum pad-buttons. used as indices to an array! +enum class Button { + Select = 0, + L3 = 1, + R3 = 2, + Start = 3, + + Up = 4, + Right = 5, + Down = 6, + Left = 7, + + L2 = 8, + R2 = 9, + L1 = 10, + R1 = 11, + + Triangle = 12, + Circle = 13, + X = 14, + Square = 15, + + Max = 16, + + // aliases + Ecks = X, + Cross = X, + O = Circle +}; + +struct MappingInfo { + bool debug = true; // debug mode + bool input_mode = false; // input mode for controller mapping + bool buffer_mode = true; // use buffered inputs + int pad_mapping[CONTROLLER_COUNT][(int)Pad::Button::Max]; // controller button mapping + // TODO complex button mapping & key macros (e.g. shift+x for l2+r2 press etc.) +}; + +// key-down status of any detected key. +extern std::unordered_map g_key_status; +// key-down status of any detected key. this is buffered for the remainder of a frame. +extern std::unordered_map g_buffered_key_status; + +void OnKeyPress(int key); +void OnKeyRelease(int key); +void ForceClearKeys(); +void ClearKeys(); + +void DefaultMapping(MappingInfo& mapping); +int IsPressed(MappingInfo& mapping, Button button, int pad); +void MapButton(MappingInfo& mapping, Button button, int pad, int key); + +} // namespace Pad diff --git a/goal_src/engine/load/loader.gc b/goal_src/engine/load/loader.gc index 857453dbc6..9b119d6374 100644 --- a/goal_src/engine/load/loader.gc +++ b/goal_src/engine/load/loader.gc @@ -214,7 +214,6 @@ (defmethod link-art! art-group ((obj art-group)) "Links the elements of this art-group." - ;; this check seems superfluous (when obj (countdown (s5-0 (-> obj length)) (let* ((art-elt (-> obj data s5-0)) diff --git a/goal_src/engine/ps2/pad.gc b/goal_src/engine/ps2/pad.gc index e8f9d93d65..d7ec50a5ac 100644 --- a/goal_src/engine/ps2/pad.gc +++ b/goal_src/engine/ps2/pad.gc @@ -30,7 +30,15 @@ (x 14) (square 15) ) - + +(defenum pad-type + (normal 4) + (analog 5) + (dualshock 7) + (negcon 2) + (namco-gun 6) + ) + ;; these forward declarations should probably go somewhere else... (define-extern get-current-time (function uint)) (define-extern get-integral-current-time (function uint)) @@ -38,16 +46,25 @@ ;; this gets set to #f later on. (define *cheat-mode* #t) -;; data that comes directly from hardware. +;; data that comes directly from hardware. it's 32 bytes + type tag (ignored in C kernel). (deftype hw-cpad (basic) - ((valid uint8 :offset-assert 4) - (status uint8 :offset-assert 5) - (button0 uint16 :offset-assert 6) - (rightx uint8 :offset-assert 8) - (righty uint8 :offset-assert 9) - (leftx uint8 :offset-assert 10) - (lefty uint8 :offset-assert 11) - (abutton uint8 12 :offset-assert 12) + (;; BASIC CONTROLLER data + ;; status = 0x40 | (data length / 2) + (valid uint8 :offset-assert 4) ;; 0 if success, 255 if fail + (status uint8 :offset-assert 5) ;; depends on controller + (button0 uint16 :offset-assert 6) ;; binary button states! + ;; DUALSHOCK or JOYSTICK data + ;; status (dualshock) = 0x70 | (data length / 2) + ;; status (joystick) = 0x50 | (data length / 2) + (rightx uint8 :offset-assert 8) ;; right stick xdir + (righty uint8 :offset-assert 9) ;; right stick ydir + (leftx uint8 :offset-assert 10) ;; left stick xdir + (lefty uint8 :offset-assert 11) ;; left stick ydir + ;; DUALSHOCK 2 data + ;; status = 0x70 | (data length / 2) + (abutton uint8 12 :offset-assert 12) ;; pressure sensitivity information + + ;; pad buffer needs to be 32 bytes large. (dummy uint8 12 :offset-assert 24) ) :method-count-assert 9 @@ -57,7 +74,7 @@ ;; data from hardware + additional info calculated here. (deftype cpad-info (hw-cpad) - ((number int32 :offset-assert 36) + ((number int32 :offset-assert 36) ;; controller port number (cpad-file int32 :offset-assert 40) (button0-abs pad-buttons 3 :offset-assert 44) ;; bitmask of buttons, pressed or not, with history (button0-shadow-abs pad-buttons 1 :offset-assert 56) ;; modify this to change button history in the future. @@ -66,7 +83,7 @@ (stick0-speed float :offset-assert 76) (new-pad int32 :offset-assert 80) (state int32 :offset-assert 84) - (align uint8 6 :offset-assert 88) + (align uint8 6 :offset-assert 88) ;; hardware control of buzzing. (direct uint8 6 :offset-assert 94) ;; hardware control of buzzing. (buzz-val uint8 2 :offset-assert 100) ;; intensity for buzzing (buzz-time uint64 2 :offset-assert 104) ;; when to stop buzzing @@ -82,6 +99,10 @@ :flag-assert #x900000088 ) +(defmacro cpad-type? (type) + `(= (shr (-> pad status) 4) (cpad-type ,type)) + ) + (defun cpad-invalid! ((pad cpad-info)) "Reset all data in a cpad-info" (logior! (-> pad valid) 128) From ded9d63afa70d2d68f1ae9e3a684b69c9208840e Mon Sep 17 00:00:00 2001 From: ManDude <7569514+ManDude@users.noreply.github.com> Date: Sat, 14 Aug 2021 21:05:38 +0100 Subject: [PATCH 03/23] fixes --- game/graphics/gfx.h | 10 +++++----- game/kernel/kmachine.cpp | 4 ++-- game/sce/libpad.h | 36 ++++++++++++++++++------------------ game/system/newpad.h | 8 ++++---- 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/game/graphics/gfx.h b/game/graphics/gfx.h index aa81b4ed93..3b89a57c38 100644 --- a/game/graphics/gfx.h +++ b/game/graphics/gfx.h @@ -43,13 +43,13 @@ struct GfxSettings { // than older versions static constexpr u64 CURRENT_VERSION = 0x0000'0000'0002'0001; - u64 version; // the version of this settings struct + u64 version; // the version of this settings struct const GfxRendererModule* renderer; // which rendering pipeline to use. - int vsync; // (temp) number of screen update per frame - bool debug; // graphics debugging + int vsync; // (temp) number of screen update per frame + bool debug; // graphics debugging - Pad::MappingInfo pad_mapping_info; // button mapping - Pad::MappingInfo pad_mapping_info_backup; // button mapping backup (see newpad.h) + Pad::MappingInfo pad_mapping_info; // button mapping + Pad::MappingInfo pad_mapping_info_backup; // button mapping backup (see newpad.h) }; namespace Gfx { diff --git a/game/kernel/kmachine.cpp b/game/kernel/kmachine.cpp index 08147155ad..6f61f62ded 100644 --- a/game/kernel/kmachine.cpp +++ b/game/kernel/kmachine.cpp @@ -520,10 +520,10 @@ Ptr CPadGetData(u64 cpad_info) { } break; case 78: // pressure mode request check - if (scePadGetReqState(cpad->number, 0) == 1) { + if (scePadGetReqState(cpad->number, 0) == scePadReqStateFailed) { cpad->state = 76; } - if (scePadGetReqState(cpad->number, 0) == 0) { + if (scePadGetReqState(cpad->number, 0) == scePadReqStateComplete) { cpad->state = 99; } break; diff --git a/game/sce/libpad.h b/game/sce/libpad.h index 04fa75dd01..5574da73cb 100644 --- a/game/sce/libpad.h +++ b/game/sce/libpad.h @@ -10,31 +10,31 @@ #define SCE_PAD_DMA_BUFFER_SIZE 0x100 // pad status -#define scePadStateDiscon 0 -#define scePadStateFindPad 1 +#define scePadStateDiscon 0 +#define scePadStateFindPad 1 #define scePadStateFindCTP1 2 -#define scePadStateExecCmd 5 -#define scePadStateStable 6 -#define scePadStateError 7 -#define scePadStateClosed 99 +#define scePadStateExecCmd 5 +#define scePadStateStable 6 +#define scePadStateError 7 +#define scePadStateClosed 99 // pad mode info checks -#define InfoModeCurID 1 -#define InfoModeCurExID 2 +#define InfoModeCurID 1 +#define InfoModeCurExID 2 #define InfoModeCurExOffs 3 -#define InfoModeIdTable 4 +#define InfoModeIdTable 4 // pad async request states -#define scePadReqStateComplete 0 -#define scePadReqStateFaild 1 // lol -#define scePadReqStateFailed 1 -#define scePadReqStateBusy 2 +#define scePadReqStateComplete 0 +#define scePadReqStateFaild 1 // lol +#define scePadReqStateFailed 1 +#define scePadReqStateBusy 2 // pad actuator info checks -#define InfoActFunc 1 -#define InfoActSub 2 -#define InfoActSize 3 -#define InfoActCurr 4 +#define InfoActFunc 1 +#define InfoActSub 2 +#define InfoActSize 3 +#define InfoActCurr 4 namespace ee { @@ -59,4 +59,4 @@ int scePadGetReqState(int port, int slot); int scePadInfoAct(int port, int slot, int actno, int term); int scePadInfoPressMode(int port, int slot); int scePadEnterPressMode(int port, int slot); -} +} // namespace ee diff --git a/game/system/newpad.h b/game/system/newpad.h index 7d0d9b7e9a..0514b48c9f 100644 --- a/game/system/newpad.h +++ b/game/system/newpad.h @@ -17,7 +17,7 @@ namespace Pad { -static constexpr int CONTROLLER_COUNT = 2; // support 2 controllers. +static constexpr int CONTROLLER_COUNT = 2; // support 2 controllers. // mirrors goal enum pad-buttons. used as indices to an array! enum class Button { @@ -50,9 +50,9 @@ enum class Button { }; struct MappingInfo { - bool debug = true; // debug mode - bool input_mode = false; // input mode for controller mapping - bool buffer_mode = true; // use buffered inputs + bool debug = true; // debug mode + bool input_mode = false; // input mode for controller mapping + bool buffer_mode = true; // use buffered inputs int pad_mapping[CONTROLLER_COUNT][(int)Pad::Button::Max]; // controller button mapping // TODO complex button mapping & key macros (e.g. shift+x for l2+r2 press etc.) }; From ca8f0f7e9313618646edc4ea79e328d84acef625 Mon Sep 17 00:00:00 2001 From: ManDude <7569514+ManDude@users.noreply.github.com> Date: Sat, 14 Aug 2021 23:23:45 +0100 Subject: [PATCH 04/23] minor fixes --- game/sce/libpad.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/game/sce/libpad.cpp b/game/sce/libpad.cpp index 5a8fee20a2..5a61cd9175 100644 --- a/game/sce/libpad.cpp +++ b/game/sce/libpad.cpp @@ -5,7 +5,7 @@ #include "game/graphics/gfx.h" /*! - * @file libpad.h + * @file libpad.cpp * Stub implementation of the EE pad (controller) library */ @@ -64,7 +64,8 @@ static const Pad::Button libpad_PadPressureButtons[] = { int scePadRead(int port, int slot, u8* rdata) { auto cpad = (CPadInfo*)(rdata); - cpad->valid = 0; // success + cpad->valid = 0; // success + cpad->status = 0x70 /* (dualshock2) */ | (20 / 2); /* (dualshock2 data size) */ cpad->rightx = 0; From ff3174f29278a5afd708169cdf6ffe434d745287 Mon Sep 17 00:00:00 2001 From: ManDude <7569514+ManDude@users.noreply.github.com> Date: Mon, 16 Aug 2021 03:50:36 +0100 Subject: [PATCH 05/23] more cpad stuff + make `font-flags` --- decompiler/config/all-types.gc | 32 ++++-- game/graphics/gfx.cpp | 6 +- game/graphics/gfx.h | 2 + game/graphics/pipelines/opengl.cpp | 15 ++- game/kernel/kmachine.cpp | 18 +++- game/kernel/kscheme.cpp | 8 -- game/sce/libpad.cpp | 1 + game/system/newpad.cpp | 35 +++++- game/system/newpad.h | 10 +- goal_src/engine/debug/debug.gc | 2 +- goal_src/engine/debug/menu.gc | 2 +- goal_src/engine/game/main.gc | 16 +-- goal_src/engine/gfx/font-h.gc | 46 +++++--- goal_src/engine/gfx/font.gc | 8 +- goal_src/engine/gfx/hw/display.gc | 8 +- goal_src/engine/ps2/memcard-h.gc | 2 +- goal_src/engine/sound/gsound.gc | 8 +- goal_src/engine/target/logic-target.gc | 9 +- goal_src/engine/ui/credits.gc | 8 +- goal_src/engine/ui/text.gc | 6 +- goal_src/examples/debug-draw-example.gc | 3 + goal_src/kernel-defs.gc | 18 ++-- goal_src/kernel/gkernel-h.gc | 2 +- goal_src/kernel/gstate.gc | 14 +++ goal_src/pc_debug/pc-pad-utils.gc | 100 ++++++++++++++++++ .../reference/engine/debug/debug_REF.gc | 2 +- .../reference/engine/debug/menu_REF.gc | 2 +- .../reference/engine/gfx/font-h_REF.gc | 10 +- .../reference/engine/gfx/hw/display_REF.gc | 15 ++- .../reference/engine/nav/navigate-h_REF.gc | 2 +- .../reference/engine/ps2/memcard-h_REF.gc | 2 +- .../reference/engine/sound/gsound_REF.gc | 8 +- .../reference/engine/ui/credits_REF.gc | 8 +- .../reference/levels/common/nav-enemy_REF.gc | 2 +- 34 files changed, 309 insertions(+), 121 deletions(-) create mode 100644 goal_src/pc_debug/pc-pad-utils.gc diff --git a/decompiler/config/all-types.gc b/decompiler/config/all-types.gc index 281db45696..0699db3688 100644 --- a/decompiler/config/all-types.gc +++ b/decompiler/config/all-types.gc @@ -5223,7 +5223,7 @@ (another-gray 17) (dark-dark-green 18) (flat-dark-purple 19) - (yellow 20) + (flat-yellow 20) (blue-white 21) (flat-dark-gray 22) (flat-gray 23) @@ -5235,9 +5235,29 @@ (yellow-orange 29) (yellow-green-2 30) (another-light-blue 31) - (another-default 32) + (light-yellow 32) (red-orange 33) (another-orange-red 34) + + (red 3) + (red2 4) + (yellow 5) + (green 6) + (blue 7) + (cyan 10) + (red-reverse 33) + (red-obverse 34) + ) + +(defenum font-flags + :type uint32 + :bitfield #t + (shadow 0) + (kerning 1) + (middle 2) + (left 3) + (right 4) + (large 5) ) (deftype font-context (basic) @@ -5249,7 +5269,7 @@ (context-vec vector :inline :offset 48) ;; added (color font-color :offset-assert 64) (color-s32 int32 :offset 64) ;; added for asm - (flags uint32 :offset-assert 72) + (flags font-flags :offset-assert 72) (flags-signed int32 :offset 72) ;; added for asm (mat matrix :offset-assert 76) (start-line uint32 :offset-assert 80) @@ -5259,7 +5279,7 @@ :size-assert #x58 :flag-assert #x1400000058 (:methods - (new (symbol type matrix int int float font-color uint) _type_ 0) + (new (symbol type matrix int int float font-color font-flags) _type_ 0) (set-mat! (font-context matrix) font-context 9) (set-origin! (font-context int int) font-context 10) (set-depth! (font-context int) font-context 11) @@ -5268,7 +5288,7 @@ (set-height! (font-context int) font-context 14) (set-projection! (font-context float) font-context 15) (set-color! (font-context font-color) font-context 16) - (set-flags! (font-context uint) font-context 17) + (set-flags! (font-context font-flags) font-context 17) (set-start-line! (font-context uint) font-context 18) (set-scale! (font-context float) font-context 19) ) @@ -5363,7 +5383,7 @@ (define-extern set-display-env (function display-env int int int int int int display-env)) (define-extern set-draw-env (function draw-env int int int int int int draw-env)) (define-extern get-video-mode (function symbol)) -(define-extern draw-string-xy (function string dma-buffer int int font-color int none)) +(define-extern draw-string-xy (function string dma-buffer int int font-color font-flags none)) (define-extern set-draw-env-offset (function draw-env int int int draw-env)) (define-extern put-display-alpha-env (function display-env none)) (define-extern set-display2 (function display int int int int int display)) diff --git a/game/graphics/gfx.cpp b/game/graphics/gfx.cpp index 53bc0d58a0..a4bc089019 100644 --- a/game/graphics/gfx.cpp +++ b/game/graphics/gfx.cpp @@ -30,8 +30,6 @@ void InitSettings(GfxSettings& settings) { // debug for now settings.debug = true; - // we're not setting controller info - settings.pad_mapping_info.input_mode = false; // use buffered input mode settings.pad_mapping_info.buffer_mode = true; // debug input settings @@ -129,6 +127,10 @@ void texture_relocate(u32 destination, u32 source, u32 format) { } } +void poll_events() { + g_settings.renderer->poll_events(); +} + int PadIsPressed(Pad::Button button, int port) { return Pad::IsPressed(g_settings.pad_mapping_info, button, port); } diff --git a/game/graphics/gfx.h b/game/graphics/gfx.h index 3b89a57c38..431090d0e5 100644 --- a/game/graphics/gfx.h +++ b/game/graphics/gfx.h @@ -32,6 +32,7 @@ struct GfxRendererModule { std::function send_chain; std::function texture_upload_now; std::function texture_relocate; + std::function poll_events; GfxPipeline pipeline; const char* name; @@ -68,6 +69,7 @@ u32 sync_path(); void send_chain(const void* data, u32 offset); void texture_upload_now(const u8* tpage, int mode, u32 s7_ptr); void texture_relocate(u32 destination, u32 source, u32 format); +void poll_events(); int PadIsPressed(Pad::Button button, int port); diff --git a/game/graphics/pipelines/opengl.cpp b/game/graphics/pipelines/opengl.cpp index e91b050698..b134df27e0 100644 --- a/game/graphics/pipelines/opengl.cpp +++ b/game/graphics/pipelines/opengl.cpp @@ -50,10 +50,10 @@ std::unique_ptr g_gfx_data; void SetDisplayCallbacks(GLFWwindow* d) { glfwSetKeyCallback(d, [](GLFWwindow* /*window*/, int key, int scancode, int action, int mods) { if (action == GlfwKeyAction::Press) { - lg::debug("KEY PRESS: key: {} scancode: {} mods: {:X}", key, scancode, mods); + // lg::debug("KEY PRESS: key: {} scancode: {} mods: {:X}", key, scancode, mods); Pad::OnKeyPress(key); } else if (action == GlfwKeyAction::Release) { - lg::debug("KEY RELEASE: key: {} scancode: {} mods: {:X}", key, scancode, mods); + // lg::debug("KEY RELEASE: key: {} scancode: {} mods: {:X}", key, scancode, mods); Pad::OnKeyRelease(key); } }); @@ -145,6 +145,9 @@ static void gl_kill_display(GfxDisplay* display) { static void gl_render_display(GfxDisplay* display) { GLFWwindow* window = display->window_glfw; + // poll events + glfwPollEvents(); + glfwMakeContextCurrent(window); // wait for a copied chain. @@ -182,10 +185,9 @@ static void gl_render_display(GfxDisplay* display) { { std::unique_lock lock(g_gfx_data->sync_mutex); g_gfx_data->frame_idx++; + g_gfx_data->sync_cv.notify_all(); } - // poll events TODO integrate input with cpad - glfwPollEvents(); // exit if display window was closed if (glfwWindowShouldClose(window)) { @@ -271,6 +273,10 @@ void gl_texture_relocate(u32 destination, u32 source, u32 format) { } } +void gl_poll_events() { + glfwPollEvents(); +} + const GfxRendererModule moduleOpenGL = { gl_init, // init gl_make_main_display, // make_main_display @@ -282,6 +288,7 @@ const GfxRendererModule moduleOpenGL = { gl_send_chain, // send_chain gl_texture_upload_now, // texture_upload_now gl_texture_relocate, // texture_relocate + gl_poll_events, // poll_events GfxPipeline::OpenGL, // pipeline "OpenGL 3.0" // name }; diff --git a/game/kernel/kmachine.cpp b/game/kernel/kmachine.cpp index 6f61f62ded..30cc6dd578 100644 --- a/game/kernel/kmachine.cpp +++ b/game/kernel/kmachine.cpp @@ -36,6 +36,7 @@ #include "game/graphics/dma/dma_copy.h" #include "game/system/vm/vm.h" +#include "game/system/newpad.h" using namespace ee; /*! @@ -423,8 +424,7 @@ u64 CPadOpen(u64 cpad_info, s32 pad_number) { return cpad_info; } -// TODO CPadGetData -Ptr CPadGetData(u64 cpad_info) { +u64 CPadGetData(u64 cpad_info) { auto cpad = Ptr(cpad_info).c(); auto pad_state = scePadGetState(cpad->number, 0); if (pad_state == scePadStateDiscon) { @@ -472,7 +472,7 @@ Ptr CPadGetData(u64 cpad_info) { if (scePadInfoMode(cpad->number, 0, InfoModeIdTable, -1) == 0) { // no controller modes cpad->state = 90; - return make_ptr(cpad); + return cpad_info; } cpad->state = 41; case 41: // controller mode - change to dualshock mode! @@ -530,7 +530,7 @@ Ptr CPadGetData(u64 cpad_info) { case 90: break; // unsupported controller. too bad! } - return make_ptr(cpad); + return cpad_info; } // TODO InstallHandler @@ -715,6 +715,16 @@ void InitMachine_PCPort() { make_function_symbol_from_c("__send-gfx-dma-chain", (void*)send_gfx_dma_chain); make_function_symbol_from_c("__pc-texture-upload-now", (void*)pc_texture_upload_now); make_function_symbol_from_c("__pc-texture-relocate", (void*)pc_texture_relocate); + + // pad stuff + make_function_symbol_from_c("pc-pad-input-mode-set", (void*)Pad::input_mode_set); + make_function_symbol_from_c("pc-pad-input-mode-get", (void*)Pad::input_mode_get); + + // init ps2 VM + if (VM::use) { + make_function_symbol_from_c("vm-ptr", (void*)VM::get_vm_ptr); + VM::vm_init(); + } } void vif_interrupt_callback() { diff --git a/game/kernel/kscheme.cpp b/game/kernel/kscheme.cpp index b6084d79a4..3e1d29ccfa 100644 --- a/game/kernel/kscheme.cpp +++ b/game/kernel/kscheme.cpp @@ -24,8 +24,6 @@ #include "common/log/log.h" #include "common/util/Timer.h" -#include "game/system/vm/vm.h" - //! Controls link mode when EnableMethodSet = 0, MasterDebug = 1, DiskBoot = 0. Will enable a //! warning message if EnableMethodSet = 1 u32 FastLink; @@ -1966,12 +1964,6 @@ s32 InitHeapAndSymbol() { // set *boot-video-mode* intern_from_c("*boot-video-mode*")->value = 0; - // OpenGOAL only - init ps2 VM - if (VM::use) { - make_function_symbol_from_c("vm-ptr", (void*)VM::get_vm_ptr); - VM::vm_init(); - } - lg::info("Initialized GOAL heap in {:.2} ms", heap_init_timer.getMs()); // load the kernel! // todo, remove MasterUseKernel diff --git a/game/sce/libpad.cpp b/game/sce/libpad.cpp index 5a61cd9175..fb5a0fe1de 100644 --- a/game/sce/libpad.cpp +++ b/game/sce/libpad.cpp @@ -63,6 +63,7 @@ static const Pad::Button libpad_PadPressureButtons[] = { // returns buffer size (32) or 0 on error. int scePadRead(int port, int slot, u8* rdata) { auto cpad = (CPadInfo*)(rdata); + Gfx::poll_events(); cpad->valid = 0; // success diff --git a/game/system/newpad.cpp b/game/system/newpad.cpp index 834b962b20..0a5ec76e5b 100644 --- a/game/system/newpad.cpp +++ b/game/system/newpad.cpp @@ -8,6 +8,7 @@ #include "common/log/log.h" #include "game/graphics/pipelines/opengl.h" // for GLFW macros +#include "game/kernel/kscheme.h" namespace Pad { @@ -20,21 +21,32 @@ namespace Pad { std::unordered_map g_key_status; std::unordered_map g_buffered_key_status; +// input mode for controller mapping +bool input_mode = false; +u64 input_mode_key = -1; +u64 input_mode_mod = 0; + void ForceClearKeys() { g_key_status.clear(); g_buffered_key_status.clear(); } void ClearKeys() { + g_buffered_key_status.clear(); for (auto& key : g_key_status) { - key.second = false; - } - for (auto& key : g_buffered_key_status) { - key.second = false; + g_buffered_key_status.insert(std::make_pair(key.first, key.second)); } } void OnKeyPress(int key) { + if (input_mode) { + if (key == GLFW_KEY_ESCAPE) { + input_mode = false; + return; + } + input_mode_key = key; + return; + } // set absolute key status if (g_key_status.find(key) == g_key_status.end()) { g_key_status.insert(std::make_pair(key, 1)); @@ -51,6 +63,9 @@ void OnKeyPress(int key) { } void OnKeyRelease(int key) { + if (input_mode) { + return; + } // set absolute key status // no bounds checking for now in order to catch bugs g_key_status.at(key) = 0; @@ -111,4 +126,16 @@ void DefaultMapping(MappingInfo& mapping) { MapButton(mapping, Button::Left, 0, GLFW_KEY_LEFT); } +void input_mode_set(u32 enable) { + if (enable != s7.offset) { + input_mode = true; + } else { + input_mode = false; + } +} + +u64 input_mode_get() { + return input_mode_key; +} + }; // namespace Pad diff --git a/game/system/newpad.h b/game/system/newpad.h index 0514b48c9f..a2cd77cc89 100644 --- a/game/system/newpad.h +++ b/game/system/newpad.h @@ -14,6 +14,7 @@ */ #include +#include "common/common_types.h" namespace Pad { @@ -50,9 +51,9 @@ enum class Button { }; struct MappingInfo { - bool debug = true; // debug mode - bool input_mode = false; // input mode for controller mapping - bool buffer_mode = true; // use buffered inputs + bool debug = true; // debug mode + bool buffer_mode = true; // use buffered inputs + int pad_mapping[CONTROLLER_COUNT][(int)Pad::Button::Max]; // controller button mapping // TODO complex button mapping & key macros (e.g. shift+x for l2+r2 press etc.) }; @@ -71,4 +72,7 @@ void DefaultMapping(MappingInfo& mapping); int IsPressed(MappingInfo& mapping, Button button, int pad); void MapButton(MappingInfo& mapping, Button button, int pad, int key); +void input_mode_set(u32 enable); +u64 input_mode_get(); + } // namespace Pad diff --git a/goal_src/engine/debug/debug.gc b/goal_src/engine/debug/debug.gc index ca97504b89..60bef85c49 100644 --- a/goal_src/engine/debug/debug.gc +++ b/goal_src/engine/debug/debug.gc @@ -214,7 +214,7 @@ ) 0.0 font-color-id - (the-as uint 3) + (font-flags shadow kerning) ))) (let ((v1-9 a2-2)) (set! (-> v1-9 origin z) (the float (/ (-> s2-0 z) 16))) diff --git a/goal_src/engine/debug/menu.gc b/goal_src/engine/debug/menu.gc index c178378b7d..3e3883ebb4 100644 --- a/goal_src/engine/debug/menu.gc +++ b/goal_src/engine/debug/menu.gc @@ -38,7 +38,7 @@ (set! (-> gp-0 root-menu) #f) (set! (-> gp-0 joypad-func) #f) (set! (-> gp-0 joypad-item) #f) - (set! (-> gp-0 font) (new 'debug 'font-context *font-default-matrix* 0 0 0.0 (font-color default) (the-as uint 3))) + (set! (-> gp-0 font) (new 'debug 'font-context *font-default-matrix* 0 0 0.0 (font-color default) (font-flags shadow kerning))) gp-0 ) ) diff --git a/goal_src/engine/game/main.gc b/goal_src/engine/game/main.gc index 18983ed3ee..ebf5babe2e 100644 --- a/goal_src/engine/game/main.gc +++ b/goal_src/engine/game/main.gc @@ -1146,7 +1146,7 @@ (when *display-deci-count* (let ((s2-1 draw-string-xy)) (format (clear *temp-string*) "~D" *deci-count*) - (s2-1 *temp-string* debug-buf 448 210 (font-color default) 3) + (s2-1 *temp-string* debug-buf 448 210 (font-color default) (font-flags shadow kerning)) ) ) @@ -1183,7 +1183,7 @@ (if (= *master-mode* 'pause) (draw-string-xy (lookup-text! *common-text* (game-text-id pause) #f) - s3-1 256 160 (font-color orange-red) 39) + s3-1 256 160 (font-color orange-red) (font-flags shadow kerning middle large)) ) ;; draw console text on screen @@ -1193,7 +1193,7 @@ (the int (-> *font-context* origin x)) a3-8 (font-color default) - 3 + (font-flags shadow kerning) ) ) @@ -1277,14 +1277,8 @@ ) ) (set! *run* #t) - ;; this is actually a macro (see logic-target.gc) - (let ((new-dproc (swhen (get-process *4k-dead-pool* process (* 16 1024)) - ((method-of-type process activate) bc *display-pool* 'display *kernel-dram-stack*) - ((the (function cpu-thread function object) set-to-run) (-> bc main-thread) display-loop) - (-> bc ppointer) - )) - ) - (set! *dproc* (the process (if new-dproc (-> new-dproc 0 self)))) + (let ((new-dproc (make-function-process *4k-dead-pool* *display-pool* process 'display display-loop))) + (set! *dproc* (the process (as-process new-dproc))) ) (cond ((or (level-get-with-status *level* 'loaded) diff --git a/goal_src/engine/gfx/font-h.gc b/goal_src/engine/gfx/font-h.gc index d8f49ed058..4ab76e8e1c 100644 --- a/goal_src/engine/gfx/font-h.gc +++ b/goal_src/engine/gfx/font-h.gc @@ -8,14 +8,6 @@ ;; The font system draws all of the strings. ;; The font textures live in the upper 8 bits of the 24-bit texture format depth buffer. -;; flags -;; 1 -;; 2 -;; 4 -;; 8 -;; 16 -;; 32 (use size 24) - (defenum font-color :type uint64 (default 0) @@ -38,7 +30,7 @@ (another-gray 17) (dark-dark-green 18) (flat-dark-purple 19) - (yellow 20) + (flat-yellow 20) (blue-white 21) (flat-dark-gray 22) (flat-gray 23) @@ -50,9 +42,29 @@ (yellow-orange 29) (yellow-green-2 30) (another-light-blue 31) - (another-default 32) + (light-yellow 32) (red-orange 33) (another-orange-red 34) + + (red 3) + (red2 4) + (yellow 5) + (green 6) + (blue 7) + (cyan 10) + (red-reverse 33) + (red-obverse 34) + ) + +(defenum font-flags + :type uint32 + :bitfield #t + (shadow 0) + (kerning 1) + (middle 2) + (left 3) + (right 4) + (large 5) ) (deftype char-verts (structure) @@ -92,7 +104,7 @@ (context-vec vector :inline :offset 48) ;; added (color font-color :offset-assert 64) (color-s32 int32 :offset 64) ;; added for asm - (flags uint32 :offset-assert 72) + (flags font-flags :offset-assert 72) (flags-signed int32 :offset 72) ;; added for asm (mat matrix :offset-assert 76) (start-line uint32 :offset-assert 80) @@ -102,7 +114,7 @@ :size-assert #x58 :flag-assert #x1400000058 (:methods - (new (symbol type matrix int int float font-color uint) _type_ 0) + (new (symbol type matrix int int float font-color font-flags) _type_ 0) (set-mat! (font-context matrix) font-context 9) (set-origin! (font-context int int) font-context 10) (set-depth! (font-context int) font-context 11) @@ -111,7 +123,7 @@ (set-height! (font-context int) font-context 14) (set-projection! (font-context float) font-context 15) (set-color! (font-context font-color) font-context 16) - (set-flags! (font-context uint) font-context 17) + (set-flags! (font-context font-flags) font-context 17) (set-start-line! (font-context uint) font-context 18) (set-scale! (font-context float) font-context 19) ) @@ -176,7 +188,7 @@ obj ) -(defmethod set-flags! font-context ((obj font-context) (flags uint)) +(defmethod set-flags! font-context ((obj font-context) (flags font-flags)) (declare (inline)) (set! (-> obj flags) flags) @@ -197,7 +209,7 @@ obj ) -(defmethod new font-context ((allocation symbol) (type-to-make type) (mat matrix) (x int) (y int) (z float) (color font-color) (flags uint)) +(defmethod new font-context ((allocation symbol) (type-to-make type) (mat matrix) (x int) (y int) (z float) (color font-color) (flags font-flags)) (let ((obj (object-new allocation type-to-make (the-as int (-> type-to-make size))) @@ -280,7 +292,7 @@ (buf basic :offset-assert 3024) (str-ptr uint32 :offset-assert 3028) (str-ptr-signed (pointer uint8) :offset 3028) ;; added - (flags uint32 :offset-assert 3032) + (flags font-flags :offset-assert 3032) (flags-signed int32 :offset 3032) ;; added (reg-save uint32 5 :offset-assert 3036) ) @@ -750,4 +762,4 @@ (define-extern draw-string (function string dma-buffer font-context float)) -(define-extern draw-string-xy (function string dma-buffer int int font-color int none)) \ No newline at end of file +(define-extern draw-string-xy (function string dma-buffer int int font-color font-flags none)) \ No newline at end of file diff --git a/goal_src/engine/gfx/font.gc b/goal_src/engine/gfx/font.gc index 4969f9ae64..3c8aefc303 100644 --- a/goal_src/engine/gfx/font.gc +++ b/goal_src/engine/gfx/font.gc @@ -826,7 +826,7 @@ (.mov.vf vf2 vf0) (.mov.vf vf3 vf0) (.mov.vf vf4 vf0) - (set! (-> fw flags) (the-as uint flags)) + (set! (-> fw flags) (the-as font-flags flags)) (.lvf vf16 (&-> fw size-st1 quad)) (.lvf vf17 (&-> fw size-st2 quad)) (.lvf vf18 (&-> fw size-st3 quad)) @@ -2081,7 +2081,7 @@ (.mul.vf vf24 vf24 vf1 :mask #b11) (let ((a1-4 *font-work*)) (set! (-> a1-4 str-ptr) (the-as uint arg0)) - (set! (-> a1-4 flags) (the-as uint v1-0)) + (set! (-> a1-4 flags) (the-as font-flags v1-0)) (.mov.vf vf1 vf0) (let ((a2-0 (logand v1-0 32))) (nop!) @@ -2231,7 +2231,7 @@ ) ) -(defun draw-string-xy ((arg0 string) (arg1 dma-buffer) (arg2 int) (arg3 int) (arg4 font-color) (arg5 int)) +(defun draw-string-xy ((arg0 string) (arg1 dma-buffer) (arg2 int) (arg3 int) (arg4 font-color) (arg5 font-flags)) ;(format #t "call to ds: ~A~%" arg0) (let ((a2-2 (new 'stack 'font-context *font-default-matrix* @@ -2239,7 +2239,7 @@ arg3 0.0 arg4 - (the-as uint arg5) + arg5 ) ) ) diff --git a/goal_src/engine/gfx/hw/display.gc b/goal_src/engine/gfx/hw/display.gc index 62e59dd448..aa255dac85 100644 --- a/goal_src/engine/gfx/hw/display.gc +++ b/goal_src/engine/gfx/hw/display.gc @@ -280,8 +280,8 @@ ) -(define *font-context* (new 'global 'font-context *font-default-matrix* 0 24 0.0 (font-color default) (the uint 3))) -(define *pause-context* (new 'global 'font-context *font-default-matrix* 256 170 0.0 (font-color orange-red) (the uint 3))) +(define *font-context* (new 'global 'font-context *font-default-matrix* 0 24 0.0 (font-color default) (font-flags shadow kerning))) +(define *pause-context* (new 'global 'font-context *font-default-matrix* 256 170 0.0 (font-color orange-red) (font-flags shadow kerning))) @@ -410,7 +410,7 @@ (cond (*profile-ticks* (draw-string-xy (string-format "~5D" (-> worst-time-cache (/ bar-pos 10))) - buf 488 (+ bar-pos 8) (font-color default) 17) + buf 488 (+ bar-pos 8) (font-color default) (font-flags shadow right)) (the float (-> worst-time-cache (/ bar-pos 10))) ) (else @@ -423,7 +423,7 @@ ))) (draw-string-xy (string-format "~5,,2f" f30-0) buf 488 (+ bar-pos 8) (if (>= f30-0 100.0) (font-color orange-red) (font-color default)) ;; turn red if over 100. - 17 + (font-flags shadow right) ) f30-0 ) diff --git a/goal_src/engine/ps2/memcard-h.gc b/goal_src/engine/ps2/memcard-h.gc index 90c6518773..45f0ee802d 100644 --- a/goal_src/engine/ps2/memcard-h.gc +++ b/goal_src/engine/ps2/memcard-h.gc @@ -93,7 +93,7 @@ ) ) ) - (draw-string-xy *temp-string* dma-buf 32 (+ (* 12 slot-idx) 8) (font-color orange-red) 1) + (draw-string-xy *temp-string* dma-buf 32 (+ (* 12 slot-idx) 8) (font-color orange-red) (font-flags shadow)) ) ) (none) diff --git a/goal_src/engine/sound/gsound.gc b/goal_src/engine/sound/gsound.gc index 993bc02200..56d90b212b 100644 --- a/goal_src/engine/sound/gsound.gc +++ b/goal_src/engine/sound/gsound.gc @@ -734,12 +734,12 @@ (dotimes (ch 24) (draw-string-xy (if (zero? (-> *sound-iop-info* chinfo ch)) "." "X") - buf (+ (* ch 16) 16) 48 (font-color default) 1) + buf (+ (* ch 16) 16) 48 (font-color default) (font-flags shadow)) ) (dotimes (ch 24) (draw-string-xy (if (zero? (-> *sound-iop-info* chinfo (+ ch 24))) "." "X") - buf (+ (* ch 16) 16) 64 (font-color default) 1) + buf (+ (* ch 16) 16) 64 (font-color default) (font-flags shadow)) ) 0 ) @@ -748,11 +748,11 @@ (draw-string-xy (string-format "~8D [~4D]" (-> *sound-iop-info* freemem) (shr (-> *sound-iop-info* freemem) 10)) - buf 32 96 (font-color default) 1) + buf 32 96 (font-color default) (font-flags shadow)) (draw-string-xy (string-format "~8D [~4D]" (-> *sound-iop-info* freemem2) (shr (-> *sound-iop-info* freemem2) 10)) - buf 32 64 (font-color default) 1) + buf 32 64 (font-color default) (font-flags shadow)) 0 ) diff --git a/goal_src/engine/target/logic-target.gc b/goal_src/engine/target/logic-target.gc index 349829350f..feec857c14 100644 --- a/goal_src/engine/target/logic-target.gc +++ b/goal_src/engine/target/logic-target.gc @@ -32,14 +32,7 @@ (set! (-> *level* border?) #f) (set! (-> *setting-control* default border-mode) #f) (stop game-mode) - ;; this is also that same macro... i just have no idea how to write it. - (let* ((s5-0 (the target (get-process *target-dead-pool* target #x4000))) - (v1-3 (when s5-0 - ((method-of-type target activate) s5-0 *target-pool* 'target *kernel-dram-stack*) - ((the (function object object object object) run-function-in-process) s5-0 init-target cont) - (-> s5-0 ppointer) - )) - ) + (let ((v1-3 (make-function-process *target-dead-pool* *target-pool* target 'target init-target cont))) (if v1-3 (set! *target* (the target (-> v1-3 0 self))) (set! *target* #f) diff --git a/goal_src/engine/ui/credits.gc b/goal_src/engine/ui/credits.gc index ce918151ef..8e2b7711e0 100644 --- a/goal_src/engine/ui/credits.gc +++ b/goal_src/engine/ui/credits.gc @@ -60,7 +60,7 @@ 0 0.0 (font-color default) - (the-as uint 3) + (font-flags shadow kerning) ) ) ) @@ -71,7 +71,7 @@ (let ((v1-4 gp-0)) (set! (-> v1-4 height) (the float 10)) ) - (set! (-> gp-0 flags) (the-as uint 38)) + (set! (-> gp-0 flags) (font-flags kerning middle large)) (let* ((s5-1 (- s5-0 (mod s5-0 3))) (f0-10 (- f30-0 (the float s5-1))) ) @@ -137,7 +137,7 @@ (gp-0 2815) (s3-0 0) (s2-0 #t) - (s5-0 (new 'stack 'font-context *font-default-matrix* 31 0 0.0 (font-color default) (the-as uint 3))) + (s5-0 (new 'stack 'font-context *font-default-matrix* 31 0 0.0 (font-color default) (font-flags shadow kerning))) ) (let ((v1-2 s5-0)) (set! (-> v1-2 width) (the float 450)) @@ -148,7 +148,7 @@ (let ((v1-4 s5-0)) (set! (-> v1-4 scale) 1.0) ) - (set! (-> s5-0 flags) (the-as uint 39)) + (set! (-> s5-0 flags) (font-flags shadow kerning middle large)) (while (or s2-0 (and (< s4-0 (- s3-0)) (< (the-as uint gp-0) (the-as uint 3249)))) (+! s4-0 s3-0) (+! gp-0 1) diff --git a/goal_src/engine/ui/text.gc b/goal_src/engine/ui/text.gc index 6b1e19283a..8a53fb2c10 100644 --- a/goal_src/engine/ui/text.gc +++ b/goal_src/engine/ui/text.gc @@ -437,7 +437,7 @@ (the int (-> font-ctxt origin y)) 0.0 (font-color default) - (the-as uint 3) + (font-flags shadow kerning) ) ) ) @@ -453,8 +453,8 @@ (set! (-> gp-0 flags) (-> font-ctxt flags)) (set! (-> gp-0 color) (-> font-ctxt color)) (set! (-> gp-0 scale) sv-136) - (when (logtest? (-> gp-0 flags) 8) - (set! (-> gp-0 flags) (logand -9 (-> gp-0 flags))) + (when (logtest? (-> gp-0 flags) (font-flags left)) + (logclear! (-> gp-0 flags) (font-flags left)) (let ((f30-0 (-> gp-0 width)) (f28-0 (-> gp-0 height)) ) diff --git a/goal_src/examples/debug-draw-example.gc b/goal_src/examples/debug-draw-example.gc index 1c045dc74c..a5a50b08ac 100644 --- a/goal_src/examples/debug-draw-example.gc +++ b/goal_src/examples/debug-draw-example.gc @@ -1,3 +1,6 @@ +;;-*-Lisp-*- +(in-package goal) + ;; This file demonstrates how to use the debug draw. ;; To run this: diff --git a/goal_src/kernel-defs.gc b/goal_src/kernel-defs.gc index 358e57931d..e474ed451d 100644 --- a/goal_src/kernel-defs.gc +++ b/goal_src/kernel-defs.gc @@ -148,13 +148,11 @@ ;; gs-get-imr (define-extern gs-store-image (function object object object)) (define-extern flush-cache (function int none)) -;; cpad-open (declare-type cpad-info basic) (define-extern cpad-open (function cpad-info int cpad-info)) (define-extern cpad-get-data (function cpad-info cpad-info)) (define-extern install-handler (function int (function int) int)) ;; check return val ;; install-debug-handler -;; file-stream-open (define-extern file-stream-open (function file-stream basic basic file-stream)) (define-extern file-stream-close (function file-stream file-stream)) (define-extern file-stream-length (function file-stream int)) @@ -178,13 +176,6 @@ ;; *kernel-boot-mode* ;; *kernel-boot-level* -;; PC Port functions -(define-extern __read-ee-timer (function uint)) -(define-extern __mem-move (function pointer pointer uint none)) -(define-extern __send-gfx-dma-chain (function object object none)) -(define-extern __pc-texture-upload-now (function object object none)) -(define-extern __pc-texture-relocate (function object object object none)) - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; ksound - InitSoundScheme ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -269,6 +260,15 @@ :no-runtime-type ;; already constructed, don't do it again. ) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;; PC Port functions +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +(define-extern __read-ee-timer (function uint)) +(define-extern __mem-move (function pointer pointer uint none)) +(define-extern __send-gfx-dma-chain (function object object none)) +(define-extern __pc-texture-upload-now (function object object none)) +(define-extern __pc-texture-relocate (function object object object none)) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; vm functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/goal_src/kernel/gkernel-h.gc b/goal_src/kernel/gkernel-h.gc index b9e9ec2559..023742fd1f 100644 --- a/goal_src/kernel/gkernel-h.gc +++ b/goal_src/kernel/gkernel-h.gc @@ -455,7 +455,7 @@ ) -;; Not sure what this is, but it's probably used in the event system. +;; this is used for the event system to pass around parameters from one process to another. (deftype event-message-block (structure) ((to process :offset-assert 0) (from process :offset-assert 4) diff --git a/goal_src/kernel/gstate.gc b/goal_src/kernel/gstate.gc index cc1300809f..28c4c4852a 100644 --- a/goal_src/kernel/gstate.gc +++ b/goal_src/kernel/gstate.gc @@ -80,6 +80,20 @@ There are several ways to "go" ) ) +(defmacro make-function-process (dead-pool new-pool proc-type proc-name func &key (stack-size #x4000) &key (stack *kernel-dram-stack*) &rest args) + "Start a new process that runs a function on its main thread. Returns a pointer to the new process (or #f)." + + (with-gensyms (new-proc) + `(let ((,new-proc (get-process ,dead-pool ,proc-type ,stack-size))) + (when ,new-proc + ((method-of-type ,proc-type activate) (the-as ,proc-type ,new-proc) ,new-pool ,proc-name ,stack) + (run-now-in-process ,new-proc ,func ,@args) + (-> ,new-proc ppointer) + ) + ) + ) + ) + ;; display a listing of active processes. (defmacro ps (&key (detail #f)) `(inspect-process-tree *active-pool* 0 0 ,detail) diff --git a/goal_src/pc_debug/pc-pad-utils.gc b/goal_src/pc_debug/pc-pad-utils.gc new file mode 100644 index 0000000000..66247dc3cf --- /dev/null +++ b/goal_src/pc_debug/pc-pad-utils.gc @@ -0,0 +1,100 @@ +;;-*-Lisp-*- +(in-package goal) + + +;; This file is used for debugging and testing the PC port pad (controller/input) implementation. +;; It contains a function for creating a process for debugging cpad inputs and a function to kill that process. +;; It also contains a function to start a process to map keys to cpad inputs (X, circle, etc.), and another one to kill it. +;; THIS FILE IS DEBUG ONLY and will not work if *debug-segment* is not enabled. + +;; To run this: + +#| +(make-group "iso") ;; build the game +(lt) ;; connect to the runtime +(lg) ;; have the runtime load the game engine +(test-play) ;; start the game loop +(ml "goal_src/pc_debug/pc-pad-utils.gc") ;; build and load this file. +|# + +(if *debug-segment* (begin + +(define *pc-pad-show-proc* (the handle #f)) +(define *pc-pad-input-proc* (the handle #f)) + +(defun-debug pc-pad-show-start () + "Start the PC port pad debug display" + + (if (not (handle->process *pc-pad-show-proc*)) + (set! *pc-pad-show-proc* (ppointer->handle + (make-function-process *nk-dead-pool* *active-pool* process 'pc-pad-show + (lambda :behavior process () + (stack-size-set! (-> self main-thread) 512) + (loop + (let ((cpad (-> *cpad-list* cpads 0))) + (format *stdcon* "~3Lcpad 0~%~0L") + (format *stdcon* "~Tbutton0: ~X~%" (-> cpad button0)) + (format *stdcon* "~Tbutton0-abs 0: ~X~%" (-> cpad button0-abs 0)) + (format *stdcon* "~Tbutton0-abs 1: ~X~%" (-> cpad button0-abs 1)) + (format *stdcon* "~Tbutton0-abs 2: ~X~%" (-> cpad button0-abs 2)) + (format *stdcon* "~Tbutton0-rel 0: ~X~%" (-> cpad button0-rel 0)) + (format *stdcon* "~Tbutton0-rel 1: ~X~%" (-> cpad button0-rel 1)) + (format *stdcon* "~Tbutton0-rel 2: ~X~%" (-> cpad button0-rel 2)) + ) + (suspend) + ) + ) + ) + )) + + (format #t "That process is already running. :-)") + ) + ) + +(defun-debug pc-pad-show-stop () + "Stop the PC port pad debug display" + + (kill-by-name 'pc-pad-show *active-pool*) + ) + +(defun-debug pc-pad-input-start () + "Start the PC port pad debug key mapping" + + (if (not (handle->process *pc-pad-input-proc*)) + (set! *pc-pad-input-proc* (ppointer->handle + (make-function-process *nk-dead-pool* *active-pool* process 'pc-pad-input + (lambda :behavior process () + (stack-size-set! (-> self main-thread) 512) + (let ((start-time (get-current-time)) + (time-passed 0)) + (loop + (set! time-passed (- (the int (get-current-time)) start-time)) + + (with-dma-buffer-add-bucket ((buf (current-display-frame debug-buf)) + (current-display-frame bucket-group) + (bucket-id debug-draw1)) + (if (< (mod time-passed (seconds 2)) (seconds 1)) + (draw-string-xy "NOW MAPPING PAD" buf 256 64 (font-color red) (font-flags shadow kerning large middle)) + ) + + ) + + (suspend) + ) + ) + ) + ) + )) + + (format #t "That process is already running. :-)") + ) + ) + +(defun-debug pc-pad-input-stop () + "Stop the PC port pad debug key mapping" + + (kill-by-name 'pc-pad-input *active-pool*) + ) + +) +(format #t "No debug memory in use. pc-pad-utils not loaded.")) \ No newline at end of file diff --git a/test/decompiler/reference/engine/debug/debug_REF.gc b/test/decompiler/reference/engine/debug/debug_REF.gc index 2cb4169d05..7d4c298cd5 100644 --- a/test/decompiler/reference/engine/debug/debug_REF.gc +++ b/test/decompiler/reference/engine/debug/debug_REF.gc @@ -422,7 +422,7 @@ ) 0.0 arg3 - (the-as uint 3) + (font-flags shadow kerning) ) ) ) diff --git a/test/decompiler/reference/engine/debug/menu_REF.gc b/test/decompiler/reference/engine/debug/menu_REF.gc index f283695fd7..35b59e3c16 100644 --- a/test/decompiler/reference/engine/debug/menu_REF.gc +++ b/test/decompiler/reference/engine/debug/menu_REF.gc @@ -59,7 +59,7 @@ 0 0.0 (font-color default) - (the-as uint 3) + (font-flags shadow kerning) ) ) gp-0 diff --git a/test/decompiler/reference/engine/gfx/font-h_REF.gc b/test/decompiler/reference/engine/gfx/font-h_REF.gc index 4fad551113..5e5a10ec5e 100644 --- a/test/decompiler/reference/engine/gfx/font-h_REF.gc +++ b/test/decompiler/reference/engine/gfx/font-h_REF.gc @@ -61,7 +61,7 @@ (context-vec vector :inline :offset 48) (color font-color :offset-assert 64) (color-s32 int32 :offset 64) - (flags uint32 :offset-assert 72) + (flags font-flags :offset-assert 72) (flags-signed int32 :offset 72) (mat matrix :offset-assert 76) (start-line uint32 :offset-assert 80) @@ -71,7 +71,7 @@ :size-assert #x58 :flag-assert #x1400000058 (:methods - (new (symbol type matrix int int float font-color uint) _type_ 0) + (new (symbol type matrix int int float font-color font-flags) _type_ 0) (set-mat! (font-context matrix) font-context 9) (set-origin! (font-context int int) font-context 10) (set-depth! (font-context int) font-context 11) @@ -80,7 +80,7 @@ (set-height! (font-context int) font-context 14) (set-projection! (font-context float) font-context 15) (set-color! (font-context font-color) font-context 16) - (set-flags! (font-context uint) font-context 17) + (set-flags! (font-context font-flags) font-context 17) (set-start-line! (font-context uint) font-context 18) (set-scale! (font-context float) font-context 19) ) @@ -152,7 +152,7 @@ ) ;; definition for method 17 of type font-context -(defmethod set-flags! font-context ((obj font-context) (flags uint)) +(defmethod set-flags! font-context ((obj font-context) (flags font-flags)) (set! (-> obj flags) flags) obj ) @@ -180,7 +180,7 @@ (y int) (z float) (color font-color) - (flags uint) + (flags font-flags) ) (let ((obj diff --git a/test/decompiler/reference/engine/gfx/hw/display_REF.gc b/test/decompiler/reference/engine/gfx/hw/display_REF.gc index bce48f0cec..b53dcc27a6 100644 --- a/test/decompiler/reference/engine/gfx/hw/display_REF.gc +++ b/test/decompiler/reference/engine/gfx/hw/display_REF.gc @@ -267,7 +267,7 @@ 24 0.0 (font-color default) - (the-as uint 3) + (font-flags shadow kerning) ) ) @@ -282,7 +282,7 @@ 170 0.0 (font-color orange-red) - (the-as uint 3) + (font-flags shadow kerning) ) ) @@ -466,7 +466,14 @@ (*profile-ticks* (let ((s3-0 draw-string-xy)) (format (clear *temp-string*) "~5D" (-> worst-time-cache (/ bar-pos 10))) - (s3-0 *temp-string* buf 488 (+ bar-pos 8) (font-color default) 17) + (s3-0 + *temp-string* + buf + 488 + (+ bar-pos 8) + (font-color default) + (font-flags shadow right) + ) ) (the float (-> worst-time-cache (/ bar-pos 10))) ) @@ -491,7 +498,7 @@ 0 ) ) - 17 + (font-flags shadow right) ) ) f30-0 diff --git a/test/decompiler/reference/engine/nav/navigate-h_REF.gc b/test/decompiler/reference/engine/nav/navigate-h_REF.gc index 5c35f8601c..e75a2bad6f 100644 --- a/test/decompiler/reference/engine/nav/navigate-h_REF.gc +++ b/test/decompiler/reference/engine/nav/navigate-h_REF.gc @@ -591,7 +591,7 @@ (defmethod should-display? nav-control ((obj nav-control)) (and *display-nav-marks* - (nonzero? (logand (-> obj flags) (nav-control-flags bit0 display-marks))) + (nonzero? (logand (-> obj flags) (nav-control-flags display-marks bit0))) ) ) diff --git a/test/decompiler/reference/engine/ps2/memcard-h_REF.gc b/test/decompiler/reference/engine/ps2/memcard-h_REF.gc index 0719980874..726dc997ba 100644 --- a/test/decompiler/reference/engine/ps2/memcard-h_REF.gc +++ b/test/decompiler/reference/engine/ps2/memcard-h_REF.gc @@ -148,7 +148,7 @@ 32 (+ (* 12 slot-idx) 8) (font-color orange-red) - 1 + (font-flags shadow) ) ) ) diff --git a/test/decompiler/reference/engine/sound/gsound_REF.gc b/test/decompiler/reference/engine/sound/gsound_REF.gc index 7f918ee495..070eb688cc 100644 --- a/test/decompiler/reference/engine/sound/gsound_REF.gc +++ b/test/decompiler/reference/engine/sound/gsound_REF.gc @@ -1022,7 +1022,7 @@ (+ (* s5-0 16) 16) 48 (font-color default) - 1 + (font-flags shadow) ) ) (dotimes (s5-1 24) @@ -1034,7 +1034,7 @@ (+ (* s5-1 16) 16) 64 (font-color default) - 1 + (font-flags shadow) ) ) 0 @@ -1049,7 +1049,7 @@ (-> *sound-iop-info* freemem) (shr (-> *sound-iop-info* freemem) 10) ) - (s5-0 *temp-string* arg0 32 96 (font-color default) 1) + (s5-0 *temp-string* arg0 32 96 (font-color default) (font-flags shadow)) ) (let ((s5-1 draw-string-xy)) (format @@ -1058,7 +1058,7 @@ (-> *sound-iop-info* freemem2) (shr (-> *sound-iop-info* freemem2) 10) ) - (s5-1 *temp-string* arg0 32 64 (font-color default) 1) + (s5-1 *temp-string* arg0 32 64 (font-color default) (font-flags shadow)) ) 0 ) diff --git a/test/decompiler/reference/engine/ui/credits_REF.gc b/test/decompiler/reference/engine/ui/credits_REF.gc index a7956d0c2f..b4e69cfe48 100644 --- a/test/decompiler/reference/engine/ui/credits_REF.gc +++ b/test/decompiler/reference/engine/ui/credits_REF.gc @@ -85,7 +85,7 @@ 0 0.0 (font-color default) - (the-as uint 3) + (font-flags shadow kerning) ) ) ) @@ -96,7 +96,7 @@ (let ((v1-4 gp-0)) (set! (-> v1-4 height) (the float 10)) ) - (set! (-> gp-0 flags) (the-as uint 38)) + (set! (-> gp-0 flags) (font-flags kerning middle large)) (let* ((s5-1 (- s5-0 (mod s5-0 3))) (f0-10 (- f30-0 (the float s5-1))) ) @@ -173,7 +173,7 @@ 0 0.0 (font-color default) - (the-as uint 3) + (font-flags shadow kerning) ) ) ) @@ -186,7 +186,7 @@ (let ((v1-4 s5-0)) (set! (-> v1-4 scale) 1.0) ) - (set! (-> s5-0 flags) (the-as uint 39)) + (set! (-> s5-0 flags) (font-flags shadow kerning middle large)) (while (or s2-0 (and (< s4-0 (- s3-0)) (< (the-as uint gp-0) (the-as uint 3249)))) (+! s4-0 s3-0) diff --git a/test/decompiler/reference/levels/common/nav-enemy_REF.gc b/test/decompiler/reference/levels/common/nav-enemy_REF.gc index e088a084a6..40f53811d2 100644 --- a/test/decompiler/reference/levels/common/nav-enemy_REF.gc +++ b/test/decompiler/reference/levels/common/nav-enemy_REF.gc @@ -3759,7 +3759,7 @@ nav-enemy-default-event-handler ) (logior! (-> obj nav flags) - (nav-control-flags bit0 display-marks bit3 bit5 bit6 bit7) + (nav-control-flags display-marks bit0 bit3 bit5 bit6 bit7) ) (set! (-> obj nav gap-event) 'jump) (dummy-26 (-> obj nav)) From 395f97a0c030696e3984ef9bf1a63e254117efbc Mon Sep 17 00:00:00 2001 From: ManDude <7569514+ManDude@users.noreply.github.com> Date: Mon, 16 Aug 2021 04:04:04 +0100 Subject: [PATCH 06/23] Fix dumb mistake... --- goal_src/engine/target/logic-target.gc | 2 +- goal_src/kernel/gstate.gc | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/goal_src/engine/target/logic-target.gc b/goal_src/engine/target/logic-target.gc index feec857c14..8a1a77030f 100644 --- a/goal_src/engine/target/logic-target.gc +++ b/goal_src/engine/target/logic-target.gc @@ -32,7 +32,7 @@ (set! (-> *level* border?) #f) (set! (-> *setting-control* default border-mode) #f) (stop game-mode) - (let ((v1-3 (make-function-process *target-dead-pool* *target-pool* target 'target init-target cont))) + (let ((v1-3 (make-init-process *target-dead-pool* *target-pool* target 'target init-target cont))) (if v1-3 (set! *target* (the target (-> v1-3 0 self))) (set! *target* #f) diff --git a/goal_src/kernel/gstate.gc b/goal_src/kernel/gstate.gc index 28c4c4852a..c3388ed83f 100644 --- a/goal_src/kernel/gstate.gc +++ b/goal_src/kernel/gstate.gc @@ -81,12 +81,28 @@ There are several ways to "go" ) (defmacro make-function-process (dead-pool new-pool proc-type proc-name func &key (stack-size #x4000) &key (stack *kernel-dram-stack*) &rest args) - "Start a new process that runs a function on its main thread. Returns a pointer to the new process (or #f)." + "Start a new process that runs a function on its main thread. + Returns a pointer to the new process (or #f on error)." (with-gensyms (new-proc) - `(let ((,new-proc (get-process ,dead-pool ,proc-type ,stack-size))) + `(let ((,new-proc (the-as ,proc-type (get-process ,dead-pool ,proc-type ,stack-size)))) (when ,new-proc - ((method-of-type ,proc-type activate) (the-as ,proc-type ,new-proc) ,new-pool ,proc-name ,stack) + ((method-of-type ,proc-type activate) ,new-proc ,new-pool ,proc-name ,stack) + (run-next-time-in-process ,new-proc ,func ,@args) + (-> ,new-proc ppointer) + ) + ) + ) + ) + +(defmacro make-init-process (dead-pool new-pool proc-type proc-name func &key (stack-size #x4000) &key (stack *kernel-dram-stack*) &rest args) + "Start a new process and run an init function on it. + Returns a pointer to the new process, or #f (or is it 0?) if something goes wrong." + + (with-gensyms (new-proc) + `(let ((,new-proc (the-as ,proc-type (get-process ,dead-pool ,proc-type ,stack-size)))) + (when ,new-proc + ((method-of-type ,proc-type activate) ,new-proc ,new-pool ,proc-name ,stack) (run-now-in-process ,new-proc ,func ,@args) (-> ,new-proc ppointer) ) From efdc598c0997b38a449cb81df7b1f2d57a1e71c0 Mon Sep 17 00:00:00 2001 From: ManDude <7569514+ManDude@users.noreply.github.com> Date: Mon, 16 Aug 2021 07:44:05 +0100 Subject: [PATCH 07/23] make pc pad remapping process (incomplete) --- game/graphics/gfx.cpp | 10 ++ game/graphics/gfx.h | 10 +- game/kernel/kmachine.cpp | 4 +- game/system/newpad.cpp | 43 ++++-- game/system/newpad.h | 5 +- goal_src/engine/gfx/hw/display-h.gc | 8 ++ goal_src/engine/util/types-h.gc | 5 +- goal_src/kernel-defs.gc | 4 + goal_src/kernel/gstate.gc | 18 ++- goal_src/pc_debug/pc-pad-utils.gc | 202 +++++++++++++++++++++++----- 10 files changed, 258 insertions(+), 51 deletions(-) diff --git a/game/graphics/gfx.cpp b/game/graphics/gfx.cpp index a4bc089019..122fffaaf6 100644 --- a/game/graphics/gfx.cpp +++ b/game/graphics/gfx.cpp @@ -9,6 +9,8 @@ #include "display.h" #include "pipelines/opengl.h" +#include "game/kernel/kscheme.h" +#include "common/symbols.h" #include "common/log/log.h" #include "game/runtime.h" #include "game/system/newpad.h" @@ -131,6 +133,14 @@ void poll_events() { g_settings.renderer->poll_events(); } +void input_mode_set(u32 enable) { + if (enable == s7.offset + FIX_SYM_TRUE) { // #t + Pad::EnterInputMode(); + } else { + Pad::ExitInputMode(enable != s7.offset); // use #f for graceful exit, or 'canceled for abrupt + } +} + int PadIsPressed(Pad::Button button, int port) { return Pad::IsPressed(g_settings.pad_mapping_info, button, port); } diff --git a/game/graphics/gfx.h b/game/graphics/gfx.h index 431090d0e5..92ca95fff7 100644 --- a/game/graphics/gfx.h +++ b/game/graphics/gfx.h @@ -42,12 +42,13 @@ struct GfxRendererModule { struct GfxSettings { // current version of the settings. this should be set up so that newer versions are always higher // than older versions - static constexpr u64 CURRENT_VERSION = 0x0000'0000'0002'0001; + static constexpr u64 CURRENT_VERSION = 0x0000'0000'0003'0001; + + u64 version; // the version of this settings struct + int vsync; // (temp) number of screen update per frame + bool debug; // graphics debugging - u64 version; // the version of this settings struct const GfxRendererModule* renderer; // which rendering pipeline to use. - int vsync; // (temp) number of screen update per frame - bool debug; // graphics debugging Pad::MappingInfo pad_mapping_info; // button mapping Pad::MappingInfo pad_mapping_info_backup; // button mapping backup (see newpad.h) @@ -70,6 +71,7 @@ void send_chain(const void* data, u32 offset); void texture_upload_now(const u8* tpage, int mode, u32 s7_ptr); void texture_relocate(u32 destination, u32 source, u32 format); void poll_events(); +void input_mode_set(u32 enable); int PadIsPressed(Pad::Button button, int port); diff --git a/game/kernel/kmachine.cpp b/game/kernel/kmachine.cpp index 30cc6dd578..8a0d1f08a1 100644 --- a/game/kernel/kmachine.cpp +++ b/game/kernel/kmachine.cpp @@ -717,8 +717,10 @@ void InitMachine_PCPort() { make_function_symbol_from_c("__pc-texture-relocate", (void*)pc_texture_relocate); // pad stuff - make_function_symbol_from_c("pc-pad-input-mode-set", (void*)Pad::input_mode_set); + make_function_symbol_from_c("pc-pad-input-mode-set", (void*)Gfx::input_mode_set); make_function_symbol_from_c("pc-pad-input-mode-get", (void*)Pad::input_mode_get); + make_function_symbol_from_c("pc-pad-input-key-get", (void*)Pad::input_mode_get_key); + make_function_symbol_from_c("pc-pad-input-index-get", (void*)Pad::input_mode_get_index); // init ps2 VM if (VM::use) { diff --git a/game/system/newpad.cpp b/game/system/newpad.cpp index 0a5ec76e5b..e715adb882 100644 --- a/game/system/newpad.cpp +++ b/game/system/newpad.cpp @@ -22,9 +22,18 @@ std::unordered_map g_key_status; std::unordered_map g_buffered_key_status; // input mode for controller mapping -bool input_mode = false; +// this enum is also in pc-pad-utils.gc +enum class InputModeStatus { + Disabled, + Enabled, + Canceled +}; +InputModeStatus input_mode = InputModeStatus::Disabled; +u64 input_mode_pad = 0; u64 input_mode_key = -1; u64 input_mode_mod = 0; +u64 input_mode_index = 0; +MappingInfo input_mode_mapping; void ForceClearKeys() { g_key_status.clear(); @@ -39,12 +48,16 @@ void ClearKeys() { } void OnKeyPress(int key) { - if (input_mode) { + if (input_mode == InputModeStatus::Enabled) { if (key == GLFW_KEY_ESCAPE) { - input_mode = false; + ExitInputMode(true); return; } input_mode_key = key; + MapButton(input_mode_mapping, (Button)(input_mode_index++), input_mode_pad, key); + if (input_mode_index > (u64)Button::Max) { + ExitInputMode(false); + } return; } // set absolute key status @@ -63,7 +76,7 @@ void OnKeyPress(int key) { } void OnKeyRelease(int key) { - if (input_mode) { + if (input_mode == InputModeStatus::Enabled) { return; } // set absolute key status @@ -126,16 +139,26 @@ void DefaultMapping(MappingInfo& mapping) { MapButton(mapping, Button::Left, 0, GLFW_KEY_LEFT); } -void input_mode_set(u32 enable) { - if (enable != s7.offset) { - input_mode = true; - } else { - input_mode = false; - } +void EnterInputMode() { + input_mode = InputModeStatus::Enabled; + input_mode_index = 0; + input_mode_pad = 0; +} + +void ExitInputMode(bool canceled) { + input_mode = canceled ? InputModeStatus::Canceled : InputModeStatus::Disabled; } u64 input_mode_get() { + return (u64)input_mode; +} + +u64 input_mode_get_key() { return input_mode_key; } +u64 input_mode_get_index() { + return input_mode_index; +} + }; // namespace Pad diff --git a/game/system/newpad.h b/game/system/newpad.h index a2cd77cc89..fa09694a9d 100644 --- a/game/system/newpad.h +++ b/game/system/newpad.h @@ -72,7 +72,10 @@ void DefaultMapping(MappingInfo& mapping); int IsPressed(MappingInfo& mapping, Button button, int pad); void MapButton(MappingInfo& mapping, Button button, int pad, int key); -void input_mode_set(u32 enable); +void EnterInputMode(); +void ExitInputMode(bool); u64 input_mode_get(); +u64 input_mode_get_key(); +u64 input_mode_get_index(); } // namespace Pad diff --git a/goal_src/engine/gfx/hw/display-h.gc b/goal_src/engine/gfx/hw/display-h.gc index 56b8669906..f9d01521e7 100644 --- a/goal_src/engine/gfx/hw/display-h.gc +++ b/goal_src/engine/gfx/hw/display-h.gc @@ -234,3 +234,11 @@ (defmacro current-display-frame (&rest args) `(-> *display* frames (-> *display* on-screen) frame ,@args) ) + +(defmacro current-time () + `(-> *display* base-frame-counter) + ) + +(defmacro integral-current-time () + `(-> *display* integral-frame-counter) + ) diff --git a/goal_src/engine/util/types-h.gc b/goal_src/engine/util/types-h.gc index 1e1554bf9b..fa02edbd54 100644 --- a/goal_src/engine/util/types-h.gc +++ b/goal_src/engine/util/types-h.gc @@ -83,9 +83,12 @@ "Convert number to seconds unit. Returns uint." (cond - ((or (integer? x) (float? x)) + ((integer? x) (* TICKS_PER_SECOND x) ) + ((float? x) + (* 1 (* 1.0 x TICKS_PER_SECOND)) + ) (#t `(the uint (* TICKS_PER_SECOND ,x)) ) diff --git a/goal_src/kernel-defs.gc b/goal_src/kernel-defs.gc index e474ed451d..2faedcc56d 100644 --- a/goal_src/kernel-defs.gc +++ b/goal_src/kernel-defs.gc @@ -268,6 +268,10 @@ (define-extern __send-gfx-dma-chain (function object object none)) (define-extern __pc-texture-upload-now (function object object none)) (define-extern __pc-texture-relocate (function object object object none)) +(define-extern pc-pad-input-mode-set (function symbol none)) +(define-extern pc-pad-input-mode-get (function int)) +(define-extern pc-pad-input-key-get (function int)) +(define-extern pc-pad-input-index-get (function int)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; vm functions diff --git a/goal_src/kernel/gstate.gc b/goal_src/kernel/gstate.gc index c3388ed83f..5cdf6aeb96 100644 --- a/goal_src/kernel/gstate.gc +++ b/goal_src/kernel/gstate.gc @@ -82,7 +82,7 @@ There are several ways to "go" (defmacro make-function-process (dead-pool new-pool proc-type proc-name func &key (stack-size #x4000) &key (stack *kernel-dram-stack*) &rest args) "Start a new process that runs a function on its main thread. - Returns a pointer to the new process (or #f on error)." + Returns a pointer to the new process (or #f? on error)." (with-gensyms (new-proc) `(let ((,new-proc (the-as ,proc-type (get-process ,dead-pool ,proc-type ,stack-size)))) @@ -418,7 +418,21 @@ There are several ways to "go" #f ) - +(defmacro set-state-time () + "set the state-time field of the current object to the current time. process-drawable has one" + + `(set! (-> self state-time) (current-time)) + ) + +(defmacro time-passed () + "how much time has passed since set-state-time" + `(- (current-time) (-> self state-time)) + ) + +(defmacro time-passed? (time) + "has it been 'time' since set-state-time?" + `(>= (time-passed) ,time) + ) diff --git a/goal_src/pc_debug/pc-pad-utils.gc b/goal_src/pc_debug/pc-pad-utils.gc index 66247dc3cf..c8b0e75917 100644 --- a/goal_src/pc_debug/pc-pad-utils.gc +++ b/goal_src/pc_debug/pc-pad-utils.gc @@ -17,18 +17,60 @@ (ml "goal_src/pc_debug/pc-pad-utils.gc") ;; build and load this file. |# -(if *debug-segment* (begin +(cond (*debug-segment* -(define *pc-pad-show-proc* (the handle #f)) -(define *pc-pad-input-proc* (the handle #f)) +(deftype pc-pad-proc-list (basic) + ((show handle) + (input handle) + ) + ) +(define *pc-pad-proc-list* (new 'static 'pc-pad-proc-list)) +(set! (-> *pc-pad-proc-list* show) (the handle #f)) +(set! (-> *pc-pad-proc-list* input) (the handle #f)) + +(deftype pc-pad-proc (process) + ((state-time seconds) + (input-index uint64) + ) + :heap-base #x10 + ) + +(define *pc-pad-button-names* + (new 'static 'array string 16 + "SELECT" + "L3" + "R3" + "START" + + "UP" + "RIGHT" + "DOWN" + "LEFT" + + "L2" + "R2" + "L1" + "R1" + + "TRIANGLE" + "CIRCLE" + "X" + "SQUARE" + )) + +(defenum pc-pad-input-status + (disabled) + (enabled) + (canceled) + ) (defun-debug pc-pad-show-start () "Start the PC port pad debug display" - (if (not (handle->process *pc-pad-show-proc*)) - (set! *pc-pad-show-proc* (ppointer->handle - (make-function-process *nk-dead-pool* *active-pool* process 'pc-pad-show - (lambda :behavior process () + (if (not (handle->process (-> *pc-pad-proc-list* show))) + (let ((procp + (make-function-process *nk-dead-pool* *active-pool* pc-pad-proc 'pc-pad-show + (lambda :behavior pc-pad-proc () (stack-size-set! (-> self main-thread) 512) (loop (let ((cpad (-> *cpad-list* cpads 0))) @@ -46,8 +88,10 @@ ) ) )) + (set! (-> *pc-pad-proc-list* show) (ppointer->handle procp)) + ) - (format #t "That process is already running. :-)") + (format #t "That process is already running. :-)~%") ) ) @@ -57,36 +101,130 @@ (kill-by-name 'pc-pad-show *active-pool*) ) + +(defconstant PC_PAD_INPUT_NOTICE_TIME (seconds 1.5)) + + +(define-extern pc-pi-mapping-button state) + +(defstate pc-pi-new-mapping (pc-pad-proc) + + :enter (behavior () (set! (-> self input-index) (pc-pad-input-index-get)) ) + :code (behavior () + (set-state-time) + (until (time-passed? PC_PAD_INPUT_NOTICE_TIME) + (with-dma-buffer-add-bucket ((buf (current-display-frame debug-buf)) + (current-display-frame bucket-group) + (bucket-id debug-draw1)) + (draw-string-xy (string-format "MAPPED ~D FOR ~S!" + (pc-pad-input-key-get) (-> *pc-pad-button-names* (1- (-> self input-index)))) + buf 256 96 (font-color green) (font-flags shadow kerning large middle)) + ) + (suspend) + ) + (go pc-pi-mapping-button) + ) + :trans (behavior () + (if (or (!= (-> self input-index) (pc-pad-input-index-get)) + (!= (pc-pad-input-mode-get) (pc-pad-input-status enabled))) + ;; something's changed, go back to the main state and check everything + (go pc-pi-mapping-button) + ) + ) + + ) + +(defstate pc-pi-canceled (pc-pad-proc) + + :code (behavior () + (set-state-time) + (until (time-passed? PC_PAD_INPUT_NOTICE_TIME) + (with-dma-buffer-add-bucket ((buf (current-display-frame debug-buf)) + (current-display-frame bucket-group) + (bucket-id debug-draw1)) + (draw-string-xy "CANCELED!" buf 256 96 (font-color red-reverse) (font-flags shadow kerning large middle)) + ) + (suspend) + ) + ) + ) + +(defstate pc-pi-done (pc-pad-proc) + + :code (behavior () + (set-state-time) + (until (time-passed? PC_PAD_INPUT_NOTICE_TIME) + (with-dma-buffer-add-bucket ((buf (current-display-frame debug-buf)) + (current-display-frame bucket-group) + (bucket-id debug-draw1)) + (draw-string-xy "DONE!" buf 256 96 (font-color green) (font-flags shadow kerning large middle)) + ) + (suspend) + ) + ) + ) + +(defstate pc-pi-mapping-button (pc-pad-proc) + + :code (behavior () + (set-state-time) + (loop + (with-dma-buffer-add-bucket ((buf (current-display-frame debug-buf)) + (current-display-frame bucket-group) + (bucket-id debug-draw1)) + (if (< (mod (time-passed) (seconds 2)) (seconds 1)) + (draw-string-xy "NOW MAPPING PAD" buf 256 32 (font-color red) (font-flags shadow kerning large middle)) + ) + (draw-string-xy "PRESS ESCAPE TO EXIT" buf 256 64 (font-color default) (font-flags shadow kerning large middle)) + (draw-string-xy (string-format "PLEASE MAP FOR ~S" (-> *pc-pad-button-names* (-> self input-index))) + buf 256 96 (font-color default) (font-flags shadow kerning large middle)) + ) + (suspend) + ) + ) + :trans (behavior () + (cond + ;; canceled + ((= (pc-pad-input-mode-get) (pc-pad-input-status canceled)) + (go pc-pi-canceled) + ) + ;; finished + ((or (>= (pc-pad-input-index-get) 16) + (= (pc-pad-input-mode-get) (pc-pad-input-status disabled))) + (go pc-pi-done) + ) + ;; waiting input + ((= (-> self input-index) (pc-pad-input-index-get)) + ) + ;; one input has been done! + ((= (1+ (-> self input-index)) (pc-pad-input-index-get)) + (go pc-pi-new-mapping) + ) + ;; more than one input has been done. go to last mapping. + ((< (1+ (-> self input-index)) (pc-pad-input-index-get)) + (go pc-pi-new-mapping) + ) + ) + ) + + ) + (defun-debug pc-pad-input-start () "Start the PC port pad debug key mapping" - (if (not (handle->process *pc-pad-input-proc*)) - (set! *pc-pad-input-proc* (ppointer->handle - (make-function-process *nk-dead-pool* *active-pool* process 'pc-pad-input - (lambda :behavior process () - (stack-size-set! (-> self main-thread) 512) - (let ((start-time (get-current-time)) - (time-passed 0)) - (loop - (set! time-passed (- (the int (get-current-time)) start-time)) - - (with-dma-buffer-add-bucket ((buf (current-display-frame debug-buf)) - (current-display-frame bucket-group) - (bucket-id debug-draw1)) - (if (< (mod time-passed (seconds 2)) (seconds 1)) - (draw-string-xy "NOW MAPPING PAD" buf 256 64 (font-color red) (font-flags shadow kerning large middle)) - ) - - ) - - (suspend) - ) - ) + (if (not (handle->process (-> *pc-pad-proc-list* input))) + (let ((procp + (make-init-process *nk-dead-pool* *active-pool* pc-pad-proc 'pc-pad-input + (lambda :behavior pc-pad-proc () + (pc-pad-input-mode-set #t) + (go pc-pi-mapping-button) ) ) )) + (set! (-> *pc-pad-proc-list* input) (ppointer->handle procp)) + ) - (format #t "That process is already running. :-)") + (format #t "That process is already running. :-)~%") ) ) @@ -97,4 +235,4 @@ ) ) -(format #t "No debug memory in use. pc-pad-utils not loaded.")) \ No newline at end of file +(else (format #t "No debug memory in use. pc-pad-utils not loaded."))) \ No newline at end of file From c1fdb233107e2df01a6f164913cfefb3fe258eb7 Mon Sep 17 00:00:00 2001 From: ManDude <7569514+ManDude@users.noreply.github.com> Date: Mon, 16 Aug 2021 07:46:06 +0100 Subject: [PATCH 08/23] fix crash --- game/system/newpad.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/game/system/newpad.cpp b/game/system/newpad.cpp index e715adb882..58a912f22e 100644 --- a/game/system/newpad.cpp +++ b/game/system/newpad.cpp @@ -79,8 +79,12 @@ void OnKeyRelease(int key) { if (input_mode == InputModeStatus::Enabled) { return; } + + // if we come out of input mode, the key wont be found. + if (g_key_status.find(key) == g_key_status.end()) { + return; + } // set absolute key status - // no bounds checking for now in order to catch bugs g_key_status.at(key) = 0; } From ffd4251e712f4ebbfd9e6a2dae175053b6964cd6 Mon Sep 17 00:00:00 2001 From: ManDude <7569514+ManDude@users.noreply.github.com> Date: Mon, 16 Aug 2021 07:48:07 +0100 Subject: [PATCH 09/23] reword --- goal_src/pc_debug/pc-pad-utils.gc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/goal_src/pc_debug/pc-pad-utils.gc b/goal_src/pc_debug/pc-pad-utils.gc index c8b0e75917..9e0b3e8e65 100644 --- a/goal_src/pc_debug/pc-pad-utils.gc +++ b/goal_src/pc_debug/pc-pad-utils.gc @@ -176,7 +176,7 @@ (draw-string-xy "NOW MAPPING PAD" buf 256 32 (font-color red) (font-flags shadow kerning large middle)) ) (draw-string-xy "PRESS ESCAPE TO EXIT" buf 256 64 (font-color default) (font-flags shadow kerning large middle)) - (draw-string-xy (string-format "PLEASE MAP FOR ~S" (-> *pc-pad-button-names* (-> self input-index))) + (draw-string-xy (string-format "PRESS KEY FOR ~S" (-> *pc-pad-button-names* (-> self input-index))) buf 256 96 (font-color default) (font-flags shadow kerning large middle)) ) (suspend) From ada8f19685b394032a3096b7d0d3f89e43131cde Mon Sep 17 00:00:00 2001 From: ManDude <7569514+ManDude@users.noreply.github.com> Date: Mon, 16 Aug 2021 07:48:41 +0100 Subject: [PATCH 10/23] Update pc-pad-utils.gc --- goal_src/pc_debug/pc-pad-utils.gc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/goal_src/pc_debug/pc-pad-utils.gc b/goal_src/pc_debug/pc-pad-utils.gc index 9e0b3e8e65..fd71c0dcb8 100644 --- a/goal_src/pc_debug/pc-pad-utils.gc +++ b/goal_src/pc_debug/pc-pad-utils.gc @@ -116,7 +116,7 @@ (with-dma-buffer-add-bucket ((buf (current-display-frame debug-buf)) (current-display-frame bucket-group) (bucket-id debug-draw1)) - (draw-string-xy (string-format "MAPPED ~D FOR ~S!" + (draw-string-xy (string-format "MAPPED ~D TO ~S!" (pc-pad-input-key-get) (-> *pc-pad-button-names* (1- (-> self input-index)))) buf 256 96 (font-color green) (font-flags shadow kerning large middle)) ) From 513b0691cbbd97a08bec0dbc8938fcebc6dbc6d7 Mon Sep 17 00:00:00 2001 From: ManDude <7569514+ManDude@users.noreply.github.com> Date: Mon, 16 Aug 2021 07:52:41 +0100 Subject: [PATCH 11/23] Update pc-pad-utils.gc --- goal_src/pc_debug/pc-pad-utils.gc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/goal_src/pc_debug/pc-pad-utils.gc b/goal_src/pc_debug/pc-pad-utils.gc index fd71c0dcb8..453599da5d 100644 --- a/goal_src/pc_debug/pc-pad-utils.gc +++ b/goal_src/pc_debug/pc-pad-utils.gc @@ -157,7 +157,7 @@ (with-dma-buffer-add-bucket ((buf (current-display-frame debug-buf)) (current-display-frame bucket-group) (bucket-id debug-draw1)) - (draw-string-xy "DONE!" buf 256 96 (font-color green) (font-flags shadow kerning large middle)) + (draw-string-xy "KEY MAPPING COMPLETE!" buf 256 96 (font-color green) (font-flags shadow kerning large middle)) ) (suspend) ) From 093526721ccf786029417ff63fd5ccee95575b4e Mon Sep 17 00:00:00 2001 From: ManDude <7569514+ManDude@users.noreply.github.com> Date: Mon, 16 Aug 2021 14:57:15 +0100 Subject: [PATCH 12/23] save key mapping to memory! --- game/graphics/gfx.cpp | 17 +++++++++++++ game/graphics/gfx.h | 2 ++ game/kernel/kmachine.cpp | 2 ++ game/system/newpad.cpp | 12 +++------ game/system/newpad.h | 4 +++ goal_src/engine/game/main.gc | 2 +- goal_src/engine/target/logic-target.gc | 2 +- goal_src/kernel-defs.gc | 2 ++ goal_src/kernel/gkernel-h.gc | 4 ++- goal_src/kernel/gstate.gc | 8 +++--- goal_src/pc_debug/pc-pad-utils.gc | 35 +++++++++++++++++--------- 11 files changed, 62 insertions(+), 28 deletions(-) diff --git a/game/graphics/gfx.cpp b/game/graphics/gfx.cpp index 122fffaaf6..d2d8ea9f24 100644 --- a/game/graphics/gfx.cpp +++ b/game/graphics/gfx.cpp @@ -141,6 +141,23 @@ void input_mode_set(u32 enable) { } } +void input_mode_save() { + if (Pad::input_mode_get() == (u64)Pad::InputModeStatus::Enabled) { + lg::error("Can't save controller mapping while mapping controller."); + } else if (Pad::input_mode_get() == (u64)Pad::InputModeStatus::Disabled) { + g_settings.pad_mapping_info_backup = g_settings.pad_mapping_info; // copy to backup + g_settings.pad_mapping_info = Pad::g_input_mode_mapping; // set current mapping + } +} + +s64 get_mapped_button(s64 pad, s64 button) { + if (pad < 0 || pad > Pad::CONTROLLER_COUNT || button < 0 || button > 16) { + lg::error("Invalid parameters to get_mapped_button({}, {})", pad, button); + return -1; + } + return (s64)g_settings.pad_mapping_info.pad_mapping[pad][button]; +} + int PadIsPressed(Pad::Button button, int port) { return Pad::IsPressed(g_settings.pad_mapping_info, button, port); } diff --git a/game/graphics/gfx.h b/game/graphics/gfx.h index 92ca95fff7..207ceda8c7 100644 --- a/game/graphics/gfx.h +++ b/game/graphics/gfx.h @@ -72,6 +72,8 @@ void texture_upload_now(const u8* tpage, int mode, u32 s7_ptr); void texture_relocate(u32 destination, u32 source, u32 format); void poll_events(); void input_mode_set(u32 enable); +void input_mode_save(); +s64 get_mapped_button(s64 pad, s64 button); int PadIsPressed(Pad::Button button, int port); diff --git a/game/kernel/kmachine.cpp b/game/kernel/kmachine.cpp index 8a0d1f08a1..5818860635 100644 --- a/game/kernel/kmachine.cpp +++ b/game/kernel/kmachine.cpp @@ -717,6 +717,8 @@ void InitMachine_PCPort() { make_function_symbol_from_c("__pc-texture-relocate", (void*)pc_texture_relocate); // pad stuff + make_function_symbol_from_c("pc-pad-get-mapped-button", (void*)Gfx::get_mapped_button); + make_function_symbol_from_c("pc-pad-input-map-save!", (void*)Gfx::input_mode_save); make_function_symbol_from_c("pc-pad-input-mode-set", (void*)Gfx::input_mode_set); make_function_symbol_from_c("pc-pad-input-mode-get", (void*)Pad::input_mode_get); make_function_symbol_from_c("pc-pad-input-key-get", (void*)Pad::input_mode_get_key); diff --git a/game/system/newpad.cpp b/game/system/newpad.cpp index 58a912f22e..463c0b8407 100644 --- a/game/system/newpad.cpp +++ b/game/system/newpad.cpp @@ -22,18 +22,12 @@ std::unordered_map g_key_status; std::unordered_map g_buffered_key_status; // input mode for controller mapping -// this enum is also in pc-pad-utils.gc -enum class InputModeStatus { - Disabled, - Enabled, - Canceled -}; InputModeStatus input_mode = InputModeStatus::Disabled; u64 input_mode_pad = 0; u64 input_mode_key = -1; u64 input_mode_mod = 0; u64 input_mode_index = 0; -MappingInfo input_mode_mapping; +MappingInfo g_input_mode_mapping; void ForceClearKeys() { g_key_status.clear(); @@ -54,8 +48,8 @@ void OnKeyPress(int key) { return; } input_mode_key = key; - MapButton(input_mode_mapping, (Button)(input_mode_index++), input_mode_pad, key); - if (input_mode_index > (u64)Button::Max) { + MapButton(g_input_mode_mapping, (Button)(input_mode_index++), input_mode_pad, key); + if (input_mode_index >= (u64)Button::Max) { ExitInputMode(false); } return; diff --git a/game/system/newpad.h b/game/system/newpad.h index fa09694a9d..489e9077c9 100644 --- a/game/system/newpad.h +++ b/game/system/newpad.h @@ -72,6 +72,10 @@ void DefaultMapping(MappingInfo& mapping); int IsPressed(MappingInfo& mapping, Button button, int pad); void MapButton(MappingInfo& mapping, Button button, int pad, int key); +// this enum is also in pc-pad-utils.gc +enum class InputModeStatus { Disabled, Enabled, Canceled }; + +extern MappingInfo g_input_mode_mapping; void EnterInputMode(); void ExitInputMode(bool); u64 input_mode_get(); diff --git a/goal_src/engine/game/main.gc b/goal_src/engine/game/main.gc index ebf5babe2e..0ea948e503 100644 --- a/goal_src/engine/game/main.gc +++ b/goal_src/engine/game/main.gc @@ -1277,7 +1277,7 @@ ) ) (set! *run* #t) - (let ((new-dproc (make-function-process *4k-dead-pool* *display-pool* process 'display display-loop))) + (let ((new-dproc (make-function-process *4k-dead-pool* *display-pool* process display-loop :name 'display))) (set! *dproc* (the process (as-process new-dproc))) ) (cond diff --git a/goal_src/engine/target/logic-target.gc b/goal_src/engine/target/logic-target.gc index 8a1a77030f..9c6752462a 100644 --- a/goal_src/engine/target/logic-target.gc +++ b/goal_src/engine/target/logic-target.gc @@ -32,7 +32,7 @@ (set! (-> *level* border?) #f) (set! (-> *setting-control* default border-mode) #f) (stop game-mode) - (let ((v1-3 (make-init-process *target-dead-pool* *target-pool* target 'target init-target cont))) + (let ((v1-3 (make-init-process *target-dead-pool* *target-pool* target init-target cont))) (if v1-3 (set! *target* (the target (-> v1-3 0 self))) (set! *target* #f) diff --git a/goal_src/kernel-defs.gc b/goal_src/kernel-defs.gc index 2faedcc56d..f95997c806 100644 --- a/goal_src/kernel-defs.gc +++ b/goal_src/kernel-defs.gc @@ -272,6 +272,8 @@ (define-extern pc-pad-input-mode-get (function int)) (define-extern pc-pad-input-key-get (function int)) (define-extern pc-pad-input-index-get (function int)) +(define-extern pc-pad-input-map-save! (function none)) +(define-extern pc-pad-get-mapped-button (function int int int)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; vm functions diff --git a/goal_src/kernel/gkernel-h.gc b/goal_src/kernel/gkernel-h.gc index 023742fd1f..42ee5ee5c8 100644 --- a/goal_src/kernel/gkernel-h.gc +++ b/goal_src/kernel/gkernel-h.gc @@ -415,7 +415,9 @@ ) (defmacro ppointer->handle (pproc) - `(new 'static 'handle :process ,pproc :pid (-> ,pproc 0 pid)) + `(let ((the-process ,pproc)) + (new 'static 'handle :process the-process :pid (-> the-process 0 pid)) + ) ) (defmacro process->handle (proc) diff --git a/goal_src/kernel/gstate.gc b/goal_src/kernel/gstate.gc index 5cdf6aeb96..fb1f107dbe 100644 --- a/goal_src/kernel/gstate.gc +++ b/goal_src/kernel/gstate.gc @@ -80,14 +80,14 @@ There are several ways to "go" ) ) -(defmacro make-function-process (dead-pool new-pool proc-type proc-name func &key (stack-size #x4000) &key (stack *kernel-dram-stack*) &rest args) +(defmacro make-function-process (dead-pool new-pool proc-type func &key (name #f) &key (stack-size #x4000) &key (stack *kernel-dram-stack*) &rest args) "Start a new process that runs a function on its main thread. Returns a pointer to the new process (or #f? on error)." (with-gensyms (new-proc) `(let ((,new-proc (the-as ,proc-type (get-process ,dead-pool ,proc-type ,stack-size)))) (when ,new-proc - ((method-of-type ,proc-type activate) ,new-proc ,new-pool ,proc-name ,stack) + ((method-of-type ,proc-type activate) ,new-proc ,new-pool ,(if name name `(quote ,proc-type)) ,stack) (run-next-time-in-process ,new-proc ,func ,@args) (-> ,new-proc ppointer) ) @@ -95,14 +95,14 @@ There are several ways to "go" ) ) -(defmacro make-init-process (dead-pool new-pool proc-type proc-name func &key (stack-size #x4000) &key (stack *kernel-dram-stack*) &rest args) +(defmacro make-init-process (dead-pool new-pool proc-type func &key (name #f) &key (stack-size #x4000) &key (stack *kernel-dram-stack*) &rest args) "Start a new process and run an init function on it. Returns a pointer to the new process, or #f (or is it 0?) if something goes wrong." (with-gensyms (new-proc) `(let ((,new-proc (the-as ,proc-type (get-process ,dead-pool ,proc-type ,stack-size)))) (when ,new-proc - ((method-of-type ,proc-type activate) ,new-proc ,new-pool ,proc-name ,stack) + ((method-of-type ,proc-type activate) ,new-proc ,new-pool ,(if name name `(quote ,proc-type)) ,stack) (run-now-in-process ,new-proc ,func ,@args) (-> ,new-proc ppointer) ) diff --git a/goal_src/pc_debug/pc-pad-utils.gc b/goal_src/pc_debug/pc-pad-utils.gc index 453599da5d..71e72bf0ee 100644 --- a/goal_src/pc_debug/pc-pad-utils.gc +++ b/goal_src/pc_debug/pc-pad-utils.gc @@ -19,7 +19,8 @@ (cond (*debug-segment* -(deftype pc-pad-proc-list (basic) +;; a structure to hold the handles used in this file +(deftype pc-pad-proc-list (structure) ((show handle) (input handle) ) @@ -28,6 +29,7 @@ (set! (-> *pc-pad-proc-list* show) (the handle #f)) (set! (-> *pc-pad-proc-list* input) (the handle #f)) +;; a pc pad process (deftype pc-pad-proc (process) ((state-time seconds) (input-index uint64) @@ -69,20 +71,16 @@ (if (not (handle->process (-> *pc-pad-proc-list* show))) (let ((procp - (make-function-process *nk-dead-pool* *active-pool* pc-pad-proc 'pc-pad-show + (make-function-process *nk-dead-pool* *active-pool* pc-pad-proc :name 'pc-pad-show (lambda :behavior pc-pad-proc () (stack-size-set! (-> self main-thread) 512) (loop - (let ((cpad (-> *cpad-list* cpads 0))) - (format *stdcon* "~3Lcpad 0~%~0L") - (format *stdcon* "~Tbutton0: ~X~%" (-> cpad button0)) - (format *stdcon* "~Tbutton0-abs 0: ~X~%" (-> cpad button0-abs 0)) - (format *stdcon* "~Tbutton0-abs 1: ~X~%" (-> cpad button0-abs 1)) - (format *stdcon* "~Tbutton0-abs 2: ~X~%" (-> cpad button0-abs 2)) - (format *stdcon* "~Tbutton0-rel 0: ~X~%" (-> cpad button0-rel 0)) - (format *stdcon* "~Tbutton0-rel 1: ~X~%" (-> cpad button0-rel 1)) - (format *stdcon* "~Tbutton0-rel 2: ~X~%" (-> cpad button0-rel 2)) + (dotimes (ii 2) + (format *stdcon* "~3Lcpad ~D~0L~%" ii) + (dotimes (i 16) + (format *stdcon* " ~S: ~32L~D~0L~%" (-> *pc-pad-button-names* i) (pc-pad-get-mapped-button ii i)) ) + ) (suspend) ) ) @@ -151,7 +149,20 @@ (defstate pc-pi-done (pc-pad-proc) + :enter (behavior () (set! (-> self input-index) 16)) :code (behavior () + (pc-pad-input-map-save!) + (set-state-time) + (until (time-passed? PC_PAD_INPUT_NOTICE_TIME) + (with-dma-buffer-add-bucket ((buf (current-display-frame debug-buf)) + (current-display-frame bucket-group) + (bucket-id debug-draw1)) + (draw-string-xy (string-format "MAPPED ~D TO ~S!" + (pc-pad-input-key-get) (-> *pc-pad-button-names* (1- (-> self input-index)))) + buf 256 96 (font-color green) (font-flags shadow kerning large middle)) + ) + (suspend) + ) (set-state-time) (until (time-passed? PC_PAD_INPUT_NOTICE_TIME) (with-dma-buffer-add-bucket ((buf (current-display-frame debug-buf)) @@ -214,7 +225,7 @@ (if (not (handle->process (-> *pc-pad-proc-list* input))) (let ((procp - (make-init-process *nk-dead-pool* *active-pool* pc-pad-proc 'pc-pad-input + (make-init-process *nk-dead-pool* *active-pool* pc-pad-proc :name 'pc-pad-input (lambda :behavior pc-pad-proc () (pc-pad-input-mode-set #t) (go pc-pi-mapping-button) From 8e348a8cd194e144672df628a56d01cf9ec0f756 Mon Sep 17 00:00:00 2001 From: ManDude <7569514+ManDude@users.noreply.github.com> Date: Mon, 16 Aug 2021 15:43:12 +0100 Subject: [PATCH 13/23] save & load to file! --- .gitignore | 4 +++ game/common/file_paths.h | 12 ++++++++ game/graphics/display.cpp | 2 +- game/graphics/gfx.cpp | 65 +++++++++++++++++++++++++++++++-------- game/graphics/gfx.h | 15 +++++---- 5 files changed, 78 insertions(+), 20 deletions(-) create mode 100644 game/common/file_paths.h diff --git a/.gitignore b/.gitignore index cd4b3d4758..788ef422e1 100644 --- a/.gitignore +++ b/.gitignore @@ -16,9 +16,13 @@ logs/* .#*# *.pyc +# output from our tools *.bin *.log *.p2s savestate-out/ failures/ ee-results.json + +# game stuff +game_config/* diff --git a/game/common/file_paths.h b/game/common/file_paths.h new file mode 100644 index 0000000000..a4bdb56571 --- /dev/null +++ b/game/common/file_paths.h @@ -0,0 +1,12 @@ +#pragma once + +/*! + * @file file_paths.h + * File names and directories for user config files. + */ + +#include + +static const std::string GAME_CONFIG_DIR_NAME = "game_config"; + +static const std::string SETTINGS_GFX_FILE_NAME = "SETTINGS_GFX.CFG"; diff --git a/game/graphics/display.cpp b/game/graphics/display.cpp index 1d0b50274d..d5a3363a04 100644 --- a/game/graphics/display.cpp +++ b/game/graphics/display.cpp @@ -106,7 +106,7 @@ int InitMainDisplay(int width, int height, const char* title, GfxSettings& setti return 1; } - auto display = settings.renderer->make_main_display(width, height, title, settings); + auto display = Gfx::GetRenderer(settings.renderer)->make_main_display(width, height, title, settings); if (display == NULL) { lg::error("Failed to make main display."); return 1; diff --git a/game/graphics/gfx.cpp b/game/graphics/gfx.cpp index d2d8ea9f24..2a3333ba01 100644 --- a/game/graphics/gfx.cpp +++ b/game/graphics/gfx.cpp @@ -3,15 +3,19 @@ * Graphics component for the runtime. Abstraction layer for the main graphics routines. */ +#include #include +#include #include "gfx.h" #include "display.h" #include "pipelines/opengl.h" -#include "game/kernel/kscheme.h" #include "common/symbols.h" #include "common/log/log.h" +#include "common/util/FileUtil.h" +#include "game/common/file_paths.h" +#include "game/kernel/kscheme.h" #include "game/runtime.h" #include "game/system/newpad.h" @@ -24,7 +28,7 @@ void InitSettings(GfxSettings& settings) { settings.version = GfxSettings::CURRENT_VERSION; // use opengl by default for now - settings.renderer = Gfx::GetRenderer(GfxPipeline::OpenGL); // Gfx::renderers[0]; + settings.renderer = GfxPipeline::OpenGL; // Gfx::renderers[0]; // 1 screen update per frame settings.vsync = 1; @@ -47,6 +51,33 @@ namespace Gfx { GfxSettings g_settings; // const std::vector renderers = {&moduleOpenGL}; +void LoadSettings() { + const auto filename = file_util::get_file_path({GAME_CONFIG_DIR_NAME, SETTINGS_GFX_FILE_NAME}); + if (std::filesystem::exists(filename)) { + FILE* fp = fopen(filename.c_str(), "rb"); + u64 version; + fread(&version, sizeof(u64), 1, fp); + if (version == GfxSettings::CURRENT_VERSION) { + fseek(fp, 0, SEEK_SET); + fread(&g_settings, sizeof(GfxSettings), 1, fp); + lg::info("Loaded gfx settings."); + } else { + // TODO upgrade func + lg::info("Detected gfx settings from old version. Ignoring."); + } + fclose(fp); + } +} + +void SaveSettings() { + const auto filename = file_util::get_file_path({GAME_CONFIG_DIR_NAME, SETTINGS_GFX_FILE_NAME}); + file_util::create_dir_if_needed(file_util::get_file_path({GAME_CONFIG_DIR_NAME})); + FILE* fp = fopen(filename.c_str(), "wb"); + fwrite(&g_settings, sizeof(GfxSettings), 1, fp); + fclose(fp); + lg::info("Saved gfx settings."); +} + const GfxRendererModule* GetRenderer(GfxPipeline pipeline) { switch (pipeline) { case GfxPipeline::Invalid: @@ -61,6 +92,10 @@ const GfxRendererModule* GetRenderer(GfxPipeline pipeline) { } } +const GfxRendererModule* GetCurrentRenderer() { + return GetRenderer(g_settings.renderer); +} + u32 Init() { lg::info("GFX Init"); // initialize settings @@ -68,7 +103,9 @@ u32 Init() { // guarantee we have no keys detected by pad Pad::ForceClearKeys(); - if (g_settings.renderer->init(g_settings)) { + LoadSettings(); + + if (GetCurrentRenderer()->init(g_settings)) { lg::error("Gfx::Init error"); return 1; } @@ -99,38 +136,38 @@ void Loop(std::function f) { u32 Exit() { lg::info("GFX Exit"); Display::KillMainDisplay(); - g_settings.renderer->exit(); + GetCurrentRenderer()->exit(); return 0; } u32 vsync() { - return g_settings.renderer->vsync(); + return GetCurrentRenderer()->vsync(); } u32 sync_path() { - return g_settings.renderer->sync_path(); + return GetCurrentRenderer()->sync_path(); } void send_chain(const void* data, u32 offset) { - if (g_settings.renderer) { - g_settings.renderer->send_chain(data, offset); + if (GetCurrentRenderer()) { + GetCurrentRenderer()->send_chain(data, offset); } } void texture_upload_now(const u8* tpage, int mode, u32 s7_ptr) { - if (g_settings.renderer) { - g_settings.renderer->texture_upload_now(tpage, mode, s7_ptr); + if (GetCurrentRenderer()) { + GetCurrentRenderer()->texture_upload_now(tpage, mode, s7_ptr); } } void texture_relocate(u32 destination, u32 source, u32 format) { - if (g_settings.renderer) { - g_settings.renderer->texture_relocate(destination, source, format); + if (GetCurrentRenderer()) { + GetCurrentRenderer()->texture_relocate(destination, source, format); } } void poll_events() { - g_settings.renderer->poll_events(); + GetCurrentRenderer()->poll_events(); } void input_mode_set(u32 enable) { @@ -147,6 +184,8 @@ void input_mode_save() { } else if (Pad::input_mode_get() == (u64)Pad::InputModeStatus::Disabled) { g_settings.pad_mapping_info_backup = g_settings.pad_mapping_info; // copy to backup g_settings.pad_mapping_info = Pad::g_input_mode_mapping; // set current mapping + + SaveSettings(); } } diff --git a/game/graphics/gfx.h b/game/graphics/gfx.h index 207ceda8c7..dddff5445c 100644 --- a/game/graphics/gfx.h +++ b/game/graphics/gfx.h @@ -42,16 +42,19 @@ struct GfxRendererModule { struct GfxSettings { // current version of the settings. this should be set up so that newer versions are always higher // than older versions - static constexpr u64 CURRENT_VERSION = 0x0000'0000'0003'0001; + // increment this whenever you change this struct. + // there's probably a smarter way to do this (automatically deduce size etc.) + static constexpr u64 CURRENT_VERSION = 0x0000'0000'0004'0001; - u64 version; // the version of this settings struct - int vsync; // (temp) number of screen update per frame - bool debug; // graphics debugging - - const GfxRendererModule* renderer; // which rendering pipeline to use. + u64 version; // the version of this settings struct. MUST ALWAYS BE THE FIRST THING! Pad::MappingInfo pad_mapping_info; // button mapping Pad::MappingInfo pad_mapping_info_backup; // button mapping backup (see newpad.h) + + int vsync; // (temp) number of screen update per frame + bool debug; // graphics debugging + + GfxPipeline renderer; // which rendering pipeline to use. }; namespace Gfx { From fd4bd26d8849b9bf8ef73dfc9df5a781425c9336 Mon Sep 17 00:00:00 2001 From: ManDude <7569514+ManDude@users.noreply.github.com> Date: Mon, 16 Aug 2021 15:58:41 +0100 Subject: [PATCH 14/23] patch --- goal_src/engine/gfx/font.gc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/goal_src/engine/gfx/font.gc b/goal_src/engine/gfx/font.gc index d5af44ea98..f5d7474d9c 100644 --- a/goal_src/engine/gfx/font.gc +++ b/goal_src/engine/gfx/font.gc @@ -698,7 +698,7 @@ (.mov.vf vf2 vf0) (.mov.vf vf3 vf0) (.mov.vf vf4 vf0) - (set! (-> fw flags) (the-as uint flags)) + (set! (-> fw flags) (the-as font-flags flags)) (.lvf vf16 (&-> fw size-st1 quad)) (.lvf vf17 (&-> fw size-st2 quad)) (.lvf vf18 (&-> fw size-st3 quad)) @@ -1652,7 +1652,7 @@ (.mul.vf vf24 vf24 vf1 :mask #b11) (let ((a1-4 *font-work*)) (set! (-> a1-4 str-ptr) (the-as uint arg0)) - (set! (-> a1-4 flags) (the-as uint v1-0)) + (set! (-> a1-4 flags) (the-as font-flags v1-0)) (.mov.vf vf1 vf0) (let ((a2-0 (logand v1-0 32))) (b! (nonzero? a2-0) cfg-2 :delay (set! a2-1 *font12-table*)) @@ -1783,7 +1783,7 @@ ) ) -(defun draw-string-xy ((str string) (buf dma-buffer) (x int) (y int) (color font-color) (flags int)) +(defun draw-string-xy ((str string) (buf dma-buffer) (x int) (y int) (color font-color) (flags font-flags)) "Draw a string at the given xy location." (let ((context (new 'stack 'font-context *font-default-matrix* @@ -1791,7 +1791,7 @@ y 0.0 color - (the-as uint flags) + flags ) ) ) From f05117fb0ce3809bc7932dfb98a5dba1df83c62f Mon Sep 17 00:00:00 2001 From: ManDude <7569514+ManDude@users.noreply.github.com> Date: Mon, 16 Aug 2021 16:01:34 +0100 Subject: [PATCH 15/23] clang --- game/graphics/display.cpp | 3 ++- game/graphics/gfx.cpp | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/game/graphics/display.cpp b/game/graphics/display.cpp index d5a3363a04..92415402ad 100644 --- a/game/graphics/display.cpp +++ b/game/graphics/display.cpp @@ -106,7 +106,8 @@ int InitMainDisplay(int width, int height, const char* title, GfxSettings& setti return 1; } - auto display = Gfx::GetRenderer(settings.renderer)->make_main_display(width, height, title, settings); + auto display = + Gfx::GetRenderer(settings.renderer)->make_main_display(width, height, title, settings); if (display == NULL) { lg::error("Failed to make main display."); return 1; diff --git a/game/graphics/gfx.cpp b/game/graphics/gfx.cpp index 2a3333ba01..882151007c 100644 --- a/game/graphics/gfx.cpp +++ b/game/graphics/gfx.cpp @@ -182,8 +182,8 @@ void input_mode_save() { if (Pad::input_mode_get() == (u64)Pad::InputModeStatus::Enabled) { lg::error("Can't save controller mapping while mapping controller."); } else if (Pad::input_mode_get() == (u64)Pad::InputModeStatus::Disabled) { - g_settings.pad_mapping_info_backup = g_settings.pad_mapping_info; // copy to backup - g_settings.pad_mapping_info = Pad::g_input_mode_mapping; // set current mapping + g_settings.pad_mapping_info_backup = g_settings.pad_mapping_info; // copy to backup + g_settings.pad_mapping_info = Pad::g_input_mode_mapping; // set current mapping SaveSettings(); } From ebe24a9b79d6ec47c1399e85d541ca9424dedc2e Mon Sep 17 00:00:00 2001 From: ManDude <7569514+ManDude@users.noreply.github.com> Date: Mon, 16 Aug 2021 16:13:10 +0100 Subject: [PATCH 16/23] fix test --- decompiler/config/all-types.gc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/decompiler/config/all-types.gc b/decompiler/config/all-types.gc index deb02fc56c..7350e6135f 100644 --- a/decompiler/config/all-types.gc +++ b/decompiler/config/all-types.gc @@ -5335,7 +5335,7 @@ (buf basic :offset-assert 3024) (str-ptr uint32 :offset-assert 3028) (str-ptr-signed (pointer uint8) :offset 3028) ;; added - (flags uint32 :offset-assert 3032) + (flags font-flags :offset-assert 3032) (flags-signed int32 :offset 3032) ;; added (reg-save uint32 5 :offset-assert 3036) ) From 319bfb0d943bbc61607c8256a01f5186848d0b1d Mon Sep 17 00:00:00 2001 From: ManDude <7569514+ManDude@users.noreply.github.com> Date: Tue, 17 Aug 2021 06:23:08 +0100 Subject: [PATCH 17/23] simplify `with-dma-buffer-add-bucket` --- goal_src/engine/debug/debug.gc | 12 ++++++------ goal_src/engine/debug/menu.gc | 6 ------ goal_src/engine/dma/dma-buffer.gc | 9 +++++---- goal_src/engine/game/main.gc | 3 --- goal_src/engine/gfx/generic/generic.gc | 4 +--- goal_src/engine/gfx/sprite/sprite.gc | 4 +--- goal_src/engine/gfx/texture.gc | 10 ---------- goal_src/goos-lib.gs | 6 ++++++ goal_src/pc_debug/pc-pad-utils.gc | 5 ----- 9 files changed, 19 insertions(+), 40 deletions(-) diff --git a/goal_src/engine/debug/debug.gc b/goal_src/engine/debug/debug.gc index 60bef85c49..15bbc802d5 100644 --- a/goal_src/engine/debug/debug.gc +++ b/goal_src/engine/debug/debug.gc @@ -58,7 +58,7 @@ (set! (-> pt w) 1.0) (when (transform-point-qword! (-> s5-0 vector 0) pt) - (with-dma-buffer-add-bucket ((v1-7 (current-display-frame debug-buf)) (current-display-frame bucket-group) bucket) + (with-dma-buffer-add-bucket ((v1-7 (current-display-frame debug-buf)) bucket) (with-cnt-vif-block (v1-7) (dma-buffer-add-gif-tag v1-7 @@ -147,7 +147,7 @@ (when (and (transform-point-qword! (-> s4-0 vector 0) p0) (transform-point-qword! (-> s4-0 vector 1) p1) ) - (with-dma-buffer-add-bucket ((v1-28 (current-display-frame debug-buf)) (current-display-frame bucket-group) bucket) + (with-dma-buffer-add-bucket ((v1-28 (current-display-frame debug-buf)) bucket) (with-cnt-vif-block (v1-28) (dma-buffer-add-gif-tag v1-28 (new 'static 'gif-tag64 :nloop 1 :eop 1 :pre 1 :nreg 4 :prim (gif-prim line)) @@ -205,7 +205,7 @@ (set! (-> s2-0 quad) (the-as uint128 0)) (when (transform-point-qword! (the-as vector4w s2-0) location) - (with-dma-buffer-add-bucket ((s3-0 (current-display-frame debug-buf)) (current-display-frame bucket-group) bucket) + (with-dma-buffer-add-bucket ((s3-0 (current-display-frame debug-buf)) bucket) (let ((a2-2 (new 'stack 'font-context *font-default-matrix* (+ (+ (-> offset x) -1792) (/ (-> s2-0 x) 16)) @@ -268,7 +268,7 @@ (transform-point-qword! (-> s5-0 vector 1) p1) (transform-point-qword! (-> s5-0 vector 2) p2) ) - (with-dma-buffer-add-bucket ((v1-9 (current-display-frame debug-buf)) (current-display-frame bucket-group) bucket) + (with-dma-buffer-add-bucket ((v1-9 (current-display-frame debug-buf)) bucket) (with-cnt-vif-block (v1-9) (dma-buffer-add-gif-tag v1-9 (new 'static 'gif-tag64 :nloop 1 :eop 1 :pre 1 :nreg 6 :prim (gif-prim tri)) @@ -448,7 +448,7 @@ (if (not arg0) (return #f) ) - (with-dma-buffer-add-bucket ((s4-0 (current-display-frame debug-buf)) (current-display-frame bucket-group) arg1) + (with-dma-buffer-add-bucket ((s4-0 (current-display-frame debug-buf)) arg1) (let ((s2-0 (new 'stack 'vector4w)) (v1-7 (new 'stack 'vector4w)) @@ -836,7 +836,7 @@ (if (not arg0) (return #f) ) - (with-dma-buffer-add-bucket ((s0-0 (current-display-frame debug-buf)) (current-display-frame bucket-group) arg1) + (with-dma-buffer-add-bucket ((s0-0 (current-display-frame debug-buf)) arg1) (draw-sprite2d-xy s0-0 arg2 arg3 255 14 (new 'static 'rgba :a #x40)) (draw-sprite2d-xy s0-0 arg2 (+ arg3 2) (the int (* 255.0 arg4)) 10 arg5) ) diff --git a/goal_src/engine/debug/menu.gc b/goal_src/engine/debug/menu.gc index 3e3883ebb4..afb7ae362d 100644 --- a/goal_src/engine/debug/menu.gc +++ b/goal_src/engine/debug/menu.gc @@ -623,7 +623,6 @@ (else (font-color dim-gray)) )) (with-dma-buffer-add-bucket ((s3-0 (current-display-frame debug-buf)) - (current-display-frame bucket-group) (bucket-id debug-draw1)) (draw-string-adv (-> arg0 name) s3-0 s5-0) (draw-string-adv "..." s3-0 s5-0) @@ -653,7 +652,6 @@ ) ) (with-dma-buffer-add-bucket ((s4-0 (current-display-frame debug-buf)) - (current-display-frame bucket-group) (bucket-id debug-draw1)) (draw-string (-> arg0 name) s4-0 v1-2) ) @@ -683,7 +681,6 @@ ) ) (with-dma-buffer-add-bucket ((s4-0 (current-display-frame debug-buf)) - (current-display-frame bucket-group) (bucket-id debug-draw1)) (draw-string (-> arg0 name) s4-0 v1-2) ) @@ -710,7 +707,6 @@ ) ) (with-dma-buffer-add-bucket ((s1-0 (current-display-frame debug-buf)) - (current-display-frame bucket-group) (bucket-id debug-draw1)) (draw-string-adv (-> arg0 name) s1-0 s5-0) (draw-string-adv ":" s1-0 s5-0) @@ -784,7 +780,6 @@ ) ) (with-dma-buffer-add-bucket ((s0-0 (current-display-frame debug-buf)) - (current-display-frame bucket-group) (bucket-id debug-draw1)) (draw-sprite2d-xy s0-0 arg1 arg2 (-> arg0 pix-width) (-> arg0 pix-height) (static-rgba #x00 #x00 #x00 #x40)) ) @@ -802,7 +797,6 @@ ) (set-origin! (-> arg0 context font) s3-1 s2-1) (with-dma-buffer-add-bucket ((sv-16 (current-display-frame debug-buf)) - (current-display-frame bucket-group) (bucket-id debug-draw1)) (draw-string ">" sv-16 (-> arg0 context font)) ) diff --git a/goal_src/engine/dma/dma-buffer.gc b/goal_src/engine/dma/dma-buffer.gc index e7d93098ad..9d7aa106cf 100644 --- a/goal_src/engine/dma/dma-buffer.gc +++ b/goal_src/engine/dma/dma-buffer.gc @@ -423,12 +423,13 @@ ) ) -(defmacro with-dma-buffer-add-bucket (bindings &rest body) +(defmacro with-dma-buffer-add-bucket (bindings &key (bucket-group (current-display-frame bucket-group)) &rest body) "Bind a dma-buffer to a variable and use it on a block to allow adding things to a new bucket. - usage: (with-dma-buffer-add-bucket ((buffer-name buffer) bucket bucket-id) &rest body " + usage: (with-dma-buffer-add-bucket ((buffer-name buffer) bucket-id) &rest body + example: (with-dma-buffer-add-bucket ((buf (current-display-frame debug-buf)) (bucket-id debug-draw1)) ...)" - `(let (,(car bindings)) - (with-dma-bucket (,(caar bindings) ,(second bindings) ,(third bindings)) + `(let ((,(caar bindings) ,(cadar bindings))) + (with-dma-bucket (,(caar bindings) ,bucket-group ,(cadr bindings)) ,@body ) ) diff --git a/goal_src/engine/game/main.gc b/goal_src/engine/game/main.gc index 0ea948e503..1cff443b93 100644 --- a/goal_src/engine/game/main.gc +++ b/goal_src/engine/game/main.gc @@ -20,7 +20,6 @@ (defun letterbox () "Draw the letterbox black rectangles" (with-dma-buffer-add-bucket ((dma-buf (current-display-frame global-buf)) - (current-display-frame bucket-group) (bucket-id debug-draw1)) ;; debug-draw1 is one of the last buckets ;; draw the two sprites (draw-sprite2d-xy dma-buf 0 0 512 25 (new 'static 'rgba :a #x80)) @@ -46,7 +45,6 @@ (defun blackout () "Draw the blackout rectangle, convering the entire screen in darkness." (with-dma-buffer-add-bucket ((dma-buf (current-display-frame global-buf)) - (current-display-frame bucket-group) (bucket-id debug-draw1)) ;; debug-draw1 is one of the last buckets (draw-sprite2d-xy dma-buf 0 0 512 224 (new 'static 'rgba :a #x80)) ) @@ -854,7 +852,6 @@ (current-display-frame debug-buf) (current-display-frame global-buf) )) - (current-display-frame bucket-group) (bucket-id debug-draw0)) (show-iop-memory dma-buff) ) diff --git a/goal_src/engine/gfx/generic/generic.gc b/goal_src/engine/gfx/generic/generic.gc index 5476485c00..61b8c56fb7 100644 --- a/goal_src/engine/gfx/generic/generic.gc +++ b/goal_src/engine/gfx/generic/generic.gc @@ -33,9 +33,7 @@ (let ((s1-0 (-> *generic-foreground-sinks* s4-0))) (when s1-0 (let ((s3-0 (-> s1-0 bucket))) - (with-dma-buffer-add-bucket ((s0-0 (current-display-frame global-buf)) - (current-display-frame bucket-group) - s3-0) + (with-dma-buffer-add-bucket ((s0-0 (current-display-frame global-buf)) s3-0) (if (>= s4-0 7) (generic-init-buf s0-0 1 s5-0) (generic-init-buf s0-0 1 gp-0) diff --git a/goal_src/engine/gfx/sprite/sprite.gc b/goal_src/engine/gfx/sprite/sprite.gc index 55b3d6dd0c..915a7974db 100644 --- a/goal_src/engine/gfx/sprite/sprite.gc +++ b/goal_src/engine/gfx/sprite/sprite.gc @@ -820,9 +820,7 @@ ;; start of our DMA for all the sprite data (let ((dma-mem-begin (current-display-frame global-buf base))) ;; draw in global-buf - (with-dma-buffer-add-bucket ((dma-buff (current-display-frame global-buf)) - (current-display-frame bucket-group) - (bucket-id sprite)) + (with-dma-buffer-add-bucket ((dma-buff (current-display-frame global-buf)) (bucket-id sprite)) ;; run the distorters (sprite-init-distorter dma-buff (-> disp frames (-> disp on-screen) draw frame1 fbp)) diff --git a/goal_src/engine/gfx/texture.gc b/goal_src/engine/gfx/texture.gc index 92bd1b8e63..9fba5250be 100644 --- a/goal_src/engine/gfx/texture.gc +++ b/goal_src/engine/gfx/texture.gc @@ -801,7 +801,6 @@ ) (let ((total-upload-size 0)) (with-dma-buffer-add-bucket ((dma-buf (current-display-frame global-buf)) ;; the global DMA buffer - (current-display-frame bucket-group) bucket-idx) ;; default to segment 0 only (mode 0) @@ -986,7 +985,6 @@ ) (let ((total-upload-size 0)) (with-dma-buffer-add-bucket ((dma-buf (current-display-frame global-buf)) - (current-display-frame bucket-group) bucket-idx) (set! tex-data (-> page segment 0 block-data)) ;; data in RAM @@ -1600,7 +1598,6 @@ ;; use bucket numbers for the 0th level ;; TFRAG (with-dma-buffer-add-bucket ((v1-4 (current-display-frame global-buf)) - (current-display-frame bucket-group) (bucket-id tfrag-tex0)) (dma-buffer-add-cnt-vif2 v1-4 0 (new 'static 'vif-tag :cmd (vif-cmd nop)) @@ -1610,7 +1607,6 @@ ;; the rest are the same ;; PRIS (with-dma-buffer-add-bucket ((v1-12 (current-display-frame global-buf)) - (current-display-frame bucket-group) (bucket-id pris-tex0)) (dma-buffer-add-cnt-vif2 v1-12 0 (new 'static 'vif-tag :cmd (vif-cmd nop)) @@ -1619,7 +1615,6 @@ ) ;; SHRUB (with-dma-buffer-add-bucket ((v1-20 (current-display-frame global-buf)) - (current-display-frame bucket-group) (bucket-id shrub-tex0)) (dma-buffer-add-cnt-vif2 v1-20 0 (new 'static 'vif-tag :cmd (vif-cmd nop)) @@ -1628,7 +1623,6 @@ ) ;; ALPHA (with-dma-buffer-add-bucket ((v1-28 (current-display-frame global-buf)) - (current-display-frame bucket-group) (bucket-id alpha-tex0)) (dma-buffer-add-cnt-vif2 v1-28 0 (new 'static 'vif-tag :cmd (vif-cmd nop)) @@ -1639,7 +1633,6 @@ (else ;; TFRAG (with-dma-buffer-add-bucket ((v1-36 (current-display-frame global-buf)) - (current-display-frame bucket-group) (bucket-id tfrag-tex1)) (dma-buffer-add-cnt-vif2 v1-36 0 (new 'static 'vif-tag :cmd (vif-cmd nop)) @@ -1648,7 +1641,6 @@ ) ;; PRIS (with-dma-buffer-add-bucket ((v1-44 (current-display-frame global-buf)) - (current-display-frame bucket-group) (bucket-id pris-tex1)) (dma-buffer-add-cnt-vif2 v1-44 0 (new 'static 'vif-tag :cmd (vif-cmd nop)) @@ -1657,7 +1649,6 @@ ) ;; SHRUB (with-dma-buffer-add-bucket ((v1-52 (current-display-frame global-buf)) - (current-display-frame bucket-group) (bucket-id shrub-tex1)) (dma-buffer-add-cnt-vif2 v1-52 0 (new 'static 'vif-tag :cmd (vif-cmd nop)) @@ -1666,7 +1657,6 @@ ) ;; ALPHA (with-dma-buffer-add-bucket ((v1-60 (current-display-frame global-buf)) - (current-display-frame bucket-group) (bucket-id alpha-tex1)) (dma-buffer-add-cnt-vif2 v1-60 0 (new 'static 'vif-tag :cmd (vif-cmd nop)) diff --git a/goal_src/goos-lib.gs b/goal_src/goos-lib.gs index 639907a3b0..1ca26fca2b 100644 --- a/goal_src/goos-lib.gs +++ b/goal_src/goos-lib.gs @@ -65,6 +65,12 @@ (defsmacro cdddr (x) `(cdr (cdr (cdr ,x)))) +(defsmacro caadr (x) + `(car (car (cdr ,x)))) + +(defsmacro cadar (x) + `(car (cdr (car ,x)))) + (desfun first (x) (car x)) diff --git a/goal_src/pc_debug/pc-pad-utils.gc b/goal_src/pc_debug/pc-pad-utils.gc index 71e72bf0ee..96ef89ace8 100644 --- a/goal_src/pc_debug/pc-pad-utils.gc +++ b/goal_src/pc_debug/pc-pad-utils.gc @@ -112,7 +112,6 @@ (set-state-time) (until (time-passed? PC_PAD_INPUT_NOTICE_TIME) (with-dma-buffer-add-bucket ((buf (current-display-frame debug-buf)) - (current-display-frame bucket-group) (bucket-id debug-draw1)) (draw-string-xy (string-format "MAPPED ~D TO ~S!" (pc-pad-input-key-get) (-> *pc-pad-button-names* (1- (-> self input-index)))) @@ -138,7 +137,6 @@ (set-state-time) (until (time-passed? PC_PAD_INPUT_NOTICE_TIME) (with-dma-buffer-add-bucket ((buf (current-display-frame debug-buf)) - (current-display-frame bucket-group) (bucket-id debug-draw1)) (draw-string-xy "CANCELED!" buf 256 96 (font-color red-reverse) (font-flags shadow kerning large middle)) ) @@ -155,7 +153,6 @@ (set-state-time) (until (time-passed? PC_PAD_INPUT_NOTICE_TIME) (with-dma-buffer-add-bucket ((buf (current-display-frame debug-buf)) - (current-display-frame bucket-group) (bucket-id debug-draw1)) (draw-string-xy (string-format "MAPPED ~D TO ~S!" (pc-pad-input-key-get) (-> *pc-pad-button-names* (1- (-> self input-index)))) @@ -166,7 +163,6 @@ (set-state-time) (until (time-passed? PC_PAD_INPUT_NOTICE_TIME) (with-dma-buffer-add-bucket ((buf (current-display-frame debug-buf)) - (current-display-frame bucket-group) (bucket-id debug-draw1)) (draw-string-xy "KEY MAPPING COMPLETE!" buf 256 96 (font-color green) (font-flags shadow kerning large middle)) ) @@ -181,7 +177,6 @@ (set-state-time) (loop (with-dma-buffer-add-bucket ((buf (current-display-frame debug-buf)) - (current-display-frame bucket-group) (bucket-id debug-draw1)) (if (< (mod (time-passed) (seconds 2)) (seconds 1)) (draw-string-xy "NOW MAPPING PAD" buf 256 32 (font-color red) (font-flags shadow kerning large middle)) From b76bd7bc5f74698ec0093166d0d908e5740dd38b Mon Sep 17 00:00:00 2001 From: ManDude <7569514+ManDude@users.noreply.github.com> Date: Tue, 17 Aug 2021 06:24:29 +0100 Subject: [PATCH 18/23] fix offline ref --- test/decompiler/reference/engine/gfx/font-h_REF.gc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/decompiler/reference/engine/gfx/font-h_REF.gc b/test/decompiler/reference/engine/gfx/font-h_REF.gc index 5e5a10ec5e..1eb24b627d 100644 --- a/test/decompiler/reference/engine/gfx/font-h_REF.gc +++ b/test/decompiler/reference/engine/gfx/font-h_REF.gc @@ -265,7 +265,7 @@ (buf basic :offset-assert 3024) (str-ptr uint32 :offset-assert 3028) (str-ptr-signed (pointer uint8) :offset 3028) - (flags uint32 :offset-assert 3032) + (flags font-flags :offset-assert 3032) (flags-signed int32 :offset 3032) (reg-save uint32 5 :offset-assert 3036) ) From 63b408773acd8ef86642b88b22173c302409756d Mon Sep 17 00:00:00 2001 From: ManDude <7569514+ManDude@users.noreply.github.com> Date: Tue, 17 Aug 2021 06:32:14 +0100 Subject: [PATCH 19/23] make `pc-pad-input-stop` cancel button mapping --- goal_src/pc_debug/pc-pad-utils.gc | 1 + 1 file changed, 1 insertion(+) diff --git a/goal_src/pc_debug/pc-pad-utils.gc b/goal_src/pc_debug/pc-pad-utils.gc index 96ef89ace8..1522de46cd 100644 --- a/goal_src/pc_debug/pc-pad-utils.gc +++ b/goal_src/pc_debug/pc-pad-utils.gc @@ -238,6 +238,7 @@ "Stop the PC port pad debug key mapping" (kill-by-name 'pc-pad-input *active-pool*) + (pc-pad-input-mode-set 'canceled) ) ) From 1f15165b33a544960801a4c43aba841c3d465320 Mon Sep 17 00:00:00 2001 From: ManDude <7569514+ManDude@users.noreply.github.com> Date: Tue, 17 Aug 2021 08:04:33 +0100 Subject: [PATCH 20/23] rename `current-display-frame` and make it less confusing --- goal_src/engine/debug/debug.gc | 18 +++++++++--------- goal_src/engine/debug/menu.gc | 12 ++++++------ goal_src/engine/dma/dma-buffer.gc | 4 ++-- goal_src/engine/draw/drawable.gc | 4 ++-- goal_src/engine/game/main.gc | 8 ++++---- goal_src/engine/gfx/generic/generic.gc | 2 +- goal_src/engine/gfx/hw/display-h.gc | 4 ++-- goal_src/engine/gfx/sprite/sprite.gc | 2 +- goal_src/engine/gfx/texture.gc | 20 ++++++++++---------- goal_src/pc_debug/pc-pad-utils.gc | 10 +++++----- 10 files changed, 42 insertions(+), 42 deletions(-) diff --git a/goal_src/engine/debug/debug.gc b/goal_src/engine/debug/debug.gc index 15bbc802d5..832207c4ed 100644 --- a/goal_src/engine/debug/debug.gc +++ b/goal_src/engine/debug/debug.gc @@ -58,7 +58,7 @@ (set! (-> pt w) 1.0) (when (transform-point-qword! (-> s5-0 vector 0) pt) - (with-dma-buffer-add-bucket ((v1-7 (current-display-frame debug-buf)) bucket) + (with-dma-buffer-add-bucket ((v1-7 (-> (current-frame) debug-buf)) bucket) (with-cnt-vif-block (v1-7) (dma-buffer-add-gif-tag v1-7 @@ -118,7 +118,7 @@ 'fade, 'fade-depth, or #f. second-color can be -1 to just use the same color. " - (let ((a0-4 (current-display-frame debug-buf))) + (let ((a0-4 (-> (current-frame) debug-buf))) (if (< (the-as uint (shr (+ (&- (-> a0-4 end) (the-as uint (-> a0-4 base))) 15) 4)) (the-as uint #x8000)) (return (the-as pointer #f)) ) @@ -147,7 +147,7 @@ (when (and (transform-point-qword! (-> s4-0 vector 0) p0) (transform-point-qword! (-> s4-0 vector 1) p1) ) - (with-dma-buffer-add-bucket ((v1-28 (current-display-frame debug-buf)) bucket) + (with-dma-buffer-add-bucket ((v1-28 (-> (current-frame) debug-buf)) bucket) (with-cnt-vif-block (v1-28) (dma-buffer-add-gif-tag v1-28 (new 'static 'gif-tag64 :nloop 1 :eop 1 :pre 1 :nreg 4 :prim (gif-prim line)) @@ -205,7 +205,7 @@ (set! (-> s2-0 quad) (the-as uint128 0)) (when (transform-point-qword! (the-as vector4w s2-0) location) - (with-dma-buffer-add-bucket ((s3-0 (current-display-frame debug-buf)) bucket) + (with-dma-buffer-add-bucket ((s3-0 (-> (current-frame) debug-buf)) bucket) (let ((a2-2 (new 'stack 'font-context *font-default-matrix* (+ (+ (-> offset x) -1792) (/ (-> s2-0 x) 16)) @@ -268,7 +268,7 @@ (transform-point-qword! (-> s5-0 vector 1) p1) (transform-point-qword! (-> s5-0 vector 2) p2) ) - (with-dma-buffer-add-bucket ((v1-9 (current-display-frame debug-buf)) bucket) + (with-dma-buffer-add-bucket ((v1-9 (-> (current-frame) debug-buf)) bucket) (with-cnt-vif-block (v1-9) (dma-buffer-add-gif-tag v1-9 (new 'static 'gif-tag64 :nloop 1 :eop 1 :pre 1 :nreg 6 :prim (gif-prim tri)) @@ -448,7 +448,7 @@ (if (not arg0) (return #f) ) - (with-dma-buffer-add-bucket ((s4-0 (current-display-frame debug-buf)) arg1) + (with-dma-buffer-add-bucket ((s4-0 (-> (current-frame) debug-buf)) arg1) (let ((s2-0 (new 'stack 'vector4w)) (v1-7 (new 'stack 'vector4w)) @@ -836,7 +836,7 @@ (if (not arg0) (return #f) ) - (with-dma-buffer-add-bucket ((s0-0 (current-display-frame debug-buf)) arg1) + (with-dma-buffer-add-bucket ((s0-0 (-> (current-frame) debug-buf)) arg1) (draw-sprite2d-xy s0-0 arg2 arg3 255 14 (new 'static 'rgba :a #x40)) (draw-sprite2d-xy s0-0 arg2 (+ arg3 2) (the int (* 255.0 arg4)) 10 arg5) ) @@ -869,7 +869,7 @@ (set! (-> gp-0 0 x) (* (sin (-> arg0 stick0-dir)) (-> arg0 stick0-speed))) (set! (-> gp-0 0 y) (* (cos (-> arg0 stick0-dir)) (-> arg0 stick0-speed))) (dotimes (s5-1 32) - (let* ((s3-0 (current-display-frame debug-buf)) + (let* ((s3-0 (-> (current-frame) debug-buf)) (s4-0 (-> s3-0 base)) ) (draw-sprite2d-xy @@ -888,7 +888,7 @@ (set! (-> s3-0 base) (&+ (the-as pointer v1-12) 16)) ) (dma-bucket-insert-tag - (current-display-frame bucket-group) + (-> (current-frame) bucket-group) (bucket-id debug-draw0) s4-0 (the-as (pointer dma-tag) a3-1) diff --git a/goal_src/engine/debug/menu.gc b/goal_src/engine/debug/menu.gc index afb7ae362d..bd334b1d82 100644 --- a/goal_src/engine/debug/menu.gc +++ b/goal_src/engine/debug/menu.gc @@ -622,7 +622,7 @@ (arg4 (font-color dark-light-blue)) (else (font-color dim-gray)) )) - (with-dma-buffer-add-bucket ((s3-0 (current-display-frame debug-buf)) + (with-dma-buffer-add-bucket ((s3-0 (-> (current-frame) debug-buf)) (bucket-id debug-draw1)) (draw-string-adv (-> arg0 name) s3-0 s5-0) (draw-string-adv "..." s3-0 s5-0) @@ -651,7 +651,7 @@ ) ) ) - (with-dma-buffer-add-bucket ((s4-0 (current-display-frame debug-buf)) + (with-dma-buffer-add-bucket ((s4-0 (-> (current-frame) debug-buf)) (bucket-id debug-draw1)) (draw-string (-> arg0 name) s4-0 v1-2) ) @@ -680,7 +680,7 @@ ) ) ) - (with-dma-buffer-add-bucket ((s4-0 (current-display-frame debug-buf)) + (with-dma-buffer-add-bucket ((s4-0 (-> (current-frame) debug-buf)) (bucket-id debug-draw1)) (draw-string (-> arg0 name) s4-0 v1-2) ) @@ -706,7 +706,7 @@ ) ) ) - (with-dma-buffer-add-bucket ((s1-0 (current-display-frame debug-buf)) + (with-dma-buffer-add-bucket ((s1-0 (-> (current-frame) debug-buf)) (bucket-id debug-draw1)) (draw-string-adv (-> arg0 name) s1-0 s5-0) (draw-string-adv ":" s1-0 s5-0) @@ -779,7 +779,7 @@ (set! arg2 (- arg2 (* (+ v1-0 -16) 8))) ) ) - (with-dma-buffer-add-bucket ((s0-0 (current-display-frame debug-buf)) + (with-dma-buffer-add-bucket ((s0-0 (-> (current-frame) debug-buf)) (bucket-id debug-draw1)) (draw-sprite2d-xy s0-0 arg1 arg2 (-> arg0 pix-width) (-> arg0 pix-height) (static-rgba #x00 #x00 #x00 #x40)) ) @@ -796,7 +796,7 @@ ) ) (set-origin! (-> arg0 context font) s3-1 s2-1) - (with-dma-buffer-add-bucket ((sv-16 (current-display-frame debug-buf)) + (with-dma-buffer-add-bucket ((sv-16 (-> (current-frame) debug-buf)) (bucket-id debug-draw1)) (draw-string ">" sv-16 (-> arg0 context font)) ) diff --git a/goal_src/engine/dma/dma-buffer.gc b/goal_src/engine/dma/dma-buffer.gc index 9d7aa106cf..8dfaa0a8b3 100644 --- a/goal_src/engine/dma/dma-buffer.gc +++ b/goal_src/engine/dma/dma-buffer.gc @@ -423,10 +423,10 @@ ) ) -(defmacro with-dma-buffer-add-bucket (bindings &key (bucket-group (current-display-frame bucket-group)) &rest body) +(defmacro with-dma-buffer-add-bucket (bindings &key (bucket-group (-> (current-frame) bucket-group)) &rest body) "Bind a dma-buffer to a variable and use it on a block to allow adding things to a new bucket. usage: (with-dma-buffer-add-bucket ((buffer-name buffer) bucket-id) &rest body - example: (with-dma-buffer-add-bucket ((buf (current-display-frame debug-buf)) (bucket-id debug-draw1)) ...)" + example: (with-dma-buffer-add-bucket ((buf (-> (current-frame) debug-buf)) (bucket-id debug-draw1)) ...)" `(let ((,(caar bindings) ,(cadar bindings))) (with-dma-bucket (,(caar bindings) ,bucket-group ,(cadr bindings)) diff --git a/goal_src/engine/draw/drawable.gc b/goal_src/engine/draw/drawable.gc index 3f4e373396..b9759b7e07 100644 --- a/goal_src/engine/draw/drawable.gc +++ b/goal_src/engine/draw/drawable.gc @@ -395,8 +395,8 @@ (defmacro cpu-usage () "print out the cpu usage of the most recently rendered frame" `(format #t "CPU: ~,,2f%~%frame-time: ~,,1fms~%" - (* 100. (/ (the float (current-display-frame run-time)) *ticks-per-frame*)) - (* 1000. (/ 1. 60.) (/ (the float (current-display-frame run-time)) *ticks-per-frame*)) + (* 100. (/ (the float (-> (current-frame) run-time)) *ticks-per-frame*)) + (* 1000. (/ 1. 60.) (/ (the float (-> (current-frame) run-time)) *ticks-per-frame*)) ) ) diff --git a/goal_src/engine/game/main.gc b/goal_src/engine/game/main.gc index 1cff443b93..7ba3f6a128 100644 --- a/goal_src/engine/game/main.gc +++ b/goal_src/engine/game/main.gc @@ -19,7 +19,7 @@ (defun letterbox () "Draw the letterbox black rectangles" - (with-dma-buffer-add-bucket ((dma-buf (current-display-frame global-buf)) + (with-dma-buffer-add-bucket ((dma-buf (-> (current-frame) global-buf)) (bucket-id debug-draw1)) ;; debug-draw1 is one of the last buckets ;; draw the two sprites (draw-sprite2d-xy dma-buf 0 0 512 25 (new 'static 'rgba :a #x80)) @@ -44,7 +44,7 @@ (defun blackout () "Draw the blackout rectangle, convering the entire screen in darkness." - (with-dma-buffer-add-bucket ((dma-buf (current-display-frame global-buf)) + (with-dma-buffer-add-bucket ((dma-buf (-> (current-frame) global-buf)) (bucket-id debug-draw1)) ;; debug-draw1 is one of the last buckets (draw-sprite2d-xy dma-buf 0 0 512 224 (new 'static 'rgba :a #x80)) ) @@ -849,8 +849,8 @@ (when (nonzero? (logand (-> *cpad-list* cpads 1 button0-abs 0) (pad-buttons r3))) ;; grab a dma buffer (with-dma-buffer-add-bucket ((dma-buff (if *debug-segment* - (current-display-frame debug-buf) - (current-display-frame global-buf) + (-> (current-frame) debug-buf) + (-> (current-frame) global-buf) )) (bucket-id debug-draw0)) (show-iop-memory dma-buff) diff --git a/goal_src/engine/gfx/generic/generic.gc b/goal_src/engine/gfx/generic/generic.gc index 61b8c56fb7..b174041586 100644 --- a/goal_src/engine/gfx/generic/generic.gc +++ b/goal_src/engine/gfx/generic/generic.gc @@ -33,7 +33,7 @@ (let ((s1-0 (-> *generic-foreground-sinks* s4-0))) (when s1-0 (let ((s3-0 (-> s1-0 bucket))) - (with-dma-buffer-add-bucket ((s0-0 (current-display-frame global-buf)) s3-0) + (with-dma-buffer-add-bucket ((s0-0 (-> (current-frame) global-buf)) s3-0) (if (>= s4-0 7) (generic-init-buf s0-0 1 s5-0) (generic-init-buf s0-0 1 gp-0) diff --git a/goal_src/engine/gfx/hw/display-h.gc b/goal_src/engine/gfx/hw/display-h.gc index 29c02cd541..5f43b84920 100644 --- a/goal_src/engine/gfx/hw/display-h.gc +++ b/goal_src/engine/gfx/hw/display-h.gc @@ -231,8 +231,8 @@ (define *post-draw-hook* (the-as (function dma-buffer none) nothing)) -(defmacro current-display-frame (&rest args) - `(-> *display* frames (-> *display* on-screen) frame ,@args) +(defmacro current-frame () + `(-> *display* frames (-> *display* on-screen) frame) ) (defmacro current-time () diff --git a/goal_src/engine/gfx/sprite/sprite.gc b/goal_src/engine/gfx/sprite/sprite.gc index 915a7974db..9095d1f31f 100644 --- a/goal_src/engine/gfx/sprite/sprite.gc +++ b/goal_src/engine/gfx/sprite/sprite.gc @@ -820,7 +820,7 @@ ;; start of our DMA for all the sprite data (let ((dma-mem-begin (current-display-frame global-buf base))) ;; draw in global-buf - (with-dma-buffer-add-bucket ((dma-buff (current-display-frame global-buf)) (bucket-id sprite)) + (with-dma-buffer-add-bucket ((dma-buff (-> (current-frame) global-buf)) (bucket-id sprite)) ;; run the distorters (sprite-init-distorter dma-buff (-> disp frames (-> disp on-screen) draw frame1 fbp)) diff --git a/goal_src/engine/gfx/texture.gc b/goal_src/engine/gfx/texture.gc index 9fba5250be..f3d9efa4a7 100644 --- a/goal_src/engine/gfx/texture.gc +++ b/goal_src/engine/gfx/texture.gc @@ -800,7 +800,7 @@ (tex-id uint) ) (let ((total-upload-size 0)) - (with-dma-buffer-add-bucket ((dma-buf (current-display-frame global-buf)) ;; the global DMA buffer + (with-dma-buffer-add-bucket ((dma-buf (-> (current-frame) global-buf)) ;; the global DMA buffer bucket-idx) ;; default to segment 0 only (mode 0) @@ -984,7 +984,7 @@ (need-tex symbol) ) (let ((total-upload-size 0)) - (with-dma-buffer-add-bucket ((dma-buf (current-display-frame global-buf)) + (with-dma-buffer-add-bucket ((dma-buf (-> (current-frame) global-buf)) bucket-idx) (set! tex-data (-> page segment 0 block-data)) ;; data in RAM @@ -1597,7 +1597,7 @@ ((zero? (-> obj index)) ;; use bucket numbers for the 0th level ;; TFRAG - (with-dma-buffer-add-bucket ((v1-4 (current-display-frame global-buf)) + (with-dma-buffer-add-bucket ((v1-4 (-> (current-frame) global-buf)) (bucket-id tfrag-tex0)) (dma-buffer-add-cnt-vif2 v1-4 0 (new 'static 'vif-tag :cmd (vif-cmd nop)) @@ -1606,7 +1606,7 @@ ) ;; the rest are the same ;; PRIS - (with-dma-buffer-add-bucket ((v1-12 (current-display-frame global-buf)) + (with-dma-buffer-add-bucket ((v1-12 (-> (current-frame) global-buf)) (bucket-id pris-tex0)) (dma-buffer-add-cnt-vif2 v1-12 0 (new 'static 'vif-tag :cmd (vif-cmd nop)) @@ -1614,7 +1614,7 @@ ) ) ;; SHRUB - (with-dma-buffer-add-bucket ((v1-20 (current-display-frame global-buf)) + (with-dma-buffer-add-bucket ((v1-20 (-> (current-frame) global-buf)) (bucket-id shrub-tex0)) (dma-buffer-add-cnt-vif2 v1-20 0 (new 'static 'vif-tag :cmd (vif-cmd nop)) @@ -1622,7 +1622,7 @@ ) ) ;; ALPHA - (with-dma-buffer-add-bucket ((v1-28 (current-display-frame global-buf)) + (with-dma-buffer-add-bucket ((v1-28 (-> (current-frame) global-buf)) (bucket-id alpha-tex0)) (dma-buffer-add-cnt-vif2 v1-28 0 (new 'static 'vif-tag :cmd (vif-cmd nop)) @@ -1632,7 +1632,7 @@ ) (else ;; TFRAG - (with-dma-buffer-add-bucket ((v1-36 (current-display-frame global-buf)) + (with-dma-buffer-add-bucket ((v1-36 (-> (current-frame) global-buf)) (bucket-id tfrag-tex1)) (dma-buffer-add-cnt-vif2 v1-36 0 (new 'static 'vif-tag :cmd (vif-cmd nop)) @@ -1640,7 +1640,7 @@ ) ) ;; PRIS - (with-dma-buffer-add-bucket ((v1-44 (current-display-frame global-buf)) + (with-dma-buffer-add-bucket ((v1-44 (-> (current-frame) global-buf)) (bucket-id pris-tex1)) (dma-buffer-add-cnt-vif2 v1-44 0 (new 'static 'vif-tag :cmd (vif-cmd nop)) @@ -1648,7 +1648,7 @@ ) ) ;; SHRUB - (with-dma-buffer-add-bucket ((v1-52 (current-display-frame global-buf)) + (with-dma-buffer-add-bucket ((v1-52 (-> (current-frame) global-buf)) (bucket-id shrub-tex1)) (dma-buffer-add-cnt-vif2 v1-52 0 (new 'static 'vif-tag :cmd (vif-cmd nop)) @@ -1656,7 +1656,7 @@ ) ) ;; ALPHA - (with-dma-buffer-add-bucket ((v1-60 (current-display-frame global-buf)) + (with-dma-buffer-add-bucket ((v1-60 (-> (current-frame) global-buf)) (bucket-id alpha-tex1)) (dma-buffer-add-cnt-vif2 v1-60 0 (new 'static 'vif-tag :cmd (vif-cmd nop)) diff --git a/goal_src/pc_debug/pc-pad-utils.gc b/goal_src/pc_debug/pc-pad-utils.gc index 1522de46cd..c19ba84749 100644 --- a/goal_src/pc_debug/pc-pad-utils.gc +++ b/goal_src/pc_debug/pc-pad-utils.gc @@ -111,7 +111,7 @@ :code (behavior () (set-state-time) (until (time-passed? PC_PAD_INPUT_NOTICE_TIME) - (with-dma-buffer-add-bucket ((buf (current-display-frame debug-buf)) + (with-dma-buffer-add-bucket ((buf (-> (current-frame) debug-buf)) (bucket-id debug-draw1)) (draw-string-xy (string-format "MAPPED ~D TO ~S!" (pc-pad-input-key-get) (-> *pc-pad-button-names* (1- (-> self input-index)))) @@ -136,7 +136,7 @@ :code (behavior () (set-state-time) (until (time-passed? PC_PAD_INPUT_NOTICE_TIME) - (with-dma-buffer-add-bucket ((buf (current-display-frame debug-buf)) + (with-dma-buffer-add-bucket ((buf (-> (current-frame) debug-buf)) (bucket-id debug-draw1)) (draw-string-xy "CANCELED!" buf 256 96 (font-color red-reverse) (font-flags shadow kerning large middle)) ) @@ -152,7 +152,7 @@ (pc-pad-input-map-save!) (set-state-time) (until (time-passed? PC_PAD_INPUT_NOTICE_TIME) - (with-dma-buffer-add-bucket ((buf (current-display-frame debug-buf)) + (with-dma-buffer-add-bucket ((buf (-> (current-frame) debug-buf)) (bucket-id debug-draw1)) (draw-string-xy (string-format "MAPPED ~D TO ~S!" (pc-pad-input-key-get) (-> *pc-pad-button-names* (1- (-> self input-index)))) @@ -162,7 +162,7 @@ ) (set-state-time) (until (time-passed? PC_PAD_INPUT_NOTICE_TIME) - (with-dma-buffer-add-bucket ((buf (current-display-frame debug-buf)) + (with-dma-buffer-add-bucket ((buf (-> (current-frame) debug-buf)) (bucket-id debug-draw1)) (draw-string-xy "KEY MAPPING COMPLETE!" buf 256 96 (font-color green) (font-flags shadow kerning large middle)) ) @@ -176,7 +176,7 @@ :code (behavior () (set-state-time) (loop - (with-dma-buffer-add-bucket ((buf (current-display-frame debug-buf)) + (with-dma-buffer-add-bucket ((buf (-> (current-frame) debug-buf)) (bucket-id debug-draw1)) (if (< (mod (time-passed) (seconds 2)) (seconds 1)) (draw-string-xy "NOW MAPPING PAD" buf 256 32 (font-color red) (font-flags shadow kerning large middle)) From b18af4efae6363caac8bb340da78a2cd69ba2689 Mon Sep 17 00:00:00 2001 From: ManDude <7569514+ManDude@users.noreply.github.com> Date: Tue, 17 Aug 2021 08:05:01 +0100 Subject: [PATCH 21/23] fix typo in comment while we're at it --- game/graphics/pipelines/opengl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game/graphics/pipelines/opengl.cpp b/game/graphics/pipelines/opengl.cpp index b134df27e0..4f116a7b0b 100644 --- a/game/graphics/pipelines/opengl.cpp +++ b/game/graphics/pipelines/opengl.cpp @@ -80,7 +80,7 @@ static int gl_init(GfxSettings& settings) { return 1; } - // request an OpenGL 3.3 Core + // request an OpenGL 3.3 Core context glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // 3.3 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // core profile, not compat From 67f236d32b7cefb55a23aab45c810ebe6936b300 Mon Sep 17 00:00:00 2001 From: ManDude <7569514+ManDude@users.noreply.github.com> Date: Tue, 17 Aug 2021 08:05:18 +0100 Subject: [PATCH 22/23] Update opengl.cpp --- game/graphics/pipelines/opengl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game/graphics/pipelines/opengl.cpp b/game/graphics/pipelines/opengl.cpp index 4f116a7b0b..0df53ec068 100644 --- a/game/graphics/pipelines/opengl.cpp +++ b/game/graphics/pipelines/opengl.cpp @@ -290,5 +290,5 @@ const GfxRendererModule moduleOpenGL = { gl_texture_relocate, // texture_relocate gl_poll_events, // poll_events GfxPipeline::OpenGL, // pipeline - "OpenGL 3.0" // name + "OpenGL 3.3" // name }; From 56f805f6e6b7ba1650023b840275e1717842a6cc Mon Sep 17 00:00:00 2001 From: ManDude <7569514+ManDude@users.noreply.github.com> Date: Tue, 17 Aug 2021 08:15:49 +0100 Subject: [PATCH 23/23] regex has failed me --- goal_src/engine/game/main.gc | 10 +++++----- goal_src/engine/gfx/sprite/sprite.gc | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/goal_src/engine/game/main.gc b/goal_src/engine/game/main.gc index 7ba3f6a128..c16092495c 100644 --- a/goal_src/engine/game/main.gc +++ b/goal_src/engine/game/main.gc @@ -67,6 +67,11 @@ ) ) +(defun movie? () + "Are we in a movie?" + (logtest? (-> *kernel-context* prevent-from-run) (process-mask movie)) + ) + (defun set-master-mode ((new-mode symbol)) "Update pause masks for the given mode, and set *master-mode*" (set! *master-mode* new-mode) @@ -935,11 +940,6 @@ 0 ) -(defun movie? () - "Are we in a movie?" - (nonzero? (logand (-> *kernel-context* prevent-from-run) (process-mask movie))) - ) - (defun display-loop () "This is in progress..." diff --git a/goal_src/engine/gfx/sprite/sprite.gc b/goal_src/engine/gfx/sprite/sprite.gc index 9095d1f31f..aadc865e18 100644 --- a/goal_src/engine/gfx/sprite/sprite.gc +++ b/goal_src/engine/gfx/sprite/sprite.gc @@ -818,7 +818,7 @@ (defun sprite-draw ((disp display)) "Main sprite draw function." ;; start of our DMA for all the sprite data - (let ((dma-mem-begin (current-display-frame global-buf base))) + (let ((dma-mem-begin (-> (current-frame) global-buf base))) ;; draw in global-buf (with-dma-buffer-add-bucket ((dma-buff (-> (current-frame) global-buf)) (bucket-id sprite)) @@ -884,7 +884,7 @@ (set! (-> mem-use data 82 name) "sprite") (+! (-> mem-use data 82 count) 1) (+! (-> mem-use data 82 used) - (&- (current-display-frame global-buf base) + (&- (-> (current-frame) global-buf base) (the-as uint dma-mem-begin) ) )