diff --git a/src/main.ha b/src/main.ha index c4b67df..48ce353 100644 --- a/src/main.ha +++ b/src/main.ha @@ -4,13 +4,17 @@ use sdl3::ttf; use types::c; use os; use io; +use bufio; use fmt; +use unix; +use unix::poll; use strings; use uxn; def WIDTH = 640; def HEIGHT = 480; def DEFAULT_SCALE = 3; +def MAX_CONSOLE_INPUT = 0x1000; export fn main() void = { sdl3::Init(sdl3::InitFlags::VIDEO | sdl3::InitFlags::EVENTS | sdl3::InitFlags::GAMEPAD)!; @@ -55,6 +59,15 @@ export fn main() void = { return; }; let path = os::args[1]; + + // let console: bufio::scanner = bufio::newscanner(os::stdin); + // defer bufio::finish(&console); + //Setting up pollfds for uni::poll + const consolefd: []unix::poll::pollfd = [unix::poll::pollfd { + fd = os::stdin_file, + events = unix::poll::event::POLLIN, + revents = 0, + } ]; let state: *uxn::uxn = uxn::uxn_init(path)!; uxn::uxn_reset(state); let next_refresh: u64 = 0; @@ -98,20 +111,50 @@ export fn main() void = { i+=1; //TODO using i here seems inelegant }; // for( state.dev[0x0f] == 0; i+=1 ){ - let buf: [1]u8 = [0]; - 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)) { + 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); - }; - // fmt::println("Retuned from console_input")!; - }; + }; + // uxn::console_input(b,1,state); + }; + // match(bufio::read_byte(os::stdin)){ + // case let b: u8 => + // match (uxn::console_input(b,1,state)) { + // case done => + // yield done; + // case let val: u8 => + // fmt::fatalf("Unhandled Opcode: {:x}", val); + // }; + // case io::EOF => + // yield; + // case let err: io::error => + // fmt::fatalf("IO Error: {}", io::strerror(err)); + + // }; + }; + + // let buf: [1]u8 = [0]; + // fmt::println("About to read input")!; + // let count = io::read(os::stdin, buf)!; + // fmt::println("Read input")!; + // if(count != 0) { + // match (uxn::console_input(buf[0],1,state)) { + // case done => + // yield done; + // case let val: u8 => + // fmt::fatalf("Unhandled Opcode: {:x}", val); + // }; + // // fmt::println("Retuned from console_input")!; + // }; // }; // fmt::println("Extra input thing?!")!; // match (uxn::console_input('\n',4,state)) { //TODO should this run?