Skip to content

Commit

Permalink
fix #159: add decspace and hexspace output formats
Browse files Browse the repository at this point in the history
  • Loading branch information
hlorenzi committed Feb 20, 2023
1 parent d9db883 commit 2e7e337
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 22 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,12 @@ Options:
-f, --format FORMAT The format of the output file. Possible formats:
binary, annotated, annotatedbin, binstr, hexstr,
bindump, hexdump, mif, intelhex, deccomma, hexcomma,
decc, hexc, logisim8, logisim16
decspace, hexspace, decc, hexc, logisim8, logisim16,
addrspan
-o, --output [FILE] The name of the output file.
--symbol-format SYMBOL-FORMAT
The format of the symbol file. Possible formats:
default, mesen-mlb
-s, --symbol [FILE] The name of the output symbol file.
-t, --iter [NUM] The max number of passes the assembler will attempt
(default: 10).
Expand Down
32 changes: 19 additions & 13 deletions src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ enum OutputFormat
IntelHex,
DecComma,
HexComma,
DecSpace,
HexSpace,
DecC,
HexC,
LogiSim8,
Expand Down Expand Up @@ -97,6 +99,8 @@ fn drive_inner(
Some("intelhex") => OutputFormat::IntelHex,
Some("deccomma") => OutputFormat::DecComma,
Some("hexcomma") => OutputFormat::HexComma,
Some("decspace") => OutputFormat::DecSpace,
Some("hexspace") => OutputFormat::HexSpace,
Some("decc") => OutputFormat::DecC,
Some("hexc") => OutputFormat::HexC,
Some("c") => OutputFormat::HexC,
Expand Down Expand Up @@ -214,18 +218,20 @@ fn drive_inner(
{
OutputFormat::Binary => binary.format_binary(),

OutputFormat::BinStr => binary.format_binstr () .bytes().collect(),
OutputFormat::HexStr => binary.format_hexstr () .bytes().collect(),
OutputFormat::BinDump => binary.format_bindump () .bytes().collect(),
OutputFormat::HexDump => binary.format_hexdump () .bytes().collect(),
OutputFormat::Mif => binary.format_mif () .bytes().collect(),
OutputFormat::IntelHex => binary.format_intelhex() .bytes().collect(),
OutputFormat::DecComma => binary.format_comma (10).bytes().collect(),
OutputFormat::HexComma => binary.format_comma (16).bytes().collect(),
OutputFormat::DecC => binary.format_c_array (10).bytes().collect(),
OutputFormat::HexC => binary.format_c_array (16).bytes().collect(),
OutputFormat::LogiSim8 => binary.format_logisim (8) .bytes().collect(),
OutputFormat::LogiSim16 => binary.format_logisim (16).bytes().collect(),
OutputFormat::BinStr => binary.format_binstr() .bytes().collect(),
OutputFormat::HexStr => binary.format_hexstr() .bytes().collect(),
OutputFormat::BinDump => binary.format_bindump() .bytes().collect(),
OutputFormat::HexDump => binary.format_hexdump() .bytes().collect(),
OutputFormat::Mif => binary.format_mif() .bytes().collect(),
OutputFormat::IntelHex => binary.format_intelhex() .bytes().collect(),
OutputFormat::DecComma => binary.format_separator(10, ", ").bytes().collect(),
OutputFormat::HexComma => binary.format_separator(16, ", ").bytes().collect(),
OutputFormat::DecSpace => binary.format_separator(10, " ") .bytes().collect(),
OutputFormat::HexSpace => binary.format_separator(16, " ") .bytes().collect(),
OutputFormat::DecC => binary.format_c_array(10) .bytes().collect(),
OutputFormat::HexC => binary.format_c_array(16) .bytes().collect(),
OutputFormat::LogiSim8 => binary.format_logisim(8) .bytes().collect(),
OutputFormat::LogiSim16 => binary.format_logisim(16) .bytes().collect(),

OutputFormat::AnnotatedHex => binary.format_annotated_hex(fileserver).bytes().collect(),
OutputFormat::AnnotatedBin => binary.format_annotated_bin(fileserver).bytes().collect(),
Expand Down Expand Up @@ -290,7 +296,7 @@ fn drive_inner(
fn make_opts() -> getopts::Options
{
let mut opts = getopts::Options::new();
opts.optopt("f", "format", "The format of the output file. Possible formats: binary, annotated, annotatedbin, binstr, hexstr, bindump, hexdump, mif, intelhex, deccomma, hexcomma, decc, hexc, logisim8, logisim16, addrspan", "FORMAT");
opts.optopt("f", "format", "The format of the output file. Possible formats: binary, annotated, annotatedbin, binstr, hexstr, bindump, hexdump, mif, intelhex, deccomma, hexcomma, decspace, hexspace, decc, hexc, logisim8, logisim16, addrspan", "FORMAT");
opts.opt("o", "output", "The name of the output file.", "FILE", getopts::HasArg::Maybe, getopts::Occur::Optional);
opts.optopt("", "symbol-format", "The format of the symbol file. Possible formats: default, mesen-mlb", "SYMBOL-FORMAT");
opts.opt("s", "symbol", "The name of the output symbol file.", "FILE", getopts::HasArg::Maybe, getopts::Occur::Optional);
Expand Down
4 changes: 2 additions & 2 deletions src/util/bitvec_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ impl util::BitVec
}


pub fn format_comma(&self, radix: usize) -> String
pub fn format_separator(&self, radix: usize, separator: &str) -> String
{
let mut result = String::new();

Expand All @@ -276,7 +276,7 @@ impl util::BitVec

if index < self.len()
{
result.push_str(", ");
result.push_str(separator);

if (index / 8) % 16 == 0
{ result.push('\n'); }
Expand Down
14 changes: 8 additions & 6 deletions src/webasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ pub unsafe extern fn wasm_assemble(format: u32, src: *mut String) -> *mut String
5 => Ok(binary.format_binstr ()),
6 => Ok(binary.format_mif ()),
7 => Ok(binary.format_intelhex()),
8 => Ok(binary.format_comma (10)),
9 => Ok(binary.format_comma (16)),
10 => Ok(binary.format_c_array (10)),
11 => Ok(binary.format_c_array (16)),
12 => Ok(binary.format_logisim (8)),
13 => Ok(binary.format_logisim (16)),
8 => Ok(binary.format_separator(10, ", ")),
9 => Ok(binary.format_separator(16, ", ")),
10 => Ok(binary.format_separator(10, " ")),
11 => Ok(binary.format_separator(16, " ")),
12 => Ok(binary.format_c_array (10)),
13 => Ok(binary.format_c_array (16)),
14 => Ok(binary.format_logisim (8)),
15 => Ok(binary.format_logisim (16)),
_ => unreachable!()
}
};
Expand Down
2 changes: 2 additions & 0 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@
<option>Intel HEX</option>
<option>Comma-separated Dec</option>
<option>Comma-separated Hex</option>
<option>Space-separated Dec</option>
<option>Space-separated Hex</option>
<option>C Dec Array</option>
<option>C Hex Array</option>
<option>LogiSim 8-bit</option>
Expand Down

0 comments on commit 2e7e337

Please sign in to comment.