pub struct CPU {
pub reg: Registers,
pub flags: Flags,
pub pc: u16,
pub sp: u16,
pub bus: Bus,
pub halt: bool,
pub int: (bool, u8),
pub inte: bool,
pub debug: Debug,
/* private fields */
}
Fields§
§reg: Registers
§flags: Flags
§pc: u16
§sp: u16
§bus: Bus
§halt: bool
§int: (bool, u8)
Interrupt request : true / false, instruction to execute (normally a RST command)
inte: bool
Interrupt enable bit
debug: Debug
Outputs CPU state and disassembled code to stdout after each execute()
3E 0f MVI A,$0f
PC : 0x0003 SP : 0xff00 S : 0 Z : 0 A : 0 P : 0 C : 0
B : 0x00 C : 0x00 D : 0x00 E : 0x00 H : 0x00 L : 0x00 ...
Implementations§
Source§impl CPU
impl CPU
pub fn export_snapshot(&mut self) -> Vec<u8> ⓘ
pub fn import_snapshot( &mut self, snapshot: Vec<u8>, ) -> Result<(), SnapshotError>
Source§impl CPU
impl CPU
Sourcepub fn new(size: u16) -> CPU
pub fn new(size: u16) -> CPU
Creates a new CPU instance and its 16 bits address bus.
Examples found in repository?
examples/interrupt_test.rs (line 13)
11fn load_execute() -> Result<(), Box<dyn Error>> {
12 let a: Vec<String> = env::args().collect();
13 let mut c = CPU::new(0xFFFF);
14 c.debug.switch = true;
15
16 // Loads assembled program into memory
17 c.bus.load_bin(&a[1], 0x000)?;
18
19 c.sp = 0xff00;
20 c.inte = false;
21 c.int = (true, 0xcf);
22
23 loop {
24 c.execute();
25 println!("{}\n", c.debug.string);
26 if c.pc == 0x0000 {
27 break;
28 } // if CP/M warm boot -> we exit
29 }
30 Ok(())
31}
More examples
examples/cpmrun.rs (line 13)
11fn load_execute() -> Result<(), Box<dyn Error>> {
12 let a: Vec<String> = env::args().collect();
13 let mut c = CPU::new(0xFFFF);
14 // Loads assembled program into memory
15 c.bus.load_bin(&a[1], 0x100)?;
16
17 // RET at 0x05 for mocking of CP/M BDOS system calls
18 c.bus.write_word(0x0005, 0xc9);
19
20 // Setting PC to 0x0100 (CP/M Binaries are loaded with a 256 byte offset)
21 c.pc = 0x0100;
22
23 /* Setting up stack : by disassembling CP/M software, it seems
24 that the $0006 address is read to set the stack by some programs */
25 c.bus.write_word(0x0006, 0xFF00);
26
27 /* Setting up stack in case of the program does not read the $0006 address
28 and does not set any stack. */
29 c.sp = 0xFF00;
30
31 loop {
32 c.execute();
33 if c.pc == 0x0005 {
34 bdos_call(&c)
35 }
36 if c.pc == 0x0000 {
37 break;
38 } // if CP/M warm boot -> we exit
39 }
40 Ok(())
41}
Sourcepub fn set_freq(&mut self, f: f32)
pub fn set_freq(&mut self, f: f32)
Sets CPU frequency (MHz)
use intel8080::cpu::CPU;
let mut c = CPU::new(0xFFFF);
c.set_freq(1.7); // CPU will run at 1.7 Mhz
Sourcepub fn execute_timed(&mut self) -> Option<u32>
pub fn execute_timed(&mut self) -> Option<u32>
Fetches and executes one instruction from (pc). Returns the sleep time when slice_max_cycles is reached.
Sourcepub fn execute(&mut self) -> u32
pub fn execute(&mut self) -> u32
Fetches and executes one instruction from (pc). Returns the number of consumed clock cycles. No execution speed limit.
Examples found in repository?
examples/interrupt_test.rs (line 24)
11fn load_execute() -> Result<(), Box<dyn Error>> {
12 let a: Vec<String> = env::args().collect();
13 let mut c = CPU::new(0xFFFF);
14 c.debug.switch = true;
15
16 // Loads assembled program into memory
17 c.bus.load_bin(&a[1], 0x000)?;
18
19 c.sp = 0xff00;
20 c.inte = false;
21 c.int = (true, 0xcf);
22
23 loop {
24 c.execute();
25 println!("{}\n", c.debug.string);
26 if c.pc == 0x0000 {
27 break;
28 } // if CP/M warm boot -> we exit
29 }
30 Ok(())
31}
More examples
examples/cpmrun.rs (line 32)
11fn load_execute() -> Result<(), Box<dyn Error>> {
12 let a: Vec<String> = env::args().collect();
13 let mut c = CPU::new(0xFFFF);
14 // Loads assembled program into memory
15 c.bus.load_bin(&a[1], 0x100)?;
16
17 // RET at 0x05 for mocking of CP/M BDOS system calls
18 c.bus.write_word(0x0005, 0xc9);
19
20 // Setting PC to 0x0100 (CP/M Binaries are loaded with a 256 byte offset)
21 c.pc = 0x0100;
22
23 /* Setting up stack : by disassembling CP/M software, it seems
24 that the $0006 address is read to set the stack by some programs */
25 c.bus.write_word(0x0006, 0xFF00);
26
27 /* Setting up stack in case of the program does not read the $0006 address
28 and does not set any stack. */
29 c.sp = 0xFF00;
30
31 loop {
32 c.execute();
33 if c.pc == 0x0005 {
34 bdos_call(&c)
35 }
36 if c.pc == 0x0000 {
37 break;
38 } // if CP/M warm boot -> we exit
39 }
40 Ok(())
41}
Auto Trait Implementations§
impl Freeze for CPU
impl RefUnwindSafe for CPU
impl Send for CPU
impl Sync for CPU
impl Unpin for CPU
impl UnwindSafe for CPU
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