Skip to content

Commit ddb05c3

Browse files
committed
added readme
1 parent 397f52d commit ddb05c3

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

readme.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Emu6502
2+
3+
An MOS 6502 emulator written in the D language
4+
5+
Example:
6+
```d
7+
module example;
8+
9+
import std.stdio;
10+
import emu6502;
11+
12+
void main() {
13+
ubyte[0x10000] memory;
14+
ubyte[] code = [
15+
0xA2, 0x00, // lda #0
16+
// loop:
17+
0xBD, 0x0E, 0x80, // lda data,x
18+
0x8D, 0x00, 0xE0, // sta $E000
19+
0xC9, 0x00, // cmp #0
20+
0xE8, // inx
21+
0xD0, 0xF5, // bne loop
22+
0x00, // brk
23+
// data: .asciiz 'Hello, World!\n'
24+
0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x2C, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64, 0x21, 0x0A, 0x00
25+
];
26+
// put code into memory
27+
foreach(i, b; code)
28+
memory[0x8000+i] = b;
29+
// set reset vector
30+
memory[0xFFFC] = 0x00;
31+
memory[0xFFFD] = 0x80;
32+
// create emulator
33+
auto emu = new Emu6502(
34+
(ushort address) {
35+
return memory[address];
36+
},
37+
(ushort address, ubyte value) {
38+
if(address == 0xE000)
39+
write(cast(char)value);
40+
else
41+
memory[address] = value;
42+
},
43+
(ubyte n) {}
44+
);
45+
emu.reset();
46+
emu.throwExceptionOnBreak = true;
47+
// run until brk triggered
48+
try {
49+
while(true)
50+
emu.step();
51+
} catch(BreakException) {}
52+
}
53+
```
54+
55+
# TODO
56+
* `BIT` instruction (currently acts like `NOP`)
57+
* Handling `BRK` when `throwExceptionOnBreak` is false.
58+
* Non-Maskable Interrupt
59+
* Timings for some commands are inaccurate

0 commit comments

Comments
 (0)