diff options
| author | spicyjpeg <thatspicyjpeg@gmail.com> | 2023-06-20 03:17:34 +0200 |
|---|---|---|
| committer | spicyjpeg <thatspicyjpeg@gmail.com> | 2023-06-20 03:17:34 +0200 |
| commit | eaea5649a0803cc4bfeb6d21ee9f4098d4b493fc (patch) | |
| tree | 786f6edfae0c6affe0d7c7b222cd12f52578ca01 /libpsn00b/psxgpu | |
| parent | 7eed71a90bed67e4a987a9db55e15e9403523dca (diff) | |
| download | psn00bsdk-eaea5649a0803cc4bfeb6d21ee9f4098d4b493fc.tar.gz | |
Fix IRQ bugs, PutDispEnv() PAL screen centering
Diffstat (limited to 'libpsn00b/psxgpu')
| -rw-r--r-- | libpsn00b/psxgpu/common.c | 8 | ||||
| -rw-r--r-- | libpsn00b/psxgpu/env.c | 69 |
2 files changed, 36 insertions, 41 deletions
diff --git a/libpsn00b/psxgpu/common.c b/libpsn00b/psxgpu/common.c index 7e0758b..5678f35 100644 --- a/libpsn00b/psxgpu/common.c +++ b/libpsn00b/psxgpu/common.c @@ -88,13 +88,15 @@ void ResetGraph(int mode) { // Perform some basic system initialization when ResetGraph() is called for // the first time. if (!ResetCallback()) { - EnterCriticalSection(); + int _exit = EnterCriticalSection(); + InterruptCallback(IRQ_VBLANK, &_vblank_handler); InterruptCallback(IRQ_GPU, &_gpu_irq_handler); DMACallback(DMA_GPU, &_gpu_dma_handler); - _gpu_video_mode = (GPU_GP1 >> 20) & 1; - ExitCriticalSection(); + + if (_exit) + ExitCriticalSection(); _sdk_log("setup done, default mode is %s\n", _gpu_video_mode ? "PAL" : "NTSC"); } diff --git a/libpsn00b/psxgpu/env.c b/libpsn00b/psxgpu/env.c index 236ae4b..fdd4329 100644 --- a/libpsn00b/psxgpu/env.c +++ b/libpsn00b/psxgpu/env.c @@ -169,69 +169,62 @@ DISPENV *SetDefDispEnv(DISPENV *env, int x, int y, int w, int h) { void PutDispEnv(const DISPENV *env) { _sdk_validate_args_void(env); - uint32_t h_range, v_range, mode, fb_pos; + uint32_t fb_pos, h_range, v_range, mode; mode = _gpu_video_mode << 3; mode |= (env->isrgb24 & 1) << 4; mode |= (env->isinter & 1) << 5; mode |= (env->reverse & 1) << 7; - if (env->disp.h > 256) - mode |= 1 << 2; + int h_span = env->screen.w ? env->screen.w : 256; + int v_span = env->screen.h ? env->screen.h : 240; - // Calculate the horizontal display range values. The original code was - // this bad; in actual fact it was even worse due to being written in - // assembly and using slow multiplication even when not necessary. - int offset, span, default_span = 2560; + // Calculate the horizontal and vertical display range values. + h_span *= 10; if (env->disp.w > 560) { // 640 pixels - mode |= 3; - offset = 620; - span = env->screen.w * 4; + mode |= 3 << 0; + //h_span *= 4; } else if (env->disp.w > 400) { // 512 pixels - mode |= 2; - offset = 615; - span = env->screen.w * 4 + env->screen.w; + mode |= 2 << 0; + //h_span *= 5; } else if (env->disp.w > 352) { - // 384 pixels (this mode is weird) - mode |= 1 << 6; - offset = 539; - span = env->screen.w * 8 - env->screen.w; - default_span = 2688; + // 368 pixels + mode |= 1 << 6; + //h_span *= 7; } else if (env->disp.w > 280) { // 320 pixels - mode |= 1; - offset = 600; - span = env->screen.w * 8; + mode |= 1 << 0; + //h_span *= 8; } else { // 256 pixels - offset = 590; - span = env->screen.w * 8 + env->screen.w * 2; + mode |= 0 << 0; + //h_span *= 10; } - offset += env->screen.x * 4; - if (!span) - span = default_span; - - h_range = offset & 0xfff; - h_range |= ((offset + span) & 0xfff) << 12; - - // Calculate the vertical display range values. - offset = 16 + env->screen.y; - span = env->screen.h ? env->screen.h : 240; + if (env->disp.h > 256) { + mode |= 1 << 2; + //v_span /= 2; + } - v_range = offset & 0x3ff; - v_range |= ((offset + span) & 0x3ff) << 10; + int x = env->screen.x + 0x760; + int y = env->screen.y + (_gpu_video_mode ? 0xa3 : 0x88); + h_span /= 2; + v_span /= 2; - fb_pos = env->disp.x & 0x3ff; - fb_pos |= (env->disp.y & 0x1ff) << 10; + fb_pos = (env->disp.x & 0x3ff); + fb_pos |= (env->disp.y & 0x1ff) << 10; + h_range = ((x - h_span) & 0xfff); + h_range |= ((x + h_span) & 0xfff) << 12; + v_range = ((y - v_span) & 0x3ff); + v_range |= ((y + v_span) & 0x3ff) << 10; + GPU_GP1 = 0x05000000 | fb_pos; // Set VRAM location to display GPU_GP1 = 0x06000000 | h_range; // Set horizontal display range GPU_GP1 = 0x07000000 | v_range; // Set vertical display range GPU_GP1 = 0x08000000 | mode; // Set video mode - GPU_GP1 = 0x05000000 | fb_pos; // Set VRAM location to display } /* Deprecated "raw" display API */ |
