0
0
Fork 0
mirror of https://git.sr.ht/~rabbits/uxn synced 2024-11-30 01:33:01 +00:00

Jump experiments

This commit is contained in:
neauoire 2021-03-11 12:19:59 -08:00
parent e3e2b792a6
commit 9bb4b84e2f
11 changed files with 433 additions and 327 deletions

View file

@ -29,11 +29,11 @@ evaluxn(u, u->vframe); /* Each frame
- `;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`.
- `.address`, push label address to memory.
- `,literal`, push label address to stack, prefixed with `LIT LEN`.
- `#1a`, a literal byte/short.
- `+1a`, a literal signed byte/short.
- `-1a`, a literal signed byte/short(negative).
- `.ab`, a raw byte/short in memory.
- `,literal`, push label address to stack, prefixed with `LIT LEN`.
- `=label`, helper to STR, equivalent to `,label STR`, or `label STR2`.
- `~label`, helper to LDR, equivalent to `,label LDR2`, or `,label LDR2`.
- `|0010`, move to position in the program.
@ -55,30 +55,30 @@ evaluxn(u, u->vframe); /* Each frame
|0100 @RESET
,text1 ,print-label JSR
,text2 ,print-label JSR
#ab =dev/console.byte
#cdef =dev/console.short
,text1 ,print-label JSR2
,text2 ,print-label JSR2
#ab =CNSL.byte
#cdef =CNSL.short
BRK
@print-label ( text )
@print-label-loop
DUP2 LDR =dev/console.char ( write pointer value to console )
#0001 ADD2 ( increment string pointer )
DUP2 LDR #00 NEQ ,print-label-loop ROT JMP? POP2 ( while *ptr!=0 goto loop )
@print-label-loop NOP
( send ) DUP2 LDR =CNSL.char
( incr ) #0001 ADD2
DUP2 LDR #00 NEQ ^print-label-loop MUL JMPS
POP2
RTS
@text1 [ Hello World 0a00 ] ( store text with a linebreak and null byte )
@text2 [ Welcome to UxnVM 0a00 ]
@text1 [ Hello 20 World 0a00 ] ( store text with a linebreak and null byte )
@text2 [ Welcome 20 to 20 UxnVM 0a00 ]
|c000 @FRAME
|d000 @ERROR
|FF00 ;dev/console Console
|FF00 ;CNSL Console
|FFF0 .RESET .FRAME .ERROR ( vectors )
|FFF8 [ 13fd 1ef3 1bf2 ] ( palette )
@ -99,6 +99,16 @@ RTS
- Local loops
- Jump helpers
NOTE: OPCODES should not be relative, but there should be a relative accessor for addresses, like:
$relative_name JMP
## Notes
### Conditional Jumping
I've considered automatically popping an amount of items from the stack equal to the offset between the opcode's push/pop to make the stack length more predictable, and making the pattern JMP? POP2 unecessary, but that idea would make DUP? unusable. That change was reverted.
## Palettes
- `[ 6a03 4a0d aa0c ]`, purple/cyan

View file

@ -184,7 +184,7 @@ makemacro(char *name, FILE *f)
char wv[64];
if(findmacro(name))
return error("Macro duplicate", name);
if(sihx(name))
if(sihx(name) && slen(name) % 2 == 0)
return error("Macro name is hex number", name);
if(findopcode(name))
return error("Macro name is invalid", name);
@ -214,7 +214,7 @@ makelabel(char *name, Uint16 addr, Uint8 len, Macro *m)
Label *l;
if(findlabel(name))
return error("Label duplicate", name);
if(sihx(name))
if(sihx(name) && slen(name) % 2 == 0)
return error("Label name is hex number", name);
if(findopcode(name))
return error("Label name is invalid", name);
@ -309,7 +309,8 @@ pass1(FILE *f)
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 += 3; break;
case '.': addr += (slen(w + 1) == 2 ? 1 : 2); break;
case '.': addr += 2; break;
case '^': addr += 2; break; /* Relative jump: lit addr-offset */
case '+': /* signed positive */
case '-': /* signed negative */
case '#': addr += (slen(w + 1) == 2 ? 2 : 3); break;
@ -343,21 +344,24 @@ pass2(FILE *f)
}
else if(w[0] == '|') p.ptr = shex(w + 1);
else if((op = findopcode(w)) || scmp(w, "BRK", 4)) pushbyte(op, 0);
else if(w[0] == '^' && (l = findlabel(w + 1))) {
int off = l->addr - p.ptr - 3;
if(off < -126 || off > 126){ printf("Address %s is too far(%d).\n", w, off); return 0; }
printf("relative %s[%d]\n", w, l->addr - p.ptr - 4);
pushbyte((Sint8)(l->addr - p.ptr - 3), 1); l->refs++;
}
else if(w[0] == ':') fscanf(f, "%s", w);
else if(w[0] == ';') fscanf(f, "%s", w);
else if(w[0] == '.' && sihx(w + 1) && slen(w + 1) == 2) pushbyte(shex(w + 1), 0);
else if(w[0] == '.' && sihx(w + 1) && slen(w + 1) == 4) pushshort(shex(w + 1), 0);
else if(w[0] == '.' && (l = findlabel(w + 1))) { pushshort(findlabeladdr(w + 1), 0); l->refs++; }
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] == '#' && 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);
else if(w[0] == '+' && sihx(w + 1) && slen(w + 1) == 4) pushshort((Sint16)shex(w + 1), 1);
else if(w[0] == '-' && sihx(w + 1) && slen(w + 1) == 2) pushbyte((Sint8)(shex(w + 1) * -1), 1);
else if(w[0] == '-' && sihx(w + 1) && slen(w + 1) == 4) pushshort((Sint16)(shex(w + 1) * -1), 1);
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] == '=' && sihx(w + 1)) { pushshort(shex(w + 1), 1); pushbyte(findopcode("STR2"), 0); }
else if(w[0] == '~' && sihx(w + 1)) { pushshort(shex(w + 1), 1); pushbyte(findopcode("LDR2"), 0); }
else if((l = findlabel(w + 1))) { pushshort(findlabeladdr(w+1), w[0] == ','); l->refs++; }
else return error("Unknown label in second pass", w);
/* clang-format on */
}

View file

@ -20,5 +20,5 @@ cc -std=c89 -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werr
# cc uxn.c emulator.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -L/usr/local/lib -lSDL2 -o bin/emulator
# run
./bin/assembler projects/software/nasu.usm bin/boot.rom
./bin/assembler projects/software/left.usm bin/boot.rom
./bin/emulator bin/boot.rom

View file

