|
3 | 3 | /* This is the main file */ |
4 | 4 |
|
5 | 5 | unsigned long long FILELINE = 0; |
| 6 | +uint16_t N_START = 0xFFFF; |
6 | 7 |
|
7 | 8 | /* Let's get ready to party */ |
8 | 9 | int main(int argc, char **argv) |
@@ -306,6 +307,22 @@ int main(int argc, char **argv) |
306 | 307 | addinst(outbuf, NOP, address, &bits, &bytes); |
307 | 308 |
|
308 | 309 | } |
| 310 | + /* Find where the N_ section starts */ |
| 311 | + else if(!strncmp(tokens, "NSTART", 7)) |
| 312 | + { |
| 313 | + tokens = strtok(NULL, delims); |
| 314 | + /* Check firstly that there is a valid label or address after the instruction. */ |
| 315 | + if(tokens == NULL || tokens[0] == '\n' || tokens[0] == '\r' || tokens[0] == '\0' || tokens[0] == ' ') |
| 316 | + { |
| 317 | + fprintf(stderr, "Line %llu: A memory address must succeed a DSEC instruction.\n", FILELINE); |
| 318 | + exit(34); |
| 319 | + } |
| 320 | + /* Get the address location. */ |
| 321 | + /* If it's just a number after the instruction, that will be returned with the base address added to it. */ |
| 322 | + /* If it's a yet undeclared label, 65535 (UNKNOWNADDR) is returned. The instruction will be modified when the label is declared. */ |
| 323 | + /* If it's an already declared label return the address relative to the base address. */ |
| 324 | + N_START = findlabel(&unknownlabels, &labels, tokens, numlabels, &numunknownlabels, bits, INST); |
| 325 | + } |
309 | 326 | /* Each group of same size data sections should be recorded with the pair DNUM DSIZE */ |
310 | 327 | else if(!strncmp(tokens, "DNUM", 5)) |
311 | 328 | { |
@@ -357,9 +374,22 @@ int main(int argc, char **argv) |
357 | 374 | doneline = 1; |
358 | 375 | /* Just in case someone forgot EPINF... */ |
359 | 376 | inpinf = 0; |
360 | | - /* Add it to the buffer. */ |
| 377 | + /* Prevent the address of EINF from getting written over... */ |
| 378 | + if(unknownlabels != NULL) |
| 379 | + { |
| 380 | + for(i = 0; i < numunknownlabels; i++) |
| 381 | + { |
| 382 | + if((unknownlabels[i].str != NULL) && (!strcmp(unknownlabels[i].str, "N_")) && (unknownlabels[i].addr == (bits/4))) |
| 383 | + { |
| 384 | + char *emptystr = calloc(1, 2); |
| 385 | + memcpy(emptystr, "", 2); |
| 386 | + unknownlabels[i].str = emptystr; |
| 387 | + unknownlabels[i].addr = 0xFFFF; |
| 388 | + } |
| 389 | + } |
| 390 | + } |
| 391 | + /* Add to output buffer. */ |
361 | 392 | addinst(outbuf, NOP, 0xFFFF, &bits, &bytes); |
362 | | - |
363 | 393 | } |
364 | 394 | /* Nand instruction. */ |
365 | 395 | else if(!strncmp(tokens, "NND", 4)) |
@@ -593,7 +623,8 @@ int main(int argc, char **argv) |
593 | 623 | if(labels[j].str != NULL) |
594 | 624 | { |
595 | 625 | /* If we find it, set found to true. */ |
596 | | - if(!strcmp(labels[j].str, unknownlabels[i].str)) |
| 626 | + /* if both str is "" and addr is 0xFFFF, this was an unknown label we were meant to ignore. */ |
| 627 | + if(!strcmp(labels[j].str, unknownlabels[i].str) || (!strcmp("", unknownlabels[i].str) && (unknownlabels[i].addr == 0xFFFF))) |
597 | 628 | { |
598 | 629 | foundunknown = 1; |
599 | 630 | } |
|
0 commit comments