Browse code

Cleanup

neauoire authored on 21/03/2021 17:30:43
Showing 3 changed files
... ...
@@ -45,8 +45,8 @@ Program p;
45 45
 /* clang-format off */
46 46
 
47 47
 char ops[][4] = {
48
-	"BRK", "NOP", "LIT", "LDR", "STR", "---", "JMP", "JSR", 
49
-	"EQU", "NEQ", "GTH", "LTH", "GTS", "LTS", "---", "---",
48
+	"BRK", "NOP", "LIT", "LDR", "STR", "---", "---", "---", 
49
+	"EQU", "NEQ", "GTH", "LTH", "GTS", "LTS", "JMP", "JSR",
50 50
 	"POP", "DUP", "SWP", "OVR", "ROT", "---", "CLN", "STH",
51 51
 	"ADD", "SUB", "MUL", "DIV", "AND", "ORA", "EOR", "SFT"
52 52
 };
... ...
@@ -20,5 +20,5 @@ cc -std=c89 -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werr
20 20
 # cc uxn.c emulator.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -L/usr/local/lib -lSDL2 -o bin/emulator
21 21
 
22 22
 # run
23
-./bin/assembler projects/software/left.usm bin/boot.rom
23
+./bin/assembler projects/software/nasu.usm bin/boot.rom
24 24
 ./bin/emulator bin/boot.rom
... ...
@@ -29,19 +29,21 @@ Uint8  peek8(Stack *s, Uint8 a) { return s->dat[s->ptr - a - 1]; }
29 29
 void   push16(Stack *s, Uint16 a) { push8(s, a >> 8); push8(s, a); }
30 30
 Uint16 pop16(Stack *s) { return pop8(s) + (pop8(s) << 8); }
31 31
 Uint16 peek16(Stack *s, Uint8 a) { return peek8(s, a * 2) + (peek8(s, a * 2 + 1) << 8); }
32
-/* I/O */
32
+/* Core */
33 33
 void op_brk(Uxn *u) { setflag(&u->status, FLAG_HALT, 1); }
34 34
 void op_lit(Uxn *u) { u->literal += 1; }
35 35
 void op_nop(Uxn *u) { (void)u; }
36
-void op_jmp(Uxn *u) { Uint8 a = pop8(u->src); u->ram.ptr += (Sint8)a; }
37
-void op_jsr(Uxn *u) { Uint8 a = pop8(u->src); push16(u->dst, u->ram.ptr); u->ram.ptr += (Sint8)a; }
38 36
 void op_ldr(Uxn *u) { Uint16 a = pop16(u->src); push8(u->src, mempeek8(u, a)); }
39 37
 void op_str(Uxn *u) { Uint16 a = pop16(u->src); Uint8 b = pop8(u->src); mempoke8(u, a, b); }
40 38
 /* Logic */
41
-void op_and(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b & a); }
42
-void op_ora(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b | a); }
43
-void op_eor(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b ^ a); }
44
-void op_sft(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); Uint8 left = (a & 0xf0) >> 4; Uint8 right = (a & 0x0f); push8(u->src, b >> (right % 8) << (left % 8)); }
39
+void op_equ(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b == a); }
40
+void op_neq(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b != a); }
41
+void op_gth(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b > a); }
42
+void op_lth(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b < a); }
43
+void op_gts(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, (Sint8)b > (Sint8)a); }
44
+void op_lts(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, (Sint8)b < (Sint8)a); }
45
+void op_jmp(Uxn *u) { Uint8 a = pop8(u->src); u->ram.ptr += (Sint8)a; }
46
+void op_jsr(Uxn *u) { Uint8 a = pop8(u->src); push16(u->dst, u->ram.ptr); u->ram.ptr += (Sint8)a; }
45 47
 /* Stack */
46 48
 void op_pop(Uxn *u) { pop8(u->src); }
47 49
 void op_dup(Uxn *u) { push8(u->src, peek8(u->src, 0)); }
