Skip to content

OpenBIOS: Add ZN-1 support (and lay the groundwork for ZN-2 support)#1987

Open
spicyjpeg wants to merge 3 commits intogrumpycoders:mainfrom
spicyjpeg:openbios-zn
Open

OpenBIOS: Add ZN-1 support (and lay the groundwork for ZN-2 support)#1987
spicyjpeg wants to merge 3 commits intogrumpycoders:mainfrom
spicyjpeg:openbios-zn

Conversation

@spicyjpeg
Copy link
Contributor

This PR adds preliminary support for Sony's ZN-1 arcade PCB to OpenBIOS. Support is currently limited to booting an executable embedded in the ROM; the game-specific security and program ROM bootstrap code present in Sony's ZN BIOSes has not been reimplemented.

As with the System 573 port, the bulk of the changes is in the entry point (boot/zn.s), which has been modified with the appropriate bus configuration values as well as some additional logic to correctly set up main RAM depending on the board revision. The setMemSize() API call has been expanded to support 4 and 16 MB RAM, reflecting the implementation found in the ZN and System 573 kernels. The previously missing getSystemInfo() function has been added as well, returning the correct main RAM, VRAM and SPU RAM sizes for all currently supported boards.

The build has so far been tested and confirmed to work on a ZN-1 board but not on a ZN-2, for which more investigation is required. The getSystemInfo() implementation has not been tested but it is trivial enough that there should be no bugs in it (no software is currently known to use it anyway).

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 17, 2026

📝 Walkthrough

Walkthrough

This PR adds OpenBIOS support for the ZN arcade board variant, including hardware register definitions, a dedicated MIPS boot routine, board-specific kernel functions for system information retrieval, and build system modifications for conditional ZN/system573 compilation.

Changes

Cohort / File(s) Summary
Hardware Register Definitions
src/mips/common/hardware/hwregs.h, src/mips/common/hardware/hwregs.inc
Added four new ZN board hardware register macros: ZN_BOARD_CONFIG, ZN_SIO0_MUX, ZN_COIN_CTRL, ZN_IRQ10_MUX with corresponding hex addresses.
Build System & Documentation
src/mips/openbios/Makefile, src/mips/openbios/README.md
Reworked board-based conditional logic to support both system573 and zn builds with per-board CPPFLAGS definitions. Updated documentation with ZN board option details and startup references.
Boot Assembly Routines
src/mips/openbios/boot/psx.s, src/mips/openbios/boot/system573.s, src/mips/openbios/boot/zn.s
Enhanced psx.s with explicit RAM size initialization. Reworked system573.s with board revision probing for dynamic RAM size detection. Added complete new zn.s boot routine with RAM configuration tables, hardware initialization, and startup sequence.
Kernel & System Information
src/mips/openbios/kernel/handlers.c, src/mips/openbios/kernel/misc.c, src/mips/openbios/kernel/misc.h
Updated BIOS A0 function table entry at offset b4 to call getSystemInfo. Introduced board-specific kernel metadata, new getSystemInfo(int index) function supporting multiple system parameters, and extended setMemSize() to handle 2/4/8/16 MB configurations.
Main Initialization
src/mips/openbios/main/main.c, src/mips/openbios/main/main.h
Removed hardcoded RAM size assignment in main. Added clearZNRegisters() helper for ZN-specific register cleanup and printBoardConfiguration() for board config logging. Updated boot flow to call bootThunk() and incorporate board-specific initialization steps.

Sequence Diagrams

sequenceDiagram
    participant Boot as Boot Routine<br/>(zn.s)
    participant HW as Hardware<br/>(Registers)
    participant RAM as Memory Controller<br/>(DRAM Config)
    participant Kernel as Kernel<br/>(misc.c)
    participant Main as Main Init<br/>(main.c)

    Boot->>HW: Write PSX bus config
    Boot->>RAM: Probe ZN_RAM_CONFIGS
    Boot->>RAM: Read board revision
    Boot->>RAM: Set DRAM controller
    Boot->>Boot: Clear registers & cop0/cop2
    Boot->>Boot: Copy data segment
    Boot->>Boot: Initialize BSS
    Boot->>Kernel: Call _ucsdk_start()
    
    Kernel->>HW: Query ZN_BOARD_CONFIG
    Kernel->>Kernel: Store __globals60.ramsize
    
    Main->>Main: clearZNRegisters()
    Main->>Main: printBoardConfiguration()
    Main->>HW: Write 0x0A to 0x1f802080
    Main->>Main: Enter stop loop
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Suggested reviewers

  • nicolasnoble

Poem

🐰 Whiskers twitch with ZN delight,
New boards boot with MIPS code bright!
Hardware configs dance and sway,
RAM probes configured just the way—
Another arcade joins the fold, hooray! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the primary change: adding ZN-1 support to OpenBIOS with groundwork for ZN-2, which aligns with the substantial changes across boot configuration, kernel functions, and hardware register definitions throughout the changeset.
Description check ✅ Passed The description is directly related to the changeset, providing context for ZN-1 support implementation, explaining the ROM-only boot capability, setMemSize() expansion, and getSystemInfo() implementation that are all reflected in the file changes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (3)
src/mips/openbios/kernel/misc.c (2)

