This commit is contained in:
neauoire 2021-02-03 11:30:18 -08:00
parent 6d445ccee1
commit 1422c5dc6e
5 changed files with 25 additions and 39 deletions

View File

@ -35,18 +35,16 @@ cc uxn.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -o uxn
## Mission
- Catch overflow/underflow
- Jumps should be relative
- constants
- variables
- Pointers/Literals
- A Three-Way Decision Routine(http://www.6502.org/tutorials/compare_instructions.html)
- Carry flag?
- Loop
- Pointers/Literals
- Print word to stdout
- Draw pixel to screen
- Detect mouse click
- Jumps should be relative
- Catch overflow/underflow
- Audo-detect literals length.
- SDL Layer Emulator
- Build PPU
- Interrupts

View File

@ -14,5 +14,5 @@ cc -std=c89 -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werr
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
# run
./uxnasm examples/loop.usm boot.rom
./uxnasm examples/arithmetic.usm boot.rom
./uxn boot.rom

6
examples/arithmetic.usm Normal file
View File

@ -0,0 +1,6 @@
< arithmetic >
0203 LTH .true JMZ
:false ee BRK
:true ff BRK

46
uxn.c
View File

@ -68,39 +68,21 @@ echo(Stack *s, Uint8 len, char *name)
printf("\n\n");
}
void
wspush(Uint8 v)
{
cpu.wst.dat[cpu.wst.ptr++] = v;
}
Uint8
wspop(void)
{
return cpu.wst.dat[--cpu.wst.ptr];
}
void
rspush(Uint8 v)
{
cpu.rst.dat[cpu.rst.ptr++] = v;
}
Uint8
rspop(void)
{
return cpu.rst.dat[--cpu.rst.ptr];
}
#pragma mark - Operations
/* clang-format off */
void wspush(Uint8 v) { cpu.wst.dat[cpu.wst.ptr++] = v; }
Uint8 wspop(void) { return cpu.wst.dat[--cpu.wst.ptr]; }
Uint8 wspeek(void) { return cpu.wst.dat[cpu.wst.ptr - 1]; }
void rspush(Uint8 v) { cpu.rst.dat[cpu.rst.ptr++] = v; }
Uint8 rspop(void) { return cpu.rst.dat[--cpu.rst.ptr]; }
void op_brk() { setflag(FLAG_HALT, 1); }
void op_rts() { cpu.rom.ptr = rspop(); }
void op_lit() { cpu.literal += cpu.rom.dat[cpu.rom.ptr++]; }
void op_drp() { wspop(); }
void op_dup() { wspush(cpu.wst.dat[cpu.wst.ptr - 1]); }
void op_dup() { wspush(wspeek()); }
void op_swp() { Uint8 b = wspop(), a = wspop(); wspush(b); wspush(a); }
void op_ovr() { wspush(cpu.wst.dat[cpu.wst.ptr - 2]); }
void op_rot() { Uint8 c = wspop(),b = wspop(),a = wspop(); wspush(b); wspush(c); wspush(a); }
@ -108,10 +90,10 @@ void op_jmi() { cpu.rom.ptr = wspop(); }
void op_jsi() { rspush(cpu.rom.ptr); cpu.rom.ptr = wspop(); }
void op_jmz() { Uint8 a = wspop(); if(getflag(FLAG_ZERO)){ cpu.rom.ptr = a; } setflag(FLAG_ZERO,0); }
void op_jsz() { Uint8 a = wspop(); if(getflag(FLAG_ZERO)){ rspush(cpu.rom.ptr); cpu.rom.ptr = a; } setflag(FLAG_ZERO,0); }
void op_equ() { Uint8 a = wspop(); Uint8 b = wspop(); setflag(FLAG_ZERO, a == b); wspush(b); }
void op_neq() { Uint8 a = wspop(); Uint8 b = wspop(); setflag(FLAG_ZERO, a != b); wspush(b); }
void op_lth() { setflag(FLAG_ZERO, wspop() < cpu.wst.dat[cpu.wst.ptr]); }
void op_gth() { setflag(FLAG_ZERO, wspop() > cpu.wst.dat[cpu.wst.ptr]); }
void op_equ() { setflag(FLAG_ZERO, wspop() == wspeek()); }
void op_neq() { setflag(FLAG_ZERO, wspop() != wspeek()); }
void op_gth() { setflag(FLAG_ZERO, wspop() < wspeek()); }
void op_lth() { setflag(FLAG_ZERO, wspop() > wspeek()); }
void op_and() { wspush(wspop() & wspop()); }
void op_ora() { wspush(wspop() | wspop()); }
void op_rol() { wspush(wspop() << 1); }
@ -127,10 +109,10 @@ void (*ops[])(void) = {
op_and, op_ora, op_rol, op_ror, op_add, op_sub, op_mul, op_div};
Uint8 opr[][2] = {
{0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0},
{0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0},
{0,0}, {0,0}, {0,0}, {1,0}, {0,1}, {1,1}, {0,1}, {3,3},
{1,0}, {1,0}, {1,0}, {1,0}, {1,0}, {1,0}, {1,0}, {1,0},
{1,0}, {1,0}, {1,0}, {1,0}, {2,1}, {0,0}, {0,0}, {0,0},
{0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0},
{2,1}, {2,1}, {2,1}, {2,1}, {2,1}, {2,1}, {2,1}, {2,1}
};
/* clang-format on */

View File

@ -33,7 +33,7 @@ Label labels[256];
char opcodes[][4] = {
"BRK", "RTS", "LIT", "POP", "DUP", "SWP", "OVR", "ROT",
"JMI", "JSI", "JMZ", "JSZ", "EQU", "NEQ", "LTH", "GTH",
"JMI", "JSI", "JMZ", "JSZ", "EQU", "NEQ", "GTH", "LTH",
"AND", "ORA", "ROL", "ROR", "ADD", "SUB", "MUL", "DIV"};
/* clang-format on */