-
Notifications
You must be signed in to change notification settings - Fork 0
/
rtest.rs
45 lines (36 loc) · 1.36 KB
/
rtest.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use std::io::stdin;
use rustycoat::core::clock::*;
use rustycoat::core::memory::*;
use rustycoat::core::*;
use rustycoat::cpus::c6502::*;
const RESET_PROGRAM: &[u8] = &[
0xA9, 0x00, // LDA #$00
0x85, 0x05, // STA $05
0xA5, 0x05, // LDA $05
0x69, 0x01, // ADC #$01
0x85, 0x05, // STA $05
0x4C, 0x04, 0xE0, // JMP $E004
];
const NMI_PROGRAM: &[u8] = &[];
const IRQ_PROGRAM: &[u8] = &[];
fn main() {
let mut rom_bytes: [u8; 0x2000] = [0; 0x2000];
rom_bytes[0..RESET_PROGRAM.len()].copy_from_slice(RESET_PROGRAM);
rom_bytes[0x1000..0x1000 + NMI_PROGRAM.len()].copy_from_slice(NMI_PROGRAM);
rom_bytes[0x1100..0x1100 + IRQ_PROGRAM.len()].copy_from_slice(IRQ_PROGRAM);
rom_bytes[0x1ffa..].copy_from_slice(&[0x00, 0xf0, 0x00, 0xe0, 0x00, 0xf1]);
// Create a new memory object with a ROM loaded into the top 8K
let memory = Memory::new();
memory.configure_banks(vec![RomBank::with_bytes(&rom_bytes)], &[(0xe000, 0x2000, 1, 0x0000)]);
// Create a CPU instance wired to the memory.
let mut cpu = C6502::new(&memory);
cpu.reset();
// Create a 1MHz clock and wire it up to the CPU.
let mut clock = Clock::new(1_000_000);
clock.output().connect_to(cpu.phi0_in());
// Create a computer, add components, and start it up.
let mut c = Computer::new();
c.add_async(cpu);
c.add_async(clock);
c.run();
}