# HG changeset patch # User Michael Pavone # Date 1459733821 25200 # Node ID 5a8b5f9fc50a6d6b5fb67c949319cc2caa340474 # Parent c677507682e3bd61d3339840189691a9d73a2f02 Added incbin directive to assembler diff -r c677507682e3 -r 5a8b5f9fc50a src/asm.c --- a/src/asm.c Sun Apr 03 00:33:54 2016 -0700 +++ b/src/asm.c Sun Apr 03 18:37:01 2016 -0700 @@ -395,6 +395,30 @@ return 1; } +uint8_t handle_incbin(char *cur, uint8_t *outbuf, uint16_t *pc) +{ + char * end = strchr(cur, ';'); + if (end) { + *end = 0; + } else { + end = cur + strlen(cur); + } + while (end - cur > 1 && isspace(*(end-1))) + { + end--; + } + *end = 0; + FILE *incfile = fopen(cur, "rb"); + if (!incfile) { + fprintf(stderr, "Failed to open inclued file %s for reading\n", cur); + return 0; + } + size_t read = fread(outbuf + *pc, 1, 48*1024-*pc, incfile); + fclose(incfile); + *pc += read; + return 1; +} + uint8_t assemble_file(FILE *input, FILE *output) { //fixed size buffers are lame, but so are lines longer than 4K characters @@ -476,6 +500,12 @@ } continue; } + if (!strcmp(mnemonic, "incbin")) { + if (!handle_incbin(cur, outbuf, &pc)) { + goto error; + } + continue; + } //automatically align to word boundary if (pc & 1) { outbuf[pc] = 0;