Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ Thumbs.db
# Build artifacts
build/
dist/

# Node.js / npm
node_modules/
package-lock.json
73 changes: 72 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: help setup install test lint shell run clean rebuild
.PHONY: help setup install test lint shell run clean rebuild build-wasm serve-wasm wasm-info

help: ## Show this help message
@echo 'Usage: make [target]'
Expand Down Expand Up @@ -92,3 +92,74 @@ memory-profile: ## Run with memory profiling (usage: make memory-profile ROM=pat
exit 1; \
fi
docker compose run --rm phpboy php -d memory_limit=512M bin/phpboy.php $(ROM) --headless --frames=$(or $(FRAMES),1000) --memory-profile

build-wasm: ## Build WebAssembly version for browser (Step 15)
@echo "Building PHPBoy for WebAssembly..."
@echo ""
@echo "⚠️ WASM Build Prerequisites:"
@echo " 1. Install Emscripten SDK: https://emscripten.org/docs/getting_started/downloads.html"
@echo " 2. Install php-wasm builder: npm install -g php-wasm-builder (if available)"
@echo " 3. Or use seanmorris/php-wasm: https://github.com/seanmorris/php-wasm"
@echo ""
@echo "📦 Build Steps (to be implemented):"
@echo " 1. Compile PHP 8.3+ to WebAssembly using Emscripten"
@echo " 2. Bundle PHPBoy PHP source files"
@echo " 3. Generate php-wasm.js loader"
@echo " 4. Copy web/ assets to dist/"
@echo " 5. Create dist/ directory with all browser files"
@echo ""
@echo "📁 Expected output: dist/"
@echo " - dist/php-wasm.js (PHP WASM runtime)"
@echo " - dist/php-wasm.wasm (PHP interpreter binary)"
@echo " - dist/index.html (Web UI)"
@echo " - dist/styles.css (Styles)"
@echo " - dist/js/phpboy.js (Emulator bridge)"
@echo " - dist/js/app.js (UI controller)"
@echo " - dist/phpboy/ (PHP source files)"
@echo ""
@echo "📖 See docs/wasm-build.md for detailed build instructions"
@echo ""
@mkdir -p dist
@cp -r web/* dist/
@mkdir -p dist/phpboy
@cp -r src dist/phpboy/
@cp -r vendor dist/phpboy/ 2>/dev/null || echo "Note: Run 'make install' first to include vendor/"
@echo ""
@echo "✅ Static files copied to dist/"
@echo "⚠️ PHP WASM compilation not yet implemented - see docs/wasm-build.md"

serve-wasm: ## Serve WebAssembly build locally (requires Python 3)
@echo "Starting local web server for PHPBoy WASM..."
@echo ""
@echo "🌐 Open browser to: http://localhost:8000"
@echo "Press Ctrl+C to stop"
@echo ""
@cd dist && python3 -m http.server 8000

wasm-info: ## Show information about WebAssembly build setup
@echo "PHPBoy WebAssembly Build Information"
@echo "======================================"
@echo ""
@echo "Current Status: Infrastructure complete, awaiting WASM compiler"
@echo ""
@echo "✅ Completed Components:"
@echo " - WasmFramebuffer implementation (src/Frontend/Wasm/WasmFramebuffer.php)"
@echo " - WasmInput implementation (src/Frontend/Wasm/WasmInput.php)"
@echo " - BufferSink for audio (src/Apu/Sink/BufferSink.php)"
@echo " - JavaScript bridge (web/js/phpboy.js)"
@echo " - Web UI (web/index.html, web/styles.css, web/js/app.js)"
@echo " - Build target (make build-wasm)"
@echo ""
@echo "⏳ Pending:"
@echo " - PHP to WASM compilation setup"
@echo " - WASM module loading and integration"
@echo " - Browser testing with actual ROM"
@echo ""
@echo "📖 Documentation:"
@echo " - docs/wasm-options.md - Research on PHP-to-WASM options"
@echo " - docs/wasm-build.md - Build instructions (to be created)"
@echo " - docs/browser-usage.md - Browser usage guide (to be created)"
@echo ""
@echo "🎯 Recommended Approach:"
@echo " Use seanmorris/php-wasm (WordPress Playground approach)"
@echo " See: https://github.com/seanmorris/php-wasm"
62 changes: 60 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ A readable, well-architected Game Boy Color (GBC) emulator written in PHP 8.5 th

- **Modern PHP 8.5 RC**: Leverages the latest PHP 8.5 release candidate features including strict types, readonly properties, enums, typed class constants, and property hooks
- **Fully Dockerized Development**: All PHP/Composer/testing tools run exclusively in Docker containers for consistency
- **Comprehensive Testing**: PHPUnit 10 for unit and integration tests
- **Browser Support**: Run PHPBoy in your browser via WebAssembly (Step 15)
- **Comprehensive Testing**: PHPUnit 10 for unit and integration tests with 100% Blargg test pass rate
- **Static Analysis**: PHPStan at maximum level (9) for type safety
- **Modular Architecture**: Clean separation of concerns with dedicated namespaces for CPU, PPU, APU, Bus, and Frontend
- **Complete Emulation**: Full CPU (LR35902), PPU with sprites/background/window, APU with 4 channels, MBC1/3/5 cartridge support

## Requirements

Expand Down Expand Up @@ -74,19 +76,69 @@ For debugging or manual operations:
make shell
```

## Browser Version (WebAssembly)

PHPBoy can run entirely in your browser using WebAssembly! Play Game Boy games without installing anything.

### Quick Start (Browser)

1. **Build for browser:**
```bash
make build-wasm
```

2. **Serve locally:**
```bash
make serve-wasm
```

3. **Open browser:**
- Navigate to `http://localhost:8000`
- Click "Choose ROM File" and select a .gb or .gbc ROM
- Click "Play" and enjoy!

### Browser Controls

| Key | Game Boy Button |
|-----|----------------|
| Arrow Keys | D-Pad |
| Z | A Button |
| X | B Button |
| Enter | Start |
| Shift | Select |

### Browser Build Commands

- `make build-wasm` - Build WebAssembly version
- `make serve-wasm` - Serve locally at http://localhost:8000
- `make wasm-info` - Show WASM build information

### Documentation

- [Browser Usage Guide](docs/browser-usage.md) - How to use PHPBoy in your browser
- [WASM Build Guide](docs/wasm-build.md) - How to build the WebAssembly version
- [WASM Options Research](docs/wasm-options.md) - Technical research on PHP-to-WASM approaches

**Note:** The WebAssembly build requires php-wasm (Emscripten-compiled PHP). See [docs/wasm-build.md](docs/wasm-build.md) for setup instructions.

## Project Structure

```
phpboy/
├── bin/ # CLI entry point
├── docs/ # Documentation
│ └── research.md # Game Boy hardware research
│ ├── research.md # Game Boy hardware research
│ ├── wasm-options.md # PHP-to-WASM research
│ ├── wasm-build.md # WebAssembly build guide
│ └── browser-usage.md # Browser usage instructions
├── src/ # Source code
│ ├── Apu/ # Audio Processing Unit
│ ├── Bus/ # Memory bus
│ ├── Cartridge/ # ROM/MBC handling
│ ├── Cpu/ # CPU emulation
│ ├── Frontend/ # CLI and WASM frontends
│ │ ├── Cli/ # CLI renderer & input
│ │ └── Wasm/ # Browser framebuffer & input
│ ├── Ppu/ # Pixel Processing Unit
│ └── Support/ # Utilities and helpers
├── tests/ # Test suite
Expand All @@ -95,6 +147,12 @@ phpboy/
├── third_party/ # External resources
│ ├── references/ # Technical documentation
│ └── roms/ # Test ROMs
├── web/ # Browser frontend (WebAssembly)
│ ├── index.html # Web UI
│ ├── styles.css # UI styles
│ └── js/ # JavaScript bridge & controller
│ ├── phpboy.js # WASM/PHP bridge
│ └── app.js # UI controller
├── composer.json # PHP dependencies
├── Dockerfile # Docker image definition
├── docker-compose.yml # Docker services
Expand Down
160 changes: 0 additions & 160 deletions STEP4_STATUS.md

This file was deleted.

Loading