From df6669b32c67642bf54dc8101fb92449b4d37ccc Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Sat, 19 Jan 2019 14:02:04 +0200 Subject: [PATCH] - reverted GME Kss_Cpu.cpp to previous version Update to GME 0.6.2 broke playback of MSX .kss files https://forum.zdoom.org/viewtopic.php?t=63206 --- game-music-emu/gme/Kss_Cpu.cpp | 97 ++++++++++++++++++---------------- 1 file changed, 51 insertions(+), 46 deletions(-) diff --git a/game-music-emu/gme/Kss_Cpu.cpp b/game-music-emu/gme/Kss_Cpu.cpp index 10eec4fcc0..4a4ebc16ad 100644 --- a/game-music-emu/gme/Kss_Cpu.cpp +++ b/game-music-emu/gme/Kss_Cpu.cpp @@ -1,4 +1,4 @@ -// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/ +// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/ /* Last validated with zexall 2006.11.14 2:19 PM @@ -162,6 +162,11 @@ static byte const ed_dd_timing [0x100] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00, }; +// even on x86, using short and unsigned char was slower +typedef int fint16; +typedef unsigned fuint16; +typedef unsigned fuint8; + bool Kss_Cpu::run( cpu_time_t end_time ) { set_end_time( end_time ); @@ -178,10 +183,10 @@ bool Kss_Cpu::run( cpu_time_t end_time ) rg = this->r.b; cpu_time_t s_time = s.time; - uint16_t pc = r.pc; - uint16_t sp = r.sp; - uint16_t ix = r.ix; // TODO: keep in memory for direct access? - uint16_t iy = r.iy; + fuint16 pc = r.pc; + fuint16 sp = r.sp; + fuint16 ix = r.ix; // TODO: keep in memory for direct access? + fuint16 iy = r.iy; int flags = r.b.flags; goto loop; @@ -203,7 +208,7 @@ loop: uint8_t const* instr = s.read [pc >> page_shift]; #define GET_ADDR() GET_LE16( instr ) - uint8_t opcode; + fuint8 opcode; // TODO: eliminate this special case #if BLARGG_NONPORTABLE @@ -236,7 +241,7 @@ loop: 11,10,10, 4,17,11, 7,11,11, 6,10, 4,17, 8, 7,11, // F }; - uint16_t data; + fuint16 data; data = base_timing [opcode]; if ( (s_time += data) >= 0 ) goto possibly_out_of_time; @@ -292,7 +297,7 @@ possibly_out_of_time: goto loop; case 0x3A:{// LD A,(addr) - uint16_t addr = GET_ADDR(); + fuint16 addr = GET_ADDR(); pc += 2; rg.a = READ( addr ); goto loop; @@ -380,7 +385,7 @@ possibly_out_of_time: case 0xCD:{// CALL addr call_taken: - uint16_t addr = pc + 2; + fuint16 addr = pc + 2; pc = GET_ADDR(); sp = uint16_t (sp - 2); WRITE_WORD( sp, addr ); @@ -388,7 +393,7 @@ possibly_out_of_time: } case 0xFF: // RST - if ( pc >= idle_addr ) + if ( pc > idle_addr ) goto hit_idle_addr; CASE7( C7, CF, D7, DF, E7, EF, F7 ): data = pc; @@ -496,7 +501,7 @@ possibly_out_of_time: add_hl_data: { blargg_ulong sum = rp.hl + data; data ^= rp.hl; - rp.hl = sum; + rp.hl = (uint16_t)sum; flags = (flags & (S80 | Z40 | V04)) | (sum >> 16) | (sum >> 8 & (F20 | F08)) | @@ -686,21 +691,21 @@ possibly_out_of_time: goto loop; case 0x2A:{// LD HL,(addr) - uint16_t addr = GET_ADDR(); + fuint16 addr = GET_ADDR(); pc += 2; rp.hl = READ_WORD( addr ); goto loop; } case 0x32:{// LD (addr),A - uint16_t addr = GET_ADDR(); + fuint16 addr = GET_ADDR(); pc += 2; WRITE( addr, rg.a ); goto loop; } case 0x22:{// LD (addr),HL - uint16_t addr = GET_ADDR(); + fuint16 addr = GET_ADDR(); pc += 2; WRITE_WORD( addr, rp.hl ); goto loop; @@ -723,7 +728,7 @@ possibly_out_of_time: // Rotate case 0x07:{// RLCA - uint16_t temp = rg.a; + fuint16 temp = rg.a; temp = (temp << 1) | (temp >> 7); flags = (flags & (S80 | Z40 | P04)) | (temp & (F20 | F08 | C01)); @@ -732,7 +737,7 @@ possibly_out_of_time: } case 0x0F:{// RRCA - uint16_t temp = rg.a; + fuint16 temp = rg.a; flags = (flags & (S80 | Z40 | P04)) | (temp & C01); temp = (temp << 7) | (temp >> 1); @@ -746,12 +751,12 @@ possibly_out_of_time: flags = (flags & (S80 | Z40 | P04)) | (temp & (F20 | F08)) | (temp >> 8); - rg.a = temp; + rg.a = (uint8_t)temp; goto loop; } case 0x1F:{// RRA - uint16_t temp = (flags << 7) | (rg.a >> 1); + fuint16 temp = (flags << 7) | (rg.a >> 1); flags = (flags & (S80 | Z40 | P04)) | (temp & (F20 | F08)) | (rg.a & C01); @@ -761,7 +766,7 @@ possibly_out_of_time: // Misc case 0x2F:{// CPL - uint16_t temp = ~rg.a; + fuint16 temp = ~rg.a; flags = (flags & (S80 | Z40 | P04 | C01)) | (temp & (F20 | F08)) | (H10 | N02); @@ -787,21 +792,21 @@ possibly_out_of_time: goto loop; case 0xE3:{// EX (SP),HL - uint16_t temp = READ_WORD( sp ); + fuint16 temp = READ_WORD( sp ); WRITE_WORD( sp, rp.hl ); rp.hl = temp; goto loop; } case 0xEB:{// EX DE,HL - uint16_t temp = rp.hl; + fuint16 temp = rp.hl; rp.hl = rp.de; rp.de = temp; goto loop; } case 0xD9:{// EXX DE,HL - uint16_t temp = r.alt.w.bc; + fuint16 temp = r.alt.w.bc; r.alt.w.bc = rp.bc; rp.bc = temp; @@ -842,7 +847,7 @@ possibly_out_of_time: // Rotate left #define RLC( read, write ) {\ - uint8_t result = read;\ + fuint8 result = read;\ result = uint8_t (result << 1) | (result >> 7);\ flags = SZ28P( result ) | (result & C01);\ write;\ @@ -861,7 +866,7 @@ possibly_out_of_time: } #define RL( read, write ) {\ - uint16_t result = (read << 1) | (flags & C01);\ + fuint16 result = (read << 1) | (flags & C01);\ flags = SZ28PC( result );\ write;\ goto loop;\ @@ -879,7 +884,7 @@ possibly_out_of_time: } #define SLA( read, add, write ) {\ - uint16_t result = (read << 1) | add;\ + fuint16 result = (read << 1) | add;\ flags = SZ28PC( result );\ write;\ goto loop;\ @@ -910,7 +915,7 @@ possibly_out_of_time: // Rotate right #define RRC( read, write ) {\ - uint8_t result = read;\ + fuint8 result = read;\ flags = result & C01;\ result = uint8_t (result << 7) | (result >> 1);\ flags |= SZ28P( result );\ @@ -930,8 +935,8 @@ possibly_out_of_time: } #define RR( read, write ) {\ - uint8_t result = read;\ - uint8_t temp = result & C01;\ + fuint8 result = read;\ + fuint8 temp = result & C01;\ result = uint8_t (flags << 7) | (result >> 1);\ flags = SZ28P( result ) | temp;\ write;\ @@ -950,7 +955,7 @@ possibly_out_of_time: } #define SRA( read, write ) {\ - uint8_t result = read;\ + fuint8 result = read;\ flags = result & C01;\ result = (result & 0x80) | (result >> 1);\ flags |= SZ28P( result );\ @@ -970,7 +975,7 @@ possibly_out_of_time: } #define SRL( read, write ) {\ - uint8_t result = read;\ + fuint8 result = read;\ flags = result & C01;\ result >>= 1;\ flags |= SZ28P( result );\ @@ -1078,7 +1083,7 @@ possibly_out_of_time: blargg_ulong sum = temp + (flags & C01); flags = ~data >> 2 & N02; if ( flags ) - sum = -sum; + sum = (blargg_ulong)-(blargg_long)sum; sum += rp.hl; temp ^= rp.hl; temp ^= sum; @@ -1086,7 +1091,7 @@ possibly_out_of_time: (temp >> 8 & H10) | (sum >> 8 & (S80 | F20 | F08)) | ((temp - -0x8000) >> 14 & V04); - rp.hl = sum; + rp.hl = (uint16_t)sum; if ( (uint16_t) sum ) goto loop; flags |= Z40; @@ -1114,7 +1119,7 @@ possibly_out_of_time: case 0x43: // LD (ADDR),BC case 0x53: // LD (ADDR),DE temp = R16( data, 4, 0x43 ); - uint16_t addr = GET_ADDR(); + fuint16 addr = GET_ADDR(); pc += 2; WRITE_WORD( addr, temp ); goto loop; @@ -1122,21 +1127,21 @@ possibly_out_of_time: case 0x4B: // LD BC,(ADDR) case 0x5B:{// LD DE,(ADDR) - uint16_t addr = GET_ADDR(); + fuint16 addr = GET_ADDR(); pc += 2; R16( data, 4, 0x4B ) = READ_WORD( addr ); goto loop; } case 0x7B:{// LD SP,(ADDR) - uint16_t addr = GET_ADDR(); + fuint16 addr = GET_ADDR(); pc += 2; sp = READ_WORD( addr ); goto loop; } case 0x67:{// RRD - uint8_t temp = READ( rp.hl ); + fuint8 temp = READ( rp.hl ); WRITE( rp.hl, (rg.a << 4) | (temp >> 4) ); temp = (rg.a & 0xF0) | (temp & 0x0F); flags = (flags & C01) | SZ28P( temp ); @@ -1145,7 +1150,7 @@ possibly_out_of_time: } case 0x6F:{// RLD - uint8_t temp = READ( rp.hl ); + fuint8 temp = READ( rp.hl ); WRITE( rp.hl, (temp << 4) | (rg.a & 0x0F) ); temp = (rg.a & 0xF0) | (temp >> 4); flags = (flags & C01) | SZ28P( temp ); @@ -1169,7 +1174,7 @@ possibly_out_of_time: case 0xA1: // CPI case 0xB1: // CPIR inc = +1; - uint16_t addr = rp.hl; + fuint16 addr = rp.hl; rp.hl = addr + inc; int temp = READ( addr ); @@ -1202,7 +1207,7 @@ possibly_out_of_time: case 0xA0: // LDI case 0xB0: // LDIR inc = +1; - uint16_t addr = rp.hl; + fuint16 addr = rp.hl; rp.hl = addr + inc; int temp = READ( addr ); @@ -1234,7 +1239,7 @@ possibly_out_of_time: case 0xA3: // OUTI case 0xB3: // OTIR inc = +1; - uint16_t addr = rp.hl; + fuint16 addr = rp.hl; rp.hl = addr + inc; int temp = READ( addr ); @@ -1260,7 +1265,7 @@ possibly_out_of_time: case 0xB2: // INIR inc = +1; - uint16_t addr = rp.hl; + fuint16 addr = rp.hl; rp.hl = addr + inc; int temp = IN( rp.bc ); @@ -1325,7 +1330,7 @@ possibly_out_of_time: //////////////////////////////////////// DD/FD prefix { - uint16_t ixy; + fuint16 ixy; case 0xDD: ixy = ix; goto ix_prefix; @@ -1521,7 +1526,7 @@ possibly_out_of_time: goto loop; case 0x22:{// LD (ADDR),IXY - uint16_t addr = GET_ADDR(); + fuint16 addr = GET_ADDR(); pc += 2; WRITE_WORD( addr, ixy ); goto loop; @@ -1533,7 +1538,7 @@ possibly_out_of_time: goto set_ixy; case 0x2A:{// LD IXY,(addr) - uint16_t addr = GET_ADDR(); + fuint16 addr = GET_ADDR(); ixy = READ_WORD( addr ); pc += 2; goto set_ixy; @@ -1557,7 +1562,7 @@ possibly_out_of_time: case 0x3E: goto srl_data_addr; // SRL (IXY) CASE8( 46, 4E, 56, 5E, 66, 6E, 76, 7E ):{// BIT b,(IXY+disp) - uint8_t temp = READ( data ); + fuint8 temp = READ( data ); int masked = temp & 1 << (data2 >> 3 & 7); flags = (flags & C01) | H10 | (masked & S80) | @@ -1659,7 +1664,7 @@ possibly_out_of_time: goto loop; case 0xE3:{// EX (SP),IXY - uint16_t temp = READ_WORD( sp ); + fuint16 temp = READ_WORD( sp ); WRITE_WORD( sp, ixy ); ixy = temp; goto set_ixy;