uxn

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

commit 4693ae1c1c0c93922c9aaac774f3818cf01a2856
parent f22e6b383716e34662cf60495cbc8275ba88d801
Author: neauoire <aliceffekt@gmail.com>
Date:   Thu, 11 Feb 2021 18:48:45 -0800

Added lineRect subroutine

Diffstat:
MREADME.md | 24++++++++++++++++++++++++
Memulator.c | 11++++++-----
Mexamples/draw.usm | 30++++++++++++++++++++++++++++--
Muxn.c | 2--
4 files changed, 58 insertions(+), 9 deletions(-)

diff --git a/README.md b/README.md @@ -2,6 +2,26 @@ A [stack-based VM](https://wiki.xxiivv.com/site/uxn.html), written in ANSI C. +## Setup + +If you wish to build your own emulator, you can create a new instance of Uxn like: + +``` +#include "uxn.h" + +Uxn u; + +if(!bootuxn(&u)) + return error("Boot", "Failed"); +if(!loaduxn(&u, argv[1])) + return error("Load", "Failed"); +if(!init()) + return error("Init", "Failed"); + +evaluxn(u, u->vreset); /* Once on start */ +evaluxn(u, u->vframe); /* Each frame +``` + ## Assembly Syntax ### Write @@ -67,6 +87,10 @@ BRK - Auto-advance ldr? - Getting rid of IOR/IOW would be nice.. - Sending from the wst to the rst, balance mode/flag? +- Device that works like an extra memory bank +- Line routine +- LineRect routine +- Draw a chr sprite. ## Refs diff --git a/emulator.c b/emulator.c @@ -190,6 +190,12 @@ consolew(Device *d, Uint8 b) Uint8 screenr(Device *d, Uint8 b) { + switch(b) { + case 0: return (WIDTH >> 8) & 0xff; + case 1: return WIDTH & 0xff; + case 2: return (HEIGHT >> 8) & 0xff; + case 3: return HEIGHT & 0xff; + } return d->mem[b]; } @@ -293,11 +299,6 @@ main(int argc, char **argv) devmouse = portuxn(&u, "mouse", mouser, mousew); devkey = portuxn(&u, "key", keyr, keyw); - devscreen->mem[0] = (WIDTH >> 8) & 0xff; - devscreen->mem[1] = WIDTH & 0xff; - devscreen->mem[2] = (HEIGHT >> 8) & 0xff; - devscreen->mem[3] = HEIGHT & 0xff; - start(&u); echos(&u.wst, 0x40, "stack"); diff --git a/examples/draw.usm b/examples/draw.usm @@ -22,11 +22,22 @@ ( fill rect x y w h ) ,0040 ,0040 ,0060 ,0040 ,fillrect JSR - ,01 ,color STR ( fill rect x y w h ) ,00a0 ,0010 ,0020 ,0020 ,fillrect JSR + ,02 ,color STR + ( fill rect x y w h ) + ,00b0 ,0040 ,0020 ,0020 ,linerect JSR + + ,03 ,color STR + ( fill rect x y w h ) + ,0058 ,0028 ,0050 ,0050 ,linerect JSR + + ,01 ,color STR + ( fill rect x y w h ) + ,0028 ,0038 ,0050 ,0030 ,linerect JSR + ,redraw JSR BRK @@ -37,13 +48,28 @@ BRK @fillrectrow ,x LDR^ ,x_ STR^ @fillrectcol - ,x_ LDR^ ,y_ LDR^ ,putpixel JSR + ( draw ) ,x_ LDR^ ,y_ LDR^ ,putpixel JSR ,x_ LDR^ ,0001 ADD^ ,x_ STR^ ,x_ LDR^ ,w LDR^ ,x LDR^ ADD^ LTH^ ,fillrectcol ROT JMP? POP^ ,y_ LDR^ ,0001 ADD^ ,y_ STR^ ,y_ LDR^ ,h LDR^ ,y LDR^ ADD^ LTH^ ,fillrectrow ROT JMP? POP^ RTS +@linerect + ,h STR^ ,w STR^ ,y STR^ ,x STR^ + ,x LDR^ ,x_ STR^ ,y LDR^ ,y_ STR^ + @linerectcol + ( draw ) ,x LDR^ ,y_ LDR^ ,putpixel JSR + ( draw ) ,x LDR^ ,w LDR^ ADD^ ,y_ LDR^ ,putpixel JSR + ,y_ LDR^ ,0001 ADD^ ,y_ STR^ + ,y_ LDR^ ,h LDR^ ,y LDR^ ADD^ LTH^ ,linerectcol ROT JMP? POP^ + @linerectrow + ( draw ) ,x_ LDR^ ,y LDR^ ,putpixel JSR + ( draw ) ,x_ LDR^ ,y LDR^ ,h LDR^ ADD^ ,putpixel JSR + ,x_ LDR^ ,0001 ADD^ ,x_ STR^ + ,x_ LDR^ ,w LDR^ ,x LDR^ ADD^ ,0001 ADD^ LTH^ ,linerectrow ROT JMP? POP^ + RTS + @redraw ,0000 IOW^ ,0000 IOW^ diff --git a/uxn.c b/uxn.c @@ -199,8 +199,6 @@ loaduxn(Uxn *u, char *filepath) return 1; } -/* to start: evaluxn(u, u->vreset); */ - Device * portuxn(Uxn *u, char *name, Uint8 (*rfn)(Device *, Uint8), Uint8 (*wfn)(Device *, Uint8)) {