/* screen and input */ R_API void bfvm_peek(BfvmCPU *c) { int idx = c->input_idx; ut8 *ptr = bfvm_get_ptr (c); if (idx >= c->input_size) idx = 0; if (ptr) { *ptr = c->input_buf[idx]; c->input_idx = idx+1; } }
/* debug */ R_API int bfvm_step(BfvmCPU *c, int over) { ut8 op2, op = bfvm_op (c); do { T bfvm_trace_op (c, op); switch (op) { case '\0': /* trap */ return 1; case '.': bfvm_get_ptr (c); bfvm_poke (c); break; case ',': bfvm_peek (c); /* TODO read */ break; case '+': bfvm_inc (c); break; case '-': bfvm_dec (c); break; case '>': c->ptr++; break; case '<': c->ptr--; break; case '[': break; case ']': if (bfvm_get (c) != 0) { do { /* control underflow */ if (c->eip < (c->eip-1)) { c->eip = 0; break; } c->eip--; } while (bfvm_op (c)!='['); } break; default: break; } c->eip++; op2 = bfvm_op (c); } while (over && op == op2); return 0; }
R_API ut8 bfvm_get(BfvmCPU *c) { ut8 *ptr = bfvm_get_ptr (c); return ptr? *ptr: 0; }
R_API void bfvm_dec(BfvmCPU *c) { ut8 *mem = bfvm_get_ptr (c); if (mem != NULL) mem[0]--; }
R_API void bfvm_inc(BfvmCPU *c) { ut8 *mem = bfvm_get_ptr (c); if (mem != NULL) mem[0]++; }