Skip to content

Commit 84b3477

Browse files
committed
prelim work on a public interface
1 parent c636693 commit 84b3477

File tree

4 files changed

+75
-9
lines changed

4 files changed

+75
-9
lines changed

lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
extern crate c2rust_bitfields;
1111
pub mod z80;
1212

13-
#[cfg(tests)]
13+
#[cfg(test)]
1414
mod z80_tests;

porting-notes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
translate with;
22
https://github.com/immunant/c2rust
3+
34
to create a compilation db for makefile scripts;
45
https://github.com/nickdiego/compiledb
6+
7+
c2rust transpile --emit-build-files compile_commands.json

z80.rs

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,59 @@ pub trait z80Mem {
1212
fn write_byte(&mut self, addr: u16, value: u8);
1313
}
1414

15+
// TODO: default implementation for port
16+
1517
impl z80 {
18+
pub fn new(memory: Box<dyn z80Mem>) -> Self {
19+
z80 {
20+
memory,
21+
port_in: None,
22+
port_out: None,
23+
pc: 0,
24+
sp: 0,
25+
ix: 0,
26+
iy: 0,
27+
mem_ptr: 0,
28+
c2rust_unnamed: C2RustUnnamed_14 {
29+
c2rust_unnamed: C2RustUnnamed_15 { f: 0, a: 0, },
30+
},
31+
c2rust_unnamed_0: C2RustUnnamed_12 {
32+
c2rust_unnamed: C2RustUnnamed_13 { c: 0, b: 0, },
33+
},
34+
c2rust_unnamed_1: C2RustUnnamed_10 {
35+
c2rust_unnamed: C2RustUnnamed_11 { e: 0, d: 0, },
36+
},
37+
c2rust_unnamed_2: C2RustUnnamed_8 {
38+
c2rust_unnamed: C2RustUnnamed_9 { l: 0, h: 0, },
39+
},
40+
c2rust_unnamed_3: C2RustUnnamed_6 {
41+
c2rust_unnamed: C2RustUnnamed_7 { f_: 0, a_: 0, },
42+
},
43+
c2rust_unnamed_4: C2RustUnnamed_4 {
44+
c2rust_unnamed: C2RustUnnamed_5 { c_: 0, b_: 0, },
45+
},
46+
c2rust_unnamed_5: C2RustUnnamed_2 {
47+
c2rust_unnamed: C2RustUnnamed_3 { e_: 0, d_: 0, },
48+
},
49+
c2rust_unnamed_6: C2RustUnnamed_0 {
50+
c2rust_unnamed: C2RustUnnamed_1 { l_: 0, h_: 0, },
51+
},
52+
i: 0,
53+
r: 0,
54+
iff_delay: 0,
55+
interrupt_mode: 0,
56+
irq_data: 0,
57+
irq_pending: 0,
58+
nmi_pending: 0,
59+
iff1_iff2_halted: [0; 1],
60+
c2rust_padding: [0; 6],
61+
}
62+
}
63+
fn init(&mut self) {
1664

65+
}
1766
}
1867

19-
// setup tests
20-
// impl
21-
// add port to trait
22-
2368
#[derive(BitfieldStruct)]
2469
#[repr(C)]
2570
pub struct z80 {

z80_tests.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
1-
use crate::z80;
1+
use crate::z80::{z80, z80Mem};
22

3+
#[derive(Debug)]
4+
struct Memory {
5+
mem: [u8; 0x10000],
6+
}
37

4-
#[test]
5-
pub fn main_0() {
6-
8+
impl z80Mem for Memory {
9+
fn read_byte(&self, addr: u16) -> u8 {
10+
self.mem[addr as usize]
11+
}
712

13+
fn write_byte(&mut self, addr: u16, value: u8) {
14+
self.mem[addr as usize] = value;
815
}
16+
}
17+
18+
19+
#[test]
20+
pub fn main_0() {
21+
let memory = Memory {
22+
mem: [0; 0x10000],
23+
};
24+
let cpu = z80::new(Box::new(memory));
25+
26+
}

0 commit comments

Comments
 (0)