1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
pub mod emul;
mod preamble;
mod z80;
use cpclib_asm::preamble::*;
pub use self::z80::{HasValue, Z80};
#[derive(Default, Debug, Copy, Clone)]
pub struct ListingExecution {
nops: usize
}
impl ListingExecution {
pub fn duration(&self) -> usize {
self.nops
}
}
pub fn execute_dummy_listing(lst: &Listing) -> Result<ListingExecution, String> {
let mut res = ListingExecution::default();
let mut z80 = z80::Z80::default();
for token in lst.listing().iter() {
loop {
let old_pc = z80.pc().value();
let nops = z80.execute(token);
let new_pc = z80.pc().value();
res.nops += nops;
if old_pc != new_pc {
if new_pc != old_pc + token.number_of_bytes().unwrap() as u16 {
return Err(format!("{} does not allow a sequential execution", token));
}
else {
break;
}
}
}
}
Ok(res)
}