Browse code

Started implementing peek/poke

neauoire authored on 21/03/2021 18:28:59
Showing 4 changed files
... ...
@@ -47,7 +47,7 @@ Program p;
47 47
 char ops[][4] = {
48 48
 	"BRK", "NOP", "LIT", "POP", "DUP", "SWP", "OVR", "ROT",
49 49
 	"EQU", "NEQ", "GTH", "LTH", "GTS", "LTS", "JMP", "JSR",
50
-	"LDR", "STR", "---", "---", "---", "---", "CLN", "STH",
50
+	"PEK", "POK", "LDR", "STR", "---", "---", "CLN", "STH",
51 51
 	"ADD", "SUB", "MUL", "DIV", "AND", "ORA", "EOR", "SFT"
52 52
 };
53 53
 
... ...
@@ -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/noodle.usm bin/boot.rom
23
+./bin/assembler projects/software/left.usm bin/boot.rom
24 24
 ./bin/emulator bin/boot.rom
25 25
new file mode 100644
... ...
@@ -0,0 +1,21 @@
1
+( tests/cond )
2
+
3
+;a { byte 1 }
4
+;b { byte1 1 byte2 1 }
5
+;c { byte1 1 byte2 1 byte3 1 }
6
+
7
+|0100 @RESET 
8
+	
9
+	#12 #00 POK
10
+
11
+	#00 PEK
12
+
13
+BRK
14
+
15
+|c000 @FRAME
16
+|d000 @ERROR 
17
+
18
+|FF00 ;Console { pad 8 char 1 byte 1 short 2 }
19
+
20
+|FFF0 .RESET .FRAME .ERROR ( vectors )
21
+|FFF8 [ 13fd 1ef3 1bf2 ] ( palette )
0 22
\ No newline at end of file
... ...
@@ -48,6 +48,8 @@ void op_lts(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, (S
48 48
 void op_jmp(Uxn *u) { Uint8 a = pop8(u->src); u->ram.ptr += (Sint8)a; }
49 49
 void op_jsr(Uxn *u) { Uint8 a = pop8(u->src); push16(u->dst, u->ram.ptr); u->ram.ptr += (Sint8)a; }
50 50
 /* Memory */
51
+void op_pek(Uxn *u) { Uint16 a = pop8(u->src); push8(u->src, mempeek8(u, a)); }
52
+void op_pok(Uxn *u) { Uint16 a = pop8(u->src); Uint8 b = pop8(u->src); mempoke8(u, a, b); }
51 53
 void op_ldr(Uxn *u) { Uint16 a = pop16(u->src); push8(u->src, mempeek8(u, a)); }
52 54
 void op_str(Uxn *u) { Uint16 a = pop16(u->src); Uint8 b = pop8(u->src); mempoke8(u, a, b); }
53 55
 void op_cln(Uxn *u) { push8(u->src, peek8(u->dst, 0)); }
... ...
@@ -79,6 +81,8 @@ void op_lts16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push8(u->sr
79 81
 void op_jmp16(Uxn *u) { u->ram.ptr = pop16(u->src); }
80 82
 void op_jsr16(Uxn *u) { push16(u->dst, u->ram.ptr); u->ram.ptr = pop16(u->src); }
81 83
 /* Memory(16-bits) */
84
+void op_pek16(Uxn *u) { Uint16 a = pop16(u->src); push8(u->src, mempeek8(u, a)); }
85
+void op_pok16(Uxn *u) { Uint16 a = pop16(u->src); Uint8 b = pop8(u->src); mempoke8(u, a, b); }
82 86
 void op_ldr16(Uxn *u) { Uint16 a = pop16(u->src); push16(u->src, mempeek16(u, a)); }
83 87
 void op_str16(Uxn *u) { Uint16 a = pop16(u->src); Uint16 b = pop16(u->src); mempoke16(u, a, b); }
84 88
 void op_cln16(Uxn *u) { push16(u->src, peek16(u->dst, 0)); }
... ...
@@ -96,24 +100,24 @@ void op_sft16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); Uint8 left
96 100
 void (*ops[])(Uxn *u) = {
97 101
 	op_brk, op_nop, op_lit, op_pop, op_dup, op_swp, op_ovr, op_rot,
98 102
 	op_equ, op_neq, op_gth, op_lth, op_gts, op_lts, op_jmp, op_jsr, 
99
-	op_ldr, op_str, op_nop, op_nop, op_nop, op_nop, op_cln, op_sth, 
103
+	op_pek, op_pok, op_ldr, op_str, op_nop, op_nop, op_cln, op_sth, 
100 104
 	op_add, op_sub, op_mul, op_div, op_and, op_ora, op_eor, op_sft,
101 105
 	/* 16-bit */
102 106
 	op_brk,   op_nop16, op_lit16, op_pop16, op_dup16, op_swp16, op_ovr16, op_rot16,
103 107
 	op_equ16, op_neq16, op_gth16, op_lth16, op_gts16, op_lts16, op_jmp16, op_jsr16, 
104
-	op_ldr16, op_str16, op_nop,   op_nop,   op_nop,  op_nop,   op_cln16, op_sth16, 
108
+	op_pek16, op_pok16, op_ldr16, op_str16, op_nop,   op_nop,   op_cln16, op_sth16, 
105 109
 	op_add16, op_sub16, op_mul16, op_div16, op_and16, op_ora16, op_eor16, op_sft16
106 110
 };
107 111
 
108 112
 Uint8 opr[][4] = { /* wstack-/+ rstack-/+ */
109 113
 	{0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {1,0,0,0}, {0,2,0,0}, {2,2,0,0}, {2,3,0,0}, {3,3,0,0},
110 114
 	{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
-	{2,1,0,0}, {3,0,0,0}, {1,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,1}, {0,1,1,0},
115
+	{1,1,0,0}, {2,0,0,0}, {2,1,0,0}, {3,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,1}, {0,1,1,0},
112 116
 	{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 117
 	/* 16-bit */
114 118
 	{0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,2,0,0}, {0,2,0,0}, {1,1,0,0}, {4,6,0,0}, {6,6,0,0},
115 119
 	{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
-	{2,2,0,0}, {4,0,0,0}, {2,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,2}, {0,2,2,0},
120
+	{2,1,0,0}, {3,0,0,0}, {2,2,0,0}, {4,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,2}, {0,2,2,0},
117 121
 	{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 122
 };
119 123