Fixed color modes

This commit is contained in:
JJ Bliss
2026-04-27 16:32:13 -04:00
parent 3061973f1a
commit 3a32a4dec0
2 changed files with 253 additions and 35 deletions
+110 -14
View File
@@ -13,7 +13,7 @@ def HEIGHT = 480;
def DEFAULT_SCALE = 3;
export fn main() void = {
sdl3::Init(sdl3::InitFlags::VIDEO | sdl3::InitFlags::EVENTS)!;
sdl3::Init(sdl3::InitFlags::VIDEO | sdl3::InitFlags::EVENTS | sdl3::InitFlags::GAMEPAD)!;
defer sdl3::Quit();
let scale = DEFAULT_SCALE;
@@ -65,10 +65,11 @@ export fn main() void = {
const now: u64 = sdl3::GetPerformanceCounter();
if(state.running){
// fmt::printf("Next Step!\n")!;
uxn::uxn_step(state)!;
// uxn::uxn_step(state)!;
yield;
}else{
// fmt::printf("Not Running!\n")!;
if(state.console_vector != 0){
// fmt::printf("Console!\n")!;
let args = os::args[2..];
let i: u8 = 0;
let argcount = len(args): u8;
@@ -96,10 +97,12 @@ export fn main() void = {
};
i+=1; //TODO using i here seems inelegant
};
for( state.dev[0x0f] == 0; i+=1 ){
// for( state.dev[0x0f] == 0; i+=1 ){
let buf: [1]u8 = [0];
let count = io::read(os::stdin, buf)!;
// fmt::println("Read input")!;
fmt::println("About to read input")!;
// let count = io::read(os::stdin, buf)!;
let count = 0;
fmt::println("Read input")!;
if(count != 0) {
match (uxn::console_input(buf[0],1,state)) {
case done =>
@@ -109,13 +112,15 @@ export fn main() void = {
};
// fmt::println("Retuned from console_input")!;
};
};
match (uxn::console_input('\n',4,state)) { //TODO should this run?
case done =>
yield done;
case let val: u8 =>
fmt::fatalf("Unhandled Opcode: {:x}", val);
};
// };
// fmt::println("Extra input thing?!")!;
// match (uxn::console_input('\n',4,state)) { //TODO should this run?
// case done =>
// yield done;
// case let val: u8 =>
// fmt::fatalf("Unhandled Opcode: {:x}", val);
// };
// fmt::println("Finished Console!")!;
};
};
@@ -270,6 +275,96 @@ export fn main() void = {
};
case sdl3::EventType::MOUSE_WHEEL =>
fmt::printfln("Mouse Wheel!")!;
case sdl3::EventType::KEY_DOWN =>
uxn::set_key_down(ev.key.key: u8,state);
//Handle keyboard controller keys
const key = ev.key.key;
// Ctrl -> A 0x01
if(key == sdl3::K_LCTRL || key == sdl3::K_RCTRL){
uxn::set_controller_down(0x01,state);
};
// Alt -> B 0x02
if(key == sdl3::K_LALT || key == sdl3::K_RALT){
uxn::set_controller_down(0x02,state);
};
// Shift -> Select 0x04
if(key == sdl3::K_LSHIFT || key == sdl3::K_RSHIFT){
uxn::set_controller_down(0x04,state);
};
// Home -> Start 0x08
if(key == sdl3::K_HOME){
uxn::set_controller_down(0x08,state);
};
// Up -> Up 0x10
if(key == sdl3::K_UP){
uxn::set_controller_down(0x10,state);
};
// Down -> Down 0x20
if(key == sdl3::K_DOWN){
uxn::set_controller_down(0x20,state);
};
// Left -> Left 0x40
if(key == sdl3::K_LEFT){
uxn::set_controller_down(0x40,state);
};
// Right -> Right 0x80
if(key == sdl3::K_RIGHT){
uxn::set_controller_down(0x80,state);
};
match (uxn::uxn_eval(state.controller_vector, state)) {
case done =>
yield;
case uxn::quit =>
run = false;
case let err: uxn::error =>
fmt::fatalf("Error evaluating: {}", uxn::strerror(err));
};
uxn::clear_key_down(state);
case sdl3::EventType::KEY_UP =>
const key = ev.key.key;
// Ctrl -> A 0x01
if(key == sdl3::K_LCTRL || key == sdl3::K_RCTRL){
uxn::set_controller_up(0x01,state);
};
// Alt -> B 0x02
if(key == sdl3::K_LALT || key == sdl3::K_RALT){
uxn::set_controller_up(0x02,state);
};
// Shift -> Select 0x04
if(key == sdl3::K_LSHIFT || key == sdl3::K_RSHIFT){
uxn::set_controller_up(0x04,state);
};
// Home -> Start 0x08
if(key == sdl3::K_HOME){
uxn::set_controller_up(0x08,state);
};
// Up -> Up 0x10
if(key == sdl3::K_UP){
uxn::set_controller_up(0x10,state);
};
// Down -> Down 0x20
if(key == sdl3::K_DOWN){
uxn::set_controller_up(0x20,state);
};
// Left -> Left 0x40
if(key == sdl3::K_LEFT){
uxn::set_controller_up(0x40,state);
};
// Right -> Right 0x80
if(key == sdl3::K_RIGHT){
uxn::set_controller_up(0x80,state);
};
match (uxn::uxn_eval(state.controller_vector, state)) {
case done =>
yield;
case uxn::quit =>
run = false;
case let err: uxn::error =>
fmt::fatalf("Error evaluating: {}", uxn::strerror(err));
};
case sdl3::EventType::WINDOW_EXPOSED =>
sdl3::RenderClear(render)!;
sdl3::RenderTexture(render, meadow_texture, null, null)!;
@@ -296,7 +391,8 @@ export fn main() void = {
};
};
//TODO handle this in a better place
if(state.dev[0x0f] != 0) run = false;
// sdl3::RenderClear(render)!;
// sdl3::RenderTexture(render, meadow_texture, null, null)!;