Minor cleanup

This commit is contained in:
neauoire 2021-03-11 20:41:35 -08:00
parent b42cec41ef
commit 9f264959a3
3 changed files with 66 additions and 103 deletions

View File

@ -22,43 +22,9 @@ evaluxn(u, u->vreset); /* Once on start */
evaluxn(u, u->vframe); /* Each frame evaluxn(u, u->vframe); /* Each frame
``` ```
## Assembly Syntax ## Uxambly
### Define Read more in the [Uxambly Guide](https://wiki.xxiivv.com/site/uxambly.html).
- `@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`.
### Program
- `ADD`, push an opcode.
- `.address`, push label address to memory.
- `,literal`, push label address to stack, prefixed with `LIT LEN`.
- `#1a`, push a literal byte/short.
- `+1a`, push a literal signed byte/short.
- `-1a`, push a literal signed byte/short(negative).
- `|0010`, move to position in the program.
### Helpers
- `=label`, helper to STR, equivalent to `,label STR`, or `label STR2`.
- `~label`, helper to LDR, equivalent to `,label LDR2`, or `,label LDR2`.
### Blocks
- `( comment )`, toggle parsing on/off.
- `[ 0123 abcd ]`, write shorts to memory.
- `[ Hello World ]`, write text to memory.
### Operator modes
- `#1234 #0001 ADD2`, 16-bits operators have the short flag `2`.
- `#12 #11 GTH JMP?`, conditional operators have the cond flag `?`.
- `+21 -03 MULS`, signed operators have the cond flag `S`.
- `ADDS2?`, modes can be combined.
``` ```
( hello world ) ( hello world )
@ -107,7 +73,6 @@ RTS
- Includes - Includes
- Defines - Defines
- Local loops
- Jump helpers - Jump helpers
## Notes ## Notes

View File

@ -14,7 +14,7 @@ WITH REGARD TO THIS SOFTWARE.
#include "uxn.h" #include "uxn.h"
#define HOR 64 #define HOR 48
#define VER 32 #define VER 32
#define PAD 2 #define PAD 2
#define RES (HOR * VER * 16) #define RES (HOR * VER * 16)

View File

@ -211,9 +211,9 @@ RTS
( get file length ) ( get file length )
,document.body =document.eof ,document.body =document.eof
@load-file-loop NOP $loop NOP
( incr ) ~document.eof #0001 ADD2 =document.eof ( incr ) ~document.eof #0001 ADD2 =document.eof
~document.eof LDR #00 NEQ ^load-file-loop MUL JMPS ~document.eof LDR #00 NEQ ^$loop MUL JMPS
RTS RTS
@ -221,10 +221,10 @@ RTS
=i =i
~selection.from #0001 SUB2 =j ( start -> end ) ~selection.from #0001 SUB2 =j ( start -> end )
@shift-left-loop NOP $loop NOP
( move ) ~j ~i ADD2 LDR ~j STR ( move ) ~j ~i ADD2 LDR ~j STR
( incr ) ~j #0001 ADD2 =j ( incr ) ~j #0001 ADD2 =j
~j ~document.eof LTH2 ^shift-left-loop MUL JMPS ~j ~document.eof LTH2 ^$loop MUL JMPS
~document.eof ~i SUB2 =document.eof ~document.eof ~i SUB2 =document.eof
RTS RTS
@ -250,11 +250,11 @@ RTS
@goto-linestart @goto-linestart
@goto-linestart-loop NOP $loop NOP
~selection.from #0001 SUB2 LDR #0a EQU RTS? ~selection.from #0001 SUB2 LDR #0a EQU RTS?
~selection.from #0001 SUB2 LDR #0d EQU RTS? ~selection.from #0001 SUB2 LDR #0d EQU RTS?
( decr ) ~selection.from DUP2 =selection.to #0001 SUB2 =selection.from ( decr ) ~selection.from DUP2 =selection.to #0001 SUB2 =selection.from
~selection.from LDR #00 NEQ ^goto-linestart-loop MUL JMPS ~selection.from LDR #00 NEQ ^$loop MUL JMPS
( clamp at document body ) ( clamp at document body )
~selection.from ,document.body GTH2 RTS? ~selection.from ,document.body GTH2 RTS?
,document.body DUP2 =selection.from #0001 ADD2 =selection.to ,document.body DUP2 =selection.from #0001 ADD2 =selection.to
@ -263,11 +263,11 @@ RTS
@goto-lineend @goto-lineend
@goto-lineend-loop NOP $loop NOP
~selection.from LDR #0a EQU RTS? ~selection.from LDR #0a EQU RTS?
~selection.from LDR #0d EQU RTS? ~selection.from LDR #0d EQU RTS?
( incr ) ~selection.from #0001 ADD2 DUP2 #0001 ADD2 =selection.to =selection.from ( incr ) ~selection.from #0001 ADD2 DUP2 #0001 ADD2 =selection.to =selection.from
~selection.from LDR #00 NEQ ^goto-lineend-loop MUL JMPS ~selection.from LDR #00 NEQ ^$loop MUL JMPS
( clamp at document body ) ( clamp at document body )
~selection.from ,document.eof LTH2 RTS? ~selection.from ,document.eof LTH2 RTS?
,document.eof #0001 SUB2 DUP2 =selection.from #0001 ADD2 =selection.to ,document.eof #0001 SUB2 DUP2 =selection.from #0001 ADD2 =selection.to
@ -277,13 +277,13 @@ RTS
@find-wordstart @find-wordstart
~selection.to =j ~selection.to =j
@find-wordstart-loop NOP $loop NOP
( decr ) ~j #0001 SUB2 =j ( decr ) ~j #0001 SUB2 =j
,find-wordstart-end ~j LDR #20 EQU JMP2? POP2 ,$end ~j LDR #20 EQU JMP2? POP2
,find-wordstart-end ~j LDR #0a EQU JMP2? POP2 ,$end ~j LDR #0a EQU JMP2? POP2
,find-wordstart-end ~j LDR #0d EQU JMP2? POP2 ,$end ~j LDR #0d EQU JMP2? POP2
~j ,document.body GTH2 ^find-wordstart-loop MUL JMPS ~j ,document.body GTH2 ^$loop MUL JMPS
@find-wordstart-end $end
( return ) ~j #0001 SUB2 ( return ) ~j #0001 SUB2
RTS RTS
@ -291,13 +291,13 @@ RTS
@find-wordend @find-wordend
~selection.to =j ~selection.to =j
@find-wordend-loop NOP $loop NOP
( incr ) ~j #0001 ADD2 =j ( incr ) ~j #0001 ADD2 =j
,find-wordend-end ~j LDR #20 EQU JMP2? POP2 ,$end ~j LDR #20 EQU JMP2? POP2
,find-wordend-end ~j LDR #0a EQU JMP2? POP2 ,$end ~j LDR #0a EQU JMP2? POP2
,find-wordend-end ~j LDR #0d EQU JMP2? POP2 ,$end ~j LDR #0d EQU JMP2? POP2
~j ,document.body GTH2 ^find-wordend-loop MUL JMPS ~j ,document.body GTH2 ^$loop MUL JMPS
@find-wordend-end $end
( return ) ~j #0001 ADD2 ( return ) ~j #0001 ADD2
RTS RTS
@ -305,12 +305,12 @@ RTS
@find-lineoffset ( return character offset from linestart ) @find-lineoffset ( return character offset from linestart )
#0000 =j #0000 =j
@find-lineoffset-loop NOP $loop NOP
( incr ) ~j #0001 ADD2 =j ( incr ) ~j #0001 ADD2 =j
,find-lineoffset-end ~selection.from ~j SUB2 LDR #0a EQU JMP2? POP2 ,$end ~selection.from ~j SUB2 LDR #0a EQU JMP2? POP2
,find-lineoffset-end ~selection.from ~j SUB2 LDR #0d EQU JMP2? POP2 ,$end ~selection.from ~j SUB2 LDR #0d EQU JMP2? POP2
~selection.from ~j SUB2 ,document.body GTH2 ^find-lineoffset-loop MUL JMPS ~selection.from ~j SUB2 ,document.body GTH2 ^$loop MUL JMPS
@find-lineoffset-end $end
( return ) ~j ( return ) ~j
RTS RTS
@ -318,14 +318,14 @@ RTS
@find-line ( position -> addr ) @find-line ( position -> addr )
,document.body =j #0000 =pt.y ,document.body =j #0000 =pt.y
@find-line-loop NOP $loop NOP
,find-line-end ~pt.y ~position.y #0001 SUB2 GTH2 JMP2? POP2 ,$end ~pt.y ~position.y #0001 SUB2 GTH2 JMP2? POP2
,find-line-no-space ~j LDR #0a NEQ ~j LDR #0d NEQ #0101 EQU2 JMP2? POP2 ,$no-space ~j LDR #0a NEQ ~j LDR #0d NEQ #0101 EQU2 JMP2? POP2
( incr ) ~pt.y #0001 ADD2 =pt.y ( incr ) ~pt.y #0001 ADD2 =pt.y
@find-line-no-space $no-space
( incr ) ~j #0001 ADD2 =j ( incr ) ~j #0001 ADD2 =j
~j LDR #00 NEQ ^find-line-loop MUL JMPS ~j LDR #00 NEQ ^$loop MUL JMPS
@find-line-end $end
( return ) ~j ( return ) ~j
RTS RTS
@ -336,12 +336,12 @@ RTS
#0000 =pt.x #0000 =pt.x
@find-selection-loop NOP $loop NOP
,find-selection-end ~j ~pt.x ADD2 LDR #0a EQU JMP2? POP2 ,$end ~j ~pt.x ADD2 LDR #0a EQU JMP2? POP2
,find-selection-end ~j ~pt.x ADD2 LDR #0d EQU JMP2? POP2 ,$end ~j ~pt.x ADD2 LDR #0d EQU JMP2? POP2
( incr ) ~pt.x #0001 ADD2 =pt.x ( incr ) ~pt.x #0001 ADD2 =pt.x
~pt.x ~position.x #0001 SUB2 LTH2 ^find-selection-loop MUL JMPS ~pt.x ~position.x #0001 SUB2 LTH2 ^$loop MUL JMPS
@find-selection-end $end
( return ) ~pt.x ADD2 ( return ) ~pt.x ADD2
RTS RTS
@ -350,18 +350,18 @@ RTS
,document.body =selection.from #0000 =pt.x #0000 =pt.y ,document.body =selection.from #0000 =pt.x #0000 =pt.y
@select-loop $loop
,no-space ~selection.from LDR #0a NEQ ~selection.from LDR #0d NEQ #0101 EQU2 JMP2? POP2 ,$no-space ~selection.from LDR #0a NEQ ~selection.from LDR #0d NEQ #0101 EQU2 JMP2? POP2
( incr ) ~pt.y #0001 ADD2 =pt.y ( incr ) ~pt.y #0001 ADD2 =pt.y
#0000 =pt.x #0000 =pt.x
@no-space $no-space
,no-reached ~pt.y ~position.y #0001 SUB2 GTH2 ~pt.x ~position.x #0001 SUB2 GTH2 #0101 NEQ2 JMP2? POP2 ,$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 ~selection.from #0001 ADD2 =selection.to
RTS RTS
@no-reached $no-reached
( incr ) ~pt.x #0001 ADD2 =pt.x ( incr ) ~pt.x #0001 ADD2 =pt.x
( incr ) ~selection.from #0001 ADD2 =selection.from ( incr ) ~selection.from #0001 ADD2 =selection.from
,select-loop ~selection.from LDR #00 NEQ JMP2? POP2 ,$loop ~selection.from LDR #00 NEQ JMP2? POP2
RTS RTS
@ -392,17 +392,17 @@ RTS
#0000 =j #0000 =j
#0000 =SPRT.x #0000 =SPRT.y #0000 =SPRT.x #0000 =SPRT.y
@draw-lines-loop $loop
~scroll.y ~j ADD2 =addr ~scroll.y ~j ADD2 =addr
#0000 =SPRT.x #0000 =SPRT.x
,font_hex #00 ,addr #0001 ADD2 LDR #f0 AND #04 ROR #08 MUL ADD2 =SPRT.addr ,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 ( draw ) #02 ~addr ~position.y EQU2 #0c MUL ADD =SPRT.color
#0008 =SPRT.x #0008 =SPRT.x
,font_hex #00 ,addr #0001 ADD2 LDR #0f AND #08 MUL ADD2 =SPRT.addr ,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 ( draw ) #02 ~addr ~position.y EQU2 #0c MUL ADD =SPRT.color
( incr ) ~j #0001 ADD2 =j ( incr ) ~j #0001 ADD2 =j
( incr ) ~SPRT.y #0008 ADD2 =SPRT.y ( incr ) ~SPRT.y #0008 ADD2 =SPRT.y
,draw-lines-loop ~j ~SCRN.height #0008 SUB2 #0008 DIV2 NEQ2 JMP2? POP2 ,$loop ~j ~SCRN.height #0008 SUB2 #0008 DIV2 NEQ2 JMP2? POP2
RTS RTS
@ -469,9 +469,9 @@ RTS
#0018 =SPRT.x #0018 =SPRT.x
@draw-textarea-loop $loop
,draw-textarea-end ~SPRT.y ~SCRN.height #0010 SUB2 GTH2 JMP2? POP2 ,$end ~SPRT.y ~SCRN.height #0010 SUB2 GTH2 JMP2? POP2
( get character ) ( get character )
,font #00 ~j LDR #20 SUB #0008 MUL2 ADD2 =SPRT.addr ,font #00 ~j LDR #20 SUB #0008 MUL2 ADD2 =SPRT.addr
@ -481,29 +481,29 @@ RTS
~j ~selection.to LTH2 #0101 EQU2 ~j ~selection.to LTH2 #0101 EQU2
#05 MUL ADD =SPRT.color #05 MUL ADD =SPRT.color
,no-linebreak ~j LDR #0a NEQ ~j LDR #0d NEQ #0101 EQU2 JMP2? POP2 ,$no-linebreak ~j LDR #0a NEQ ~j LDR #0d NEQ #0101 EQU2 JMP2? POP2
( draw linebreak ) ( draw linebreak )
,linebreak_icn =SPRT.addr ,linebreak_icn =SPRT.addr
( draw ) #03 ( draw ) #02
~j ~selection.from #0001 SUB2 GTH2 ~j ~selection.from #0001 SUB2 GTH2
~j ~selection.to LTH2 #0101 EQU2 ~j ~selection.to LTH2 #0101 EQU2
#05 MUL ADD =SPRT.color #06 MUL ADD =SPRT.color
( fill clear ) ( fill clear )
@fill-clear $fill-clear
( incr ) ~SPRT.x #0008 ADD2 =SPRT.x ( incr ) ~SPRT.x #0008 ADD2 =SPRT.x
,font =SPRT.addr ,font =SPRT.addr
#01 =SPRT.color #01 =SPRT.color
,fill-clear ~SPRT.x ~SCRN.width #0008 SUB2 LTH2 JMP2? POP2 ,$fill-clear ~SPRT.x ~SCRN.width #0008 SUB2 LTH2 JMP2? POP2
#0010 =SPRT.x #0010 =SPRT.x
( incr ) ~SPRT.y #0008 ADD2 =SPRT.y ( incr ) ~SPRT.y #0008 ADD2 =SPRT.y
@no-linebreak $no-linebreak
( incr ) ~j #0001 ADD2 =j ( incr ) ~j #0001 ADD2 =j
( incr ) ~SPRT.x #0007 ADD2 =SPRT.x ( incr ) ~SPRT.x #0007 ADD2 =SPRT.x
,draw-textarea-loop ~j LDR #00 NEQ JMP2? POP2 ,$loop ~j LDR #00 NEQ JMP2? POP2
@draw-textarea-end $end
RTS RTS
@ -513,10 +513,10 @@ RTS
#0000 =SPRT.y #0000 =SPRT.y
,scrollbar_bg =SPRT.addr ,scrollbar_bg =SPRT.addr
@draw-scrollbar-loop $loop
( draw ) #08 =SPRT.color ( draw ) #08 =SPRT.color
( incr ) ~SPRT.y #0008 ADD2 =SPRT.y ( incr ) ~SPRT.y #0008 ADD2 =SPRT.y
,draw-scrollbar-loop ~SPRT.y ~SCRN.height LTH2 JMP2? POP2 ,$loop ~SPRT.y ~SCRN.height LTH2 JMP2? POP2
#0000 =SPRT.y #0000 =SPRT.y
,arrowup_icn =SPRT.addr ,arrowup_icn =SPRT.addr
@ -536,16 +536,14 @@ RTS
@draw-titlebar @draw-titlebar
#0018 ~SCRN.height #0008 SUB2 #09 ,filepath #0018 ~SCRN.height #0008 SUB2 #09 ,filepath
( load ) =label.addr =label.color =SPRT.y =SPRT.x ( load ) =label.addr =label.color =SPRT.y =SPRT.x
~label.addr ~label.addr
@draw-titlebar-loop NOP $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 =SPRT.addr ~label.color =SPRT.color
( incr ) #0001 ADD2 ( incr ) #0001 ADD2
( incr ) ~SPRT.x #0008 ADD2 =SPRT.x ( incr ) ~SPRT.x #0008 ADD2 =SPRT.x
DUP2 LDR #00 NEQ ^draw-titlebar-loop MUL JMPS DUP2 LDR #00 NEQ ^$loop MUL JMPS
POP2 POP2
( selection ) ( selection )
~selection.from ,document.body SUB2 ,draw-short JSR2 ~selection.from ,document.body SUB2 ,draw-short JSR2
@ -625,8 +623,8 @@ RTS
@arrowdown_icn [ 0010 1010 fe7c 3810 ] @arrowdown_icn [ 0010 1010 fe7c 3810 ]
@load_icn [ feaa d6aa d4aa f400 ] @load_icn [ feaa d6aa d4aa f400 ]
@save_icn [ fe82 8282 848a f400 ] @save_icn [ fe82 8282 848a f400 ]
@filepath1 [ projects/examples/jumptest.usm 00 ] @filepath [ projects/examples/gui.hover.usm 00 ]
@filepath [ projects/software/left.usm 00 ] @filepath1 [ projects/software/left.usm 00 ]
|4000 ;document Document |4000 ;document Document
@ -641,4 +639,4 @@ RTS
|FF60 ;FILE File |FF60 ;FILE File
|FFF0 .RESET .FRAME .ERROR ( vectors ) |FFF0 .RESET .FRAME .ERROR ( vectors )
|FFF8 [ a0fe a0f7 a0f2 ] ( palette ) |FFF8 [ 30ff e0f3 b0f3 ] ( palette )