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

feat: made receive a delayed operation

This changes the way the device is called.
parent 5256bb2a
No related branches found
No related tags found
1 merge request!16Support for Game Boy Color (CGB) 😎🖍️
Pipeline #2595 failed
...@@ -22,6 +22,7 @@ pub struct Serial { ...@@ -22,6 +22,7 @@ pub struct Serial {
timer: i16, timer: i16,
length: u16, length: u16,
bit_count: u8, bit_count: u8,
byte_send: u8,
byte_receive: u8, byte_receive: u8,
int_serial: bool, int_serial: bool,
device: Box<dyn SerialDevice>, device: Box<dyn SerialDevice>,
...@@ -38,6 +39,7 @@ impl Serial { ...@@ -38,6 +39,7 @@ impl Serial {
timer: 0, timer: 0,
length: 512, length: 512,
bit_count: 0, bit_count: 0,
byte_send: 0x0,
byte_receive: 0x0, byte_receive: 0x0,
int_serial: false, int_serial: false,
device: Box::<NullDevice>::default(), device: Box::<NullDevice>::default(),
...@@ -53,6 +55,7 @@ impl Serial { ...@@ -53,6 +55,7 @@ impl Serial {
self.timer = 0; self.timer = 0;
self.length = 512; self.length = 512;
self.bit_count = 0; self.bit_count = 0;
self.byte_send = 0x0;
self.byte_receive = 0x0; self.byte_receive = 0x0;
self.int_serial = false; self.int_serial = false;
} }
...@@ -120,8 +123,10 @@ impl Serial { ...@@ -120,8 +123,10 @@ impl Serial {
// executes the send and receive operation immediately // executes the send and receive operation immediately
// this is considered an operational optimization with // this is considered an operational optimization with
// no real effect on the emulation (ex: no timing issues) // no real effect on the emulation (ex: no timing issues)
// then stores the byte to be sent to the device so that
// it's sent by the end of the send cycle
self.byte_receive = self.device.send(); self.byte_receive = self.device.send();
self.device.receive(self.data); self.byte_send = self.data;
} }
} }
_ => warnln!("Writing to unknown Serial location 0x{:04x}", addr), _ => warnln!("Writing to unknown Serial location 0x{:04x}", addr),
...@@ -173,6 +178,10 @@ impl Serial { ...@@ -173,6 +178,10 @@ impl Serial {
self.length = 0; self.length = 0;
self.bit_count = 0; self.bit_count = 0;
// received the byte on the device as the
// complete send operation has been performed
self.device.receive(self.byte_send);
// signals the interrupt for the serial // signals the interrupt for the serial
// transfer completion, indicating that // transfer completion, indicating that
// a new byte is ready to be read // a new byte is ready to be read
......
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