Mercurial > repos > simple16
comparison src/asm.c @ 29:5a8b5f9fc50a
Added incbin directive to assembler
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 03 Apr 2016 18:37:01 -0700 |
parents | fb14515266f4 |
children | 718aaedc4582 |
comparison
equal
deleted
inserted
replaced
28:c677507682e3 | 29:5a8b5f9fc50a |
---|---|
390 } | 390 } |
391 diff &= 0x1FE; | 391 diff &= 0x1FE; |
392 uint16_t inst = BCC | diff << 3 | intcc << 12; | 392 uint16_t inst = BCC | diff << 3 | intcc << 12; |
393 outbuf[pc] = inst >> 8; | 393 outbuf[pc] = inst >> 8; |
394 outbuf[pc+1] = inst; | 394 outbuf[pc+1] = inst; |
395 return 1; | |
396 } | |
397 | |
398 uint8_t handle_incbin(char *cur, uint8_t *outbuf, uint16_t *pc) | |
399 { | |
400 char * end = strchr(cur, ';'); | |
401 if (end) { | |
402 *end = 0; | |
403 } else { | |
404 end = cur + strlen(cur); | |
405 } | |
406 while (end - cur > 1 && isspace(*(end-1))) | |
407 { | |
408 end--; | |
409 } | |
410 *end = 0; | |
411 FILE *incfile = fopen(cur, "rb"); | |
412 if (!incfile) { | |
413 fprintf(stderr, "Failed to open inclued file %s for reading\n", cur); | |
414 return 0; | |
415 } | |
416 size_t read = fread(outbuf + *pc, 1, 48*1024-*pc, incfile); | |
417 fclose(incfile); | |
418 *pc += read; | |
395 return 1; | 419 return 1; |
396 } | 420 } |
397 | 421 |
398 uint8_t assemble_file(FILE *input, FILE *output) | 422 uint8_t assemble_file(FILE *input, FILE *output) |
399 { | 423 { |
474 if (!handle_dc(mnemonic[3], cur, outbuf, &pc, &labels)) { | 498 if (!handle_dc(mnemonic[3], cur, outbuf, &pc, &labels)) { |
475 goto error; | 499 goto error; |
476 } | 500 } |
477 continue; | 501 continue; |
478 } | 502 } |
503 if (!strcmp(mnemonic, "incbin")) { | |
504 if (!handle_incbin(cur, outbuf, &pc)) { | |
505 goto error; | |
506 } | |
507 continue; | |
508 } | |
479 //automatically align to word boundary | 509 //automatically align to word boundary |
480 if (pc & 1) { | 510 if (pc & 1) { |
481 outbuf[pc] = 0; | 511 outbuf[pc] = 0; |
482 pc++; | 512 pc++; |
483 } | 513 } |