uxn

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

commit e2b6b6907dc4bbe16bc3f5e7880b0fa0e6a3a747
parent 678b26c942c1533bd1258b2626db887cf4cf1807
Author: neauoire <aliceffekt@gmail.com>
Date:   Fri,  5 Feb 2021 10:51:45 -0800

Added constants

Diffstat:
MREADME.md | 18+++++++++++-------
Aetc/usm.sublime-syntax | 48++++++++++++++++++++++++++++++++++++++++++++++++
Aexamples/blank.usm | 27+++++++++++++++++++++++++++
Mexamples/core.usm | 34++++++++++++++++++----------------
Dextras/usm.sublime-syntax | 45---------------------------------------------
Muxnasm.c | 28++++++++++++++++++++++------
6 files changed, 126 insertions(+), 74 deletions(-)

diff --git a/README.md b/README.md @@ -12,18 +12,19 @@ cc uxn.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -o uxn ### Write -- `;variable`, set a name to address on the zero-page -- `:label`, set a name to an address +- `;variable`, set a label to an assigned address +- `:const`, set a label to a constant short +- `@label`, set a label to an address ### Read -- `,literal`, get a literal pointer -- `.pointer`, get a raw pointer +- `,literal`, push label value to stack +- `.pointer`, read label value ### Special -- `@0010`, move to position in the program -- `( comment )` +- `( comment )`, toggle parsing on/off +- `|0010`, move to position in the program ``` ;value ( alloc a zero-page variable ) @@ -49,7 +50,6 @@ cc uxn.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -o uxn ### Assembler - Catch overflow/underflow -- Constants - Jumps should be relative ### CPU @@ -63,6 +63,10 @@ cc uxn.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -o uxn - Build PPU - Add flags.. +### Devices + +- Devices each have an input byte, an output byte and two request bytes. + ## Refs https://code.9front.org/hg/plan9front/file/a7f9946e238f/sys/src/games/nes/cpu.c diff --git a/etc/usm.sublime-syntax b/etc/usm.sublime-syntax @@ -0,0 +1,48 @@ +%YAML 1.2 +--- +# See http://www.sublimetext.com/docs/3/syntax.html +name: Uxn Assembly +scopeName: usm. +fileTypes: [usm] +file_extensions: + - usm +scope: source.usm + +contexts: + prototype: + - include: comments + + main: + - include: keywords + - include: numbers + - include: strings + + numbers: + - match: '\|(\S+)\s?' + scope: punctuation.definition + pop: true + + strings: + - match: '\:(\S+)\s?' + scope: string.control + pop: true + - match: '\;(\S+)\s?' + scope: string.control + pop: true + - match: '\_(\S+)\s?' + scope: string.control + pop: true + - match: '\,(\S+)\s?' + scope: keyword.control + pop: true + - match: '\.(\S+)\s?' + scope: keyword.control + pop: true + + comments: + - match: '\(' + scope: punctuation.definition.comment.tome + push: + - meta_scope: comment.line.double-slash.tome + - match: '\)' + pop: true diff --git a/examples/blank.usm b/examples/blank.usm @@ -0,0 +1,27 @@ +( blank project ) + +;variable1 +;variable2 +_constant1 abcd + +|0100 ( -------------------------------- ) + +:RESET BRK + +|c000 ( -------------------------------- ) + +:FRAME ( FRAME-START ) + + + +BRK ( FRAME-END ) + +|d000 ( -------------------------------- ) + +:ERROR BRK + +|FFFA ( -------------------------------- ) + +.RESET +.FRAME +.ERROR diff --git a/examples/core.usm b/examples/core.usm @@ -1,27 +1,29 @@ -( define some variables in the zero-page ) +( blank project ) -;var1 -;var2 +;variable1 +:constant1 9abc -@0100 +|0100 ( -------------------------------- ) -:RESET ( --- ) - ,1234 - BRK +@RESET -@c000 ( much further.. ) +,abcd -:FRAME ( --- ) - ,ab ,0008 str - BRK +BRK ( RESET-END ) -@d000 ( further still.. ) +|c000 ( -------------------------------- ) -:ERROR ( --- ) - ,cdef - BRK +@FRAME ( FRAME-START ) -@FFFA ( vectors, last 3 shorts ) +,abcd + +BRK ( FRAME-END ) + +|d000 ( -------------------------------- ) + +@ERROR BRK + +|FFFA ( -------------------------------- ) .RESET .FRAME diff --git a/extras/usm.sublime-syntax b/extras/usm.sublime-syntax @@ -1,45 +0,0 @@ -%YAML 1.2 ---- -# See http://www.sublimetext.com/docs/3/syntax.html -name: Uxn Assembly -scopeName: usm. -fileTypes: [usm] -file_extensions: - - usm -scope: source.usm - -contexts: - prototype: - - include: comments - - main: - - include: keywords - - include: numbers - - include: strings - - numbers: - - match: '\@(\S+)\s?' - scope: punctuation.definition - pop: true - - strings: - - match: '\:(\S+)\s?' - scope: string.control - pop: true - - match: '\;(\S+)\s?' - scope: string.control - pop: true - - match: '\,(\S+)\s?' - scope: keyword.control - pop: true - - match: '\.(\S+)\s?' - scope: keyword.control - pop: true - - comments: - - match: '\(' - scope: punctuation.definition.comment.tome - push: - - meta_scope: comment.line.double-slash.tome - - match: '\)' - pop: true diff --git a/uxnasm.c b/uxnasm.c @@ -103,7 +103,7 @@ shex(char *s) /* string to num */ else if(c >= 'A' && c <= 'F') n = n * 16 + 10 + (c - 'A'); else if(c >= 'a' && c <= 'f') - n = n * 16 + 10 + (c - 'f'); + n = n * 16 + 10 + (c - 'a'); return n; } @@ -191,6 +191,14 @@ makelabel(char *id, Uint16 addr) } int +makeconst(char *id, FILE *f) +{ + char wv[64]; + fscanf(f, "%s", wv); + return makelabel(id, shex(wv)); +} + +int pass1(FILE *f) { int skip = 0, vars = 0; @@ -199,16 +207,22 @@ pass1(FILE *f) while(fscanf(f, "%s", w) == 1) { if(iscomment(w, &skip)) continue; suca(w); - if(w[0] == ':' && !makelabel(w + 1, addr)) + if(w[0] == '@' && !makelabel(w + 1, addr)) return error("Pass1 failed", w); if(w[0] == ';' && !makelabel(w + 1, vars++)) return error("Pass1 failed", w); + if(w[0] == ':') { + if(!makeconst(w + 1, f)) + return error("Pass1 failed", w); + else + continue; + } /* move addr ptr */ if(findop(w) || scmp(w, "BRK")) addr += 1; - else if(w[0] == '@') { + else if(w[0] == '|') addr = shex(w + 1); - } else if(w[0] == ':') + else if(w[0] == '@') addr += 0; else if(w[0] == ';') addr += 0; @@ -233,12 +247,14 @@ pass2(FILE *f) while(fscanf(f, "%s", w) == 1) { Uint8 op = 0; Label *l; - if(w[0] == ':') continue; + if(w[0] == '@') continue; if(w[0] == ';') continue; suca(w); if(iscomment(w, &skip) || ismarker(w)) continue; - if(w[0] == '@') + if(w[0] == '|') p.ptr = shex(w + 1); + else if(w[0] == ':') + fscanf(f, "%s", w); else if((op = findop(w)) || scmp(w, "BRK")) pushbyte(op, 0); else if((l = findlabel(w + 1)))