2021-11-07 04:46:17 +00:00
|
|
|
|
2023-04-23 22:46:47 +00:00
|
|
|
use moa_core::{System, Error, Frequency, MemoryBlock, BusPort, wrap_transmutable};
|
2022-09-25 06:14:03 +00:00
|
|
|
use moa_core::host::Host;
|
2021-11-07 04:46:17 +00:00
|
|
|
|
2022-09-25 06:14:03 +00:00
|
|
|
use moa_z80::{Z80, Z80Type};
|
|
|
|
|
|
|
|
use crate::peripherals::model1::Model1Peripherals;
|
2021-11-07 04:46:17 +00:00
|
|
|
|
|
|
|
|
2021-11-11 17:52:18 +00:00
|
|
|
pub struct Trs80Options {
|
|
|
|
pub rom: String,
|
|
|
|
pub memory: u16,
|
2023-04-23 22:46:47 +00:00
|
|
|
pub frequency: Frequency,
|
2021-11-11 17:52:18 +00:00
|
|
|
}
|
|
|
|
|
2023-03-06 04:19:49 +00:00
|
|
|
impl Default for Trs80Options {
|
|
|
|
fn default() -> Self {
|
2021-11-11 17:52:18 +00:00
|
|
|
Self {
|
|
|
|
rom: "binaries/trs80/level2.rom".to_string(),
|
|
|
|
memory: 0xC000,
|
2023-04-23 22:46:47 +00:00
|
|
|
frequency: Frequency::from_hz(1_774_000),
|
2021-11-11 17:52:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-11-07 04:46:17 +00:00
|
|
|
|
2021-11-11 17:52:18 +00:00
|
|
|
|
|
|
|
pub fn build_trs80<H: Host>(host: &mut H, options: Trs80Options) -> Result<System, Error> {
|
2023-03-06 04:19:49 +00:00
|
|
|
let mut system = System::default();
|
2021-11-07 04:46:17 +00:00
|
|
|
|
2021-11-24 22:38:38 +00:00
|
|
|
let mut rom = MemoryBlock::new(vec![0; 0x3000]);
|
2021-11-11 17:52:18 +00:00
|
|
|
//rom.load_at(0x0000, "binaries/trs80/level1.rom")?;
|
2021-11-10 21:28:31 +00:00
|
|
|
//rom.load_at(0x0000, "binaries/trs80/level2.rom")?;
|
2021-11-11 17:52:18 +00:00
|
|
|
rom.load_at(0x0000, &options.rom)?;
|
2021-11-07 04:46:17 +00:00
|
|
|
rom.read_only();
|
|
|
|
system.add_addressable_device(0x0000, wrap_transmutable(rom))?;
|
|
|
|
|
2021-11-11 17:52:18 +00:00
|
|
|
let ram = MemoryBlock::new(vec![0; options.memory as usize]);
|
2021-11-07 04:46:17 +00:00
|
|
|
system.add_addressable_device(0x4000, wrap_transmutable(ram))?;
|
|
|
|
|
2022-09-25 06:14:03 +00:00
|
|
|
let model1 = Model1Peripherals::create(host)?;
|
2021-11-07 04:46:17 +00:00
|
|
|
system.add_addressable_device(0x37E0, wrap_transmutable(model1)).unwrap();
|
|
|
|
|
2021-12-13 20:00:24 +00:00
|
|
|
let cpu = Z80::new(Z80Type::Z80, options.frequency, BusPort::new(0, 16, 8, system.bus.clone()));
|
2021-11-08 06:44:40 +00:00
|
|
|
//cpu.add_breakpoint(0x0);
|
|
|
|
//cpu.add_breakpoint(0xb55);
|
|
|
|
//cpu.add_breakpoint(0xb76);
|
|
|
|
//cpu.add_breakpoint(0x1e5);
|
|
|
|
//cpu.add_breakpoint(0x340); // "exec", the function that executes the line typed in
|
|
|
|
//cpu.add_breakpoint(0x357);
|
2021-11-10 21:28:31 +00:00
|
|
|
//cpu.add_breakpoint(0x401); // LIST command exec
|
|
|
|
//cpu.add_breakpoint(0x10); // putchar
|
|
|
|
//cpu.add_breakpoint(0x970);
|
|
|
|
//cpu.add_breakpoint(0x9f9);
|
|
|
|
//cpu.add_breakpoint(0xa58); // return from printing the line number
|
|
|
|
//cpu.add_breakpoint(0xc59); // the function called first thing when printing a decimal number
|
|
|
|
//cpu.add_breakpoint(0xe00); // normalize the float??
|
|
|
|
//cpu.add_breakpoint(0x970); // just after the decimal number print function is called, but after the call at the start is complete
|
|
|
|
//cpu.add_breakpoint(0xa6c);
|
|
|
|
|
|
|
|
//cpu.add_breakpoint(0xe00);
|
|
|
|
//cpu.add_breakpoint(0xc77);
|
|
|
|
//cpu.add_breakpoint(0xc83);
|
|
|
|
//cpu.add_breakpoint(0x96d);
|
2021-11-11 17:52:18 +00:00
|
|
|
//cpu.add_breakpoint(0x970);
|
|
|
|
//cpu.add_breakpoint(0x9e2);
|
|
|
|
//cpu.add_breakpoint(0x9f9);
|
2021-11-10 21:28:31 +00:00
|
|
|
|
2021-11-07 04:46:17 +00:00
|
|
|
system.add_interruptable_device("cpu", wrap_transmutable(cpu))?;
|
|
|
|
|
|
|
|
Ok(system)
|
|
|
|
}
|
|
|
|
|