2021-10-28 04:01:18 +00:00
|
|
|
|
2021-11-13 19:39:20 +00:00
|
|
|
use std::rc::Rc;
|
|
|
|
use std::cell::RefCell;
|
|
|
|
|
2021-10-28 04:01:18 +00:00
|
|
|
use crate::error::Error;
|
|
|
|
use crate::system::System;
|
2021-11-13 19:39:20 +00:00
|
|
|
use crate::memory::{MemoryBlock, Bus, BusPort};
|
2021-11-16 04:51:33 +00:00
|
|
|
use crate::devices::{wrap_transmutable, Address, Addressable, Debuggable};
|
2021-10-28 04:01:18 +00:00
|
|
|
|
|
|
|
use crate::cpus::m68k::{M68k, M68kType};
|
2021-11-13 19:39:20 +00:00
|
|
|
use crate::cpus::z80::{Z80, Z80Type};
|
2021-10-28 04:01:18 +00:00
|
|
|
use crate::peripherals::genesis;
|
|
|
|
|
2021-11-13 19:39:20 +00:00
|
|
|
use crate::host::traits::{Host};
|
2021-10-28 04:01:18 +00:00
|
|
|
|
|
|
|
|
2021-11-07 04:44:25 +00:00
|
|
|
pub fn build_genesis<H: Host>(host: &mut H) -> Result<System, Error> {
|
2021-10-28 04:01:18 +00:00
|
|
|
let mut system = System::new();
|
|
|
|
|
2021-12-02 23:04:41 +00:00
|
|
|
let mut rom = MemoryBlock::load("binaries/genesis/GenTestV3.0.bin").unwrap();
|
|
|
|
//let mut rom = MemoryBlock::load("binaries/genesis/HDRV_Genesis_Test_v1_4.bin").unwrap();
|
|
|
|
//let mut rom = MemoryBlock::load("binaries/genesis/ComradeOj's tiny demo.bin").unwrap();
|
2021-11-03 22:33:22 +00:00
|
|
|
//let mut rom = MemoryBlock::load("binaries/genesis/Sonic The Hedgehog (W) (REV 00) [!].bin").unwrap();
|
|
|
|
//let mut rom = MemoryBlock::load("binaries/genesis/Sonic The Hedgehog (W) (REV 01) [!].bin").unwrap();
|
2021-11-29 19:11:32 +00:00
|
|
|
//let mut rom = MemoryBlock::load("binaries/genesis/Sonic the Hedgehog 2 (JUE) [!].bin").unwrap();
|
2021-11-03 22:33:22 +00:00
|
|
|
//let mut rom = MemoryBlock::load("binaries/genesis/Sonic the Hedgehog 3 (U) [!].bin").unwrap();
|
|
|
|
//let mut rom = MemoryBlock::load("binaries/genesis/Earthworm Jim (U) [h1].bin").unwrap();
|
|
|
|
//let mut rom = MemoryBlock::load("binaries/genesis/Home Alone (beta).bin").unwrap();
|
2021-11-07 04:44:25 +00:00
|
|
|
//let mut rom = MemoryBlock::load("binaries/genesis/F1 World Championship (JUE) [!].bin").unwrap();
|
2021-11-03 22:33:22 +00:00
|
|
|
//let mut rom = MemoryBlock::load("binaries/genesis/Ren and Stimpy's Invention (U) [!].bin").unwrap();
|
|
|
|
//let mut rom = MemoryBlock::load("binaries/genesis/Out of this World (U) [!].bin").unwrap();
|
|
|
|
//let mut rom = MemoryBlock::load("binaries/genesis/Ghostbusters (REV 00) (JUE).bin").unwrap();
|
|
|
|
//let mut rom = MemoryBlock::load("binaries/genesis/Teenage Mutant Ninja Turtles - The Hyperstone Heist (U) [!].bin").unwrap();
|
2021-12-04 21:55:58 +00:00
|
|
|
//rom.read_only();
|
2021-11-16 04:51:33 +00:00
|
|
|
let rom_end = rom.len();
|
2021-10-28 04:01:18 +00:00
|
|
|
system.add_addressable_device(0x00000000, wrap_transmutable(rom)).unwrap();
|
|
|
|
|
2021-11-16 04:51:33 +00:00
|
|
|
let nvram = MemoryBlock::new(vec![0; 0x00010000]);
|
|
|
|
system.add_addressable_device(rom_end as Address, wrap_transmutable(nvram)).unwrap();
|
|
|
|
|
2021-10-28 04:01:18 +00:00
|
|
|
let ram = MemoryBlock::new(vec![0; 0x00010000]);
|
2021-11-13 19:39:20 +00:00
|
|
|
system.add_addressable_device(0x00ff0000, wrap_transmutable(ram)).unwrap();
|
|
|
|
|
2021-10-28 04:01:18 +00:00
|
|
|
|
2021-11-13 19:39:20 +00:00
|
|
|
let coproc_bus = Rc::new(RefCell::new(Bus::new()));
|
2021-11-16 04:51:33 +00:00
|
|
|
let coproc_mem = wrap_transmutable(MemoryBlock::new(vec![0; 0x00010000]));
|
|
|
|
coproc_bus.borrow_mut().insert(0x0000, coproc_mem.borrow_mut().as_addressable().unwrap().len(), coproc_mem.clone());
|
2021-11-13 19:39:20 +00:00
|
|
|
let mut coproc = Z80::new(Z80Type::Z80, 3_579_545, BusPort::new(0, 16, 8, coproc_bus.clone()));
|
2021-11-16 04:51:33 +00:00
|
|
|
let reset = coproc.reset.clone();
|
|
|
|
let bus_request = coproc.bus_request.clone();
|
2021-10-28 04:01:18 +00:00
|
|
|
|
2021-11-16 04:51:33 +00:00
|
|
|
system.add_addressable_device(0x00a00000, coproc_mem)?;
|
2021-11-29 19:11:32 +00:00
|
|
|
//system.add_device("coproc", wrap_transmutable(coproc))?;
|
2021-10-28 04:01:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-10-31 18:00:14 +00:00
|
|
|
let controllers = genesis::controllers::GenesisController::create(host)?;
|
|
|
|
let interrupt = controllers.get_interrupt_signal();
|
2021-10-28 04:01:18 +00:00
|
|
|
system.add_addressable_device(0x00a10000, wrap_transmutable(controllers)).unwrap();
|
|
|
|
|
2021-11-16 04:51:33 +00:00
|
|
|
let coproc = genesis::coprocessor::CoprocessorCoordinator::new(reset, bus_request);
|
2021-10-28 04:01:18 +00:00
|
|
|
system.add_addressable_device(0x00a11000, wrap_transmutable(coproc)).unwrap();
|
|
|
|
|
2021-10-31 18:00:14 +00:00
|
|
|
let vdp = genesis::ym7101::Ym7101::new(host, interrupt);
|
2021-11-29 19:11:32 +00:00
|
|
|
system.add_peripheral("vdp", 0x00c00000, wrap_transmutable(vdp)).unwrap();
|
2021-10-28 04:01:18 +00:00
|
|
|
|
|
|
|
|
2021-12-04 21:55:58 +00:00
|
|
|
// TODO this is temporarily a 68010 because GenTest tests the CPU type by relying on the illegal instruction
|
|
|
|
// exception which is bypassed to Error and I don't want to un-bypass yet while testing
|
|
|
|
let mut cpu = M68k::new(M68kType::MC68010, 7_670_454, BusPort::new(0, 24, 16, system.bus.clone()));
|
2021-10-28 04:01:18 +00:00
|
|
|
|
|
|
|
//cpu.enable_tracing();
|
2021-11-03 22:33:22 +00:00
|
|
|
//cpu.add_breakpoint(0x206);
|
2021-10-28 04:01:18 +00:00
|
|
|
//cpu.add_breakpoint(0x1dd0); // Sonic: some kind of palette fading function
|
2021-10-30 23:16:09 +00:00
|
|
|
//cpu.add_breakpoint(0x16ee);
|
2021-10-28 04:01:18 +00:00
|
|
|
//cpu.decoder.dump_disassembly(&mut system, 0x206, 0x2000);
|
|
|
|
|
2021-11-03 22:33:22 +00:00
|
|
|
//cpu.add_breakpoint(0x16a0e);
|
|
|
|
//cpu.add_breakpoint(0x16812);
|
|
|
|
//cpu.add_breakpoint(0x166ec);
|
2021-11-07 04:44:25 +00:00
|
|
|
//cpu.add_breakpoint(0x13e18);
|
|
|
|
//cpu.add_breakpoint(0x16570);
|
|
|
|
//cpu.add_breakpoint(0x1714);
|
|
|
|
|
|
|
|
//cpu.add_breakpoint(0x43c2);
|
2021-11-03 22:33:22 +00:00
|
|
|
|
2021-11-29 19:11:32 +00:00
|
|
|
//cpu.add_breakpoint(0x21a);
|
|
|
|
|
2021-11-01 23:51:45 +00:00
|
|
|
system.add_interruptable_device("cpu", wrap_transmutable(cpu)).unwrap();
|
2021-10-28 04:01:18 +00:00
|
|
|
|
|
|
|
Ok(system)
|
|
|
|
}
|
|
|
|
|