Merge pull request #760 from ManDude/d/cpad-test

Implement cpad w/ keyboard input into runtime
This commit is contained in:
water111
2021-08-17 19:53:18 -04:00
committed by GitHub
52 changed files with 1293 additions and 277 deletions
+4
View File
@@ -16,9 +16,13 @@ logs/*
.#*#
*.pyc
# output from our tools
*.bin
*.log
*.p2s
savestate-out/
failures/
ee-results.json
# game stuff
game_config/*
+27 -7
View File
@@ -5228,7 +5228,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)
@@ -5240,9 +5240,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)
@@ -5254,7 +5274,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)
@@ -5264,7 +5284,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)
@@ -5273,7 +5293,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)
)
@@ -5315,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)
)
@@ -5368,7 +5388,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))
+1
View File
@@ -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
+12
View File
@@ -0,0 +1,12 @@
#pragma once
/*!
* @file file_paths.h
* File names and directories for user config files.
*/
#include <string>
static const std::string GAME_CONFIG_DIR_NAME = "game_config";
static const std::string SETTINGS_GFX_FILE_NAME = "SETTINGS_GFX.CFG";
+23 -12
View File
@@ -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<GfxDisplay> 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 {
@@ -100,7 +106,8 @@ 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;
@@ -109,6 +116,10 @@ int InitMainDisplay(int width, int height, const char* title, GfxSettings& setti
return 0;
}
void KillMainDisplay() {
KillDisplay(GetMainDisplay());
}
void KillDisplay(std::shared_ptr<GfxDisplay> display) {
// lg::debug("kill display #x{:x}", (uintptr_t)display);
if (!display->is_active()) {
@@ -118,8 +129,8 @@ void KillDisplay(std::shared_ptr<GfxDisplay> 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));
}
}
+2 -1
View File
@@ -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<std::shared_ptr<GfxDisplay>> g_displays;
int InitMainDisplay(int width, int height, const char* title, GfxSettings& settings);
void KillDisplay(std::shared_ptr<GfxDisplay> display);
void KillMainDisplay();
std::shared_ptr<GfxDisplay> GetMainDisplay();
+109 -19
View File
@@ -3,37 +3,81 @@
* Graphics component for the runtime. Abstraction layer for the main graphics routines.
*/
#include "gfx.h"
#include <cstdio>
#include <functional>
#include "common/log/log.h"
#include "game/runtime.h"
#include "display.h"
#include <filesystem>
#include "gfx.h"
#include "display.h"
#include "pipelines/opengl.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"
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];
settings.renderer = GfxPipeline::OpenGL; // Gfx::renderers[0];
// 1 screen update per frame
settings.vsync = 1;
return;
// debug for now
settings.debug = true;
// 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
namespace Gfx {
GfxVertex g_vertices_temp[VERTEX_BUFFER_LENGTH_TEMP];
GfxSettings g_settings;
// const std::vector<const GfxRendererModule*> 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:
@@ -48,12 +92,20 @@ const GfxRendererModule* GetRenderer(GfxPipeline pipeline) {
}
}
const GfxRendererModule* GetCurrentRenderer() {
return GetRenderer(g_settings.renderer);
}
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()) {
LoadSettings();
if (GetCurrentRenderer()->init(g_settings)) {
lg::error("Gfx::Init error");
return 1;
}
@@ -70,6 +122,9 @@ u32 Init() {
void Loop(std::function<bool()> 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");
@@ -80,35 +135,70 @@ void Loop(std::function<bool()> f) {
u32 Exit() {
lg::info("GFX Exit");
Display::KillDisplay(Display::GetMainDisplay());
g_settings.renderer->exit();
Display::KillMainDisplay();
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() {
GetCurrentRenderer()->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
}
}
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
SaveSettings();
}
}
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);
}
} // namespace Gfx
+24 -20
View File
@@ -7,8 +7,10 @@
#include <functional>
#include <memory>
#include "common/common_types.h"
#include "game/kernel/kboot.h"
#include "game/system/newpad.h"
// forward declarations
struct GfxSettings;
@@ -19,17 +21,18 @@ enum class GfxPipeline { Invalid = 0, OpenGL };
// module for the different rendering pipelines
struct GfxRendererModule {
std::function<int()> init;
std::function<int(GfxSettings&)> init;
std::function<std::shared_ptr<GfxDisplay>(int w, int h, const char* title, GfxSettings& settings)>
make_main_display;
std::function<void(GfxDisplay* display)> kill_display;
std::function<void(GfxDisplay* display)> render_display;
std::function<void(GfxDisplay*)> kill_display;
std::function<void(GfxDisplay*)> render_display;
std::function<void()> exit;
std::function<u32()> vsync;
std::function<u32()> sync_path;
std::function<void(const void*, u32)> send_chain;
std::function<void(const u8*, int, u32)> texture_upload_now;
std::function<void(u32, u32, u32)> texture_relocate;
std::function<void()> poll_events;
GfxPipeline pipeline;
const char* name;
@@ -37,30 +40,25 @@ struct GfxRendererModule {
// store settings related to the gfx systems
struct GfxSettings {
const GfxRendererModule* renderer; // which rendering pipeline to use.
// current version of the settings. this should be set up so that newer versions are always higher
// than older versions
// 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;
int vsync; // (temp) number of screen update per frame
};
u64 version; // the version of this settings struct. MUST ALWAYS BE THE FIRST THING!
// struct for a single vertex. this should in theory be renderer-agnostic
struct GfxVertex {
// x y z
float x, y, z;
Pad::MappingInfo pad_mapping_info; // button mapping
Pad::MappingInfo pad_mapping_info_backup; // button mapping backup (see newpad.h)
// rgba or the full u32 thing.
union {
u32 rgba;
struct {
u8 r, g, b, a;
};
};
int vsync; // (temp) number of screen update per frame
bool debug; // graphics debugging
GfxPipeline renderer; // which rendering pipeline to use.
};
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<const GfxRendererModule*> renderers;
@@ -75,5 +73,11 @@ 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();
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);
} // namespace Gfx
+23 -8
View File
@@ -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"
@@ -49,9 +50,11 @@ std::unique_ptr<GraphicsData> 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);
}
});
}
@@ -67,7 +70,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 +80,16 @@ static int gl_init() {
return 1;
}
// request Debug 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_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;
}
@@ -137,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.
@@ -174,10 +185,9 @@ static void gl_render_display(GfxDisplay* display) {
{
std::unique_lock<std::mutex> 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)) {
@@ -263,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
@@ -274,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
"OpenGL 3.3" // name
};
+128 -13
View File
@@ -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;
/*!
@@ -409,27 +410,127 @@ 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<CpadInfo>(cpad_info).c();
if (info->cpad_file == 0) {
auto cpad = Ptr<CPadInfo>(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;
u64 CPadGetData(u64 cpad_info) {
auto cpad = Ptr<CPadInfo>(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 cpad_info;
}
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) == scePadReqStateFailed) {
cpad->state = 76;
}
if (scePadGetReqState(cpad->number, 0) == scePadReqStateComplete) {
cpad->state = 99;
}
break;
case 90:
break; // unsupported controller. too bad!
}
return cpad_info;
}
// TODO InstallHandler
@@ -614,6 +715,20 @@ 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-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);
make_function_symbol_from_c("pc-pad-input-index-get", (void*)Pad::input_mode_get_index);
// 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() {
+19 -7
View File
@@ -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 {
-8
View File
@@ -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
-5
View File
@@ -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
+121
View File
@@ -1,7 +1,16 @@
#include "common/util/assert.h"
#include "libpad.h"
#include "game/kernel/kmachine.h"
#include "game/graphics/gfx.h"
/*!
* @file libpad.cpp
* 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,116 @@ 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);
Gfx::poll_events();
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
+56 -1
View File
@@ -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);
}
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);
} // namespace ee
+162
View File
@@ -0,0 +1,162 @@
/*!
* @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
#include "game/kernel/kscheme.h"
namespace Pad {
/*
********************************
* Key checking
********************************
*/
std::unordered_map<int, int> g_key_status;
std::unordered_map<int, int> g_buffered_key_status;
// input mode for controller mapping
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 g_input_mode_mapping;
void ForceClearKeys() {
g_key_status.clear();
g_buffered_key_status.clear();
}
void ClearKeys() {
g_buffered_key_status.clear();
for (auto& key : g_key_status) {
g_buffered_key_status.insert(std::make_pair(key.first, key.second));
}
}
void OnKeyPress(int key) {
if (input_mode == InputModeStatus::Enabled) {
if (key == GLFW_KEY_ESCAPE) {
ExitInputMode(true);
return;
}
input_mode_key = key;
MapButton(g_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
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) {
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
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);
}
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
+85
View File
@@ -0,0 +1,85 @@
#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 <unordered_map>
#include "common/common_types.h"
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 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<int, int> g_key_status;
// key-down status of any detected key. this is buffered for the remainder of a frame.
extern std::unordered_map<int, int> 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);
// 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();
u64 input_mode_get_key();
u64 input_mode_get_index();
} // namespace Pad
+10 -10
View File
@@ -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-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)) (current-display-frame bucket-group) 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)) (current-display-frame bucket-group) 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))
@@ -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)))
@@ -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-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-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-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)
+7 -13
View File
@@ -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
)
)
@@ -622,8 +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))
(current-display-frame bucket-group)
(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)
@@ -652,8 +651,7 @@
)
)
)
(with-dma-buffer-add-bucket ((s4-0 (current-display-frame debug-buf))
(current-display-frame bucket-group)
(with-dma-buffer-add-bucket ((s4-0 (-> (current-frame) debug-buf))
(bucket-id debug-draw1))
(draw-string (-> arg0 name) s4-0 v1-2)
)
@@ -682,8 +680,7 @@
)
)
)
(with-dma-buffer-add-bucket ((s4-0 (current-display-frame debug-buf))
(current-display-frame bucket-group)
(with-dma-buffer-add-bucket ((s4-0 (-> (current-frame) debug-buf))
(bucket-id debug-draw1))
(draw-string (-> arg0 name) s4-0 v1-2)
)
@@ -709,8 +706,7 @@
)
)
)
(with-dma-buffer-add-bucket ((s1-0 (current-display-frame debug-buf))
(current-display-frame bucket-group)
(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)
@@ -783,8 +779,7 @@
(set! arg2 (- arg2 (* (+ v1-0 -16) 8)))
)
)
(with-dma-buffer-add-bucket ((s0-0 (current-display-frame debug-buf))
(current-display-frame bucket-group)
(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))
)
@@ -801,8 +796,7 @@
)
)
(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)
(with-dma-buffer-add-bucket ((sv-16 (-> (current-frame) debug-buf))
(bucket-id debug-draw1))
(draw-string ">" sv-16 (-> arg0 context font))
)
+5 -4
View File
@@ -423,12 +423,13 @@
)
)
(defmacro with-dma-buffer-add-bucket (bindings &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 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-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
)
)
+2 -2
View File
@@ -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*))
)
)
+14 -23
View File
@@ -19,8 +19,7 @@
(defun letterbox ()
"Draw the letterbox black rectangles"
(with-dma-buffer-add-bucket ((dma-buf (current-display-frame global-buf))
(current-display-frame bucket-group)
(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))
@@ -45,8 +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))
(current-display-frame bucket-group)
(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))
)
@@ -69,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)
@@ -851,10 +854,9 @@
(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)
))
(current-display-frame bucket-group)
(bucket-id debug-draw0))
(show-iop-memory dma-buff)
)
@@ -938,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..."
@@ -1146,7 +1143,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 +1180,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 +1190,7 @@
(the int (-> *font-context* origin x))
a3-8
(font-color default)
3
(font-flags shadow kerning)
)
)
@@ -1277,14 +1274,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-loop :name 'display)))
(set! *dproc* (the process (as-process new-dproc)))
)
(cond
((or (level-get-with-status *level* 'loaded)
+29 -17
View File
@@ -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))
(define-extern draw-string-xy (function string dma-buffer int int font-color font-flags none))
+4 -4
View File
@@ -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
)
)
)
+1 -3
View File
@@ -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-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)
+10 -2
View File
@@ -231,6 +231,14 @@
(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 ()
`(-> *display* base-frame-counter)
)
(defmacro integral-current-time ()
`(-> *display* integral-frame-counter)
)
+4 -4
View File
@@ -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
)
+3 -5
View File
@@ -818,11 +818,9 @@
(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-display-frame global-buf))
(current-display-frame bucket-group)
(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))
@@ -886,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)
)
)
+10 -20
View File
@@ -800,8 +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
(current-display-frame bucket-group)
(with-dma-buffer-add-bucket ((dma-buf (-> (current-frame) global-buf)) ;; the global DMA buffer
bucket-idx)
;; default to segment 0 only (mode 0)
@@ -985,8 +984,7 @@
(need-tex symbol)
)
(let ((total-upload-size 0))
(with-dma-buffer-add-bucket ((dma-buf (current-display-frame global-buf))
(current-display-frame bucket-group)
(with-dma-buffer-add-bucket ((dma-buf (-> (current-frame) global-buf))
bucket-idx)
(set! tex-data (-> page segment 0 block-data)) ;; data in RAM
@@ -1599,8 +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))
(current-display-frame bucket-group)
(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))
@@ -1609,8 +1606,7 @@
)
;; the rest are the same
;; PRIS
(with-dma-buffer-add-bucket ((v1-12 (current-display-frame global-buf))
(current-display-frame bucket-group)
(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))
@@ -1618,8 +1614,7 @@
)
)
;; SHRUB
(with-dma-buffer-add-bucket ((v1-20 (current-display-frame global-buf))
(current-display-frame bucket-group)
(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))
@@ -1627,8 +1622,7 @@
)
)
;; ALPHA
(with-dma-buffer-add-bucket ((v1-28 (current-display-frame global-buf))
(current-display-frame bucket-group)
(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))
@@ -1638,8 +1632,7 @@
)
(else
;; TFRAG
(with-dma-buffer-add-bucket ((v1-36 (current-display-frame global-buf))
(current-display-frame bucket-group)
(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))
@@ -1647,8 +1640,7 @@
)
)
;; PRIS
(with-dma-buffer-add-bucket ((v1-44 (current-display-frame global-buf))
(current-display-frame bucket-group)
(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))
@@ -1656,8 +1648,7 @@
)
)
;; SHRUB
(with-dma-buffer-add-bucket ((v1-52 (current-display-frame global-buf))
(current-display-frame bucket-group)
(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))
@@ -1665,8 +1656,7 @@
)
)
;; ALPHA
(with-dma-buffer-add-bucket ((v1-60 (current-display-frame global-buf))
(current-display-frame bucket-group)
(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))
-1
View File
@@ -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))
+1 -1
View File
@@ -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)
+33 -12
View File
@@ -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)
+4 -4
View File
@@ -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
)
+1 -8
View File
@@ -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-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)
+4 -4
View File
@@ -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)
+3 -3
View File
@@ -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))
)
+4 -1
View File
@@ -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))
)
+3
View File
@@ -1,3 +1,6 @@
;;-*-Lisp-*-
(in-package goal)
;; This file demonstrates how to use the debug draw.
;; To run this:
+6
View File
@@ -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))
+15 -9
View File
@@ -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,21 @@
: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))
(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))
(define-extern pc-pad-input-map-save! (function none))
(define-extern pc-pad-get-mapped-button (function int int int))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; vm functions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+4 -2
View File
@@ -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)
@@ -455,7 +457,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)
+45 -1
View File
@@ -80,6 +80,36 @@ There are several ways to "go"
)
)
(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 ,(if name name `(quote ,proc-type)) ,stack)
(run-next-time-in-process ,new-proc ,func ,@args)
(-> ,new-proc ppointer)
)
)
)
)
(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 ,(if name name `(quote ,proc-type)) ,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)
@@ -388,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)
)
+245
View File
@@ -0,0 +1,245 @@
;;-*-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.
|#
(cond (*debug-segment*
;; a structure to hold the handles used in this file
(deftype pc-pad-proc-list (structure)
((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))
;; a pc pad process
(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-proc-list* show)))
(let ((procp
(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
(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)
)
)
)
))
(set! (-> *pc-pad-proc-list* show) (ppointer->handle procp))
)
(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*)
)
(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-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))))
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-frame) debug-buf))
(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)
: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-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))))
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-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))
)
(suspend)
)
)
)
(defstate pc-pi-mapping-button (pc-pad-proc)
:code (behavior ()
(set-state-time)
(loop
(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))
)
(draw-string-xy "PRESS ESCAPE TO EXIT" buf 256 64 (font-color default) (font-flags shadow kerning large middle))
(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)
)
)
: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-proc-list* input)))
(let ((procp
(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)
)
)
))
(set! (-> *pc-pad-proc-list* input) (ppointer->handle procp))
)
(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*)
(pc-pad-input-mode-set 'canceled)
)
)
(else (format #t "No debug memory in use. pc-pad-utils not loaded.")))
+1 -1
View File
@@ -422,7 +422,7 @@
)
0.0
arg3
(the-as uint 3)
(font-flags shadow kerning)
)
)
)
+1 -1
View File
@@ -59,7 +59,7 @@
0
0.0
(font-color default)
(the-as uint 3)
(font-flags shadow kerning)
)
)
gp-0
+6 -6
View File
@@ -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
@@ -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)
)
+11 -4
View File
@@ -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
+1 -1
View File
@@ -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)))
)
)
+1 -1
View File
@@ -148,7 +148,7 @@
32
(+ (* 12 slot-idx) 8)
(font-color orange-red)
1
(font-flags shadow)
)
)
)
+4 -4
View File
@@ -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
)
+4 -4
View File
@@ -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)
+1 -1
View File
@@ -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))