Skip to content

Commit acd9ce1

Browse files
committed
test implementation complete
1 parent 62ae51a commit acd9ce1

File tree

2 files changed

+35
-10
lines changed

2 files changed

+35
-10
lines changed

z80.rs

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,32 @@ impl z80 {
120120
pub fn step(&mut self) -> u32 {
121121
unsafe { z80_step_s(self) }
122122
}
123+
fn internal_port_in(&self, addr: u16) -> u8 {
124+
#[cfg(test)]
125+
unsafe {
126+
let mut operation = self.c2rust_unnamed_0.c2rust_unnamed.c;
127+
if operation == 2{
128+
print!( "{}", self.c2rust_unnamed_1.c2rust_unnamed.e);
129+
} else if operation == 9 {
130+
let mut addr = ((self.c2rust_unnamed_1.c2rust_unnamed.d as i32)
131+
<< 8 as i32 | self.c2rust_unnamed_1.c2rust_unnamed.e as i32)
132+
as u16;
133+
loop {
134+
let fresh0 = addr;
135+
addr = addr.wrapping_add(1);
136+
print!("{}", String::from_utf8(vec![self.ctrl.read_byte(fresh0)]).unwrap());
137+
if !(self.ctrl.read_byte(addr) as i32 != '$' as i32 as i32) {
138+
break;
139+
}
140+
}
141+
}
142+
143+
}
144+
self.ctrl.port_in(addr)
145+
}
146+
fn internal_port_out(&mut self, addr: u16, value: u8) {
147+
self.ctrl.port_out(addr, value);
148+
}
123149
}
124150

125151
#[derive(Copy, Clone)]
@@ -793,15 +819,15 @@ unsafe extern "C" fn cpd(z: *mut z80) {
793819
(*z).mem_ptr = ((*z).mem_ptr as i32 - 2 as i32) as uint16_t;
794820
}
795821
unsafe extern "C" fn in_r_c(z: *mut z80, mut r: *mut uint8_t) {
796-
*r = (*z).ctrl.port_in((*z).c2rust_unnamed_0.bc);
822+
*r = (*z).internal_port_in((*z).c2rust_unnamed_0.bc);
797823
flag_set(z, zf, *r as i32 == 0 as i32);
798824
flag_set(z, sf, *r as i32 >> 7 as i32 != 0);
799825
flag_set(z, pf, parity(*r));
800826
flag_set(z, nf, 0 as i32 != 0);
801827
flag_set(z, hf, 0 as i32 != 0);
802828
}
803829
unsafe extern "C" fn ini(z: *mut z80) {
804-
let mut tmp: u32 = (*z).ctrl.port_in((*z).c2rust_unnamed_0.bc)
830+
let mut tmp: u32 = (*z).internal_port_in((*z).c2rust_unnamed_0.bc)
805831
as u32;
806832
let mut tmp2: u32 = tmp
807833
.wrapping_add(
@@ -836,7 +862,7 @@ unsafe extern "C" fn ini(z: *mut z80) {
836862
as uint8_t;
837863
}
838864
unsafe extern "C" fn ind(z: *mut z80) {
839-
let mut tmp: u32 = (*z).ctrl.port_in((*z).c2rust_unnamed_0.bc)
865+
let mut tmp: u32 = (*z).internal_port_in((*z).c2rust_unnamed_0.bc)
840866
as u32;
841867
let mut tmp2: u32 = tmp
842868
.wrapping_add(
@@ -873,7 +899,7 @@ unsafe extern "C" fn ind(z: *mut z80) {
873899
unsafe extern "C" fn outi(z: *mut z80) {
874900
let mut tmp: u32 = rb(z, (*z).c2rust_unnamed_2.hl) as u32;
875901
let mut tmp2: u32 = 0;
876-
(*z).ctrl.port_out((*z).c2rust_unnamed_0.bc, tmp as uint8_t);
902+
(*z).internal_port_out((*z).c2rust_unnamed_0.bc, tmp as uint8_t);
877903
(*z).c2rust_unnamed_2.hl = ((*z).c2rust_unnamed_2.hl).wrapping_add(1);
878904
(*z)
879905
.c2rust_unnamed_0
@@ -910,7 +936,7 @@ unsafe extern "C" fn outd(z: *mut z80) {
910936
as uint16_t;
911937
}
912938
unsafe extern "C" fn outc(z: *mut z80, mut data: uint8_t) {
913-
(*z).ctrl.port_out((*z).c2rust_unnamed_0.bc, data);
939+
(*z).internal_port_out((*z).c2rust_unnamed_0.bc, data);
914940
(*z)
915941
.mem_ptr = ((*z).c2rust_unnamed_0.bc as i32 + 1 as i32)
916942
as uint16_t;
@@ -2844,15 +2870,15 @@ unsafe extern "C" fn exec_opcode(z: *mut z80, mut opcode: uint8_t) -> u32 {
28442870
(*z)
28452871
.c2rust_unnamed
28462872
.c2rust_unnamed
2847-
.a = (*z).ctrl.port_in(port);
2873+
.a = (*z).internal_port_in(port);
28482874
(*z).mem_ptr = (port as i32 + 1 as i32) as uint16_t;
28492875
}
28502876
211 => {
28512877
cyc = cyc.wrapping_add(11 as i32 as u32);
28522878
let port_0: uint16_t = (nextb(z) as i32
28532879
| ((*z).c2rust_unnamed.c2rust_unnamed.a as i32)
28542880
<< 8 as i32) as uint16_t;
2855-
(*z).ctrl.port_out(port_0, (*z).c2rust_unnamed.c2rust_unnamed.a);
2881+
(*z).internal_port_out(port_0, (*z).c2rust_unnamed.c2rust_unnamed.a);
28562882
(*z)
28572883
.mem_ptr = (port_0 as i32 + 1 as i32
28582884
& 0xff as i32

z80_tests.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ impl z80Ctrl for Memory {
1313
fn write_byte(&mut self, addr: u16, value: u8) {
1414
self.mem[addr as usize] = value;
1515
}
16-
fn port_in(&self, addr: u16) -> u8 {
16+
fn port_in(&self, _addr: u16) -> u8 {
1717
0xff
1818
}
19-
fn port_out(&mut self, addr: u16, value: u8) {
19+
fn port_out(&mut self, _addr: u16, _value: u8) {
2020
self.test_finished = true;
2121
}
2222
fn test_finished(&self) -> bool {
@@ -35,7 +35,6 @@ fn run_test(rom: &[u8], cyc_expected: u64) {
3535
}
3636

3737
let mut cyc: u64 = 0;
38-
println!("{:#?}", 1);
3938

4039
let mut cpu = z80::new(memory);
4140
cpu.init();

0 commit comments

Comments
 (0)