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
+28 -36
View File
@@ -6,7 +6,6 @@ use bufio;
use bytes;
use time;
use time::date;
use strings;
export type uxn = struct {
pc: u16,
@@ -14,6 +13,7 @@ export type uxn = struct {
screen_vector: u16,
mouse_vector: u16,
controller_vector: u16,
audio_vectors: [4] u16,
ram: [BANKS_CAP] u8,
dev: [0x100] u8,
ptr: [2] u8,
@@ -69,6 +69,7 @@ fn initialize_uxn_mem() *uxn = {
screen_vector = 0,
mouse_vector = 0,
controller_vector = 0,
audio_vectors = [0...],
ram = [0...],
dev = [0...],
ptr = [0...],
@@ -178,7 +179,7 @@ export fn emu_deo(port: u8, value: u8, state: *uxn) void = {
const low = value;
state.console_vector = short_from_bytes(high,low);
case 0x18 =>
fmt::print(value: rune)!;
console_output(value: rune,state);
case 0x19 =>
fmt::error(value)!;
case 0x21 =>
@@ -189,6 +190,31 @@ export fn emu_deo(port: u8, value: u8, state: *uxn) void = {
draw_pixel(value,state);
case 0x2f =>
draw_sprite(value,state);
case 0x31 =>
const high = state.dev[0x30];
const low = value;
state.audio_vectors[0] = short_from_bytes(high,low);
case 0x3f =>
audio_pitch(0,state);
case 0x41 =>
const high = state.dev[0x40];
const low = value;
state.audio_vectors[1] = short_from_bytes(high,low);
case 0x4f =>
audio_pitch(1,state);
case 0x51 =>
const high = state.dev[0x50];
const low = value;
state.audio_vectors[2] = short_from_bytes(high,low);
case 0x5f =>
audio_pitch(2,state);
case 0x61 =>
const high = state.dev[0x60];
const low = value;
state.audio_vectors[3] = short_from_bytes(high,low);
case 0x6f =>
audio_pitch(3,state);
case 0x81 =>
const high = state.dev[0x80];
const low = value;
@@ -963,37 +989,3 @@ export fn uxn_reset(state: *uxn) void = {
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
};
};