| ... | ... |
@@ -30,7 +30,7 @@ contexts: |
| 30 | 30 |
# Special |
| 31 | 31 |
|
| 32 | 32 |
- match: '\&(\S+)\s?' |
| 33 |
- scope: string.control |
|
| 33 |
+ scope: entity.name.type |
|
| 34 | 34 |
pop: true |
| 35 | 35 |
- match: '\=(\S+)\s?' |
| 36 | 36 |
scope: entity.name.type |
| ... | ... |
@@ -38,14 +38,10 @@ contexts: |
| 38 | 38 |
|
| 39 | 39 |
# Pushing to stack |
| 40 | 40 |
|
| 41 |
- - match: '\^(\S+)\s?' |
|
| 42 |
- scope: keyword.control |
|
| 43 |
- pop: true |
|
| 44 | 41 |
- match: '\#(\S+)\s?' |
| 45 | 42 |
scope: keyword.control |
| 46 | 43 |
pop: true |
| 47 | 44 |
|
| 48 |
- |
|
| 49 | 45 |
# Addressing |
| 50 | 46 |
- match: '\.(\S+)\s?' # zero-page |
| 51 | 47 |
scope: variable.control |
| ... | ... |
@@ -73,10 +69,3 @@ contexts: |
| 73 | 69 |
- meta_scope: comment.line |
| 74 | 70 |
- match: '\)' |
| 75 | 71 |
pop: true |
| 76 |
- |
|
| 77 |
- - match: '\[' |
|
| 78 |
- scope: keyword |
|
| 79 |
- push: |
|
| 80 |
- - meta_scope: keyword.line |
|
| 81 |
- - match: '\]' |
|
| 82 |
- pop: true |
| ... | ... |
@@ -9,26 +9,26 @@ |
| 9 | 9 |
|
| 10 | 10 |
( devices ) |
| 11 | 11 |
|
| 12 |
-|0100 @System &vector $2 &pad $6 &r $2 &g $2 &b $2 |
|
| 13 |
-|0110 @Console &pad $8 &char $1 &byte $1 &short $2 &string $2 |
|
| 14 |
-|0120 @Screen &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &color $1 |
|
| 15 |
-|0140 @Controller &vector $2 &button $1 &key $1 |
|
| 12 |
+|0100 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ] |
|
| 13 |
+|0110 @Console [ &pad $8 &char $1 &byte $1 &short $2 &string $2 ] |
|
| 14 |
+|0120 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &color $1 ] |
|
| 15 |
+|0140 @Controller [ &vector $2 &button $1 &key $1 ] |
|
| 16 | 16 |
|
| 17 | 17 |
|0200 |
| 18 | 18 |
|
| 19 | 19 |
( theme ) |
| 20 |
- #0daf ;System/r STR2 |
|
| 21 |
- #02ff ;System/g STR2 |
|
| 22 |
- #035f ;System/b STR2 |
|
| 20 |
+ #0daf .System/r IOW2 |
|
| 21 |
+ #02ff .System/g IOW2 |
|
| 22 |
+ #035f .System/b IOW2 |
|
| 23 | 23 |
|
| 24 | 24 |
( vectors ) |
| 25 |
- ;on-frame ;Screen/vector STR2 |
|
| 25 |
+ ;on-frame .Screen/vector IOW2 |
|
| 26 | 26 |
|
| 27 | 27 |
( set origin ) |
| 28 |
- ;Screen/width LDR2 2/ ;Screen/x STR2 |
|
| 29 |
- ;Screen/height LDR2 2/ ;Screen/y STR2 |
|
| 30 |
- ;default_icn ;Screen/addr STR2 |
|
| 31 |
- #31 ;Screen/color POK2 |
|
| 28 |
+ .Screen/width IOR2 2/ .Screen/x IOW2 |
|
| 29 |
+ .Screen/height IOR2 2/ .Screen/y IOW2 |
|
| 30 |
+ ;default_icn .Screen/addr IOW2 |
|
| 31 |
+ #31 .Screen/color IOW |
|
| 32 | 32 |
#2a .slime POK |
| 33 | 33 |
|
| 34 | 34 |
BRK |
| ... | ... |
@@ -36,43 +36,42 @@ BRK |
| 36 | 36 |
@on-frame |
| 37 | 37 |
|
| 38 | 38 |
#2a .slime POK |
| 39 |
- ;default_icn ;Screen/addr STR2 |
|
| 39 |
+ ;default_icn .Screen/addr IOW2 |
|
| 40 | 40 |
|
| 41 | 41 |
( hold ctrl key to change slime color ) |
| 42 |
- |
|
| 43 |
- ;Controller/button PEK2 #0f AND |
|
| 42 |
+ .Controller/button IOR #0f AND |
|
| 44 | 43 |
DUP #01 NEQ ,&no-ctrl JNZ #25 .slime POK &no-ctrl |
| 45 | 44 |
DUP #02 NEQ ,&no-alt JNZ #2f .slime POK &no-alt |
| 46 | 45 |
POP |
| 47 | 46 |
|
| 48 |
- ( clear ) #30 ;Screen/color POK2 |
|
| 47 |
+ ( clear ) #30 .Screen/color IOW |
|
| 49 | 48 |
|
| 50 | 49 |
( detect movement ) |
| 51 |
- ;Controller/button PEK2 #f0 AND |
|
| 50 |
+ .Controller/button IOR #f0 AND |
|
| 52 | 51 |
DUP #04 SFT #01 AND #01 NEQ ,&no-up JNZ |
| 53 | 52 |
( move ) |
| 54 |
- ;Screen/y LDR2 -- ;Screen/y STR2 |
|
| 55 |
- ;up_icn ;Screen/addr STR2 &no-up |
|
| 53 |
+ .Screen/y IOR2 -- .Screen/y IOW2 |
|
| 54 |
+ ;up_icn .Screen/addr IOW2 &no-up |
|
| 56 | 55 |
DUP #05 SFT #01 AND #01 NEQ ,&no-down JNZ |
| 57 | 56 |
( move ) |
| 58 |
- ;Screen/y LDR2 ++ ;Screen/y STR2 |
|
| 59 |
- ;down_icn ;Screen/addr STR2 &no-down |
|
| 57 |
+ .Screen/y IOR2 ++ .Screen/y IOW2 |
|
| 58 |
+ ;down_icn .Screen/addr IOW2 &no-down |
|
| 60 | 59 |
DUP #06 SFT #01 AND #01 NEQ ,&no-left JNZ |
| 61 | 60 |
( move ) |
| 62 |
- ;Screen/x LDR2 -- ;Screen/x STR2 |
|
| 63 |
- ;left_icn ;Screen/addr STR2 &no-left |
|
| 61 |
+ .Screen/x IOR2 -- .Screen/x IOW2 |
|
| 62 |
+ ;left_icn .Screen/addr IOW2 &no-left |
|
| 64 | 63 |
DUP #07 SFT #01 AND #01 NEQ ,&no-right JNZ |
| 65 | 64 |
( move ) |
| 66 |
- ;Screen/x LDR2 ++ ;Screen/x STR2 |
|
| 67 |
- ;right_icn ;Screen/addr STR2 &no-right |
|
| 65 |
+ .Screen/x IOR2 ++ .Screen/x IOW2 |
|
| 66 |
+ ;right_icn .Screen/addr IOW2 &no-right |
|
| 68 | 67 |
POP |
| 69 | 68 |
|
| 70 | 69 |
( draw face ) |
| 71 |
- #31 ;Screen/color POK2 |
|
| 70 |
+ #31 .Screen/color IOW |
|
| 72 | 71 |
|
| 73 | 72 |
( draw slime ) |
| 74 |
- ;slime_icn ;Screen/addr STR2 |
|
| 75 |
- .slime PEK ;Screen/color POK2 |
|
| 73 |
+ ;slime_icn .Screen/addr IOW2 |
|
| 74 |
+ .slime PEK .Screen/color IOW |
|
| 76 | 75 |
|
| 77 | 76 |
BRK |
| 78 | 77 |
|
| ... | ... |
@@ -11,22 +11,19 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 11 | 11 |
WITH REGARD TO THIS SOFTWARE. |
| 12 | 12 |
*/ |
| 13 | 13 |
|
| 14 |
-#define WORDLENMAX 32 |
|
| 15 |
-#define MACROMAX 64 |
|
| 16 |
-#define OFFSET 0x0200 |
|
| 14 |
+#define TRIM 0x0200 |
|
| 17 | 15 |
|
| 18 | 16 |
typedef unsigned char Uint8; |
| 19 | 17 |
typedef signed char Sint8; |
| 20 | 18 |
typedef unsigned short Uint16; |
| 21 |
-typedef signed short Sint16; |
|
| 22 | 19 |
|
| 23 | 20 |
typedef struct {
|
| 24 |
- char name[WORDLENMAX], items[MACROMAX][WORDLENMAX]; |
|
| 21 |
+ char name[64], items[64][64]; |
|
| 25 | 22 |
Uint8 len, refs; |
| 26 | 23 |
} Macro; |
| 27 | 24 |
|
| 28 | 25 |
typedef struct {
|
| 29 |
- char name[WORDLENMAX]; |
|
| 26 |
+ char name[64]; |
|
| 30 | 27 |
Uint8 refs; |
| 31 | 28 |
Uint16 addr; |
| 32 | 29 |
} Label; |
| ... | ... |
@@ -44,7 +41,7 @@ Program p; |
| 44 | 41 |
|
| 45 | 42 |
char ops[][4] = {
|
| 46 | 43 |
"BRK", "LIT", "NOP", "POP", "DUP", "SWP", "OVR", "ROT", |
| 47 |
- "EQU", "NEQ", "GTH", "LTH", "GTS", "LTS", "---", "---", |
|
| 44 |
+ "EQU", "NEQ", "GTH", "LTH", "GTS", "LTS", "IOR", "IOW", |
|
| 48 | 45 |
"PEK", "POK", "LDR", "STR", "JMP", "JNZ", "JSR", "STH", |
| 49 | 46 |
"ADD", "SUB", "MUL", "DIV", "AND", "ORA", "EOR", "SFT" |
| 50 | 47 |
}; |
| ... | ... |
@@ -163,9 +160,9 @@ makemacro(char *name, FILE *f) |
| 163 | 160 |
while(fscanf(f, "%s", word)) {
|
| 164 | 161 |
if(word[0] == '{') continue;
|
| 165 | 162 |
if(word[0] == '}') break; |
| 166 |
- if(m->len > MACROMAX) |
|
| 163 |
+ if(m->len > 64) |
|
| 167 | 164 |
return error("Macro too large", name);
|
| 168 |
- if(slen(word) >= WORDLENMAX) |
|
| 165 |
+ if(slen(word) >= 64) |
|
| 169 | 166 |
return error("Word too long", name);
|
| 170 | 167 |
scpy(word, m->items[m->len++], 64); |
| 171 | 168 |
} |
| ... | ... |
@@ -210,10 +207,13 @@ walktoken(char *w) |
| 210 | 207 |
if(findopcode(w) || scmp(w, "BRK", 4)) |
| 211 | 208 |
return 1; |
| 212 | 209 |
switch(w[0]) {
|
| 210 |
+ case '[': return 0; |
|
| 211 |
+ case ']': return 0; |
|
| 213 | 212 |
case '.': return 2; /* zero-page: LIT addr-lb */ |
| 214 |
- case ';': return 3; /* absolute: LIT addr-hb addr-lb */ |
|
| 215 |
- case ',': return 2; /* Relative jump: lit addr-offset */ |
|
| 216 |
- case '#': return (slen(w + 1) == 4 ? 3 : 2); |
|
| 213 |
+ case ',': return 2; /* relative: LIT addr-rel */ |
|
| 214 |
+ case ';': return 3; /* absolute: LIT addr-hb addr-lb */ |
|
| 215 |
+ case '$': return shex(w + 1); |
|
| 216 |
+ case '#': return slen(w + 1) == 4 ? 3 : 2; |
|
| 217 | 217 |
} |
| 218 | 218 |
if((m = findmacro(w))) {
|
| 219 | 219 |
int i, res = 0; |
| ... | ... |
@@ -227,10 +227,8 @@ walktoken(char *w) |
| 227 | 227 |
int |
| 228 | 228 |
parsetoken(char *w) |
| 229 | 229 |
{
|
| 230 |
- Uint8 op = 0; |
|
| 231 | 230 |
Label *l; |
| 232 | 231 |
Macro *m; |
| 233 |
- |
|
| 234 | 232 |
if(w[0] == '.' && (l = findlabel(w + 1))) { /* zero-page */
|
| 235 | 233 |
pushbyte(l->addr, 1); |
| 236 | 234 |
return ++l->refs; |
| ... | ... |
@@ -243,8 +241,8 @@ parsetoken(char *w) |
| 243 | 241 |
} else if(w[0] == ';' && (l = findlabel(w + 1))) { /* absolute */
|
| 244 | 242 |
pushshort(l->addr, 1); |
| 245 | 243 |
return ++l->refs; |
| 246 |
- } else if((op = findopcode(w)) || scmp(w, "BRK", 4)) {
|
|
| 247 |
- pushbyte(op, 0); |
|
| 244 |
+ } else if(findopcode(w) || scmp(w, "BRK", 4)) {
|
|
| 245 |
+ pushbyte(findopcode(w), 0); |
|
| 248 | 246 |
return 1; |
| 249 | 247 |
} else if(w[0] == '#') {
|
| 250 | 248 |
if(slen(w + 1) == 1) |
| ... | ... |
@@ -263,6 +261,12 @@ parsetoken(char *w) |
| 263 | 261 |
if(!parsetoken(m->items[i])) |
| 264 | 262 |
return 0; |
| 265 | 263 |
return 1; |
| 264 |
+ } else if(sihx(w)) {
|
|
| 265 |
+ if(slen(w) == 2) |
|
| 266 |
+ pushbyte(shex(w), 0); |
|
| 267 |
+ else if(slen(w) == 4) |
|
| 268 |
+ pushshort(shex(w), 0); |
|
| 269 |
+ return 1; |
|
| 266 | 270 |
} |
| 267 | 271 |
return 0; |
| 268 | 272 |
} |
| ... | ... |
@@ -270,38 +274,28 @@ parsetoken(char *w) |
| 270 | 274 |
int |
| 271 | 275 |
pass1(FILE *f) |
| 272 | 276 |
{
|
| 273 |
- int ccmnt = 0, cbits = 0; |
|
| 277 |
+ int ccmnt = 0; |
|
| 274 | 278 |
Uint16 addr = 0; |
| 275 | 279 |
char w[64], scope[64], subw[64]; |
| 276 | 280 |
printf("Pass 1\n");
|
| 277 | 281 |
while(fscanf(f, "%s", w) == 1) {
|
| 278 | 282 |
if(skipblock(w, &ccmnt, '(', ')')) continue;
|
| 279 |
- if(w[0] == '&') {
|
|
| 280 |
- if(!makelabel(sublabel(subw, scope, w + 1), addr)) |
|
| 281 |
- return error("Pass1 failed", w);
|
|
| 282 |
- } else if(skipblock(w, &cbits, '[', ']')) {
|
|
| 283 |
- if(w[0] == '[' || w[0] == ']') |
|
| 284 |
- continue; |
|
| 285 |
- if(slen(w) == 4 && sihx(w)) |
|
| 286 |
- addr += 2; |
|
| 287 |
- else if(slen(w) == 2 && sihx(w)) |
|
| 288 |
- addr += 1; |
|
| 289 |
- else |
|
| 290 |
- addr += slen(w); |
|
| 283 |
+ if(w[0] == '|') {
|
|
| 284 |
+ if(shex(w + 1) < addr) |
|
| 285 |
+ return error("Memory Overwrite", w);
|
|
| 286 |
+ addr = shex(w + 1); |
|
| 291 | 287 |
} else if(w[0] == '%') {
|
| 292 | 288 |
if(!makemacro(w + 1, f)) |
| 293 | 289 |
return error("Pass1 failed", w);
|
| 294 |
- scpy(w + 1, scope, 64); |
|
| 295 | 290 |
} else if(w[0] == '@') {
|
| 296 | 291 |
if(!makelabel(w + 1, addr)) |
| 297 | 292 |
return error("Pass1 failed", w);
|
| 298 | 293 |
scpy(w + 1, scope, 64); |
| 299 |
- } else if(w[0] == '|') {
|
|
| 300 |
- if(shex(w + 1) < addr) |
|
| 301 |
- return error("Memory Overwrite", w);
|
|
| 302 |
- addr = shex(w + 1); |
|
| 303 |
- } else if(w[0] == '$') |
|
| 304 |
- addr += shex(w + 1); |
|
| 294 |
+ } else if(w[0] == '&') {
|
|
| 295 |
+ if(!makelabel(sublabel(subw, scope, w + 1), addr)) |
|
| 296 |
+ return error("Pass1 failed", w);
|
|
| 297 |
+ } else if(sihx(w)) |
|
| 298 |
+ addr += slen(w) / 2; |
|
| 305 | 299 |
else |
| 306 | 300 |
addr += walktoken(w); |
| 307 | 301 |
} |
| ... | ... |
@@ -312,37 +306,29 @@ pass1(FILE *f) |
| 312 | 306 |
int |
| 313 | 307 |
pass2(FILE *f) |
| 314 | 308 |
{
|
| 315 |
- int ccmnt = 0, cbits = 0, ctemplate = 0; |
|
| 309 |
+ int ccmnt = 0, ctemplate = 0; |
|
| 316 | 310 |
char w[64], scope[64], subw[64]; |
| 317 | 311 |
printf("Pass 2\n");
|
| 318 | 312 |
while(fscanf(f, "%s", w) == 1) {
|
| 319 | 313 |
if(w[0] == '%') continue; |
| 320 | 314 |
if(w[0] == '&') continue; |
| 315 |
+ if(w[0] == '[') continue; |
|
| 316 |
+ if(w[0] == ']') continue; |
|
| 321 | 317 |
if(skipblock(w, &ccmnt, '(', ')')) continue;
|
| 322 | 318 |
if(skipblock(w, &ctemplate, '{', '}')) continue;
|
| 323 | 319 |
if(w[0] == '|') {
|
| 324 | 320 |
p.ptr = shex(w + 1); |
| 325 | 321 |
continue; |
| 326 |
- } |
|
| 327 |
- else if(w[0] == '$') {
|
|
| 322 |
+ } else if(w[0] == '$') {
|
|
| 328 | 323 |
p.ptr += shex(w + 1); |
| 329 | 324 |
continue; |
| 330 |
- } |
|
| 331 |
- else if(w[0] == '@') {
|
|
| 325 |
+ } else if(w[0] == '@') {
|
|
| 332 | 326 |
scpy(w + 1, scope, 64); |
| 333 | 327 |
continue; |
| 334 | 328 |
} |
| 335 | 329 |
if(w[1] == '&') |
| 336 | 330 |
scpy(sublabel(subw, scope, w + 2), w + 1, 64); |
| 337 |
- if(skipblock(w, &cbits, '[', ']')) {
|
|
| 338 |
- if(w[0] == '[' || w[0] == ']') { continue; }
|
|
| 339 |
- if(slen(w) == 4 && sihx(w)) |
|
| 340 |
- pushshort(shex(w), 0); |
|
| 341 |
- else if(slen(w) == 2 && sihx(w)) |
|
| 342 |
- pushbyte(shex(w), 0); |
|
| 343 |
- else |
|
| 344 |
- pushtext(w, 0); |
|
| 345 |
- } else if(!parsetoken(w)) |
|
| 331 |
+ if(!parsetoken(w)) |
|
| 346 | 332 |
return error("Unknown label in second pass", w);
|
| 347 | 333 |
} |
| 348 | 334 |
return 1; |
| ... | ... |
@@ -352,7 +338,7 @@ void |
| 352 | 338 |
cleanup(char *filename) |
| 353 | 339 |
{
|
| 354 | 340 |
int i; |
| 355 |
- printf("Assembled %s(%0.2fkb), %d labels, %d macros.\n\n", filename, (p.ptr - OFFSET) / 1000.0, p.llen, p.mlen);
|
|
| 341 |
+ printf("Assembled %s(%0.2fkb), %d labels, %d macros.\n\n", filename, (p.ptr - TRIM) / 1000.0, p.llen, p.mlen);
|
|
| 356 | 342 |
for(i = 0; i < p.llen; ++i) |
| 357 | 343 |
if(!p.labels[i].refs) |
| 358 | 344 |
printf("--- Unused label: %s\n", p.labels[i].name);
|
| ... | ... |
@@ -371,7 +357,7 @@ main(int argc, char *argv[]) |
| 371 | 357 |
return !error("Open", "Failed");
|
| 372 | 358 |
if(!pass1(f) || !pass2(f)) |
| 373 | 359 |
return !error("Assembly", "Failed");
|
| 374 |
- fwrite(p.data + OFFSET, p.ptr - OFFSET, 1, fopen(argv[2], "wb")); |
|
| 360 |
+ fwrite(p.data + TRIM, p.ptr - TRIM, 1, fopen(argv[2], "wb")); |
|
| 375 | 361 |
fclose(f); |
| 376 | 362 |
cleanup(argv[2]); |
| 377 | 363 |
return 0; |
| ... | ... |
@@ -181,6 +181,15 @@ doctrl(Uxn *u, SDL_Event *event, int z) |
| 181 | 181 |
|
| 182 | 182 |
#pragma mark - Devices |
| 183 | 183 |
|
| 184 |
+Uint8 |
|
| 185 |
+system_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1) |
|
| 186 |
+{
|
|
| 187 |
+ getcolors(&ppu, &u->ram.dat[ptr + 0x0008]); |
|
| 188 |
+ reqdraw = 1; |
|
| 189 |
+ (void)b0; |
|
| 190 |
+ return b1; |
|
| 191 |
+} |
|
| 192 |
+ |
|
| 184 | 193 |
Uint8 |
| 185 | 194 |
console_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1) |
| 186 | 195 |
{
|
| ... | ... |
@@ -199,9 +208,9 @@ Uint8 |
| 199 | 208 |
screen_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1) |
| 200 | 209 |
{
|
| 201 | 210 |
if(b0 == 0x0e) {
|
| 202 |
- Uint16 x = mempeek16(u, ptr + 8); |
|
| 203 |
- Uint16 y = mempeek16(u, ptr + 10); |
|
| 204 |
- Uint8 *addr = &u->ram.dat[mempeek16(u, ptr + 12)]; |
|
| 211 |
+ Uint16 x = mempeek16(u, devscreen->addr + 0x08); |
|
| 212 |
+ Uint16 y = mempeek16(u, devscreen->addr + 0x0a); |
|
| 213 |
+ Uint8 *addr = &u->ram.dat[mempeek16(u, devscreen->addr + 0x0c)]; |
|
| 205 | 214 |
Uint8 *layer = b1 >> 4 & 0x1 ? ppu.fg : ppu.bg; |
| 206 | 215 |
switch(b1 >> 5) {
|
| 207 | 216 |
case 0: putpixel(&ppu, layer, x, y, b1 & 0x3); break; |
| ... | ... |
@@ -210,6 +219,7 @@ screen_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1) |
| 210 | 219 |
} |
| 211 | 220 |
reqdraw = 1; |
| 212 | 221 |
} |
| 222 |
+ (void)ptr; |
|
| 213 | 223 |
return b1; |
| 214 | 224 |
} |
| 215 | 225 |
|
| ... | ... |
@@ -286,16 +296,6 @@ datetime_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1) |
| 286 | 296 |
return b1; |
| 287 | 297 |
} |
| 288 | 298 |
|
| 289 |
-Uint8 |
|
| 290 |
-system_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1) |
|
| 291 |
-{
|
|
| 292 |
- u->ram.dat[ptr + b0] = b1; |
|
| 293 |
- getcolors(&ppu, &u->ram.dat[ptr + 0x0008]); |
|
| 294 |
- reqdraw = 1; |
|
| 295 |
- (void)ptr; |
|
| 296 |
- return b1; |
|
| 297 |
-} |
|
| 298 |
- |
|
| 299 | 299 |
Uint8 |
| 300 | 300 |
ppnil(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1) |
| 301 | 301 |
{
|
| ... | ... |
@@ -16,11 +16,10 @@ WITH REGARD TO THIS SOFTWARE. |
| 16 | 16 |
#pragma mark - Operations |
| 17 | 17 |
|
| 18 | 18 |
/* clang-format off */ |
| 19 |
-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; }
|
|
| 20 | 19 |
void push8(Stack *s, Uint8 a) { if (s->ptr == 0xff) { s->error = 2; return; } s->dat[s->ptr++] = a; }
|
| 21 | 20 |
Uint8 pop8(Stack *s) { if (s->ptr == 0) { s->error = 1; return 0; } return s->dat[--s->ptr]; }
|
| 22 | 21 |
Uint8 peek8(Stack *s, Uint8 a) { if (s->ptr < a + 1) s->error = 1; return s->dat[s->ptr - a - 1]; }
|
| 23 |
-void mempoke8(Uxn *u, Uint16 a, Uint8 b) { u->ram.dat[a] = (a & 0xff00) == PAGE_DEVICE ? devpoke8(u, (a & 0xff) >> 4, a & 0xf, b) : b; }
|
|
| 22 |
+void mempoke8(Uxn *u, Uint16 a, Uint8 b) { u->ram.dat[a] = b; }
|
|
| 24 | 23 |
Uint8 mempeek8(Uxn *u, Uint16 a) { return u->ram.dat[a]; }
|
| 25 | 24 |
void push16(Stack *s, Uint16 a) { push8(s, a >> 8); push8(s, a); }
|
| 26 | 25 |
Uint16 pop16(Stack *s) { return pop8(s) + (pop8(s) << 8); }
|
| ... | ... |
@@ -43,6 +42,8 @@ void op_gth(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b
|
| 43 | 42 |
void op_lth(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b < a); }
|
| 44 | 43 |
void op_gts(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, (Sint8)b > (Sint8)a); }
|
| 45 | 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_ior(Uxn *u) { Uint8 a = pop8(u->src); push8(u->src, mempeek8(u, PAGE_DEVICE + a)); }
|
|
| 46 |
+void op_iow(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); mempoke8(u, PAGE_DEVICE + a, b); u->dev[(a & 0xf0) >> 4].poke(u, PAGE_DEVICE + (a & 0xf0), a & 0x0f, b); }
|
|
| 46 | 47 |
/* Memory */ |
| 47 | 48 |
void op_pek(Uxn *u) { Uint8 a = pop8(u->src); push8(u->src, mempeek8(u, a)); }
|
| 48 | 49 |
void op_pok(Uxn *u) { Uint8 a = pop8(u->src); Uint8 b = pop8(u->src); mempoke8(u, a, b); }
|
| ... | ... |
@@ -75,6 +76,8 @@ void op_gth16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push8(u->sr
|
| 75 | 76 |
void op_lth16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push8(u->src, b < a); }
|
| 76 | 77 |
void op_gts16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push8(u->src, (Sint16)b > (Sint16)a); }
|
| 77 | 78 |
void op_lts16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push8(u->src, (Sint16)b < (Sint16)a); }
|
| 79 |
+void op_ior16(Uxn *u) { Uint8 a = pop8(u->src); push16(u->src, mempeek16(u, PAGE_DEVICE + a)); }
|
|
| 80 |
+void op_iow16(Uxn *u) { Uint8 a = pop8(u->src); Uint16 b = pop16(u->src); mempoke16(u, PAGE_DEVICE + a, b); u->dev[(a & 0xf0) >> 4].poke(u, PAGE_DEVICE + (a & 0xf0), (a & 0x0f)+1, b); }
|
|
| 78 | 81 |
/* Memory(16-bits) */ |
| 79 | 82 |
void op_pek16(Uxn *u) { Uint16 a = pop16(u->src); push8(u->src, mempeek8(u, a)); }
|
| 80 | 83 |
void op_pok16(Uxn *u) { Uint16 a = pop16(u->src); Uint8 b = pop8(u->src); mempoke8(u, a, b); }
|
| ... | ... |
@@ -96,12 +99,12 @@ void op_sft16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push16(u->s
|
| 96 | 99 |
|
| 97 | 100 |
void (*ops[])(Uxn *u) = {
|
| 98 | 101 |
op_brk, op_lit, op_nop, op_pop, op_dup, op_swp, op_ovr, op_rot, |
| 99 |
- op_equ, op_neq, op_gth, op_lth, op_gts, op_lts, op_nop, op_nop, |
|
| 102 |
+ op_equ, op_neq, op_gth, op_lth, op_gts, op_lts, op_ior, op_iow, |
|
| 100 | 103 |
op_pek, op_pok, op_ldr, op_str, op_jmp, op_jnz, op_jsr, op_sth, |
| 101 | 104 |
op_add, op_sub, op_mul, op_div, op_and, op_ora, op_eor, op_sft, |
| 102 | 105 |
/* 16-bit */ |
| 103 |
- op_brk, op_lit16, op_nop, op_pop16, op_dup16, op_swp16, op_ovr16, op_rot16, |
|
| 104 |
- op_equ16, op_neq16, op_gth16, op_lth16, op_gts16, op_lts16, op_nop, op_nop, |
|
| 106 |
+ op_brk, op_lit16, op_nop, op_pop16, op_dup16, op_swp16, op_ovr16, op_rot16, |
|
| 107 |
+ op_equ16, op_neq16, op_gth16, op_lth16, op_gts16, op_lts16, op_ior16, op_iow16, |
|
| 105 | 108 |
op_pek16, op_pok16, op_ldr16, op_str16, op_jmp16, op_jnz16, op_jsr16, op_sth16, |
| 106 | 109 |
op_add16, op_sub16, op_mul16, op_div16, op_and16, op_ora16, op_eor16, op_sft16 |
| 107 | 110 |
}; |