CPU: Added another runtime sanity check and made them optional in config.h

This commit is contained in:
(Tim) Efthimis Kritikos 2024-05-04 07:31:09 +01:00
parent 3e86db9600
commit 8e2eed0130
2 changed files with 16 additions and 1 deletions

View File

@ -1 +1 @@
//#define USE_AALIB
#define RUNTIME_CHECKS // uncomment to trade runtime checks for negligible performance improvements

15
cpu.c
View File

@ -3,6 +3,7 @@
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include "config.h"
/* Known errors:
* 1) Exec does the calculations on the first clock cycle, there is a bug where in some cases exec isn't run on the last cycle and because of this the CPU still works.
@ -336,8 +337,18 @@ int delay_values[]={
};
/*
* RETURN CODES:
* 0 : success
* 1 : Normal execute error
* 2 : Internal error
*/
int exec(struct simdata_t *simdata){
free_instr_list(&simdata->cpu_gui_hints->executing_list);
#ifdef RUNTIME_CHECKS
if(simdata->registers->SP&0xFF000000)
return 2;
#endif
if(simdata->exec_data->valid==1){
simdata->fetch_data->exec_done=0;
simdata->decode_data->exec_done=0;
@ -346,7 +357,11 @@ int exec(struct simdata_t *simdata){
if(simdata->exec_data->valid==0)
return 0;
int condition=0;
#ifdef RUNTIME_CHECKS
#define SANITY_CHECK(x) { if(x>0x0F){return 1;} }
#else
#define SANITY_CHECK(x) {}
#endif
switch(simdata->exec_data->EXEC_ACTION){
case CALL:
case JUMP: