emu: Factor out hi/lo register access
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
use emu::pc::Bus;
|
use emu::pc::Bus;
|
||||||
use emu::i8088::i8088;
|
use emu::i8088::{i8088, read_hi};
|
||||||
|
|
||||||
pub fn interrupt(cpu: &mut i8088, _bus: &mut Bus) {
|
pub fn interrupt(cpu: &mut i8088, _bus: &mut Bus) {
|
||||||
let svc = cpu.a;
|
let svc = read_hi(cpu.a);
|
||||||
match svc {
|
match svc {
|
||||||
_ => unimplemented!("dos service: {:#02X}\ncpu: {:#X?}", svc, cpu)
|
_ => unimplemented!("dos service: AH={:02X}h\ncpu: {:#X?}", svc, cpu)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,18 +120,13 @@ struct RegHi<'a> {
|
|||||||
|
|
||||||
impl<'a> LValue<u8> for RegHi<'a> {
|
impl<'a> LValue<u8> for RegHi<'a> {
|
||||||
fn write(&mut self, val: u8) {
|
fn write(&mut self, val: u8) {
|
||||||
let mut buf = [0; 2];
|
write_hi(&mut self.reg, val);
|
||||||
LittleEndian::write_u16(&mut buf, *self.reg);
|
|
||||||
buf[1] = val;
|
|
||||||
*self.reg = LittleEndian::read_u16(&buf);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> RValue<u8> for RegHi<'a> {
|
impl<'a> RValue<u8> for RegHi<'a> {
|
||||||
fn read(&self) -> u8 {
|
fn read(&self) -> u8 {
|
||||||
let mut buf = [0; 2];
|
read_hi(*self.reg)
|
||||||
LittleEndian::write_u16(&mut buf, *self.reg);
|
|
||||||
buf[1] as u8
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -220,6 +215,32 @@ pub const fn segoff_to_addr(segment: u16, offset: u16) -> usize {
|
|||||||
segaddr + offset as usize
|
segaddr + offset as usize
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn read_hi(val: u16) -> u8 {
|
||||||
|
let mut buf = [0; 2];
|
||||||
|
LittleEndian::write_u16(&mut buf, val);
|
||||||
|
buf[1] as u8
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn read_lo(val: u16) -> u8 {
|
||||||
|
let mut buf = [0; 2];
|
||||||
|
LittleEndian::write_u16(&mut buf, val);
|
||||||
|
buf[0] as u8
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn write_hi(reg: &mut u16, val: u8) {
|
||||||
|
let mut buf = [0; 2];
|
||||||
|
LittleEndian::write_u16(&mut buf, *reg);
|
||||||
|
buf[1] = val;
|
||||||
|
*reg = LittleEndian::read_u16(&buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn write_lo(reg: &mut u16, val: u8) {
|
||||||
|
let mut buf = [0; 2];
|
||||||
|
LittleEndian::write_u16(&mut buf, *reg);
|
||||||
|
buf[1] = val;
|
||||||
|
*reg = LittleEndian::read_u16(&buf);
|
||||||
|
}
|
||||||
|
|
||||||
impl i8088 {
|
impl i8088 {
|
||||||
pub fn run(&mut self, bus: &mut Bus) {
|
pub fn run(&mut self, bus: &mut Bus) {
|
||||||
loop {
|
loop {
|
||||||
|
|||||||
Reference in New Issue
Block a user