... ...
@@ -55,24 +57,24 @@ void op_add(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b
55 57
 void op_sub(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b - a); }
56 58
 void op_mul(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b * a); }
57 59
 void op_div(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b / a); }
58
-void op_equ(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b == a); }
59
-void op_neq(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b != a); }
60
-void op_gth(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b > a); }
61
-void op_gts(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, (Sint8)b > (Sint8)a); }
62
-void op_lth(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b < a); }
63
-void op_lts(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, (Sint8)b < (Sint8)a); }
64
-/* --- */
60
+void op_and(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b & a); }
61
+void op_ora(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b | a); }
62
+void op_eor(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b ^ a); }
63
+void op_sft(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); Uint8 left = (a & 0xf0) >> 4; Uint8 right = (a & 0x0f); push8(u->src, b >> (right % 8) << (left % 8)); }
64
+/* Core */
65 65
 void op_lit16(Uxn *u) { u->literal += 2; }
66 66
 void op_nop16(Uxn *u) { printf("%04x\n", pop16(u->src)); }
67
-void op_jmp16(Uxn *u) { u->ram.ptr = pop16(u->src); }
68
-void op_jsr16(Uxn *u) { push16(u->dst, u->ram.ptr); u->ram.ptr = pop16(u->src); }
69 67
 void op_ldr16(Uxn *u) { Uint16 a = pop16(u->src); push16(u->src, mempeek16(u, a)); }
70 68
 void op_str16(Uxn *u) { Uint16 a = pop16(u->src); Uint16 b = pop16(u->src); mempoke16(u, a, b); }
71
-/* Logic */
72
-void op_and16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push16(u->src, b & a); }
73
-void op_ora16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push16(u->src, b | a); }
74
-void op_eor16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push16(u->src, b ^ a); }
75
-void op_sft16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); Uint8 left = (a & 0x00f0) >> 4; Uint8 right = (a & 0x000f); push16(u->src, b >> (right % 16) << (left % 16)); }
69
+/* Logic(16-bits) */
70
+void op_equ16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push8(u->src, b == a); }
71
+void op_neq16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push8(u->src, b != a); }
72
+void op_gth16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push8(u->src, b > a); }
73
+void op_lth16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push8(u->src, b < a); }
74
+void op_gts16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push8(u->src, (Sint16)b > (Sint16)a); }
75
+void op_lts16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push8(u->src, (Sint16)b < (Sint16)a); }
76
+void op_jmp16(Uxn *u) { u->ram.ptr = pop16(u->src); }
77
+void op_jsr16(Uxn *u) { push16(u->dst, u->ram.ptr); u->ram.ptr = pop16(u->src); }
76 78
 /* Stack(16-bits) */
77 79
 void op_pop16(Uxn *u) { pop16(u->src); }
78 80
 void op_dup16(Uxn *u) { push16(u->src, peek16(u->src, 0)); }
... ...
@@ -86,33 +88,31 @@ void op_add16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push16(u->s
86 88
 void op_sub16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push16(u->src, b - a); }
87 89
 void op_mul16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push16(u->src, b * a); }
88 90
 void op_div16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push16(u->src, b / a); }
89
-void op_equ16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push8(u->src, b == a); }
90
-void op_neq16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push8(u->src, b != a); }
91
-void op_gth16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push8(u->src, b > a); }
92
-void op_gts16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push8(u->src, (Sint16)b > (Sint16)a); }
93
-void op_lth16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push8(u->src, b < a); }
94
-void op_lts16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push8(u->src, (Sint16)b < (Sint16)a); }
91
+void op_and16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push16(u->src, b & a); }
92
+void op_ora16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push16(u->src, b | a); }
93
+void op_eor16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push16(u->src, b ^ a); }
94
+void op_sft16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); Uint8 left = (a & 0x00f0) >> 4; Uint8 right = (a & 0x000f); push16(u->src, b >> (right % 16) << (left % 16)); }
95 95
 
