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

chore: moved serial regs to constants

parent 7a06d01a
No related branches found
No related tags found
No related merge requests found
Pipeline #4672 passed
...@@ -27,3 +27,7 @@ pub const HDMA2_ADDR: u16 = 0xff52; ...@@ -27,3 +27,7 @@ pub const HDMA2_ADDR: u16 = 0xff52;
pub const HDMA3_ADDR: u16 = 0xff53; pub const HDMA3_ADDR: u16 = 0xff53;
pub const HDMA4_ADDR: u16 = 0xff54; pub const HDMA4_ADDR: u16 = 0xff54;
pub const HDMA5_ADDR: u16 = 0xff55; pub const HDMA5_ADDR: u16 = 0xff55;
// Serial registers
pub const SB_ADDR: u16 = 0xff01;
pub const SC_ADDR: u16 = 0xff02;
//! Serial transfer (Link Cable) functions and structures. //! Serial transfer (Link Cable) functions and structures.
use crate::{mmu::BusComponent, warnln}; use crate::{
consts::{SB_ADDR, SC_ADDR},
mmu::BusComponent,
warnln,
};
pub trait SerialDevice { pub trait SerialDevice {
/// Sends a byte (u8) to the attached serial connection. /// Sends a byte (u8) to the attached serial connection.
...@@ -89,9 +93,9 @@ impl Serial { ...@@ -89,9 +93,9 @@ impl Serial {
pub fn read(&mut self, addr: u16) -> u8 { pub fn read(&mut self, addr: u16) -> u8 {
match addr { match addr {
// 0xFF01 — SB: Serial transfer data // 0xFF01 — SB: Serial transfer data
0xff01 => self.data, SB_ADDR => self.data,
// 0xFF02 — SC: Serial transfer control // 0xFF02 — SC: Serial transfer control
0xff02 => SC_ADDR =>
{ {
#[allow(clippy::bool_to_int_with_if)] #[allow(clippy::bool_to_int_with_if)]
(if self.shift_clock { 0x01 } else { 0x00 } (if self.shift_clock { 0x01 } else { 0x00 }
...@@ -108,9 +112,9 @@ impl Serial { ...@@ -108,9 +112,9 @@ impl Serial {
pub fn write(&mut self, addr: u16, value: u8) { pub fn write(&mut self, addr: u16, value: u8) {
match addr { match addr {
// 0xFF01 — SB: Serial transfer data // 0xFF01 — SB: Serial transfer data
0xff01 => self.data = value, SB_ADDR => self.data = value,
// 0xFF02 — SC: Serial transfer control // 0xFF02 — SC: Serial transfer control
0xff02 => { SC_ADDR => {
self.shift_clock = value & 0x01 == 0x01; self.shift_clock = value & 0x01 == 0x01;
self.clock_speed = value & 0x02 == 0x02; self.clock_speed = value & 0x02 == 0x02;
self.transferring = value & 0x80 == 0x80; self.transferring = value & 0x80 == 0x80;
......
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