more work
This commit is contained in:
parent
ad17d8f8b2
commit
92124b0efe
BIN
challenge.mctf
BIN
challenge.mctf
Binary file not shown.
11
src/main.rs
11
src/main.rs
|
@ -17,6 +17,7 @@ struct Machine {
|
||||||
SMAIN: Vec<u16>,
|
SMAIN: Vec<u16>,
|
||||||
SCODE: Vec<u16>,
|
SCODE: Vec<u16>,
|
||||||
IP: u16,
|
IP: u16,
|
||||||
|
input: Vec<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Machine {
|
impl Machine {
|
||||||
|
@ -272,6 +273,7 @@ impl Default for Machine {
|
||||||
RX: 0,
|
RX: 0,
|
||||||
RY: 0,
|
RY: 0,
|
||||||
RZ: 0,
|
RZ: 0,
|
||||||
|
input: vec![],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -517,6 +519,8 @@ impl Machine {
|
||||||
let a = self.read(ci.args[0]);
|
let a = self.read(ci.args[0]);
|
||||||
let b = self.read(ci.args[1]);
|
let b = self.read(ci.args[1]);
|
||||||
|
|
||||||
|
eprintln!("CMP({}, {})", a, b);
|
||||||
|
|
||||||
self.RSTAT.set(Flags::FZERO, a == 0 || b == 0);
|
self.RSTAT.set(Flags::FZERO, a == 0 || b == 0);
|
||||||
self.RSTAT.set(Flags::FEQUL, a == b);
|
self.RSTAT.set(Flags::FEQUL, a == b);
|
||||||
self.RSTAT.set(Flags::FLT, a < b);
|
self.RSTAT.set(Flags::FLT, a < b);
|
||||||
|
@ -546,11 +550,7 @@ impl Machine {
|
||||||
self.RSTAT.set(Flags::FZERO, val == 0);
|
self.RSTAT.set(Flags::FZERO, val == 0);
|
||||||
}
|
}
|
||||||
OP::READ => {
|
OP::READ => {
|
||||||
let mut input = 0;
|
let input = self.input.remove(0);
|
||||||
std::io::stdin().read(&mut [input]).unwrap();
|
|
||||||
|
|
||||||
if input == b'~' { input = 0; }
|
|
||||||
|
|
||||||
self.write(ci.args[0], input as u16);
|
self.write(ci.args[0], input as u16);
|
||||||
self.RSTAT.set(Flags::FZERO, input == 0);
|
self.RSTAT.set(Flags::FZERO, input == 0);
|
||||||
}
|
}
|
||||||
|
@ -658,6 +658,7 @@ fn main() {
|
||||||
let mut m = Machine::default();
|
let mut m = Machine::default();
|
||||||
m.SIN[1..=sin.inner().len()].copy_from_slice(sin.inner());
|
m.SIN[1..=sin.inner().len()].copy_from_slice(sin.inner());
|
||||||
m.SCODE[1..=code.inner().len()].copy_from_slice(code.inner());
|
m.SCODE[1..=code.inner().len()].copy_from_slice(code.inner());
|
||||||
|
m.input = b"\x0a".to_vec();
|
||||||
|
|
||||||
// dump_instructions(&m.SCODE[1..=code.inner().len()]);
|
// dump_instructions(&m.SCODE[1..=code.inner().len()]);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue