Registers

Struct Registers 

Source
pub struct Registers { /* private fields */ }
Expand description

Z80 internal register values

Implementations§

Source§

impl Registers

Source

pub fn a(&self) -> u8

Returns the value of the A register

Examples found in repository?
examples/simplest.rs (line 22)
3fn main() {
4    // Prepare the device
5    let mut machine = PlainMachine::new();
6    let mut cpu = Cpu::new();
7    cpu.set_trace(true);
8
9    // Load program inline or from a file with:
10    //      let code = include_bytes!("XXXX.rom");
11    let code = [0x3c, 0xc3, 0x00, 0x00]; // INC A, JP $0000
12    for (i, e) in code.iter().enumerate() {
13        machine.poke(i as u16, *e);
14    }
15
16    // Run emulation
17    cpu.registers().set_pc(0x0000);
18    loop {
19        cpu.execute_instruction(&mut machine);
20
21        // Examine machine state to update the hosting device as needed.
22        if cpu.registers().a() == 0x10 {
23            // Let's stop
24            break;
25        }
26    }
27}
More examples
Hide additional examples
examples/simplest8080.rs (line 22)
3fn main() {
4    // Prepare the device
5    let mut machine = PlainMachine::new();
6    let mut cpu = Cpu::new_8080();
7    cpu.set_trace(true);
8
9    // Load program inline or from a file with:
10    //      let code = include_bytes!("XXXX.rom");
11    let code = [0x3c, 0xc3, 0x00, 0x00]; // INC A, JP $0000
12    for (i, e) in code.iter().enumerate() {
13        machine.poke(i as u16, *e);
14    }
15
16    // Run emulation
17    cpu.registers().set_pc(0x0000);
18    loop {
19        cpu.execute_instruction(&mut machine);
20
21        // Examine machine state to update the hosting device as needed.
22        if cpu.registers().a() == 0x10 {
23            // Let's stop
24            break;
25        }
26    }
27}
Source

pub fn set_a(&mut self, value: u8)

Sets the A register

Source

pub fn get8(&self, reg: Reg8) -> u8

Returns the value of an 8 bit register

Source

pub fn set8(&mut self, reg: Reg8, value: u8)

Sets the value of an 8 bit register

Source

pub fn get16(&self, rr: Reg16) -> u16

Returns the value of a 16 bit register

Source

pub fn set16(&mut self, rr: Reg16, value: u16)

Sets the value of a 16 bit register. Changes the value of the two underlying 8 bit registers.

Source

pub fn get_flag(&self, flag: Flag) -> bool

Returns the value of a flag

Source

pub fn set_flag(&mut self, flag: Flag)

Sets a flag. Sets the value to true

Source

pub fn clear_flag(&mut self, flag: Flag)

Clears a flag. Sets the value to false

Source

pub fn put_flag(&mut self, flag: Flag, value: bool)

Sets the value of a flag

Source

pub fn pc(&self) -> u16

Returns the program counter

Source

pub fn set_pc(&mut self, value: u16)

Changes the program counter

Examples found in repository?
examples/simplest.rs (line 17)
3fn main() {
4    // Prepare the device
5    let mut machine = PlainMachine::new();
6    let mut cpu = Cpu::new();
7    cpu.set_trace(true);
8
9    // Load program inline or from a file with:
10    //      let code = include_bytes!("XXXX.rom");
11    let code = [0x3c, 0xc3, 0x00, 0x00]; // INC A, JP $0000
12    for (i, e) in code.iter().enumerate() {
13        machine.poke(i as u16, *e);
14    }
15
16    // Run emulation
17    cpu.registers().set_pc(0x0000);
18    loop {
19        cpu.execute_instruction(&mut machine);
20
21        // Examine machine state to update the hosting device as needed.
22        if cpu.registers().a() == 0x10 {
23            // Let's stop
24            break;
25        }
26    }
27}
More examples
Hide additional examples
examples/simplest8080.rs (line 17)
3fn main() {
4    // Prepare the device
5    let mut machine = PlainMachine::new();
6    let mut cpu = Cpu::new_8080();
7    cpu.set_trace(true);
8
9    // Load program inline or from a file with:
10    //      let code = include_bytes!("XXXX.rom");
11    let code = [0x3c, 0xc3, 0x00, 0x00]; // INC A, JP $0000
12    for (i, e) in code.iter().enumerate() {
13        machine.poke(i as u16, *e);
14    }
15
16    // Run emulation
17    cpu.registers().set_pc(0x0000);
18    loop {
19        cpu.execute_instruction(&mut machine);
20
21        // Examine machine state to update the hosting device as needed.
22        if cpu.registers().a() == 0x10 {
23            // Let's stop
24            break;
25        }
26    }
27}
examples/cpuville.rs (line 38)
20fn main() {
21    let mut machine = VilleMachine::new();
22    let mut cpu = Cpu::new();
23    let mut timed_runner = TimedRunner::default();
24    timed_runner.set_mhz(&cpu, MHZ, 1000);
25
26    // Init console
27    let mut stdout = stdout();
28    let stdin_channel = spawn_stdin_channel();
29    let mut in_char_waiting = false;
30
31    // Load program
32    let code = TINY_BASIC;
33    for (i, e) in code.iter().enumerate() {
34        machine.poke(i as u16, *e);
35    }
36
37    // Init
38    cpu.registers().set_pc(0x0000);
39    machine.in_values[3] = 1; // TX Ready
40
41    loop {
42        timed_runner.execute(&mut cpu, &mut machine);
43
44        if let Some(port) = machine.out_port {
45            match port {
46                2 => {
47                    print!("{}", machine.out_value as char);
48                    stdout.flush().unwrap();
49                },
50                3 => {},
51                _ => panic!("BDOS command not implemented")
52            }
53            machine.out_port = None;
54        }
55
56        if let Some(port) = machine.in_port {
57            match port {
58                2 => {
59                    in_char_waiting = false;
60                },
61                3 => {},
62                _ => panic!("BDOS command not implemented")
63            }
64            machine.in_port = None;
65
66            // Avoid 100% CPU usage waiting for input.
67            if MHZ == 0.0 {
68                thread::sleep(Duration::from_millis(1));  
69            }
70        }
71
72        if !in_char_waiting {
73            // Let's get another char if available
74            match stdin_channel.try_recv() {
75                Ok(key) => {
76                    machine.in_values[2] = key;
77                    in_char_waiting = true;
78                    machine.in_values[3] = 3; // RX Ready
79                },
80                Err(TryRecvError::Empty) => {
81                    machine.in_values[3] = 1; // RX Not ready
82                },
83                Err(TryRecvError::Disconnected) => {},
84            }
85        }
86    }
87}

Trait Implementations§

Source§

impl Debug for Registers

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.