rustzx_core/host/
mod.rs

1mod frame_buffer;
2mod io;
3
4pub use core::time::Duration;
5pub use frame_buffer::{FrameBuffer, FrameBufferSource};
6pub use io::{BufferCursor, DataRecorder, LoadableAsset, SeekFrom, SeekableAsset};
7
8pub trait Stopwatch {
9    fn new() -> Self;
10    fn measure(&self) -> Duration;
11}
12
13pub enum Snapshot<LoadableAssetImpl: LoadableAsset> {
14    Sna(LoadableAssetImpl),
15    // TODO(#55): Implement SLT snapshot format support
16}
17
18pub enum SnapshotRecorder<DataRecorderImpl: DataRecorder> {
19    Sna(DataRecorderImpl),
20}
21
22pub enum Tape<LoadableAssetImpl: LoadableAsset> {
23    Tap(LoadableAssetImpl),
24    // TODO(#56): Implement TZX tape format support
25}
26
27pub enum Screen<LoadableAssetImpl: LoadableAsset> {
28    Scr(LoadableAssetImpl),
29}
30
31pub enum RomFormat {
32    Binary16KPages,
33}
34
35pub trait RomSet {
36    type Asset: LoadableAsset;
37
38    fn format(&self) -> RomFormat;
39    fn next_asset(&mut self) -> Option<Self::Asset>;
40}
41
42pub trait HostContext<H: Host + ?Sized>: Sized {
43    fn frame_buffer_context(&self) -> <H::FrameBuffer as FrameBuffer>::Context;
44}
45
46pub trait ScreenAsset: LoadableAsset + SeekableAsset {}
47impl<T> ScreenAsset for T where T: LoadableAsset + SeekableAsset {}
48
49pub trait SnapshotAsset: LoadableAsset + SeekableAsset {}
50impl<T> SnapshotAsset for T where T: LoadableAsset + SeekableAsset {}
51
52/// Allows to extend base rustzx-core functionality by providing
53/// interface for user-defined IO ports handling
54pub trait IoExtender {
55    /// Write byte value to io extender
56    fn write(&mut self, port: u16, data: u8);
57    /// Read byte value from io extender
58    fn read(&mut self, port: u16) -> u8;
59    /// Return true if io externder can process
60    /// incoming read/write operation for a
61    /// given port
62    fn extends_port(&self, port: u16) -> bool;
63}
64
65/// IO externder which does nothing
66pub struct StubIoExtender;
67
68impl IoExtender for StubIoExtender {
69    fn write(&mut self, _: u16, _: u8) {}
70
71    fn read(&mut self, _: u16) -> u8 {
72        0
73    }
74
75    fn extends_port(&self, _: u16) -> bool {
76        false
77    }
78}
79
80/// Allows to externd RustZX emulator with custom debug logic
81pub trait DebugInterface {
82    /// Returns true if breakpoint at given address is set and emulation should be stopped
83    fn check_pc_breakpoint(&mut self, addr: u16) -> bool;
84}
85
86/// Debug interface which does nothing
87pub struct StubDebugInterface;
88
89impl DebugInterface for StubDebugInterface {
90    fn check_pc_breakpoint(&mut self, _addr: u16) -> bool {
91        false
92    }
93}
94
95/// Represents set of required types for emulator implementation
96/// based on `rustzx-core`.
97pub trait Host {
98    /// Immutable `Context` implementation which is used to obtain host-specific
99    /// context objects for host-defined emulator parts construction (e.g. FrameBuffers)
100    type Context: HostContext<Self>;
101    /// File-like type implementation for tape loading
102    type TapeAsset: LoadableAsset + SeekableAsset;
103    /// Frame buffer implementation
104    type FrameBuffer: FrameBuffer;
105    /// Type which should provide methods to measure time intervals
106    type EmulationStopwatch: Stopwatch;
107    /// RustZX debug port implementation
108    type IoExtender: IoExtender;
109    /// Debug interface logic (e.g. breakpoints)
110    type DebugInterface: DebugInterface;
111}