Skip to content

VS Code extension: fix/update templates based on ps1-bare-metal#1970

Open
spicyjpeg wants to merge 4 commits intogrumpycoders:mainfrom
spicyjpeg:vscode-template-update
Open

VS Code extension: fix/update templates based on ps1-bare-metal#1970
spicyjpeg wants to merge 4 commits intogrumpycoders:mainfrom
spicyjpeg:vscode-template-update

Conversation

@spicyjpeg
Copy link
Copy Markdown
Contributor

Quick fixes for the empty-cmake and cmake-cube templates provided by the PSX.Dev VS Code extension, which no longer compiled due to some minor but breaking changes in the ps1-bare-metal repository they depend on. I haven't bothered to bump the extension's version number as I already did that as part of #1948, which is still unmerged.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Oct 11, 2025

📝 Walkthrough

Walkthrough

Templates switch from manual CMake executable/post-build steps to toolchain macros (e.g., addPS1Executable/addBinaryFile), and GPU/DMA APIs are renamed and refactored (DMAChain → GPUDMAChain), with accompanying updates to GPU init, packet allocation, texture upload, and font rendering.

Changes

Cohort / File(s) Summary
Build templates
tools/vscode-extension/templates/bare-metal/cmake-cube/CMakeLists.txt, tools/vscode-extension/templates/bare-metal/empty-cmake/CMakeLists.txt
Replace manual add_executable/target_link_libraries/add_custom_command with addPS1Executable macro and tools-based includes. Update common OBJECT library sources (add clz.s, string.s, ps1/cache.s; remove memset.s, misc.s) and add link_libraries(common).
Main app
tools/vscode-extension/templates/bare-metal/cmake-cube/src/main.c
Rename fixed-point/unit constants and GTE control (ONEGTE_UNIT, COP0 SR→COP0_STATUS_*), switch DMA/GPU usage to GPUDMAChain APIs, cast GTE register reads to signed, adjust ordering-table sizing to GPU_ORDERING_TABLE_SIZE, and update on-screen text.
GPU core
tools/vscode-extension/templates/bare-metal/cmake-cube/src/gpu.h, .../src/gpu.c
Rename typedef/consts (DMAChainGPUDMAChain, CHAIN_BUFFER_SIZEGPU_CHAIN_BUFFER_SIZE, ORDERING_TABLE_SIZEGPU_ORDERING_TABLE_SIZE). Rename APIs (waitForDMADonewaitForGPUDMADone, sendLinkedListsendGPULinkedList, allocatePacketallocateGP0Packet). Add DMA initialization in GPU setup, update VRAM length math, introduce GP0 packet allocator assertions, and flush GP0 cache after uploads.
Font rendering
tools/vscode-extension/templates/bare-metal/cmake-cube/src/font.h, .../src/font.c
Change printString to accept GPUDMAChain*. Switch allocations to allocateGP0Packet, replace gp0_texpage with gp0_setPage, and adjust packet sizes and comments to match GP0 flow.
Build artifacts / libc sources
tools/vscode-extension/templates/bare-metal/*/ps1-bare-metal/src/libc/*, .../src/ps1/cache.s, .../src/vendor/printf.c
Recompose common sources: add clz.s, string.s, ps1/cache.s, include setjmp.s, string.c, vendor/printf.c; remove memset.s, misc.s.
Misc / formatting
tools/vscode-extension/templates/bare-metal/cmake-cube/src/trig.c
Minor whitespace/formatting adjustment to macro alignment (no semantic change).

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant App as Application
    participant GPUDMA as GPUDMAChain
    participant GP0 as GP0 Command Stream
    participant VRAM as VRAM/Video HW

    App->>GPUDMA: allocateGP0Packet(zIndex, numCommands)
    App->>GP0: uploadTexture(image, coords, size)
    GP0->>GP0: gp0_flushCache()
    App->>GP0: gp0_setPage(...)
    App->>GP0: sendGPULinkedList(packet)
    GP0->>VRAM: DMA transfer
    VRAM-->>GPUDMA: notify DMA done
    GPUDMA-->>App: waitForGPUDMADone()
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~40 minutes

Poem

🐰
I hopped through CMake fields so green,
macros sprouted where commands had been,
DMAChain donned a GPUDMA coat,
packets, pages — I proudly tote,
builds compile — a carrot dream!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 6.25% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely identifies the main change: updating VS Code extension templates to fix compatibility issues with ps1-bare-metal dependencies.
Description check ✅ Passed The description is directly related to the changeset, explaining the motivation (breaking changes in ps1-bare-metal) and scope (empty-cmake and cmake-cube templates) of the fixes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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
Copy Markdown
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.

Actionable comments posted: 0

🧹 Nitpick comments (1)
tools/vscode-extension/templates/bare-metal/cmake-cube/src/main.c (1)

195-197: LGTM! Cleaner DMA channel enabling with helper macro.

The consolidated approach using DMA_DPCR_CH_ENABLE() is more maintainable than manual bit shifts. The |= 0 pattern is unconventional but harmless—you could simplify to DMA_DPCR |= DMA_DPCR_CH_ENABLE(DMA_GPU) | DMA_DPCR_CH_ENABLE(DMA_OTC); if preferred.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 718f091 and 7cb57ad.

📒 Files selected for processing (3)
  • tools/vscode-extension/templates/bare-metal/cmake-cube/CMakeLists.txt (1 hunks)
  • tools/vscode-extension/templates/bare-metal/cmake-cube/src/main.c (2 hunks)
  • tools/vscode-extension/templates/bare-metal/empty-cmake/CMakeLists.txt (1 hunks)
🧰 Additional context used
🪛 GitHub Check: CodeScene Code Health Review (main)
tools/vscode-extension/templates/bare-metal/cmake-cube/src/main.c

[warning] 195-197: ❌ Getting worse: Complex Method
main already has high cyclomatic complexity, and now it increases in Lines of Code from 87 to 88. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: macos-intel-build-and-test
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: toolchain
🔇 Additional comments (8)
tools/vscode-extension/templates/bare-metal/cmake-cube/src/main.c (1)

33-33: LGTM! API naming update aligns with ps1-bare-metal.

The change from COP0_SR to COP0_STATUS and COP0_SR_CU2 to COP0_STATUS_CU2 reflects updated naming conventions in the ps1-bare-metal library, improving code clarity.

tools/vscode-extension/templates/bare-metal/empty-cmake/CMakeLists.txt (3)

28-36: LGTM! Library sources updated for ps1-bare-metal compatibility.

The addition of clz.s, string.s, and cache.s alongside the removal of obsolete sources aligns the template with upstream ps1-bare-metal changes.


44-44: LGTM! Default linking simplifies executable configuration.

The link_libraries(common) directive ensures the common library is automatically linked to all executables, reducing boilerplate in subsequent target definitions.


46-50: LGTM! Macro-driven executable creation reduces boilerplate.

The addPS1Executable() macro encapsulates executable creation and PS1 format conversion, eliminating the need for manual add_custom_command post-build steps. This modernizes the build flow and improves maintainability.

tools/vscode-extension/templates/bare-metal/cmake-cube/CMakeLists.txt (4)

28-36: LGTM! Library sources synchronized with ps1-bare-metal.

Identical to the empty-cmake template, these source updates maintain compatibility with upstream ps1-bare-metal changes.


44-44: LGTM! Consistent default linking across templates.

The link_libraries(common) directive matches the approach in the empty-cmake template, ensuring consistency.


46-56: LGTM! Multi-source executable with addPS1Executable.

The macro correctly handles multiple source files, demonstrating its flexibility beyond the single-file usage in the empty-cmake template.


58-64: LGTM! Updated documentation reflects macro-based asset embedding.

The comments accurately reference the convertImage() and addBinaryFile() macros, guiding users on the modernized asset embedding workflow.

Copy link
Copy Markdown
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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tools/vscode-extension/templates/bare-metal/cmake-cube/src/gpu.h (1)

7-10: ⚠️ Potential issue | 🟡 Minor

Stale macro name in comment.

The constant was renamed to GPU_ORDERING_TABLE_SIZE, but the surrounding comment still refers to the old ORDERING_TABLE_SIZE. Update the comment to avoid confusing readers grepping for the macro.

📝 Proposed fix
-// In order for Z averaging to work properly, ORDERING_TABLE_SIZE should be set
-// to either a relatively high value (1024 or more) or a multiple of 12; see
-// setupGTE() for more details. Higher values will take up more memory but are
-// required to render more complex scenes with wide depth ranges correctly.
+// In order for Z averaging to work properly, GPU_ORDERING_TABLE_SIZE should be
+// set to either a relatively high value (1024 or more) or a multiple of 12;
+// see setupGTE() for more details. Higher values will take up more memory but
+// are required to render more complex scenes with wide depth ranges correctly.
 `#define` GPU_CHAIN_BUFFER_SIZE   1024
 `#define` GPU_ORDERING_TABLE_SIZE  240
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tools/vscode-extension/templates/bare-metal/cmake-cube/src/gpu.h` around
lines 7 - 10, Update the stale comment to reference the renamed macro
GPU_ORDERING_TABLE_SIZE instead of ORDERING_TABLE_SIZE; locate the comment near
setupGTE() in gpu.h and change the text so it advises about
GPU_ORDERING_TABLE_SIZE needing to be large (e.g., 1024 or multiple of 12) for Z
averaging and notes the memory/tradeoffs just as before.
🧹 Nitpick comments (2)
tools/vscode-extension/templates/bare-metal/cmake-cube/src/main.c (1)

309-319: Nit: prefer the canonical PCSX-Redux URL over a bit.ly shortlink.

Embedding a URL shortener in a template string makes the destination opaque to readers and creates a third-party dependency that can break or be repurposed. Since this is sample code that users will see and learn from, it's worth using the direct project URL.

📝 Proposed change
-            "https://bit.ly/pcsx-redux\n"
+            "https://pcsx-redux.consoledev.net\n"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tools/vscode-extension/templates/bare-metal/cmake-cube/src/main.c` around
lines 309 - 319, Replace the bit.ly shortlink in the string passed to
printString with the canonical PCSX-Redux repo URL so the template shows the
direct destination; locate the string literal argument in the call to
printString (the block using chain, &font, 16, 24, 0) and swap
"https://bit.ly/pcsx-redux" for "https://github.com/pcsx-redux/pcsx-redux" (or
the correct canonical repo URL) so examples reference the full URL directly.
tools/vscode-extension/templates/bare-metal/cmake-cube/src/gpu.c (1)

80-91: Confirm caller contract for sendVRAMData chunking.

The slice DMA path requires length (computed as (width*height + 1)/2) to either be < DMA_MAX_CHUNK_SIZE or be an exact multiple of DMA_MAX_CHUNK_SIZE — otherwise the assert(!(length % DMA_MAX_CHUNK_SIZE)) at line 90 fires. For the cube template's font upload (FONT_WIDTH=96, FONT_HEIGHT=56, 4bpp → image upload width=24, height=56length = 24*56/2 = 672 = 42*16 ✅; palette 16x1length = 8 ✅), the dimensions happen to satisfy this, but it's a sharp edge for users adapting the template.

A short comment near the assert (or in uploadTexture/uploadIndexedTexture) noting the dimension constraint would prevent confusion when learners hit the assert. Not a blocker.

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

In `@tools/vscode-extension/templates/bare-metal/cmake-cube/src/gpu.c` around
lines 80 - 91, The assert in sendVRAMData enforces that length = (width*height +
1)/2 is either < DMA_MAX_CHUNK_SIZE or an exact multiple of DMA_MAX_CHUNK_SIZE;
add a short clarifying comment next to the assert (and/or in
uploadTexture/uploadIndexedTexture) stating this caller contract and the
dimension constraint (e.g., 4bpp images require width*height/2 to be divisible
by DMA_MAX_CHUNK_SIZE or smaller) so users know why the assert exists and what
dimensions are required when chunking VRAM uploads.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@tools/vscode-extension/templates/bare-metal/cmake-cube/src/gpu.h`:
- Around line 7-10: Update the stale comment to reference the renamed macro
GPU_ORDERING_TABLE_SIZE instead of ORDERING_TABLE_SIZE; locate the comment near
setupGTE() in gpu.h and change the text so it advises about
GPU_ORDERING_TABLE_SIZE needing to be large (e.g., 1024 or multiple of 12) for Z
averaging and notes the memory/tradeoffs just as before.

---

Nitpick comments:
In `@tools/vscode-extension/templates/bare-metal/cmake-cube/src/gpu.c`:
- Around line 80-91: The assert in sendVRAMData enforces that length =
(width*height + 1)/2 is either < DMA_MAX_CHUNK_SIZE or an exact multiple of
DMA_MAX_CHUNK_SIZE; add a short clarifying comment next to the assert (and/or in
uploadTexture/uploadIndexedTexture) stating this caller contract and the
dimension constraint (e.g., 4bpp images require width*height/2 to be divisible
by DMA_MAX_CHUNK_SIZE or smaller) so users know why the assert exists and what
dimensions are required when chunking VRAM uploads.

In `@tools/vscode-extension/templates/bare-metal/cmake-cube/src/main.c`:
- Around line 309-319: Replace the bit.ly shortlink in the string passed to
printString with the canonical PCSX-Redux repo URL so the template shows the
direct destination; locate the string literal argument in the call to
printString (the block using chain, &font, 16, 24, 0) and swap
"https://bit.ly/pcsx-redux" for "https://github.com/pcsx-redux/pcsx-redux" (or
the correct canonical repo URL) so examples reference the full URL directly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 13aeb66f-0004-4df4-8e51-f9e181eb5281

📥 Commits

Reviewing files that changed from the base of the PR and between 7cb57ad and 2bb01c7.

📒 Files selected for processing (6)
  • tools/vscode-extension/templates/bare-metal/cmake-cube/src/font.c
  • tools/vscode-extension/templates/bare-metal/cmake-cube/src/font.h
  • tools/vscode-extension/templates/bare-metal/cmake-cube/src/gpu.c
  • tools/vscode-extension/templates/bare-metal/cmake-cube/src/gpu.h
  • tools/vscode-extension/templates/bare-metal/cmake-cube/src/main.c
  • tools/vscode-extension/templates/bare-metal/cmake-cube/src/trig.c
✅ Files skipped from review due to trivial changes (1)
  • tools/vscode-extension/templates/bare-metal/cmake-cube/src/trig.c

Copy link
Copy Markdown
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 (1)
tools/vscode-extension/templates/bare-metal/cmake-cube/src/main.c (1)

182-324: Optional: CodeScene flags growing complexity in main() — consider a follow-up extraction, not a blocker.

Static analysis notes main grew from 87 to 97 LoC and remains a high-cyclomatic-complexity function. For an example/template that is meant to be readable top-to-bottom this is a reasonable trade-off, so I'd defer this. If you ever revisit, splitting out the per-frame work into helpers like drawCubeFaces(chain, frameCounter) and setupFrame(chain, bufferX, bufferY) would tame the conditional/loop count without changing behavior.

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

In `@tools/vscode-extension/templates/bare-metal/cmake-cube/src/main.c` around
lines 182 - 324, main() has grown in size/complexity; extract per-frame logic
into smaller helpers to reduce cyclomatic complexity. Split the loop body into
at least two functions such as setupFrame(GPUDMAChain *chain, int bufferX, int
bufferY, bool usingSecondFrame) to handle buffer selection, GPUDMA setup, GTE
resets/rotation and ordering table init, and drawCubeFaces(GPUDMAChain *chain,
int frameCounter) to handle the cube face loop (gte_loadV*/gte_command/GTE_CMD_*
processing, culling, zIndex checks, and allocateGP0Packet calls). Ensure each
new helper uses existing symbols (GPUDMAChain, allocateGP0Packet,
gte_getDataReg, gte_storeDataReg, printString, waitForGP0Ready,
sendGPULinkedList) and keep main() as a high-level orchestrator that calls
setupFrame(...), drawCubeFaces(...), renders UI (printString), waits for VSync,
and sends the linked list.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tools/vscode-extension/templates/bare-metal/cmake-cube/src/main.c`:
- Around line 182-324: main() has grown in size/complexity; extract per-frame
logic into smaller helpers to reduce cyclomatic complexity. Split the loop body
into at least two functions such as setupFrame(GPUDMAChain *chain, int bufferX,
int bufferY, bool usingSecondFrame) to handle buffer selection, GPUDMA setup,
GTE resets/rotation and ordering table init, and drawCubeFaces(GPUDMAChain
*chain, int frameCounter) to handle the cube face loop
(gte_loadV*/gte_command/GTE_CMD_* processing, culling, zIndex checks, and
allocateGP0Packet calls). Ensure each new helper uses existing symbols
(GPUDMAChain, allocateGP0Packet, gte_getDataReg, gte_storeDataReg, printString,
waitForGP0Ready, sendGPULinkedList) and keep main() as a high-level orchestrator
that calls setupFrame(...), drawCubeFaces(...), renders UI (printString), waits
for VSync, and sends the linked list.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 03108e8c-608d-4dc8-a051-b62309fb74e9

📥 Commits

Reviewing files that changed from the base of the PR and between 2bb01c7 and c56e5e8.

📒 Files selected for processing (2)
  • tools/vscode-extension/templates/bare-metal/cmake-cube/src/gpu.h
  • tools/vscode-extension/templates/bare-metal/cmake-cube/src/main.c

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