Skip to content

Releases

PSX3DS v0.2.8 — Smooth Real-3DS Audio Fix (Zero Silence Splices, Core 2 SPU Worker, NDSP Rate Matching & Phase-Locked CD Clock)

Choose a tag to compare

@codescv codescv released this 11 Nov 11:12

PSX3DS v0.2.8 — Smooth Real-3DS Audio Fix (Zero Silence-Padding Splices, Core 2 Dedicated 804 MHz SPU Worker, NDSP Hardware Rate Matching, Phase-Locked CD-ROM Sector Clock & Division-Free Reverb/XA)

v0.2.8 resolves the real New 3DS audio stuttering/choppiness reported on v0.2.7 ("画面流畅, 声音卡顿" — video runs smoothly at 60 FPS and sound plays on real hardware, but audio chopped/stuttered), eliminating all premature silence-padding wavebuf splices, Core 1 SysCore quota freezes, CD-ROM INT1 acknowledge XA drift, dropped SPU_CMD_REG_ADVANCE audio batches, and ~727,000 software divisions/sec on ARM11v6K.


English Release Notes

1. Smooth Real-3DS NDSP Audio Pipeline (src/platform/3ds/audio_ndsp.c, src/platform/3ds/threads_3ds.c, src/platform/3ds/ui_bottom.c)

  • Eliminated Premature active_wbufs <= 1 Silence-Padding Splices & Synchronous SPU Drain:
    • Root Cause: In v0.2.7, CTR_NDSP_PRIME_FRAMES was 2 x 735 (33.3 ms). Whenever wb[0] retired during Core 0's pacer_wait() frame sleep (active_wbufs dropping from 2 to 1 while avail < 735), audio_pump_locked() hit the active_wbufs <= 1 branch and padded the remaining ~700 frames (~16 ms) of a 735-frame wavebuf with an exponential fade-to-zero ramp (WB inflated to 3,610 in 3,200 frames of KOF '97 = ~8 silence holes/sec). In addition, a trylock miss against the SPU worker left part of the emulated frame's SpuCmd queue unrendered in cmd_ring.
    • Fix: Removed the active_wbufs <= 1 silence-padding branch so Core 0 submits full 735-frame wavebufs only while NDSP is playing; expanded the NDSP ring to 8 x 735 frames (133.3 ms) with a 3 x 735 (50.0 ms) prime (CTR_SPU_HIGH_WATER = 6 x 735 = 100.0 ms, 250 ms stall watchdog); and added spu_drain_all_cmds_sync(sys) whenever queued < CTR_NDSP_PRIME_FRAMES so 100% of Core-0-emulated audio is rendered into out_ring before checking availability.
  • New 3DS Dedicated Core 2 (804 MHz, Unthrottled AppCore) SPU Worker Placement:
    • Root Cause: On real New 3DS hardware, Core 1 (SysCore) is throttled by the Horizon OS Kernel11 APT_SetAppCpuTimeLimit(30) quota (4.8 ms CPU budget per 16.67 ms window, freezing Core 1 app threads for ~11.2 ms) and shared with dsp::DSP, gsp::Gpu, and fs::USER. Meanwhile, Core 2 is a dedicated 804 MHz AppCore with 100% unthrottled CPU time and zero OS services.
    • Fix: On New 3DS (hw->is_n3ds), g_spu_worker now runs on Core 2 at priority 0x2F (main_prio - 1), while g_cd_worker (bursty CHD readahead) moves to Core 1 at 0x2F/0x30 (never 0x31, avoiding starvation below the 0x30 SysCore quota thread), with clean fallback chains for Old 3DS / restricted .3dsx launchers. 2:HUD now displays SPU:C2 / SPU:C1 / SPU:SYN alongside CD [CHD]: Core <N>.
  • TeakLite II NDSP Hardware Resampler Rate Matching with Hysteresis:
    • Because the 60.00 Hz NTSC pacer runs native PS1 (59.8261 Hz, 737.13 SPU frames/vblank) at 44,228 Hz (50.00 Hz PAL at 44,312 Hz), ndspChnSetRate now runs at 44,228 Hz NTSC (44,312 Hz PAL) and steers smoothly with hysteresis (44,100 / 44,228 / 44,360 Hz NTSC; 44,180 / 44,312 / 44,440 Hz PAL) around ~3 queued wavebufs without step-resampling pitch jumps or queue drift.

2. Phase-Locked CD-ROM Sector Clock & XA Gap Decay (src/periph/cdrom.c, src/periph/spu.c)

  • Zero Guest INT1 Acknowledge Drift on XA / FMV Streams:
    • Root Cause: At 2x speed, 8 CD sectors (7 video + 1 XA 37.8 kHz stereo sector) take 8 x 225,792 = 1,806,336 cycles (2,352.000 SPU samples) and produce 2,352 XA samples. v0.2.7 scheduled the next sector after the guest acknowledged CD_INT1_DATARDY (+t_irq_ack ≈ 15,000 cycles/sector), stretching every 8 sectors to ~2,490 SPU samples and starving xa_ring every ~53 ms.
    • Fix: Added wrap-safe u32 next_sector_cycle + sector_clock_armed phase-locked sector scheduling (cd_schedule_next_sector), scheduling EV_CDROM immediately on INT1 delivery as well as on guest acknowledge so 8 sectors take 8 x 225,792 = 1,806,336 cycles regardless of guest IRQ latency. Brief xa_ring transitions now smoothly decay last_cd_l/r (* 252 / 256 toward 0) instead of stepping full-scale to 0. Covered by test_cdrom_sector_clock_no_ack_drift and test_spu_xa_gap_decay.

3. Zero Dropped SPU_CMD_REG_ADVANCE Audio & ARM11v6K Division Elimination (src/periph/spu.c, src/periph/spu_reverb.c, src/periph/spu_xa.c)

  • Render Queued ADVANCE Batches on Drain & Before SPU DMA:
    • spu_drain_all_cmds now renders all queued SPU_CMD_REG_ADVANCE time into out_ring (with deferred IRQ9 delivery) instead of discarding up to a full frame (736 samples) when SPUCNT toggles IRQ9 (0x8040) or on savestate, and drains cmd_ring before spu_dma_write_words overwrites SPU sample RAM. Covered by test_spu_drain_renders_queued_advance.
  • Eliminated ~727,000 Software Divisions/sec on ARM11v6K:
    • Replaced s64 % in spu_reverb.c (rev_calc_addr + rev_next_pos, called 29 times per 22.05 kHz tick = 639,450 calls/sec to __aeabi_ldivmod) with single add/subtract wrap-around plus a muted-reverb fast path (vLOUT == 0 && vROUT == 0 && (SPUCNT & 0x00C0) == 0), and replaced per-sample / 44100 in spu_xa.c with exact UMULL reciprocal multiplication ((p * 1595663134ULL) >> 32 for all 0 <= p < 44100).

