uxn/README.md

114 lines
2.7 KiB
Markdown
Raw Normal View History

2021-01-29 19:17:59 +00:00
# Uxn
2021-02-08 22:49:45 +00:00
A [stack-based VM](https://wiki.xxiivv.com/site/uxn.html), written in ANSI C.
2021-01-29 19:35:59 +00:00
2021-02-12 02:48:45 +00:00
## 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
```
2021-01-30 01:49:10 +00:00
## Assembly Syntax
2021-01-29 19:35:59 +00:00
- `ADD`, an opcode.
2021-02-08 22:49:45 +00:00
- `@label`, assign the current address to a label.
2021-02-13 21:21:05 +00:00
- `;variable 2`, assign an address to a label automatically.
- `:const 1a2b`, assign an address to a label manually.
2021-02-23 06:15:02 +00:00
- `&macro { x 2 y 2 }`, define a macro named `macro`.
- `#1a`, a literal byte/short.
- `+1a`, a literal signed byte/short.
- `-1a`, a literal signed byte/short(negative).
- `.ab`, a raw byte/short in memory.
2021-02-15 01:00:17 +00:00
- `,literal`, push label address to stack, prefixed with `LIT LEN`.
- `=label`, helper to STR, equivalent to `,label STR`, or `label STR2`.
- `~label`, helper to LDR, equivalent to `,label LDR2`, or `,label LDR2`.
- `|0010`, move to position in the program.
- `( comment )`, toggle parsing on/off.
- `[ 0123 abcd ]`, write shorts to memory.
- `[ Hello World ]`, write text to memory.
2021-01-31 05:31:49 +00:00
2021-02-06 18:39:13 +00:00
### Operator modes
2021-02-13 21:21:05 +00:00
- `#1234 #0001 ADD2`, 16-bits operators have the short flag `2`.
- `#12 #11 GTH JMP?`, conditional operators have the cond flag `?`.
2021-02-13 16:38:23 +00:00
- `+21 -03 MULS`, signed operators have the cond flag `S`.
2021-02-15 01:00:17 +00:00
- `ADDS2?`, modes can be combined.
2021-02-06 18:39:13 +00:00
2021-01-29 19:35:59 +00:00
```
( hello world )
2021-01-30 22:25:48 +00:00
2021-03-01 19:18:11 +00:00
&Console { pad 8 char 1 byte 1 short 2 }
2021-02-05 22:01:34 +00:00
|0100 @RESET
2021-03-01 17:38:54 +00:00
,text1 ,print-label JSR
,text2 ,print-label JSR
2021-03-01 19:18:11 +00:00
#ab =dev/console.byte
#cdef =dev/console.short
2021-02-08 04:49:00 +00:00
2021-02-13 21:21:05 +00:00
BRK
2021-02-05 22:01:34 +00:00
@print-label ( text )
2021-03-01 19:18:11 +00:00
@print-label-loop
2021-03-01 17:38:54 +00:00
DUP2 LDR =dev/console.char ( write pointer value to console )
#0001 ADD2 ( increment string pointer )
2021-03-01 19:18:11 +00:00
DUP2 LDR #00 NEQ ,print-label-loop ROT JMP? POP2 ( while *ptr!=0 goto loop )
POP2
2021-03-01 17:38:54 +00:00
RTS
2021-03-01 17:38:54 +00:00
@text1 [ Hello World 0a00 ] ( store text with a linebreak and null byte )
@text2 [ Welcome to UxnVM 0a00 ]
2021-02-08 04:49:00 +00:00
|c000 @FRAME
|d000 @ERROR
2021-02-27 03:46:56 +00:00
|FF00 ;dev/console Console
2021-03-01 17:38:54 +00:00
|FFF0 .RESET .FRAME .ERROR ( vectors )
|FFF8 [ 13fd 1ef3 1bf2 ] ( palette )
2021-01-29 19:35:59 +00:00
```
2021-02-08 22:49:45 +00:00
## TODOs
2021-02-01 19:58:47 +00:00
2021-02-26 18:16:35 +00:00
### OS Boot Disk
2021-02-15 01:00:17 +00:00
2021-02-26 18:16:35 +00:00
- Load external disk in disk2
- Build hex editor
### Assembler
2021-02-15 01:00:17 +00:00
- Includes
- Defines
2021-03-11 03:41:46 +00:00
- Jump relative
- Local loops
- Jump helpers
2021-02-05 18:51:45 +00:00
2021-03-08 18:30:13 +00:00
## Palettes
- `[ 6a03 4a0d aa0c ]`, purple/cyan
- `[ a1f3 a14d a16c ]`, grey-pink/teal
2021-01-30 22:25:48 +00:00
## Refs
https://code.9front.org/hg/plan9front/file/a7f9946e238f/sys/src/games/nes/cpu.c
http://www.w3group.de/stable_glossar.html
http://www.emulator101.com/6502-addressing-modes.html
http://forth.works/8f0c04f616b6c34496eb2141785b4454
2021-02-06 04:18:30 +00:00
https://justinmeiners.github.io/lc3-vm/