📄 support.c
字号:
*p; int word; int pc; extern int (*(sfop_table[])) (); extern int (*(bfop_table[])) (); int (*((*table))) (); sim_state_type *context = &the_state; if (step) { context->exception = SIM_SINGLE_STEP; } else { context->exception = 0; } pc = context->sometimes_pc; if (sim_z8001_mode) { table = bfop_table; pc = MAP_PHYSICAL_TO_LOGICAL (pc); } else { table = sfop_table; } do { word = get_word_mem_da (context, pc); p = op_info_table + word;#ifdef LOG log[word]++;#endif pc = table[p->exec] (context, pc, word); context->insts++; } while (!context->exception); context->sometimes_pc = MAP_LOGICAL_TO_PHYSICAL (pc); context->ticks += get_now () - now;}inttm_signal (){ return the_state.exception;}voidtm_info_print (x) sim_state_type *x;{ double timetaken = (double) x->ticks / (double) now_persec (); double virttime = x->cycles / 4.0e6; printf ("instructions executed : %9d\n", x->insts); printf ("cycles counted : %9d \n", x->cycles); printf ("cycles / inst : %9.1f \n", (double) x->cycles / (double) x->insts); printf ("virtual time taked (at 4 Mhz) : %9.1f \n", virttime); printf ("real time taken : %9.1f \n", timetaken); if (timetaken) { printf ("virtual instructions per second : %9.1f\n", x->insts / timetaken); printf ("emulation speed : %9.1f%%\n", virttime / timetaken * 100.0); }#ifdef LOG { extern int quick[]; for (i = 0; quick[i]; i++) { log[quick[i]] += 100000; } } for (i = 0; i < 64 * 1024; i++) { if (log[i]) { printf (" /*%7d*/ 0x%x,\n", log[i], i); } }#endif}intsim_trace (sd) SIM_DESC sd;{ int i; char buffer[10]; int r; printf ("\n"); for (r = 0; r < 16; r++) { int m; printf ("r%2d", r); printf ("=%04x ", get_word_reg (&the_state, r)); for (m = -4; m < 8; m++) { if (m == 0) printf (">"); printf ("%04x ", get_word_mem_da (&the_state, (0xfffe & get_word_reg (&the_state, r)) + m * 2)); } printf ("\n"); } printf ("\n"); printf ("%9d %9d %08x ", the_state.cycles, the_state.insts, the_state.sometimes_pc); for (i = 0; i < 6; i++) { buffer[i] = get_byte_mem_da (&the_state, the_state.sometimes_pc + i); } print_insn_z8001 (the_state.sometimes_pc, buffer, stdout); printf ("\n"); tm_resume (1); if (the_state.exception != SIM_SINGLE_STEP) return 1; return 0;}voidtm_state (x) sim_state_type *x;{ *x = the_state;}voidtm_exception (x) int x;{ the_state.exception = x;}inttm_read_byte (x) int x;{ x &= 0x3f00ffff; return sim_read_byte (&the_state, x);}voidtm_write_byte (x, y) int x, y;{ x &= 0x3f00ffff; sim_write_byte (&the_state, x, y);}#define SIGN(x) ((x) & MASK)normal_flags_32(context,d,sa,sb,sub)sim_state_type *context;unsigned int d;unsigned int sa;unsigned int sb;unsigned int sub;{#undef MASK#define MASK (1<<31) context->broken_flags = 0; if (sub) PSW_CARRY = sa < sb; else PSW_CARRY = d < sa; if (sub) PSW_OVERFLOW = (SIGN(sa) != SIGN(sb)) && (SIGN(d) == SIGN(sb)); else PSW_OVERFLOW = (SIGN(sa) == SIGN(sb)) && (SIGN(d) != SIGN(sb)); PSW_SIGN = ((int)d) <0; PSW_ZERO = d == 0;}normal_flags_16(context,d,sal,sbl,sub)sim_state_type *context;unsigned int d;unsigned int sal;unsigned int sbl;unsigned short int sub;{ unsigned short sa = sal; unsigned short sb = sbl;#undef MASK#define MASK (1<<15) context->broken_flags = 0; if (sub) PSW_CARRY = sal < sbl; else PSW_CARRY = (d & 0x10000) != 0; if (sub) PSW_OVERFLOW = (SIGN(sa) != SIGN(sb)) && (SIGN(d) == SIGN(sb)); else PSW_OVERFLOW = (SIGN(sa) == SIGN(sb)) && (SIGN(d) != SIGN(sb)); PSW_SIGN = ((short int)d) <0; PSW_ZERO = ((short)d) == 0;}normal_flags_8(context,d,sa,sb,sub)sim_state_type *context;unsigned char d;unsigned char sa;unsigned char sb;unsigned char sub;{#undef MASK#define MASK (1<<7) context->broken_flags = 0; if (sub) PSW_CARRY = sa < sb; else PSW_CARRY = d < sa; if (sub) PSW_OVERFLOW = (SIGN(sa) != SIGN(sb)) && (SIGN(d) == SIGN(sb)); else PSW_OVERFLOW = (SIGN(sa) == SIGN(sb)) && (SIGN(d) != SIGN(sb)); PSW_SIGN = ((char)d) <0; PSW_ZERO = d == 0;}static intis_cond_true (context, c) sim_state_type *context; int c;{ switch (c) { case T: return 1; case F: return 0; /* F */ case LE: return (PSW_ZERO | (PSW_SIGN ^ PSW_OVERFLOW)) & 1; /*LE */ case GT: return (~(PSW_ZERO | (PSW_SIGN ^ PSW_OVERFLOW))) & 1; /*GT */ case 0x5: return (PSW_SIGN & 1); /* sign */ case 0xd: return (~(PSW_SIGN)) & 1; /* not sign */ case 0x3: return ((PSW_CARRY | PSW_ZERO) & 1); /* ule*/ case UGT: return ((~(PSW_CARRY | PSW_ZERO)) & 1); /* ugt */ case 0x4: return (PSW_OVERFLOW & 1);/* overflow */ case 0xc: return (~(PSW_OVERFLOW)) & 1; /* not overflow */ case LT: return (PSW_SIGN ^ PSW_OVERFLOW) & 1; /* LT */ case GE: return (~(PSW_SIGN ^ PSW_OVERFLOW)) & 1; /* GE */ case EQ: return (PSW_ZERO) & 1; /* zero */ case NE: return ((~PSW_ZERO) & 1); /* not zero */ case 0x7: return (PSW_CARRY) & 1; /* carry */ case 0xf: return (~PSW_CARRY) & 1; /* not carry */ default: abort (); }}intCOND (context, c) sim_state_type *context; int c;{ if (c == 8) return 1; /* We can calculate what the flags would have been by looking at the src and dst and size of the operation */ if (context->broken_flags) { int slow = 0; int size; int dst; int srca; int srcb; int mask; int ans; /* see if we can short-cut the nasty flag calcs */ switch (size = context->size) { default: abort(); return 0; case 8: srca = (char) (context->srca); srcb = (char) (context->srcb); dst = (char) (context->dst); mask = 0xff; break; case 16: srca = (short) (context->srca); srcb = (short) (context->srcb); dst = (short) (context->dst); mask = 0xffff; break; case 32: srca = (long) (context->srca); srcb = (long) (context->srcb); dst = (long) (context->dst); mask = 0xffffffff; break; } switch (c) { case T: return 1; case F: return 0; case EQ: return !dst; case NE: return dst; case GT: ans = ((dst)) > 0; if (slow) { if (is_cond_true (context, c) != ans) abort (); } return ans; case LE: ans = ((dst)) <= 0; if (slow) { if (is_cond_true (context, c) != ans) abort (); } return ans; case GE: ans = ((dst)) >= 0; if (slow) { if (is_cond_true (context, c) != ans) abort (); } return ans; case LT: ans = ((dst)) < 0; if (slow) { if (is_cond_true (context, c) != ans) abort (); } return ans; default: break; } /* Can't fake it, we'll have to work out the flags the hard way */ makeflags (context, mask); } /* don't know how to fake a test, inspect the flags the hard way */ return is_cond_true (context, c);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -