emu: move cpu Flags into own module
This commit is contained in:
69
src/emu/flags.rs
Normal file
69
src/emu/flags.rs
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
use std::fmt::{Debug, Formatter};
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Default)]
|
||||||
|
pub struct Flags {
|
||||||
|
pub cf: bool, // 0: Carry Flag: 1=CY(Carry), 0=NC(No Carry)
|
||||||
|
// 1: Reserved
|
||||||
|
pub pf: bool, // 2: Parity Flag: 1=PE(Even), 0=PO(Odd)
|
||||||
|
// 3: Reserved
|
||||||
|
pub af: bool, // 4: Adjust Flag: 1=AC(Aux Carry), 0=NA(No Aux Carry)
|
||||||
|
// 5: Reserved
|
||||||
|
pub zf: bool, // 6: Zero Flag: 1=ZR(Zero), 0=NZ(Not Zero)
|
||||||
|
pub sf: bool, // 7: Sign Flag: 1=NG(Negative), 0=PL(Positive)
|
||||||
|
pub tf: bool, // 8: Trap Flag
|
||||||
|
pub ie: bool, // 9: (Real name "IF") Interrupt Enable: 1=EI(Enable Interrupt), 0=DI(Disable Interrupt)
|
||||||
|
pub df: bool, // 10: Direction Flag: 1=DN(Down), 0=UP(Up)
|
||||||
|
pub of: bool, // 11: Overflow Flag: 1=OV(Overflow), 0=NV(Not Overflow)
|
||||||
|
// bits 12-15 always 1
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<u16> for Flags {
|
||||||
|
fn from(flags: u16) -> Self {
|
||||||
|
Self {
|
||||||
|
cf: flags & 1 != 0,
|
||||||
|
pf: flags & 1 << 2 != 0,
|
||||||
|
af: flags & 1 << 4 != 0,
|
||||||
|
zf: flags & 1 << 6 != 0,
|
||||||
|
sf: flags & 1 << 7 != 0,
|
||||||
|
tf: flags & 1 << 8 != 0,
|
||||||
|
ie: flags & 1 << 9 != 0,
|
||||||
|
df: flags & 1 << 10 != 0,
|
||||||
|
of: flags & 1 << 11 != 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Flags> for u16 {
|
||||||
|
fn from(flags: Flags) -> Self {
|
||||||
|
0b1111_0000_0010_1010 // Not sure what all reserved bits should be, but it shouldn't matter
|
||||||
|
| (flags.cf as u16)
|
||||||
|
| (flags.pf as u16) << 2
|
||||||
|
| (flags.af as u16) << 4
|
||||||
|
| (flags.zf as u16) << 6
|
||||||
|
| (flags.sf as u16) << 7
|
||||||
|
| (flags.tf as u16) << 8
|
||||||
|
| (flags.ie as u16) << 9
|
||||||
|
| (flags.df as u16) << 10
|
||||||
|
| (flags.of as u16) << 11
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Debug for Flags {
|
||||||
|
fn fmt(&self, fmt: &mut Formatter) -> Result<(), std::fmt::Error> {
|
||||||
|
use std::fmt::Write;
|
||||||
|
fmt.write_str("[ ")?;
|
||||||
|
for flag in [ (self.cf, "CF "),
|
||||||
|
(self.pf, "PF "),
|
||||||
|
(self.af, "AF "),
|
||||||
|
(self.zf, "ZF "),
|
||||||
|
(self.sf, "SF "),
|
||||||
|
(self.tf, "TF "),
|
||||||
|
(self.ie, "IF "),
|
||||||
|
(self.df, "DF "),
|
||||||
|
(self.of, "OF ") ].iter() {
|
||||||
|
if flag.0 { fmt.write_str(flag.1)? };
|
||||||
|
}
|
||||||
|
fmt.write_char(']')?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,11 @@
|
|||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::fmt::{Debug, Formatter};
|
use std::fmt::Debug;
|
||||||
|
|
||||||
use super::byteorder::{ByteOrder, LittleEndian};
|
use super::byteorder::{ByteOrder, LittleEndian};
|
||||||
|
|
||||||
use emu::operands::{FarPtr, Reg, RegHi, RegLo};
|
use emu::operands::{FarPtr, Reg, RegHi, RegLo};
|
||||||
use emu::operations as ops;
|
use emu::operations as ops;
|
||||||
|
use emu::flags::Flags;
|
||||||
use emu::pc::Bus;
|
use emu::pc::Bus;
|
||||||
use emu::util::segoff_to_addr;
|
use emu::util::segoff_to_addr;
|
||||||
|
|
||||||
@@ -36,23 +37,6 @@ pub struct i8088 {
|
|||||||
pub flags: Flags,
|
pub flags: Flags,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Default)]
|
|
||||||
pub struct Flags {
|
|
||||||
pub cf: bool, // 0: Carry Flag: 1=CY(Carry), 0=NC(No Carry)
|
|
||||||
// 1: Reserved
|
|
||||||
pub pf: bool, // 2: Parity Flag: 1=PE(Even), 0=PO(Odd)
|
|
||||||
// 3: Reserved
|
|
||||||
pub af: bool, // 4: Adjust Flag: 1=AC(Aux Carry), 0=NA(No Aux Carry)
|
|
||||||
// 5: Reserved
|
|
||||||
pub zf: bool, // 6: Zero Flag: 1=ZR(Zero), 0=NZ(Not Zero)
|
|
||||||
pub sf: bool, // 7: Sign Flag: 1=NG(Negative), 0=PL(Positive)
|
|
||||||
pub tf: bool, // 8: Trap Flag
|
|
||||||
pub ie: bool, // 9: (Real name "IF") Interrupt Enable: 1=EI(Enable Interrupt), 0=DI(Disable Interrupt)
|
|
||||||
pub df: bool, // 10: Direction Flag: 1=DN(Down), 0=UP(Up)
|
|
||||||
pub of: bool, // 11: Overflow Flag: 1=OV(Overflow), 0=NV(Not Overflow)
|
|
||||||
// bits 12-15 always 1
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||||
pub enum RepPrefix {
|
pub enum RepPrefix {
|
||||||
None, // No Prefix
|
None, // No Prefix
|
||||||
@@ -610,54 +594,3 @@ impl i8088 {
|
|||||||
LittleEndian::read_u16(buf)
|
LittleEndian::read_u16(buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<u16> for Flags {
|
|
||||||
fn from(flags: u16) -> Self {
|
|
||||||
Self {
|
|
||||||
cf: flags & 1 != 0,
|
|
||||||
pf: flags & 1 << 2 != 0,
|
|
||||||
af: flags & 1 << 4 != 0,
|
|
||||||
zf: flags & 1 << 6 != 0,
|
|
||||||
sf: flags & 1 << 7 != 0,
|
|
||||||
tf: flags & 1 << 8 != 0,
|
|
||||||
ie: flags & 1 << 9 != 0,
|
|
||||||
df: flags & 1 << 10 != 0,
|
|
||||||
of: flags & 1 << 11 != 0,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<Flags> for u16 {
|
|
||||||
fn from(flags: Flags) -> Self {
|
|
||||||
0b1111_0000_0010_1010 // Not sure what all reserved bits should be, but it shouldn't matter
|
|
||||||
| (flags.cf as u16)
|
|
||||||
| (flags.pf as u16) << 2
|
|
||||||
| (flags.af as u16) << 4
|
|
||||||
| (flags.zf as u16) << 6
|
|
||||||
| (flags.sf as u16) << 7
|
|
||||||
| (flags.tf as u16) << 8
|
|
||||||
| (flags.ie as u16) << 9
|
|
||||||
| (flags.df as u16) << 10
|
|
||||||
| (flags.of as u16) << 11
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Debug for Flags {
|
|
||||||
fn fmt(&self, fmt: &mut Formatter) -> Result<(), std::fmt::Error> {
|
|
||||||
use std::fmt::Write;
|
|
||||||
fmt.write_str("[ ")?;
|
|
||||||
for flag in [ (self.cf, "CF "),
|
|
||||||
(self.pf, "PF "),
|
|
||||||
(self.af, "AF "),
|
|
||||||
(self.zf, "ZF "),
|
|
||||||
(self.sf, "SF "),
|
|
||||||
(self.tf, "TF "),
|
|
||||||
(self.ie, "IF "),
|
|
||||||
(self.df, "DF "),
|
|
||||||
(self.of, "OF ") ].iter() {
|
|
||||||
if flag.0 { fmt.write_str(flag.1)? };
|
|
||||||
}
|
|
||||||
fmt.write_char(']')?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ extern crate byteorder;
|
|||||||
extern crate num_traits;
|
extern crate num_traits;
|
||||||
|
|
||||||
pub mod dos;
|
pub mod dos;
|
||||||
|
mod flags;
|
||||||
pub mod i8088;
|
pub mod i8088;
|
||||||
mod operands;
|
mod operands;
|
||||||
mod operations;
|
mod operations;
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ use std::convert::Into;
|
|||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
|
||||||
use emu::dos;
|
use emu::dos;
|
||||||
use emu::i8088::{Flags, RepPrefix, i8088};
|
use emu::flags::Flags;
|
||||||
|
use emu::i8088::{RepPrefix, i8088};
|
||||||
use emu::operands::{Address, DynLValue, FarPtr, LValue, Operand, Reg, RValue};
|
use emu::operands::{Address, DynLValue, FarPtr, LValue, Operand, Reg, RValue};
|
||||||
use emu::pc::Bus;
|
use emu::pc::Bus;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user