pub struct Registers { /* private fields */ }Expand description
Z80 internal register values
Implementations§
Source§impl Registers
impl Registers
Sourcepub fn a(&self) -> u8
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
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}Sourcepub fn set16(&mut self, rr: Reg16, value: u16)
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.
Sourcepub fn clear_flag(&mut self, flag: Flag)
pub fn clear_flag(&mut self, flag: Flag)
Clears a flag. Sets the value to false
Sourcepub fn set_pc(&mut self, value: u16)
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
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§
Auto Trait Implementations§
impl Freeze for Registers
impl RefUnwindSafe for Registers
impl Send for Registers
impl Sync for Registers
impl Unpin for Registers
impl UnwindSafe for Registers
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more