cleaned up some console code

This commit is contained in:
JJ Bliss
2026-05-14 10:43:19 -04:00
parent 1c13f607ee
commit 73d2af846a
4 changed files with 131 additions and 132 deletions
+15 -42
View File
@@ -74,48 +74,21 @@ export fn main() void = {
const ms_interval = perf_freq / 1000;
for (run) {
const now: u64 = sdl3::GetPerformanceCounter();
if(state.running){
// fmt::printf("Next Step!\n")!;
// uxn::uxn_step(state)!;
yield;
}else{
if(state.console_vector != 0){
// fmt::printf("Console!\n")!;
const pollr: uint = match(unix::poll::poll(consolefd, unix::poll::NONBLOCK)){
case let i: uint =>
yield i;
case =>
yield 0;
};
if(pollr > 0){
// fmt::println("Input!")!;
let buf: [MAX_CONSOLE_INPUT]u8 = [0...];
io::read(os::stdin_file, buf)!;
for( let b .. buf ){
// fmt::printfln("Input: {}",b: rune)!;
if(b == 0){
// fmt::printfln("Ending stdin argument")!;
match (uxn::console_input('\n',4,state)) {
case done =>
yield done;
case let val: u8 =>
fmt::fatalf("Unhandled Opcode: {:x}", val);
};
// fmt::printfln("Finished stdin argument")!;
break;
};
match (uxn::console_input(b,1,state)) {
case done =>
yield done;
case let val: u8 =>
fmt::fatalf("Unhandled Opcode: {:x}", val);
};
};
// fmt::printfln("Finished stdin argument")!;
};
};
if(state.console_vector != 0){
// fmt::printf("Console!\n")!;
const pollr: uint = match(unix::poll::poll(consolefd, unix::poll::NONBLOCK)){
case let i: uint =>
yield i;
case =>
yield 0;
};
if(pollr > 0){
// fmt::println("Input!")!;
let buf: [MAX_CONSOLE_INPUT]u8 = [0...];
io::read(os::stdin_file, buf)!;
uxn::console_poll(buf,state);
};
};
if(now >= next_refresh){
+18 -53
View File
@@ -25,61 +25,26 @@ export fn main() void = {
} ];
let state: *uxn::uxn = uxn::uxn_init(path)!;
uxn::uxn_reset(state);
uxn::uxn_console_argument(state);
for (run) {
if(state.running){
// fmt::printf("Next Step!\n")!;
uxn::uxn_step(state)!;
yield;
}else{
if(state.console_vector != 0){
// fmt::printf("Console!\n")!;
let args = os::args[2..];
let i: u8 = 0;
let argcount = len(args): u8;
for (let arg .. args){
// fmt::println("Console input args")!;
for(let char: u8 .. strings::toutf8(arg)){
// fmt::printfln("Console input arg char: {:x}", char)!;
match (uxn::console_input(char,2,state)) {
case done =>
yield done;
case let val: u8 =>
fmt::fatalf("Unhandled Opcode: {:x}", val);
};
};
let ctype: u8 = if(i == (argcount - 1)){
yield 4;
} else {
yield 3;
};
match (uxn::console_input('\n',ctype,state)) {
case done =>
yield done;
case let val: u8 =>
fmt::fatalf("Unhandled Opcode: {:x}", val);
};
i+=1; //TODO using i here seems inelegant
};
const pollr = unix::poll::poll(consolefd, unix::poll::NONBLOCK);
if(pollr > 0){
// fmt::println("Input!")!;
let buf: [MAX_CONSOLE_INPUT]u8 = [0...];
io::read(os::stdin_file, buf)!;
for( let b .. buf ){
// fmt::printfln("Input: {}",buf[0])!;
match (uxn::console_input(b,1,state)) {
case done =>
yield done;
case let val: u8 =>
fmt::fatalf("Unhandled Opcode: {:x}", val);
};
// uxn::console_input(b,1,state);
};
};
};
if(state.console_vector != 0){
const pollr: uint = match(unix::poll::poll(consolefd, unix::poll::NONBLOCK)){
case let i: uint =>
yield i;
case =>
yield 0;
};
if(pollr > 0){
// fmt::println("Input!")!;
let buf: [MAX_CONSOLE_INPUT]u8 = [0...];
io::read(os::stdin_file, buf)!;
uxn::console_poll(buf,state);
};
}else{
// nothing left to do...
run = false;
};
if(state.dev[0x0f] != 0) run = false;