Fixed blocking on console input
This commit is contained in:
+53
-10
@@ -4,13 +4,17 @@ use sdl3::ttf;
|
|||||||
use types::c;
|
use types::c;
|
||||||
use os;
|
use os;
|
||||||
use io;
|
use io;
|
||||||
|
use bufio;
|
||||||
use fmt;
|
use fmt;
|
||||||
|
use unix;
|
||||||
|
use unix::poll;
|
||||||
use strings;
|
use strings;
|
||||||
use uxn;
|
use uxn;
|
||||||
|
|
||||||
def WIDTH = 640;
|
def WIDTH = 640;
|
||||||
def HEIGHT = 480;
|
def HEIGHT = 480;
|
||||||
def DEFAULT_SCALE = 3;
|
def DEFAULT_SCALE = 3;
|
||||||
|
def MAX_CONSOLE_INPUT = 0x1000;
|
||||||
|
|
||||||
export fn main() void = {
|
export fn main() void = {
|
||||||
sdl3::Init(sdl3::InitFlags::VIDEO | sdl3::InitFlags::EVENTS | sdl3::InitFlags::GAMEPAD)!;
|
sdl3::Init(sdl3::InitFlags::VIDEO | sdl3::InitFlags::EVENTS | sdl3::InitFlags::GAMEPAD)!;
|
||||||
@@ -55,6 +59,15 @@ export fn main() void = {
|
|||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let path = os::args[1];
|
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)!;
|
let state: *uxn::uxn = uxn::uxn_init(path)!;
|
||||||
uxn::uxn_reset(state);
|
uxn::uxn_reset(state);
|
||||||
let next_refresh: u64 = 0;
|
let next_refresh: u64 = 0;
|
||||||
@@ -98,20 +111,50 @@ export fn main() void = {
|
|||||||
i+=1; //TODO using i here seems inelegant
|
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];
|
const pollr = unix::poll::poll(consolefd, unix::poll::NONBLOCK);
|
||||||
fmt::println("About to read input")!;
|
if(pollr > 0){
|
||||||
// let count = io::read(os::stdin, buf)!;
|
// fmt::println("Input!")!;
|
||||||
let count = 0;
|
let buf: [MAX_CONSOLE_INPUT]u8 = [0...];
|
||||||
fmt::println("Read input")!;
|
io::read(os::stdin_file, buf)!;
|
||||||
if(count != 0) {
|
for( let b .. buf ){
|
||||||
match (uxn::console_input(buf[0],1,state)) {
|
// fmt::printfln("Input: {}",buf[0])!;
|
||||||
|
match (uxn::console_input(b,1,state)) {
|
||||||
case done =>
|
case done =>
|
||||||
yield done;
|
yield done;
|
||||||
case let val: u8 =>
|
case let val: u8 =>
|
||||||
fmt::fatalf("Unhandled Opcode: {:x}", val);
|
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?!")!;
|
// fmt::println("Extra input thing?!")!;
|
||||||
// match (uxn::console_input('\n',4,state)) { //TODO should this run?
|
// match (uxn::console_input('\n',4,state)) { //TODO should this run?
|
||||||
|
|||||||
Reference in New Issue
Block a user