Stacker crate didn't do anything after all; fixed a couple bugs Will found, implemented shift / enter / backspace

This commit is contained in:
2022-05-01 22:06:50 -05:00
parent 2f457ea197
commit ba55405b69
4 changed files with 103 additions and 60 deletions
Generated
-23
View File
@@ -950,15 +950,6 @@ version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9145ac0af1d93c638c98c40cf7d25665f427b2a44ad0a99b1dccf3e2f25bb987" checksum = "9145ac0af1d93c638c98c40cf7d25665f427b2a44ad0a99b1dccf3e2f25bb987"
[[package]]
name = "psm"
version = "0.1.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "871372391786ccec00d3c5d3d6608905b3d4db263639cfe075d3b60a736d115a"
dependencies = [
"cc",
]
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.18" version = "1.0.18"
@@ -1117,19 +1108,6 @@ dependencies = [
"num-traits", "num-traits",
] ]
[[package]]
name = "stacker"
version = "0.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90939d5171a4420b3ff5fbc8954d641e7377335454c259dcb80786f3f21dc9b4"
dependencies = [
"cc",
"cfg-if 1.0.0",
"libc",
"psm",
"winapi",
]
[[package]] [[package]]
name = "strsim" name = "strsim"
version = "0.10.0" version = "0.10.0"
@@ -1240,7 +1218,6 @@ version = "0.1.0"
dependencies = [ dependencies = [
"pixels", "pixels",
"rand", "rand",
"stacker",
"vasm", "vasm",
"vcore", "vcore",
"winit", "winit",
-1
View File
@@ -11,4 +11,3 @@ vasm = { path = "../vasm" }
rand = "0.8.0" rand = "0.8.0"
winit = "0.26.1" winit = "0.26.1"
pixels = "0.9.0" pixels = "0.9.0"
stacker = "0.1"
+7 -2
View File
@@ -33,7 +33,8 @@ fn main() {
}; };
let pixels = { let pixels = {
let surface_texture = SurfaceTexture::new(640, 480, &window); let winit::dpi::PhysicalSize { width, height } = window.inner_size();
let surface_texture = SurfaceTexture::new(width, height, &window);
Pixels::new(640, 480, surface_texture).unwrap() Pixels::new(640, 480, surface_texture).unwrap()
}; };
@@ -43,6 +44,7 @@ fn main() {
let mut cpu = CPU::new(memory); let mut cpu = CPU::new(memory);
display::reset(&mut cpu); display::reset(&mut cpu);
let code = assemble_snippet(include_str!("typewriter.asm").lines()).expect("Assemble error"); let code = assemble_snippet(include_str!("typewriter.asm").lines()).expect("Assemble error");
println!("ROM size: {} bytes", code.len());
cpu.poke_slice(0x400.into(), code.as_slice()); cpu.poke_slice(0x400.into(), code.as_slice());
cpu.start(); cpu.start();
window_loop(event_loop, window, pixels, cpu) window_loop(event_loop, window, pixels, cpu)
@@ -86,13 +88,16 @@ fn window_loop(event_loop: EventLoop<()>, window: Window, mut pixels: Pixels, mu
let start = Instant::now(); let start = Instant::now();
draw(pixels.get_frame(), &mut cpu); draw(pixels.get_frame(), &mut cpu);
pixels.render().expect("Problem displaying framebuffer"); pixels.render().expect("Problem displaying framebuffer");
while Instant::now() < start + Duration::from_millis(25) { loop {
if let Some((int, arg)) = interrupt_events.pop_front() { if let Some((int, arg)) = interrupt_events.pop_front() {
cpu.interrupt(int, arg) cpu.interrupt(int, arg)
} }
for _ in 1..1000 { for _ in 1..1000 {
cpu.tick() cpu.tick()
} }
if Instant::now() > start + Duration::from_millis(25) {
break;
}
} }
} }
_ => {} _ => {}
+95 -33
View File
@@ -2,6 +2,11 @@
screen: .equ 0x10000 screen: .equ 0x10000
reg: .equ 16 reg: .equ 16
lshift: .equ 0xe1
rshift: .equ 0xe5
enter: .equ 0x28
backspace: .equ 0x2a
;;;;; Start ;;;;; Start
push on_key push on_key
setiv 5 setiv 5
@@ -66,24 +71,71 @@ on_key:
setint 1 ; this can be reentrant, doesn't hurt anything setint 1 ; this can be reentrant, doesn't hurt anything
call is_press ; check for press call is_press ; check for press
#if #if
call is_alpha call is_ret
brnz @putc brnz @newline
call is_punc call is_back
brnz @handle_backspace
call is_printable
brnz @putc brnz @putc
call is_shift
brnz @set_shift
; if backspace, clear cursor and dec
pop pop
ret ret
#else #else
; TODO: call is_shift
; if is punc, look up in punc map and print brnz @clear_shift
; if shift, set shift flag pop
; if return inc cursor ret
; if backspace, clear cursor and dec #end
; else release: ret
; if shift, clear shift flag
newline:
loadw cursor
sub screen
add 40
dup
gt 40 * 30 - 1
#if
pop
push 40
#else
dup
mod 40
sub
#end
add screen
storew cursor
ret
handle_backspace:
loadw cursor
sub screen
dup
mod 40
#if
sub 1
add screen
dup
swap 32 ; a space
store
storew cursor
#else
pop pop
#end #end
ret ret
set_shift:
push shift_table
storew current_table
ret
clear_shift:
push default_table
storew current_table
ret
is_press: ; ( event -- key bool ) is_press: ; ( event -- key bool )
dup dup
and 0xff and 0xff
@@ -91,39 +143,47 @@ is_press: ; ( event -- key bool )
and 0xff00 and 0xff00
ret ret
is_ret: ; ( key -- 1 ) or ( key -- key 0 ) is_ret:
push enter
jmp is_key
is_back:
push backspace
jmp is_key
is_shift: ; ( key -- 1 ) or ( key -- key 0 )
push lshift
call is_key
brz @+2
ret 1
push rshift
jmp is_key
is_key: ; ( key1 key2 -- 1 ) or ( key1 key2 -- key1 0 )
swap
dup dup
sub 0x28 pushr
brnz @+3 sub
#unless ; they're equal
popr
pop pop
ret 1 ret 1
#else ; they're not
popr
ret 0 ret 0
#end
is_alpha: ; ( key -- ch 1 ) or ( key -- key 0 ) is_printable: ; ( key -- ch 1 ) or ( key -- key 0 )
dup dup
dup dup
gt 0x03 gt 0x03
swap swap
lt 0x28
and
#if
sub 0x04
add alpha_table
load
ret 1
#end
ret 0
is_punc: ; ( key -- ch 1 ) or (key -- key 0 )
dup
dup
gt 0x2b
swap
lt 0x39 lt 0x39
and and
#if #if
sub 0x2c sub 0x04
add punc_table loadw current_table
add
load load
ret 1 ret 1
#end #end
@@ -139,7 +199,9 @@ putc: ; ( ch -- ) (also modifies cursor)
storew cursor storew cursor
ret ret
default_table: .db "abcdefghijklmnopqrstuvwxyz1234567890???? -=[]\\?;'`,./"
shift_table: .db "ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()???? _+{}|?:\"~<>?"
cursor: .db screen + 40 cursor: .db screen + 40
msg: .db "Type something:\0" msg: .db "Type something:\0"
alpha_table: .db "abcdefghijklmnopqrstuvwxyz1234567890" current_table: .db default_table
punc_table: .db " -=[]\\?;'`,./"