4 ms·
You start by reading hardware documentation and you don't need to understand the machine at an electronic level. It's not a simulation of digital circuits. It d
by xcv123 2y ago
You start by reading hardware documentation and you don't need to understand the machine at an electronic level. It's not a simulation of digital circuits. It doesn't need to be that complicated. An 8-bit CPU is a simple state machine with only a few bytes of state (registers). You can read the program one byte at a time and simulate whatever operation the CPU would do after reading that byte. They are very simple operations like adding and subtracting numbers, loading and storing bytes.
http://www.6502.org/users/obelisk/6502/registers.html http://www.6502.org/users/obelisk/6502/registers.html
http://www.6502.org/users/obelisk/6502/instructions.html http://www.6502.org/users/obelisk/6502/instructions.html
Your 6502 CPU emulator would read the next few bytes of the program, interpret the bytes as an instruction, execute the instruction, which involves updating a couple of registers/counters in the CPU, doing some arithmetic or bitwise operations, and possibly loading or storing a byte of data from one location to another. This process is then repeated in an endless loop.
It is a simulation of the fetch-decode-execute cycle.
https://en.wikipedia.org/wiki/Instruction_cycle https://en.wikipedia.org/wiki/Instruction_cycle
- purple-leafy 2y agoThanks for that! You put it into a very understandable form
- xcv123 2y agoYou're welcome. I learned about the basics here http://www.emulator101.com http://www.emulator101.com Then I read the docs at NESdev Wiki and eventually wrote my own NES emulator. https://www.nesdev.org/wiki/Nesdev_Wiki https://www.nesdev.org/wiki/Nesdev_Wiki If you have good documentation then you're just following the specs and turning that into code. Next level difficulty is reverse engineering the hardware, figuring out how it works when there isn't any documentation. These guys did that for NES back in the 90s and early 2000s, writing little test ROMs to see what the hardware does, in addition to whatever official or unofficial developer docs they could find.