Skip to content

Add ROM data parameter support via URL hash #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 23, 2025

Conversation

partouf
Copy link
Member

@partouf partouf commented May 23, 2025

Summary

This PR adds support for passing ROM data directly via URL hash parameters, enabling users to share Game Boy games without hosting the ROM files.

Changes

  • Modified demo/iframe/stores.js to parse hash parameters alongside query parameters
  • Updated demo/iframe/components/WasmBoy.svelte to decode base64 ROM data
  • Added support for rom-data, rom-url, and rom-name in URL hash fragment
  • Added documentation explaining the feature and usage

Implementation Details

  • Uses URL hash fragment (#) instead of query parameters (?) to keep ROM data private
  • Hash fragments are never sent to the server, ensuring ROM data stays in the browser
  • Supports base64-encoded Game Boy ROM files (.gb, .gbc)
  • Falls back to query parameters for rom-url and rom-name if not found in hash
  • Processes base64 data in chunks to avoid call stack size errors

URL Format

https://wasmboy.app/iframe/#rom-data=<base64-encoded-rom>&rom-name=<optional-name>

Motivation

This feature enables Compiler Explorer to embed Game Boy games directly in URLs without requiring external hosting, similar to how viciious handles C64 programs. This is particularly useful for:

  • Sharing small homebrew games and demos
  • Educational examples in compiler output
  • Temporary game sharing without permanent hosting

Test Plan

  1. Build the iframe demo: npm run iframe:build
  2. Start the dev server: npm run iframe:dev
  3. Use the test HTML file to convert a ROM to base64 and generate a test URL
  4. Verify the ROM loads and plays correctly
  5. Confirm that the hash data is not sent to the server (check network tab)

Example Usage

// Convert ROM to base64
const romBytes = new Uint8Array(romBuffer);
let binary = '';
for (let i = 0; i < romBytes.length; i += 0x8000) {
    const chunk = romBytes.subarray(i, i + 0x8000);
    binary += String.fromCharCode.apply(null, chunk);
}
const base64 = btoa(binary);

// Create shareable URL
const url = `https://wasmboy.app/iframe/#rom-data=${encodeURIComponent(base64)}&rom-name=MyGame.gb`;

Limitations

  • Browser URL length limits (typically 2MB+, varies by browser)
  • Base64 encoding increases size by ~33%
  • Very large ROMs may not work in all browsers

Related

This implementation follows the same pattern as viciious for Compiler Explorer: compiler-explorer/viciious@aa132cd

- Added support for passing ROM data as base64 in URL hash fragment
- Uses hash (#) instead of query (?) to keep ROM data private
- Hash parameters supported: rom-data, rom-url, rom-name
- Falls back to query parameters for rom-url and rom-name
- Added documentation explaining the feature and usage

This allows sharing Game Boy ROMs via URL without hosting files,
similar to how viciious handles C64 programs for Compiler Explorer.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@partouf
Copy link
Member Author

partouf commented May 23, 2025

This PR addresses one of the TODOs mentioned in compiler-explorer/compiler-explorer#7717 - specifically the ability to pass ROM data via URL parameters.

With this implementation, Compiler Explorer will be able to embed Game Boy ROMs directly in URLs using the hash fragment, similar to how viciious handles C64 programs. This eliminates the need for external ROM hosting when displaying compiler output as Game Boy games.

@partouf
Copy link
Member Author

partouf commented May 23, 2025

There's no option I think to show the debug options like wasmboy.app shows, will try to get that in after some sleep

@partouf partouf requested a review from mattgodbolt May 23, 2025 03:53
- Added ROM data parameter support to debugger (loads from URL hash)
- Hidden Open menu to prevent confusion (ROMs load automatically)
- Updated Help and About sections to indicate this is a CE fork
- Customized default layout: Player, Controls, Disassembler, CPU State
- Made UI more compact:
  - Smaller fonts (0.8em) and fixed-width fonts for CPU State and Disassembler
  - Reduced padding throughout (0px content, 5px inner divs)
  - Compact h1 headers (1.2em, 5px margins)
  - Shortened row heights in virtual lists
- Removed notification popups for stepping opcodes
- Added minimal util polyfill to fix browser compatibility

These changes optimize the debugger for displaying compiler output
with a focus on code execution and register inspection.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@partouf partouf merged commit efcc96e into master May 23, 2025
1 check passed
@partouf partouf deleted the add-rom-data-parameter branch May 23, 2025 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant