Skip to content
Merged
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 @@ -21,6 +21,10 @@ var/
.DS_Store
Thumbs.db

# Node.js
node_modules/
package-lock.json

# Build artifacts
build/
dist/
31 changes: 30 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

help: ## Show this help message
@echo 'Usage: make [target]'
Expand Down Expand Up @@ -92,3 +92,32 @@ 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 WASM distribution for browser
@echo "Building PHPBoy for WebAssembly..."
@if [ ! -d "vendor" ]; then \
echo "Error: vendor directory not found. Run 'make install' first."; \
exit 1; \
fi
@mkdir -p dist/php
@echo "Copying web files..."
@cp -r web/* dist/
@echo "Copying PHP source..."
@cp -r src dist/php/
@cp composer.json dist/php/
@echo "Copying vendor directory..."
@cp -r vendor dist/php/
@echo "Build complete! Output in dist/"
@echo ""
@echo "To serve locally:"
@echo " cd dist && python3 -m http.server 8080"
@echo " or"
@echo " npm install && npm run serve"

serve-wasm: ## Serve WASM build locally (requires Python 3)
@if [ ! -d "dist" ]; then \
echo "Error: dist directory not found. Run 'make build-wasm' first."; \
exit 1; \
fi
@echo "Starting HTTP server on http://localhost:8080"
@cd dist && python3 -m http.server 8080
55 changes: 53 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ A readable, well-architected Game Boy Color (GBC) emulator written in PHP 8.5 th
## Features

- **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
- **Browser Support**: Runs in the browser via WebAssembly using php-wasm - no backend required!
- **Fully Dockerized Development**: All PHP/Composer/testing tools run exclusively in Docker containers for consistency
- **Comprehensive Testing**: PHPUnit 10 for unit and integration tests
- **Static Analysis**: PHPStan at maximum level (9) for type safety
Expand Down Expand Up @@ -51,7 +52,9 @@ All development tasks are managed through the Makefile and run inside Docker con
- `make test` - Run PHPUnit tests in Docker
- `make lint` - Run PHPStan static analysis in Docker
- `make shell` - Open bash shell in Docker container
- `make run ROM=path/to/rom.gb` - Run emulator with specified ROM in Docker (coming soon)
- `make run ROM=path/to/rom.gb` - Run emulator with specified ROM in Docker
- `make build-wasm` - Build WebAssembly version for browser
- `make serve-wasm` - Serve WASM build locally on port 8080
- `make clean` - Remove vendor directory and composer.lock
- `make clean-docker` - Remove Docker containers and images

Expand All @@ -74,19 +77,61 @@ For debugging or manual operations:
make shell
```

### Running in the Browser

PHPBoy can run entirely in the browser via WebAssembly using [php-wasm](https://github.com/seanmorris/php-wasm).

#### Build for Browser

1. Build the WASM distribution:
```bash
make build-wasm
```

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

3. Open `http://localhost:8080` in your browser

4. Load a ROM file and play!

**Features**:
- ✅ Full emulation in the browser
- ✅ No backend server required
- ✅ Keyboard controls
- ✅ Speed control
- ✅ Pause/Resume
- ✅ Works offline after first load

**Browser Requirements**:
- Chrome 90+, Firefox 88+, Safari 14+, or Edge 90+
- WebAssembly support required

**Documentation**:
- [WASM Build Guide](docs/wasm-build.md) - How to build and deploy
- [Browser Usage Guide](docs/browser-usage.md) - How to use in browser
- [WASM Options Evaluation](docs/wasm-options.md) - Technical decisions

## Project Structure

```
phpboy/
├── bin/ # CLI entry point
├── docs/ # Documentation
│ └── research.md # Game Boy hardware research
│ ├── research.md # Game Boy hardware research
│ ├── wasm-build.md # WebAssembly build guide
│ ├── browser-usage.md # Browser usage guide
│ └── wasm-options.md # WASM implementation options
├── src/ # Source code
│ ├── Apu/ # Audio Processing Unit
│ ├── Bus/ # Memory bus
│ ├── Cartridge/ # ROM/MBC handling
│ ├── Cpu/ # CPU emulation
│ ├── Frontend/ # CLI and WASM frontends
│ │ ├── Cli/ # CLI implementation
│ │ └── Wasm/ # WASM adapters
│ ├── Ppu/ # Pixel Processing Unit
│ └── Support/ # Utilities and helpers
├── tests/ # Test suite
Expand All @@ -95,7 +140,13 @@ phpboy/
├── third_party/ # External resources
│ ├── references/ # Technical documentation
│ └── roms/ # Test ROMs
├── web/ # Browser frontend
│ ├── index.html # Main page
│ ├── css/ # Stylesheets
│ ├── js/ # JavaScript bridge
│ └── phpboy-wasm.php # PHP entry point
├── composer.json # PHP dependencies
├── package.json # npm dependencies (for php-wasm)
├── Dockerfile # Docker image definition
├── docker-compose.yml # Docker services
├── Makefile # Task automation
Expand Down
Loading