diff --git a/projects/examples/gui/monospace.tal b/projects/examples/gui/monospace.tal new file mode 100644 index 0000000..65522af --- /dev/null +++ b/projects/examples/gui/monospace.tal @@ -0,0 +1,155 @@ +( Draw a 8x8 font ) + +%+ { ADD } %- { SUB } %* { MUL } %/ { DIV } +%< { LTH } %> { GTH } %= { EQU } %! { NEQ } +%++ { ADD2 } %-- { SUB2 } %** { MUL2 } %// { DIV2 } +%<< { LTH2 } %>> { GTH2 } %== { EQU2 } %!! { NEQ2 } + +%AUTO-X { #01 .Screen/auto DEO } + +( devices ) + +|00 @System &vector $2 &wst $1 &rst $1 &eaddr $2 &ecode $1 &pad $1 &r $2 &g $2 &b $2 &debug $1 &halt $1 +|20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 + +( variables ) + +|0000 + +( program ) + +|0100 + + ( theme ) + #f05d .System/r DEO2 + #f0cd .System/g DEO2 + #f0ad .System/b DEO2 + + ( draw hello world ) + #0010 .Screen/x DEO2 + #0010 .Screen/y DEO2 + ;hello-txt #01 ;draw-uf1 JSR2 + + ( draw long text ) + #0010 .Screen/x DEO2 + #0030 .Screen/y DEO2 + ;long-txt #02 ;draw-uf1-linebreaks JSR2 + +BRK + +@draw-uf1 ( string* color -- ) + + AUTO-X + STH + &while + ( get sprite ) LDAk #20 - #00 SWP #30 SFT2 ;font ++ .Screen/addr DEO2 + ( draw ) STHkr .Screen/sprite DEO + INC2 LDAk ,&while JCN + POPr + +JMP2r + +@draw-uf1-linebreaks ( string* color -- ) + + .Screen/x DEI2 ,&anchor STR2 + AUTO-X + STH + &while + LDAk #0a ! ,&no-lb JCN + ( rewind ) LIT2 &anchor $2 .Screen/x DEO2 + ( skip line ) .Screen/y DEI2k #0008 ++ ROT DEO2 + ,&end JMP + &no-lb + ( get sprite ) LDAk #20 - #00 SWP #30 SFT2 ;font ++ .Screen/addr DEO2 + ( draw ) STHkr .Screen/sprite DEO + &end + INC2 LDAk ,&while JCN + POPr + +JMP2r + +@hello-txt "Hello 20 "Uxn! $1 + +@long-txt + 5275 7374 6963 2043 6f6d 7075 7469 6e67 + 2072 6566 6572 7320 746f 2074 6865 2063 + 6f6e 7374 7275 6374 696f 6e20 0a6f 6620 + 6361 6c63 756c 6174 696f 6e20 6d61 6368 + 696e 6573 2075 7369 6e67 2070 7265 2d69 + 6e64 7573 7472 6961 6c20 0a6f 7220 6576 + 656e 2070 7265 2d68 6973 746f 7269 6320 + 7465 6368 6e6f 6c6f 6779 2e20 0a0a 4974 + 2072 6576 6561 6c73 2061 2068 6973 746f + 7279 206f 6620 636f 6d70 7574 696e 6720 + 6173 2074 6865 200a 7061 7374 696d 6520 + 6f66 2064 696c 6574 7461 6e74 6573 2c20 + 616d 6174 6575 7220 7363 6965 6e74 6973 + 7473 0a61 6e64 2074 6162 756c 6174 6f72 + 7320 7768 6f20 636f 6e73 7472 7563 7420 + 6d61 6368 696e 6573 2074 6f20 0a6d 616e + 6970 756c 6174 6520 6162 7374 7261 6374 + 2073 796d 626f 6c73 2077 6974 6820 6e6f + 2070 7261 6374 6963 616c 200a 6170 706c + 6963 6174 696f 6e2e 2041 7320 7468 6573 + 6520 6d61 6368 696e 6573 2061 7265 2067 + 656e 6572 616c 6c79 200a 6c65 7373 2065 + 6666 6963 6965 6e74 2074 6861 6e20 636f + 6e76 656e 7469 6f6e 616c 2070 656e 6369 + 6c20 616e 6420 0a70 6170 6572 2063 6f6d + 7075 7461 7469 6f6e 2c20 7468 6579 2061 + 6c6c 7564 6520 746f 2061 206d 6f72 6520 + 0a65 7069 6375 7265 616e 2070 7261 6374 + 6963 6520 6f66 2063 6f6d 7075 7469 6e67 + 2066 6f72 2070 6c65 6173 7572 6520 0a72 + 6174 6865 7220 7468 616e 2070 726f 6475 + 6374 696f 6e2e + +@font ( bbcmicro ) + 0000 0000 0000 0000 1818 1818 1800 1800 + 6c6c 6c00 0000 0000 3636 7f36 7f36 3600 + 0c3f 683e 0b7e 1800 6066 0c18 3066 0600 + 386c 6c38 6d66 3b00 0c18 3000 0000 0000 + 0c18 3030 3018 0c00 3018 0c0c 0c18 3000 + 0018 7e3c 7e18 0000 0018 187e 1818 0000 + 0000 0000 0018 1830 0000 007e 0000 0000 + 0000 0000 0018 1800 0006 0c18 3060 0000 + 3c66 6e7e 7666 3c00 1838 1818 1818 7e00 + 3c66 060c 1830 7e00 3c66 061c 0666 3c00 + 0c1c 3c6c 7e0c 0c00 7e60 7c06 0666 3c00 + 1c30 607c 6666 3c00 7e06 0c18 3030 3000 + 3c66 663c 6666 3c00 3c66 663e 060c 3800 + 0000 1818 0018 1800 0000 1818 0018 1830 + 0c18 3060 3018 0c00 0000 7e00 7e00 0000 + 3018 0c06 0c18 3000 3c66 0c18 1800 1800 + 3c66 6e6a 6e60 3c00 3c66 667e 6666 6600 + 7c66 667c 6666 7c00 3c66 6060 6066 3c00 + 786c 6666 666c 7800 7e60 607c 6060 7e00 + 7e60 607c 6060 6000 3c66 606e 6666 3c00 + 6666 667e 6666 6600 7e18 1818 1818 7e00 + 3e0c 0c0c 0c6c 3800 666c 7870 786c 6600 + 6060 6060 6060 7e00 6377 7f6b 6b63 6300 + 6666 767e 6e66 6600 3c66 6666 6666 3c00 + 7c66 667c 6060 6000 3c66 6666 6a6c 3600 + 7c66 667c 6c66 6600 3c66 603c 0666 3c00 + 7e18 1818 1818 1800 6666 6666 6666 3c00 + 6666 6666 663c 1800 6363 6b6b 7f77 6300 + 6666 3c18 3c66 6600 6666 663c 1818 1800 + 7e06 0c18 3060 7e00 7c60 6060 6060 7c00 + 0060 3018 0c06 0000 3e06 0606 0606 3e00 + 183c 6642 0000 0000 0000 0000 0000 00ff + 1c36 307c 3030 7e00 0000 3c06 3e66 3e00 + 6060 7c66 6666 7c00 0000 3c66 6066 3c00 + 0606 3e66 6666 3e00 0000 3c66 7e60 3c00 + 1c30 307c 3030 3000 0000 3e66 663e 063c + 6060 7c66 6666 6600 1800 3818 1818 3c00 + 1800 3818 1818 1870 6060 666c 786c 6600 + 3818 1818 1818 3c00 0000 367f 6b6b 6300 + 0000 7c66 6666 6600 0000 3c66 6666 3c00 + 0000 7c66 667c 6060 0000 3e66 663e 0607 + 0000 6c76 6060 6000 0000 3e60 3c06 7c00 + 3030 7c30 3030 1c00 0000 6666 6666 3e00 + 0000 6666 663c 1800 0000 636b 6b7f 3600 + 0000 663c 183c 6600 0000 6666 663e 063c + 0000 7e0c 1830 7e00 0c18 1870 1818 0c00 + 1818 1800 1818 1800 3018 180e 1818 3000 + 316b 4600 0000 0000 ffff ffff ffff ffff diff --git a/src/devices/system.c b/src/devices/system.c index 42ad4ad..1b46994 100644 --- a/src/devices/system.c +++ b/src/devices/system.c @@ -23,19 +23,22 @@ static const char *errors[] = { "Return-stack division by zero"}; static void -print_stack(Stack *s, char *name) +system_print(Stack *s, char *name) { - Uint8 x, y; - fprintf(stderr, "\n%s\n", name); - for(y = 0; y < 0x04; y++) { - for(x = 0; x < 0x08; x++) { - Uint8 p = y * 0x08 + x; - fprintf(stderr, - p == s->ptr ? "[%02x]" : " %02x ", - s->dat[p]); - } - fprintf(stderr, "\n"); - } + Uint8 i; + fprintf(stderr, "<%s> ", name); + for(i = 0; i < s->ptr; i++) + fprintf(stderr, i == s->ptr ? "[%02x]" : " %02x ", s->dat[i]); + if(!i) + fprintf(stderr, "empty"); + fprintf(stderr, "\n"); +} + +void +system_inspect(Uxn *u) +{ + system_print(&u->wst, "wst"); + system_print(&u->rst, "rst"); } int @@ -53,16 +56,11 @@ uxn_halt(Uxn *u, Uint8 error, Uint16 addr) vec += 0x0004; return uxn_eval(u, vec); } + system_inspect(u); fprintf(stderr, "Halted: %s#%04x, at 0x%04x\n", errors[error], u->ram[addr], addr); return 0; } -void -system_inspect(Uxn *u){ - print_stack(&u->wst, "Working-stack"); - print_stack(&u->rst, "Return-stack"); -} - /* IO */ Uint8 diff --git a/src/devices/system.h b/src/devices/system.h index 114d2d1..6bdc847 100644 --- a/src/devices/system.h +++ b/src/devices/system.h @@ -15,6 +15,7 @@ typedef struct SystemDevice { } SystemDevice; void system_inspect(Uxn *u); + Uint8 system_dei(Device *d, Uint8 port); void system_deo(Device *d, Uint8 port); void system_deo_special(Device *d, Uint8 port); diff --git a/src/uxncli.c b/src/uxncli.c index f3af6f0..867cdb2 100644 --- a/src/uxncli.c +++ b/src/uxncli.c @@ -34,7 +34,6 @@ error(char *msg, const char *err) void system_deo_special(Device *d, Uint8 port) { - } static void diff --git a/src/uxnemu.c b/src/uxnemu.c index 3ccfe32..7cbc100 100644 --- a/src/uxnemu.c +++ b/src/uxnemu.c @@ -42,7 +42,7 @@ static SDL_Rect gRect; /* devices */ -static Device *devsystem, *devscreen, *devmouse, *devctrl, *devaudio0; +static Device *devscreen, *devmouse, *devctrl, *devaudio0; static Uint8 zoom = 1; static Uint32 stdin_event, audio0_event; @@ -292,13 +292,6 @@ set_zoom(Uint8 scale) set_window_size(gWindow, (uxn_screen.width + PAD * 2) * zoom, (uxn_screen.height + PAD * 2) * zoom); } -static void -toggle_debugger(void) -{ - devsystem->dat[0xe] = !devsystem->dat[0xe]; - screen_clear(&uxn_screen, &uxn_screen.fg); -} - static void capture_screen(void) { @@ -390,8 +383,9 @@ console_input(Uxn *u, char c) static int run(Uxn *u) { + Device *devsys = &u->dev[0]; redraw(); - while(!devsystem->dat[0xf]) { + while(!devsys->dat[0xf]) { SDL_Event event; double elapsed, begin; if(!BENCH) @@ -454,7 +448,7 @@ run(Uxn *u) console_input(u, event.cbutton.button); } uxn_eval(u, GETVECTOR(devscreen)); - if(uxn_screen.fg.changed || uxn_screen.bg.changed || devsystem->dat[0xe]) + if(uxn_screen.fg.changed || uxn_screen.bg.changed) redraw(); if(!BENCH) { elapsed = (SDL_GetPerformanceCounter() - begin) / (double)SDL_GetPerformanceFrequency() * 1000.0f;