From b78f105e8d59b41da9dddc03065fbb397405a5d2 Mon Sep 17 00:00:00 2001 From: thecozies <79979276+thecozies@users.noreply.github.com> Date: Wed, 13 Aug 2025 18:03:55 -0500 Subject: [PATCH] Added gEXSetNearClipping command (#212) * Added gEXSetNearClipping command * flush rsp state --- include/rt64_extended_gbi.h | 9 ++++++++- src/gbi/rt64_gbi_extended.cpp | 6 ++++++ src/hle/rt64_rsp.cpp | 7 +++++++ src/hle/rt64_rsp.h | 1 + 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/include/rt64_extended_gbi.h b/include/rt64_extended_gbi.h index ea4d459..cd03786 100644 --- a/include/rt64_extended_gbi.h +++ b/include/rt64_extended_gbi.h @@ -73,7 +73,8 @@ #define G_EX_POPGEOMETRYMODE_V1 0x00002A #define G_EX_SETDITHERNOISESTRENGTH_V1 0x00002B #define G_EX_SETRDRAMEXTENDED_V1 0x00002C -#define G_EX_MAX 0x00002D +#define G_EX_SETNEARCLIPPING_V1 0x00002D +#define G_EX_MAX 0x00002E #define G_EX_ORIGIN_NONE 0x800 #define G_EX_ORIGIN_LEFT 0x0 @@ -515,4 +516,10 @@ typedef union { PARAM(isExtended, 1, 0) \ ) +#define gEXSetNearClipping(cmd, isEnabled) \ + G_EX_COMMAND1(cmd, \ + PARAM(RT64_EXTENDED_OPCODE, 8, 24) | PARAM(G_EX_SETNEARCLIPPING_V1, 24, 0), \ + PARAM(isEnabled, 1, 0) \ + ) + #endif // RT64_EXTENDED_GBI diff --git a/src/gbi/rt64_gbi_extended.cpp b/src/gbi/rt64_gbi_extended.cpp index 47940a1..2c5dac1 100644 --- a/src/gbi/rt64_gbi_extended.cpp +++ b/src/gbi/rt64_gbi_extended.cpp @@ -291,6 +291,11 @@ namespace RT64 { state->setExtendedRDRAM(extended); } + void setNearClippingV1(State *state, DisplayList **dl) { + const uint8_t nearClipping = (*dl)->p1(0, 1); + state->rsp->setNoN(!nearClipping); + } + void noOpHook(State *state, DisplayList **dl) { uint32_t magicNumber = (*dl)->p0(0, 24); if (magicNumber == RT64_HOOK_MAGIC_NUMBER) { @@ -392,6 +397,7 @@ namespace RT64 { Map[G_EX_POPGEOMETRYMODE_V1] = &popGeometryModeV1; Map[G_EX_SETDITHERNOISESTRENGTH_V1] = &setDitherNoiseStrengthV1; Map[G_EX_SETRDRAMEXTENDED_V1] = &setRDRAMExtendedV1; + Map[G_EX_SETNEARCLIPPING_V1] = &setNearClippingV1; MapInitialized = true; } } diff --git a/src/hle/rt64_rsp.cpp b/src/hle/rt64_rsp.cpp index cbeab86..ea0c1ac 100644 --- a/src/hle/rt64_rsp.cpp +++ b/src/hle/rt64_rsp.cpp @@ -1185,4 +1185,11 @@ namespace RT64 { pushMask = gbi->constants[F3DENUM::G_MTX_PUSH]; shadingSmoothMask = gbi->constants[F3DENUM::G_SHADING_SMOOTH]; } + + void RSP::setNoN(bool NoN) { + if (this->NoN != NoN) { + state->flush(); + this->NoN = NoN; + } + } }; \ No newline at end of file diff --git a/src/hle/rt64_rsp.h b/src/hle/rt64_rsp.h index ba8f7d8..1611b7a 100644 --- a/src/hle/rt64_rsp.h +++ b/src/hle/rt64_rsp.h @@ -282,5 +282,6 @@ namespace RT64 { void extendRDRAM(bool isExtended); void clearExtended(); void setGBI(GBI *gbi); + void setNoN(bool NoN); }; }; \ No newline at end of file