forked from Lea/invadeez
Merge pull request 'apply cargo formatting, inline format macro, fix instructions for 0xb0-0xbf' (#1) from lucy/invadeez:master into master
Reviewed-on: Lea/invadeez#1
This commit is contained in:
commit
06b9cab76a
73
bacon.toml
Normal file
73
bacon.toml
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
# This is a configuration file for the bacon tool
|
||||||
|
#
|
||||||
|
# Bacon repository: https://github.com/Canop/bacon
|
||||||
|
# Complete help on configuration: https://dystroy.org/bacon/config/
|
||||||
|
|
||||||
|
default_job = "check"
|
||||||
|
|
||||||
|
[jobs]
|
||||||
|
|
||||||
|
[jobs.check]
|
||||||
|
command = ["cargo", "check", "--color", "always"]
|
||||||
|
need_stdout = false
|
||||||
|
|
||||||
|
[jobs.check-all]
|
||||||
|
command = ["cargo", "check", "--all-targets", "--color", "always"]
|
||||||
|
need_stdout = false
|
||||||
|
watch = ["tests", "benches", "examples"]
|
||||||
|
|
||||||
|
[jobs.clippy]
|
||||||
|
command = [
|
||||||
|
"cargo",
|
||||||
|
"clippy",
|
||||||
|
"--color",
|
||||||
|
"always",
|
||||||
|
"--",
|
||||||
|
"-W",
|
||||||
|
"clippy::pedantic",
|
||||||
|
]
|
||||||
|
need_stdout = false
|
||||||
|
|
||||||
|
[jobs.clippy-all]
|
||||||
|
command = ["cargo", "clippy", "--all-targets", "--color", "always"]
|
||||||
|
need_stdout = false
|
||||||
|
watch = ["tests", "benches", "examples"]
|
||||||
|
|
||||||
|
[jobs.test]
|
||||||
|
command = ["cargo", "test", "--color", "always"]
|
||||||
|
need_stdout = true
|
||||||
|
watch = ["tests"]
|
||||||
|
|
||||||
|
[jobs.doc]
|
||||||
|
command = ["cargo", "doc", "--color", "always", "--no-deps"]
|
||||||
|
need_stdout = false
|
||||||
|
|
||||||
|
# If the doc compiles, then it opens in your browser and bacon switches
|
||||||
|
# to the previous job
|
||||||
|
[jobs.doc-open]
|
||||||
|
command = ["cargo", "doc", "--color", "always", "--no-deps", "--open"]
|
||||||
|
need_stdout = false
|
||||||
|
on_success = "back" # so that we don't open the browser at each change
|
||||||
|
|
||||||
|
# You can run your application and have the result displayed in bacon,
|
||||||
|
# *if* it makes sense for this crate. You can run an example the same
|
||||||
|
# way. Don't forget the `--color always` part or the errors won't be
|
||||||
|
# properly parsed.
|
||||||
|
# If you want to pass options to your program, a `--` separator
|
||||||
|
# will be needed.
|
||||||
|
[jobs.run]
|
||||||
|
command = ["cargo", "run", "--color", "always"]
|
||||||
|
need_stdout = true
|
||||||
|
allow_warnings = true
|
||||||
|
|
||||||
|
# You may define here keybindings that would be specific to
|
||||||
|
# a project, for example a shortcut to launch a specific job.
|
||||||
|
# Shortcuts to internal functions (scrolling, toggling, etc.)
|
||||||
|
# should go in your personal prefs.toml file instead.
|
||||||
|
[keybindings]
|
||||||
|
a = "job:check-all"
|
||||||
|
i = "job:initial"
|
||||||
|
c = "job:clippy"
|
||||||
|
d = "job:doc-open"
|
||||||
|
t = "job:test"
|
||||||
|
r = "job:run"
|
|
@ -1,11 +1,15 @@
|
||||||
use std::{env, fs};
|
#![allow(clippy::useless_format)]
|
||||||
|
#![allow(clippy::too_many_lines)]
|
||||||
use core::slice::Iter;
|
use core::slice::Iter;
|
||||||
|
use std::{env, fs};
|
||||||
|
|
||||||
const REGISTERS: [&str; 8] = ["B", "C", "D", "E", "H", "L", "M", "A"];
|
const REGISTERS: [&str; 8] = ["B", "C", "D", "E", "H", "L", "M", "A"];
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut args = env::args();
|
let mut args = env::args();
|
||||||
let filename = args.nth(1).expect("Provide a path to a file to disassemble as an argument");
|
let filename = args
|
||||||
|
.nth(1)
|
||||||
|
.expect("Provide a path to a file to disassemble as an argument");
|
||||||
let file = fs::read(filename).expect("where file");
|
let file = fs::read(filename).expect("where file");
|
||||||
let mut data = file.iter();
|
let mut data = file.iter();
|
||||||
|
|
||||||
|
@ -14,10 +18,13 @@ fn main() {
|
||||||
let mut res = String::new();
|
let mut res = String::new();
|
||||||
|
|
||||||
for _ in 0..len {
|
for _ in 0..len {
|
||||||
res.insert_str(0, format!("{:x}", data.next().expect("Expected data")).as_str());
|
res.insert_str(
|
||||||
|
0,
|
||||||
|
format!("{:x}", data.next().expect("Expected data")).as_str(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
// http://www.emulator101.com/reference/8080-by-opcode.html
|
// http://www.emulator101.com/reference/8080-by-opcode.html
|
||||||
|
@ -82,7 +89,7 @@ fn main() {
|
||||||
0x3f => format!("CMC"),
|
0x3f => format!("CMC"),
|
||||||
0x76 => format!("HLT ; Trigger interrupt"),
|
0x76 => format!("HLT ; Trigger interrupt"),
|
||||||
0x40..=0x7f // Test this!
|
0x40..=0x7f // Test this!
|
||||||
=> format!("MOV {},{}", REGISTERS[(byte & 0b111000) as usize >> 3], REGISTERS[(byte & 0b111) as usize]),
|
=> format!("MOV {},{}", REGISTERS[(byte & 0b11_1000) as usize >> 3], REGISTERS[(byte & 0b111) as usize]),
|
||||||
0x80..=0x87
|
0x80..=0x87
|
||||||
=> format!("ADD {}", REGISTERS[(byte & 0b111) as usize]),
|
=> format!("ADD {}", REGISTERS[(byte & 0b111) as usize]),
|
||||||
0x88..=0x8f
|
0x88..=0x8f
|
||||||
|
@ -96,9 +103,9 @@ fn main() {
|
||||||
0xa8..=0xaf
|
0xa8..=0xaf
|
||||||
=> format!("XRA {}", REGISTERS[(byte & 0b111) as usize]),
|
=> format!("XRA {}", REGISTERS[(byte & 0b111) as usize]),
|
||||||
0xb0..=0xb7
|
0xb0..=0xb7
|
||||||
=> format!("ANA {}", REGISTERS[(byte & 0b111) as usize]),
|
=> format!("ORA {}", REGISTERS[(byte & 0b111) as usize]),
|
||||||
0xb8..=0xbf
|
0xb8..=0xbf
|
||||||
=> format!("XRA {}", REGISTERS[(byte & 0b111) as usize]),
|
=> format!("CMP {}", REGISTERS[(byte & 0b111) as usize]),
|
||||||
0xc0 => format!("RNZ"),
|
0xc0 => format!("RNZ"),
|
||||||
0xc1 => format!("POP B"),
|
0xc1 => format!("POP B"),
|
||||||
0xc2 => format!("JNZ ${}", next(&mut data, 2)),
|
0xc2 => format!("JNZ ${}", next(&mut data, 2)),
|
||||||
|
@ -158,9 +165,9 @@ fn main() {
|
||||||
0xfc => format!("CM ${}", next(&mut data, 2)),
|
0xfc => format!("CM ${}", next(&mut data, 2)),
|
||||||
0xfe => format!("CPI #0x{}", next(&mut data, 1)),
|
0xfe => format!("CPI #0x{}", next(&mut data, 1)),
|
||||||
0xff => format!("RST 7 ; CALL $38"),
|
0xff => format!("RST 7 ; CALL $38"),
|
||||||
_ => panic!("Unimplemented instruction {:#x}", byte),
|
_ => panic!("Unimplemented instruction {byte:#x}"),
|
||||||
};
|
};
|
||||||
|
|
||||||
println!("{}", instruction);
|
println!("{instruction}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue