got basic screen working with pixel drawing and filling

This commit is contained in:
JJ Bliss
2026-04-25 14:47:54 -04:00
parent 623e01d169
commit 81abb061b3
3 changed files with 113 additions and 48 deletions
+43 -5
View File
@@ -45,7 +45,7 @@ fn initialize_uxn_mem() *uxn = {
stk = [[0...],[0...]],
running = false,
screen_size_changed = false,
screen_update = false,
screen_update = true,
screen = ([[0...]...],[[0...]...]),
palette = [0...],
})!;
@@ -117,6 +117,7 @@ fn regenerate_palettes(state: *uxn) void = {
state.palette[1] = ((r & 0x0f00) >> 0) | ((g & 0x0f00) >> 4) | ((b & 0x0f00) >> 8);
state.palette[2] = ((r & 0x00f0) << 4) | ((g & 0x00f0) >> 0) | ((b & 0x00f0) >> 4);
state.palette[3] = ((r & 0x000f) << 8) | ((g & 0x000f) << 4) | ((b & 0x000f) >> 0);
// fmt::printfln("Palette Color0: {:x} Color1: {:x} Color2: {:x} Color3: {:x}", state.palette[0], state.palette[1],state.palette[2],state.palette[3])!;
};
@@ -125,11 +126,39 @@ fn draw_pixel(value: u8, state: *uxn) void = {
const color = value & 0b00000011;
const x = short_from_bytes(state.dev[0x28],state.dev[0x29]);
const y = short_from_bytes(state.dev[0x2a],state.dev[0x2b]);
if((value & 0b01000000) == 0){
state.screen.0[x][y] = color;
} else {
state.screen.1[x][y] = color;
const fill: bool = (value & 0b10000000) != 0;
const layer1: bool = (value & 0b01000000) != 0;
const flipy: bool = (value & 0b00100000) != 0;
const flipx: bool = (value & 0b00010000) != 0;
if(!fill){
// fmt::printfln("Pixel at x: {:x} y: {:x} color: {:x}", x, y, color)!;
if(!layer1){
state.screen.0[x][y] = color;
} else {
state.screen.1[x][y] = color;
};
}else{
fmt::println("Doing Fill")!;
const dims = get_window_size(state);
const startx: u16 = if(flipx) {yield 0; }else{ yield x; };
const starty: u16 = if(flipy) {yield 0; }else{ yield y; };
const endx: u16 = if(flipx) {yield x; }else{ yield dims.width; };
const endy: u16 = if(flipy) {yield y; }else{ yield dims.height; };
// fmt::printfln("Fill startx: {:x} endx: {:x} starty: {:x} endy: {:x}", startx, endx, starty, endy)!;
for(let xl = startx; xl < endx; xl+=1){
for(let yl = starty; yl < endy; yl+=1){
// fmt::printfln("Filling at x: {:x} y: {:x} color: {:x}", xl, yl, color)!;
if(!layer1){
state.screen.0[xl][yl] = color;
} else {
state.screen.1[xl][yl] = color;
};
};
};
};
state.screen_update = true;
};
@@ -803,6 +832,15 @@ export fn uxn_init(path: str) ( *uxn | error ) = {
fmt::fatalf("Error reading: {}", io::strerror(err));
};
io::close(romfile)!; //TODO, isn't there some kind of oversized roms?
//Initialize default colors TODO look for .theme files
state.dev[0x08] = 0xf0;
state.dev[0x09] = 0x7f;
state.dev[0x0a] = 0xf0;
state.dev[0x0b] = 0xd6;
state.dev[0x0c] = 0xf0;
state.dev[0x0d] = 0xb2;
regenerate_palettes(state);
return state;
};
export fn uxn_reset(state: *uxn) void = {