New name. Minor corrections. Includes PONG.

This commit is contained in:
2017-02-03 18:59:47 +01:00
parent fa4abcbf2c
commit 88c0288931
13 changed files with 222 additions and 35 deletions

9
vm.cpp
View File

@@ -114,7 +114,7 @@ static int vm_cycles = 0;
#define GRAB(x) a = x[x[0]--]; b = x[x[0]--];
bool sleeping = false;
Uint32 time, delay = 0;
static void load_rom() {
FILE *f = fopen("rom.bin", "rb");
@@ -162,7 +162,10 @@ void vm_init(const char* filename) {
inline unsigned short WORD() { vm_pc += 2; return vm_program[vm_pc - 2] + (vm_program[vm_pc - 1] << 8); }
const unsigned short vm_step() {
if (sleeping) return vm_pc;
if (delay > 0) {
if (SDL_GetTicks() - time < delay) return vm_pc;
delay = 0;
}
unsigned char a, b, c;
OPS opcode = (OPS)vm_program[vm_pc++];
@@ -239,7 +242,7 @@ const unsigned short vm_step() {
case OP_GEQ: GRAB(ds); PUSH(ds, b >= a); vm_cycles++; break;
case OP_IN: PUSH(ds, in_ports[vm_program[vm_pc++]]()); vm_cycles++; break;
case OP_OUT: out_ports[vm_program[vm_pc++]](POP(ds)); vm_cycles++; break;
case OP_SLEEP: SDL_Delay(POP(ds) * 1000); vm_cycles++; break;
case OP_SLEEP: delay = POP(ds) * 1000; time = SDL_GetTicks(); vm_cycles++; break;
}
return vm_pc;
}