Skip to content
Snippets Groups Projects
Verified Commit 21ce4632 authored by João Magalhães's avatar João Magalhães :rocket:
Browse files

feat: added allow slave flag

parent 6294210a
No related branches found
No related tags found
1 merge request!23Support for serial data transfer 🔌
Pipeline #2505 passed
......@@ -246,6 +246,10 @@ impl SerialDevice for PrinterDevice {
self.state = PrinterState::from_u8(self.state as u8 + 1);
}
}
fn allow_slave(&self) -> bool {
false
}
}
impl Default for PrinterDevice {
......
......@@ -23,6 +23,10 @@ impl SerialDevice for StdoutDevice {
stdout().flush().unwrap();
}
}
fn allow_slave(&self) -> bool {
false
}
}
impl Default for StdoutDevice {
......
......@@ -3,6 +3,11 @@ use crate::warnln;
pub trait SerialDevice {
fn send(&mut self) -> u8;
fn receive(&mut self, byte: u8);
/// Whether the serial device "driver" supports slave mode
/// simulating an external clock source. Or if instead the
/// clock should always be generated by the running device.
fn allow_slave(&self) -> bool;
}
pub struct Serial {
......@@ -89,15 +94,18 @@ impl Serial {
self.clock_speed = value & 0x02 == 0x02;
self.transferring = value & 0x80 == 0x80;
// @TODO: THIS SEEMS LIKE A HACK, we'll need to check with
// the device driver how to handle no communication and receive
// we must simulate no cable communication
if self.transferring && !self.shift_clock {
// in case the clock is meant to be set by the attached device
// and the current Game Boy is meant to be running in slave mode
// then checks if the attached device "driver" allows clock set
// by external device and if not then ignores the transfer request
// by immediately disabling the transferring flag
if !self.shift_clock && !self.device.allow_slave() {
self.transferring = false;
}
// in case a transfer of byte has been requested and
// this is the then we need to start the transfer setup
else if self.transferring {
if self.transferring {
// @TODO: if the GBC mode exists there should
// be special check logic here
//self.length = if self.gb.is_cgb() && self.clock_speed { 16 } else { 512 };
......@@ -189,6 +197,10 @@ impl SerialDevice for NullDevice {
}
fn receive(&mut self, _: u8) {}
fn allow_slave(&self) -> bool {
false
}
}
impl Default for NullDevice {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment