my first schip rom works in my schip emulator.

BUGFIX: Corrects runaway after drawing in my first schip rom
scroll down, left, right all test with test rom
assembler now assembles to the expected output it seems
fixes incorrect loading of schip font to memory
replaces schip font from new chatgpt feedback
This commit is contained in:
2024-11-05 10:02:19 -05:00
parent 434cf92414
commit 67ca71ccb7
39 changed files with 509 additions and 1052 deletions
+25 -52
View File
@@ -1,9 +1,14 @@
use std::fs;
use gemma::chip8::util::InstructionUtil;
use gemma::chip8::{instructions::Chip8CpuInstructions, quirk_modes::QuirkMode};
use std::fs::{self, File};
use std::io::Write;
// Ch8Asm
// Converts well formed CH8ASM.
// no variables.
// no labels.
// nothing fun.
// VALID FORMAT
// <INSTRUCTION> <0x|0X><parameter>[, ][<0x|OX><parameter>[, ][<0x|OX><parameter>]][; comment]
use pest::Parser;
use pest_derive::Parser;
@@ -14,62 +19,30 @@ pub struct Chip8AsmParser;
fn main() {
println!("Taxation is Theft");
let unparsed = fs::read_to_string("resources/test/gemma_disassembler_1_chip_logo_ch8_asm.asc").expect("Unable to read input");
let unparsed = fs::read_to_string("resources/test/gemma_disassembler_manual_document.asc")
.expect("Unable to read input");
let file = Chip8AsmParser::parse(Rule::file, &unparsed).expect("Unable to parse. Try again.")
.next().unwrap();
let file = Chip8AsmParser::parse(Rule::file, &unparsed)
.expect("Unable to parse. Try again.")
.next()
.unwrap();
println!("PREPARING TO WRITE THE TARGET FILE...");
let mut target_file = File::create("thisismytarget.ch8").expect("Unable to create target");
for record in file.into_inner() {
// let mut working_instruction = Chip8CpuInstructions::XXXXERRORINSTRUCTION;
match record.as_rule() {
Rule::instruction => {
println!("INSTRUCTION = {:?}", record.into_inner().flatten())
}
_ => {
println!("UNHANDLED PART.");
Rule::record => {
print!("record = {:?}\t", record.as_str());
let x = Chip8CpuInstructions::from_str(record.as_str());
println!("DECODED TO {:?} {:04x}", x, x.encode());
let (high, low) = InstructionUtil::split_bytes(x.encode());
target_file
.write_all(&[high, low])
.expect("Unable to write to the file.");
}
_ => {}
}
}
}
#[cfg(test)]
mod test {
use pest::Parser;
use crate::{Chip8AsmParser, Rule};
#[test]
fn bits_all_parse() {
println!("PARSED: {:?}",
Chip8AsmParser::parse(Rule::instruction, "CLS")
);
println!("PARSED: {:?}",
Chip8AsmParser::parse(Rule::parameter, "0x01")
);
let parsed = Chip8AsmParser::parse(Rule::comment, "; comment").unwrap();
for i in parsed {
println!("PARSED COMMENT -> {:?}", i);
}
let parsed =
Chip8AsmParser::parse(Rule::record, "CLS ; comment").unwrap();
for i in parsed {
println!("RULE PAIR THING: {:?}", i);
}
let parsed = Chip8AsmParser::parse(Rule::record, "ADDI 0x01 ; comment");
for i in parsed {
println!("RULE PAIR THING: {:?}", i);
}
println!("PARSED: {:?}",
Chip8AsmParser::parse(Rule::record, "ADD ADD ADD")
);
println!("PARSED: {:?}",
Chip8AsmParser::parse(Rule::record, "ADD 0x01 0x02 ; Comment")
);
println!("PARSED: {:?}",
Chip8AsmParser::parse(Rule::record, "ADD 0x01 0x02 ; Comment")
);
}
}
+7 -7
View File
@@ -1,7 +1,7 @@
WHITESPACE = _{ " " }
instruction = { ASCII_ALPHA+ }
parameter = { "0X" ~ ASCII_HEX_DIGIT+ }
comment = { ";" ~ WHITESPACE* ~ ASCII* }
parameters = { parameter ~ (WHITESPACE* ~ "," ~ WHITESPACE* ~ parameter)* }
record = { instruction ~ WHITESPACE* ~ parameters? ~ WHITESPACE* ~ comment? }
file = { SOI ~ (record ~ ("\r\n" | "\n"))* ~ EOI }
WHITESPACE = _{ " " | "\t" } // Allow tabs and multiple spaces
instruction = { ASCII_ALPHA+ } // Instruction, e.g., "CLS" or "LDX"
parameter = { ("0x" | "0X") ~ ASCII_HEX_DIGIT+ } // Parameter format, e.g., "0X250"
comment = { ";" ~ (!"\n" ~ ANY)* } // Capture everything after ";", up to end of line
parameters = { (parameter ~ (WHITESPACE* ~ ","* ~ WHITESPACE* ~ parameter)*)?} // Zero or more parameters
record = { instruction ~ WHITESPACE* ~ parameters ~ WHITESPACE* ~ comment? } // Record structure
file = { SOI ~ (record ~ (("\r\n" | "\n") | WHITESPACE*))* ~ EOI } // Allow for trailing newlines and empty lines