0
0
Fork 0
mirror of https://git.sr.ht/~rabbits/uxn synced 2024-11-25 15:25:12 +00:00

Progress on branching

This commit is contained in:
neauoire 2021-02-01 11:58:47 -08:00
parent 1482e5662d
commit 2782586f78
8 changed files with 61 additions and 35 deletions

View file

@ -34,6 +34,17 @@ $01 < pointer8 >
:label ADD RTS :label ADD RTS
``` ```
## Mission
- Loop
- Conditional example
- Pointers/Literals
- Print word to stdout
- Draw pixel to screen
- Detect mouse click
- 16 bits addressing
- jumping to subroutine should be relative
## TODOs ## TODOs
- Implement addressing - Implement addressing
@ -44,6 +55,7 @@ $01 < pointer8 >
- Audo-detect literals length. - Audo-detect literals length.
- SDL Layer Emulator - SDL Layer Emulator
- Build PPU - Build PPU
- Interrupts
## Refs ## Refs

View file

@ -13,12 +13,6 @@ rm -f ./boot.rom
cc -std=c89 -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined uxnasm.c -o uxnasm cc -std=c89 -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined uxnasm.c -o uxnasm
cc -std=c89 -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined uxn.c -o uxn cc -std=c89 -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined uxn.c -o uxn
# build(fast)
# cc uxn.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -o uxn
# Size
# echo "Size: $(du -sk ./uxn)"
# run # run
./uxnasm example.usm boot.rom ./uxnasm examples/cond.usm boot.rom
./uxn boot.rom ./uxn boot.rom

16
examples/cond.usm Normal file
View file

@ -0,0 +1,16 @@
< conditionals >
+03 +02 ADD
+05 EQU
.there JMQ
:here
< when not equal >
+ee
BRK
:there
< when is equal >
+ff
BRK

3
examples/core.usm Normal file
View file

@ -0,0 +1,3 @@
< core >
+12 -34

7
examples/jump.usm Normal file
View file

@ -0,0 +1,7 @@
< conditionals >
.end JMP
:end
+ff
BRK

12
uxn.c
View file

@ -91,8 +91,8 @@ rspop(void)
/* clang-format off */ /* clang-format off */
void op_brk() { setflag(FLAG_HALT, 1); } void op_brk() { setflag(FLAG_HALT, 1); }
void op_lit() { cpu.literal += cpu.memory[cpu.mptr++]; } void op_rts() { cpu.mptr = rspop(); }
void op_nop() { } void op_lit() { cpu.literal += 1;}
void op_drp() { spop(); } void op_drp() { spop(); }
void op_dup() { spush(cpu.stack[cpu.sptr - 1]); } void op_dup() { spush(cpu.stack[cpu.sptr - 1]); }
void op_swp() { Uint8 b = spop(), a = spop(); spush(b); spush(a); } void op_swp() { Uint8 b = spop(), a = spop(); spush(b); spush(a); }
@ -100,8 +100,8 @@ void op_ovr() { spush(cpu.stack[cpu.sptr - 2]); }
void op_rot() { Uint8 c = spop(),b = spop(),a = spop(); spush(b); spush(c); spush(a); } void op_rot() { Uint8 c = spop(),b = spop(),a = spop(); spush(b); spush(c); spush(a); }
void op_jmp() { cpu.mptr = spop(); } void op_jmp() { cpu.mptr = spop(); }
void op_jsr() { rspush(cpu.mptr); cpu.mptr = spop(); } void op_jsr() { rspush(cpu.mptr); cpu.mptr = spop(); }
void op_jeq() { if(getflag(FLAG_ZERO)) cpu.mptr = spop(); } void op_jmq() { if(getflag(FLAG_ZERO)) op_jmp(); }
void op_rts() { cpu.mptr = rspop(); } void op_jsq() { if(getflag(FLAG_ZERO)) op_jsr(); }
void op_equ() { setflag(FLAG_ZERO, spop() == spop()); } void op_equ() { setflag(FLAG_ZERO, spop() == spop()); }
void op_neq() { setflag(FLAG_ZERO, spop() != spop()); } void op_neq() { setflag(FLAG_ZERO, spop() != spop()); }
void op_lth() { setflag(FLAG_ZERO, spop() < spop()); } void op_lth() { setflag(FLAG_ZERO, spop() < spop()); }
@ -116,8 +116,8 @@ void op_mul() { spush(spop() * spop()); }
void op_div() { spush(spop() / spop()); } void op_div() { spush(spop() / spop()); }
void (*ops[])(void) = { void (*ops[])(void) = {
op_brk, op_lit, op_nop, op_drp, op_dup, op_swp, op_ovr, op_rot, op_brk, op_rts, op_lit, op_drp, op_dup, op_swp, op_ovr, op_rot,
op_jmp, op_jsr, op_jeq, op_rts, op_equ, op_neq, op_gth, op_lth, op_jmp, op_jsr, op_jmq, op_jsq, op_equ, op_neq, op_gth, op_lth,
op_and, op_ora, op_rol, op_ror, op_add, op_sub, op_mul, op_div}; op_and, op_ora, op_rol, op_ror, op_add, op_sub, op_mul, op_div};
/* clang-format on */ /* clang-format on */

