From f024c4db843417c8e05f2bda6bc9b8783613fef3 Mon Sep 17 00:00:00 2001 From: Mr-Wiseguy Date: Thu, 2 Mar 2023 23:38:52 -0500 Subject: [PATCH] Implemented VI register tracking --- portultra/events.cpp | 43 ++++++++++++++++++++++++++++++++++++++++--- portultra/ultra64.h | 28 ++++++++++++++++++++++++++++ src/vi.cpp | 2 +- 3 files changed, 69 insertions(+), 4 deletions(-) diff --git a/portultra/events.cpp b/portultra/events.cpp index be30b8c..66d3014 100644 --- a/portultra/events.cpp +++ b/portultra/events.cpp @@ -193,8 +193,8 @@ int sdl_event_filter(void* userdata, SDL_Event* event) { button = new_button; - stick_x = 127 * (key_states[SDL_Scancode::SDL_SCANCODE_D] - key_states[SDL_Scancode::SDL_SCANCODE_A]); - stick_y = 127 * (key_states[SDL_Scancode::SDL_SCANCODE_W] - key_states[SDL_Scancode::SDL_SCANCODE_S]); + stick_x = 85 * (key_states[SDL_Scancode::SDL_SCANCODE_D] - key_states[SDL_Scancode::SDL_SCANCODE_A]); + stick_y = 85 * (key_states[SDL_Scancode::SDL_SCANCODE_W] - key_states[SDL_Scancode::SDL_SCANCODE_S]); } break; case SDL_EventType::SDL_QUIT: @@ -304,9 +304,46 @@ void event_thread_func(uint8_t* rdram, uint8_t* rom, std::atomic_flag* events_th } } +extern unsigned int VI_STATUS_REG; +extern unsigned int VI_ORIGIN_REG; +extern unsigned int VI_WIDTH_REG; +extern unsigned int VI_INTR_REG; +extern unsigned int VI_V_CURRENT_LINE_REG; +extern unsigned int VI_TIMING_REG; +extern unsigned int VI_V_SYNC_REG; +extern unsigned int VI_H_SYNC_REG; +extern unsigned int VI_LEAP_REG; +extern unsigned int VI_H_START_REG; +extern unsigned int VI_V_START_REG; +extern unsigned int VI_V_BURST_REG; +extern unsigned int VI_X_SCALE_REG; +extern unsigned int VI_Y_SCALE_REG; + +uint32_t vi_origin_offset = 320 * sizeof(uint16_t); + extern "C" void osViSwapBuffer(RDRAM_ARG PTR(void) frameBufPtr) { events_context.vi.next_buffer = frameBufPtr; - events_context.action_queue.enqueue(SwapBuffersAction{ osVirtualToPhysical(frameBufPtr) + 640 }); + events_context.action_queue.enqueue(SwapBuffersAction{ osVirtualToPhysical(frameBufPtr) + vi_origin_offset }); +} + +extern "C" void osViSetMode(RDRAM_ARG PTR(OSViMode) mode_) { + OSViMode* mode = TO_PTR(OSViMode, mode_); + VI_STATUS_REG = mode->comRegs.ctrl; + VI_WIDTH_REG = mode->comRegs.width; + // burst + VI_V_SYNC_REG = mode->comRegs.vSync; + VI_H_SYNC_REG = mode->comRegs.hSync; + VI_LEAP_REG = mode->comRegs.leap; + VI_H_START_REG = mode->comRegs.hStart; + VI_X_SCALE_REG = mode->comRegs.xScale; + VI_V_CURRENT_LINE_REG = mode->comRegs.vCurrent; + + // TODO swap these every VI to account for fields changing + vi_origin_offset = mode->fldRegs[0].origin; + VI_Y_SCALE_REG = mode->fldRegs[0].yScale; + VI_V_START_REG = mode->fldRegs[0].vStart; + VI_V_BURST_REG = mode->fldRegs[0].vBurst; + VI_INTR_REG = mode->fldRegs[0].vIntr; } extern "C" PTR(void) osViGetNextFramebuffer() { diff --git a/portultra/ultra64.h b/portultra/ultra64.h index ef03116..e01f1f5 100644 --- a/portultra/ultra64.h +++ b/portultra/ultra64.h @@ -176,6 +176,33 @@ struct OSPiHandle { u32 transferInfo[18]; /* for disk only */ }; +typedef struct { + u32 ctrl; + u32 width; + u32 burst; + u32 vSync; + u32 hSync; + u32 leap; + u32 hStart; + u32 xScale; + u32 vCurrent; +} OSViCommonRegs; + +typedef struct { + u32 origin; + u32 yScale; + u32 vStart; + u32 vBurst; + u32 vIntr; +} OSViFieldRegs; + +typedef struct { + u8 padding[3]; + u8 type; + OSViCommonRegs comRegs; + OSViFieldRegs fldRegs[2]; +} OSViMode; + /////////////// // Functions // /////////////// @@ -207,6 +234,7 @@ s32 osRecvMesg(RDRAM_ARG PTR(OSMesgQueue), PTR(OSMesg), s32); void osSetEventMesg(RDRAM_ARG OSEvent, PTR(OSMesgQueue), OSMesg); void osViSetEvent(RDRAM_ARG PTR(OSMesgQueue), OSMesg, u32); void osViSwapBuffer(RDRAM_ARG PTR(void) frameBufPtr); +void osViSetMode(RDRAM_ARG PTR(OSViMode)); PTR(void) osViGetNextFramebuffer(); PTR(void) osViGetCurrentFramebuffer(); u32 osGetCount(); diff --git a/src/vi.cpp b/src/vi.cpp index 0b1f714..9b0edc0 100644 --- a/src/vi.cpp +++ b/src/vi.cpp @@ -34,5 +34,5 @@ extern "C" void osViSwapBuffer_recomp(uint8_t* rdram, recomp_context* ctx) { } extern "C" void osViSetMode_recomp(uint8_t* rdram, recomp_context* ctx) { - ; + osViSetMode(rdram, (int32_t)ctx->r4); }