| ... | ... |
@@ -18,11 +18,24 @@ |
| 18 | 18 |
&pad 0000 |
| 19 | 19 |
0000 |
| 20 | 20 |
0000 |
| 21 |
- &r 0000 |
|
| 22 |
- &g 0000 |
|
| 23 |
- &b 0000 |
|
| 21 |
+ &r 0daf |
|
| 22 |
+ &g 02ff |
|
| 23 |
+ &b 035f |
|
| 24 | 24 |
&end |
| 25 | 25 |
] |
| 26 |
+ |
|
| 27 |
+|0110 @Console [ |
|
| 28 |
+ &pad 0000 |
|
| 29 |
+ 0000 |
|
| 30 |
+ 0000 |
|
| 31 |
+ 0000 |
|
| 32 |
+ &char 00 |
|
| 33 |
+ &byte 00 |
|
| 34 |
+ &short 0000 |
|
| 35 |
+ &string 0000 |
|
| 36 |
+ &end |
|
| 37 |
+] |
|
| 38 |
+ |
|
| 26 | 39 |
|0120 @Screen [ |
| 27 | 40 |
&vector 0000 |
| 28 | 41 |
&width 0000 |
| ... | ... |
@@ -34,6 +47,7 @@ |
| 34 | 47 |
&color 00 |
| 35 | 48 |
&end |
| 36 | 49 |
] |
| 50 |
+ |
|
| 37 | 51 |
|0140 @Controller [ |
| 38 | 52 |
&vector 0000 |
| 39 | 53 |
&button 00 |
| ... | ... |
@@ -42,51 +56,64 @@ |
| 42 | 56 |
] |
| 43 | 57 |
|
| 44 | 58 |
|0200 |
| 59 |
+ |
|
| 60 |
+ ( theme ) |
|
| 61 |
+ #0daf ,System/r STR2 |
|
| 62 |
+ #02ff ,System/g STR2 |
|
| 63 |
+ #035f ,System/b STR2 |
|
| 45 | 64 |
|
| 46 |
- ( theme ) #0daf =System/r #02ff =System/g #035f =System/b |
|
| 47 |
- ( vectors ) ,on-frame =Screen/vector |
|
| 65 |
+ ( vectors ) |
|
| 66 |
+ ,on-frame ,Screen/vector STR2 |
|
| 48 | 67 |
|
| 49 | 68 |
( set origin ) |
| 50 |
- ~Screen/width 2/ =Screen/x |
|
| 51 |
- ~Screen/height 2/ =Screen/y |
|
| 52 |
- ,default_icn =Screen/addr |
|
| 53 |
- #31 =Screen/color |
|
| 54 |
- #2a =slime/color |
|
| 69 |
+ ,Screen/width LDR2 2/ ,Screen/x STR2 |
|
| 70 |
+ ,Screen/height LDR2 2/ ,Screen/y STR2 |
|
| 71 |
+ ,default_icn ,Screen/addr STR2 |
|
| 72 |
+ #31 ,Screen/color POK2 |
|
| 73 |
+ #2a ,slime/color POK2 |
|
| 55 | 74 |
|
| 56 | 75 |
BRK |
| 57 | 76 |
|
| 58 | 77 |
@on-frame |
| 59 | 78 |
|
| 60 |
- #2a =slime/color |
|
| 61 |
- ,default_icn =Screen/addr |
|
| 79 |
+ #2a ,slime/color POK2 |
|
| 80 |
+ ,default_icn ,Screen/addr STR2 |
|
| 62 | 81 |
|
| 63 | 82 |
( hold ctrl key to change slime color ) |
| 64 | 83 |
|
| 65 |
- ~Controller/button #0f AND |
|
| 66 |
- DUP #01 NEQ ^$no-ctrl JNZ #25 =slime/color $no-ctrl |
|
| 67 |
- DUP #02 NEQ ^$no-alt JNZ #2f =slime/color $no-alt |
|
| 84 |
+ ,Controller/button PEK2 #0f AND |
|
| 85 |
+ DUP #01 NEQ ^&no-ctrl JNZ #25 ,slime/color POK2 &no-ctrl |
|
| 86 |
+ DUP #02 NEQ ^&no-alt JNZ #2f ,slime/color POK2 &no-alt |
|
| 68 | 87 |
POP |
| 69 | 88 |
|
| 70 |
- ( clear ) #30 =Screen/color |
|
| 89 |
+ ( clear ) #30 ,Screen/color POK2 |
|
| 71 | 90 |
|
| 72 | 91 |
( detect movement ) |
| 73 |
- ~Controller/button #f0 AND |
|
| 74 |
- DUP #04 SFT #01 AND #01 NEQ ^$no-up JNZ |
|
| 75 |
- ( move ) ~Screen/y -- =Screen/y ,up_icn =Screen/addr $no-up |
|
| 76 |
- DUP #05 SFT #01 AND #01 NEQ ^$no-down JNZ |
|
| 77 |
- ( move ) ~Screen/y ++ =Screen/y ,down_icn =Screen/addr $no-down |
|
| 78 |
- DUP #06 SFT #01 AND #01 NEQ ^$no-left JNZ |
|
| 79 |
- ( move ) ~Screen/x -- =Screen/x ,left_icn =Screen/addr $no-left |
|
| 80 |
- DUP #07 SFT #01 AND #01 NEQ ^$no-right JNZ |
|
| 81 |
- ( move ) ~Screen/x ++ =Screen/x ,right_icn =Screen/addr $no-right |
|
| 92 |
+ ,Controller/button PEK2 #f0 AND |
|
| 93 |
+ DUP #04 SFT #01 AND #01 NEQ ^&no-up JNZ |
|
| 94 |
+ ( move ) |
|
| 95 |
+ ,Screen/y LDR2 -- ,Screen/y STR2 |
|
| 96 |
+ ,up_icn ,Screen/addr STR2 &no-up |
|
| 97 |
+ DUP #05 SFT #01 AND #01 NEQ ^&no-down JNZ |
|
| 98 |
+ ( move ) |
|
| 99 |
+ ,Screen/y LDR2 ++ ,Screen/y STR2 |
|
| 100 |
+ ,down_icn ,Screen/addr STR2 &no-down |
|
| 101 |
+ DUP #06 SFT #01 AND #01 NEQ ^&no-left JNZ |
|
| 102 |
+ ( move ) |
|
| 103 |
+ ,Screen/x LDR2 -- ,Screen/x STR2 |
|
| 104 |
+ ,left_icn ,Screen/addr STR2 &no-left |
|
| 105 |
+ DUP #07 SFT #01 AND #01 NEQ ^&no-right JNZ |
|
| 106 |
+ ( move ) |
|
| 107 |
+ ,Screen/x LDR2 ++ ,Screen/x STR2 |
|
| 108 |
+ ,right_icn ,Screen/addr STR2 &no-right |
|
| 82 | 109 |
POP |
| 83 | 110 |
|
| 84 | 111 |
( draw face ) |
| 85 |
- #31 =Screen/color |
|
| 112 |
+ #31 ,Screen/color POK2 |
|
| 86 | 113 |
|
| 87 | 114 |
( draw slime ) |
| 88 |
- ,slime_icn =Screen/addr |
|
| 89 |
- ~slime/color =Screen/color |
|
| 115 |
+ ,slime_icn ,Screen/addr STR2 |
|
| 116 |
+ ,slime/color PEK2 ,Screen/color POK2 |
|
| 90 | 117 |
|
| 91 | 118 |
BRK |
| 92 | 119 |
|
| ... | ... |
@@ -13,6 +13,7 @@ WITH REGARD TO THIS SOFTWARE. |
| 13 | 13 |
|
| 14 | 14 |
#define WORDLENMAX 32 |
| 15 | 15 |
#define MACROMAX 64 |
| 16 |
+#define OFFSET 0x0200 |
|
| 16 | 17 |
|
| 17 | 18 |
typedef unsigned char Uint8; |
| 18 | 19 |
typedef signed char Sint8; |
| ... | ... |
@@ -26,14 +27,8 @@ typedef struct {
|
| 26 | 27 |
|
| 27 | 28 |
typedef struct {
|
| 28 | 29 |
char name[WORDLENMAX]; |
| 29 |
- unsigned int size; |
|
| 30 |
-} Map; |
|
| 31 |
- |
|
| 32 |
-typedef struct {
|
|
| 33 |
- char name[WORDLENMAX]; |
|
| 34 |
- Uint8 refs, maps; |
|
| 35 |
- Uint16 addr, len; |
|
| 36 |
- Map map[16]; |
|
| 30 |
+ Uint8 refs; |
|
| 31 |
+ Uint16 addr; |
|
| 37 | 32 |
} Label; |
| 38 | 33 |
|
| 39 | 34 |
typedef struct {
|
| ... | ... |
@@ -102,35 +97,15 @@ findmacro(char *name) |
| 102 | 97 |
} |
| 103 | 98 |
|
| 104 | 99 |
Label * |
| 105 |
-findlabel(char *s) |
|
| 100 |
+findlabel(char *name) |
|
| 106 | 101 |
{
|
| 107 |
- int i, rng = scin(s, '.'); |
|
| 108 |
- char name[64]; |
|
| 109 |
- scpy(s, name, rng > 0 ? rng + 1 : 64); |
|
| 102 |
+ int i; |
|
| 110 | 103 |
for(i = 0; i < p.llen; ++i) |
| 111 | 104 |
if(scmp(p.labels[i].name, name, 64)) |
| 112 | 105 |
return &p.labels[i]; |
| 113 | 106 |
return NULL; |
| 114 | 107 |
} |
| 115 | 108 |
|
| 116 |
-Uint16 |
|
| 117 |
-findlabeladdr(char *s) |
|
| 118 |
-{
|
|
| 119 |
- int i, o = 0; |
|
| 120 |
- char *param; |
|
| 121 |
- Label *l = findlabel(s); |
|
| 122 |
- if(scin(s, '.') < 1) |
|
| 123 |
- return l->addr; |
|
| 124 |
- param = s + scin(s, '.') + 1; |
|
| 125 |
- for(i = 0; i < l->maps; ++i) {
|
|
| 126 |
- if(scmp(l->map[i].name, param, 64)) |
|
| 127 |
- return l->addr + o; |
|
| 128 |
- o += l->map[i].size; |
|
| 129 |
- } |
|
| 130 |
- printf("!!! Warning %s.%s\n", l->name, param);
|
|
| 131 |
- return 0; |
|
| 132 |
-} |
|
| 133 |
- |
|
| 134 | 109 |
Uint8 |
| 135 | 110 |
findopcode(char *s) |
| 136 | 111 |
{
|
| ... | ... |
@@ -194,7 +169,7 @@ makemacro(char *name, FILE *f) |
| 194 | 169 |
return error("Word too long", name);
|
| 195 | 170 |
scpy(word, m->items[m->len++], 64); |
| 196 | 171 |
} |
| 197 |
- printf("New macro: %s(%d items)\n", m->name, m->len);
|
|
| 172 |
+ printf("New macro: %s, %d items\n", m->name, m->len);
|
|
| 198 | 173 |
return 1; |
| 199 | 174 |
} |
| 200 | 175 |
|
| ... | ... |
@@ -208,13 +183,6 @@ makelabel(char *name, Uint16 addr) |
| 208 | 183 |
return error("Label name is hex number", name);
|
| 209 | 184 |
if(findopcode(name)) |
| 210 | 185 |
return error("Label name is invalid", name);
|
| 211 |
- /* set length of last label */ |
|
| 212 |
- if(p.llen) {
|
|
| 213 |
- l = &p.labels[p.llen - 1]; |
|
| 214 |
- l->len = addr - l->addr; |
|
| 215 |
- printf(" Set length of #%d \n", l->len);
|
|
| 216 |
- } |
|
| 217 |
- /* make new label */ |
|
| 218 | 186 |
l = &p.labels[p.llen++]; |
| 219 | 187 |
l->addr = addr; |
| 220 | 188 |
l->refs = 0; |
| ... | ... |
@@ -242,11 +210,9 @@ walktoken(char *w) |
| 242 | 210 |
if(findopcode(w) || scmp(w, "BRK", 4)) |
| 243 | 211 |
return 1; |
| 244 | 212 |
switch(w[0]) {
|
| 245 |
- case '=': return 4 - (findlabel(w + 1) && findlabeladdr(w + 1) < 0x0100); /* POK/STR helper (lit addr(1/2) str) */ |
|
| 246 |
- case '~': return 4 - (findlabel(w + 1) && findlabeladdr(w + 1) < 0x0100); /* PEK/LDR helper (lit addr(1/2) ldr) */ |
|
| 247 |
- case ',': return 3; /* lit2 addr-hb addr-lb */ |
|
| 248 |
- case '.': return 2; /* addr-hb addr-lb */ |
|
| 249 |
- case '^': return 2; /* Relative jump: lit addr-offset */ |
|
| 213 |
+ case ',': return 3; /* lit2 addr-hb addr-lb */ |
|
| 214 |
+ case '.': return 2; /* addr-hb addr-lb */ |
|
| 215 |
+ case '^': return 2; /* Relative jump: lit addr-offset */ |
|
| 250 | 216 |
case '#': return (slen(w + 1) == 4 ? 3 : 2); |
| 251 | 217 |
} |
| 252 | 218 |
if((m = findmacro(w))) {
|
| ... | ... |
@@ -273,33 +239,11 @@ parsetoken(char *w) |
| 273 | 239 |
} |
| 274 | 240 |
pushbyte((Sint8)(l->addr - p.ptr - 3), 1); |
| 275 | 241 |
return ++l->refs; |
| 276 |
- } else if(w[0] == '=' && (l = findlabel(w + 1))) {
|
|
| 277 |
- if(!l->len || l->len > 2) |
|
| 278 |
- return error("Invalid store helper", w);
|
|
| 279 |
- if(findlabeladdr(w + 1) < 0x0100) {
|
|
| 280 |
- pushbyte(findlabeladdr(w + 1), 1); |
|
| 281 |
- pushbyte(findopcode(l->len == 2 ? "STR" : "POK"), 0); |
|
| 282 |
- } else {
|
|
| 283 |
- pushshort(findlabeladdr(w + 1), 1); |
|
| 284 |
- pushbyte(findopcode(l->len == 2 ? "STR2" : "POK2"), 0); |
|
| 285 |
- } |
|
| 286 |
- return ++l->refs; |
|
| 287 |
- } else if(w[0] == '~' && (l = findlabel(w + 1))) {
|
|
| 288 |
- if(!l->len || l->len > 2) |
|
| 289 |
- return error("Invalid load helper", w);
|
|
| 290 |
- if(findlabeladdr(w + 1) < 0x0100) {
|
|
| 291 |
- pushbyte(findlabeladdr(w + 1), 1); |
|
| 292 |
- pushbyte(findopcode(l->len == 2 ? "LDR" : "PEK"), 0); |
|
| 293 |
- } else {
|
|
| 294 |
- pushshort(findlabeladdr(w + 1), 1); |
|
| 295 |
- pushbyte(findopcode(l->len == 2 ? "LDR2" : "PEK2"), 0); |
|
| 296 |
- } |
|
| 297 |
- return ++l->refs; |
|
| 298 | 242 |
} else if(w[0] == '.' && (l = findlabel(w + 1))) {
|
| 299 |
- pushshort(findlabeladdr(w + 1), 0); |
|
| 243 |
+ pushshort(l->addr, 0); |
|
| 300 | 244 |
return ++l->refs; |
| 301 | 245 |
} else if(w[0] == ',' && (l = findlabel(w + 1))) {
|
| 302 |
- pushshort(findlabeladdr(w + 1), 1); |
|
| 246 |
+ pushshort(l->addr, 1); |
|
| 303 | 247 |
return ++l->refs; |
| 304 | 248 |
} else if((op = findopcode(w)) || scmp(w, "BRK", 4)) {
|
| 305 | 249 |
pushbyte(op, 0); |
| ... | ... |
@@ -354,9 +298,6 @@ pass1(FILE *f) |
| 354 | 298 |
if(!makelabel(w + 1, addr)) |
| 355 | 299 |
return error("Pass1 failed", w);
|
| 356 | 300 |
scpy(w + 1, scope, 64); |
| 357 |
- } else if(w[0] == '$') {
|
|
| 358 |
- if(!makelabel(sublabel(subw, scope, w + 1), addr)) |
|
| 359 |
- return error("Pass1 failed", w);
|
|
| 360 | 301 |
} else if(w[0] == '|') {
|
| 361 | 302 |
if(shex(w + 1) < addr) |
| 362 | 303 |
return error("Memory Overwrite", w);
|
| ... | ... |
@@ -375,15 +316,10 @@ pass2(FILE *f) |
| 375 | 316 |
char w[64], scope[64], subw[64]; |
| 376 | 317 |
printf("Pass 2\n");
|
| 377 | 318 |
while(fscanf(f, "%s", w) == 1) {
|
| 378 |
- if(w[0] == '$') continue; |
|
| 379 | 319 |
if(w[0] == '%') continue; |
| 380 | 320 |
if(w[0] == '&') continue; |
| 381 | 321 |
if(skipblock(w, &ccmnt, '(', ')')) continue;
|
| 382 | 322 |
if(skipblock(w, &ctemplate, '{', '}')) continue;
|
| 383 |
- if(w[0] == ';') {
|
|
| 384 |
- p.ptr += findlabel(w + 1)->len; |
|
| 385 |
- continue; |
|
| 386 |
- } |
|
| 387 | 323 |
if(w[0] == '|') {
|
| 388 | 324 |
p.ptr = shex(w + 1); |
| 389 | 325 |
continue; |
| ... | ... |
@@ -392,7 +328,7 @@ pass2(FILE *f) |
| 392 | 328 |
scpy(w + 1, scope, 64); |
| 393 | 329 |
continue; |
| 394 | 330 |
} |
| 395 |
- if(w[1] == '$') |
|
| 331 |
+ if(w[1] == '&') |
|
| 396 | 332 |
scpy(sublabel(subw, scope, w + 2), w + 1, 64); |
| 397 | 333 |
if(skipblock(w, &cbits, '[', ']')) {
|
| 398 | 334 |
if(w[0] == '[' || w[0] == ']') { continue; }
|
| ... | ... |
@@ -412,7 +348,7 @@ void |
| 412 | 348 |
cleanup(char *filename) |
| 413 | 349 |
{
|
| 414 | 350 |
int i; |
| 415 |
- printf("Assembled %s(%0.2fkb), %d labels, %d macros.\n\n", filename, p.ptr / 1000.0, p.llen, p.mlen);
|
|
| 351 |
+ printf("Assembled %s(%0.2fkb), %d labels, %d macros.\n\n", filename, (p.ptr - OFFSET) / 1000.0, p.llen, p.mlen);
|
|
| 416 | 352 |
for(i = 0; i < p.llen; ++i) |
| 417 | 353 |
if(!p.labels[i].refs) |
| 418 | 354 |
printf("--- Unused label: %s\n", p.labels[i].name);
|
| ... | ... |
@@ -431,7 +367,7 @@ main(int argc, char *argv[]) |
| 431 | 367 |
return !error("Open", "Failed");
|
| 432 | 368 |
if(!pass1(f) || !pass2(f)) |
| 433 | 369 |
return !error("Assembly", "Failed");
|
| 434 |
- fwrite(p.data, p.ptr, 1, fopen(argv[2], "wb")); |
|
| 370 |
+ fwrite(p.data + OFFSET, p.ptr - OFFSET, 1, fopen(argv[2], "wb")); |
|
| 435 | 371 |
fclose(f); |
| 436 | 372 |
cleanup(argv[2]); |
| 437 | 373 |
return 0; |
| ... | ... |
@@ -166,7 +166,7 @@ loaduxn(Uxn *u, char *filepath) |
| 166 | 166 |
FILE *f; |
| 167 | 167 |
if(!(f = fopen(filepath, "rb"))) |
| 168 | 168 |
return haltuxn(u, "Missing input rom.", 0); |
| 169 |
- fread(u->ram.dat + LOAD_OFFSET, sizeof(u->ram.dat) - LOAD_OFFSET, 1, f); |
|
| 169 |
+ fread(u->ram.dat + PAGE_PROGRAM, sizeof(u->ram.dat) - PAGE_PROGRAM, 1, f); |
|
| 170 | 170 |
printf("Uxn loaded[%s].\n", filepath);
|
| 171 | 171 |
return 1; |
| 172 | 172 |
} |