diff --git a/projects/examples/devices/console.tal b/projects/examples/devices/console.tal index ad0a574..32ece1e 100644 --- a/projects/examples/devices/console.tal +++ b/projects/examples/devices/console.tal @@ -1,7 +1,9 @@ ( dev/console ) -|00 @System $e &debug -|10 @Console $8 &write +%HALT { #010f DEO } +%EMIT { #18 DEO } +%DEBUG { ;print-hex/byte JSR2 #0a EMIT } +%DEBUG2 { ;print-hex JSR2 #0a EMIT } ( init ) @@ -9,11 +11,28 @@ ;hello-word &while - ( send ) LDAk .Console/write DEO + ( send ) LDAk EMIT + #20 EMIT + DUP2 ;print-hex JSR2 + #20 EMIT + LDAk ;print-hex/byte JSR2 + #0a EMIT INC2 LDAk ,&while JCN POP2 - ( show debugger ) #01 .System/debug DEO + ( stop ) HALT BRK +@print-hex ( value* -- ) + + SWP ,&byte JSR + &byte ( byte -- ) + STHk #04 SFT ,&parse JSR #18 DEO + STHr #0f AND ,&parse JSR #18 DEO + JMP2r + &parse ( byte -- char ) DUP #09 GTH ,&above JCN #30 ADD JMP2r + &above #57 ADD JMP2r + +JMP2r + @hello-word "Hello 20 "Uxn! \ No newline at end of file diff --git a/src/uxn-fast.c b/src/uxn-fast.c index 5208653..b849ac2 100644 --- a/src/uxn-fast.c +++ b/src/uxn-fast.c @@ -4018,12 +4018,13 @@ error: } int -uxn_boot(Uxn *u) +uxn_boot(Uxn *u, Uint8 *memory) { unsigned int i; char *cptr = (char *)u; for(i = 0; i < sizeof(*u); ++i) cptr[i] = 0x00; + u->ram.dat = memory; return 1; } diff --git a/src/uxn.c b/src/uxn.c index 5d251e0..d61a675 100644 --- a/src/uxn.c +++ b/src/uxn.c @@ -136,12 +136,13 @@ uxn_eval(Uxn *u, Uint16 vec) /* clang-format on */ int -uxn_boot(Uxn *u) +uxn_boot(Uxn *u, Uint8 *memory) { Uint32 i; char *cptr = (char *)u; for(i = 0; i < sizeof(*u); ++i) cptr[i] = 0x00; + u->ram.dat = memory; return 1; } diff --git a/src/uxn.h b/src/uxn.h index 5ad45db..bb6690f 100644 --- a/src/uxn.h +++ b/src/uxn.h @@ -24,7 +24,7 @@ typedef struct { typedef struct { Uint16 ptr; - Uint8 dat[65536]; + Uint8 *dat; } Memory; typedef struct Device { @@ -44,7 +44,7 @@ typedef struct Uxn { void poke16(Uint8 *m, Uint16 a, Uint16 b); Uint16 peek16(Uint8 *m, Uint16 a); -int uxn_boot(Uxn *c); +int uxn_boot(Uxn *c, Uint8 *memory); int uxn_eval(Uxn *u, Uint16 vec); int uxn_halt(Uxn *u, Uint8 error, char *name, int id); Device *uxn_port(Uxn *u, Uint8 id, Uint8 (*deifn)(Device *, Uint8), void (*deofn)(Device *, Uint8)); diff --git a/src/uxncli.c b/src/uxncli.c index aacda00..3018819 100644 --- a/src/uxncli.c +++ b/src/uxncli.c @@ -1,4 +1,5 @@ #include +#include #include #include #include "uxn.h" @@ -147,7 +148,7 @@ load(Uxn *u, char *filepath) FILE *f; int r; if(!(f = fopen(filepath, "rb"))) return 0; - r = fread(u->ram.dat + PAGE_PROGRAM, 1, sizeof(u->ram.dat) - PAGE_PROGRAM, f); + r = fread(u->ram.dat + PAGE_PROGRAM, 1, 0xffff - PAGE_PROGRAM, f); fclose(f); if(r < 1) return 0; fprintf(stderr, "Loaded %s\n", filepath); @@ -160,7 +161,7 @@ main(int argc, char **argv) Uxn u; int i, loaded = 0; - if(!uxn_boot(&u)) + if(!uxn_boot(&u, (Uint8 *)calloc(0xffff, sizeof(Uint8)))) return error("Boot", "Failed"); /* system */ devsystem = uxn_port(&u, 0x0, system_dei, system_deo); diff --git a/src/uxnemu.c b/src/uxnemu.c index aec8b61..07f1555 100644 --- a/src/uxnemu.c +++ b/src/uxnemu.c @@ -273,7 +273,7 @@ load(Uxn *u, char *rom) SDL_RWops *f; int r; if(!(f = SDL_RWFromFile(rom, "rb"))) return 0; - r = f->read(f, u->ram.dat + PAGE_PROGRAM, 1, sizeof(u->ram.dat) - PAGE_PROGRAM); + r = f->read(f, u->ram.dat + PAGE_PROGRAM, 1, 0xffff - PAGE_PROGRAM); f->close(f); if(r < 1) return 0; fprintf(stderr, "Loaded %s\n", rom); @@ -284,7 +284,8 @@ load(Uxn *u, char *rom) static int start(Uxn *u, char *rom) { - if(!uxn_boot(u)) + Uint8 *memory = (Uint8 *)calloc(0xffff, sizeof(Uint8)); + if(!uxn_boot(u, memory)) return error("Boot", "Failed to start uxn."); if(!load(u, rom)) return error("Boot", "Failed to load rom.");