static int intern_op (unw_addr_space_t as, unw_accessors_t *a, unw_word_t *addr, unw_dyn_op_t *op, void *arg) { int ret; if ((ret = fetch8 (as, a, addr, &op->tag, arg)) < 0 || (ret = fetch8 (as, a, addr, &op->qp, arg)) < 0 || (ret = fetch16 (as, a, addr, &op->reg, arg)) < 0 || (ret = fetch32 (as, a, addr, &op->when, arg)) < 0 || (ret = fetchw (as, a, addr, &op->val, arg)) < 0) return ret; return 0; }
static inline int intern_string (unw_addr_space_t as, unw_accessors_t *a, unw_word_t addr, char *buf, size_t buf_len, void *arg) { size_t i; int ret; for (i = 0; i < buf_len; ++i) { if ((ret = fetch8 (as, a, &addr, (int8_t *) buf + i, arg)) < 0) return ret; if (buf[i] == '\0') return 0; /* copied full string; return success */ } buf[buf_len - 1] = '\0'; /* ensure string is NUL terminated */ return -UNW_ENOMEM; }
int emulate8080 (int cycles) { int cyclesDone = 0; while (cyclesDone < cycles) { if (e8080.halt) { printf("Halted!\n"); break; } u8 opcode = fetch8(); #ifdef DEBUG printf("[%04x] %s\n", e8080.PC, lut_mnemonic[opcode]); #endif opTbl[opcode].execute (opcode); cyclesDone += opTbl[opcode].cycles; } return cyclesDone; }