diff --git a/src/main.ha b/src/main.ha index ffcabe2..da5c187 100644 --- a/src/main.ha +++ b/src/main.ha @@ -132,6 +132,9 @@ export fn main() void = { // fmt::printfln("Setting window to width: {:x} height: {:x}", dims.width, dims.height)!; if((dims.width != 0) && (dims.height !=0)){ sdl3::DestroyTexture(meadow_texture); + free(pixeldata); + pixeldata = alloc([0...])!; //TODO figure out actual size + let w: int = dims.width: int; let h: int = dims.height: int; @@ -184,11 +187,14 @@ export fn main() void = { if((dims.width != w: u16) || (dims.height != h: u16)){ // fmt::println("Dimensions not allowed!")!; //TODO handle this maybe + uxn::set_window_size(w: u16,h: u16,state); sdl3::DestroyTexture(meadow_texture); + free(pixeldata); + pixeldata = alloc([0...])!; //TODO figure out actual size let old_w: int = dims.width: int; let old_h: int = dims.height: int; - fmt::printfln("Setting window to width: {} height: {}", w, h)!; + fmt::printfln("User setting window to width: {} height: {}", w, h)!; sdl3::SetWindowSize(win,w,h)!; meadow_texture = sdl3::CreateTexture(render, diff --git a/uxn/uxn.ha b/uxn/uxn.ha index c7b4d28..89bd9a5 100644 --- a/uxn/uxn.ha +++ b/uxn/uxn.ha @@ -64,6 +64,14 @@ export fn get_window_size(state: *uxn) struct{width: u16, height: u16} = { return result; }; +export fn set_window_size(w: u16, h: u16, state: *uxn) void = { + + state.dev[0x22] = (w >> 8): u8; + state.dev[0x23] = (w): u8; + state.dev[0x24] = (h >> 8): u8; + state.dev[0x25] = (h): u8; +}; + fn emu_dei(port: u8, state: *uxn) u8 = { let val = state.dev[port]; // fmt::printfln("Read {:x} from port {:x}", val, port)!; @@ -252,10 +260,16 @@ fn copy_sprite_to_screen(bpp2: bool, colors: u8, x: u16, y: u16, addr: u16, flip }; for(let p .. pixels){ - const color = p; //TODO handle right; - fmt::printfln("Drawing 2bpp: {} Sprite Pixel to x: {} y: {} color: {}", bpp2, x+xoff, y+yoff, p)!; - if(layer1) { state.screen.1[x+xoff][y+yoff] = p; } - else {state.screen.0[x+xoff][y+yoff] = p; }; + const color: u8 = if (bpp2){ + yield p: u8; // implement real value based on colors value + }else { + if( p == 0 ) yield 0: u8; + yield colors: u8; + + } & 0b00000011; + // fmt::printfln("Drawing 2bpp: {} Sprite Pixel to x: {} y: {} color: {}", bpp2, x+xoff, y+yoff, p)!; + if(layer1) { state.screen.1[x+xoff][y+yoff] = color; } + else {state.screen.0[x+xoff][y+yoff] = color; }; xoff += 1; if(xoff >= 8){ xoff = 0; @@ -272,7 +286,7 @@ export fn get_color(x: u16, y: u16, state: *uxn) u16 = { // check layer 1 let color = state.screen.1[x][y] & 0b00000011; if(color == 0){ - color = state.screen.0[x][y]; + color = state.screen.0[x][y] & 0b00000011; }; return state.palette[color]; };