This is the home page for MOS6502, a small, simplistic, self contained, object oriented emulator of the old 8-bit processor MOS 6502.
The model started out as a summer hack to see how difficult it would be to create a CPU model capable of executing real object code using Python. As hacks often go, this one turned into something a little bit more advanced than a simple afternoon hack.
The CPU contains the same pointers, registers and flags etc as the real CPU. Furthermore the CPU is equipped with extra counters for counting cycles and instructions. The purpose of these are to support code profiling and analysis.
The CPU model supports methods for running a program as well as single stepping an instruction. Also there are methods for resetting either all registers or the support counters. Finally is equipped with a method for dumping a select part of the memory to std out.
In terms of memory the model contains a single, flat 64 kByte memory. No memory banks are as yet supported. Future implementations might support banking similator the the Commodore 64.
Release 2008-08-28
Initial public release.
Currently the model does NOT implement all instructions of the original MOS 6502 processor and none of the subsequent CPU models. These instructions might be added later though. The CPU also lacks proper implementation of stack, interrupts etc.
I have started adding unit tests for the instructions as well as the internal registers, flags etc, but the tests are far from complete. (Yes, I know the tests should be written first…). There are a number of unit test stubs for the CPU functionality, bot most of them fail by default.
Finally this release contains two examples that demonstrates how to use the CPU model. The first example is a very simple example that illustrates how to instantiate a CPU, load a short program into memory, run the program and look at the results.
The second example is a more advanced example. The program loaded into the CPU memory is an implementation of the RPNG part of the RC4 stream cipher. The PRNG program runs one million times, and for each run the RC4 internal state is updated. After one millions iterations the example dumps the internal state. Total exectution time on a MacBook takes less than 100s, which hints at an emulated CPU performance close to 1 MHz.
Note that the assembler code for the RC4 is not written for speed and can easily be improved.
File for downloading: MOS6502_2008-08-28.tgz (7349 Bytes)
SHA-1 (MOS6502_2008-08-28.tgz):
68b9577998be1123dd86ed3b2ba82a0b6c408a87
Trackbacks /
Pingbacks