View file

@ -31,8 +31,8 @@ Label labels[256];
char opcodes[][4] = { char opcodes[][4] = {
"BRK", "BRK",
"RTS",
"LIT", "LIT",
"---",
"POP", "POP",
"DUP", "DUP",
"SWP", "SWP",
@ -41,8 +41,8 @@ char opcodes[][4] = {
/* */ /* */
"JMP", "JMP",
"JSR", "JSR",
"JEQ", "JMQ",
"RTS", "JSQ",
"EQU", "EQU",
"NEQ", "NEQ",
"LTH", "LTH",
@ -164,11 +164,10 @@ int
getlength(char *w) getlength(char *w)
{ {
if(findop(w) || scmp(w, "BRK")) return 1; if(findop(w) || scmp(w, "BRK")) return 1;
if(w[0] == '.') return 3; if(w[0] == '.') return 2;
if(w[0] == ':') return 0; if(w[0] == ':') return 0;
if(w[0] == '[') return 2; if(w[0] == '+') return 2;
if(sihx(w)) return 1; if(w[0] == '-') return 2;
if(w[0] == ']') return 0;
printf("Unknown length %s\n", w); printf("Unknown length %s\n", w);
return 0; return 0;
} }
@ -205,28 +204,23 @@ pass2(FILE *f)
int skip = 0; int skip = 0;
char word[64]; char word[64];
while(fscanf(f, "%s", word) == 1) { while(fscanf(f, "%s", word) == 1) {
Uint8 op; Uint8 op = 0;
Label *l; Label *l;
if(word[0] == ':') continue; if(word[0] == ':') continue;
suca(word); suca(word);
if(comment(word, &skip)) continue; if(comment(word, &skip)) continue;
if(word[0] == ']') continue; /* literals */
if(word[0] == '+') { if(word[0] == '+' || word[0] == '-')
addprg(0x01); addprg(0x02);
addprg(1); if(word[0] == '+')
addprg(shex(word + 1)); addprg(shex(word + 1));
} else if(word[0] == '[') { else if(word[0] == '-')
addprg(0x01); addprg((Uint8)(-1 * shex(word + 1)));
addprg(shex(word + 1)); /* opcodes */
} else if((op = findop(word))) else if((op = findop(word)) || scmp(word, "BRK"))
addprg(op); addprg(op);
else if(sihx(word))
addprg(shex(word));
else if(scmp(word, "BRK"))
addprg(0x00);
else if((l = findlabel(word + 1))) { else if((l = findlabel(word + 1))) {
addprg(0x01); addprg(0x02);
addprg(1);
addprg(l->addr); addprg(l->addr);
} else } else
printf("unknown: %s\n", word); printf("unknown: %s\n", word);