From 8719abe2171ce8cd1fbce23ba49994f84b7ba46d Mon Sep 17 00:00:00 2001 From: dcvz Date: Wed, 19 Jun 2024 10:51:08 +0200 Subject: [PATCH 1/2] Implement osViGetCurrentLine and osViGetCurrentField --- librecomp/src/vi.cpp | 8 ++++++++ ultramodern/include/ultramodern/ultra64.h | 4 ++++ ultramodern/src/events.cpp | 8 ++++++++ 3 files changed, 20 insertions(+) diff --git a/librecomp/src/vi.cpp b/librecomp/src/vi.cpp index 1f3a4cf..4e62c2a 100644 --- a/librecomp/src/vi.cpp +++ b/librecomp/src/vi.cpp @@ -22,6 +22,14 @@ extern "C" void osViRepeatLine_recomp(uint8_t* rdram, recomp_context* ctx) { osViRepeatLine(_arg<0, u8>(rdram, ctx)); } +extern "C" void osViGetCurrentLine_recomp(uint8_t* rdram, recomp_context* ctx) { + ctx->r2 = (gpr)osViGetCurrentLine(); +} + +extern "C" void osViGetCurrentField_recomp(uint8_t* rdram, recomp_context* ctx) { + ctx->r2 = (gpr)osViGetCurrentField(); +} + extern "C" void osViSetSpecialFeatures_recomp(uint8_t* rdram, recomp_context* ctx) { osViSetSpecialFeatures((uint32_t)ctx->r4); } diff --git a/ultramodern/include/ultramodern/ultra64.h b/ultramodern/include/ultramodern/ultra64.h index bce6090..fd6ab8c 100644 --- a/ultramodern/include/ultramodern/ultra64.h +++ b/ultramodern/include/ultramodern/ultra64.h @@ -44,6 +44,8 @@ typedef uint8_t u8; # ifdef __cplusplus # define NULLPTR (PTR(void))0 # endif +# define PHYS_TO_K1(x) ((x)|0xA0000000) +# define IO_READ(addr) (*(volatile uint32_t*)PHYS_TO_K1(addr)) #endif #ifndef NULL @@ -285,6 +287,8 @@ void osViSetMode(RDRAM_ARG PTR(OSViMode)); void osViSetSpecialFeatures(uint32_t func); void osViBlack(uint8_t active); void osViRepeatLine(uint8_t active); +u32 osViGetCurrentLine(); +u32 osViGetCurrentField(); void osViSetXScale(float scale); void osViSetYScale(float scale); PTR(void) osViGetNextFramebuffer(); diff --git a/ultramodern/src/events.cpp b/ultramodern/src/events.cpp index 0b4db7b..a20cc72 100644 --- a/ultramodern/src/events.cpp +++ b/ultramodern/src/events.cpp @@ -480,6 +480,14 @@ extern "C" void osViRepeatLine(uint8_t active) { } } +extern "C" u32 osViGetCurrentLine() { + return IO_READ(VI_V_CURRENT_LINE_REG); +} + +extern "C" u32 osViGetCurrentField() { + return IO_READ(VI_V_CURRENT_LINE_REG) & 1; +} + extern "C" void osViSetXScale(float scale) { if (scale != 1.0f) { assert(false); From 8b5800233a9ecbfec8db7d7d2454a085557d33b2 Mon Sep 17 00:00:00 2001 From: dcvz Date: Wed, 19 Jun 2024 10:57:17 +0200 Subject: [PATCH 2/2] Implement osViGetStatus --- librecomp/src/vi.cpp | 4 ++++ ultramodern/include/ultramodern/ultra64.h | 1 + ultramodern/src/events.cpp | 4 ++++ 3 files changed, 9 insertions(+) diff --git a/librecomp/src/vi.cpp b/librecomp/src/vi.cpp index 4e62c2a..8c20aa6 100644 --- a/librecomp/src/vi.cpp +++ b/librecomp/src/vi.cpp @@ -30,6 +30,10 @@ extern "C" void osViGetCurrentField_recomp(uint8_t* rdram, recomp_context* ctx) ctx->r2 = (gpr)osViGetCurrentField(); } +extern "C" void osViGetStatus_recomp(uint8_t* rdram, recomp_context* ctx) { + ctx->r2 = (gpr)osViGetStatus(); +} + extern "C" void osViSetSpecialFeatures_recomp(uint8_t* rdram, recomp_context* ctx) { osViSetSpecialFeatures((uint32_t)ctx->r4); } diff --git a/ultramodern/include/ultramodern/ultra64.h b/ultramodern/include/ultramodern/ultra64.h index fd6ab8c..aa7ae8c 100644 --- a/ultramodern/include/ultramodern/ultra64.h +++ b/ultramodern/include/ultramodern/ultra64.h @@ -289,6 +289,7 @@ void osViBlack(uint8_t active); void osViRepeatLine(uint8_t active); u32 osViGetCurrentLine(); u32 osViGetCurrentField(); +u32 osViGetStatus(); void osViSetXScale(float scale); void osViSetYScale(float scale); PTR(void) osViGetNextFramebuffer(); diff --git a/ultramodern/src/events.cpp b/ultramodern/src/events.cpp index a20cc72..baadd33 100644 --- a/ultramodern/src/events.cpp +++ b/ultramodern/src/events.cpp @@ -488,6 +488,10 @@ extern "C" u32 osViGetCurrentField() { return IO_READ(VI_V_CURRENT_LINE_REG) & 1; } +extern "C" u32 osViGetStatus() { + return IO_READ(VI_STATUS_REG); +} + extern "C" void osViSetXScale(float scale) { if (scale != 1.0f) { assert(false);