中文更新说明 (v0.2.8)

  1. 彻底消除 New 3DS 实机声音卡顿/断续(修复 v0.2.7 “画面流畅,声音卡顿”):
    • 移除过早静音拼接并同步排空 SPU 命令队列:修复 v0.2.7 在 pacer_wait 帧间休眠时当活跃缓冲降至 1 块(active_wbufs <= 1)即向 735 帧 wavebuf 强行填充约 700 帧渐隐静音(导致《拳皇 '97》每秒混入约 8 次 16 ms 静音断口、WB 虚高膨胀)的问题;现扩展为 8 x 735 帧(133.3 ms)环形缓冲与 3 块(50.0 ms)预充水位,播放期间仅提交完整 735 帧音频块,并在低水位时通过 spu_drain_all_cmds_sync 同步渲染当帧全部 SPU 采样(WB 与帧数严格保持 ~1.0x)。
    • New 3DS 独占 Core 2 (804 MHz 无配额限制核心) 运行 SPU 音频线程:实机上 Core 1 (SysCore) 受 Horizon OS APT_SetAppCpuTimeLimit(30) 限制(每 16.67 ms 窗口仅 4.8 ms 配额、其余约 11.2 ms 被内核冻结)且与 dsp/gsp/fs 系统服务共享;现将 New 3DS 的 SPU 渲染线程移至拥有 100% 算力、零系统服务抢占 的独立应用核 Core 2(优先级 0x2F),并将突发式 CHD 预读线程移至 Core 1(优先级 0x2F/0x30,避免落入 0x31 被配额线程饿死)。下屏 2:HUD 现精确显示 SPU:C2 与 CD [CHD]: Core 1。
    • 3DS NDSP 硬件重采样器自适应锁相调速(带迟滞防抖):针对 60.00 Hz NTSC 限速器下 PS1 实际采样率(44,228 Hz,PAL 为 44,312 Hz),利用 3DS TeakLite II DSP 硬件线性重采样器围绕 3 块缓冲水位平滑微调(±0.3% 带迟滞区间),无需跳变重采样即可长期稳态不空载、不溢出。
  2. CD-ROM 锁相扇区时钟与 XA 音频无缝衔接(消除 FMV / XA 周期性断音):
    • 修复 v0.2.7 在游戏确认 CD_INT1_DATARDY 后才调度下一扇区导致的累计确认延迟漂移(每 8 扇区多消耗约 138 个采样,每 ~53 ms 抽空一次 xa_ring);现改为 INT1 触发即按精确扇区周期锁相调度(8 个 2x 扇区严格耗时 1,806,336 周期 = 2,352 采样),并对扇区间极短间隙做平滑衰减避免爆音。
  3. 零丢帧 SPU 队列排空与 ARM11v6K 零软除法优化:
    • spu_drain_all_cmds(含切换 SPUCNT IRQ9 与 SPU DMA 写入前)现完整渲染队列中的 ADVANCE 时间片,不再丢弃未渲染音频;
    • 消除 spu_reverb.c 与 spu_xa.c 在无硬件除法指令的 ARM11v6K 上每秒约 72.7 万次 __aeabi_ldivmod / __aeabi_idiv 软件除法开销,大幅降低 SPU 混响与 XA 解码 CPU 占用。

PSX3DS v0.2.7 — Real-3DS NDSP Hardware Audio Fix & Winning Eleven 4 Anti-Modchip Fix

Choose a tag to compare

@codescv codescv released this 11 Nov 09:58

PSX3DS v0.2.7 — Real-3DS NDSP Hardware Audio Fix (ndspChnWaveBufClear Stop-Race Re-Arm, Core 0 Exclusive WaveBuf Owner & svcFlushProcessDataCache, Async SPU Readback Coherency) & Winning Eleven 4 Anti-Modchip Fix

v0.2.7 resolves the remaining real New 3DS hardware missing-audio issue reported on v0.2.6 ("1. 还是没声音", while "帧数没问题" confirmed the 60.0 FPS pacer works cleanly on real hardware) and fixes the anti-modchip lockout in World Soccer Jikkyou Winning Eleven 4 (Japan) (SLPM_862.91), verified across The King of Fighters '97, Winning Eleven 3 Final Ver., Winning Eleven 4, and Winning Eleven 2002.


English Release Notes

1. Real-3DS Hardware Audio Fix (src/platform/3ds/audio_ndsp.c, src/platform/3ds/threads_3ds.c, src/platform/3ds/main_3ds.c, src/periph/spu.c)

  • libctru ndspiReadChnState / ndspiUpdateChn Stop-Race Fix (ndspChnWaveBufClear Re-Arm & Zero Menu Dummy Buffers):
    • Root Cause: ELF disassembly of libctru's ndspiReadChnState (0x001ccf88..0x001cd07c) revealed that when the final wavebuf in NDSP finishes (wavebuf_seq == 0, flags == 0x0100), libctru sets chn->wavebuf_queued_count = 0 while leaving chn->playing = 1. Queuing dummy silence buffers in the ROM menu (or draining during BIOS boot) and later calling ndspChnWaveBufAdd without ndspChnWaveBufClear caused ndspiUpdateChn (dirty_playing == 0) to mark wavebufs NDSP_WBUF_PLAYING without restarting the stopped DSP hardware channel or incrementing chn->sync_count, deadlocking g_wbufs in PLAYING on a stopped DSP channel forever.
    • Fix: ctr_audio_init no longer queues silence buffers in the ROM menu; ctr_audio_bind_system resets the channel cleanly on every game boot; and whenever NDSP drains (active_wbufs == 0) or triggers the 150 ms / 35 ms-stopped stall watchdog, ndspChnWaveBufClear(CTR_NDSP_CH) is called before pre-priming 2 x 735 frames (33.3 ms) to bump chn->sync_count and cleanly restart the DSP channel. When down to the final active wavebuf (active_wbufs <= 1), partial frames smoothly decay toward 0 instead of letting the DSP channel stop mid-stream.
  • Core 1 Render / Core 0 NDSP Ownership Split & Kernel11 svcFlushProcessDataCache:
    • Root Cause: DSP_FlushDataCache invokes svcSendSyncRequest(dspHandle) without a lock, racing ndspThreadMain (priority 0x18 on Core 0) on every 5 ms DSP interrupt, and calling it on Core 1 could not clean Core 0's private 16 KiB ARM11 L1 D-cache.
    • Fix: Core 1 (spu_core1_worker) now exclusively calls ctr_audio_render_core1(sys) (rendering queued SpuCmd batches into sys->spu.out_ring without touching g_linear_pcm or ndsp*). Core 0 exclusively owns wavebuf refill and submission (ctr_audio_step_core1 / ctr_audio_pump_core0, pumped every frame and every <= 4 ms slice inside pacer_wait), flushing wavebuf PCM directly from Core 0's L1/L2 cache to FCRAM via Kernel11 svcFlushProcessDataCache(CUR_PROCESS_HANDLE, ...) + GSPGPU_FlushDataCache.
  • Core 0 / Core 1 Async SPU Register Readback Coherency (src/periph/spu.c):
    • Made all spu->endx updates/reads atomic across Core 0 and Core 1, updated Core-0-readable voice shadow state (start_addr, repeat_addr, adsr_vol, and KON clearing endx + zeroing adsr_vol) immediately on MMIO write before cmd_ring drain, and prevented Core 1 cmd_ring replay (spu_apply_queued_reg16) from overwriting newer Core 0 spu->regs[] mirrors. Covered by test_spu_async_readback_coherency.
  • Live Audio Diagnostics on 2:HUD & 4:LOG (src/platform/3ds/ui_bottom.c):
    • 2:HUD now displays live wavebuf submission/in-flight counts and PCM peak amplitude (SPU:C1 NDSP:OK WB:<sub/act> Pk:<peak>), and 4:LOG highlights [audio_ndsp] activation lines in green (COL_OK).

2. Winning Eleven 4 (SLPM_862.91) Anti-Modchip Lockout Fix (src/periph/cdrom.c)

  • Root Cause: At boot (LBA ~52875..53125), Winning Eleven 4 starts muted CD-DA playback, resets SCEx counters (0x19 0x04), and queries GetSCExCounters (0x19 0x05). Returning { stat, 0x01, 0x01 } outside the Lead-In (LBA < 150) mimicked an old non-stealth modchip continuously injecting SCEx strings and triggered "強制終了しました。本体が改造されているおそれがあります。".
  • Fix: CDL_TEST 0x05 now returns { stat, 0x01, 0x01 } only when idle in the Lead-In (cur_lba < 150 and not playing/reading), and { stat, 0x00, 0x00 } whenever playing, reading, or cur_lba >= 150. Covered by test_cdrom_scex_counters.

中文更新说明 (v0.2.7)

  1. 彻底修复 New 3DS 实机无声音问题(libctru NDSP 停止态死锁与跨核缓存一致性):
    • 修复 libctru NDSP 通道耗尽后无法重启的固件交互 Bug:反汇编 psx3ds.elf 中 libctru 的 ndspiReadChnState / ndspiUpdateChn 发现,当最后一个音频缓冲区播放完毕时,libctru 将队列计数清零但保留 chn->playing = 1;此前在 ROM 菜单预先入队的静音缓冲在 67 ms 内耗尽后,后续 ndspChnWaveBufAdd 未先调用 ndspChnWaveBufClear 重置同步计数与播放标志,导致新缓冲永久卡在已停止的 DSP 硬件通道上静音死锁。现移除菜单空转静音缓冲,每次启动游戏及缓冲重充前均通过 ndspChnWaveBufClear 重新武装通道,并加入 150 ms / 35 ms 停滞看门狗与尾帧平滑衰减保护。
    • Core 1 渲染 / Core 0 提交职责分离与 svcFlushProcessDataCache 直刷:Core 1 线程仅负责异步渲染 SPU 采样至 out_ring;所有 NDSP 缓冲区填充、Kernel11 svcFlushProcessDataCache(零 dspHandle IPC 竞争、直刷 Core 0 私有 16 KiB L1 D-Cache 至 FCRAM)及 ndspChnWaveBufAdd 均由 Core 0 独占执行(含 pacer_wait 帧限速休眠期间每 <= 4 ms 切片自动泵送)。
    • 异步 SPU 寄存器回读一致性与 HUD 实时音频监控:原子化 ENDX 状态并在 Core 0 写入 KON / repeat_addr / adsr_vol 时即时同步可读镜像;下屏 2:HUD 新增 SPU:C1 NDSP:OK WB:<已提交/活跃> Pk:<峰值> 实时音频指标,4:LOG 高亮显示 [audio_ndsp] audio active 日志。
  2. 修复《实况足球 4》(Winning Eleven 4, SLPM_862.91) 反改机检测锁死:
    • 修正 CD-ROM Test 0x19 0x05 (GetSCExCounters):仅在光头静止于导入区(LBA < 150)时返回 0x01, 0x01;在数据/音轨区(LBA >= 150)或播放 CD-DA / 读取数据时返回真机一致的 0x00, 0x00,顺利通过反改机校验进入 JOC 授权画面、片头动画与标题界面。
  3. 多游戏实测通过:《拳皇 '97》(SLPM_860.84)、《实况足球 3 最终版》(SLPM_861.62)、《实况足球 4》(SLPM_862.91)、《实况足球 2002》(SLPM_870.56) 均验证正常启动、音频输出饱满且帧率稳定锁定 60.0 FPS。

PSX3DS v0.2.6 — Real-3DS Audio Fix & Steady 60.0 FPS Lock

Choose a tag to compare

@codescv codescv released this 11 Nov 06:59

PSX3DS v0.2.6 — Real-Hardware Audio Fix (SysCore Priority 0x2F, Core 0 NDSP Backstop, 4x735 Full-Buffer FIFO Feeder) & Steady 60.0 FPS Frame Pacer

v0.2.6 resolves the two issues reported on real New 3DS hardware running World Soccer Jikkyou Winning Eleven 3 - Final Ver. (Japan) (SLPM_861.62 + SCPH5500.BIN) on v0.2.5: missing audio output ("另外没有声音") and 30–80 FPS framerate fluctuation ("帧数不稳定, 在30-80之间跳动. 希望能锁定最高60帧稳定运行").


English Release Notes

1. Fix Real-3DS Missing Audio (src/platform/3ds/threads_3ds.c, src/platform/3ds/audio_ndsp.c, src/platform/3ds/main_3ds.c, src/periph/spu.c)

  • SysCore (Core 1) SPU Worker Priority Ladder (0x2F):
    • Root Cause: In v0.2.4/v0.2.5, spu_core1_worker was spawned on Core 1 at main_prio + 1 (0x31), numerically lower priority than Horizon OS's 0x30 APT_SetAppCpuTimeLimit SysCore quota thread (or fell back to Core 0 at 0x30 where main() never yields), starving the audio worker 100% of the time while still displaying Core1 SPU: ASYNC on the HUD.
    • Fix: spu_core1_worker now launches on Core 1 at main_prio - 1 (0x2F) with a Core 1 retry ladder (0x2F -> 0x30 -> 0x31) and a sleeping-worker-safe Core 0 fallback (0x2F). Because the worker sleeps 500 us per step and parks 10 ms on APTHOOK_ONSUSPEND, 0x2F never blocks HOME Menu transitions. spu_core1_active now checks actual_core == 1 and logs spu_core=%d.
  • Dual-Core Trylock-Guarded NDSP Feeder & Core 0 Frame-End Backstop:
    • ctr_audio_step_core1(sys) is now guarded by an atomic trylock (g_step_lock) and pumped at the end of every emulated frame on Core 0 in addition to Core 1's 500 us worker. When Core 1 keeps up, Core 0 returns in < 1 us; if SysCore ever throttles Core 1, Core 0 seamlessly renders queued SpuCmd batches and feeds NDSP wavebufs.
  • 4x735 Full-Buffer FIFO NDSP Ring, 2-Buffer (33.3 ms) Re-Prime & Bounded Drift Resampler:
    • Root Cause: Previously, waking every 500 us popped partial 48..64-frame SPU batches into 735-frame NDSP wavebufs and padded the remaining 93.5%–100% with flat DC (g_last_l/g_last_r), locking NDSP into 50 ms of flat silence and inflating spu_underruns at 2 kHz.
    • Fix: Expanded NDSP ring to 4 x 735 stereo frames (66.7 ms), submitted via a strict FIFO cursor (g_wbuf_next) only when a full 735-frame buffer of real audio is ready. After cold start or a full NDSP drain, playback pre-primes 2 x 735 frames (33.33 ms, one full 30 Hz VSync(2) Even+Odd pair) so heavy ~22 ms 3D frames never underrun NDSP, counting exactly one atomic spu_underruns transition per genuine stream drain (0 underruns in we3_f2000/we3_f3100). Above high water, a gentle <= 1.1% linear resampler bounds latency under the 60.00 Hz lock.
  • Savestate Async SPU Regression Test (tests/unit/test_periph_spu.c):
    • Added test_spu_async_savestate_and_ring verifying that loading a sync (async_mode = false) savestate into an async (cfg.spu_async = true) 3DS system preserves async_mode == true and renders contiguous non-zero stereo audio across queued SpuCmd batches without drops.

2. Steady 60.0 FPS Wall-Clock Pacer & 32-Frame Rolling HUD Telemetry (src/gpu_hw/gpu_citro3d.c, src/platform/3ds/main_3ds.c, src/platform/3ds/ui_bottom.c)

  • Eliminate Extra VBlank Stalls on Empty VSync(2) Odd Frames:
    • hw_present now calls begin_frame(st, 0) instead of C3D_FRAME_SYNCDRAW when !st->in_frame, preventing empty Odd frames of 30 Hz VSync(2) games (~22 ms Even + ~6 ms Odd = ~28 ms < 33.33 ms) from stalling an extra hardware VBlank.
  • Drift-Free 60.00 Hz NTSC / 50.00 Hz PAL Deadline Pacer:
    • Added CtrFramePacer (16667 / 16667 / 16666 us = exact 50,000 us per 3 NTSC frames; 20,000 us PAL) with a 2-frame (33,334 us) catch-up window so 30 Hz VSync(2) Even+Odd pairs lock cleanly to 60.0 FPS while capping menus at 60.0 FPS (instead of running uncapped at 80+ FPS), without fast-forwarding after CD seeks or state loads.
  • 32-Frame Rolling HUD Average & Odd Redraw Cadence (15 frames = 4.0 Hz):
    • Replaced single-frame unpaced 1000000.0 / us_frame HUD readouts and the even-parity 16-frame redraw divisor (which aliased onto either heavy Even frames ~35 FPS or light Odd frames ~80 FPS) with a 32-frame rolling average of paced frame/CPU/GPU times, clamped cleanly at 60.0 FPS (16.67 ms) with an odd 15-frame idle redraw cadence.

中文更新说明 (v0.2.6)

  1. 彻底修复 New 3DS 实机无声音问题:
    • 修复 Core 1 (SysCore) SPU 音频线程饥饿:v0.2.4/v0.2.5 将 SPU 异步线程优先级设为 0x31(低于 Horizon OS 在 Core 1 上运行的 0x30 系统配额线程,或静默回退至主循环从不让出 CPU 的 Core 0),导致音频线程完全饥饿。现改为 0x2F(main_prio - 1)并配备优先级回退梯队与每帧末尾 Core 0 原子无锁(trylock)兜底泵送,确保任何情况下音频持续输出,且不影响 HOME 键挂起/退出。
    • 修复 NDSP 半满缓冲静音拼接与 FIFO 乱序:NDSP 环形缓冲扩容至 4 x 735 立体声采样帧(66.7 ms),严格按 FIFO 顺序仅在攒满 735 帧真实音频采样时提交(不再将未满缓冲区的 93%+ 填平为直流静音);启动或缓冲耗尽后自动预充 2 x 735 帧(33.3 ms,覆盖完整 30 Hz 奇偶帧周期),并通过 <= 1.1% 线性自适应重采样消除 60.00 Hz 锁帧下的长期音频延迟累积。
  2. 修复 30–80 帧跳动,稳定锁定最高 60.0 FPS:
    • 消除 30 Hz 游戏空奇帧额外垂直同步停顿:移除 hw_present 在无绘制奇帧上的 C3D_FRAME_SYNCDRAW,使《实况足球 3》比赛画面(偶帧 ~22 ms + 奇帧 ~6 ms = 28 ms < 33.33 ms)不再多等一次硬件 VBlank。
    • 零漂移 60.00 Hz(NTSC)/ 50.00 Hz(PAL)硬件时钟限帧器:带 2 帧(33.33 ms)追赶窗口,菜单与比赛最高稳定锁死 60.0 FPS(不再冲上 80+ FPS,也不会在光盘寻道后快进)。
    • HUD 32 帧滑动平均与奇分频(每 15 帧)刷新:消除旧版每 16 帧(偶数分频)采样奇偶帧导致的帧数显示跳变,稳定显示真实平滑帧率(最高钳位 60.0 FPS)。

PSX3DS v0.2.5 — Real-HW Performance Boost & Texel-Exact PICA200 Sampling

Choose a tag to compare

@codescv codescv released this 11 Nov 05:46

PSX3DS v0.2.5 — Real-Hardware Performance Boost (Eliminate PICA200 Readback/Sync Stalls, Early Scissor Culling, 128-Slot Stale-First TexCache) & Texel-Exact Hardware Sampling

v0.2.5 resolves the two issues reported on real New 3DS hardware running World Soccer Jikkyou Winning Eleven 3 - Final Ver. (Japan) (SLPM_861.62 + SCPH5500.BIN): ~20 FPS real-hardware framerate bottlenecks and display/texture sampling glitches (broken menu text, dotted player shadows, and off-by-one/wrapped polygon texel rows).


English Release Notes

1. Eliminate Per-Frame PICA200 Readback & Re-Upload Stalls on No-Op GP0(0x80) (src/gpu/gpu.c, src/gpu_hw/gpu_citro3d.c)

  • Root Cause: Winning Eleven 3 issues an unmasked self-copy GP0(0x80) (0, 0) -> (0, 0) of 2 x 512 at the end of every frame. Previously this forced hw_sync_to_shadow (C3D_FrameEnd(0) + synchronous C3D_SyncTextureCopy DMA readback + D-cache invalidation + CPU Morton un-swizzle) followed by a CPU tile upload and a second GPU stall on the next frame — two full PICA200 pipeline stalls per frame.
  • Fix: gpu_vram_copy_is_noop() short-circuits unmasked self-copies (sx == dx mod 1024, sy == dy mod 512, check_mask == 0, set_mask == 0) while preserving cycle-accurate command scheduling and full execution when mask bits are active. Masked GP0(0xA0) CPU->VRAM loads now also synchronize destination shadow VRAM before testing mask bit 15.

2. Early Scissor Bounding-Box Culling & Reduced GSPGPU / PICA200 Sync Overhead (src/gpu_hw/gpu_citro3d.c)

  • Early Scissor Culling: Primitives completely outside the active drawing area (~39% of draw calls in Winning Eleven 3 3D matches, including flashing off-screen stadium billboard CLUTs) are now culled at the top of hw_draw() before texture-page decoding, CLUT hashing, or batch breaks. flush_cpu_dirty_if_needed() now tests only the scissor-clipped primitive bounding box.
  • Single Vertex D-Cache Flush per Submission: Vertex ring buffers (expanded to 8192 vertices x 2) now call GSPGPU_FlushDataCache once per C3D_FrameEnd() submission instead of once per batch (eliminating ~360 GSPGPU IPC syscalls per match frame on real 3DS hardware).
  • Stall-Free upload_tex Updates: flush_cpu_dirty_if_needed() now stalls the open GPU frame only if upload_tex was already sampled in that open frame, and flushes D-cache only for the dirty 8-pixel tile-row span instead of the full 1 MiB texture.

3. 128-Slot Lazy TexCache & clut_dirty Victim Priority (src/gpu_hw/gpu_texcache.c, include/psx3ds/gpu_hw.h)

  • Root Cause: Animated palettes rewritten every frame left stale clut_dirty slots in the cache until all slots filled and began evicting clean, active 3D match textures.
  • Fix: Victim selection now recycles free allocated slots, texel_dirty slots, and stale clut_dirty slots before evicting any clean active texture (while keeping A <-> B palette toggles zero-redecode when capacity permits). Capacity is expanded to 128 lazily allocated slots on New 3DS (capped at a 24 MiB LINEAR RAM budget) and 32 slots on Old 3DS (small_mem).

4. Coalesced ARM11 L1 I-Cache Invalidation & Idle Bottom-Screen UI Throttling (src/jit/arm_jit.c, src/platform/3ds/jit_mem_3ds.c, src/platform/3ds/main_3ds.c)

  • Coalesced svc 0x94: jit_compile_at_pc() now cleans D-cache per block (jit_mem_commit_dcache) and executes a single ARM11 L1 I-cache + BTB invalidation (jit_mem_flush_icache) after the entire eager compilation pass (up to 33 blocks) finishes, before returning to native execution.
  • Bottom-Screen UI Throttling: During active gameplay with no new button/touch input, the software-rendered bottom status UI now redraws every 16th frame (~3.75 Hz) instead of every 4th frame, redrawing immediately on any input.

5. Texel-Exact PS1 Hardware Polygon & Sprite Sampling (src/gpu_hw/gpu_citro3d.c)

  • Root Cause: PICA200 samples fragment centers in bottom-up t = 1.0 - v / H texture coordinates under GPU_REPEAT. Polygon vertices (PRIM_TRI / PRIM_QUAD) lacked the PS1 +0.5 texel offset and integer pixel sample alignment, causing v = 0 edges to wrap to row 255, constant/decreasing v to sample row v - 1 (corrupting "Europe Zone" -> "Europe Zore"), and minified polygons to turn player shadows into dotted lines.
  • Fix: Vertex UVs now use 1/16-texel fixed point (HW_UV_SHIFT = 4), the VRAM render-target projection shifts geometry by +7/16 pixel to align PICA200 pixel centers with PS1 integer sample points, set_uv_transform applies a 1/64-texel floor nudge across the flipped t axis, and tri_uv_to_hw applies floor(u + 0.5) with per-triangle (du/dx + du/dy) / 16 gradient compensation. Menus/dialogs now match gpu_soft pixel-for-pixel (0.00% diff) and 3D match scenes match within 0.05% (Gouraud rounding only).

中文更新说明 (v0.2.5)

  1. 大幅优化 New 3DS 实机帧率(消除每帧 GPU 回读停顿与高频同步开销):
    • 跳过无掩码自拷贝 GP0(0x80):《实况足球 3 最终版》在每一帧末尾都会发送 (0,0) -> (0,0) 2x512 的自拷贝指令,旧版会触发整帧 PICA200 同步回读与次帧重传(每帧 2 次 GPU 管线停顿)。现已通过 gpu_vram_copy_is_noop() 直接短路跳过,比赛与菜单实测 readbacks = 0、stalls = 0、ring_wraps = 0。
    • 提前视口裁剪(Early Scissor Culling):在解码纹理页前提前剔除完全落在绘图裁剪区外的图元(剔除《实况足球 3》比赛画面约 39% 的场外无效绘制与场边闪烁广告牌调色板)。
    • 合并顶点缓冲 D-Cache 刷新与 upload_tex 按需同步:每帧提交(C3D_FrameEnd)仅执行 1 次顶点 D-Cache 刷新(消除每帧约 360 次 GSPGPU_FlushDataCache 系统调用),顶点环扩容至 8192;CPU 脏瓦片上传仅在当前未闭合帧已采样过 upload_tex 时才等待同步,且仅刷新脏瓦片所在行区间。
    • 128 槽位纹理缓存与动态调色板优先回收:优先回收已失效的动态调色板(clut_dirty)与脏纹素槽位,绝不驱逐活跃干净纹理(比赛纹理缓存命中率达 99.94%);New 3DS 扩容至 128 槽位(24 MiB 线性内存上限按需分配),Old 3DS 扩容至 32 槽位。
    • 合并 JIT L1 指令缓存刷新与下屏 UI 降频:jit_compile_at_pc 预编译整批代码块后仅执行一次 svc 0x94 全量 I-Cache 刷新;游戏无按键/触控输入时下屏软件 UI 降频至每 16 帧刷新一次。
  2. 彻底修复多边形与 UI 贴图采样显示错误:
    • 引入 1/16 纹素定点 UV、VRAM 投影 +7/16 像素对齐、翻转 t 轴 1/64 纹素向下取整偏置,以及三角形梯度补偿 tri_uv_to_hw,精确还原 PS1 硬件整数像素采样与 floor(u + 0.5) 纹素寻址。
    • 彻底修复了菜单文字错位断裂(如 "Europe Zone" 误显示为 "Europe Zore")、v = 0 贴图边缘回绕至第 255 行、球员脚下阴影变成断续黑点线、以及带掩码 GP0(0xA0) 写入未先行同步目标区域等问题。

PSX3DS v0.2.4 — Fix 480i VSync(0) Logo Freeze, FMV MDEC DMA1 Pacing & 3DS HOME->Close Hang

Choose a tag to compare

@codescv codescv released this 11 Nov 03:41

PSX3DS v0.2.4 — Fix 480i Interlaced VSync(0) Freeze, FMV MDEC DMA1 Pacing, PICA200 TexPage Wrap/Readback Stripes, and 3DS HOME -> Close Hang

v0.2.4 fixes real-hardware issues reported on New 3DS XL (SCPH5500.BIN + World Soccer Jikkyou Winning Eleven 3 - Final Ver. SLPM_861.62): freezing on the 480i interlaced logo screen (VSync(0)), FMV MDEC_in_sync timeout stalls, PICA200 hardware-backend right-column texture stripes on tp_x = 960 8bpp pages, and hanging on "Closing software..." when closing the emulator from the 3DS HOME Menu.


English Release Notes

1. Fix 480i Interlaced GPUSTAT Bit 31 / Bit 13 Freeze in Psy-Q VSync(0) (src/gpu/gpu.c, src/core/timers.c)

  • Root Cause: sys->gpu.frame was incremented twice per frame — once in gpu_on_vblank() at scanline 240 and a second time in timers_hblank_cb() at scanline 0 — leaving (gpu.frame & 1) permanently even (0) during active video (!in_vblank) while VBlank cleared bit 31 to 0. Consequently, in 480i interlaced mode (GP1(0x08) bit 22 + bit 19), GPUSTAT bit 31 never toggled, hanging Sony Psy-Q VSync(0) forever after initial logo mode switches (e.g. Winning Eleven 3 around frame 560).
  • Fix: sys->gpu.frame now increments strictly once per frame in gpu_on_vblank(), and gpu_refresh_scanline_bits() latches the new field parity into GPUSTAT bits 13 & 31 before IRQ0 (IRQ_VBLANK) is raised. Also removed duplicate sys->stats.frames++ from the standalone timers_vblank_default_cb fallback.

2. Fix FMV MDEC_in_sync timeout When DecDCTout (DMA1) Is Armed Before DecDCTin (DMA0) (src/core/dma.c, src/periph/mdec.c)

  • Root Cause: Standard Psy-Q FMV pipelines call DecDCTout() (DMA1, SyncMode 1) before DecDCTin() (DMA0). Previously, DMA1 executed immediately against an empty MDEC Data-Out FIFO (writing zeros into slice 0 and stranding the final decoded slice with MDEC_STAT bit 29 Command Busy = 1), causing the next frame's DecDCTinSync(0) to spin out with MDEC_in_sync timeout.
  • Fix: DMA1 (PSX_DMA_CH_MDEC_OUT, SyncMode 1) now stays armed until mdec_dma_out_blocks_ready() reports decoded blocks available, transfers only decoded blocks, and wakes immediately via dma_request_wakeup() when MDEC produces output. MDEC_STAT bit 29 (Command Busy) clears cleanly once decoding finishes and DMA1 is idle.

3. Fix PICA200 citro3d Right-Column Stripes (tp_x = 960 Wrap & Dirty-Cell Readback/Upload Coherence) (src/gpu_hw/gpu_citro3d.c, src/gpu_hw/gpu_texcache.c, src/gpu_hw/gpu_morton.c)

  • Root Cause: On 8bpp texture pages at tp_x = 960 (128 words wide), 960 + 128 = 1088 wrapped onto X = 0..63 (the active framebuffer), triggering hw_sync_to_shadow(960, 0, 128, 256) on every frame and copying back non-dirty cells at X = 960..1023 whose opaque RGBA5551 upload had forced PSX bit 15 (0x8000) to 1 — adding +128 to every odd 8bpp texel column.
  • Fix: Clamped TexPage coherence/invalidation width at X = 1023 (gpu_texpage_coherence_width()), restricted hw_sync_to_shadow to GPU-dirty 16x16 cells only (gpu_morton_readback_cells), replaced bounding-box CPU uploads with exact 8x8 dirty-tile runs (gpu_morton_upload_tiles), and added sync_cells_around_rect() on partial CPU overwrites (gpu_tex_hit_pct improved to 99.8% with zero stripes).

4. Fix 3DS HOME Menu -> "Close" Console Hang (src/gpu_hw/gpu_citro3d.c, src/platform/3ds/threads_3ds.c)

  • Root Cause:
    1. Pressing HOME triggers citro3d's APTHOOK_ONSUSPEND callback, disabling GSP VBlank callbacks and releasing GPU rights to the Home Menu. Tapping Close sends APTCMD_EXIT without APTHOOK_ONRESTORE, so calling C3D_FrameEnd(0) / C3D_FrameSync() unconditionally in hw_destroy() deadlocked forever inside gspWaitForAnyEvent().
    2. spu_core1_worker ran on Core 1 (SysCore, shared with Horizon OS Home Menu/APT/GSP/DSP applets) at main_prio - 1 (0x2F, higher priority than main 0x30), and worker threads were not parked during APT suspend/sleep/exit transitions.
  • Fix:
    • gpu_citro3d registers hw_apt_hook (called before citro3d's own hook) to cleanly flush and C3D_FrameEnd(0) any open frame on APTHOOK_ONSUSPEND, and guards hw_present() / hw_destroy() behind aptIsActive() && !aptShouldClose().
    • spu_core1_worker on Core 1 (SysCore) now runs cooperatively at main_prio + 1 (0x31), and threads_apt_hook parks both Core 1 (SPU) and Core 2 (CD readahead) workers in 10 ms sleeps without touching NDSP, DSP cache, or SDMC across APTHOOK_ONSUSPEND / ONSLEEP / ONEXIT.

中文更新说明 (v0.2.4)

  1. 修复 480i 隔行扫描模式下卡在 Logo 画面的问题(如《实况足球 3 最终版》):
    • 修复了 sys->gpu.frame 在每帧 VBlank 起点(扫描线 240)和扫描线 0 被重复递增两次的 Bug。现在场奇偶计数每帧严格递增一次,且在触发 IRQ_VBLANK 前预先锁存 GPUSTAT 第 13/31 位奇偶场标志,使 Psy-Q VSync(0) 正常翻转退出,顺利通过 480i JFA/Konami Logo 进入片头 FMV 动画与标题菜单。
  2. 修复片头 FMV 视频播放期间 MDEC_in_sync timeout 卡顿:
    • 当游戏按 Psy-Q 惯例先挂载 DecDCTout(DMA1,SyncMode 1)再启动 DecDCTin(DMA0)时,DMA1 现会等待 MDEC 输出 FIFO 产生解码宏块后再由 dma_request_wakeup() 唤醒搬运,彻底消除空读全零切片与 MDEC_in_sync timeout 超时。
  3. 修复 PICA200 硬件渲染器在 tp_x = 960 8bpp 纹理页上的右侧竖条纹花屏:
    • 限制纹理页一致性检测宽度不跨过 X = 1023 回绕至主帧缓冲,将 VRAM 回读严格限定于 GPU 脏 16x16 区块,并将 CPU 上传改为精确 8x8 脏瓦片区间提交,标题画面全部 368 列完整清晰无条纹(纹理缓存命中率提升至 99.8%)。
  4. 修复按下 3DS HOME 键在主界面关闭软件时卡在“正在关闭软件…”的死锁:
    • gpu_citro3d 新增 APTHOOK_ONSUSPEND 钩子在挂起前提交未闭合帧,并在 !aptIsActive() || aptShouldClose() 时跳过 C3D_FrameBegin / C3D_FrameEnd / C3D_FrameSync,避免在失去 GSP 权限后永久阻塞于 gspWaitForAnyEvent()。
    • Core 1(SysCore)上的 SPU 音频线程优先级调整为协作式 main_prio + 1,并在 HOME 挂起/休眠/退出期间自动挂起双核工作线程(不触碰 NDSP / DSP 缓存 / SD 卡),确保退回主界面与关闭游戏秒退不卡死。

PSX3DS v0.2.3 — Real New 3DS ARM11 L1 I-Cache Fix & Dedicated SD Scan Folders

Choose a tag to compare

@codescv codescv released this 11 Nov 02:04

PSX3DS v0.2.3 — Real New 3DS ARM11 L1 I-Cache Invalidation, VIPT & 32B JIT Alignment, SP Guard, and Dedicated SD Scan Folders

v0.2.3 fixes a real-hardware New 3DS XL (Luma3DS) prefetch abort (Permission - Section) crash during JIT execution (PC = 0x08067E70, LR = 0x001378D8) and restricts SD card ROM/BIOS scanning to dedicated PS1 folders instead of scanning the SD root.


English Release Notes

Root Cause Fixed from Real-Hardware v0.2.2 Crash Dump (PC = 0x08067E70, SP = 0x0803DEA0)

  • On real ARM11 MPCore hardware, svcFlushProcessDataCache only cleans the L1 D-Cache out to FCRAM without invalidating the separate 32 KiB 4-way (8 KiB/way) VIPT L1 Instruction Cache or branch target buffer.
  • Inside a newly compiled JIT block, emit_call executed push {r12, lr} (SP: 0x0803DE80 -> 0x0803DE78) and then crossed a 32-byte ARM11 L1 I-Cache line boundary into a cache line that still held stale 0x00000000 (andeq r0, r0, r0 = NOP) words cached by earlier instruction prefetching across 4-byte-packed blocks.
  • Executing blx r12 and pop {r12, lr} as NOPs left LR = 0x001378D8 (psx_run_frame + 0x778) untouched and SP shifted by -8 bytes at jit_exit, causing pop {r4-r12, pc} to pop saved_r11 = 0x08067E70 (sys + 0xb000, non-executable heap data) into PC while leaving [0x0803DEA0] = 0x08931D30 (saved_r12) and [0x0803DEA4] = 0x001378D8 (saved_lr) at [SP].

What's New in v0.2.3

  1. ARM11 L1 I-Cache & Branch Predictor Invalidation on Every JIT Commit (jit_mem_commit):
    • Flushes 32-byte aligned D-Cache lines for both the m->rw view and m->rx mirror, invalidates the ARM11 L1 I-Cache + BTB via Luma3DS svc 0x94 (svcInvalidateEntireInstructionCache, with r0-r3, r12 clobbers; or the 128 KiB NOP eviction sled on non-Luma hardware), and executes EL0-safe DSB (c7, c10, 4) + ISB (c7, c5, 4).
  2. 16 KiB VIPT Cache-Color Alignment & 32-Byte JIT Block Alignment:
    • jit_mem_alloc() now allocates m->rw via memalign(0x4000, size) (16 KiB >= 8 KiB/way) to match the 1 MiB-aligned m->rx mirror across all ARM11 VIPT cache colors (VA bits [13:12]).
    • arm_jit now aligns and zero-pads every emitted native block to a 32-byte ARM11 cache-line boundary (((uintptr_t)entry & 31) == 0).
  3. Hardware SP Guard Across jit_enter / jit_exit* (jit_thunks.S):
    • jit_enter saves the exact host stack pointer at cpu->jit_saved_sp ([r11, #0x270]), and all 4 exit paths (jit_exit, jit_exit_step_one, jit_exit_with_reason, jit_raise_exception_exit) restore ldr sp, [r11, #0x270] immediately before pop {r4-r12, pc}.
  4. Dedicated SD Card ROM & BIOS Scan Folders (No Full SD Root Scan):
    • 1:ROMS now scans only sdmc:/psx3ds/roms, sdmc:/roms/psx, and sdmc:/psx (sdmc:/ root is never scanned).
    • External BIOS auto-detection scans only sdmc:/psx3ds/bios, sdmc:/bios, and those three PS1 ROM folders.

中文更新说明 (v0.2.3)

  1. 修复 New 3DS 实机 ARM11 L1 指令缓存(I-Cache)未失效导致的 PC = 0x08067E70 崩溃:
    • 每次编译提交 JIT 代码块(jit_mem_commit)时,同步刷写 m->rw 与 m->rx 的数据缓存(D-Cache),并通过 Luma3DS svc 0x94 使 ARM11 L1 指令缓存与分支预测器(BTB)失效,随后执行 DSB + ISB 内存与指令屏障。
    • JIT 读写缓冲区升级为 16 KiB 对齐(memalign(0x4000, size)),消除 ARM11 32 KiB 4-way(8 KiB/way)VIPT 缓存颜色别名;所有 JIT 代码块统一按 32 字节缓存行边界对齐与填充。
    • jit_enter / jit_exit* 新增硬件栈指针保护([r11, #0x270] 保存与恢复 SP),确保 pop {r4-r12, pc} 永不错位。
  2. 精简 SD 卡扫描目录(不再扫描 SD 卡根目录):
    • 1:ROMS 游戏列表现仅扫描 sdmc:/psx3ds/roms、sdmc:/roms/psx 与 sdmc:/psx(外置 BIOS 仅扫描 sdmc:/psx3ds/bios、sdmc:/bios 及上述游戏目录),大幅加快大肚量 SD 卡启动与刷新速度。

PSX3DS v0.2.2 — Built-in OpenBIOS, ISO9660 .chd CD-ROM Boot & 4:LOG UI

Choose a tag to compare

@codescv codescv released this 10 Nov 13:42

PSX3DS v0.2.2 — Zero-Setup Embedded OpenBIOS, ISO9660 .chd/CD-ROM Boot, and On-Screen 4:LOG Diagnostics

v0.2.2 fixes the black top-screen issue when booting .chd / .cue / .bin / .iso CD-ROM games without an external SCPH1001.BIN BIOS file on the SD card, and adds live bottom-screen boot/runtime logging (4:LOG).


English Release Notes

Root Causes Fixed from Real-Hardware v0.2.1 Report ([HLE BIOS] + JIT: 6 blks + CD Miss 0 + Prims: 0)

  1. openbios.bin was not embedded into .cia / .3dsx / .cci: v0.2.1 looked for romfs:/openbios.bin without a packaged RomFS, and SD BIOS scanning only checked exact SCPH1001.BIN / openbios.bin filenames. Without SCPH1001.BIN on the SD card, psx3ds fell back to [HLE BIOS].
  2. [HLE BIOS] lacked ISO9660 CD-ROM bootstrap: Previously, HLE mode only injected standalone .exe homebrew (psx_load_exe), not ISO9660 SYSTEM.CNF boot executables from mounted CD-ROMs (psx_load_cd), causing the CPU to spin in the 0x80030000 6-block idle loop with 0 CD sector reads and 0 GPU primitives.

What's New in v0.2.2

  • Built-In 512 KiB OPENBIOS Embedded in Every Build (src/sys/openbios_blob.S):
    • Works out of the box with zero external BIOS setup required ([OPENBIOS] green badge on startup).
    • Case-insensitively auto-detects any external 512 KiB retail BIOS (SCPH*.BIN, PSXONPSP*.BIN, BIOS*.BIN, openbios.bin) placed in sdmc:/psx3ds/bios/, sdmc:/psx/, sdmc:/roms/psx/, sdmc:/bios/, or sdmc:/ and prefers it automatically.
  • Full ISO9660 SYSTEM.CNF / PS-X EXE CD-ROM Boot (src/sys/cdboot.c, src/sys/hle_bios.c):
    • Native BIOS CD boot under OPENBIOS / retail SCPH*.BIN (skips the BIOS shell at 0x80030000 and boots SYSTEM.CNF -> BOOT = cdrom:\... through the emulated CD-ROM controller + DMA3, with automatic 0x80030000 sideload fallback and optional CD Boot: Fast mode in 3:CTRL).
    • Direct ISO9660 SYSTEM.CNF / PS-X EXE extraction + cdrom: HLE file I/O (open/read/lseek/close/Load/LoadExec) + B0:15 pad driver support in [HLE BIOS] mode.
  • On-Screen 4:LOG Tab, Live PC / CD Rd / IRQ / Disp HUD Diagnostics & SD Log File:
    • Bottom screen now features 4 tabs: 1:ROMS | 2:HUD | 3:CTRL | 4:LOG.
    • 2:HUD displays live PC, cumulative CD Rd sector count, IRQ flags/mask, and Disp resolution/VRAM coordinates.
    • 4:LOG displays real-time [bios], [cdboot], [hle], and guest BIOS [tty] output with Up/Down scrolling, Dump Log, and Clear, while mirroring boot logs to sdmc:/psx3ds/psx3ds.log.
    • 3:CTRL adds toggles for BIOS: Auto/OpenBIOS <-> HLE Direct and CD Boot: Native <-> Fast.

中文更新说明(修复 .chd / 光盘镜像启动黑屏 + 内置 OpenBIOS 免配置启动 + 新增 4:LOG 调试日志页)

问题根因解析(对应实机照片 [HLE BIOS] + JIT: 6 blks + Miss 0 + Prims: 0)

  1. v0.2.1 未将 openbios.bin 内嵌进 .cia / .3dsx:当 SD 卡中没有放置 SCPH1001.BIN 时,程序回退到了 [HLE BIOS] 模式(顶栏橙色标记)。
  2. [HLE BIOS] 此前仅支持直接加载独立 .exe 自制程序(psx_load_exe),尚未实现从 .chd / .bin 光盘镜像解析 ISO9660 SYSTEM.CNF 启动文件(psx_load_cd),导致 CPU 跳到 0x80030000 后停留在 6 个基本块的空循环中,未读取任何光盘扇区(Miss 0),也未绘制任何多边形(Prims: 0)。

v0.2.2 核心更新与新功能

  1. 直接内嵌 512 KiB OPENBIOS 到 .cia / .3dsx(零配置开箱即用):
    • 无需拷贝任何外部 BIOS 文件即可直接启动 .chd / .cue / .bin / .iso 游戏(顶栏显示绿色 [OPENBIOS])。
    • 同时扩展了外部 BIOS 自动扫描:若你在 sdmc:/psx3ds/bios/、sdmc:/psx/、sdmc:/roms/psx/ 或 sdmc:/bios/ 放入任意 512 KiB 原版 BIOS(如 SCPH1001.BIN、SCPH5501.BIN、SCPH7001.BIN、PSXONPSP660.BIN,不区分大小写),会自动优先加载外部原版 BIOS。
  2. 完整支持 ISO9660 SYSTEM.CNF / PS-X EXE 光盘引导(兼容 OPENBIOS 原生引导、快速引导与 HLE BIOS):
    • 在 OPENBIOS / 原版 BIOS 下支持通过模拟光驱控制器原生读取 SYSTEM.CNF 与主程序 EXE,并在 3:CTRL 页提供 CD Boot: Native / Fast(原生引导 / 瞬间直载)与 BIOS: Auto/OpenBIOS / HLE Direct 切换开关。
    • 在 HLE BIOS 模式下同样补齐了 ISO9660 主程序自动解析注入、cdrom: 文件读取(open/read/lseek/close)及手柄驱动 HLE 接口。
  3. 新增下屏 4:LOG 实时日志标签页、2:HUD 实时 PC / CD Rd 状态行与 SD 卡日志文件:
    • 采纳你的建议,在下屏新增 4:LOG 标签页(支持上下翻页、Dump Log 导出与 Clear 清空),并同步写入 sdmc:/psx3ds/psx3ds.log,直观展示 [bios]、[cdboot] SYSTEM.CNF -> BOOT=... 及 BIOS 内核 [tty] 输出。
    • 在 2:HUD 新增实时 PC、CD Rd(累计读取光盘扇区数)、IRQ 与 Disp 显示状态行,一眼即可确认光盘读取与渲染进度。

安装/升级方法

  • .cia 桌面安装版(推荐):下载 psx3ds.cia(或解压 psx3ds-v0.2.2-3ds.zip 到 SD 卡根目录),使用 FBI 直接覆盖安装即可(相同 TitleID 000400000F853D00,无需任何额外设置即可直接运行 .chd 游戏)。
  • .3dsx 自制系统启动版:下载 psx3ds.3dsx 与 psx3ds.smdh 覆盖 sdmc:/3ds/psx3ds/ 目录后从 Homebrew Launcher 启动。

PSX3DS v0.2.1 — Fix New 3DS Startup Crash (svcBreak in __system_allocateHeaps)

Choose a tag to compare

@codescv codescv released this 10 Nov 12:30

PSX3DS v0.2.1 — Fix New 3DS Startup Crash (svcBreak in __system_allocateHeaps)

v0.2.1 is a critical hotfix for all real New Nintendo 3DS / New 3DS XL / New 2DS XL consoles running Luma3DS (both .cia and .3dsx builds).


English Release Notes

Bug Fixed: Immediate Startup Crash (prefetch abort / Debug event) on Real New 3DS Hardware

  • Symptom in v0.2.0: Launching psx3ds.cia (or psx3ds.3dsx with >= 124 MiB commit limit) on a real New 3DS running Luma3DS immediately crashed before main() with a Luma3DS exception screen:
    • Exception type: prefetch abort (Fault status: Debug event — svcBreak(USERBREAK_PANIC))
    • PC = 0x001CB108 (svcBreak), LR = 0x001CABF4 (__system_allocateHeaps + 0x1bc)
    • R3 = 0x06694000 (102.58 MiB) with New 3DS RESLIMIT_COMMIT = 0x07C00000 (124 MiB)
  • Root Cause:
    • To fit 26 MiB PsxArena + 6 MiB JIT on 64 MiB Old 3DS .cia installs, v0.2.0 set u32 __ctru_linear_heap_size = 20 MiB while leaving __ctru_heap_size = 0.
    • In libctru's __system_allocateHeaps, setting a non-zero __ctru_linear_heap_size with __ctru_heap_size == 0 bypasses libctru's default 32 MiB linear-heap branch and takes an uncapped branch: __ctru_heap_size = remaining - __ctru_linear_heap_size.
    • On a real New 3DS (124 MiB RESLIMIT_COMMIT, ~122.58 MiB remaining), __ctru_heap_size became 102.58 MiB (0x06694000). When svcControlMemory(MEMOP_ALLOC) attempted to map 0x08000000 .. 0x0E694000, it overflowed Horizon OS Kernel11's 96 MiB ([0x08000000, 0x0E000000)) application heap virtual address ceiling (OS_HEAP_AREA_END), failing and triggering svcBreak(USERBREAK_PANIC) before main(). (Azahar's HLE kernel permits a 128 MiB heap window, masking this bug in emulator-only tests.)
  • Fix in v0.2.1:
    • Custom __system_allocateHeaps Override (src/platform/3ds/main_3ds.c + include/psx3ds/ctr_heap.h): Computes normal_heap = min(remaining - 20 MiB, 80 MiB) and assigns the remaining commit budget to the linear heap:
      • New 3DS (124 MiB .cia / .cci / .3dsx): 80.00 MiB (0x05000000) normal heap (0x08000000 .. 0x0D000000, leaving a full 16 MiB VA safety margin below 0x0E000000) + ~42.58 MiB linear heap.
      • New 3DS (178 MiB extended .3dsx): 80.00 MiB normal heap + ~96.58 MiB linear heap.
      • Old 3DS (64 MiB .cia / .cci / .3dsx): ~42.58 MiB normal heap + 20.00 MiB linear heap (unchanged).
    • Resilient Kernel Fallback: If svcControlMemory ever rejects a requested heap or contiguous linear-heap allocation (e.g. fragmented FCRAM under .3dsx launchers), __system_allocateHeaps shrinks in 8 MiB steps and retries instead of panicking.
    • Accurate Old 3DS small_mem Auto-Detection: psx_system_init() now inspects envGetHeapSize() < 64 MiB (__ctru_heap_size) instead of osGetMemRegionFree(MEMREGION_APPLICATION) (which reads ~0 after startup commits RESLIMIT_COMMIT), ensuring New 3DS .cia and .3dsx always run the full 16 MiB JIT + 64-slot RGBA8 texture cache + 8-slot CHD cache profile while Old 3DS uses small_mem.
    • Startup Heap Regression Suite (tests/unit/test_ctr_heap.c): Verifies 36 MiB <= heap_size <= 80 MiB < 96 MiB across O3DS 64/80/96 MiB, N3DS 124/178 MiB, the exact crash dump registers, and a 1..256 MiB sweep across all 3 CI/test tiers.

Quick Start (SD Card Installation)

  1. Download psx3ds.cia (or extract psx3ds-v0.2.1-3ds.zip to the root of your 3DS SD card sdmc:/).
  2. Recommended (.cia): Open FBI → SD → install psx3ds.cia (overwrites v0.2.0 cleanly under TitleID 000400000F853D00), then launch PSX3DS from the Home Menu.
  3. Alternative (.3dsx): Place psx3ds.3dsx and psx3ds.smdh in sdmc:/3ds/psx3ds/ and launch from Homebrew Launcher.
  4. Put PS1 BIOS (SCPH1001.BIN or included openbios.bin) in sdmc:/psx3ds/bios/ and games (.chd, .cue/.bin, .iso, .exe) in sdmc:/psx3ds/roms/.

中文更新说明(修复 New 3DS 实机打开即崩溃问题)

修复核心问题:New 3DS / New 3DS XL / New 2DS XL(Luma3DS)启动即报 prefetch abort (svcBreak) 崩溃

  • 问题原因(v0.2.0):
    • v0.2.0 为了兼容老三(Old 3DS 64 MiB)的内存预算,设置了 __ctru_linear_heap_size = 20 MiB 且保留 __ctru_heap_size = 0。
    • 在 libctru 的 __system_allocateHeaps 中,当仅指定线性堆大小而未指定普通堆上限时,会跳过默认的 32 MiB 线性堆分支,直接按 remaining - 20 MiB 无上限计算普通堆。
    • 在 New 3DS(RESLIMIT_COMMIT = 124 MiB,剩余约 122.58 MiB)实机上,普通堆请求大小变成了 102.58 MiB(R3 = 0x06694000),映射范围 0x08000000 .. 0x0E694000 超出了 3DS Kernel11 应用普通堆的 96 MiB 虚拟地址上限 [0x08000000, 0x0E000000),导致 svcControlMemory 失败并在进入 main() 前触发 svcBreak(USERBREAK_PANIC)(Luma3DS 显示 prefetch abort / Debug event)。
  • v0.2.1 修复方案:
    • 接管并重写 __system_allocateHeaps:通过 psx_ctr_compute_heap_split() 精确划分普通堆与线性堆:普通堆上限严格封顶为 80 MiB(0x05000000,最高至 0x0D000000),彻底杜绝越过 0x0E000000 内核虚拟地址边界:
      • New 3DS (124 MiB .cia / .3dsx):80.00 MiB 普通堆 + 42.58 MiB 线性堆(完整启用 16 MiB ARM11 W^X JIT 缓存、64 槽位硬件纹理缓存与 8 槽位 CHD 缓存)。
      • Old 3DS (64 MiB .cia / .3dsx):42.58 MiB 普通堆 + 20.00 MiB 线性堆(自动启用 small_mem 配置)。
    • 内核分配自适应退避重试:若在内存碎片化的自制软件启动器环境下单次分配被内核拒绝,自动按 8 MiB 步进收缩重试,避免直接崩溃。
    • 修复 small_mem 自动识别逻辑:改用 envGetHeapSize() < 64 MiB 判定老三/新三内存配置,并新增 test_ctr_heap 单元测试覆盖全部机型内存布局。

安装/升级方法

  • .cia 桌面安装版(推荐):下载 psx3ds.cia(或解压 psx3ds-v0.2.1-3ds.zip 到 SD 卡根目录),使用 FBI 直接覆盖安装即可(相同 TitleID 000400000F853D00,存档与记忆卡完全保留)。
  • .3dsx 自制系统启动版:下载 psx3ds.3dsx(及 psx3ds.smdh)覆盖 sdmc:/3ds/psx3ds/ 目录后从 Homebrew Launcher 启动。
  • 所有发布文件均可通过 SHA256SUMS.txt 校验完整性。

PSX3DS v0.2.0 — ARM11v6K Dynarec, PICA200 Hardware GPU, CHD Support & Installable CIA

Choose a tag to compare

@codescv codescv released this 06 Nov 16:52

PSX3DS v0.2.0 — ARM11v6K Dynarec, PICA200 Hardware GPU, CHD v5 & Installable CIA

PSX3DS is a PlayStation 1 (PSX) emulator built from scratch in C11 and ARMv6K assembly specifically for the Nintendo 3DS (ARM11 MPCore + VFPv2 + PICA200 GPU + 4-core multi-threading).

v0.2.0 adds full CHD v1–v5 compressed disc streaming (cdzl / cdlz / cdzs / cdfl + multi-hunk LRU cache + Core 2 async offload) and an installable universal .cia package unlocking native Horizon OS SVC 0x70 hardware W^X dual-mapped JIT on Luma3DS across both New 3DS and Old 3DS.


English Highlights

  • Installable Universal .cia (psx3ds.cia, 789 KiB):
    • Install directly via FBI onto the 3DS Home Menu (TitleID 000400000F853D00, custom 3D banner, icon & boot chime).
    • Grants native SVC 0x70 (ControlProcessMemory) for hardware W^X dual-mapped RW+RX JIT (JIT_MEM_MIRROR_RWRX) on Luma3DS, 804 MHz ARM11 + 2 MiB L2 + 124 MiB FCRAM + Core 2 + ir:rst / qtm:s C-Stick & ZL/ZR on New 3DS / New 2DS XL.
    • Automatically adapts to Old 3DS / Old 2DS (64 MiB FCRAM, 268 MHz) via the small_mem profile (20 MiB linear heap + 42.6 MiB normal heap, 26 MiB arena, 6 MiB JIT cache, 20-slot RGBA5551 texture cache, 4-slot CHD cache).
  • Full CHD v1–v5 Compressed Disc Streaming (libchdr v0.3.0):
    • Supports all four CHD v5 CD codecs — cdzl (Deflate), cdlz (LZMA), cdzs (Zstandard), and cdfl (FLAC 16-bit CD-DA + Subcode) — plus legacy CHD v1–v4, shrinking PS1 multi-bin dumps by 40–60% into single .chd files (chdman createcd -i game.cue -o game.chd).
    • Exact CD_TRACK_PADDING = 4 multi-track frame remapping, synthesized Q-subchannel BCD MSF addresses, and ARMv6K two-sample-per-word REV16 big-to-little-endian CD-DA swap.
    • 8-slot LRU hunk cache (87.5% sequential cold hit rate; 1,531 MB/s warm on ARM11v6K) + lock-serialized Core 2 async decompression, running 64×–138× faster than PS1 2× CD-ROM (22.4–48.3 MB/s cold decode on ARM11v6K).
  • arm_jit MIPS R3000A → ARM11v6K Dynamic Recompiler & 100% Inline GTE:
    • 71.0× faster than interpreter on compute loops; all 22 GTE (COP2) commands emitted inline using ARMv6 SMLAD/SMLALD (1,150 / 1,150 gte-test-all, 00000101 psxtest_cpu).
    • Sub-page 64-byte SMC bitmask eliminates display-list/BSS false invalidations (69/frame → 0/frame steady-state recompiles; 788.8 FPS Cube, 512.7 FPS PSXNICCC on ARM11v6K harness).
  • Batched PICA200 Hardware GPU (gpu_citro3d) + Multi-Core SPU (ndsp):
    • 2-stage TEV textured/untextured/FillRect batch fusion + Morton texture cache with per-8×8-tile STP semi-transparency masks (2.5×–3.5× faster than ARMv6 SIMD software rasterizer) + Core 1 44.1 kHz stereo SPU worker (92–97% fewer audio underruns).

Quick Start (SD Card Installation)

  1. Extract psx3ds-v0.2.0-3ds.zip directly to the root of your 3DS SD card (sdmc:/), or grab standalone psx3ds.cia / psx3ds.3dsx.
  2. Recommended (.cia): Open FBI → SD → cia → psx3ds.cia → Install and delete CIA, then launch PSX3DS from the Home Menu.
    (Homebrew Launcher users can launch sdmc:/3ds/psx3ds/psx3ds.3dsx directly.)
  3. Place your legally dumped PS1 BIOS (SCPH1001.BIN) in sdmc:/psx3ds/bios/ (MIT-licensed openbios.bin is pre-included for homebrew / PS-EXE titles; retail CD/CHD games require a console BIOS) and drop .chd / .cue+.bin / .iso / .exe titles into sdmc:/psx3ds/roms/. Ensure sdmc:/3ds/dspfirm.cdc is dumped for hardware ndsp audio.

中文更新说明(v0.2.0 亮点)

  • 原生可安装 .cia 安装包(支持 FBI 安装,通吃新三 / 老三):
    • 使用 Luma3DS 上的 FBI 安装 psx3ds.cia(自带专属 3DS 桌面图标、横幅动画与启动音效),直接从桌面启动。
    • 原生解锁 Horizon OS SVC 0x70 硬件级 W^X 双映射动态重编译(JIT_MEM_MIRROR_RWRX);在 New 3DS / New 2DS XL 上自动开启 804 MHz 超频 + 2 MiB L2 缓存 + 124 MiB 大内存 + Core 2 独立光驱核 + C-Stick 右摇杆与 ZL/ZR(ir:rst / qtm:s);在 Old 3DS / 2DS(64 MiB / 268 MHz) 上自动切换 small_mem 精简内存池并保持满速 ARM11 JIT!
  • 完整支持 CHD v1–v5 无损压缩光盘镜像(单文件省空间 40%–60%):
    • 内置 libchdr v0.3.0 + 3DS 硬件浮点解码库,完整支持 cdzl(Deflate)、cdlz(LZMA)、cdzs(Zstd)、cdfl(FLAC 无损音轨 + ARMv6K REV16 字节序加速) 四大 CHD v5 编码与多轨 4 扇区对齐重映射(可通过 chdman createcd -i game.cue -o game.chd 一键转换)。
    • 配备 8 槽位 LRU Hunk 缓存(顺序读取命中率 87.5%,ARM11 缓存命中带宽 1,531 MB/s,冷解码吞吐达 PS1 双倍速光驱的 64–138 倍)以及 Core 2 后台异步预读解压,UI 列表自动显示 [CHD] 标识与实时缓存命中率。
  • 专为 3DS ARM11 + PICA200 深度定制的极速内核:
    • arm_jit 动态重编译器 + 100% 内联 ARMv6K GTE 几何引擎(全部 22 条 GTE 指令采用 SMLAD/SMLALD 内联发射,零函数调用开销,通过 psxtest_cpu 与 gte-test-all 1150/1150 严苛测试)+ 64 字节子页级 SMC 脏行掩码(稳态每帧重编译降至 0)。
    • PICA200 citro3d 硬件加速渲染(2 阶段 TEV 批次融合 + Morton 纹理缓存 + 8×8 图块半透明 STP 精准分类)+ Core 1 独立 SPU 44.1 kHz 混音线程。

安装与目录结构

将 psx3ds-v0.2.0-3ds.zip 解压到内存卡根目录:

  • sdmc:/cia/psx3ds.cia — 推荐通过 FBI 安装至桌面(解锁完整 SVC 0x70 W^X JIT 权限)
  • sdmc:/3ds/psx3ds/{psx3ds.3dsx, psx3ds.smdh} — Homebrew Launcher 自制系统启动版
  • sdmc:/psx3ds/bios/ — 放入自备主机提取的 SCPH1001.BIN(压缩包内亦附带开源 MIT 协议 openbios.bin)
  • sdmc:/psx3ds/roms/ — 放入 .chd(推荐)、.cue/.bin、.iso 或 .exe 游戏镜像

Benchmark & Verification Snapshot (v0.2.0)

Metric Measured Result
Unit & Sanitizer Gates (ctest) 19 / 19 PASS on x86_64 ASan+UBSan (-Werror, 0 leaks/UB) & 19 / 19 PASS on qemu-arm -cpu arm11mpcore (0 warnings, 0 SIGILL)
PS1 CPU & GTE Accuracy (arm_jit) psxtest_cpu.exe 00000101 PASS; gte-test-all.exe 1,150 / 1,150 PASS (100% inline ARMv6K GTE)
CHD v5 Throughput (ARM11v6K / x86_64) Zstd 48.3 / 206.9 MB/s, Deflate 28.7 / 163.0 MB/s, LZMA 27.6 / 108.3 MB/s, FLAC 22.4 / 118.2 MB/s; 8-slot LRU warm 1,531 / 28,356 MB/s
3DS .cia/.cci & .3dsx (azahar-headless) Cube.exe 120.7 FPS (N3DS) / 120.2 FPS (O3DS 64 MiB small_mem); PSXNICCC.exe 117.9 FPS; cube_v5.chd bit-identical vs ISO

See docs/BENCHMARKS.md and docs/ARCHITECTURE.md for full architecture and telemetry details. Verify release downloads against SHA256SUMS.txt.