From 3b05396300d39e7abfbee40e472a7f707866fe7f Mon Sep 17 00:00:00 2001 From: Thomas Martin <304581853+boubou666@users.noreply.github.com> Date: Fri, 27 Nov 2026 00:36:29 +0100 Subject: [PATCH] Widescreen in 1P/2P matches, and QUIT GAME in PC SETTINGS Widescreen (runtime/tmb_widescreen.cpp; off by default: Video's Widescreen in F2 or PC SETTINGS, video.ini `widescreen`, PS2X_WIDESCREEN): at each match frame's end, when every view is the screen's full width (one player, or two one above the other), each view's width goes from 640 to 853 about the same centre and the game's own viewTweakSetFov (0x1FDEA0) rebuilds its frustum planes and projection from it, on a copy of the context. The game then culls, projects and clips a scene 4/3 as wide with the same focal length: more at the sides, nothing stretched. The 3D screen (tmb_native.cpp) and the 2D overlay follow the views' width, so the HUD keeps its shape; the window shows 16:9 (BozoEngine's setPictureAspect) while a view is wide. The menus, the pause dialog and the next level make their views again at 640 (viewCreate), so they stay 4:3; three- and four-player splits stay 4:3; the loading bar and movie pictures are drawn centred. QUIT GAME at the bottom of PC SETTINGS' first page: Cross shows "PRESS X AGAIN", a second Cross ends the game (the host's stop; the window closes), Back or a move disarms it. BozoEngine at master e2dff55 (#154: video::Settings::widescreen, offerWidescreen, setPictureAspect; #153 libmpeg's demux in runs). Checked: the 11 native suites pass; the 1P (9,500) and 4P (8,500) replays match main 89d5306 on every recorded field, RAM image and sound; the pinned boot and match1p checks match. Hidden window runs with widescreen on: 1P matches at 16:9 (cars, rain and target markers to the edges, the radar round), the menus 4:3, a 4P split 4:3, the pause screen as without it; QUIT GAME ended the game at the second Cross. Co-Authored-By: Claude Opus 5.5 --- BozoEngine | 2 +- CHANGELOG.md | 5 ++ README.md | 10 +++- bozo/tmb_window.cpp | 4 ++ runtime/tmb_2d.cpp | 13 +++-- runtime/tmb_menu.cpp | 32 ++++++++++- runtime/tmb_menu.h | 7 +++ runtime/tmb_native.cpp | 8 +++ runtime/tmb_overrides.cpp | 7 +++ runtime/tmb_widescreen.cpp | 114 +++++++++++++++++++++++++++++++++++++ 10 files changed, 193 insertions(+), 9 deletions(-) create mode 100644 runtime/tmb_widescreen.cpp diff --git a/BozoEngine b/BozoEngine index 5d34d41..e2dff55 160000 --- a/BozoEngine +++ b/BozoEngine @@ -1 +1 @@ -Subproject commit 5d34d4142235d537406dd3e4063a8e5f8a159078 +Subproject commit e2dff552bdc0a55a922394f21e0fd7dffe851489 diff --git a/CHANGELOG.md b/CHANGELOG.md index 910f0e7..0aa753c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,11 @@ under "Unreleased" as they land, then move them under the new version's heading AND SAVE writes `video.ini`), **Cheats** (unlock everything, infinite health / ammo / energy, no AI, weak enemies; at once) and **Save states** (the slot, LOAD, SAVE, as F5 / F7). Triangle or Circle goes back. The controls stay in F2. +- **QUIT GAME** at the bottom of PC SETTINGS: Cross, then Cross again, ends the game and closes the window. +- **Widescreen (16:9)**, off by default: in F2's Video tab, PC SETTINGS → Video, or `widescreen = on` in `video.ini` + (`PS2X_WIDESCREEN=1`). In one-player and two-player matches the game draws a 16:9 picture: it shows more at the + sides (its own views made wider, culling and all), nothing is stretched, and the HUD keeps its shape. The menus, + movies and loading screens stay 4:3, centred, and three- and four-player split screens stay 4:3. ## [0.6.0] - 2026-11-11 diff --git a/README.md b/README.md index 24c2a3b..dde5e53 100644 --- a/README.md +++ b/README.md @@ -114,6 +114,7 @@ those comparisons from actual native play. [docs/RECOMP_NOTES.md](docs/RECOMP_NO | Multi-player split-screen, 2 to 4 players; frame-keyed scripts for unattended checks | ✅ | | Settings (F2): controls, video, cheats; windowed / fullscreen / borderless | ✅ | | PC SETTINGS in the game's Options screen: video, cheats and save states with the pad | ✅ | +| Widescreen 16:9 in one- and two-player matches (more at the sides, HUD unstretched; menus stay 4:3) | ✅ | | Save states (F5 save, F7 load, ten slots; `--save-state` / `--load-state` for scripted runs) | ✅ | | Higher internal resolution (2× by default; Video's render scale) | ✅ | | Interpolated presentation above 60 Hz; rain, snow, flares and some trails still update at game rate | 🧪 | @@ -402,7 +403,7 @@ use physical US positions: | Key | What it does | |---|---| -| F2 | Settings: Controls (per-player buttons, sticks, triggers, mouse and sensitivity), Video (resolution, window mode, render scale, presentation frame rate and texture upscaling), Cheats. Controls save to `input.ini`; video saves to `video.ini`. | +| F2 | Settings: Controls (per-player buttons, sticks, triggers, mouse and sensitivity), Video (resolution, window mode, render scale, presentation frame rate, texture upscaling and widescreen), Cheats. Controls save to `input.ini`; video saves to `video.ini`. | | F3 | Toggle the frame-rate counter. | | F5 / F7 | Save / load a save state in the current slot (`states/slot.state` in the user folder). A state loads only into the build that wrote it; a save waits while a movie plays. | | F6, Shift+F6 | Next / previous save-state slot (0-9); F2 → Save states lists them. | @@ -412,7 +413,12 @@ use physical US positions: In the game, **Options → PC SETTINGS** (the last line, under the memory card lines) has the same Video, Cheats and Save states with the pad: Up / Down to choose, Left / Right to change, Cross to open or act (Video's APPLY AND SAVE, -Save states' LOAD and SAVE), Triangle or Circle to go back. The controls are rebound in F2. +Save states' LOAD and SAVE), Triangle or Circle to go back. The controls are rebound in F2. **QUIT GAME** at the +bottom of PC SETTINGS closes the game (press Cross twice). + +**Widescreen** (Video: Widescreen, off by default; `widescreen = on` in `video.ini`, `PS2X_WIDESCREEN=1`): one- and +two-player matches are drawn 16:9, showing more at the sides with nothing stretched. Menus, movies, loading screens +and three- or four-player split screens stay 4:3. The picture stays 4:3 inside the window. Video can present at game rate, a fixed higher rate, or the monitor's rate with interpolation; the game itself keeps its 60 Hz timing. Interpolation adds about one game frame of latency and diff --git a/bozo/tmb_window.cpp b/bozo/tmb_window.cpp index ae8e38a..4a97828 100644 --- a/bozo/tmb_window.cpp +++ b/bozo/tmb_window.cpp @@ -293,6 +293,10 @@ int main(int argc, char **argv) host.requestLoad(bozo::app::stateSlotPath(slot)); return true; }; + menuHooks.quit = [&] { host.requestStop(); }; + menuHooks.widescreen = [] { return bozo::app::video::shared().applied.widescreen; }; + menuHooks.setPictureAspect = [](float aspect) { bozo::app::setPictureAspect(aspect); }; + bozo::app::video::offerWidescreen(true); // runtime/tmb_widescreen.cpp tmb::menu::setHooks(std::move(menuHooks)); return bozo::app::runWindow(window, game, &pad); } diff --git a/runtime/tmb_2d.cpp b/runtime/tmb_2d.cpp index e2caec9..4c8465e 100644 --- a/runtime/tmb_2d.cpp +++ b/runtime/tmb_2d.cpp @@ -30,6 +30,11 @@ namespace tmb::native bool enabled(); } +namespace tmb::widescreen +{ + float screenWidth(); +} + namespace tmb::textures { std::shared_ptr font(); @@ -752,7 +757,7 @@ namespace tmb::twod const uint32_t def = word(rdram, kViews + 4u); const float width = half(rdram, def + 8u), height = half(rdram, def + 0xau); bozo::render::Screen screen; - screen.width = width > 0.0f ? width : 640.0f; + screen.width = std::max(width > 0.0f ? width : 640.0f, tmb::widescreen::screenWidth()); // widescreen: the bar centred screen.height = height > 0.0f ? height : 448.0f; screen.originX = 2048.0f - screen.width * 0.5f; screen.originY = 2048.0f - screen.height * 0.5f; @@ -902,13 +907,13 @@ namespace tmb::twod return false; constexpr float kFrameHeight = 448.0f; bozo::render::Screen screen; - screen.originX = 2048.0f - 320.0f; + screen.width = tmb::widescreen::screenWidth(); // widescreen: the picture centred in its 640 + screen.originX = 2048.0f - screen.width * 0.5f; screen.originY = 2048.0f - kFrameHeight * 0.5f; - screen.width = 640.0f; screen.height = kFrameHeight; const float width = static_cast(picture->width), height = static_cast(picture->height); if (!tmb::native::menusDrawn()) - bozo::render::Renderer::instance().setBackdrop(std::move(picture), screen, screen.originX + (640.0f - width) * 0.5f, + bozo::render::Renderer::instance().setBackdrop(std::move(picture), screen, 2048.0f - 320.0f + (640.0f - width) * 0.5f, screen.originY + (kFrameHeight - height) * 0.5f, width, height); return true; } diff --git a/runtime/tmb_menu.cpp b/runtime/tmb_menu.cpp index 3c9e7e3..15b43c9 100644 --- a/runtime/tmb_menu.cpp +++ b/runtime/tmb_menu.cpp @@ -1,7 +1,8 @@ // PC SETTINGS in the game's own Options screen: a ninth line under the game's eight, and behind it pages drawn with the // game's font and steered with the pad, for what the settings window (F2) offers besides the controls: Video (the -// window's settings, applied and saved to video.ini), Cheats (runtime/tmb_cheats.cpp's switches, at once) and Save -// states (the slot, load, save). The controls stay in F2. +// window's settings, applied and saved to video.ini; widescreen: runtime/tmb_widescreen.cpp), Cheats +// (runtime/tmb_cheats.cpp's switches, at once) and Save states (the slot, load, save), and QUIT GAME (a second Cross +// ends the game). The controls stay in F2. // // The Options screen (uiOptions, 0x1911F0, screen 10 of uiMain's table; one call a frame), from its code: // - Its cursor is options_main_line (0x4FB2F4), 0 to 7 (DIFFICULTY ... SAVE SETTINGS TO MEMORY CARD); options_subScreen @@ -202,6 +203,7 @@ namespace tmb::menu std::vector> resolutions; int monitorRefresh = 0; std::string status; // a line under the page: what Cross did + bool quitArmed = false; // QUIT GAME pressed once: a second Cross quits } g_menu; std::string upper(std::string s) @@ -279,6 +281,7 @@ namespace tmb::menu VUpscale, VFilter, VPack, + VWide, VPause, VFast, VApply, @@ -300,6 +303,7 @@ namespace tmb::menu rows[VFilter] = {"UPSCALING FILTER", v.textureUpscale.filter == bozo::render::UpscaleFilter::Smooth ? "SMOOTH" : "EDGE"}; const bool pack = h.texturePackFolder && !h.texturePackFolder(packOn(v.texturePack) ? v.texturePack : "").empty(); rows[VPack] = {"TEXTURE PACK", pack ? onOff(packOn(v.texturePack)) : "NONE"}; + rows[VWide] = {"WIDESCREEN", onOff(v.widescreen)}; rows[VPause] = {"PAUSE IN BACKGROUND", onOff(v.pauseInBackground)}; rows[VFast] = {"FAST FORWARD", v.fastForward == 0 ? "UNLIMITED" : timesText(v.fastForward / 100)}; rows[VApply] = {"APPLY AND SAVE", ""}; @@ -353,6 +357,7 @@ namespace tmb::menu v.texturePack = packOn(v.texturePack) ? "off" : s_lastOn; return true; } + case VWide: v.widescreen = !v.widescreen; return true; case VPause: v.pauseInBackground = !v.pauseInBackground; return true; case VFast: v.fastForward = step(kFastForwards, v.fastForward, delta); return true; default: return false; @@ -479,6 +484,8 @@ namespace tmb::menu std::vector rows; for (const Page p : topPages(h)) rows.push_back({pageName(p), ""}); + if (h.quit) + rows.push_back({m.quitArmed ? "QUIT GAME: PRESS X AGAIN" : "QUIT GAME", ""}); return rows; } case Page::Video: return videoRows(m, h); @@ -505,6 +512,7 @@ namespace tmb::menu m.page = page; m.line = 0; m.status.clear(); + m.quitArmed = false; if (page == Page::Video && h.videoShared) { const bozo::app::video::Shared s = h.videoShared(); @@ -528,6 +536,13 @@ namespace tmb::menu if (pressed(kTriangle) || pressed(kCircle)) { + if (m.quitArmed) + { + m.quitArmed = false; // Back only disarms QUIT GAME + g.sound(kSoundBack); + rows = rowsOf(m, h); + goto draw; + } g.sound(kSoundBack); if (m.page == Page::Top) { @@ -543,6 +558,7 @@ namespace tmb::menu else if (pressed(kUp) || pressed(kDown)) { m.line = nextLine(rows, m.line, pressed(kUp) ? -1 : 1); + m.quitArmed = false; g.sound(pressed(kUp) ? kSoundUp : kSoundDown); m.status.clear(); } @@ -577,6 +593,15 @@ namespace tmb::menu open(m, pages[static_cast(m.line)], h); rows = rowsOf(m, h); } + else if (h.quit && m.line == static_cast(pages.size())) + { + // QUIT GAME: a second Cross ends the game (the window closes, as closing it does). + g.sound(kSoundAccept); + if (m.quitArmed) + h.quit(); + m.quitArmed = !m.quitArmed; + rows = rowsOf(m, h); + } } else if (m.page == Page::Video && m.line == VApply && h.videoApply) { @@ -602,6 +627,7 @@ namespace tmb::menu } } + draw: // The page's sliders hidden, as the game's controls page hides them (uiOptions shows them again on its page). g.call(&blankSliders__Fi_0x19de38, kBlankSliders, {0u}); // Drawn: the title, then each line (the selected one larger and brighter, as the game's), its value to the right. @@ -700,6 +726,8 @@ namespace tmb::menu } } + Hooks currentHooks() { return hooks(); } + void setHooks(Hooks h) { std::lock_guard lock(g_hooksMutex); diff --git a/runtime/tmb_menu.h b/runtime/tmb_menu.h index 5610b11..1498b4a 100644 --- a/runtime/tmb_menu.h +++ b/runtime/tmb_menu.h @@ -23,8 +23,15 @@ namespace tmb::menu std::function setStateSlot; std::function slotSummary; std::function saveState, loadState; + // Ends the game (the window closes): QUIT GAME, confirmed by a second Cross. + std::function quit; + // Widescreen (runtime/tmb_widescreen.cpp): the setting applied now, and the window's picture shape (0 the + // default 4:3, 16:9 while a view is wide). + std::function widescreen; + std::function setPictureAspect; }; void setHooks(Hooks hooks); + Hooks currentHooks(); // A save state was loaded: the pages close (what they showed is gone). void stateLoaded(); diff --git a/runtime/tmb_native.cpp b/runtime/tmb_native.cpp index 9c4a5b0..7a549c2 100644 --- a/runtime/tmb_native.cpp +++ b/runtime/tmb_native.cpp @@ -22,6 +22,11 @@ #include #include +namespace tmb::widescreen +{ + float screenWidth(); +} + namespace tmb::twod { void publish(); @@ -112,6 +117,9 @@ namespace tmb::native // A match draws fields (the frame's every other line), the shell's menus whole frames. const float lines = menusNative() ? 2.0f : 1.0f; screen.originY = 2048.0f - 112.0f * lines; // NTSC: a 640 x 224 field + // Widescreen: the views 853 wide about the same centre (runtime/tmb_widescreen.cpp). + screen.width = tmb::widescreen::screenWidth(); + screen.originX = 2048.0f - screen.width * 0.5f; screen.height = 224.0f * lines; // GS Z is z / w itself (the microprograms write FTOI4 of z / w into XYZF2's 24-bit Z, that word over 16). screen.gsZScale = 1.0f; diff --git a/runtime/tmb_overrides.cpp b/runtime/tmb_overrides.cpp index 3a27256..ce86b7e 100644 --- a/runtime/tmb_overrides.cpp +++ b/runtime/tmb_overrides.cpp @@ -61,6 +61,11 @@ namespace tmb::menu void install(tmb::Registry &runtime); } +namespace tmb::widescreen +{ + void update(uint8_t *rdram, R5900Context *ctx, PS2Runtime *runtime, bool match); +} + namespace tmb::meshes { void install(tmb::Registry &runtime); @@ -501,6 +506,7 @@ namespace g_lastMatchFrameNoted.store(hitchClock(), std::memory_order_relaxed); tmb::cheats::onFrame(rdram); // the Cheats tab (runtime/tmb_cheats.cpp) const uint32_t gp = getRegU32(ctx, 28); + tmb::widescreen::update(rdram, ctx, runtime, true); // widescreen: the match's views (runtime/tmb_widescreen.cpp) tmb::native::onFrameEnd(); // TMB_NATIVE: publish the frame's native draws timerEndOfRealTimeProcessing__Fv_0x1f67f0(rdram, ctx, runtime); int32_t *frameTicks = reinterpret_cast(rdram + ((gp + kFrameTicksGpOffset) & 0x1FFFFFFu)); @@ -550,6 +556,7 @@ namespace { g_pacer.setCap(static_cast(fieldRate(rdram, gp))); g_pacer.setPaced(bozo::port::realTime(runtime)); // a headless or checked run is not held to real time + tmb::widescreen::update(rdram, ctx, runtime, false); // the window's picture shape as the views are now tmb::native::onMenuFrameEnd(); // TMB_NATIVE: publishes a menu frame's native draws (not in a match) const double step = g_pacer.frameEnd(); tmb::cheats::logProgress(rdram, gp); // TMB_LOG_PROGRESS diff --git a/runtime/tmb_widescreen.cpp b/runtime/tmb_widescreen.cpp new file mode 100644 index 0000000..198c861 --- /dev/null +++ b/runtime/tmb_widescreen.cpp @@ -0,0 +1,114 @@ +// Widescreen (the Video settings' widescreen, video.ini): in a match whose views are each the screen's full width (one +// player, or two players one above the other), the game is made to draw a 16:9 picture. Each view's width goes from +// 640 to 853 pixels about the same centre, then the game's own viewTweakSetFov (0x1FDEA0: viewSetFov for every view, +// with its horizontal FOV and the view's definition) rebuilds the frustum planes it culls with and the projection it +// clips with from that width. The game then projects, culls and clips a scene 4/3 as wide with the same focal length: +// more at the sides, nothing stretched. The 3D screen (tmb_native.cpp) and the 2D overlay (the views' union, +// tmb_2d.cpp) follow the views' width; the HUD, drawn about the screen's centre in its 640 pixels, stays in the middle; +// the window shows a 16:9 picture (bozo::app::setPictureAspect, through the menu's hooks) while a view is wide. +// +// The views, from the game's code: viewNumViews (0x4FBC44) views, each a 16-byte record at 0x4DFCD0 whose word +4 is +// its viewport (viewGetWH: width u16 +4, height +6; viewSetFov's planes and projection from them). viewCreate makes +// them again at each screen's start (the menus get theirs back at 640), so only a match frame's end widens them, and +// one ends them narrow again when widescreen is switched off or the layout is split in four. +// +// Off (the default) or in the headless program (no hooks), nothing changes: replays and the reference check are the +// game's own picture. + +#include "tmb_port.h" +#include "tmb_menu.h" + +#include +#include +#include + +namespace tmb::widescreen +{ + namespace + { + constexpr uint32_t kViews = 0x004DFCD0u, kNumViews = 0x004FBC44u, kViewTweakSetFov = 0x001FDEA0u; + constexpr uint16_t kNarrow = 640, kWide = 853; // 640 * 4 / 3 + constexpr float kWideAspect = 16.0f / 9.0f; + + std::atomic g_wide{false}; + float g_aspectSet = -1.0f; + + uint32_t word(const uint8_t *rdram, uint32_t address) + { + uint32_t value; + std::memcpy(&value, rdram + (address & 0x1FFFFFCu), 4); + return value; + } + uint16_t half(const uint8_t *rdram, uint32_t address) + { + uint16_t value; + std::memcpy(&value, rdram + (address & 0x1FFFFFEu), 2); + return value; + } + void setHalf(uint8_t *rdram, uint32_t address, uint16_t value) { std::memcpy(rdram + (address & 0x1FFFFFEu), &value, 2); } + + // The view's viewport (0 none). + uint32_t viewport(const uint8_t *rdram, uint32_t view) + { + const uint32_t v = word(rdram, kViews + view * 16u + 4u); + return v >= 0x100000u && v < 0x2000000u ? v : 0u; + } + } + + bool wide() { return g_wide.load(std::memory_order_relaxed); } + float screenWidth() { return wide() ? kNarrow * 4.0f / 3.0f : static_cast(kNarrow); } + + // At a frame's end: in a match (`match`), the views widened or narrowed as the setting and the layout want; at + // every frame end, whether a view is wide now and the window's picture shaped to it. + void update(uint8_t *rdram, R5900Context *ctx, PS2Runtime *runtime, bool match) + { + if (!bozo::port::nativeGraphics(runtime)) + return; + const tmb::menu::Hooks h = tmb::menu::currentHooks(); + if (!h.setPictureAspect) + return; // the headless program: no window, no widescreen + const uint32_t count = std::min(word(rdram, kNumViews), 4u); + if (match) + { + bool fullWidth = count > 0u; + for (uint32_t i = 0; i < count; ++i) + { + const uint32_t vp = viewport(rdram, i); + const uint16_t w = vp ? half(rdram, vp + 4u) : 0; + fullWidth = fullWidth && (w == kNarrow || w == kWide); + } + const bool want = fullWidth && h.widescreen && h.widescreen(); + bool changed = false; + for (uint32_t i = 0; i < count; ++i) + if (const uint32_t vp = viewport(rdram, i)) + { + const uint16_t w = half(rdram, vp + 4u); + if (want && w == kNarrow) + setHalf(rdram, vp + 4u, kWide), changed = true; + else if (!want && w == kWide) + setHalf(rdram, vp + 4u, kNarrow), changed = true; + } + if (changed) + { + // The game's own rebuild of every view's frustum and projection, on a copy of the context (guest code + // there never leaves the override: BozoEngine kernel.md section 3b), its stack below the thread's. + R5900Context copy = *ctx; + SET_GPR_U32(©, 29, (getRegU32(ctx, 29) - 0x200u) & ~0xFu); + copy.leaving = 0; + copy.pc = kViewTweakSetFov; + viewTweakSetFov__Fv_0x1fdea0(rdram, ©, runtime); + } + } + bool anyWide = false; + for (uint32_t i = 0; i < count; ++i) + if (const uint32_t vp = viewport(rdram, i)) + anyWide = anyWide || half(rdram, vp + 4u) == kWide; + g_wide.store(anyWide, std::memory_order_relaxed); + const float aspect = anyWide ? kWideAspect : 0.0f; + if (aspect != g_aspectSet) + { + g_aspectSet = aspect; + h.setPictureAspect(aspect); + } + } +}