96 96
 void (*ops[])(Uxn *u) = {
97
-	op_brk, op_nop, op_lit, op_ldr, op_str, op_nop, op_jmp, op_jsr, 
98
-	op_equ, op_neq, op_gth, op_lth, op_gts, op_lts, op_nop, op_nop, 
97
+	op_brk, op_nop, op_lit, op_ldr, op_str, op_nop, op_nop, op_nop, 
98
+	op_equ, op_neq, op_gth, op_lth, op_gts, op_lts, op_jmp, op_jsr, 
99 99
 	op_pop, op_dup, op_swp, op_ovr, op_rot, op_nop, op_cln, op_sth, 
100 100
 	op_add, op_sub, op_mul, op_div, op_and, op_ora, op_eor, op_sft,
101 101
 	/* 16-bit */
102
-	op_brk,   op_nop16, op_lit16, op_ldr16, op_str16, op_nop,   op_jmp16, op_jsr16, 
103
-	op_equ16, op_neq16, op_gth16, op_lth16, op_gts16, op_lts16, op_nop,   op_nop, 
102
+	op_brk,   op_nop16, op_lit16, op_ldr16, op_str16, op_nop,   op_nop,   op_nop, 
103
+	op_equ16, op_neq16, op_gth16, op_lth16, op_gts16, op_lts16, op_jmp16, op_jsr16, 
104 104
 	op_pop16, op_dup16, op_swp16, op_ovr16, op_rot16, op_nop,   op_cln16, op_sth16, 
105 105
 	op_add16, op_sub16, op_mul16, op_div16, op_and16, op_ora16, op_eor16, op_sft16
106 106
 };
107 107
 
108 108
 Uint8 opr[][4] = { /* wstack-/+ rstack-/+ */
109
-	{0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {2,1,0,0}, {3,0,0,0}, {1,0,0,0}, {1,0,0,0}, {1,0,0,2}, 
110
-	{2,1,0,0}, {2,1,0,0}, {2,1,0,0}, {2,1,0,0}, {2,1,0,0}, {2,1,0,0}, {0,0,0,0}, {0,0,0,0},
109
+	{0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {2,1,0,0}, {3,0,0,0}, {1,0,0,0}, {0,0,0,0}, {0,0,0,0},
110
+	{2,1,0,0}, {2,1,0,0}, {2,1,0,0}, {2,1,0,0}, {2,1,0,0}, {2,1,0,0}, {1,0,0,0}, {1,0,0,2}, 
111 111
 	{1,0,0,0}, {0,2,0,0}, {2,2,0,0}, {2,3,0,0}, {3,3,0,0}, {0,0,0,0}, {0,0,0,1}, {0,1,1,0},
112 112
 	{2,1,0,0}, {2,1,0,0}, {2,1,0,0}, {2,1,0,0}, {2,1,0,0}, {2,1,0,0}, {2,1,0,0}, {2,1,0,0},
113 113
 	/* 16-bit */
114
-	{0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {2,2,0,0}, {4,0,0,0}, {2,0,0,0}, {2,0,0,0}, {2,0,0,2},
115
-	{4,2,0,0}, {4,2,0,0}, {4,2,0,0}, {4,2,0,0}, {4,1,0,0}, {4,1,0,0}, {0,0,0,0}, {0,0,0,0},
114
+	{0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {2,2,0,0}, {4,0,0,0}, {2,0,0,0}, {0,0,0,0}, {0,0,0,0},
115
+	{4,2,0,0}, {4,2,0,0}, {4,2,0,0}, {4,2,0,0}, {4,1,0,0}, {4,1,0,0}, {2,0,0,0}, {2,0,0,2},
116 116
 	{0,2,0,0}, {0,2,0,0}, {1,1,0,0}, {4,6,0,0}, {6,6,0,0}, {0,0,0,0}, {0,0,0,2}, {0,2,2,0},
117 117
 	{4,2,0,0}, {4,2,0,0}, {4,2,0,0}, {4,2,0,0}, {4,2,0,0}, {4,2,0,0}, {4,2,0,0}, {4,2,0,0},
118 118
 };