Mercurial > audlegacy-plugins
diff src/console/Sap_Cpu.cxx @ 341:986f098da058 trunk
[svn] - merge in blargg's changes
author | nenolod |
---|---|
date | Thu, 07 Dec 2006 15:20:41 -0800 |
parents | fb513e10174e |
children |
line wrap: on
line diff
--- a/src/console/Sap_Cpu.cxx Wed Dec 06 07:57:05 2006 -0800 +++ b/src/console/Sap_Cpu.cxx Thu Dec 07 15:20:41 2006 -0800 @@ -1,4 +1,4 @@ -// Game_Music_Emu 0.5.1. http://www.slack.net/~ant/ +// Game_Music_Emu 0.5.2. http://www.slack.net/~ant/ #include "Sap_Cpu.h" @@ -18,8 +18,8 @@ License along with this module; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#define SYNC_TIME() (void) (s.time = s_time) -#define RELOAD_TIME() (void) (s_time = s.time) +#define FLUSH_TIME() (void) (s.time = s_time) +#define CACHE_TIME() (void) (s_time = s.time) #include "sap_cpu_io.h" @@ -94,18 +94,18 @@ // status flags #define IS_NEG (nz & 0x8080) - #define CALC_STATUS( out ) do { \ - out = status & (st_v | st_d | st_i); \ - out |= ((nz >> 8) | nz) & st_n; \ - out |= c >> 8 & st_c; \ - if ( !(nz & 0xFF) ) out |= st_z; \ + #define CALC_STATUS( out ) do {\ + out = status & (st_v | st_d | st_i);\ + out |= ((nz >> 8) | nz) & st_n;\ + out |= c >> 8 & st_c;\ + if ( !(nz & 0xFF) ) out |= st_z;\ } while ( 0 ) - #define SET_STATUS( in ) do { \ - status = in & (st_v | st_d | st_i); \ - nz = in << 8; \ - c = nz; \ - nz |= ~in & st_z; \ + #define SET_STATUS( in ) do {\ + status = in & (st_v | st_d | st_i);\ + nz = in << 8;\ + c = nz;\ + nz |= ~in & st_z;\ } while ( 0 ) fuint8 status; @@ -182,7 +182,7 @@ // Macros #define GET_MSB() (instr [1]) -#define ADD_PAGE (pc++, data += 0x100 * GET_MSB()); +#define ADD_PAGE() (pc++, data += 0x100 * GET_MSB()) #define GET_ADDR() GET_LE16( instr ) #define NO_PAGE_CROSSING( lsb ) @@ -190,53 +190,54 @@ #define INC_DEC_XY( reg, n ) reg = uint8_t (nz = reg + n); goto loop; -#define IND_Y( cross, out ) { \ - fuint16 temp = READ_LOW( data ) + y; \ - out = temp + 0x100 * READ_LOW( uint8_t (data + 1) ); \ - cross( temp ); \ +#define IND_Y( cross, out ) {\ + fuint16 temp = READ_LOW( data ) + y;\ + out = temp + 0x100 * READ_LOW( uint8_t (data + 1) );\ + cross( temp );\ } -#define IND_X( out ) { \ - fuint16 temp = data + x; \ - out = 0x100 * READ_LOW( uint8_t (temp + 1) ) + READ_LOW( uint8_t (temp) ); \ +#define IND_X( out ) {\ + fuint16 temp = data + x;\ + out = 0x100 * READ_LOW( uint8_t (temp + 1) ) + READ_LOW( uint8_t (temp) );\ } -#define ARITH_ADDR_MODES( op ) \ -case op - 0x04: /* (ind,x) */ \ - IND_X( data ) \ - goto ptr##op; \ -case op + 0x0C: /* (ind),y */ \ - IND_Y( HANDLE_PAGE_CROSSING, data ) \ - goto ptr##op; \ -case op + 0x10: /* zp,X */ \ - data = uint8_t (data + x); \ -case op + 0x00: /* zp */ \ - data = READ_LOW( data ); \ - goto imm##op; \ -case op + 0x14: /* abs,Y */ \ - data += y; \ - goto ind##op; \ -case op + 0x18: /* abs,X */ \ - data += x; \ -ind##op: \ - HANDLE_PAGE_CROSSING( data ); \ -case op + 0x08: /* abs */ \ - ADD_PAGE \ -ptr##op: \ - SYNC_TIME(); \ - data = READ( data ); \ - RELOAD_TIME(); \ -case op + 0x04: /* imm */ \ -imm##op: \ +#define ARITH_ADDR_MODES( op )\ +case op - 0x04: /* (ind,x) */\ + IND_X( data )\ + goto ptr##op;\ +case op + 0x0C: /* (ind),y */\ + IND_Y( HANDLE_PAGE_CROSSING, data )\ + goto ptr##op;\ +case op + 0x10: /* zp,X */\ + data = uint8_t (data + x);\ +case op + 0x00: /* zp */\ + data = READ_LOW( data );\ + goto imm##op;\ +case op + 0x14: /* abs,Y */\ + data += y;\ + goto ind##op;\ +case op + 0x18: /* abs,X */\ + data += x;\ +ind##op:\ + HANDLE_PAGE_CROSSING( data );\ +case op + 0x08: /* abs */\ + ADD_PAGE();\ +ptr##op:\ + FLUSH_TIME();\ + data = READ( data );\ + CACHE_TIME();\ +case op + 0x04: /* imm */\ +imm##op: -#define BRANCH( cond ) \ -{ \ - fint16 offset = (BOOST::int8_t) data; \ +// TODO: more efficient way to handle negative branch that wraps PC around +#define BRANCH( cond )\ +{\ + fint16 offset = (BOOST::int8_t) data;\ fuint16 extra_clock = (++pc & 0xFF) + offset;\ - if ( !(cond) ) goto dec_clock_loop; \ - pc += offset; \ - s_time += extra_clock >> 8 & 1; \ - goto loop; \ + if ( !(cond) ) goto dec_clock_loop;\ + pc += offset;\ + s_time += extra_clock >> 8 & 1;\ + goto loop;\ } // Often-Used @@ -352,9 +353,9 @@ goto loop; } sta_ptr: - SYNC_TIME(); + FLUSH_TIME(); WRITE( addr, a ); - RELOAD_TIME(); + CACHE_TIME(); goto loop; case 0x91: // STA (ind),Y @@ -411,9 +412,9 @@ if ( (addr ^ 0x8000) <= 0x9FFF ) goto loop; a_nz_read_addr: - SYNC_TIME(); + FLUSH_TIME(); a = nz = READ( addr ); - RELOAD_TIME(); + CACHE_TIME(); goto loop; } @@ -474,9 +475,9 @@ case 0xAC:{// LDY abs unsigned addr = data + 0x100 * GET_MSB(); pc += 2; - SYNC_TIME(); + FLUSH_TIME(); y = nz = READ( addr ); - RELOAD_TIME(); + CACHE_TIME(); goto loop; } @@ -486,9 +487,9 @@ case 0xAE:{// LDX abs unsigned addr = data + 0x100 * GET_MSB(); pc += 2; - SYNC_TIME(); + FLUSH_TIME(); x = nz = READ( addr ); - RELOAD_TIME(); + CACHE_TIME(); goto loop; } @@ -508,9 +509,9 @@ WRITE_LOW( addr, temp ); goto loop; } - SYNC_TIME(); + FLUSH_TIME(); WRITE( addr, temp ); - RELOAD_TIME(); + CACHE_TIME(); goto loop; } @@ -519,9 +520,9 @@ case 0xEC:{// CPX abs unsigned addr = GET_ADDR(); pc++; - SYNC_TIME(); + FLUSH_TIME(); data = READ( addr ); - RELOAD_TIME(); + CACHE_TIME(); goto cpx_data; } @@ -538,9 +539,9 @@ case 0xCC:{// CPY abs unsigned addr = GET_ADDR(); pc++; - SYNC_TIME(); + FLUSH_TIME(); data = READ( addr ); - RELOAD_TIME(); + CACHE_TIME(); goto cpy_data; } @@ -645,8 +646,8 @@ c = 0; case 0x6E: // ROR abs ror_abs: { - ADD_PAGE - SYNC_TIME(); + ADD_PAGE(); + FLUSH_TIME(); int temp = READ( data ); nz = (c >> 1 & 0x80) | (temp >> 1); c = temp << 8; @@ -663,14 +664,14 @@ c = 0; case 0x2E: // ROL abs rol_abs: - ADD_PAGE + ADD_PAGE(); nz = c >> 8 & 1; - SYNC_TIME(); + FLUSH_TIME(); nz |= (c = READ( data ) << 1); rotate_common: pc++; WRITE( data, (uint8_t) nz ); - RELOAD_TIME(); + CACHE_TIME(); goto loop; case 0x7E: // ROR abs,X @@ -751,11 +752,11 @@ dec_ptr: nz = (unsigned) -1; inc_common: - SYNC_TIME(); + FLUSH_TIME(); nz += READ( data ); pc += 2; WRITE( data, (uint8_t) nz ); - RELOAD_TIME(); + CACHE_TIME(); goto loop; // Transfer @@ -940,7 +941,7 @@ int result_; handle_brk: - if ( pc >= idle_addr + 1 ) + if ( (pc - 1) >= idle_addr ) goto idle_done; pc++; result_ = 4; @@ -978,9 +979,9 @@ goto stop; out_of_time: pc--; - SYNC_TIME(); + FLUSH_TIME(); CPU_DONE( this, TIME, result_ ); - RELOAD_TIME(); + CACHE_TIME(); if ( result_ >= 0 ) goto interrupt; if ( s_time < 0 )