... | ... |
@@ -90,6 +90,15 @@ clamp(int val, int min, int max) |
90 | 90 |
return (val >= min) ? (val <= max) ? val : max : min; |
91 | 91 |
} |
92 | 92 |
|
93 |
+void |
|
94 |
+setflag(Uint8 *a, char flag, int b) |
|
95 |
+{ |
|
96 |
+ if(b) |
|
97 |
+ *a |= flag; |
|
98 |
+ else |
|
99 |
+ *a &= (~flag); |
|
100 |
+} |
|
101 |
+ |
|
93 | 102 |
#pragma mark - Paint |
94 | 103 |
|
95 | 104 |
void |
... | ... |
@@ -598,7 +607,7 @@ start(Uxn *u) |
598 | 607 |
if(screen.reqdraw) |
599 | 608 |
redraw(pixels, u); |
600 | 609 |
elapsed = (SDL_GetPerformanceCounter() - start) / (double)SDL_GetPerformanceFrequency() * 1000.0f; |
601 |
- SDL_Delay(floor(16.666f - elapsed)); |
|
610 |
+ SDL_Delay((int)(16.666f - elapsed)); |
|
602 | 611 |
} |
603 | 612 |
} |
604 | 613 |
|
... | ... |
@@ -16,7 +16,6 @@ WITH REGARD TO THIS SOFTWARE. |
16 | 16 |
#pragma mark - Operations |
17 | 17 |
|
18 | 18 |
/* clang-format off */ |
19 |
-void setflag(Uint8 *a, char flag, int b) { if(b) *a |= flag; else *a &= (~flag); } |
|
20 | 19 |
int getflag(Uint8 *a, char flag) { return *a & flag; } |
21 | 20 |
Uint8 devpoke8(Uxn *u, Uint8 id, Uint8 b0, Uint8 b1){ return id < 0x10 ? u->dev[id].poke(u, PAGE_DEVICE + id * 0x10, b0, b1) : b1; } |
22 | 21 |
|
... | ... |
@@ -32,9 +31,9 @@ Uint16 peek16(Stack *s, Uint8 a) { return peek8(s, a * 2) + (peek8(s, a * 2 + 1) |
32 | 31 |
void mempoke16(Uxn *u, Uint16 a, Uint16 b) { mempoke8(u, a, b >> 8); mempoke8(u, a + 1, b); } |
33 | 32 |
Uint16 mempeek16(Uxn *u, Uint16 a) { return (mempeek8(u, a) << 8) + mempeek8(u, a + 1); } |
34 | 33 |
/* Stack */ |
35 |
-void op_brk(Uxn *u) { setflag(&u->status, FLAG_HALT, 1); } |
|
34 |
+void op_brk(Uxn *u) { u->ram.ptr = 0; } |
|
36 | 35 |
void op_nop(Uxn *u) { (void)u; } |
37 |
-void op_lit(Uxn *u) { setflag(&u->status, FLAG_LIT1, 1); } |
|
36 |
+void op_lit(Uxn *u) { push8(u->src, mempeek8(u, u->ram.ptr++)); } |
|
38 | 37 |
void op_pop(Uxn *u) { pop8(u->src); } |
39 | 38 |
void op_dup(Uxn *u) { push8(u->src, peek8(u->src, 0)); } |
40 | 39 |
void op_swp(Uxn *u) { Uint8 b = pop8(u->src), a = pop8(u->src); push8(u->src, b); push8(u->src, a); } |
... | ... |
@@ -66,7 +65,7 @@ void op_ora(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b |
66 | 65 |
void op_eor(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b ^ a); } |
67 | 66 |
void op_sft(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b >> (a & 0x07) << ((a & 0x70) >> 4)); } |
68 | 67 |
/* Stack */ |
69 |
-void op_lit16(Uxn *u) { setflag(&u->status, FLAG_LIT2, 1); } |
|
68 |
+void op_lit16(Uxn *u) { push16(u->src, mempeek16(u, u->ram.ptr++)); u->ram.ptr++; } |
|
70 | 69 |
void op_nop16(Uxn *u) { printf("%04x\n", pop16(u->src)); } |
71 | 70 |
void op_pop16(Uxn *u) { pop16(u->src); } |
72 | 71 |
void op_dup16(Uxn *u) { push16(u->src, peek16(u->src, 0)); } |
... | ... |
@@ -122,17 +121,6 @@ haltuxn(Uxn *u, char *name, int id) |
122 | 121 |
return 0; |
123 | 122 |
} |
124 | 123 |
|
125 |
-void |
|
126 |
-lituxn(Uxn *u, Uint8 instr) |
|
127 |
-{ |
|
128 |
- push8(u->src, instr); |
|
129 |
- if(getflag(&u->status, FLAG_LIT2)) { |
|
130 |
- setflag(&u->status, FLAG_LIT2, 0); |
|
131 |
- setflag(&u->status, FLAG_LIT1, 1); |
|
132 |
- } else if(getflag(&u->status, FLAG_LIT1)) |
|
133 |
- setflag(&u->status, FLAG_LIT1, 0); |
|
134 |
-} |
|
135 |
- |
|
136 | 124 |
void |
137 | 125 |
opcuxn(Uxn *u, Uint8 instr) |
138 | 126 |
{ |
... | ... |
@@ -145,10 +133,7 @@ opcuxn(Uxn *u, Uint8 instr) |
145 | 133 |
int |
146 | 134 |
stepuxn(Uxn *u, Uint8 instr) |
147 | 135 |
{ |
148 |
- if(u->status & 0x0c) |
|
149 |
- lituxn(u, instr); |
|
150 |
- else |
|
151 |
- opcuxn(u, instr); |
|
136 |
+ opcuxn(u, instr); |
|
152 | 137 |
if(u->wst.error) |
153 | 138 |
return haltuxn(u, u->wst.error == 1 ? "Working-stack underflow" : "Working-stack overflow", instr); |
154 | 139 |
if(u->rst.error) |
... | ... |
@@ -159,12 +144,10 @@ stepuxn(Uxn *u, Uint8 instr) |
159 | 144 |
int |
160 | 145 |
evaluxn(Uxn *u, Uint16 vec) |
161 | 146 |
{ |
162 |
- u->status = 0; |
|
163 | 147 |
u->ram.ptr = vec; |
164 | 148 |
u->wst.error = 0; |
165 | 149 |
u->rst.error = 0; |
166 |
- setflag(&u->status, FLAG_HALT, 0); |
|
167 |
- while(!(u->status & FLAG_HALT)) { |
|
150 |
+ while(u->ram.ptr) { |
|
168 | 151 |
Uint8 instr = u->ram.dat[u->ram.ptr++]; |
169 | 152 |
if(!stepuxn(u, instr)) |
170 | 153 |
return 0; |
... | ... |
@@ -16,7 +16,6 @@ typedef signed char Sint8; |
16 | 16 |
typedef unsigned short Uint16; |
17 | 17 |
typedef signed short Sint16; |
18 | 18 |
|
19 |
-#define FLAG_HALT 0x01 |
|
20 | 19 |
#define FLAG_LIT1 0x04 |
21 | 20 |
#define FLAG_LIT2 0x08 |
22 | 21 |
#define PAGE_DEVICE 0x0100 |
... | ... |
@@ -40,13 +39,11 @@ typedef struct Device { |
40 | 39 |
} Device; |
41 | 40 |
|
42 | 41 |
typedef struct Uxn { |
43 |
- Uint8 status; |
|
44 | 42 |
Stack wst, rst, *src, *dst; |
45 | 43 |
Memory ram; |
46 | 44 |
Device dev[16]; |
47 | 45 |
} Uxn; |
48 | 46 |
|
49 |
-void setflag(Uint8 *status, char flag, int b); |
|
50 | 47 |
int getflag(Uint8 *status, char flag); |
51 | 48 |
int loaduxn(Uxn *c, char *filepath); |
52 | 49 |
int bootuxn(Uxn *c); |