uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

commit b42cec41ef809c358aac791a701908cf35a65e0d
parent 59e6ced7b97fd9ada15b3c368adc3839d36a81e5
Author: neauoire <aliceffekt@gmail.com>
Date:   Thu, 11 Mar 2021 15:47:28 -0800

Implemented local templated labels

Diffstat:
MREADME.md | 15++++++++-------
Massembler.c | 31++++++++++++++++++++++++-------
Metc/usm.sublime-syntax | 3+++
Mprojects/examples/dev.console.usm | 10++++------
Dprojects/examples/dev.key.usm | 236-------------------------------------------------------------------------------
Aprojects/examples/dev.keys.usm | 233+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mprojects/examples/dev.mouse.usm | 4++--
Mprojects/software/nasu.usm | 54+++++++++++++++++++++++++++---------------------------
Mprojects/tests/loop.usm | 16+++++++++-------
9 files changed, 310 insertions(+), 292 deletions(-)

diff --git a/README.md b/README.md @@ -27,6 +27,7 @@ evaluxn(u, u->vframe); /* Each frame ### Define - `@label`, assign the current address to a label. +- `$label`, assign the current address to a local label. - `;variable 2`, assign an address to a label automatically. - `:const 1a2b`, assign an address to a label manually. - `&macro { x 2 y 2 }`, define a macro named `macro`. @@ -75,16 +76,16 @@ BRK @print-label ( text ) - NOP - ( send ) DUP2 LDR =CNSL.char - ( incr ) #0001 ADD2 - ( loop ) DUP2 LDR #00 NEQ ^print-label MUL JMPS + $loop NOP + ( send ) DUP2 LDR =CNSL.char + ( incr ) #0001 ADD2 + ( loop ) DUP2 LDR #00 NEQ ^$loop MUL JMPS POP2 -RTS +RTS -@text1 [ Hello 20 World 0a00 ] ( text with linebreak and null bytes ) -@text2 [ Welcome 20 to 20 UxnVM 0a00 ] +@text1 [ Welcome 20 to 20 UxnVM 0a00 ] +@text2 [ Hello 20 World 0a00 ] |c000 @FRAME |d000 @ERROR diff --git a/assembler.c b/assembler.c @@ -167,6 +167,15 @@ findopcode(char *s) return 0; } +char * +sublabel(char *src, char *scope, char *name) +{ + scpy(scope, src, 64); + scpy("-", src + slen(src), 64); + scpy(name, src + slen(src), 64); + return src; +} + #pragma mark - Parser int @@ -274,7 +283,7 @@ pass1(FILE *f) { int ccmnt = 0, cbits = 0; Uint16 addr = 0; - char w[64]; + char w[64], scope[64], subw[64]; printf("Pass 1\n"); while(fscanf(f, "%s", w) == 1) { if(skipblock(w, &ccmnt, '(', ')')) continue; @@ -288,6 +297,10 @@ pass1(FILE *f) } else if(w[0] == '@') { if(!makelabel(w + 1, addr, 0, NULL)) return error("Pass1 failed", w); + scpy(w + 1, scope, 64); + } else if(w[0] == '$') { + if(!makelabel(sublabel(subw, scope, w + 1), addr, 0, NULL)) + return error("Pass1 failed", w); } else if(w[0] == ';') { if(!makevariable(w + 1, &addr, f)) return error("Pass1 failed", w); @@ -308,8 +321,6 @@ pass1(FILE *f) break; case '=': addr += 4; break; /* STR helper (lit addr-hb addr-lb str) */ case '~': addr += 4; break; /* LDR helper (lit addr-hb addr-lb ldr) */ - case '$': addr += 4; break; /* JSR helper (lit addr-hb addr-lb jsr) */ - case '/': addr += 4; break; /* JMP helper (lit addr-hb addr-lb jmp) */ case ',': addr += 3; break; case '.': addr += 2; break; case '^': addr += 2; break; /* Relative jump: lit addr-offset */ @@ -328,13 +339,21 @@ int pass2(FILE *f) { int ccmnt = 0, cbits = 0, cmacro = 0; - char w[64]; + char w[64], scope[64], subw[64]; printf("Pass 2\n"); while(fscanf(f, "%s", w) == 1) { Uint8 op = 0; Label *l; - if(w[0] == '@') continue; if(w[0] == '&') continue; + if(w[0] == '$') continue; + if(w[0] == '@') { + scpy(w + 1, scope, 64); + continue; + } + if(w[1] == '$') { + sublabel(subw, scope, w + 2); + scpy(subw, w + 1, 64); + } if(skipblock(w, &ccmnt, '(', ')')) continue; if(skipblock(w, &cmacro, '{', '}')) continue; /* clang-format off */ @@ -357,8 +376,6 @@ pass2(FILE *f) else if(w[0] == ',' && (l = findlabel(w + 1))) { pushshort(findlabeladdr(w + 1), 1); l->refs++; } else if(w[0] == '=' && (l = findlabel(w + 1)) && l->len){ pushshort(findlabeladdr(w + 1), 1); pushbyte(findopcode(findlabellen(w + 1) == 2 ? "STR2" : "STR"), 0); l->refs++;} else if(w[0] == '~' && (l = findlabel(w + 1)) && l->len){ pushshort(findlabeladdr(w + 1), 1); pushbyte(findopcode(findlabellen(w + 1) == 2 ? "LDR2" : "LDR"), 0); l->refs++;} - else if(w[0] == '/' && (l = findlabel(w + 1))){ pushshort(findlabeladdr(w + 1), 1); pushbyte(findopcode("JMP2"), 0); l->refs++;} - else if(w[0] == '$' && (l = findlabel(w + 1))){ pushshort(findlabeladdr(w + 1), 1); pushbyte(findopcode("JSR2"), 0); l->refs++;} else if(w[0] == '#' && sihx(w + 1) && slen(w + 1) == 2) pushbyte(shex(w + 1), 1); else if(w[0] == '#' && sihx(w + 1) && slen(w + 1) == 4) pushshort(shex(w + 1), 1); else if(w[0] == '+' && sihx(w + 1) && slen(w + 1) == 2) pushbyte((Sint8)shex(w + 1), 1); diff --git a/etc/usm.sublime-syntax b/etc/usm.sublime-syntax @@ -30,6 +30,9 @@ contexts: - match: '\&(\S+)\s?' scope: string.control pop: true + - match: '\$(\S+)\s?' + scope: string.control + pop: true # Special diff --git a/projects/examples/dev.console.usm b/projects/examples/dev.console.usm @@ -4,8 +4,8 @@ |0100 @RESET - ,text1 $print-label - ,text2 $print-label + ,text1 ,print-label JSR2 + ,text2 ,print-label JSR2 #ab =CNSL.byte #cdef =CNSL.short @@ -13,16 +13,14 @@ BRK @print-label ( text ) - @print-label-loop NOP + $loop NOP ( send ) DUP2 LDR =CNSL.char ( incr ) #0001 ADD2 - ( loop ) DUP2 LDR #00 NEQ ^print-label-loop MUL JMPS + ( loop ) DUP2 LDR #00 NEQ ^$loop MUL JMPS POP2 RTS -( store text in memory ) - @text1 [ Welcome 20 to 20 UxnVM 0a00 ] @text2 [ Hello 20 World 0a00 ] diff --git a/projects/examples/dev.key.usm b/projects/examples/dev.key.usm @@ -1,236 +0,0 @@ -( dev/key ) - -&Screen { width 2 height 2 pad 4 x 2 y 2 color 1 } -&Sprite { pad 8 x 2 y 2 addr 2 color 1 } -&Keyboard { key 1 } -&Mouse { x 2 y 2 state 1 chord 1 } - -&Textarea2d { x1 2 y1 2 x2 2 y2 2 color 1 addr 2 cursor 1 } -&Rect2d { x1 2 y1 2 x2 2 y2 2 } -&Point2d { x 2 y 2 } - -;mouse Point2d -;textarea Textarea2d -;rect Rect2d -;color 1 -;blink 1 -;timer 1 - -|0100 @RESET - - #0080 =textarea.x1 #0060 =textarea.y1 #00c0 =textarea.x2 #0090 =textarea.y2 ,body =textarea.addr - ,redraw JSR2 - ,redraw-window JSR2 - -BRK - -|0200 @FRAME - - ,do-cursor JSR2 - ,do-textarea JSR2 - -BRK - -@redraw-window - - #0000 #0000 ~dev/screen.width ~dev/screen.height #01 ,pattern ,tile-rect JSR2 - ( dropshadow ) - ~textarea.x2 #0001 ADD2 ~textarea.y1 ~textarea.x2 #0004 ADD2 ~textarea.y2 #0004 ADD2 #01 ,fill-rect JSR2 - ~textarea.x1 ~textarea.y2 #0001 ADD2 ~textarea.x2 #0001 ADD2 ~textarea.y2 #0004 ADD2 #01 ,fill-rect JSR2 - ~textarea.x1 #0001 SUB2 ~textarea.y1 #0001 SUB2 ~textarea.x2 ~textarea.y2 #00 ,line-rect JSR2 - ~textarea.x1 #0002 SUB2 ~textarea.y1 #0002 SUB2 ~textarea.x2 #0001 ADD2 ~textarea.y2 #0001 ADD2 #01 ,line-rect JSR2 - -RTS - -@redraw - - ~textarea.x1 ~textarea.y1 ~textarea.x2 ~textarea.y2 #01 ,fill-rect JSR2 - ~textarea.x1 ~textarea.y1 #04 ~textarea.addr ,draw-textarea JSR2 - -RTS - -@blink-cursor - - ,skip ~timer #10 LTH JMP2? POP2 - #00 =timer - ~blink #00 EQU =blink - ,cursor =dev/sprite.addr - #05 ~blink ADD =dev/sprite.color - @skip - ~timer #01 ADD =timer - -RTS - -@tile-rect ( x1 y1 x2 y2 color addr ) - - =dev/sprite.addr =color =rect.y2 =rect.x2 DUP2 =dev/sprite.y =rect.y1 DUP2 =dev/sprite.x =rect.x1 - - @tile-rect-ver - ~rect.x1 =dev/sprite.x - @tile-rect-hor - ( draw ) ~color =dev/sprite.color - ( incr ) ~dev/sprite.x #0008 ADD2 =dev/sprite.x - ,tile-rect-hor ~dev/sprite.x ~rect.x2 LTH2 JMP2? POP2 - ( incr ) ~dev/sprite.y #0008 ADD2 =dev/sprite.y - ,tile-rect-ver ~dev/sprite.y ~rect.y2 LTH2 JMP2? POP2 - -RTS - -@fill-rect ( x1 y1 x2 y2 color ) - - ( load ) =color =rect.y2 =rect.x2 DUP2 =dev/screen.y =rect.y1 DUP2 =dev/screen.x =rect.x1 - @fill-rect-ver - ~rect.x1 =dev/screen.x - @fill-rect-hor - ( draw ) ~color =dev/screen.color - ( incr ) ~dev/screen.x #0001 ADD2 =dev/screen.x - ,fill-rect-hor ~dev/screen.x ~rect.x2 LTH2 JMP2? POP2 - ( incr ) ~dev/screen.y #0001 ADD2 =dev/screen.y - ,fill-rect-ver ~dev/screen.y ~rect.y2 LTH2 JMP2? POP2 - -RTS - -@line-rect ( x1 y1 x2 y2 color ) - - ( load ) =color =rect.y2 =rect.x2 DUP2 =dev/screen.y =rect.y1 DUP2 =dev/screen.x =rect.x1 - @line-rect-hor - ( incr ) ~dev/screen.x #0001 ADD2 =dev/screen.x - ( draw ) ~rect.y1 =dev/screen.y ~color =dev/screen.color - ( draw ) ~rect.y2 =dev/screen.y ~color =dev/screen.color - ,line-rect-hor ~dev/screen.x ~rect.x2 LTH2 JMP2? POP2 - ~rect.y1 =dev/screen.y - @line-rect-ver - ( draw ) ~rect.x1 =dev/screen.x ~color =dev/screen.color - ( draw ) ~rect.x2 =dev/screen.x ~color =dev/screen.color - ( incr ) ~dev/screen.y #0001 ADD2 =dev/screen.y - ,line-rect-ver ~dev/screen.y ~rect.y2 #0001 ADD2 LTH2 JMP2? POP2 - -RTS - -@draw-textarea ( x y color addr ) - - ( load ) =textarea.addr =textarea.color =dev/sprite.y =dev/sprite.x - ~textarea.addr - @draw-textarea-left-loop - ( draw ) DUP2 LDR #00 SWP #0008 MUL2 ,font ADD2 =dev/sprite.addr ~textarea.color =dev/sprite.color - - ( detect linebreaks ) - DUP2 LDR #0d NEQ ,no-return ROT JMP2? POP2 - ~textarea.x1 =dev/sprite.x - ( incr ) ~dev/sprite.y #0008 ADD2 =dev/sprite.y - ( decr ) ~dev/sprite.x #0008 SUB2 =dev/sprite.x - @no-return - - ( incr ) #0001 ADD2 - ( incr ) ~dev/sprite.x #0008 ADD2 =dev/sprite.x - - DUP2 LDR #00 NEQ ,draw-textarea-left-loop ROT JMP2? POP2 - POP2 - -RTS - -@do-textarea - - ( ,blink-cursor JSR2 ) - ,do-textarea-end ~dev/key #00 EQU JMP2? POP2 ( skip on no key ) - ( backspace ) - ,any-key ~dev/key #08 NEQ JMP2? POP2 - ,input-end ~textarea.cursor #00 EQU JMP2? POP2 - ( decr ) ~textarea.cursor #01 SUB =textarea.cursor - #00 ~textarea.addr #00 ~textarea.cursor ADD2 STR - ,input-end JMP2 - @any-key - ~dev/key ~textarea.addr #00 ~textarea.cursor ADD2 STR - ( incr ) ~textarea.cursor #01 ADD =textarea.cursor - @input-end - #00 =dev/key ( release key ) - ,redraw JSR2 - ( add cursor ) - ,cursor =dev/sprite.addr - #06 =dev/sprite.color - @do-textarea-end - -RTS - -@do-cursor - - ,skip-drag ~dev/mouse.state #01 NEQ JMP2? POP2 - ~mouse.x =textarea.x1 ~mouse.y =textarea.y1 - ,redraw-window JSR2 - ,redraw JSR2 - @skip-drag - - ~mouse.x ~dev/mouse.x NEQU2 - ~mouse.y ~dev/mouse.y NEQU2 - - #0000 EQU2 RTS? ( Return if unchanged ) - - ( clear last cursor ) - #10 ,clear_icn ~mouse.x ~mouse.y ,draw-sprite JSR2 - ( record mouse positions ) - ~dev/mouse.x =mouse.x ~dev/mouse.y =mouse.y - #12 ,cursor_icn ~mouse.x ~mouse.y ,draw-sprite JSR2 - - -RTS - -@draw-sprite - - =dev/sprite.y - =dev/sprite.x - =dev/sprite.addr - =dev/sprite.color - -RTS - -@font ( spectrum-zx font ) -[ - 0000 0000 0000 0000 0000 2400 7e3c 0000 0000 2400 3c42 0000 0000 6c7c 7c38 1000 - 0010 387c 7c38 1000 0038 387c 6c10 3800 0010 387c 7c10 3800 0000 0018 1800 0000 - 007e 4242 4242 7e00 0000 1824 2418 0000 0018 2442 4224 1800 001e 063a 4a48 3000 - 0038 446c 107c 1000 0000 0000 0000 0000 003e 2222 2266 6600 0000 0822 0022 0800 - 0000 1018 1c18 1000 0000 0818 3818 0800 0008 1c00 001c 0800 0028 2828 2800 2800 - 003e 4a4a 3a0a 0a00 000c 3046 620c 3000 0000 0000 0000 ffff 0010 3800 3810 0038 - 0008 1c2a 0808 0800 0008 0808 2a1c 0800 0000 0804 7e04 0800 0000 1020 7e20 1000 - 0000 4040 7e00 0000 0000 0024 6624 0000 0000 1038 7c00 0000 0000 007c 3810 0000 - 0000 0000 0000 0000 0008 0808 0800 0800 0014 1400 0000 0000 0024 7e24 247e 2400 - 0008 1e28 1c0a 3c08 0042 0408 1020 4200 0030 4832 4c44 3a00 0008 1000 0000 0000 - 0004 0808 0808 0400 0010 0808 0808 1000 0000 1408 3e08 1400 0000 0808 3e08 0800 - 0000 0000 0008 0810 0000 0000 3c00 0000 0000 0000 0000 0800 0000 0204 0810 2000 - 003c 464a 5262 3c00 0018 2808 0808 3e00 003c 4202 3c40 7e00 003c 421c 0242 3c00 - 0008 1828 487e 0800 007e 407c 0242 3c00 003c 407c 4242 3c00 007e 0204 0810 1000 - 003c 423c 4242 3c00 003c 4242 3e02 3c00 0000 0008 0000 0800 0000 0800 0008 0810 - 0000 0810 2010 0800 0000 003e 003e 0000 0000 1008 0408 1000 003c 4202 0c00 0800 - 003c 425a 5442 3c00 0018 2442 7e42 4200 007c 427c 4242 7c00 003c 4240 4042 3c00 - 0078 4442 4244 7800 007e 407c 4040 7e00 003e 4040 7c40 4000 003c 4240 4e42 3c00 - 0042 427e 4242 4200 003e 0808 0808 3e00 0002 0202 4242 3c00 0044 4870 4844 4200 - 0040 4040 4040 7e00 0042 665a 4242 4200 0042 6252 4a46 4200 003c 4242 4242 3c00 - 007c 4242 7c40 4000 003c 4242 524a 3c00 007c 4242 7c44 4200 003c 403c 0242 3c00 - 00fe 1010 1010 1000 0042 4242 4242 3c00 0042 4242 4224 1800 0042 4242 5a66 4200 - 0042 2418 1824 4200 0082 4428 1010 1000 007e 0408 1020 7e00 000c 0808 0808 0c00 - 0040 2010 0804 0200 0018 0808 0808 1800 0008 1422 0000 0000 0000 0000 0000 7e00 - 0008 0400 0000 0000 0000 1c02 1e22 1e00 0020 203c 2222 3c00 0000 1e20 2020 1e00 - 0002 021e 2222 1e00 0000 1c22 3c20 1e00 000c 101c 1010 1000 0000 1c22 221e 021c - 0020 202c 3222 2200 0008 0018 0808 0400 0008 0008 0808 4830 0020 2428 3028 2400 - 0010 1010 1010 0c00 0000 6854 5454 5400 0000 5864 4444 4400 0000 3844 4444 3800 - 0000 7844 4478 4040 0000 3c44 443c 0406 0000 2c30 2020 2000 0000 3840 3804 7800 - 0010 103c 1010 0c00 0000 4444 4444 3800 0000 4444 2828 1000 0000 4454 5454 2800 - 0000 4428 1028 4400 0000 4444 443c 0438 0000 7c08 1020 7c00 000c 0810 1008 0c00 - 0008 0808 0808 0800 0030 1008 0810 3000 0000 0032 4c00 0000 3c42 99a1 a199 423c -] - -@clear_icn [ 0000 0000 0000 0000 ] -@cursor_icn [ 80c0 e0f0 f8e0 1000 ] -@pattern [ aa55 aa55 aa55 aa55 ] -@cursor [ 7e7e 7e7e 7e7e 7e7e ] -@body [ ] - -|d000 @ERROR BRK - -|FF10 ;dev/screen Screen -|FF20 ;dev/sprite Sprite -|FF40 ;dev/key Keyboard -|FF50 ;dev/mouse Mouse - -|FFF0 .RESET .FRAME .ERROR ( vectors ) -|FFF8 [ f0ff f000 f00f ] ( palette ) diff --git a/projects/examples/dev.keys.usm b/projects/examples/dev.keys.usm @@ -0,0 +1,233 @@ +( dev/key ) + +&Screen { width 2 height 2 pad 4 x 2 y 2 color 1 } +&Sprite { pad 8 x 2 y 2 addr 2 color 1 } +&Keyboard { key 1 } +&Mouse { x 2 y 2 state 1 chord 1 } + +&Textarea2d { x1 2 y1 2 x2 2 y2 2 color 1 addr 2 cursor 1 } +&Rect2d { x1 2 y1 2 x2 2 y2 2 } +&Point2d { x 2 y 2 } + +;mouse Point2d +;textarea Textarea2d +;rect Rect2d +;color 1 +;blink 1 +;timer 1 + +|0100 @RESET + + #0080 =textarea.x1 #0060 =textarea.y1 #00c0 =textarea.x2 #0090 =textarea.y2 ,body =textarea.addr + ,redraw JSR2 + ,redraw-window JSR2 + +BRK + +|0200 @FRAME + + ,do-cursor JSR2 + ,do-textarea JSR2 + +BRK + +@redraw-window + + #0000 #0000 ~dev/screen.width ~dev/screen.height #01 ,pattern ,tile-rect JSR2 + ( dropshadow ) + ~textarea.x2 #0001 ADD2 ~textarea.y1 ~textarea.x2 #0004 ADD2 ~textarea.y2 #0004 ADD2 #01 ,fill-rect JSR2 + ~textarea.x1 ~textarea.y2 #0001 ADD2 ~textarea.x2 #0001 ADD2 ~textarea.y2 #0004 ADD2 #01 ,fill-rect JSR2 + ~textarea.x1 #0001 SUB2 ~textarea.y1 #0001 SUB2 ~textarea.x2 ~textarea.y2 #00 ,line-rect JSR2 + ~textarea.x1 #0002 SUB2 ~textarea.y1 #0002 SUB2 ~textarea.x2 #0001 ADD2 ~textarea.y2 #0001 ADD2 #01 ,line-rect JSR2 + +RTS + +@redraw + + ~textarea.x1 ~textarea.y1 ~textarea.x2 ~textarea.y2 #01 ,fill-rect JSR2 + ~textarea.x1 ~textarea.y1 #04 ~textarea.addr ,draw-textarea JSR2 + +RTS + +@blink-cursor + + ,skip ~timer #10 LTH JMP2? POP2 + #00 =timer + ~blink #00 EQU =blink + ,cursor =dev/sprite.addr + #05 ~blink ADD =dev/sprite.color + @skip + ~timer #01 ADD =timer + +RTS + +@tile-rect ( x1 y1 x2 y2 color addr ) + + =dev/sprite.addr =color =rect.y2 =rect.x2 DUP2 =dev/sprite.y =rect.y1 DUP2 =dev/sprite.x =rect.x1 + + $ver + ~rect.x1 =dev/sprite.x + $hor + ( draw ) ~color =dev/sprite.color + ( incr ) ~dev/sprite.x #0008 ADD2 =dev/sprite.x + ,$hor ~dev/sprite.x ~rect.x2 LTH2 JMP2? POP2 + ( incr ) ~dev/sprite.y #0008 ADD2 =dev/sprite.y + ,$ver ~dev/sprite.y ~rect.y2 LTH2 JMP2? POP2 + +RTS + +@fill-rect ( x1 y1 x2 y2 color ) + + ( load ) =color =rect.y2 =rect.x2 DUP2 =dev/screen.y =rect.y1 DUP2 =dev/screen.x =rect.x1 + $ver + ~rect.x1 =dev/screen.x + $hor + ( draw ) ~color =dev/screen.color + ( incr ) ~dev/screen.x #0001 ADD2 =dev/screen.x + ,$hor ~dev/screen.x ~rect.x2 LTH2 JMP2? POP2 + ( incr ) ~dev/screen.y #0001 ADD2 =dev/screen.y + ,$ver ~dev/screen.y ~rect.y2 LTH2 JMP2? POP2 + +RTS + +@line-rect ( x1 y1 x2 y2 color ) + + ( load ) =color =rect.y2 =rect.x2 DUP2 =dev/screen.y =rect.y1 DUP2 =dev/screen.x =rect.x1 + $hor + ( incr ) ~dev/screen.x #0001 ADD2 =dev/screen.x + ( draw ) ~rect.y1 =dev/screen.y ~color =dev/screen.color + ( draw ) ~rect.y2 =dev/screen.y ~color =dev/screen.color + ,$hor ~dev/screen.x ~rect.x2 LTH2 JMP2? POP2 + ~rect.y1 =dev/screen.y + $ver + ( draw ) ~rect.x1 =dev/screen.x ~color =dev/screen.color + ( draw ) ~rect.x2 =dev/screen.x ~color =dev/screen.color + ( incr ) ~dev/screen.y #0001 ADD2 =dev/screen.y + ,$ver ~dev/screen.y ~rect.y2 #0001 ADD2 LTH2 JMP2? POP2 + +RTS + +@draw-textarea ( x y color addr ) + + ( load ) =textarea.addr =textarea.color =dev/sprite.y =dev/sprite.x + ~textarea.addr + $loop + ( draw ) DUP2 LDR #00 SWP #0008 MUL2 ,font ADD2 =dev/sprite.addr ~textarea.color =dev/sprite.color + ( detect linebreaks ) + DUP2 LDR #0d NEQ ,$no-return ROT JMP2? POP2 + ~textarea.x1 =dev/sprite.x + ( incr ) ~dev/sprite.y #0008 ADD2 =dev/sprite.y + ( decr ) ~dev/sprite.x #0008 SUB2 =dev/sprite.x + $no-return + ( incr ) #0001 ADD2 + ( incr ) ~dev/sprite.x #0008 ADD2 =dev/sprite.x + DUP2 LDR #00 NEQ ,$loop ROT JMP2? POP2 + POP2 + +RTS + +@do-textarea + + ( ,blink-cursor JSR2 ) + ,do-textarea-end ~dev/key #00 EQU JMP2? POP2 ( skip on no key ) + ( backspace ) + ,any-key ~dev/key #08 NEQ JMP2? POP2 + ,input-end ~textarea.cursor #00 EQU JMP2? POP2 + ( decr ) ~textarea.cursor #01 SUB =textarea.cursor + #00 ~textarea.addr #00 ~textarea.cursor ADD2 STR + ,input-end JMP2 + @any-key + ~dev/key ~textarea.addr #00 ~textarea.cursor ADD2 STR + ( incr ) ~textarea.cursor #01 ADD =textarea.cursor + @input-end + #00 =dev/key ( release key ) + ,redraw JSR2 + ( add cursor ) + ,cursor =dev/sprite.addr + #06 =dev/sprite.color + @do-textarea-end + +RTS + +@do-cursor + + ,skip-drag ~dev/mouse.state #01 NEQ JMP2? POP2 + ~mouse.x =textarea.x1 ~mouse.y =textarea.y1 + ,redraw-window JSR2 + ,redraw JSR2 + @skip-drag + + ~mouse.x ~dev/mouse.x NEQU2 + ~mouse.y ~dev/mouse.y NEQU2 + + #0000 EQU2 RTS? ( Return if unchanged ) + + ( clear last cursor ) + #10 ,clear_icn ~mouse.x ~mouse.y ,draw-sprite JSR2 + ( record mouse positions ) + ~dev/mouse.x =mouse.x ~dev/mouse.y =mouse.y + #12 ,cursor_icn ~mouse.x ~mouse.y ,draw-sprite JSR2 + + +RTS + +@draw-sprite + + =dev/sprite.y + =dev/sprite.x + =dev/sprite.addr + =dev/sprite.color + +RTS + +@font ( spectrum-zx font ) +[ + 0000 0000 0000 0000 0000 2400 7e3c 0000 0000 2400 3c42 0000 0000 6c7c 7c38 1000 + 0010 387c 7c38 1000 0038 387c 6c10 3800 0010 387c 7c10 3800 0000 0018 1800 0000 + 007e 4242 4242 7e00 0000 1824 2418 0000 0018 2442 4224 1800 001e 063a 4a48 3000 + 0038 446c 107c 1000 0000 0000 0000 0000 003e 2222 2266 6600 0000 0822 0022 0800 + 0000 1018 1c18 1000 0000 0818 3818 0800 0008 1c00 001c 0800 0028 2828 2800 2800 + 003e 4a4a 3a0a 0a00 000c 3046 620c 3000 0000 0000 0000 ffff 0010 3800 3810 0038 + 0008 1c2a 0808 0800 0008 0808 2a1c 0800 0000 0804 7e04 0800 0000 1020 7e20 1000 + 0000 4040 7e00 0000 0000 0024 6624 0000 0000 1038 7c00 0000 0000 007c 3810 0000 + 0000 0000 0000 0000 0008 0808 0800 0800 0014 1400 0000 0000 0024 7e24 247e 2400 + 0008 1e28 1c0a 3c08 0042 0408 1020 4200 0030 4832 4c44 3a00 0008 1000 0000 0000 + 0004 0808 0808 0400 0010 0808 0808 1000 0000 1408 3e08 1400 0000 0808 3e08 0800 + 0000 0000 0008 0810 0000 0000 3c00 0000 0000 0000 0000 0800 0000 0204 0810 2000 + 003c 464a 5262 3c00 0018 2808 0808 3e00 003c 4202 3c40 7e00 003c 421c 0242 3c00 + 0008 1828 487e 0800 007e 407c 0242 3c00 003c 407c 4242 3c00 007e 0204 0810 1000 + 003c 423c 4242 3c00 003c 4242 3e02 3c00 0000 0008 0000 0800 0000 0800 0008 0810 + 0000 0810 2010 0800 0000 003e 003e 0000 0000 1008 0408 1000 003c 4202 0c00 0800 + 003c 425a 5442 3c00 0018 2442 7e42 4200 007c 427c 4242 7c00 003c 4240 4042 3c00 + 0078 4442 4244 7800 007e 407c 4040 7e00 003e 4040 7c40 4000 003c 4240 4e42 3c00 + 0042 427e 4242 4200 003e 0808 0808 3e00 0002 0202 4242 3c00 0044 4870 4844 4200 + 0040 4040 4040 7e00 0042 665a 4242 4200 0042 6252 4a46 4200 003c 4242 4242 3c00 + 007c 4242 7c40 4000 003c 4242 524a 3c00 007c 4242 7c44 4200 003c 403c 0242 3c00 + 00fe 1010 1010 1000 0042 4242 4242 3c00 0042 4242 4224 1800 0042 4242 5a66 4200 + 0042 2418 1824 4200 0082 4428 1010 1000 007e 0408 1020 7e00 000c 0808 0808 0c00 + 0040 2010 0804 0200 0018 0808 0808 1800 0008 1422 0000 0000 0000 0000 0000 7e00 + 0008 0400 0000 0000 0000 1c02 1e22 1e00 0020 203c 2222 3c00 0000 1e20 2020 1e00 + 0002 021e 2222 1e00 0000 1c22 3c20 1e00 000c 101c 1010 1000 0000 1c22 221e 021c + 0020 202c 3222 2200 0008 0018 0808 0400 0008 0008 0808 4830 0020 2428 3028 2400 + 0010 1010 1010 0c00 0000 6854 5454 5400 0000 5864 4444 4400 0000 3844 4444 3800 + 0000 7844 4478 4040 0000 3c44 443c 0406 0000 2c30 2020 2000 0000 3840 3804 7800 + 0010 103c 1010 0c00 0000 4444 4444 3800 0000 4444 2828 1000 0000 4454 5454 2800 + 0000 4428 1028 4400 0000 4444 443c 0438 0000 7c08 1020 7c00 000c 0810 1008 0c00 + 0008 0808 0808 0800 0030 1008 0810 3000 0000 0032 4c00 0000 3c42 99a1 a199 423c +] + +@clear_icn [ 0000 0000 0000 0000 ] +@cursor_icn [ 80c0 e0f0 f8e0 1000 ] +@pattern [ aa55 aa55 aa55 aa55 ] +@cursor [ 7e7e 7e7e 7e7e 7e7e ] +@body [ ] + +|d000 @ERROR BRK + +|FF10 ;dev/screen Screen +|FF20 ;dev/sprite Sprite +|FF40 ;dev/key Keyboard +|FF50 ;dev/mouse Mouse + +|FFF0 .RESET .FRAME .ERROR ( vectors ) +|FFF8 [ f0ff f000 f00f ] ( palette ) diff --git a/projects/examples/dev.mouse.usm b/projects/examples/dev.mouse.usm @@ -129,11 +129,11 @@ RTS ( load ) =label.addr =label.color =dev/sprite.y =dev/sprite.x ~label.addr - @draw-label-loop + $loop ( draw ) DUP2 LDR #00 SWP #0008 MUL2 ,font ADD2 =dev/sprite.addr ~label.color =dev/sprite.color ( incr ) #0001 ADD2 ( incr ) ~dev/sprite.x #0008 ADD2 =dev/sprite.x - DUP2 #0001 ADD2 LDR #00 NEQ ,draw-label-loop ROT JMP2? POP2 + DUP2 #0001 ADD2 LDR #00 NEQ ,$loop ROT JMP2? POP2 POP2 RTS diff --git a/projects/software/nasu.usm b/projects/software/nasu.usm @@ -270,7 +270,7 @@ RTS ( guides ) #00 =i ,font_hex =SPRT.addr - @draw-bankview-guides + $guides ~bankview.x #0010 SUB2 =SPRT.x ~bankview.y #00 ~i #08 MUL ADD2 =SPRT.y ( draw ) #02 =SPRT.color @@ -279,28 +279,28 @@ RTS ( draw ) #02 =SPRT.color ~SPRT.addr #0008 ADD2 =SPRT.addr ( incr ) ~i #01 ADD =i - ,draw-bankview-guides ~i #10 LTH JMP2? POP2 + ,$guides ~i #10 LTH JMP2? POP2 ( body ) ~bankview.x =SPRT.x ~bankview.y =SPRT.y #00 =pt.x #00 =pt.y ~bankview.addr =SPRT.addr - @draw-bankview-tiles-ver + $ver #00 =pt.x ~bankview.x =SPRT.x - @draw-bankview-tiles-hor + $hor ( draw ) #01 =SPRT.color - ,no-highlight ~SPRT.addr ~tileview.addr LTH2 JMP2? POP2 - ,no-highlight ~SPRT.addr ~tileview.addr #0018 ADD2 GTH2 JMP2? POP2 + ,$no-highlight ~SPRT.addr ~tileview.addr LTH2 JMP2? POP2 + ,$no-highlight ~SPRT.addr ~tileview.addr #0018 ADD2 GTH2 JMP2? POP2 ( draw ) #0c =SPRT.color - @no-highlight + $no-highlight ( incr ) ~SPRT.x #0008 ADD2 =SPRT.x ( incr ) ~SPRT.addr #0008 ADD2 =SPRT.addr ( incr ) ~pt.x #01 ADD =pt.x - ,draw-bankview-tiles-hor ~pt.x #10 LTH JMP2? POP2 + ,$hor ~pt.x #10 LTH JMP2? POP2 ( incr ) ~pt.y #01 ADD =pt.y ( incr ) ~SPRT.y #0008 ADD2 =SPRT.y - ,draw-bankview-tiles-ver ~pt.y #10 LTH JMP2? POP2 + ,$ver ~pt.y #10 LTH JMP2? POP2 RTS @@ -344,18 +344,18 @@ RTS ( line hor ) ~tileview.y #003f ADD2 =SCRN.y ~tileview.x =SCRN.x - @draw-hor + $line-hor ( draw ) #03 =SCRN.color ( incr ) ~SCRN.x #0002 ADD2 =SCRN.x - ~SCRN.x ~tileview.x #0082 ADD2 LTH2 ,draw-hor ROT JMP2? POP2 + ~SCRN.x ~tileview.x #0082 ADD2 LTH2 ,$line-hor ROT JMP2? POP2 ( line ver ) ~tileview.y =SCRN.y ~tileview.x #003f ADD2 =SCRN.x - @draw-ver + $line-ver ( draw ) #03 =SCRN.color ( incr ) ~SCRN.y #0002 ADD2 =SCRN.y - ~SCRN.y ~tileview.y #0081 ADD2 LTH2 ,draw-ver ROT JMP2? POP2 + ~SCRN.y ~tileview.y #0081 ADD2 LTH2 ,$line-ver ROT JMP2? POP2 ( rewind ) ~tileview.addr #0018 SUB2 =tileview.addr @@ -363,7 +363,7 @@ RTS ~tileview.y #0018 ADD2 =SPRT.y #00 =i - @draw-tileview-bytes + $bytes ~tileview.x #0088 ADD2 =SPRT.x ,font_hex #00 ~tileview.addr #00 ~i ADD2 LDR #f0 AND #04 ROR #08 MUL ADD2 =SPRT.addr ( draw ) #02 =SPRT.color @@ -372,7 +372,7 @@ RTS ( draw ) #02 =SPRT.color ( incr ) ~i #01 ADD =i ( incr ) ~SPRT.y #0008 ADD2 =SPRT.y - ,draw-tileview-bytes ~i #08 LTH JMP2? POP2 + ,$bytes ~i #08 LTH JMP2? POP2 ( operations ) @@ -387,27 +387,27 @@ RTS ~tileview.y =SPRT.y #00 =pt.x #00 =pt.y ~tileview.addr =SPRT.addr - @draw-tileview-tiles-ver + $tiles-ver #00 =pt.x ~tileview.x #0088 ADD2 =SPRT.x - @draw-tileview-tiles-hor + $tiles-hor ( draw ) #03 =SPRT.color ( incr ) ~SPRT.x #0008 ADD2 =SPRT.x ( incr ) ~SPRT.addr #0008 ADD2 =SPRT.addr ( incr ) ~pt.x #01 ADD =pt.x - ,draw-tileview-tiles-hor ~pt.x #02 LTH JMP2? POP2 + ,$tiles-hor ~pt.x #02 LTH JMP2? POP2 ( incr ) ~pt.y #01 ADD =pt.y ( incr ) ~SPRT.y #0008 ADD2 =SPRT.y - ,draw-tileview-tiles-ver ~pt.y #02 LTH JMP2? POP2 + ,$tiles-ver ~pt.y #02 LTH JMP2? POP2 RTS @draw-tileview-icn #00 =pt.x #00 =pt.y - @redraw-ver + $ver #00 =pt.x - @redraw-hor + $hor ( get bit ) ,blank_icn #00 ~tileview.addr #00 ~pt.y ADD2 LDR #07 ~pt.x SUB ROR #01 AND ( get bit ) @@ -415,11 +415,11 @@ RTS ( draw ) #01 =SPRT.color ( incr ) ~SPRT.x #0008 ADD2 =SPRT.x ( incr ) ~pt.x #01 ADD =pt.x - ,redraw-hor ~pt.x #08 LTH JMP2? POP2 + ,$hor ~pt.x #08 LTH JMP2? POP2 ( incr ) ~SPRT.y #0008 ADD2 =SPRT.y ( incr ) ~pt.y #01 ADD =pt.y ~SPRT.x #0040 SUB2 =SPRT.x - ,redraw-ver ~pt.y #08 LTH JMP2? POP2 + ,$ver ~pt.y #08 LTH JMP2? POP2 RTS @@ -470,17 +470,17 @@ RTS @line-rect ( x1 y1 x2 y2 color ) ( load ) =color =rect.y2 =rect.x2 DUP2 =SCRN.y =rect.y1 DUP2 =SCRN.x =rect.x1 - @line-rect-hor NOP + $hor NOP ( incr ) ~SCRN.x #0001 ADD2 =SCRN.x ( draw ) ~rect.y1 =SCRN.y ~color =SCRN.color ( draw ) ~rect.y2 =SCRN.y ~color =SCRN.color - ~SCRN.x ~rect.x2 LTH2 ^line-rect-hor MUL JMPS + ~SCRN.x ~rect.x2 LTH2 ^$hor MUL JMPS ~rect.y1 =SCRN.y - @line-rect-ver NOP + $ver NOP ( draw ) ~rect.x1 =SCRN.x ~color =SCRN.color ( draw ) ~rect.x2 =SCRN.x ~color =SCRN.color ( incr ) ~SCRN.y #0001 ADD2 =SCRN.y - ~SCRN.y ~rect.y2 #0001 ADD2 LTH2 ^line-rect-ver MUL JMPS + ~SCRN.y ~rect.y2 #0001 ADD2 LTH2 ^$ver MUL JMPS RTS diff --git a/projects/tests/loop.usm b/projects/tests/loop.usm @@ -7,22 +7,24 @@ |0100 @RESET ( type: padded muljmp ) - - @loop1 NOP + @part1 + $loop NOP ~a #01 ADD =a - ~a #d0 LTH ^loop1 MUL JMPS + ~a #d0 LTH ^$loop MUL JMPS ( type: jmppop ) - @loop2 + @part2 + $loop ~b #01 ADD =b - ,loop2 ~b #d0 LTH JMP2? POP2 + ,$loop ~b #d0 LTH JMP2? POP2 ( type: padded jmppop ) - @loop3 NOP + @part3 + $loop NOP ~c #01 ADD =c - ~c #d0 LTH ^loop3 SWP JMPS? POP + ~c #d0 LTH ^$loop SWP JMPS? POP ~a =dev/console.byte ~b =dev/console.byte