Renamed RTS to RTN

This commit is contained in:
neauoire 2021-03-14 14:26:17 -07:00
parent 677515924a
commit 9cd5bf7d0a
16 changed files with 230 additions and 230 deletions

View File

@ -46,7 +46,7 @@ BRK
( loop ) DUP2 LDR #00 NEQ ^$loop MUL JMPS
POP2
RTS
RTN
@text1 [ Welcome 20 to 20 UxnVM 0a00 ]
@text2 [ Hello 20 World 0a00 ]

View File

@ -18,7 +18,7 @@ typedef signed short Sint16;
typedef struct {
char name[64], items[16][64];
Uint8 len;
Uint8 len, refs;
} Macro;
typedef struct {
@ -45,10 +45,10 @@ Program p;
/* clang-format off */
char ops[][4] = {
"BRK", "NOP", "LIT", "LDR", "STR", "JMP", "JSR", "RTS",
"BRK", "NOP", "LIT", "LDR", "STR", "JMP", "JSR", "RTN",
"EQU", "NEQ", "GTH", "LTH", "AND", "XOR", "ROL", "ROR",
"POP", "DUP", "SWP", "OVR", "ROT", "---", "WSR", "RSW",
"ADD", "SUB", "MUL", "DIV", "---", "---", "---", "PRG"
"ADD", "SUB", "MUL", "DIV", "---", "---", "---", "---"
};
int scin(char *s, char c) { int i = 0; while(s[i]) if(s[i++] == c) return i - 1; return -1; } /* string char index */
@ -434,10 +434,13 @@ void
cleanup(char *filename)
{
int i;
printf("Assembled %s, %d labels.\n\n", filename, p.llen);
printf("Assembled %s, %d labels, %d macros.\n\n", filename, p.llen, p.mlen);
for(i = 0; i < p.llen; ++i)
if(!p.labels[i].refs)
printf("--- Unused label: %s\n", p.labels[i].name);
for(i = 0; i < p.mlen; ++i)
if(!p.macros[i].refs)
printf("--- Unused macro: %s\n", p.macros[i].name);
}
int

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

@ -17,7 +17,7 @@ BRK
( loop ) DUP2 LDR #00 NEQ ^$loop MUL JMPS
POP2
RTS
RTN
@text1 [ Welcome 20 to 20 UxnVM 0a00 ]
@text2 [ Hello 20 World 0a00 ]

View File

@ -56,7 +56,7 @@ BRK
,slime_icn =Sprite.addr
~slime =Sprite.color
RTS
RTN
@default_icn [ 3c7e ffdb ffe7 7e3c ]
@up_icn [ 2466 e7db ffff 7e3c ]

View File

@ -31,14 +31,14 @@ BRK
~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
RTN
@redraw
~textarea.x1 ~textarea.y1 ~textarea.x2 ~textarea.y2 #01 ,fill-rect JSR2
~textarea.x1 ~textarea.y1 #04 ~textarea.addr ,draw-textarea JSR2
RTS
RTN
@blink-cursor
@ -50,7 +50,7 @@ RTS
@skip
~timer #01 ADD =timer
RTS
RTN
@tile-rect ( x1 y1 x2 y2 color addr )
@ -65,7 +65,7 @@ RTS
( incr ) ~Sprite.y #0008 ADD2 =Sprite.y
,$ver ~Sprite.y ~rect.y2 LTH2 JMP2? POP2
RTS
RTN
@fill-rect ( x1 y1 x2 y2 color )
@ -79,7 +79,7 @@ RTS
( incr ) ~Screen.y #0001 ADD2 =Screen.y
,$ver ~Screen.y ~rect.y2 LTH2 JMP2? POP2
RTS
RTN
@line-rect ( x1 y1 x2 y2 color )
@ -96,7 +96,7 @@ RTS
( incr ) ~Screen.y #0001 ADD2 =Screen.y
,$ver ~Screen.y ~rect.y2 #0001 ADD2 LTH2 JMP2? POP2
RTS
RTN
@draw-textarea ( x y color addr )
@ -115,7 +115,7 @@ RTS
DUP2 LDR #00 NEQ ,$loop ROT JMP2? POP2
POP2
RTS
RTN
@do-textarea
@ -138,7 +138,7 @@ RTS
#06 =Sprite.color
@do-textarea-end
RTS
RTN
@do-cursor
@ -151,7 +151,7 @@ RTS
~mouse.x ~Mouse.x NEQU2
~mouse.y ~Mouse.y NEQU2
#0000 EQU2 RTS? ( Return if unchanged )
#0000 EQU2 RTN? ( Return if unchanged )
( clear last cursor )
#10 ,clear_icn ~mouse.x ~mouse.y ,draw-sprite JSR2
@ -160,7 +160,7 @@ RTS
#12 ,cursor_icn ~mouse.x ~mouse.y ,draw-sprite JSR2
RTS
RTN
@draw-sprite
@ -169,7 +169,7 @@ RTS
=Sprite.addr
=Sprite.color
RTS
RTN
@font ( spectrum-zx font )
[

View File

@ -72,7 +72,7 @@ BRK
~pointer.y =Sprite.y
#11 =Sprite.color
RTS
RTN
@draw-polycat
@ -86,7 +86,7 @@ RTS
,polycat #00a0 ADD2 ~cat.x ~cat.y #0010 ADD2 ,draw-sprite-chr JSR2
,polycat #00b0 ADD2 ~cat.x #0008 ADD2 ~cat.y #0010 ADD2 ,draw-sprite-chr JSR2
RTS
RTN
@animate-polycat
@ -105,22 +105,22 @@ RTS
~pointer.y ~cat.y #0008 ADD2 GTH2 ,animate-polycat-left-down ROT JMP2? POP2
,polycat #0040 ADD2 ~cat.x ~cat.y #0008 ADD2 ,draw-sprite-chr JSR2
,polycat #0050 ADD2 ~cat.x #0008 ADD2 ~cat.y #0008 ADD2 ,draw-sprite-chr JSR2
RTS
RTN
@animate-polycat-left-down
,polycat #0020 ADD2 ~cat.x ~cat.y #0008 ADD2 ,draw-sprite-chr JSR2
,polycat #0030 ADD2 ~cat.x #0008 ADD2 ~cat.y #0008 ADD2 ,draw-sprite-chr JSR2
RTS
RTN
@animate-polycat-right
~pointer.y ~cat.y #0008 ADD2 GTH2 ,animate-polycat-right-down ROT JMP2? POP2
,polycat #0060 ADD2 ~cat.x ~cat.y #0008 ADD2 ,draw-sprite-chr JSR2
,polycat #0070 ADD2 ~cat.x #0008 ADD2 ~cat.y #0008 ADD2 ,draw-sprite-chr JSR2
RTS
RTN
@animate-polycat-right-down
,polycat #0080 ADD2 ~cat.x ~cat.y #0008 ADD2 ,draw-sprite-chr JSR2
,polycat #0090 ADD2 ~cat.x #0008 ADD2 ~cat.y #0008 ADD2 ,draw-sprite-chr JSR2
RTS
RTN
RTS
RTN
@draw-label ( x y color addr )
@ -133,7 +133,7 @@ RTS
DUP2 #0001 ADD2 LDR #00 NEQ ,$loop ROT JMP2? POP2
POP2
RTS
RTN
@draw-sprite
@ -142,7 +142,7 @@ RTS
=Sprite.addr
=Sprite.color
RTS
RTN
@draw-sprite-chr
@ -151,7 +151,7 @@ RTS
=Sprite.addr
#20 =Sprite.color
RTS
RTN
@clear_icn [ 0000 0000 0000 0000 ]
@cursor_icn [ 80c0 e0f0 f8e0 1000 ]

View File

@ -68,7 +68,7 @@ BRK
~pointer.y =Sprite.y
#11 =Sprite.color
RTS
RTN
@line-rect ( x1 y1 x2 y2 color )
@ -85,7 +85,7 @@ RTS
( incr ) ~Screen.y #0001 ADD2 =Screen.y
,$ver ~Screen.y ~rect.y2 #0001 ADD2 LTH2 JMP2? POP2
RTS
RTN
@clear_icn [ 0000 0000 0000 0000 ]
@pointer_icn [ 80c0 e0f0 f8e0 1000 ]

View File

@ -37,7 +37,7 @@ BRK
DUP2 LDR #00 NEQ ,$loop ROT JMP2? POP2
POP2
RTS
RTN
@draw-label-middle ( x y color addr )
@ -51,7 +51,7 @@ RTS
DUP2 LDR #00 NEQ ,$loop ROT JMP2? POP2
POP2
RTS
RTN
@draw-label-right ( x y color addr )
@ -65,7 +65,7 @@ RTS
DUP2 LDR #00 NEQ ,$loop ROT JMP2? POP2
POP2
RTS
RTN
@get-text-length ( label )
@ -75,7 +75,7 @@ RTS
LDR #00 NEQ ,$loop ROT JMP2? POP2
SWP2 POP2
RTS
RTN
@font ( spectrum-zx font )
[

View File

@ -23,7 +23,7 @@ BRK
( incr ) ~Sprite.y #0008 ADD2 =Sprite.y
,$ver ~Sprite.y ~pict.height ~pict.y ADD2 LTH2 JMP2? POP2
RTS
RTN
@pict_small [
ff80 8080 8080 8088 ffff fffc f8f9 f1f4

View File

@ -41,7 +41,7 @@ BRK
( incr ) ~Screen.y #0001 ADD2 =Screen.y
,$ver ~Screen.y ~rect.y2 #0001 ADD2 LTH2 JMP2? POP2
RTS
RTN
@fill-rect ( x1 y1 x2 y2 color )
@ -55,7 +55,7 @@ RTS
( incr ) ~Screen.y #0001 ADD2 =Screen.y
,$ver ~Screen.y ~rect.y2 LTH2 JMP2? POP2
RTS
RTN
@draw-picture ( x y width height color addr )
@ -70,7 +70,7 @@ RTS
( incr ) ~Sprite.y #0008 ADD2 =Sprite.y
,$ver ~Sprite.y ~pict.height ~pict.y ADD2 LTH2 JMP2? POP2
RTS
RTN
@draw-label ( x y color addr )
@ -82,7 +82,7 @@ RTS
DUP2 LDR #00 NEQ ,$loop ROT JMP2? POP2
POP2
RTS
RTN
@pict_small [

View File

@ -65,7 +65,7 @@ BRK
( background ) ~window.x1 ~window.y1 ~window.x2 ~window.y2 #02 ,fill-rect JSR2
( label ) ~window.x1 ~window.y1 #04 ,window_name ,draw-label-left JSR2
RTS
RTN
@draw-editor
@ -94,7 +94,7 @@ RTS
~window.x2 #0008 SUB2 =Sprite.x
( draw ) #01 =Sprite.color
RTS
RTN
@draw-label-left ( x y color addr )
@ -107,7 +107,7 @@ RTS
DUP2 LDR #00 NEQ ^$loop MUL JMPS
POP2
RTS
RTN
@fill-rect ( x1 y1 x2 y2 color )
@ -121,7 +121,7 @@ RTS
( incr ) ~Screen.y #0001 ADD2 =Screen.y
~Screen.y ~rect.y2 LTH2 ^$ver MUL JMPS
RTS
RTN
@line-rect ( x1 y1 x2 y2 color )
@ -138,7 +138,7 @@ RTS
( incr ) ~Screen.y #0001 ADD2 =Screen.y
~Screen.y ~rect.y2 #0001 ADD2 LTH2 ^$ver MUL JMPS
RTS
RTN
@tile-rect ( x1 y1 x2 y2 color addr )
@ -152,7 +152,7 @@ RTS
( incr ) ~Sprite.y #0008 ADD2 =Sprite.y
~Sprite.y ~rect.y2 LTH2 ^$ver MUL JMPS
RTS
RTN
@draw-cursor
@ -176,7 +176,7 @@ RTS
~pointer.y =Sprite.y
#11 =Sprite.color
RTS
RTN
@pattern [ 0000 0000 0000 0000 ]
@clear_icn [ 0000 0000 0000 0000 ]

View File

@ -35,7 +35,7 @@
( load file )
,filepath ,load-file JSR2
( place textarea )
#0018 =textarea.x1 ~SCRN.height #0008 SUB2 =textarea.y2
#0018 =textarea.x1 ~Screen.height #0008 SUB2 =textarea.y2
,select JSR2
,redraw JSR2
@ -46,62 +46,62 @@ BRK
( ctrl )
,ctrl-end ~CTRL #00 EQU ~lock #00 NEQ #0000 NEQ2 JMP2? POP2
,ctrl-end ~Controller #00 EQU ~lock #00 NEQ #0000 NEQ2 JMP2? POP2
( lock ) #04 =lock
,no-ctrl-up ~CTRL #10 NEQ JMP2? POP2
,no-ctrl-up ~Controller #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 ,follow-selection JSR2 ,redraw JSR2 ,ctrl-end JMP2
@no-ctrl-up
,no-ctrl-down ~CTRL #20 NEQ JMP2? POP2
,no-ctrl-down ~Controller #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 ,follow-selection JSR2 ,redraw JSR2 ,ctrl-end JMP2
@no-ctrl-down
,no-ctrl-left ~CTRL #40 NEQ JMP2? POP2
,no-ctrl-left ~Controller #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 ,follow-selection JSR2 ,redraw JSR2 ,ctrl-end JMP2
@no-ctrl-left
,no-ctrl-right ~CTRL #80 NEQ JMP2? POP2
,no-ctrl-right ~Controller #80 NEQ JMP2? POP2
~selection.from #0001 ADD2 DUP2 =selection.from #0001 ADD2 =selection.to
,clamp-selection JSR2 ,follow-selection JSR2 ,redraw JSR2 ,ctrl-end JMP2
@no-ctrl-right
( alt )
,no-alt ~CTRL #0f AND #02 NEQ JMP2? POP2
,no-aup ~CTRL #04 ROR #01 NEQ JMP2? POP2
,no-alt ~Controller #0f AND #02 NEQ JMP2? POP2
,no-aup ~Controller #04 ROR #01 NEQ JMP2? POP2
,find-wordstart JSR2 =selection.to
,clamp-selection JSR2 ,redraw JSR2 ,ctrl-end JMP2
@no-aup
,no-adown ~CTRL #04 ROR #02 NEQ JMP2? POP2
,no-adown ~Controller #04 ROR #02 NEQ JMP2? POP2
,find-wordend JSR2 =selection.to
,clamp-selection JSR2 ,redraw JSR2 ,ctrl-end JMP2
@no-adown
,no-aleft ~CTRL #04 ROR #04 NEQ JMP2? POP2
,no-aleft ~Controller #04 ROR #04 NEQ JMP2? POP2
~selection.to #0001 SUB2 =selection.to
,clamp-selection JSR2 ,redraw JSR2 ,ctrl-end JMP2
@no-aleft
,no-aright ~CTRL #04 ROR #08 NEQ JMP2? POP2
,no-aright ~Controller #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 ~CTRL #0f AND #01 NEQ JMP2? POP2
,no-cup ~CTRL #04 ROR #01 NEQ JMP2? POP2
,no-ctrl ~Controller #0f AND #01 NEQ JMP2? POP2
,no-cup ~Controller #04 ROR #01 NEQ JMP2? POP2
#0004 ,scroll-up JSR2
,redraw JSR2 ,ctrl-end JMP2
@no-cup
,no-cdown ~CTRL #04 ROR #02 NEQ JMP2? POP2
,no-cdown ~Controller #04 ROR #02 NEQ JMP2? POP2
#0004 ,scroll-down JSR2
,redraw JSR2 ,ctrl-end JMP2
@no-cdown
,no-cleft ~CTRL #04 ROR #04 NEQ JMP2? POP2
,no-cleft ~Controller #04 ROR #04 NEQ JMP2? POP2
,goto-linestart JSR2 ,redraw JSR2 ,ctrl-end JMP2
@no-cleft
,no-cright ~CTRL #04 ROR #08 NEQ JMP2? POP2
,no-cright ~Controller #04 ROR #08 NEQ JMP2? POP2
,goto-lineend JSR2 ,redraw JSR2 ,ctrl-end JMP2
@no-cright
@no-ctrl
@ -110,9 +110,9 @@ BRK
( keys )
,no-keys ~KEYS #00 EQU JMP2? POP2
,no-keys ~Keys #00 EQU JMP2? POP2
,$no-backspace ~KEYS #08 NEQ JMP2? POP2
,$no-backspace ~Keys #08 NEQ JMP2? POP2
( erase )
,$erase-multiple ~selection.to ~selection.from SUB2 #0001 NEQ2 JMP2? POP2
~selection.to ~selection.from SUB2 ,shift-left JSR2
@ -127,38 +127,38 @@ BRK
( insert )
~selection.to ~selection.from SUB2 ,shift-right JSR2
~KEYS ~selection.from STR
~Keys ~selection.from STR
~selection.from #0001 ADD2 =selection.from
$keys-end
~selection.from #0001 ADD2 =selection.to
( release ) #00 =KEYS
( release ) #00 =Keys
,redraw JSR2
@no-keys
( mouse )
,no-change ~MOUS.state ~touch.state EQU JMP2? POP2
,no-change ~Mouse.state ~touch.state EQU JMP2? POP2
#0000 =SPRT.x ~SCRN.height #0008 SUB2 =SPRT.y
,mouse00icn =SPRT.addr
,nobutton1 ~MOUS.state #01 NEQ JMP2? POP2 ,mouse01icn =SPRT.addr @nobutton1
,nobutton2 ~MOUS.state #10 NEQ JMP2? POP2 ,mouse10icn =SPRT.addr @nobutton2
,nobutton3 ~MOUS.state #11 NEQ JMP2? POP2 ,mouse11icn =SPRT.addr @nobutton3
#01 =SPRT.color
#0000 =Sprite.x ~Screen.height #0008 SUB2 =Sprite.y
,mouse00icn =Sprite.addr
,nobutton1 ~Mouse.state #01 NEQ JMP2? POP2 ,mouse01icn =Sprite.addr @nobutton1
,nobutton2 ~Mouse.state #10 NEQ JMP2? POP2 ,mouse10icn =Sprite.addr @nobutton2
,nobutton3 ~Mouse.state #11 NEQ JMP2? POP2 ,mouse11icn =Sprite.addr @nobutton3
#01 =Sprite.color
@no-change
,touch-end ~MOUS.state #00 EQU JMP2? POP2
,touch-end ~Mouse.state #00 EQU JMP2? POP2
,touch-linebar ~MOUS.x #0010 LTH2 JMP2? POP2
,touch-body ~MOUS.x ~SCRN.width #0008 SUB2 LTH2 JMP2? POP2
,touch-linebar ~Mouse.x #0010 LTH2 JMP2? POP2
,touch-body ~Mouse.x ~Screen.width #0008 SUB2 LTH2 JMP2? POP2
,touch-scrollbar JMP2
@touch-end
~MOUS.state =touch.state
~Mouse.state =touch.state
( unlock ) ,skip-unlock ~lock #00 EQU JMP2? POP2 ~lock #01 SUB =lock @skip-unlock
@ -168,49 +168,49 @@ BRK
@touch-scrollbar
,$no-up ~MOUS.y #0008 GTH2 JMP2? POP2
,$no-up ~Mouse.y #0008 GTH2 JMP2? POP2
( decr ) ~scroll.y #00 ~scroll.y #0000 NEQ2 SUB2 =scroll.y
^$end JMPS
$no-up
,$no-down ~MOUS.y ~SCRN.height #0008 SUB2 LTH2 JMP2? POP2
,$no-down ~Mouse.y ~Screen.height #0008 SUB2 LTH2 JMP2? POP2
( incr ) ~scroll.y #0001 ADD2 =scroll.y
^$end JMPS
$no-down
~MOUS.y #0008 SUB2 =scroll.y
~Mouse.y #0008 SUB2 =scroll.y
$end
,redraw JSR2
,touch-end JMP2
RTS
RTN
@touch-linebar
~MOUS.y #0008 DIV2 ~scroll.y ADD2 =position.y #0000 =position.x
~Mouse.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
RTS
RTN
@touch-body
~MOUS.y #0008 DIV2 ~scroll.y ADD2 =position.y
~MOUS.x ~textarea.x1 SUB2 #0007 ADD2 #0007 DIV2 =position.x
~Mouse.y #0008 DIV2 ~scroll.y ADD2 =position.y
~Mouse.x ~textarea.x1 SUB2 #0007 ADD2 #0007 DIV2 =position.x
,$no-chord-cut ~MOUS.chord #01 NEQ JMP2? POP2
,$no-chord-cut ~Mouse.chord #01 NEQ JMP2? POP2
,cut JSR2
( release ) #00 DUP =MOUS.state =MOUS.chord
( release ) #00 DUP =Mouse.state =Mouse.chord
^$end JMPS
$no-chord-cut
,$no-chord-paste ~MOUS.chord #10 NEQ JMP2? POP2
,$no-chord-paste ~Mouse.chord #10 NEQ JMP2? POP2
,paste JSR2
( release ) #00 DUP =MOUS.state =MOUS.chord
( release ) #00 DUP =Mouse.state =Mouse.chord
^$end JMPS
$no-chord-paste
,$end ~MOUS.state #11 EQU JMP2? POP2
,$end ~Mouse.state #11 EQU JMP2? POP2
,$no-drag ~MOUS.state ~touch.state NEQ ~CTRL #0f AND #02 NEQ #0101 EQU2 JMP2? POP2
,$no-drag ~Mouse.state ~touch.state NEQ ~Controller #0f AND #02 NEQ #0101 EQU2 JMP2? POP2
( on drag )
,find-selection JSR2 #0001 ADD2 =selection.to
,clamp-selection JSR2
@ -222,34 +222,34 @@ RTS
,redraw JSR2
,touch-end JMP2
RTS
RTN
@load-file ( path )
=FILE.name #8000 =FILE.length ,document.body =FILE.load
=File.name #8000 =File.length ,document.body =File.load
( get file length )
,document.body =document.eof
$loop NOP
( incr ) ~document.eof #0001 ADD2 =document.eof
~document.eof LDR #00 NEQ ^$loop MUL JMPS
RTS
RTN
@scroll-up ( length )
DUP2 ~scroll.y LTH2 ,$clamp ROT JMP2? POP2
#0000 =scroll.y POP2 RTS
#0000 =scroll.y POP2 RTN
$clamp
~scroll.y SWP2 SUB2 =scroll.y
RTS
RTN
@scroll-down ( length )
( TODO: Clamp )
~scroll.y SWP2 ADD2 =scroll.y
RTS
RTN
@shift-left ( length )
@ -261,7 +261,7 @@ RTS
~j ~document.eof LTH2 ^$loop MUL JMPS
~document.eof ~i SUB2 =document.eof
RTS
RTN
@shift-right ( length )
@ -273,51 +273,51 @@ RTS
~j ~selection.from GTH2 ^$loop MUL JMPS
~document.eof ~i ADD2 =document.eof
RTS
RTN
@follow-selection
,$no-up ~position.y ~scroll.y GTH2 JMP2? POP2
~position.y =scroll.y RTS
~position.y =scroll.y RTN
$no-up
,$no-down ~position.y ~SCRN.height #0010 SUB2 #0008 DIV2 ~scroll.y ADD2 LTH2 JMP2? POP2
~position.y ~SCRN.height #0010 SUB2 #0008 DIV2 SUB2 =scroll.y RTS
,$no-down ~position.y ~Screen.height #0010 SUB2 #0008 DIV2 ~scroll.y ADD2 LTH2 JMP2? POP2
~position.y ~Screen.height #0010 SUB2 #0008 DIV2 SUB2 =scroll.y RTN
$no-down
RTS
RTN
@clamp-selection
~selection.from ~selection.to LTH2 RTS?
~selection.from ~selection.to LTH2 RTN?
~selection.from #0001 ADD2 =selection.to
RTS
RTN
@goto-linestart
$loop NOP
~selection.from #0001 SUB2 LDR #0a EQU RTS?
~selection.from #0001 SUB2 LDR #0d EQU RTS?
~selection.from #0001 SUB2 LDR #0a EQU RTN?
~selection.from #0001 SUB2 LDR #0d EQU RTN?
( decr ) ~selection.from DUP2 =selection.to #0001 SUB2 =selection.from
~selection.from LDR #00 NEQ ^$loop MUL JMPS
( clamp at document body )
~selection.from ,document.body GTH2 RTS?
~selection.from ,document.body GTH2 RTN?
,document.body DUP2 =selection.from #0001 ADD2 =selection.to
RTS
RTN
@goto-lineend
$loop NOP
~selection.from LDR #0a EQU RTS?
~selection.from LDR #0d EQU RTS?
~selection.from LDR #0a EQU RTN?
~selection.from LDR #0d EQU RTN?
( incr ) ~selection.from #0001 ADD2 DUP2 #0001 ADD2 =selection.to =selection.from
~selection.from LDR #00 NEQ ^$loop MUL JMPS
( clamp at document body )
~selection.from ,document.eof LTH2 RTS?
~selection.from ,document.eof LTH2 RTN?
,document.eof #0001 SUB2 DUP2 =selection.from #0001 ADD2 =selection.to
RTS
RTN
@find-wordstart
@ -331,7 +331,7 @@ RTS
$end
( return ) ~j #0001 SUB2
RTS
RTN
@find-wordend
@ -345,7 +345,7 @@ RTS
$end
( return ) ~j #0001 ADD2
RTS
RTN
@find-lineoffset ( return character offset from linestart )
@ -358,7 +358,7 @@ RTS
$end
( return ) ~j
RTS
RTN
@find-line ( position -> addr )
@ -373,7 +373,7 @@ RTS
$end
( return ) ~j
RTS
RTN
@find-selection ( position -> addr )
@ -387,7 +387,7 @@ RTS
$end
( return ) ~pt.x ADD2
RTS
RTN
@cut
@ -395,7 +395,7 @@ RTS
~selection.to ~selection.from SUB2 ,shift-left JSR2
~selection.from #0001 ADD2 =selection.to
RTS
RTN
@copy ( selection )
@ -407,7 +407,7 @@ RTS
( incr ) ~i #0001 ADD2 =i
~i ~j LTH2 ^$loop MUL JMPS
RTS
RTN
@paste
@ -419,7 +419,7 @@ RTS
( incr ) ~i #0001 ADD2 =i
~i ~j LTH2 ^$loop MUL JMPS
RTS
RTN
@select ( position -> selection )
@ -431,13 +431,13 @@ RTS
$no-space
,$no-reached ~pt.y ~position.y #0001 SUB2 GTH2 ~pt.x ~position.x #0001 SUB2 GTH2 #0101 NEQ2 JMP2? POP2
~selection.from #0001 ADD2 =selection.to
RTS
RTN
$no-reached
( incr ) ~pt.x #0001 ADD2 =pt.x
( incr ) ~selection.from #0001 ADD2 =selection.from
,$loop ~selection.from LDR #00 NEQ JMP2? POP2
RTS
RTN
( drawing functions )
@ -448,57 +448,57 @@ RTS
,draw-titlebar JSR2
( save/load icons )
~SCRN.height #0008 SUB2 =SPRT.y
~SCRN.width #0018 SUB2 =SPRT.x
,load_icn =SPRT.addr
#02 =SPRT.color
~SCRN.width #0010 SUB2 =SPRT.x
,save_icn =SPRT.addr
#02 =SPRT.color
~Screen.height #0008 SUB2 =Sprite.y
~Screen.width #0018 SUB2 =Sprite.x
,load_icn =Sprite.addr
#02 =Sprite.color
~Screen.width #0010 SUB2 =Sprite.x
,save_icn =Sprite.addr
#02 =Sprite.color
RTS
RTN
@draw-short ( short )
=addr
,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
,font_hex #00 ,addr LDR #f0 AND #04 ROR #08 MUL ADD2 =Sprite.addr
( draw ) #0e =Sprite.color
~Sprite.x #0008 ADD2 =Sprite.x
,font_hex #00 ,addr LDR #0f AND #08 MUL ADD2 =Sprite.addr
( draw ) #0e =Sprite.color
~Sprite.x #0008 ADD2 =Sprite.x
,font_hex #00 ,addr #0001 ADD2 LDR #f0 AND #04 ROR #08 MUL ADD2 =Sprite.addr
( draw ) #0e =Sprite.color
~Sprite.x #0008 ADD2 =Sprite.x
,font_hex #00 ,addr #0001 ADD2 LDR #0f AND #08 MUL ADD2 =Sprite.addr
( draw ) #0e =Sprite.color
RTS
RTN
@draw-cursor
~mouse.x ~MOUS.x NEQU2
~mouse.y ~MOUS.y NEQU2
~mouse.x ~Mouse.x NEQU2
~mouse.y ~Mouse.y NEQU2
#0000 EQU2 RTS? ( Return if unchanged )
#0000 EQU2 RTN? ( Return if unchanged )
( clear last cursor )
~mouse.x =SPRT.x
~mouse.y =SPRT.y
,blank_icn =SPRT.addr
#10 =SPRT.color
~mouse.x =Sprite.x
~mouse.y =Sprite.y
,blank_icn =Sprite.addr
#10 =Sprite.color
( record mouse positions )
~MOUS.x =mouse.x
~MOUS.y =mouse.y
~Mouse.x =mouse.x
~Mouse.y =mouse.y
( draw new cursor )
~mouse.x =SPRT.x
~mouse.y =SPRT.y
,cursor_icn =SPRT.addr
#13 =SPRT.color
~mouse.x =Sprite.x
~mouse.y =Sprite.y
,cursor_icn =Sprite.addr
#13 =Sprite.color
RTS
RTN
@draw-textarea ( x y color addr )
@ -515,100 +515,100 @@ RTS
~textarea.addr LDR #00 NEQ ^$find-offset MUL JMPS
$find-offset-end
#0018 =SPRT.x #0000 =SPRT.y
#0018 =Sprite.x #0000 =Sprite.y
~textarea.addr =i
$loop
,$end ~SPRT.y ~SCRN.height #0010 SUB2 GTH2 JMP2? POP2
,$end ~Sprite.y ~Screen.height #0010 SUB2 GTH2 JMP2? POP2
( get character )
,font #00 ~i LDR #20 SUB #0008 MUL2 ADD2 =SPRT.addr
,font #00 ~i LDR #20 SUB #0008 MUL2 ADD2 =Sprite.addr
( draw ) #01
~i ~selection.from #0001 SUB2 GTH2
~i ~selection.to LTH2 #0101 EQU2
#05 MUL ADD ~i ~selection.from EQU2 ADD =SPRT.color
#05 MUL ADD ~i ~selection.from EQU2 ADD =Sprite.color
,$no-linebreak ~i LDR #0a NEQ ~i LDR #0d NEQ #0101 EQU2 JMP2? POP2
( draw linebreak )
,linebreak_icn =SPRT.addr
,linebreak_icn =Sprite.addr
( draw ) #02
~i ~selection.from #0001 SUB2 GTH2
~i ~selection.to LTH2 #0101 EQU2
#06 MUL ADD =SPRT.color
#06 MUL ADD =Sprite.color
( fill clear )
$fill-clear
( incr ) ~SPRT.x #0008 ADD2 =SPRT.x
,font =SPRT.addr
#01 =SPRT.color
,$fill-clear ~SPRT.x ~SCRN.width #0008 SUB2 LTH2 JMP2? POP2
( incr ) ~Sprite.x #0008 ADD2 =Sprite.x
,font =Sprite.addr
#01 =Sprite.color
,$fill-clear ~Sprite.x ~Screen.width #0008 SUB2 LTH2 JMP2? POP2
( draw line number )
#0000 =SPRT.x
~scroll.y ~SPRT.y #0008 DIV2 ADD2 DUP2 SWP POP =k
#0000 =Sprite.x
~scroll.y ~Sprite.y #0008 DIV2 ADD2 DUP2 SWP POP =k
~position.y EQU2 #0c MUL =l
,font_hex #00 ~k #f0 AND #04 ROR #08 MUL ADD2 =SPRT.addr
#02 ~l ADD =SPRT.color
#0008 =SPRT.x
,font_hex #00 ~k #0f AND #08 MUL ADD2 =SPRT.addr
#02 ~l ADD =SPRT.color
,font_hex #00 ~k #f0 AND #04 ROR #08 MUL ADD2 =Sprite.addr
#02 ~l ADD =Sprite.color
#0008 =Sprite.x
,font_hex #00 ~k #0f AND #08 MUL ADD2 =Sprite.addr
#02 ~l ADD =Sprite.color
#0010 =SPRT.x
( incr ) ~SPRT.y #0008 ADD2 =SPRT.y
#0010 =Sprite.x
( incr ) ~Sprite.y #0008 ADD2 =Sprite.y
$no-linebreak
( incr ) ~i #0001 ADD2 =i
( incr ) ~SPRT.x #0007 ADD2 =SPRT.x
( incr ) ~Sprite.x #0007 ADD2 =Sprite.x
,$loop ~i LDR #00 NEQ JMP2? POP2
$end
RTS
RTN
@draw-scrollbar
~SCRN.width #0008 SUB2 =SPRT.x
#0000 =SPRT.y
,scrollbar_bg =SPRT.addr
~Screen.width #0008 SUB2 =Sprite.x
#0000 =Sprite.y
,scrollbar_bg =Sprite.addr
$loop NOP
( draw ) #08 =SPRT.color
( incr ) ~SPRT.y #0008 ADD2 =SPRT.y
~SPRT.y ~SCRN.height LTH2 ^$loop MUL JMPS
( draw ) #08 =Sprite.color
( incr ) ~Sprite.y #0008 ADD2 =Sprite.y
~Sprite.y ~Screen.height LTH2 ^$loop MUL JMPS
#0000 =SPRT.y
,arrowup_icn =SPRT.addr
( draw ) #08 =SPRT.color
#0000 =Sprite.y
,arrowup_icn =Sprite.addr
( draw ) #08 =Sprite.color
( at )
~scroll.y #0008 ADD2 =SPRT.y
,scrollbar_fg =SPRT.addr
( draw ) #08 =SPRT.color
~scroll.y #0008 ADD2 =Sprite.y
,scrollbar_fg =Sprite.addr
( draw ) #08 =Sprite.color
~SCRN.height #0008 SUB2 =SPRT.y
,arrowdown_icn =SPRT.addr
( draw ) #08 =SPRT.color
~Screen.height #0008 SUB2 =Sprite.y
,arrowdown_icn =Sprite.addr
( draw ) #08 =Sprite.color
RTS
RTN
@draw-titlebar
#0018 ~SCRN.height #0008 SUB2 #09 ,filepath
( load ) =label.addr =label.color =SPRT.y =SPRT.x
#0018 ~Screen.height #0008 SUB2 #09 ,filepath
( load ) =label.addr =label.color =Sprite.y =Sprite.x
~label.addr
$loop NOP
( draw ) DUP2 LDR #00 SWP #20 SUB #0008 MUL2 ,font ADD2 =SPRT.addr ~label.color =SPRT.color
( draw ) DUP2 LDR #00 SWP #20 SUB #0008 MUL2 ,font ADD2 =Sprite.addr ~label.color =Sprite.color
( incr ) #0001 ADD2
( incr ) ~SPRT.x #0008 ADD2 =SPRT.x
( incr ) ~Sprite.x #0008 ADD2 =Sprite.x
DUP2 LDR #00 NEQ ^$loop MUL JMPS
POP2
( selection )
~selection.from ,document.body SUB2 ,draw-short JSR2
RTS
RTN
@font_hex ( 0-F TODO: should pull from @font instead.. )
[
@ -697,13 +697,13 @@ RTS
|d000 @ERROR BRK
|FF00 ;CNSL { pad 8 char 1 byte 1 short 2 }
|FF10 ;SCRN { width 2 height 2 pad 4 x 2 y 2 color 1 }
|FF20 ;SPRT { pad 8 x 2 y 2 addr 2 color 1 }
|FF30 ;CTRL { buttons 1 }
|FF40 ;KEYS { key 1 }
|FF50 ;MOUS { x 2 y 2 state 1 chord 1 xt 1 yt 1 }
|FF60 ;FILE { pad 8 name 2 length 2 load 2 save 2 }
|FF00 ;Console { pad 8 char 1 byte 1 short 2 }
|FF10 ;Screen { width 2 height 2 pad 4 x 2 y 2 color 1 }
|FF20 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 }
|FF30 ;Controller { buttons 1 }
|FF40 ;Keys { key 1 }
|FF50 ;Mouse { x 2 y 2 state 1 chord 1 xt 1 yt 1 }
|FF60 ;File { pad 8 name 2 length 2 load 2 save 2 }
|FFF0 .RESET .FRAME .ERROR ( vectors )
|FFF8 [ 30ff e0f3 b0f3 ] ( palette )

View File

@ -197,7 +197,7 @@ BRK
~tileview.addr #0007 ADD2 LDR ~tileview.addr #0006 ADD2 STR
~tileview.addr #0007 ADD2 STR
RTS
RTN
@op_shiftdown
@ -211,14 +211,14 @@ RTS
~tileview.addr LDR ~tileview.addr #0001 ADD2 STR
~tileview.addr STR
RTS
RTN
@redraw
,draw-bankview JSR2
,draw-tileview JSR2
RTS
RTN
@draw-bankview
@ -288,7 +288,7 @@ RTS
( incr ) ~SPRT.y #0008 ADD2 =SPRT.y
,$ver ~pt.y #10 LTH JMP2? POP2
RTS
RTN
@draw-tileview
@ -386,7 +386,7 @@ RTS
( incr ) ~SPRT.y #0008 ADD2 =SPRT.y
,$tiles-ver ~pt.y #02 LTH JMP2? POP2
RTS
RTN
@draw-tileview-icn
@ -407,14 +407,14 @@ RTS
~SPRT.x #0040 SUB2 =SPRT.x
,$ver ~pt.y #08 LTH JMP2? POP2
RTS
RTN
@draw-cursor
~mouse.x ~MOUS.x NEQU2
~mouse.y ~MOUS.y NEQU2
#0000 EQU2 RTS? ( Return if unchanged )
#0000 EQU2 RTN? ( Return if unchanged )
( clear last cursor )
~mouse.x =SPRT.x
@ -432,7 +432,7 @@ RTS
,tool_selector #00 ~bankview.mode #08 MUL ADD2 =SPRT.addr
#12 =SPRT.color
RTS
RTN
@draw-short ( short )
@ -449,7 +449,7 @@ RTS
,font_hex #00 ,addr #0001 ADD2 LDR #0f AND #08 MUL ADD2 =SPRT.addr
( draw ) #02 =SPRT.color
RTS
RTN
( Utils )
@ -468,7 +468,7 @@ RTS
( incr ) ~SCRN.y #0001 ADD2 =SCRN.y
~SCRN.y ~rect.y2 #0001 ADD2 LTH2 ^$ver MUL JMPS
RTS
RTN
@tool_selector [ 80c0 e0f0 f8e0 1000 ]
@tool_hand [ 4040 4070 f8f8 f870 ]

View File

@ -1,12 +1,9 @@
( tests/jump )
%RTS { RSW2 JMP }
%JSR2 { PRG WSR2 JMP2 }
%JMC { JMP2? POP2 }
|0100 @RESET
,test1 JSR2
,test2 JSR2
BRK
@ -26,7 +23,7 @@ BRK
#33 =Console.byte
,skip1 #12 #34 LTH JMC
,skip1 #12 #34 LTH JMP2? POP2
#ff =Console.byte
@skip1
@ -36,7 +33,7 @@ BRK
#44 =Console.byte
RTS
RTN
@test2
@ -51,7 +48,7 @@ RTS
@end
RTS
RTN
|c000 @FRAME
|d000 @ERROR

12
uxn.c
View File

@ -34,9 +34,9 @@ void op_brk(Uxn *u) { setflag(&u->status, FLAG_HALT, 1); }
void op_lit(Uxn *u) { u->literal += 1; }
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_prg(Uxn *u) { push16(&u->wst, u->ram.ptr); }
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); }
void op_rtn(Uxn *u) { u->ram.ptr = pop16(&u->rst); }
void op_ldr(Uxn *u) { Uint16 a = pop16(&u->wst); push8(&u->wst, mempeek8(u, a)); }
void op_str(Uxn *u) { Uint16 a = pop16(&u->wst); Uint8 b = pop8(&u->wst); mempoke8(u, a, b); }
/* Logic */
@ -91,12 +91,12 @@ void op_gth16(Uxn *u) { Uint16 a = pop16(&u->wst), b = pop16(&u->wst); push8(&u-
void op_lth16(Uxn *u) { Uint16 a = pop16(&u->wst), b = pop16(&u->wst); push8(&u->wst, getflag(&u->status, FLAG_SIGN) ? (Sint16)b < (Sint16)a : b < a); }
void (*ops[])(Uxn *u) = {
op_brk, op_nop, op_lit, op_ldr, op_str, op_jmp, op_jsr, op_rts,
op_brk, op_nop, op_lit, op_ldr, op_str, op_jmp, op_jsr, op_rtn,
op_equ, op_neq, op_gth, op_lth, op_and, op_xor, op_rol, op_ror,
op_pop, op_dup, op_swp, op_ovr, op_rot, op_nop, op_wsr, op_rsw,
op_add, op_sub, op_mul, op_div, op_nop, op_nop, op_nop, op_nop,
/* 16-bit */
op_brk, op_nop16, op_lit16, op_ldr16, op_str16, op_jmp16, op_jsr16, op_rts,
op_brk, op_nop16, op_lit16, op_ldr16, op_str16, op_jmp16, op_jsr16, op_rtn,
op_equ16, op_neq16, op_gth16, op_lth16, op_and16, op_xor16, op_rol16, op_ror16,
op_pop16, op_dup16, op_swp16, op_ovr16, op_rot16, op_nop, op_wsr16, op_rsw16,
op_add16, op_sub16, op_mul16, op_div16, op_nop, op_nop, op_nop, op_nop
@ -106,12 +106,12 @@ Uint8 opr[][4] = { /* wstack-/+ rstack-/+ */
{0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {2,1,0,0}, {3,0,0,0}, {1,0,0,0}, {1,0,0,2}, {0,0,2,0},
{2,1,0,0}, {2,1,0,0}, {2,1,0,0}, {2,1,0,0}, {2,1,0,0}, {2,1,0,0}, {2,1,0,0}, {2,1,0,0},
{1,0,0,0}, {1,2,0,0}, {2,2,0,0}, {2,3,0,0}, {3,3,0,0}, {0,0,0,0}, {1,0,0,1}, {0,1,1,0},
{2,1,0,0}, {2,1,0,0}, {2,1,0,0}, {2,1,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0},
{2,1,0,0}, {2,1,0,0}, {2,1,0,0}, {2,1,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,2,0,0},
/* 16-bit */
{0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {2,2,0,0}, {4,0,0,0}, {2,0,0,0}, {2,0,0,0}, {0,0,0,0}, /* TODO */
{4,2,0,0}, {4,2,0,0}, {4,2,0,0}, {4,2,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, /* TODO */
{0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {2,0,0,2}, {0,2,2,0}, /* TODO */
{4,2,0,0}, {4,2,0,0}, {4,2,0,0}, {4,2,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}
{4,2,0,0}, {4,2,0,0}, {4,2,0,0}, {4,2,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,2,0,0}
};
/* clang-format on */