void va_emitcode (const char *inst, const char *fmt, va_list ap) { const char *line = format_opcode (inst, fmt, ap); emit_raw (line); dbuf_free (line); }
int main(int argc, char **argv) { BuildCtx ctx_; BuildCtx *ctx = &ctx_; int status, binmode; if (sizeof(void *) != 4*LJ_32+8*LJ_64) { fprintf(stderr,"Error: pointer size mismatch in cross-build.\n"); fprintf(stderr,"Try: make HOST_CC=\"gcc -m32\" CROSS=...\n\n"); return 1; } UNUSED(argc); parseargs(ctx, argv); if ((status = build_code(ctx))) { fprintf(stderr,"Error: DASM error %08x\n", status); return 1; } switch (ctx->mode) { case BUILD_peobj: case BUILD_raw: binmode = 1; break; default: binmode = 0; break; } if (ctx->outname[0] == '-' && ctx->outname[1] == '\0') { ctx->fp = stdout; #if defined(_WIN32) if (binmode) _setmode(_fileno(stdout), _O_BINARY); /* Yuck. */ #endif } else if (!(ctx->fp = fopen(ctx->outname, binmode ? "wb" : "w"))) { fprintf(stderr, "Error: cannot open output file '%s': %s\n", ctx->outname, strerror(errno)); exit(1); } switch (ctx->mode) { case BUILD_elfasm: case BUILD_coffasm: case BUILD_machasm: emit_asm(ctx); emit_asm_debug(ctx); break; case BUILD_peobj: emit_peobj(ctx); break; case BUILD_raw: emit_raw(ctx); break; case BUILD_bcdef: emit_bcdef(ctx); emit_lib(ctx); break; case BUILD_vmdef: emit_vmdef(ctx); emit_lib(ctx); break; case BUILD_ffdef: case BUILD_libdef: case BUILD_recdef: emit_lib(ctx); break; case BUILD_folddef: emit_fold(ctx); break; default: break; } fflush(ctx->fp); if (ferror(ctx->fp)) { fprintf(stderr, "Error: cannot write to output file: %s\n", strerror(errno)); exit(1); } fclose(ctx->fp); return 0; }
int main(int argc, char **argv) { BuildCtx ctx_; BuildCtx *ctx = &ctx_; int status, binmode; UNUSED(argc); parseargs(ctx, argv); if ((status = build_code(ctx))) { fprintf(stderr,"Error: DASM error %08x\n", status); return 1; } switch (ctx->mode) { case BUILD_peobj: case BUILD_raw: binmode = 1; break; default: binmode = 0; break; } if (ctx->outname[0] == '-' && ctx->outname[1] == '\0') { ctx->fp = stdout; #ifdef LUA_USE_WIN if (binmode) _setmode(_fileno(stdout), _O_BINARY); /* Yuck. */ #endif } else if (!(ctx->fp = fopen(ctx->outname, binmode ? "wb" : "w"))) { fprintf(stderr, "Error: cannot open output file '%s': %s\n", ctx->outname, strerror(errno)); exit(1); } switch (ctx->mode) { case BUILD_elfasm: case BUILD_coffasm: case BUILD_machasm: emit_asm(ctx); emit_asm_debug(ctx); break; case BUILD_peobj: emit_peobj(ctx); break; case BUILD_raw: emit_raw(ctx); break; case BUILD_bcdef: emit_bcdef(ctx); emit_lib(ctx); break; case BUILD_vmdef: emit_vmdef(ctx); emit_lib(ctx); break; case BUILD_ffdef: case BUILD_libdef: case BUILD_recdef: emit_lib(ctx); break; case BUILD_folddef: emit_fold(ctx); break; default: break; } fflush(ctx->fp); if (ferror(ctx->fp)) { fprintf(stderr, "Error: cannot write to output file: %s\n", strerror(errno)); exit(1); } fclose(ctx->fp); return 0; }
static bool_t dsk_read_track(struct image *im) { struct tib *tib = tib_p(im); struct image_buf *rd = &im->bufs.read_data; struct image_buf *bc = &im->bufs.read_bc; uint8_t *buf = (uint8_t *)rd->p + 512; /* skip DIB/TIB */ uint16_t *bc_b = bc->p; uint32_t bc_len, bc_mask, bc_space, bc_p, bc_c; uint16_t pr = 0, crc; unsigned int i; if (tib->nr_secs && (rd->prod == rd->cons)) { uint16_t off = 0, len; for (i = 0; i < im->dsk.trk_pos; i++) off += tib->sib[i].actual_length; len = data_sz(&tib->sib[i]); if (len != tib->sib[i].actual_length) { /* Weak sector -- pick different data each revolution. */ off += len * (im->dsk.rev % (tib->sib[i].actual_length / len)); } off += im->dsk.rd_sec_pos * 1024; len -= im->dsk.rd_sec_pos * 1024; if (len > 1024) { len = 1024; im->dsk.rd_sec_pos++; } else { im->dsk.rd_sec_pos = 0; if (++im->dsk.trk_pos >= tib->nr_secs) { im->dsk.trk_pos = 0; im->dsk.rev++; } } F_lseek(&im->fp, im->dsk.trk_off + off); F_read(&im->fp, buf, len, NULL); rd->prod++; } /* Generate some MFM if there is space in the raw-bitcell ring buffer. */ bc_p = bc->prod / 16; /* MFM words */ bc_c = bc->cons / 16; /* MFM words */ bc_len = bc->len / 2; /* MFM words */ bc_mask = bc_len - 1; bc_space = bc_len - (uint16_t)(bc_p - bc_c); #define emit_raw(r) ({ \ uint16_t _r = (r); \ bc_b[bc_p++ & bc_mask] = htobe16(_r & ~(pr << 15)); \ pr = _r; }) #define emit_byte(b) emit_raw(mfmtab[(uint8_t)(b)]) if (im->dsk.decode_pos == 0) { /* Post-index track gap */ if (bc_space < im->dsk.idx_sz) return FALSE; for (i = 0; i < GAP_4A; i++) emit_byte(0x4e); /* IAM */ for (i = 0; i < GAP_SYNC; i++) emit_byte(0x00); for (i = 0; i < 3; i++) emit_raw(0x5224); emit_byte(0xfc); for (i = 0; i < GAP_1; i++) emit_byte(0x4e); } else if (im->dsk.decode_pos == (tib->nr_secs * 4 + 1)) { /* Pre-index track gap */ uint16_t sz = im->dsk.gap4 - im->dsk.decode_data_pos * 1024; if (bc_space < min_t(unsigned int, sz, 1024)) return FALSE; if (sz > 1024) { sz = 1024; im->dsk.decode_data_pos++; im->dsk.decode_pos--; } else { im->dsk.decode_data_pos = 0; im->dsk.decode_pos = -1; } for (i = 0; i < sz; i++) emit_byte(0x4e); } else {
static void do_block (void) { int lazylen = 0, lazypos = 0, lazyraw = 0; int hashv, ph, h; bpos = 0; while (bpos < blkstart) { hashv = hash(blk+bpos); h = hashp[hashv]; ph = -1; while (h != -1) { ph = h; h = linkp[h]; } if (ph != -1) linkp[ph] = bpos; else hashp[hashv] = bpos; linkp[bpos] = -1; bpos++; } while (bpos < blklen && ntuple < MAXTUPLES-1) { if (blklen - bpos < 3) emit_raw (blklen - bpos); else { int len, maxlen, maxlenpos; int savebpos; hashv = hash(blk+bpos); h = hashp[hashv]; maxlen = 0; maxlenpos = ph = -1; while (h != -1) { unsigned char *p = blk+bpos; unsigned char *v = blk+h; len = 0; while (*p == *v && p < blk+blklen) p++, v++, len++; if (maxlen < len) { maxlen = len; maxlenpos = h; } ph = h; h = linkp[h]; } if (ph != -1) linkp[ph] = bpos; else hashp[hashv] = bpos; linkp[bpos] = -1; savebpos = bpos; bpos -= lazyraw; if (lazyraw) { if (maxlen >= lazylen+2) { emit_raw (lazyraw); lazyraw = 1; lazypos = maxlenpos; lazylen = maxlen; } else { emit_pair (lazypos, lazylen); lazyraw = lazypos = lazylen = 0; } } else if (maxlen >= 3) { lazyraw = 1; lazypos = maxlenpos; lazylen = maxlen; } else { emit_raw (1); } bpos += lazyraw; while (++savebpos < bpos) { hashv = hash(blk+savebpos); h = hashp[hashv]; ph = -1; while (h != -1) { ph = h; h = linkp[h]; } if (ph != -1) linkp[ph] = savebpos; else hashp[hashv] = savebpos; linkp[savebpos] = -1; } } } if (lazyraw) { bpos -= lazyraw; emit_raw (lazyraw); } }