Skip to content

Commit

Permalink
Using doom's X11 colormap, the start screen renders correctly!!
Browse files Browse the repository at this point in the history
AWESOME!!

Unfortunately, I also ran `cargo fmt`, so this commit is full of reformatting :(
  • Loading branch information
diekmann committed Mar 19, 2021
1 parent 5d08898 commit c39559f
Show file tree
Hide file tree
Showing 8 changed files with 342 additions and 41 deletions.
30 changes: 20 additions & 10 deletions doom/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,32 @@ static LIBGCC_SRC: &str = "clang_compiler_rt";
fn main() {
// libc
println!("cargo:rerun-if-changed={}", LIBC_SRC);
let status = Command::new("make").args(&["-C", LIBC_SRC, "lib/libc.a"]).status().expect("failed to start musl libc make");
if !status.success(){
let status = Command::new("make")
.args(&["-C", LIBC_SRC, "lib/libc.a"])
.status()
.expect("failed to start musl libc make");
if !status.success() {
panic!("Failed to make: {}", status);
}
println!("cargo:rustc-link-search={}/lib/", LIBC_SRC);
println!("cargo:rustc-link-lib=c");

// system headers for wasm32
let status = Command::new("make").args(&["-C", LIBC_SRC, "install-headers"]).status().expect("failed to start musl libc install-headers make");
if !status.success(){
let status = Command::new("make")
.args(&["-C", LIBC_SRC, "install-headers"])
.status()
.expect("failed to start musl libc install-headers make");
if !status.success() {
panic!("Failed to make: {}", status);
}


// compiler runtime, with e.g., floating point funtcions
println!("cargo:rerun-if-changed={}", LIBGCC_SRC);
let status = Command::new("make").args(&["-C", LIBGCC_SRC, "build/libclang_rt.builtins-wasm32.a"]).status().expect("failed to start compiler_rt make");
if !status.success(){
let status = Command::new("make")
.args(&["-C", LIBGCC_SRC, "build/libclang_rt.builtins-wasm32.a"])
.status()
.expect("failed to start compiler_rt make");
if !status.success() {
panic!("Failed to make: {}", status);
}
println!("cargo:rustc-link-search={}/build", LIBGCC_SRC);
Expand All @@ -35,11 +43,13 @@ fn main() {
//println!("cargo:rustc-link-search=foo");
//println!("cargo:rustc-link-lib=clang_rt.builtins-wasm32");


// original Doom Sources
println!("cargo:rerun-if-changed={}", DOON_SRC);
let status = Command::new("make").args(&["-C", DOON_SRC, "linux/liblinuxxdoom.a"]).status().expect("failed to start doom make");
if !status.success(){
let status = Command::new("make")
.args(&["-C", DOON_SRC, "linux/liblinuxxdoom.a"])
.status()
.expect("failed to start doom make");
if !status.success() {
panic!("Failed to make: {}", status);
}
println!("cargo:rustc-link-search={}/linux", DOON_SRC);
Expand Down
10 changes: 3 additions & 7 deletions doom/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,11 @@

function DrawCanvas(ptr) {
console.log("DrawCanvas", ptr);
var doom_screen = new Uint8Array(memory.buffer, ptr, doom_screen_width*doom_screen_height);
var doom_screen = new Uint8Array(memory.buffer, ptr, doom_screen_width*doom_screen_height*4);
var ctx = canvas.getContext('2d');
var render_screen = ctx.createImageData(doom_screen_width, doom_screen_height);
for (i=0; i < doom_screen_width*doom_screen_height; ++i) {
// TODO: this is wrong! Do I need to lookup something in a structure from XCreateColormap???
render_screen.data[i*4 +0] = ((doom_screen[i] & 0b11100000) >>> 5) * 32; // red
render_screen.data[i*4 +1] = ((doom_screen[i] & 0b00011100) >>> 2) * 32; // green
render_screen.data[i*4 +2] = ((doom_screen[i] & 0b00000011) >>> 0) * 64; // blue
render_screen.data[i*4 +3] = 255; // alpha
for (i=0; i < doom_screen_width*doom_screen_height*4; ++i) {
render_screen.data[i] = doom_screen[i]; // Is there some memcpy in JS?
}

ctx.putImageData(render_screen, 0, 0);
Expand Down
2 changes: 1 addition & 1 deletion doom/src/js_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
#[link(wasm_import_module = "js")]
extern "C" {
pub fn console_log(ptr: *const u8, len: usize);
}
}
4 changes: 2 additions & 2 deletions doom/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
extern crate lazy_static;

pub mod js_imports;
mod printf;
mod malloc;
mod printf;
mod unimplemented_libc;

#[macro_export]
Expand All @@ -15,4 +15,4 @@ macro_rules! log {
}

#[macro_export]
macro_rules! println { ($($arg:tt),*) => { log!( $( $arg )* ) }; }
macro_rules! println { ($($arg:tt),*) => { log!( $( $arg )* ) }; }
Loading

0 comments on commit c39559f

Please sign in to comment.