diff --git a/Makefile b/Makefile index 7545a80..a82fecb 100644 --- a/Makefile +++ b/Makefile @@ -24,6 +24,8 @@ else Q = endif +CFLAGS=-O2 + ifeq "${PROFILING}" "1" CFLAGS += -pg LDFLAGS += -pg diff --git a/cpu.c b/cpu.c index 5a26219..e114a61 100644 --- a/cpu.c +++ b/cpu.c @@ -49,11 +49,11 @@ int decode(struct simdata_t *simdata){ case 0x14: case 0x15: switch(opcode){ - case 0x01: case 0x11: simdata->exec_data->COND=NONE; break; - case 0x02: case 0x12: simdata->exec_data->COND=ZERO; break; - case 0x03: case 0x13: simdata->exec_data->COND=NZERO; break; - case 0x04: case 0x14: simdata->exec_data->COND=CARRY; break; - case 0x05: case 0x15: simdata->exec_data->COND=NCARRY; break; + case 0x01: case 0x11: simdata->exec_data->COND=COND_NONE; break; + case 0x02: case 0x12: simdata->exec_data->COND=COND_ZERO; break; + case 0x03: case 0x13: simdata->exec_data->COND=COND_NZERO; break; + case 0x04: case 0x14: simdata->exec_data->COND=COND_CARRY; break; + case 0x05: case 0x15: simdata->exec_data->COND=COND_NCARRY; break; default: return 1; } simdata->exec_data->out_op->OP_ADDR=IMMEDIATE; @@ -262,11 +262,11 @@ int exec(struct simdata_t *simdata){ case CALL: case JUMP: switch(simdata->exec_data->COND){ - case NONE: condition=1; break; - case ZERO: condition=simdata->registers->FLAGS&1; break; - case NZERO: condition=!(simdata->registers->FLAGS&1); break; - case CARRY: condition=simdata->registers->FLAGS&2; break; - case NCARRY: condition=!(simdata->registers->FLAGS&2); break; + case COND_NONE: condition=1; break; + case COND_ZERO: condition=simdata->registers->FLAGS&1; break; + case COND_NZERO: condition=!(simdata->registers->FLAGS&1); break; + case COND_CARRY: condition=simdata->registers->FLAGS&2; break; + case COND_NCARRY: condition=!(simdata->registers->FLAGS&2); break; } if(condition){ if(simdata->exec_data->EXEC_ACTION==CALL){ @@ -314,26 +314,26 @@ int exec(struct simdata_t *simdata){ result = simdata->registers->GPR[simdata->exec_data->in_op1->data]>>1; break; case ALU_FDIV: - *(float*)&result = *(float*)(&simdata->registers->GPR[simdata->exec_data->in_op2->data])/ - *(float*)(&simdata->registers->GPR[simdata->exec_data->in_op1->data]); + result = ieee754_float_to_uint32(uint32_to_ieee754_float(simdata->registers->GPR[simdata->exec_data->in_op2->data])/ + uint32_to_ieee754_float(simdata->registers->GPR[simdata->exec_data->in_op1->data])); break; case ALU_FMUL: - *(float*)&result = *(float*)(&simdata->registers->GPR[simdata->exec_data->in_op1->data])* - *(float*)(&simdata->registers->GPR[simdata->exec_data->in_op2->data]); + result = ieee754_float_to_uint32(uint32_to_ieee754_float(simdata->registers->GPR[simdata->exec_data->in_op1->data])* + uint32_to_ieee754_float(simdata->registers->GPR[simdata->exec_data->in_op2->data])); break; case ALU_FADD: - *(float*)&result = *(float*)(&simdata->registers->GPR[simdata->exec_data->in_op2->data])+ - *(float*)(&simdata->registers->GPR[simdata->exec_data->in_op1->data]); + result = ieee754_float_to_uint32(uint32_to_ieee754_float(simdata->registers->GPR[simdata->exec_data->in_op2->data])+ + uint32_to_ieee754_float(simdata->registers->GPR[simdata->exec_data->in_op1->data])); break; case ALU_FSUB: - *(float*)&result = *(float*)(&simdata->registers->GPR[simdata->exec_data->in_op2->data])- - *(float*)(&simdata->registers->GPR[simdata->exec_data->in_op1->data]); + result = ieee754_float_to_uint32(uint32_to_ieee754_float(simdata->registers->GPR[simdata->exec_data->in_op2->data])- + uint32_to_ieee754_float(simdata->registers->GPR[simdata->exec_data->in_op1->data])); break; case ALU_FSIN: - *(float*)&result = sinf(*(float*)(&simdata->registers->GPR[simdata->exec_data->in_op1->data])); + result = ieee754_float_to_uint32(sinf(uint32_to_ieee754_float(simdata->registers->GPR[simdata->exec_data->in_op1->data]))); break; case ALU_FCOS: - *(float*)&result = cosf(*(float*)(&simdata->registers->GPR[simdata->exec_data->in_op1->data])); + result = ieee754_float_to_uint32(cosf(uint32_to_ieee754_float(simdata->registers->GPR[simdata->exec_data->in_op1->data]))); break; case ALU_DEC: *(uint32_t*)&result = *(uint32_t*)(&simdata->registers->GPR[simdata->exec_data->in_op1->data])-1; @@ -485,7 +485,7 @@ int cpu_simdata_malloc(struct simdata_t *simdata){ simdata->exec_data=malloc_exec_data(); simdata->registers=malloc(sizeof(struct registers_t)); simdata->registers->PC=0x00000000; - simdata->registers->SP&=0x00FFFFFF; //intentionally leave it uninitialised but within the legal range + simdata->registers->SP=0; if((simdata->fetch_data!=NULL)&&(simdata->decode_data!=NULL)&&(simdata->exec_data!=NULL)) return 1; else diff --git a/cpu.h b/cpu.h index e8b2b08..0e398ec 100644 --- a/cpu.h +++ b/cpu.h @@ -55,11 +55,11 @@ struct exec_op_t { }; enum COND_t{ - NONE, - ZERO, - NZERO, - CARRY, - NCARRY + COND_NONE, + COND_ZERO, + COND_NZERO, + COND_CARRY, + COND_NCARRY }; struct exec_data_t { diff --git a/gui.c b/gui.c index 08a14a2..21f0df7 100644 --- a/gui.c +++ b/gui.c @@ -417,7 +417,7 @@ int update_general_memdump(struct simdata_t *simdata){ uint32_t ADDRESS=(simdata->registers->PC-n*usable_height/2)&0x00FFFFFF; uint32_t color_addr; - int have_color; + int have_color=0; for(int h=0;hvfb_height)?vfb_height:vfb_width; int xoff=0,yoff=0; x0*=1.25; diff --git a/simdata.c b/simdata.c index 1af7b73..4d8c2f9 100644 --- a/simdata.c +++ b/simdata.c @@ -85,3 +85,22 @@ void free_simdata(struct simdata_t *p){ free(p->terminal_output); free(p); } + +#if defined ( __STDC_IEC_559__ ) +union U32FLOAT_RETURN{ + float f; + uint32_t u; +}; +float uint32_to_ieee754_float(uint32_t in){ + union U32FLOAT_RETURN ret; + ret.u=in; + return ret.f; +} +uint32_t ieee754_float_to_uint32(float in){ + union U32FLOAT_RETURN ret; + ret.f=in; + return ret.u; +} +#else +#error Your libc/compiler/architecture doesnt support IEEE 457/IEC 559 Please write a software alternative here +#endif diff --git a/simdata.h b/simdata.h index 9fc78b6..0c76494 100644 --- a/simdata.h +++ b/simdata.h @@ -40,6 +40,8 @@ void free_simdata(struct simdata_t *); int add_to_instr_list(struct instr_list_t **addr_of_toadd,uint32_t address); void free_instr_list(struct instr_list_t **addr_of_tofree); int terminal_output(uint32_t c,struct simdata_t *simdata); +float uint32_to_ieee754_float(uint32_t in); +uint32_t ieee754_float_to_uint32(float in); enum GUI_CPU_STATE_t{ GUI_CPU_RUNNING,