X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdsp.cpp;h=294b73e8ee73ed376a5bab4fa66728a58f291cf9;hb=4fc7c64eac42b571ee64ec693e6da1d5a458344f;hp=99cc887c7ffd02de4c5fb44db457d3d723bbd586;hpb=aaa37222bec76a065e74830b363e8c9dfa4709ae;p=virtualjaguar diff --git a/src/dsp.cpp b/src/dsp.cpp index 99cc887..294b73e 100644 --- a/src/dsp.cpp +++ b/src/dsp.cpp @@ -1,15 +1,12 @@ -////////////////////////////////////////////////////////////////////////////// // -////////////////////////////////////////////////////////////////////////////// +// DSP core // +// by cal2 +// GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (BeOS) +// Cleanups by James L. Hammons // -// -// -// -// -////////////////////////////////////////////////////////////////////////////// -#include "include/dsp.h" +#include "dsp.h" #define CINT0FLAG 0x00200 #define CINT1FLAG 0x00400 @@ -155,7 +152,6 @@ char *dsp_opcode_str[64]= static uint16 *mirror_table; static uint8 *dsp_ram_8; - static uint32 dsp_pc; static uint32 dsp_acc; static uint32 dsp_remain; @@ -200,52 +196,23 @@ uint32 dsp_convert_zero[32] = { 32,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18, uint8 *dsp_branch_condition_table=0; #define branch_condition(x) dsp_branch_condition_table[(x) + ((jaguar_flags & 7) << 5)] -static uint32 dsp_in_exec=0; -static uint32 dsp_releaseTimeSlice_flag=0; +static uint32 dsp_in_exec = 0; +static uint32 dsp_releaseTimeSlice_flag = 0; + +FILE * dsp_fp; -FILE *dsp_fp; -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// void dsp_reset_stats(void) { - for (uint32 i=0;i<64;i++) - dsp_opcode_use[i]=0; + for (uint32 i=0; i<64; i++) + dsp_opcode_use[i] = 0; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// void dsp_releaseTimeslice(void) { - dsp_releaseTimeSlice_flag=1; + dsp_releaseTimeSlice_flag = 1; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// void dsp_build_branch_condition_table(void) { int i,j; @@ -291,16 +258,7 @@ void dsp_build_branch_condition_table(void) } } } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + unsigned dsp_byte_read(unsigned int offset) { // battlemorph @@ -333,16 +291,7 @@ unsigned dsp_byte_read(unsigned int offset) } return(jaguar_byte_read(offset)); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + unsigned dsp_word_read(unsigned int offset) { offset&=0xFFFFFFFE; @@ -408,16 +357,7 @@ unsigned dsp_word_read(unsigned int offset) } return(jaguar_word_read(offset)); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + unsigned dsp_long_read(unsigned int offset) { offset&=0xFFFFFFFC; @@ -459,16 +399,7 @@ unsigned dsp_long_read(unsigned int offset) data|=jaguar_word_read(offset+2); return(data); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void dsp_byte_write(unsigned offset, unsigned data) { if ((offset >= dsp_work_ram_base) && (offset < dsp_work_ram_base+0x2000)) @@ -502,16 +433,7 @@ void dsp_byte_write(unsigned offset, unsigned data) // fprintf(log_get(),"dsp: writing %.2x at 0x%.8x\n",data,offset); jaguar_byte_write(offset, data); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void dsp_word_write(unsigned offset, unsigned data) { offset &= 0xFFFFFFFE; @@ -552,16 +474,7 @@ void dsp_word_write(unsigned offset, unsigned data) } jaguar_word_write(offset, data); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void dsp_long_write(unsigned offset, unsigned data) { offset &= 0xFFFFFFFC; @@ -663,16 +576,7 @@ void dsp_long_write(unsigned offset, unsigned data) jaguar_word_write(offset, (data>>16) & 0xFFFF); jaguar_word_write(offset+2, data & 0xFFFF); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + uint8 * jaguar_rom_load(char * path, uint32 * romSize); void dsp_load_bin_at(char * path, uint32 offset) { @@ -683,16 +587,7 @@ void dsp_load_bin_at(char * path, uint32 offset) for(uint32 i=0; i= dsp_work_ram_base) && (Rm < (dsp_work_ram_base+0x2000))) @@ -2093,16 +1679,7 @@ static void dsp_opcode_storeb(void) else jaguar_byte_write(Rm,Rn); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_storew(void) { if ((Rm >= dsp_work_ram_base) && (Rm < (dsp_work_ram_base+0x2000))) @@ -2110,30 +1687,12 @@ static void dsp_opcode_storew(void) else jaguar_word_write(Rm,Rn); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_store(void) { dsp_long_write(Rm,Rn); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_loadb(void) { if ((Rm >= dsp_work_ram_base) && (Rm < (dsp_work_ram_base+0x2000))) @@ -2141,16 +1700,7 @@ static void dsp_opcode_loadb(void) else Rn=jaguar_byte_read(Rm); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_loadw(void) { if ((Rm >= dsp_work_ram_base) && (Rm < (dsp_work_ram_base+0x2000))) @@ -2158,175 +1708,67 @@ static void dsp_opcode_loadw(void) else Rn=jaguar_word_read(Rm); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_load(void) { Rn = dsp_long_read(Rm); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_load_r14_indexed(void) { Rn = dsp_long_read( dsp_reg[14] + (dsp_convert_zero[imm_1] << 2)); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_load_r15_indexed(void) { Rn = dsp_long_read( dsp_reg[15] + (dsp_convert_zero[imm_1] << 2)); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_movei(void) { Rn = ((uint32)dsp_word_read(dsp_pc)) + (((uint32)dsp_word_read(dsp_pc+2))<<16); dsp_pc+=4; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_moveta(void) { alternate_Rn = Rm; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_movefa(void) { Rn = alternate_Rm; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_move(void) { Rn = Rm; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_moveq(void) { Rn = imm_1; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_resmac(void) { Rn = dsp_acc; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_imult(void) { uint32 res=Rn=((int16)Rn)*((int16)Rm); set_flag_z(res); set_flag_n(res); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_mult(void) { uint32 res=Rn = ((uint16)Rm) * ((uint16)Rn); set_flag_z(res); set_flag_n(res); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_bclr(void) { uint32 _Rm=imm_1; @@ -2382,16 +1824,7 @@ static void dsp_opcode_bclr(void) #endif Rn=res; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_btst(void) { uint32 _Rm=imm_1; @@ -2435,16 +1868,7 @@ static void dsp_opcode_btst(void) }; #endif } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_bset(void) { uint32 _Rm=imm_1; @@ -2499,59 +1923,23 @@ static void dsp_opcode_bset(void) #endif Rn=res; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_subqt(void) { Rn -= dsp_convert_zero[imm_1]; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_addqt(void) { Rn += dsp_convert_zero[imm_1]; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_imacn(void) { uint32 res=((int16)Rm) * ((int16)(Rn)); dsp_acc += res; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_mtoi(void) { uint32 _Rm=Rm; @@ -2559,16 +1947,7 @@ static void dsp_opcode_mtoi(void) set_flag_z(res); set_flag_n(res); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_normi(void) { uint32 _Rm = Rm; @@ -2591,16 +1970,7 @@ static void dsp_opcode_normi(void) set_flag_z(res); set_flag_n(res); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_mmult(void) { int count = dsp_matrix_control&0x0f; @@ -2641,16 +2011,7 @@ static void dsp_opcode_mmult(void) set_flag_z(res); set_flag_n(res); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_abs(void) { uint32 _Rn=Rn; @@ -2668,16 +2029,7 @@ static void dsp_opcode_abs(void) set_flag_z(res); } } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_div(void) { uint32 _Rm=Rm; @@ -2703,16 +2055,7 @@ static void dsp_opcode_div(void) else Rn=0xffffffff; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_imultn(void) { uint32 res=(int32)(((int16)Rn)*((int16)Rm)); @@ -2720,16 +2063,7 @@ static void dsp_opcode_imultn(void) set_flag_z(res); set_flag_n(res); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_neg(void) { uint32 _Rn=Rn; @@ -2785,16 +2119,7 @@ static void dsp_opcode_neg(void) #endif Rn=res; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_shlq(void) { uint32 shift=(32-dsp_convert_zero[imm_1]); @@ -2855,16 +2180,7 @@ static void dsp_opcode_shlq(void) #endif Rn=res; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_shrq(void) { uint32 shift=dsp_convert_zero[imm_1]; @@ -2926,16 +2242,7 @@ static void dsp_opcode_shrq(void) #endif Rn=res; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_ror(void) { uint32 shift=Rm; @@ -2996,16 +2303,7 @@ static void dsp_opcode_ror(void) #endif Rn=res; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_rorq(void) { uint32 shift=dsp_convert_zero[imm_1&0x1f]; @@ -3066,16 +2364,7 @@ static void dsp_opcode_rorq(void) #endif Rn=res; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_sha(void) { int32 sRm=(int32)Rm; @@ -3107,16 +2396,7 @@ static void dsp_opcode_sha(void) set_flag_z(_Rn); set_flag_n(_Rn); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_sharq(void) { uint32 shift=dsp_convert_zero[imm_1]; @@ -3132,16 +2412,7 @@ static void dsp_opcode_sharq(void) set_flag_z(_Rn); set_flag_n(_Rn); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_sh(void) { int32 sRm=(int32)Rm;