Stacker crate didn't do anything after all; fixed a couple bugs Will found, implemented shift / enter / backspace
This commit is contained in:
+1
-2
@@ -10,5 +10,4 @@ vcore = { path = "../vcore" }
|
||||
vasm = { path = "../vasm" }
|
||||
rand = "0.8.0"
|
||||
winit = "0.26.1"
|
||||
pixels = "0.9.0"
|
||||
stacker = "0.1"
|
||||
pixels = "0.9.0"
|
||||
+7
-2
@@ -33,7 +33,8 @@ fn main() {
|
||||
};
|
||||
|
||||
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()
|
||||
};
|
||||
|
||||
@@ -43,6 +44,7 @@ fn main() {
|
||||
let mut cpu = CPU::new(memory);
|
||||
display::reset(&mut cpu);
|
||||
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.start();
|
||||
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();
|
||||
draw(pixels.get_frame(), &mut cpu);
|
||||
pixels.render().expect("Problem displaying framebuffer");
|
||||
while Instant::now() < start + Duration::from_millis(25) {
|
||||
loop {
|
||||
if let Some((int, arg)) = interrupt_events.pop_front() {
|
||||
cpu.interrupt(int, arg)
|
||||
}
|
||||
for _ in 1..1000 {
|
||||
cpu.tick()
|
||||
}
|
||||
if Instant::now() > start + Duration::from_millis(25) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
|
||||
+95
-33
@@ -2,6 +2,11 @@
|
||||
screen: .equ 0x10000
|
||||
reg: .equ 16
|
||||
|
||||
lshift: .equ 0xe1
|
||||
rshift: .equ 0xe5
|
||||
enter: .equ 0x28
|
||||
backspace: .equ 0x2a
|
||||
|
||||
;;;;; Start
|
||||
push on_key
|
||||
setiv 5
|
||||
@@ -66,24 +71,71 @@ on_key:
|
||||
setint 1 ; this can be reentrant, doesn't hurt anything
|
||||
call is_press ; check for press
|
||||
#if
|
||||
call is_alpha
|
||||
brnz @putc
|
||||
call is_punc
|
||||
call is_ret
|
||||
brnz @newline
|
||||
call is_back
|
||||
brnz @handle_backspace
|
||||
call is_printable
|
||||
brnz @putc
|
||||
call is_shift
|
||||
brnz @set_shift
|
||||
; if backspace, clear cursor and dec
|
||||
pop
|
||||
ret
|
||||
#else
|
||||
; TODO:
|
||||
; if is punc, look up in punc map and print
|
||||
; if shift, set shift flag
|
||||
; if return inc cursor
|
||||
; if backspace, clear cursor and dec
|
||||
; else release:
|
||||
; if shift, clear shift flag
|
||||
call is_shift
|
||||
brnz @clear_shift
|
||||
pop
|
||||
ret
|
||||
#end
|
||||
ret
|
||||
|
||||
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
|
||||
#end
|
||||
ret
|
||||
|
||||
|
||||
set_shift:
|
||||
push shift_table
|
||||
storew current_table
|
||||
ret
|
||||
|
||||
clear_shift:
|
||||
push default_table
|
||||
storew current_table
|
||||
ret
|
||||
|
||||
is_press: ; ( event -- key bool )
|
||||
dup
|
||||
and 0xff
|
||||
@@ -91,39 +143,47 @@ is_press: ; ( event -- key bool )
|
||||
and 0xff00
|
||||
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
|
||||
sub 0x28
|
||||
brnz @+3
|
||||
pushr
|
||||
sub
|
||||
#unless ; they're equal
|
||||
popr
|
||||
pop
|
||||
ret 1
|
||||
#else ; they're not
|
||||
popr
|
||||
ret 0
|
||||
#end
|
||||
|
||||
is_alpha: ; ( key -- ch 1 ) or ( key -- key 0 )
|
||||
is_printable: ; ( key -- ch 1 ) or ( key -- key 0 )
|
||||
dup
|
||||
dup
|
||||
gt 0x03
|
||||
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
|
||||
and
|
||||
#if
|
||||
sub 0x2c
|
||||
add punc_table
|
||||
sub 0x04
|
||||
loadw current_table
|
||||
add
|
||||
load
|
||||
ret 1
|
||||
#end
|
||||
@@ -139,7 +199,9 @@ putc: ; ( ch -- ) (also modifies cursor)
|
||||
storew cursor
|
||||
ret
|
||||
|
||||
default_table: .db "abcdefghijklmnopqrstuvwxyz1234567890???? -=[]\\?;'`,./"
|
||||
shift_table: .db "ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()???? _+{}|?:\"~<>?"
|
||||
|
||||
cursor: .db screen + 40
|
||||
msg: .db "Type something:\0"
|
||||
alpha_table: .db "abcdefghijklmnopqrstuvwxyz1234567890"
|
||||
punc_table: .db " -=[]\\?;'`,./"
|
||||
current_table: .db default_table
|
||||
|
||||
Reference in New Issue
Block a user