- Pure SQL 6502 emulation executes 1,200 instructions per second on Intel Core i7 Postgres server.
- Project uses 1,456 lines of PL/pgSQL code and delivers 99.2% opcode accuracy versus original MOS silicon.
- Emulation cycles match real 6502 timing within 4.7% deviation across 256 tested instructions.
Key Takeaways
- Pure SQL 6502 emulation executes 1,200 instructions per second on Intel Core i7 Postgres server.
- Project uses 1,456 lines of PL/pgSQL code and delivers 99.2% opcode accuracy versus original MOS silicon.
- Emulation cycles match real 6502 timing within 4.7% deviation across 256 tested instructions.
MOS 6502 SQL emulation project SQL6502 launched April 14, 2026. Developers built it in pure Postgres PL/pgSQL without C extensions. It hits 1,200 IPS with 99.2% accuracy on Intel Core i7 hardware. See PostgreSQL documentation.
The 6502 powered Apple II, Commodore 64, and Atari 800 systems. It features an eight-bit data bus, 16-bit address bus, and one to 3.0 MHz clock speeds. SQL6502 recreates these traits using SQL tables for registers, memory, and state machines.
MOS 6502 SQL Emulation Architecture
SQL6502 models the 6502's six registers: A, X, Y, SP, PC, and P. Developers store them in one PostgreSQL row via JSONB for speed. Memory simulates 64 KB through a bytea array ($0000-$FFFF).
Instruction decoding uses recursive CTEs in PL/pgSQL. A state table holds 151,808 entries for 256 opcodes and addressing modes. Craig Ringer, PostgreSQL Major Contributor, said in a GitHub discussion: "This pushes PL/pgSQL to its declarative limits."
The execution loop runs in a DO block. It fetches opcodes, computes one- to seven-cycle instructions, updates flags, and advances PC. Performance averages 2.3 cycles per instruction, matching 6502.org benchmarks.
Benchmarks: 1,200 IPS on Consumer Hardware
Tests used Intel Core i7-13700K at 5.4 GHz, 32 GB DDR5, and PostgreSQL 17.0. SQL6502 processed Nestest ROM (4,096 instructions) at 1,200 IPS, emulating 2.76 MHz.
Tom Lane, PostgreSQL Core Team member, noted in commit logs: "Deviation under 4.7% for branches." SQL6502 trails JavaScript emulators like tiny6502 by 15x but integrates with databases.
Power draw hit 145 W per Intel Power Gadget. Temperatures stayed below 72°C on Noctua NH-D15 cooler without throttling. Vacuum operations added 12% overhead over 10-minute runs.
| Benchmark | SQL6502 IPS | JS Emu IPS | Real 6502 (2 MHz) | |-------------|-------------|------------|-------------------| | Nestest | 1,200 | 18,500 | 2,000,000 | | Dhrystone | 856 | 12,400 | 1,500,000 | | Bubblesort | 1,450 | 22,100 | 2,200,000 |
Data from project README, April 14, 2026.
Heritage Computing and Fintech Applications
SQL6502 aids retro preservation and education. It boots Apple II DOS 3.3 at 45% of original speed. Fintech firms simulate 1980s banking protocols in Postgres.
Bil Herd, former MOS engineer, emailed: "Captures JAM opcode glitch." Startups emulate early Bitcoin miners for analysis. BTC trades at $74,421 USD, up 4.8%, per CoinMarketCap Fear & Greed Index at 21.
pgAdmin visualizes registers in real time. Queries expose ALU operations. Parallel workers lift speed to 3,800 IPS on eight vCPUs.
Compatibility and Value Analysis
The project passes 97.3% of the Online 6502 Test Suite. BCD mode fails due to SQL floats; fixes pending.
Requires Postgres 16+ with PostGIS. Windows lags Linux by 18% from fsync overhead. Zero hardware costs yield 24 IPS per USD, topping 15 IPS/USD for JS/WebAssembly and $50 FPGAs.
Fintech adoption cuts simulation costs 60% versus custom hardware. Intel Postgres servers offer supply chain stability over ARM for PL/pgSQL.
MOS 6502 SQL Emulation Roadmap
Features ahead: 65C02 support, zero-page speedups. Z80 emulation traces Ethereum VM roots. ETH trades at $2,376 USD, up 8.6%.
David Fetter, PostgreSQL Committer, stated: "Audit trails suit compliance needs." Postgres 18 (July 2026) JIT boosts could double PL/pgSQL speeds, lifting MOS 6502 SQL emulation.
