mirror of
https://git.sr.ht/~rabbits/uxn
synced 2024-11-23 06:15:10 +00:00
Added constants
This commit is contained in:
parent
678b26c942
commit
e2b6b6907d
5 changed files with 82 additions and 30 deletions
18
README.md
18
README.md
|
@ -12,18 +12,19 @@ cc uxn.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -o uxn
|
||||||
|
|
||||||
### Write
|
### Write
|
||||||
|
|
||||||
- `;variable`, set a name to address on the zero-page
|
- `;variable`, set a label to an assigned address
|
||||||
- `:label`, set a name to an address
|
- `:const`, set a label to a constant short
|
||||||
|
- `@label`, set a label to an address
|
||||||
|
|
||||||
### Read
|
### Read
|
||||||
|
|
||||||
- `,literal`, get a literal pointer
|
- `,literal`, push label value to stack
|
||||||
- `.pointer`, get a raw pointer
|
- `.pointer`, read label value
|
||||||
|
|
||||||
### Special
|
### Special
|
||||||
|
|
||||||
- `@0010`, move to position in the program
|
- `( comment )`, toggle parsing on/off
|
||||||
- `( comment )`
|
- `|0010`, move to position in the program
|
||||||
|
|
||||||
```
|
```
|
||||||
;value ( alloc a zero-page variable )
|
;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
|
### Assembler
|
||||||
|
|
||||||
- Catch overflow/underflow
|
- Catch overflow/underflow
|
||||||
- Constants
|
|
||||||
- Jumps should be relative
|
- Jumps should be relative
|
||||||
|
|
||||||
### CPU
|
### CPU
|
||||||
|
@ -63,6 +63,10 @@ cc uxn.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -o uxn
|
||||||
- Build PPU
|
- Build PPU
|
||||||
- Add flags..
|
- Add flags..
|
||||||
|
|
||||||
|
### Devices
|
||||||
|
|
||||||
|
- Devices each have an input byte, an output byte and two request bytes.
|
||||||
|
|
||||||
## Refs
|
## Refs
|
||||||
|
|
||||||
https://code.9front.org/hg/plan9front/file/a7f9946e238f/sys/src/games/nes/cpu.c
|
https://code.9front.org/hg/plan9front/file/a7f9946e238f/sys/src/games/nes/cpu.c
|
||||||
|
|
|
@ -18,7 +18,7 @@ contexts:
|
||||||
- include: strings
|
- include: strings
|
||||||
|
|
||||||
numbers:
|
numbers:
|
||||||
- match: '\@(\S+)\s?'
|
- match: '\|(\S+)\s?'
|
||||||
scope: punctuation.definition
|
scope: punctuation.definition
|
||||||
pop: true
|
pop: true
|
||||||
|
|
||||||
|
@ -29,6 +29,9 @@ contexts:
|
||||||
- match: '\;(\S+)\s?'
|
- match: '\;(\S+)\s?'
|
||||||
scope: string.control
|
scope: string.control
|
||||||
pop: true
|
pop: true
|
||||||
|
- match: '\_(\S+)\s?'
|
||||||
|
scope: string.control
|
||||||
|
pop: true
|
||||||
- match: '\,(\S+)\s?'
|
- match: '\,(\S+)\s?'
|
||||||
scope: keyword.control
|
scope: keyword.control
|
||||||
pop: true
|
pop: true
|
27
examples/blank.usm
Normal file
27
examples/blank.usm
Normal file
|
@ -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
|
|
@ -1,27 +1,29 @@
|
||||||
( define some variables in the zero-page )
|
( blank project )
|
||||||
|
|
||||||
;var1
|
;variable1
|
||||||
;var2
|
:constant1 9abc
|
||||||
|
|
||||||
@0100
|
|0100 ( -------------------------------- )
|
||||||
|
|
||||||
:RESET ( --- )
|
@RESET
|
||||||
,1234
|
|
||||||
BRK
|
|
||||||
|
|
||||||
@c000 ( much further.. )
|
,abcd
|
||||||
|
|
||||||
:FRAME ( --- )
|
BRK ( RESET-END )
|
||||||
,ab ,0008 str
|
|
||||||
BRK
|
|
||||||
|
|
||||||
@d000 ( further still.. )
|
|c000 ( -------------------------------- )
|
||||||
|
|
||||||
:ERROR ( --- )
|
@FRAME ( FRAME-START )
|
||||||
,cdef
|
|
||||||
BRK
|
|
||||||
|
|
||||||
@FFFA ( vectors, last 3 shorts )
|
,abcd
|
||||||
|
|
||||||
|
BRK ( FRAME-END )
|
||||||
|
|
||||||
|
|d000 ( -------------------------------- )
|
||||||
|
|
||||||
|
@ERROR BRK
|
||||||
|
|
||||||
|
|FFFA ( -------------------------------- )
|
||||||
|
|
||||||
.RESET
|
.RESET
|
||||||
.FRAME
|
.FRAME
|
||||||
|
|
28
uxnasm.c
28
uxnasm.c
|
@ -103,7 +103,7 @@ shex(char *s) /* string to num */
|
||||||
else if(c >= 'A' && c <= 'F')
|
else if(c >= 'A' && c <= 'F')
|
||||||
n = n * 16 + 10 + (c - 'A');
|
n = n * 16 + 10 + (c - 'A');
|
||||||
else if(c >= 'a' && c <= 'f')
|
else if(c >= 'a' && c <= 'f')
|
||||||
n = n * 16 + 10 + (c - 'f');
|
n = n * 16 + 10 + (c - 'a');
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,6 +190,14 @@ makelabel(char *id, Uint16 addr)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
makeconst(char *id, FILE *f)
|
||||||
|
{
|
||||||
|
char wv[64];
|
||||||
|
fscanf(f, "%s", wv);
|
||||||
|
return makelabel(id, shex(wv));
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
pass1(FILE *f)
|
pass1(FILE *f)
|
||||||
{
|
{
|
||||||
|
@ -199,16 +207,22 @@ pass1(FILE *f)
|
||||||
while(fscanf(f, "%s", w) == 1) {
|
while(fscanf(f, "%s", w) == 1) {
|
||||||
if(iscomment(w, &skip)) continue;
|
if(iscomment(w, &skip)) continue;
|
||||||
suca(w);
|
suca(w);
|
||||||
if(w[0] == ':' && !makelabel(w + 1, addr))
|
if(w[0] == '@' && !makelabel(w + 1, addr))
|
||||||
return error("Pass1 failed", w);
|
return error("Pass1 failed", w);
|
||||||
if(w[0] == ';' && !makelabel(w + 1, vars++))
|
if(w[0] == ';' && !makelabel(w + 1, vars++))
|
||||||
return error("Pass1 failed", w);
|
return error("Pass1 failed", w);
|
||||||
|
if(w[0] == ':') {
|
||||||
|
if(!makeconst(w + 1, f))
|
||||||
|
return error("Pass1 failed", w);
|
||||||
|
else
|
||||||
|
continue;
|
||||||
|
}
|
||||||
/* move addr ptr */
|
/* move addr ptr */
|
||||||
if(findop(w) || scmp(w, "BRK"))
|
if(findop(w) || scmp(w, "BRK"))
|
||||||
addr += 1;
|
addr += 1;
|
||||||
else if(w[0] == '@') {
|
else if(w[0] == '|')
|
||||||
addr = shex(w + 1);
|
addr = shex(w + 1);
|
||||||
} else if(w[0] == ':')
|
else if(w[0] == '@')
|
||||||
addr += 0;
|
addr += 0;
|
||||||
else if(w[0] == ';')
|
else if(w[0] == ';')
|
||||||
addr += 0;
|
addr += 0;
|
||||||
|
@ -233,12 +247,14 @@ pass2(FILE *f)
|
||||||
while(fscanf(f, "%s", w) == 1) {
|
while(fscanf(f, "%s", w) == 1) {
|
||||||
Uint8 op = 0;
|
Uint8 op = 0;
|
||||||
Label *l;
|
Label *l;
|
||||||
if(w[0] == ':') continue;
|
if(w[0] == '@') continue;
|
||||||
if(w[0] == ';') continue;
|
if(w[0] == ';') continue;
|
||||||
suca(w);
|
suca(w);
|
||||||
if(iscomment(w, &skip) || ismarker(w)) continue;
|
if(iscomment(w, &skip) || ismarker(w)) continue;
|
||||||
if(w[0] == '@')
|
if(w[0] == '|')
|
||||||
p.ptr = shex(w + 1);
|
p.ptr = shex(w + 1);
|
||||||
|
else if(w[0] == ':')
|
||||||
|
fscanf(f, "%s", w);
|
||||||
else if((op = findop(w)) || scmp(w, "BRK"))
|
else if((op = findop(w)) || scmp(w, "BRK"))
|
||||||
pushbyte(op, 0);
|
pushbyte(op, 0);
|
||||||
else if((l = findlabel(w + 1)))
|
else if((l = findlabel(w + 1)))
|
||||||
|
|
Loading…
Reference in a new issue