holey-bytes/hbvm/src/main.rs

46 lines
1.3 KiB
Rust
Raw Normal View History

2023-05-22 14:01:13 +00:00
use hbvm::{
2023-04-22 21:06:33 +00:00
bytecode::ops::{Operations::*, RWSubTypes::*, SubTypes::*},
2023-05-06 12:33:40 +00:00
engine::Engine,
2023-04-22 18:00:19 +00:00
RuntimeErrors,
};
2023-04-18 23:08:30 +00:00
fn main() -> Result<(), RuntimeErrors> {
2023-04-22 22:17:49 +00:00
#[rustfmt::skip]
let prog: Vec<u8> = vec![
2023-05-23 03:47:29 +00:00
// NOP as u8, NOP as u8,
// 255, 10,
2023-04-22 22:17:49 +00:00
ADD as u8, EightBit as u8, 100, 20, 0xA7,
2023-05-23 03:47:29 +00:00
// ADD as u8,
// EightBit as u8, 1, 0, 0xB0,
// ADD as u8,
// SixtyFourBit as u8,
// 0, 0, 0, 0, 0, 0, 0, 0,
// 0, 0, 0, 0, 0, 0, 0, 2, 0xD0,
// SUB as u8, EightBit as u8, 255, 0, 0xA7,
// DIV as u8, EightBit as u8, 12, 5, 0xA8,
// ADD as u8, Register8 as u8, 0xA7, 0xB0, 0xA7,
// LOAD as u8, AddrToReg as u8,
// 0, 0, 0, 0, 0, 0, 0, 2,
// 0xA0,
// JUMP as u8, 0, 0, 0, 0, 0, 0, 0, 0,
2023-05-06 12:33:40 +00:00
2023-04-22 22:17:49 +00:00
];
2023-04-22 21:06:33 +00:00
2023-04-22 22:17:49 +00:00
let mut eng = Engine::new(prog);
// eng.set_timer_callback(time);
2023-05-23 03:47:29 +00:00
eng.enviroment_call_table[10] = Some(print_fn);
2023-05-06 12:33:40 +00:00
eng.run()?;
eng.dump();
println!("{:#?}", eng.registers);
2023-04-22 21:06:33 +00:00
Ok(())
}
pub fn time() -> u32 {
9
}
2023-05-06 12:33:40 +00:00
pub fn print_fn(engine: &mut Engine) -> Result<&mut Engine, u64> {
println!("hello");
Ok(engine)
2023-04-18 23:08:30 +00:00
}