uxn

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

commit cda02143cdd067d8847391ae53dfc1bf0c0c0e7a
parent 92397ff105b0be239ed5c6c6785da56dd7b319b5
Author: neauoire <aliceffekt@gmail.com>
Date:   Fri, 12 Feb 2021 19:51:39 -0800

Improved draw example

Diffstat:
Mbuild.sh | 2+-
Mexamples/draw.usm | 43+++++++++++++++++++++++++++++++++++++++++++
Mexamples/line.usm | 32+++++++++++++++++---------------
3 files changed, 61 insertions(+), 16 deletions(-)

diff --git a/build.sh b/build.sh @@ -24,5 +24,5 @@ rm -f ./bin/emulator cc -std=c89 -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined uxn.c emulator.c -L/usr/local/lib -lSDL2 -o bin/emulator # run -./bin/assembler examples/line.usm bin/boot.rom +./bin/assembler examples/draw.usm bin/boot.rom ./bin/emulator bin/boot.rom diff --git a/examples/draw.usm b/examples/draw.usm @@ -4,6 +4,7 @@ :dev/w fff9 ( std write port ) ;x_ 2 ;y_ 2 ;x 2 ;y 2 ;w 2 ;h 2 ;color 1 +;x0 2 ;y0 2 ;x1 2 ;y1 2 ;dx 2 ;dy 2 ;err1 2 ;err2 2 ( line ) |0100 @RESET @@ -38,6 +39,23 @@ ( fill rect x y w h ) ,0028 ,0038 ,0050 ,0030 ,linerect JSR + + ( positive ) + ,01 ,color STR + +0030 ,x0 STR^ +0040 ,y0 STR^ + +0100 ,x1 STR^ +0060 ,y1 STR^ + ,line JSR + + ,02 ,color STR + +0020 ,x0 STR^ +0010 ,y0 STR^ + +0090 ,x1 STR^ +0070 ,y1 STR^ + ,line JSR + + ,03 ,color STR + +0010 ,x0 STR^ +0040 ,y0 STR^ + +0070 ,x1 STR^ +0060 ,y1 STR^ + ,line JSR + ,redraw JSR BRK @@ -70,6 +88,31 @@ BRK ,x_ LDR^ ,w LDR^ ,x LDR^ ADD^ ,0001 ADD^ LTH^ ,linerectrow ROT JMP? POP^ RTS +@line + ,x0 LDR^ ,x_ STR^ ,y0 LDR^ ,y_ STR^ ( start at x0,y0 ) + ,x1 LDR^ ,x0 LDR^ ,diff16sub JSR ,dx STR^ ( int dx = abs[x1 - x0] ) + ,y1 LDR^ ,y0 LDR^ ,diff16sub JSR -0001 MUL!^ ,dy STR^ ( int dy = -abs[y1 - y0] ) + ,dx LDR^ ,dy LDR^ ADD!^ ,err1 STR^ ( int err1 = dx + dy, e2; ) + @lineloop + ,x_ LDR^ ,y_ LDR^ ,putpixel JSR ( draw ) + @line-x + ,err1 LDR^ +0002 MUL!^ ,err2 STR^ ( e2 = 2 * err; ) + ,err2 LDR^ ,dy LDR^ LTH!^ ,line-y ROT JMP? POP^ ( e2 >= dy ) + ,err1 LDR^ ,dy LDR^ ADD!^ ,err1 STR^ ( err1 += dy; ) + ,x_ LDR^ +0001 ADD!^ ,x_ STR^ ( y0 += y0 < y1 ? 1 : -1; ) + @line-y + ,err2 LDR^ ,dx LDR^ GTH!^ ,line-end ROT JMP? POP^ ( e2 <= dx ) + ,err1 LDR^ ,dx LDR^ ADD!^ ,err1 STR^ ( err1 += dx; ) + ,y_ LDR^ +0001 ADD!^ ,y_ STR^ ( y0 += y0 < y1 ? 1 : -1; ) + @line-end + ,x_ LDR^ ,x1 LDR^ NEQ!^ ,lineloop ROT JMP? POP^ ( loop ) + RTS + +@diff16 + OVR^ OVR^ GTH^ ,diff16sub ROT JMP? POP^ + SWP^ @diff16sub SUB^ +RTS + @redraw ,0000 IOW^ ,0000 IOW^ diff --git a/examples/line.usm b/examples/line.usm @@ -3,27 +3,28 @@ :dev/r fff8 ( std read port ) :dev/w fff9 ( std write port ) -;x_ 2 ;y_ 2 ;x0 2 ;y0 2 ;x1 2 ;y1 2 ;color 1 -;dx 2 ;dy 2 ;err 2 ;err2 2 +;x_ 2 ;y_ 2 ;color 1 +;x0 2 ;y0 2 ;x1 2 ;y1 2 ;dx 2 ;dy 2 ;err1 2 ;err2 2 |0100 @RESET ( set dev/write to screen ) ,01 ,dev/w STR + ( positive ) ,01 ,color STR +0030 ,x0 STR^ +0040 ,y0 STR^ - +0050 ,x1 STR^ +0060 ,y1 STR^ + +0100 ,x1 STR^ +0060 ,y1 STR^ ,line JSR ,02 ,color STR +0020 ,x0 STR^ +0010 ,y0 STR^ - +0060 ,x1 STR^ +0070 ,y1 STR^ + +0090 ,x1 STR^ +0070 ,y1 STR^ ,line JSR ,03 ,color STR +0010 ,x0 STR^ +0040 ,y0 STR^ - +0080 ,x1 STR^ +0060 ,y1 STR^ + +0070 ,x1 STR^ +0060 ,y1 STR^ ,line JSR ( draw control points ) @@ -39,19 +40,20 @@ BRK ,x0 LDR^ ,x_ STR^ ,y0 LDR^ ,y_ STR^ ( start at x0,y0 ) ,x1 LDR^ ,x0 LDR^ ,diff16sub JSR ,dx STR^ ( int dx = abs[x1 - x0] ) ,y1 LDR^ ,y0 LDR^ ,diff16sub JSR -0001 MUL!^ ,dy STR^ ( int dy = -abs[y1 - y0] ) - ,dx LDR^ ,dy LDR^ ADD!^ ,err STR^ ( int err = dx + dy, e2; ) - @loop + ,dx LDR^ ,dy LDR^ ADD!^ ,err1 STR^ ( int err1 = dx + dy, e2; ) + @lineloop ,x_ LDR^ ,y_ LDR^ ,putpixel JSR ( draw ) - ,err LDR^ +0002 MUL!^ ,err2 STR^ ( e2 = 2 * err; ) - ,err2 LDR^ ,dy LDR^ LTH!^ ,continue1 ROT JMP? POP^ ( e2 >= dy ) - ,err LDR^ ,dy LDR^ ADD!^ ,err STR^ ( err += dy; ) + @line-x + ,err1 LDR^ +0002 MUL!^ ,err2 STR^ ( e2 = 2 * err; ) + ,err2 LDR^ ,dy LDR^ LTH!^ ,line-y ROT JMP? POP^ ( e2 >= dy ) + ,err1 LDR^ ,dy LDR^ ADD!^ ,err1 STR^ ( err1 += dy; ) ,x_ LDR^ +0001 ADD!^ ,x_ STR^ ( y0 += y0 < y1 ? 1 : -1; ) - @continue1 - ,err2 LDR^ ,dx LDR^ GTH!^ ,continue2 ROT JMP? POP^ ( e2 <= dx ) - ,err LDR^ ,dx LDR^ ADD!^ ,err STR^ ( err += dx; ) + @line-y + ,err2 LDR^ ,dx LDR^ GTH!^ ,line-end ROT JMP? POP^ ( e2 <= dx ) + ,err1 LDR^ ,dx LDR^ ADD!^ ,err1 STR^ ( err1 += dx; ) ,y_ LDR^ +0001 ADD!^ ,y_ STR^ ( y0 += y0 < y1 ? 1 : -1; ) - @continue2 - ,x_ LDR^ ,x1 LDR^ LTH!^ ,loop ROT JMP? POP^ ( loop ) + @line-end + ,x_ LDR^ ,x1 LDR^ NEQ!^ ,lineloop ROT JMP? POP^ ( loop ) RTS @redraw