back to functional

This commit is contained in:
Alex Janka 2023-02-06 21:00:56 +11:00
parent 98b217b858
commit acbddcb08f

View file

@ -68,12 +68,7 @@ impl Memory {
0xFEA0..0xFF00 => {
return 0x0;
}
0xFF00..0xFF4C => {
if address == 0xFF00 {
return 0xFF;
}
return self.io[(address - 0xFF00) as usize];
}
0xFF00..0xFF4C => self.get_io(address),
0xFF4C..0xFF80 => {
// println!("empty space 2 read");
return 0xFF;
@ -114,22 +109,10 @@ impl Memory {
0xFEA0..0xFF00 => {
// println!("empty space write: {:#X} to addr {:#X}", data, address);
}
0xFF04 => {
if self.user_mode {
self.io[0xFF04 - 0xFF00] = 0;
} else {
self.io[0xFF04 - 0xFF00] = data;
}
}
0xFF00..0xFF04 | 0xFF05..0xFF4C => {
0xFF00..0xFF4C => {
self.set_io(address, data);
// verbose_print!("writing to addr {:#X}\r", address);
stdout().flush().unwrap();
if address == 0xFF02 && data == 0x81 {
print!("{}", self.get(0xFF01) as char);
stdout().flush().unwrap();
}
self.io[(address - 0xFF00) as usize] = data;
}
0xFF50 => {
self.bootrom_enabled = false;
@ -147,4 +130,32 @@ impl Memory {
}
}
}
fn get_io(&self, address: Address) -> u8 {
if address == 0xFF00 {
return 0xFF;
}
return self.io[(address - 0xFF00) as usize];
}
fn set_io(&mut self, address: Address, data: u8) {
let addr_l = (address - 0xFF00) as usize;
if !self.user_mode {
self.io[addr_l] = data;
} else {
match address {
0xFF02 => {
if data == 0x81 {
print!("{}", self.get(0xFF01) as char);
stdout().flush().unwrap();
}
}
0xFF04 => self.io[addr_l] = 0,
_ => {
self.io[addr_l] = data;
// panic!("passed non-io address to io handler!");
}
}
}
}
}