misc changes
This commit is contained in:
parent
e16e71b04a
commit
33e024d565
33
src/main.rs
33
src/main.rs
|
@ -59,11 +59,15 @@ impl Machine {
|
|||
}
|
||||
|
||||
fn read(&mut self, a: Arg) -> u16 {
|
||||
match a {
|
||||
let v = match a {
|
||||
Arg::Register(r) => self.read_reg(r),
|
||||
Arg::SIN(v) => self.SIN[v as usize],
|
||||
Arg::SMAIN(v) => self.SMAIN[v as usize],
|
||||
}
|
||||
};
|
||||
|
||||
log::debug!("read {} from {:?}", v, a);
|
||||
|
||||
v
|
||||
}
|
||||
|
||||
fn write(&mut self, a: Arg, val: u16) {
|
||||
|
@ -72,6 +76,8 @@ impl Machine {
|
|||
Arg::SIN(v) => {}
|
||||
Arg::SMAIN(v) => self.SMAIN[v as usize] = val,
|
||||
}
|
||||
|
||||
log::debug!("wrote {} to {:?}", val, a);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -508,6 +514,7 @@ impl Machine {
|
|||
let arg0 = ci.args[0].as_immediate();
|
||||
self.write(ci.args[1], arg0);
|
||||
self.RSTAT.set(Flags::FZERO, arg0 == 0);
|
||||
|
||||
log::info!("copying {} to {:?}", arg0, ci.args[1]);
|
||||
}
|
||||
OP::CMP => {
|
||||
|
@ -581,6 +588,7 @@ impl Machine {
|
|||
self.RY = self.pop_stack();
|
||||
self.RX = self.pop_stack();
|
||||
self.RSTAT = Flags::from_bits(self.pop_stack()).unwrap();
|
||||
self.RSTAT.set(Flags::FZERO, true);
|
||||
self.RCALL = self.pop_stack();
|
||||
|
||||
self.push_stack(self.RTRGT);
|
||||
|
@ -652,19 +660,25 @@ impl Machine {
|
|||
self.IP += inc_by as u16;
|
||||
}
|
||||
|
||||
log::debug!("");
|
||||
|
||||
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
fn dump_instructions(mut x: &[u16]) {
|
||||
let mut offset = 1;
|
||||
while !x.is_empty() {
|
||||
let (i, inc) = parse_instruction(x);
|
||||
println!("{:04} {:?}({}) {:?}", offset, i.def.opcode(), i.def.sign(), i.args);
|
||||
x = &x[inc..];
|
||||
//println!("{:?}", i);
|
||||
offset += inc;
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// set RUST_LOG=debug or RUST_LOG=info to get more information
|
||||
env_logger::init();
|
||||
|
||||
let bin = include_bytes!("../challenge.mctf");
|
||||
|
@ -681,9 +695,18 @@ fn main() {
|
|||
let mut m = Machine::default();
|
||||
m.SIN[1..=sin.inner().len()].copy_from_slice(sin.inner());
|
||||
m.SCODE[1..=code.inner().len()].copy_from_slice(code.inner());
|
||||
m.input = b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0a".to_vec();
|
||||
m.input = vec![
|
||||
0x05,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
|
||||
0x0a];
|
||||
|
||||
// dump_instructions(&m.SCODE[1..=code.inner().len()]);
|
||||
log::debug!("{:?}", &m.SIN[1..=sin.inner().len()]);
|
||||
|
||||
dump_instructions(&m.SCODE[1..=code.inner().len()]);
|
||||
|
||||
// Return here if you don't want it to run
|
||||
|
||||
|
||||
// return;
|
||||
|
||||
while m.step() {}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue