Fixed console input, Left works now to load files
This commit is contained in:
+20
-29
@@ -67,6 +67,7 @@ export fn main() void = {
|
|||||||
} ];
|
} ];
|
||||||
let state: *uxn::uxn = uxn::uxn_init(path)!;
|
let state: *uxn::uxn = uxn::uxn_init(path)!;
|
||||||
uxn::uxn_reset(state);
|
uxn::uxn_reset(state);
|
||||||
|
uxn::uxn_console_argument(state);
|
||||||
let next_refresh: u64 = 0;
|
let next_refresh: u64 = 0;
|
||||||
const perf_freq: u64 = sdl3::GetPerformanceFrequency();
|
const perf_freq: u64 = sdl3::GetPerformanceFrequency();
|
||||||
const frame_interval = perf_freq / 60;
|
const frame_interval = perf_freq / 60;
|
||||||
@@ -80,48 +81,38 @@ export fn main() void = {
|
|||||||
}else{
|
}else{
|
||||||
if(state.console_vector != 0){
|
if(state.console_vector != 0){
|
||||||
// fmt::printf("Console!\n")!;
|
// fmt::printf("Console!\n")!;
|
||||||
let args = os::args[2..];
|
const pollr: uint = match(unix::poll::poll(consolefd, unix::poll::NONBLOCK)){
|
||||||
let i: u8 = 0;
|
case let i: uint =>
|
||||||
let argcount = len(args): u8;
|
yield i;
|
||||||
for (let arg .. args){
|
case =>
|
||||||
// fmt::println("Console input args")!;
|
yield 0;
|
||||||
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){
|
if(pollr > 0){
|
||||||
// fmt::println("Input!")!;
|
// fmt::println("Input!")!;
|
||||||
let buf: [MAX_CONSOLE_INPUT]u8 = [0...];
|
let buf: [MAX_CONSOLE_INPUT]u8 = [0...];
|
||||||
io::read(os::stdin_file, buf)!;
|
io::read(os::stdin_file, buf)!;
|
||||||
for( let b .. buf ){
|
for( let b .. buf ){
|
||||||
// fmt::printfln("Input: {}",buf[0])!;
|
// 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)) {
|
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);
|
||||||
};
|
};
|
||||||
// uxn::console_input(b,1,state);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// fmt::printfln("Finished stdin argument")!;
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
+18
-4
@@ -1,13 +1,27 @@
|
|||||||
|
use fmt;
|
||||||
|
|
||||||
export fn console_input(c: u8, ctype: u8, state: *uxn) (done | error) = {
|
export fn console_input(c: u8, ctype: u8, state: *uxn) (done | error) = {
|
||||||
state.dev[0x12] = c;
|
state.dev[0x12] = c;
|
||||||
state.dev[0x17] = ctype;
|
state.dev[0x17] = ctype;
|
||||||
if(state.console_vector != 0){
|
if(state.console_vector != 0){
|
||||||
// fmt::println("Evaluating Console Vector")!;
|
// fmt::printfln("Evaluating Console Vector ctype: {:x} value: {:x}",ctype,c)!;
|
||||||
uxn_eval(state.console_vector, state)?;
|
match(uxn_eval(state.console_vector, state)){
|
||||||
// fmt::println("Done Evaluating Console Vector")!;
|
case done =>
|
||||||
|
state.dev[0x12] = 0;
|
||||||
|
state.dev[0x17] = 0;
|
||||||
|
return done;
|
||||||
|
case let err: error =>
|
||||||
|
state.dev[0x12] = 0;
|
||||||
|
state.dev[0x17] = 0;
|
||||||
|
return err;
|
||||||
|
case =>
|
||||||
|
state.dev[0x12] = 0;
|
||||||
|
state.dev[0x17] = 0;
|
||||||
|
return done;
|
||||||
|
};
|
||||||
}; //TODO implement eval
|
}; //TODO implement eval
|
||||||
|
state.dev[0x12] = 0;
|
||||||
|
state.dev[0x17] = 0;
|
||||||
return done;
|
return done;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+43
@@ -952,5 +952,48 @@ export fn uxn_init(path: str) ( *uxn | error ) = {
|
|||||||
};
|
};
|
||||||
export fn uxn_reset(state: *uxn) void = {
|
export fn uxn_reset(state: *uxn) void = {
|
||||||
state.running = true;
|
state.running = true;
|
||||||
|
const args = os::args[2..];
|
||||||
|
const argcount = len(args): u8;
|
||||||
|
if(argcount > 0){
|
||||||
|
state.dev[0x17] = 1;
|
||||||
|
}else {
|
||||||
|
state.dev[0x17] = 0;
|
||||||
|
};
|
||||||
uxn_eval(reset_vector,state)!;
|
uxn_eval(reset_vector,state)!;
|
||||||
|
state.dev[0x17] = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
export fn uxn_console_argument(state: *uxn) void = {
|
||||||
|
// fmt::printf("Evaluating console arguments")!;
|
||||||
|
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: {}", char: rune)!;
|
||||||
|
match (console_input(char,2,state)) {
|
||||||
|
case done =>
|
||||||
|
yield done;
|
||||||
|
case let val: u8 =>
|
||||||
|
fmt::fatalf("Unhandled Opcode: {:x}", val);
|
||||||
|
case =>
|
||||||
|
yield done;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
let ctype: u8 = if(i == (argcount - 1)){
|
||||||
|
yield 4;
|
||||||
|
} else {
|
||||||
|
yield 3;
|
||||||
|
};
|
||||||
|
match (console_input('\n',ctype,state)) {
|
||||||
|
case done =>
|
||||||
|
yield done;
|
||||||
|
case let val: u8 =>
|
||||||
|
fmt::fatalf("Unhandled Opcode: {:x}", val);
|
||||||
|
case =>
|
||||||
|
yield done;
|
||||||
|
};
|
||||||
|
i+=1; //TODO using i here seems inelegant
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user