Emulating a 6502 shouldn’t be that hard on a modern computer. Maybe that’s why [lasect] decided to make it a bit harder. The PG_6502 emulator uses PostgreSQL. All the CPU resources are database tables, and all opcodes are stored procedures. Huh.
The database is pretty simple. The pg6502.cpu table has a single row that holds the registers. Then there is a pg6502.mem table that has 64K rows, each representing a byte. There’s also a pg6502.opcode_table that stores information about each instruction. For example, the 0xA9 opcode is an immediate LDA and requires two bytes.
The pg6502.op_lda procedure grabs that information and updates the tables appropriately. In particular, it will load the next byte, increment the program counter, set the accumulator, and update the flags.
Honestly, we’ve wondered why more people don’t use databases instead of the file system for structured data but, for us, this may be a bit much. Still, it is undoubtedly unique, and if you read SQL, you have to admit the logic is quite clear.
We can’t throw stones. We’ve been known to do horrible emulators in spreadsheets, which is arguably an even worse idea. We aren’t the only ones.

Now, that is a hack!
Just riffing on the idea of using databases instead of filesystems…
I love the flexibility of databases for queries. At least, SQL. For one-off queries, nothing is easier than SELECT, with its different kinds of JOIN and so on. There’s a little benefit from the flexibility in table formats… ALTER TABLE, ADD INDEX, these are neat operations to have.
But in every other way, it’s a disaster. It’s always going to be dog slow. It’s always going to scale horribly. It’s always going to have exactly the wrong set of concurrency / locking idioms for your actual needs. It’s never going to be easy to recover your data. It’s never going to survive version upgrades without breaking both your stored data and your SQL statements. Despite “SQL is a standard”, you will inevitably get locked into a specific vendor.
There definitely are use cases. And i suspect there’s a lot of value in the “NoSQL movement”, but from my perspective that’s hardly a general database, it’s all bespoke hacks for specific contexts.
I can still read ext2 filesystems from 30 years ago but mysql etc give me trouble even after only a couple years. In an afternoon, i can write a bespoke program to rescue data from a corrupted ext2 filesystem. The SQL databases i’ve known, at least, are all super the opposite of that. I don’t just want structure and flexible recall, i also want reliable and robust storage and recall.
And here I am wondering why more people don’t use file system instead of databases for structured data ;-)
My name is Tim. I’m 30 years old and I’m from the UK. I’m a senior database developer. I’m a database performance specialist. I’m hired for companies to fulfill their requirements. Their complex, business requirements. I was gonna be a movie star, with modelling and acting. After a hundred or two auditions and small parts, I decided I had enough. Then I got into database work. The client requested a lot of tables. So I just decided to go full master and changed his entire setup into a normal form, a 6th normal form, with a lot of tables in the database, and its gone really well. Consulting is 300 bucks per hour. Usually the client’s internal IT team is pretty much high on coffee, to really stay awake, and I have this long LaTeX presentation that goes all the way up to the 6th normal form. Then I put on a serious face. And make them say: “The key, the whole key, and nothing but the key, so help me Codd.” It’s a long process to get their whole team up to spec. But its an intense feeling for the other person, I think for myself too. You go to places that even though it’s logical with tables and relations, for some reason it’s also more emotional. It’s more psychological too. We all reach the same place, it’s really strange at the same time. And I found with a consulting session like that it’s really exhausting.
Your text shows several issues, an AI-like tone, repetitive phrasing, uneven rhythm, potential plagiarism, and low readability. These inconsistencies affect its style, flow, and credibility.
92% AI score
Sister, I’m the same way!
About 40 years back, I designed ICE (In Circuit Emulators) at a small company. Emulation is where something becomes the target, including meeting timing and electrical properties. In my dictionary, this article is about simulation. Just sayin’.
I agree in principle with drawing a distinction between emulation and simulation. I disagree with classifying this as a simulator, though, because in this case it is accurately emulating the 6502 Instruction Set Architecture (ISA). I’ve written a number of ISA-level emulators as well as cycle-accurate emulators over the years, and that’s how I classify them.
I think this is a delightful hack, whichever bin you care to put it in.
Well, the most fascinating program for the 6502/65C02 is a program called Diversi-Dial for the Apple //e.
If you go to magviz.ca, you’ll see a modern representation of this incredible program.
Bill Basham, a doctor and programmer wrote DDial because a nurse at the place he worked lamented about how expensive online services at the time were. Imagine, 7 modems inside an Apple //e, with the program loaded through the cassette port, giving those modems the ability to communicate between each other.
It was quite advanced for its time. Who would have thought that a little one Mhz cpu could do such a thing?
Nowadays, we have the internet with multi-ghz CPUs and gigabit internet speeds that connect the entire world. A far cry from an Apple //e with 7 modems and phone lines connecting 7 users plus the system operator. There’s an expression, from humble beginnings come great things.
I’m old, gray, and can honestly say I was there from the beginning. I never could have imagined the internet we have today back then. There are times I miss running a DDial and the small close knit community it generated. DDials would link up together at night, when landline phone rates were lower. (Anyone remember that?) The 6502 is indeed a remarkable processor and a remarkable feat of engineering.
SQL injection payload includes an entire processor and slow blow malicious program, all hidden in your database!