Added constants
This commit is contained in:
parent
678b26c942
commit
e2b6b6907d
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
|
||||
|
||||
- `;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
|
||||
|
|
|
@ -18,7 +18,7 @@ contexts:
|
|||
- include: strings
|
||||
|
||||
numbers:
|
||||
- match: '\@(\S+)\s?'
|
||||
- match: '\|(\S+)\s?'
|
||||
scope: punctuation.definition
|
||||
pop: true
|
||||
|
||||
|
@ -29,6 +29,9 @@ contexts:
|
|||
- match: '\;(\S+)\s?'
|
||||
scope: string.control
|
||||
pop: true
|
||||
- match: '\_(\S+)\s?'
|
||||
scope: string.control
|
||||
pop: true
|
||||
- match: '\,(\S+)\s?'
|
||||
scope: keyword.control
|
||||
pop: true
|
|
@ -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
|
||||
;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
|
||||
|
|
28
uxnasm.c
28
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;
|
||||
}
|
||||
|
||||
|
@ -190,6 +190,14 @@ makelabel(char *id, Uint16 addr)
|
|||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
makeconst(char *id, FILE *f)
|
||||
{
|
||||
char wv[64];
|
||||
fscanf(f, "%s", wv);
|
||||
return makelabel(id, shex(wv));
|
||||
}
|
||||
|
||||
int
|
||||
pass1(FILE *f)
|
||||
{
|
||||
|
@ -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)))
|
||||
|
|
Loading…
Reference in New Issue