68-96: Missing case 8 and case 10/case 11 — intentional gaps?

The switch jumps from case 7 (VRAM size) to case 9 (SPU RAM size), and from case 9 to case 12/13. If this mirrors the original Sony kernel's behavior, a brief comment noting these indices are intentionally undefined (return 0) would help future readers.

The static analysis flagged cyclomatic complexity of 14 (threshold 9), but this is a flat lookup table — restructuring wouldn't improve clarity.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/mips/openbios/kernel/misc.c` around lines 68 - 96, The getSystemInfo
switch omits case 8 and cases 10/11 which look like intentional undefined
indices; update the getSystemInfo function to document this by adding a concise
comment above the switch (or inline near the gaps) stating that indices 8, 10
and 11 are intentionally undefined and return 0 to mirror the original Sony
kernel behavior, and optionally add explicit case labels (case 8: case 10: case
11:) that return 0 to make the intent clear; reference the getSystemInfo
function and related symbols like s_kernelFlags, s_unknownFlag, getVRAMSize and
getSPURAMSize when locating where to add the comment or explicit cases.

42-50: ZN-2: s_kernelFlags is hardcoded to the ZN-1 value.

Line 44 hardcodes s_kernelFlags = 0x11001 (ZN-1) while the comment notes ZN-2 should be 0x13000. Since the board config register is already read at runtime for revision/VRAM/SPU, consider deriving s_kernelFlags from ZN_BOARD_CONFIG as well (e.g., checking the board revision) so this doesn't become a latent bug when ZN-2 testing begins.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/mips/openbios/kernel/misc.c` around lines 42 - 50, s_kernelFlags is
hardcoded to the ZN-1 value (0x11001) but should reflect ZN-2 (0x13000) when the
board revision indicates ZN-2; change s_kernelFlags to be derived at runtime
(either compute it in an init path or replace the const with a getter) using the
existing ZN_BOARD_CONFIG parsing (reuse getBoardRevision() or the same
((ZN_BOARD_CONFIG >> 5) & 7) - 2 expression) and return 0x11001 for ZN-1 and
0x13000 for ZN-2 so all consumers of s_kernelFlags observe the correct value for
the detected board.
src/mips/openbios/main/main.c (1)

298-311: Intentional "Borad" typo and original-BIOS-faithful output — looks good.

The comment on lines 298–301 makes the intent clear. One small note: revision - 2 on line 308 can produce negative values when bits [7:5] of ZN_BOARD_CONFIG are 0 or 1. If this matches the original BIOS behavior, it's fine, but worth a brief inline comment to prevent a future contributor from "fixing" it.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/mips/openbios/main/main.c` around lines 298 - 311, The calculation
"revision - 2" in printBoardConfiguration can produce negative values for low
ZN_BOARD_CONFIG revision bits; add a brief inline comment next to the expression
(or near the computation of revision) stating that the subtraction is
intentional to match original BIOS behavior and may yield negative values so
future contributors do not "fix" it; reference the revision variable, the
subtraction (revision - 2), ZN_BOARD_CONFIG and the psxprintf call so the
comment is clearly colocated with the logic in printBoardConfiguration.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/mips/openbios/kernel/misc.c`:
- Around line 68-96: The getSystemInfo switch omits case 8 and cases 10/11 which
look like intentional undefined indices; update the getSystemInfo function to
document this by adding a concise comment above the switch (or inline near the
gaps) stating that indices 8, 10 and 11 are intentionally undefined and return 0
to mirror the original Sony kernel behavior, and optionally add explicit case
labels (case 8: case 10: case 11:) that return 0 to make the intent clear;
reference the getSystemInfo function and related symbols like s_kernelFlags,
s_unknownFlag, getVRAMSize and getSPURAMSize when locating where to add the
comment or explicit cases.
- Around line 42-50: s_kernelFlags is hardcoded to the ZN-1 value (0x11001) but
should reflect ZN-2 (0x13000) when the board revision indicates ZN-2; change
s_kernelFlags to be derived at runtime (either compute it in an init path or
replace the const with a getter) using the existing ZN_BOARD_CONFIG parsing
(reuse getBoardRevision() or the same ((ZN_BOARD_CONFIG >> 5) & 7) - 2
expression) and return 0x11001 for ZN-1 and 0x13000 for ZN-2 so all consumers of
s_kernelFlags observe the correct value for the detected board.

In `@src/mips/openbios/main/main.c`:
- Around line 298-311: The calculation "revision - 2" in printBoardConfiguration
can produce negative values for low ZN_BOARD_CONFIG revision bits; add a brief
inline comment next to the expression (or near the computation of revision)
stating that the subtraction is intentional to match original BIOS behavior and
may yield negative values so future contributors do not "fix" it; reference the
revision variable, the subtraction (revision - 2), ZN_BOARD_CONFIG and the
psxprintf call so the comment is clearly colocated with the logic in
printBoardConfiguration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant