Changes for first REPL
This commit is contained in:
+1
-1
@@ -22,7 +22,7 @@ number = { dec_number | hex_number | bin_number | oct_number | dec_zero | neg_nu
|
||||
|
||||
// A label can be any sequence of C-identifier-y characters, as long as it doesn't start with
|
||||
// a digit:
|
||||
label_char = { ASCII_ALPHA_LOWER | ASCII_ALPHA_UPPER | "_" }
|
||||
label_char = { ASCII_ALPHA_LOWER | ASCII_ALPHA_UPPER | "_" | "$" }
|
||||
label = @{ label_char ~ (label_char | ASCII_DIGIT | "$")* }
|
||||
label_def = { label ~ ":" }
|
||||
|
||||
|
||||
+22
-11
@@ -182,16 +182,21 @@ pub fn assemble_snippet<T: IntoIterator<Item = String>>(
|
||||
assemble_line_results(line_results)
|
||||
}
|
||||
|
||||
/// Assemble a file from the filesystem, opening other files as it includes them.
|
||||
pub fn assemble_file(filename: &str) -> Result<Vec<u8>, AssembleError> {
|
||||
let lines = lines_from_file(filename)?;
|
||||
let line_results: Vec<Result<Line, AssembleError>> = LineSource::new(filename, lines, |file| {
|
||||
println!("Including {}", file);
|
||||
lines_from_file(file.as_str())
|
||||
}).collect();
|
||||
})
|
||||
.collect();
|
||||
|
||||
assemble_line_results(line_results)
|
||||
}
|
||||
|
||||
fn assemble_line_results(mut line_results: Vec<Result<Line, AssembleError>>) -> Result<Vec<u8>, AssembleError> {
|
||||
fn assemble_line_results(
|
||||
mut line_results: Vec<Result<Line, AssembleError>>,
|
||||
) -> Result<Vec<u8>, AssembleError> {
|
||||
if let Some(Err(error)) = line_results.iter().find(|line| line.is_err()) {
|
||||
Err(error.clone())
|
||||
} else {
|
||||
@@ -204,7 +209,8 @@ fn assemble_line_results(mut line_results: Vec<Result<Line, AssembleError>>) ->
|
||||
}
|
||||
|
||||
fn lines_from_file(filename: &str) -> Result<Vec<String>, AssembleError> {
|
||||
let file = fs::read_to_string(filename).map_err(|_e| AssembleError::FileError(filename.into()))?;
|
||||
let file =
|
||||
fs::read_to_string(filename).map_err(|_e| AssembleError::FileError(filename.into()))?;
|
||||
Ok(file.lines().map(String::from).collect())
|
||||
}
|
||||
|
||||
@@ -510,7 +516,8 @@ mod test {
|
||||
hlt
|
||||
blah: mul 2
|
||||
ret"
|
||||
.lines().map(String::from)
|
||||
.lines()
|
||||
.map(String::from)
|
||||
),
|
||||
Ok(vec![
|
||||
0x01, 0x03, // nop 3
|
||||
@@ -524,15 +531,19 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn test_relative_blanks() {
|
||||
assert_eq!(assemble_snippet(".org 0x400
|
||||
assert_eq!(
|
||||
assemble_snippet(
|
||||
".org 0x400
|
||||
nop $+2
|
||||
|
||||
nop 0x111111
|
||||
nop 0x222222".lines().map(String::from)),
|
||||
Ok(vec![
|
||||
0x03, 0x08, 0x04, 0x00,
|
||||
0x03, 0x11, 0x11, 0x11,
|
||||
0x03, 0x22, 0x22, 0x22
|
||||
]))
|
||||
nop 0x222222"
|
||||
.lines()
|
||||
.map(String::from)
|
||||
),
|
||||
Ok(vec![
|
||||
0x03, 0x08, 0x04, 0x00, 0x03, 0x11, 0x11, 0x11, 0x03, 0x22, 0x22, 0x22
|
||||
])
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+10
-3
@@ -11,8 +11,10 @@ use winit::{
|
||||
use crate::keyboard::convert_keycode;
|
||||
use pixels::{Pixels, SurfaceTexture};
|
||||
use std::collections::VecDeque;
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
use std::time::{Duration, Instant};
|
||||
use vasm::assemble_snippet;
|
||||
use vasm::{assemble_file, assemble_snippet};
|
||||
use vcore::cpu::CPU;
|
||||
use vcore::memory::{Memory, PeekPoke};
|
||||
use vcore::word::Word;
|
||||
@@ -43,7 +45,11 @@ fn main() {
|
||||
let memory = Memory::from(rng);
|
||||
let mut cpu = CPU::new(memory);
|
||||
display::reset(&mut cpu);
|
||||
let code = assemble_snippet(include_str!("typewriter.asm").lines().map(String::from)).expect("Assemble error");
|
||||
// let code = assemble_snippet(include_str!("typewriter.asm").lines().map(String::from)).expect("Assemble error");
|
||||
// let code = assemble_file("init.asm").expect("Assemble error");
|
||||
let mut file = File::open("4th.rom").expect("ROM not found");
|
||||
let mut code = Vec::new();
|
||||
file.read_to_end(&mut code).expect("Couldn't read ROM");
|
||||
println!("ROM size: {} bytes", code.len());
|
||||
cpu.poke_slice(0x400.into(), code.as_slice());
|
||||
cpu.start();
|
||||
@@ -103,7 +109,8 @@ fn window_loop(event_loop: EventLoop<()>, window: Window, mut pixels: Pixels, mu
|
||||
let start = Instant::now();
|
||||
draw(pixels.get_frame(), &mut cpu);
|
||||
pixels.render().expect("Problem displaying framebuffer");
|
||||
loop { // TODO: this will run the CPU at 100%, need to not spin while halted
|
||||
loop {
|
||||
// TODO: this will run the CPU at 100%, need to not spin while halted
|
||||
if let Some((int, arg)) = interrupt_events.pop_front() {
|
||||
cpu.interrupt(int, arg)
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ backspace: .equ 0x2a
|
||||
call set_video
|
||||
push msg
|
||||
push screen
|
||||
call print
|
||||
call print_to
|
||||
wfi_loop: hlt
|
||||
jmpr @wfi_loop
|
||||
;;;;;
|
||||
@@ -47,7 +47,7 @@ clear_screen:
|
||||
pop
|
||||
ret
|
||||
|
||||
print: ; ( msg addr -- )
|
||||
print_to: ; ( msg addr -- )
|
||||
pushr
|
||||
#while
|
||||
dup
|
||||
|
||||
Reference in New Issue
Block a user