A full-featured ZX Spectrum emulator written in Python, featuring complete Z80 CPU emulation, graphics, sound, and I/O subsystems.
- Complete Z80 CPU emulation with all instruction sets (base, extended, IX/IY registers)
- 48K and 128K Spectrum models support
- Accurate timing and interrupt handling
- Memory banking for 128K models
- Full screen rendering with pixel-perfect accuracy
- Color palette emulation (15 colors + bright variants)
- Border effects and screen attributes
- SCR file loading for screen snapshots
- Real-time screen updates
- Full keyboard emulation with Spectrum key matrix
- I/O port handling for peripherals
- Snapshot loading (.z80, .sna formats)
- ROM loading for different Spectrum models
- Built-in debugger with register and memory inspection
- Test suite with Z80 instruction verification
- Multiple CPU implementations for comparison and optimization
- Logging and tracing capabilities
- Python 3.7 or higher
- pip package manager
# Clone the repository
git clone https://github.com/eng2007/ZXEmulator.git
cd ZXEmulator
# Install dependencies
pip install -r requirements.txt# Run the emulator
python emulator.pystart_emul.bat- Launch the main emulatorstart_draw_keyboard.bat- Keyboard visualization demostart_screen.bat- Screen loading demostart_test.bat- Run test suite
Place your ZX Spectrum ROM files in the roms/ directory:
48.rom- 48K Spectrum ROM128k.rom- 128K Spectrum ROM
- ROM files:
.rom,.bin - Snapshots:
.z80,.sna - Screen files:
.scr - Archives:
.zip(automatically extracted)
- F1 - Open ROM selection menu
- F2 - Reset emulator
- ESC - Exit emulator
The emulator maps PC keyboard to ZX Spectrum keys:
- Standard QWERTY layout maps to Spectrum keyboard matrix
- Special keys (Symbol Shift, Caps Shift) are mapped appropriately
ZXEmulator/
โโโ emulator.py # Main emulator class and GUI
โโโ new_cpu.py # Z80 CPU implementation (main)
โโโ cpu.py # Alternative Z80 CPU implementation
โโโ base_cpu.py # Base CPU functionality
โโโ ext_cpu.py # Extended CPU instructions
โโโ memory.py # Memory management and banking
โโโ graphics.py # Screen rendering and graphics
โโโ keyboard.py # Keyboard input handling
โโโ io_controller.py # I/O port management
โโโ interrupt_controller.py # Interrupt handling
โโโ const.py # Constants and definitions
โโโ tests.py # Test suite
โโโ tests_new.py # Additional tests
โโโ requirements.txt # Python dependencies
โโโ roms/ # ZX Spectrum ROM files
โโโ demos/ # Demo programs and games
โโโ snapshots/ # Game snapshots (.z80, .sna)
โโโ screens/ # Screen captures (.scr)
โโโ z80-master/ # Z80 reference implementation
- Complete instruction set including undocumented opcodes
- Accurate flag handling and register operations
- Interrupt modes (IM 0, IM 1, IM 2)
- Multiple CPU cores for testing and compatibility
- 64KB base memory for 48K model
- 128KB extended memory with proper banking
- ROM/RAM switching and memory paging
- Snapshot loading with memory state restoration
- 256x192 pixel resolution with color attributes
- 8x8 character cells with ink/paper colors
- Border rendering with 8 possible colors
- Real-time screen updates at 50Hz
Run the test suite to verify Z80 instruction accuracy:
python tests_new.pyThe emulator includes comprehensive tests against known Z80 test suites and maintains compatibility with existing ZX Spectrum software.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Python 3.7+ required
- Windows, Linux, macOS supported
- Pygame 2.0+ for graphics and input
- NumPy for performance optimizations
This project is licensed under the MIT License - see the LICENSE file for details.
- Based on the original ZX Spectrum architecture
- Z80 CPU emulation inspired by various open-source projects
- Special thanks to the ZX Spectrum preservation community
ZX Spectrum is a trademark of Sinclair Research Ltd.