mirror of
https://github.com/mre/mos6502.git
synced 2024-11-28 07:49:19 +00:00
11499b6bc8
* start on separating 6502 variants from cpu itself
* add a single variant: the NMOS one
* get examples & tests running again
* Add the Revision A variant, one that has no ROR
* disable failing lint in build-time dependencies
* Variant with no decimal mode
* Revert "disable failing lint in build-time dependencies"
This reverts commit c87975e937
.
* some doc comments
* specify the variant in unit test now the API has changed
---------
Co-authored-by: Sam M W <you@example.com>
36 lines
960 B
Rust
36 lines
960 B
Rust
use mos6502::cpu;
|
|
use mos6502::instruction::Nmos6502;
|
|
use mos6502::memory::Bus;
|
|
use mos6502::memory::Memory;
|
|
use std::fs::read;
|
|
|
|
fn main() {
|
|
println!("Enter two numbers (< 128) separated by a space to know their GCD.");
|
|
let mut input = String::new();
|
|
std::io::stdin().read_line(&mut input).unwrap();
|
|
|
|
let zero_page_data = input
|
|
.split_whitespace()
|
|
.map(|s| s.parse::<u8>().unwrap())
|
|
.collect::<Vec<u8>>();
|
|
|
|
// Load the binary file from disk
|
|
let program = match read("examples/asm/euclid/euclid.bin") {
|
|
Ok(data) => data,
|
|
Err(err) => {
|
|
println!("Error reading euclid.bin: {}", err);
|
|
return;
|
|
}
|
|
};
|
|
|
|
let mut cpu = cpu::CPU::new(Memory::new(), Nmos6502);
|
|
|
|
cpu.memory.set_bytes(0x00, &zero_page_data);
|
|
cpu.memory.set_bytes(0x10, &program);
|
|
cpu.registers.program_counter = 0x10;
|
|
|
|
cpu.run();
|
|
|
|
println!("GCD is {}", cpu.registers.accumulator);
|
|
}
|