原文
链接
module example;
import std.stdio;
import emu6502;
void main() {
ubyte[0x10000] memory;
ubyte[] code = [
0xA2, 0x00,
0xBD, 0x0E, 0x80,
0x8D, 0x00, 0xE0,
0xC9, 0x00,
0xE8,
0xD0, 0xF5,
0x00,
0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x2C, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64, 0x21, 0x0A, 0x00
];
foreach(i, b; code)
memory[0x8000+i] = b;
memory[0xFFFC] = 0x00;
memory[0xFFFD] = 0x80;
auto emu = new Emu6502(
(ushort address) {
return memory[address];
},
(ushort address, ubyte value) {
if(address == 0xE000)
write(cast(char)value);
else
memory[address] = value;
},
(ubyte n) {}
);
emu.reset();
emu.throwExceptionOnBreak = true;
try {
while(true)
emu.step();
} catch(BreakException) {}
}