From 2c668179810e8bb76b201e50a4446937ebdfb8de Mon Sep 17 00:00:00 2001 From: Logan McNaughton <848146+loganmc10@users.noreply.github.com> Date: Thu, 7 Jul 2022 21:21:41 -0600 Subject: [PATCH] update core --- mupen64plus-core/src/device/device.c | 2 +- mupen64plus-core/src/device/pif/pif.c | 2 ++ mupen64plus-core/src/device/pif/pif.h | 2 ++ .../src/device/rcp/si/si_controller.c | 21 +++++++++++++++++++ .../src/device/rcp/si/si_controller.h | 2 ++ .../src/device/rcp/vi/vi_controller.c | 4 +++- .../src/device/rcp/vi/vi_controller.h | 3 ++- 7 files changed, 33 insertions(+), 3 deletions(-) diff --git a/mupen64plus-core/src/device/device.c b/mupen64plus-core/src/device/device.c index cad4381..b09b1ab 100644 --- a/mupen64plus-core/src/device/device.c +++ b/mupen64plus-core/src/device/device.c @@ -190,7 +190,7 @@ void init_device(struct device* dev, &dev->mi, &dev->ri, &dev->dp); init_ri(&dev->ri, &dev->rdram); init_si(&dev->si, si_dma_duration, &dev->mi, &dev->pif, &dev->ri); - init_vi(&dev->vi, vi_clock, expected_refresh_rate, &dev->mi, &dev->dp); + init_vi(&dev->vi, vi_clock, expected_refresh_rate, &dev->mi, &dev->dp, &dev->si); /* FIXME: should boot on cart, unless only a disk is present, but having no cart is not yet supported by ui/core, * so use another way of selecting boot device: diff --git a/mupen64plus-core/src/device/pif/pif.c b/mupen64plus-core/src/device/pif/pif.c index f226203..8dd0e86 100644 --- a/mupen64plus-core/src/device/pif/pif.c +++ b/mupen64plus-core/src/device/pif/pif.c @@ -144,6 +144,7 @@ void init_pif(struct pif* pif, pif->r4300 = r4300; pif->si = si; + pif->update_counter = 0; } void reset_pif(struct pif* pif, unsigned int reset_type) @@ -380,6 +381,7 @@ void update_pif_ram(struct pif* pif) if (input.readController) { input.readController(-1, NULL); } + ++pif->update_counter; netplay_update_input(pif); diff --git a/mupen64plus-core/src/device/pif/pif.h b/mupen64plus-core/src/device/pif/pif.h index 4bdb090..d2429a6 100644 --- a/mupen64plus-core/src/device/pif/pif.h +++ b/mupen64plus-core/src/device/pif/pif.h @@ -59,6 +59,8 @@ struct pif struct cic cic; + uint32_t update_counter; + struct r4300_core* r4300; struct si_controller* si; }; diff --git a/mupen64plus-core/src/device/rcp/si/si_controller.c b/mupen64plus-core/src/device/rcp/si/si_controller.c index c35de37..62edbca 100644 --- a/mupen64plus-core/src/device/rcp/si/si_controller.c +++ b/mupen64plus-core/src/device/rcp/si/si_controller.c @@ -175,3 +175,24 @@ void si_end_of_dma_event(void* opaque) raise_rcp_interrupt(si->mi, MI_INTR_SI); } +void si_dynamic_dma_duration(struct si_controller* si) +{ + uint32_t input_updated = 0; + for (int i = 0; i < 4; ++i) + { + if (si->pif->channels[i].tx) + { + input_updated = 1; + } + } + if (input_updated) + { + /* try to keep controller polling to 1-2 per VI */ + if (si->pif->update_counter > 2) + si->dma_duration += 1000; + else if (si->pif->update_counter < 1 && si->dma_duration > 1000) + si->dma_duration -= 1000; + } + + si->pif->update_counter = 0; +} diff --git a/mupen64plus-core/src/device/rcp/si/si_controller.h b/mupen64plus-core/src/device/rcp/si/si_controller.h index 01a371f..e5e0756 100644 --- a/mupen64plus-core/src/device/rcp/si/si_controller.h +++ b/mupen64plus-core/src/device/rcp/si/si_controller.h @@ -89,4 +89,6 @@ void write_si_regs(void* opaque, uint32_t address, uint32_t value, uint32_t mask void si_end_of_dma_event(void* opaque); +void si_dynamic_dma_duration(struct si_controller* si); + #endif diff --git a/mupen64plus-core/src/device/rcp/vi/vi_controller.c b/mupen64plus-core/src/device/rcp/vi/vi_controller.c index 4cd3abb..0a2be0d 100644 --- a/mupen64plus-core/src/device/rcp/vi/vi_controller.c +++ b/mupen64plus-core/src/device/rcp/vi/vi_controller.c @@ -67,12 +67,13 @@ void set_vi_vertical_interrupt(struct vi_controller* vi) } void init_vi(struct vi_controller* vi, unsigned int clock, unsigned int expected_refresh_rate, - struct mi_controller* mi, struct rdp_core* dp) + struct mi_controller* mi, struct rdp_core* dp, struct si_controller* si) { vi->clock = clock; vi->expected_refresh_rate = expected_refresh_rate; vi->mi = mi; vi->dp = dp; + vi->si = si; } void poweron_vi(struct vi_controller* vi) @@ -164,6 +165,7 @@ void vi_vertical_interrupt_event(void* opaque) /* allow main module to do things on VI event */ new_vi(); + si_dynamic_dma_duration(vi->si); /* toggle vi field if in interlaced mode */ vi->field ^= (vi->regs[VI_STATUS_REG] >> 6) & 0x1; diff --git a/mupen64plus-core/src/device/rcp/vi/vi_controller.h b/mupen64plus-core/src/device/rcp/vi/vi_controller.h index efa575d..d41607f 100644 --- a/mupen64plus-core/src/device/rcp/vi/vi_controller.h +++ b/mupen64plus-core/src/device/rcp/vi/vi_controller.h @@ -60,6 +60,7 @@ struct vi_controller struct mi_controller* mi; struct rdp_core* dp; + struct si_controller* si; }; static osal_inline uint32_t vi_reg(uint32_t address) @@ -73,7 +74,7 @@ unsigned int vi_expected_refresh_rate_from_tv_standard(m64p_system_type tv_stand void set_vi_vertical_interrupt(struct vi_controller* vi); void init_vi(struct vi_controller* vi, unsigned int clock, unsigned int expected_refresh_rate, - struct mi_controller* mi, struct rdp_core* dp); + struct mi_controller* mi, struct rdp_core* dp, struct si_controller* si); void poweron_vi(struct vi_controller* vi);