From: Shamus Hammons Date: Fri, 22 Aug 2003 19:43:46 +0000 (+0000) Subject: Changes for the upcoming 1.0.5 release X-Git-Tag: 1.0.5~19 X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=67a5f1a40072983cf87ae2093ca95c271d14e706;p=virtualjaguar Changes for the upcoming 1.0.5 release --- diff --git a/src/blitter.cpp b/src/blitter.cpp index 90a0b3a..432b53c 100644 --- a/src/blitter.cpp +++ b/src/blitter.cpp @@ -8,7 +8,6 @@ bool specialLog = false; #include "jaguar.h" -#include "blitter2.h" // Testing purposes only! #define REG(A) (((uint32)blitter_ram[(A)] << 24) | ((uint32)blitter_ram[(A)+1] << 16) \ | ((uint32)blitter_ram[(A)+2] << 8) | (uint32)blitter_ram[(A)+3]) @@ -104,32 +103,39 @@ bool specialLog = false; #define YADD1_A1 (REG(A1_FLAGS)&0x040000) #define YADD1_A2 (REG(A2_FLAGS)&0x040000) +//Put 'em back, once we fix the problem!!! [KO] // 1 bpp pixel read #define PIXEL_SHIFT_1(a) (((~a##_x) >> 16) & 7) #define PIXEL_OFFSET_1(a) (((((UINT32)a##_y >> 16) * a##_width / 8) + (((UINT32)a##_x >> 19) & ~7)) * (1 + a##_pitch) + (((UINT32)a##_x >> 19) & 7)) -#define READ_PIXEL_1(a) ((jaguar_byte_read(a##_addr+PIXEL_OFFSET_1(a)) >> PIXEL_SHIFT_1(a)) & 0x01) +#define READ_PIXEL_1(a) ((JaguarReadByte(a##_addr+PIXEL_OFFSET_1(a), BLITTER) >> PIXEL_SHIFT_1(a)) & 0x01) +//#define READ_PIXEL_1(a) ((JaguarReadByte(a##_addr+PIXEL_OFFSET_1(a)) >> PIXEL_SHIFT_1(a)) & 0x01) // 2 bpp pixel read #define PIXEL_SHIFT_2(a) (((~a##_x) >> 15) & 6) #define PIXEL_OFFSET_2(a) (((((UINT32)a##_y >> 16) * a##_width / 4) + (((UINT32)a##_x >> 18) & ~7)) * (1 + a##_pitch) + (((UINT32)a##_x >> 18) & 7)) -#define READ_PIXEL_2(a) ((jaguar_byte_read(a##_addr+PIXEL_OFFSET_2(a)) >> PIXEL_SHIFT_2(a)) & 0x03) +#define READ_PIXEL_2(a) ((JaguarReadByte(a##_addr+PIXEL_OFFSET_2(a), BLITTER) >> PIXEL_SHIFT_2(a)) & 0x03) +//#define READ_PIXEL_2(a) ((JaguarReadByte(a##_addr+PIXEL_OFFSET_2(a)) >> PIXEL_SHIFT_2(a)) & 0x03) // 4 bpp pixel read #define PIXEL_SHIFT_4(a) (((~a##_x) >> 14) & 4) #define PIXEL_OFFSET_4(a) (((((UINT32)a##_y >> 16) * (a##_width/2)) + (((UINT32)a##_x >> 17) & ~7)) * (1 + a##_pitch) + (((UINT32)a##_x >> 17) & 7)) -#define READ_PIXEL_4(a) ((jaguar_byte_read(a##_addr+PIXEL_OFFSET_4(a)) >> PIXEL_SHIFT_4(a)) & 0x0f) +#define READ_PIXEL_4(a) ((JaguarReadByte(a##_addr+PIXEL_OFFSET_4(a), BLITTER) >> PIXEL_SHIFT_4(a)) & 0x0f) +//#define READ_PIXEL_4(a) ((JaguarReadByte(a##_addr+PIXEL_OFFSET_4(a)) >> PIXEL_SHIFT_4(a)) & 0x0f) // 8 bpp pixel read #define PIXEL_OFFSET_8(a) (((((UINT32)a##_y >> 16) * a##_width) + (((UINT32)a##_x >> 16) & ~7)) * (1 + a##_pitch) + (((UINT32)a##_x >> 16) & 7)) -#define READ_PIXEL_8(a) (jaguar_byte_read(a##_addr+PIXEL_OFFSET_8(a))) +#define READ_PIXEL_8(a) (JaguarReadByte(a##_addr+PIXEL_OFFSET_8(a), BLITTER)) +//#define READ_PIXEL_8(a) (JaguarReadByte(a##_addr+PIXEL_OFFSET_8(a))) // 16 bpp pixel read #define PIXEL_OFFSET_16(a) (((((UINT32)a##_y >> 16) * a##_width) + (((UINT32)a##_x >> 16) & ~3)) * (1 + a##_pitch) + (((UINT32)a##_x >> 16) & 3)) -#define READ_PIXEL_16(a) (jaguar_word_read(a##_addr+(PIXEL_OFFSET_16(a)<<1))) +#define READ_PIXEL_16(a) (JaguarReadWord(a##_addr+(PIXEL_OFFSET_16(a)<<1), BLITTER)) +//#define READ_PIXEL_16(a) (JaguarReadWord(a##_addr+(PIXEL_OFFSET_16(a)<<1))) // 32 bpp pixel read #define PIXEL_OFFSET_32(a) (((((UINT32)a##_y >> 16) * a##_width) + (((UINT32)a##_x >> 16) & ~1)) * (1 + a##_pitch) + (((UINT32)a##_x >> 16) & 1)) -#define READ_PIXEL_32(a) (jaguar_long_read(a##_addr+(PIXEL_OFFSET_32(a)<<2))) +#define READ_PIXEL_32(a) (JaguarReadLong(a##_addr+(PIXEL_OFFSET_32(a)<<2), BLITTER)) +//#define READ_PIXEL_32(a) (JaguarReadLong(a##_addr+(PIXEL_OFFSET_32(a)<<2))) // pixel read #define READ_PIXEL(a,f) (\ @@ -142,14 +148,15 @@ bool specialLog = false; // 16 bpp z data read #define ZDATA_OFFSET_16(a) (PIXEL_OFFSET_16(a) + a##_zoffs * 4) -#define READ_ZDATA_16(a) (jaguar_word_read(a##_addr+(ZDATA_OFFSET_16(a)<<1))) +#define READ_ZDATA_16(a) (JaguarReadWord(a##_addr+(ZDATA_OFFSET_16(a)<<1), BLITTER)) +//#define READ_ZDATA_16(a) (JaguarReadWord(a##_addr+(ZDATA_OFFSET_16(a)<<1))) // z data read #define READ_ZDATA(a,f) (READ_ZDATA_16(a)) // 16 bpp z data write -#define WRITE_ZDATA_16(a,d) { jaguar_word_write(a##_addr+(ZDATA_OFFSET_16(a)<<1),d); } -//#define WRITE_ZDATA_16(a,d) { jaguar_word_write(a##_addr+(ZDATA_OFFSET_16(a)<<1),d); WriteLog("16bpp z write --> "); } +#define WRITE_ZDATA_16(a,d) { JaguarWriteWord(a##_addr+(ZDATA_OFFSET_16(a)<<1), d, BLITTER); } +//#define WRITE_ZDATA_16(a,d) { JaguarWriteWord(a##_addr+(ZDATA_OFFSET_16(a)<<1), d); } // z data write #define WRITE_ZDATA(a,f,d) WRITE_ZDATA_16(a,d); @@ -182,24 +189,29 @@ bool specialLog = false; (((f>>3)&0x07) == 5) ? (READ_RDATA_32(r,a,p)) : 0) // 1 bpp pixel write -#define WRITE_PIXEL_1(a,d) { jaguar_byte_write(a##_addr+PIXEL_OFFSET_1(a),(jaguar_byte_read(a##_addr+PIXEL_OFFSET_1(a))&(~(0x01 << PIXEL_SHIFT_1(a))))|(d< "); } +#define WRITE_PIXEL_32(a,d) { JaguarWriteLong(a##_addr+(PIXEL_OFFSET_32(a)<<2), d, BLITTER); } +//#define WRITE_PIXEL_32(a,d) { JaguarWriteLong(a##_addr+(PIXEL_OFFSET_32(a)<<2), d); } // pixel write #define WRITE_PIXEL(a,f,d) {\ @@ -870,35 +882,35 @@ WriteLog("BLIT: Asked to used invalid bit combo for A2...\n"); // zbuffering if (GOURZ) { - zadd = jaguar_long_read(0xF02274); + zadd = JaguarReadLong(0xF02274, BLITTER); for(int v=0; v<4; v++) - z_i[v] = (int32)jaguar_long_read(0xF0228C + (v << 2)); + z_i[v] = (int32)JaguarReadLong(0xF0228C + (v << 2), BLITTER); } if (GOURD || GOURZ || SRCSHADE) { // gouraud shading - gouraud_add = jaguar_long_read(0xF02270); + gouraud_add = JaguarReadLong(0xF02270, BLITTER); - gd_c[0] = jaguar_byte_read(0xF02268); - gd_i[0] = jaguar_byte_read(0xF02269); + gd_c[0] = JaguarReadByte(0xF02268, BLITTER); + gd_i[0] = JaguarReadByte(0xF02269, BLITTER); gd_i[0] <<= 16; - gd_i[0] |= jaguar_word_read(0xF02240); + gd_i[0] |= JaguarReadWord(0xF02240, BLITTER); - gd_c[1] = jaguar_byte_read(0xF0226A); - gd_i[1] = jaguar_byte_read(0xF0226B); + gd_c[1] = JaguarReadByte(0xF0226A, BLITTER); + gd_i[1] = JaguarReadByte(0xF0226B, BLITTER); gd_i[1] <<= 16; - gd_i[1] |= jaguar_word_read(0xF02242); + gd_i[1] |= JaguarReadWord(0xF02242, BLITTER); - gd_c[2] = jaguar_byte_read(0xF0226C); - gd_i[2] = jaguar_byte_read(0xF0226D); + gd_c[2] = JaguarReadByte(0xF0226C, BLITTER); + gd_i[2] = JaguarReadByte(0xF0226D, BLITTER); gd_i[2] <<= 16; - gd_i[2] |= jaguar_word_read(0xF02244); + gd_i[2] |= JaguarReadWord(0xF02244, BLITTER); - gd_c[3] = jaguar_byte_read(0xF0226E); - gd_i[3] = jaguar_byte_read(0xF0226F); + gd_c[3] = JaguarReadByte(0xF0226E, BLITTER); + gd_i[3] = JaguarReadByte(0xF0226F, BLITTER); gd_i[3] <<= 16; - gd_i[3] |= jaguar_word_read(0xF02246); + gd_i[3] |= JaguarReadWord(0xF02246, BLITTER); gd_ia = gouraud_add & 0xFFFFFF; if (gd_ia & 0x800000) @@ -1090,10 +1102,10 @@ if (blit_start_log) { WriteLog("\nBytes at 004D58:\n"); for(int i=0x004D58; i<0x004D58+(10*127*4); i++) - WriteLog("%02X ", jaguar_byte_read(i)); + WriteLog("%02X ", JaguarReadByte(i)); WriteLog("\nBytes at F03000:\n"); for(int i=0xF03000; i<0xF03000+(6*127*4); i++) - WriteLog("%02X ", jaguar_byte_read(i)); + WriteLog("%02X ", JaguarReadByte(i)); WriteLog("\n\n"); } }//*/ @@ -1101,17 +1113,6 @@ if (blit_start_log) blitter_working = 0; } -uint32 blitter_long_read(uint32 offset) -{ - return (blitter_word_read(offset) << 16) | blitter_word_read(offset+2); -} - -void blitter_long_write(uint32 offset, uint32 data) -{ - blitter_word_write(offset, data >> 16); - blitter_word_write(offset+2, data & 0xFFFF); -} - void blitter_init(void) { blitter_reset(); @@ -1127,7 +1128,28 @@ void blitter_done(void) WriteLog("BLIT: Done.\n"); } -void blitter_byte_write(uint32 offset, uint8 data) +uint8 BlitterReadByte(uint32 offset, uint32 who/*=UNKNOWN*/) +{ + offset &= 0xFF; + + // status register + if (offset == (0x38 + 3)) + return 0x01; // always idle + + return blitter_ram[offset]; +} + +uint16 BlitterReadWord(uint32 offset, uint32 who/*=UNKNOWN*/) +{ + return ((uint16)BlitterReadByte(offset, who) << 8) | (uint16)BlitterReadByte(offset+1, who); +} + +uint32 BlitterReadLong(uint32 offset, uint32 who/*=UNKNOWN*/) +{ + return (BlitterReadWord(offset, who) << 16) | BlitterReadWord(offset+2, who); +} + +void BlitterWriteByte(uint32 offset, uint8 data, uint32 who/*=UNKNOWN*/) { /*if (offset & 0xFF == 0x7B) WriteLog("--> Wrote to B_STOP: value -> %02X\n", data);*/ @@ -1166,10 +1188,10 @@ void blitter_byte_write(uint32 offset, uint8 data) blitter_ram[offset] = data; } -void blitter_word_write(uint32 offset, uint16 data) +void BlitterWriteWord(uint32 offset, uint16 data, uint32 who/*=UNKNOWN*/) { - blitter_byte_write(offset+0, (data>>8) & 0xFF); - blitter_byte_write(offset+1, data & 0xFF); + BlitterWriteByte(offset+0, (data>>8) & 0xFF, who); + BlitterWriteByte(offset+1, data & 0xFF, who); if ((offset & 0xFF) == 0x3A) // I.e., the second write of 32-bit value--not convinced this is the best way to do this! @@ -1181,18 +1203,8 @@ void blitter_word_write(uint32 offset, uint16 data) } //F02278,9,A,B -uint8 blitter_byte_read(uint32 offset) -{ - offset &= 0xFF; - - // status register - if (offset == (0x38 + 3)) - return 0x01; // always idle - - return blitter_ram[offset]; -} - -uint16 blitter_word_read(uint32 offset) +void BlitterWriteLong(uint32 offset, uint32 data, uint32 who/*=UNKNOWN*/) { - return ((uint16)blitter_byte_read(offset) << 8) | (uint16)blitter_byte_read(offset+1); + BlitterWriteWord(offset, data >> 16, who); + BlitterWriteWord(offset+2, data & 0xFFFF, who); } diff --git a/src/blitter2.cpp b/src/blitter2.cpp deleted file mode 100644 index fa60c22..0000000 --- a/src/blitter2.cpp +++ /dev/null @@ -1,696 +0,0 @@ -//#include "stdafx.h" -#include "jaguar.h" -#include "blitter.h" -//#include "mem.h" -//#include "regs.h" - -//extern BYTE* MEM; - -// Stuff from the header file... - -typedef struct { - int srcen; - int srcenz; - int srcenx; - int dsten; - int dstenz; - int dstwrz; - int clip_a1; - int upda1f; - int upda1; - int upda2; - int dsta2; - int gourd; - int zbuff; - int topben; - int topnen; - int patdsel; - int adddsel; - int zmode; - int logic; - int cmpdst; - int bcompen; - int dcompen; - int bkgwren; - int srcshade; -} BLITCMD; - -typedef struct { - DWORD base; - DWORD pitch; - DWORD width; - DWORD depth; - DWORD z_offset; - signed int xadd; - signed int yadd; - WORD clip_x; - WORD clip_y; - unsigned int pixel_x; - unsigned int pixel_y; - signed int step_x; - signed int step_y; - unsigned int fstep_x; - unsigned int fstep_y; - signed int inc_x; - signed int inc_y; - DWORD pixelmode; - DWORD xsign; - DWORD ysign; -} BLIT_A1; - -typedef struct { - DWORD base; - DWORD pitch; - DWORD width; - DWORD depth; - DWORD z_offset; - DWORD mask_enable; - signed int xadd; - signed int yadd; - DWORD mask; - unsigned int pixel_x; - unsigned int pixel_y; - signed int step_x; - signed int step_y; - DWORD pixelmode; - DWORD xsign; - DWORD ysign; -} BLIT_A2; - -const DWORD bitdepth[8] = { 1,2,4,8,16,32,0,0 }; -const DWORD bitsize[8] = { 1,1,1,1,2,4,0,0 }; -const DWORD pitch[4] = { 8, 16, 32, 24 }; -const DWORD pixels_phrase[8] = {64,32,16,8,4,2,1,0}; - -const DWORD width_table[64] = { 1, 1, 1, 1, 2, 2, 3, 3, - 4, 4, 6, 6, 8, 10, 12, 14, - 16, 20, 24, 28, 32, 40, 48, 56, - 64, 80, 96, 112, 128, 160, 192, 224, - 256, 320, 384, 448, 512, 640, 768, 896, - 1024,1280,1536,1792,2048,2560,3072,3584, - 4096,5120,6144,7168,8192,10240,12288,14336, - 16384,20480,24576,28672,32768,40960,49152,57344 }; - -// - -// More stuff from REG.H - -// Blitter Registers - -#define A1_BASE jaguar_long_read(0xF02200) -#define A1_FLAGS jaguar_long_read(0xF02204) -#define A1_CLIP jaguar_long_read(0xF02208) -#define A1_CLIP_X jaguar_word_read(0xF0220A) -#define A1_CLIP_Y jaguar_word_read(0xF02208) -#define A1_PIXEL jaguar_long_read(0xF0220C) -#define A1_PIXEL_Y jaguar_word_read(0xF0220C) -#define A1_PIXEL_X jaguar_word_read(0xF0220E) -#define A1_STEP jaguar_long_read(0xF02210) -#define A1_STEP_Y jaguar_word_read(0xF02210) -#define A1_STEP_X jaguar_word_read(0xF02212) -#define A1_FSTEP jaguar_long_read(0xF02214) -#define A1_FSTEP_Y jaguar_word_read(0xF02214) -#define A1_FSTEP_X jaguar_word_read(0xF02216) -#define A1_FPIXEL jaguar_long_read(0xF02218) -#define A1_FPIXEL_Y jaguar_word_read(0xF02218) -#define A1_FPIXEL_X jaguar_word_read(0xF0221A) -#define A1_INC jaguar_long_read(0xF0221C) -#define A1_INC_Y jaguar_word_read(0xF0221C) -#define A1_INC_X jaguar_word_read(0xF0221E) -#define A1_FINC jaguar_long_read(0xF02220) -#define A1_FINC_Y jaguar_word_read(0xF02220) -#define A1_FINC_X jaguar_word_read(0xF02222) -#define A2_BASE jaguar_long_read(0xF02224) -#define A2_FLAGS jaguar_long_read(0xF02228) -#define A2_MASK jaguar_long_read(0xF0222C) -#define A2_MASK_Y jaguar_word_read(0xF0222C) -#define A2_MASK_X jaguar_word_read(0xF0222E) -#define A2_PIXEL jaguar_long_read(0xF02230) -#define A2_PIXEL_Y jaguar_word_read(0xF02230) -#define A2_PIXEL_X jaguar_word_read(0xF02232) -#define A2_STEP jaguar_long_read(0xF02234) -#define A2_STEP_Y jaguar_word_read(0xF02234) -#define A2_STEP_X jaguar_word_read(0xF02236) -#define B_CMD jaguar_long_read(0xF02238) -#define B_COUNT jaguar_long_read(0xF0223C) -#define B_COUNT_OUT jaguar_word_read(0xF0223C) -#define B_COUNT_IN jaguar_word_read(0xF0223E) -#define B_SRCD *(LONGLONG*)(MEM+0xF02240) -#define B_SRCD0 jaguar_long_read(0xF02240) -#define B_SRCD1 jaguar_long_read(0xF02244) -#define B_DSTD *(LONGLONG*)(MEM+0xF02248) -#define B_DSTD0 jaguar_long_read(0xF02248) -#define B_DSTD1 jaguar_long_read(0xF0224C) -#define B_DSTZ *(LONGLONG*)(MEM+0xF02250) -#define B_DSTZ0 jaguar_long_read(0xF02250) -#define B_DSTZ1 jaguar_long_read(0xF02254) -#define B_SRCZ *(LONGLONG*)(MEM+0xF02258) // Source Z Integer -#define B_SRCZ0 jaguar_long_read(0xF02258) -#define B_SRCZ1 jaguar_long_read(0xF0225C) -#define B_SRCZF *(LONGLONG*)(MEM+0xF02260) // Source Z Fraction -#define B_SRCZF0 jaguar_long_read(0xF02260) -#define B_SRCZF1 jaguar_long_read(0xF02264) -#define B_PATD *(LONGLONG*)(MEM+0xF02268) -#define B_PATD0 jaguar_long_read(0xF02268) -#define B_PATD1 jaguar_long_read(0xF0226C) -#define B_IINC jaguar_long_read(0xF02270) -#define B_IINC_I jaguar_word_read(0xF02270) -#define B_IINC_F jaguar_word_read(0xF02272) -#define B_ZINC jaguar_long_read(0xF02274) -#define B_ZINC_I jaguar_word_read(0xF02274) -#define B_ZINC_F jaguar_word_read(0xF02276) -#define B_STOP jaguar_long_read(0xF02278) -#define B_I3 jaguar_long_read(0xF0227C) -#define B_I3_I jaguar_word_read(0xF0227C) -#define B_I3_F jaguar_word_read(0xF0227E) -#define B_I2 jaguar_long_read(0xF02280) -#define B_I2_I jaguar_word_read(0xF02280) -#define B_I2_F jaguar_word_read(0xF02282) -#define B_I1 jaguar_long_read(0xF02284) -#define B_I1_I jaguar_word_read(0xF02284) -#define B_I1_F jaguar_word_read(0xF02286) -#define B_I0 jaguar_long_read(0xF02288) -#define B_I0_I jaguar_word_read(0xF02288) -#define B_I0_F jaguar_word_read(0xF0228A) -#define B_Z3 jaguar_long_read(0xF0228C) -#define B_Z3_I jaguar_word_read(0xF0228C) -#define B_Z3_F jaguar_word_read(0xF0228E) -#define B_Z2 jaguar_long_read(0xF02290) -#define B_Z2_I jaguar_word_read(0xF02290) -#define B_Z2_F jaguar_word_read(0xF02292) -#define B_Z1 jaguar_long_read(0xF02294) -#define B_Z1_I jaguar_word_read(0xF02294) -#define B_Z1_F jaguar_word_read(0xF02296) -#define B_Z0 jaguar_long_read(0xF02298) -#define B_Z0_I jaguar_word_read(0xF02298) -#define B_Z0_F jaguar_word_read(0xF0229A) - -//#define DWORDBIG(x) ((x>>16)&0xFFFF)|(x<<16) -#define DWORDBIG(x) x - -// - -//const pixels_per_phrase[8] = { 64, 32, 16, 8, 4, 2, 1, 0 }; - -void blitter2_exec(DWORD cmd) -{ - DWORD* src,* dst,* read; - DWORD a1_address, a2_address; - DWORD a1_bm,a2_bm; - DWORD* src_bm,* dst_bm; - BLITCMD bcmd; - BLIT_A1 a1; - BLIT_A2 a2; - memset(&a1,0,sizeof(BLIT_A1)); - memset(&a2,0,sizeof(BLIT_A2)); - memset(&bcmd,0,sizeof(BLITCMD)); - DWORD srcd = 0xF02240; - DWORD dstd = 0xF02248; - DWORD patd = 0xF02268; - - bcmd.srcen = (cmd & 0x1) ? 1 : 0; - bcmd.srcenz = (cmd & 0x2) ? 1 : 0; - bcmd.srcenx = (cmd & 0x4) ? 1 : 0; - bcmd.dsten = (cmd & 0x8) ? 1 : 0; - bcmd.dstenz = (cmd & 0x10) ? 1 : 0; - bcmd.dstwrz = (cmd & 0x20) ? 1 : 0; - bcmd.clip_a1 = (cmd & 0x40) ? 1 : 0; - bcmd.upda1f = (cmd & 0x100) ? 1 : 0; - bcmd.upda1 = (cmd & 0x200) ? 1 : 0; - bcmd.upda2 = (cmd & 0x400) ? 1 : 0; - bcmd.dsta2 = (cmd & 0x800) ? 1 : 0; - bcmd.gourd = (cmd & 0x1000) ? 1 : 0; - bcmd.patdsel = (cmd & 0x10000) ? 1 : 0; - bcmd.cmpdst = (cmd & 0x2000000) ? 1 : 0; - bcmd.bcompen = (cmd & 0x4000000) ? 1 : 0; - bcmd.dcompen = (cmd & 0x8000000) ? 1 : 0; - bcmd.bkgwren = (cmd & 0x10000000) ? 1 : 0; - bcmd.srcshade = (cmd & 0x40000000) ? 1 : 0; - bcmd.logic = (cmd >> 21) & 0xF; - bcmd.zmode = (cmd >> 18) & 0x7; - - DWORD outer_loop = B_COUNT_OUT; - DWORD inner_loop = B_COUNT_IN; - - a1.base = DWORDBIG(A1_BASE); - DWORD flags = DWORDBIG(A1_FLAGS); - a1.pitch = flags & 0x3; - a1.depth = (flags >> 3) & 0x7; - a1.z_offset = ((flags >> 6) & 0x7)*8; - a1.xadd = (short)((flags >> 16) & 0x3); - a1.pixel_x = A1_PIXEL_X << 16 | A1_FPIXEL_X; - a1.pixel_y = A1_PIXEL_Y << 16 | A1_FPIXEL_Y; - a1.step_x = (signed short)A1_STEP_X << 16; - a1.step_y = (signed short)A1_STEP_Y << 16; - a1.fstep_x = A1_FSTEP_X; - a1.fstep_y = A1_FSTEP_Y; - a1.inc_x = A1_INC_X << 16 | A1_FINC_X; - a1.inc_y = A1_INC_Y << 16 | A1_FINC_Y; - a1.clip_x = A1_CLIP_X & 0x7FFF; - a1.clip_y = A1_CLIP_Y & 0x7FFF; - a1.width = width_table[(flags >> 9) & 0x3F]; - - a1.yadd = (short)((flags >> 18) & 0x1); - a1.xsign = (flags >> 19) & 0x1; - a1.ysign = (flags >> 20) & 0x1; - if(a1.ysign) - a1.yadd = -a1.yadd; - a1.pixelmode = (flags >> 16) & 0x3; - - a2.base = DWORDBIG(A2_BASE); - flags = DWORDBIG(A2_FLAGS); - a2.pitch = flags & 0x3; - a2.z_offset = ((flags >> 6) & 0x7)*8; - a2.pixel_x = A2_PIXEL_X; - a2.pixel_y = A2_PIXEL_Y; - a2.step_x = (signed short)A2_STEP_X; - a2.step_y = (signed short)A2_STEP_Y; - a2.mask = DWORDBIG(A2_MASK); - a2.width = width_table[(flags >> 9) & 0x3F]; -// a2.yadd = (flags >> 18) & 0x1; - a2.yadd = a1.yadd; // Buggy blitter !!? YES! It is!!! - a2.pixelmode = (flags >> 16) & 0x3; - a2.xsign = (flags >> 19) & 0x1; - a2.ysign = (flags >> 20) & 0x1; - if(a2.ysign) - a2.yadd = -a2.yadd; - - if(bcmd.dsta2 == 0) { - dst = &a1_address; - src = &a2_address; - read = &a1_address; - dst_bm = &a1_bm; - src_bm = &a2_bm; - } else { - src = &a1_address; - dst = &a2_address; - read = &a2_address; - dst_bm = &a2_bm; - src_bm = &a1_bm; - } - if(!bcmd.srcen) { - src = &srcd; - } - if(bcmd.patdsel) { - src = &patd; - } - if(!bcmd.dsten) { - read = &dstd; - } - - int src_zoffset,dst_zoffset; - if(bcmd.dsta2) { - src_zoffset = a1.z_offset; - dst_zoffset = a2.z_offset; - } else { - src_zoffset = a2.z_offset; - dst_zoffset = a1.z_offset; - } - - unsigned int a1_x = a1.pixel_x; - unsigned int a1_y = a1.pixel_y; - unsigned int a2_x = a2.pixel_x; - unsigned int a2_y = a2.pixel_y; - int a1_size = pitch[a1.pitch]; - int a2_size = pitch[a2.pitch]; - //inner_loop = (inner_loop * bitdepth[a1.depth]) / 8; - - int a1_inc_x,a1_inc_y; - short a2_inc_x; - switch(a1.pixelmode) { - case 0:a1_inc_x = 1<<16; a1_inc_y = a1.yadd<<16; break; - case 1:a1_inc_x = 1<<16; a1_inc_y = a1.yadd<<16; break; - case 2:a1_inc_x = 0; a1_inc_y = a1.yadd<<16; break; - case 3:a1_inc_x = a1.inc_x; a1_inc_y = a1.inc_y; break; - } - if(a1.xsign) - a1_inc_x = -a1_inc_x; - switch(a2.pixelmode) { - case 0:a2_inc_x = 1;break; - case 1:a2_inc_x = 1;break; - case 2:a2_inc_x = 0;break; - case 3:a2_inc_x = 1;break; - } - if(a2.xsign) - a2_inc_x = -a2_inc_x; - - int gd_i[4]; - int gd_c[4]; - int gd_ia,gd_ca; - DWORD gouraud_add,gouraud_data; - WORD gint[4],gfrac[4]; - BYTE gcolour[4]; - gouraud_add = jaguar_long_read(0xF02270); - gcolour[3] = jaguar_byte_read(0xF02268); - gcolour[2] = jaguar_byte_read(0xF0226A); - gcolour[1] = jaguar_byte_read(0xF0226C); - gcolour[0] = jaguar_byte_read(0xF0226E); - gint[3] = jaguar_word_read(0xF0227C); - gint[2] = jaguar_word_read(0xF02280); - gint[1] = jaguar_word_read(0xF02284); - gint[0] = jaguar_word_read(0xF02288); - gfrac[3] = jaguar_word_read(0xF0227E); - gfrac[2] = jaguar_word_read(0xF02282); - gfrac[1] = jaguar_word_read(0xF02286); - gfrac[0] = jaguar_word_read(0xF0228A); - gd_ia = gouraud_add & 0xFFFFFF; - if(gd_ia & 0x800000) - gd_ia = 0xFF000000 | gd_ia; - gd_ca = (gouraud_add>>24) & 0xFF; - if(gd_ca & 0x80) - gd_ca = 0xFFFFFF00 | gd_ca; - for(int v=0;v<4;v++) { - gd_i[v] = gint[v] & 0xFF; - //if(gd_i[v] & 0x80) - // gd_i[v] = 0xFF00 | gd_i[v]; - gd_i[v] = (gd_i[v] << 16) | gfrac[v]; - gd_c[v] = gcolour[v]<<4; - } - int colour_index = 0; - int pi=0; - switch(a1.depth) { - case 0:case 1:case 2:case 3: - for(DWORD j=0; j>16) * a1.width + (a1_x>>16))*bitdepth[a1.depth])/8); - a2_address = a2.base + (((a2_y * a2.width + a2_x)*bitdepth[a1.depth])/8); - src1 = jaguar_byte_read(*src); - dst1 = jaguar_byte_read(*dst); - dst_old = dst1; - //jaguar_long_read(*src+4,&src2); - if(!bcmd.patdsel) { - //jaguar_long_read(*dst+4,&dst2); - switch(bcmd.logic) - { - case 0:dst1 = 0;dst2 = 0;break; - case 1:dst1 = !src1 & !dst1; dst2 = !src2 & !dst2;break; - case 2:dst1 = !src1 & dst1; dst2 = !src2 & dst2;break; - case 3:dst1 = !src1; dst2 = !src2;break; - case 4:dst1 = src1 & !dst1; dst2 = src2 & !dst2;break; - case 5:dst1 = !dst1; dst2 = !dst2;break; - case 6:dst1 = !(src1 ^ dst1); dst2 = !(src2 ^ dst2);break; - case 7:dst1 = !src1 | !dst1; dst2 = !src2 | !dst2;break; - case 8:dst1 = src1 & dst1; dst2 = src2 & dst2;break; - case 9:dst1 = src1 ^ dst1; dst2 = src2 ^ dst2;break; - case 10:dst1 = dst1; dst2 = dst2;break; - case 11:dst1 = !src1 | dst1; dst2 = !src2 | dst2;break; - case 12:dst1 = src1; dst2 = src2;break; - case 13:dst1 = src1 | !dst1; dst2 = src2 | !dst2;break; - case 14:dst1 = src1 | dst1; dst2 = src2 | dst2;break; - case 15:dst1 = 0xFF; dst2 = 0xFF;break; - } - } else { - dst1 = src1; - //dst2 = src2; - } - if(bcmd.dcompen) { - BYTE pattern; - pattern = jaguar_byte_read(0xF02268); - if(!bcmd.cmpdst) { - if(src1 == !dst_old) - dst1 = dst_old; - } else { - if(dst1 == !dst_old) - dst1 = dst_old; - } - } - if(bcmd.clip_a1) { - if((a1_x>>16) < a1.clip_x && (a1_x>>16) >= 0 && (a1_y>>16) < a1.clip_y && (a1_y>>16) >= 0) { - jaguar_byte_write(*dst,dst1); - //jaguar_long_write(*dst+4,dst2); - } - } else { - jaguar_byte_write(*dst,dst1); - //jaguar_long_write(*dst+4,dst2); - } - a1_x += a1_inc_x; - a2_x += a2_inc_x; - a1_y += a1_inc_y; - a2_y += a2.yadd; - for(int v=0;v<4;v++) { - gd_i[v] += gd_ia; - gd_c[v] += gd_ca; - } - } - if(bcmd.upda1) { - a1_x += a1.step_x; - a1_y += a1.step_y; - } - if(bcmd.upda1f) { - a1_x += a1.fstep_x; - a1_y += a1.fstep_y; - } - if(bcmd.upda2) { - a2_x += a2.step_x; - a2_y += a2.step_y; - } - //a1_x = old_a1x; - //a2_x = old_a2x; - } - break; - case 4: - { - int zinc = jaguar_long_read(0xF02274); - INT32 compz[4]; - compz[0] = jaguar_long_read(0xF0228C); - compz[1] = jaguar_long_read(0xF02290); - compz[2] = jaguar_long_read(0xF02294); - compz[3] = jaguar_long_read(0xF02298); - for(DWORD j=0; j>16) * a1.width + ((a1_x>>16)&0xFFFFFFFC))*2*(a1_size/8)) + (((a1_x>>16)&0x3)*2); - a2_address = a2.base + ((a2_y * a2.width + (a2_x&0xFFFFFFFC))*2*(a2_size/8)) + ((a2_x&0x3)*2); - src1 = jaguar_word_read(*src); - dst1 = jaguar_word_read(*dst); - dst_old = dst1; - if(bcmd.srcenz) - srcz = jaguar_word_read(*src+src_zoffset); - else - srcz = compz[pi & 0x3] >> 16; - if(bcmd.dstenz) - dstz = jaguar_word_read(*dst+dst_zoffset); - - //jaguar_long_read(*src+4,&src2); - if(bcmd.patdsel) { -// dst1 = *(WORD*)(&MEM[0xF02268]); - dst1 = jaguar_word_read(0xF02268); - } else { - //jaguar_long_read(*dst+4,&dst2); - switch(bcmd.logic) - { - case 0:dst1 = 0;dst2 = 0;break; - case 1:dst1 = !src1 & !dst1; dst2 = !src2 & !dst2;break; - case 2:dst1 = !src1 & dst1; dst2 = !src2 & dst2;break; - case 3:dst1 = !src1; dst2 = !src2;break; - case 4:dst1 = src1 & !dst1; dst2 = src2 & !dst2;break; - case 5:dst1 = !dst1; dst2 = !dst2;break; - case 6:dst1 = (src1 ^ dst1); dst2 = !(src2 ^ dst2);break; - case 7:dst1 = !src1 | !dst1; dst2 = !src2 | !dst2;break; - case 8:dst1 = src1 & dst1; dst2 = src2 & dst2;break; - case 9:dst1 = src1 ^ dst1; dst2 = src2 ^ dst2;break; - case 10:dst1 = dst1; dst2 = dst2;break; - case 11:dst1 = !src1 | dst1; dst2 = !src2 | dst2;break; - case 12:dst1 = src1; dst2 = src2;break; - case 13:dst1 = src1 | !dst1; dst2 = src2 | !dst2;break; - case 14:dst1 = src1 | dst1; dst2 = src2 | dst2;break; - case 15:dst1 = 0xFFFFFFFF; dst2 = 0xFFFFFFFF;break; - } - } - if(bcmd.gourd) { - DWORD gdt = (gd_i[pi & 0x3] & 0xFFFFFF) | ((gd_c[pi & 0x3]>>4) << 24); - dst1 = gdt >> 16; - } - if(bcmd.srcshade) { - int intensity = src1 & 0xFF; - int ia = gd_ia >> 16; - if(ia & 0x80) - ia = 0xFFFFFF00 | ia; - intensity += ia; - if(intensity < 0) - intensity = 0; - if(intensity > 0xFF) - intensity = 0xFF; - dst1 = (src1 & 0xFF00) | intensity; - } - if(bcmd.dcompen) { - WORD pattern; - pattern = jaguar_word_read(0xF02268); - if(!bcmd.cmpdst) { - if(src1 == pattern)//dst_old) - dst1 = dst_old; - } else { - if(dst1 == pattern) - dst1 = dst_old; - } - } - if(bcmd.zmode > 0) { - bool zc = false; - switch(bcmd.zmode) { - case 1: zc = (srcz < dstz);break; - case 2: zc = (srcz == dstz);break; - case 3: zc = (srcz <= dstz);break; - case 4: zc = (srcz > dstz);break; - case 5: zc = (srcz != dstz);break; - case 6: zc = (srcz >= dstz);break; - } - if(zc == false) { - if(bcmd.clip_a1) { - if((a1_x>>16) < a1.clip_x && (a1_x>>16) >= 0 && (a1_y>>16) < a1.clip_y && (a1_y>>16) >= 0) { - jaguar_word_write(*dst,dst1); - //jaguar_long_write(*dst+4,dst2); - } - } else { - jaguar_word_write(*dst,dst1); - //jaguar_long_write(*dst+4,dst2); - } - } else { - srcz = dstz; - } - } else { - if(bcmd.clip_a1) { - if((a1_x>>16) < a1.clip_x && (a1_x>>16) >= 0 && (a1_y>>16) < a1.clip_y && (a1_y>>16) >= 0) { - jaguar_word_write(*dst,dst1); - //jaguar_long_write(*dst+4,dst2); - } - } else { - jaguar_word_write(*dst,dst1); - //jaguar_long_write(*dst+4,dst2); - } - } - if(bcmd.dstwrz) { - jaguar_word_write(*dst+dst_zoffset,srcz & 0xFFFF); - } - a1_x += a1_inc_x; - a2_x += a2_inc_x; - a1_y += a1_inc_y; - a2_y += a2.yadd; - gd_i[pi & 0x3] += gd_ia; - gd_c[pi & 0x3] += gd_ca; - if(gd_i[pi & 0x3] > 0xFFFFFF) - gd_i[pi & 0x3] = 0xFFFFFF; - if(gd_i[pi & 0x3] < 0) - gd_i[pi & 0x3] = 0; - compz[pi & 0x3] += zinc; - if(compz[pi & 0x3] > 0xFFFFFFFF) - compz[pi & 0x3] = 0xFFFFFFFF; - if(compz[pi & 0x3] < 0) - compz[pi & 0x3] = 0; - if(a1.pixelmode == 0) { - pi++; - } - } - if(bcmd.upda1) { - a1_x += a1.step_x; - a1_y += a1.step_y; - } - if(bcmd.upda1f) { - a1_x += a1.fstep_x; - a1_y += a1.fstep_y; - } - if(bcmd.upda2) { - a2_x += a2.step_x; - a2_y += a2.step_y; - } - } - break; - } - case 5: - for(DWORD j=0; j>16) * a1.width + (a1_x>>16))*bitdepth[a1.depth])/8); - a2_address = a2.base + (((a2_y * a2.width + a2_x)*bitdepth[a1.depth])/8); - src1 = jaguar_long_read(*src); - //jaguar_long_read(*src+4,&src2); - if(!bcmd.patdsel) { - dst1 = jaguar_long_read(*read); - //jaguar_long_read(*dst+4,&dst2); - switch(bcmd.logic) - { - case 0:dst1 = 0;dst2 = 0;break; - case 1:dst1 = !src1 & !dst1; dst2 = !src2 & !dst2;break; - case 2:dst1 = !src1 & dst1; dst2 = !src2 & dst2;break; - case 3:dst1 = !src1; dst2 = !src2;break; - case 4:dst1 = src1 & !dst1; dst2 = src2 & !dst2;break; - case 5:dst1 = !dst1; dst2 = !dst2;break; - case 6:dst1 = !(src1 ^ dst1); dst2 = !(src2 ^ dst2);break; - case 7:dst1 = !src1 | !dst1; dst2 = !src2 | !dst2;break; - case 8:dst1 = src1 & dst1; dst2 = src2 & dst2;break; - case 9:dst1 = src1 ^ dst1; dst2 = src2 ^ dst2;break; - case 10:dst1 = dst1; dst2 = dst2;break; - case 11:dst1 = !src1 | dst1; dst2 = !src2 | dst2;break; - case 12:dst1 = src1; dst2 = src2;break; - case 13:dst1 = src1 | !dst1; dst2 = src2 | !dst2;break; - case 14:dst1 = src1 | dst1; dst2 = src2 | dst2;break; - case 15:dst1 = 0xFFFFFFFF; dst2 = 0xFFFFFFFF;break; - } - } else { - dst1 = src1; - dst2 = src2; - } - if(bcmd.clip_a1) { - if((a1_x>>16) < a1.clip_x && (a1_x>>16) >= 0 && (a1_y>>16) < a1.clip_y && (a1_y>>16) >= 0) { - jaguar_long_write(*dst,dst1); - //jaguar_long_write(*dst+4,dst2); - } - } else { - jaguar_long_write(*dst,dst1); - //jaguar_long_write(*dst+4,dst2); - } - a1_x += a1_inc_x; - a2_x += a2_inc_x; - a1_y += a1_inc_y; - a2_y += a2.yadd; - for(int v=0;v<4;v++) { - gd_i[v] += gd_ia; - gd_c[v] += gd_ca; - } - } - if(bcmd.upda1) { - a1_x += a1.step_x; - a1_y += a1.step_y; - } - if(bcmd.upda1f) { - a1_x += a1.fstep_x; - a1_y += a1.fstep_y; - } - if(bcmd.upda2) { - a2_x += a2.step_x; - a2_y += a2.step_y; - } - } - break; - default: - break; - } -/* A1_PIXEL_X = a1_x >> 16; - A1_PIXEL_Y = a1_y >> 16; - A1_FPIXEL_X = a1_x & 0xFFFF; - A1_FPIXEL_Y = a1_y & 0xFFFF; - A2_PIXEL_X = a2_x; - A2_PIXEL_Y = a2_y;*/ - jaguar_word_write(0xF0220E, a1_x >> 16); // A1_PIXEL_X = - jaguar_word_write(0xF0220C, a1_y >> 16); // A1_PIXEL_Y = - jaguar_word_write(0xF0221A, a1_x & 0xFFFF); // A1_FPIXEL_X = - jaguar_word_write(0xF02218, a1_y & 0xFFFF); // A1_FPIXEL_Y = - jaguar_word_write(0xF02232, a2_x); // A2_PIXEL_X = - jaguar_word_write(0xF02230, a2_y); // A2_PIXEL_Y = -} -/* -#define A1_PIXEL_Y jaguar_word_read(0xF0220C) -#define A1_PIXEL_X jaguar_word_read(0xF0220E) -#define A1_FPIXEL_Y jaguar_word_read(0xF02218) -#define A1_FPIXEL_X jaguar_word_read(0xF0221A) -#define A2_PIXEL_Y jaguar_word_read(0xF02230) -#define A2_PIXEL_X jaguar_word_read(0xF02232) -*/ diff --git a/src/cdbios.cpp b/src/cdbios.cpp index b57c01b..aa65e36 100644 --- a/src/cdbios.cpp +++ b/src/cdbios.cpp @@ -142,16 +142,16 @@ void cdbios_encode_toc(void) int i; uint32 base=CD_TOC; - jaguar_byte_write(base++,0x00); - jaguar_byte_write(base++,0x00); - jaguar_byte_write(base++,0x01); + JaguarWriteByte(base++,0x00); + JaguarWriteByte(base++,0x00); + JaguarWriteByte(base++,0x01); int nbtracks=0; for (i=0;inb_of_sessions;i++) nbtracks+=cdi_descriptor->sessions[i].nb_of_tracks; - jaguar_byte_write(base++,nbtracks+1); - jaguar_byte_write(base++,cdi_descriptor->nb_of_sessions); + JaguarWriteByte(base++,nbtracks+1); + JaguarWriteByte(base++,cdi_descriptor->nb_of_sessions); uint32 mm=0; uint32 ss=0; @@ -162,9 +162,9 @@ void cdbios_encode_toc(void) cdi_descriptor->sessions[cdi_descriptor->nb_of_sessions-1].tracks[cdi_descriptor->sessions[cdi_descriptor->nb_of_sessions-1].nb_of_tracks-1].pregap_length, &mm,&ss,&ff); - jaguar_byte_write(base++,mm); - jaguar_byte_write(base++,ss); - jaguar_byte_write(base++,ff); + JaguarWriteByte(base++,mm); + JaguarWriteByte(base++,ss); + JaguarWriteByte(base++,ff); int track_count=1; for (i=0;inb_of_sessions;i++) @@ -174,16 +174,16 @@ void cdbios_encode_toc(void) // fprintf(log_get(),"track %i\n",track_count); - jaguar_byte_write(base++,track_count); + JaguarWriteByte(base++,track_count); cdbios_get_time(track->start_lba+track->pregap_length,&mm,&ss,&ff); - jaguar_byte_write(base++,mm); - jaguar_byte_write(base++,ss); - jaguar_byte_write(base++,ff); - jaguar_byte_write(base++,i); + JaguarWriteByte(base++,mm); + JaguarWriteByte(base++,ss); + JaguarWriteByte(base++,ff); + JaguarWriteByte(base++,i); cdbios_get_time(track->length,&mm,&ss,&ff); - jaguar_byte_write(base++,mm); - jaguar_byte_write(base++,ss); - jaguar_byte_write(base++,ff); + JaguarWriteByte(base++,mm); + JaguarWriteByte(base++,ss); + JaguarWriteByte(base++,ff); track_count++; } @@ -209,11 +209,11 @@ void cdbios_decode_toc(void) fprintf(log_get(),"cdbios: toc:\n"); fprintf(log_get(),"cdbios:\n"); addr+=2; - fprintf(log_get(),"cdbios: minimum track number: %i\n",jaguar_byte_read(addr++)); - fprintf(log_get(),"cdbios: maximum track number: %i\n",nb_tracks=jaguar_byte_read(addr++)); - fprintf(log_get(),"cdbios: number of sessions : %i\n",jaguar_byte_read(addr++)); + fprintf(log_get(),"cdbios: minimum track number: %i\n",JaguarReadByte(addr++)); + fprintf(log_get(),"cdbios: maximum track number: %i\n",nb_tracks=JaguarReadByte(addr++)); + fprintf(log_get(),"cdbios: number of sessions : %i\n",JaguarReadByte(addr++)); fprintf(log_get(),"cdbios: start of last lead out time: %.2i:%.2i:%.2i\n", - jaguar_byte_read(addr++),jaguar_byte_read(addr++),jaguar_byte_read(addr++)); + JaguarReadByte(addr++),JaguarReadByte(addr++),JaguarReadByte(addr++)); uint32 mm,ss,ff; @@ -222,18 +222,18 @@ void cdbios_decode_toc(void) while (nb_tracks) { fprintf(log_get(),"cdbios:\n"); - fprintf(log_get(),"cdbios: track : %i\n",jaguar_byte_read(addr++)); + fprintf(log_get(),"cdbios: track : %i\n",JaguarReadByte(addr++)); - mm=jaguar_byte_read(addr++); - ss=jaguar_byte_read(addr++); - ff=jaguar_byte_read(addr++); + mm=JaguarReadByte(addr++); + ss=JaguarReadByte(addr++); + ff=JaguarReadByte(addr++); fprintf(log_get(),"cdbios: start at : %.2i:%.2i:%.2i\n",mm,ss,ff); - fprintf(log_get(),"cdbios: session : %i\n",jaguar_byte_read(addr++)); + fprintf(log_get(),"cdbios: session : %i\n",JaguarReadByte(addr++)); - mm=jaguar_byte_read(addr++); - ss=jaguar_byte_read(addr++); - ff=jaguar_byte_read(addr++); + mm=JaguarReadByte(addr++); + ss=JaguarReadByte(addr++); + ff=JaguarReadByte(addr++); fprintf(log_get(),"cdbios: duration : %.2i:%.2i:%.2i\n",mm,ss,ff); nb_tracks--; @@ -260,10 +260,10 @@ void cd_bios_boot(char *filename) // copy the code to ram for (uint32 i=0;i>1) & 0x01; uint32 cdrom_speed = data & 0x01; - jaguar_word_write(ERR_FLAG, CDROM_STATUS_OK); + JaguarWriteWord(ERR_FLAG, CDROM_STATUS_OK); // fprintf(log_get(),"cdbios: %s\n",(cdrom_mode==CDROM_AUDIO_MODE)?"audio mode":"data mode"); // fprintf(log_get(),"cdbios: %s\n",(cdrom_speed==CDROM_DOUBLE_SPEED)?"double speed":"single speed"); @@ -325,12 +325,12 @@ void cdbios_cmd_mode(void) void cdbios_cmd_ack(void) { - jaguar_word_write(ERR_FLAG,CDROM_STATUS_OK); + JaguarWriteWord(ERR_FLAG,CDROM_STATUS_OK); } void cdbios_cmd_jeri(void) { - jaguar_word_write(ERR_FLAG,CDROM_STATUS_OK); + JaguarWriteWord(ERR_FLAG,CDROM_STATUS_OK); } void cdbios_cmd_spin(void) @@ -338,33 +338,33 @@ void cdbios_cmd_spin(void) // uint16 spin=(1<<(s68000context.dreg[0]&0xffff)); uint16 spin = (1 << (m68k_get_reg(NULL, M68K_REG_D0) & 0xFFFF)); cdbios_session = spin; - jaguar_word_write(ERR_FLAG, CDROM_STATUS_OK); + JaguarWriteWord(ERR_FLAG, CDROM_STATUS_OK); // fprintf(log_get(),"cdbios: switching to session %i\n",spin); } void cdbios_cmd_stop(void) { - jaguar_word_write(ERR_FLAG,CDROM_STATUS_OK); + JaguarWriteWord(ERR_FLAG,CDROM_STATUS_OK); } void cdbios_cmd_mute(void) { - jaguar_word_write(ERR_FLAG,CDROM_STATUS_OK); + JaguarWriteWord(ERR_FLAG,CDROM_STATUS_OK); } void cdbios_cmd_umute(void) { - jaguar_word_write(ERR_FLAG,CDROM_STATUS_OK); + JaguarWriteWord(ERR_FLAG,CDROM_STATUS_OK); } void cdbios_cmd_pause(void) { - jaguar_word_write(ERR_FLAG,CDROM_STATUS_OK); + JaguarWriteWord(ERR_FLAG,CDROM_STATUS_OK); } void cdbios_cmd_upause(void) { - jaguar_word_write(ERR_FLAG,CDROM_STATUS_OK); + JaguarWriteWord(ERR_FLAG,CDROM_STATUS_OK); } void cdi_read_block(uint32 sector, uint8 *buffer, uint32 count) { @@ -440,7 +440,7 @@ void cdbios_cmd_read(void) uint8 *buffer=(uint8*)malloc((nb_sectors+1)*2352); cdi_read_block(track_offset,buffer,nb_sectors+1); for (uint32 k=0;k> 8) & 0xFF; @@ -51,7 +89,7 @@ void cdrom_word_write(uint32 offset, uint16 data) cdrom_cmd=data; if ((data&0xff00)==0x1500) { - fprintf(log_get(),"cdrom: setting mode 0x%.2x\n",data&0xff); + WriteLog("CDROM: setting mode 0x%.2x\n",data&0xff); return; } if (data==0x7001) @@ -68,48 +106,14 @@ void cdrom_word_write(uint32 offset, uint16 data) offset<<=8; offset|=cdrom_ram[0x05]; - fprintf(log_get(),"cdrom: READ(0x%.8x, 0x%.4x) [68k pc=0x%.8x]\n",offset,size,s68000readPC()); + WriteLog("CDROM: READ(0x%.8x, 0x%.4x) [68k pc=0x%.8x]\n",offset,size,s68000readPC()); return; } else - fprintf(log_get(),"cdrom: unknown command 0x%.4x\n",data); + WriteLog("CDROM: unknown command 0x%.4x\n",data); } */ #ifdef CDROM_LOG - fprintf(log_get(),"cdrom: writing word 0x%.4x at 0x%.8x\n",data,offset); -#endif -} - -uint8 cdrom_byte_read(uint32 offset) -{ -#ifdef CDROM_LOG - fprintf(log_get(),"cdrom: reading byte from 0x%.8x\n",offset); + WriteLog("CDROM: writing word 0x%.4x at 0x%.8x\n",data,offset); #endif - return cdrom_ram[offset & 0xFF]; -} - -uint16 cdrom_word_read(uint32 offset) -{ - offset &= 0xFF; - - uint16 data = 0x0000; - - if (offset == 0x00) - data = 0x0000; - else if (offset == 0x02) - data = 0x2000; - else if (offset == 0x0A) - { - if (cdrom_cmd == 0x7001) - data = cdrom_cmd; - else - data = 0x0400; - } - else - data = (cdrom_ram[offset+0] << 8) | cdrom_ram[offset+1]; - -#ifdef CDROM_LOG - fprintf(log_get(),"cdrom: reading word 0x%.4x from 0x%.8x [68k pc=0x%.8x]\n",data,offset,s68000readPC()); -#endif - return data; } diff --git a/src/dac.cpp b/src/dac.cpp index be2f2c5..2ae3e69 100644 --- a/src/dac.cpp +++ b/src/dac.cpp @@ -25,10 +25,10 @@ uint32 LeftFIFOHeadPtr, LeftFIFOTailPtr, RightFIFOHeadPtr, RightFIFOTailPtr; SDL_AudioSpec desired; // We can get away with using native endian here because we can tell SDL to use the native -// when looking at the sample buffer, i.e., no need to worry about it. +// endian when looking at the sample buffer, i.e., no need to worry about it. uint16 * DACBuffer; -uint8 SCLKFrequencyDivider = 9; // Start out roughly 44.1K (46164 Hz in NTSC mode) +uint8 SCLKFrequencyDivider = 19; // Default is roughly 22 KHz (20774 Hz in NTSC mode) uint16 serialMode = 0; // Private function prototypes @@ -86,6 +86,8 @@ void DACDone(void) // void SDLSoundCallback(void * userdata, Uint8 * buffer, int length) { + // Clear the buffer to silence, in case the DAC buffer is empty (or short) + memset(buffer, desired.silence, length); //WriteLog("DAC: Inside callback...\n"); if (LeftFIFOHeadPtr != LeftFIFOTailPtr) { @@ -98,10 +100,19 @@ void SDLSoundCallback(void * userdata, Uint8 * buffer, int length) - RightFIFOHeadPtr; int numSamplesReady = (numLeftSamplesReady < numRightSamplesReady - ? numLeftSamplesReady : numRightSamplesReady) * 2; + ? numLeftSamplesReady : numRightSamplesReady);//Hmm. * 2; - if (numSamplesReady > length) - numSamplesReady = length; +//The numbers look good--it's just that the DSP can't get enough samples in the DAC buffer! +//WriteLog("DAC: Left/RightFIFOHeadPtr: %u/%u, Left/RightFIFOTailPtr: %u/%u\n", LeftFIFOHeadPtr, RightFIFOHeadPtr, LeftFIFOTailPtr, RightFIFOTailPtr); +//WriteLog(" numLeft/RightSamplesReady: %i/%i, numSamplesReady: %i, length of buffer: %i\n", numLeftSamplesReady, numRightSamplesReady, numSamplesReady, length); + +/* if (numSamplesReady > length) + numSamplesReady = length;//*/ + if (numSamplesReady > length / 2) // length / 2 because we're comparing 16-bit lengths + numSamplesReady = length / 2; +//else +// WriteLog(" Not enough samples to fill the buffer (short by %u L/R samples)...\n", (length / 2) - numSamplesReady); +//WriteLog("DAC: %u samples ready.\n", numSamplesReady); // Actually, it's a bit more involved than this, but this is the general idea: // memcpy(buffer, DACBuffer, length); @@ -110,12 +121,16 @@ void SDLSoundCallback(void * userdata, Uint8 * buffer, int length) ((uint16 *)buffer)[i] = DACBuffer[(LeftFIFOHeadPtr + i) % BUFFER_SIZE]; // buffer[i] = DACBuffer[(LeftFIFOHeadPtr + i) & (BUFFER_SIZE - 1)]; - LeftFIFOHeadPtr = (LeftFIFOHeadPtr + (numSamplesReady / 2)) % BUFFER_SIZE; - RightFIFOHeadPtr = (RightFIFOHeadPtr + (numSamplesReady / 2)) % BUFFER_SIZE; + LeftFIFOHeadPtr = (LeftFIFOHeadPtr + numSamplesReady) % BUFFER_SIZE; + RightFIFOHeadPtr = (RightFIFOHeadPtr + numSamplesReady) % BUFFER_SIZE; // Could also use (as long as BUFFER_SIZE is a multiple of 2): -// LeftFIFOHeadPtr = (LeftFIFOHeadPtr + (numSamplesReady / 2)) & (BUFFER_SIZE - 1); -// RightFIFOHeadPtr = (RightFIFOHeadPtr + (numSamplesReady / 2)) & (BUFFER_SIZE - 1); +// LeftFIFOHeadPtr = (LeftFIFOHeadPtr + (numSamplesReady)) & (BUFFER_SIZE - 1); +// RightFIFOHeadPtr = (RightFIFOHeadPtr + (numSamplesReady)) & (BUFFER_SIZE - 1); +//WriteLog(" -> Left/RightFIFOHeadPtr: %u/%u, Left/RightFIFOTailPtr: %u/%u\n", LeftFIFOHeadPtr, RightFIFOHeadPtr, LeftFIFOTailPtr, RightFIFOTailPtr); } +//Hmm. Seems that the SDL buffer isn't being starved by the DAC buffer... +// else +// WriteLog("DAC: Silence...!\n"); } // @@ -136,7 +151,9 @@ int GetCalculatedFrequency(void) // void DACWriteByte(uint32 offset, uint8 data) { -// WriteLog("DAC: Writing %02X at %08X\n", data, offset); + WriteLog("DAC: Writing %02X at %08X\n", data, offset); + if (offset == SCLK + 3) + DACWriteWord(offset - 3, (uint16)data); } void DACWriteWord(uint32 offset, uint16 data) @@ -147,12 +164,14 @@ void DACWriteWord(uint32 offset, uint16 data) { SDL_LockAudio(); // Is it necessary to do this? Mebbe. // We use a circular buffer 'cause it's easy. Note that the callback function - // takes care of dumping audio to the soundcard...! + // takes care of dumping audio to the soundcard...! Also note that we're writing + // the samples in the buffer in an interleaved L/R format. LeftFIFOTailPtr = (LeftFIFOTailPtr + 2) % BUFFER_SIZE; DACBuffer[LeftFIFOTailPtr] = data; // Aaron's code does this, but I don't know why... //Flipping this bit makes the audio MUCH louder. Need to look at the amplitude of the //waveform to see if any massaging is needed here... +//Looks like a cheap & dirty way to convert signed samples to unsigned... // DACBuffer[LeftFIFOTailPtr] = data ^ 0x8000; SDL_UnlockAudio(); } @@ -175,22 +194,27 @@ void DACWriteWord(uint32 offset, uint16 data) } else if (offset == SCLK + 2) // Sample rate { + WriteLog("DAC: Writing %u to SCLK...\n", data); if ((uint8)data != SCLKFrequencyDivider) { -WriteLog("DAC: Changing sample rate!\n"); - SDL_CloseAudio(); SCLKFrequencyDivider = (uint8)data; - desired.freq = GetCalculatedFrequency();// SDL will do conversion on the fly, if it can't get the exact rate. Nice! - - if (SDL_OpenAudio(&desired, NULL) < 0) // NULL means SDL guarantees what we want +//Of course a better way would be to query the hardware to find the upper limit... + if (data > 7) // Anything less is too high! { - WriteLog("DAC: Failed to initialize SDL sound. Shutting down!\n"); - log_done(); - exit(1); + SDL_CloseAudio(); + desired.freq = GetCalculatedFrequency();// SDL will do conversion on the fly, if it can't get the exact rate. Nice! + WriteLog("DAC: Changing sample rate to %u Hz!\n", desired.freq); + + if (SDL_OpenAudio(&desired, NULL) < 0) // NULL means SDL guarantees what we want + { + WriteLog("DAC: Failed to initialize SDL sound: %s.\nDesired freq: %u\nShutting down!\n", SDL_GetError(), desired.freq); + log_done(); + exit(1); + } + + DACReset(); + SDL_PauseAudio(false); // Start playback! } - - DACReset(); - SDL_PauseAudio(false); // Start playback! } } else if (offset == SMODE + 2) diff --git a/src/dsp.cpp b/src/dsp.cpp index b2674d6..de54c3e 100644 --- a/src/dsp.cpp +++ b/src/dsp.cpp @@ -3,11 +3,113 @@ // // by cal2 // GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (BeOS) -// Cleanups by James L. Hammons +// Extensive cleanups/rewrites by James L. Hammons // +#include // Used only for SDL_GetTicks... #include "dsp.h" +#define DSP_DEBUG +//#define DSP_DEBUG_IRQ + +// Disassembly definitions + +#define DSP_DIS_ADD +#define DSP_DIS_ADDC +#define DSP_DIS_ADDQ +#define DSP_DIS_ADDQMOD +#define DSP_DIS_ADDQT +#define DSP_DIS_AND +#define DSP_DIS_BCLR +#define DSP_DIS_BSET +#define DSP_DIS_BTST +#define DSP_DIS_CMP +#define DSP_DIS_CMPQ +#define DSP_DIS_IMACN +#define DSP_DIS_IMULT +#define DSP_DIS_IMULTN +#define DSP_DIS_JR +#define DSP_DIS_JUMP +#define DSP_DIS_LOAD +#define DSP_DIS_LOAD14I +#define DSP_DIS_LOAD14R +#define DSP_DIS_LOAD15I +#define DSP_DIS_LOAD15R +#define DSP_DIS_LOADB +#define DSP_DIS_LOADW +#define DSP_DIS_MOVE +#define DSP_DIS_MOVEI +#define DSP_DIS_MOVEQ +#define DSP_DIS_MOVEFA +#define DSP_DIS_MOVETA +#define DSP_DIS_MULT +#define DSP_DIS_NEG +#define DSP_DIS_NOP +#define DSP_DIS_NOT +#define DSP_DIS_OR +#define DSP_DIS_RESMAC +#define DSP_DIS_ROR +#define DSP_DIS_RORQ +#define DSP_DIS_SHARQ +#define DSP_DIS_SHLQ +#define DSP_DIS_SHRQ +#define DSP_DIS_STORE +#define DSP_DIS_STORE14I +#define DSP_DIS_STORE15I +#define DSP_DIS_STOREB +#define DSP_DIS_STOREW +#define DSP_DIS_SUB +#define DSP_DIS_SUBC +#define DSP_DIS_SUBQ +#define DSP_DIS_SUBQT +#define DSP_DIS_XOR + +bool doDSPDis = false; +//*/ + +/* +No dis yet: ++ subqt 4560 ++ mult 1472 ++ imultn 395024 ++ resmac 395024 ++ imacn 395024 ++ addqmod 93328 + +dsp opcodes use: ++ add 1672497 ++ addq 4366576 ++ addqt 44405640 ++ sub 94833 ++ subq 111769 ++ and 47416 ++ btst 94521 ++ bset 2277826 ++ bclr 3223372 ++ mult 47104 ++ imult 237080 ++ shlq 365464 ++ shrq 141624 ++ sharq 318368 ++ cmp 45175078 ++ move 2238994 ++ moveq 335305 ++ moveta 19 ++ movefa 47406440 ++ movei 1920664 ++ loadb 94832 ++ load 4031281 ++ load_r15_indexed 284500 ++ store 2161732 ++ store_r15_indexed 47416 ++ jump 3872424 ++ jr 46386967 ++ nop 3300029 ++ load_r14_ri 1229448 +*/ + +// DSP flags (old--have to get rid of this crap) + #define CINT0FLAG 0x00200 #define CINT1FLAG 0x00400 #define CINT2FLAG 0x00800 @@ -16,78 +118,112 @@ #define CINT04FLAGS (CINT0FLAG | CINT1FLAG | CINT2FLAG | CINT3FLAG | CINT4FLAG) #define CINT5FLAG 0x20000 /* DSP only */ +// DSP_FLAGS bits + +#define ZERO_FLAG 0x00001 +#define CARRY_FLAG 0x00002 +#define NEGA_FLAG 0x00004 +#define IMASK 0x00008 +#define INT_ENA0 0x00010 +#define INT_ENA1 0x00020 +#define INT_ENA2 0x00040 +#define INT_ENA3 0x00080 +#define INT_ENA4 0x00100 +#define INT_CLR0 0x00200 +#define INT_CLR1 0x00400 +#define INT_CLR2 0x00800 +#define INT_CLR3 0x01000 +#define INT_CLR4 0x02000 +#define REGPAGE 0x04000 +#define DMAEN 0x08000 +#define INT_ENA5 0x10000 +#define INT_CLR5 0x20000 + +// DSP_CTRL bits + +#define DSPGO 0x00001 +#define CPUINT 0x00002 +#define DSPINT0 0x00004 +#define SINGLE_STEP 0x00008 +#define SINGLE_GO 0x00010 +// Bit 5 is unused! +#define INT_LAT0 0x00040 +#define INT_LAT1 0x00080 +#define INT_LAT2 0x00100 +#define INT_LAT3 0x00200 +#define INT_LAT4 0x00400 +#define BUS_HOG 0x00800 +#define VERSION 0x0F000 +#define INT_LAT5 0x10000 + extern uint32 jaguar_mainRom_crc32; -static void dsp_opcode_addqmod(void); -static void dsp_opcode_subqmod(void); -static void dsp_opcode_mirror(void); -static void dsp_opcode_sat32s(void); -static void dsp_opcode_sat16s(void); +// Is opcode 62 *really* a NOP? Seems like it... +static void dsp_opcode_abs(void); static void dsp_opcode_add(void); static void dsp_opcode_addc(void); static void dsp_opcode_addq(void); +static void dsp_opcode_addqmod(void); static void dsp_opcode_addqt(void); -static void dsp_opcode_sub(void); -static void dsp_opcode_subc(void); -static void dsp_opcode_subq(void); -static void dsp_opcode_subqt(void); -static void dsp_opcode_neg(void); static void dsp_opcode_and(void); -static void dsp_opcode_or(void); -static void dsp_opcode_xor(void); -static void dsp_opcode_not(void); -static void dsp_opcode_btst(void); -static void dsp_opcode_bset(void); static void dsp_opcode_bclr(void); -static void dsp_opcode_mult(void); -static void dsp_opcode_imult(void); -static void dsp_opcode_imultn(void); -static void dsp_opcode_resmac(void); -static void dsp_opcode_imacn(void); -static void dsp_opcode_div(void); -static void dsp_opcode_abs(void); -static void dsp_opcode_sh(void); -static void dsp_opcode_shlq(void); -static void dsp_opcode_shrq(void); -static void dsp_opcode_sha(void); -static void dsp_opcode_sharq(void); -static void dsp_opcode_ror(void); -static void dsp_opcode_rorq(void); +static void dsp_opcode_bset(void); +static void dsp_opcode_btst(void); static void dsp_opcode_cmp(void); static void dsp_opcode_cmpq(void); -static void dsp_opcode_sat8(void); -static void dsp_opcode_sat16(void); -static void dsp_opcode_move(void); -static void dsp_opcode_moveq(void); -static void dsp_opcode_moveta(void); -static void dsp_opcode_movefa(void); -static void dsp_opcode_movei(void); +static void dsp_opcode_div(void); +static void dsp_opcode_imacn(void); +static void dsp_opcode_imult(void); +static void dsp_opcode_imultn(void); +static void dsp_opcode_jr(void); +static void dsp_opcode_jump(void); +static void dsp_opcode_load(void); static void dsp_opcode_loadb(void); static void dsp_opcode_loadw(void); -static void dsp_opcode_load(void); -static void dsp_opcode_loadp(void); static void dsp_opcode_load_r14_indexed(void); +static void dsp_opcode_load_r14_ri(void); static void dsp_opcode_load_r15_indexed(void); -static void dsp_opcode_storeb(void); -static void dsp_opcode_storew(void); -static void dsp_opcode_store(void); -static void dsp_opcode_storep(void); -static void dsp_opcode_store_r14_indexed(void); -static void dsp_opcode_store_r15_indexed(void); -static void dsp_opcode_move_pc(void); -static void dsp_opcode_jump(void); -static void dsp_opcode_jr(void); +static void dsp_opcode_load_r15_ri(void); +static void dsp_opcode_mirror(void); static void dsp_opcode_mmult(void); +static void dsp_opcode_move(void); +static void dsp_opcode_movei(void); +static void dsp_opcode_movefa(void); +static void dsp_opcode_move_pc(void); +static void dsp_opcode_moveq(void); +static void dsp_opcode_moveta(void); static void dsp_opcode_mtoi(void); -static void dsp_opcode_normi(void); +static void dsp_opcode_mult(void); +static void dsp_opcode_neg(void); static void dsp_opcode_nop(void); -static void dsp_opcode_load_r14_ri(void); -static void dsp_opcode_load_r15_ri(void); +static void dsp_opcode_normi(void); +static void dsp_opcode_not(void); +static void dsp_opcode_or(void); +static void dsp_opcode_resmac(void); +static void dsp_opcode_ror(void); +static void dsp_opcode_rorq(void); +static void dsp_opcode_xor(void); +static void dsp_opcode_sat16s(void); +static void dsp_opcode_sat32s(void); +static void dsp_opcode_sh(void); +static void dsp_opcode_sha(void); +static void dsp_opcode_sharq(void); +static void dsp_opcode_shlq(void); +static void dsp_opcode_shrq(void); +static void dsp_opcode_store(void); +static void dsp_opcode_storeb(void); +static void dsp_opcode_storew(void); +static void dsp_opcode_store_r14_indexed(void); static void dsp_opcode_store_r14_ri(void); +static void dsp_opcode_store_r15_indexed(void); static void dsp_opcode_store_r15_ri(void); -static void dsp_opcode_sat24(void); +static void dsp_opcode_sub(void); +static void dsp_opcode_subc(void); +static void dsp_opcode_subq(void); +static void dsp_opcode_subqmod(void); +static void dsp_opcode_subqt(void); -uint8 dsp_opcode_cycles[64] = +uint8 dsp_opcode_cycles[64] = { 3, 3, 3, 3, 3, 3, 3, 3, @@ -107,7 +243,7 @@ uint8 dsp_opcode_cycles[64] = 2, 2, 3, 3 }; -void (*dsp_opcode[64])()= +void (* dsp_opcode[64])() = { dsp_opcode_add, dsp_opcode_addc, dsp_opcode_addq, dsp_opcode_addqt, dsp_opcode_sub, dsp_opcode_subc, dsp_opcode_subq, dsp_opcode_subqt, @@ -129,7 +265,7 @@ void (*dsp_opcode[64])()= uint32 dsp_opcode_use[64]; -char *dsp_opcode_str[64]= +char * dsp_opcode_str[64]= { "add", "addc", "addq", "addqt", "sub", "subc", "subq", "subqt", @@ -149,84 +285,82 @@ char *dsp_opcode_str[64]= "store_r14_ri", "store_r15_ri", "nop", "addqmod", }; -static uint16 *mirror_table; -static uint8 *dsp_ram_8; - uint32 dsp_pc; -static uint32 dsp_acc; -static uint32 dsp_remain; -static uint32 dsp_modulo; -static uint32 dsp_flags; -static uint32 dsp_matrix_control; -static uint32 dsp_pointer_to_matrix; -static uint32 dsp_data_organization; +static uint64 dsp_acc; // 40 bit register, NOT 32! +static uint32 dsp_remain; +static uint32 dsp_modulo; +static uint32 dsp_flags; +static uint32 dsp_matrix_control; +static uint32 dsp_pointer_to_matrix; +static uint32 dsp_data_organization; uint32 dsp_control; -static uint32 dsp_div_control; -static uint8 dsp_flag_z; -static uint8 dsp_flag_n; -static uint8 dsp_flag_c; -static uint8 dsp_alternate_flag_z; -static uint8 dsp_alternate_flag_n; -static uint8 dsp_alternate_flag_c; -static uint32 *dsp_reg; -static uint32 *dsp_alternate_reg; -static uint32 *dsp_reg_bank_0; -static uint32 *dsp_reg_bank_1; - -static uint32 dsp_opcode_first_parameter; -static uint32 dsp_opcode_second_parameter; - -#define dsp_running (dsp_control&0x01) - -#define Rm dsp_reg[dsp_opcode_first_parameter] -#define Rn dsp_reg[dsp_opcode_second_parameter] -#define alternate_Rm dsp_alternate_reg[dsp_opcode_first_parameter] -#define alternate_Rn dsp_alternate_reg[dsp_opcode_second_parameter] -#define imm_1 dsp_opcode_first_parameter -#define imm_2 dsp_opcode_second_parameter - -#define set_flag_z(r) dsp_flag_z=(r==0); -#define set_flag_n(r) dsp_flag_n=(r&0x80000000); - -#define reset_flag_z() dsp_flag_z=0; -#define reset_flag_n() dsp_flag_n=0; -#define reset_flag_c() dsp_flag_c=0; +static uint32 dsp_div_control; +static uint8 dsp_flag_z, dsp_flag_n, dsp_flag_c; +static uint32 * dsp_reg, * dsp_alternate_reg; +static uint32 * dsp_reg_bank_0, * dsp_reg_bank_1; + +static uint32 dsp_opcode_first_parameter; +static uint32 dsp_opcode_second_parameter; + +#define DSP_RUNNING (dsp_control & 0x01) + +#define RM dsp_reg[dsp_opcode_first_parameter] +#define RN dsp_reg[dsp_opcode_second_parameter] +#define ALTERNATE_RM dsp_alternate_reg[dsp_opcode_first_parameter] +#define ALTERNATE_RN dsp_alternate_reg[dsp_opcode_second_parameter] +#define IMM_1 dsp_opcode_first_parameter +#define IMM_2 dsp_opcode_second_parameter + +#define CLR_Z (dsp_flag_z = 0) +#define CLR_ZN (dsp_flag_z = dsp_flag_n = 0) +#define CLR_ZNC (dsp_flag_z = dsp_flag_n = dsp_flag_c = 0) +#define SET_Z(r) (dsp_flag_z = ((r) == 0)) +#define SET_N(r) (dsp_flag_n = (((UINT32)(r) >> 31) & 0x01)) +#define SET_C_ADD(a,b) (dsp_flag_c = ((UINT32)(b) > (UINT32)(~(a)))) +#define SET_C_SUB(a,b) (dsp_flag_c = ((UINT32)(b) > (UINT32)(a))) +#define SET_ZN(r) SET_N(r); SET_Z(r) +#define SET_ZNC_ADD(a,b,r) SET_N(r); SET_Z(r); SET_C_ADD(a,b) +#define SET_ZNC_SUB(a,b,r) SET_N(r); SET_Z(r); SET_C_SUB(a,b) uint32 dsp_convert_zero[32] = { 32,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31 }; -uint8 *dsp_branch_condition_table=0; -#define branch_condition(x) dsp_branch_condition_table[(x) + ((jaguar_flags & 7) << 5)] +uint8 * dsp_branch_condition_table = NULL; +static uint16 * mirror_table = NULL; +static uint8 * dsp_ram_8 = NULL; + +#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; FILE * dsp_fp; +// Private function prototypes + +void DSPDumpRegisters(void); +void DSPDumpDisassembly(void); + void dsp_reset_stats(void) { - for (uint32 i=0; i<64; i++) + for(int i=0; i<64; i++) dsp_opcode_use[i] = 0; } void dsp_releaseTimeslice(void) { +//This does absolutely nothing!!! !!! FIX !!! dsp_releaseTimeSlice_flag = 1; } void dsp_build_branch_condition_table(void) { - int i,j; - #define ZFLAG 0x00001 - #define CFLAG 0x00002 - #define NFLAG 0x00004 - - /* allocate the mirror table */ + // Allocate the mirror table if (!mirror_table) - mirror_table = (uint16*)malloc(65536 * sizeof(mirror_table[0])); + mirror_table = (uint16 *)malloc(65536 * sizeof(mirror_table[0])); - /* fill in the mirror table */ + // Fill in the mirror table if (mirror_table) - for (int i = 0; i < 65536; i++) + for(int i=0; i<65536; i++) mirror_table[i] = ((i >> 15) & 0x0001) | ((i >> 13) & 0x0002) | ((i >> 11) & 0x0004) | ((i >> 9) & 0x0008) | ((i >> 7) & 0x0010) | ((i >> 5) & 0x0020) | @@ -238,44 +372,52 @@ void dsp_build_branch_condition_table(void) if (!dsp_branch_condition_table) { - dsp_branch_condition_table = (uint8*)malloc(32 * 8 * sizeof(dsp_branch_condition_table[0])); + dsp_branch_condition_table = (uint8 *)malloc(32 * 8 * sizeof(dsp_branch_condition_table[0])); - /* fill in the condition table */ + // Fill in the condition table if (dsp_branch_condition_table) - for (i = 0; i < 8; i++) - for (j = 0; j < 32; j++) + { + for(int i=0; i<8; i++) + { + for(int j=0; j<32; j++) { int result = 1; if (j & 1) - if (i & ZFLAG) result = 0; + if (i & ZERO_FLAG) + result = 0; if (j & 2) - if (!(i & ZFLAG)) result = 0; + if (!(i & ZERO_FLAG)) + result = 0; if (j & 4) - if (i & (CFLAG << (j >> 4))) result = 0; + if (i & (CARRY_FLAG << (j >> 4))) + result = 0; if (j & 8) - if (!(i & (CFLAG << (j >> 4)))) result = 0; + if (!(i & (CARRY_FLAG << (j >> 4)))) + result = 0; dsp_branch_condition_table[i * 32 + j] = result; } + } + } } } -unsigned dsp_byte_read(unsigned int offset) +uint8 DSPReadByte(uint32 offset, uint32 who/*=UNKNOWN*/) { // battlemorph // if ((offset==0xF1CFE0)||(offset==0xF1CFE2)) // return(0xffff); // mutant penguin - if ((jaguar_mainRom_crc32==0xbfd751a4)||(jaguar_mainRom_crc32==0x053efaf9)) +/* if ((jaguar_mainRom_crc32==0xbfd751a4)||(jaguar_mainRom_crc32==0x053efaf9)) { if (offset==0xF1CFE0) return(0xff); - } - if ((offset>=DSP_WORK_RAM_BASE)&&(offset= DSP_WORK_RAM_BASE && offset <= (DSP_WORK_RAM_BASE + 0x1FFF)) + return dsp_ram_8[offset - DSP_WORK_RAM_BASE]; - if ((offset>=DSP_CONTROL_RAM_BASE)&&(offset= DSP_CONTROL_RAM_BASE && offset <= (DSP_CONTROL_RAM_BASE + 0x1F)) { - uint32 data=dsp_long_read(offset&0xfffffffc); + uint32 data = DSPReadLong(offset & 0xFFFFFFFC, who); if ((offset&0x03)==0) return(data>>24); @@ -289,20 +431,22 @@ unsigned dsp_byte_read(unsigned int offset) if ((offset&0x03)==3) return(data&0xff); } - return(jaguar_byte_read(offset)); + + return JaguarReadByte(offset, who); } -unsigned dsp_word_read(unsigned int offset) +uint16 DSPReadWord(uint32 offset, uint32 who/*=UNKNOWN*/) { - offset&=0xFFFFFFFE; + //??? + offset &= 0xFFFFFFFE; // jaguar cd bios - if (jaguar_mainRom_crc32==0xa74a97cd) +/* if (jaguar_mainRom_crc32==0xa74a97cd) { if (offset==0xF1A114) return(0x0000); if (offset==0xF1A116) return(0x0000); if (offset==0xF1B000) return(0x1234); if (offset==0xF1B002) return(0x5678); - } + }*/ /* if (jaguar_mainRom_crc32==0x7ae20823) { @@ -318,7 +462,7 @@ unsigned dsp_word_read(unsigned int offset) */ // pour permettre à nba jam de tourner sans le dsp - if (jaguar_mainRom_crc32==0x4faddb18) +/* if (jaguar_mainRom_crc32==0x4faddb18) { if (offset==0xf1b2c0) return(0); if (offset==0xf1b2c2) return(0); @@ -336,82 +480,84 @@ unsigned dsp_word_read(unsigned int offset) if (offset==0xF1B142) return(0); if (offset==0xF1B1C0) return(0); if (offset==0xF1B1C2) return(0); - } + }*/ - if ((offset>=DSP_WORK_RAM_BASE)&&(offset= DSP_WORK_RAM_BASE && offset <= DSP_WORK_RAM_BASE+0x1FFF) { - offset-=DSP_WORK_RAM_BASE; - uint16 data=(((uint16)dsp_ram_8[offset])<<8)|((uint16)dsp_ram_8[offset+1]); - return(data); + offset -= DSP_WORK_RAM_BASE; +/* uint16 data = (((uint16)dsp_ram_8[offset])<<8)|((uint16)dsp_ram_8[offset+1]); + return data;*/ + return GET16(dsp_ram_8, offset); } - if ((offset>=DSP_CONTROL_RAM_BASE)&&(offset=DSP_CONTROL_RAM_BASE)&&(offset>16); + return data >> 16; } - return(jaguar_word_read(offset)); + + return JaguarReadWord(offset, who); } -unsigned dsp_long_read(unsigned int offset) +uint32 DSPReadLong(uint32 offset, uint32 who/*=UNKNOWN*/) { - offset&=0xFFFFFFFC; - - if ((offset>=DSP_WORK_RAM_BASE)&&(offset %08X [%02X %02X %02X %02X][%04X %04X]\n", GET32(dsp_ram_8, 0x0CF4), dsp_ram_8[0x0CF4], dsp_ram_8[0x0CF5], dsp_ram_8[0x0CF6], dsp_ram_8[0x0CF7], JaguarReadWord(0xF1BCF4, DSP), JaguarReadWord(0xF1BCF6, DSP)); + DSPDumpDisassembly(); +}*/ + if (offset >= DSP_WORK_RAM_BASE && offset <= DSP_WORK_RAM_BASE + 0x1FFF) { - offset-=DSP_WORK_RAM_BASE; - uint32 data= (((uint32)dsp_ram_8[offset] )<<24)| - (((uint32)dsp_ram_8[offset+1])<<16)| - (((uint32)dsp_ram_8[offset+2])<<8 )| - ( (uint32)dsp_ram_8[offset+3]); - return(data); + offset -= DSP_WORK_RAM_BASE; + return GET32(dsp_ram_8, offset); } - if ((offset>=DSP_CONTROL_RAM_BASE)&&(offset= DSP_CONTROL_RAM_BASE && offset <= DSP_CONTROL_RAM_BASE + 0x23) { - offset&=0x1f; + offset &= 0x3F; switch (offset) { - case 0x00: dsp_flag_c?(dsp_flag_c=1):(dsp_flag_c=0); + case 0x00: /*dsp_flag_c?(dsp_flag_c=1):(dsp_flag_c=0); dsp_flag_z?(dsp_flag_z=1):(dsp_flag_z=0); - dsp_flag_n?(dsp_flag_n=1):(dsp_flag_n=0); - - dsp_flags=(dsp_flags&0xFFFFFFF8)|(dsp_flag_n<<2)|(dsp_flag_c<<1)|dsp_flag_z; - - return(dsp_flags&0xFFFFC1FF); - case 0x04: return(dsp_matrix_control); - case 0x08: return(dsp_pointer_to_matrix); - case 0x0C: return(dsp_data_organization); - case 0x10: return(dsp_pc); - case 0x14: return(dsp_control); - case 0x18: return(dsp_modulo); - case 0x1C: return(dsp_remain); -// default: // unaligned long read //__asm int 3 + dsp_flag_n?(dsp_flag_n=1):(dsp_flag_n=0);*/ + + dsp_flags = (dsp_flags & 0xFFFFFFF8) | (dsp_flag_n << 2) | (dsp_flag_c << 1) | dsp_flag_z; + return dsp_flags & 0xFFFFC1FF; + case 0x04: return dsp_matrix_control; + case 0x08: return dsp_pointer_to_matrix; + case 0x0C: return dsp_data_organization; + case 0x10: return dsp_pc; + case 0x14: return dsp_control; + case 0x18: return dsp_modulo; + case 0x1C: return dsp_remain; + case 0x20: + return (int32)((int8)(dsp_acc >> 32)); // Top 8 bits of 40-bit accumulator, sign extended } - return(0xfffffff); + // unaligned long read-- !!! FIX !!! + return 0xFFFFFFFF; } - uint32 data=jaguar_word_read(offset); - data<<=16; - data|=jaguar_word_read(offset+2); - return(data); + + return JaguarReadLong(offset, who); } -void dsp_byte_write(unsigned offset, unsigned data) +void DSPWriteByte(uint32 offset, uint8 data, uint32 who/*=UNKNOWN*/) { if ((offset >= DSP_WORK_RAM_BASE) && (offset < DSP_WORK_RAM_BASE+0x2000)) { offset -= DSP_WORK_RAM_BASE; dsp_ram_8[offset] = data; - if (dsp_in_exec == 0) +//This is rather stupid! !!! FIX !!! +/* if (dsp_in_exec == 0) { -// s68000releaseTimeslice(); m68k_end_timeslice(); gpu_releaseTimeslice(); - } + }*/ return; } if ((offset >= DSP_CONTROL_RAM_BASE) && (offset < DSP_CONTROL_RAM_BASE+0x20)) @@ -423,33 +569,39 @@ void dsp_byte_write(unsigned offset, unsigned data) dsp_div_control = (dsp_div_control & (~(0xFF << (bytenum << 3)))) | (data << (bytenum << 3)); else { - uint32 old_data = dsp_long_read(offset&0xFFFFFFC); +//This looks funky. !!! FIX !!! + uint32 old_data = DSPReadLong(offset&0xFFFFFFC, who); bytenum = 3 - bytenum; // convention motorola !!! old_data = (old_data & (~(0xFF << (bytenum << 3)))) | (data << (bytenum << 3)); - dsp_long_write(offset & 0xFFFFFFC, old_data); + DSPWriteLong(offset & 0xFFFFFFC, old_data, who); } return; } -// fprintf(log_get(),"dsp: writing %.2x at 0x%.8x\n",data,offset); - jaguar_byte_write(offset, data); +// WriteLog("dsp: writing %.2x at 0x%.8x\n",data,offset); +//Should this *ever* happen??? Shouldn't we be saying "unknown" here??? + JaguarWriteByte(offset, data, who); } -void dsp_word_write(unsigned offset, unsigned data) +void DSPWriteWord(uint32 offset, uint16 data, uint32 who/*=UNKNOWN*/) { offset &= 0xFFFFFFFE; -// fprintf(log_get(),"dsp: writing %.4x at 0x%.8x\n",data,offset); +/*if (offset == 0xF1BCF4) +{ + WriteLog("DSPWriteWord: Writing to 0xF1BCF4... %04X -> %04X\n", GET16(dsp_ram_8, 0x0CF4), data); +}*/ +// WriteLog("dsp: writing %.4x at 0x%.8x\n",data,offset); if ((offset >= DSP_WORK_RAM_BASE) && (offset < DSP_WORK_RAM_BASE+0x2000)) { offset -= DSP_WORK_RAM_BASE; dsp_ram_8[offset] = data >> 8; dsp_ram_8[offset+1] = data & 0xFF; - if (dsp_in_exec == 0) +//This is rather stupid! !!! FIX !!! +/* if (dsp_in_exec == 0) { -// fprintf(log_get(),"dsp: writing %.4x at 0x%.8x\n",data,offset+DSP_WORK_RAM_BASE); -// s68000releaseTimeslice(); +// WriteLog("dsp: writing %.4x at 0x%.8x\n",data,offset+DSP_WORK_RAM_BASE); m68k_end_timeslice(); gpu_releaseTimeslice(); - } + }*/ return; } else if ((offset >= DSP_CONTROL_RAM_BASE) && (offset < DSP_CONTROL_RAM_BASE+0x20)) @@ -463,46 +615,64 @@ void dsp_word_write(unsigned offset, unsigned data) } else { - uint32 old_data = dsp_long_read(offset & 0xffffffc); + uint32 old_data = DSPReadLong(offset & 0xffffffc, who); if (offset & 0x03) old_data = (old_data&0xffff0000)|(data&0xffff); else old_data = (old_data&0xffff)|((data&0xffff)<<16); - dsp_long_write(offset & 0xffffffc, old_data); + DSPWriteLong(offset & 0xffffffc, old_data, who); } return; } - jaguar_word_write(offset, data); + + JaguarWriteWord(offset, data, who); } -void dsp_long_write(unsigned offset, unsigned data) +void DSPWriteLong(uint32 offset, uint32 data, uint32 who/*=UNKNOWN*/) { + // ??? WHY ??? offset &= 0xFFFFFFFC; -// fprintf(log_get(),"dsp: writing %.8x at 0x%.8x\n",data,offset); - if ((offset >= DSP_WORK_RAM_BASE) && (offset < DSP_WORK_RAM_BASE+0x2000)) +/*if (offset == 0xF1BCF4) +{ + WriteLog("DSPWriteLong: Writing to 0xF1BCF4... %08X -> %08X\n", GET32(dsp_ram_8, 0x0CF4), data); +}*/ +// WriteLog("dsp: writing %.8x at 0x%.8x\n",data,offset); + if (offset >= DSP_WORK_RAM_BASE && offset <= DSP_WORK_RAM_BASE + 0x1FFF) { +if (offset == 0xF1BE2C) +{ + WriteLog("DSP: %s is writing %08X at location 0xF1BE2C (DSP_PC: %08X)...\n", whoName[who], data, dsp_pc - 2); +} offset -= DSP_WORK_RAM_BASE; - dsp_ram_8[offset] = data >> 24; - dsp_ram_8[offset+1] = (data>>16) & 0xFF; - dsp_ram_8[offset+2] = (data>>8) & 0xFF; - dsp_ram_8[offset+3] = data & 0xFF; + SET32(dsp_ram_8, offset, data); return; } - else if ((offset >= DSP_CONTROL_RAM_BASE) && (offset < DSP_CONTROL_RAM_BASE+0x20)) + else if (offset >= DSP_CONTROL_RAM_BASE && offset <= (DSP_CONTROL_RAM_BASE + 0x1F)) { - offset&=0x1f; + offset &= 0x1F; switch (offset) { case 0x00: + { + bool IMASKCleared = (dsp_flags & IMASK) && !(data & IMASK); dsp_flags = data; dsp_flag_z = dsp_flags & 0x01; - dsp_flag_c = (dsp_flags>>1) & 0x01; - dsp_flag_n = (dsp_flags>>2) & 0x01; - dsp_update_register_banks(); + dsp_flag_c = (dsp_flags >> 1) & 0x01; + dsp_flag_n = (dsp_flags >> 2) & 0x01; + DSPUpdateRegisterBanks(); dsp_control &= ~((dsp_flags & CINT04FLAGS) >> 3); dsp_control &= ~((dsp_flags & CINT5FLAG) >> 1); - dsp_check_irqs(); + if (IMASKCleared) // If IMASK was cleared, +#ifdef DSP_DEBUG_IRQ + { + WriteLog("DSP: Finished interrupt.\n"); +#endif + DSPHandleIRQs(); // see if any other interrupts need servicing! +#ifdef DSP_DEBUG_IRQ + } +#endif break; + } case 0x04: dsp_matrix_control = data; break; @@ -514,1443 +684,1003 @@ void dsp_long_write(unsigned offset, unsigned data) break; case 0x10: dsp_pc = data; +#ifdef DSP_DEBUG + WriteLog("DSP: Setting DSP PC to %08X by %s%s\n", dsp_pc, whoName[who], (DSP_RUNNING ? " (DSP is RUNNING!)" : ""));//*/ +#endif break; case 0x14: { - uint32 dsp_was_running = dsp_running; - // check for DSP->CPU interrupt - if (data & 0x02) +// uint32 dsp_was_running = DSP_RUNNING; + // Check for DSP -> CPU interrupt + if (data & CPUINT) { -// fprintf(log_get(),"DSP->CPU interrupt\n"); - if (tom_irq_enabled(IRQ_GPU) && jaguar_interrupt_handler_is_valid(64)) +// WriteLog("DSP: DSP -> CPU interrupt\n"); +// This was WRONG +// Why do we check for a valid handler at 64? Isn't that the Jag programmer's responsibility? + if (JERRYIRQEnabled(IRQ2_DSP) && jaguar_interrupt_handler_is_valid(64)) { - tom_set_pending_gpu_int(); -// s68000interrupt(7,64); -// s68000flushInterrupts(); - m68k_set_irq(7); // Set 68000 NMI... + JERRYSetPendingIRQ(IRQ2_DSP); dsp_releaseTimeslice(); + m68k_set_irq(7); // Set 68000 NMI... } - data &= ~(0x02); + data &= ~CPUINT; } - // check for CPU->DSP interrupt - if (data & 0x04) + // Check for CPU -> DSP interrupt + if (data & DSPINT0) { -// fprintf(log_get(),"CPU->DSP interrupt\n"); - dsp_set_irq_line(0, 1); -// s68000releaseTimeslice(); +// WriteLog("DSP: CPU -> DSP interrupt\n"); m68k_end_timeslice(); gpu_releaseTimeslice(); - data &= ~(0x04); + DSPSetIRQLine(DSPIRQ_CPU, ASSERT_LINE); + data &= ~DSPINT0; } // single stepping - if (data & 0x10) + if (data & SINGLE_STEP) { - //fprintf(log_get(),"asked to perform a single step (single step is %senabled)\n",(data&0x8)?"":"not "); +// WriteLog("DSP: Asked to perform a single step (single step is %senabled)\n", (data & 0x8 ? "" : "not ")); } - dsp_control = data; + + // Protect writes to VERSION and the interrupt latches... + uint32 mask = VERSION | INT_LAT0 | INT_LAT1 | INT_LAT2 | INT_LAT3 | INT_LAT4 | INT_LAT5; + dsp_control = (dsp_control & mask) | (data & ~mask); // if dsp wasn't running but is now running // execute a few cycles +//This is just plain wrong, wrong, WRONG! #ifndef DSP_SINGLE_STEPPING - if (!dsp_was_running && dsp_running) +/* if (!dsp_was_running && DSP_RUNNING) { - dsp_exec(200); - } + DSPExec(200); + }*/ #else +//This is WRONG! !!! FIX !!! if (dsp_control & 0x18) - dsp_exec(1); + DSPExec(1); #endif +#ifdef DSP_DEBUG +WriteLog("Write to DSP CTRL: %08X ", data); +if (DSP_RUNNING) + WriteLog(" --> Starting to run at %08X by %s...", dsp_pc, whoName[who]); +else + WriteLog(" --> Stopped by %s! (DSP PC: %08X)", whoName[who], dsp_pc); +WriteLog("\n"); +#endif // DSP_DEBUG +//This isn't exactly right either--we don't know if it was the M68K or the GPU writing here... +// !!! FIX !!! + if (DSP_RUNNING) + m68k_end_timeslice(); break; } case 0x18: dsp_modulo = data; break; case 0x1C: - dsp_div_control=data; + dsp_div_control = data; break; // default: // unaligned long read //__asm int 3 } return; } - 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) -{ - uint32 romSize; - uint8 * rom; - - rom = jaguar_rom_load(path, &romSize); - for(uint32 i=0; i>16) & 0xFFFF, DSP); +// JaguarWriteWord(offset+2, data & 0xFFFF, DSP); + JaguarWriteLong(offset, data, who); } - -void dsp_check_if_i2s_interrupt_needed(void) +// +// Update the DSP register file pointers depending on REGPAGE bit +// +void DSPUpdateRegisterBanks(void) { -// Commenting this shit out helped a little bit... This is probably the reason -// why the sound isn't working right! -/* static uint32 count=8; - -// int mask; - count--; - if (count>0) - return; - - count=4;*/ - // already in an interrupt handler ? - if (dsp_flags & 0x8) - return; + int bank = (dsp_flags & REGPAGE); - // get the interrupt mask - int mask = (dsp_flags >> 4) & 0x1f; - mask |= (dsp_flags >> 11) & 0x20; + if (dsp_flags & IMASK) + bank = 0; // IMASK forces main bank to be bank 0 - if (mask & 0x02) - dsp_set_irq_line(1, 1); + if (bank) + dsp_reg = dsp_reg_bank_1, dsp_alternate_reg = dsp_reg_bank_0; + else + dsp_reg = dsp_reg_bank_0, dsp_alternate_reg = dsp_reg_bank_1; } -void dsp_check_irqs(void) +// +// Check for an handle any asserted DSP IRQs +// +void DSPHandleIRQs(void) { - int bits, mask, which = 0; - - if (dsp_flags & 0x8) + if (dsp_flags & IMASK) // Bail if we're already inside an interrupt return; - // get the active interrupt bits - bits = (dsp_control >> 6) & 0x1f; - bits |= (dsp_control >> 10) & 0x20; + // Get the active interrupt bits (latches) & interrupt mask (enables) + uint32 bits = ((dsp_control >> 10) & 0x20) | ((dsp_control >> 6) & 0x1F), + mask = ((dsp_flags >> 11) & 0x20) | ((dsp_flags >> 4) & 0x1F); - // get the interrupt mask - mask = (dsp_flags >> 4) & 0x1f; - mask |= (dsp_flags >> 11) & 0x20; - -// fprintf(log_get(),"dsp: bits=%.2x mask=%.2x\n",bits,mask); - // bail if nothing is available +// WriteLog("dsp: bits=%.2x mask=%.2x\n",bits,mask); bits &= mask; - if (!bits) + if (!bits) // Bail if nothing is enabled return; - // determine which interrupt - if (bits & 0x01) which = 0; - if (bits & 0x02) which = 1; - if (bits & 0x04) which = 2; - if (bits & 0x08) which = 3; - if (bits & 0x10) which = 4; - if (bits & 0x20) which = 5; - -// fprintf(log_get(),"dsp: generating interrupt %i\n",which); + int which = 0; // Determine which interrupt + if (bits & 0x01) + which = 0; + if (bits & 0x02) + which = 1; + if (bits & 0x04) + which = 2; + if (bits & 0x08) + which = 3; + if (bits & 0x10) + which = 4; + if (bits & 0x20) + which = 5; + +#ifdef DSP_DEBUG_IRQ + WriteLog("DSP: Generating interrupt #%i...\n", which); +#endif - dsp_flags |= 0x08; - dsp_update_register_banks(); + dsp_flags |= IMASK; + DSPUpdateRegisterBanks(); // subqt #4,r31 ; pre-decrement stack pointer // move pc,r30 ; address of interrupted code // store r30,(r31) ; store return address dsp_reg[31] -= 4; - dsp_reg[30]=dsp_pc; - dsp_long_write(dsp_reg[31], dsp_pc - 2); + DSPWriteLong(dsp_reg[31], dsp_pc - 2, DSP); // movei #service_address,r30 ; pointer to ISR entry // jump (r30) ; jump to ISR // nop - dsp_pc = DSP_WORK_RAM_BASE; - dsp_pc += which * 0x10; - dsp_reg[30]=dsp_pc; + dsp_pc = dsp_reg[30] = DSP_WORK_RAM_BASE + (which * 0x10); } -void dsp_set_irq_line(int irqline, int state) +// +// Set the specified DSP IRQ line to a given state +// +void DSPSetIRQLine(int irqline, int state) { - int mask = 0x40 << irqline; - dsp_control &= ~mask; +//NOTE: This doesn't take INT_LAT5 into account. !!! FIX !!! + uint32 mask = INT_LAT0 << irqline; + dsp_control &= ~mask; // Clear the latch bit + if (state) { - dsp_control |= mask; - dsp_check_irqs(); + dsp_control |= mask; // Set the latch bit + DSPHandleIRQs(); } } -void dsp_init(void) +void DSPInit(void) { memory_malloc_secure((void **)&dsp_ram_8, 0x2000, "DSP work RAM"); - memory_malloc_secure((void **)&dsp_reg, 32*sizeof(int32), "DSP bank 0 regs"); - memory_malloc_secure((void **)&dsp_alternate_reg, 32*sizeof(int32), "DSP bank 1 regs"); + memory_malloc_secure((void **)&dsp_reg_bank_0, 32 * sizeof(int32), "DSP bank 0 regs"); + memory_malloc_secure((void **)&dsp_reg_bank_1, 32 * sizeof(int32), "DSP bank 1 regs"); dsp_build_branch_condition_table(); - dsp_reset(); + DSPReset(); } -void dsp_reset(void) +void DSPReset(void) { - dsp_pc = 0x00f1b000; + dsp_pc = 0x00F1B000; dsp_acc = 0x00000000; dsp_remain = 0x00000000; dsp_modulo = 0xFFFFFFFF; dsp_flags = 0x00040000; dsp_matrix_control = 0x00000000; dsp_pointer_to_matrix = 0x00000000; - dsp_data_organization = 0xffffffff; - dsp_control = 0x00012800; + dsp_data_organization = 0xFFFFFFFF; + dsp_control = 0x00002000; // Report DSP version 2 dsp_div_control = 0x00000000; dsp_in_exec = 0; - for(int i=0; i<32; i++) - { - dsp_reg[i] = 0x00000000; - dsp_alternate_reg[i] = 0x00000000; - } - - dsp_reg_bank_0 = dsp_reg; - dsp_reg_bank_1 = dsp_alternate_reg; -// dsp_reg_bank_1 = dsp_reg; -// dsp_reg_bank_0 = dsp_alternate_reg; + dsp_reg = dsp_reg_bank_0; + dsp_alternate_reg = dsp_reg_bank_1; - reset_flag_z(); - reset_flag_n(); - reset_flag_c(); + for(int i=0; i<32; i++) + dsp_reg[i] = dsp_alternate_reg[i] = 0x00000000; - dsp_alternate_flag_z = 0; - dsp_alternate_flag_n = 0; - dsp_alternate_flag_c = 0; + CLR_ZNC; dsp_reset_stats(); memset(dsp_ram_8, 0xFF, 0x2000); } -void dsp_done(void) +void DSPDumpDisassembly(void) +{ + char buffer[512]; + + WriteLog("\n---[DSP code at 00F1B000]---------------------------\n"); + uint32 j = 0xF1B000; + while (j <= 0xF1CFFF) + { + uint32 oldj = j; + j += dasmjag(JAGUAR_DSP, buffer, j); + WriteLog("\t%08X: %s\n", oldj, buffer); + } +} + +void DSPDumpRegisters(void) +{ +//Shoud add modulus, etc to dump here... + WriteLog("\n---[DSP flags: NCZ %d%d%d, DSP PC: %08X]------------\n", dsp_flag_n, dsp_flag_c, dsp_flag_z, dsp_pc); + WriteLog("\nRegisters bank 0\n"); + for(int j=0; j<8; j++) + { + WriteLog("\tR%02i = %08X R%02i = %08X R%02i = %08X R%02i = %08X\n", + (j << 2) + 0, dsp_reg_bank_0[(j << 2) + 0], + (j << 2) + 1, dsp_reg_bank_0[(j << 2) + 1], + (j << 2) + 2, dsp_reg_bank_0[(j << 2) + 2], + (j << 2) + 3, dsp_reg_bank_0[(j << 2) + 3]); + } + WriteLog("Registers bank 1\n"); + for(int j=0; j<8; j++) + { + WriteLog("\tR%02i = %08X R%02i = %08X R%02i = %08X R%02i = %08X\n", + (j << 2) + 0, dsp_reg_bank_1[(j << 2) + 0], + (j << 2) + 1, dsp_reg_bank_1[(j << 2) + 1], + (j << 2) + 2, dsp_reg_bank_1[(j << 2) + 2], + (j << 2) + 3, dsp_reg_bank_1[(j << 2) + 3]); + } +} + +void DSPDone(void) { int i, j; - fprintf(log_get(), "DSP: Stopped at PC=%08X dsp_modulo=%08X(dsp %s running)\n", dsp_pc, dsp_modulo, dsp_running ? "was" : "wasn't"); - fprintf(log_get(), "DSP: %sin interrupt handler\n", (dsp_flags & 0x8) ? "" : "not "); - int bits, mask; + WriteLog("DSP: Stopped at PC=%08X dsp_modulo=%08X (dsp %s running)\n", dsp_pc, dsp_modulo, (DSP_RUNNING ? "was" : "wasn't")); + WriteLog("DSP: %sin interrupt handler\n", (dsp_flags & IMASK ? "" : "not ")); // get the active interrupt bits - bits = (dsp_control >> 6) & 0x1F; - bits |= (dsp_control >> 10) & 0x20; - + int bits = ((dsp_control >> 10) & 0x20) | ((dsp_control >> 6) & 0x1F); // get the interrupt mask - mask = (dsp_flags >> 4) & 0x1F; - mask |= (dsp_flags >> 11) & 0x20; + int mask = ((dsp_flags >> 11) & 0x20) | ((dsp_flags >> 4) & 0x1F); - fprintf(log_get(), "DSP: bits=%08X mask=%08X\n", bits, mask); - fprintf(log_get(), "\nRegisters bank 0\n"); + WriteLog("DSP: pending=%08X enabled=%08X\n", bits, mask); + WriteLog("\nRegisters bank 0\n"); for(int j=0; j<8; j++) { - fprintf(log_get(), "\tr%2i=0x%.8x r%2i=0x%.8x r%2i=0x%.8x r%2i=0x%.8x\n", - (j << 2) + 0, dsp_reg[(j << 2) + 0], - (j << 2) + 1, dsp_reg[(j << 2) + 1], - (j << 2) + 2, dsp_reg[(j << 2) + 2], - (j << 2) + 3, dsp_reg[(j << 2) + 3]); + WriteLog("\tr%2i=0x%.8x r%2i=0x%.8x r%2i=0x%.8x r%2i=0x%.8x\n", + (j << 2) + 0, dsp_reg_bank_0[(j << 2) + 0], + (j << 2) + 1, dsp_reg_bank_0[(j << 2) + 1], + (j << 2) + 2, dsp_reg_bank_0[(j << 2) + 2], + (j << 2) + 3, dsp_reg_bank_0[(j << 2) + 3]); } -// fprintf(log_get(),"registers bank 1\n"); -// for (j=0;j<8;j++) -// { -// fprintf(log_get(),"\tr%2i=0x%.8x r%2i=0x%.8x r%2i=0x%.8x r%2i=0x%.8x\n", -// (j<<2)+0,dsp_alternate_reg[(j<<2)+0], -// (j<<2)+1,dsp_alternate_reg[(j<<2)+1], -// (j<<2)+2,dsp_alternate_reg[(j<<2)+2], -// (j<<2)+3,dsp_alternate_reg[(j<<2)+3]); -// -// } + WriteLog("\nRegisters bank 1\n"); + for (j=0; j<8; j++) + { + WriteLog("\tr%2i=0x%.8x r%2i=0x%.8x r%2i=0x%.8x r%2i=0x%.8x\n", + (j << 2) + 0, dsp_reg_bank_1[(j << 2) + 0], + (j << 2) + 1, dsp_reg_bank_1[(j << 2) + 1], + (j << 2) + 2, dsp_reg_bank_1[(j << 2) + 2], + (j << 2) + 3, dsp_reg_bank_1[(j << 2) + 3]); + + } + static char buffer[512]; j = DSP_WORK_RAM_BASE; -// for(int i=0; i<4096; i++) while (j <= 0xF1BFFF) { uint32 oldj = j; j += dasmjag(JAGUAR_DSP, buffer, j); - fprintf(log_get(), "\t%08X: %s\n", oldj, buffer); + WriteLog("\t%08X: %s\n", oldj, buffer); }//*/ - fprintf(log_get(),"dsp opcodes use:\n"); + WriteLog("DSP opcodes use:\n"); for (i=0;i<64;i++) { if (dsp_opcode_use[i]) - fprintf(log_get(),"\t%s %i\n",dsp_opcode_str[i],dsp_opcode_use[i]); + WriteLog("\t%s %i\n", dsp_opcode_str[i], dsp_opcode_use[i]); }//*/ memory_free(dsp_ram_8); } -void dsp_exec(int32 cycles) +// +// DSP execution core +// +static bool R20Set = false, tripwire = false; +static uint32 pcQueue[32], ptrPCQ = 0; +void DSPExec(int32 cycles) { - if ((cycles!=1)&&(jaguar_mainRom_crc32==0xba74c3ed)) - dsp_check_if_i2s_interrupt_needed(); +/*HACKS!!! -> if (cycles != 1 && jaguar_mainRom_crc32 == 0xba74c3ed) + dsp_check_if_i2s_interrupt_needed();*/ #ifdef DSP_SINGLE_STEPPING - if (dsp_control&0x18) + if (dsp_control & 0x18) { - cycles=1; - dsp_control&=~0x10; + cycles = 1; + dsp_control &= ~0x10; } #endif - dsp_check_irqs(); - dsp_releaseTimeSlice_flag=0; +//There is *no* good reason to do this here! +// DSPHandleIRQs(); + dsp_releaseTimeSlice_flag = 0; dsp_in_exec++; - while ((cycles>0)&&(dsp_running)) - { - dsp_flag_c=(dsp_flag_c?1:0); - dsp_flag_z=(dsp_flag_z?1:0); - dsp_flag_n=(dsp_flag_n?1:0); - -/* - if (dsp_pc==0x00f1b02c) - { - if (dsp_fp) - { - fclose(dsp_fp); - exit(0); - } - } - else - if (dsp_pc==0x00f1b032) - { - dsp_fp=fopen("c:\\bad.log","wrt"); - if (dsp_fp==NULL) - MessageBox(NULL,"Cannot open dsp log","",MB_OK); - } - if (dsp_fp) - { - fprintf(dsp_fp,"0x%.8x\n",dsp_pc); - } - -// if (dsp_pc==0x00f1b130) -// dsp_load_bin_at("SCHRIFT.DAT",0x120000); -*/ - uint16 opcode=dsp_word_read(dsp_pc); - dsp_opcode_first_parameter=(opcode&0x3e0)>>5; - dsp_opcode_second_parameter=(opcode&0x1f); - dsp_pc+=2; - dsp_opcode[opcode>>10](); - dsp_opcode_use[opcode>>10]++; - cycles-=dsp_opcode_cycles[opcode>>10]; + while (cycles > 0 && DSP_RUNNING) + { +if (dsp_pc == 0xF1B5D8) +{ + WriteLog("DSP: At $F1B4D8--R15 = %08X at %u ms%s...\n", dsp_reg[15], SDL_GetTicks(), (dsp_flags & IMASK ? " (inside interrupt)" : "")); +} +/*if (dsp_pc == 0xF1B7D2) // Start here??? + doDSPDis = true; +pcQueue[ptrPCQ++] = dsp_pc; +ptrPCQ %= 32;*/ + uint16 opcode = DSPReadWord(dsp_pc, DSP); + uint32 index = opcode >> 10; + dsp_opcode_first_parameter = (opcode >> 5) & 0x1F; + dsp_opcode_second_parameter = opcode & 0x1F; + dsp_pc += 2; + dsp_opcode[index](); + dsp_opcode_use[index]++; + cycles -= dsp_opcode_cycles[index]; +/*if (dsp_reg_bank_0[20] == 0xF1A100 & !R20Set) +{ + WriteLog("DSP: R20 set to $F1A100 at %u ms%s...\n", SDL_GetTicks(), (dsp_flags & IMASK ? " (inside interrupt)" : "")); + R20Set = true; +} +if (dsp_reg_bank_0[20] != 0xF1A100 && R20Set) +{ + WriteLog("DSP: R20 corrupted at %u ms from starting%s!\nAborting!\n", SDL_GetTicks(), (dsp_flags & IMASK ? " (inside interrupt)" : "")); + DSPDumpRegisters(); + DSPDumpDisassembly(); + exit(1); +} +if ((dsp_pc < 0xF1B000 || dsp_pc > 0xF1CFFE) && !tripwire) +{ + char buffer[512]; + WriteLog("DSP: Jumping outside of DSP RAM at %u ms. Register dump:\n", SDL_GetTicks()); + DSPDumpRegisters(); + tripwire = true; + WriteLog("\nBacktrace:\n"); + for(int i=0; i<32; i++) + { + dasmjag(JAGUAR_DSP, buffer, pcQueue[(ptrPCQ + i) % 32]); + WriteLog("\t%08X: %s\n", pcQueue[(ptrPCQ + i) % 32], buffer); + } + WriteLog("\n"); +}*/ } + dsp_in_exec--; } +// +// DSP opcode handlers +// + +// There is a problem here with interrupt handlers the JUMP and JR instructions that +// can cause trouble because an interrupt can occur *before* the instruction following the +// jump can execute... !!! FIX !!! static void dsp_opcode_jump(void) { - uint32 delayed_pc = Rm; - uint32 jaguar_flags; - +#ifdef DSP_DIS_JUMP +char * condition[32] = +{ "T", "nz", "z", "???", "nc", "nc nz", "nc z", "???", "c", "c nz", + "c z", "???", "???", "???", "???", "???", "???", "???", "???", + "???", "nn", "nn nz", "nn z", "???", "n", "n nz", "n z", "???", + "???", "???", "???", "F" }; + if (doDSPDis) + WriteLog("%06X: JUMP %s, (R%02u) [NCZ:%u%u%u, R%02u=%08X] ", dsp_pc-2, condition[IMM_2], IMM_1, dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_1, RM); +#endif // normalize flags - dsp_flag_c=dsp_flag_c?1:0; +/* dsp_flag_c=dsp_flag_c?1:0; dsp_flag_z=dsp_flag_z?1:0; - dsp_flag_n=dsp_flag_n?1:0; - - jaguar_flags=(dsp_flag_n<<2)|(dsp_flag_c<<1)|dsp_flag_z; + dsp_flag_n=dsp_flag_n?1:0;*/ + // KLUDGE: Used by BRANCH_CONDITION + uint32 jaguar_flags = (dsp_flag_n << 2) | (dsp_flag_c << 1) | dsp_flag_z; - if (branch_condition(imm_2)) + if (BRANCH_CONDITION(IMM_2)) { - dsp_exec(1); - dsp_pc=delayed_pc; +#ifdef DSP_DIS_JUMP + if (doDSPDis) + WriteLog("Branched!\n"); +#endif + uint32 delayed_pc = RM; + DSPExec(1); + dsp_pc = delayed_pc; } +#ifdef DSP_DIS_JUMP + else + if (doDSPDis) + WriteLog("Branch NOT taken.\n"); +#endif } static void dsp_opcode_jr(void) { - int32 offset=(imm_1&0x10) ? (0xFFFFFFF0|imm_1) : imm_1; - - int32 delayed_pc = dsp_pc + (offset * 2); - uint32 jaguar_flags; - +#ifdef DSP_DIS_JR +char * condition[32] = +{ "T", "nz", "z", "???", "nc", "nc nz", "nc z", "???", "c", "c nz", + "c z", "???", "???", "???", "???", "???", "???", "???", "???", + "???", "nn", "nn nz", "nn z", "???", "n", "n nz", "n z", "???", + "???", "???", "???", "F" }; + if (doDSPDis) + WriteLog("%06X: JR %s, %06X [NCZ:%u%u%u] ", dsp_pc-2, condition[IMM_2], dsp_pc+((IMM_1 & 0x10 ? 0xFFFFFFF0 | IMM_1 : IMM_1) * 2), dsp_flag_n, dsp_flag_c, dsp_flag_z); +#endif // normalize flags - dsp_flag_c=dsp_flag_c?1:0; +/* dsp_flag_c=dsp_flag_c?1:0; dsp_flag_z=dsp_flag_z?1:0; - dsp_flag_n=dsp_flag_n?1:0; - - jaguar_flags=(dsp_flag_n<<2)|(dsp_flag_c<<1)|dsp_flag_z; + dsp_flag_n=dsp_flag_n?1:0;*/ + // KLUDGE: Used by BRANCH_CONDITION + uint32 jaguar_flags = (dsp_flag_n << 2) | (dsp_flag_c << 1) | dsp_flag_z; - if (branch_condition(imm_2)) + if (BRANCH_CONDITION(IMM_2)) { - dsp_exec(1); - dsp_pc=delayed_pc; +#ifdef DSP_DIS_JR + if (doDSPDis) + WriteLog("Branched!\n"); +#endif + int32 offset = (IMM_1 & 0x10 ? 0xFFFFFFF0 | IMM_1 : IMM_1); // Sign extend IMM_1 + int32 delayed_pc = dsp_pc + (offset * 2); + DSPExec(1); + dsp_pc = delayed_pc; } +#ifdef DSP_DIS_JR + else + if (doDSPDis) + WriteLog("Branch NOT taken.\n"); +#endif } static void dsp_opcode_add(void) { - uint32 _Rm=Rm; - uint32 _Rn=Rn; - uint32 res; -#ifdef __PORT__ - - /* - GCC on WIN32 (more importantly mingw) doesn't know the declared - variables in asm until we put a _ before it. - - So the declaration dsp_flag_c needs to be _dsp_flag_c on mingw. - */ - #ifdef __GCCWIN32__ - asm( - "addl %1, %2 - setc _dsp_flag_c - setz _dsp_flag_z - sets _dsp_flag_n - movl %%eax, %0 - " - : "=m"(res) - : "d"(_Rm), "a"(_Rn)); - - #else - asm( - "addl %1, %2 - setc dsp_flag_c - setz dsp_flag_z - sets dsp_flag_n - movl %%eax, %0 - " - : "=m"(res) - : "d"(_Rm), "a"(_Rn)); - #endif - -#else - __asm - { - mov edx,_Rm - mov eax,_Rn - add eax,edx - setc [dsp_flag_c] - setz [dsp_flag_z] - sets [dsp_flag_n] - mov res,eax - }; +#ifdef DSP_DIS_ADD + if (doDSPDis) + WriteLog("%06X: ADD R%02u, R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", dsp_pc-2, IMM_1, IMM_2, dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_1, RM, IMM_2, RN); +#endif + UINT32 res = RN + RM; + SET_ZNC_ADD(RN, RM, res); + RN = res; +#ifdef DSP_DIS_ADD + if (doDSPDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_1, RM, IMM_2, RN); #endif - Rn=res; } static void dsp_opcode_addc(void) { - uint32 _Rm=Rm; - uint32 _Rn=Rn; - uint32 res; -#ifdef __PORT__ - - /* - GCC on WIN32 (more importantly mingw) doesn't know the declared - variables in asm until we put a _ before it. - - So the declaration dsp_flag_c needs to be _dsp_flag_c on mingw. - We use __GCCWIN32__ for this "bug". - */ - - #ifdef __GCCWIN32__ - - asm( - "addl %1, %2 - cmp $0, _dsp_flag_c - clc - jz 1f - stc - 1: - adc %1, %2 - setc _dsp_flag_c - setz _dsp_flag_z - sets _dsp_flag_n - movl %%eax, %0 - " - : "=m"(res) - : "d"(_Rm), "a"(_Rn)); - #else - - asm( - "addl %1, %2 - cmp $0, dsp_flag_c - clc - jz 1f - stc - 1: - adc %1, %2 - setc dsp_flag_c - setz dsp_flag_z - sets dsp_flag_n - movl %%eax, %0 - " - : "=m"(res) - : "d"(_Rm), "a"(_Rn)); - - #endif - -#else - __asm - { - mov edx,_Rm - mov eax,_Rn - cmp [dsp_flag_c],0 - clc - jz dsp_opcode_addc_no_carry - stc -dsp_opcode_addc_no_carry: - adc eax,edx - setc [dsp_flag_c] - setz [dsp_flag_z] - sets [dsp_flag_n] - mov res,eax - }; -#endif - Rn=res; +#ifdef DSP_DIS_ADDC + if (doDSPDis) + WriteLog("%06X: ADDC R%02u, R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", dsp_pc-2, IMM_1, IMM_2, dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_1, RM, IMM_2, RN); +#endif + UINT32 res = RN + RM + dsp_flag_c; + UINT32 carry = dsp_flag_c; +// SET_ZNC_ADD(RN, RM, res); //???BUG??? Yes! + SET_ZNC_ADD(RN + carry, RM, res); +// SET_ZNC_ADD(RN, RM + carry, res); + RN = res; +#ifdef DSP_DIS_ADDC + if (doDSPDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_1, RM, IMM_2, RN); +#endif } static void dsp_opcode_addq(void) { - uint32 _Rn=Rn; - uint32 _Rm=dsp_convert_zero[imm_1]; - uint32 res; - -#ifdef __PORT__ - - /* - GCC on WIN32 (more importantly mingw) doesn't know the declared - variables in asm until we put a _ before it. - - So the declaration dsp_flag_c needs to be _dsp_flag_c on mingw. - */ - - #ifdef __GCCWIN32__ - - asm( - "addl %1, %2 - setc _dsp_flag_c - setz _dsp_flag_z - sets _dsp_flag_n - movl %%eax, %0 - " - : "=m"(res) - : "d"(_Rm), "a"(_Rn)); - - #else - - asm( - "addl %1, %2 - setc dsp_flag_c - setz dsp_flag_z - sets dsp_flag_n - movl %%eax, %0 - " - : "=m"(res) - : "d"(_Rm), "a"(_Rn)); - - #endif - -#else - __asm - { - mov edx,_Rm - mov eax,_Rn - add eax,edx - setc [dsp_flag_c] - setz [dsp_flag_z] - sets [dsp_flag_n] - mov res,eax - }; +#ifdef DSP_DIS_ADDQ + if (doDSPDis) + WriteLog("%06X: ADDQ #%u, R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", dsp_pc-2, dsp_convert_zero[IMM_1], IMM_2, dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_2, RN); +#endif + UINT32 r1 = dsp_convert_zero[IMM_1]; + UINT32 res = RN + r1; + CLR_ZNC; SET_ZNC_ADD(RN, r1, res); + RN = res; +#ifdef DSP_DIS_ADDQ + if (doDSPDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_2, RN); #endif - Rn=res; } static void dsp_opcode_sub(void) { - uint32 _Rm=Rm; - uint32 _Rn=Rn; - uint32 res; -#ifdef __PORT__ - - /* - GCC on WIN32 (more importantly mingw) doesn't know the declared - variables in asm until we put a _ before it. - - So the declaration dsp_flag_c needs to be _dsp_flag_c on mingw. - */ - - #ifdef __GCCWIN32__ - - asm( - "subl %1, %2 - setc _dsp_flag_c - setz _dsp_flag_z - sets _dsp_flag_n - movl %%eax, %0 - " - : "=m"(res) - : "d"(_Rm), "a"(_Rn)); - - #else - - asm( - "subl %1, %2 - setc dsp_flag_c - setz dsp_flag_z - sets dsp_flag_n - movl %%eax, %0 - " - : "=m"(res) - : "d"(_Rm), "a"(_Rn)); - - #endif - -#else - __asm - { - mov eax,_Rn - mov edx,_Rm - sub eax,edx - setc [dsp_flag_c] - setz [dsp_flag_z] - sets [dsp_flag_n] - mov res,eax - }; +#ifdef DSP_DIS_SUB + if (doDSPDis) + WriteLog("%06X: SUB R%02u, R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", dsp_pc-2, IMM_1, IMM_2, dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_1, RM, IMM_2, RN); +#endif + UINT32 res = RN - RM; + SET_ZNC_SUB(RN, RM, res); + RN = res; +#ifdef DSP_DIS_SUB + if (doDSPDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_1, RM, IMM_2, RN); #endif - Rn=res; } static void dsp_opcode_subc(void) { - uint32 _Rm=Rm; - uint32 _Rn=Rn; - uint32 res; -#ifdef __PORT__ - - /* - GCC on WIN32 (more importantly mingw) doesn't know the declared - variables in asm until we put a _ before it. - - So the declaration dsp_flag_c needs to be _dsp_flag_c on mingw. - */ - - #ifdef __GCCWIN32__ - - asm( - "addl %1, %2 - cmp $0, _dsp_flag_c - clc - jz 1f - stc - 1: - sbb %1, %2 - setc _dsp_flag_c - setz _dsp_flag_z - sets _dsp_flag_n - movl %%eax, %0 - " - : "=m"(res) - : "d"(_Rm), "a"(_Rn)); - - #else - - asm( - "addl %1, %2 - cmp $0, dsp_flag_c - clc - jz 1f - stc - 1: - sbb %1, %2 - setc dsp_flag_c - setz dsp_flag_z - sets dsp_flag_n - movl %%eax, %0 - " - : "=m"(res) - : "d"(_Rm), "a"(_Rn)); - - #endif - -#else - __asm - { - mov edx,_Rm - mov eax,_Rn - cmp [dsp_flag_c],0 - clc - jz dsp_opcode_subc_no_carry - stc -dsp_opcode_subc_no_carry: - sbb eax,edx - setc [dsp_flag_c] - setz [dsp_flag_z] - sets [dsp_flag_n] - mov res,eax - }; -#endif - Rn=res; +#ifdef DSP_DIS_SUBC + if (doDSPDis) + WriteLog("%06X: SUBC R%02u, R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", dsp_pc-2, IMM_1, IMM_2, dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_1, RM, IMM_2, RN); +#endif + UINT32 res = RN - RM - dsp_flag_c; + UINT32 borrow = dsp_flag_c; + SET_ZNC_SUB(RN - borrow, RM, res); + RN = res; +#ifdef DSP_DIS_SUBC + if (doDSPDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_1, RM, IMM_2, RN); +#endif } static void dsp_opcode_subq(void) { - uint32 _Rm=dsp_convert_zero[imm_1]; - uint32 _Rn=Rn; - uint32 res; -#ifdef __PORT__ - - /* - GCC on WIN32 (more importantly mingw) doesn't know the declared - variables in asm until we put a _ before it. - - So the declaration dsp_flag_c needs to be _dsp_flag_c on mingw. - */ - - #ifdef __GCCWIN32__ - - asm( - "subl %1, %2 - setc _dsp_flag_c - setz _dsp_flag_z - sets _dsp_flag_n - movl %%eax, %0 - " - : "=m"(res) - : "d"(_Rm), "a"(_Rn)); - - #else - - asm( - "subl %1, %2 - setc dsp_flag_c - setz dsp_flag_z - sets dsp_flag_n - movl %%eax, %0 - " - : "=m"(res) - : "d"(_Rm), "a"(_Rn)); - - #endif -#else - __asm - { - mov eax,_Rn - mov edx,_Rm - sub eax,edx - setc [dsp_flag_c] - setz [dsp_flag_z] - sets [dsp_flag_n] - mov res,eax - }; +#ifdef DSP_DIS_SUBQ + if (doDSPDis) + WriteLog("%06X: SUBQ #%u, R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", dsp_pc-2, dsp_convert_zero[IMM_1], IMM_2, dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_2, RN); +#endif + UINT32 r1 = dsp_convert_zero[IMM_1]; + UINT32 res = RN - r1; + SET_ZNC_SUB(RN, r1, res); + RN = res; +#ifdef DSP_DIS_SUBQ + if (doDSPDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_2, RN); #endif - Rn=res; } static void dsp_opcode_cmp(void) { - uint32 _Rm=Rm; - uint32 _Rn=Rn; -#ifdef __PORT__ - - /* - GCC on WIN32 (more importantly mingw) doesn't know the declared - variables in asm until we put a _ before it. - - So the declaration dsp_flag_c needs to be _dsp_flag_c on mingw. - */ - - #ifdef __GCCWIN32__ - - asm( - "cmpl %0, %1 - setc _dsp_flag_c - setz _dsp_flag_z - sets _dsp_flag_n - " - : - : "d"(_Rm), "a"(_Rn)); - - #else - - asm( - "cmpl %0, %1 - setc dsp_flag_c - setz dsp_flag_z - sets dsp_flag_n - " - : - : "d"(_Rm), "a"(_Rn)); - - #endif - -#else - __asm - { - mov eax,_Rn - mov edx,_Rm - cmp eax,edx - setc [dsp_flag_c] - setz [dsp_flag_z] - sets [dsp_flag_n] - }; +#ifdef DSP_DIS_CMP + if (doDSPDis) + WriteLog("%06X: CMP R%02u, R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", dsp_pc-2, IMM_1, IMM_2, dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_1, RM, IMM_2, RN); +#endif + UINT32 res = RN - RM; + SET_ZNC_SUB(RN, RM, res); +#ifdef DSP_DIS_CMP + if (doDSPDis) + WriteLog("[NCZ:%u%u%u]\n", dsp_flag_n, dsp_flag_c, dsp_flag_z); #endif } static void dsp_opcode_cmpq(void) { - static int32 sqtable[32] = { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,-16,-15,-14,-13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1}; - int32 _Rm=sqtable[imm_1&0x1f]; - uint32 _Rn=Rn; -#ifdef __PORT__ - - /* - GCC on WIN32 (more importantly mingw) doesn't know the declared - variables in asm until we put a _ before it. - - So the declaration dsp_flag_c needs to be _dsp_flag_c on mingw. - */ - - #ifdef __GCCWIN32__ - - asm( - "cmpl %0, %1 - setc _dsp_flag_c - setz _dsp_flag_z - sets _dsp_flag_n - " - : - : "d"(_Rm), "a"(_Rn)); - - #else - - asm( - "cmpl %0, %1 - setc dsp_flag_c - setz dsp_flag_z - sets dsp_flag_n - " - : - : "d"(_Rm), "a"(_Rn)); - - #endif - -#else - __asm - { - mov eax,_Rn - mov edx,_Rm - cmp eax,edx - setc [dsp_flag_c] - setz [dsp_flag_z] - sets [dsp_flag_n] - }; + static int32 sqtable[32] = + { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,-16,-15,-14,-13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1 }; +#ifdef DSP_DIS_CMPQ + if (doDSPDis) + WriteLog("%06X: CMPQ #%d, R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", dsp_pc-2, sqtable[IMM_1], IMM_2, dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_2, RN); +#endif + UINT32 r1 = sqtable[IMM_1 & 0x1F]; // I like this better -> (INT8)(jaguar.op >> 2) >> 3; + UINT32 res = RN - r1; + SET_ZNC_SUB(RN, r1, res); +#ifdef DSP_DIS_CMPQ + if (doDSPDis) + WriteLog("[NCZ:%u%u%u]\n", dsp_flag_n, dsp_flag_c, dsp_flag_z); #endif } static void dsp_opcode_and(void) { - uint32 _Rm=Rm; - uint32 _Rn=Rn; - uint32 res; -#ifdef __PORT__ - - /* - GCC on WIN32 (more importantly mingw) doesn't know the declared - variables in asm until we put a _ before it. - - So the declaration dsp_flag_c needs to be _dsp_flag_c on mingw. - */ - - #ifdef __GCCWIN32__ - - asm( - "andl %1, %2 - setz _dsp_flag_z - sets _dsp_flag_n - movl %%eax, %0 - " - : "=m"(res) - : "d"(_Rm), "a"(_Rn)); - - #else - - asm( - "andl %1, %2 - setz dsp_flag_z - sets dsp_flag_n - movl %%eax, %0 - " - : "=m"(res) - : "d"(_Rm), "a"(_Rn)); - - #endif - -#else - __asm - { - mov eax,_Rn - mov edx,_Rm - and eax,edx - setz [dsp_flag_z] - sets [dsp_flag_n] - mov res,eax - }; +#ifdef DSP_DIS_AND + if (doDSPDis) + WriteLog("%06X: AND R%02u, R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", dsp_pc-2, IMM_1, IMM_2, dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_1, RM, IMM_2, RN); +#endif + RN = RN & RM; + SET_ZN(RN); +#ifdef DSP_DIS_AND + if (doDSPDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_1, RM, IMM_2, RN); #endif - Rn=res; } static void dsp_opcode_or(void) { - uint32 _Rm=Rm; - uint32 _Rn=Rn; - uint32 res; -#ifdef __PORT__ - - /* - GCC on WIN32 (more importantly mingw) doesn't know the declared - variables in asm until we put a _ before it. - - So the declaration dsp_flag_c needs to be _dsp_flag_c on mingw. - */ - - #ifdef __GCCWIN32__ - - asm( - "orl %1, %2 - setz _dsp_flag_z - sets _dsp_flag_n - movl %%eax, %0 - " - : "=m"(res) - : "d"(_Rm), "a"(_Rn)); - - #else - - asm( - "orl %1, %2 - setz dsp_flag_z - sets dsp_flag_n - movl %%eax, %0 - " - : "=m"(res) - : "d"(_Rm), "a"(_Rn)); - - #endif - -#else - __asm - { - mov eax,_Rn - mov edx,_Rm - or eax,edx - setz [dsp_flag_z] - sets [dsp_flag_n] - mov res,eax - }; +#ifdef DSP_DIS_OR + if (doDSPDis) + WriteLog("%06X: OR R%02u, R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", dsp_pc-2, IMM_1, IMM_2, dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_1, RM, IMM_2, RN); +#endif + RN = RN | RM; + SET_ZN(RN); +#ifdef DSP_DIS_OR + if (doDSPDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_1, RM, IMM_2, RN); #endif - Rn=res; } static void dsp_opcode_xor(void) { - uint32 _Rm=Rm; - uint32 _Rn=Rn; - uint32 res; -#ifdef __PORT__ - - /* - GCC on WIN32 (more importantly mingw) doesn't know the declared - variables in asm until we put a _ before it. - - So the declaration dsp_flag_c needs to be _dsp_flag_c on mingw. - */ - - #ifdef __GCCWIN32__ - - asm( - "xorl %1, %2 - setz _dsp_flag_z - sets _dsp_flag_n - movl %%eax, %0 - " - : "=m"(res) - : "d"(_Rm), "a"(_Rn)); - - #else - - asm( - "xorl %1, %2 - setz dsp_flag_z - sets dsp_flag_n - movl %%eax, %0 - " - : "=m"(res) - : "d"(_Rm), "a"(_Rn)); - - #endif - -#else - __asm - { - mov eax,_Rn - mov edx,_Rm - xor eax,edx - setz [dsp_flag_z] - sets [dsp_flag_n] - mov res,eax - }; +#ifdef DSP_DIS_XOR + if (doDSPDis) + WriteLog("%06X: XOR R%02u, R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", dsp_pc-2, IMM_1, IMM_2, dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_1, RM, IMM_2, RN); +#endif + RN = RN ^ RM; + SET_ZN(RN); +#ifdef DSP_DIS_XOR + if (doDSPDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_1, RM, IMM_2, RN); #endif - Rn=res; } static void dsp_opcode_not(void) { - uint32 _Rn=Rn; - uint32 res; -#ifdef __PORT__ - - /* - GCC on WIN32 (more importantly mingw) doesn't know the declared - variables in asm until we put a _ before it. - - So the declaration dsp_flag_c needs to be _dsp_flag_c on mingw. - */ - - #ifdef __GCCWIN32__ - - asm( - "notl %1 - setz _dsp_flag_z - sets _dsp_flag_n - movl %%eax, %0 - " - : "=m"(res) - : "a"(_Rn)); - - #else - - asm( - "notl %1 - setz dsp_flag_z - sets dsp_flag_n - movl %%eax, %0 - " - : "=m"(res) - : "a"(_Rn)); - - #endif - -#else - __asm - { - mov eax,_Rn - not eax - setz [dsp_flag_z] - sets [dsp_flag_n] - mov res,eax - }; +#ifdef DSP_DIS_NOT + if (doDSPDis) + WriteLog("%06X: NOT R%02u, R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", dsp_pc-2, IMM_1, IMM_2, dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_1, RM, IMM_2, RN); +#endif + RN = ~RN; + SET_ZN(RN); +#ifdef DSP_DIS_NOT + if (doDSPDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_1, RM, IMM_2, RN); #endif - Rn=res; } static void dsp_opcode_move_pc(void) { - Rn = dsp_pc-2; -} - -static void dsp_opcode_sat8(void) -{ - int32 _Rn=(int32)Rn; - - uint32 res= Rn = (_Rn<0) ? 0 : (_Rn > 0xff ? 0xff : _Rn); - set_flag_z(res); - reset_flag_n(); -} - -static void dsp_opcode_sat16(void) -{ - uint32 _Rn=Rn; - uint32 res= Rn = (_Rn&0x80000000) ? 0 : (_Rn > 0xFFFF ? 0xFFFF : _Rn); - set_flag_z(res); - reset_flag_n(); -} - -static void dsp_opcode_sat24(void) -{ - uint32 _Rn=Rn; - - uint32 res= Rn = (_Rn&0x80000000) ? 0 : (_Rn > 0xFFFFFF ? 0xFFFFFF : _Rn); - set_flag_z(res); - reset_flag_n(); + RN = dsp_pc - 2; } static void dsp_opcode_store_r14_indexed(void) { - dsp_long_write( dsp_reg[14] + (dsp_convert_zero[imm_1] << 2),Rn); +#ifdef DSP_DIS_STORE14I + if (doDSPDis) + WriteLog("%06X: STORE R%02u, (R14+$%02X) [NCZ:%u%u%u, R%02u=%08X, R14+$%02X=%08X]\n", dsp_pc-2, IMM_2, dsp_convert_zero[IMM_1] << 2, dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_2, RN, dsp_convert_zero[IMM_1] << 2, dsp_reg[14]+(dsp_convert_zero[IMM_1] << 2)); +#endif + DSPWriteLong(dsp_reg[15] + (dsp_convert_zero[IMM_1] << 2), RN, DSP); } static void dsp_opcode_store_r15_indexed(void) { - dsp_long_write( dsp_reg[15] + (dsp_convert_zero[imm_1] << 2),Rn); +#ifdef DSP_DIS_STORE15I + if (doDSPDis) + WriteLog("%06X: STORE R%02u, (R15+$%02X) [NCZ:%u%u%u, R%02u=%08X, R15+$%02X=%08X]\n", dsp_pc-2, IMM_2, dsp_convert_zero[IMM_1] << 2, dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_2, RN, dsp_convert_zero[IMM_1] << 2, dsp_reg[15]+(dsp_convert_zero[IMM_1] << 2)); +#endif + DSPWriteLong(dsp_reg[15] + (dsp_convert_zero[IMM_1] << 2), RN, DSP); } static void dsp_opcode_load_r14_ri(void) { - Rn=dsp_long_read(dsp_reg[14] + Rm); +#ifdef DSP_DIS_LOAD14R + if (doDSPDis) + WriteLog("%06X: LOAD (R14+R%02u), R%02u [NCZ:%u%u%u, R14+R%02u=%08X, R%02u=%08X] -> ", dsp_pc-2, IMM_1, IMM_2, dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_1, RM+dsp_reg[14], IMM_2, RN); +#endif + RN = DSPReadLong(dsp_reg[14] + RM, DSP); +#ifdef DSP_DIS_LOAD14R + if (doDSPDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_2, RN); +#endif } static void dsp_opcode_load_r15_ri(void) { - Rn=dsp_long_read(dsp_reg[15] + Rm); +#ifdef DSP_DIS_LOAD15R + if (doDSPDis) + WriteLog("%06X: LOAD (R15+R%02u), R%02u [NCZ:%u%u%u, R15+R%02u=%08X, R%02u=%08X] -> ", dsp_pc-2, IMM_1, IMM_2, dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_1, RM+dsp_reg[15], IMM_2, RN); +#endif + RN = DSPReadLong(dsp_reg[15] + RM, DSP); +#ifdef DSP_DIS_LOAD15R + if (doDSPDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_2, RN); +#endif } static void dsp_opcode_store_r14_ri(void) { - dsp_long_write(dsp_reg[14] + Rm,Rn); + DSPWriteLong(dsp_reg[14] + RM, RN, DSP); } static void dsp_opcode_store_r15_ri(void) { - dsp_long_write(dsp_reg[15] + Rm,Rn); + DSPWriteLong(dsp_reg[15] + RM, RN, DSP); } static void dsp_opcode_nop(void) { -} - -static void dsp_opcode_pack(void) -{ - uint32 _Rn=Rn; - - if (Rm==0) - { - Rn =((_Rn & 0x03C00000) >> 10) | - ((_Rn & 0x0001E000) >> 5) | - ((_Rn & 0x000000FF)); - } - else - { - Rn =((_Rn & 0x0000F000) << 10) | - ((_Rn & 0x00000F00) << 5) | - ((_Rn & 0x000000FF)); - } - reset_flag_z(); - reset_flag_n(); - set_flag_z(Rn); - set_flag_n(Rn); +#ifdef DSP_DIS_NOP + if (doDSPDis) + WriteLog("%06X: NOP [NCZ:%u%u%u]\n", dsp_pc-2, dsp_flag_n, dsp_flag_c, dsp_flag_z); +#endif } static void dsp_opcode_storeb(void) { - if ((Rm >= DSP_WORK_RAM_BASE) && (Rm < (DSP_WORK_RAM_BASE+0x2000))) - dsp_long_write(Rm,Rn&0xff); +#ifdef DSP_DIS_STOREB + if (doDSPDis) + WriteLog("%06X: STOREB R%02u, (R%02u) [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", dsp_pc-2, IMM_2, IMM_1, dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_2, RN, IMM_1, RM); +#endif + if (RM >= DSP_WORK_RAM_BASE && RM <= (DSP_WORK_RAM_BASE + 0x1FFF)) + DSPWriteLong(RM, RN & 0xFF, DSP); else - jaguar_byte_write(Rm,Rn); + JaguarWriteByte(RM, RN, DSP); } static void dsp_opcode_storew(void) { - if ((Rm >= DSP_WORK_RAM_BASE) && (Rm < (DSP_WORK_RAM_BASE+0x2000))) - dsp_long_write(Rm,Rn&0xffff); +#ifdef DSP_DIS_STOREW + if (doDSPDis) + WriteLog("%06X: STOREW R%02u, (R%02u) [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", dsp_pc-2, IMM_2, IMM_1, dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_2, RN, IMM_1, RM); +#endif + if (RM >= DSP_WORK_RAM_BASE && RM <= (DSP_WORK_RAM_BASE + 0x1FFF)) + DSPWriteLong(RM, RN & 0xFFFF, DSP); else - jaguar_word_write(Rm,Rn); + JaguarWriteWord(RM, RN, DSP); } static void dsp_opcode_store(void) { - dsp_long_write(Rm,Rn); +#ifdef DSP_DIS_STORE + if (doDSPDis) + WriteLog("%06X: STORE R%02u, (R%02u) [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", dsp_pc-2, IMM_2, IMM_1, dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_2, RN, IMM_1, RM); +#endif + DSPWriteLong(RM, RN, DSP); } static void dsp_opcode_loadb(void) { - if ((Rm >= DSP_WORK_RAM_BASE) && (Rm < (DSP_WORK_RAM_BASE+0x2000))) - Rn=dsp_long_read(Rm)&0xff; +#ifdef DSP_DIS_LOADB + if (doDSPDis) + WriteLog("%06X: LOADB (R%02u), R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", dsp_pc-2, IMM_1, IMM_2, dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_1, RM, IMM_2, RN); +#endif + if (RM >= DSP_WORK_RAM_BASE && RM <= (DSP_WORK_RAM_BASE + 0x1FFF)) + RN = DSPReadLong(RM, DSP) & 0xFF; else - Rn=jaguar_byte_read(Rm); + RN = JaguarReadByte(RM, DSP); +#ifdef DSP_DIS_LOADB + if (doDSPDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_2, RN); +#endif } static void dsp_opcode_loadw(void) { - if ((Rm >= DSP_WORK_RAM_BASE) && (Rm < (DSP_WORK_RAM_BASE+0x2000))) - Rn=dsp_long_read(Rm)&0xffff; +#ifdef DSP_DIS_LOADW + if (doDSPDis) + WriteLog("%06X: LOADW (R%02u), R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", dsp_pc-2, IMM_1, IMM_2, dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_1, RM, IMM_2, RN); +#endif + if (RM >= DSP_WORK_RAM_BASE && RM <= (DSP_WORK_RAM_BASE + 0x1FFF)) + RN = DSPReadLong(RM, DSP) & 0xFFFF; else - Rn=jaguar_word_read(Rm); + RN = JaguarReadWord(RM, DSP); +#ifdef DSP_DIS_LOADW + if (doDSPDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_2, RN); +#endif } static void dsp_opcode_load(void) { - Rn = dsp_long_read(Rm); +#ifdef DSP_DIS_LOAD + if (doDSPDis) + WriteLog("%06X: LOAD (R%02u), R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", dsp_pc-2, IMM_1, IMM_2, dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_1, RM, IMM_2, RN); +#endif + RN = DSPReadLong(RM, DSP); +#ifdef DSP_DIS_LOAD + if (doDSPDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_2, RN); +#endif } static void dsp_opcode_load_r14_indexed(void) { - Rn = dsp_long_read( dsp_reg[14] + (dsp_convert_zero[imm_1] << 2)); +#ifdef DSP_DIS_LOAD14I + if (doDSPDis) + WriteLog("%06X: LOAD (R14+$%02X), R%02u [NCZ:%u%u%u, R14+$%02X=%08X, R%02u=%08X] -> ", dsp_pc-2, dsp_convert_zero[IMM_1] << 2, IMM_2, dsp_flag_n, dsp_flag_c, dsp_flag_z, dsp_convert_zero[IMM_1] << 2, dsp_reg[14]+(dsp_convert_zero[IMM_1] << 2), IMM_2, RN); +#endif + RN = DSPReadLong(dsp_reg[14] + (dsp_convert_zero[IMM_1] << 2), DSP); +#ifdef DSP_DIS_LOAD14I + if (doDSPDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_2, RN); +#endif } static void dsp_opcode_load_r15_indexed(void) { - Rn = dsp_long_read( dsp_reg[15] + (dsp_convert_zero[imm_1] << 2)); +#ifdef DSP_DIS_LOAD15I + if (doDSPDis) + WriteLog("%06X: LOAD (R15+$%02X), R%02u [NCZ:%u%u%u, R15+$%02X=%08X, R%02u=%08X] -> ", dsp_pc-2, dsp_convert_zero[IMM_1] << 2, IMM_2, dsp_flag_n, dsp_flag_c, dsp_flag_z, dsp_convert_zero[IMM_1] << 2, dsp_reg[15]+(dsp_convert_zero[IMM_1] << 2), IMM_2, RN); +#endif + RN = DSPReadLong(dsp_reg[15] + (dsp_convert_zero[IMM_1] << 2), DSP); +#ifdef DSP_DIS_LOAD15I + if (doDSPDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_2, RN); +#endif } static void dsp_opcode_movei(void) { - Rn = ((uint32)dsp_word_read(dsp_pc)) + (((uint32)dsp_word_read(dsp_pc+2))<<16); - dsp_pc+=4; +#ifdef DSP_DIS_MOVEI + if (doDSPDis) + WriteLog("%06X: MOVEI #$%08X, R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", dsp_pc-2, (uint32)DSPReadWord(dsp_pc) | ((uint32)DSPReadWord(dsp_pc + 2) << 16), IMM_2, dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_2, RN); +#endif + // This instruction is followed by 32-bit value in LSW / MSW format... + RN = (uint32)DSPReadWord(dsp_pc, DSP) | ((uint32)DSPReadWord(dsp_pc + 2, DSP) << 16); + dsp_pc += 4; +#ifdef DSP_DIS_MOVEI + if (doDSPDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_2, RN); +#endif } static void dsp_opcode_moveta(void) { - alternate_Rn = Rm; +#ifdef DSP_DIS_MOVETA + if (doDSPDis) + WriteLog("%06X: MOVETA R%02u, R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u(alt)=%08X] -> ", dsp_pc-2, IMM_1, IMM_2, dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_1, RM, IMM_2, ALTERNATE_RN); +#endif + ALTERNATE_RN = RM; +#ifdef DSP_DIS_MOVETA + if (doDSPDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X, R%02u(alt)=%08X]\n", dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_1, RM, IMM_2, ALTERNATE_RN); +#endif } static void dsp_opcode_movefa(void) { - Rn = alternate_Rm; +#ifdef DSP_DIS_MOVEFA + if (doDSPDis) + WriteLog("%06X: MOVEFA R%02u, R%02u [NCZ:%u%u%u, R%02u(alt)=%08X, R%02u=%08X] -> ", dsp_pc-2, IMM_1, IMM_2, dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_1, ALTERNATE_RM, IMM_2, RN); +#endif + RN = ALTERNATE_RM; +#ifdef DSP_DIS_MOVEFA + if (doDSPDis) + WriteLog("[NCZ:%u%u%u, R%02u(alt)=%08X, R%02u=%08X]\n", dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_1, ALTERNATE_RM, IMM_2, RN); +#endif } static void dsp_opcode_move(void) { - Rn = Rm; +#ifdef DSP_DIS_MOVE + if (doDSPDis) + WriteLog("%06X: MOVE R%02u, R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", dsp_pc-2, IMM_1, IMM_2, dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_1, RM, IMM_2, RN); +#endif + RN = RM; +#ifdef DSP_DIS_MOVE + if (doDSPDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_1, RM, IMM_2, RN); +#endif } static void dsp_opcode_moveq(void) { - Rn = imm_1; +#ifdef DSP_DIS_MOVEQ + if (doDSPDis) + WriteLog("%06X: MOVEQ #%u, R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", dsp_pc-2, IMM_1, IMM_2, dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_2, RN); +#endif + RN = IMM_1; +#ifdef DSP_DIS_MOVEQ + if (doDSPDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_2, RN); +#endif } static void dsp_opcode_resmac(void) { - Rn = dsp_acc; +#ifdef DSP_DIS_RESMAC + if (doDSPDis) + WriteLog("%06X: RESMAC R%02u [NCZ:%u%u%u, R%02u=%08X, DSP_ACC=%02X%08X] -> ", dsp_pc-2, IMM_2, dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_2, RN, (uint8)(dsp_acc >> 32), (uint32)(dsp_acc & 0xFFFFFFFF)); +#endif + RN = (uint32)dsp_acc; +#ifdef DSP_DIS_RESMAC + if (doDSPDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_2, RN); +#endif } static void dsp_opcode_imult(void) { - uint32 res=Rn=((int16)Rn)*((int16)Rm); - set_flag_z(res); - set_flag_n(res); +#ifdef DSP_DIS_IMULT + if (doDSPDis) + WriteLog("%06X: IMULT R%02u, R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", dsp_pc-2, IMM_1, IMM_2, dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_1, RM, IMM_2, RN); +#endif + RN = (int16)RN * (int16)RM; + SET_ZN(RN); +#ifdef DSP_DIS_IMULT + if (doDSPDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_1, RM, IMM_2, RN); +#endif } static void dsp_opcode_mult(void) { - uint32 res=Rn = ((uint16)Rm) * ((uint16)Rn); - set_flag_z(res); - set_flag_n(res); +#ifdef DSP_DIS_MULT + if (doDSPDis) + WriteLog("%06X: MULT R%02u, R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", dsp_pc-2, IMM_1, IMM_2, dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_1, RM, IMM_2, RN); +#endif + RN = (uint16)RM * (uint16)RN; + SET_ZN(RN); +#ifdef DSP_DIS_MULT + if (doDSPDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_1, RM, IMM_2, RN); +#endif } static void dsp_opcode_bclr(void) { - uint32 _Rm=imm_1; - uint32 _Rn=Rn; - uint32 res; -#ifdef __PORT__ - - /* - GCC on WIN32 (more importantly mingw) doesn't know the declared - variables in asm until we put a _ before it. - - So the declaration dsp_flag_c needs to be _dsp_flag_c on mingw. - */ - - #ifdef __GCCWIN32__ - - asm( - "btrl %1, %2 - cmpl $0, %2 - setz _dsp_flag_z - sets _dsp_flag_n - movl %%eax, %0 - " - : "=m"(res) - : "c"(_Rm), "a"(_Rn)); - - #else - - asm( - "btrl %1, %2 - cmpl $0, %2 - setz dsp_flag_z - sets dsp_flag_n - movl %%eax, %0 - " - : "=m"(res) - : "c"(_Rm), "a"(_Rn)); - - #endif - - -#else - __asm - { - mov eax,_Rn - mov ecx,_Rm - btr eax,ecx - cmp eax,0 - setz [dsp_flag_z] - sets [dsp_flag_n] - mov res,eax - }; +#ifdef DSP_DIS_BCLR + if (doDSPDis) + WriteLog("%06X: BCLR #%u, R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", dsp_pc-2, IMM_1, IMM_2, dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_2, RN); +#endif + UINT32 res = RN & ~(1 << IMM_1); + RN = res; + SET_ZN(res); +#ifdef DSP_DIS_BCLR + if (doDSPDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_2, RN); #endif - Rn=res; } static void dsp_opcode_btst(void) { - uint32 _Rm=imm_1; - uint32 _Rn=Rn; -#ifdef __PORT__ - - /* - GCC on WIN32 (more importantly mingw) doesn't know the declared - variables in asm until we put a _ before it. - - So the declaration dsp_flag_c needs to be _dsp_flag_c on mingw. - */ - - #ifdef __GCCWIN32__ - - asm( - "bt %0, %1 - setnc _dsp_flag_z - " - : - : "c"(_Rm), "a"(_Rn)); - - #else - - asm( - "bt %0, %1 - setnc dsp_flag_z - " - : - : "c"(_Rm), "a"(_Rn)); - - #endif - -#else - __asm - { - mov eax,_Rn - mov ecx,_Rm - bt eax,ecx - setnc [dsp_flag_z] - }; +#ifdef DSP_DIS_BTST + if (doDSPDis) + WriteLog("%06X: BTST #%u, R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", dsp_pc-2, IMM_1, IMM_2, dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_2, RN); +#endif + dsp_flag_z = (~RN >> IMM_1) & 1; +#ifdef DSP_DIS_BTST + if (doDSPDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_2, RN); #endif } static void dsp_opcode_bset(void) { - uint32 _Rm=imm_1; - uint32 _Rn=Rn; - uint32 res; -#ifdef __PORT__ - - /* - GCC on WIN32 (more importantly mingw) doesn't know the declared - variables in asm until we put a _ before it. - - So the declaration dsp_flag_c needs to be _dsp_flag_c on mingw. - */ - - #ifdef __GCCWIN32__ - - asm( - "btsl %1, %2 - cmpl $0, %2 - setz _dsp_flag_z - sets _dsp_flag_n - movl %%eax, %0 - " - : "=m"(res) - : "c"(_Rm), "a"(_Rn)); - - #else - - asm( - "btsl %1, %2 - cmpl $0, %2 - setz dsp_flag_z - sets dsp_flag_n - movl %%eax, %0 - " - : "=m"(res) - : "c"(_Rm), "a"(_Rn)); - - #endif - -#else - __asm - { - mov eax,_Rn - mov ecx,_Rm - bts eax,ecx - cmp eax,0 - setz [dsp_flag_z] - sets [dsp_flag_n] - mov res,eax - }; +#ifdef DSP_DIS_BSET + if (doDSPDis) + WriteLog("%06X: BSET #%u, R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", dsp_pc-2, IMM_1, IMM_2, dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_2, RN); +#endif + UINT32 res = RN | (1 << IMM_1); + RN = res; + SET_ZN(res); +#ifdef DSP_DIS_BSET + if (doDSPDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_2, RN); #endif - Rn=res; } static void dsp_opcode_subqt(void) { - Rn -= dsp_convert_zero[imm_1]; +#ifdef DSP_DIS_SUBQT + if (doDSPDis) + WriteLog("%06X: SUBQT #%u, R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", dsp_pc-2, dsp_convert_zero[IMM_1], IMM_2, dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_2, RN); +#endif + RN -= dsp_convert_zero[IMM_1]; +#ifdef DSP_DIS_SUBQT + if (doDSPDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_2, RN); +#endif } static void dsp_opcode_addqt(void) { - Rn += dsp_convert_zero[imm_1]; +#ifdef DSP_DIS_ADDQT + if (doDSPDis) + WriteLog("%06X: ADDQT #%u, R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", dsp_pc-2, dsp_convert_zero[IMM_1], IMM_2, dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_2, RN); +#endif + RN += dsp_convert_zero[IMM_1]; +#ifdef DSP_DIS_ADDQT + if (doDSPDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_2, RN); +#endif } static void dsp_opcode_imacn(void) { - uint32 res=((int16)Rm) * ((int16)(Rn)); - dsp_acc += res; +#ifdef DSP_DIS_IMACN + if (doDSPDis) + WriteLog("%06X: IMACN R%02u, R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", dsp_pc-2, IMM_1, IMM_2, dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_1, RM, IMM_2, RN); +#endif + int32 res = (int16)RM * (int16)RN; + dsp_acc += (int64)res; +//Should we AND the result to fit into 40 bits here??? +#ifdef DSP_DIS_IMACN + if (doDSPDis) + WriteLog("[NCZ:%u%u%u, DSP_ACC=%02X%08X]\n", dsp_flag_n, dsp_flag_c, dsp_flag_z, (uint8)(dsp_acc >> 32), (uint32)(dsp_acc & 0xFFFFFFFF)); +#endif } static void dsp_opcode_mtoi(void) { - uint32 _Rm=Rm; - uint32 res=Rn=(((INT32)_Rm >> 8) & 0xff800000) | (_Rm & 0x007fffff); - set_flag_z(res); - set_flag_n(res); + RN = (((INT32)RM >> 8) & 0xFF800000) | (RM & 0x007FFFFF); + SET_ZN(RN); } static void dsp_opcode_normi(void) { - uint32 _Rm = Rm; + uint32 _Rm = RM; uint32 res = 0; if (_Rm) @@ -1966,9 +1696,8 @@ static void dsp_opcode_normi(void) res++; } } - Rn = res; - set_flag_z(res); - set_flag_n(res); + RN = res; + SET_ZN(RN); } static void dsp_opcode_mmult(void) @@ -1987,7 +1716,7 @@ static void dsp_opcode_mmult(void) a=(int16)((dsp_alternate_reg[dsp_opcode_first_parameter + (i>>1)]>>16)&0xffff); else a=(int16)(dsp_alternate_reg[dsp_opcode_first_parameter + (i>>1)]&0xffff); - int16 b=((int16)dsp_word_read(addr+2)); + int16 b=((int16)DSPReadWord(addr + 2, DSP)); accum += a*b; addr += 4; } @@ -2001,39 +1730,36 @@ static void dsp_opcode_mmult(void) a=(int16)((dsp_alternate_reg[dsp_opcode_first_parameter + (i>>1)]>>16)&0xffff); else a=(int16)(dsp_alternate_reg[dsp_opcode_first_parameter + (i>>1)]&0xffff); - int16 b=((int16)dsp_word_read(addr+2)); + int16 b=((int16)DSPReadWord(addr + 2, DSP)); accum += a*b; addr += 4 * count; } } - Rn = res = (int32)accum; + RN = res = (int32)accum; // carry flag to do - set_flag_z(res); - set_flag_n(res); +//NOTE: The flags are set based upon the last add/multiply done... + SET_ZN(RN); } static void dsp_opcode_abs(void) { - uint32 _Rn=Rn; + uint32 _Rn = RN; uint32 res; - if (_Rn==0x80000000) - { - set_flag_n(1); - } + if (_Rn == 0x80000000) + dsp_flag_n = 1; else { - dsp_flag_c = ((_Rn&0x80000000)>>31); - res= Rn = (_Rn & 0x80000000) ? -_Rn : _Rn; - reset_flag_n(); - set_flag_z(res); + dsp_flag_c = ((_Rn & 0x80000000) >> 31); + res = RN = (_Rn & 0x80000000 ? -_Rn : _Rn); + CLR_ZN; SET_Z(res); } } static void dsp_opcode_div(void) { - uint32 _Rm=Rm; - uint32 _Rn=Rn; + uint32 _Rm=RM; + uint32 _Rn=RN; if (_Rm) { @@ -2042,333 +1768,120 @@ static void dsp_opcode_div(void) dsp_remain = (((uint64)_Rn) << 16) % _Rm; if (dsp_remain&0x80000000) dsp_remain-=_Rm; - Rn = (((uint64)_Rn) << 16) / _Rm; + RN = (((uint64)_Rn) << 16) / _Rm; } else { dsp_remain = _Rn % _Rm; if (dsp_remain&0x80000000) dsp_remain-=_Rm; - Rn/=_Rm; + RN/=_Rm; } } else - Rn=0xffffffff; + RN=0xffffffff; } static void dsp_opcode_imultn(void) { - uint32 res=(int32)(((int16)Rn)*((int16)Rm)); - dsp_acc=(int32)res; - set_flag_z(res); - set_flag_n(res); +#ifdef DSP_DIS_IMULTN + if (doDSPDis) + WriteLog("%06X: IMULTN R%02u, R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", dsp_pc-2, IMM_1, IMM_2, dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_1, RM, IMM_2, RN); +#endif + // This is OK, since this multiply won't overflow 32 bits... + int32 res = (int32)((int16)RN * (int16)RM); + dsp_acc = (int64)res; + SET_ZN(res); +#ifdef DSP_DIS_IMULTN + if (doDSPDis) + WriteLog("[NCZ:%u%u%u, DSP_ACC=%02X%08X]\n", dsp_flag_n, dsp_flag_c, dsp_flag_z, (uint8)(dsp_acc >> 32), (uint32)(dsp_acc & 0xFFFFFFFF)); +#endif } static void dsp_opcode_neg(void) { - uint32 _Rn=Rn; - uint32 res; -#ifdef __PORT__ - - /* - GCC on WIN32 (more importantly mingw) doesn't know the declared - variables in asm until we put a _ before it. - - So the declaration dsp_flag_c needs to be _dsp_flag_c on mingw. - */ - - #ifdef __GCCWIN32__ - - asm( - " - subl %1, %2 - setc _dsp_flag_c - setz _dsp_flag_z - sets _dsp_flag_n - movl %%eax, %0 - " - : "=m"(res) - : "d"(_Rn), "a"(0)); - - #else - - asm( - " - subl %1, %2 - setc dsp_flag_c - setz dsp_flag_z - sets dsp_flag_n - movl %%eax, %0 - " - : "=m"(res) - : "d"(_Rn), "a"(0)); - - #endif - -#else - __asm - { - xor eax,eax - mov edx,_Rn - sub eax,edx - setc [dsp_flag_c] - setz [dsp_flag_z] - sets [dsp_flag_n] - mov res,eax - }; +#ifdef DSP_DIS_NEG + if (doDSPDis) + WriteLog("%06X: NEG R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", dsp_pc-2, IMM_2, dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_2, RN); +#endif + UINT32 res = -RN; + SET_ZNC_SUB(0, RN, res); + RN = res; +#ifdef DSP_DIS_NEG + if (doDSPDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_2, RN); #endif - Rn=res; } static void dsp_opcode_shlq(void) { - uint32 shift=(32-dsp_convert_zero[imm_1]); - uint32 _Rn=Rn; - uint32 res; -#ifdef __PORT__ - - /* - GCC on WIN32 (more importantly mingw) doesn't know the declared - variables in asm until we put a _ before it. - - So the declaration dsp_flag_c needs to be _dsp_flag_c on mingw. - */ - - #ifdef __GCCWIN32__ - - asm( - "testl $0x80000000, %2 - setnz _dsp_flag_c - shl %%cl, %2 - cmpl $0, %2 - setz _dsp_flag_z - sets _dsp_flag_n - movl %%eax, %0 - " - : "=m"(res) - : "c"(shift), "a"(_Rn)); - - #else - - asm( - "testl $0x80000000, %2 - setnz dsp_flag_c - shl %%cl, %2 - cmpl $0, %2 - setz dsp_flag_z - sets dsp_flag_n - movl %%eax, %0 - " - : "=m"(res) - : "c"(shift), "a"(_Rn)); - - #endif - -#else - __asm - { - mov ecx,shift - mov eax,_Rn - test eax,0x80000000 - setnz [dsp_flag_c] - shl eax,cl - cmp eax,0 - setz [dsp_flag_z] - sets [dsp_flag_n] - mov res,eax - } +#ifdef DSP_DIS_SHLQ + if (doDSPDis) + WriteLog("%06X: SHLQ #%u, R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", dsp_pc-2, 32 - IMM_1, IMM_2, dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_2, RN); +#endif + INT32 r1 = 32 - IMM_1; + UINT32 res = RN << r1; + SET_ZN(res); dsp_flag_c = (RN >> 31) & 1; + RN = res; +#ifdef DSP_DIS_SHLQ + if (doDSPDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_2, RN); #endif - Rn=res; } static void dsp_opcode_shrq(void) { - uint32 shift=dsp_convert_zero[imm_1]; - uint32 _Rn=Rn; - - uint32 res; -#ifdef __PORT__ - - /* - GCC on WIN32 (more importantly mingw) doesn't know the declared - variables in asm until we put a _ before it. - - So the declaration dsp_flag_c needs to be _dsp_flag_c on mingw. - */ - - #ifdef __GCCWIN32__ - - asm( - "testl $0x00000001, %2 - setnz _dsp_flag_c - shr %%cl, %2 - cmpl $0, %2 - setz _dsp_flag_z - sets _dsp_flag_n - movl %%eax, %0 - " - : "=m"(res) - : "c"(shift), "a"(_Rn)); - - #else - - asm( - "testl $0x00000001, %2 - setnz dsp_flag_c - shr %%cl, %2 - cmpl $0, %2 - setz dsp_flag_z - sets dsp_flag_n - movl %%eax, %0 - " - : "=m"(res) - : "c"(shift), "a"(_Rn)); - - #endif - -#else - __asm - { - mov ecx,shift - mov eax,_Rn - test eax,0x00000001 - setnz [dsp_flag_c] - shr eax,cl - cmp eax,0 - setz [dsp_flag_z] - sets [dsp_flag_n] - mov res,eax - } +#ifdef DSP_DIS_SHRQ + if (doDSPDis) + WriteLog("%06X: SHRQ #%u, R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", dsp_pc-2, dsp_convert_zero[IMM_1], IMM_2, dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_2, RN); +#endif + INT32 r1 = dsp_convert_zero[IMM_1]; + UINT32 res = RN >> r1; + SET_ZN(res); dsp_flag_c = RN & 1; + RN = res; +#ifdef DSP_DIS_SHRQ + if (doDSPDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_2, RN); #endif - Rn=res; } static void dsp_opcode_ror(void) { - uint32 shift=Rm; - uint32 _Rn=Rn; - uint32 res; -#ifdef __PORT__ - - /* - GCC on WIN32 (more importantly mingw) doesn't know the declared - variables in asm until we put a _ before it. - - So the declaration dsp_flag_c needs to be _dsp_flag_c on mingw. - */ - - #ifdef __GCCWIN32__ - - asm( - "testl $0x80000000, %2 - setnz _dsp_flag_c - ror %%cl, %2 - cmpl $0, %2 - setz _dsp_flag_z - sets _dsp_flag_n - movl %%eax, %0 - " - : "=m"(res) - : "c"(shift), "a"(_Rn)); - - #else - - asm( - "testl $0x80000000, %2 - setnz dsp_flag_c - ror %%cl, %2 - cmpl $0, %2 - setz dsp_flag_z - sets dsp_flag_n - movl %%eax, %0 - " - : "=m"(res) - : "c"(shift), "a"(_Rn)); - - #endif - -#else - __asm - { - mov ecx,shift - mov eax,_Rn - test eax,0x80000000 - setnz [dsp_flag_c] - ror eax,cl - cmp eax,0 - setz [dsp_flag_z] - sets [dsp_flag_n] - mov res,eax - } +#ifdef DSP_DIS_ROR + if (doDSPDis) + WriteLog("%06X: ROR R%02u, R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", dsp_pc-2, IMM_1, IMM_2, dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_1, RM, IMM_2, RN); +#endif + UINT32 r1 = RM & 0x1F; + UINT32 res = (RN >> r1) | (RN << (32 - r1)); + SET_ZN(res); dsp_flag_c = (RN >> 31) & 1; + RN = res; +#ifdef DSP_DIS_ROR + if (doDSPDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_1, RM, IMM_2, RN); #endif - Rn=res; } static void dsp_opcode_rorq(void) { - uint32 shift=dsp_convert_zero[imm_1&0x1f]; - uint32 _Rn=Rn; - uint32 res; -#ifdef __PORT__ - - /* - GCC on WIN32 (more importantly mingw) doesn't know the declared - variables in asm until we put a _ before it. - - So the declaration dsp_flag_c needs to be _dsp_flag_c on mingw. - */ - - #ifdef __GCCWIN32__ - - asm( - "testl $0x80000000, %2 - setnz _dsp_flag_c - ror %%cl, %2 - cmpl $0, %2 - setz _dsp_flag_z - sets _dsp_flag_n - movl %%eax, %0 - " - : "=m"(res) - : "c"(shift), "a"(_Rn)); - - #else - - asm( - "testl $0x80000000, %2 - setnz dsp_flag_c - ror %%cl, %2 - cmpl $0, %2 - setz dsp_flag_z - sets dsp_flag_n - movl %%eax, %0 - " - : "=m"(res) - : "c"(shift), "a"(_Rn)); - - #endif - -#else - __asm - { - mov ecx,shift - mov eax,_Rn - test eax,0x80000000 - setnz [dsp_flag_c] - ror eax,cl - cmp eax,0 - setz [dsp_flag_z] - sets [dsp_flag_n] - mov res,eax - } +#ifdef DSP_DIS_RORQ + if (doDSPDis) + WriteLog("%06X: RORQ #%u, R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", dsp_pc-2, dsp_convert_zero[IMM_1], IMM_2, dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_2, RN); +#endif + UINT32 r1 = dsp_convert_zero[IMM_1 & 0x1F]; + UINT32 r2 = RN; + UINT32 res = (r2 >> r1) | (r2 << (32 - r1)); + RN = res; + SET_ZN(res); dsp_flag_c = (r2 >> 31) & 0x01; +#ifdef DSP_DIS_RORQ + if (doDSPDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_2, RN); #endif - Rn=res; } static void dsp_opcode_sha(void) { - int32 sRm=(int32)Rm; - uint32 _Rn=Rn; + int32 sRm=(int32)RM; + uint32 _Rn=RN; if (sRm<0) { @@ -2392,31 +1905,29 @@ static void dsp_opcode_sha(void) shift--; } } - Rn=_Rn; - set_flag_z(_Rn); - set_flag_n(_Rn); + RN = _Rn; + SET_ZN(RN); } static void dsp_opcode_sharq(void) { - uint32 shift=dsp_convert_zero[imm_1]; - uint32 _Rn=Rn; - - dsp_flag_c = (_Rn & 0x1); - while (shift) - { - _Rn=((int32)_Rn)>>1; - shift--; - } - Rn=_Rn; - set_flag_z(_Rn); - set_flag_n(_Rn); +#ifdef DSP_DIS_SHARQ + if (doDSPDis) + WriteLog("%06X: SHARQ #%u, R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", dsp_pc-2, dsp_convert_zero[IMM_1], IMM_2, dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_2, RN); +#endif + UINT32 res = (INT32)RN >> dsp_convert_zero[IMM_1]; + SET_ZN(res); dsp_flag_c = RN & 0x01; + RN = res; +#ifdef DSP_DIS_SHARQ + if (doDSPDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_2, RN); +#endif } static void dsp_opcode_sh(void) { - int32 sRm=(int32)Rm; - uint32 _Rn=Rn; + int32 sRm=(int32)RM; + uint32 _Rn=RN; if (sRm<0) { @@ -2440,59 +1951,59 @@ static void dsp_opcode_sh(void) shift--; } } - Rn=_Rn; - set_flag_z(_Rn); - set_flag_n(_Rn); + RN = _Rn; + SET_ZN(RN); } -#define CLR_ZN { dsp_flag_n=0; dsp_flag_z=0; }; -#define CLR_ZNC { dsp_flag_c=0; dsp_flag_n=0; dsp_flag_z=0; }; -#define SET_Z(r) (dsp_flag_z= ((r) == 0)) -#define SET_C_ADD(a,b) (dsp_flag_c= ((UINT32)(b) > (UINT32)(~(a))) << 1) -#define SET_C_SUB(a,b) (dsp_flag_c= ((UINT32)(b) > (UINT32)(a)) << 1) -#define SET_N(r) (dsp_flag_n= (((UINT32)(r) >> 29) & 4)) -#define SET_ZN(r) SET_N(r); SET_Z(r) -#define SET_ZNC_ADD(a,b,r) SET_N(r); SET_Z(r); SET_C_ADD(a,b) -#define SET_ZNC_SUB(a,b,r) SET_N(r); SET_Z(r); SET_C_SUB(a,b) - -void dsp_opcode_addqmod(void) +void dsp_opcode_addqmod(void) { - UINT32 r1 = dsp_convert_zero[imm_1]; - UINT32 r2 = Rn; +#ifdef DSP_DIS_ADDQMOD + if (doDSPDis) + WriteLog("%06X: ADDQMOD #%u, R%02u [NCZ:%u%u%u, R%02u=%08X, DSP_MOD=%08X] -> ", dsp_pc-2, dsp_convert_zero[IMM_1], IMM_2, dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_2, RN, dsp_modulo); +#endif + UINT32 r1 = dsp_convert_zero[IMM_1]; + UINT32 r2 = RN; UINT32 res = r2 + r1; res = (res & (~dsp_modulo)) | (r2 & dsp_modulo); - Rn = res; - CLR_ZNC; SET_ZNC_ADD(r2,r1,res); + RN = res; + SET_ZNC_ADD(r2, r1, res); +#ifdef DSP_DIS_ADDQMOD + if (doDSPDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_2, RN); +#endif } + void dsp_opcode_subqmod(void) { - UINT32 r1 = dsp_convert_zero[imm_1]; - UINT32 r2 = Rn; + UINT32 r1 = dsp_convert_zero[IMM_1]; + UINT32 r2 = RN; UINT32 res = r2 - r1; res = (res & (~dsp_modulo)) | (r2 & dsp_modulo); - Rn = res; + RN = res; - SET_ZNC_SUB(r2,r1,res); + SET_ZNC_SUB(r2, r1, res); } + void dsp_opcode_mirror(void) { - UINT32 r1 = Rn; - UINT32 res = (mirror_table[r1 & 0xffff] << 16) | mirror_table[r1 >> 16]; - Rn = res; - CLR_ZN; SET_ZN(res); + UINT32 r1 = RN; + RN = (mirror_table[r1 & 0xFFFF] << 16) | mirror_table[r1 >> 16]; + SET_ZN(RN); } + void dsp_opcode_sat32s(void) { - INT32 r2 = (UINT32)Rn; + INT32 r2 = (UINT32)RN; INT32 temp = dsp_acc >> 32; - UINT32 res = (temp < -1) ? (INT32)0x80000000 : (temp > 0) ? (INT32)0x7fffffff : r2; - Rn = res; - CLR_ZN; SET_ZN(res); + UINT32 res = (temp < -1) ? (INT32)0x80000000 : (temp > 0) ? (INT32)0x7FFFFFFF : r2; + RN = res; + SET_ZN(res); } + void dsp_opcode_sat16s(void) { - INT32 r2 = Rn; + INT32 r2 = RN; UINT32 res = (r2 < -32768) ? -32768 : (r2 > 32767) ? 32767 : r2; - Rn = res; - CLR_ZN; SET_ZN(res); + RN = res; + SET_ZN(res); } diff --git a/src/gpu.cpp b/src/gpu.cpp index 9a9cc0b..f7951cc 100644 --- a/src/gpu.cpp +++ b/src/gpu.cpp @@ -72,6 +72,9 @@ #define GPU_DIS_SUBQ #define GPU_DIS_SUBQT #define GPU_DIS_XOR + +bool doGPUDis = false; +//bool doGPUDis = true; //*/ /* GPU opcodes use (BIOS flying ATARI logo): @@ -146,9 +149,11 @@ GPU opcodes use (BIOS flying ATARI logo): void GPUUpdateRegisterBanks(void); -void gpu_dump_disassembly(void); -void gpu_dump_registers(void); -void gpu_dump_memory(void); +void GPUDumpDisassembly(void); +void GPUDumpRegisters(void); +void GPUDumpMemory(void); + +// External global variables extern int start_logging; extern int gpu_start_log; @@ -251,7 +256,7 @@ void (*gpu_opcode[64])()= }; static uint8 * gpu_ram_8; -static uint32 gpu_pc; +uint32 gpu_pc; static uint32 gpu_acc; static uint32 gpu_remain; static uint32 gpu_hidata; @@ -331,7 +336,6 @@ char * gpu_opcode_str[64]= static uint32 gpu_in_exec = 0; static uint32 gpu_releaseTimeSlice_flag = 0; -bool GPUInterruptPending = false; void gpu_releaseTimeslice(void) { @@ -343,10 +347,6 @@ uint32 gpu_get_pc(void) return gpu_pc; } -/*#define ZFLAG 0x00001 -#define CFLAG 0x00002 -#define NFLAG 0x00004*/ - void build_branch_condition_table(void) { if (!branch_condition_table) @@ -382,14 +382,13 @@ void build_branch_condition_table(void) // // GPU byte access (read) // -//unsigned gpu_byte_read(unsigned int offset, uint32 calledBy) -unsigned gpu_byte_read(unsigned int offset) +uint8 GPUReadByte(uint32 offset, uint32 who/*=UNKNOWN*/) { if ((offset >= GPU_WORK_RAM_BASE) && (offset < GPU_WORK_RAM_BASE+0x1000)) return gpu_ram_8[offset & 0xFFF]; else if ((offset >= GPU_CONTROL_RAM_BASE) && (offset < GPU_CONTROL_RAM_BASE+0x20)) { - uint32 data = gpu_long_read(offset & 0xFFFFFFFC); + uint32 data = GPUReadLong(offset & 0xFFFFFFFC, who); if ((offset & 0x03) == 0) return data >> 24; @@ -401,13 +400,13 @@ unsigned gpu_byte_read(unsigned int offset) return data & 0xFF; } - return jaguar_byte_read(offset); + return JaguarReadByte(offset, who); } // // GPU word access (read) // -unsigned gpu_word_read(unsigned int offset) +uint16 GPUReadWord(uint32 offset, uint32 who/*=UNKNOWN*/) { if ((offset >= GPU_WORK_RAM_BASE) && (offset < GPU_WORK_RAM_BASE+0x1000)) { @@ -420,9 +419,9 @@ unsigned gpu_word_read(unsigned int offset) // This looks and smells wrong... // But it *might* be OK... if (offset & 0x01) // Catch cases 1 & 3... (unaligned read) - return (gpu_byte_read(offset) << 8) | gpu_byte_read(offset+1); + return (GPUReadByte(offset, who) << 8) | GPUReadByte(offset+1, who); - uint32 data = gpu_long_read(offset & 0xFFFFFFFC); + uint32 data = GPUReadLong(offset & 0xFFFFFFFC, who); if (offset & 0x02) // Cases 0 & 2... return data & 0xFFFF; @@ -432,15 +431,15 @@ unsigned gpu_word_read(unsigned int offset) //TEMP--Mirror of F03000? if (offset >= 0xF0B000 && offset <= 0xF0BFFF) -WriteLog("[GPUR16] --> Possible GPU RAM mirror access!"); +WriteLog("[GPUR16] --> Possible GPU RAM mirror access by %s!", whoName[who]); - return jaguar_word_read(offset); + return JaguarReadWord(offset, who); } // // GPU dword access (read) // -unsigned gpu_long_read(unsigned int offset) +uint32 GPUReadLong(uint32 offset, uint32 who/*=UNKNOWN*/) { // if ((offset >= GPU_WORK_RAM_BASE) && (offset < GPU_WORK_RAM_BASE + 0x1000)) if ((offset >= GPU_WORK_RAM_BASE) && (offset <= GPU_WORK_RAM_BASE + 0x0FFC)) @@ -480,34 +479,35 @@ unsigned gpu_long_read(unsigned int offset) return gpu_remain; default: // unaligned long read #ifdef GPU_DEBUG - WriteLog("GPU: Read32--unaligned 32 bit read at %08X.\n", GPU_CONTROL_RAM_BASE + offset); + WriteLog("GPU: Read32--unaligned 32 bit read at %08X by %s.\n", GPU_CONTROL_RAM_BASE + offset, whoName[who]); #endif // GPU_DEBUG return 0; } } //TEMP--Mirror of F03000? if (offset >= 0xF0B000 && offset <= 0xF0BFFF) - WriteLog("[GPUR32] --> Possible GPU RAM mirror access!\n"); + WriteLog("[GPUR32] --> Possible GPU RAM mirror access by %s!\n", whoName[who]); /*if (offset >= 0xF1D000 && offset <= 0xF1DFFF) WriteLog("[GPUR32] --> Reading from Wavetable ROM!\n");//*/ - return (jaguar_word_read(offset) << 16) | jaguar_word_read(offset + 2); + return (JaguarReadWord(offset, who) << 16) | JaguarReadWord(offset + 2, who); } // // GPU byte access (write) // -void gpu_byte_write(unsigned offset, unsigned data) +void GPUWriteByte(uint32 offset, uint8 data, uint32 who/*=UNKNOWN*/) { if ((offset >= GPU_WORK_RAM_BASE) && (offset <= GPU_WORK_RAM_BASE + 0x0FFF)) { gpu_ram_8[offset & 0xFFF] = data; - if (!gpu_in_exec) +//This is the same stupid worthless code that was in the DSP!!! AARRRGGGGHHHHH!!!!!! +/* if (!gpu_in_exec) { m68k_end_timeslice(); dsp_releaseTimeslice(); - } + }*/ return; } else if ((offset >= GPU_CONTROL_RAM_BASE) && (offset <= GPU_CONTROL_RAM_BASE + 0x1F)) @@ -520,21 +520,21 @@ void gpu_byte_write(unsigned offset, unsigned data) gpu_div_control = (gpu_div_control & (~(0xFF << (bytenum << 3)))) | (data << (bytenum << 3)); else { - uint32 old_data = gpu_long_read(offset & 0xFFFFFFC); + uint32 old_data = GPUReadLong(offset & 0xFFFFFFC, who); bytenum = 3 - bytenum; // convention motorola !!! old_data = (old_data & (~(0xFF << (bytenum << 3)))) | (data << (bytenum << 3)); - gpu_long_write(offset & 0xFFFFFFC, old_data); + GPUWriteLong(offset & 0xFFFFFFC, old_data, who); } return; } // WriteLog("gpu: writing %.2x at 0x%.8x\n",data,offset); - jaguar_byte_write(offset, data); + JaguarWriteByte(offset, data, who); } // // GPU word access (write) // -void gpu_word_write(unsigned offset, unsigned data) +void GPUWriteWord(uint32 offset, uint16 data, uint32 who/*=UNKNOWN*/) { if ((offset >= GPU_WORK_RAM_BASE) && (offset <= GPU_WORK_RAM_BASE + 0x0FFE)) { @@ -543,11 +543,12 @@ void gpu_word_write(unsigned offset, unsigned data) /* offset &= 0xFFF; SET16(gpu_ram_8, offset, data);//*/ - if (!gpu_in_exec) +//This is the same stupid worthless code that was in the DSP!!! AARRRGGGGHHHHH!!!!!! +/* if (!gpu_in_exec) { m68k_end_timeslice(); dsp_releaseTimeslice(); - } + }*/ return; } else if ((offset >= GPU_CONTROL_RAM_BASE) && (offset <= GPU_CONTROL_RAM_BASE + 0x1E)) @@ -556,7 +557,7 @@ void gpu_word_write(unsigned offset, unsigned data) { #ifdef GPU_DEBUG WriteLog("GPU: Write16--unaligned write @ %08X [%04X]\n", offset, data); - gpu_dump_registers(); + GPUDumpRegisters(); #endif // GPU_DEBUG return; } @@ -573,32 +574,32 @@ void gpu_word_write(unsigned offset, unsigned data) else { //WriteLog("[GPU W16:%08X,%04X]", offset, data); - uint32 old_data = gpu_long_read(offset & 0xFFFFFFC); + uint32 old_data = GPUReadLong(offset & 0xFFFFFFC, who); if (offset & 0x02) old_data = (old_data & 0xFFFF0000) | (data & 0xFFFF); else old_data = (old_data & 0x0000FFFF) | ((data & 0xFFFF) << 16); - gpu_long_write(offset & 0xFFFFFFC, old_data); + GPUWriteLong(offset & 0xFFFFFFC, old_data, who); } return; } else if ((offset == GPU_WORK_RAM_BASE + 0x0FFF) || (GPU_CONTROL_RAM_BASE + 0x1F)) { #ifdef GPU_DEBUG - WriteLog("GPU: Write16--unaligned write @ %08X [%04X]\n", offset, data); - gpu_dump_registers(); + WriteLog("GPU: Write16--unaligned write @ %08X by %s [%04X]!\n", offset, whoName[who], data); + GPUDumpRegisters(); #endif // GPU_DEBUG return; } // Have to be careful here--this can cause an infinite loop! - jaguar_word_write(offset, data); + JaguarWriteWord(offset, data, who); } // // GPU dword access (write) // -void gpu_long_write(unsigned offset, unsigned data) +void GPUWriteLong(uint32 offset, uint32 data, uint32 who/*=UNKNOWN*/) { // if ((offset >= GPU_WORK_RAM_BASE) && (offset < GPU_WORK_RAM_BASE + 0x1000)) if ((offset >= GPU_WORK_RAM_BASE) && (offset <= GPU_WORK_RAM_BASE + 0x0FFC)) @@ -607,7 +608,7 @@ void gpu_long_write(unsigned offset, unsigned data) if (offset & 0x03) { WriteLog("GPU: Write32--unaligned write @ %08X [%08X]\n", offset, data); - gpu_dump_registers(); + GPUDumpRegisters(); } #endif // GPU_DEBUG @@ -626,6 +627,8 @@ void gpu_long_write(unsigned offset, unsigned data) switch (offset) { case 0x00: + { + bool IMASKCleared = (gpu_flags & IMASK) && !(data & IMASK); gpu_flags = data; gpu_flag_z = gpu_flags & ZERO_FLAG; gpu_flag_c = (gpu_flags & CARRY_FLAG) >> 1; @@ -635,17 +638,15 @@ void gpu_long_write(unsigned offset, unsigned data) //Writing here is only an interrupt enable--this approach is just plain wrong! // GPUHandleIRQs(); //This, however, is A-OK! ;-) - if (!(gpu_flags & IMASK) && GPUInterruptPending) // IMASK was cleared - { - GPUInterruptPending = false; - GPUHandleIRQs(); - } + if (IMASKCleared) // If IMASK was cleared, + GPUHandleIRQs(); // see if any other interrupts need servicing! #ifdef GPU_DEBUG if (gpu_flags & (INT_ENA0 | INT_ENA1 | INT_ENA2 | INT_ENA3 | INT_ENA4)) - WriteLog("GPU: Setting interrupt enable! Bits: %02X\n", (gpu_flags >> 4) & 0x1F); + WriteLog("GPU: Interrupt enable set by %s! Bits: %02X\n", whoName[who], (gpu_flags >> 4) & 0x1F); WriteLog("GPU: REGPAGE %s...\n", (gpu_flags & REGPAGE ? "set" : "cleared")); #endif // GPU_DEBUG break; + } case 0x04: gpu_matrix_control = data; break; @@ -659,7 +660,7 @@ void gpu_long_write(unsigned offset, unsigned data) case 0x10: gpu_pc = data; #ifdef GPU_DEBUG -WriteLog("GPU: Setting GPU PC to %08X %s\n", gpu_pc, (GPU_RUNNING ? "(GPU is RUNNING!)" : ""));//*/ +WriteLog("GPU: %s setting GPU PC to %08X %s\n", whoName[who], gpu_pc, (GPU_RUNNING ? "(GPU is RUNNING!)" : ""));//*/ #endif // GPU_DEBUG break; case 0x14: @@ -717,15 +718,15 @@ WriteLog("GPU: Setting GPU PC to %08X %s\n", gpu_pc, (GPU_RUNNING ? "(GPU is RUN gpu_exec(1); #endif // #ifndef GPU_SINGLE_STEPPING #ifdef GPU_DEBUG -WriteLog("Write to GPU CTRL: %08X ", data); +WriteLog("Write to GPU CTRL by %s: %08X ", whoName[who], data); if (GPU_RUNNING) - WriteLog(" --> Starting to run at %08X...", gpu_pc); + WriteLog(" --> Starting to run at %08X by %s...", gpu_pc, whoName[who]); else - WriteLog(" --> Stopped! (GPU_PC: %08X)", gpu_pc); + WriteLog(" --> Stopped by %s! (GPU_PC: %08X)", whoName[who], gpu_pc); WriteLog("\n"); #endif // GPU_DEBUG //if (GPU_RUNNING) -// gpu_dump_disassembly(); +// GPUDumpDisassembly(); // (?) If we're set running by the M68K (or DSP?) then end its timeslice to // allow the GPU a chance to run... // Yes! This partially fixed Trevor McFur... @@ -746,8 +747,9 @@ WriteLog("\n"); return; } - jaguar_word_write(offset, (data >> 16) & 0xFFFF); - jaguar_word_write(offset+2, data & 0xFFFF); +// JaguarWriteWord(offset, (data >> 16) & 0xFFFF, who); +// JaguarWriteWord(offset+2, data & 0xFFFF, who); + JaguarWriteLong(offset, data, who); } // @@ -755,9 +757,9 @@ WriteLog("\n"); // void GPUUpdateRegisterBanks(void) { - int bank = (gpu_flags & 0x4000); // REGPAGE bit + int bank = (gpu_flags & REGPAGE); // REGPAGE bit - if (gpu_flags & 0x0008) // IMASK bit + if (gpu_flags & IMASK) // IMASK bit bank = 0; // IMASK forces main bank to be bank 0 if (bank) @@ -768,6 +770,10 @@ void GPUUpdateRegisterBanks(void) void GPUHandleIRQs(void) { + // Bail out if we're already in an interrupt! + if (gpu_flags & IMASK) + return; + // Get the interrupt latch & enable bits uint32 bits = (gpu_control >> 6) & 0x1F, mask = (gpu_flags >> 4) & 0x1F; @@ -776,14 +782,6 @@ void GPUHandleIRQs(void) if (!bits) return; - // Bail out if we're already in an interrupt! (Note that the order this executes - // in is critical--we don't have a pending interrupt unless it's been enabled!) - if (gpu_flags & IMASK) - { - GPUInterruptPending = true; - return; - } - // Determine which interrupt to service uint32 which = 0; //Isn't there a #pragma to disable this warning??? if (bits & 0x01) @@ -808,14 +806,12 @@ void GPUHandleIRQs(void) // move pc,r30 ; address of interrupted code // store r30,(r31) ; store return address gpu_reg[31] -= 4; - gpu_reg[30] = gpu_pc - 2; - gpu_long_write(gpu_reg[31], gpu_pc - 2); + GPUWriteLong(gpu_reg[31], gpu_pc - 2, GPU); // movei #service_address,r30 ; pointer to ISR entry // jump (r30) ; jump to ISR // nop - gpu_pc = GPU_WORK_RAM_BASE + (which * 0x10); - gpu_reg[30] = gpu_pc; + gpu_pc = gpu_reg[30] = GPU_WORK_RAM_BASE + (which * 0x10); } void GPUSetIRQLine(int irqline, int state) @@ -834,8 +830,8 @@ void GPUSetIRQLine(int irqline, int state) } //TEMPORARY: Testing only! -#include "gpu2.h" -#include "gpu3.h" +//#include "gpu2.h" +//#include "gpu3.h" void gpu_init(void) { @@ -850,8 +846,8 @@ void gpu_init(void) gpu_reset(); //TEMPORARY: Testing only! - gpu2_init(); - gpu3_init(); +// gpu2_init(); +// gpu3_init(); } void gpu_reset(void) @@ -879,7 +875,7 @@ void gpu_reset(void) CLR_ZNC; memset(gpu_ram_8, 0xFF, 0x1000); gpu_in_exec = 0; - GPUInterruptPending = false; +//not needed GPUInterruptPending = false; gpu_reset_stats(); } @@ -895,7 +891,7 @@ void gpu_reset_stats(void) WriteLog("--> GPU stats were reset!\n"); } -void gpu_dump_disassembly(void) +void GPUDumpDisassembly(void) { char buffer[512]; @@ -909,30 +905,30 @@ void gpu_dump_disassembly(void) } } -void gpu_dump_registers(void) +void GPUDumpRegisters(void) { WriteLog("\n---[GPU flags: NCZ %d%d%d]-----------------------\n", gpu_flag_n, gpu_flag_c, gpu_flag_z); WriteLog("\nRegisters bank 0\n"); for(int j=0; j<8; j++) { - WriteLog("\tr%2i = %08X r%2i = %08X r%2i = %08X r%2i = %08X\n", - (j << 2) + 0, gpu_reg[(j << 2) + 0], - (j << 2) + 1, gpu_reg[(j << 2) + 1], - (j << 2) + 2, gpu_reg[(j << 2) + 2], - (j << 2) + 3, gpu_reg[(j << 2) + 3]); + WriteLog("\tR%02i = %08X R%02i = %08X R%02i = %08X R%02i = %08X\n", + (j << 2) + 0, gpu_reg_bank_0[(j << 2) + 0], + (j << 2) + 1, gpu_reg_bank_0[(j << 2) + 1], + (j << 2) + 2, gpu_reg_bank_0[(j << 2) + 2], + (j << 2) + 3, gpu_reg_bank_0[(j << 2) + 3]); } WriteLog("Registers bank 1\n"); for(int j=0; j<8; j++) { - WriteLog("\tr%2i = %08X r%2i = %08X r%2i = %08X r%2i = %08X\n", - (j << 2) + 0, gpu_alternate_reg[(j << 2) + 0], - (j << 2) + 1, gpu_alternate_reg[(j << 2) + 1], - (j << 2) + 2, gpu_alternate_reg[(j << 2) + 2], - (j << 2) + 3, gpu_alternate_reg[(j << 2) + 3]); + WriteLog("\tR%02i = %08X R%02i = %08X R%02i = %08X R%02i = %08X\n", + (j << 2) + 0, gpu_reg_bank_1[(j << 2) + 0], + (j << 2) + 1, gpu_reg_bank_1[(j << 2) + 1], + (j << 2) + 2, gpu_reg_bank_1[(j << 2) + 2], + (j << 2) + 3, gpu_reg_bank_1[(j << 2) + 3]); } } -void gpu_dump_memory(void) +void GPUDumpMemory(void) { WriteLog("\n---[GPU data at 00F03000]---------------------------\n"); for(int i=0; i<0xFFF; i+=4) @@ -948,36 +944,8 @@ void gpu_done(void) uint8 bits = (gpu_control >> 6) & 0x1F, mask = (gpu_flags >> 4) & 0x1F; WriteLog("GPU: Latch bits = %02X, enable bits = %02X\n", bits, mask); -// WriteLog("\nregisters bank 0\n"); -// for (int j=0;j<8;j++) -// { -// WriteLog("\tr%2i=0x%.8x r%2i=0x%.8x r%2i=0x%.8x r%2i=0x%.8x\n", -// (j<<2)+0,gpu_reg[(j<<2)+0], -// (j<<2)+1,gpu_reg[(j<<2)+1], -// (j<<2)+2,gpu_reg[(j<<2)+2], -// (j<<2)+3,gpu_reg[(j<<2)+3]); -// -// } -// WriteLog("registers bank 1\n"); -// for (j=0;j<8;j++) -// { -// WriteLog("\tr%2i=0x%.8x r%2i=0x%.8x r%2i=0x%.8x r%2i=0x%.8x\n", -// (j<<2)+0,gpu_alternate_reg[(j<<2)+0], -// (j<<2)+1,gpu_alternate_reg[(j<<2)+1], -// (j<<2)+2,gpu_alternate_reg[(j<<2)+2], -// (j<<2)+3,gpu_alternate_reg[(j<<2)+3]); -// -// } - WriteLog("\n---[GPU code at 00F03000]---------------------------\n"); - static char buffer[512]; - int j = 0xF03000; -// for(int i=0; i<4096; i++) - while (j <= 0xF03FFF) - { - uint32 oldj = j; - j += dasmjag(JAGUAR_GPU, buffer, j); - WriteLog("\t%08X: %s\n", oldj, buffer); - }//*/ + GPUDumpRegisters(); + GPUDumpDisassembly(); /* WriteLog("---[GPU code at %08X]---------------------------\n", gpu_pc); j = gpu_pc - 64; @@ -1004,6 +972,7 @@ void gpu_done(void) // static int testCount = 1; static int len = 0; +static bool tripwire = false; void gpu_exec(int32 cycles) { if (!GPU_RUNNING) @@ -1020,14 +989,18 @@ void gpu_exec(int32 cycles) gpu_releaseTimeSlice_flag = 0; gpu_in_exec++; - while ((cycles > 0) && GPU_RUNNING) + while (cycles > 0 && GPU_RUNNING) { - gpu_flag_c = (gpu_flag_c ? 1 : 0); +/*if (gpu_pc == 0xF0359A) +{ + doGPUDis = true; + GPUDumpRegisters(); +}*/ +/* gpu_flag_c = (gpu_flag_c ? 1 : 0); gpu_flag_z = (gpu_flag_z ? 1 : 0); - gpu_flag_n = (gpu_flag_n ? 1 : 0); + gpu_flag_n = (gpu_flag_n ? 1 : 0);*/ - uint16 opcode = gpu_word_read(gpu_pc); - + uint16 opcode = GPUReadWord(gpu_pc, GPU); uint32 index = opcode >> 10; gpu_instruction = opcode; // Added for GPU #3... gpu_opcode_first_parameter = (opcode >> 5) & 0x1F; @@ -1041,76 +1014,76 @@ WriteLog("--> Writing BITMAP object ***\n");//*/ /*if (gpu_pc == 0xF03546) { WriteLog("\n--> GPU PC: F03546\n"); - gpu_dump_registers(); - gpu_dump_disassembly(); + GPUDumpRegisters(); + GPUDumpDisassembly(); }//*/ /*if (gpu_pc == 0xF033F6) { WriteLog("\n--> GPU PC: F033F6\n"); - gpu_dump_registers(); - gpu_dump_disassembly(); + GPUDumpRegisters(); + GPUDumpDisassembly(); }//*/ /*if (gpu_pc == 0xF033CC) { WriteLog("\n--> GPU PC: F033CC\n"); - gpu_dump_registers(); - gpu_dump_disassembly(); + GPUDumpRegisters(); + GPUDumpDisassembly(); }//*/ /*if (gpu_pc == 0xF033D6) { WriteLog("\n--> GPU PC: F033D6 (#%d)\n", testCount++); - gpu_dump_registers(); - gpu_dump_memory(); + GPUDumpRegisters(); + GPUDumpMemory(); }//*/ /*if (gpu_pc == 0xF033D8) { WriteLog("\n--> GPU PC: F033D8 (#%d)\n", testCount++); - gpu_dump_registers(); - gpu_dump_memory(); + GPUDumpRegisters(); + GPUDumpMemory(); }//*/ /*if (gpu_pc == 0xF0358E) { WriteLog("\n--> GPU PC: F0358E (#%d)\n", testCount++); - gpu_dump_registers(); - gpu_dump_memory(); + GPUDumpRegisters(); + GPUDumpMemory(); }//*/ /*if (gpu_pc == 0xF034CA) { WriteLog("\n--> GPU PC: F034CA (#%d)\n", testCount++); - gpu_dump_registers(); + GPUDumpRegisters(); }//*/ /*if (gpu_pc == 0xF034CA) { len = gpu_reg[1] + 4;//, r9save = gpu_reg[9]; WriteLog("\nAbout to subtract [#%d] (R14=%08X, R15=%08X, R9=%08X):\n ", testCount++, gpu_reg[14], gpu_reg[15], gpu_reg[9]); for(int i=0; i GPU PC: F035C8 (#%d)\n", testCount++); - gpu_dump_registers(); - gpu_dump_disassembly(); + GPUDumpRegisters(); + GPUDumpDisassembly(); }//*/ if (gpu_start_log) @@ -1157,6 +1130,11 @@ if (gpu_pc == 0xF03548 && firstTime) gpu_opcode_use[index]++; if (gpu_start_log) WriteLog("(RM=%08X, RN=%08X)\n", RM, RN);//*/ +if ((gpu_pc < 0xF03000 || gpu_pc > 0xF03FFF) && !tripwire) +{ + WriteLog("GPU: Executing outside local RAM!\n"); + tripwire = true; +} } gpu_in_exec--; @@ -1209,7 +1187,8 @@ char * condition[32] = "c z", "???", "???", "???", "???", "???", "???", "???", "???", "???", "nn", "nn nz", "nn z", "???", "n", "n nz", "n z", "???", "???", "???", "???", "F" }; - WriteLog("%06X: JUMP %s, (R%02u) [NCZ:%u%u%u, R%02u=%08X] ", gpu_pc-2, condition[IMM_2], IMM_1, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM); + if (doGPUDis) + WriteLog("%06X: JUMP %s, (R%02u) [NCZ:%u%u%u, R%02u=%08X] ", gpu_pc-2, condition[IMM_2], IMM_1, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM); #endif // normalize flags /* gpu_flag_c = (gpu_flag_c ? 1 : 0); @@ -1221,15 +1200,15 @@ char * condition[32] = if (BRANCH_CONDITION(IMM_2)) { #ifdef GPU_DIS_JUMP - WriteLog("Branched!\n"); + if (doGPUDis) + WriteLog("Branched!\n"); #endif if (gpu_start_log) WriteLog(" --> JUMP: Branch taken.\n"); uint32 delayed_pc = RM; - gpu_exec(1); gpu_pc = delayed_pc; -/* uint16 opcode = gpu_word_read(gpu_pc); +/* uint16 opcode = GPUReadWord(gpu_pc, GPU); gpu_opcode_first_parameter = (opcode >> 5) & 0x1F; gpu_opcode_second_parameter = opcode & 0x1F; @@ -1238,7 +1217,8 @@ if (gpu_start_log) } #ifdef GPU_DIS_JUMP else - WriteLog("Branch NOT taken.\n"); + if (doGPUDis) + WriteLog("Branch NOT taken.\n"); #endif } @@ -1250,7 +1230,8 @@ char * condition[32] = "c z", "???", "???", "???", "???", "???", "???", "???", "???", "???", "nn", "nn nz", "nn z", "???", "n", "n nz", "n z", "???", "???", "???", "???", "F" }; - WriteLog("%06X: JR %s, %06X [NCZ:%u%u%u] ", gpu_pc-2, condition[IMM_2], gpu_pc+((IMM_1 & 0x10 ? 0xFFFFFFF0 | IMM_1 : IMM_1) * 2), gpu_flag_n, gpu_flag_c, gpu_flag_z); + if (doGPUDis) + WriteLog("%06X: JR %s, %06X [NCZ:%u%u%u] ", gpu_pc-2, condition[IMM_2], gpu_pc+((IMM_1 & 0x10 ? 0xFFFFFFF0 | IMM_1 : IMM_1) * 2), gpu_flag_n, gpu_flag_c, gpu_flag_z); #endif /* if (CONDITION(jaguar.op & 31)) { @@ -1273,16 +1254,16 @@ char * condition[32] = if (BRANCH_CONDITION(IMM_2)) { #ifdef GPU_DIS_JR - WriteLog("Branched!\n"); + if (doGPUDis) + WriteLog("Branched!\n"); #endif if (gpu_start_log) WriteLog(" --> JR: Branch taken.\n"); int32 offset = (IMM_1 & 0x10 ? 0xFFFFFFF0 | IMM_1 : IMM_1); // Sign extend IMM_1 int32 delayed_pc = gpu_pc + (offset * 2); - gpu_exec(1); gpu_pc = delayed_pc; -/* uint16 opcode = gpu_word_read(gpu_pc); +/* uint16 opcode = GPUReadWord(gpu_pc, GPU); gpu_opcode_first_parameter = (opcode >> 5) & 0x1F; gpu_opcode_second_parameter = opcode & 0x1F; @@ -1291,27 +1272,31 @@ if (gpu_start_log) } #ifdef GPU_DIS_JR else - WriteLog("Branch NOT taken.\n"); + if (doGPUDis) + WriteLog("Branch NOT taken.\n"); #endif } static void gpu_opcode_add(void) { #ifdef GPU_DIS_ADD - WriteLog("%06X: ADD R%02u, R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); + if (doGPUDis) + WriteLog("%06X: ADD R%02u, R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); #endif UINT32 res = RN + RM; CLR_ZNC; SET_ZNC_ADD(RN, RM, res); RN = res; #ifdef GPU_DIS_ADD - WriteLog("[NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); + if (doGPUDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); #endif } static void gpu_opcode_addc(void) { #ifdef GPU_DIS_ADDC - WriteLog("%06X: ADDC R%02u, R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); + if (doGPUDis) + WriteLog("%06X: ADDC R%02u, R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); #endif /* int dreg = jaguar.op & 31; UINT32 r1 = jaguar.r[(jaguar.op >> 5) & 31]; @@ -1322,57 +1307,65 @@ static void gpu_opcode_addc(void) UINT32 res = RN + RM + gpu_flag_c; UINT32 carry = gpu_flag_c; -// SET_ZNC_ADD(RN, RM, res); //???BUG??? +// SET_ZNC_ADD(RN, RM, res); //???BUG??? Yes! SET_ZNC_ADD(RN + carry, RM, res); // SET_ZNC_ADD(RN, RM + carry, res); RN = res; #ifdef GPU_DIS_ADDC - WriteLog("[NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); + if (doGPUDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); #endif } static void gpu_opcode_addq(void) { #ifdef GPU_DIS_ADDQ - WriteLog("%06X: ADDQ #%u, R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", gpu_pc-2, gpu_convert_zero[IMM_1], IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); + if (doGPUDis) + WriteLog("%06X: ADDQ #%u, R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", gpu_pc-2, gpu_convert_zero[IMM_1], IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); #endif UINT32 r1 = gpu_convert_zero[IMM_1]; UINT32 res = RN + r1; CLR_ZNC; SET_ZNC_ADD(RN, r1, res); RN = res; #ifdef GPU_DIS_ADDQ - WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); + if (doGPUDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); #endif } static void gpu_opcode_addqt(void) { #ifdef GPU_DIS_ADDQT - WriteLog("%06X: ADDQT #%u, R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", gpu_pc-2, gpu_convert_zero[IMM_1], IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); + if (doGPUDis) + WriteLog("%06X: ADDQT #%u, R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", gpu_pc-2, gpu_convert_zero[IMM_1], IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); #endif RN += gpu_convert_zero[IMM_1]; #ifdef GPU_DIS_ADDQT - WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); + if (doGPUDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); #endif } static void gpu_opcode_sub(void) { #ifdef GPU_DIS_SUB - WriteLog("%06X: SUB R%02u, R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); + if (doGPUDis) + WriteLog("%06X: SUB R%02u, R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); #endif UINT32 res = RN - RM; SET_ZNC_SUB(RN, RM, res); RN = res; #ifdef GPU_DIS_SUB - WriteLog("[NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); + if (doGPUDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); #endif } static void gpu_opcode_subc(void) { #ifdef GPU_DIS_SUBC - WriteLog("%06X: SUBC R%02u, R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); + if (doGPUDis) + WriteLog("%06X: SUBC R%02u, R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); #endif UINT32 res = RN - RM - gpu_flag_c; UINT32 borrow = gpu_flag_c; @@ -1380,44 +1373,51 @@ static void gpu_opcode_subc(void) SET_ZNC_SUB(RN - borrow, RM, res); RN = res; #ifdef GPU_DIS_SUBC - WriteLog("[NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); + if (doGPUDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); #endif } static void gpu_opcode_subq(void) { #ifdef GPU_DIS_SUBQ - WriteLog("%06X: SUBQ #%u, R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", gpu_pc-2, gpu_convert_zero[IMM_1], IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); + if (doGPUDis) + WriteLog("%06X: SUBQ #%u, R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", gpu_pc-2, gpu_convert_zero[IMM_1], IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); #endif UINT32 r1 = gpu_convert_zero[IMM_1]; UINT32 res = RN - r1; SET_ZNC_SUB(RN, r1, res); RN = res; #ifdef GPU_DIS_SUBQ - WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); + if (doGPUDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); #endif } static void gpu_opcode_subqt(void) { #ifdef GPU_DIS_SUBQT - WriteLog("%06X: SUBQT #%u, R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", gpu_pc-2, gpu_convert_zero[IMM_1], IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); + if (doGPUDis) + WriteLog("%06X: SUBQT #%u, R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", gpu_pc-2, gpu_convert_zero[IMM_1], IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); #endif RN -= gpu_convert_zero[IMM_1]; #ifdef GPU_DIS_SUBQT - WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); + if (doGPUDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); #endif } static void gpu_opcode_cmp(void) { #ifdef GPU_DIS_CMP - WriteLog("%06X: CMP R%02u, R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); + if (doGPUDis) + WriteLog("%06X: CMP R%02u, R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); #endif UINT32 res = RN - RM; SET_ZNC_SUB(RN, RM, res); #ifdef GPU_DIS_CMP - WriteLog("[NCZ:%u%u%u]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z); + if (doGPUDis) + WriteLog("[NCZ:%u%u%u]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z); #endif } @@ -1426,86 +1426,100 @@ static void gpu_opcode_cmpq(void) static int32 sqtable[32] = { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,-16,-15,-14,-13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1 }; #ifdef GPU_DIS_CMPQ - WriteLog("%06X: CMPQ #%d, R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", gpu_pc-2, sqtable[IMM_1], IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); + if (doGPUDis) + WriteLog("%06X: CMPQ #%d, R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", gpu_pc-2, sqtable[IMM_1], IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); #endif UINT32 r1 = sqtable[IMM_1 & 0x1F]; // I like this better -> (INT8)(jaguar.op >> 2) >> 3; UINT32 res = RN - r1; SET_ZNC_SUB(RN, r1, res); #ifdef GPU_DIS_CMPQ - WriteLog("[NCZ:%u%u%u]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z); + if (doGPUDis) + WriteLog("[NCZ:%u%u%u]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z); #endif } static void gpu_opcode_and(void) { #ifdef GPU_DIS_AND - WriteLog("%06X: AND R%02u, R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); + if (doGPUDis) + WriteLog("%06X: AND R%02u, R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); #endif RN = RN & RM; SET_ZN(RN); #ifdef GPU_DIS_AND - WriteLog("[NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); + if (doGPUDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); #endif } static void gpu_opcode_or(void) { #ifdef GPU_DIS_OR - WriteLog("%06X: OR R%02u, R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); + if (doGPUDis) + WriteLog("%06X: OR R%02u, R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); #endif RN = RN | RM; SET_ZN(RN); #ifdef GPU_DIS_OR - WriteLog("[NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); + if (doGPUDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); #endif } static void gpu_opcode_xor(void) { #ifdef GPU_DIS_XOR - WriteLog("%06X: XOR R%02u, R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); + if (doGPUDis) + WriteLog("%06X: XOR R%02u, R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); #endif RN = RN ^ RM; SET_ZN(RN); #ifdef GPU_DIS_XOR - WriteLog("[NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); + if (doGPUDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); #endif } static void gpu_opcode_not(void) { #ifdef GPU_DIS_NOT - WriteLog("%06X: NOT R%02u, R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); + if (doGPUDis) + WriteLog("%06X: NOT R%02u, R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); #endif RN = ~RN; SET_ZN(RN); #ifdef GPU_DIS_NOT - WriteLog("[NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); + if (doGPUDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); #endif } static void gpu_opcode_move_pc(void) { #ifdef GPU_DIS_MOVEPC - WriteLog("%06X: MOVE PC, R%02u [NCZ:%u%u%u, PC=%08X, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, gpu_pc-2, IMM_2, RN); + if (doGPUDis) + WriteLog("%06X: MOVE PC, R%02u [NCZ:%u%u%u, PC=%08X, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, gpu_pc-2, IMM_2, RN); #endif // Should be previous PC--this might not always be previous instruction! // Then again, this will point right at the *current* instruction, i.e., MOVE PC,R! RN = gpu_pc - 2; #ifdef GPU_DIS_MOVEPC - WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); + if (doGPUDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); #endif } static void gpu_opcode_sat8(void) { #ifdef GPU_DIS_SAT8 - WriteLog("%06X: SAT8 R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", gpu_pc-2, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); + if (doGPUDis) + WriteLog("%06X: SAT8 R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", gpu_pc-2, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); #endif RN = ((int32)RN < 0 ? 0 : (RN > 0xFF ? 0xFF : RN)); SET_ZN(RN); #ifdef GPU_DIS_SAT8 - WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); + if (doGPUDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); #endif } @@ -1524,68 +1538,78 @@ static void gpu_opcode_sat24(void) static void gpu_opcode_store_r14_indexed(void) { #ifdef GPU_DIS_STORE14I - WriteLog("%06X: STORE R%02u, (R14+$%02X) [NCZ:%u%u%u, R%02u=%08X, R14+$%02X=%08X]\n", gpu_pc-2, IMM_2, gpu_convert_zero[IMM_1] << 2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN, gpu_convert_zero[IMM_1] << 2, gpu_reg[14]+(gpu_convert_zero[IMM_1] << 2)); + if (doGPUDis) + WriteLog("%06X: STORE R%02u, (R14+$%02X) [NCZ:%u%u%u, R%02u=%08X, R14+$%02X=%08X]\n", gpu_pc-2, IMM_2, gpu_convert_zero[IMM_1] << 2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN, gpu_convert_zero[IMM_1] << 2, gpu_reg[14]+(gpu_convert_zero[IMM_1] << 2)); #endif - gpu_long_write(gpu_reg[14] + (gpu_convert_zero[IMM_1] << 2), RN); + GPUWriteLong(gpu_reg[14] + (gpu_convert_zero[IMM_1] << 2), RN, GPU); } static void gpu_opcode_store_r15_indexed(void) { #ifdef GPU_DIS_STORE15I - WriteLog("%06X: STORE R%02u, (R15+$%02X) [NCZ:%u%u%u, R%02u=%08X, R15+$%02X=%08X]\n", gpu_pc-2, IMM_2, gpu_convert_zero[IMM_1] << 2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN, gpu_convert_zero[IMM_1] << 2, gpu_reg[15]+(gpu_convert_zero[IMM_1] << 2)); + if (doGPUDis) + WriteLog("%06X: STORE R%02u, (R15+$%02X) [NCZ:%u%u%u, R%02u=%08X, R15+$%02X=%08X]\n", gpu_pc-2, IMM_2, gpu_convert_zero[IMM_1] << 2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN, gpu_convert_zero[IMM_1] << 2, gpu_reg[15]+(gpu_convert_zero[IMM_1] << 2)); #endif - gpu_long_write(gpu_reg[15] + (gpu_convert_zero[IMM_1] << 2), RN); + GPUWriteLong(gpu_reg[15] + (gpu_convert_zero[IMM_1] << 2), RN, GPU); } static void gpu_opcode_load_r14_ri(void) { #ifdef GPU_DIS_LOAD14R - WriteLog("%06X: LOAD (R14+R%02u), R%02u [NCZ:%u%u%u, R14+R%02u=%08X, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM+gpu_reg[14], IMM_2, RN); + if (doGPUDis) + WriteLog("%06X: LOAD (R14+R%02u), R%02u [NCZ:%u%u%u, R14+R%02u=%08X, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM+gpu_reg[14], IMM_2, RN); #endif - RN = gpu_long_read(gpu_reg[14] + RM); + RN = GPUReadLong(gpu_reg[14] + RM, GPU); #ifdef GPU_DIS_LOAD14R - WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); + if (doGPUDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); #endif } static void gpu_opcode_load_r15_ri(void) { #ifdef GPU_DIS_LOAD15R - WriteLog("%06X: LOAD (R15+R%02u), R%02u [NCZ:%u%u%u, R15+R%02u=%08X, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM+gpu_reg[15], IMM_2, RN); + if (doGPUDis) + WriteLog("%06X: LOAD (R15+R%02u), R%02u [NCZ:%u%u%u, R15+R%02u=%08X, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM+gpu_reg[15], IMM_2, RN); #endif - RN = gpu_long_read(gpu_reg[15] + RM); + RN = GPUReadLong(gpu_reg[15] + RM, GPU); #ifdef GPU_DIS_LOAD15R - WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); + if (doGPUDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); #endif } static void gpu_opcode_store_r14_ri(void) { #ifdef GPU_DIS_STORE14R - WriteLog("%06X: STORE R%02u, (R14+R%02u) [NCZ:%u%u%u, R%02u=%08X, R14+R%02u=%08X]\n", gpu_pc-2, IMM_2, IMM_1, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN, IMM_1, RM+gpu_reg[14]); + if (doGPUDis) + WriteLog("%06X: STORE R%02u, (R14+R%02u) [NCZ:%u%u%u, R%02u=%08X, R14+R%02u=%08X]\n", gpu_pc-2, IMM_2, IMM_1, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN, IMM_1, RM+gpu_reg[14]); #endif - gpu_long_write(gpu_reg[14] + RM, RN); + GPUWriteLong(gpu_reg[14] + RM, RN, GPU); } static void gpu_opcode_store_r15_ri(void) { #ifdef GPU_DIS_STORE15R - WriteLog("%06X: STORE R%02u, (R15+R%02u) [NCZ:%u%u%u, R%02u=%08X, R15+R%02u=%08X]\n", gpu_pc-2, IMM_2, IMM_1, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN, IMM_1, RM+gpu_reg[15]); + if (doGPUDis) + WriteLog("%06X: STORE R%02u, (R15+R%02u) [NCZ:%u%u%u, R%02u=%08X, R15+R%02u=%08X]\n", gpu_pc-2, IMM_2, IMM_1, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN, IMM_1, RM+gpu_reg[15]); #endif - gpu_long_write(gpu_reg[15] + RM, RN); + GPUWriteLong(gpu_reg[15] + RM, RN, GPU); } static void gpu_opcode_nop(void) { #ifdef GPU_DIS_NOP - WriteLog("%06X: NOP [NCZ:%u%u%u]\n", gpu_pc-2, gpu_flag_n, gpu_flag_c, gpu_flag_z); + if (doGPUDis) + WriteLog("%06X: NOP [NCZ:%u%u%u]\n", gpu_pc-2, gpu_flag_n, gpu_flag_c, gpu_flag_z); #endif } static void gpu_opcode_pack(void) { #ifdef GPU_DIS_PACK - WriteLog("%06X: %s R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", gpu_pc-2, (!IMM_1 ? "PACK " : "UNPACK"), IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); + if (doGPUDis) + WriteLog("%06X: %s R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", gpu_pc-2, (!IMM_1 ? "PACK " : "UNPACK"), IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); #endif uint32 val = RN; @@ -1595,169 +1619,193 @@ static void gpu_opcode_pack(void) else // Unpack RN = ((val & 0x0000F000) << 10) | ((val & 0x00000F00) << 5) | (val & 0x000000FF); #ifdef GPU_DIS_PACK - WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); + if (doGPUDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); #endif } static void gpu_opcode_storeb(void) { #ifdef GPU_DIS_STOREB - WriteLog("%06X: STOREB R%02u, (R%02u) [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", gpu_pc-2, IMM_2, IMM_1, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN, IMM_1, RM); + if (doGPUDis) + WriteLog("%06X: STOREB R%02u, (R%02u) [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", gpu_pc-2, IMM_2, IMM_1, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN, IMM_1, RM); #endif //Is this right??? // Would appear to be so...! if ((RM >= 0xF03000) && (RM <= 0xF03FFF)) - gpu_long_write(RM, RN & 0xFF); + GPUWriteLong(RM, RN & 0xFF, GPU); else - jaguar_byte_write(RM, RN); + JaguarWriteByte(RM, RN, GPU); } static void gpu_opcode_storew(void) { #ifdef GPU_DIS_STOREW - WriteLog("%06X: STOREW R%02u, (R%02u) [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", gpu_pc-2, IMM_2, IMM_1, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN, IMM_1, RM); + if (doGPUDis) + WriteLog("%06X: STOREW R%02u, (R%02u) [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", gpu_pc-2, IMM_2, IMM_1, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN, IMM_1, RM); #endif if ((RM >= 0xF03000) && (RM <= 0xF03FFF)) - gpu_long_write(RM, RN & 0xFFFF); + GPUWriteLong(RM, RN & 0xFFFF, GPU); else - jaguar_word_write(RM, RN); + JaguarWriteWord(RM, RN, GPU); } static void gpu_opcode_store(void) { #ifdef GPU_DIS_STORE - WriteLog("%06X: STORE R%02u, (R%02u) [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", gpu_pc-2, IMM_2, IMM_1, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN, IMM_1, RM); + if (doGPUDis) + WriteLog("%06X: STORE R%02u, (R%02u) [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", gpu_pc-2, IMM_2, IMM_1, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN, IMM_1, RM); #endif - gpu_long_write(RM, RN); + GPUWriteLong(RM, RN, GPU); } static void gpu_opcode_storep(void) { - gpu_long_write(RM + 0, gpu_hidata); - gpu_long_write(RM + 4, RN); + GPUWriteLong(RM + 0, gpu_hidata, GPU); + GPUWriteLong(RM + 4, RN, GPU); } static void gpu_opcode_loadb(void) { #ifdef GPU_DIS_LOADB - WriteLog("%06X: LOADB (R%02u), R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); + if (doGPUDis) + WriteLog("%06X: LOADB (R%02u), R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); #endif if ((RM >= 0xF03000) && (RM <= 0xF03FFF)) - RN = gpu_long_read(RM) & 0xFF; + RN = GPUReadLong(RM, GPU) & 0xFF; else - RN = jaguar_byte_read(RM); + RN = JaguarReadByte(RM, GPU); #ifdef GPU_DIS_LOADB - WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); + if (doGPUDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); #endif } static void gpu_opcode_loadw(void) { #ifdef GPU_DIS_LOADW - WriteLog("%06X: LOADW (R%02u), R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); + if (doGPUDis) + WriteLog("%06X: LOADW (R%02u), R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); #endif if ((RM >= 0xF03000) && (RM <= 0xF03FFF)) - RN = gpu_long_read(RM) & 0xFFFF; + RN = GPUReadLong(RM, GPU) & 0xFFFF; else - RN = jaguar_word_read(RM); + RN = JaguarReadWord(RM, GPU); #ifdef GPU_DIS_LOADW - WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); + if (doGPUDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); #endif } static void gpu_opcode_load(void) { #ifdef GPU_DIS_LOAD - WriteLog("%06X: LOAD (R%02u), R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); + if (doGPUDis) + WriteLog("%06X: LOAD (R%02u), R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); #endif - RN = gpu_long_read(RM); + RN = GPUReadLong(RM, GPU); #ifdef GPU_DIS_LOAD - WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); + if (doGPUDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); #endif } static void gpu_opcode_loadp(void) { - gpu_hidata = gpu_long_read(RM + 0); - RN = gpu_long_read(RM + 4); + gpu_hidata = GPUReadLong(RM + 0, GPU); + RN = GPUReadLong(RM + 4, GPU); } static void gpu_opcode_load_r14_indexed(void) { #ifdef GPU_DIS_LOAD14I - WriteLog("%06X: LOAD (R14+$%02X), R%02u [NCZ:%u%u%u, R14+$%02X=%08X, R%02u=%08X] -> ", gpu_pc-2, gpu_convert_zero[IMM_1] << 2, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, gpu_convert_zero[IMM_1] << 2, gpu_reg[14]+(gpu_convert_zero[IMM_1] << 2), IMM_2, RN); + if (doGPUDis) + WriteLog("%06X: LOAD (R14+$%02X), R%02u [NCZ:%u%u%u, R14+$%02X=%08X, R%02u=%08X] -> ", gpu_pc-2, gpu_convert_zero[IMM_1] << 2, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, gpu_convert_zero[IMM_1] << 2, gpu_reg[14]+(gpu_convert_zero[IMM_1] << 2), IMM_2, RN); #endif - RN = gpu_long_read(gpu_reg[14] + (gpu_convert_zero[IMM_1] << 2)); + RN = GPUReadLong(gpu_reg[14] + (gpu_convert_zero[IMM_1] << 2), GPU); #ifdef GPU_DIS_LOAD14I - WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); + if (doGPUDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); #endif } static void gpu_opcode_load_r15_indexed(void) { #ifdef GPU_DIS_LOAD15I - WriteLog("%06X: LOAD (R15+$%02X), R%02u [NCZ:%u%u%u, R15+$%02X=%08X, R%02u=%08X] -> ", gpu_pc-2, gpu_convert_zero[IMM_1] << 2, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, gpu_convert_zero[IMM_1] << 2, gpu_reg[15]+(gpu_convert_zero[IMM_1] << 2), IMM_2, RN); + if (doGPUDis) + WriteLog("%06X: LOAD (R15+$%02X), R%02u [NCZ:%u%u%u, R15+$%02X=%08X, R%02u=%08X] -> ", gpu_pc-2, gpu_convert_zero[IMM_1] << 2, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, gpu_convert_zero[IMM_1] << 2, gpu_reg[15]+(gpu_convert_zero[IMM_1] << 2), IMM_2, RN); #endif - RN = gpu_long_read(gpu_reg[15] + (gpu_convert_zero[IMM_1] << 2)); + RN = GPUReadLong(gpu_reg[15] + (gpu_convert_zero[IMM_1] << 2), GPU); #ifdef GPU_DIS_LOAD15I - WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); + if (doGPUDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); #endif } static void gpu_opcode_movei(void) { #ifdef GPU_DIS_MOVEI - WriteLog("%06X: MOVEI #$%08X, R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", gpu_pc-2, (uint32)gpu_word_read(gpu_pc) | ((uint32)gpu_word_read(gpu_pc + 2) << 16), IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); + if (doGPUDis) + WriteLog("%06X: MOVEI #$%08X, R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", gpu_pc-2, (uint32)GPUReadWord(gpu_pc) | ((uint32)GPUReadWord(gpu_pc + 2) << 16), IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); #endif // This instruction is followed by 32-bit value in LSW / MSW format... - RN = (uint32)gpu_word_read(gpu_pc) | ((uint32)gpu_word_read(gpu_pc + 2) << 16); + RN = (uint32)GPUReadWord(gpu_pc, GPU) | ((uint32)GPUReadWord(gpu_pc + 2, GPU) << 16); gpu_pc += 4; #ifdef GPU_DIS_MOVEI - WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); + if (doGPUDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); #endif } static void gpu_opcode_moveta(void) { #ifdef GPU_DIS_MOVETA - WriteLog("%06X: MOVETA R%02u, R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u(alt)=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, ALTERNATE_RN); + if (doGPUDis) + WriteLog("%06X: MOVETA R%02u, R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u(alt)=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, ALTERNATE_RN); #endif ALTERNATE_RN = RM; #ifdef GPU_DIS_MOVETA - WriteLog("[NCZ:%u%u%u, R%02u=%08X, R%02u(alt)=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, ALTERNATE_RN); + if (doGPUDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X, R%02u(alt)=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, ALTERNATE_RN); #endif } static void gpu_opcode_movefa(void) { #ifdef GPU_DIS_MOVEFA - WriteLog("%06X: MOVEFA R%02u, R%02u [NCZ:%u%u%u, R%02u(alt)=%08X, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, ALTERNATE_RM, IMM_2, RN); + if (doGPUDis) + WriteLog("%06X: MOVEFA R%02u, R%02u [NCZ:%u%u%u, R%02u(alt)=%08X, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, ALTERNATE_RM, IMM_2, RN); #endif RN = ALTERNATE_RM; #ifdef GPU_DIS_MOVEFA - WriteLog("[NCZ:%u%u%u, R%02u(alt)=%08X, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, ALTERNATE_RM, IMM_2, RN); + if (doGPUDis) + WriteLog("[NCZ:%u%u%u, R%02u(alt)=%08X, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, ALTERNATE_RM, IMM_2, RN); #endif } static void gpu_opcode_move(void) { #ifdef GPU_DIS_MOVE - WriteLog("%06X: MOVE R%02u, R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); + if (doGPUDis) + WriteLog("%06X: MOVE R%02u, R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); #endif RN = RM; #ifdef GPU_DIS_MOVE - WriteLog("[NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); + if (doGPUDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); #endif } static void gpu_opcode_moveq(void) { #ifdef GPU_DIS_MOVEQ - WriteLog("%06X: MOVEQ #%u, R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); + if (doGPUDis) + WriteLog("%06X: MOVEQ #%u, R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); #endif RN = IMM_1; #ifdef GPU_DIS_MOVEQ - WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); + if (doGPUDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); #endif } @@ -1769,61 +1817,71 @@ static void gpu_opcode_resmac(void) static void gpu_opcode_imult(void) { #ifdef GPU_DIS_IMULT - WriteLog("%06X: IMULT R%02u, R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); + if (doGPUDis) + WriteLog("%06X: IMULT R%02u, R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); #endif RN = (int16)RN * (int16)RM; SET_ZN(RN); #ifdef GPU_DIS_IMULT - WriteLog("[NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); + if (doGPUDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); #endif } static void gpu_opcode_mult(void) { #ifdef GPU_DIS_MULT - WriteLog("%06X: MULT R%02u, R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); + if (doGPUDis) + WriteLog("%06X: MULT R%02u, R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); #endif RN = (uint16)RM * (uint16)RN; SET_ZN(RN); #ifdef GPU_DIS_MULT - WriteLog("[NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); + if (doGPUDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); #endif } static void gpu_opcode_bclr(void) { #ifdef GPU_DIS_BCLR - WriteLog("%06X: BCLR #%u, R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); + if (doGPUDis) + WriteLog("%06X: BCLR #%u, R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); #endif UINT32 res = RN & ~(1 << IMM_1); RN = res; SET_ZN(res); #ifdef GPU_DIS_BCLR - WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); + if (doGPUDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); #endif } static void gpu_opcode_btst(void) { #ifdef GPU_DIS_BTST - WriteLog("%06X: BTST #%u, R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); + if (doGPUDis) + WriteLog("%06X: BTST #%u, R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); #endif gpu_flag_z = (~RN >> IMM_1) & 1; #ifdef GPU_DIS_BTST - WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); + if (doGPUDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); #endif } static void gpu_opcode_bset(void) { #ifdef GPU_DIS_BSET - WriteLog("%06X: BSET #%u, R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); + if (doGPUDis) + WriteLog("%06X: BSET #%u, R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); #endif UINT32 res = RN | (1 << IMM_1); RN = res; SET_ZN(res); #ifdef GPU_DIS_BSET - WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); + if (doGPUDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); #endif } @@ -1879,7 +1937,7 @@ static void gpu_opcode_mmult(void) else a = (int16)(gpu_alternate_reg[IMM_1 + (i >> 1)] & 0xFFFF); - int16 b = ((int16)gpu_word_read(addr + 2)); + int16 b = ((int16)GPUReadWord(addr + 2, GPU)); accum += a * b; addr += 4 * count; } @@ -1894,7 +1952,7 @@ static void gpu_opcode_mmult(void) else a = (int16)(gpu_alternate_reg[IMM_1 + (i >> 1)] & 0xFFFF); - int16 b = ((int16)gpu_word_read(addr + 2)); + int16 b = ((int16)GPUReadWord(addr + 2, GPU)); accum += a * b; addr += 4; } @@ -1907,7 +1965,8 @@ static void gpu_opcode_mmult(void) static void gpu_opcode_abs(void) { #ifdef GPU_DIS_ABS - WriteLog("%06X: ABS R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", gpu_pc-2, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); + if (doGPUDis) + WriteLog("%06X: ABS R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", gpu_pc-2, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); #endif gpu_flag_c = RN >> 31; if (RN == 0x80000000) @@ -1920,14 +1979,16 @@ static void gpu_opcode_abs(void) gpu_flag_n = 0; SET_FLAG_Z(RN); } #ifdef GPU_DIS_ABS - WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); + if (doGPUDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); #endif } static void gpu_opcode_div(void) // RN / RM { #ifdef GPU_DIS_DIV - WriteLog("%06X: DIV R%02u, R%02u (%s) [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, (gpu_div_control & 0x01 ? "16.16" : "32"), gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); + if (doGPUDis) + WriteLog("%06X: DIV R%02u, R%02u (%s) [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, (gpu_div_control & 0x01 ? "16.16" : "32"), gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); #endif // NOTE: remainder is NOT calculated correctly here! // The original tried to get it right by checking to see if the @@ -1976,7 +2037,8 @@ static void gpu_opcode_div(void) // RN / RM else RN=0xffffffff;*/ #ifdef GPU_DIS_DIV - WriteLog("[NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] Remainder: %08X\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN, gpu_remain); + if (doGPUDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] Remainder: %08X\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN, gpu_remain); #endif } @@ -1991,27 +2053,23 @@ static void gpu_opcode_imultn(void) static void gpu_opcode_neg(void) { #ifdef GPU_DIS_NEG - WriteLog("%06X: NEG R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", gpu_pc-2, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); + if (doGPUDis) + WriteLog("%06X: NEG R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", gpu_pc-2, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); #endif UINT32 res = -RN; SET_ZNC_SUB(0, RN, res); RN = res; #ifdef GPU_DIS_NEG - WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); + if (doGPUDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); #endif } static void gpu_opcode_shlq(void) { -/* int dreg = jaguar.op & 31; - INT32 r1 = convert_zero[(jaguar.op >> 5) & 31]; - UINT32 r2 = jaguar.r[dreg]; - UINT32 res = r2 << (32 - r1); - jaguar.r[dreg] = res; - CLR_ZNC; SET_ZN(res); jaguar.FLAGS |= (r2 >> 30) & 2;*/ - #ifdef GPU_DIS_SHLQ - WriteLog("%06X: SHLQ #%u, R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", gpu_pc-2, 32 - IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); + if (doGPUDis) + WriteLog("%06X: SHLQ #%u, R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", gpu_pc-2, 32 - IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); #endif // Was a bug here... // (Look at Aaron's code: If r1 = 32, then 32 - 32 = 0 which is wrong!) @@ -2020,63 +2078,48 @@ static void gpu_opcode_shlq(void) SET_ZN(res); gpu_flag_c = (RN >> 31) & 1; RN = res; #ifdef GPU_DIS_SHLQ - WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); + if (doGPUDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); #endif } static void gpu_opcode_shrq(void) { -/* int dreg = jaguar.op & 31; - INT32 r1 = convert_zero[(jaguar.op >> 5) & 31]; - UINT32 r2 = jaguar.r[dreg]; - UINT32 res = r2 >> r1; - jaguar.r[dreg] = res; - CLR_ZNC; SET_ZN(res); jaguar.FLAGS |= (r2 << 1) & 2;*/ - #ifdef GPU_DIS_SHRQ - WriteLog("%06X: SHRQ #%u, R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", gpu_pc-2, gpu_convert_zero[IMM_1], IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); + if (doGPUDis) + WriteLog("%06X: SHRQ #%u, R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", gpu_pc-2, gpu_convert_zero[IMM_1], IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); #endif INT32 r1 = gpu_convert_zero[IMM_1]; UINT32 res = RN >> r1; SET_ZN(res); gpu_flag_c = RN & 1; RN = res; #ifdef GPU_DIS_SHRQ - WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); + if (doGPUDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); #endif } static void gpu_opcode_ror(void) { -/* int dreg = jaguar.op & 31; - UINT32 r1 = jaguar.r[(jaguar.op >> 5) & 31] & 31; - UINT32 r2 = jaguar.r[dreg]; - UINT32 res = (r2 >> r1) | (r2 << (32 - r1)); - jaguar.r[dreg] = res; - CLR_ZNC; SET_ZN(res); jaguar.FLAGS |= (r2 >> 30) & 2;*/ - #ifdef GPU_DIS_ROR - WriteLog("%06X: ROR R%02u, R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); + if (doGPUDis) + WriteLog("%06X: ROR R%02u, R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); #endif UINT32 r1 = RM & 0x1F; UINT32 res = (RN >> r1) | (RN << (32 - r1)); SET_ZN(res); gpu_flag_c = (RN >> 31) & 1; RN = res; #ifdef GPU_DIS_ROR - WriteLog("[NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); + if (doGPUDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); #endif } static void gpu_opcode_rorq(void) { -/* int dreg = jaguar.op & 31; - UINT32 r1 = convert_zero[(jaguar.op >> 5) & 31]; - UINT32 r2 = jaguar.r[dreg]; - UINT32 res = (r2 >> r1) | (r2 << (32 - r1)); - jaguar.r[dreg] = res; - CLR_ZNC; SET_ZN(res); jaguar.FLAGS |= (r2 >> 30) & 2;*/ - #ifdef GPU_DIS_RORQ - WriteLog("%06X: RORQ #%u, R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", gpu_pc-2, gpu_convert_zero[IMM_1], IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); + if (doGPUDis) + WriteLog("%06X: RORQ #%u, R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", gpu_pc-2, gpu_convert_zero[IMM_1], IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); #endif UINT32 r1 = gpu_convert_zero[IMM_1 & 0x1F]; UINT32 r2 = RN; @@ -2084,7 +2127,8 @@ static void gpu_opcode_rorq(void) RN = res; SET_ZN(res); gpu_flag_c = (r2 >> 31) & 0x01; #ifdef GPU_DIS_RORQ - WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); + if (doGPUDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); #endif } @@ -2110,7 +2154,8 @@ static void gpu_opcode_sha(void) SET_ZN(res);*/ #ifdef GPU_DIS_SHA - WriteLog("%06X: SHA R%02u, R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); + if (doGPUDis) + WriteLog("%06X: SHA R%02u, R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); #endif UINT32 res; @@ -2127,7 +2172,8 @@ static void gpu_opcode_sha(void) RN = res; SET_ZN(res); #ifdef GPU_DIS_SHA - WriteLog("[NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); + if (doGPUDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); #endif /* int32 sRM=(int32)RM; @@ -2162,42 +2208,24 @@ static void gpu_opcode_sha(void) static void gpu_opcode_sharq(void) { -/* int dreg = jaguar.op & 31; - INT32 r1 = convert_zero[(jaguar.op >> 5) & 31]; - UINT32 r2 = jaguar.r[dreg]; - UINT32 res = (INT32)r2 >> r1; - jaguar.r[dreg] = res; - CLR_ZNC; SET_ZN(res); jaguar.FLAGS |= (r2 << 1) & 2;*/ - #ifdef GPU_DIS_SHARQ - WriteLog("%06X: SHARQ #%u, R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", gpu_pc-2, gpu_convert_zero[IMM_1], IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); + if (doGPUDis) + WriteLog("%06X: SHARQ #%u, R%02u [NCZ:%u%u%u, R%02u=%08X] -> ", gpu_pc-2, gpu_convert_zero[IMM_1], IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); #endif UINT32 res = (INT32)RN >> gpu_convert_zero[IMM_1]; SET_ZN(res); gpu_flag_c = RN & 0x01; RN = res; #ifdef GPU_DIS_SHARQ - WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); + if (doGPUDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_2, RN); #endif - -//OLD: -/* uint32 shift = gpu_convert_zero[IMM_1]; - uint32 _RN = RN; - - gpu_flag_c = (_RN & 0x01); - while (shift) - { - _RN = ((int32)_RN) >> 1; - shift--; - } - RN = _RN; - SET_FLAG_Z(_RN); - SET_FLAG_N(_RN);*/ } static void gpu_opcode_sh(void) { #ifdef GPU_DIS_SH - WriteLog("%06X: SH R%02u, R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); + if (doGPUDis) + WriteLog("%06X: SH R%02u, R%02u [NCZ:%u%u%u, R%02u=%08X, R%02u=%08X] -> ", gpu_pc-2, IMM_1, IMM_2, gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); #endif if (RM & 0x80000000) // Shift left { @@ -2211,10 +2239,11 @@ static void gpu_opcode_sh(void) } SET_ZN(RN); #ifdef GPU_DIS_SH - WriteLog("[NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); + if (doGPUDis) + WriteLog("[NCZ:%u%u%u, R%02u=%08X, R%02u=%08X]\n", gpu_flag_n, gpu_flag_c, gpu_flag_z, IMM_1, RM, IMM_2, RN); #endif } //Temporary: Testing only! -#include "gpu2.cpp" -#include "gpu3.cpp" +//#include "gpu2.cpp" +//#include "gpu3.cpp" diff --git a/src/gui.cpp b/src/gui.cpp index 17e522c..bf4c30e 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -5,8 +5,10 @@ // by James L. Hammons // +#include #include "types.h" #include "tom.h" +#include "font1.h" #include "gui.h" void InitGUI(void) @@ -17,7 +19,31 @@ void GUIDone(void) { } -void DrawText(uint16 * screen, uint32 x, uint32 y, const char * string) +void DrawText(int16 * screen, uint32 x, uint32 y, const char * text, ...) { - uint32 pitch = TOMGetSDLScreenPitch(); + char string[4096]; + va_list arg; + + va_start(arg, text); + vsprintf(string, text, arg); + va_end(arg); + + uint32 pitch = TOMGetSDLScreenPitch() / 2; // Returns pitch in bytes but we need words... + uint32 length = strlen(string), address = x + (y * pitch); + + for(uint32 i=0; i -typedef unsigned char BYTE; -typedef unsigned short WORD; -typedef unsigned long DWORD; -#ifdef __GCCUNIX__ -typedef long long __int64; // Could probably remove this crap with some judicious pruning -#endif // #ifdef __GCCUNIX__ -typedef int HWND; -#else -#include -#endif // #ifdef __PORT__ +#include // Why??? + +//typedef unsigned char BYTE; +//typedef unsigned short WORD; +//typedef unsigned long DWORD; +//#ifdef __GCCUNIX__ +//typedef long long __int64; // Could probably remove this crap with some judicious pruning +//#endif // This is only good on certain intel 32-bit platforms... // You may need to tweak to suit your specific platform. @@ -39,4 +36,8 @@ typedef INT32 int32; typedef UINT64 uint64; typedef INT64 int64; -#endif // #ifndef __TYPES_H__ +// Read/write tracing enumeration + +enum { UNKNOWN, JAGUAR, DSP, GPU, TOM, JERRY, M68K, BLITTER, OP }; + +#endif // __TYPES_H__ diff --git a/src/jagdasm.cpp b/src/jagdasm.cpp index fb0652c..20981bd 100644 --- a/src/jagdasm.cpp +++ b/src/jagdasm.cpp @@ -1,6 +1,6 @@ #include "jaguar.h" -#define ROPCODE(a) jaguar_word_read(a) +#define ROPCODE(a) JaguarReadWord(a) uint8 convert_zero[32] = { 32,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31 }; diff --git a/src/jaguar.cpp b/src/jaguar.cpp index a658266..2b91abc 100644 --- a/src/jaguar.cpp +++ b/src/jaguar.cpp @@ -11,25 +11,27 @@ #include "jaguar.h" //#include "m68kdasmAG.h" -//#define LOG_UNMAPPED_MEMORY_ACCESSES -//#define SOUND_OUTPUT #define CPU_DEBUG -#define JAGUAR_WIP_RELEASE //Do this in makefile??? Yes! Could, but it's easier to define here... -//#define LOG_UNMAPPED_MEMORY_ACCESSES +#define LOG_UNMAPPED_MEMORY_ACCESSES // Private function prototypes -unsigned jaguar_unknown_readbyte(unsigned address); -unsigned jaguar_unknown_readword(unsigned address); -void jaguar_unknown_writebyte(unsigned address, unsigned data); -void jaguar_unknown_writeword(unsigned address, unsigned data); +unsigned jaguar_unknown_readbyte(unsigned address, uint32 who = UNKNOWN); +unsigned jaguar_unknown_readword(unsigned address, uint32 who = UNKNOWN); +void jaguar_unknown_writebyte(unsigned address, unsigned data, uint32 who = UNKNOWN); +void jaguar_unknown_writeword(unsigned address, unsigned data, uint32 who = UNKNOWN); void M68K_show_context(void); // External variables extern bool hardwareTypeNTSC; // Set to false for PAL +// Memory debugging identifiers + +char * whoName[9] = + { "Unknown", "Jaguar", "DSP", "GPU", "TOM", "JERRY", "M68K", "Blitter", "OP" }; + // These values are overridden by command line switches... bool dsp_enabled = false; @@ -62,21 +64,21 @@ void M68KInstructionHook(void) /* if (m68kPC == 0x803F16) { WriteLog("M68K: Registers found at $803F16:\n"); - WriteLog( "\t68K PC=%06X\n", m68k_get_reg(NULL, M68K_REG_PC)); + WriteLog("\t68K PC=%06X\n", m68k_get_reg(NULL, M68K_REG_PC)); for(int i=M68K_REG_D0; i<=M68K_REG_D7; i++) - WriteLog( "\tD%i = %08X\n", i-M68K_REG_D0, m68k_get_reg(NULL, (m68k_register_t)i)); - WriteLog( "\n"); + WriteLog("\tD%i = %08X\n", i-M68K_REG_D0, m68k_get_reg(NULL, (m68k_register_t)i)); + WriteLog("\n"); for(int i=M68K_REG_A0; i<=M68K_REG_A7; i++) - WriteLog( "\tA%i = %08X\n", i-M68K_REG_A0, m68k_get_reg(NULL, (m68k_register_t)i)); + WriteLog("\tA%i = %08X\n", i-M68K_REG_A0, m68k_get_reg(NULL, (m68k_register_t)i)); }*/ - if (!m68k_is_valid_instruction(jaguar_word_read(m68kPC), M68K_CPU_TYPE_68000)) + if (!m68k_is_valid_instruction(JaguarReadWord(m68kPC), M68K_CPU_TYPE_68000)) { - WriteLog("\nEncountered illegal instruction at %08X!!!\n\nAborting!\n", m68kPC); + WriteLog("\nM68K encountered an illegal instruction at %08X!!!\n\nAborting!\n", m68kPC); uint32 topOfStack = m68k_get_reg(NULL, M68K_REG_A7); - WriteLog("M68K: Top of stack: %08X. Stack trace:\n", jaguar_long_read(topOfStack)); + WriteLog("M68K: Top of stack: %08X. Stack trace:\n", JaguarReadLong(topOfStack)); for(int i=0; i<10; i++) - WriteLog("%06X: %08X\n", topOfStack - (i * 4), jaguar_long_read(topOfStack - (i * 4))); + WriteLog("%06X: %08X\n", topOfStack - (i * 4), JaguarReadLong(topOfStack - (i * 4))); WriteLog("Jaguar: VBL interrupt is %s\n", ((tom_irq_enabled(IRQ_VBLANK)) && (jaguar_interrupt_handler_is_valid(64))) ? "enabled" : "disabled"); M68K_show_context(); log_done(); @@ -105,7 +107,7 @@ int irq_ack_handler(int level) unsigned int m68k_read_memory_8(unsigned int address) { -//WriteLog( "[RM8] Addr: %08X\n", address); +//WriteLog("[RM8] Addr: %08X\n", address); unsigned int retVal = 0; if ((address >= 0x000000) && (address <= 0x3FFFFF)) @@ -115,13 +117,13 @@ unsigned int m68k_read_memory_8(unsigned int address) else if ((address >= 0xE00000) && (address <= 0xE3FFFF)) retVal = jaguar_bootRom[address - 0xE00000]; else if ((address >= 0xDFFF00) && (address <= 0xDFFFFF)) - retVal = cdrom_byte_read(address); + retVal = CDROMReadByte(address); else if ((address >= 0xF00000) && (address <= 0xF0FFFF)) - retVal = tom_byte_read(address); + retVal = TOMReadByte(address, M68K); else if ((address >= 0xF10000) && (address <= 0xF1FFFF)) - retVal = jerry_byte_read(address); + retVal = JERRYReadByte(address, M68K); else - retVal = jaguar_unknown_readbyte(address); + retVal = jaguar_unknown_readbyte(address, M68K); return retVal; } @@ -131,7 +133,7 @@ void gpu_dump_registers(void); unsigned int m68k_read_memory_16(unsigned int address) { -//WriteLog( "[RM16] Addr: %08X\n", address); +//WriteLog("[RM16] Addr: %08X\n", address); /*if (m68k_get_reg(NULL, M68K_REG_PC) == 0x00005FBA) // for(int i=0; i<10000; i++) WriteLog("[M68K] In routine #6!\n");//*/ @@ -139,13 +141,13 @@ unsigned int m68k_read_memory_16(unsigned int address) //if (m68k_get_reg(NULL, M68K_REG_PC) == 0x00005B3C) // GPU Program #2 /*if (m68k_get_reg(NULL, M68K_REG_PC) == 0x00005BA8) // GPU Program #3 { - WriteLog("[M68K] About to run GPU! (Addr:%08X, data:%04X)\n", address, tom_word_read(address)); + WriteLog("[M68K] About to run GPU! (Addr:%08X, data:%04X)\n", address, TOMReadWord(address)); gpu_dump_registers(); gpu_dump_disassembly(); // for(int i=0; i<10000; i++) -// WriteLog( "[M68K] About to run GPU!\n"); +// WriteLog("[M68K] About to run GPU!\n"); }//*/ -//WriteLog( "[WM8 PC=%08X] Addr: %08X, val: %02X\n", m68k_get_reg(NULL, M68K_REG_PC), address, value); +//WriteLog("[WM8 PC=%08X] Addr: %08X, val: %02X\n", m68k_get_reg(NULL, M68K_REG_PC), address, value); /*if (m68k_get_reg(NULL, M68K_REG_PC) >= 0x00006696 && m68k_get_reg(NULL, M68K_REG_PC) <= 0x000066A8) { if (address == 0x000066A0) @@ -154,7 +156,7 @@ unsigned int m68k_read_memory_16(unsigned int address) gpu_dump_disassembly(); } for(int i=0; i<10000; i++) - WriteLog( "[M68K] About to run GPU! (Addr:%08X, data:%04X)\n", address, tom_word_read(address)); + WriteLog("[M68K] About to run GPU! (Addr:%08X, data:%04X)\n", address, TOMReadWord(address)); }//*/ unsigned int retVal = 0; @@ -165,23 +167,20 @@ unsigned int m68k_read_memory_16(unsigned int address) else if ((address >= 0xE00000) && (address <= 0xE3FFFE)) retVal = (jaguar_bootRom[address - 0xE00000] << 8) | jaguar_bootRom[address - 0xE00000 + 1]; else if ((address >= 0xDFFF00) && (address <= 0xDFFFFE)) - retVal = cdrom_word_read(address); + retVal = CDROMReadWord(address, M68K); else if ((address >= 0xF00000) && (address <= 0xF0FFFE)) - retVal = tom_word_read(address); + retVal = TOMReadWord(address, M68K); else if ((address >= 0xF10000) && (address <= 0xF1FFFE)) - retVal = jerry_word_read(address); + retVal = JERRYReadWord(address, M68K); else -//{ -//WriteLog( "[RM16] Unknown address: %08X\n", address); - retVal = jaguar_unknown_readword(address); -//} + retVal = jaguar_unknown_readword(address, M68K); return retVal; } unsigned int m68k_read_memory_32(unsigned int address) { -//WriteLog( "--> [RM32]\n"); +//WriteLog("--> [RM32]\n"); return (m68k_read_memory_16(address) << 16) | m68k_read_memory_16(address + 2); } @@ -189,42 +188,24 @@ void m68k_write_memory_8(unsigned int address, unsigned int value) { //if ((address >= 0x1FF020 && address <= 0x1FF03F) || (address >= 0x1FF820 && address <= 0x1FF83F)) // WriteLog("M68K: Writing %02X at %08X\n", value, address); -//WriteLog( "[WM8 PC=%08X] Addr: %08X, val: %02X\n", m68k_get_reg(NULL, M68K_REG_PC), address, value); +//WriteLog("[WM8 PC=%08X] Addr: %08X, val: %02X\n", m68k_get_reg(NULL, M68K_REG_PC), address, value); if ((address >= 0x000000) && (address <= 0x3FFFFF)) jaguar_mainRam[address] = value; else if ((address >= 0xDFFF00) && (address <= 0xDFFFFF)) - cdrom_byte_write(address, value); + CDROMWriteByte(address, value, M68K); else if ((address >= 0xF00000) && (address <= 0xF0FFFF)) - tom_byte_write(address, value); + TOMWriteByte(address, value, M68K); else if ((address >= 0xF10000) && (address <= 0xF1FFFF)) - jerry_byte_write(address, value); + JERRYWriteByte(address, value, M68K); else - jaguar_unknown_writebyte(address, value); + jaguar_unknown_writebyte(address, value, M68K); } void m68k_write_memory_16(unsigned int address, unsigned int value) { -extern int dsp_pc;//, dsp_control; -if (address == 0xF1A116 && (value & 0x01)) -{ - WriteLog(" M68K(16): DSP is GO! (DSP_PC: %08X)\n\n", dsp_pc); - -/* static char buffer[512]; - uint32 j = 0xF1B000; - while (j <= 0xF1BFFF) - { - uint32 oldj = j; - j += dasmjag(JAGUAR_DSP, buffer, j); - WriteLog( "\t%08X: %s\n", oldj, buffer); - } - WriteLog( "\n");//*/ -} -//else -// WriteLog("M68K(16): DSP halted... (Old value: %08X)\n", dsp_control); - //if ((address >= 0x1FF020 && address <= 0x1FF03F) || (address >= 0x1FF820 && address <= 0x1FF83F)) // WriteLog("M68K: Writing %04X at %08X\n", value, address); -//WriteLog( "[WM16 PC=%08X] Addr: %08X, val: %04X\n", m68k_get_reg(NULL, M68K_REG_PC), address, value); +//WriteLog("[WM16 PC=%08X] Addr: %08X, val: %04X\n", m68k_get_reg(NULL, M68K_REG_PC), address, value); //if (address >= 0xF02200 && address <= 0xF0229F) // WriteLog("M68K: Writing to blitter --> %04X at %08X\n", value, address); //if (address >= 0x0E75D0 && address <= 0x0E75E7) @@ -242,39 +223,31 @@ if (address == 0xF02110) if ((address >= 0x000000) && (address <= 0x3FFFFE)) { - jaguar_mainRam[address] = value >> 8; - jaguar_mainRam[address + 1] = value & 0xFF; +/* jaguar_mainRam[address] = value >> 8; + jaguar_mainRam[address + 1] = value & 0xFF;*/ + SET16(jaguar_mainRam, address, value); } else if ((address >= 0xDFFF00) && (address <= 0xDFFFFE)) - cdrom_word_write(address, value); + CDROMWriteWord(address, value, M68K); else if ((address >= 0xF00000) && (address <= 0xF0FFFE)) - tom_word_write(address, value); + TOMWriteWord(address, value, M68K); else if ((address >= 0xF10000) && (address <= 0xF1FFFE)) - jerry_word_write(address, value); + JERRYWriteWord(address, value, M68K); else - jaguar_unknown_writeword(address, value); + jaguar_unknown_writeword(address, value, M68K); } void m68k_write_memory_32(unsigned int address, unsigned int value) { -extern int dsp_pc;//, dsp_control; -if (address == 0xF1A114 && (value & 0x01)) - WriteLog("M68K(32): DSP is GO! (DSP_PC: %08X)\n", dsp_pc); -//else -// WriteLog("M68K(32): DSP halted... (Old value: %08X)\n", dsp_control); - -//WriteLog( "--> [WM32]\n"); +//WriteLog("--> [WM32]\n"); m68k_write_memory_16(address, value >> 16); m68k_write_memory_16(address + 2, value & 0xFFFF); } - uint32 jaguar_get_handler(uint32 i) { -// return (jaguar_word_read(i<<2) << 16) | jaguar_word_read((i<<2) + 2); -// return (jaguar_word_read(i*4) << 16) | jaguar_word_read((i*4) + 2); - return jaguar_long_read(i * 4); + return JaguarReadLong(i * 4); } uint32 jaguar_interrupt_handler_is_valid(uint32 i) @@ -288,64 +261,84 @@ uint32 jaguar_interrupt_handler_is_valid(uint32 i) void M68K_show_context(void) { - WriteLog( "\t68K PC=%06X\n", m68k_get_reg(NULL, M68K_REG_PC)); + WriteLog("\t68K PC=%06X\n", m68k_get_reg(NULL, M68K_REG_PC)); for(int i=M68K_REG_D0; i<=M68K_REG_D7; i++) - WriteLog( "\tD%i = %08X\n", i-M68K_REG_D0, m68k_get_reg(NULL, (m68k_register_t)i)); - WriteLog( "\n"); + WriteLog("\tD%i = %08X\n", i-M68K_REG_D0, m68k_get_reg(NULL, (m68k_register_t)i)); + WriteLog("\n"); for(int i=M68K_REG_A0; i<=M68K_REG_A7; i++) - WriteLog( "\tA%i = %08X\n", i-M68K_REG_A0, m68k_get_reg(NULL, (m68k_register_t)i)); + WriteLog("\tA%i = %08X\n", i-M68K_REG_A0, m68k_get_reg(NULL, (m68k_register_t)i)); - WriteLog( "68K disasm\n"); + WriteLog("68K disasm\n"); // jaguar_dasm(s68000readPC()-0x1000,0x20000); jaguar_dasm(m68k_get_reg(NULL, M68K_REG_PC) - 0x80, 0x200); // jaguar_dasm(0x5000, 0x14414); - WriteLog( "..................\n"); + WriteLog("..................\n"); if (tom_irq_enabled(IRQ_VBLANK)) { - WriteLog( "vblank int: enabled\n"); + WriteLog("vblank int: enabled\n"); jaguar_dasm(jaguar_get_handler(64), 0x200); } else - WriteLog( "vblank int: disabled\n"); + WriteLog("vblank int: disabled\n"); - WriteLog( "..................\n"); + WriteLog("..................\n"); for(int i=0; i<256; i++) - WriteLog( "handler %03i at $%08X\n", i, (unsigned int)jaguar_get_handler(i)); + WriteLog("handler %03i at $%08X\n", i, (unsigned int)jaguar_get_handler(i)); } // // Unknown read/write byte/word routines // -void jaguar_unknown_writebyte(unsigned address, unsigned data) +void jaguar_unknown_writebyte(unsigned address, unsigned data, uint32 who/*=UNKNOWN*/) { #ifdef LOG_UNMAPPED_MEMORY_ACCESSES - WriteLog( "jaguar: unknown byte %02X write at %08X (PC=%06X)\n", data, address, m68k_get_reg(NULL, M68K_REG_PC)); + WriteLog("Jaguar: Unknown byte %02X written at %08X by %s (M68K PC=%06X)\n", data, address, whoName[who], m68k_get_reg(NULL, M68K_REG_PC)); + extern bool finished; + finished = true; + extern bool doDSPDis; + if (who == DSP) + doDSPDis = true; #endif } -void jaguar_unknown_writeword(unsigned address, unsigned data) +void jaguar_unknown_writeword(unsigned address, unsigned data, uint32 who/*=UNKNOWN*/) { #ifdef LOG_UNMAPPED_MEMORY_ACCESSES - WriteLog( "jaguar: unknown word %04X write at %08X (PC=%06X)\n", data, address, m68k_get_reg(NULL, M68K_REG_PC)); + WriteLog("Jaguar: Unknown word %04X written at %08X by %s (M68K PC=%06X)\n", data, address, whoName[who], m68k_get_reg(NULL, M68K_REG_PC)); + extern bool finished; + finished = true; + extern bool doDSPDis; + if (who == DSP) + doDSPDis = true; #endif } -unsigned jaguar_unknown_readbyte(unsigned address) +unsigned jaguar_unknown_readbyte(unsigned address, uint32 who/*=UNKNOWN*/) { #ifdef LOG_UNMAPPED_MEMORY_ACCESSES - WriteLog( "jaguar: unknown byte read at %08X (PC=%06X)\n", address, m68k_get_reg(NULL, M68K_REG_PC)); + WriteLog("Jaguar: Unknown byte read at %08X by %s (M68K PC=%06X)\n", address, whoName[who], m68k_get_reg(NULL, M68K_REG_PC)); + extern bool finished; + finished = true; + extern bool doDSPDis; + if (who == DSP) + doDSPDis = true; #endif return 0xFF; } -unsigned jaguar_unknown_readword(unsigned address) +unsigned jaguar_unknown_readword(unsigned address, uint32 who/*=UNKNOWN*/) { #ifdef LOG_UNMAPPED_MEMORY_ACCESSES - WriteLog( "Jaguar: Unknown word read at %08X (PC=%06X)\n", address, m68k_get_reg(NULL, M68K_REG_PC)); + WriteLog("Jaguar: Unknown word read at %08X by %s (M68K PC=%06X)\n", address, whoName[who], m68k_get_reg(NULL, M68K_REG_PC)); + extern bool finished; + finished = true; + extern bool doDSPDis; + if (who == DSP) + doDSPDis = true; #endif return 0xFFFF; } @@ -390,160 +383,126 @@ void jaguar_dasm(uint32 offset, uint32 qt) #endif } -unsigned jaguar_byte_read(unsigned int offset) +uint8 JaguarReadByte(uint32 offset, uint32 who/*=UNKNOWN*/) { uint8 data = 0x00; offset &= 0xFFFFFF; if (offset < 0x400000) -// data = (jaguar_mainRam[(offset^0x01) & 0x3FFFFF]); data = jaguar_mainRam[offset & 0x3FFFFF]; else if ((offset >= 0x800000) && (offset < 0xC00000)) -// data = (jaguar_mainRom[(offset^0x01)-0x800000]); data = jaguar_mainRom[offset - 0x800000]; -// else if ((offset >= 0xDFFF00) && (offset < 0xDFFF00)) else if ((offset >= 0xDFFF00) && (offset <= 0xDFFFFF)) - data = cdrom_byte_read(offset); + data = CDROMReadByte(offset, who); else if ((offset >= 0xE00000) && (offset < 0xE40000)) -// data = (jaguar_bootRom[(offset^0x01) & 0x3FFFF]); data = jaguar_bootRom[offset & 0x3FFFF]; else if ((offset >= 0xF00000) && (offset < 0xF10000)) - data = tom_byte_read(offset); + data = TOMReadByte(offset, who); else if ((offset >= 0xF10000) && (offset < 0xF20000)) - data = jerry_byte_read(offset); + data = JERRYReadByte(offset, who); else - data = jaguar_unknown_readbyte(offset); + data = jaguar_unknown_readbyte(offset, who); return data; } -unsigned jaguar_word_read(unsigned int offset) +uint16 JaguarReadWord(uint32 offset, uint32 who/*=UNKNOWN*/) { -//TEMP--Mirror of F03000? -/*if (offset >= 0xF0B000 && offset <= 0xF0BFFF) -WriteLog( "[JWR16] --> Possible GPU RAM mirror access! [%08X]\n", offset);//*/ - offset &= 0xFFFFFF; if (offset <= 0x3FFFFE) { -// return (jaguar_mainRam[(offset+1) & 0x3FFFFF] << 8) | jaguar_mainRam[(offset+0) & 0x3FFFFF]; return (jaguar_mainRam[(offset+0) & 0x3FFFFF] << 8) | jaguar_mainRam[(offset+1) & 0x3FFFFF]; } else if ((offset >= 0x800000) && (offset <= 0xBFFFFE)) { offset -= 0x800000; -// return (jaguar_mainRom[offset+1] << 8) | jaguar_mainRom[offset+0]; return (jaguar_mainRom[offset+0] << 8) | jaguar_mainRom[offset+1]; } // else if ((offset >= 0xDFFF00) && (offset < 0xDFFF00)) else if ((offset >= 0xDFFF00) && (offset <= 0xDFFFFE)) - return cdrom_word_read(offset); + return CDROMReadWord(offset, who); else if ((offset >= 0xE00000) && (offset <= 0xE3FFFE)) -// return *((uint16 *)&jaguar_bootRom[offset & 0x3FFFF]); return (jaguar_bootRom[(offset+0) & 0x3FFFF] << 8) | jaguar_bootRom[(offset+1) & 0x3FFFF]; else if ((offset >= 0xF00000) && (offset <= 0xF0FFFE)) - return tom_word_read(offset); + return TOMReadWord(offset, who); else if ((offset >= 0xF10000) && (offset <= 0xF1FFFE)) -//{ -//WriteLog("Reading from JERRY offset %08X...\n", offset); - return jerry_word_read(offset); -//} + return JERRYReadWord(offset, who); - return jaguar_unknown_readword(offset); + return jaguar_unknown_readword(offset, who); } -void jaguar_byte_write(unsigned offset, unsigned data) +void JaguarWriteByte(uint32 offset, uint8 data, uint32 who/*=UNKNOWN*/) { offset &= 0xFFFFFF; if (offset < 0x400000) { -// jaguar_mainRam[(offset^0x01) & 0x3FFFFF] = data; jaguar_mainRam[offset & 0x3FFFFF] = data; return; } -// else if ((offset >= 0xDFFF00) && (offset < 0xDFFF00)) else if ((offset >= 0xDFFF00) && (offset <= 0xDFFFFF)) { - cdrom_byte_write(offset, data); + CDROMWriteByte(offset, data, who); return; } else if ((offset >= 0xF00000) && (offset <= 0xF0FFFF)) { - tom_byte_write(offset, data); + TOMWriteByte(offset, data, who); return; } else if ((offset >= 0xF10000) && (offset <= 0xF1FFFF)) { - jerry_byte_write(offset, data); + JERRYWriteByte(offset, data, who); return; } - jaguar_unknown_writebyte(offset, data); + jaguar_unknown_writebyte(offset, data, who); } -void jaguar_word_write(unsigned offset, unsigned data) +void JaguarWriteWord(uint32 offset, uint16 data, uint32 who/*=UNKNOWN*/) { -extern int dsp_pc;//, dsp_control; -if (offset == 0xF1A116 && (data & 0x01)) - WriteLog(" JagWW: DSP is GO! (DSP_PC: %08X)\n", dsp_pc); -//else -// WriteLog("JagWW: DSP halted... (Old value: %08X)\n", dsp_control); - -//extern int blit_start_log; -//if (blit_start_log) -/*{ - if (offset == 0x0674DE) - WriteLog( "[JWW16] Bad write starting @ 0674DE! [%04X]\n", data); -}//*/ -//TEMP--Mirror of F03000? +//TEMP--Mirror of F03000? Yes, but only 32-bit CPUs can do it (i.e., NOT the 68K!) //if (offset >= 0xF0B000 && offset <= 0xF0BFFF) -//WriteLog( "[JWW16] --> Possible GPU RAM mirror access! [%08X]", offset); +//WriteLog("[JWW16] --> Possible GPU RAM mirror access! [%08X]", offset); //if ((offset >= 0x1FF020 && offset <= 0x1FF03F) || (offset >= 0x1FF820 && offset <= 0x1FF83F)) // WriteLog("JagWW: Writing %04X at %08X\n", data, offset); offset &= 0xFFFFFF; if (offset <= 0x3FFFFE) { -// jaguar_mainRam[(offset+0) & 0x3FFFFF] = data & 0xFF; -// jaguar_mainRam[(offset+1) & 0x3FFFFF] = (data>>8) & 0xFF; jaguar_mainRam[(offset+0) & 0x3FFFFF] = (data>>8) & 0xFF; jaguar_mainRam[(offset+1) & 0x3FFFFF] = data & 0xFF; return; } else if ((offset >= 0xDFFF00) && (offset <= 0xDFFFFE)) { - cdrom_word_write(offset, data); + CDROMWriteWord(offset, data, who); return; } else if ((offset >= 0xF00000) && (offset <= 0xF0FFFE)) { - tom_word_write(offset, data); + TOMWriteWord(offset, data, who); return; } else if ((offset >= 0xF10000) && (offset <= 0xF1FFFE)) { - jerry_word_write(offset, data); + JERRYWriteWord(offset, data, who); return; } - jaguar_unknown_writeword(offset, data); + jaguar_unknown_writeword(offset, data, who); } -unsigned jaguar_long_read(unsigned int offset) +// We really should re-do this so that it does *real* 32-bit access... !!! FIX !!! +uint32 JaguarReadLong(uint32 offset, uint32 who/*=UNKNOWN*/) { - return (jaguar_word_read(offset) << 16) | jaguar_word_read(offset+2); + return (JaguarReadWord(offset, who) << 16) | JaguarReadWord(offset+2, who); } -void jaguar_long_write(unsigned offset, unsigned data) +// We really should re-do this so that it does *real* 32-bit access... !!! FIX !!! +void JaguarWriteLong(uint32 offset, uint32 data, uint32 who/*=UNKNOWN*/) { -extern int dsp_pc;//, dsp_control; -if (offset == 0xF1A114 && (data & 0x01)) - WriteLog("JagLW: DSP is GO! (DSP_PC: %08X)\n", dsp_pc); -//else -// WriteLog("JagLW: DSP halted... (Old value: %08X)\n", dsp_control); - - jaguar_word_write(offset, data >> 16); - jaguar_word_write(offset+2, data & 0xFFFF); + JaguarWriteWord(offset, data >> 16, who); + JaguarWriteWord(offset+2, data & 0xFFFF, who); } // @@ -578,7 +537,7 @@ void jaguar_init(void) m68k_set_cpu_type(M68K_CPU_TYPE_68000); gpu_init(); - dsp_init(); + DSPInit(); tom_init(); jerry_init(); cdrom_init(); @@ -590,9 +549,9 @@ void jaguar_done(void) // for(int i=M68K_REG_A0; i<=M68K_REG_A7; i++) // WriteLog("\tA%i = 0x%.8x\n", i-M68K_REG_A0, m68k_get_reg(NULL, (m68k_register_t)i)); int32 topOfStack = m68k_get_reg(NULL, M68K_REG_A7); - WriteLog("M68K: Top of stack: %08X. Stack trace:\n", jaguar_long_read(topOfStack)); + WriteLog("M68K: Top of stack: %08X. Stack trace:\n", JaguarReadLong(topOfStack)); for(int i=-2; i<9; i++) - WriteLog("%06X: %08X\n", topOfStack + (i * 4), jaguar_long_read(topOfStack + (i * 4))); + WriteLog("%06X: %08X\n", topOfStack + (i * 4), JaguarReadLong(topOfStack + (i * 4))); /* WriteLog("\nM68000 disassembly at $802288...\n"); jaguar_dasm(0x802288, 3); @@ -609,8 +568,8 @@ void jaguar_done(void) jaguar_dasm(0x802B00, 500); WriteLog("\n");//*/ -// WriteLog("Jaguar: CD BIOS version %04X\n", jaguar_word_read(0x3004)); - WriteLog("Jaguar: Interrupt enable = %02X\n", tom_byte_read(0xF000E1) & 0x1F); +// WriteLog("Jaguar: CD BIOS version %04X\n", JaguarReadWord(0x3004)); + WriteLog("Jaguar: Interrupt enable = %02X\n", TOMReadByte(0xF000E1) & 0x1F); WriteLog("Jaguar: VBL interrupt is %s\n", ((tom_irq_enabled(IRQ_VBLANK)) && (jaguar_interrupt_handler_is_valid(64))) ? "enabled" : "disabled"); M68K_show_context(); //#endif @@ -619,8 +578,11 @@ void jaguar_done(void) //#endif cd_bios_done(); cdrom_done(); + gpu_done(); + DSPDone(); tom_done(); jerry_done(); + memory_free(jaguar_mainRom); memory_free(jaguar_bootRom); memory_free(jaguar_mainRam); @@ -653,10 +615,10 @@ void jaguar_reset(void) tom_reset(); jerry_reset(); gpu_reset(); - dsp_reset(); + DSPReset(); cdrom_reset(); m68k_pulse_reset(); // Reset the 68000 - WriteLog( "\t68K PC=%06X SP=%08X\n", m68k_get_reg(NULL, M68K_REG_PC), m68k_get_reg(NULL, M68K_REG_A7)); + WriteLog("\t68K PC=%06X SP=%08X\n", m68k_get_reg(NULL, M68K_REG_PC), m68k_get_reg(NULL, M68K_REG_A7)); } void jaguar_reset_handler(void) @@ -668,9 +630,9 @@ void jaguar_exec(int16 * backbuffer, bool render) uint32 i, vblank_duration = tom_get_vdb(); // vblank - if ((tom_irq_enabled(IRQ_VBLANK)) && (jaguar_interrupt_handler_is_valid(64))) + if (tom_irq_enabled(IRQ_VBLANK) && jaguar_interrupt_handler_is_valid(64)) { - if (jaguar_word_read(0xF0004E) != 0x07FF) // VI (11 bits wide!) + if (JaguarReadWord(0xF0004E) != 0x07FF) // VI (11 bits wide!) { tom_set_pending_video_int(); // s68000interrupt(7, IRQ_VBLANK+64); @@ -696,7 +658,7 @@ void jaguar_exec(int16 * backbuffer, bool render) jerry_i2s_exec(m68k_cycles_per_scanline); gpu_exec(gpu_cycles_per_scanline); if (dsp_enabled) - dsp_exec(dsp_cycles_per_scanline); + DSPExec(dsp_cycles_per_scanline); } for (; i= vdb && i < vde)//vbb) diff --git a/src/jerry.cpp b/src/jerry.cpp index 73db728..8226262 100644 --- a/src/jerry.cpp +++ b/src/jerry.cpp @@ -161,43 +161,47 @@ static int32 jerry_timer_2_counter; static uint32 jerry_i2s_interrupt_divide = 8; static int32 jerry_i2s_interrupt_timer = -1; -static int32 jerry_i2s_interrupt_cycles_per_scanline = 0; - +uint32 jerryI2SCycles; +uint32 jerryIntPending; +//This approach is probably wrong, since the timer is continuously counting down, though +//it might only be a problem if the # of interrupts generated is greater than 1--the M68K's +//timeslice should be running during that phase... (The DSP needs to be aware of this!) void jerry_i2s_exec(uint32 cycles) { - // Why is it called this? Instead of SCLK? + extern uint16 serialMode; // From DAC.CPP + if (!(serialMode & 0x01)) // INTERNAL flag + return; + + // Why is it called this? Instead of SCLK? Shouldn't this be read from DAC.CPP??? +//Yes, it should. !!! FIX !!! jerry_i2s_interrupt_divide &= 0xFF; if (jerry_i2s_interrupt_timer == -1) { - uint32 jerry_i2s_int_freq = (26591000 / 64) / (jerry_i2s_interrupt_divide + 1); -//Note: The formula is system_clock_freq / (2 * (N + 1)), and to get 16 bits each of -// left & right channel, ... -// -//WriteLog("SCLK: Setting serial clock freqency to %u Hz...\n", jerry_i2s_int_freq); -//WriteLog("SCLK: Real serial clock freqency would be %u Hz (N=%u)...\n", 26590906 / (2 * (jerry_i2s_interrupt_divide + 1)), jerry_i2s_interrupt_divide); -//WTF is this??? - jerry_i2s_interrupt_cycles_per_scanline = 13300000 / jerry_i2s_int_freq; - jerry_i2s_interrupt_timer = jerry_i2s_interrupt_cycles_per_scanline; - //WriteLog("jerry: i2s interrupt rate set to %i hz (every %i cpu clock cycles) jerry_i2s_interrupt_divide=%i\n",jerry_i2s_int_freq,jerry_i2s_interrupt_cycles_per_scanline,jerry_i2s_interrupt_divide); -//No need, we write it directly pcm_set_sample_rate(jerry_i2s_int_freq); + // We don't have to divide the RISC clock rate by this--the reason is a bit + // convoluted. Will put explanation here later... +// What's needed here is to find the ratio of the frequency to the number of clock cycles +// in one second. For example, if the sample rate is 44100, we divide the clock rate by +// this: 26590906 / 44100 = 602 cycles. +// Which means, every 602 cycles that go by we have to generate an interrupt. + jerryI2SCycles = 32 * (2 * (jerry_i2s_interrupt_divide + 1)); } + jerry_i2s_interrupt_timer -= cycles; - // note : commented since the sound doesn't work properly else -// !!! FIX !!! - if (1)//jerry_i2s_interrupt_timer<=0) + if (jerry_i2s_interrupt_timer <= 0) { - // i2s interrupt - dsp_check_if_i2s_interrupt_needed(); - //WriteLog("jerry_i2s_interrupt_timer=%i, generating an i2s interrupt\n",jerry_i2s_interrupt_timer); - jerry_i2s_interrupt_timer += jerry_i2s_interrupt_cycles_per_scanline; + DSPSetIRQLine(DSPIRQ_SSI, ASSERT_LINE); + jerry_i2s_interrupt_timer += jerryI2SCycles; + if (jerry_i2s_interrupt_timer < 0) + WriteLog("JERRY: Missed generating an interrupt (missed %u)!\n", (-jerry_i2s_interrupt_timer / jerryI2SCycles) + 1); } } void jerry_reset_i2s_timer(void) { //WriteLog("i2s: reseting\n"); +//This is really SCLK... !!! FIX !!! jerry_i2s_interrupt_divide = 8; jerry_i2s_interrupt_timer = -1; } @@ -234,7 +238,7 @@ void jerry_pit_exec(uint32 cycles) if (jerry_timer_1_counter <= 0) { - dsp_set_irq_line(2, 1); + DSPSetIRQLine(DSPIRQ_TIMER0, ASSERT_LINE); jerry_reset_timer_1(); } @@ -243,7 +247,7 @@ void jerry_pit_exec(uint32 cycles) if (jerry_timer_2_counter <= 0) { - dsp_set_irq_line(3, 1); + DSPSetIRQLine(DSPIRQ_TIMER1, ASSERT_LINE); jerry_reset_timer_2(); } } @@ -262,7 +266,6 @@ void jerry_init(void) void jerry_reset(void) { - //WriteLog("jerry_reset()\n"); clock_reset(); anajoy_reset(); joystick_reset(); @@ -271,7 +274,6 @@ void jerry_reset(void) DACReset(); memset(jerry_ram_8, 0x00, 0xD000); // Don't clear out the Wavetable ROM...! - jerry_ram_8[JERRY_CONFIG+1] |= 0x10; // NTSC (bit 4) jerry_timer_1_prescaler = 0xFFFF; jerry_timer_2_prescaler = 0xFFFF; jerry_timer_1_divider = 0xFFFF; @@ -282,7 +284,7 @@ void jerry_reset(void) void jerry_done(void) { - //WriteLog("jerry_done()\n"); + WriteLog("JERRY: M68K Interrupt control ($F10020) = %04X\n", GET16(jerry_ram_8, 0x20)); memory_free(jerry_ram_8); clock_done(); anajoy_done(); @@ -291,18 +293,30 @@ void jerry_done(void) eeprom_done(); } +bool JERRYIRQEnabled(int irq) +{ + // Read the word @ $F10020 + return jerry_ram_8[0x21] & (1 << irq); +} + +void JERRYSetPendingIRQ(int irq) +{ + // This is the shadow of INT (it's a split RO/WO register) + jerryIntPending |= (1 << irq); +} + // // JERRY byte access (read) // -unsigned jerry_byte_read(unsigned int offset) +uint8 JERRYReadByte(uint32 offset, uint32 who/*=UNKNOWN*/) { #ifdef JERRY_DEBUG WriteLog("JERRY: Reading byte at %06X\n", offset); #endif if ((offset >= DSP_CONTROL_RAM_BASE) && (offset < DSP_CONTROL_RAM_BASE+0x20)) - return dsp_byte_read(offset); + return DSPReadByte(offset, who); else if ((offset >= DSP_WORK_RAM_BASE) && (offset < DSP_WORK_RAM_BASE+0x2000)) - return dsp_byte_read(offset); + return DSPReadByte(offset, who); else if (offset >= 0xF10000 && offset <= 0xF10007) { switch(offset & 0x07) @@ -325,7 +339,7 @@ unsigned jerry_byte_read(unsigned int offset) return jerry_timer_2_divider & 0xFF; } } - else if (offset >= 0xF10010 && offset <= 0xf10015) + else if (offset >= 0xF10010 && offset <= 0xF10015) return clock_byte_read(offset); else if (offset >= 0xF17C00 && offset <= 0xF17C01) return anajoy_byte_read(offset); @@ -342,16 +356,16 @@ unsigned jerry_byte_read(unsigned int offset) // // JERRY word access (read) // -unsigned jerry_word_read(unsigned int offset) +uint16 JERRYReadWord(uint32 offset, uint32 who/*=UNKNOWN*/) { #ifdef JERRY_DEBUG WriteLog("JERRY: Reading word at %06X\n", offset); #endif if ((offset >= DSP_CONTROL_RAM_BASE) && (offset < DSP_CONTROL_RAM_BASE+0x20)) - return dsp_word_read(offset); - else if ((offset >= DSP_WORK_RAM_BASE) && (offset < DSP_WORK_RAM_BASE+0x2000)) - return dsp_word_read(offset); + return DSPReadWord(offset, who); + else if (offset >= DSP_WORK_RAM_BASE && offset <= DSP_WORK_RAM_BASE + 0x1FFF) + return DSPReadWord(offset, who); else if ((offset >= 0xF10000) && (offset <= 0xF10007)) { switch(offset & 0x07) @@ -370,7 +384,7 @@ unsigned jerry_word_read(unsigned int offset) else if ((offset >= 0xF10010) && (offset <= 0xF10015)) return clock_word_read(offset); else if (offset == 0xF10020) - return 0x00; + return jerryIntPending; else if ((offset >= 0xF17C00) && (offset <= 0xF17C01)) return anajoy_word_read(offset); else if (offset == 0xF14000) @@ -383,11 +397,6 @@ unsigned jerry_word_read(unsigned int offset) else if ((offset >= 0xF14000) && (offset <= 0xF1A0FF)) return eeprom_word_read(offset); -// This is never executed! -/* offset &= 0xFFFF; - if (offset==0x4002) - return(0xffff);*/ - /*if (offset >= 0xF1D000) WriteLog("JERRY: Reading word at %08X [%04X]...\n", offset, ((uint16)jerry_ram_8[(offset+0)&0xFFFF] << 8) | jerry_ram_8[(offset+1)&0xFFFF]);//*/ @@ -398,25 +407,25 @@ unsigned jerry_word_read(unsigned int offset) // // JERRY byte access (write) // -void jerry_byte_write(unsigned offset, unsigned data) +void JERRYWriteByte(uint32 offset, uint8 data, uint32 who/*=UNKNOWN*/) { #ifdef JERRY_DEBUG WriteLog("jerry: writing byte %.2x at 0x%.6x\n",data,offset); #endif if ((offset >= DSP_CONTROL_RAM_BASE) && (offset < DSP_CONTROL_RAM_BASE+0x20)) { - dsp_byte_write(offset, data); + DSPWriteByte(offset, data, who); return; } else if ((offset >= DSP_WORK_RAM_BASE) && (offset < DSP_WORK_RAM_BASE+0x2000)) { - dsp_byte_write(offset, data); + DSPWriteByte(offset, data, who); return; } // SCLK ($F1A150--8 bits wide) else if ((offset >= 0xF1A152) && (offset <= 0xF1A153)) { -// WriteLog("i2s: writing 0x%.2x to SCLK\n",data); +// WriteLog("JERRY: Writing %02X to SCLK...\n", data); if ((offset & 0x03) == 2) jerry_i2s_interrupt_divide = (jerry_i2s_interrupt_divide & 0x00FF) | ((uint32)data << 8); else @@ -424,17 +433,26 @@ void jerry_byte_write(unsigned offset, unsigned data) jerry_i2s_interrupt_timer = -1; jerry_i2s_exec(0); - return; +// return; } - else if ((offset >= 0xF10000) && (offset <= 0xF10007)) + // LTXD/RTXD/SCLK/SMODE $F1A148/4C/50/54 (really 16-bit registers...) + else if (offset >= 0xF1A148 && offset <= 0xF1A157) + { + DACWriteByte(offset, data); + return; + } + else if (offset >= 0xF10000 && offset <= 0xF10007) { - switch(offset & 0x07) + switch (offset & 0x07) { case 0: jerry_timer_1_prescaler = (jerry_timer_1_prescaler & 0x00FF) | (data << 8); jerry_reset_timer_1(); break; - case 1: { jerry_timer_1_prescaler=(jerry_timer_1_prescaler&0xff00)|(data); jerry_reset_timer_1(); return; } + case 1: + jerry_timer_1_prescaler = (jerry_timer_1_prescaler & 0xFF00) | (data); + jerry_reset_timer_1(); + break; case 2: { jerry_timer_1_divider=(jerry_timer_1_divider&0x00ff)|(data<<8); jerry_reset_timer_1(); return; } case 3: { jerry_timer_1_divider=(jerry_timer_1_divider&0xff00)|(data); jerry_reset_timer_1(); return; } case 4: { jerry_timer_2_prescaler=(jerry_timer_2_prescaler&0x00ff)|(data<<8); jerry_reset_timer_2(); return; } @@ -476,7 +494,7 @@ void jerry_byte_write(unsigned offset, unsigned data) // // JERRY word access (write) // -void jerry_word_write(unsigned offset, unsigned data) +void JERRYWriteWord(uint32 offset, uint16 data, uint32 who/*=UNKNOWN*/) { #ifdef JERRY_DEBUG WriteLog( "JERRY: Writing word %04X at %06X\n", data, offset); @@ -484,20 +502,29 @@ void jerry_word_write(unsigned offset, unsigned data) if ((offset >= DSP_CONTROL_RAM_BASE) && (offset < DSP_CONTROL_RAM_BASE+0x20)) { - dsp_word_write(offset, data); + DSPWriteWord(offset, data, who); return; } else if ((offset >= DSP_WORK_RAM_BASE) && (offset < DSP_WORK_RAM_BASE+0x2000)) { - dsp_word_write(offset, data); + DSPWriteWord(offset, data, who); return; } else if (offset == 0xF1A152) // Bottom half of SCLK ($F1A150) { -// WriteLog("i2s: writing 0x%.4x to SCLK\n",data); - jerry_i2s_interrupt_divide = data & 0xFF; + WriteLog("JERRY: Writing %04X to SCLK (by %s)...\n", data, whoName[who]); + jerry_i2s_interrupt_divide = (uint8)data; jerry_i2s_interrupt_timer = -1; jerry_i2s_exec(0); + + DACWriteWord(offset, data); + return; + } + // LTXD/RTXD/SCLK/SMODE $F1A148/4C/50/54 (really 16-bit registers...) + else if (offset >= 0xF1A148 && offset <= 0xF1A156) + { + DACWriteWord(offset, data); + return; } else if ((offset >= 0xF10000) && (offset <= 0xF10007)) { @@ -522,17 +549,15 @@ void jerry_word_write(unsigned offset, unsigned data) // Need to handle (unaligned) cases??? return; } - // LTXD/RTXD/SCLK/SMODE $F1A148/4C/50/54 (really 16-bit registers...) - else if (offset >= 0xF1A148 && offset <= 0xF1A156) - { - DACWriteWord(offset, data); - return; - } else if ((offset >= 0xF10010) && (offset < 0xF10016)) { clock_word_write(offset, data); return; } + // JERRY -> 68K interrupt enables/latches (need to be handled!) + else if (offset >= 0xF10020 && offset <= 0xF10022) + { + } else if ((offset >= 0xF17C00) && (offset < 0xF17C02)) { //I think this was removed from the Jaguar. If so, then we don't need this...! diff --git a/src/joystick.cpp b/src/joystick.cpp index 453c521..3c496ce 100644 --- a/src/joystick.cpp +++ b/src/joystick.cpp @@ -44,6 +44,7 @@ static uint8 joystick_ram[4]; static uint8 joypad_0_buttons[21]; static uint8 joypad_1_buttons[21]; extern bool finished; +extern bool showGUI, GUIKeyHeld = false; extern int start_logging; int gpu_start_log = 0; int op_start_log = 0; @@ -118,8 +119,17 @@ void joystick_exec(void) if (keystate[SDLK_z]) joypad_0_buttons[BUTTON_C] = 0x01; if (keystate[SDLK_x]) joypad_0_buttons[BUTTON_B] = 0x01; if (keystate[SDLK_c]) joypad_0_buttons[BUTTON_A] = 0x01; - if (keystate[SDLK_TAB]) joypad_0_buttons[BUTTON_OPTION] = 0x01; + if (keystate[SDLK_QUOTE]) joypad_0_buttons[BUTTON_OPTION] = 0x01; if (keystate[SDLK_RETURN]) joypad_0_buttons[BUTTON_PAUSE] = 0x01; + + if (keystate[SDLK_TAB]) + { + if (!GUIKeyHeld) + showGUI = !showGUI, GUIKeyHeld = true; + } + else + GUIKeyHeld = false; + if (keystate[SDLK_q]) start_logging = 1; if (keystate[SDLK_w]) diff --git a/src/log.cpp b/src/log.cpp index cd968ee..282898c 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -34,13 +34,8 @@ void log_done(void) // This logger is used mainly to ensure that text gets written to the log file // even if the program crashes. The performance hit is acceptable in this case! // -//bool suppressOutput = true;//temporary stuff -bool suppressOutput = false;//temporary stuff void WriteLog(const char * text, ...) { - if (suppressOutput) - return; - va_list arg; va_start(arg, text); diff --git a/src/objectp.cpp b/src/objectp.cpp index 43b575e..747e672 100644 --- a/src/objectp.cpp +++ b/src/objectp.cpp @@ -131,7 +131,7 @@ void op_done(void) WriteLog("OP: Phrase dump\n ----------\n"); for(uint32 i=0; i<0x100; i+=8) { - uint32 hi = jaguar_long_read(olp + i), lo = jaguar_long_read(olp + i + 4); + uint32 hi = JaguarReadLong(olp + i, OP), lo = JaguarReadLong(olp + i + 4, OP); WriteLog("\t%08X: %08X %08X %s", olp + i, hi, lo, opType[lo & 0x07]); if ((lo & 0x07) == 3) { @@ -153,41 +153,38 @@ void op_done(void) // Object Processor memory access // Memory range: F00010 - F00027 // -void op_byte_write(uint32 offset, uint8 data) +uint8 OPReadByte(uint32 offset, uint32 who/*=UNKNOWN*/) { offset &= 0x3F; - objectp_ram[offset] = data; + return objectp_ram[offset]; } -void op_word_write(uint32 offset, uint16 data) +uint16 OPReadWord(uint32 offset, uint32 who/*=UNKNOWN*/) { offset &= 0x3F; -// objectp_ram[offset] = (data >> 8) & 0xFF; -// objectp_ram[offset+1] = data & 0xFF; - SET16(objectp_ram, offset, data); - -/*if (offset == 0x20) -WriteLog("OP: Setting lo list pointer: %04X\n", data); -if (offset == 0x22) -WriteLog("OP: Setting hi list pointer: %04X\n", data);//*/ + return GET16(objectp_ram, offset); } -uint8 op_byte_read(uint32 offset) +// F00010-F00017 R xxxxxxxx xxxxxxxx OB - current object code from the graphics processor +// F00020-F00023 W xxxxxxxx xxxxxxxx OLP - start of the object list +// F00026 W -------- -------x OBF - object processor flag + +void OPWriteByte(uint32 offset, uint8 data, uint32 who/*=UNKNOWN*/) { offset &= 0x3F; - return objectp_ram[offset]; + objectp_ram[offset] = data; } -uint16 op_word_read(uint32 offset) +void OPWriteWord(uint32 offset, uint16 data, uint32 who/*=UNKNOWN*/) { -// return (objectp_ram[offset & 0x3F] << 8) | objectp_ram[(offset+1) & 0x3F]; offset &= 0x3F; - return GET16(objectp_ram, offset); -} + SET16(objectp_ram, offset, data); -// F00010-F00017 R xxxxxxxx xxxxxxxx OB - current object code from the graphics processor -// F00020-F00023 W xxxxxxxx xxxxxxxx OLP - start of the object list -// F00026 W -------- -------x OBF - object processor flag +/*if (offset == 0x20) +WriteLog("OP: Setting lo list pointer: %04X\n", data); +if (offset == 0x22) +WriteLog("OP: Setting hi list pointer: %04X\n", data);//*/ +} uint32 op_get_list_pointer(void) { @@ -245,14 +242,14 @@ void op_set_current_object(uint64 object) uint64 op_load_phrase(uint32 offset) { offset &= ~0x07; // 8 byte alignment - return ((uint64)jaguar_long_read(offset) << 32) | (uint64)jaguar_long_read(offset+4); + return ((uint64)JaguarReadLong(offset, OP) << 32) | (uint64)JaguarReadLong(offset+4, OP); } void OPStorePhrase(uint32 offset, uint64 p) { offset &= ~0x07; // 8 byte alignment - jaguar_long_write(offset, p >> 32); - jaguar_long_write(offset + 4, p & 0xFFFFFFFF); + JaguarWriteLong(offset, p >> 32, OP); + JaguarWriteLong(offset + 4, p & 0xFFFFFFFF, OP); } // @@ -431,7 +428,7 @@ WriteLog(" --> List end\n"); //No, the reason this was needed is that the OP code before was wrong. Any value //less than VDB will get written to the top line of the display! // if (ypos == 0) -// ypos = tom_word_read(0xF00046) / 2; // Get the VDB value +// ypos = TOMReadWord(0xF00046, OP) / 2; // Get the VDB value uint32 height = (p0 & 0xFFC000) >> 14; uint32 oldOPP = op_pointer - 8; // *** BEGIN OP PROCESSOR TESTING ONLY *** @@ -488,7 +485,7 @@ if (!inhibit) // For OP testing only! //No, the reason this was needed is that the OP code before was wrong. Any value //less than VDB will get written to the top line of the display! // if (ypos == 0) -// ypos = tom_word_read(0xF00046) / 2; // Get the VDB value +// ypos = TOMReadWord(0xF00046, OP) / 2; // Get the VDB value uint32 height = (p0 & 0xFFC000) >> 14; uint32 oldOPP = op_pointer - 8; // *** BEGIN OP PROCESSOR TESTING ONLY *** @@ -593,17 +590,17 @@ if (!inhibit) // For OP testing only! // ypos ^= 0x01; // if ((2 * tom_get_scanline()) == ypos || ypos == 0x7FF) //Here we're using VC instead of the bogus tom_get_scanline() value... - if (tom_word_read(0xF00006) == ypos || ypos == 0x7FF) + if (TOMReadWord(0xF00006, OP) == ypos || ypos == 0x7FF) op_pointer = link; break; case CONDITION_LESS_THAN: // if ((2 * tom_get_scanline()) < ypos) - if (tom_word_read(0xF00006) < ypos) + if (TOMReadWord(0xF00006, OP) < ypos) op_pointer = link; break; case CONDITION_GREATER_THAN: // if ((2 * tom_get_scanline()) > ypos) - if (tom_word_read(0xF00006) > ypos) + if (TOMReadWord(0xF00006, OP) > ypos) op_pointer = link; break; case CONDITION_OP_FLAG_SET: @@ -820,7 +817,7 @@ if (depth > 5) int32 lbufDelta = ((int8)((flags << 7) & 0xFF) >> 5) | 0x02; // Fetch 1st phrase... - uint64 pixels = ((uint64)jaguar_long_read(data) << 32) | jaguar_long_read(data + 4); + uint64 pixels = ((uint64)JaguarReadLong(data, OP) << 32) | JaguarReadLong(data + 4, OP); //Note that firstPix should only be honored *if* we start with the 1st phrase of the bitmap //i.e., we didn't clip on the margin... pixels <<= firstPix; // Skip first N pixels (N=firstPix)... @@ -854,7 +851,7 @@ if (depth > 5) i = 0; // Fetch next phrase... data += pitch << 3; // Multiply pitch * 8 (optimize: precompute this value) - pixels = ((uint64)jaguar_long_read(data) << 32) | jaguar_long_read(data + 4); + pixels = ((uint64)JaguarReadLong(data, OP) << 32) | JaguarReadLong(data + 4, OP); } } else if (depth == 1) // 2 BPP @@ -868,7 +865,7 @@ if (firstPix) while (iwidth--) { // Fetch phrase... - uint64 pixels = ((uint64)jaguar_long_read(data) << 32) | jaguar_long_read(data + 4); + uint64 pixels = ((uint64)JaguarReadLong(data, OP) << 32) | JaguarReadLong(data + 4, OP); data += pitch << 3; // Multiply pitch * 8 (optimize: precompute this value) for(int i=0; i<32; i++) @@ -908,7 +905,7 @@ if (firstPix) while (iwidth--) { // Fetch phrase... - uint64 pixels = ((uint64)jaguar_long_read(data) << 32) | jaguar_long_read(data + 4); + uint64 pixels = ((uint64)JaguarReadLong(data, OP) << 32) | JaguarReadLong(data + 4, OP); data += pitch << 3; // Multiply pitch * 8 (optimize: precompute this value) for(int i=0; i<16; i++) @@ -947,7 +944,7 @@ if (firstPix) while (iwidth--) { // Fetch phrase... - uint64 pixels = ((uint64)jaguar_long_read(data) << 32) | jaguar_long_read(data + 4); + uint64 pixels = ((uint64)JaguarReadLong(data, OP) << 32) | JaguarReadLong(data + 4, OP); data += pitch << 3; // Multiply pitch * 8 (optimize: precompute this value) for(int i=0; i<8; i++) @@ -986,7 +983,7 @@ if (firstPix) while (iwidth--) { // Fetch phrase... - uint64 pixels = ((uint64)jaguar_long_read(data) << 32) | jaguar_long_read(data + 4); + uint64 pixels = ((uint64)JaguarReadLong(data, OP) << 32) | JaguarReadLong(data + 4, OP); data += pitch << 3; // Multiply pitch * 8 (optimize: precompute this value) for(int i=0; i<4; i++) @@ -1030,7 +1027,7 @@ if (firstPix) while (iwidth--) { // Fetch phrase... - uint64 pixels = ((uint64)jaguar_long_read(data) << 32) | jaguar_long_read(data + 4); + uint64 pixels = ((uint64)JaguarReadLong(data, OP) << 32) | JaguarReadLong(data + 4, OP); data += pitch << 3; // Multiply pitch * 8 (optimize: precompute this value) for(int i=0; i<2; i++) @@ -1240,7 +1237,7 @@ if (firstPix != 0) int32 lbufDelta = ((int8)((flags << 7) & 0xFF) >> 5) | 0x02; int pixCount = 0; - uint64 pixels = ((uint64)jaguar_long_read(data) << 32) | jaguar_long_read(data + 4); + uint64 pixels = ((uint64)JaguarReadLong(data, OP) << 32) | JaguarReadLong(data + 4, OP); while ((int32)iwidth > 0) { @@ -1276,7 +1273,7 @@ if (firstPix != 0) int phrasesToSkip = pixCount / 64, pixelShift = pixCount % 64; data += (pitch << 3) * phrasesToSkip; - pixels = ((uint64)jaguar_long_read(data) << 32) | jaguar_long_read(data + 4); + pixels = ((uint64)JaguarReadLong(data, OP) << 32) | JaguarReadLong(data + 4, OP); pixels <<= 1 * pixelShift; iwidth -= phrasesToSkip; pixCount = pixelShift; @@ -1292,7 +1289,7 @@ if (firstPix != 0) int32 lbufDelta = ((int8)((flags << 7) & 0xFF) >> 5) | 0x02; int pixCount = 0; - uint64 pixels = ((uint64)jaguar_long_read(data) << 32) | jaguar_long_read(data + 4); + uint64 pixels = ((uint64)JaguarReadLong(data, OP) << 32) | JaguarReadLong(data + 4, OP); while ((int32)iwidth > 0) { @@ -1328,7 +1325,7 @@ if (firstPix != 0) int phrasesToSkip = pixCount / 32, pixelShift = pixCount % 32; data += (pitch << 3) * phrasesToSkip; - pixels = ((uint64)jaguar_long_read(data) << 32) | jaguar_long_read(data + 4); + pixels = ((uint64)JaguarReadLong(data, OP) << 32) | JaguarReadLong(data + 4, OP); pixels <<= 2 * pixelShift; iwidth -= phrasesToSkip; pixCount = pixelShift; @@ -1344,7 +1341,7 @@ if (firstPix != 0) int32 lbufDelta = ((int8)((flags << 7) & 0xFF) >> 5) | 0x02; int pixCount = 0; - uint64 pixels = ((uint64)jaguar_long_read(data) << 32) | jaguar_long_read(data + 4); + uint64 pixels = ((uint64)JaguarReadLong(data, OP) << 32) | JaguarReadLong(data + 4, OP); while ((int32)iwidth > 0) { @@ -1380,7 +1377,7 @@ if (firstPix != 0) int phrasesToSkip = pixCount / 16, pixelShift = pixCount % 16; data += (pitch << 3) * phrasesToSkip; - pixels = ((uint64)jaguar_long_read(data) << 32) | jaguar_long_read(data + 4); + pixels = ((uint64)JaguarReadLong(data, OP) << 32) | JaguarReadLong(data + 4, OP); pixels <<= 4 * pixelShift; iwidth -= phrasesToSkip; pixCount = pixelShift; @@ -1395,7 +1392,7 @@ if (firstPix) int32 lbufDelta = ((int8)((flags << 7) & 0xFF) >> 5) | 0x02; int pixCount = 0; - uint64 pixels = ((uint64)jaguar_long_read(data) << 32) | jaguar_long_read(data + 4); + uint64 pixels = ((uint64)JaguarReadLong(data, OP) << 32) | JaguarReadLong(data + 4, OP); while ((int32)iwidth > 0) { @@ -1431,7 +1428,7 @@ if (firstPix) int phrasesToSkip = pixCount / 8, pixelShift = pixCount % 8; data += (pitch << 3) * phrasesToSkip; - pixels = ((uint64)jaguar_long_read(data) << 32) | jaguar_long_read(data + 4); + pixels = ((uint64)JaguarReadLong(data, OP) << 32) | JaguarReadLong(data + 4, OP); pixels <<= 8 * pixelShift; iwidth -= phrasesToSkip; pixCount = pixelShift; @@ -1446,7 +1443,7 @@ if (firstPix != 0) int32 lbufDelta = ((int8)((flags << 7) & 0xFF) >> 5) | 0x02; int pixCount = 0; - uint64 pixels = ((uint64)jaguar_long_read(data) << 32) | jaguar_long_read(data + 4); + uint64 pixels = ((uint64)JaguarReadLong(data, OP) << 32) | JaguarReadLong(data + 4, OP); while ((int32)iwidth > 0) { @@ -1481,7 +1478,7 @@ if (firstPix != 0) int phrasesToSkip = pixCount / 4, pixelShift = pixCount % 4; data += (pitch << 3) * phrasesToSkip; - pixels = ((uint64)jaguar_long_read(data) << 32) | jaguar_long_read(data + 4); + pixels = ((uint64)JaguarReadLong(data, OP) << 32) | JaguarReadLong(data + 4, OP); pixels <<= 16 * pixelShift; iwidth -= phrasesToSkip; @@ -1503,7 +1500,7 @@ if (firstPix != 0) while (iwidth--) { // Fetch phrase... - uint64 pixels = ((uint64)jaguar_long_read(data) << 32) | jaguar_long_read(data + 4); + uint64 pixels = ((uint64)JaguarReadLong(data, OP) << 32) | JaguarReadLong(data + 4, OP); data += pitch << 3; // Multiply pitch * 8 (optimize: precompute this value) for(int i=0; i<2; i++) diff --git a/src/tom.cpp b/src/tom.cpp index f6d254a..add3e44 100644 --- a/src/tom.cpp +++ b/src/tom.cpp @@ -658,7 +658,7 @@ void tom_exec_scanline(int16 * backbuffer, int32 scanline, bool render) tom_scanline = scanline; // Increment the horizontal count (why? RNG?) -// tom_word_write(0xF00004, tom_word_read(0xF00004) + 1); +// TOMWriteWord(0xF00004, TOMReadWord(0xF00004) + 1); if (render) { @@ -708,9 +708,9 @@ void tom_done(void) videoMode_to_str[tom_getVideoMode()]); // WriteLog("\ntom: object processor:\n"); // WriteLog("tom: pointer to object list: 0x%.8x\n",op_get_list_pointer()); -// WriteLog("tom: INT1=0x%.2x%.2x\n",tom_byte_read(0xf000e0),tom_byte_read(0xf000e1)); - gpu_done(); - dsp_done(); +// WriteLog("tom: INT1=0x%.2x%.2x\n",TOMReadByte(0xf000e0),TOMReadByte(0xf000e1)); +// gpu_done(); +// dsp_done(); memory_free(tom_ram_8); } @@ -859,13 +859,12 @@ void tom_reset(void) tom_timer_divider = 0; tom_timer_counter = 0; memcpy(scanline_render, scanline_render_normal, sizeof(scanline_render)); -} +} // // TOM byte access (read) // - -unsigned tom_byte_read(unsigned int offset) +uint8 TOMReadByte(uint32 offset, uint32 who/*=UNKNOWN*/) { //???Is this needed??? // It seems so. Perhaps it's the +$8000 offset being written to (32-bit interface)? @@ -878,13 +877,13 @@ unsigned tom_byte_read(unsigned int offset) #endif if ((offset >= GPU_CONTROL_RAM_BASE) && (offset < GPU_CONTROL_RAM_BASE+0x20)) - return gpu_byte_read(offset); + return GPUReadByte(offset, who); else if ((offset >= GPU_WORK_RAM_BASE) && (offset < GPU_WORK_RAM_BASE+0x1000)) - return gpu_byte_read(offset); + return GPUReadByte(offset, who); else if ((offset >= 0xF00010) && (offset < 0xF00028)) - return op_byte_read(offset); + return OPReadByte(offset, who); else if ((offset >= 0xF02200) && (offset < 0xF022A0)) - return blitter_byte_read(offset); + return BlitterReadByte(offset, who); else if (offset == 0xF00050) return tom_timer_prescaler >> 8; else if (offset == 0xF00051) @@ -900,8 +899,7 @@ unsigned tom_byte_read(unsigned int offset) // // TOM word access (read) // - -unsigned tom_word_read(unsigned int offset) +uint16 TOMReadWord(uint32 offset, uint32 who/*=UNKNOWN*/) { //???Is this needed??? // offset &= 0xFF3FFF; @@ -909,7 +907,7 @@ unsigned tom_word_read(unsigned int offset) WriteLog("TOM: Reading word at %06X\n", offset); #endif if (offset >= 0xF02000 && offset <= 0xF020FF) - WriteLog("TOM: Read attempted from GPU register file (unimplemented)!\n"); + WriteLog("TOM: Read attempted from GPU register file by %s (unimplemented)!\n", whoName[who]); if (offset == 0xF000E0) { @@ -928,27 +926,26 @@ if (offset >= 0xF02000 && offset <= 0xF020FF) //Because VC is even in NI mode when calling the OP! That's why! return (tom_scanline << 1) + 1;//*/ else if ((offset >= GPU_CONTROL_RAM_BASE) && (offset < GPU_CONTROL_RAM_BASE+0x20)) - return gpu_word_read(offset); + return GPUReadWord(offset, who); else if ((offset >= GPU_WORK_RAM_BASE) && (offset < GPU_WORK_RAM_BASE+0x1000)) - return gpu_word_read(offset); + return GPUReadWord(offset, who); else if ((offset >= 0xF00010) && (offset < 0xF00028)) - return op_word_read(offset); + return OPReadWord(offset, who); else if ((offset >= 0xF02200) && (offset < 0xF022A0)) - return blitter_word_read(offset); + return BlitterReadWord(offset, who); else if (offset == 0xF00050) return tom_timer_prescaler; else if (offset == 0xF00052) return tom_timer_divider; offset &= 0x3FFF; - return (tom_byte_read(offset) << 8) | tom_byte_read(offset+1); + return (TOMReadByte(offset, who) << 8) | TOMReadByte(offset + 1, who); } // // TOM byte access (write) // - -void tom_byte_write(unsigned offset, unsigned data) +void TOMWriteByte(uint32 offset, uint8 data, uint32 who/*=UNKNOWN*/) { //???Is this needed??? // Perhaps on the writes--32-bit writes that is! And masked with FF7FFF... @@ -960,22 +957,22 @@ void tom_byte_write(unsigned offset, unsigned data) if ((offset >= GPU_CONTROL_RAM_BASE) && (offset < GPU_CONTROL_RAM_BASE+0x20)) { - gpu_byte_write(offset, data); + GPUWriteByte(offset, data, who); return; } else if ((offset >= GPU_WORK_RAM_BASE) && (offset < GPU_WORK_RAM_BASE+0x1000)) { - gpu_byte_write(offset, data); + GPUWriteByte(offset, data, who); return; } else if ((offset >= 0xF00010) && (offset < 0xF00028)) { - op_byte_write(offset, data); + OPWriteByte(offset, data, who); return; } else if ((offset >= 0xF02200) && (offset < 0xF022A0)) { - blitter_byte_write(offset, data); + BlitterWriteByte(offset, data, who); return; } else if (offset == 0xF00050) @@ -1015,8 +1012,7 @@ void tom_byte_write(unsigned offset, unsigned data) // // TOM word access (write) // - -void tom_word_write(unsigned offset, unsigned data) +void TOMWriteWord(uint32 offset, uint16 data, uint32 who/*=UNKNOWN*/) { //???Is this needed??? offset &= 0xFF3FFF; @@ -1025,31 +1021,31 @@ void tom_word_write(unsigned offset, unsigned data) WriteLog("TOM: Writing word %04X at %06X\n", data, offset); #endif if (offset == 0xF00000 + MEMCON1) - WriteLog("TOM: Memory Configuration 1 written: %04X\n", data); + WriteLog("TOM: Memory Configuration 1 written by %s: %04X\n", whoName[who], data); if (offset == 0xF00000 + MEMCON2) - WriteLog("TOM: Memory Configuration 2 written: %04X\n", data); + WriteLog("TOM: Memory Configuration 2 written by %s: %04X\n", whoName[who], data); if (offset >= 0xF02000 && offset <= 0xF020FF) - WriteLog("TOM: Write attempted to GPU register file (unimplemented)!\n"); + WriteLog("TOM: Write attempted to GPU register file by %s (unimplemented)!\n", whoName[who]); if ((offset >= GPU_CONTROL_RAM_BASE) && (offset < GPU_CONTROL_RAM_BASE+0x20)) { - gpu_word_write(offset, data); + GPUWriteWord(offset, data, who); return; } else if ((offset >= GPU_WORK_RAM_BASE) && (offset < GPU_WORK_RAM_BASE+0x1000)) { - gpu_word_write(offset, data); + GPUWriteWord(offset, data, who); return; } //What's so special about this? /* else if ((offset >= 0xF00000) && (offset < 0xF00002)) { - tom_byte_write(offset, data >> 8); - tom_byte_write(offset+1, data & 0xFF); + TOMWriteByte(offset, data >> 8); + TOMWriteByte(offset+1, data & 0xFF); }*/ else if ((offset >= 0xF00010) && (offset < 0xF00028)) { - op_word_write(offset, data); + OPWriteWord(offset, data, who); return; } else if (offset == 0xF00050) @@ -1080,7 +1076,7 @@ if (offset >= 0xF02000 && offset <= 0xF020FF) } else if ((offset >= 0xF02200) && (offset <= 0xF0229F)) { - blitter_word_write(offset, data); + BlitterWriteWord(offset, data, who); return; } else if (offset >= 0xF00400 && offset <= 0xF007FE) // CLUT (A & B) @@ -1100,35 +1096,35 @@ if (offset >= 0xF02000 && offset <= 0xF020FF) if (offset == 0x2E || offset == 0x36 || offset == 0x54) data &= 0x03FF; // These are all 10-bit registers - tom_byte_write(offset, data >> 8); - tom_byte_write(offset+1, data & 0xFF); + TOMWriteByte(offset, data >> 8, who); + TOMWriteByte(offset+1, data & 0xFF, who); if (offset == VDB) - WriteLog("TOM: Vertical Display Begin written: %u\n", data); + WriteLog("TOM: Vertical Display Begin written by %s: %u\n", whoName[who], data); if (offset == VDE) - WriteLog("TOM: Vertical Display End written: %u\n", data); + WriteLog("TOM: Vertical Display End written by %s: %u\n", whoName[who], data); if (offset == VP) - WriteLog("TOM: Vertical Period written: %u (%sinterlaced)\n", data, (data & 0x01 ? "non-" : "")); + WriteLog("TOM: Vertical Period written by %s: %u (%sinterlaced)\n", whoName[who], data, (data & 0x01 ? "non-" : "")); if (offset == HDB1) - WriteLog("TOM: Horizontal Display Begin 1 written: %u\n", data); + WriteLog("TOM: Horizontal Display Begin 1 written by %s: %u\n", whoName[who], data); if (offset == HDE) - WriteLog("TOM: Horizontal Display End written: %u\n", data); + WriteLog("TOM: Horizontal Display End written by %s: %u\n", whoName[who], data); if (offset == HP) - WriteLog("TOM: Horizontal Period written: %u\n", data); + WriteLog("TOM: Horizontal Period written by %s: %u\n", whoName[who], data); if (offset == VBB) - WriteLog("TOM: Vertical Blank Begin written: %u\n", data); + WriteLog("TOM: Vertical Blank Begin written by %s: %u\n", whoName[who], data); if (offset == VBE) - WriteLog("TOM: Vertical Blank End written: %u\n", data); + WriteLog("TOM: Vertical Blank End written by %s: %u\n", whoName[who], data); if (offset == VS) - WriteLog("TOM: Vertical Sync written: %u\n", data); + WriteLog("TOM: Vertical Sync written by %s: %u\n", whoName[who], data); if (offset == VI) - WriteLog("TOM: Vertical Interrupt written: %u\n", data); + WriteLog("TOM: Vertical Interrupt written by %s: %u\n", whoName[who], data); if (offset == HBB) - WriteLog("TOM: Horizontal Blank Begin written: %u\n", data); + WriteLog("TOM: Horizontal Blank Begin written by %s: %u\n", whoName[who], data); if (offset == HBE) - WriteLog("TOM: Horizontal Blank End written: %u\n", data); + WriteLog("TOM: Horizontal Blank End written by %s: %u\n", whoName[who], data); if (offset == VMODE) - WriteLog("TOM: Video Mode written: %04X (PWIDTH = %u, VC = %u)\n", data, ((data >> 9) & 0x07) + 1, GET16(tom_ram_8, VC)); + WriteLog("TOM: Video Mode written by %s: %04X (PWIDTH = %u, VC = %u)\n", whoName[who], data, ((data >> 9) & 0x07) + 1, GET16(tom_ram_8, VC)); // detect screen resolution changes //This may go away in the future, if we do the virtualized screen thing... @@ -1150,14 +1146,9 @@ if (offset == VMODE) { extern SDL_Surface * surface, * mainSurface; extern Uint32 mainSurfaceFlags; -// ws_audio_done(); - static char window_title[256]; -// delete surface; tom_width = width, tom_height = height; -// Format format(16, 0x007C00, 0x00003E0, 0x0000001F); -// surface = new Surface(tom_width, tom_height, format); SDL_FreeSurface(surface); surface = SDL_CreateRGBSurface(SDL_SWSURFACE, tom_width, tom_height, 16, 0x7C00, 0x03E0, 0x001F, 0); @@ -1168,9 +1159,7 @@ if (offset == VMODE) } sprintf(window_title, "Virtual Jaguar (%i x %i)", (int)tom_width, (int)tom_height); -// console.close(); -// console.open(window_title, width, tom_height, format); -//???Should we do this??? +//???Should we do this??? No! // SDL_FreeSurface(mainSurface); mainSurface = SDL_SetVideoMode(tom_width, tom_height, 16, mainSurfaceFlags); @@ -1181,9 +1170,6 @@ if (offset == VMODE) } SDL_WM_SetCaption(window_title, window_title); - -// ws_audio_init(); -// ws_audio_reset(); } } } @@ -1212,10 +1198,15 @@ void tom_reset_timer(void) if (!tom_timer_prescaler || !tom_timer_divider) tom_timer_counter = 0; else +//Probably should *add* this amount to the counter to retain cycle accuracy! !!! FIX !!! +//Also, why +1??? tom_timer_counter = (1 + tom_timer_prescaler) * (1 + tom_timer_divider); // WriteLog("tom: reseting timer to 0x%.8x (%i)\n",tom_timer_counter,tom_timer_counter); } +// +// TOM Programmable Interrupt Timer handler +// void tom_pit_exec(uint32 cycles) { if (tom_timer_counter > 0) @@ -1225,8 +1216,8 @@ void tom_pit_exec(uint32 cycles) if (tom_timer_counter <= 0) { tom_set_pending_timer_int(); - GPUSetIRQLine(2, ASSERT_LINE); - if ((tom_irq_enabled(IRQ_TIMER)) && (jaguar_interrupt_handler_is_valid(64))) + GPUSetIRQLine(GPUIRQ_TIMER, ASSERT_LINE); + if (tom_irq_enabled(IRQ_TIMER) && jaguar_interrupt_handler_is_valid(64)) m68k_set_irq(7); // Cause a 68000 NMI... tom_reset_timer(); diff --git a/src/vj.cpp b/src/vj.cpp index 376c3e2..58589ac 100644 --- a/src/vj.cpp +++ b/src/vj.cpp @@ -14,10 +14,10 @@ #include #include -//#include "SDLptc.h" // Ick! Aargh! Bleah! #include "jaguar.h" #include "crc32.h" #include "unzip.h" +#include "gui.h" // Uncomment this for speed control //#define SPEED_CONTROL @@ -49,14 +49,12 @@ SDL_Surface * surface, * mainSurface; SDL_Joystick * joystick; Uint32 mainSurfaceFlags = SDL_SWSURFACE; -//Console console; -//Surface * surface; -//Format format(16, 0x007C00, 0x00003E0, 0x0000001F); bool finished = false; bool fullscreen = false; bool hardwareTypeNTSC = true; // Set to false for PAL bool useJoystick = false; +bool showGUI = false; // Added/changed by SDLEMU http://sdlemu.ngemu.com @@ -65,12 +63,8 @@ uint32 totalFrames;//so we can grab this from elsewhere... int main(int argc, char * argv[]) { uint32 startTime;//, totalFrames;//, endTime;//, w, h; -// int32 * vs; uint32 nNormalLast = 0; int32 nNormalFrac = 0; -// int32 i = 0; -//unused int32 nTime = 0; -//unused int32 nCount = 0; int32 nFrameskip = 0; // Default: Show every frame int32 nFrame = 0; // No. of Frame int32 nJoyport = 0; // Joystick port @@ -81,8 +75,6 @@ int main(int argc, char * argv[]) printf("Portions massaged by James L. Hammons (WIN32)\n"); printf("Contact: http://sdlemu.ngemu.com/ | sdlemu@ngemu.com\n"); -// console.option("windowed output"); - // BIOS is now ON by default--use the -nobios switch to turn it off! jaguar_use_bios = true; bool haveCart = false; // Assume there is no cartridge...! @@ -96,10 +88,7 @@ int main(int argc, char * argv[]) haveCart = true; // It looks like we have a cartridge! if (!strcmp(argv[i], "-fullscreen")) -// { fullscreen = true; -// console.option("fullscreen output"); -// } //We *don't* need this option! /* if (!strcmp(argv[i], "-window")) @@ -107,7 +96,6 @@ int main(int argc, char * argv[]) fullscreen = false;*/ if (!strcmp(argv[i], "-joystick")) -// console.option("joystick enabled"); useJoystick = true; if (!strcmp(argv[i], "-joyport")) @@ -184,12 +172,12 @@ int main(int argc, char * argv[]) exit(1); } - // Let's get proper info about the platform we're running on. + // Let's get proper info about the platform we're running on... const SDL_VideoInfo * info = SDL_GetVideoInfo(); if (!info) { - WriteLog("VJ: SDL is unable to get the video query: %s\n", SDL_GetError()); + WriteLog("VJ: SDL is unable to get the video info: %s\n", SDL_GetError()); exit(1); } @@ -203,7 +191,7 @@ int main(int argc, char * argv[]) mainSurfaceFlags |= SDL_FULLSCREEN; // Note: mainSurface is *never* used again! - //Not true--had to look at what's what here... + //Not true--had to look at what's what here... It's the primary surface... mainSurface = SDL_SetVideoMode(tom_getVideoModeWidth(), tom_getVideoModeHeight(), 16, mainSurfaceFlags); if (mainSurface == NULL) @@ -215,43 +203,35 @@ int main(int argc, char * argv[]) SDL_WM_SetCaption("Virtual Jaguar", "Virtual Jaguar"); // Create the primary SDL display (16 BPP, 5/5/5 RGB format) -// surface = new Surface(tom_getVideoModeWidth(), tom_getVideoModeHeight(), format); -//Format format(16, 0x007C00, 0x00003E0, 0x0000001F); surface = SDL_CreateRGBSurface(SDL_SWSURFACE, tom_getVideoModeWidth(), tom_getVideoModeHeight(), 16, 0x7C00, 0x03E0, 0x001F, 0); + if (surface == NULL) { - WriteLog("VJ: Could not create primary SDL surface: %s", SDL_GetError()); + WriteLog("VJ: Could not create primary SDL surface: %s\n", SDL_GetError()); exit(1); } // Initialize Joystick support under SDL -// if (console.JoyEnabled() == 1) if (useJoystick) { if (SDL_NumJoysticks() <= 0) { -// console.option("joystick disabled"); useJoystick = false; - printf("No joystick(s) or joypad(s) detected on your system. Using keyboard...\n"); + printf("VJ: No joystick(s) or joypad(s) detected on your system. Using keyboard...\n"); } else { -// if ((console.joystick = SDL_JoystickOpen(nJoyport)) == 0) if ((joystick = SDL_JoystickOpen(nJoyport)) == 0) { -// console.option("joystick disabled"); useJoystick = false; - printf("Unable to open a Joystick on port: %d\n", (int)nJoyport); + printf("VJ: Unable to open a Joystick on port: %d\n", (int)nJoyport); } else - printf("Using: %s\n", SDL_JoystickName(nJoyport)); + printf("VJ: Using: %s\n", SDL_JoystickName(nJoyport)); } } - // Open the display and start emulating some 3l337 Atari Jaguar games :P -// console.open("Virtual Jaguar", tom_getVideoModeWidth(), tom_getVideoModeHeight(), format); - totalFrames = 0; startTime = clock(); nNormalLast = 0; // Last value of timeGetTime() @@ -286,34 +266,36 @@ int main(int argc, char * argv[]) jaguar_exec(backbuffer, false); #endif // Setting up new backbuffer with new pixels and data -// jaguar_exec(backbuffer, true); JaguarExecute(backbuffer, true); totalFrames++; + // GUI stuff here... + if (showGUI) + { + extern uint32 gpu_pc; + extern uint32 dsp_pc; + DrawText(backbuffer, 8, 0, "Friendly GUI brought to you by JLH ;-)"); + DrawText(backbuffer, 8, 8, "GPU PC: %08X", gpu_pc); + DrawText(backbuffer, 8, 16, "DSP PC: %08X", dsp_pc); + } + // Simple frameskip if (nFrame == nFrameskip) { -// int32 * vs = (int32 *)surface->lock(); if (SDL_MUSTLOCK(surface)) while (SDL_LockSurface(surface) < 0) SDL_Delay(10); -// uint8 * vs = (Uint8 *)surface->pixels; -// memcpy(vs, backbuffer, tom_width * tom_height * 2); + memcpy(surface->pixels, backbuffer, tom_width * tom_height * 2); -// surface->unlock(); + if (SDL_MUSTLOCK(surface)) SDL_UnlockSurface(surface); -// surface->copy(console); + SDL_Rect srcrect, dstrect; srcrect.x = srcrect.y = 0, srcrect.w = surface->w, srcrect.h = surface->h; dstrect.x = dstrect.y = 0, dstrect.w = surface->w, dstrect.h = surface->h; -// SDL_LowerBlit(surface, &srcrect, dst.surface, &dstrect); SDL_BlitSurface(surface, &srcrect, mainSurface, &dstrect); -// dst.updates[dst.nupdates++] = dstrect; -// console.update(); SDL_Flip(mainSurface); -// nupdates = 0; - nFrame = 0; } else @@ -328,13 +310,13 @@ int main(int argc, char * argv[]) int elapsedTime = clock() - startTime; int fps = (1000 * totalFrames) / elapsedTime; - fprintf(log_get(), "Statistics: %i FPS\n", fps); + fprintf(log_get(), "VJ: Ran at an average of %i FPS.\n", fps); jaguar_done(); version_done(); memory_done(); log_done(); -// console.close(); // Close SDL items as last! + SDL_JoystickClose(joystick); SDL_FreeSurface(surface); SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO | SDL_INIT_TIMER);