1
0
mirror of https://github.com/danbee/8080 synced 2025-03-04 08:39:07 +00:00

Improve mnemonic formatting

This commit is contained in:
Daniel Barber 2015-12-13 19:47:52 +01:00
parent 86da1e6124
commit fc4764c5de
Signed by: danbarber
GPG Key ID: 931D8112E0103DD8

View File

@ -1,10 +1,31 @@
use std::io::{self, Read};
fn print_mnemonic(mnemonic: &str, bytes: &[u8]) {
let split_mnemonic: Vec<&str> = mnemonic.split(" ").collect();
let mut argument = "";
let mnemonic = split_mnemonic[0];
if split_mnemonic.len() == 2 {
argument = split_mnemonic[1];
}
match bytes.len() {
1 => println!("{:02x} {}", bytes[0], mnemonic),
2 => println!("{:02x} {:02x} {:5} #0x{:02x}", bytes[0], bytes[1], mnemonic, bytes[1]),
3 => println!("{:02x} {:02x} {:02x} {:5} ${:02x}{:02x}", bytes[0], bytes[1], bytes[2], mnemonic, bytes[2], bytes[1]),
1 => println!("{opcode:02x} {mnemonic:6} {arg}",
opcode = bytes[0],
mnemonic = mnemonic,
arg = argument),
2 => println!("{opcode:02x} {byte:02x} {mnemonic:6} {arg}#0x{byte:02x}",
opcode = bytes[0],
byte = bytes[1],
mnemonic = mnemonic,
arg = argument),
3 => println!("{opcode:02x} {low_byte:02x} {high_byte:02x} {mnemonic:6} {arg}${high_byte:02x}{low_byte:02x}",
opcode = bytes[0],
low_byte = bytes[1],
high_byte = bytes[2],
mnemonic = mnemonic,
arg = argument),
_ => {},
}