bool negative_flag = false;
uint8_t *pc = nullptr;
uint32_t cycle_count = 0;
+ bool exit = false;
};
CpuState global_state;
- struct ReturnException
- {
- };
-
void op_return()
{
- throw ReturnException();
+ global_state.exit = true;
}
void op_add()
global_state.pc = program;
global_state.regs[X0] = param;
global_state.cycle_count = 0;
- try
- {
- while(true)
- {
- uint8_t opcode = *global_state.pc++;
- global_state.cycle_count += cycle_table[opcode];
- dispatch_table[opcode]();
-
-
- }
-
+ global_state.exit = false;
- } catch(ReturnException ex)
+ while(!global_state.exit)
{
- return std::make_pair(global_state.regs[X0], global_state.cycle_count);
+ uint8_t opcode = *global_state.pc++;
+ global_state.cycle_count += cycle_table[opcode];
+ dispatch_table[opcode]();
}
+ return std::make_pair(global_state.regs[X0], global_state.cycle_count);
}
bool negative_flag = false;
uint8_t *pc = nullptr;
uint32_t cycle_count = 0;
+ bool exit = false;
};
- struct ReturnException
- {
- };
-
void op_return(CpuState *state)
{
- throw ReturnException();
+ state->exit = true;
}
void op_add(CpuState *state)
state->pc = program;
state->regs[X0] = param;
state->cycle_count = 0;
- try
+ state->exit = false;
+ while(!state->exit)
{
- while(true)
- {
- uint8_t opcode = *state->pc++;
- state->cycle_count += cycle_table[opcode];
- dispatch_table[opcode](state);
-
+ uint8_t opcode = *state->pc++;
+ state->cycle_count += cycle_table[opcode];
+ dispatch_table[opcode](state);
- }
-
- } catch(ReturnException ex)
- {
- return std::make_pair(state->regs[X0], state->cycle_count);
}
-
+ return std::make_pair(state->regs[X0], state->cycle_count);
}
bool negative_flag = false;
uint8_t *pc = nullptr;
uint32_t cycle_count = 0;
+ bool exit = false;
};
- struct ReturnException
- {
- };
-
void op_return(CpuState *state)
{
state->cycle_count += 1;
- throw ReturnException();
+ state->exit = true;
}
void op_add(CpuState *state)
state->pc = program;
state->regs[X0] = param;
state->cycle_count = 0;
- try
- {
- while(true)
- {
- uint8_t opcode = *state->pc++;
- dispatch_table[opcode](state);
+ state->exit = false;
-
- }
-
-
- } catch(ReturnException ex)
+ while(!state->exit)
{
- return std::make_pair(state->regs[X0], state->cycle_count);
+ uint8_t opcode = *state->pc++;
+ dispatch_table[opcode](state);
}
+ return std::make_pair(state->regs[X0], state->cycle_count);
+
}
bool zero_flag = false;
bool negative_flag = false;
uint32_t cycle_count = 0;
+ bool exit = false;
};
- struct ReturnException
- {
- };
-
uint8_t *op_return(CpuState *state, uint8_t *pc)
{
state->cycle_count += 1;
- throw ReturnException();
+ state->exit = true;
+ return pc;
}
uint8_t *op_add(CpuState *state, uint8_t *pc)
uint8_t *pc = program;
state->regs[X0] = param;
state->cycle_count = 0;
- try
- {
- while(true)
- {
- uint8_t opcode = *pc++;
- pc = dispatch_table[opcode](state, pc);
-
-
- }
-
-
- } catch(ReturnException ex)
+ state->exit = false;
+ while(!state->exit)
{
- return std::make_pair(state->regs[X0], state->cycle_count);
+ uint8_t opcode = *pc++;
+ pc = dispatch_table[opcode](state, pc);
}
+ return std::make_pair(state->regs[X0], state->cycle_count);
+
}
{
int32_t regs[16] = {0};
uint32_t cycle_count = 0;
- };
-
-
- struct ReturnException
- {
+ bool exit = false;
};
ReturnVal op_return(PARAMS)
{
state->cycle_count += 1;
- throw ReturnException();
+ state->exit = true;
+ return RETURN_VAL;
}
ReturnVal op_add(PARAMS)
uint8_t *pc = program;
state->regs[X0] = param;
state->cycle_count = 0;
+ state->exit = false;
Flags flags = {0, 0};
- try
- {
- while(true)
- {
- uint8_t opcode = *pc++;
- ReturnVal ret = dispatch_table[opcode](ARGS);
- pc = ret.pc;
- flags = ret.flags;
- }
-
- } catch(ReturnException ex)
+ while(!state->exit)
{
- return std::make_pair(state->regs[X0], state->cycle_count);
+ uint8_t opcode = *pc++;
+ ReturnVal ret = dispatch_table[opcode](ARGS);
+ pc = ret.pc;
+ flags = ret.flags;
}
+ return std::make_pair(state->regs[X0], state->cycle_count);
+
}
{
int32_t regs[16] = {0};
uint32_t final_cycle_count = 0;
- };
-
-
- struct ReturnException
- {
+ bool exit = false;
};
{
cycle_count += 1;
state->final_cycle_count = cycle_count;
- throw ReturnException();
+ state->exit = true;
+ return RETURN_VAL;
}
ReturnVal op_add(PARAMS)
CpuState *state = &local_state;
uint8_t *pc = program;
state->regs[X0] = param;
+ state->exit = false;
uint32_t cycle_count = 0;
Flags flags = {0, 0};
- try
+ while(!state->exit)
{
- while(true)
- {
- uint8_t opcode = *pc++;
- ReturnVal ret = dispatch_table[opcode](ARGS);
- pc = ret.pc;
- flags = ret.flags;
- cycle_count = ret.cycle_count;
- }
-
-
- } catch(ReturnException ex)
- {
- return std::make_pair(state->regs[X0], state->final_cycle_count);
+ uint8_t opcode = *pc++;
+ ReturnVal ret = dispatch_table[opcode](ARGS);
+ pc = ret.pc;
+ flags = ret.flags;
+ cycle_count = ret.cycle_count;
}
+ return std::make_pair(state->regs[X0], state->final_cycle_count);
+
}