From 4738b8581e932174f9ab99d21c6a24024fb6414d Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Mon, 28 Oct 2024 20:11:15 +1300 Subject: Restructure the library The main type of the library is now the BedrockEmulator type, which contains a new BedrockCore type and an instance of a user-implemented DeviceBus trait. This new structure makes it possible to hot-swap a device bus while a BedrockEmulator is running, which keeps the core and the device bus well separated. This was important when bedrock-pc was going to have two graphical emulator types and upgrade from one to the other once the screen device was accessed. The new structure also vastly simplifies the code previously required with the old Bedrock type, which was parametric over 16 device types and so needed each device type to be enumerated in every place the Bedrock type was stored. The new BedrockEmulator type is only parametric over the particular DeviceBus implementation. --- src/lib.rs | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 8fd363e..f8fa3d6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,21 +1,31 @@ -mod bedrock; -mod device_bus; mod processor; mod program_memory; mod stack; -pub use bedrock::Bedrock; -pub use device_bus::{Device, DeviceBus}; -pub use processor::Signal; pub use program_memory::ProgramMemory; pub use stack::Stack; +mod core; +mod device_bus; +mod signal; +mod emulator; + +pub use core::BedrockCore; +pub use device_bus::{Device, DeviceBus}; +pub use signal::Signal; +pub use emulator::BedrockEmulator; + + pub mod macros { #[macro_export] macro_rules! read_hh { ($v:expr) => { ($v>>24) as u8 }; } #[macro_export] macro_rules! read_hl { ($v:expr) => { ($v>>16) as u8 }; } #[macro_export] + macro_rules! read_lh { ($v:expr) => { ($v>>8) as u8 }; } + #[macro_export] + macro_rules! read_ll { ($v:expr) => { $v as u8 }; } + #[macro_export] macro_rules! read_h { ($v:expr) => { ($v>>8) as u8 }; } #[macro_export] macro_rules! read_l { ($v:expr) => { $v as u8 }; } @@ -27,6 +37,10 @@ pub mod macros { #[macro_export] macro_rules! write_hl { ($v:expr, $low:expr) => { $v = $v & 0xff00ffff | (($low as u32) << 16) }; } #[macro_export] + macro_rules! write_lh { ($v:expr, $high:expr) => { $v = $v & 0xffff00ff | (($high as u32) << 8) }; } + #[macro_export] + macro_rules! write_ll { ($v:expr, $low:expr) => { $v = $v & 0xffffff00 | ($low as u32) }; } + #[macro_export] macro_rules! write_h { ($v:expr, $high:expr) => { $v = $v & 0x00ff | (($high as u16) << 8) }; } #[macro_export] macro_rules! write_l { ($v:expr, $low:expr) => { $v = $v & 0xff00 | ($low as u16) }; } -- cgit v1.2.3-70-g09d2