diff --git a/Cargo.lock b/Cargo.lock index d7f770c..e5b360f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -950,15 +950,6 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9145ac0af1d93c638c98c40cf7d25665f427b2a44ad0a99b1dccf3e2f25bb987" -[[package]] -name = "psm" -version = "0.1.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "871372391786ccec00d3c5d3d6608905b3d4db263639cfe075d3b60a736d115a" -dependencies = [ - "cc", -] - [[package]] name = "quote" version = "1.0.18" @@ -1117,19 +1108,6 @@ dependencies = [ "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]] name = "strsim" version = "0.10.0" @@ -1240,7 +1218,6 @@ version = "0.1.0" dependencies = [ "pixels", "rand", - "stacker", "vasm", "vcore", "winit", diff --git a/vemu/Cargo.toml b/vemu/Cargo.toml index dc3f16a..4c83198 100644 --- a/vemu/Cargo.toml +++ b/vemu/Cargo.toml @@ -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" \ No newline at end of file +pixels = "0.9.0" \ No newline at end of file diff --git a/vemu/src/main.rs b/vemu/src/main.rs index 6b594e9..c76ae21 100644 --- a/vemu/src/main.rs +++ b/vemu/src/main.rs @@ -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; + } } } _ => {} diff --git a/vemu/src/typewriter.asm b/vemu/src/typewriter.asm index d0c4ad7..da5f52e 100644 --- a/vemu/src/typewriter.asm +++ b/vemu/src/typewriter.asm @@ -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 " -=[]\\?;'`,./" \ No newline at end of file +current_table: .db default_table