| ... | ... |
@@ -2,6 +2,26 @@ |
| 2 | 2 |
|
| 3 | 3 |
A [stack-based VM](https://wiki.xxiivv.com/site/uxn.html), written in ANSI C. |
| 4 | 4 |
|
| 5 |
+## Setup |
|
| 6 |
+ |
|
| 7 |
+If you wish to build your own emulator, you can create a new instance of Uxn like: |
|
| 8 |
+ |
|
| 9 |
+``` |
|
| 10 |
+#include "uxn.h" |
|
| 11 |
+ |
|
| 12 |
+Uxn u; |
|
| 13 |
+ |
|
| 14 |
+if(!bootuxn(&u)) |
|
| 15 |
+ return error("Boot", "Failed");
|
|
| 16 |
+if(!loaduxn(&u, argv[1])) |
|
| 17 |
+ return error("Load", "Failed");
|
|
| 18 |
+if(!init()) |
|
| 19 |
+ return error("Init", "Failed");
|
|
| 20 |
+ |
|
| 21 |
+evaluxn(u, u->vreset); /* Once on start */ |
|
| 22 |
+evaluxn(u, u->vframe); /* Each frame |
|
| 23 |
+``` |
|
| 24 |
+ |
|
| 5 | 25 |
## Assembly Syntax |
| 6 | 26 |
|
| 7 | 27 |
### Write |
| ... | ... |
@@ -67,6 +87,10 @@ BRK |
| 67 | 87 |
- Auto-advance ldr? |
| 68 | 88 |
- Getting rid of IOR/IOW would be nice.. |
| 69 | 89 |
- Sending from the wst to the rst, balance mode/flag? |
| 90 |
+- Device that works like an extra memory bank |
|
| 91 |
+- Line routine |
|
| 92 |
+- LineRect routine |
|
| 93 |
+- Draw a chr sprite. |
|
| 70 | 94 |
|
| 71 | 95 |
## Refs |
| 72 | 96 |
|
| ... | ... |
@@ -190,6 +190,12 @@ consolew(Device *d, Uint8 b) |
| 190 | 190 |
Uint8 |
| 191 | 191 |
screenr(Device *d, Uint8 b) |
| 192 | 192 |
{
|
| 193 |
+ switch(b) {
|
|
| 194 |
+ case 0: return (WIDTH >> 8) & 0xff; |
|
| 195 |
+ case 1: return WIDTH & 0xff; |
|
| 196 |
+ case 2: return (HEIGHT >> 8) & 0xff; |
|
| 197 |
+ case 3: return HEIGHT & 0xff; |
|
| 198 |
+ } |
|
| 193 | 199 |
return d->mem[b]; |
| 194 | 200 |
} |
| 195 | 201 |
|
| ... | ... |
@@ -293,11 +299,6 @@ main(int argc, char **argv) |
| 293 | 299 |
devmouse = portuxn(&u, "mouse", mouser, mousew); |
| 294 | 300 |
devkey = portuxn(&u, "key", keyr, keyw); |
| 295 | 301 |
|
| 296 |
- devscreen->mem[0] = (WIDTH >> 8) & 0xff; |
|
| 297 |
- devscreen->mem[1] = WIDTH & 0xff; |
|
| 298 |
- devscreen->mem[2] = (HEIGHT >> 8) & 0xff; |
|
| 299 |
- devscreen->mem[3] = HEIGHT & 0xff; |
|
| 300 |
- |
|
| 301 | 302 |
start(&u); |
| 302 | 303 |
|
| 303 | 304 |
echos(&u.wst, 0x40, "stack"); |
| ... | ... |
@@ -22,11 +22,22 @@ |
| 22 | 22 |
( fill rect x y w h ) |
| 23 | 23 |
,0040 ,0040 ,0060 ,0040 ,fillrect JSR |
| 24 | 24 |
|
| 25 |
- |
|
| 26 | 25 |
,01 ,color STR |
| 27 | 26 |
( fill rect x y w h ) |
| 28 | 27 |
,00a0 ,0010 ,0020 ,0020 ,fillrect JSR |
| 29 | 28 |
|
| 29 |
+ ,02 ,color STR |
|
| 30 |
+ ( fill rect x y w h ) |
|
| 31 |
+ ,00b0 ,0040 ,0020 ,0020 ,linerect JSR |
|
| 32 |
+ |
|
| 33 |
+ ,03 ,color STR |
|
| 34 |
+ ( fill rect x y w h ) |
|
| 35 |
+ ,0058 ,0028 ,0050 ,0050 ,linerect JSR |
|
| 36 |
+ |
|
| 37 |
+ ,01 ,color STR |
|
| 38 |
+ ( fill rect x y w h ) |
|
| 39 |
+ ,0028 ,0038 ,0050 ,0030 ,linerect JSR |
|
| 40 |
+ |
|
| 30 | 41 |
,redraw JSR |
| 31 | 42 |
|
| 32 | 43 |
BRK |
| ... | ... |
@@ -37,13 +48,28 @@ BRK |
| 37 | 48 |
@fillrectrow |
| 38 | 49 |
,x LDR^ ,x_ STR^ |
| 39 | 50 |
@fillrectcol |
| 40 |
- ,x_ LDR^ ,y_ LDR^ ,putpixel JSR |
|
| 51 |
+ ( draw ) ,x_ LDR^ ,y_ LDR^ ,putpixel JSR |
|
| 41 | 52 |
,x_ LDR^ ,0001 ADD^ ,x_ STR^ |
| 42 | 53 |
,x_ LDR^ ,w LDR^ ,x LDR^ ADD^ LTH^ ,fillrectcol ROT JMP? POP^ |
| 43 | 54 |
,y_ LDR^ ,0001 ADD^ ,y_ STR^ |
| 44 | 55 |
,y_ LDR^ ,h LDR^ ,y LDR^ ADD^ LTH^ ,fillrectrow ROT JMP? POP^ |
| 45 | 56 |
RTS |
| 46 | 57 |
|
| 58 |
+@linerect |
|
| 59 |
+ ,h STR^ ,w STR^ ,y STR^ ,x STR^ |
|
| 60 |
+ ,x LDR^ ,x_ STR^ ,y LDR^ ,y_ STR^ |
|
| 61 |
+ @linerectcol |
|
| 62 |
+ ( draw ) ,x LDR^ ,y_ LDR^ ,putpixel JSR |
|
| 63 |
+ ( draw ) ,x LDR^ ,w LDR^ ADD^ ,y_ LDR^ ,putpixel JSR |
|
| 64 |
+ ,y_ LDR^ ,0001 ADD^ ,y_ STR^ |
|
| 65 |
+ ,y_ LDR^ ,h LDR^ ,y LDR^ ADD^ LTH^ ,linerectcol ROT JMP? POP^ |
|
| 66 |
+ @linerectrow |
|
| 67 |
+ ( draw ) ,x_ LDR^ ,y LDR^ ,putpixel JSR |
|
| 68 |
+ ( draw ) ,x_ LDR^ ,y LDR^ ,h LDR^ ADD^ ,putpixel JSR |
|
| 69 |
+ ,x_ LDR^ ,0001 ADD^ ,x_ STR^ |
|
| 70 |
+ ,x_ LDR^ ,w LDR^ ,x LDR^ ADD^ ,0001 ADD^ LTH^ ,linerectrow ROT JMP? POP^ |
|
| 71 |
+ RTS |
|
| 72 |
+ |
|
| 47 | 73 |
@redraw |
| 48 | 74 |
,0000 IOW^ |
| 49 | 75 |
,0000 IOW^ |