@ -310,8 +310,10 @@ doctrl(Uxn *u, SDL_Event *event, int z)
{
Uint8 flag = 0x00;
Uint16 addr = devctrl->addr;
if(z && event->key.keysym.sym == SDLK_h && SDL_GetModState() & KMOD_LCTRL)
if(z && event->key.keysym.sym == SDLK_h && SDL_GetModState() & KMOD_LCTRL) {
GUIDES = !GUIDES;
redraw(pixels, u);
}
switch(event->key.keysym.sym) {
case SDLK_LCTRL: flag = 0x01; break;
case SDLK_LALT: flag = 0x02; break;

View file

@ -45,16 +45,15 @@ contexts:
- match: '\,(\S+)\s?'
scope: keyword.control
pop: true
- match: '\.(\S+)\s?'
scope: keyword.control
pop: true
- match: '\^(\S+)\s?'
scope: keyword.control
pop: true
- match: '\#(\S+)\s?'
scope: keyword.control
pop: true
- match: '\.(\S+)\s?'
scope: keyword.control
- match: '\+(\S+)\s?'
scope: string.control
pop: true
- match: '\-(\S+)\s?'
scope: string.control
# Blocks

View file

@ -6,17 +6,17 @@
,text1 ,print-label JSR2
,text2 ,print-label JSR2
#ab =dev/console.byte
#cdef =dev/console.short
#ab =CNSL.byte
#cdef =CNSL.short
BRK
@print-label ( text )
@print-label-loop
DUP2 LDR =dev/console.char ( write pointer value to console )
#0001 ADD2 ( increment string pointer )
DUP2 LDR #00 NEQ ,print-label-loop ROT JMP2? POP2 ( while *ptr!=0 goto loop )
@print-label-loop NOP
( send ) DUP2 LDR =CNSL.char
( incr ) #0001 ADD2
DUP2 LDR #00 NEQ ^print-label-loop MUL JMPS
POP2
RTS
@ -27,7 +27,7 @@ RTS
|c000 @FRAME
|d000 @ERROR
|FF00 ;dev/console Console
|FF00 ;CNSL Console
|FFF0 .RESET .FRAME .ERROR ( vectors )
|FFF8 [ 13fd 1ef3 1bf2 ] ( palette )

View file

@ -45,7 +45,7 @@
,filepath ,load-file JSR2
( place textarea )
#0018 =textarea.x1 ~dev/screen.height #0008 SUB2 =textarea.y2
#0018 =textarea.x1 ~SCRN.height #0008 SUB2 =textarea.y2
,select JSR2
,redraw JSR2
@ -56,62 +56,62 @@ BRK
( ctrl )
,ctrl-end ~dev/ctrl #00 EQU ~lock #00 NEQ #0000 NEQ2 JMP2? POP2
,ctrl-end ~CTRL #00 EQU ~lock #00 NEQ #0000 NEQ2 JMP2? POP2
( lock ) #04 =lock
,no-ctrl-up ~dev/ctrl #10 NEQ JMP2? POP2
,no-ctrl-up ~CTRL #10 NEQ JMP2? POP2
( clamp ) ,no-ctrl-up ~position.y #0000 EQU2 JMP2? POP2
,find-lineoffset JSR2 =position.x
~position.y #0001 SUB2 =position.y
,find-selection JSR2 DUP2 =selection.from #0001 ADD2 =selection.to
,clamp-selection JSR2 ,redraw JSR2 ,ctrl-end JMP2
@no-ctrl-up
,no-ctrl-down ~dev/ctrl #20 NEQ JMP2? POP2
,no-ctrl-down ~CTRL #20 NEQ JMP2? POP2
,find-lineoffset JSR2 =position.x ~position.y #0001 ADD2 =position.y
,find-selection JSR2 DUP2 =selection.from #0001 ADD2 =selection.to
,clamp-selection JSR2 ,redraw JSR2 ,ctrl-end JMP2
@no-ctrl-down
,no-ctrl-left ~dev/ctrl #40 NEQ JMP2? POP2
,no-ctrl-left ~CTRL #40 NEQ JMP2? POP2
( clamp ) ,no-ctrl-left ~selection.from ,document.body EQU2 JMP2? POP2
~selection.from #0001 SUB2 DUP2 =selection.from #0001 ADD2 =selection.to
,clamp-selection JSR2 ,redraw JSR2 ,ctrl-end JMP2
@no-ctrl-left
,no-ctrl-right ~dev/ctrl #80 NEQ JMP2? POP2
,no-ctrl-right ~CTRL #80 NEQ JMP2? POP2
~selection.from #0001 ADD2 DUP2 =selection.from #0001 ADD2 =selection.to
,clamp-selection JSR2 ,redraw JSR2 ,ctrl-end JMP2
@no-ctrl-right
( alt )
,no-alt ~dev/ctrl #0f AND #02 NEQ JMP2? POP2
,no-aup ~dev/ctrl #04 ROR #01 NEQ JMP2? POP2
,no-alt ~CTRL #0f AND #02 NEQ JMP2? POP2
,no-aup ~CTRL #04 ROR #01 NEQ JMP2? POP2
,find-wordstart JSR2 =selection.to
,clamp-selection JSR2 ,redraw JSR2 ,ctrl-end JMP2
@no-aup
,no-adown ~dev/ctrl #04 ROR #02 NEQ JMP2? POP2
,no-adown ~CTRL #04 ROR #02 NEQ JMP2? POP2
,find-wordend JSR2 =selection.to
,clamp-selection JSR2 ,redraw JSR2 ,ctrl-end JMP2
@no-adown
,no-aleft ~dev/ctrl #04 ROR #04 NEQ JMP2? POP2
,no-aleft ~CTRL #04 ROR #04 NEQ JMP2? POP2
~selection.to #0001 SUB2 =selection.to
,clamp-selection JSR2 ,redraw JSR2 ,ctrl-end JMP2
@no-aleft
,no-aright ~dev/ctrl #04 ROR #08 NEQ JMP2? POP2
,no-aright ~CTRL #04 ROR #08 NEQ JMP2? POP2
~selection.to #0001 ADD2 =selection.to
,clamp-selection JSR2 ,redraw JSR2 ,ctrl-end JMP2
@no-aright
@no-alt
( ctrl )
,no-ctrl ~dev/ctrl #0f AND #01 NEQ JMP2? POP2
,no-cup ~dev/ctrl #04 ROR #01 NEQ JMP2? POP2
,no-ctrl ~CTRL #0f AND #01 NEQ JMP2? POP2
,no-cup ~CTRL #04 ROR #01 NEQ JMP2? POP2
~scroll.y #0004 SUB2 =scroll.y
,redraw JSR2 ,ctrl-end JMP2
@no-cup
,no-cdown ~dev/ctrl #04 ROR #02 NEQ JMP2? POP2
,no-cdown ~CTRL #04 ROR #02 NEQ JMP2? POP2
~scroll.y #0004 ADD2 =scroll.y
,redraw JSR2 ,ctrl-end JMP2
@no-cdown
,no-cleft ~dev/ctrl #04 ROR #04 NEQ JMP2? POP2
,no-cleft ~CTRL #04 ROR #04 NEQ JMP2? POP2
,goto-linestart JSR2 ,redraw JSR2 ,ctrl-end JMP2
@no-cleft
,no-cright ~dev/ctrl #04 ROR #08 NEQ JMP2? POP2
,no-cright ~CTRL #04 ROR #08 NEQ JMP2? POP2
,goto-lineend JSR2 ,redraw JSR2 ,ctrl-end JMP2
@no-cright
@no-ctrl
@ -120,39 +120,39 @@ BRK
( keys )
,keys-end ~dev/key #00 EQU JMP2? POP2
,keys-end ~KEYS #00 EQU JMP2? POP2
,no-backspace ~dev/key #08 NEQ JMP2? POP2
,no-backspace ~KEYS #08 NEQ JMP2? POP2
( erase )
~selection.to ~selection.from SUB2 ,shift-left JSR2
~selection.from #0001 SUB2 =selection.from
~selection.from #0001 ADD2 =selection.to
( release ) #00 =dev/key
( release ) #00 =KEYS
,redraw JSR2
,keys-end JMP2
@no-backspace
( insert )
~selection.to ~selection.from SUB2 ,shift-right JSR2
~dev/key ~selection.from STR
~KEYS ~selection.from STR
~selection.from #0001 ADD2 =selection.from
~selection.from #0001 ADD2 =selection.to
( release ) #00 =dev/key
( release ) #00 =KEYS
,redraw JSR2
@keys-end
( mouse )
,touch-end ~dev/mouse.state #00 EQU JMP2? POP2
,touch-end ~MOUS.state #00 EQU JMP2? POP2
,touch-linebar ~dev/mouse.x #0010 LTH2 JMP2? POP2
,touch-body ~dev/mouse.x ~dev/screen.width #0008 SUB2 LTH2 JMP2? POP2
,touch-linebar ~MOUS.x #0010 LTH2 JMP2? POP2
,touch-body ~MOUS.x ~SCRN.width #0008 SUB2 LTH2 JMP2? POP2
,touch-scrollbar JMP2
@touch-end
~dev/mouse.state =touch.state
~MOUS.state =touch.state
( unlock ) ,skip-unlock ~lock #00 EQU JMP2? POP2 ~lock #01 SUB =lock @skip-unlock
@ -162,15 +162,15 @@ BRK
@touch-scrollbar
,no-click-scroll-up ~dev/mouse.y #0008 GTH2 JMP2? POP2
,no-click-scroll-up ~MOUS.y #0008 GTH2 JMP2? POP2
( decr ) ~scroll.y #00 ~scroll.y #0000 NEQ2 SUB2 =scroll.y
,redraw JSR2 ,touch-end JMP2
@no-click-scroll-up
,no-click-scroll-down ~dev/mouse.y ~dev/screen.height #0008 SUB2 LTH2 JMP2? POP2
,no-click-scroll-down ~MOUS.y ~SCRN.height #0008 SUB2 LTH2 JMP2? POP2
( incr ) ~scroll.y #0001 ADD2 =scroll.y
,redraw JSR2 ,touch-end JMP2
@no-click-scroll-down
~dev/mouse.y #0008 SUB2 =scroll.y
~MOUS.y #0008 SUB2 =scroll.y
,redraw JSR2
,touch-end JMP2
@ -178,7 +178,7 @@ RTS
@touch-linebar
~dev/mouse.y #0008 DIV2 ~scroll.y ADD2 =position.y #0000 =position.x
~MOUS.y #0008 DIV2 ~scroll.y ADD2 =position.y #0000 =position.x
,find-selection JSR2 DUP2 =selection.from #0001 ADD2 =selection.to
,redraw JSR2
,touch-end JMP2
@ -187,10 +187,10 @@ RTS
@touch-body
~dev/mouse.y #0008 DIV2 ~scroll.y ADD2 =position.y
~dev/mouse.x ~textarea.x1 SUB2 #0007 ADD2 #0007 DIV2 =position.x
~MOUS.y #0008 DIV2 ~scroll.y ADD2 =position.y
~MOUS.x ~textarea.x1 SUB2 #0007 ADD2 #0007 DIV2 =position.x
,touch-when ~dev/mouse.state ~touch.state NEQ ~dev/ctrl #0f AND #02 NEQ #0101 EQU2 JMP2? POP2
,touch-when ~MOUS.state ~touch.state NEQ ~CTRL #0f AND #02 NEQ #0101 EQU2 JMP2? POP2
( on drag )
,find-selection JSR2 #0001 ADD2 =selection.to
,clamp-selection JSR2
@ -207,7 +207,7 @@ RTS
@load-file ( path )
=dev/file.name #8000 =dev/file.length ,document.body =dev/file.load
=FILE.name #8000 =FILE.length ,document.body =FILE.load
( get file length )
,document.body =document.eof
@ -379,75 +379,75 @@ RTS
( save/load icons )
~dev/screen.height #0008 SUB2 =dev/sprite.y
~SCRN.height #0008 SUB2 =SPRT.y
~dev/screen.width #0018 SUB2 =dev/sprite.x
,load_icn =dev/sprite.addr
#02 =dev/sprite.color
~SCRN.width #0018 SUB2 =SPRT.x
,load_icn =SPRT.addr
#02 =SPRT.color
~dev/screen.width #0010 SUB2 =dev/sprite.x
,save_icn =dev/sprite.addr
#02 =dev/sprite.color
~SCRN.width #0010 SUB2 =SPRT.x
,save_icn =SPRT.addr
#02 =SPRT.color
RTS
@draw-lines
#0000 =j
#0000 =dev/sprite.x #0000 =dev/sprite.y
#0000 =SPRT.x #0000 =SPRT.y
@draw-lines-loop
~scroll.y ~j ADD2 =addr
#0000 =dev/sprite.x
,font_hex #00 ,addr #0001 ADD2 LDR #f0 AND #04 ROR #08 MUL ADD2 =dev/sprite.addr
( draw ) #02 ~addr ~position.y EQU2 #06 MUL ADD =dev/sprite.color
#0008 =dev/sprite.x
,font_hex #00 ,addr #0001 ADD2 LDR #0f AND #08 MUL ADD2 =dev/sprite.addr
( draw ) #02 ~addr ~position.y EQU2 #06 MUL ADD =dev/sprite.color
#0000 =SPRT.x
,font_hex #00 ,addr #0001 ADD2 LDR #f0 AND #04 ROR #08 MUL ADD2 =SPRT.addr
( draw ) #02 ~addr ~position.y EQU2 #06 MUL ADD =SPRT.color
#0008 =SPRT.x
,font_hex #00 ,addr #0001 ADD2 LDR #0f AND #08 MUL ADD2 =SPRT.addr
( draw ) #02 ~addr ~position.y EQU2 #06 MUL ADD =SPRT.color
( incr ) ~j #0001 ADD2 =j
( incr ) ~dev/sprite.y #0008 ADD2 =dev/sprite.y
,draw-lines-loop ~j ~dev/screen.height #0008 SUB2 #0008 DIV2 NEQ2 JMP2? POP2
( incr ) ~SPRT.y #0008 ADD2 =SPRT.y
,draw-lines-loop ~j ~SCRN.height #0008 SUB2 #0008 DIV2 NEQ2 JMP2? POP2
RTS
@draw-short ( short )
=addr
,font_hex #00 ,addr LDR #f0 AND #04 ROR #08 MUL ADD2 =dev/sprite.addr
( draw ) #0e =dev/sprite.color
~dev/sprite.x #0008 ADD2 =dev/sprite.x
,font_hex #00 ,addr LDR #0f AND #08 MUL ADD2 =dev/sprite.addr
( draw ) #0e =dev/sprite.color
~dev/sprite.x #0008 ADD2 =dev/sprite.x
,font_hex #00 ,addr #0001 ADD2 LDR #f0 AND #04 ROR #08 MUL ADD2 =dev/sprite.addr
( draw ) #0e =dev/sprite.color
~dev/sprite.x #0008 ADD2 =dev/sprite.x
,font_hex #00 ,addr #0001 ADD2 LDR #0f AND #08 MUL ADD2 =dev/sprite.addr
( draw ) #0e =dev/sprite.color
,font_hex #00 ,addr LDR #f0 AND #04 ROR #08 MUL ADD2 =SPRT.addr
( draw ) #0e =SPRT.color
~SPRT.x #0008 ADD2 =SPRT.x
,font_hex #00 ,addr LDR #0f AND #08 MUL ADD2 =SPRT.addr
( draw ) #0e =SPRT.color
~SPRT.x #0008 ADD2 =SPRT.x
,font_hex #00 ,addr #0001 ADD2 LDR #f0 AND #04 ROR #08 MUL ADD2 =SPRT.addr
( draw ) #0e =SPRT.color
~SPRT.x #0008 ADD2 =SPRT.x
,font_hex #00 ,addr #0001 ADD2 LDR #0f AND #08 MUL ADD2 =SPRT.addr
( draw ) #0e =SPRT.color
RTS
@draw-cursor
~mouse.x ~dev/mouse.x NEQU2
~mouse.y ~dev/mouse.y NEQU2
~mouse.x ~MOUS.x NEQU2
~mouse.y ~MOUS.y NEQU2
#0000 EQU2 RTS? ( Return if unchanged )
( clear last cursor )
~mouse.x =dev/sprite.x
~mouse.y =dev/sprite.y
,blank_icn =dev/sprite.addr
#10 =dev/sprite.color
~mouse.x =SPRT.x
~mouse.y =SPRT.y
,blank_icn =SPRT.addr
#10 =SPRT.color
( record mouse positions )
~dev/mouse.x =mouse.x
~dev/mouse.y =mouse.y
~MOUS.x =mouse.x
~MOUS.y =mouse.y
( draw new cursor )
~mouse.x =dev/sprite.x
~mouse.y =dev/sprite.y
,cursor_icn =dev/sprite.addr
#13 =dev/sprite.color
~mouse.x =SPRT.x
~mouse.y =SPRT.y
,cursor_icn =SPRT.addr
#13 =SPRT.color
RTS
@ -467,42 +467,42 @@ RTS
@find-scroll-offset-end
~textarea.addr #0000 ADD2 =textarea.addr
#0000 =dev/sprite.y
#0000 =SPRT.y
~textarea.addr =j
#0018 =dev/sprite.x
#0018 =SPRT.x
@draw-textarea-loop
,draw-textarea-end ~dev/sprite.y ~dev/screen.height #0010 SUB2 GTH2 JMP2? POP2
,draw-textarea-end ~SPRT.y ~SCRN.height #0010 SUB2 GTH2 JMP2? POP2
( get character )
,font #00 ~j LDR #20 SUB #0008 MUL2 ADD2 =dev/sprite.addr
,font #00 ~j LDR #20 SUB #0008 MUL2 ADD2 =SPRT.addr
( draw ) #01
~j ~selection.from #0001 SUB2 GTH2
~j ~selection.to LTH2 #0101 EQU2
#05 MUL ADD =dev/sprite.color
#05 MUL ADD =SPRT.color
,no-linebreak ~j LDR #0a NEQ ~j LDR #0d NEQ #0101 EQU2 JMP2? POP2
( draw linebreak )
,linebreak_icn =dev/sprite.addr
,linebreak_icn =SPRT.addr
( draw ) #03
~j ~selection.from #0001 SUB2 GTH2
~j ~selection.to LTH2 #0101 EQU2
#05 MUL ADD =dev/sprite.color
#05 MUL ADD =SPRT.color
( fill clear )
@fill-clear
( incr ) ~dev/sprite.x #0008 ADD2 =dev/sprite.x
,font =dev/sprite.addr
#01 =dev/sprite.color
,fill-clear ~dev/sprite.x ~dev/screen.width #0008 SUB2 LTH2 JMP2? POP2
#0010 =dev/sprite.x
( incr ) ~dev/sprite.y #0008 ADD2 =dev/sprite.y
( incr ) ~SPRT.x #0008 ADD2 =SPRT.x
,font =SPRT.addr
#01 =SPRT.color
,fill-clear ~SPRT.x ~SCRN.width #0008 SUB2 LTH2 JMP2? POP2
#0010 =SPRT.x
( incr ) ~SPRT.y #0008 ADD2 =SPRT.y
@no-linebreak
( incr ) ~j #0001 ADD2 =j
( incr ) ~dev/sprite.x #0007 ADD2 =dev/sprite.x
( incr ) ~SPRT.x #0007 ADD2 =SPRT.x
,draw-textarea-loop ~j LDR #00 NEQ JMP2? POP2
@ -512,40 +512,40 @@ RTS
@draw-scrollbar
~dev/screen.width #0008 SUB2 =dev/sprite.x
#0000 =dev/sprite.y
,scrollbar_bg =dev/sprite.addr
~SCRN.width #0008 SUB2 =SPRT.x
#0000 =SPRT.y
,scrollbar_bg =SPRT.addr
@draw-scrollbar-loop
( draw ) #08 =dev/sprite.color
( incr ) ~dev/sprite.y #0008 ADD2 =dev/sprite.y
,draw-scrollbar-loop ~dev/sprite.y ~dev/screen.height LTH2 JMP2? POP2
( draw ) #08 =SPRT.color
( incr ) ~SPRT.y #0008 ADD2 =SPRT.y
,draw-scrollbar-loop ~SPRT.y ~SCRN.height LTH2 JMP2? POP2
#0000 =dev/sprite.y
,arrowup_icn =dev/sprite.addr
( draw ) #08 =dev/sprite.color
#0000 =SPRT.y
,arrowup_icn =SPRT.addr
( draw ) #08 =SPRT.color
( at )
~scroll.y #0008 ADD2 =dev/sprite.y
,scrollbar_fg =dev/sprite.addr
( draw ) #08 =dev/sprite.color
~scroll.y #0008 ADD2 =SPRT.y
,scrollbar_fg =SPRT.addr
( draw ) #08 =SPRT.color
~dev/screen.height #0008 SUB2 =dev/sprite.y
,arrowdown_icn =dev/sprite.addr
( draw ) #08 =dev/sprite.color
~SCRN.height #0008 SUB2 =SPRT.y
,arrowdown_icn =SPRT.addr
( draw ) #08 =SPRT.color
RTS
@draw-titlebar
#0018 ~dev/screen.height #0008 SUB2 #09 ,filepath
#0018 ~SCRN.height #0008 SUB2 #09 ,filepath
( load ) =label.addr =label.color =dev/sprite.y =dev/sprite.x
( load ) =label.addr =label.color =SPRT.y =SPRT.x
~label.addr
@draw-titlebar-loop
( draw ) DUP2 LDR #00 SWP #20 SUB #0008 MUL2 ,font ADD2 =dev/sprite.addr ~label.color =dev/sprite.color
( draw ) DUP2 LDR #00 SWP #20 SUB #0008 MUL2 ,font ADD2 =SPRT.addr ~label.color =SPRT.color
( incr ) #0001 ADD2
( incr ) ~dev/sprite.x #0008 ADD2 =dev/sprite.x
( incr ) ~SPRT.x #0008 ADD2 =SPRT.x
DUP2 LDR #00 NEQ ,draw-titlebar-loop ROT JMP2? POP2
POP2
@ -628,20 +628,20 @@ RTS
@arrowdown_icn [ 0010 1010 fe7c 3810 ]
@load_icn [ feaa d6aa d4aa f400 ]
@save_icn [ fe82 8282 848a f400 ]
@filepath [ test.txt 00 ]
@filepath1 [ projects/software/left.usm 00 ]
@filepath1 [ projects/examples/jumptest.usm 00 ]
@filepath [ projects/software/left.usm 00 ]
|4000 ;document Document
|d000 @ERROR BRK
|FF00 ;dev/console Console
|FF10 ;dev/screen Screen
|FF20 ;dev/sprite Sprite
|FF30 ;dev/ctrl Controller
|FF40 ;dev/key Keyboard
|FF50 ;dev/mouse Mouse
|FF60 ;dev/file File
|FF10 ;SCRN Screen
|FF20 ;SPRT Sprite
|FF30 ;CTRL Controller
|FF40 ;KEYS Keyboard
|FF50 ;MOUS Mouse
|FF60 ;FILE File
|FFF0 .RESET .FRAME .ERROR ( vectors )
|FFF8 [ a0fe a0f7 a0f2 ] ( palette )

View file

@ -32,12 +32,12 @@
|0100 @RESET
~dev/screen.width #0002 DIV2 #008a SUB2 =bankview.x
~dev/screen.height #0002 DIV2 #003f SUB2 =bankview.y
~SCRN.width #0002 DIV2 #008a SUB2 =bankview.x
~SCRN.height #0002 DIV2 #003f SUB2 =bankview.y
,bank1 =bankview.addr
~dev/screen.width #0002 DIV2 #0002 ADD2 =tileview.x
~dev/screen.height #0002 DIV2 #003f SUB2 =tileview.y
~SCRN.width #0002 DIV2 #0002 ADD2 =tileview.x
~SCRN.height #0002 DIV2 #003f SUB2 =tileview.y
,bank1 #0448 ADD2 =tileview.addr
,redraw JSR2
@ -48,28 +48,28 @@ BRK
( keyboard controls )
,no-key ~dev/key #00 EQU JMP2? POP2
,no-key ~KEYS #00 EQU JMP2? POP2
,no-key ~dev/key #31 LTH JMP2? POP2
,no-key ~dev/key #33 GTH JMP2? POP2
( select ) ~dev/key #31 SUB =bankview.mode
( release ) #00 =dev/key
,no-key ~KEYS #31 LTH JMP2? POP2
,no-key ~KEYS #33 GTH JMP2? POP2
( select ) ~KEYS #31 SUB =bankview.mode
( release ) #00 =KEYS
,redraw JSR2
@no-key
,no-ctrl ~dev/ctrl.buttons #00 EQU JMP2? POP2
,no-ctrl ~CTRL.buttons #00 EQU JMP2? POP2
,no-ctrl-up ~dev/ctrl.buttons #10 EQU JMP2? POP2
,no-ctrl-up ~CTRL.buttons #10 EQU JMP2? POP2
~tileview.addr #0080 ADD2 =tileview.addr
@no-ctrl-up
,no-ctrl-down ~dev/ctrl.buttons #20 EQU JMP2? POP2
,no-ctrl-down ~CTRL.buttons #20 EQU JMP2? POP2
~tileview.addr #0080 SUB2 =tileview.addr
@no-ctrl-down
,no-ctrl-left ~dev/ctrl.buttons #40 EQU JMP2? POP2
,no-ctrl-left ~CTRL.buttons #40 EQU JMP2? POP2
~tileview.addr #0008 ADD2 =tileview.addr
@no-ctrl-left
,no-ctrl-right ~dev/ctrl.buttons #80 EQU JMP2? POP2
,no-ctrl-right ~CTRL.buttons #80 EQU JMP2? POP2
~tileview.addr #0008 SUB2 =tileview.addr
@no-ctrl-right
~tileview.addr #0800 DIV2 #0800 MUL2 =bankview.addr
@ -79,30 +79,30 @@ BRK
( mouse controls )
,click-end ~dev/mouse.state #00 EQU JMP2? POP2
,click-end ~MOUS.state #00 EQU JMP2? POP2
( toolbar )
,no-toolbar-click ~dev/mouse.y ~bankview.y #0010 SUB2 SUB2 #0008 DIV2 #0000 NEQ2 JMP2? POP2
,no-toolbar-click ~MOUS.y ~bankview.y #0010 SUB2 SUB2 #0008 DIV2 #0000 NEQ2 JMP2? POP2
( brush )
,no-brush-click ~dev/mouse.x ~bankview.x SUB2 #0008 DIV2 #000d LTH2 JMP2? POP2
,no-brush-click ~dev/mouse.x ~bankview.x SUB2 #0008 DIV2 #000f GTH2 JMP2? POP2
,no-brush-click ~MOUS.x ~bankview.x SUB2 #0008 DIV2 #000d LTH2 JMP2? POP2
,no-brush-click ~MOUS.x ~bankview.x SUB2 #0008 DIV2 #000f GTH2 JMP2? POP2
( select ) ~mouse.x ~bankview.x SUB2 #0008 DIV2 #000d SUB2 SWP POP =bankview.mode
( release ) #00 =dev/mouse.state
( release ) #00 =MOUS.state
,redraw JSR2 ,click-end JMP2
@no-brush-click
,no-load-click ~dev/mouse.x ~tileview.x SUB2 #0008 DIV2 #000e NEQU2 JMP2? POP2
( load ) ,filename =dev/file.name #0800 =dev/file.length ~bankview.addr =dev/file.load
( release ) #00 =dev/mouse.state
,no-load-click ~MOUS.x ~tileview.x SUB2 #0008 DIV2 #000e NEQU2 JMP2? POP2
( load ) ,filename =FILE.name #0800 =FILE.length ~bankview.addr =FILE.load
( release ) #00 =MOUS.state
,redraw JSR2 ,click-end JMP2
@no-load-click
,no-save-click ~dev/mouse.x ~tileview.x SUB2 #0008 DIV2 #000f NEQU2 JMP2? POP2
( save ) ,filename =dev/file.name #0800 =dev/file.length ~bankview.addr =dev/file.save
( release ) #00 =dev/mouse.state
,no-save-click ~MOUS.x ~tileview.x SUB2 #0008 DIV2 #000f NEQU2 JMP2? POP2
( save ) ,filename =FILE.name #0800 =FILE.length ~bankview.addr =FILE.save
( release ) #00 =MOUS.state
,redraw JSR2 ,click-end JMP2
@no-save-click
@ -110,8 +110,8 @@ BRK
( bankview )
~dev/mouse.x ~bankview.x GTH2 ~dev/mouse.x ~bankview.x #0080 ADD2 LTH2 #0101 EQU2
~dev/mouse.y ~bankview.y GTH2 ~dev/mouse.y ~bankview.y #0080 ADD2 LTH2 #0101 EQU2
~MOUS.x ~bankview.x GTH2 ~MOUS.x ~bankview.x #0080 ADD2 LTH2 #0101 EQU2
~MOUS.y ~bankview.y GTH2 ~MOUS.y ~bankview.y #0080 ADD2 LTH2 #0101 EQU2
#0101 NEQ2 ,no-bank-click ROT JMP2? POP2
,not-copy-mode ~bankview.mode #01 NEQ JMP2? POP2
@ -119,8 +119,8 @@ BRK
@copy-loop
( load ) ~tileview.addr ~i ADD LDR
( get touch addr )
~dev/mouse.x ~bankview.x SUB2 #0008 DIV2 #0008 MUL2
~dev/mouse.y ~bankview.y SUB2 #0008 DIV2 #0008 MUL2 #0010 MUL2 ADD2
~MOUS.x ~bankview.x SUB2 #0008 DIV2 #0008 MUL2
~MOUS.y ~bankview.y SUB2 #0008 DIV2 #0008 MUL2 #0010 MUL2 ADD2
~bankview.addr ADD2 #00 ~i ADD2 STR
( incr ) ~i #01 ADD =i
,copy-loop ~i #08 LTH JMP2? POP2
@ -132,16 +132,16 @@ BRK
@erase-loop
#00
( get touch addr )
~dev/mouse.x ~bankview.x SUB2 #0008 DIV2 #0008 MUL2
~dev/mouse.y ~bankview.y SUB2 #0008 DIV2 #0008 MUL2 #0010 MUL2 ADD2
~MOUS.x ~bankview.x SUB2 #0008 DIV2 #0008 MUL2
~MOUS.y ~bankview.y SUB2 #0008 DIV2 #0008 MUL2 #0010 MUL2 ADD2
~bankview.addr ADD2 #00 ~i ADD2 STR
( incr ) ~i #01 ADD =i
,erase-loop ~i #08 LTH JMP2? POP2
,redraw JSR2 ,click-end JMP2
@not-erase-mode
~dev/mouse.x ~bankview.x SUB2 #0008 DIV2 #0008 MUL2
~dev/mouse.y ~bankview.y SUB2 #0008 DIV2 #0008 MUL2 #0010 MUL2 ADD2
~MOUS.x ~bankview.x SUB2 #0008 DIV2 #0008 MUL2
~MOUS.y ~bankview.y SUB2 #0008 DIV2 #0008 MUL2 #0010 MUL2 ADD2
~bankview.addr ADD2 =tileview.addr
,redraw JSR2 ,click-end JMP2
@ -149,16 +149,16 @@ BRK
( tileview )
~dev/mouse.x ~tileview.x GTH2 ~dev/mouse.x ~tileview.x #0080 ADD2 LTH2 #0101 EQU2
~dev/mouse.y ~tileview.y GTH2 ~dev/mouse.y ~tileview.y #0080 ADD2 LTH2 #0101 EQU2
~MOUS.x ~tileview.x GTH2 ~MOUS.x ~tileview.x #0080 ADD2 LTH2 #0101 EQU2
~MOUS.y ~tileview.y GTH2 ~MOUS.y ~tileview.y #0080 ADD2 LTH2 #0101 EQU2
#0101 NEQ2 ,no-tile-click ROT JMP2? POP2
~dev/mouse.x ~tileview.x SUB2 #0008 DIV2 #0008 MUL2 #0040 DIV2
~dev/mouse.y ~tileview.y SUB2 #0008 DIV2 #0008 MUL2 #0040 DIV2 #0002 MUL2 ADD2
~MOUS.x ~tileview.x SUB2 #0008 DIV2 #0008 MUL2 #0040 DIV2
~MOUS.y ~tileview.y SUB2 #0008 DIV2 #0008 MUL2 #0040 DIV2 #0002 MUL2 ADD2
#0008 MUL2
~tileview.addr ADD2 =addr ( addr offset )
~dev/mouse.x ~tileview.x SUB2 ~dev/mouse.x ~tileview.x SUB2 #0040 DIV2 #0040 MUL2 SUB2 =pos.x
~dev/mouse.y ~tileview.y SUB2 ~dev/mouse.y ~tileview.y SUB2 #0040 DIV2 #0040 MUL2 SUB2 =pos.y
~MOUS.x ~tileview.x SUB2 ~MOUS.x ~tileview.x SUB2 #0040 DIV2 #0040 MUL2 SUB2 =pos.x
~MOUS.y ~tileview.y SUB2 ~MOUS.y ~tileview.y SUB2 #0040 DIV2 #0040 MUL2 SUB2 =pos.y
,no-fill-mode ~bankview.mode #01 NEQ JMP2? POP2
( fill row ) #ff ~addr ~pos.y #0008 DIV2 ADD2 STR
,redraw JSR2 ,click-end JMP2
@ -177,17 +177,17 @@ BRK
( operations )
,no-operations ~dev/mouse.y ~tileview.y SUB2 #0008 DIV2 #000c NEQ2 JMP2? POP2
,no-operations ~MOUS.y ~tileview.y SUB2 #0008 DIV2 #000c NEQ2 JMP2? POP2
,no-move-up ~dev/mouse.x ~tileview.x SUB2 #0008 DIV2 #0011 NEQ2 JMP2? POP2
,no-move-up ~MOUS.x ~tileview.x SUB2 #0008 DIV2 #0011 NEQ2 JMP2? POP2
,op_shiftup JSR2
( release ) #00 =dev/mouse.state
( release ) #00 =MOUS.state
,redraw JSR2 ,click-end JMP2
@no-move-up
,no-move-down ~dev/mouse.x ~tileview.x SUB2 #0008 DIV2 #0012 NEQ2 JMP2? POP2
,no-move-down ~MOUS.x ~tileview.x SUB2 #0008 DIV2 #0012 NEQ2 JMP2? POP2
,op_shiftdown JSR2
( release ) #00 =dev/mouse.state
( release ) #00 =MOUS.state
,redraw JSR2 ,click-end JMP2
@no-move-down
@ -240,66 +240,66 @@ RTS
( position )
~bankview.x =dev/sprite.x
~bankview.y #0010 SUB2 =dev/sprite.y
~bankview.x =SPRT.x
~bankview.y #0010 SUB2 =SPRT.y
~bankview.addr ,draw-short JSR2
( toolbar )
~bankview.x #0068 ADD2 =dev/sprite.x
~bankview.y #0010 SUB2 =dev/sprite.y
,tool_selector =dev/sprite.addr
#01 ~bankview.mode #00 EQU ADD =dev/sprite.color
~bankview.x #0068 ADD2 =SPRT.x
~bankview.y #0010 SUB2 =SPRT.y
,tool_selector =SPRT.addr
#01 ~bankview.mode #00 EQU ADD =SPRT.color
~dev/sprite.x #0008 ADD2 =dev/sprite.x
,tool_hand =dev/sprite.addr
#01 ~bankview.mode #01 EQU ADD =dev/sprite.color
~SPRT.x #0008 ADD2 =SPRT.x
,tool_hand =SPRT.addr
#01 ~bankview.mode #01 EQU ADD =SPRT.color
~dev/sprite.x #0008 ADD2 =dev/sprite.x
,tool_eraser =dev/sprite.addr
#01 ~bankview.mode #02 EQU ADD =dev/sprite.color
~SPRT.x #0008 ADD2 =SPRT.x
,tool_eraser =SPRT.addr
#01 ~bankview.mode #02 EQU ADD =SPRT.color
~tileview.x #0070 ADD2 =dev/sprite.x
,load_icn =dev/sprite.addr
#01 =dev/sprite.color
~tileview.x #0070 ADD2 =SPRT.x
,load_icn =SPRT.addr
#01 =SPRT.color
~tileview.x #0078 ADD2 =dev/sprite.x
,save_icn =dev/sprite.addr
#01 =dev/sprite.color
~tileview.x #0078 ADD2 =SPRT.x
,save_icn =SPRT.addr
#01 =SPRT.color
( guides )
#00 =i ,font_hex =dev/sprite.addr
#00 =i ,font_hex =SPRT.addr
@draw-bankview-guides
~bankview.x #0010 SUB2 =dev/sprite.x
~bankview.y #00 ~i #08 MUL ADD2 =dev/sprite.y
( draw ) #02 =dev/sprite.color
~bankview.x #00 ~i #08 MUL ADD2 =dev/sprite.x
~bankview.y #0088 ADD2 =dev/sprite.y
( draw ) #02 =dev/sprite.color
~dev/sprite.addr #0008 ADD2 =dev/sprite.addr
~bankview.x #0010 SUB2 =SPRT.x
~bankview.y #00 ~i #08 MUL ADD2 =SPRT.y
( draw ) #02 =SPRT.color
~bankview.x #00 ~i #08 MUL ADD2 =SPRT.x
~bankview.y #0088 ADD2 =SPRT.y
( draw ) #02 =SPRT.color
~SPRT.addr #0008 ADD2 =SPRT.addr
( incr ) ~i #01 ADD =i
,draw-bankview-guides ~i #10 LTH JMP2? POP2
( body )
~bankview.x =dev/sprite.x ~bankview.y =dev/sprite.y
#00 =pt.x #00 =pt.y ~bankview.addr =dev/sprite.addr
~bankview.x =SPRT.x ~bankview.y =SPRT.y
#00 =pt.x #00 =pt.y ~bankview.addr =SPRT.addr
@draw-bankview-tiles-ver
#00 =pt.x
~bankview.x =dev/sprite.x
~bankview.x =SPRT.x
@draw-bankview-tiles-hor
( draw ) #01 =dev/sprite.color
,no-highlight ~dev/sprite.addr ~tileview.addr LTH2 JMP2? POP2
,no-highlight ~dev/sprite.addr ~tileview.addr #0018 ADD2 GTH2 JMP2? POP2
( draw ) #0c =dev/sprite.color
( draw ) #01 =SPRT.color
,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
( incr ) ~dev/sprite.x #0008 ADD2 =dev/sprite.x
( incr ) ~dev/sprite.addr #0008 ADD2 =dev/sprite.addr
( 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
( incr ) ~pt.y #01 ADD =pt.y
( incr ) ~dev/sprite.y #0008 ADD2 =dev/sprite.y
( incr ) ~SPRT.y #0008 ADD2 =SPRT.y
,draw-bankview-tiles-ver ~pt.y #10 LTH JMP2? POP2
RTS
@ -308,96 +308,96 @@ RTS
~tileview.x #0002 SUB2 ~tileview.y #0002 SUB2 ~tileview.x #0080 ADD2 ~tileview.y #0081 ADD2 #03 ,line-rect JSR2
~tileview.x #0028 ADD2 =dev/sprite.x
~tileview.y #0010 SUB2 =dev/sprite.y
~tileview.addr =dev/sprite.addr
#03 =dev/sprite.color
~tileview.x #0028 ADD2 =SPRT.x
~tileview.y #0010 SUB2 =SPRT.y
~tileview.addr =SPRT.addr
#03 =SPRT.color
( position )
~tileview.x =dev/sprite.x
~tileview.y #0010 SUB2 =dev/sprite.y
~tileview.x =SPRT.x
~tileview.y #0010 SUB2 =SPRT.y
~tileview.addr ,draw-short JSR2
( body )
~tileview.x =dev/sprite.x
~tileview.y =dev/sprite.y
~tileview.x =SPRT.x
~tileview.y =SPRT.y
~tileview.addr =tileview.addr
,draw-tileview-icn JSR2
~tileview.x #0040 ADD2 =dev/sprite.x
~tileview.y =dev/sprite.y
~tileview.x #0040 ADD2 =SPRT.x
~tileview.y =SPRT.y
~tileview.addr #0008 ADD2 =tileview.addr
,draw-tileview-icn JSR2
~tileview.x =dev/sprite.x
~tileview.y #0040 ADD2 =dev/sprite.y
~tileview.x =SPRT.x
~tileview.y #0040 ADD2 =SPRT.y
~tileview.addr #0008 ADD2 =tileview.addr
,draw-tileview-icn JSR2
~tileview.x #0040 ADD2 =dev/sprite.x
~tileview.y #0040 ADD2 =dev/sprite.y
~tileview.x #0040 ADD2 =SPRT.x
~tileview.y #0040 ADD2 =SPRT.y
~tileview.addr #0008 ADD2 =tileview.addr
,draw-tileview-icn JSR2
( line hor )
~tileview.y #003f ADD2 =dev/screen.y
~tileview.x =dev/screen.x
~tileview.y #003f ADD2 =SCRN.y
~tileview.x =SCRN.x
@draw-hor
( draw ) #03 =dev/screen.color
( incr ) ~dev/screen.x #0002 ADD2 =dev/screen.x
~dev/screen.x ~tileview.x #0082 ADD2 LTH2 ,draw-hor ROT JMP2? POP2
( draw ) #03 =SCRN.color
( incr ) ~SCRN.x #0002 ADD2 =SCRN.x
~SCRN.x ~tileview.x #0082 ADD2 LTH2 ,draw-hor ROT JMP2? POP2
( line ver )
~tileview.y =dev/screen.y
~tileview.x #003f ADD2 =dev/screen.x
~tileview.y =SCRN.y
~tileview.x #003f ADD2 =SCRN.x
@draw-ver
( draw ) #03 =dev/screen.color
( incr ) ~dev/screen.y #0002 ADD2 =dev/screen.y
~dev/screen.y ~tileview.y #0081 ADD2 LTH2 ,draw-ver ROT JMP2? POP2
( draw ) #03 =SCRN.color
( incr ) ~SCRN.y #0002 ADD2 =SCRN.y
~SCRN.y ~tileview.y #0081 ADD2 LTH2 ,draw-ver ROT JMP2? POP2
( rewind ) ~tileview.addr #0018 SUB2 =tileview.addr
( bytes )
~tileview.y #0018 ADD2 =dev/sprite.y
~tileview.y #0018 ADD2 =SPRT.y
#00 =i
@draw-tileview-bytes
~tileview.x #0088 ADD2 =dev/sprite.x
,font_hex #00 ~tileview.addr #00 ~i ADD2 LDR #f0 AND #04 ROR #08 MUL ADD2 =dev/sprite.addr
( draw ) #02 =dev/sprite.color
~dev/sprite.x #0008 ADD2 =dev/sprite.x
,font_hex #00 ~tileview.addr #00 ~i ADD2 LDR #0f AND #08 MUL ADD2 =dev/sprite.addr
( draw ) #02 =dev/sprite.color
~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
~SPRT.x #0008 ADD2 =SPRT.x
,font_hex #00 ~tileview.addr #00 ~i ADD2 LDR #0f AND #08 MUL ADD2 =SPRT.addr
( draw ) #02 =SPRT.color
( incr ) ~i #01 ADD =i
( incr ) ~dev/sprite.y #0008 ADD2 =dev/sprite.y
( incr ) ~SPRT.y #0008 ADD2 =SPRT.y
,draw-tileview-bytes ~i #08 LTH JMP2? POP2
( operations )
~dev/sprite.y #0008 ADD2 =dev/sprite.y
,movedown_icn =dev/sprite.addr
#01 =dev/sprite.color
~dev/sprite.x #0008 SUB2 =dev/sprite.x
,moveup_icn =dev/sprite.addr
#01 =dev/sprite.color
~SPRT.y #0008 ADD2 =SPRT.y
,movedown_icn =SPRT.addr
#01 =SPRT.color
~SPRT.x #0008 SUB2 =SPRT.x
,moveup_icn =SPRT.addr
#01 =SPRT.color
( draw tiles )
~tileview.y =dev/sprite.y
#00 =pt.x #00 =pt.y ~tileview.addr =dev/sprite.addr
~tileview.y =SPRT.y
#00 =pt.x #00 =pt.y ~tileview.addr =SPRT.addr
@draw-tileview-tiles-ver
#00 =pt.x
~tileview.x #0088 ADD2 =dev/sprite.x
~tileview.x #0088 ADD2 =SPRT.x
@draw-tileview-tiles-hor
( draw ) #03 =dev/sprite.color
( incr ) ~dev/sprite.x #0008 ADD2 =dev/sprite.x
( incr ) ~dev/sprite.addr #0008 ADD2 =dev/sprite.addr
( 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
( incr ) ~pt.y #01 ADD =pt.y
( incr ) ~dev/sprite.y #0008 ADD2 =dev/sprite.y
( incr ) ~SPRT.y #0008 ADD2 =SPRT.y
,draw-tileview-tiles-ver ~pt.y #02 LTH JMP2? POP2
RTS
@ -411,57 +411,57 @@ RTS
( get bit )
,blank_icn #00
~tileview.addr #00 ~pt.y ADD2 LDR #07 ~pt.x SUB ROR #01 AND ( get bit )
#0008 MUL2 ADD2 =dev/sprite.addr ( add *8 )
( draw ) #01 =dev/sprite.color
( incr ) ~dev/sprite.x #0008 ADD2 =dev/sprite.x
#0008 MUL2 ADD2 =SPRT.addr ( add *8 )
( 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
( incr ) ~dev/sprite.y #0008 ADD2 =dev/sprite.y
( incr ) ~SPRT.y #0008 ADD2 =SPRT.y
( incr ) ~pt.y #01 ADD =pt.y
~dev/sprite.x #0040 SUB2 =dev/sprite.x
~SPRT.x #0040 SUB2 =SPRT.x
,redraw-ver ~pt.y #08 LTH JMP2? POP2
RTS
@draw-cursor
~mouse.x ~dev/mouse.x NEQU2
~mouse.y ~dev/mouse.y NEQU2
~mouse.x ~MOUS.x NEQU2
~mouse.y ~MOUS.y NEQU2
#0000 EQU2 RTS? ( Return if unchanged )
( clear last cursor )
~mouse.x =dev/sprite.x
~mouse.y =dev/sprite.y
,blank_icn =dev/sprite.addr
#10 =dev/sprite.color
~mouse.x =SPRT.x
~mouse.y =SPRT.y
,blank_icn =SPRT.addr
#10 =SPRT.color
( record mouse positions )
~dev/mouse.x =mouse.x
~dev/mouse.y =mouse.y
~MOUS.x =mouse.x
~MOUS.y =mouse.y
( draw new cursor )
~mouse.x =dev/sprite.x
~mouse.y =dev/sprite.y
,tool_selector #00 ~bankview.mode #08 MUL ADD2 =dev/sprite.addr
#12 =dev/sprite.color
~mouse.x =SPRT.x
~mouse.y =SPRT.y
,tool_selector #00 ~bankview.mode #08 MUL ADD2 =SPRT.addr
#12 =SPRT.color
RTS
@draw-short ( short )
=addr
,font_hex #00 ,addr LDR #f0 AND #04 ROR #08 MUL ADD2 =dev/sprite.addr
( draw ) #02 =dev/sprite.color
~dev/sprite.x #0008 ADD2 =dev/sprite.x
,font_hex #00 ,addr LDR #0f AND #08 MUL ADD2 =dev/sprite.addr
( draw ) #02 =dev/sprite.color
~dev/sprite.x #0008 ADD2 =dev/sprite.x
,font_hex #00 ,addr #0001 ADD2 LDR #f0 AND #04 ROR #08 MUL ADD2 =dev/sprite.addr
( draw ) #02 =dev/sprite.color
~dev/sprite.x #0008 ADD2 =dev/sprite.x
,font_hex #00 ,addr #0001 ADD2 LDR #0f AND #08 MUL ADD2 =dev/sprite.addr
( draw ) #02 =dev/sprite.color
,font_hex #00 ,addr LDR #f0 AND #04 ROR #08 MUL ADD2 =SPRT.addr
( draw ) #02 =SPRT.color
~SPRT.x #0008 ADD2 =SPRT.x
,font_hex #00 ,addr LDR #0f AND #08 MUL ADD2 =SPRT.addr
( draw ) #02 =SPRT.color
~SPRT.x #0008 ADD2 =SPRT.x
,font_hex #00 ,addr #0001 ADD2 LDR #f0 AND #04 ROR #08 MUL ADD2 =SPRT.addr
( draw ) #02 =SPRT.color
~SPRT.x #0008 ADD2 =SPRT.x
,font_hex #00 ,addr #0001 ADD2 LDR #0f AND #08 MUL ADD2 =SPRT.addr
( draw ) #02 =SPRT.color
RTS
@ -469,18 +469,18 @@ 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
( load ) =color =rect.y2 =rect.x2 DUP2 =SCRN.y =rect.y1 DUP2 =SCRN.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
( incr ) ~SCRN.x #0001 ADD2 =SCRN.x
( draw ) ~rect.y1 =SCRN.y ~color =SCRN.color
( draw ) ~rect.y2 =SCRN.y ~color =SCRN.color
,line-rect-hor ~SCRN.x ~rect.x2 LTH2 JMP2? POP2
~rect.y1 =SCRN.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
( draw ) ~rect.x1 =SCRN.x ~color =SCRN.color
( draw ) ~rect.x2 =SCRN.x ~color =SCRN.color
( incr ) ~SCRN.y #0001 ADD2 =SCRN.y
,line-rect-ver ~SCRN.y ~rect.y2 #0001 ADD2 LTH2 JMP2? POP2
RTS
@ -774,12 +774,12 @@ RTS
|FE00 @ERROR BRK
|FF10 ;dev/screen Screen
|FF20 ;dev/sprite Sprite
|FF30 ;dev/ctrl Controller
|FF40 ;dev/key Keyboard
|FF50 ;dev/mouse Mouse
|FF60 ;dev/file File
|FF10 ;SCRN Screen
|FF20 ;SPRT Sprite
|FF30 ;CTRL Controller
|FF40 ;KEYS Keyboard
|FF50 ;MOUS Mouse
|FF60 ;FILE File
|FFF0 .RESET .FRAME .ERROR ( vectors )
|FFF8 [ e0fc 30cc 30ac ] ( palette )

52
projects/tests/jump.usm Normal file
View file

@ -0,0 +1,52 @@
( tests/jump )
&Console { pad 8 char 1 byte 1 short 2 }
|0100 @RESET
( skip forward with value )
#11 =dev/console.byte
#03 JMPS BRK BRK BRK
( skip foward with id )
#22 =dev/console.byte
^jump JMPS BRK BRK BRK @jump
( skip patterns )
#33 =dev/console.byte
,skip1 #12 #34 LTH JMP2? POP2
#ff =dev/console.byte
@skip1
#12 #34 LTH ^skip2 #04 SUB MUL JMPS
#ff =dev/console.byte
@skip2
#44 =dev/console.byte
,end JMP2
( should print aa, bb, cc, dd )
@label1 #aa =dev/console.byte ^label3 JMPS
@label2 #cc =dev/console.byte ^label4 JMPS
@label3 #bb =dev/console.byte ^label2 JMPS
@label4 #dd =dev/console.byte BRK
@end
^label1 JMPS
BRK
|c000 @FRAME
|d000 @ERROR
|FF00 ;dev/console Console
|FFF0 .RESET .FRAME .ERROR ( vectors )
|FFF8 [ 13fd 1ef3 1bf2 ] ( palette )

39
projects/tests/loop.usm Normal file
View file

@ -0,0 +1,39 @@
( hello world )
&Console { pad 8 char 1 byte 1 short 2 }
;a 1 ;b 1 ;c 1
|0100 @RESET
( type: padded muljmp )
@loop1 NOP
~a #01 ADD =a
~a #d0 LTH ^loop1 MUL JMPS
( type: jmppop )
@loop2
~b #01 ADD =b
,loop2 ~b #d0 LTH JMP2? POP2
( type: padded jmppop )
@loop3 NOP
~c #01 ADD =c
~c #d0 LTH ^loop3 SWP JMPS? POP
~a =dev/console.byte
~b =dev/console.byte
~c =dev/console.byte
BRK
|c000 @FRAME
|d000 @ERROR
|FF00 ;dev/console Console
|FFF0 .RESET .FRAME .ERROR ( vectors )
|FFF8 [ 13fd 1ef3 1bf2 ] ( palette )

4
uxn.c
View file

@ -32,7 +32,7 @@ Uint16 peek16(Stack *s, Uint8 a) { return peek8(s, a * 2) + (peek8(s, a * 2 + 1)
/* I/O */
void op_brk(Uxn *u) { setflag(&u->status, FLAG_HALT, 1); }
void op_lit(Uxn *u) { u->literal += 1; }
void op_nop(Uxn *u) { printf("0x%02x \n", pop8(&u->wst)); fflush(stdout); }
void op_nop(Uxn *u) { (void)u; }
void op_jmp(Uxn *u) { Uint8 a = pop8(&u->wst); u->ram.ptr += getflag(&u->status, FLAG_SIGN) ? (Sint8)a : a; }
void op_jsr(Uxn *u) { Uint8 a = pop8(&u->wst); push16(&u->rst, u->ram.ptr); u->ram.ptr += getflag(&u->status, FLAG_SIGN) ? (Sint8)a : a; }
void op_rts(Uxn *u) { u->ram.ptr = pop16(&u->rst); }
@ -102,7 +102,7 @@ void (*ops[])(Uxn *u) = {
};
Uint8 opr[][2] = {
{0,0}, {0,0}, {0,0}, {2,0}, {2,0}, {0,0}, {2,1}, {3,0},
{0,0}, {0,0}, {0,0}, {1,0}, {1,0}, {0,0}, {2,1}, {3,0},
{2,0}, {2,0}, {0,0}, {0,0}, {2,1}, {2,1}, {2,1}, {2,1},
{1,0}, {1,2}, {2,2}, {2,3}, {3,3}, {1,0}, {0,1}, {2,1},
{2,1}, {2,1}, {2,1}, {2,1}, {2,1}, {2,1}, {2,1}, {2,1},