diff options
Diffstat (limited to 'source')
52 files changed, 4131 insertions, 6175 deletions
diff --git a/source/65c816.h b/source/65c816.h index f180037..1d8eb60 100644 --- a/source/65c816.h +++ b/source/65c816.h @@ -26,50 +26,47 @@ #define Negative 128 #define Emulation 256 -#define ClearCarry() (ICPU._Carry = 0) -#define SetCarry() (ICPU._Carry = 1) -#define SetZero() (ICPU._Zero = 0) -#define ClearZero() (ICPU._Zero = 1) -#define SetIRQ() (ICPU.Registers.PL |= IRQ) -#define ClearIRQ() (ICPU.Registers.PL &= ~IRQ) -#define SetDecimal() (ICPU.Registers.PL |= Decimal) -#define ClearDecimal() (ICPU.Registers.PL &= ~Decimal) -#define SetIndex() (ICPU.Registers.PL |= IndexFlag) -#define ClearIndex() (ICPU.Registers.PL &= ~IndexFlag) -#define SetMemory() (ICPU.Registers.PL |= MemoryFlag) -#define ClearMemory() (ICPU.Registers.PL &= ~MemoryFlag) -#define SetOverflow() (ICPU._Overflow = 1) -#define ClearOverflow() (ICPU._Overflow = 0) -#define SetNegative() (ICPU._Negative = 0x80) -#define ClearNegative() (ICPU._Negative = 0) +#define SetCarry() (ICPU._Carry = 1) +#define ClearCarry() (ICPU._Carry = 0) +#define SetZero() (ICPU._Zero = 0) +#define ClearZero() (ICPU._Zero = 1) +#define SetIRQ() (ICPU.Registers.PL |= IRQ) +#define ClearIRQ() (ICPU.Registers.PL &= ~IRQ) +#define SetDecimal() (ICPU.Registers.PL |= Decimal) +#define ClearDecimal() (ICPU.Registers.PL &= ~Decimal) +#define SetIndex() (ICPU.Registers.PL |= IndexFlag) +#define ClearIndex() (ICPU.Registers.PL &= ~IndexFlag) +#define SetMemory() (ICPU.Registers.PL |= MemoryFlag) +#define ClearMemory() (ICPU.Registers.PL &= ~MemoryFlag) +#define SetOverflow() (ICPU._Overflow = 1) +#define ClearOverflow() (ICPU._Overflow = 0) +#define SetNegative() (ICPU._Negative = 0x80) +#define ClearNegative() (ICPU._Negative = 0) -#define CheckZero() (ICPU._Zero == 0) -#define CheckCarry() (ICPU._Carry) -#define CheckIRQ() (ICPU.Registers.PL & IRQ) -#define CheckDecimal() (ICPU.Registers.PL & Decimal) -#define CheckIndex() (ICPU.Registers.PL & IndexFlag) -#define CheckMemory() (ICPU.Registers.PL & MemoryFlag) -#define CheckOverflow() (ICPU._Overflow) -#define CheckNegative() (ICPU._Negative & 0x80) +#define CheckCarry() (ICPU._Carry) +#define CheckZero() (ICPU._Zero == 0) +#define CheckIRQ() (ICPU.Registers.PL & IRQ) +#define CheckDecimal() (ICPU.Registers.PL & Decimal) +#define CheckIndex() (ICPU.Registers.PL & IndexFlag) +#define CheckMemory() (ICPU.Registers.PL & MemoryFlag) +#define CheckOverflow() (ICPU._Overflow) +#define CheckNegative() (ICPU._Negative & 0x80) #define CheckEmulation() (ICPU.Registers.P.W & Emulation) -#define ClearFlags(f) (ICPU.Registers.P.W &= ~(f)) -#define SetFlags(f) (ICPU.Registers.P.W |= (f)) -#define CheckFlag(f) (ICPU.Registers.PL & (f)) +#define SetFlags(f) (ICPU.Registers.P.W |= (f)) +#define ClearFlags(f) (ICPU.Registers.P.W &= ~(f)) +#define CheckFlag(f) (ICPU.Registers.PL & (f)) typedef union { -#ifdef MSB_FIRST struct { +#ifdef MSB_FIRST uint8_t h, l; - } B; #else - struct - { uint8_t l, h; - } B; #endif + } B; uint16_t W; } pair; diff --git a/source/apu.c b/source/apu.c index a28469d..521d9b3 100644 --- a/source/apu.c +++ b/source/apu.c @@ -77,7 +77,6 @@ void S9xResetAPU() for (i = 0; i < 3; i++) { APU.TimerEnabled [i] = false; - APU.TimerValueWritten [i] = 0; APU.TimerTarget [i] = 0; APU.Timer [i] = 0; } @@ -388,9 +387,9 @@ void S9xSetAPUControl(uint8_t byte) if ((APU.TimerTarget [2] = IAPU.RAM [0xfc]) == 0) APU.TimerTarget [2] = 0x100; } - APU.TimerEnabled [0] = byte & 1; - APU.TimerEnabled [1] = (byte & 2) >> 1; - APU.TimerEnabled [2] = (byte & 4) >> 2; + APU.TimerEnabled [0] = (bool) (byte & 1); + APU.TimerEnabled [1] = (bool) (byte & 2); + APU.TimerEnabled [2] = (bool) (byte & 4); if (byte & 0x10) IAPU.RAM [0xF4] = IAPU.RAM [0xF5] = 0; diff --git a/source/apu.h b/source/apu.h index bafeac9..57ff79d 100644 --- a/source/apu.h +++ b/source/apu.h @@ -47,21 +47,21 @@ typedef struct SAPU APU; SIAPU IAPU; -static inline void S9xAPUUnpackStatus(void) +static inline void S9xAPUUnpackStatus() { IAPU._Zero = ((IAPU.Registers.P & Zero) == 0) | (IAPU.Registers.P & Negative); IAPU._Carry = (IAPU.Registers.P & Carry); IAPU._Overflow = (IAPU.Registers.P & Overflow) >> 6; } -static inline void S9xAPUPackStatus(void) +static inline void S9xAPUPackStatus() { IAPU.Registers.P &= ~(Zero | Negative | Carry | Overflow); IAPU.Registers.P |= IAPU._Carry | ((IAPU._Zero == 0) << 1) | (IAPU._Zero & 0x80) | (IAPU._Overflow << 6); } -void S9xResetAPU(void); +void S9xResetAPU(); bool S9xInitAPU(); void S9xDeinitAPU(); void S9xDecacheSamples(); @@ -73,7 +73,7 @@ void S9xOpenCloseSoundTracingFile(bool); void S9xPrintAPUState(); extern uint16_t S9xAPUCycles [256]; // Scaled cycle lengths extern uint16_t S9xAPUCycleLengths [256]; // Raw data. -extern void (*S9xApuOpcodes [256])(void); +extern void (*S9xApuOpcodes [256])(); #define APU_VOL_LEFT 0x00 #define APU_VOL_RIGHT 0x01 diff --git a/source/apu_blargg.c b/source/apu_blargg.c index bbe02c9..abf982e 100644 --- a/source/apu_blargg.c +++ b/source/apu_blargg.c @@ -327,7 +327,7 @@ static INLINE void dsp_decode_brr( dsp_voice_t* v ) if ( (dsp_m.every_other_sample ^= 1) != 0 ) \ dsp_m.new_kon &= ~dsp_m.kon; /* clears KON 63 clocks after it was last read */ -static INLINE void dsp_misc_30 (void) +static INLINE void dsp_misc_30() { if ( dsp_m.every_other_sample ) { @@ -606,11 +606,11 @@ static void dsp_voice_V9_V6_V3( dsp_voice_t* const v ) ECHO_FIR( 0 ) [ch] = ECHO_FIR( 8 ) [ch] = s >> 1; \ } -static INLINE void dsp_echo_22 (void) +static INLINE void dsp_echo_22() { int32_t l, r; - if ( ++dsp_m.echo_hist_pos >= &dsp_m.echo_hist [ECHO_HIST_SIZE] ) + if (++dsp_m.echo_hist_pos >= &dsp_m.echo_hist [ECHO_HIST_SIZE]) dsp_m.echo_hist_pos = dsp_m.echo_hist; dsp_m.t_echo_ptr = (dsp_m.t_esa * 0x100 + dsp_m.echo_offset) & 0xFFFF; @@ -624,7 +624,7 @@ static INLINE void dsp_echo_22 (void) dsp_m.t_echo_in [1] = r; } -static INLINE void dsp_echo_23 (void) +static INLINE void dsp_echo_23() { int32_t l, r; @@ -637,7 +637,7 @@ static INLINE void dsp_echo_23 (void) ECHO_READ(1); } -static INLINE void dsp_echo_24 (void) +static INLINE void dsp_echo_24() { int32_t l, r; @@ -648,7 +648,7 @@ static INLINE void dsp_echo_24 (void) dsp_m.t_echo_in [1] += r; } -static INLINE void dsp_echo_25 (void) +static INLINE void dsp_echo_25() { int32_t l = dsp_m.t_echo_in [0] + (((dsp_m.echo_hist_pos [6 + 1]) [0] * (int8_t) dsp_m.regs [R_FIR + 6 * 0x10]) >> 6); int32_t r = dsp_m.t_echo_in [1] + (((dsp_m.echo_hist_pos [6 + 1]) [1] * (int8_t) dsp_m.regs [R_FIR + 6 * 0x10]) >> 6); @@ -674,7 +674,7 @@ static INLINE void dsp_echo_25 (void) CLAMP16( var ); \ } -static INLINE void dsp_echo_26 (void) +static INLINE void dsp_echo_26() { int32_t l, r; @@ -690,7 +690,7 @@ static INLINE void dsp_echo_26 (void) dsp_m.t_echo_out [1] = r & ~1; } -static INLINE void dsp_echo_27 (void) +static INLINE void dsp_echo_27() { int32_t l, r; int16_t *out; @@ -733,7 +733,7 @@ static INLINE void dsp_echo_27 (void) } \ dsp_m.t_echo_out [ch] = 0; -static INLINE void dsp_echo_29 (void) +static INLINE void dsp_echo_29() { dsp_m.t_esa = dsp_m.regs [R_ESA]; @@ -949,7 +949,7 @@ static void dsp_set_output( int16_t * out, int32_t size ) /* Setup */ -static void dsp_soft_reset_common (void) +static void dsp_soft_reset_common() { dsp_m.noise = 0x4000; dsp_m.echo_hist_pos = dsp_m.echo_hist; @@ -962,7 +962,7 @@ static void dsp_soft_reset_common (void) /* Resets DSP to power-on state */ -static void dsp_reset (void) +static void dsp_reset() { int32_t i; @@ -1009,7 +1009,7 @@ static void dsp_init( void* ram_64k ) /* Emulates pressing reset switch on SNES */ -static void dsp_soft_reset (void) +static void dsp_soft_reset() { dsp_m.regs[R_FLG] = 0xE0; dsp_soft_reset_common(); @@ -2576,7 +2576,6 @@ set_psw: { addr &= 0xFFFF; SET_PC( addr ); - /* dprintf( "SPC: PC wrapped around\n" ); */ goto loop; } } @@ -2670,7 +2669,7 @@ uint8_t * spc_apuram() /* Init */ -static void spc_reset_buffer(void) +static void spc_reset_buffer() { int16_t *out; /* Start with half extra buffer of silence */ @@ -2745,7 +2744,7 @@ static void spc_reset_common( int32_t timer_counter_init ) /* Resets SPC to power-on state. This resets your output buffer, so you must call set_output() after this. */ -static void spc_reset (void) +static void spc_reset() { m.cpu_regs.pc = 0xFFC0; m.cpu_regs.a = 0x00; @@ -2782,9 +2781,9 @@ static void spc_reset (void) /* Emulates pressing reset switch on SNES. This resets your output buffer, so you must call set_output() after this. */ -static void spc_soft_reset (void) +static void spc_soft_reset() { - spc_reset_common( 0 ); + spc_reset_common(0); dsp_soft_reset(); } @@ -2926,7 +2925,7 @@ static INLINE int32_t hermite (int32_t mu1, int32_t a, int32_t b, int32_t c, int return ((a0) + (a1) + (a2) + (a3)) >> 15; } -static void resampler_clear(void) +static void resampler_clear() { rb_start = 0; rb_size = 0; @@ -3073,7 +3072,7 @@ bool S9xMixSamples (int16_t *buffer, uint32_t sample_count) return (true); } -int32_t S9xGetSampleCount (void) +int32_t S9xGetSampleCount() { return AVAIL(); } @@ -3108,7 +3107,7 @@ static void spc_set_output( int16_t* out, int32_t size ) dsp_set_output( out, out_end - out ); } -void S9xFinalizeSamples (void) +void S9xFinalizeSamples() { bool ret; @@ -3126,13 +3125,13 @@ void S9xFinalizeSamples (void) spc_set_output(landing_buffer, buffer_size); } -void S9xClearSamples (void) +void S9xClearSamples() { resampler_clear(); lag = lag_master; } -bool S9xSyncSound (void) +bool S9xSyncSound() { if (!Settings.SoundSync || sound_in_sync) return true; @@ -3147,7 +3146,7 @@ void S9xSetSamplesAvailableCallback (apu_callback callback) sa_callback = callback; } -static void UpdatePlaybackRate (void) +static void UpdatePlaybackRate() { double time_ratio; if (Settings.SoundInputRate == 0) @@ -3179,8 +3178,6 @@ bool S9xInitSound (int32_t buffer_ms, int32_t lag_ms) buffer_size <<= 1; buffer_size <<= 1; - printf("Sound buffer size: %d (%d samples)\n", buffer_size, sample_count); - if (landing_buffer) free(landing_buffer); landing_buffer = (int16_t*)malloc(buffer_size * 2); @@ -3248,7 +3245,7 @@ static int8_t const reg_times_ [256] = 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, }; -bool S9xInitAPU (void) +bool S9xInitAPU() { int32_t i; @@ -3303,7 +3300,7 @@ bool S9xInitAPU (void) return true; } -void S9xDeinitAPU (void) +void S9xDeinitAPU() { if (resampler) { @@ -3338,7 +3335,7 @@ void S9xAPUSetReferenceTime (int32_t cpucycles) reference_time = cpucycles; } -void S9xAPUExecute (void) +void S9xAPUExecute() { /* Accumulate partial APU cycles */ spc_end_frame(S9X_APU_GET_CLOCK(CPU.Cycles)); @@ -3352,9 +3349,6 @@ void S9xAPUExecute (void) void S9xAPUTimingSetSpeedup (int32_t ticks) { - if (ticks != 0) - printf("APU speedup hack: %d\n", ticks); - timing_hack_denominator = TEMPO_UNIT - ticks; spc_set_tempo(timing_hack_denominator); @@ -3370,7 +3364,7 @@ void S9xAPUAllowTimeOverflow (bool allow) allow_time_overflow = allow; } -void S9xResetAPU (void) +void S9xResetAPU() { reference_time = 0; spc_remainder = 0; @@ -3383,7 +3377,7 @@ void S9xResetAPU (void) resampler_clear(); } -void S9xSoftResetAPU (void) +void S9xSoftResetAPU() { reference_time = 0; spc_remainder = 0; diff --git a/source/apu_blargg.h b/source/apu_blargg.h index 66c375f..00d9428 100644 --- a/source/apu_blargg.h +++ b/source/apu_blargg.h @@ -226,7 +226,7 @@ typedef struct } Timer; /* Support SNES_MEMORY_APURAM */ -uint8_t *spc_apuram (void); +uint8_t* spc_apuram(); typedef struct { @@ -276,31 +276,31 @@ typedef struct /* Number of samples written to output since last set */ #define SPC_SAMPLE_COUNT() ((m.extra_clocks >> 5) * 2) -typedef void (*apu_callback)(void); +typedef void (*apu_callback)(); #define SPC_SAVE_STATE_BLOCK_SIZE (STATE_SIZE + 8) -bool S9xInitAPU (void); -void S9xDeinitAPU (void); -void S9xResetAPU (void); -void S9xSoftResetAPU (void); -uint8_t S9xAPUReadPort (int32_t port); -void S9xAPUWritePort (int32_t port, uint8_t byte); -void S9xAPUExecute (void); -void S9xAPUSetReferenceTime (int32_t cpucycles); -void S9xAPUTimingSetSpeedup (int32_t ticks); -void S9xAPUAllowTimeOverflow (bool allow); -void S9xAPULoadState (const uint8_t * block); -void S9xAPUSaveState (uint8_t * block); - -bool S9xInitSound (int32_t buffer_ms, int32_t lag_ms); - -bool S9xSyncSound (void); -int32_t S9xGetSampleCount (void); -void S9xFinalizeSamples (void); -void S9xClearSamples (void); -bool S9xMixSamples (int16_t * buffer, uint32_t sample_count); -void S9xSetSamplesAvailableCallback (apu_callback); +bool S9xInitAPU(); +void S9xDeinitAPU(); +void S9xResetAPU(); +void S9xSoftResetAPU(); +uint8_t S9xAPUReadPort(int32_t port); +void S9xAPUWritePort(int32_t port, uint8_t byte); +void S9xAPUExecute(); +void S9xAPUSetReferenceTime(int32_t cpucycles); +void S9xAPUTimingSetSpeedup(int32_t ticks); +void S9xAPUAllowTimeOverflow(bool allow); +void S9xAPULoadState(const uint8_t * block); +void S9xAPUSaveState(uint8_t * block); + +bool S9xInitSound(int32_t buffer_ms, int32_t lag_ms); + +bool S9xSyncSound(); +int32_t S9xGetSampleCount(); +void S9xFinalizeSamples(); +void S9xClearSamples(); +bool S9xMixSamples(int16_t * buffer, uint32_t sample_count); +void S9xSetSamplesAvailableCallback(apu_callback); #endif // APU_BLARGG_H diff --git a/source/c4.c b/source/c4.c index 65d4c01..9519cc3 100644 --- a/source/c4.c +++ b/source/c4.c @@ -3,7 +3,7 @@ #include <math.h> #include <stdlib.h> #include "c4.h" -#include "memmap.h" +#include "port.h" int16_t C4WFXVal; int16_t C4WFYVal; @@ -13,70 +13,174 @@ int16_t C4WFY2Val; int16_t C4WFDist; int16_t C4WFScale; -static double tanval; -static double c4x, c4y, c4z; -static double c4x2, c4y2, c4z2; +int32_t tanval; +static int32_t c4x, c4y, c4z; +static int32_t c4x2, c4y2, c4z2; + +const int16_t C4MulTable[256] = +{ + 0x0000, 0x0003, 0x0006, 0x0009, 0x000c, 0x000f, 0x0012, 0x0015, + 0x0019, 0x001c, 0x001f, 0x0022, 0x0025, 0x0028, 0x002b, 0x002f, + 0x0032, 0x0035, 0x0038, 0x003b, 0x003e, 0x0041, 0x0045, 0x0048, + 0x004b, 0x004e, 0x0051, 0x0054, 0x0057, 0x005b, 0x005e, 0x0061, + 0x0064, 0x0067, 0x006a, 0x006d, 0x0071, 0x0074, 0x0077, 0x007a, + 0x007d, 0x0080, 0x0083, 0x0087, 0x008a, 0x008d, 0x0090, 0x0093, + 0x0096, 0x0099, 0x009d, 0x00a0, 0x00a3, 0x00a6, 0x00a9, 0x00ac, + 0x00af, 0x00b3, 0x00b6, 0x00b9, 0x00bc, 0x00bf, 0x00c2, 0x00c5, + 0x00c9, 0x00cc, 0x00cf, 0x00d2, 0x00d5, 0x00d8, 0x00db, 0x00df, + 0x00e2, 0x00e5, 0x00e8, 0x00eb, 0x00ee, 0x00f1, 0x00f5, 0x00f8, + 0x00fb, 0x00fe, 0x0101, 0x0104, 0x0107, 0x010b, 0x010e, 0x0111, + 0x0114, 0x0117, 0x011a, 0x011d, 0x0121, 0x0124, 0x0127, 0x012a, + 0x012d, 0x0130, 0x0133, 0x0137, 0x013a, 0x013d, 0x0140, 0x0143, + 0x0146, 0x0149, 0x014d, 0x0150, 0x0153, 0x0156, 0x0159, 0x015c, + 0x015f, 0x0163, 0x0166, 0x0169, 0x016c, 0x016f, 0x0172, 0x0175, + 0x0178, 0x017c, 0x017f, 0x0182, 0x0185, 0x0188, 0x018b, 0x018e, + 0x0192, 0x0195, 0x0198, 0x019b, 0x019e, 0x01a1, 0x01a4, 0x01a8, + 0x01ab, 0x01ae, 0x01b1, 0x01b4, 0x01b7, 0x01ba, 0x01be, 0x01c1, + 0x01c4, 0x01c7, 0x01ca, 0x01cd, 0x01d0, 0x01d4, 0x01d7, 0x01da, + 0x01dd, 0x01e0, 0x01e3, 0x01e6, 0x01ea, 0x01ed, 0x01f0, 0x01f3, + 0x01f6, 0x01f9, 0x01fc, 0x0200, 0x0203, 0x0206, 0x0209, 0x020c, + 0x020f, 0x0212, 0x0216, 0x0219, 0x021c, 0x021f, 0x0222, 0x0225, + 0x0228, 0x022c, 0x022f, 0x0232, 0x0235, 0x0238, 0x023b, 0x023e, + 0x0242, 0x0245, 0x0248, 0x024b, 0x024e, 0x0251, 0x0254, 0x0258, + 0x025b, 0x025e, 0x0261, 0x0264, 0x0267, 0x026a, 0x026e, 0x0271, + 0x0274, 0x0277, 0x027a, 0x027d, 0x0280, 0x0284, 0x0287, 0x028a, + 0x028d, 0x0290, 0x0293, 0x0296, 0x029a, 0x029d, 0x02a0, 0x02a3, + 0x02a6, 0x02a9, 0x02ac, 0x02b0, 0x02b3, 0x02b6, 0x02b9, 0x02bc, + 0x02bf, 0x02c2, 0x02c6, 0x02c9, 0x02cc, 0x02cf, 0x02d2, 0x02d5, + 0x02d8, 0x02db, 0x02df, 0x02e2, 0x02e5, 0x02e8, 0x02eb, 0x02ee, + 0x02f1, 0x02f5, 0x02f8, 0x02fb, 0x02fe, 0x0301, 0x0304, 0x0307, + 0x030b, 0x030e, 0x0311, 0x0314, 0x0317, 0x031a, 0x031d, 0x0321 +}; + +int16_t C4_Sin(int16_t Angle) +{ + if (Angle < 0) + { + if (Angle == -32768) + return 0; + return -C4_Sin(-Angle); + } + int16_t AngleS7 = Angle >> 7; + int32_t S = C4SinTable[AngleS7] + (C4MulTable[Angle & 0xff] * C4SinTable[0x80 + AngleS7] >> 15); + if (S > 32767) + S = 32767; + return (int16_t) S; +} + +int16_t C4_Cos(int16_t Angle) +{ + if (Angle < 0) + { + if (Angle == -32768) + return -32768; + Angle = -Angle; + } + int16_t AngleS7 = Angle >> 7; + int32_t S = C4SinTable[0x80 + AngleS7] - (C4MulTable[Angle & 0xff] * C4SinTable[AngleS7] >> 15); + if (S < -32768) + S = -32767; + return (int16_t) S; +} + +const int16_t atantbl[256] = { + 0, 1, 1, 2, 3, 3, 4, 4, 5, 6, 6, 7, 8, 8, 9, 10, + 10, 11, 11, 12, 13, 13, 14, 15, 15, 16, 16, 17, 18, 18, 19, 20, + 20, 21, 21, 22, 23, 23, 24, 25, 25, 26, 26, 27, 28, 28, 29, 29, + 30, 31, 31, 32, 33, 33, 34, 34, 35, 36, 36, 37, 37, 38, 39, 39, + 40, 40, 41, 42, 42, 43, 43, 44, 44, 45, 46, 46, 47, 47, 48, 49, + 49, 50, 50, 51, 51, 52, 53, 53, 54, 54, 55, 55, 56, 57, 57, 58, + 58, 59, 59, 60, 60, 61, 62, 62, 63, 63, 64, 64, 65, 65, 66, 66, + 67, 67, 68, 69, 69, 70, 70, 71, 71, 72, 72, 73, 73, 74, 74, 75, + 75, 76, 76, 77, 77, 78, 78, 79, 79, 80, 80, 81, 81, 82, 82, 83, + 83, 84, 84, 85, 85, 86, 86, 86, 87, 87, 88, 88, 89, 89, 90, 90, + 91, 91, 92, 92, 92, 93, 93, 94, 94, 95, 95, 96, 96, 96, 97, 97, + 98, 98, 99, 99, 99, 100, 100, 101, 101, 101, 102, 102, 103, 103, 104, 104, + 104, 105, 105, 106, 106, 106, 107, 107, 108, 108, 108, 109, 109, 109, 110, 110, + 111, 111, 111, 112, 112, 113, 113, 113, 114, 114, 114, 115, 115, 115, 116, 116, + 117, 117, 117, 118, 118, 118, 119, 119, 119, 120, 120, 120, 121, 121, 121, 122, + 122, 122, 123, 123, 123, 124, 124, 124, 125, 125, 125, 126, 126, 126, 127, 127 +}; + +int16_t _atan2(int16_t x, int16_t y) +{ + if (x == 0) + return 0; + + int32_t x1 = ABS(x), y1 = ABS(y); + int32_t absAtan; + + if (x1 > y1) + absAtan = atantbl[(unsigned char)((y1 << 8) / x1)]; + else + absAtan = atantbl[(unsigned char)((x1 << 8) / y1)]; + + if ((x >= 0) ^ (y >= 0)) + return -absAtan; + + return absAtan; +} void C4TransfWireFrame() { - c4x = (double) C4WFXVal; - c4y = (double) C4WFYVal; - c4z = (double) C4WFZVal - 0x95; + c4x = C4WFXVal; + c4y = C4WFYVal; + c4z = C4WFZVal - 0x95; // Rotate X - tanval = -(double) C4WFX2Val * 3.14159265 * 2 / 128; - c4y2 = c4y * cos(tanval) - c4z * sin(tanval); - c4z2 = c4y * sin(tanval) + c4z * cos(tanval); + tanval = -C4WFX2Val << 9; + c4y2 = (c4y * C4_Cos(tanval) - c4z * C4_Sin(tanval)) >> 15; + c4z2 = (c4y * C4_Sin(tanval) + c4z * C4_Cos(tanval)) >> 15; // Rotate Y - tanval = -(double)C4WFY2Val * 3.14159265 * 2 / 128; - c4x2 = c4x * cos(tanval) + c4z2 * sin(tanval); - c4z = c4x * - sin(tanval) + c4z2 * cos(tanval); + tanval = -C4WFY2Val << 9; + c4x2 = (c4x * C4_Cos(tanval) + c4z2 * C4_Sin(tanval)) >> 15; + c4z = (c4x * -C4_Sin(tanval) + c4z2 * C4_Cos(tanval)) >> 15; // Rotate Z - tanval = -(double) C4WFDist * 3.14159265 * 2 / 128; - c4x = c4x2 * cos(tanval) - c4y2 * sin(tanval); - c4y = c4x2 * sin(tanval) + c4y2 * cos(tanval); + tanval = -C4WFDist << 9; + c4x = (c4x2 * C4_Cos(tanval) - c4y2 * C4_Sin(tanval)) >> 15; + c4y = (c4x2 * C4_Sin(tanval) + c4y2 * C4_Cos(tanval)) >> 15; // Scale - C4WFXVal = (int16_t)(c4x * (double)C4WFScale / (0x90 * (c4z + 0x95)) * 0x95); - C4WFYVal = (int16_t)(c4y * (double)C4WFScale / (0x90 * (c4z + 0x95)) * 0x95); + C4WFXVal = (int16_t)(((int32_t)c4x * C4WFScale * 0x95) / (0x90 * (c4z + 0x95))); + C4WFYVal = (int16_t)(((int32_t)c4y * C4WFScale * 0x95) / (0x90 * (c4z + 0x95))); } void C4TransfWireFrame2() { - c4x = (double)C4WFXVal; - c4y = (double)C4WFYVal; - c4z = (double)C4WFZVal; + c4x = C4WFXVal; + c4y = C4WFYVal; + c4z = C4WFZVal; // Rotate X - tanval = -(double) C4WFX2Val * 3.14159265 * 2 / 128; - c4y2 = c4y * cos(tanval) - c4z * sin(tanval); - c4z2 = c4y * sin(tanval) + c4z * cos(tanval); + tanval = -C4WFX2Val << 9; + c4y2 = (c4y * C4_Cos(tanval) - c4z * C4_Sin(tanval)) >> 15; + c4z2 = (c4y * C4_Sin(tanval) + c4z * C4_Cos(tanval)) >> 15; // Rotate Y - tanval = -(double) C4WFY2Val * 3.14159265 * 2 / 128; - c4x2 = c4x * cos(tanval) + c4z2 * sin(tanval); - c4z = c4x * -sin(tanval) + c4z2 * cos(tanval); + tanval = -C4WFY2Val << 9; + c4x2 = (c4x * C4_Cos(tanval) + c4z2 * C4_Sin(tanval)) >> 15; + c4z = (c4x * -C4_Sin(tanval) + c4z2 * C4_Cos(tanval)) >> 15; // Rotate Z - tanval = -(double)C4WFDist * 3.14159265 * 2 / 128; - c4x = c4x2 * cos(tanval) - c4y2 * sin(tanval); - c4y = c4x2 * sin(tanval) + c4y2 * cos(tanval); + tanval = -C4WFDist << 9; + c4x = (c4x2 * C4_Cos(tanval) - c4y2 * C4_Sin(tanval)) >> 15; + c4y = (c4x2 * C4_Sin(tanval) + c4y2 * C4_Cos(tanval)) >> 15; // Scale - C4WFXVal = (int16_t)(c4x * (double)C4WFScale / 0x100); - C4WFYVal = (int16_t)(c4y * (double)C4WFScale / 0x100); + C4WFXVal = (int16_t)(((int32_t)c4x * C4WFScale) / 0x100); + C4WFYVal = (int16_t)(((int32_t)c4y * C4WFScale) / 0x100); } void C4CalcWireFrame() { C4WFXVal = C4WFX2Val - C4WFXVal; C4WFYVal = C4WFY2Val - C4WFYVal; - if (abs(C4WFXVal) > abs(C4WFYVal)) + if (ABS(C4WFXVal) > ABS(C4WFYVal)) { - C4WFDist = abs(C4WFXVal) + 1; - C4WFYVal = (int16_t)(256 * (double) C4WFYVal / abs(C4WFXVal)); + C4WFDist = ABS(C4WFXVal) + 1; + C4WFYVal = (int16_t)(((int32_t)C4WFYVal << 8) / ABS(C4WFXVal)); if (C4WFXVal < 0) C4WFXVal = -256; else @@ -86,8 +190,8 @@ void C4CalcWireFrame() { if (C4WFYVal != 0) { - C4WFDist = abs(C4WFYVal) + 1; - C4WFXVal = (int16_t)(256 * (double)C4WFXVal / abs(C4WFYVal)); + C4WFDist = ABS(C4WFYVal) + 1; + C4WFXVal = (int16_t)(((int32_t)C4WFXVal << 8) / ABS(C4WFYVal)); if (C4WFYVal < 0) C4WFYVal = -256; else @@ -103,36 +207,3 @@ int16_t C41FYVal; int16_t C41FAngleRes; int16_t C41FDist; int16_t C41FDistVal; - -void C4Op1F() -{ - if (C41FXVal == 0) - { - if (C41FYVal > 0) - C41FAngleRes = 0x80; - else - C41FAngleRes = 0x180; - } - else - { - tanval = (double) C41FYVal / C41FXVal; - C41FAngleRes = (int16_t)(atan(tanval) / (3.141592675 * 2) * 512); - if (C41FXVal < 0) - C41FAngleRes += 0x100; - C41FAngleRes &= 0x1FF; - } -} - -void C4Op15() -{ - tanval = sqrt((double) C41FYVal * C41FYVal + (double) C41FXVal * C41FXVal); - C41FDist = (int16_t) tanval; -} - -void C4Op0D() -{ - tanval = sqrt((double) C41FYVal * C41FYVal + (double) C41FXVal * C41FXVal); - tanval = C41FDistVal / tanval; - C41FYVal = (int16_t)(C41FYVal * tanval * 0.99); - C41FXVal = (int16_t)(C41FXVal * tanval * 0.98); -} diff --git a/source/c4.h b/source/c4.h index 590ead0..7ab3964 100644 --- a/source/c4.h +++ b/source/c4.h @@ -23,9 +23,9 @@ extern int16_t C41FAngleRes; extern int16_t C41FDist; extern int16_t C41FDistVal; -void C4Op1F(); -void C4Op15(); -void C4Op0D(); +extern int32_t tanval; + +int16_t _atan2(int16_t x, int16_t y); extern int16_t C4CosTable[]; extern int16_t C4SinTable[]; diff --git a/source/c4emu.c b/source/c4emu.c index a6baecf..0cfb3aa 100644 --- a/source/c4emu.c +++ b/source/c4emu.c @@ -12,11 +12,13 @@ void S9xInitC4() { - memset(Memory.C4RAM, 0, 0x2000); + Memory.C4RAM = &Memory.FillRAM [0x6000]; } uint8_t S9xGetC4(uint16_t Address) { + if (Address == 0x7f5e) + return 0; return (Memory.C4RAM [Address - 0x6000]); } @@ -37,15 +39,12 @@ static uint8_t C4TestPattern [12 * 4] = }; -static void C4ConvOAM(void) +static void C4ConvOAM() { uint8_t* i; uint8_t* OAMptr = Memory.C4RAM + (Memory.C4RAM[0x626] << 2); for (i = Memory.C4RAM + 0x1fd; i > OAMptr; i -= 4) - { - // Clear OAM-to-be - *i = 0xe0; - } + *i = 0xe0; // Clear OAM-to-be uint16_t globalX, globalY; uint8_t* OAMptr2; @@ -67,7 +66,8 @@ static void C4ConvOAM(void) uint8_t* srcptr = Memory.C4RAM + 0x220; for (i = Memory.C4RAM[0x0620]; i > 0 && SprCount > 0; i--, srcptr += 16) { - if ((srcptr[4] & 0x30) != prio) continue; + if ((srcptr[4] & 0x30) != prio) + continue; SprX = READ_WORD(srcptr) - globalX; SprY = READ_WORD(srcptr + 2) - globalY; SprName = srcptr[5]; @@ -97,12 +97,15 @@ static void C4ConvOAM(void) OAMptr[2] = SprName + sprptr[3]; OAMptr[3] = SprAttr ^ (sprptr[0] & 0xc0); // XXX: Carry from SprName addition? *OAMptr2 &= ~(3 << offset); - if (X & 0x100) *OAMptr2 |= 1 << offset; - if (sprptr[0] & 0x20) *OAMptr2 |= 2 << offset; + if (X & 0x100) + *OAMptr2 |= 1 << offset; + if (sprptr[0] & 0x20) + *OAMptr2 |= 2 << offset; OAMptr += 4; SprCount--; offset = (offset + 2) & 6; - if (offset == 0) OAMptr2++; + if (offset == 0) + OAMptr2++; } } } @@ -114,17 +117,19 @@ static void C4ConvOAM(void) OAMptr[2] = SprName; OAMptr[3] = SprAttr; *OAMptr2 &= ~(3 << offset); - if (SprX & 0x100) *OAMptr2 |= 3 << offset; - else *OAMptr2 |= 2 << offset; + if (SprX & 0x100) + *OAMptr2 |= 3 << offset; + else + *OAMptr2 |= 2 << offset; OAMptr += 4; SprCount--; offset = (offset + 2) & 6; - if (offset == 0) OAMptr2++; + if (offset == 0) + OAMptr2++; } } } } - // XXX: Copy to OAM? I doubt it. } static void C4DoScaleRotate(int32_t row_padding) @@ -133,9 +138,11 @@ static void C4DoScaleRotate(int32_t row_padding) // Calculate matrix int32_t XScale = READ_WORD(Memory.C4RAM + 0x1f8f); - if (XScale & 0x8000) XScale = 0x7fff; + if (XScale & 0x8000) + XScale = 0x7fff; int32_t YScale = READ_WORD(Memory.C4RAM + 0x1f92); - if (YScale & 0x8000) YScale = 0x7fff; + if (YScale & 0x8000) + YScale = 0x7fff; if (READ_WORD(Memory.C4RAM + 0x1f80) == 0) { @@ -173,14 +180,10 @@ static void C4DoScaleRotate(int32_t row_padding) } else { - A = (int16_t)SAR16(C4CosTable[READ_WORD(Memory.C4RAM + 0x1f80) & 0x1ff] * XScale, - 15); - B = (int16_t)(-SAR16(C4SinTable[READ_WORD(Memory.C4RAM + 0x1f80) & 0x1ff] * - YScale, 15)); - C = (int16_t)SAR16(C4SinTable[READ_WORD(Memory.C4RAM + 0x1f80) & 0x1ff] * XScale, - 15); - D = (int16_t)SAR16(C4CosTable[READ_WORD(Memory.C4RAM + 0x1f80) & 0x1ff] * YScale, - 15); + A = (int16_t) SAR16(C4CosTable[READ_WORD(Memory.C4RAM + 0x1f80) & 0x1ff] * XScale, 15); + B = (int16_t)(-SAR16(C4SinTable[READ_WORD(Memory.C4RAM + 0x1f80) & 0x1ff] * YScale, 15)); + C = (int16_t) SAR16(C4SinTable[READ_WORD(Memory.C4RAM + 0x1f80) & 0x1ff] * XScale, 15); + D = (int16_t) SAR16(C4CosTable[READ_WORD(Memory.C4RAM + 0x1f80) & 0x1ff] * YScale, 15); } // Calculate Pixel Resolution @@ -218,14 +221,19 @@ static void C4DoScaleRotate(int32_t row_padding) { uint32_t addr = (Y >> 12) * w + (X >> 12); byte = Memory.C4RAM[0x600 + (addr >> 1)]; - if (addr & 1) byte >>= 4; + if (addr & 1) + byte >>= 4; } // De-bitplanify - if (byte & 1) Memory.C4RAM[outidx] |= bit; - if (byte & 2) Memory.C4RAM[outidx + 1] |= bit; - if (byte & 4) Memory.C4RAM[outidx + 16] |= bit; - if (byte & 8) Memory.C4RAM[outidx + 17] |= bit; + if (byte & 1) + Memory.C4RAM[outidx] |= bit; + if (byte & 2) + Memory.C4RAM[outidx + 1] |= bit; + if (byte & 4) + Memory.C4RAM[outidx + 16] |= bit; + if (byte & 8) + Memory.C4RAM[outidx + 17] |= bit; bit >>= 1; if (bit == 0) @@ -247,8 +255,7 @@ static void C4DoScaleRotate(int32_t row_padding) } } -static void C4DrawLine(int32_t X1, int32_t Y1, int16_t Z1, - int32_t X2, int32_t Y2, int16_t Z2, uint8_t Color) +static void C4DrawLine(int32_t X1, int32_t Y1, int16_t Z1, int32_t X2, int32_t Y2, int16_t Z2, uint8_t Color) { // Transform coordinates C4WFXVal = (int16_t)X1; @@ -270,8 +277,8 @@ static void C4DrawLine(int32_t X1, int32_t Y1, int16_t Z1, Y2 = (C4WFYVal + 48) << 8; // get line info - C4WFXVal = (int16_t)(X1 >> 8); - C4WFYVal = (int16_t)(Y1 >> 8); + C4WFXVal = (int16_t)(X1 >> 8); + C4WFYVal = (int16_t)(Y1 >> 8); C4WFX2Val = (int16_t)(X2 >> 8); C4WFY2Val = (int16_t)(Y2 >> 8); C4CalcWireFrame(); @@ -285,20 +292,21 @@ static void C4DrawLine(int32_t X1, int32_t Y1, int16_t Z1, //.loop if (X1 > 0xff && Y1 > 0xff && X1 < 0x6000 && Y1 < 0x6000) { - uint16_t addr = (((Y1 >> 8) >> 3) << 8) - (((Y1 >> 8) >> 3) << 6) + ((( - X1 >> 8) >> 3) << 4) + ((Y1 >> 8) & 7) * 2; + uint16_t addr = (((Y1 >> 8) >> 3) << 8) - (((Y1 >> 8) >> 3) << 6) + (((X1 >> 8) >> 3) << 4) + ((Y1 >> 8) & 7) * 2; uint8_t bit = 0x80 >> ((X1 >> 8) & 7); Memory.C4RAM[addr + 0x300] &= ~bit; Memory.C4RAM[addr + 0x301] &= ~bit; - if (Color & 1) Memory.C4RAM[addr + 0x300] |= bit; - if (Color & 2) Memory.C4RAM[addr + 0x301] |= bit; + if (Color & 1) + Memory.C4RAM[addr + 0x300] |= bit; + if (Color & 2) + Memory.C4RAM[addr + 0x301] |= bit; } X1 += X2; Y1 += Y2; } } -static void C4DrawWireFrame(void) +static void C4DrawWireFrame() { uint8_t* line = S9xGetMemPointer(READ_3WORD(Memory.C4RAM + 0x1f80)); uint8_t* point1, *point2; @@ -312,15 +320,13 @@ static void C4DrawWireFrame(void) if (line[0] == 0xff && line[1] == 0xff) { uint8_t* tmp = line - 5; - while (line[2] == 0xff && line[3] == 0xff) tmp -= 5; - point1 = S9xGetMemPointer((Memory.C4RAM[0x1f82] << 16) | - (tmp[2] << 8) | tmp[3]); + while (line[2] == 0xff && line[3] == 0xff) + tmp -= 5; + point1 = S9xGetMemPointer((Memory.C4RAM[0x1f82] << 16) | (tmp[2] << 8) | tmp[3]); } else - point1 = S9xGetMemPointer((Memory.C4RAM[0x1f82] << 16) | - (line[0] << 8) | line[1]); - point2 = S9xGetMemPointer((Memory.C4RAM[0x1f82] << 16) | - (line[2] << 8) | line[3]); + point1 = S9xGetMemPointer((Memory.C4RAM[0x1f82] << 16) | (line[0] << 8) | line[1]); + point2 = S9xGetMemPointer((Memory.C4RAM[0x1f82] << 16) | (line[2] << 8) | line[3]); X1 = (point1[0] << 8) | point1[1]; Y1 = (point1[2] << 8) | point1[3]; @@ -333,7 +339,7 @@ static void C4DrawWireFrame(void) } } -static void C4TransformLines(void) +static void C4TransformLines() { C4WFX2Val = Memory.C4RAM[0x1f83]; C4WFY2Val = Memory.C4RAM[0x1f86]; @@ -366,19 +372,17 @@ static void C4TransformLines(void) ptr = Memory.C4RAM + 0xb02; uint8_t* ptr2 = Memory.C4RAM; + + for (i = READ_WORD(Memory.C4RAM + 0xb00); i > 0; i--, ptr += 2, ptr2 += 8) { - int32_t i; - for (i = READ_WORD(Memory.C4RAM + 0xb00); i > 0; i--, ptr += 2, ptr2 += 8) - { - C4WFXVal = READ_WORD(Memory.C4RAM + (ptr[0] << 4) + 1); - C4WFYVal = READ_WORD(Memory.C4RAM + (ptr[0] << 4) + 5); - C4WFX2Val = READ_WORD(Memory.C4RAM + (ptr[1] << 4) + 1); - C4WFY2Val = READ_WORD(Memory.C4RAM + (ptr[1] << 4) + 5); - C4CalcWireFrame(); - WRITE_WORD(ptr2 + 0x600, C4WFDist ? C4WFDist : 1); - WRITE_WORD(ptr2 + 0x602, C4WFXVal); - WRITE_WORD(ptr2 + 0x605, C4WFYVal); - } + C4WFXVal = READ_WORD(Memory.C4RAM + (ptr[0] << 4) + 1); + C4WFYVal = READ_WORD(Memory.C4RAM + (ptr[0] << 4) + 5); + C4WFX2Val = READ_WORD(Memory.C4RAM + (ptr[1] << 4) + 1); + C4WFY2Val = READ_WORD(Memory.C4RAM + (ptr[1] << 4) + 5); + C4CalcWireFrame(); + WRITE_WORD(ptr2 + 0x600, C4WFDist ? C4WFDist : 1); + WRITE_WORD(ptr2 + 0x602, C4WFXVal); + WRITE_WORD(ptr2 + 0x605, C4WFYVal); } } static void C4BitPlaneWave() @@ -479,12 +483,17 @@ static void C4SprDisintegrate() uint8_t pixel = (j & 1) ? (*src >> 4) : *src; int32_t idx = (y >> 11) * width * 4 + (x >> 11) * 32 + ((y >> 8) & 7) * 2; uint8_t mask = 0x80 >> ((x >> 8) & 7); - if (pixel & 1) Memory.C4RAM[idx] |= mask; - if (pixel & 2) Memory.C4RAM[idx + 1] |= mask; - if (pixel & 4) Memory.C4RAM[idx + 16] |= mask; - if (pixel & 8) Memory.C4RAM[idx + 17] |= mask; + if (pixel & 1) + Memory.C4RAM[idx] |= mask; + if (pixel & 2) + Memory.C4RAM[idx + 1] |= mask; + if (pixel & 4) + Memory.C4RAM[idx + 16] |= mask; + if (pixel & 8) + Memory.C4RAM[idx + 17] |= mask; } - if (j & 1) src++; + if (j & 1) + src++; } } } @@ -496,31 +505,24 @@ static void S9xC4ProcessSprites() case 0x00: // Build OAM C4ConvOAM(); break; - case 0x03: // Scale/Rotate C4DoScaleRotate(0); break; - case 0x05: // Transform Lines C4TransformLines(); break; - case 0x07: // Scale/Rotate C4DoScaleRotate(64); break; - case 0x08: // Draw wireframe C4DrawWireFrame(); break; - case 0x0b: // Disintegrate C4SprDisintegrate(); break; - case 0x0c: // Wave C4BitPlaneWave(); break; - default: break; } @@ -541,76 +543,75 @@ void S9xSetC4(uint8_t byte, uint16_t Address) case 0x00: // Sprite S9xC4ProcessSprites(); break; - case 0x01: // Draw wireframe memset(Memory.C4RAM + 0x300, 0, 16 * 12 * 3 * 4); C4DrawWireFrame(); break; - case 0x05: // Propulsion (?) { int32_t tmp = 0x10000; if (READ_WORD(Memory.C4RAM + 0x1f83)) - tmp = SAR32((tmp / READ_WORD(Memory.C4RAM + 0x1f83)) * READ_WORD( - Memory.C4RAM + 0x1f81), 8); + tmp = SAR32((tmp / READ_WORD(Memory.C4RAM + 0x1f83)) * READ_WORD(Memory.C4RAM + 0x1f81), 8); WRITE_WORD(Memory.C4RAM + 0x1f80, (uint16_t)tmp); + break; } - break; - case 0x0d: // Set vector length C41FXVal = READ_WORD(Memory.C4RAM + 0x1f80); C41FYVal = READ_WORD(Memory.C4RAM + 0x1f83); C41FDistVal = READ_WORD(Memory.C4RAM + 0x1f86); - C4Op0D(); + tanval = C41FDistVal / _isqrt((int32_t) C41FYVal * C41FYVal + (int32_t) C41FXVal * C41FXVal); + C41FYVal = (int16_t)(((int32_t)C41FYVal * tanval * 99) / 100); + C41FXVal = (int16_t)(((int32_t)C41FXVal * tanval * 98) / 100); WRITE_WORD(Memory.C4RAM + 0x1f89, C41FXVal); WRITE_WORD(Memory.C4RAM + 0x1f8c, C41FYVal); break; - case 0x10: // Polar to rectangluar { - int32_t tmp = SAR32((int32_t)READ_WORD(Memory.C4RAM + 0x1f83) * - C4CosTable[READ_WORD(Memory.C4RAM + 0x1f80) & 0x1ff] * 2, 16); + int32_t tmp = SAR32((int32_t)READ_WORD(Memory.C4RAM + 0x1f83) * C4CosTable[READ_WORD(Memory.C4RAM + 0x1f80) & 0x1ff] * 2, 16); WRITE_3WORD(Memory.C4RAM + 0x1f86, tmp); - tmp = SAR32((int32_t)READ_WORD(Memory.C4RAM + 0x1f83) * C4SinTable[READ_WORD( - Memory.C4RAM + 0x1f80) & 0x1ff] * 2, 16); + tmp = SAR32((int32_t)READ_WORD(Memory.C4RAM + 0x1f83) * C4SinTable[READ_WORD(Memory.C4RAM + 0x1f80) & 0x1ff] * 2, 16); WRITE_3WORD(Memory.C4RAM + 0x1f89, (tmp - SAR32(tmp, 6))); + break; } - break; - case 0x13: // Polar to rectangluar { - int32_t tmp = SAR32((int32_t)READ_WORD(Memory.C4RAM + 0x1f83) * - C4CosTable[READ_WORD(Memory.C4RAM + 0x1f80) & 0x1ff] * 2, 8); + int32_t tmp = SAR32((int32_t)READ_WORD(Memory.C4RAM + 0x1f83) * C4CosTable[READ_WORD(Memory.C4RAM + 0x1f80) & 0x1ff] * 2, 8); WRITE_3WORD(Memory.C4RAM + 0x1f86, tmp); - tmp = SAR32((int32_t)READ_WORD(Memory.C4RAM + 0x1f83) * C4SinTable[READ_WORD( - Memory.C4RAM + 0x1f80) & 0x1ff] * 2, 8); + tmp = SAR32((int32_t)READ_WORD(Memory.C4RAM + 0x1f83) * C4SinTable[READ_WORD(Memory.C4RAM + 0x1f80) & 0x1ff] * 2, 8); WRITE_3WORD(Memory.C4RAM + 0x1f89, tmp); + break; } - break; - case 0x15: // Pythagorean C41FXVal = READ_WORD(Memory.C4RAM + 0x1f80); C41FYVal = READ_WORD(Memory.C4RAM + 0x1f83); - C41FDist = (int16_t)sqrt((double)C41FXVal * C41FXVal + (double)C41FYVal * - C41FYVal); + C41FDist = (int16_t)_isqrt((int32_t) C41FXVal * C41FXVal + (int32_t) C41FYVal * C41FYVal); WRITE_WORD(Memory.C4RAM + 0x1f80, C41FDist); break; - case 0x1f: // atan C41FXVal = READ_WORD(Memory.C4RAM + 0x1f80); C41FYVal = READ_WORD(Memory.C4RAM + 0x1f83); - C4Op1F(); + if (C41FXVal == 0) + { + if (C41FYVal > 0) + C41FAngleRes = 0x80; + else + C41FAngleRes = 0x180; + } + else + { + C41FAngleRes = (int16_t)(_atan2(C41FYVal, C41FXVal) / 2); + if (C41FXVal < 0) + C41FAngleRes += 0x100; + C41FAngleRes &= 0x1FF; + } WRITE_WORD(Memory.C4RAM + 0x1f86, C41FAngleRes); break; - case 0x22: // Trapezoid { int16_t angle1 = READ_WORD(Memory.C4RAM + 0x1f8c) & 0x1ff; int16_t angle2 = READ_WORD(Memory.C4RAM + 0x1f8f) & 0x1ff; - int32_t tan1 = (C4CosTable[angle1] != 0) ? ((((int32_t)C4SinTable[angle1]) << 16) / - C4CosTable[angle1]) : 0x80000000; - int32_t tan2 = (C4CosTable[angle2] != 0) ? ((((int32_t)C4SinTable[angle2]) << 16) / - C4CosTable[angle2]) : 0x80000000; + int32_t tan1 = (C4CosTable[angle1] != 0) ? ((((int32_t)C4SinTable[angle1]) << 16) / C4CosTable[angle1]) : 0x80000000; + int32_t tan2 = (C4CosTable[angle2] != 0) ? ((((int32_t)C4SinTable[angle2]) << 16) / C4CosTable[angle2]) : 0x80000000; int16_t y = READ_WORD(Memory.C4RAM + 0x1f83) - READ_WORD(Memory.C4RAM + 0x1f89); int16_t left, right; int32_t j; @@ -618,13 +619,8 @@ void S9xSetC4(uint8_t byte, uint16_t Address) { if (y >= 0) { - left = SAR32((int32_t)tan1 * y, 16) - - READ_WORD(Memory.C4RAM + 0x1f80) + - READ_WORD(Memory.C4RAM + 0x1f86); - right = SAR32((int32_t)tan2 * y, 16) - - READ_WORD(Memory.C4RAM + 0x1f80) + - READ_WORD(Memory.C4RAM + 0x1f86) + - READ_WORD(Memory.C4RAM + 0x1f93); + left = SAR32((int32_t)tan1 * y, 16) - READ_WORD(Memory.C4RAM + 0x1f80) + READ_WORD(Memory.C4RAM + 0x1f86); + right = SAR32((int32_t)tan2 * y, 16) - READ_WORD(Memory.C4RAM + 0x1f80) + READ_WORD(Memory.C4RAM + 0x1f86) + READ_WORD(Memory.C4RAM + 0x1f93); if (left < 0 && right < 0) { @@ -654,18 +650,16 @@ void S9xSetC4(uint8_t byte, uint16_t Address) Memory.C4RAM[j + 0x900] = (uint8_t)right; y++; } + break; } - break; - case 0x25: // Multiply { int32_t foo = READ_3WORD(Memory.C4RAM + 0x1f80); int32_t bar = READ_3WORD(Memory.C4RAM + 0x1f83); foo *= bar; WRITE_3WORD(Memory.C4RAM + 0x1f80, foo); + break; } - break; - case 0x2d: // Transform Coords C4WFXVal = READ_WORD(Memory.C4RAM + 0x1f81); C4WFYVal = READ_WORD(Memory.C4RAM + 0x1f84); @@ -678,88 +672,79 @@ void S9xSetC4(uint8_t byte, uint16_t Address) WRITE_WORD(Memory.C4RAM + 0x1f80, C4WFXVal); WRITE_WORD(Memory.C4RAM + 0x1f83, C4WFYVal); break; - case 0x40: // Sum { int32_t i; uint16_t sum = 0; for (i = 0; i < 0x800; sum += Memory.C4RAM[i++]); WRITE_WORD(Memory.C4RAM + 0x1f80, sum); + break; } - break; - case 0x54: // Square { int64_t a = SAR64((int64_t)READ_3WORD(Memory.C4RAM + 0x1f80) << 40, 40); a *= a; WRITE_3WORD(Memory.C4RAM + 0x1f83, a); WRITE_3WORD(Memory.C4RAM + 0x1f86, (a >> 24)); + break; } - break; - case 0x5c: // Immediate Reg for (i = 0; i < 12 * 4; i++) Memory.C4RAM [i] = C4TestPattern [i]; break; - case 0x89: // Immediate ROM Memory.C4RAM [0x1f80] = 0x36; Memory.C4RAM [0x1f81] = 0x43; Memory.C4RAM [0x1f82] = 0x05; break; - default: break; } } } else if (Address == 0x7f47) - { // memmove required: Can overlap arbitrarily [Neb] - memmove(Memory.C4RAM + (READ_WORD(Memory.C4RAM + 0x1f45) & 0x1fff), - S9xGetMemPointer(READ_3WORD(Memory.C4RAM + 0x1f40)), - READ_WORD(Memory.C4RAM + 0x1f43)); - } + memmove(Memory.C4RAM + (READ_WORD(Memory.C4RAM + 0x1f45) & 0x1fff), S9xGetMemPointer(READ_3WORD(Memory.C4RAM + 0x1f40)), READ_WORD(Memory.C4RAM + 0x1f43)); } int16_t C4SinTable[512] = { - 0, 402, 804, 1206, 1607, 2009, 2410, 2811, - 3211, 3611, 4011, 4409, 4808, 5205, 5602, 5997, - 6392, 6786, 7179, 7571, 7961, 8351, 8739, 9126, - 9512, 9896, 10278, 10659, 11039, 11416, 11793, 12167, - 12539, 12910, 13278, 13645, 14010, 14372, 14732, 15090, - 15446, 15800, 16151, 16499, 16846, 17189, 17530, 17869, - 18204, 18537, 18868, 19195, 19519, 19841, 20159, 20475, - 20787, 21097, 21403, 21706, 22005, 22301, 22594, 22884, - 23170, 23453, 23732, 24007, 24279, 24547, 24812, 25073, - 25330, 25583, 25832, 26077, 26319, 26557, 26790, 27020, - 27245, 27466, 27684, 27897, 28106, 28310, 28511, 28707, - 28898, 29086, 29269, 29447, 29621, 29791, 29956, 30117, - 30273, 30425, 30572, 30714, 30852, 30985, 31114, 31237, - 31357, 31471, 31581, 31685, 31785, 31881, 31971, 32057, - 32138, 32214, 32285, 32351, 32413, 32469, 32521, 32568, - 32610, 32647, 32679, 32706, 32728, 32745, 32758, 32765, - 32767, 32765, 32758, 32745, 32728, 32706, 32679, 32647, - 32610, 32568, 32521, 32469, 32413, 32351, 32285, 32214, - 32138, 32057, 31971, 31881, 31785, 31685, 31581, 31471, - 31357, 31237, 31114, 30985, 30852, 30714, 30572, 30425, - 30273, 30117, 29956, 29791, 29621, 29447, 29269, 29086, - 28898, 28707, 28511, 28310, 28106, 27897, 27684, 27466, - 27245, 27020, 26790, 26557, 26319, 26077, 25832, 25583, - 25330, 25073, 24812, 24547, 24279, 24007, 23732, 23453, - 23170, 22884, 22594, 22301, 22005, 21706, 21403, 21097, - 20787, 20475, 20159, 19841, 19519, 19195, 18868, 18537, - 18204, 17869, 17530, 17189, 16846, 16499, 16151, 15800, - 15446, 15090, 14732, 14372, 14010, 13645, 13278, 12910, - 12539, 12167, 11793, 11416, 11039, 10659, 10278, 9896, - 9512, 9126, 8739, 8351, 7961, 7571, 7179, 6786, - 6392, 5997, 5602, 5205, 4808, 4409, 4011, 3611, - 3211, 2811, 2410, 2009, 1607, 1206, 804, 402, - 0, -402, -804, -1206, -1607, -2009, -2410, -2811, + 0, 402, 804, 1206, 1607, 2009, 2410, 2811, + 3211, 3611, 4011, 4409, 4808, 5205, 5602, 5997, + 6392, 6786, 7179, 7571, 7961, 8351, 8739, 9126, + 9512, 9896, 10278, 10659, 11039, 11416, 11793, 12167, + 12539, 12910, 13278, 13645, 14010, 14372, 14732, 15090, + 15446, 15800, 16151, 16499, 16846, 17189, 17530, 17869, + 18204, 18537, 18868, 19195, 19519, 19841, 20159, 20475, + 20787, 21097, 21403, 21706, 22005, 22301, 22594, 22884, + 23170, 23453, 23732, 24007, 24279, 24547, 24812, 25073, + 25330, 25583, 25832, 26077, 26319, 26557, 26790, 27020, + 27245, 27466, 27684, 27897, 28106, 28310, 28511, 28707, + 28898, 29086, 29269, 29447, 29621, 29791, 29956, 30117, + 30273, 30425, 30572, 30714, 30852, 30985, 31114, 31237, + 31357, 31471, 31581, 31685, 31785, 31881, 31971, 32057, + 32138, 32214, 32285, 32351, 32413, 32469, 32521, 32568, + 32610, 32647, 32679, 32706, 32728, 32745, 32758, 32765, + 32767, 32765, 32758, 32745, 32728, 32706, 32679, 32647, + 32610, 32568, 32521, 32469, 32413, 32351, 32285, 32214, + 32138, 32057, 31971, 31881, 31785, 31685, 31581, 31471, + 31357, 31237, 31114, 30985, 30852, 30714, 30572, 30425, + 30273, 30117, 29956, 29791, 29621, 29447, 29269, 29086, + 28898, 28707, 28511, 28310, 28106, 27897, 27684, 27466, + 27245, 27020, 26790, 26557, 26319, 26077, 25832, 25583, + 25330, 25073, 24812, 24547, 24279, 24007, 23732, 23453, + 23170, 22884, 22594, 22301, 22005, 21706, 21403, 21097, + 20787, 20475, 20159, 19841, 19519, 19195, 18868, 18537, + 18204, 17869, 17530, 17189, 16846, 16499, 16151, 15800, + 15446, 15090, 14732, 14372, 14010, 13645, 13278, 12910, + 12539, 12167, 11793, 11416, 11039, 10659, 10278, 9896, + 9512, 9126, 8739, 8351, 7961, 7571, 7179, 6786, + 6392, 5997, 5602, 5205, 4808, 4409, 4011, 3611, + 3211, 2811, 2410, 2009, 1607, 1206, 804, 402, + 0, -402, -804, -1206, -1607, -2009, -2410, -2811, -3211, -3611, -4011, -4409, -4808, -5205, -5602, -5997, -6392, -6786, -7179, -7571, -7961, -8351, -8739, -9126, - -9512, -9896, -10278, -10659, -11039, -11416, -11793, -12167, + -9512, -9896, -10278, -10659, -11039, -11416, -11793, -12167, -12539, -12910, -13278, -13645, -14010, -14372, -14732, -15090, -15446, -15800, -16151, -16499, -16846, -17189, -17530, -17869, -18204, -18537, -18868, -19195, -19519, -19841, -20159, -20475, @@ -792,26 +777,26 @@ int16_t C4SinTable[512] = int16_t C4CosTable[512] = { - 32767, 32765, 32758, 32745, 32728, 32706, 32679, 32647, - 32610, 32568, 32521, 32469, 32413, 32351, 32285, 32214, - 32138, 32057, 31971, 31881, 31785, 31685, 31581, 31471, - 31357, 31237, 31114, 30985, 30852, 30714, 30572, 30425, - 30273, 30117, 29956, 29791, 29621, 29447, 29269, 29086, - 28898, 28707, 28511, 28310, 28106, 27897, 27684, 27466, - 27245, 27020, 26790, 26557, 26319, 26077, 25832, 25583, - 25330, 25073, 24812, 24547, 24279, 24007, 23732, 23453, - 23170, 22884, 22594, 22301, 22005, 21706, 21403, 21097, - 20787, 20475, 20159, 19841, 19519, 19195, 18868, 18537, - 18204, 17869, 17530, 17189, 16846, 16499, 16151, 15800, - 15446, 15090, 14732, 14372, 14010, 13645, 13278, 12910, - 12539, 12167, 11793, 11416, 11039, 10659, 10278, 9896, - 9512, 9126, 8739, 8351, 7961, 7571, 7179, 6786, - 6392, 5997, 5602, 5205, 4808, 4409, 4011, 3611, - 3211, 2811, 2410, 2009, 1607, 1206, 804, 402, - 0, -402, -804, -1206, -1607, -2009, -2410, -2811, + 32767, 32765, 32758, 32745, 32728, 32706, 32679, 32647, + 32610, 32568, 32521, 32469, 32413, 32351, 32285, 32214, + 32138, 32057, 31971, 31881, 31785, 31685, 31581, 31471, + 31357, 31237, 31114, 30985, 30852, 30714, 30572, 30425, + 30273, 30117, 29956, 29791, 29621, 29447, 29269, 29086, + 28898, 28707, 28511, 28310, 28106, 27897, 27684, 27466, + 27245, 27020, 26790, 26557, 26319, 26077, 25832, 25583, + 25330, 25073, 24812, 24547, 24279, 24007, 23732, 23453, + 23170, 22884, 22594, 22301, 22005, 21706, 21403, 21097, + 20787, 20475, 20159, 19841, 19519, 19195, 18868, 18537, + 18204, 17869, 17530, 17189, 16846, 16499, 16151, 15800, + 15446, 15090, 14732, 14372, 14010, 13645, 13278, 12910, + 12539, 12167, 11793, 11416, 11039, 10659, 10278, 9896, + 9512, 9126, 8739, 8351, 7961, 7571, 7179, 6786, + 6392, 5997, 5602, 5205, 4808, 4409, 4011, 3611, + 3211, 2811, 2410, 2009, 1607, 1206, 804, 402, + 0, -402, -804, -1206, -1607, -2009, -2410, -2811, -3211, -3611, -4011, -4409, -4808, -5205, -5602, -5997, -6392, -6786, -7179, -7571, -7961, -8351, -8739, -9126, - -9512, -9896, -10278, -10659, -11039, -11416, -11793, -12167, + -9512, -9896, -10278, -10659, -11039, -11416, -11793, -12167, -12539, -12910, -13278, -13645, -14010, -14372, -14732, -15090, -15446, -15800, -16151, -16499, -16846, -17189, -17530, -17869, -18204, -18537, -18868, -19195, -19519, -19841, -20159, -20475, @@ -836,24 +821,24 @@ int16_t C4CosTable[512] = -20787, -20475, -20159, -19841, -19519, -19195, -18868, -18537, -18204, -17869, -17530, -17189, -16846, -16499, -16151, -15800, -15446, -15090, -14732, -14372, -14010, -13645, -13278, -12910, - -12539, -12167, -11793, -11416, -11039, -10659, -10278, -9896, + -12539, -12167, -11793, -11416, -11039, -10659, -10278, -9896, -9512, -9126, -8739, -8351, -7961, -7571, -7179, -6786, -6392, -5997, -5602, -5205, -4808, -4409, -4011, -3611, - -3211, -2811, -2410, -2009, -1607, -1206, -804, -402, - 0, 402, 804, 1206, 1607, 2009, 2410, 2811, - 3211, 3611, 4011, 4409, 4808, 5205, 5602, 5997, - 6392, 6786, 7179, 7571, 7961, 8351, 8739, 9126, - 9512, 9896, 10278, 10659, 11039, 11416, 11793, 12167, - 12539, 12910, 13278, 13645, 14010, 14372, 14732, 15090, - 15446, 15800, 16151, 16499, 16846, 17189, 17530, 17869, - 18204, 18537, 18868, 19195, 19519, 19841, 20159, 20475, - 20787, 21097, 21403, 21706, 22005, 22301, 22594, 22884, - 23170, 23453, 23732, 24007, 24279, 24547, 24812, 25073, - 25330, 25583, 25832, 26077, 26319, 26557, 26790, 27020, - 27245, 27466, 27684, 27897, 28106, 28310, 28511, 28707, - 28898, 29086, 29269, 29447, 29621, 29791, 29956, 30117, - 30273, 30425, 30572, 30714, 30852, 30985, 31114, 31237, - 31357, 31471, 31581, 31685, 31785, 31881, 31971, 32057, - 32138, 32214, 32285, 32351, 32413, 32469, 32521, 32568, - 32610, 32647, 32679, 32706, 32728, 32745, 32758, 32765 + -3211, -2811, -2410, -2009, -1607, -1206, -804, -402, + 0, 402, 804, 1206, 1607, 2009, 2410, 2811, + 3211, 3611, 4011, 4409, 4808, 5205, 5602, 5997, + 6392, 6786, 7179, 7571, 7961, 8351, 8739, 9126, + 9512, 9896, 10278, 10659, 11039, 11416, 11793, 12167, + 12539, 12910, 13278, 13645, 14010, 14372, 14732, 15090, + 15446, 15800, 16151, 16499, 16846, 17189, 17530, 17869, + 18204, 18537, 18868, 19195, 19519, 19841, 20159, 20475, + 20787, 21097, 21403, 21706, 22005, 22301, 22594, 22884, + 23170, 23453, 23732, 24007, 24279, 24547, 24812, 25073, + 25330, 25583, 25832, 26077, 26319, 26557, 26790, 27020, + 27245, 27466, 27684, 27897, 28106, 28310, 28511, 28707, + 28898, 29086, 29269, 29447, 29621, 29791, 29956, 30117, + 30273, 30425, 30572, 30714, 30852, 30985, 31114, 31237, + 31357, 31471, 31581, 31685, 31785, 31881, 31971, 32057, + 32138, 32214, 32285, 32351, 32413, 32469, 32521, 32568, + 32610, 32647, 32679, 32706, 32728, 32745, 32758, 32765 }; diff --git a/source/cheats.c b/source/cheats.c index b394032..5856769 100644 --- a/source/cheats.c +++ b/source/cheats.c @@ -34,8 +34,7 @@ const char* S9xProActionReplayToRaw(const char* code, uint32_t* address, return (NULL); } -const char* S9xGoldFingerToRaw(const char* code, uint32_t* address, bool* sram, - uint8_t* num_bytes, uint8_t bytes[3]) +const char* S9xGoldFingerToRaw(const char* code, uint32_t* address, bool* sram, uint8_t* num_bytes, uint8_t bytes[3]) { char tmp [15]; if (strlen(code) != 14) @@ -65,8 +64,7 @@ const char* S9xGameGenieToRaw(const char* code, uint32_t* address, uint8_t* byte { char new_code [12]; - if (strlen(code) != 9 || *(code + 4) != '-' || !S9xAllHex(code, 4) || - !S9xAllHex(code + 5, 4)) + if (strlen(code) != 9 || *(code + 4) != '-' || !S9xAllHex(code, 4) || !S9xAllHex(code + 5, 4)) return ("Invalid Game Genie(tm) code - should be 'xxxx-xxxx'."); strcpy(new_code, "0x"); @@ -104,7 +102,7 @@ const char* S9xGameGenieToRaw(const char* code, uint32_t* address, uint8_t* byte ((data & 0x0f0000) >> 12) + ((data & 0x0003c0) >> 6); - return (NULL); + return NULL; } void S9xStartCheatSearch(SCheatData* d) diff --git a/source/cheats.h b/source/cheats.h index a4a5ba7..6c3c093 100644 --- a/source/cheats.h +++ b/source/cheats.h @@ -44,33 +44,28 @@ typedef enum S9X_8_BITS, S9X_16_BITS, S9X_24_BITS, S9X_32_BITS } S9xCheatDataSize; -void S9xInitCheatData (); +void S9xInitCheatData(); -const char *S9xGameGenieToRaw (const char *code, uint32_t *address, uint8_t *byte); -const char *S9xProActionReplayToRaw (const char *code, uint32_t *address, uint8_t *byte); -const char *S9xGoldFingerToRaw (const char *code, uint32_t *address, bool *sram, - uint8_t *num_bytes, uint8_t bytes[3]); -void S9xApplyCheats(void); -void S9xApplyCheat (uint32_t which1); -void S9xRemoveCheats (); -void S9xRemoveCheat (uint32_t which1); -void S9xEnableCheat (uint32_t which1); -void S9xDisableCheat (uint32_t which1); -void S9xDisableAllCheat(void); -void S9xAddCheat (bool enable, bool save_current_value, uint32_t address, - uint8_t byte); -void S9xDeleteCheats(void); -void S9xDeleteCheat (uint32_t which1); -bool S9xLoadCheatFile (const char *filename); -bool S9xSaveCheatFile (const char *filename); +const char *S9xGameGenieToRaw(const char *code, uint32_t *address, uint8_t *byte); +const char *S9xProActionReplayToRaw(const char *code, uint32_t *address, uint8_t *byte); +const char *S9xGoldFingerToRaw(const char *code, uint32_t *address, bool *sram, uint8_t *num_bytes, uint8_t bytes[3]); +void S9xApplyCheats(); +void S9xApplyCheat(uint32_t which1); +void S9xRemoveCheats(); +void S9xRemoveCheat(uint32_t which1); +void S9xEnableCheat(uint32_t which1); +void S9xDisableCheat(uint32_t which1); +void S9xDisableAllCheat(); +void S9xAddCheat(bool enable, bool save_current_value, uint32_t address, uint8_t byte); +void S9xDeleteCheats(); +void S9xDeleteCheat(uint32_t which1); +bool S9xLoadCheatFile(const char *filename); +bool S9xSaveCheatFile(const char *filename); -void S9xStartCheatSearch (SCheatData *cheats); -void S9xSearchForChange (SCheatData *cheats, S9xCheatComparisonType cmp, - S9xCheatDataSize size, bool is_signed, bool update); -void S9xSearchForValue (SCheatData *cheats, S9xCheatComparisonType cmp, - S9xCheatDataSize size, uint32_t value, - bool is_signed, bool update); -void S9xOutputCheatSearchResults (SCheatData *cheats); +void S9xStartCheatSearch(SCheatData *cheats); +void S9xSearchForChange(SCheatData *cheats, S9xCheatComparisonType cmp, S9xCheatDataSize size, bool is_signed, bool update); +void S9xSearchForValue(SCheatData *cheats, S9xCheatComparisonType cmp, S9xCheatDataSize size, uint32_t value, bool is_signed, bool update); +void S9xOutputCheatSearchResults(SCheatData *cheats); #endif diff --git a/source/cpu.c b/source/cpu.c index e702670..15206c5 100644 --- a/source/cpu.c +++ b/source/cpu.c @@ -7,6 +7,7 @@ #include "cpuexec.h" #include "apu.h" #include "dma.h" +#include "fxemu.h" #include "sa1.h" #include "cheats.h" #include "srtc.h" @@ -14,8 +15,6 @@ #include "spc7110.h" #include "obc1.h" -#include "fxemu.h" - extern struct FxInit_s SuperFX; void S9xResetSuperFX() @@ -27,11 +26,11 @@ void S9xResetSuperFX() void S9xResetCPU() { ICPU.Registers.PB = 0; - ICPU.Registers.PC = S9xGetWord(0xFFFC); + ICPU.Registers.PC = S9xGetWord(0xfffc); ICPU.Registers.D.W = 0; ICPU.Registers.DB = 0; ICPU.Registers.SH = 1; - ICPU.Registers.SL = 0xFF; + ICPU.Registers.SL = 0xff; ICPU.Registers.XH = 0; ICPU.Registers.YH = 0; ICPU.Registers.P.W = 0; @@ -52,13 +51,12 @@ void S9xResetCPU() CPU.PCBase = NULL; CPU.PCAtOpcodeStart = NULL; CPU.WaitAddress = NULL; - CPU.WaitCounter = 0; - CPU.Cycles = 0; + CPU.WaitCounter = 1; + CPU.Cycles = 188; // This is the cycle count just after the jump to the Reset Vector. CPU.NextEvent = Settings.HBlankStart; CPU.V_Counter = 0; CPU.MemSpeed = SLOW_ONE_CYCLE; CPU.MemSpeedx2 = SLOW_ONE_CYCLE * 2; - CPU.FastROMSpeed = SLOW_ONE_CYCLE; CPU.AutoSaveTimer = 0; CPU.SRAMModified = false; CPU.BRKTriggered = false; @@ -72,7 +70,7 @@ void S9xResetCPU() S9xUnpackStatus(); } -static void CommonS9xReset(void) +static void CommonS9xReset() { if (Settings.SuperFX) S9xResetSuperFX(); @@ -101,14 +99,14 @@ static void CommonS9xReset(void) #endif } -void S9xReset(void) +void S9xReset() { CommonS9xReset(); S9xResetPPU(); memset(Memory.RAM, 0x55, 0x20000); } -void S9xSoftReset(void) +void S9xSoftReset() { CommonS9xReset(); S9xSoftResetPPU(); diff --git a/source/cpuaddr.h b/source/cpuaddr.h index 3531686..1085921 100644 --- a/source/cpuaddr.h +++ b/source/cpuaddr.h @@ -3,283 +3,309 @@ #ifndef _CPUADDR_H_ #define _CPUADDR_H_ -typedef enum -{ - NONE = 0, - READ = 1, - WRITE = 2, - MODIFY = 3, - JUMP = 4 -} AccessMode; - -// The type for a function that can run after the addressing mode is resolved: -typedef void (*InternalOp)(int32_t); +extern int32_t OpAddress; -static void Immediate8(AccessMode a, InternalOp op) +static inline void Immediate8() { - int32_t Addr = ICPU.ShiftedPB + CPU.PC - CPU.PCBase; + OpAddress = ICPU.ShiftedPB + CPU.PC - CPU.PCBase; CPU.PC++; - (*op)(Addr); } -static void Immediate16(AccessMode a, InternalOp op) +static inline void Immediate16() { - int32_t Addr = ICPU.ShiftedPB + CPU.PC - CPU.PCBase; + OpAddress = ICPU.ShiftedPB + CPU.PC - CPU.PCBase; CPU.PC += 2; - (*op)(Addr); } -static void Relative(AccessMode a, InternalOp op) +static inline void Relative() { int8_t Int8 = *CPU.PC++; - int32_t Addr = ((int32_t)(CPU.PC - CPU.PCBase) + Int8) & 0xffff; - (*op)(Addr); +#ifndef SA1_OPCODES + CPU.Cycles += CPU.MemSpeed; +#endif + OpAddress = ((int32_t)(CPU.PC - CPU.PCBase) + Int8) & 0xffff; } -static void RelativeLong(AccessMode a, InternalOp op) +static inline void RelativeLong() { - int32_t Addr; #ifdef FAST_LSB_WORD_ACCESS - Addr = *(uint16_t*) CPU.PC; + OpAddress = *(uint16_t*) CPU.PC; #else - Addr = *CPU.PC + (*(CPU.PC + 1) << 8); + OpAddress = *CPU.PC + (*(CPU.PC + 1) << 8); +#endif +#ifndef SA1_OPCODES + CPU.Cycles += CPU.MemSpeedx2 + ONE_CYCLE; #endif CPU.PC += 2; - Addr += (CPU.PC - CPU.PCBase); - Addr &= 0xffff; - (*op)(Addr); + OpAddress += (CPU.PC - CPU.PCBase); + OpAddress &= 0xffff; } -static void AbsoluteIndexedIndirect(AccessMode a, InternalOp op) +static inline void AbsoluteIndexedIndirect(bool read) { - int32_t Addr; #ifdef FAST_LSB_WORD_ACCESS - Addr = (ICPU.Registers.X.W + * (uint16_t*) CPU.PC) & 0xffff; + OpAddress = (ICPU.Registers.X.W + * (uint16_t*) CPU.PC) & 0xffff; #else - Addr = (ICPU.Registers.X.W + *CPU.PC + (*(CPU.PC + 1) << 8)) & 0xffff; + OpAddress = (ICPU.Registers.X.W + *CPU.PC + (*(CPU.PC + 1) << 8)) & 0xffff; +#endif +#ifndef SA1_OPCODES + CPU.Cycles += CPU.MemSpeedx2; #endif OpenBus = *(CPU.PC + 1); CPU.PC += 2; - Addr = S9xGetWord(ICPU.ShiftedPB + Addr); - if (a & READ) OpenBus = (uint8_t)(Addr >> 8); - (*op)(Addr); + OpAddress = S9xGetWord(ICPU.ShiftedPB + OpAddress); + if (read) + OpenBus = (uint8_t)(OpAddress >> 8); } -static void AbsoluteIndirectLong(AccessMode a, InternalOp op) +static inline void AbsoluteIndirectLong(bool read) { - int32_t Addr; #ifdef FAST_LSB_WORD_ACCESS - Addr = *(uint16_t*) CPU.PC; + OpAddress = *(uint16_t*) CPU.PC; #else - Addr = *CPU.PC + (*(CPU.PC + 1) << 8); + OpAddress = *CPU.PC + (*(CPU.PC + 1) << 8); +#endif +#ifndef SA1_OPCODES + CPU.Cycles += CPU.MemSpeedx2; #endif - OpenBus = *(CPU.PC + 1); CPU.PC += 2; - if (a & READ) - Addr = S9xGetWord(Addr) | ((OpenBus = S9xGetByte(Addr + 2)) << 16); + if (read) + OpAddress = S9xGetWord(OpAddress) | ((OpenBus = S9xGetByte(OpAddress + 2)) << 16); else - Addr = S9xGetWord(Addr) | (S9xGetByte(Addr + 2) << 16); - (*op)(Addr); + OpAddress = S9xGetWord(OpAddress) | (S9xGetByte(OpAddress + 2) << 16); } -static void AbsoluteIndirect(AccessMode a, InternalOp op) +static inline void AbsoluteIndirect(bool read) { - int32_t Addr; #ifdef FAST_LSB_WORD_ACCESS - Addr = *(uint16_t*) CPU.PC; + OpAddress = *(uint16_t*) CPU.PC; #else - Addr = *CPU.PC + (*(CPU.PC + 1) << 8); + OpAddress = *CPU.PC + (*(CPU.PC + 1) << 8); +#endif +#ifndef SA1_OPCODES + CPU.Cycles += CPU.MemSpeedx2; #endif - OpenBus = *(CPU.PC + 1); CPU.PC += 2; - Addr = S9xGetWord(Addr); - if (a & READ) OpenBus = (uint8_t)(Addr >> 8); - Addr += ICPU.ShiftedPB; - (*op)(Addr); + OpAddress = S9xGetWord(OpAddress); + if (read) + OpenBus = (uint8_t) (OpAddress >> 8); + OpAddress += ICPU.ShiftedPB; } -static void Absolute(AccessMode a, InternalOp op) +static inline void Absolute(bool read) { - int32_t Addr; #ifdef FAST_LSB_WORD_ACCESS - Addr = *(uint16_t*) CPU.PC + ICPU.ShiftedDB; + OpAddress = *(uint16_t*) CPU.PC + ICPU.ShiftedDB; #else - Addr = *CPU.PC + (*(CPU.PC + 1) << 8) + ICPU.ShiftedDB; + OpAddress = *CPU.PC + (*(CPU.PC + 1) << 8) + ICPU.ShiftedDB; #endif - if (a & READ) OpenBus = *(CPU.PC + 1); + if (read) + OpenBus = *(CPU.PC + 1); CPU.PC += 2; - (*op)(Addr); +#ifndef SA1_OPCODES + CPU.Cycles += CPU.MemSpeedx2; +#endif } -static void AbsoluteLong(AccessMode a, InternalOp op) +static inline void AbsoluteLong(bool read) { - int32_t Addr; #ifdef FAST_LSB_WORD_ACCESS - Addr = (*(uint32_t*) CPU.PC) & 0xffffff; + OpAddress = (*(uint32_t*) CPU.PC) & 0xffffff; #elif defined FAST_ALIGNED_LSB_WORD_ACCESS if (((int32_t) CPU.PC & 1) == 0) - Addr = (*(uint16_t*) CPU.PC) + (*(CPU.PC + 2) << 16); + OpAddress = (*(uint16_t*) CPU.PC) + (*(CPU.PC + 2) << 16); else - Addr = *CPU.PC + ((*(uint16_t*)(CPU.PC + 1)) << 8); + OpAddress = *CPU.PC + ((*(uint16_t*)(CPU.PC + 1)) << 8); #else - Addr = *CPU.PC + (*(CPU.PC + 1) << 8) + (*(CPU.PC + 2) << 16); + OpAddress = *CPU.PC + (*(CPU.PC + 1) << 8) + (*(CPU.PC + 2) << 16); #endif - if (a & READ) OpenBus = *(CPU.PC + 2); + if (read) + OpenBus = *(CPU.PC + 2); CPU.PC += 3; - (*op)(Addr); +#ifndef SA1_OPCODES + CPU.Cycles += CPU.MemSpeedx2 + CPU.MemSpeed; +#endif } -static void Direct(AccessMode a, InternalOp op) +static inline void Direct(bool read) { - if (a & READ) OpenBus = *CPU.PC; - int32_t Addr = (*CPU.PC++ + ICPU.Registers.D.W) & 0xffff; - (*op)(Addr); + if (read) + OpenBus = *CPU.PC; + OpAddress = (*CPU.PC++ + ICPU.Registers.D.W) & 0xffff; +#ifndef SA1_OPCODES + CPU.Cycles += CPU.MemSpeed; +#endif } -static void DirectIndirectIndexed(AccessMode a, InternalOp op) +static inline void DirectIndirectIndexed(bool read) { OpenBus = *CPU.PC; - int32_t Addr = (*CPU.PC++ + ICPU.Registers.D.W) & 0xffff; - - Addr = S9xGetWord(Addr); - if (a & READ) OpenBus = (uint8_t)(Addr >> 8); - Addr += ICPU.ShiftedDB + ICPU.Registers.Y.W; + OpAddress = (*CPU.PC++ + ICPU.Registers.D.W) & 0xffff; +#ifndef SA1_OPCODES + CPU.Cycles += CPU.MemSpeed; +#endif + OpAddress = S9xGetWord(OpAddress); + if (read) + OpenBus = (uint8_t)(OpAddress >> 8); + OpAddress += ICPU.ShiftedDB + ICPU.Registers.Y.W; // XXX: always add one if STA // XXX: else Add one cycle if crosses page boundary - (*op)(Addr); } -static void DirectIndirectIndexedLong(AccessMode a, InternalOp op) +static inline void DirectIndirectIndexedLong(bool read) { OpenBus = *CPU.PC; - int32_t Addr = (*CPU.PC++ + ICPU.Registers.D.W) & 0xffff; - - if (a & READ) - Addr = S9xGetWord(Addr) + ((OpenBus = S9xGetByte(Addr + 2)) << 16) + - ICPU.Registers.Y.W; + OpAddress = (*CPU.PC++ + ICPU.Registers.D.W) & 0xffff; +#ifndef SA1_OPCODES + CPU.Cycles += CPU.MemSpeed; +#endif + if (read) + OpAddress = S9xGetWord(OpAddress) + ((OpenBus = S9xGetByte(OpAddress + 2)) << 16) + ICPU.Registers.Y.W; else - Addr = S9xGetWord(Addr) + (S9xGetByte(Addr + 2) << 16) + ICPU.Registers.Y.W; - (*op)(Addr); + OpAddress = S9xGetWord(OpAddress) + (S9xGetByte(OpAddress + 2) << 16) + ICPU.Registers.Y.W; } -static void DirectIndexedIndirect(AccessMode a, InternalOp op) +static inline void DirectIndexedIndirect(bool read) { OpenBus = *CPU.PC; - int32_t Addr = (*CPU.PC++ + ICPU.Registers.D.W + ICPU.Registers.X.W) & 0xffff; - - Addr = S9xGetWord(Addr); - if (a & READ) OpenBus = (uint8_t)(Addr >> 8); - Addr += ICPU.ShiftedDB; - (*op)(Addr); + OpAddress = (*CPU.PC++ + ICPU.Registers.D.W + ICPU.Registers.X.W) & 0xffff; +#ifndef SA1_OPCODES + CPU.Cycles += CPU.MemSpeed; +#endif + OpAddress = S9xGetWord(OpAddress); + if (read) + OpenBus = (uint8_t)(OpAddress >> 8); + OpAddress += ICPU.ShiftedDB; +#ifndef SA1_OPCODES + CPU.Cycles += ONE_CYCLE; +#endif } -static void DirectIndexedX(AccessMode a, InternalOp op) +static inline void DirectIndexedX(bool read) { - if (a & READ) OpenBus = *CPU.PC; - int32_t Addr = (*CPU.PC++ + ICPU.Registers.D.W + ICPU.Registers.X.W); - Addr &= CheckEmulation() ? 0xff : 0xffff; - - (*op)(Addr); + if (read) + OpenBus = *CPU.PC; + OpAddress = (*CPU.PC++ + ICPU.Registers.D.W + ICPU.Registers.X.W); + OpAddress &= CheckEmulation() ? 0xff : 0xffff; +#ifndef SA1_OPCODES + CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; +#endif } -static void DirectIndexedY(AccessMode a, InternalOp op) +static void DirectIndexedY(bool read) { - if (a & READ) OpenBus = *CPU.PC; - int32_t Addr = (*CPU.PC++ + ICPU.Registers.D.W + ICPU.Registers.Y.W); - Addr &= CheckEmulation() ? 0xff : 0xffff; - (*op)(Addr); + if (read) + OpenBus = *CPU.PC; + OpAddress = (*CPU.PC++ + ICPU.Registers.D.W + ICPU.Registers.Y.W); + OpAddress &= CheckEmulation() ? 0xff : 0xffff; +#ifndef SA1_OPCODES + CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; +#endif } -static void AbsoluteIndexedX(AccessMode a, InternalOp op) +static inline void AbsoluteIndexedX(bool read) { - int32_t Addr; #ifdef FAST_LSB_WORD_ACCESS - Addr = ICPU.ShiftedDB + *(uint16_t*) CPU.PC + ICPU.Registers.X.W; + OpAddress = ICPU.ShiftedDB + *(uint16_t*) CPU.PC + ICPU.Registers.X.W; #else - Addr = ICPU.ShiftedDB + *CPU.PC + (*(CPU.PC + 1) << 8) + - ICPU.Registers.X.W; + OpAddress = ICPU.ShiftedDB + *CPU.PC + (*(CPU.PC + 1) << 8) + ICPU.Registers.X.W; #endif - if (a & READ) OpenBus = *(CPU.PC + 1); + if (read) + OpenBus = *(CPU.PC + 1); CPU.PC += 2; +#ifndef SA1_OPCODES + CPU.Cycles += CPU.MemSpeedx2; +#endif // XXX: always add one cycle for ROL, LSR, etc // XXX: else is cross page boundary add one cycle - (*op)(Addr); } -static void AbsoluteIndexedY(AccessMode a, InternalOp op) +static inline void AbsoluteIndexedY(bool read) { - int32_t Addr; #ifdef FAST_LSB_WORD_ACCESS - Addr = ICPU.ShiftedDB + *(uint16_t*) CPU.PC + ICPU.Registers.Y.W; + OpAddress = ICPU.ShiftedDB + *(uint16_t*) CPU.PC + ICPU.Registers.Y.W; #else - Addr = ICPU.ShiftedDB + *CPU.PC + (*(CPU.PC + 1) << 8) + - ICPU.Registers.Y.W; + OpAddress = ICPU.ShiftedDB + *CPU.PC + (*(CPU.PC + 1) << 8) + ICPU.Registers.Y.W; #endif - if (a & READ) OpenBus = *(CPU.PC + 1); + if (read) + OpenBus = *(CPU.PC + 1); CPU.PC += 2; +#ifndef SA1_OPCODES + CPU.Cycles += CPU.MemSpeedx2; +#endif // XXX: always add cycle for STA // XXX: else is cross page boundary add one cycle - (*op)(Addr); } -static void AbsoluteLongIndexedX(AccessMode a, InternalOp op) +static inline void AbsoluteLongIndexedX(bool read) { - int32_t Addr; #ifdef FAST_LSB_WORD_ACCESS - Addr = (*(uint32_t*) CPU.PC + ICPU.Registers.X.W) & 0xffffff; + OpAddress = (*(uint32_t*) CPU.PC + ICPU.Registers.X.W) & 0xffffff; #elif defined FAST_ALIGNED_LSB_WORD_ACCESS if (((int32_t) CPU.PC & 1) == 0) - Addr = ((*(uint16_t*) CPU.PC) + (*(CPU.PC + 2) << 16) + ICPU.Registers.X.W) & 0xFFFFFF; + OpAddress = ((*(uint16_t*) CPU.PC) + (*(CPU.PC + 2) << 16) + ICPU.Registers.X.W) & 0xFFFFFF; else - Addr = (*CPU.PC + ((*(uint16_t*)(CPU.PC + 1)) << 8) + ICPU.Registers.X.W) & 0xFFFFFF; + OpAddress = (*CPU.PC + ((*(uint16_t*)(CPU.PC + 1)) << 8) + ICPU.Registers.X.W) & 0xFFFFFF; #else - Addr = (*CPU.PC + (*(CPU.PC + 1) << 8) + (*(CPU.PC + 2) << 16) + - ICPU.Registers.X.W) & 0xffffff; + OpAddress = (*CPU.PC + (*(CPU.PC + 1) << 8) + (*(CPU.PC + 2) << 16) + ICPU.Registers.X.W) & 0xffffff; #endif - if (a & READ) OpenBus = *(CPU.PC + 2); + if (read) + OpenBus = *(CPU.PC + 2); CPU.PC += 3; - (*op)(Addr); +#ifndef SA1_OPCODES + CPU.Cycles += CPU.MemSpeedx2 + CPU.MemSpeed; +#endif } -static void DirectIndirect(AccessMode a, InternalOp op) +static inline void DirectIndirect(bool read) { OpenBus = *CPU.PC; - int32_t Addr = (*CPU.PC++ + ICPU.Registers.D.W) & 0xffff; - Addr = S9xGetWord(Addr); - if (a & READ) OpenBus = (uint8_t)(Addr >> 8); - Addr += ICPU.ShiftedDB; - (*op)(Addr); + OpAddress = (*CPU.PC++ + ICPU.Registers.D.W) & 0xffff; +#ifndef SA1_OPCODES + CPU.Cycles += CPU.MemSpeed; +#endif + OpAddress = S9xGetWord(OpAddress); + if (read) + OpenBus = (uint8_t)(OpAddress >> 8); + OpAddress += ICPU.ShiftedDB; } -static void DirectIndirectLong(AccessMode a, InternalOp op) +static inline void DirectIndirectLong(bool read) { OpenBus = *CPU.PC; - int32_t Addr = (*CPU.PC++ + ICPU.Registers.D.W) & 0xffff; - if (a & READ) - Addr = S9xGetWord(Addr) + ((OpenBus = S9xGetByte(Addr + 2)) << 16); + OpAddress = (*CPU.PC++ + ICPU.Registers.D.W) & 0xffff; +#ifndef SA1_OPCODES + CPU.Cycles += CPU.MemSpeed; +#endif + if (read) + OpAddress = S9xGetWord(OpAddress) + ((OpenBus = S9xGetByte(OpAddress + 2)) << 16); else - Addr = S9xGetWord(Addr) + (S9xGetByte(Addr + 2) << 16); - (*op)(Addr); + OpAddress = S9xGetWord(OpAddress) + (S9xGetByte(OpAddress + 2) << 16); } -static void StackRelative(AccessMode a, InternalOp op) +static inline void StackRelative(bool read) { - if (a & READ) OpenBus = *CPU.PC; - int32_t Addr = (*CPU.PC++ + ICPU.Registers.S.W) & 0xffff; - (*op)(Addr); + if (read) + OpenBus = *CPU.PC; + OpAddress = (*CPU.PC++ + ICPU.Registers.S.W) & 0xffff; +#ifndef SA1_OPCODES + CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; +#endif } -static void StackRelativeIndirectIndexed(AccessMode a, InternalOp op) +static inline void StackRelativeIndirectIndexed(bool read) { OpenBus = *CPU.PC; - int32_t Addr = (*CPU.PC++ + ICPU.Registers.S.W) & 0xffff; - Addr = S9xGetWord(Addr); - if (a & READ) OpenBus = (uint8_t)(Addr >> 8); - Addr = (Addr + ICPU.ShiftedDB + - ICPU.Registers.Y.W) & 0xffffff; - (*op)(Addr); + OpAddress = (*CPU.PC++ + ICPU.Registers.S.W) & 0xffff; +#ifndef SA1_OPCODES + CPU.Cycles += CPU.MemSpeed + TWO_CYCLES; +#endif + OpAddress = S9xGetWord(OpAddress); + if (read) + OpenBus = (uint8_t)(OpAddress >> 8); + OpAddress = (OpAddress + ICPU.ShiftedDB + ICPU.Registers.Y.W) & 0xffffff; } #endif diff --git a/source/cpuexec.c b/source/cpuexec.c index c834adf..d7151be 100644 --- a/source/cpuexec.c +++ b/source/cpuexec.c @@ -13,10 +13,10 @@ #include "sa1.h" #include "spc7110.h" -void S9xMainLoop_SA1_SFX(void); -void S9xMainLoop_SA1_NoSFX(void); -void S9xMainLoop_NoSA1_SFX(void); -void S9xMainLoop_NoSA1_NoSFX(void); +void S9xMainLoop_SA1_SFX(); +void S9xMainLoop_SA1_NoSFX(); +void S9xMainLoop_NoSA1_SFX(); +void S9xMainLoop_NoSA1_NoSFX(); /* * This is a CATSFC modification inspired by a Snes9x-Euphoria modification. @@ -27,7 +27,7 @@ void S9xMainLoop_NoSA1_NoSFX(void); * to propagate modifications to the SA1_NoSFX, NoSA1_SFX and NoSA1_NoSFX * versions. */ -void S9xMainLoop(void) +void S9xMainLoop() { if (Settings.SA1) { @@ -41,7 +41,7 @@ void S9xMainLoop(void) } } -void S9xMainLoop_SA1_SFX(void) +void S9xMainLoop_SA1_SFX() { for (;;) { @@ -56,7 +56,7 @@ void S9xMainLoop_SA1_SFX(void) if (CPU.WaitingForInterrupt) { CPU.WaitingForInterrupt = false; - ++CPU.PC; + CPU.PC++; } S9xOpcode_NMI(); } @@ -69,7 +69,7 @@ void S9xMainLoop_SA1_SFX(void) if (CPU.WaitingForInterrupt) { CPU.WaitingForInterrupt = false; - ++CPU.PC; + CPU.PC++; } if (CPU.IRQActive && !Settings.DisableIRQ) { @@ -79,13 +79,9 @@ void S9xMainLoop_SA1_SFX(void) else CPU.Flags &= ~IRQ_PENDING_FLAG; } - else - { - if (--CPU.IRQCycleCount == 0 && CheckFlag(IRQ)) - CPU.IRQCycleCount = 1; - } + else if (--CPU.IRQCycleCount == 0 && CheckFlag(IRQ)) + CPU.IRQCycleCount = 1; } - if (CPU.Flags & SCAN_KEYS_FLAG) break; } @@ -94,7 +90,6 @@ void S9xMainLoop_SA1_SFX(void) CPU.PCAtOpcodeStart = CPU.PC; #endif CPU.Cycles += CPU.MemSpeed; - (*ICPU.S9xOpcodes [*CPU.PC++].S9xOpcode)(); if (SA1.Executing) @@ -110,18 +105,9 @@ void S9xMainLoop_SA1_SFX(void) #endif if (CPU.Flags & SCAN_KEYS_FLAG) CPU.Flags &= ~SCAN_KEYS_FLAG; - -#ifdef DETECT_NASTY_FX_INTERLEAVE - if (CPU.BRKTriggered && Settings.SuperFX && !CPU.TriedInterleavedMode2) - { - CPU.TriedInterleavedMode2 = true; - CPU.BRKTriggered = false; - S9xDeinterleaveMode2(); - } -#endif } -void S9xMainLoop_SA1_NoSFX(void) +void S9xMainLoop_SA1_NoSFX() { for (;;) { @@ -159,13 +145,9 @@ void S9xMainLoop_SA1_NoSFX(void) else CPU.Flags &= ~IRQ_PENDING_FLAG; } - else - { - if (--CPU.IRQCycleCount == 0 && CheckFlag(IRQ)) - CPU.IRQCycleCount = 1; - } + else if (--CPU.IRQCycleCount == 0 && CheckFlag(IRQ)) + CPU.IRQCycleCount = 1; } - if (CPU.Flags & SCAN_KEYS_FLAG) break; } @@ -174,7 +156,6 @@ void S9xMainLoop_SA1_NoSFX(void) CPU.PCAtOpcodeStart = CPU.PC; #endif CPU.Cycles += CPU.MemSpeed; - (*ICPU.S9xOpcodes [*CPU.PC++].S9xOpcode)(); if (SA1.Executing) @@ -192,7 +173,7 @@ void S9xMainLoop_SA1_NoSFX(void) CPU.Flags &= ~SCAN_KEYS_FLAG; } -void S9xMainLoop_NoSA1_SFX(void) +void S9xMainLoop_NoSA1_SFX() { for (;;) { @@ -207,7 +188,7 @@ void S9xMainLoop_NoSA1_SFX(void) if (CPU.WaitingForInterrupt) { CPU.WaitingForInterrupt = false; - ++CPU.PC; + CPU.PC++; } S9xOpcode_NMI(); } @@ -220,7 +201,7 @@ void S9xMainLoop_NoSA1_SFX(void) if (CPU.WaitingForInterrupt) { CPU.WaitingForInterrupt = false; - ++CPU.PC; + CPU.PC++; } if (CPU.IRQActive && !Settings.DisableIRQ) { @@ -230,13 +211,9 @@ void S9xMainLoop_NoSA1_SFX(void) else CPU.Flags &= ~IRQ_PENDING_FLAG; } - else - { - if (--CPU.IRQCycleCount == 0 && CheckFlag(IRQ)) - CPU.IRQCycleCount = 1; - } + else if (--CPU.IRQCycleCount == 0 && CheckFlag(IRQ)) + CPU.IRQCycleCount = 1; } - if (CPU.Flags & SCAN_KEYS_FLAG) break; } @@ -245,9 +222,7 @@ void S9xMainLoop_NoSA1_SFX(void) CPU.PCAtOpcodeStart = CPU.PC; #endif CPU.Cycles += CPU.MemSpeed; - (*ICPU.S9xOpcodes [*CPU.PC++].S9xOpcode)(); - DO_HBLANK_CHECK_SFX(); } @@ -259,18 +234,9 @@ void S9xMainLoop_NoSA1_SFX(void) #endif if (CPU.Flags & SCAN_KEYS_FLAG) CPU.Flags &= ~SCAN_KEYS_FLAG; - -#ifdef DETECT_NASTY_FX_INTERLEAVE - if (CPU.BRKTriggered && Settings.SuperFX && !CPU.TriedInterleavedMode2) - { - CPU.TriedInterleavedMode2 = true; - CPU.BRKTriggered = false; - S9xDeinterleaveMode2(); - } -#endif } -void S9xMainLoop_NoSA1_NoSFX(void) +void S9xMainLoop_NoSA1_NoSFX() { for (;;) { @@ -308,13 +274,9 @@ void S9xMainLoop_NoSA1_NoSFX(void) else CPU.Flags &= ~IRQ_PENDING_FLAG; } - else - { - if (--CPU.IRQCycleCount == 0 && CheckFlag(IRQ)) - CPU.IRQCycleCount = 1; - } + else if (--CPU.IRQCycleCount == 0 && CheckFlag(IRQ)) + CPU.IRQCycleCount = 1; } - if (CPU.Flags & SCAN_KEYS_FLAG) break; } @@ -323,9 +285,7 @@ void S9xMainLoop_NoSA1_NoSFX(void) CPU.PCAtOpcodeStart = CPU.PC; #endif CPU.Cycles += CPU.MemSpeed; - (*ICPU.S9xOpcodes [*CPU.PC++].S9xOpcode)(); - DO_HBLANK_CHECK_NoSFX(); } @@ -396,8 +356,7 @@ void S9xDoHBlankProcessing_SFX() CPU.NextEvent = -1; ICPU.Scanline++; - if (++CPU.V_Counter >= (Settings.PAL ? SNES_MAX_PAL_VCOUNTER : - SNES_MAX_NTSC_VCOUNTER)) + if (++CPU.V_Counter >= (Settings.PAL ? SNES_MAX_PAL_VCOUNTER : SNES_MAX_NTSC_VCOUNTER)) { CPU.V_Counter = 0; Memory.FillRAM[0x213F] ^= 0x80; diff --git a/source/cpuexec.h b/source/cpuexec.h index c4342be..6d738dd 100644 --- a/source/cpuexec.h +++ b/source/cpuexec.h @@ -6,9 +6,9 @@ typedef struct { #ifdef __WIN32__ - void (__cdecl* S9xOpcode)(void); + void (__cdecl* S9xOpcode)(); #else - void (*S9xOpcode)(void); + void (*S9xOpcode)(); #endif } SOpcodes; @@ -41,9 +41,9 @@ typedef struct uint32_t FrameAdvanceCount; } SICPU; -void S9xMainLoop(void); -void S9xReset(void); -void S9xSoftReset(void); +void S9xMainLoop(); +void S9xReset(); +void S9xSoftReset(); void S9xDoHBlankProcessing_SFX(); void S9xDoHBlankProcessing_NoSFX(); void S9xClearIRQ(uint32_t); @@ -68,8 +68,7 @@ static inline void S9xUnpackStatus() static inline void S9xPackStatus() { ICPU.Registers.PL &= ~(Zero | Negative | Carry | Overflow); - ICPU.Registers.PL |= ICPU._Carry | ((ICPU._Zero == 0) << 1) | - (ICPU._Negative & 0x80) | (ICPU._Overflow << 6); + ICPU.Registers.PL |= ICPU._Carry | ((ICPU._Zero == 0) << 1) | (ICPU._Negative & 0x80) | (ICPU._Overflow << 6); } static inline void CLEAR_IRQ_SOURCE(uint32_t M) @@ -104,8 +103,7 @@ static inline void S9xReschedule() uint8_t which; int32_t max; - if (CPU.WhichEvent == HBLANK_START_EVENT || - CPU.WhichEvent == HTIMER_AFTER_EVENT) + if (CPU.WhichEvent == HBLANK_START_EVENT || CPU.WhichEvent == HTIMER_AFTER_EVENT) { which = HBLANK_END_EVENT; max = Settings.H_Max; diff --git a/source/cpumacro.h b/source/cpumacro.h index eb76b69..5868fed 100644 --- a/source/cpumacro.h +++ b/source/cpumacro.h @@ -3,50 +3,49 @@ #ifndef _CPUMACRO_H_ #define _CPUMACRO_H_ -static void SetZN16(uint16_t Work) +extern int32_t OpAddress; + +static inline void SetZN16(uint16_t Work) { ICPU._Zero = Work != 0; ICPU._Negative = (uint8_t)(Work >> 8); } -static void SetZN8(uint8_t Work) +static inline void SetZN8(uint8_t Work) { ICPU._Zero = Work; ICPU._Negative = Work; } -static void ADC8(int32_t Addr) +static inline void ADC8() { - uint8_t Work8 = S9xGetByte(Addr); + uint8_t Work8 = S9xGetByte(OpAddress); if (CheckDecimal()) { - uint8_t A1 = (ICPU.Registers.A.W) & 0xF; - uint8_t A2 = (ICPU.Registers.A.W >> 4) & 0xF; - uint8_t W1 = Work8 & 0xF; - uint8_t W2 = (Work8 >> 4) & 0xF; + uint8_t A1 = (ICPU.Registers.A.W) & 0x0f; + uint8_t A2 = (ICPU.Registers.A.W) & 0xf0; + uint8_t W1 = Work8 & 0x0f; + uint8_t W2 = Work8 & 0xf0; A1 += W1 + CheckCarry(); - if (A1 > 9) + if (A1 >= 0x0a) { - A1 -= 10; - A1 &= 0xF; - A2++; + A1 -= 0x0a; + A2 += 0x10; } A2 += W2; - if (A2 > 9) + if (A2 >= 0xa0) { - A2 -= 10; - A2 &= 0xF; + A2 -= 0xa0; SetCarry(); } else ClearCarry(); - int8_t Ans8 = (A2 << 4) | A1; - if (~(ICPU.Registers.AL ^ Work8) & - (Work8 ^ Ans8) & 0x80) + uint8_t Ans8 = A2 | A1; + if (~(ICPU.Registers.AL ^ Work8) & (Work8 ^ Ans8) & 0x80) SetOverflow(); else ClearOverflow(); @@ -54,12 +53,9 @@ static void ADC8(int32_t Addr) } else { - int16_t Ans16 = ICPU.Registers.AL + Work8 + CheckCarry(); - - ICPU._Carry = Ans16 >= 0x100; - - if (~(ICPU.Registers.AL ^ Work8) & - (Work8 ^ (uint8_t) Ans16) & 0x80) + uint16_t Ans16 = ICPU.Registers.AL + Work8 + CheckCarry(); + ICPU._Carry = Ans16 > 0xff; + if (~(ICPU.Registers.AL ^ Work8) & (Work8 ^ (uint8_t) Ans16) & 0x80) SetOverflow(); else ClearOverflow(); @@ -68,58 +64,53 @@ static void ADC8(int32_t Addr) SetZN8(ICPU.Registers.AL); } -static void ADC16(int32_t Addr) +static inline void ADC16() { - uint16_t Work16 = S9xGetWord(Addr); + uint16_t Work16 = S9xGetWord(OpAddress); if (CheckDecimal()) { - uint8_t A1 = (ICPU.Registers.A.W) & 0xF; - uint8_t A2 = (ICPU.Registers.A.W >> 4) & 0xF; - uint8_t A3 = (ICPU.Registers.A.W >> 8) & 0xF; - uint8_t A4 = (ICPU.Registers.A.W >> 12) & 0xF; - uint8_t W1 = Work16 & 0xF; - uint8_t W2 = (Work16 >> 4) & 0xF; - uint8_t W3 = (Work16 >> 8) & 0xF; - uint8_t W4 = (Work16 >> 12) & 0xF; + uint16_t A1 = ICPU.Registers.A.W & 0x000f; + uint16_t A2 = ICPU.Registers.A.W & 0x00f0; + uint16_t A3 = ICPU.Registers.A.W & 0x0f00; + uint16_t A4 = ICPU.Registers.A.W & 0xf000; + uint16_t W1 = Work16 & 0x000f; + uint16_t W2 = Work16 & 0x00f0; + uint16_t W3 = Work16 & 0x0f00; + uint16_t W4 = Work16 & 0xf000; A1 += W1 + CheckCarry(); - if (A1 > 9) + if (A1 >= 0x000a) { - A1 -= 10; - A1 &= 0xF; - A2++; + A1 -= 0x000a; + A2 += 0x0010; } A2 += W2; - if (A2 > 9) + if (A2 >= 0x00a0) { - A2 -= 10; - A2 &= 0xF; - A3++; + A2 -= 0x00a0; + A3 += 0x0100; } A3 += W3; - if (A3 > 9) + if (A3 >= 0x0a00) { - A3 -= 10; - A3 &= 0xF; - A4++; + A3 -= 0x0a00; + A4 += 0x1000; } A4 += W4; - if (A4 > 9) + if (A4 >= 0xa000) { - A4 -= 10; - A4 &= 0xF; + A4 -= 0xa000; SetCarry(); } else ClearCarry(); - uint16_t Ans16 = (A4 << 12) | (A3 << 8) | (A2 << 4) | (A1); - if (~(ICPU.Registers.A.W ^ Work16) & - (Work16 ^ Ans16) & 0x8000) + uint16_t Ans16 = A4 | A3 | A2 | A1; + if (~(ICPU.Registers.A.W ^ Work16) & (Work16 ^ Ans16) & 0x8000) SetOverflow(); else ClearOverflow(); @@ -129,10 +120,9 @@ static void ADC16(int32_t Addr) { uint32_t Ans32 = ICPU.Registers.A.W + Work16 + CheckCarry(); - ICPU._Carry = Ans32 >= 0x10000; + ICPU._Carry = Ans32 > 0xffff; - if (~(ICPU.Registers.A.W ^ Work16) & - (Work16 ^ (uint16_t) Ans32) & 0x8000) + if (~(ICPU.Registers.A.W ^ Work16) & (Work16 ^ (uint16_t) Ans32) & 0x8000) SetOverflow(); else ClearOverflow(); @@ -141,15 +131,15 @@ static void ADC16(int32_t Addr) SetZN16(ICPU.Registers.A.W); } -static void AND16(int32_t Addr) +static inline void AND16() { - ICPU.Registers.A.W &= S9xGetWord(Addr); + ICPU.Registers.A.W &= S9xGetWord(OpAddress); SetZN16(ICPU.Registers.A.W); } -static void AND8(int32_t Addr) +static inline void AND8() { - ICPU.Registers.AL &= S9xGetByte(Addr); + ICPU.Registers.AL &= S9xGetByte(OpAddress); SetZN8(ICPU.Registers.AL); } @@ -173,81 +163,85 @@ static inline void A_ASL8() SetZN8(ICPU.Registers.AL); } -static void ASL16(int32_t Addr) +static inline void ASL16() { - uint16_t Work16 = S9xGetWord(Addr); +#ifndef SA1_OPCODES + CPU.Cycles += ONE_CYCLE; +#endif + uint16_t Work16 = S9xGetWord(OpAddress); ICPU._Carry = (Work16 & 0x8000) != 0; Work16 <<= 1; - S9xSetByte(Work16 >> 8, Addr + 1); - S9xSetByte(Work16 & 0xFF, Addr); + S9xSetByte(Work16 >> 8, OpAddress + 1); + S9xSetByte(Work16 & 0xFF, OpAddress); SetZN16(Work16); } -static void ASL8(int32_t Addr) +static inline void ASL8() { - uint8_t Work8 = S9xGetByte(Addr); +#ifndef SA1_OPCODES + CPU.Cycles += ONE_CYCLE; +#endif + uint8_t Work8 = S9xGetByte(OpAddress); ICPU._Carry = (Work8 & 0x80) != 0; Work8 <<= 1; - S9xSetByte(Work8, Addr); + S9xSetByte(Work8, OpAddress); SetZN8(Work8); } -static void BIT16(int32_t Addr) +static inline void BIT16() { - uint16_t Work16 = S9xGetWord(Addr); + uint16_t Work16 = S9xGetWord(OpAddress); ICPU._Overflow = (Work16 & 0x4000) != 0; ICPU._Negative = (uint8_t)(Work16 >> 8); ICPU._Zero = (Work16 & ICPU.Registers.A.W) != 0; } -static void BIT8(int32_t Addr) +static inline void BIT8() { - uint8_t Work8 = S9xGetByte(Addr); + uint8_t Work8 = S9xGetByte(OpAddress); ICPU._Overflow = (Work8 & 0x40) != 0; ICPU._Negative = Work8; ICPU._Zero = Work8 & ICPU.Registers.AL; } -static void CMP16(int32_t Addr) +static inline void CMP16() { - int32_t Int32 = (int32_t) ICPU.Registers.A.W - (int32_t) S9xGetWord(Addr); + int32_t Int32 = (int32_t) ICPU.Registers.A.W - (int32_t) S9xGetWord(OpAddress); ICPU._Carry = Int32 >= 0; SetZN16((uint16_t) Int32); } -static void CMP8(int32_t Addr) +static inline void CMP8() { - int16_t Int16 = (int16_t) ICPU.Registers.AL - (int16_t) S9xGetByte(Addr); + int16_t Int16 = (int16_t) ICPU.Registers.AL - (int16_t) S9xGetByte(OpAddress); ICPU._Carry = Int16 >= 0; SetZN8((uint8_t) Int16); } -static void CMX16(int32_t Addr) +static inline void CMX16() { - int32_t Int32 = (int32_t) ICPU.Registers.X.W - (int32_t) S9xGetWord(Addr); + int32_t Int32 = (int32_t) ICPU.Registers.X.W - (int32_t) S9xGetWord(OpAddress); ICPU._Carry = Int32 >= 0; SetZN16((uint16_t) Int32); } -static void CMX8(int32_t Addr) +static inline void CMX8() { - int16_t Int16 = (int16_t) ICPU.Registers.XL - - (int16_t) S9xGetByte(Addr); + int16_t Int16 = (int16_t) ICPU.Registers.XL - (int16_t) S9xGetByte(OpAddress); ICPU._Carry = Int16 >= 0; SetZN8((uint8_t) Int16); } -static void CMY16(int32_t Addr) +static inline void CMY16() { - int32_t Int32 = (int32_t) ICPU.Registers.Y.W - (int32_t) S9xGetWord(Addr); + int32_t Int32 = (int32_t) ICPU.Registers.Y.W - (int32_t) S9xGetWord(OpAddress); ICPU._Carry = Int32 >= 0; SetZN16((uint16_t) Int32); } -static void CMY8(int32_t Addr) +static inline void CMY8() { - int16_t Int16 = (int16_t) ICPU.Registers.YL - - (int16_t) S9xGetByte(Addr); + int16_t Int16 = (int16_t) ICPU.Registers.YL - (int16_t) S9xGetByte(OpAddress); ICPU._Carry = Int16 >= 0; SetZN8((uint8_t) Int16); } @@ -260,7 +254,6 @@ static inline void A_DEC16() #ifdef CPU_SHUTDOWN CPU.WaitAddress = NULL; #endif - ICPU.Registers.A.W--; SetZN16(ICPU.Registers.A.W); } @@ -273,43 +266,46 @@ static inline void A_DEC8() #ifdef CPU_SHUTDOWN CPU.WaitAddress = NULL; #endif - ICPU.Registers.AL--; SetZN8(ICPU.Registers.AL); } -static void DEC16(int32_t Addr) +static inline void DEC16() { +#ifndef SA1_OPCODES + CPU.Cycles += ONE_CYCLE; +#endif #ifdef CPU_SHUTDOWN CPU.WaitAddress = NULL; #endif - - uint16_t Work16 = S9xGetWord(Addr) - 1; - S9xSetByte(Work16 >> 8, Addr + 1); - S9xSetByte(Work16 & 0xFF, Addr); + uint16_t Work16 = S9xGetWord(OpAddress) - 1; + S9xSetByte(Work16 >> 8, OpAddress + 1); + S9xSetByte(Work16 & 0xFF, OpAddress); SetZN16(Work16); } -static void DEC8(int32_t Addr) +static inline void DEC8() { +#ifndef SA1_OPCODES + CPU.Cycles += ONE_CYCLE; +#endif #ifdef CPU_SHUTDOWN CPU.WaitAddress = NULL; #endif - - uint8_t Work8 = S9xGetByte(Addr) - 1; - S9xSetByte(Work8, Addr); + uint8_t Work8 = S9xGetByte(OpAddress) - 1; + S9xSetByte(Work8, OpAddress); SetZN8(Work8); } -static void EOR16(int32_t Addr) +static inline void EOR16() { - ICPU.Registers.A.W ^= S9xGetWord(Addr); + ICPU.Registers.A.W ^= S9xGetWord(OpAddress); SetZN16(ICPU.Registers.A.W); } -static void EOR8(int32_t Addr) +static inline void EOR8() { - ICPU.Registers.AL ^= S9xGetByte(Addr); + ICPU.Registers.AL ^= S9xGetByte(OpAddress); SetZN8(ICPU.Registers.AL); } @@ -321,7 +317,6 @@ static inline void A_INC16() #ifdef CPU_SHUTDOWN CPU.WaitAddress = NULL; #endif - ICPU.Registers.A.W++; SetZN16(ICPU.Registers.A.W); } @@ -334,67 +329,70 @@ static inline void A_INC8() #ifdef CPU_SHUTDOWN CPU.WaitAddress = NULL; #endif - ICPU.Registers.AL++; SetZN8(ICPU.Registers.AL); } -static void INC16(int32_t Addr) +static inline void INC16() { +#ifndef SA1_OPCODES + CPU.Cycles += ONE_CYCLE; +#endif #ifdef CPU_SHUTDOWN CPU.WaitAddress = NULL; #endif - - uint16_t Work16 = S9xGetWord(Addr) + 1; - S9xSetByte(Work16 >> 8, Addr + 1); - S9xSetByte(Work16 & 0xFF, Addr); + uint16_t Work16 = S9xGetWord(OpAddress) + 1; + S9xSetByte(Work16 >> 8, OpAddress + 1); + S9xSetByte(Work16 & 0xFF, OpAddress); SetZN16(Work16); } -static void INC8(int32_t Addr) +static inline void INC8() { +#ifndef SA1_OPCODES + CPU.Cycles += ONE_CYCLE; +#endif #ifdef CPU_SHUTDOWN CPU.WaitAddress = NULL; #endif - - uint8_t Work8 = S9xGetByte(Addr) + 1; - S9xSetByte(Work8, Addr); + uint8_t Work8 = S9xGetByte(OpAddress) + 1; + S9xSetByte(Work8, OpAddress); SetZN8(Work8); } -static void LDA16(int32_t Addr) +static inline void LDA16() { - ICPU.Registers.A.W = S9xGetWord(Addr); + ICPU.Registers.A.W = S9xGetWord(OpAddress); SetZN16(ICPU.Registers.A.W); } -static void LDA8(int32_t Addr) +static inline void LDA8() { - ICPU.Registers.AL = S9xGetByte(Addr); + ICPU.Registers.AL = S9xGetByte(OpAddress); SetZN8(ICPU.Registers.AL); } -static void LDX16(int32_t Addr) +static inline void LDX16() { - ICPU.Registers.X.W = S9xGetWord(Addr); + ICPU.Registers.X.W = S9xGetWord(OpAddress); SetZN16(ICPU.Registers.X.W); } -static void LDX8(int32_t Addr) +static inline void LDX8() { - ICPU.Registers.XL = S9xGetByte(Addr); + ICPU.Registers.XL = S9xGetByte(OpAddress); SetZN8(ICPU.Registers.XL); } -static void LDY16(int32_t Addr) +static inline void LDY16() { - ICPU.Registers.Y.W = S9xGetWord(Addr); + ICPU.Registers.Y.W = S9xGetWord(OpAddress); SetZN16(ICPU.Registers.Y.W); } -static void LDY8(int32_t Addr) +static inline void LDY8() { - ICPU.Registers.YL = S9xGetByte(Addr); + ICPU.Registers.YL = S9xGetByte(OpAddress); SetZN8(ICPU.Registers.YL); } @@ -418,34 +416,40 @@ static inline void A_LSR8() SetZN8(ICPU.Registers.AL); } -static void LSR16(int32_t Addr) +static inline void LSR16() { - uint16_t Work16 = S9xGetWord(Addr); +#ifndef SA1_OPCODES + CPU.Cycles += ONE_CYCLE; +#endif + uint16_t Work16 = S9xGetWord(OpAddress); ICPU._Carry = Work16 & 1; Work16 >>= 1; - S9xSetByte(Work16 >> 8, Addr + 1); - S9xSetByte(Work16 & 0xFF, Addr); + S9xSetByte(Work16 >> 8, OpAddress + 1); + S9xSetByte(Work16 & 0xFF, OpAddress); SetZN16(Work16); } -static void LSR8(int32_t Addr) +static inline void LSR8() { - uint8_t Work8 = S9xGetByte(Addr); +#ifndef SA1_OPCODES + CPU.Cycles += ONE_CYCLE; +#endif + uint8_t Work8 = S9xGetByte(OpAddress); ICPU._Carry = Work8 & 1; Work8 >>= 1; - S9xSetByte(Work8, Addr); + S9xSetByte(Work8, OpAddress); SetZN8(Work8); } -static void ORA16(int32_t Addr) +static inline void ORA16() { - ICPU.Registers.A.W |= S9xGetWord(Addr); + ICPU.Registers.A.W |= S9xGetWord(OpAddress); SetZN16(ICPU.Registers.A.W); } -static void ORA8(int32_t Addr) +static inline void ORA8() { - ICPU.Registers.AL |= S9xGetByte(Addr); + ICPU.Registers.AL |= S9xGetByte(OpAddress); SetZN8(ICPU.Registers.AL); } @@ -455,7 +459,7 @@ static inline void A_ROL16() CPU.Cycles += ONE_CYCLE; #endif uint32_t Work32 = (ICPU.Registers.A.W << 1) | CheckCarry(); - ICPU._Carry = Work32 >= 0x10000; + ICPU._Carry = Work32 > 0xffff; ICPU.Registers.A.W = (uint16_t) Work32; SetZN16((uint16_t) Work32); } @@ -468,29 +472,35 @@ static inline void A_ROL8() uint16_t Work16 = ICPU.Registers.AL; Work16 <<= 1; Work16 |= CheckCarry(); - ICPU._Carry = Work16 >= 0x100; + ICPU._Carry = Work16 > 0xff; ICPU.Registers.AL = (uint8_t) Work16; SetZN8((uint8_t) Work16); } -static void ROL16(int32_t Addr) +static inline void ROL16() { - uint32_t Work32 = S9xGetWord(Addr); +#ifndef SA1_OPCODES + CPU.Cycles += ONE_CYCLE; +#endif + uint32_t Work32 = S9xGetWord(OpAddress); Work32 <<= 1; Work32 |= CheckCarry(); - ICPU._Carry = Work32 >= 0x10000; - S9xSetByte((Work32 >> 8) & 0xFF, Addr + 1); - S9xSetByte(Work32 & 0xFF, Addr); + ICPU._Carry = Work32 > 0xffff; + S9xSetByte((Work32 >> 8) & 0xFF, OpAddress + 1); + S9xSetByte(Work32 & 0xFF, OpAddress); SetZN16((uint16_t) Work32); } -static void ROL8(int32_t Addr) +static inline void ROL8() { - uint16_t Work16 = S9xGetByte(Addr); +#ifndef SA1_OPCODES + CPU.Cycles += ONE_CYCLE; +#endif + uint16_t Work16 = S9xGetByte(OpAddress); Work16 <<= 1; Work16 |= CheckCarry(); - ICPU._Carry = Work16 >= 0x100; - S9xSetByte((uint8_t) Work16, Addr); + ICPU._Carry = Work16 > 0xff; + S9xSetByte((uint8_t) Work16, OpAddress); SetZN8((uint8_t) Work16); } @@ -519,215 +529,229 @@ static inline void A_ROR8() SetZN8((uint8_t) Work16); } -static void ROR16(int32_t Addr) +static inline void ROR16() { - uint32_t Work32 = S9xGetWord(Addr); +#ifndef SA1_OPCODES + CPU.Cycles += ONE_CYCLE; +#endif + uint32_t Work32 = S9xGetWord(OpAddress); Work32 |= (int32_t) CheckCarry() << 16; ICPU._Carry = (uint8_t)(Work32 & 1); Work32 >>= 1; - S9xSetByte((Work32 >> 8) & 0x00FF, Addr + 1); - S9xSetByte(Work32 & 0x00FF, Addr); + S9xSetByte((Work32 >> 8) & 0x00FF, OpAddress + 1); + S9xSetByte(Work32 & 0x00FF, OpAddress); SetZN16((uint16_t) Work32); } -static void ROR8(int32_t Addr) +static inline void ROR8() { - uint16_t Work16 = S9xGetByte(Addr); +#ifndef SA1_OPCODES + CPU.Cycles += ONE_CYCLE; +#endif + uint16_t Work16 = S9xGetByte(OpAddress); Work16 |= (int32_t) CheckCarry() << 8; ICPU._Carry = (uint8_t)(Work16 & 1); Work16 >>= 1; - S9xSetByte((uint8_t) Work16, Addr); + S9xSetByte((uint8_t) Work16, OpAddress); SetZN8((uint8_t) Work16); } -static void SBC16(int32_t Addr) +static inline void SBC16() { - uint16_t Work16 = S9xGetWord(Addr); + uint16_t Work16 = S9xGetWord(OpAddress); if (CheckDecimal()) { - uint8_t A1 = (ICPU.Registers.A.W) & 0xF; - uint8_t A2 = (ICPU.Registers.A.W >> 4) & 0xF; - uint8_t A3 = (ICPU.Registers.A.W >> 8) & 0xF; - uint8_t A4 = (ICPU.Registers.A.W >> 12) & 0xF; - uint8_t W1 = Work16 & 0xF; - uint8_t W2 = (Work16 >> 4) & 0xF; - uint8_t W3 = (Work16 >> 8) & 0xF; - uint8_t W4 = (Work16 >> 12) & 0xF; + uint16_t A1 = ICPU.Registers.A.W & 0x000f; + uint16_t A2 = ICPU.Registers.A.W & 0x00f0; + uint16_t A3 = ICPU.Registers.A.W & 0x0f00; + uint16_t A4 = ICPU.Registers.A.W & 0xf000; + uint16_t W1 = Work16 & 0x000f; + uint16_t W2 = Work16 & 0x00f0; + uint16_t W3 = Work16 & 0x0f00; + uint16_t W4 = Work16 & 0xf000; A1 -= W1 + !CheckCarry(); A2 -= W2; A3 -= W3; A4 -= W4; - if (A1 > 9) + if (A1 > 0x000f) { - A1 += 10; - A2--; + A1 += 0x000a; + A1 &= 0x000f; + A2 -= 0x0010; } - if (A2 > 9) + if (A2 > 0x00f0) { - A2 += 10; - A3--; + A2 += 0x00a0; + A2 &= 0x00f0; + A3 -= 0x0100; } - if (A3 > 9) + if (A3 > 0x0f00) { - A3 += 10; - A4--; + A3 += 0x0a00; + A3 &= 0x0f00; + A4 -= 0x1000; } - if (A4 > 9) + if (A4 > 0xf000) { - A4 += 10; + A4 += 0xa000; + A4 &= 0xf000; ClearCarry(); } else SetCarry(); - uint16_t Ans16 = (A4 << 12) | (A3 << 8) | (A2 << 4) | (A1); - if ((ICPU.Registers.A.W ^ Work16) & - (ICPU.Registers.A.W ^ Ans16) & 0x8000) + uint16_t Ans16 = A4 | A3 | A2 | A1; + if ((ICPU.Registers.A.W ^ Work16) & (ICPU.Registers.A.W ^ Ans16) & 0x8000) SetOverflow(); else ClearOverflow(); ICPU.Registers.A.W = Ans16; - SetZN16(ICPU.Registers.A.W); } else { int32_t Int32 = (int32_t) ICPU.Registers.A.W - (int32_t) Work16 + (int32_t) CheckCarry() - 1; - ICPU._Carry = Int32 >= 0; - - if ((ICPU.Registers.A.W ^ Work16) & - (ICPU.Registers.A.W ^ (uint16_t) Int32) & 0x8000) + if ((ICPU.Registers.A.W ^ Work16) & (ICPU.Registers.A.W ^ (uint16_t) Int32) & 0x8000) SetOverflow(); else ClearOverflow(); ICPU.Registers.A.W = (uint16_t) Int32; - SetZN16(ICPU.Registers.A.W); } + SetZN16(ICPU.Registers.A.W); } -static void SBC8(int32_t Addr) +static inline void SBC8() { - uint8_t Work8 = S9xGetByte(Addr); + uint8_t Work8 = S9xGetByte(OpAddress); if (CheckDecimal()) { - uint8_t A1 = (ICPU.Registers.A.W) & 0xF; - uint8_t A2 = (ICPU.Registers.A.W >> 4) & 0xF; - uint8_t W1 = Work8 & 0xF; - uint8_t W2 = (Work8 >> 4) & 0xF; + uint8_t A1 = ICPU.Registers.A.W & 0x0f; + uint8_t A2 = ICPU.Registers.A.W & 0xf0; + uint8_t W1 = Work8 & 0x0f; + uint8_t W2 = Work8 & 0xf0; A1 -= W1 + !CheckCarry(); A2 -= W2; - if (A1 > 9) + if (A1 > 0x0f) { - A1 += 10; - A2--; + A1 += 0x0a; + A1 &= 0x0f; + A2 -= 0x10; } - if (A2 > 9) + if (A2 > 0xf0) { - A2 += 10; + A2 += 0xa0; + A2 &= 0xf0; ClearCarry(); } else SetCarry(); - uint8_t Ans8 = (A2 << 4) | A1; - if ((ICPU.Registers.AL ^ Work8) & - (ICPU.Registers.AL ^ Ans8) & 0x80) + uint8_t Ans8 = A2 | A1; + if ((ICPU.Registers.AL ^ Work8) & (ICPU.Registers.AL ^ Ans8) & 0x80) SetOverflow(); else ClearOverflow(); ICPU.Registers.AL = Ans8; - SetZN8(ICPU.Registers.AL); } else { - int16_t Int16 = (int16_t) ICPU.Registers.AL - (int16_t) Work8 + - (int16_t) CheckCarry() - 1; - + int16_t Int16 = (int16_t) ICPU.Registers.AL - (int16_t) Work8 + (int16_t) CheckCarry() - 1; ICPU._Carry = Int16 >= 0; - if ((ICPU.Registers.AL ^ Work8) & - (ICPU.Registers.AL ^ (uint8_t) Int16) & 0x80) + if ((ICPU.Registers.AL ^ Work8) & (ICPU.Registers.AL ^ (uint8_t) Int16) & 0x80) SetOverflow(); else ClearOverflow(); ICPU.Registers.AL = (uint8_t) Int16; - SetZN8(ICPU.Registers.AL); } + SetZN8(ICPU.Registers.AL); } -static void STA16(int32_t Addr) +static inline void STA16() { - S9xSetWord(ICPU.Registers.A.W, Addr); + S9xSetWord(ICPU.Registers.A.W, OpAddress); } -static void STA8(int32_t Addr) +static inline void STA8() { - S9xSetByte(ICPU.Registers.AL, Addr); + S9xSetByte(ICPU.Registers.AL, OpAddress); } -static void STX16(int32_t Addr) +static inline void STX16() { - S9xSetWord(ICPU.Registers.X.W, Addr); + S9xSetWord(ICPU.Registers.X.W, OpAddress); } -static void STX8(int32_t Addr) +static inline void STX8() { - S9xSetByte(ICPU.Registers.XL, Addr); + S9xSetByte(ICPU.Registers.XL, OpAddress); } -static void STY16(int32_t Addr) +static inline void STY16() { - S9xSetWord(ICPU.Registers.Y.W, Addr); + S9xSetWord(ICPU.Registers.Y.W, OpAddress); } -static void STY8(int32_t Addr) +static inline void STY8() { - S9xSetByte(ICPU.Registers.YL, Addr); + S9xSetByte(ICPU.Registers.YL, OpAddress); } -static void STZ16(int32_t Addr) +static inline void STZ16() { - S9xSetWord(0, Addr); + S9xSetWord(0, OpAddress); } -static void STZ8(int32_t Addr) +static inline void STZ8() { - S9xSetByte(0, Addr); + S9xSetByte(0, OpAddress); } -static void TSB16(int32_t Addr) +static inline void TSB16() { - uint16_t Work16 = S9xGetWord(Addr); +#ifndef SA1_OPCODES + CPU.Cycles += ONE_CYCLE; +#endif + uint16_t Work16 = S9xGetWord(OpAddress); ICPU._Zero = (Work16 & ICPU.Registers.A.W) != 0; Work16 |= ICPU.Registers.A.W; - S9xSetByte(Work16 >> 8, Addr + 1); - S9xSetByte(Work16 & 0xFF, Addr); + S9xSetByte(Work16 >> 8, OpAddress + 1); + S9xSetByte(Work16 & 0xFF, OpAddress); } -static void TSB8(int32_t Addr) +static inline void TSB8() { - uint8_t Work8 = S9xGetByte(Addr); +#ifndef SA1_OPCODES + CPU.Cycles += ONE_CYCLE; +#endif + uint8_t Work8 = S9xGetByte(OpAddress); ICPU._Zero = Work8 & ICPU.Registers.AL; Work8 |= ICPU.Registers.AL; - S9xSetByte(Work8, Addr); + S9xSetByte(Work8, OpAddress); } -static void TRB16(int32_t Addr) +static inline void TRB16() { - uint16_t Work16 = S9xGetWord(Addr); +#ifndef SA1_OPCODES + CPU.Cycles += ONE_CYCLE; +#endif + uint16_t Work16 = S9xGetWord(OpAddress); ICPU._Zero = (Work16 & ICPU.Registers.A.W) != 0; Work16 &= ~ICPU.Registers.A.W; - S9xSetByte(Work16 >> 8, Addr + 1); - S9xSetByte(Work16 & 0xFF, Addr); + S9xSetByte(Work16 >> 8, OpAddress + 1); + S9xSetByte(Work16 & 0xFF, OpAddress); } -static void TRB8(int32_t Addr) +static inline void TRB8() { - uint8_t Work8 = S9xGetByte(Addr); +#ifndef SA1_OPCODES + CPU.Cycles += ONE_CYCLE; +#endif + uint8_t Work8 = S9xGetByte(OpAddress); ICPU._Zero = Work8 & ICPU.Registers.AL; Work8 &= ~ICPU.Registers.AL; - S9xSetByte(Work8, Addr); + S9xSetByte(Work8, OpAddress); } #endif diff --git a/source/cpuops.c b/source/cpuops.c index 2325255..0b92901 100644 --- a/source/cpuops.c +++ b/source/cpuops.c @@ -1,8 +1,8 @@ #include "../copyright" /*****************************************************************************/ -/* CPU-S9xOpcodes.CPP */ -/* This file contains all the opcodes */ +/* CPU-S9xOpcodes.CPP */ +/* This file contains all the opcodes */ /*****************************************************************************/ #include "snes9x.h" @@ -20,251 +20,191 @@ int32_t OpAddress; -// For use with the opcodes whose functions here examine the OpAddress. -static void OpAddressPassthrough(int32_t Addr) -{ - OpAddress = Addr; -} - /* ADC *************************************************************************************** */ -static void Op69M1(void) +static void Op69M1() { - Immediate8(READ, ADC8); + Immediate8(); + ADC8(); } -static void Op69M0(void) +static void Op69M0() { - Immediate16(READ, ADC16); + Immediate16(); + ADC16(); } -static void Op65M1(void) +static void Op65M1() { - Direct(READ, ADC8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + Direct(true); + ADC8(); } -static void Op65M0(void) +static void Op65M0() { - Direct(READ, ADC16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + Direct(true); + ADC16(); } -static void Op75M1(void) +static void Op75M1() { - DirectIndexedX(READ, ADC8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; -#endif + DirectIndexedX(true); + ADC8(); } -static void Op75M0(void) +static void Op75M0() { - DirectIndexedX(READ, ADC16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; -#endif + DirectIndexedX(true); + ADC16(); } -static void Op72M1(void) +static void Op72M1() { - DirectIndirect(READ, ADC8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirect(true); + ADC8(); } -static void Op72M0(void) +static void Op72M0() { - DirectIndirect(READ, ADC16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirect(true); + ADC16(); } -static void Op61M1(void) +static void Op61M1() { - DirectIndexedIndirect(READ, ADC8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndexedIndirect(true); + ADC8(); } -static void Op61M0(void) +static void Op61M0() { - DirectIndexedIndirect(READ, ADC16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndexedIndirect(true); + ADC16(); } -static void Op71M1(void) +static void Op71M1() { - DirectIndirectIndexed(READ, ADC8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirectIndexed(true); + ADC8(); } -static void Op71M0(void) +static void Op71M0() { - DirectIndirectIndexed(READ, ADC16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirectIndexed(true); + ADC16(); } -static void Op67M1(void) +static void Op67M1() { - DirectIndirectLong(READ, ADC8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirectLong(true); + ADC8(); } -static void Op67M0(void) +static void Op67M0() { - DirectIndirectLong(READ, ADC16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirectLong(true); + ADC16(); } -static void Op77M1(void) +static void Op77M1() { - DirectIndirectIndexedLong(READ, ADC8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirectIndexedLong(true); + ADC8(); } -static void Op77M0(void) +static void Op77M0() { - DirectIndirectIndexedLong(READ, ADC16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirectIndexedLong(true); + ADC16(); } -static void Op6DM1(void) +static void Op6DM1() { - Absolute(READ, ADC8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + Absolute(true); + ADC8(); } -static void Op6DM0(void) +static void Op6DM0() { - Absolute(READ, ADC16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + Absolute(true); + ADC16(); } -static void Op7DM1(void) +static void Op7DM1() { - AbsoluteIndexedX(READ, ADC8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + AbsoluteIndexedX(true); + ADC8(); } -static void Op7DM0(void) +static void Op7DM0() { - AbsoluteIndexedX(READ, ADC16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + AbsoluteIndexedX(true); + ADC16(); } -static void Op79M1(void) +static void Op79M1() { - AbsoluteIndexedY(READ, ADC8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + AbsoluteIndexedY(true); + ADC8(); } -static void Op79M0(void) +static void Op79M0() { - AbsoluteIndexedY(READ, ADC16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + AbsoluteIndexedY(true); + ADC16(); } -static void Op6FM1(void) +static void Op6FM1() { - AbsoluteLong(READ, ADC8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 + CPU.MemSpeed; -#endif + AbsoluteLong(true); + ADC8(); } -static void Op6FM0(void) +static void Op6FM0() { - AbsoluteLong(READ, ADC16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 + CPU.MemSpeed; -#endif + AbsoluteLong(true); + ADC16(); } -static void Op7FM1(void) +static void Op7FM1() { - AbsoluteLongIndexedX(READ, ADC8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 + CPU.MemSpeed; -#endif + AbsoluteLongIndexedX(true); + ADC8(); } -static void Op7FM0(void) +static void Op7FM0() { - AbsoluteLongIndexedX(READ, ADC16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 + CPU.MemSpeed; -#endif + AbsoluteLongIndexedX(true); + ADC16(); } -static void Op63M1(void) +static void Op63M1() { - StackRelative(READ, ADC8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; -#endif + StackRelative(true); + ADC8(); } -static void Op63M0(void) +static void Op63M0() { - StackRelative(READ, ADC16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; -#endif + StackRelative(true); + ADC16(); } -static void Op73M1(void) +static void Op73M1() { - StackRelativeIndirectIndexed(READ, ADC8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + TWO_CYCLES; -#endif + StackRelativeIndirectIndexed(true); + ADC8(); } -static void Op73M0(void) +static void Op73M0() { - StackRelativeIndirectIndexed(READ, ADC16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + TWO_CYCLES; -#endif + StackRelativeIndirectIndexed(true); + ADC16(); } /**********************************************************************************************/ /* AND *************************************************************************************** */ -static void Op29M1(void) +static void Op29M1() { ICPU.Registers.AL &= *CPU.PC++; #ifndef SA1_OPCODES @@ -273,7 +213,7 @@ static void Op29M1(void) SetZN8(ICPU.Registers.AL); } -static void Op29M0(void) +static void Op29M0() { #ifdef FAST_LSB_WORD_ACCESS ICPU.Registers.A.W &= *(uint16_t*) CPU.PC; @@ -287,309 +227,237 @@ static void Op29M0(void) SetZN16(ICPU.Registers.A.W); } -static void Op25M1(void) +static void Op25M1() { - Direct(READ, AND8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + Direct(true); + AND8(); } -static void Op25M0(void) +static void Op25M0() { - Direct(READ, AND16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + Direct(true); + AND16(); } -static void Op35M1(void) +static void Op35M1() { - DirectIndexedX(READ, AND8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; -#endif + DirectIndexedX(true); + AND8(); } -static void Op35M0(void) +static void Op35M0() { - DirectIndexedX(READ, AND16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; -#endif + DirectIndexedX(true); + AND16(); } -static void Op32M1(void) +static void Op32M1() { - DirectIndirect(READ, AND8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirect(true); + AND8(); } -static void Op32M0(void) +static void Op32M0() { - DirectIndirect(READ, AND16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirect(true); + AND16(); } -static void Op21M1(void) +static void Op21M1() { - DirectIndexedIndirect(READ, AND8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndexedIndirect(true); + AND8(); } -static void Op21M0(void) +static void Op21M0() { - DirectIndexedIndirect(READ, AND16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndexedIndirect(true); + AND16(); } -static void Op31M1(void) +static void Op31M1() { - DirectIndirectIndexed(READ, AND8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirectIndexed(true); + AND8(); } -static void Op31M0(void) +static void Op31M0() { - DirectIndirectIndexed(READ, AND16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirectIndexed(true); + AND16(); } -static void Op27M1(void) +static void Op27M1() { - DirectIndirectLong(READ, AND8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirectLong(true); + AND8(); } -static void Op27M0(void) +static void Op27M0() { - DirectIndirectLong(READ, AND16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirectLong(true); + AND16(); } -static void Op37M1(void) +static void Op37M1() { - DirectIndirectIndexedLong(READ, AND8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirectIndexedLong(true); + AND8(); } -static void Op37M0(void) +static void Op37M0() { - DirectIndirectIndexedLong(READ, AND16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirectIndexedLong(true); + AND16(); } -static void Op2DM1(void) +static void Op2DM1() { - Absolute(READ, AND8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + Absolute(true); + AND8(); } -static void Op2DM0(void) +static void Op2DM0() { - Absolute(READ, AND16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + Absolute(true); + AND16(); } -static void Op3DM1(void) +static void Op3DM1() { - AbsoluteIndexedX(READ, AND8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + AbsoluteIndexedX(true); + AND8(); } -static void Op3DM0(void) +static void Op3DM0() { - AbsoluteIndexedX(READ, AND16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + AbsoluteIndexedX(true); + AND16(); } -static void Op39M1(void) +static void Op39M1() { - AbsoluteIndexedY(READ, AND8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + AbsoluteIndexedY(true); + AND8(); } -static void Op39M0(void) +static void Op39M0() { - AbsoluteIndexedY(READ, AND16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + AbsoluteIndexedY(true); + AND16(); } -static void Op2FM1(void) +static void Op2FM1() { - AbsoluteLong(READ, AND8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 + CPU.MemSpeed; -#endif + AbsoluteLong(true); + AND8(); } -static void Op2FM0(void) +static void Op2FM0() { - AbsoluteLong(READ, AND16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 + CPU.MemSpeed; -#endif + AbsoluteLong(true); + AND16(); } -static void Op3FM1(void) +static void Op3FM1() { - AbsoluteLongIndexedX(READ, AND8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 + CPU.MemSpeed; -#endif + AbsoluteLongIndexedX(true); + AND8(); } -static void Op3FM0(void) +static void Op3FM0() { - AbsoluteLongIndexedX(READ, AND16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 + CPU.MemSpeed; -#endif + AbsoluteLongIndexedX(true); + AND16(); } -static void Op23M1(void) +static void Op23M1() { - StackRelative(READ, AND8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; -#endif + StackRelative(true); + AND8(); } -static void Op23M0(void) +static void Op23M0() { - StackRelative(READ, AND16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; -#endif + StackRelative(true); + AND16(); } -static void Op33M1(void) +static void Op33M1() { - StackRelativeIndirectIndexed(READ, AND8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + TWO_CYCLES; -#endif + StackRelativeIndirectIndexed(true); + AND8(); } -static void Op33M0(void) +static void Op33M0() { - StackRelativeIndirectIndexed(READ, AND16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + TWO_CYCLES; -#endif + StackRelativeIndirectIndexed(true); + AND16(); } /**********************************************************************************************/ /* ASL *************************************************************************************** */ -static void Op0AM1(void) +static void Op0AM1() { A_ASL8(); } -static void Op0AM0(void) +static void Op0AM0() { A_ASL16(); } -static void Op06M1(void) +static void Op06M1() { - Direct(MODIFY, ASL8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed /* memory */ + ONE_CYCLE /* opcode */; -#endif + Direct(false); + ASL8(); } -static void Op06M0(void) +static void Op06M0() { - Direct(MODIFY, ASL16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed /* memory */ + ONE_CYCLE /* opcode */; -#endif + Direct(false); + ASL16(); } -static void Op16M1(void) +static void Op16M1() { - DirectIndexedX(MODIFY, ASL8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE /* memory */ + ONE_CYCLE /* opcode */; -#endif + DirectIndexedX(false); + ASL8(); } -static void Op16M0(void) +static void Op16M0() { - DirectIndexedX(MODIFY, ASL16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE /* memory */ + ONE_CYCLE /* opcode */; -#endif + DirectIndexedX(false); + ASL16(); } -static void Op0EM1(void) +static void Op0EM1() { - Absolute(MODIFY, ASL8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 /* memory */ + ONE_CYCLE /* opcode */; -#endif + Absolute(false); + ASL8(); } -static void Op0EM0(void) +static void Op0EM0() { - Absolute(MODIFY, ASL16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 /* memory */ + ONE_CYCLE /* opcode */; -#endif + Absolute(false); + ASL16(); } -static void Op1EM1(void) +static void Op1EM1() { - AbsoluteIndexedX(MODIFY, ASL8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 /* memory */ + ONE_CYCLE /* opcode */; -#endif + AbsoluteIndexedX(false); + ASL8(); } -static void Op1EM0(void) +static void Op1EM0() { - AbsoluteIndexedX(MODIFY, ASL16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 /* memory */ + ONE_CYCLE /* opcode */; -#endif + AbsoluteIndexedX(false); + ASL16(); } /**********************************************************************************************/ /* BIT *************************************************************************************** */ -static void Op89M1(void) +static void Op89M1() { ICPU._Zero = ICPU.Registers.AL & *CPU.PC++; #ifndef SA1_OPCODES @@ -597,7 +465,7 @@ static void Op89M1(void) #endif } -static void Op89M0(void) +static void Op89M0() { #ifdef FAST_LSB_WORD_ACCESS ICPU._Zero = (ICPU.Registers.A.W & *(uint16_t*) CPU.PC) != 0; @@ -610,73 +478,57 @@ static void Op89M0(void) CPU.PC += 2; } -static void Op24M1(void) +static void Op24M1() { - Direct(READ, BIT8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + Direct(true); + BIT8(); } -static void Op24M0(void) +static void Op24M0() { - Direct(READ, BIT16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + Direct(true); + BIT16(); } -static void Op34M1(void) +static void Op34M1() { - DirectIndexedX(READ, BIT8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; -#endif + DirectIndexedX(true); + BIT8(); } -static void Op34M0(void) +static void Op34M0() { - DirectIndexedX(READ, BIT16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; -#endif + DirectIndexedX(true); + BIT16(); } -static void Op2CM1(void) +static void Op2CM1() { - Absolute(READ, BIT8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + Absolute(true); + BIT8(); } -static void Op2CM0(void) +static void Op2CM0() { - Absolute(READ, BIT16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + Absolute(true); + BIT16(); } -static void Op3CM1(void) +static void Op3CM1() { - AbsoluteIndexedX(READ, BIT8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + AbsoluteIndexedX(true); + BIT8(); } -static void Op3CM0(void) +static void Op3CM0() { - AbsoluteIndexedX(READ, BIT16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + AbsoluteIndexedX(true); + BIT16(); } /**********************************************************************************************/ /* CMP *************************************************************************************** */ -static void OpC9M1(void) +static void OpC9M1() { int32_t Int32 = (int32_t) ICPU.Registers.AL - (int32_t) *CPU.PC++; ICPU._Carry = Int32 >= 0; @@ -686,13 +538,12 @@ static void OpC9M1(void) #endif } -static void OpC9M0(void) +static void OpC9M0() { - int32_t Int32; #ifdef FAST_LSB_WORD_ACCESS - Int32 = (int32_t) ICPU.Registers.A.W - (int32_t) *(uint16_t*)CPU.PC; + int32_t Int32 = (int32_t) ICPU.Registers.A.W - (int32_t) *(uint16_t*)CPU.PC; #else - Int32 = (int32_t) ICPU.Registers.A.W - (int32_t)(*CPU.PC + (*(CPU.PC + 1) << 8)); + int32_t Int32 = (int32_t) ICPU.Registers.A.W - (int32_t)(*CPU.PC + (*(CPU.PC + 1) << 8)); #endif ICPU._Carry = Int32 >= 0; SetZN16((uint16_t) Int32); @@ -702,234 +553,178 @@ static void OpC9M0(void) #endif } -static void OpC5M1(void) +static void OpC5M1() { - Direct(READ, CMP8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + Direct(true); + CMP8(); } -static void OpC5M0(void) +static void OpC5M0() { - Direct(READ, CMP16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + Direct(true); + CMP16(); } -static void OpD5M1(void) +static void OpD5M1() { - DirectIndexedX(READ, CMP8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; -#endif + DirectIndexedX(true); + CMP8(); } -static void OpD5M0(void) +static void OpD5M0() { - DirectIndexedX(READ, CMP16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; -#endif + DirectIndexedX(true); + CMP16(); } -static void OpD2M1(void) +static void OpD2M1() { - DirectIndirect(READ, CMP8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirect(true); + CMP8(); } -static void OpD2M0(void) +static void OpD2M0() { - DirectIndirect(READ, CMP16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirect(true); + CMP16(); } -static void OpC1M1(void) +static void OpC1M1() { - DirectIndexedIndirect(READ, CMP8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndexedIndirect(true); + CMP8(); } -static void OpC1M0(void) +static void OpC1M0() { - DirectIndexedIndirect(READ, CMP16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndexedIndirect(true); + CMP16(); } -static void OpD1M1(void) +static void OpD1M1() { - DirectIndirectIndexed(READ, CMP8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirectIndexed(true); + CMP8(); } -static void OpD1M0(void) +static void OpD1M0() { - DirectIndirectIndexed(READ, CMP16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirectIndexed(true); + CMP16(); } -static void OpC7M1(void) +static void OpC7M1() { - DirectIndirectLong(READ, CMP8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirectLong(true); + CMP8(); } -static void OpC7M0(void) +static void OpC7M0() { - DirectIndirectLong(READ, CMP16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirectLong(true); + CMP16(); } -static void OpD7M1(void) +static void OpD7M1() { - DirectIndirectIndexedLong(READ, CMP8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirectIndexedLong(true); + CMP8(); } -static void OpD7M0(void) +static void OpD7M0() { - DirectIndirectIndexedLong(READ, CMP16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirectIndexedLong(true); + CMP16(); } -static void OpCDM1(void) +static void OpCDM1() { - Absolute(READ, CMP8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + Absolute(true); + CMP8(); } -static void OpCDM0(void) +static void OpCDM0() { - Absolute(READ, CMP16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + Absolute(true); + CMP16(); } -static void OpDDM1(void) +static void OpDDM1() { - AbsoluteIndexedX(READ, CMP8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + AbsoluteIndexedX(true); + CMP8(); } -static void OpDDM0(void) +static void OpDDM0() { - AbsoluteIndexedX(READ, CMP16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + AbsoluteIndexedX(true); + CMP16(); } -static void OpD9M1(void) +static void OpD9M1() { - AbsoluteIndexedY(READ, CMP8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + AbsoluteIndexedY(true); + CMP8(); } -static void OpD9M0(void) +static void OpD9M0() { - AbsoluteIndexedY(READ, CMP16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + AbsoluteIndexedY(true); + CMP16(); } -static void OpCFM1(void) +static void OpCFM1() { - AbsoluteLong(READ, CMP8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 + CPU.MemSpeed; -#endif + AbsoluteLong(true); + CMP8(); } -static void OpCFM0(void) +static void OpCFM0() { - AbsoluteLong(READ, CMP16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 + CPU.MemSpeed; -#endif + AbsoluteLong(true); + CMP16(); } -static void OpDFM1(void) +static void OpDFM1() { - AbsoluteLongIndexedX(READ, CMP8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 + CPU.MemSpeed; -#endif + AbsoluteLongIndexedX(true); + CMP8(); } -static void OpDFM0(void) +static void OpDFM0() { - AbsoluteLongIndexedX(READ, CMP16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 + CPU.MemSpeed; -#endif + AbsoluteLongIndexedX(true); + CMP16(); } -static void OpC3M1(void) +static void OpC3M1() { - StackRelative(READ, CMP8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; -#endif + StackRelative(true); + CMP8(); } -static void OpC3M0(void) +static void OpC3M0() { - StackRelative(READ, CMP16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; -#endif + StackRelative(true); + CMP16(); } -static void OpD3M1(void) +static void OpD3M1() { - StackRelativeIndirectIndexed(READ, CMP8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + TWO_CYCLES; -#endif + StackRelativeIndirectIndexed(true); + CMP8(); } -static void OpD3M0(void) +static void OpD3M0() { - StackRelativeIndirectIndexed(READ, CMP16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + TWO_CYCLES; -#endif + StackRelativeIndirectIndexed(true); + CMP16(); } /**********************************************************************************************/ /* CMX *************************************************************************************** */ -static void OpE0X1(void) +static void OpE0X1() { int32_t Int32 = (int32_t) ICPU.Registers.XL - (int32_t) *CPU.PC++; ICPU._Carry = Int32 >= 0; @@ -939,13 +734,12 @@ static void OpE0X1(void) #endif } -static void OpE0X0(void) +static void OpE0X0() { - int32_t Int32; #ifdef FAST_LSB_WORD_ACCESS - Int32 = (int32_t) ICPU.Registers.X.W - (int32_t) *(uint16_t*)CPU.PC; + int32_t Int32 = (int32_t) ICPU.Registers.X.W - (int32_t) *(uint16_t*)CPU.PC; #else - Int32 = (int32_t) ICPU.Registers.X.W - (int32_t)(*CPU.PC + (*(CPU.PC + 1) << 8)); + int32_t Int32 = (int32_t) ICPU.Registers.X.W - (int32_t)(*CPU.PC + (*(CPU.PC + 1) << 8)); #endif ICPU._Carry = Int32 >= 0; SetZN16((uint16_t) Int32); @@ -955,42 +749,34 @@ static void OpE0X0(void) #endif } -static void OpE4X1(void) +static void OpE4X1() { - Direct(READ, CMX8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + Direct(true); + CMX8(); } -static void OpE4X0(void) +static void OpE4X0() { - Direct(READ, CMX16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + Direct(true); + CMX16(); } -static void OpECX1(void) +static void OpECX1() { - Absolute(READ, CMX8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + Absolute(true); + CMX8(); } -static void OpECX0(void) +static void OpECX0() { - Absolute(READ, CMX16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + Absolute(true); + CMX16(); } /**********************************************************************************************/ /* CMY *************************************************************************************** */ -static void OpC0X1(void) +static void OpC0X1() { int32_t Int32 = (int32_t) ICPU.Registers.YL - (int32_t) *CPU.PC++; ICPU._Carry = Int32 >= 0; @@ -1000,13 +786,12 @@ static void OpC0X1(void) #endif } -static void OpC0X0(void) +static void OpC0X0() { - int32_t Int32; #ifdef FAST_LSB_WORD_ACCESS - Int32 = (int32_t) ICPU.Registers.Y.W - (int32_t) *(uint16_t*)CPU.PC; + int32_t Int32 = (int32_t) ICPU.Registers.Y.W - (int32_t) *(uint16_t*)CPU.PC; #else - Int32 = (int32_t) ICPU.Registers.Y.W - (int32_t)(*CPU.PC + (*(CPU.PC + 1) << 8)); + int32_t Int32 = (int32_t) ICPU.Registers.Y.W - (int32_t)(*CPU.PC + (*(CPU.PC + 1) << 8)); #endif ICPU._Carry = Int32 >= 0; SetZN16((uint16_t) Int32); @@ -1016,119 +801,95 @@ static void OpC0X0(void) #endif } -static void OpC4X1(void) +static void OpC4X1() { - Direct(READ, CMY8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + Direct(true); + CMY8(); } -static void OpC4X0(void) +static void OpC4X0() { - Direct(READ, CMY16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + Direct(true); + CMY16(); } -static void OpCCX1(void) +static void OpCCX1() { - Absolute(READ, CMY8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + Absolute(true); + CMY8(); } -static void OpCCX0(void) +static void OpCCX0() { - Absolute(READ, CMY16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + Absolute(true); + CMY16(); } /**********************************************************************************************/ /* DEC *************************************************************************************** */ -static void Op3AM1(void) +static void Op3AM1() { A_DEC8(); } -static void Op3AM0(void) +static void Op3AM0() { A_DEC16(); } -static void OpC6M1(void) +static void OpC6M1() { - Direct(MODIFY, DEC8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed /* memory */ + ONE_CYCLE /* opcode */; -#endif + Direct(false); + DEC8(); } -static void OpC6M0(void) +static void OpC6M0() { - Direct(MODIFY, DEC16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed /* memory */ + ONE_CYCLE /* opcode */; -#endif + Direct(false); + DEC16(); } -static void OpD6M1(void) +static void OpD6M1() { - DirectIndexedX(MODIFY, DEC8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE /* memory */ + ONE_CYCLE /* opcode */; -#endif + DirectIndexedX(false); + DEC8(); } -static void OpD6M0(void) +static void OpD6M0() { - DirectIndexedX(MODIFY, DEC16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE /* memory */ + ONE_CYCLE /* opcode */; -#endif + DirectIndexedX(false); + DEC16(); } -static void OpCEM1(void) +static void OpCEM1() { - Absolute(MODIFY, DEC8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 /* memory */ + ONE_CYCLE /* opcode */; -#endif + Absolute(false); + DEC8(); } -static void OpCEM0(void) +static void OpCEM0() { - Absolute(MODIFY, DEC16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 /* memory */ + ONE_CYCLE /* opcode */; -#endif + Absolute(false); + DEC16(); } -static void OpDEM1(void) +static void OpDEM1() { - AbsoluteIndexedX(MODIFY, DEC8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 /* memory */ + ONE_CYCLE /* opcode */; -#endif + AbsoluteIndexedX(false); + DEC8(); } -static void OpDEM0(void) +static void OpDEM0() { - AbsoluteIndexedX(MODIFY, DEC16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 /* memory */ + ONE_CYCLE /* opcode */; -#endif + AbsoluteIndexedX(false); + DEC16(); } /**********************************************************************************************/ /* EOR *************************************************************************************** */ -static void Op49M1(void) +static void Op49M1() { ICPU.Registers.AL ^= *CPU.PC++; #ifndef SA1_OPCODES @@ -1137,7 +898,7 @@ static void Op49M1(void) SetZN8(ICPU.Registers.AL); } -static void Op49M0(void) +static void Op49M0() { #ifdef FAST_LSB_WORD_ACCESS ICPU.Registers.A.W ^= *(uint16_t*) CPU.PC; @@ -1151,310 +912,238 @@ static void Op49M0(void) SetZN16(ICPU.Registers.A.W); } -static void Op45M1(void) +static void Op45M1() { - Direct(READ, EOR8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + Direct(true); + EOR8(); } -static void Op45M0(void) +static void Op45M0() { - Direct(READ, EOR16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + Direct(true); + EOR16(); } -static void Op55M1(void) +static void Op55M1() { - DirectIndexedX(READ, EOR8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; -#endif + DirectIndexedX(true); + EOR8(); } -static void Op55M0(void) +static void Op55M0() { - DirectIndexedX(READ, EOR16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; -#endif + DirectIndexedX(true); + EOR16(); } -static void Op52M1(void) +static void Op52M1() { - DirectIndirect(READ, EOR8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirect(true); + EOR8(); } -static void Op52M0(void) +static void Op52M0() { - DirectIndirect(READ, EOR16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirect(true); + EOR16(); } -static void Op41M1(void) +static void Op41M1() { - DirectIndexedIndirect(READ, EOR8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndexedIndirect(true); + EOR8(); } -static void Op41M0(void) +static void Op41M0() { - DirectIndexedIndirect(READ, EOR16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndexedIndirect(true); + EOR16(); } -static void Op51M1(void) +static void Op51M1() { - DirectIndirectIndexed(READ, EOR8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirectIndexed(true); + EOR8(); } -static void Op51M0(void) +static void Op51M0() { - DirectIndirectIndexed(READ, EOR16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirectIndexed(true); + EOR16(); } -static void Op47M1(void) +static void Op47M1() { - DirectIndirectLong(READ, EOR8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirectLong(true); + EOR8(); } -static void Op47M0(void) +static void Op47M0() { - DirectIndirectLong(READ, EOR16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirectLong(true); + EOR16(); } -static void Op57M1(void) +static void Op57M1() { - DirectIndirectIndexedLong(READ, EOR8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirectIndexedLong(true); + EOR8(); } -static void Op57M0(void) +static void Op57M0() { - DirectIndirectIndexedLong(READ, EOR16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirectIndexedLong(true); + EOR16(); } -static void Op4DM1(void) +static void Op4DM1() { - Absolute(READ, EOR8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + Absolute(true); + EOR8(); } -static void Op4DM0(void) +static void Op4DM0() { - Absolute(READ, EOR16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + Absolute(true); + EOR16(); } -static void Op5DM1(void) +static void Op5DM1() { - AbsoluteIndexedX(READ, EOR8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + AbsoluteIndexedX(true); + EOR8(); } -static void Op5DM0(void) +static void Op5DM0() { - AbsoluteIndexedX(READ, EOR16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + AbsoluteIndexedX(true); + EOR16(); } -static void Op59M1(void) +static void Op59M1() { - AbsoluteIndexedY(READ, EOR8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + AbsoluteIndexedY(true); + EOR8(); } -static void Op59M0(void) +static void Op59M0() { - AbsoluteIndexedY(READ, EOR16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + AbsoluteIndexedY(true); + EOR16(); } -static void Op4FM1(void) +static void Op4FM1() { - AbsoluteLong(READ, EOR8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 + CPU.MemSpeed; -#endif + AbsoluteLong(true); + EOR8(); } -static void Op4FM0(void) +static void Op4FM0() { - AbsoluteLong(READ, EOR16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 + CPU.MemSpeed; -#endif + AbsoluteLong(true); + EOR16(); } -static void Op5FM1(void) +static void Op5FM1() { - AbsoluteLongIndexedX(READ, EOR8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 + CPU.MemSpeed; -#endif + AbsoluteLongIndexedX(true); + EOR8(); } -static void Op5FM0(void) +static void Op5FM0() { - AbsoluteLongIndexedX(READ, EOR16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 + CPU.MemSpeed; -#endif + AbsoluteLongIndexedX(true); + EOR16(); } -static void Op43M1(void) +static void Op43M1() { - StackRelative(READ, EOR8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; -#endif + StackRelative(true); + EOR8(); } -static void Op43M0(void) +static void Op43M0() { - StackRelative(READ, EOR16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; -#endif + StackRelative(true); + EOR16(); } -static void Op53M1(void) +static void Op53M1() { - StackRelativeIndirectIndexed(READ, EOR8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + TWO_CYCLES; -#endif + StackRelativeIndirectIndexed(true); + EOR8(); } -static void Op53M0(void) +static void Op53M0() { - StackRelativeIndirectIndexed(READ, EOR16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + TWO_CYCLES; -#endif + StackRelativeIndirectIndexed(true); + EOR16(); } /**********************************************************************************************/ /* INC *************************************************************************************** */ -static void Op1AM1(void) +static void Op1AM1() { A_INC8(); } -static void Op1AM0(void) +static void Op1AM0() { A_INC16(); } -static void OpE6M1(void) +static void OpE6M1() { - Direct(MODIFY, INC8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed /* memory */ + ONE_CYCLE /* opcode */; -#endif + Direct(false); + INC8(); } -static void OpE6M0(void) +static void OpE6M0() { - Direct(MODIFY, INC16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed /* memory */ + ONE_CYCLE /* opcode */; -#endif + Direct(false); + INC16(); } -static void OpF6M1(void) +static void OpF6M1() { - DirectIndexedX(MODIFY, INC8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE /* memory */ + ONE_CYCLE /* opcode */; -#endif + DirectIndexedX(false); + INC8(); } -static void OpF6M0(void) +static void OpF6M0() { - DirectIndexedX(MODIFY, INC16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE /* memory */ + ONE_CYCLE /* opcode */; -#endif + DirectIndexedX(false); + INC16(); } -static void OpEEM1(void) +static void OpEEM1() { - Absolute(MODIFY, INC8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 /* memory */ + ONE_CYCLE /* opcode */; -#endif + Absolute(false); + INC8(); } -static void OpEEM0(void) +static void OpEEM0() { - Absolute(MODIFY, INC16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 /* memory */ + ONE_CYCLE /* opcode */; -#endif + Absolute(false); + INC16(); } -static void OpFEM1(void) +static void OpFEM1() { - AbsoluteIndexedX(MODIFY, INC8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 /* memory */ + ONE_CYCLE /* opcode */; -#endif + AbsoluteIndexedX(false); + INC8(); } -static void OpFEM0(void) +static void OpFEM0() { - AbsoluteIndexedX(MODIFY, INC16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 /* memory */ + ONE_CYCLE /* opcode */; -#endif + AbsoluteIndexedX(false); + INC16(); } /**********************************************************************************************/ /* LDA *************************************************************************************** */ -static void OpA9M1(void) +static void OpA9M1() { ICPU.Registers.AL = *CPU.PC++; #ifndef SA1_OPCODES @@ -1463,7 +1152,7 @@ static void OpA9M1(void) SetZN8(ICPU.Registers.AL); } -static void OpA9M0(void) +static void OpA9M0() { #ifdef FAST_LSB_WORD_ACCESS ICPU.Registers.A.W = *(uint16_t*) CPU.PC; @@ -1478,234 +1167,178 @@ static void OpA9M0(void) SetZN16(ICPU.Registers.A.W); } -static void OpA5M1(void) +static void OpA5M1() { - Direct(READ, LDA8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + Direct(true); + LDA8(); } -static void OpA5M0(void) +static void OpA5M0() { - Direct(READ, LDA16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + Direct(true); + LDA16(); } -static void OpB5M1(void) +static void OpB5M1() { - DirectIndexedX(READ, LDA8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; -#endif + DirectIndexedX(true); + LDA8(); } -static void OpB5M0(void) +static void OpB5M0() { - DirectIndexedX(READ, LDA16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; -#endif + DirectIndexedX(true); + LDA16(); } -static void OpB2M1(void) +static void OpB2M1() { - DirectIndirect(READ, LDA8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirect(true); + LDA8(); } -static void OpB2M0(void) +static void OpB2M0() { - DirectIndirect(READ, LDA16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirect(true); + LDA16(); } -static void OpA1M1(void) +static void OpA1M1() { - DirectIndexedIndirect(READ, LDA8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndexedIndirect(true); + LDA8(); } -static void OpA1M0(void) +static void OpA1M0() { - DirectIndexedIndirect(READ, LDA16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndexedIndirect(true); + LDA16(); } -static void OpB1M1(void) +static void OpB1M1() { - DirectIndirectIndexed(READ, LDA8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirectIndexed(true); + LDA8(); } -static void OpB1M0(void) +static void OpB1M0() { - DirectIndirectIndexed(READ, LDA16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirectIndexed(true); + LDA16(); } -static void OpA7M1(void) +static void OpA7M1() { - DirectIndirectLong(READ, LDA8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirectLong(true); + LDA8(); } -static void OpA7M0(void) +static void OpA7M0() { - DirectIndirectLong(READ, LDA16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirectLong(true); + LDA16(); } -static void OpB7M1(void) +static void OpB7M1() { - DirectIndirectIndexedLong(READ, LDA8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirectIndexedLong(true); + LDA8(); } -static void OpB7M0(void) +static void OpB7M0() { - DirectIndirectIndexedLong(READ, LDA16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirectIndexedLong(true); + LDA16(); } -static void OpADM1(void) +static void OpADM1() { - Absolute(READ, LDA8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + Absolute(true); + LDA8(); } -static void OpADM0(void) +static void OpADM0() { - Absolute(READ, LDA16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + Absolute(true); + LDA16(); } -static void OpBDM1(void) +static void OpBDM1() { - AbsoluteIndexedX(READ, LDA8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + AbsoluteIndexedX(true); + LDA8(); } -static void OpBDM0(void) +static void OpBDM0() { - AbsoluteIndexedX(READ, LDA16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + AbsoluteIndexedX(true); + LDA16(); } -static void OpB9M1(void) +static void OpB9M1() { - AbsoluteIndexedY(READ, LDA8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + AbsoluteIndexedY(true); + LDA8(); } -static void OpB9M0(void) +static void OpB9M0() { - AbsoluteIndexedY(READ, LDA16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + AbsoluteIndexedY(true); + LDA16(); } -static void OpAFM1(void) +static void OpAFM1() { - AbsoluteLong(READ, LDA8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 + CPU.MemSpeed; -#endif + AbsoluteLong(true); + LDA8(); } -static void OpAFM0(void) +static void OpAFM0() { - AbsoluteLong(READ, LDA16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 + CPU.MemSpeed; -#endif + AbsoluteLong(true); + LDA16(); } -static void OpBFM1(void) +static void OpBFM1() { - AbsoluteLongIndexedX(READ, LDA8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 + CPU.MemSpeed; -#endif + AbsoluteLongIndexedX(true); + LDA8(); } -static void OpBFM0(void) +static void OpBFM0() { - AbsoluteLongIndexedX(READ, LDA16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 + CPU.MemSpeed; -#endif + AbsoluteLongIndexedX(true); + LDA16(); } -static void OpA3M1(void) +static void OpA3M1() { - StackRelative(READ, LDA8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; -#endif + StackRelative(true); + LDA8(); } -static void OpA3M0(void) +static void OpA3M0() { - StackRelative(READ, LDA16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; -#endif + StackRelative(true); + LDA16(); } -static void OpB3M1(void) +static void OpB3M1() { - StackRelativeIndirectIndexed(READ, LDA8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + TWO_CYCLES; -#endif + StackRelativeIndirectIndexed(true); + LDA8(); } -static void OpB3M0(void) +static void OpB3M0() { - StackRelativeIndirectIndexed(READ, LDA16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + TWO_CYCLES; -#endif + StackRelativeIndirectIndexed(true); + LDA16(); } /**********************************************************************************************/ /* LDX *************************************************************************************** */ -static void OpA2X1(void) +static void OpA2X1() { ICPU.Registers.XL = *CPU.PC++; #ifndef SA1_OPCODES @@ -1714,7 +1347,7 @@ static void OpA2X1(void) SetZN8(ICPU.Registers.XL); } -static void OpA2X0(void) +static void OpA2X0() { #ifdef FAST_LSB_WORD_ACCESS ICPU.Registers.X.W = *(uint16_t*) CPU.PC; @@ -1728,73 +1361,57 @@ static void OpA2X0(void) SetZN16(ICPU.Registers.X.W); } -static void OpA6X1(void) +static void OpA6X1() { - Direct(READ, LDX8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + Direct(true); + LDX8(); } -static void OpA6X0(void) +static void OpA6X0() { - Direct(READ, LDX16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + Direct(true); + LDX16(); } -static void OpB6X1(void) +static void OpB6X1() { - DirectIndexedY(READ, LDX8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; -#endif + DirectIndexedY(true); + LDX8(); } -static void OpB6X0(void) +static void OpB6X0() { - DirectIndexedY(READ, LDX16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; -#endif + DirectIndexedY(true); + LDX16(); } -static void OpAEX1(void) +static void OpAEX1() { - Absolute(READ, LDX8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + Absolute(true); + LDX8(); } -static void OpAEX0(void) +static void OpAEX0() { - Absolute(READ, LDX16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + Absolute(true); + LDX16(); } -static void OpBEX1(void) +static void OpBEX1() { - AbsoluteIndexedY(READ, LDX8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + AbsoluteIndexedY(true); + LDX8(); } -static void OpBEX0(void) +static void OpBEX0() { - AbsoluteIndexedY(READ, LDX16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + AbsoluteIndexedY(true); + LDX16(); } /**********************************************************************************************/ /* LDY *************************************************************************************** */ -static void OpA0X1(void) +static void OpA0X1() { ICPU.Registers.YL = *CPU.PC++; #ifndef SA1_OPCODES @@ -1803,7 +1420,7 @@ static void OpA0X1(void) SetZN8(ICPU.Registers.YL); } -static void OpA0X0(void) +static void OpA0X0() { #ifdef FAST_LSB_WORD_ACCESS ICPU.Registers.Y.W = *(uint16_t*) CPU.PC; @@ -1818,150 +1435,118 @@ static void OpA0X0(void) SetZN16(ICPU.Registers.Y.W); } -static void OpA4X1(void) +static void OpA4X1() { - Direct(READ, LDY8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + Direct(true); + LDY8(); } -static void OpA4X0(void) +static void OpA4X0() { - Direct(READ, LDY16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + Direct(true); + LDY16(); } -static void OpB4X1(void) +static void OpB4X1() { - DirectIndexedX(READ, LDY8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; -#endif + DirectIndexedX(true); + LDY8(); } -static void OpB4X0(void) +static void OpB4X0() { - DirectIndexedX(READ, LDY16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; -#endif + DirectIndexedX(true); + LDY16(); } -static void OpACX1(void) +static void OpACX1() { - Absolute(READ, LDY8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + Absolute(true); + LDY8(); } -static void OpACX0(void) +static void OpACX0() { - Absolute(READ, LDY16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + Absolute(true); + LDY16(); } -static void OpBCX1(void) +static void OpBCX1() { - AbsoluteIndexedX(READ, LDY8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + AbsoluteIndexedX(true); + LDY8(); } -static void OpBCX0(void) +static void OpBCX0() { - AbsoluteIndexedX(READ, LDY16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + AbsoluteIndexedX(true); + LDY16(); } /**********************************************************************************************/ /* LSR *************************************************************************************** */ -static void Op4AM1(void) +static void Op4AM1() { A_LSR8(); } -static void Op4AM0(void) +static void Op4AM0() { A_LSR16(); } -static void Op46M1(void) +static void Op46M1() { - Direct(MODIFY, LSR8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed /* memory */ + ONE_CYCLE /* opcode */; -#endif + Direct(false); + LSR8(); } -static void Op46M0(void) +static void Op46M0() { - Direct(MODIFY, LSR16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed /* memory */ + ONE_CYCLE /* opcode */; -#endif + Direct(false); + LSR16(); } -static void Op56M1(void) +static void Op56M1() { - DirectIndexedX(MODIFY, LSR8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE /* memory */ + ONE_CYCLE /* opcode */; -#endif + DirectIndexedX(false); + LSR8(); } -static void Op56M0(void) +static void Op56M0() { - DirectIndexedX(MODIFY, LSR16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE /* memory */ + ONE_CYCLE /* opcode */; -#endif + DirectIndexedX(false); + LSR16(); } -static void Op4EM1(void) +static void Op4EM1() { - Absolute(MODIFY, LSR8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 /* memory */ + ONE_CYCLE /* opcode */; -#endif + Absolute(false); + LSR8(); } -static void Op4EM0(void) +static void Op4EM0() { - Absolute(MODIFY, LSR16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 /* memory */ + ONE_CYCLE /* opcode */; -#endif + Absolute(false); + LSR16(); } -static void Op5EM1(void) +static void Op5EM1() { - AbsoluteIndexedX(MODIFY, LSR8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 /* memory */ + ONE_CYCLE /* opcode */; -#endif + AbsoluteIndexedX(false); + LSR8(); } -static void Op5EM0(void) +static void Op5EM0() { - AbsoluteIndexedX(MODIFY, LSR16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 /* memory */ + ONE_CYCLE /* opcode */; -#endif + AbsoluteIndexedX(false); + LSR16(); } /**********************************************************************************************/ /* ORA *************************************************************************************** */ -static void Op09M1(void) +static void Op09M1() { ICPU.Registers.AL |= *CPU.PC++; #ifndef SA1_OPCODES @@ -1970,7 +1555,7 @@ static void Op09M1(void) SetZN8(ICPU.Registers.AL); } -static void Op09M0(void) +static void Op09M0() { #ifdef FAST_LSB_WORD_ACCESS ICPU.Registers.A.W |= *(uint16_t*) CPU.PC; @@ -1984,1086 +1569,832 @@ static void Op09M0(void) SetZN16(ICPU.Registers.A.W); } -static void Op05M1(void) +static void Op05M1() { - Direct(READ, ORA8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + Direct(true); + ORA8(); } -static void Op05M0(void) +static void Op05M0() { - Direct(READ, ORA16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + Direct(true); + ORA16(); } -static void Op15M1(void) +static void Op15M1() { - DirectIndexedX(READ, ORA8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; -#endif + DirectIndexedX(true); + ORA8(); } -static void Op15M0(void) +static void Op15M0() { - DirectIndexedX(READ, ORA16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; -#endif + DirectIndexedX(true); + ORA16(); } -static void Op12M1(void) +static void Op12M1() { - DirectIndirect(READ, ORA8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirect(true); + ORA8(); } -static void Op12M0(void) +static void Op12M0() { - DirectIndirect(READ, ORA16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirect(true); + ORA16(); } -static void Op01M1(void) +static void Op01M1() { - DirectIndexedIndirect(READ, ORA8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndexedIndirect(true); + ORA8(); } -static void Op01M0(void) +static void Op01M0() { - DirectIndexedIndirect(READ, ORA16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndexedIndirect(true); + ORA16(); } -static void Op11M1(void) +static void Op11M1() { - DirectIndirectIndexed(READ, ORA8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirectIndexed(true); + ORA8(); } -static void Op11M0(void) +static void Op11M0() { - DirectIndirectIndexed(READ, ORA16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirectIndexed(true); + ORA16(); } -static void Op07M1(void) +static void Op07M1() { - DirectIndirectLong(READ, ORA8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirectLong(true); + ORA8(); } -static void Op07M0(void) +static void Op07M0() { - DirectIndirectLong(READ, ORA16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirectLong(true); + ORA16(); } -static void Op17M1(void) +static void Op17M1() { - DirectIndirectIndexedLong(READ, ORA8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirectIndexedLong(true); + ORA8(); } -static void Op17M0(void) +static void Op17M0() { - DirectIndirectIndexedLong(READ, ORA16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirectIndexedLong(true); + ORA16(); } -static void Op0DM1(void) +static void Op0DM1() { - Absolute(READ, ORA8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + Absolute(true); + ORA8(); } -static void Op0DM0(void) +static void Op0DM0() { - Absolute(READ, ORA16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + Absolute(true); + ORA16(); } -static void Op1DM1(void) +static void Op1DM1() { - AbsoluteIndexedX(READ, ORA8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + AbsoluteIndexedX(true); + ORA8(); } -static void Op1DM0(void) +static void Op1DM0() { - AbsoluteIndexedX(READ, ORA16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + AbsoluteIndexedX(true); + ORA16(); } -static void Op19M1(void) +static void Op19M1() { - AbsoluteIndexedY(READ, ORA8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + AbsoluteIndexedY(true); + ORA8(); } -static void Op19M0(void) +static void Op19M0() { - AbsoluteIndexedY(READ, ORA16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + AbsoluteIndexedY(true); + ORA16(); } -static void Op0FM1(void) +static void Op0FM1() { - AbsoluteLong(READ, ORA8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 + CPU.MemSpeed; -#endif + AbsoluteLong(true); + ORA8(); } -static void Op0FM0(void) +static void Op0FM0() { - AbsoluteLong(READ, ORA16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 + CPU.MemSpeed; -#endif + AbsoluteLong(true); + ORA16(); } -static void Op1FM1(void) +static void Op1FM1() { - AbsoluteLongIndexedX(READ, ORA8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 + CPU.MemSpeed; -#endif + AbsoluteLongIndexedX(true); + ORA8(); } -static void Op1FM0(void) +static void Op1FM0() { - AbsoluteLongIndexedX(READ, ORA16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 + CPU.MemSpeed; -#endif + AbsoluteLongIndexedX(true); + ORA16(); } -static void Op03M1(void) +static void Op03M1() { - StackRelative(READ, ORA8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; -#endif + StackRelative(true); + ORA8(); } -static void Op03M0(void) +static void Op03M0() { - StackRelative(READ, ORA16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; -#endif + StackRelative(true); + ORA16(); } -static void Op13M1(void) +static void Op13M1() { - StackRelativeIndirectIndexed(READ, ORA8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + TWO_CYCLES; -#endif + StackRelativeIndirectIndexed(true); + ORA8(); } -static void Op13M0(void) +static void Op13M0() { - StackRelativeIndirectIndexed(READ, ORA16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + TWO_CYCLES; -#endif + StackRelativeIndirectIndexed(true); + ORA16(); } /**********************************************************************************************/ /* ROL *************************************************************************************** */ -static void Op2AM1(void) +static void Op2AM1() { A_ROL8(); } -static void Op2AM0(void) +static void Op2AM0() { A_ROL16(); } -static void Op26M1(void) +static void Op26M1() { - Direct(MODIFY, ROL8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed /* memory */ + ONE_CYCLE /* opcode */; -#endif + Direct(false); + ROL8(); } -static void Op26M0(void) +static void Op26M0() { - Direct(MODIFY, ROL16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed /* memory */ + ONE_CYCLE /* opcode */; -#endif + Direct(false); + ROL16(); } -static void Op36M1(void) +static void Op36M1() { - DirectIndexedX(MODIFY, ROL8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE /* memory */ + ONE_CYCLE /* opcode */; -#endif + DirectIndexedX(false); + ROL8(); } -static void Op36M0(void) +static void Op36M0() { - DirectIndexedX(MODIFY, ROL16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE /* memory */ + ONE_CYCLE /* opcode */; -#endif + DirectIndexedX(false); + ROL16(); } -static void Op2EM1(void) +static void Op2EM1() { - Absolute(MODIFY, ROL8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 /* memory */ + ONE_CYCLE /* opcode */; -#endif + Absolute(false); + ROL8(); } -static void Op2EM0(void) +static void Op2EM0() { - Absolute(MODIFY, ROL16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 /* memory */ + ONE_CYCLE /* opcode */; -#endif + Absolute(false); + ROL16(); } -static void Op3EM1(void) +static void Op3EM1() { - AbsoluteIndexedX(MODIFY, ROL8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 /* memory */ + ONE_CYCLE /* opcode */; -#endif + AbsoluteIndexedX(false); + ROL8(); } -static void Op3EM0(void) +static void Op3EM0() { - AbsoluteIndexedX(MODIFY, ROL16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 /* memory */ + ONE_CYCLE /* opcode */; -#endif + AbsoluteIndexedX(false); + ROL16(); } /**********************************************************************************************/ /* ROR *************************************************************************************** */ -static void Op6AM1(void) +static void Op6AM1() { A_ROR8(); } -static void Op6AM0(void) +static void Op6AM0() { A_ROR16(); } -static void Op66M1(void) +static void Op66M1() { - Direct(MODIFY, ROR8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed /* memory */ + ONE_CYCLE /* opcode */; -#endif + Direct(false); + ROR8(); } -static void Op66M0(void) +static void Op66M0() { - Direct(MODIFY, ROR16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed /* memory */ + ONE_CYCLE /* opcode */; -#endif + Direct(false); + ROR16(); } -static void Op76M1(void) +static void Op76M1() { - DirectIndexedX(MODIFY, ROR8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE /* memory */ + ONE_CYCLE /* opcode */; -#endif + DirectIndexedX(false); + ROR8(); } -static void Op76M0(void) +static void Op76M0() { - DirectIndexedX(MODIFY, ROR16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE /* memory */ + ONE_CYCLE /* opcode */; -#endif + DirectIndexedX(false); + ROR16(); } -static void Op6EM1(void) +static void Op6EM1() { - Absolute(MODIFY, ROR8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 /* memory */ + ONE_CYCLE /* opcode */; -#endif + Absolute(false); + ROR8(); } -static void Op6EM0(void) +static void Op6EM0() { - Absolute(MODIFY, ROR16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 /* memory */ + ONE_CYCLE /* opcode */; -#endif + Absolute(false); + ROR16(); } -static void Op7EM1(void) +static void Op7EM1() { - AbsoluteIndexedX(MODIFY, ROR8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 /* memory */ + ONE_CYCLE /* opcode */; -#endif + AbsoluteIndexedX(false); + ROR8(); } -static void Op7EM0(void) +static void Op7EM0() { - AbsoluteIndexedX(MODIFY, ROR16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 /* memory */ + ONE_CYCLE /* opcode */; -#endif + AbsoluteIndexedX(false); + ROR16(); } /**********************************************************************************************/ /* SBC *************************************************************************************** */ -static void OpE9M1(void) +static void OpE9M1() { - Immediate8(READ, SBC8); + Immediate8(); + SBC8(); } -static void OpE9M0(void) +static void OpE9M0() { - Immediate16(READ, SBC16); + Immediate16(); + SBC16(); } -static void OpE5M1(void) +static void OpE5M1() { - Direct(READ, SBC8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + Direct(true); + SBC8(); } -static void OpE5M0(void) +static void OpE5M0() { - Direct(READ, SBC16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + Direct(true); + SBC16(); } -static void OpF5M1(void) +static void OpF5M1() { - DirectIndexedX(READ, SBC8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; -#endif + DirectIndexedX(true); + SBC8(); } -static void OpF5M0(void) +static void OpF5M0() { - DirectIndexedX(READ, SBC16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; -#endif + DirectIndexedX(true); + SBC16(); } -static void OpF2M1(void) +static void OpF2M1() { - DirectIndirect(READ, SBC8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirect(true); + SBC8(); } -static void OpF2M0(void) +static void OpF2M0() { - DirectIndirect(READ, SBC16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirect(true); + SBC16(); } -static void OpE1M1(void) +static void OpE1M1() { - DirectIndexedIndirect(READ, SBC8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndexedIndirect(true); + SBC8(); } -static void OpE1M0(void) +static void OpE1M0() { - DirectIndexedIndirect(READ, SBC16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndexedIndirect(true); + SBC16(); } -static void OpF1M1(void) +static void OpF1M1() { - DirectIndirectIndexed(READ, SBC8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirectIndexed(true); + SBC8(); } -static void OpF1M0(void) +static void OpF1M0() { - DirectIndirectIndexed(READ, SBC16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirectIndexed(true); + SBC16(); } -static void OpE7M1(void) +static void OpE7M1() { - DirectIndirectLong(READ, SBC8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirectLong(true); + SBC8(); } -static void OpE7M0(void) +static void OpE7M0() { - DirectIndirectLong(READ, SBC16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirectLong(true); + SBC16(); } -static void OpF7M1(void) +static void OpF7M1() { - DirectIndirectIndexedLong(READ, SBC8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirectIndexedLong(true); + SBC8(); } -static void OpF7M0(void) +static void OpF7M0() { - DirectIndirectIndexedLong(READ, SBC16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirectIndexedLong(true); + SBC16(); } -static void OpEDM1(void) +static void OpEDM1() { - Absolute(READ, SBC8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + Absolute(true); + SBC8(); } -static void OpEDM0(void) +static void OpEDM0() { - Absolute(READ, SBC16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + Absolute(true); + SBC16(); } -static void OpFDM1(void) +static void OpFDM1() { - AbsoluteIndexedX(READ, SBC8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + AbsoluteIndexedX(true); + SBC8(); } -static void OpFDM0(void) +static void OpFDM0() { - AbsoluteIndexedX(READ, SBC16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + AbsoluteIndexedX(true); + SBC16(); } -static void OpF9M1(void) +static void OpF9M1() { - AbsoluteIndexedY(READ, SBC8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + AbsoluteIndexedY(true); + SBC8(); } -static void OpF9M0(void) +static void OpF9M0() { - AbsoluteIndexedY(READ, SBC16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + AbsoluteIndexedY(true); + SBC16(); } -static void OpEFM1(void) +static void OpEFM1() { - AbsoluteLong(READ, SBC8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 + CPU.MemSpeed; -#endif + AbsoluteLong(true); + SBC8(); } -static void OpEFM0(void) +static void OpEFM0() { - AbsoluteLong(READ, SBC16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 + CPU.MemSpeed; -#endif + AbsoluteLong(true); + SBC16(); } -static void OpFFM1(void) +static void OpFFM1() { - AbsoluteLongIndexedX(READ, SBC8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 + CPU.MemSpeed; -#endif + AbsoluteLongIndexedX(true); + SBC8(); } -static void OpFFM0(void) +static void OpFFM0() { - AbsoluteLongIndexedX(READ, SBC16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 + CPU.MemSpeed; -#endif + AbsoluteLongIndexedX(true); + SBC16(); } -static void OpE3M1(void) +static void OpE3M1() { - StackRelative(READ, SBC8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; -#endif + StackRelative(true); + SBC8(); } -static void OpE3M0(void) +static void OpE3M0() { - StackRelative(READ, SBC16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; -#endif + StackRelative(true); + SBC16(); } -static void OpF3M1(void) +static void OpF3M1() { - StackRelativeIndirectIndexed(READ, SBC8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + TWO_CYCLES; -#endif + StackRelativeIndirectIndexed(true); + SBC8(); } -static void OpF3M0(void) +static void OpF3M0() { - StackRelativeIndirectIndexed(READ, SBC16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + TWO_CYCLES; -#endif + StackRelativeIndirectIndexed(true); + SBC16(); } /**********************************************************************************************/ /* STA *************************************************************************************** */ -static void Op85M1(void) +static void Op85M1() { - Direct(WRITE, STA8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + Direct(false); + STA8(); } -static void Op85M0(void) +static void Op85M0() { - Direct(WRITE, STA16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + Direct(false); + STA16(); } -static void Op95M1(void) +static void Op95M1() { - DirectIndexedX(WRITE, STA8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; -#endif + DirectIndexedX(false); + STA8(); } -static void Op95M0(void) +static void Op95M0() { - DirectIndexedX(WRITE, STA16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; -#endif + DirectIndexedX(false); + STA16(); } -static void Op92M1(void) +static void Op92M1() { - DirectIndirect(WRITE, STA8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirect(false); + STA8(); } -static void Op92M0(void) +static void Op92M0() { - DirectIndirect(WRITE, STA16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirect(false); + STA16(); } -static void Op81M1(void) +static void Op81M1() { - DirectIndexedIndirect(WRITE, STA8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndexedIndirect(false); + STA8(); #ifdef noVAR_CYCLES if (CheckIndex()) CPU.Cycles += ONE_CYCLE; #endif } -static void Op81M0(void) +static void Op81M0() { - DirectIndexedIndirect(WRITE, STA16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndexedIndirect(false); + STA16(); #ifdef noVAR_CYCLES if (CheckIndex()) CPU.Cycles += ONE_CYCLE; #endif } -static void Op91M1(void) +static void Op91M1() { - DirectIndirectIndexed(WRITE, STA8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirectIndexed(false); + STA8(); } -static void Op91M0(void) +static void Op91M0() { - DirectIndirectIndexed(WRITE, STA16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirectIndexed(false); + STA16(); } -static void Op87M1(void) +static void Op87M1() { - DirectIndirectLong(WRITE, STA8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirectLong(false); + STA8(); } -static void Op87M0(void) +static void Op87M0() { - DirectIndirectLong(WRITE, STA16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirectLong(false); + STA16(); } -static void Op97M1(void) +static void Op97M1() { - DirectIndirectIndexedLong(WRITE, STA8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirectIndexedLong(false); + STA8(); } -static void Op97M0(void) +static void Op97M0() { - DirectIndirectIndexedLong(WRITE, STA16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirectIndexedLong(false); + STA16(); } -static void Op8DM1(void) +static void Op8DM1() { - Absolute(WRITE, STA8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + Absolute(false); + STA8(); } -static void Op8DM0(void) +static void Op8DM0() { - Absolute(WRITE, STA16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + Absolute(false); + STA16(); } -static void Op9DM1(void) +static void Op9DM1() { - AbsoluteIndexedX(WRITE, STA8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + AbsoluteIndexedX(false); + STA8(); } -static void Op9DM0(void) +static void Op9DM0() { - AbsoluteIndexedX(WRITE, STA16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + AbsoluteIndexedX(false); + STA16(); } -static void Op99M1(void) +static void Op99M1() { - AbsoluteIndexedY(WRITE, STA8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + AbsoluteIndexedY(false); + STA8(); } -static void Op99M0(void) +static void Op99M0() { - AbsoluteIndexedY(WRITE, STA16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + AbsoluteIndexedY(false); + STA16(); } -static void Op8FM1(void) +static void Op8FM1() { - AbsoluteLong(WRITE, STA8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 + CPU.MemSpeed; -#endif + AbsoluteLong(false); + STA8(); } -static void Op8FM0(void) +static void Op8FM0() { - AbsoluteLong(WRITE, STA16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 + CPU.MemSpeed; -#endif + AbsoluteLong(false); + STA16(); } -static void Op9FM1(void) +static void Op9FM1() { - AbsoluteLongIndexedX(WRITE, STA8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 + CPU.MemSpeed; -#endif + AbsoluteLongIndexedX(false); + STA8(); } -static void Op9FM0(void) +static void Op9FM0() { - AbsoluteLongIndexedX(WRITE, STA16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 + CPU.MemSpeed; -#endif + AbsoluteLongIndexedX(false); + STA16(); } -static void Op83M1(void) +static void Op83M1() { - StackRelative(WRITE, STA8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; -#endif + StackRelative(false); + STA8(); } -static void Op83M0(void) +static void Op83M0() { - StackRelative(WRITE, STA16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; -#endif + StackRelative(false); + STA16(); } -static void Op93M1(void) +static void Op93M1() { - StackRelativeIndirectIndexed(WRITE, STA8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + TWO_CYCLES; -#endif + StackRelativeIndirectIndexed(false); + STA8(); } -static void Op93M0(void) +static void Op93M0() { - StackRelativeIndirectIndexed(WRITE, STA16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + TWO_CYCLES; -#endif + StackRelativeIndirectIndexed(false); + STA16(); } /**********************************************************************************************/ /* STX *************************************************************************************** */ -static void Op86X1(void) +static void Op86X1() { - Direct(WRITE, STX8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + Direct(false); + STX8(); } -static void Op86X0(void) +static void Op86X0() { - Direct(WRITE, STX16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + Direct(false); + STX16(); } -static void Op96X1(void) +static void Op96X1() { - DirectIndexedY(WRITE, STX8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; -#endif + DirectIndexedY(false); + STX8(); } -static void Op96X0(void) +static void Op96X0() { - DirectIndexedY(WRITE, STX16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; -#endif + DirectIndexedY(false); + STX16(); } -static void Op8EX1(void) +static void Op8EX1() { - Absolute(WRITE, STX8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + Absolute(false); + STX8(); } -static void Op8EX0(void) +static void Op8EX0() { - Absolute(WRITE, STX16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + Absolute(false); + STX16(); } /**********************************************************************************************/ /* STY *************************************************************************************** */ -static void Op84X1(void) +static void Op84X1() { - Direct(WRITE, STY8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + Direct(false); + STY8(); } -static void Op84X0(void) +static void Op84X0() { - Direct(WRITE, STY16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + Direct(false); + STY16(); } -static void Op94X1(void) +static void Op94X1() { - DirectIndexedX(WRITE, STY8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; -#endif + DirectIndexedX(false); + STY8(); } -static void Op94X0(void) +static void Op94X0() { - DirectIndexedX(WRITE, STY16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; -#endif + DirectIndexedX(false); + STY16(); } -static void Op8CX1(void) +static void Op8CX1() { - Absolute(WRITE, STY8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + Absolute(false); + STY8(); } -static void Op8CX0(void) +static void Op8CX0() { - Absolute(WRITE, STY16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + Absolute(false); + STY16(); } /**********************************************************************************************/ /* STZ *************************************************************************************** */ -static void Op64M1(void) +static void Op64M1() { - Direct(WRITE, STZ8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + Direct(false); + STZ8(); } -static void Op64M0(void) +static void Op64M0() { - Direct(WRITE, STZ16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + Direct(false); + STZ16(); } -static void Op74M1(void) +static void Op74M1() { - DirectIndexedX(WRITE, STZ8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; -#endif + DirectIndexedX(false); + STZ8(); } -static void Op74M0(void) +static void Op74M0() { - DirectIndexedX(WRITE, STZ16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; -#endif + DirectIndexedX(false); + STZ16(); } -static void Op9CM1(void) +static void Op9CM1() { - Absolute(WRITE, STZ8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + Absolute(false); + STZ8(); } -static void Op9CM0(void) +static void Op9CM0() { - Absolute(WRITE, STZ16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + Absolute(false); + STZ16(); } -static void Op9EM1(void) +static void Op9EM1() { - AbsoluteIndexedX(WRITE, STZ8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + AbsoluteIndexedX(false); + STZ8(); } -static void Op9EM0(void) +static void Op9EM0() { - AbsoluteIndexedX(WRITE, STZ16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + AbsoluteIndexedX(false); + STZ16(); } /**********************************************************************************************/ /* TRB *************************************************************************************** */ -static void Op14M1(void) +static void Op14M1() { - Direct(MODIFY, TRB8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed /* memory */ + ONE_CYCLE /* opcode */; -#endif + Direct(false); + TRB8(); } -static void Op14M0(void) +static void Op14M0() { - Direct(MODIFY, TRB16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed /* memory */ + ONE_CYCLE /* opcode */; -#endif + Direct(false); + TRB16(); } -static void Op1CM1(void) +static void Op1CM1() { - Absolute(MODIFY, TRB8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 /* memory */ + ONE_CYCLE /* opcode */; -#endif + Absolute(false); + TRB8(); } -static void Op1CM0(void) +static void Op1CM0() { - Absolute(MODIFY, TRB16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 /* memory */ + ONE_CYCLE /* opcode */; -#endif + Absolute(false); + TRB16(); } /**********************************************************************************************/ /* TSB *************************************************************************************** */ -static void Op04M1(void) +static void Op04M1() { - Direct(MODIFY, TSB8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed /* memory */ + ONE_CYCLE /* opcode */; -#endif + Direct(false); + TSB8(); } -static void Op04M0(void) +static void Op04M0() { - Direct(MODIFY, TSB16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed /* memory */ + ONE_CYCLE /* opcode */; -#endif + Direct(false); + TSB16(); } -static void Op0CM1(void) +static void Op0CM1() { - Absolute(MODIFY, TSB8); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 /* memory */ + ONE_CYCLE /* opcode */; -#endif + Absolute(false); + TSB8(); } -static void Op0CM0(void) +static void Op0CM0() { - Absolute(MODIFY, TSB16); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 /* memory */ + ONE_CYCLE /* opcode */; -#endif + Absolute(false); + TSB16(); } /**********************************************************************************************/ @@ -3071,28 +2402,28 @@ static void Op0CM0(void) /* Branch Instructions *********************************************************************** */ #ifndef SA1_OPCODES #define BranchCheck0()\ - if( CPU.BranchSkip)\ - {\ - CPU.BranchSkip = false;\ - if (!Settings.SoundSkipMethod)\ - if( CPU.PC - CPU.PCBase > OpAddress)\ - return;\ - } + if(CPU.BranchSkip)\ + {\ + CPU.BranchSkip = false;\ + if (!Settings.SoundSkipMethod)\ + if (CPU.PC - CPU.PCBase > OpAddress)\ + return;\ + } #define BranchCheck1()\ - if( CPU.BranchSkip)\ + if(CPU.BranchSkip)\ {\ CPU.BranchSkip = false;\ - if (!Settings.SoundSkipMethod) {\ + if (!Settings.SoundSkipMethod)\ + {\ if( CPU.PC - CPU.PCBase > OpAddress)\ - return;\ + return;\ }\ - else \ - if (Settings.SoundSkipMethod == 1)\ + else if (Settings.SoundSkipMethod == 1)\ return;\ if (Settings.SoundSkipMethod == 3)\ {\ - if( CPU.PC - CPU.PCBase > OpAddress)\ + if (CPU.PC - CPU.PCBase > OpAddress)\ return;\ else\ CPU.PC = CPU.PCBase + OpAddress;\ @@ -3100,22 +2431,22 @@ static void Op0CM0(void) } #define BranchCheck2()\ - if( CPU.BranchSkip)\ + if(CPU.BranchSkip)\ {\ CPU.BranchSkip = false;\ - if (!Settings.SoundSkipMethod) {\ - if( CPU.PC - CPU.PCBase > OpAddress)\ - return;\ + if (!Settings.SoundSkipMethod)\ + {\ + if( CPU.PC - CPU.PCBase > OpAddress)\ + return;\ }\ - else \ - if (Settings.SoundSkipMethod == 1)\ - CPU.PC = CPU.PCBase + OpAddress;\ + else if (Settings.SoundSkipMethod == 1)\ + CPU.PC = CPU.PCBase + OpAddress;\ if (Settings.SoundSkipMethod == 3)\ {\ - if (CPU.PC - CPU.PCBase > OpAddress)\ - return;\ - else\ - CPU.PC = CPU.PCBase + OpAddress;\ + if (CPU.PC - CPU.PCBase > OpAddress)\ + return;\ + else\ + CPU.PC = CPU.PCBase + OpAddress;\ }\ } #else @@ -3135,8 +2466,7 @@ static inline void CPUShutdown() // the delay could allow the shutdown code to cycle skip again. // Was causing screen flashing on Top Gear 3000. - if (CPU.WaitCounter == 0 && - !(CPU.Flags & (IRQ_PENDING_FLAG | NMI_FLAG))) + if (CPU.WaitCounter == 0 && !(CPU.Flags & (IRQ_PENDING_FLAG | NMI_FLAG))) { CPU.WaitAddress = NULL; #ifndef USE_BLARGG_APU @@ -3182,7 +2512,7 @@ static inline void CPUShutdown() static inline void ForceShutdown() { #ifdef CPU_SHUTDOWN -#ifndef SA1_OPCODES +#ifdef VAR_CYCLES CPU.WaitAddress = NULL; #ifndef USE_BLARGG_APU CPU.Cycles = CPU.NextEvent; @@ -3192,7 +2522,8 @@ static inline void ForceShutdown() do { APU_EXECUTE1(); - } while (APU.Cycles < CPU.NextEvent); + } + while (APU.Cycles < CPU.NextEvent); ICPU.CPUExecuting = true; } #endif @@ -3204,173 +2535,140 @@ static inline void ForceShutdown() } /* BCC */ -static void Op90(void) +static void Op90() { - Relative(JUMP, OpAddressPassthrough); + Relative(); BranchCheck0(); if (!CheckCarry()) { CPU.PC = CPU.PCBase + OpAddress; #ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; + CPU.Cycles += ONE_CYCLE; #endif CPUShutdown(); } -#ifndef SA1_OPCODES - else - CPU.Cycles += CPU.MemSpeed; -#endif } /* BCS */ -static void OpB0(void) +static void OpB0() { - Relative(JUMP, OpAddressPassthrough); + Relative(); BranchCheck0(); if (CheckCarry()) { CPU.PC = CPU.PCBase + OpAddress; #ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; + CPU.Cycles += ONE_CYCLE; #endif CPUShutdown(); } -#ifndef SA1_OPCODES - else - CPU.Cycles += CPU.MemSpeed; -#endif } /* BEQ */ -static void OpF0(void) +static void OpF0() { - Relative(JUMP, OpAddressPassthrough); + Relative(); BranchCheck2(); if (CheckZero()) { CPU.PC = CPU.PCBase + OpAddress; #ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; + CPU.Cycles += ONE_CYCLE; #endif CPUShutdown(); } -#ifndef SA1_OPCODES - else - CPU.Cycles += CPU.MemSpeed; -#endif } /* BMI */ -static void Op30(void) +static void Op30() { - Relative(JUMP, OpAddressPassthrough); + Relative(); BranchCheck1(); if (CheckNegative()) { CPU.PC = CPU.PCBase + OpAddress; #ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; + CPU.Cycles += ONE_CYCLE; #endif CPUShutdown(); } -#ifndef SA1_OPCODES - else - CPU.Cycles += CPU.MemSpeed; -#endif } /* BNE */ -static void OpD0(void) +static void OpD0() { - Relative(JUMP, OpAddressPassthrough); + Relative(); BranchCheck1(); if (!CheckZero()) { CPU.PC = CPU.PCBase + OpAddress; - #ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; + CPU.Cycles += ONE_CYCLE; #endif CPUShutdown(); } -#ifndef SA1_OPCODES - else - CPU.Cycles += CPU.MemSpeed; -#endif } /* BPL */ -static void Op10(void) +static void Op10() { - Relative(JUMP, OpAddressPassthrough); + Relative(); BranchCheck1(); if (!CheckNegative()) { CPU.PC = CPU.PCBase + OpAddress; #ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; + CPU.Cycles += ONE_CYCLE; #endif CPUShutdown(); } -#ifndef SA1_OPCODES - else - CPU.Cycles += CPU.MemSpeed; -#endif } /* BRA */ -static void Op80(void) +static void Op80() { - Relative(JUMP, OpAddressPassthrough); + Relative(); CPU.PC = CPU.PCBase + OpAddress; #ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; + CPU.Cycles += ONE_CYCLE; #endif CPUShutdown(); } /* BVC */ -static void Op50(void) +static void Op50() { - Relative(JUMP, OpAddressPassthrough); + Relative(); BranchCheck0(); if (!CheckOverflow()) { CPU.PC = CPU.PCBase + OpAddress; #ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; + CPU.Cycles += ONE_CYCLE; #endif CPUShutdown(); } -#ifndef SA1_OPCODES - else - CPU.Cycles += CPU.MemSpeed; -#endif } /* BVS */ -static void Op70(void) +static void Op70() { - Relative(JUMP, OpAddressPassthrough); + Relative(); BranchCheck0(); if (CheckOverflow()) { CPU.PC = CPU.PCBase + OpAddress; #ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed + ONE_CYCLE; + CPU.Cycles += ONE_CYCLE; #endif CPUShutdown(); } -#ifndef SA1_OPCODES - else - CPU.Cycles += CPU.MemSpeed; -#endif } /**********************************************************************************************/ /* ClearFlag Instructions ******************************************************************** */ /* CLC */ -static void Op18(void) +static void Op18() { ClearCarry(); #ifndef SA1_OPCODES @@ -3379,7 +2677,7 @@ static void Op18(void) } /* CLD */ -static void OpD8(void) +static void OpD8() { ClearDecimal(); #ifndef SA1_OPCODES @@ -3388,7 +2686,7 @@ static void OpD8(void) } /* CLI */ -static void Op58(void) +static void Op58() { ClearIRQ(); #ifndef SA1_OPCODES @@ -3398,7 +2696,7 @@ static void Op58(void) } /* CLV */ -static void OpB8(void) +static void OpB8() { ClearOverflow(); #ifndef SA1_OPCODES @@ -3408,7 +2706,7 @@ static void OpB8(void) /**********************************************************************************************/ /* DEX/DEY *********************************************************************************** */ -static void OpCAX1(void) +static void OpCAX1() { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -3416,12 +2714,11 @@ static void OpCAX1(void) #ifdef CPU_SHUTDOWN CPU.WaitAddress = NULL; #endif - ICPU.Registers.XL--; SetZN8(ICPU.Registers.XL); } -static void OpCAX0(void) +static void OpCAX0() { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -3429,12 +2726,11 @@ static void OpCAX0(void) #ifdef CPU_SHUTDOWN CPU.WaitAddress = NULL; #endif - ICPU.Registers.X.W--; SetZN16(ICPU.Registers.X.W); } -static void Op88X1(void) +static void Op88X1() { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -3442,12 +2738,11 @@ static void Op88X1(void) #ifdef CPU_SHUTDOWN CPU.WaitAddress = NULL; #endif - ICPU.Registers.YL--; SetZN8(ICPU.Registers.YL); } -static void Op88X0(void) +static void Op88X0() { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -3455,14 +2750,13 @@ static void Op88X0(void) #ifdef CPU_SHUTDOWN CPU.WaitAddress = NULL; #endif - ICPU.Registers.Y.W--; SetZN16(ICPU.Registers.Y.W); } /**********************************************************************************************/ /* INX/INY *********************************************************************************** */ -static void OpE8X1(void) +static void OpE8X1() { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -3470,12 +2764,11 @@ static void OpE8X1(void) #ifdef CPU_SHUTDOWN CPU.WaitAddress = NULL; #endif - ICPU.Registers.XL++; SetZN8(ICPU.Registers.XL); } -static void OpE8X0(void) +static void OpE8X0() { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -3483,12 +2776,11 @@ static void OpE8X0(void) #ifdef CPU_SHUTDOWN CPU.WaitAddress = NULL; #endif - ICPU.Registers.X.W++; SetZN16(ICPU.Registers.X.W); } -static void OpC8X1(void) +static void OpC8X1() { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -3496,12 +2788,11 @@ static void OpC8X1(void) #ifdef CPU_SHUTDOWN CPU.WaitAddress = NULL; #endif - ICPU.Registers.YL++; SetZN8(ICPU.Registers.YL); } -static void OpC8X0(void) +static void OpC8X0() { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -3509,7 +2800,6 @@ static void OpC8X0(void) #ifdef CPU_SHUTDOWN CPU.WaitAddress = NULL; #endif - ICPU.Registers.Y.W++; SetZN16(ICPU.Registers.Y.W); } @@ -3517,7 +2807,7 @@ static void OpC8X0(void) /**********************************************************************************************/ /* NOP *************************************************************************************** */ -static void OpEA(void) +static void OpEA() { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -3526,85 +2816,63 @@ static void OpEA(void) /**********************************************************************************************/ /* PUSH Instructions ************************************************************************* */ - #define PushB(b)\ - S9xSetByte (b, ICPU.Registers.S.W--); + S9xSetByte(b, ICPU.Registers.S.W--); #define PushBE(b)\ - S9xSetByte (b, ICPU.Registers.S.W--);\ - ICPU.Registers.SH=0x01; - + PushB(b);\ + ICPU.Registers.SH = 0x01; -#define PushW(w) \ - S9xSetByte ((w)>>8, ICPU.Registers.S.W);\ - S9xSetByte ((w)&0xff, (ICPU.Registers.S.W - 1)&0xFFFF);\ - ICPU.Registers.S.W -= 2; +#define PushW(w)\ + S9xSetByte((w) >> 8, ICPU.Registers.S.W);\ + S9xSetByte((w) & 0xff, (ICPU.Registers.S.W - 1) & 0xffff);\ + ICPU.Registers.S.W -= 2; -#define PushWE(w) \ - S9xSetByte ((w)>>8, ICPU.Registers.S.W--);\ - S9xSetByte ((w)&0xff, (ICPU.Registers.S.W--)&0xFFFF);\ - ICPU.Registers.SH = 0x01; +#define PushWE(w)\ + PushW(w); \ + ICPU.Registers.SH = 0x01; //PEA NL -static void OpF4E1(void) +static void OpF4E1() { - Absolute(NONE, OpAddressPassthrough); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + Absolute(false); PushWE((uint16_t)OpAddress); } -static void OpF4(void) +static void OpF4() { - Absolute(NONE, OpAddressPassthrough); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + Absolute(false); PushW((uint16_t)OpAddress); } //PEI NL -static void OpD4E1(void) +static void OpD4E1() { - DirectIndirect(NONE, OpAddressPassthrough); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirect(false); PushWE((uint16_t)OpAddress); } -static void OpD4(void) +static void OpD4() { - DirectIndirect(NONE, OpAddressPassthrough); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeed; -#endif + DirectIndirect(false); PushW((uint16_t)OpAddress); } //PER NL -static void Op62E1(void) +static void Op62E1() { - RelativeLong(NONE, OpAddressPassthrough); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 + ONE_CYCLE; -#endif + RelativeLong(false); PushWE((uint16_t)OpAddress); } -static void Op62(void) +static void Op62() { - RelativeLong(NONE, OpAddressPassthrough); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 + ONE_CYCLE; -#endif + RelativeLong(false); PushW((uint16_t)OpAddress); } - //PHA -static void Op48E1(void) +static void Op48E1() { PushBE(ICPU.Registers.AL); #ifndef SA1_OPCODES @@ -3612,7 +2880,7 @@ static void Op48E1(void) #endif } -static void Op48M1(void) +static void Op48M1() { PushB(ICPU.Registers.AL); #ifndef SA1_OPCODES @@ -3620,7 +2888,7 @@ static void Op48M1(void) #endif } -static void Op48M0(void) +static void Op48M0() { PushW(ICPU.Registers.A.W); #ifndef SA1_OPCODES @@ -3629,14 +2897,15 @@ static void Op48M0(void) } //PHB -static void Op8BE1(void) +static void Op8BE1() { PushBE(ICPU.Registers.DB); #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; #endif } -static void Op8B(void) + +static void Op8B() { PushB(ICPU.Registers.DB); #ifndef SA1_OPCODES @@ -3645,7 +2914,7 @@ static void Op8B(void) } //PHD NL -static void Op0BE1(void) +static void Op0BE1() { PushWE(ICPU.Registers.D.W); #ifndef SA1_OPCODES @@ -3653,7 +2922,7 @@ static void Op0BE1(void) #endif } -static void Op0B(void) +static void Op0B() { PushW(ICPU.Registers.D.W); #ifndef SA1_OPCODES @@ -3662,7 +2931,7 @@ static void Op0B(void) } //PHK -static void Op4BE1(void) +static void Op4BE1() { PushBE(ICPU.Registers.PB); #ifndef SA1_OPCODES @@ -3670,7 +2939,7 @@ static void Op4BE1(void) #endif } -static void Op4B(void) +static void Op4B() { PushB(ICPU.Registers.PB); #ifndef SA1_OPCODES @@ -3679,7 +2948,7 @@ static void Op4B(void) } //PHP -static void Op08E1(void) +static void Op08E1() { S9xPackStatus(); PushBE(ICPU.Registers.PL); @@ -3688,7 +2957,7 @@ static void Op08E1(void) #endif } -static void Op08(void) +static void Op08() { S9xPackStatus(); PushB(ICPU.Registers.PL); @@ -3698,7 +2967,7 @@ static void Op08(void) } //PHX -static void OpDAE1(void) +static void OpDAE1() { PushBE(ICPU.Registers.XL); #ifndef SA1_OPCODES @@ -3706,7 +2975,7 @@ static void OpDAE1(void) #endif } -static void OpDAX1(void) +static void OpDAX1() { PushB(ICPU.Registers.XL); #ifndef SA1_OPCODES @@ -3714,7 +2983,7 @@ static void OpDAX1(void) #endif } -static void OpDAX0(void) +static void OpDAX0() { PushW(ICPU.Registers.X.W); #ifndef SA1_OPCODES @@ -3723,7 +2992,7 @@ static void OpDAX0(void) } //PHY -static void Op5AE1(void) +static void Op5AE1() { PushBE(ICPU.Registers.YL); #ifndef SA1_OPCODES @@ -3731,7 +3000,7 @@ static void Op5AE1(void) #endif } -static void Op5AX1(void) +static void Op5AX1() { PushB(ICPU.Registers.YL); #ifndef SA1_OPCODES @@ -3739,7 +3008,7 @@ static void Op5AX1(void) #endif } -static void Op5AX0(void) +static void Op5AX0() { PushW(ICPU.Registers.Y.W); #ifndef SA1_OPCODES @@ -3749,24 +3018,23 @@ static void Op5AX0(void) /**********************************************************************************************/ /* PULL Instructions ************************************************************************* */ -#define PullW(w) \ - w = S9xGetByte (++ICPU.Registers.S.W); \ - w |= (S9xGetByte (++ICPU.Registers.S.W)<<8); - #define PullB(b)\ b = S9xGetByte (++ICPU.Registers.S.W); #define PullBE(b)\ - ICPU.Registers.S.W++;\ - ICPU.Registers.SH=0x01;\ - b = S9xGetByte (ICPU.Registers.S.W); + PullB(b);\ + ICPU.Registers.SH = 0x01; + +#define PullW(w)\ + w = S9xGetByte(++ICPU.Registers.S.W);\ + w |= (S9xGetByte(++ICPU.Registers.S.W) << 8); -#define PullWE(w) \ +#define PullWE(w)\ PullW(w);\ - ICPU.Registers.SH=0x01; + ICPU.Registers.SH = 0x01; //PLA -static void Op68E1(void) +static void Op68E1() { #ifndef SA1_OPCODES CPU.Cycles += TWO_CYCLES; @@ -3775,7 +3043,7 @@ static void Op68E1(void) SetZN8(ICPU.Registers.AL); } -static void Op68M1(void) +static void Op68M1() { #ifndef SA1_OPCODES CPU.Cycles += TWO_CYCLES; @@ -3784,7 +3052,7 @@ static void Op68M1(void) SetZN8(ICPU.Registers.AL); } -static void Op68M0(void) +static void Op68M0() { #ifndef SA1_OPCODES CPU.Cycles += TWO_CYCLES; @@ -3794,7 +3062,7 @@ static void Op68M0(void) } //PLB -static void OpABE1(void) +static void OpABE1() { #ifndef SA1_OPCODES CPU.Cycles += TWO_CYCLES; @@ -3804,7 +3072,7 @@ static void OpABE1(void) ICPU.ShiftedDB = ICPU.Registers.DB << 16; } -static void OpAB(void) +static void OpAB() { #ifndef SA1_OPCODES CPU.Cycles += TWO_CYCLES; @@ -3816,7 +3084,7 @@ static void OpAB(void) /* PHP */ //PLD NL -static void Op2BE1(void) +static void Op2BE1() { #ifndef SA1_OPCODES CPU.Cycles += TWO_CYCLES; @@ -3825,7 +3093,7 @@ static void Op2BE1(void) SetZN16(ICPU.Registers.D.W); } -static void Op2B(void) +static void Op2B() { #ifndef SA1_OPCODES CPU.Cycles += TWO_CYCLES; @@ -3835,7 +3103,7 @@ static void Op2B(void) } /* PLP */ -static void Op28E1(void) +static void Op28E1() { #ifndef SA1_OPCODES CPU.Cycles += TWO_CYCLES; @@ -3851,7 +3119,7 @@ static void Op28E1(void) S9xFixCycles(); } -static void Op28(void) +static void Op28() { #ifndef SA1_OPCODES CPU.Cycles += TWO_CYCLES; @@ -3868,7 +3136,7 @@ static void Op28(void) } //PLX -static void OpFAE1(void) +static void OpFAE1() { #ifndef SA1_OPCODES CPU.Cycles += TWO_CYCLES; @@ -3877,7 +3145,7 @@ static void OpFAE1(void) SetZN8(ICPU.Registers.XL); } -static void OpFAX1(void) +static void OpFAX1() { #ifndef SA1_OPCODES CPU.Cycles += TWO_CYCLES; @@ -3886,7 +3154,7 @@ static void OpFAX1(void) SetZN8(ICPU.Registers.XL); } -static void OpFAX0(void) +static void OpFAX0() { #ifndef SA1_OPCODES CPU.Cycles += TWO_CYCLES; @@ -3896,7 +3164,7 @@ static void OpFAX0(void) } //PLY -static void Op7AE1(void) +static void Op7AE1() { #ifndef SA1_OPCODES CPU.Cycles += TWO_CYCLES; @@ -3905,7 +3173,7 @@ static void Op7AE1(void) SetZN8(ICPU.Registers.YL); } -static void Op7AX1(void) +static void Op7AX1() { #ifndef SA1_OPCODES CPU.Cycles += TWO_CYCLES; @@ -3914,7 +3182,7 @@ static void Op7AX1(void) SetZN8(ICPU.Registers.YL); } -static void Op7AX0(void) +static void Op7AX0() { #ifndef SA1_OPCODES CPU.Cycles += TWO_CYCLES; @@ -3927,7 +3195,7 @@ static void Op7AX0(void) /* SetFlag Instructions ********************************************************************** */ /* SEC */ -static void Op38(void) +static void Op38() { SetCarry(); #ifndef SA1_OPCODES @@ -3936,7 +3204,7 @@ static void Op38(void) } /* SED */ -static void OpF8(void) +static void OpF8() { SetDecimal(); #ifndef SA1_OPCODES @@ -3946,7 +3214,7 @@ static void OpF8(void) } /* SEI */ -static void Op78(void) +static void Op78() { SetIRQ(); #ifndef SA1_OPCODES @@ -3957,7 +3225,7 @@ static void Op78(void) /* Transfer Instructions ********************************************************************* */ /* TAX8 */ -static void OpAAX1(void) +static void OpAAX1() { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -3967,7 +3235,7 @@ static void OpAAX1(void) } /* TAX16 */ -static void OpAAX0(void) +static void OpAAX0() { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -3977,7 +3245,7 @@ static void OpAAX0(void) } /* TAY8 */ -static void OpA8X1(void) +static void OpA8X1() { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -3987,7 +3255,7 @@ static void OpA8X1(void) } /* TAY16 */ -static void OpA8X0(void) +static void OpA8X0() { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -3996,7 +3264,7 @@ static void OpA8X0(void) SetZN16(ICPU.Registers.Y.W); } -static void Op5B(void) +static void Op5B() { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -4005,7 +3273,7 @@ static void Op5B(void) SetZN16(ICPU.Registers.D.W); } -static void Op1B(void) +static void Op1B() { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -4015,7 +3283,7 @@ static void Op1B(void) ICPU.Registers.SH = 1; } -static void Op7B(void) +static void Op7B() { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -4024,7 +3292,7 @@ static void Op7B(void) SetZN16(ICPU.Registers.A.W); } -static void Op3B(void) +static void Op3B() { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -4033,7 +3301,7 @@ static void Op3B(void) SetZN16(ICPU.Registers.A.W); } -static void OpBAX1(void) +static void OpBAX1() { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -4042,7 +3310,7 @@ static void OpBAX1(void) SetZN8(ICPU.Registers.XL); } -static void OpBAX0(void) +static void OpBAX0() { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -4051,7 +3319,7 @@ static void OpBAX0(void) SetZN16(ICPU.Registers.X.W); } -static void Op8AM1(void) +static void Op8AM1() { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -4060,7 +3328,7 @@ static void Op8AM1(void) SetZN8(ICPU.Registers.AL); } -static void Op8AM0(void) +static void Op8AM0() { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -4069,7 +3337,7 @@ static void Op8AM0(void) SetZN16(ICPU.Registers.A.W); } -static void Op9A(void) +static void Op9A() { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -4079,7 +3347,7 @@ static void Op9A(void) ICPU.Registers.SH = 1; } -static void Op9BX1(void) +static void Op9BX1() { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -4088,7 +3356,7 @@ static void Op9BX1(void) SetZN8(ICPU.Registers.YL); } -static void Op9BX0(void) +static void Op9BX0() { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -4097,7 +3365,7 @@ static void Op9BX0(void) SetZN16(ICPU.Registers.Y.W); } -static void Op98M1(void) +static void Op98M1() { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -4106,7 +3374,7 @@ static void Op98M1(void) SetZN8(ICPU.Registers.AL); } -static void Op98M0(void) +static void Op98M0() { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -4115,7 +3383,7 @@ static void Op98M0(void) SetZN16(ICPU.Registers.A.W); } -static void OpBBX1(void) +static void OpBBX1() { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -4124,7 +3392,7 @@ static void OpBBX1(void) SetZN8(ICPU.Registers.XL); } -static void OpBBX0(void) +static void OpBBX0() { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -4136,12 +3404,11 @@ static void OpBBX0(void) /**********************************************************************************************/ /* XCE *************************************************************************************** */ -static void OpFB(void) +static void OpFB() { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; #endif - uint8_t A1 = ICPU._Carry; uint8_t A2 = ICPU.Registers.PH; ICPU._Carry = A2 & 1; @@ -4163,12 +3430,11 @@ static void OpFB(void) /**********************************************************************************************/ /* BRK *************************************************************************************** */ -static void Op00(void) +static void Op00() { #ifndef SA1_OPCODES CPU.BRKTriggered = true; #endif - if (!CheckEmulation()) { PushB(ICPU.Registers.PB); @@ -4206,18 +3472,15 @@ static void Op00(void) /**********************************************************************************************/ /* BRL ************************************************************************************** */ -static void Op82(void) +static void Op82() { - RelativeLong(JUMP, OpAddressPassthrough); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 + ONE_CYCLE; -#endif + RelativeLong(); S9xSetPCBase(ICPU.ShiftedPB + OpAddress); } /**********************************************************************************************/ /* IRQ *************************************************************************************** */ -void S9xOpcode_IRQ(void) +void S9xOpcode_IRQ() { if (!CheckEmulation()) { @@ -4240,6 +3503,8 @@ void S9xOpcode_IRQ(void) (Memory.FillRAM [0x220f] << 8)); else S9xSetPCBase(S9xGetWord(0xFFEE)); +#endif +#ifndef SA1_OPCODES CPU.Cycles += TWO_CYCLES; #endif } @@ -4263,6 +3528,8 @@ void S9xOpcode_IRQ(void) (Memory.FillRAM [0x220f] << 8)); else S9xSetPCBase(S9xGetWord(0xFFFE)); +#endif +#ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; #endif } @@ -4271,7 +3538,7 @@ void S9xOpcode_IRQ(void) /**********************************************************************************************/ /* NMI *************************************************************************************** */ -void S9xOpcode_NMI(void) +void S9xOpcode_NMI() { if (!CheckEmulation()) { @@ -4294,6 +3561,8 @@ void S9xOpcode_NMI(void) (Memory.FillRAM [0x220d] << 8)); else S9xSetPCBase(S9xGetWord(0xFFEA)); +#endif +#ifndef SA1_OPCODES CPU.Cycles += TWO_CYCLES; #endif } @@ -4317,6 +3586,8 @@ void S9xOpcode_NMI(void) (Memory.FillRAM [0x220d] << 8)); else S9xSetPCBase(S9xGetWord(0xFFFA)); +#endif +#ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; #endif } @@ -4324,7 +3595,7 @@ void S9xOpcode_NMI(void) /**********************************************************************************************/ /* COP *************************************************************************************** */ -static void Op02(void) +static void Op02() { if (!CheckEmulation()) { @@ -4363,23 +3634,20 @@ static void Op02(void) /**********************************************************************************************/ /* JML *************************************************************************************** */ -static void OpDC(void) +static void OpDC() { - AbsoluteIndirectLong(JUMP, OpAddressPassthrough); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 + TWO_CYCLES; -#endif + AbsoluteIndirectLong(false); ICPU.Registers.PB = (uint8_t)(OpAddress >> 16); ICPU.ShiftedPB = OpAddress & 0xff0000; S9xSetPCBase(OpAddress); +#ifndef SA1_OPCODES + CPU.Cycles += TWO_CYCLES; +#endif } -static void Op5C(void) +static void Op5C() { - AbsoluteLong(JUMP, OpAddressPassthrough); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 + CPU.MemSpeed; -#endif + AbsoluteLong(false); ICPU.Registers.PB = (uint8_t)(OpAddress >> 16); ICPU.ShiftedPB = OpAddress & 0xff0000; S9xSetPCBase(OpAddress); @@ -4387,44 +3655,35 @@ static void Op5C(void) /**********************************************************************************************/ /* JMP *************************************************************************************** */ -static void Op4C(void) +static void Op4C() { - Absolute(JUMP, OpAddressPassthrough); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + Absolute(false); S9xSetPCBase(ICPU.ShiftedPB + (OpAddress & 0xffff)); #if defined(CPU_SHUTDOWN) && defined(SA1_OPCODES) CPUShutdown(); #endif } -static void Op6C(void) +static void Op6C() { - AbsoluteIndirect(JUMP, OpAddressPassthrough); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2; -#endif + AbsoluteIndirect(false); S9xSetPCBase(ICPU.ShiftedPB + (OpAddress & 0xffff)); } -static void Op7C(void) +static void Op7C() { - AbsoluteIndexedIndirect(JUMP, OpAddressPassthrough); + AbsoluteIndexedIndirect(false); + S9xSetPCBase(ICPU.ShiftedPB + OpAddress); #ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 + ONE_CYCLE; + CPU.Cycles += ONE_CYCLE; #endif - S9xSetPCBase(ICPU.ShiftedPB + OpAddress); } /**********************************************************************************************/ /* JSL/RTL *********************************************************************************** */ -static void Op22E1(void) +static void Op22E1() { - AbsoluteLong(JUMP, OpAddressPassthrough); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 + CPU.MemSpeed; -#endif + AbsoluteLong(false); PushB(ICPU.Registers.PB); PushWE(CPU.PC - CPU.PCBase - 1); ICPU.Registers.PB = (uint8_t)(OpAddress >> 16); @@ -4432,12 +3691,9 @@ static void Op22E1(void) S9xSetPCBase(OpAddress); } -static void Op22(void) +static void Op22() { - AbsoluteLong(JUMP, OpAddressPassthrough); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 + CPU.MemSpeed; -#endif + AbsoluteLong(false); PushB(ICPU.Registers.PB); PushW(CPU.PC - CPU.PCBase - 1); ICPU.Registers.PB = (uint8_t)(OpAddress >> 16); @@ -4445,7 +3701,7 @@ static void Op22(void) S9xSetPCBase(OpAddress); } -static void Op6BE1(void) +static void Op6BE1() { PullWE(ICPU.Registers.PC); PullB(ICPU.Registers.PB); @@ -4456,7 +3712,7 @@ static void Op6BE1(void) #endif } -static void Op6B(void) +static void Op6B() { PullW(ICPU.Registers.PC); PullB(ICPU.Registers.PB); @@ -4469,38 +3725,38 @@ static void Op6B(void) /**********************************************************************************************/ /* JSR/RTS *********************************************************************************** */ -static void Op20(void) +static void Op20() { - Absolute(JUMP, OpAddressPassthrough); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 + ONE_CYCLE; -#endif + Absolute(false); PushW(CPU.PC - CPU.PCBase - 1); S9xSetPCBase(ICPU.ShiftedPB + (OpAddress & 0xffff)); +#ifndef SA1_OPCODES + CPU.Cycles += ONE_CYCLE; +#endif } //JSR a,x -static void OpFCE1(void) +static void OpFCE1() { - AbsoluteIndexedIndirect(JUMP, OpAddressPassthrough); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 + ONE_CYCLE; -#endif + AbsoluteIndexedIndirect(false); PushWE(CPU.PC - CPU.PCBase - 1); S9xSetPCBase(ICPU.ShiftedPB + OpAddress); +#ifndef SA1_OPCODES + CPU.Cycles += ONE_CYCLE; +#endif } -static void OpFC(void) +static void OpFC() { - AbsoluteIndexedIndirect(JUMP, OpAddressPassthrough); -#ifndef SA1_OPCODES - CPU.Cycles += CPU.MemSpeedx2 + ONE_CYCLE; -#endif + AbsoluteIndexedIndirect(false); PushW(CPU.PC - CPU.PCBase - 1); S9xSetPCBase(ICPU.ShiftedPB + OpAddress); +#ifndef SA1_OPCODES + CPU.Cycles += ONE_CYCLE; +#endif } -static void Op60(void) +static void Op60() { PullW(ICPU.Registers.PC); S9xSetPCBase(ICPU.ShiftedPB + ((ICPU.Registers.PC + 1) & 0xffff)); @@ -4512,20 +3768,17 @@ static void Op60(void) /**********************************************************************************************/ /* MVN/MVP *********************************************************************************** */ -static void Op54X1(void) +static void Op54X1() { - uint32_t SrcBank; - #ifndef SA1_OPCODES CPU.Cycles += CPU.MemSpeedx2 + TWO_CYCLES; #endif ICPU.Registers.DB = *CPU.PC++; ICPU.ShiftedDB = ICPU.Registers.DB << 16; - OpenBus = SrcBank = *CPU.PC++; + OpenBus = *CPU.PC++; - S9xSetByte(S9xGetByte((SrcBank << 16) + ICPU.Registers.X.W), - ICPU.ShiftedDB + ICPU.Registers.Y.W); + S9xSetByte(S9xGetByte((OpenBus << 16) + ICPU.Registers.X.W), ICPU.ShiftedDB + ICPU.Registers.Y.W); ICPU.Registers.XL++; ICPU.Registers.YL++; @@ -4534,20 +3787,17 @@ static void Op54X1(void) CPU.PC -= 3; } -static void Op54X0(void) +static void Op54X0() { - uint32_t SrcBank; - #ifndef SA1_OPCODES CPU.Cycles += CPU.MemSpeedx2 + TWO_CYCLES; #endif ICPU.Registers.DB = *CPU.PC++; ICPU.ShiftedDB = ICPU.Registers.DB << 16; - OpenBus = SrcBank = *CPU.PC++; + OpenBus = *CPU.PC++; - S9xSetByte(S9xGetByte((SrcBank << 16) + ICPU.Registers.X.W), - ICPU.ShiftedDB + ICPU.Registers.Y.W); + S9xSetByte(S9xGetByte((OpenBus << 16) + ICPU.Registers.X.W), ICPU.ShiftedDB + ICPU.Registers.Y.W); ICPU.Registers.X.W++; ICPU.Registers.Y.W++; @@ -4556,18 +3806,15 @@ static void Op54X0(void) CPU.PC -= 3; } -static void Op44X1(void) +static void Op44X1() { - uint32_t SrcBank; - #ifndef SA1_OPCODES CPU.Cycles += CPU.MemSpeedx2 + TWO_CYCLES; #endif ICPU.Registers.DB = *CPU.PC++; ICPU.ShiftedDB = ICPU.Registers.DB << 16; - OpenBus = SrcBank = *CPU.PC++; - S9xSetByte(S9xGetByte((SrcBank << 16) + ICPU.Registers.X.W), - ICPU.ShiftedDB + ICPU.Registers.Y.W); + OpenBus = *CPU.PC++; + S9xSetByte(S9xGetByte((OpenBus << 16) + ICPU.Registers.X.W), ICPU.ShiftedDB + ICPU.Registers.Y.W); ICPU.Registers.XL--; ICPU.Registers.YL--; @@ -4576,18 +3823,15 @@ static void Op44X1(void) CPU.PC -= 3; } -static void Op44X0(void) +static void Op44X0() { - uint32_t SrcBank; - #ifndef SA1_OPCODES CPU.Cycles += CPU.MemSpeedx2 + TWO_CYCLES; #endif ICPU.Registers.DB = *CPU.PC++; ICPU.ShiftedDB = ICPU.Registers.DB << 16; - OpenBus = SrcBank = *CPU.PC++; - S9xSetByte(S9xGetByte((SrcBank << 16) + ICPU.Registers.X.W), - ICPU.ShiftedDB + ICPU.Registers.Y.W); + OpenBus = *CPU.PC++; + S9xSetByte(S9xGetByte((OpenBus << 16) + ICPU.Registers.X.W), ICPU.ShiftedDB + ICPU.Registers.Y.W); ICPU.Registers.X.W--; ICPU.Registers.Y.W--; @@ -4599,7 +3843,7 @@ static void Op44X0(void) /**********************************************************************************************/ /* REP/SEP *********************************************************************************** */ -static void OpC2(void) +static void OpC2() { uint8_t Work8 = ~*CPU.PC++; ICPU.Registers.PL &= Work8; @@ -4624,7 +3868,7 @@ static void OpC2(void) S9xFixCycles(); } -static void OpE2(void) +static void OpE2() { uint8_t Work8 = *CPU.PC++; ICPU.Registers.PL |= Work8; @@ -4651,12 +3895,11 @@ static void OpE2(void) /**********************************************************************************************/ /* XBA *************************************************************************************** */ -static void OpEB(void) +static void OpEB() { uint8_t Work8 = ICPU.Registers.AL; ICPU.Registers.AL = ICPU.Registers.AH; ICPU.Registers.AH = Work8; - SetZN8(ICPU.Registers.AL); #ifndef SA1_OPCODES CPU.Cycles += TWO_CYCLES; @@ -4665,7 +3908,7 @@ static void OpEB(void) /**********************************************************************************************/ /* RTI *************************************************************************************** */ -static void Op40(void) +static void Op40() { PullB(ICPU.Registers.PL); S9xUnpackStatus(); @@ -4696,46 +3939,38 @@ static void Op40(void) /* STP/WAI/DB ******************************************************************************** */ // WAI -static void OpCB(void) +static void OpCB() { #ifdef SA1_OPCODES SA1.WaitingForInterrupt = true; SA1.PC--; -#else // SA1_OPCODES - { - CPU.WaitingForInterrupt = true; - CPU.PC--; +#else // SA_OPCODES + CPU.WaitingForInterrupt = true; + CPU.PC--; #ifdef CPU_SHUTDOWN - if (Settings.Shutdown) - { - CPU.Cycles = CPU.NextEvent; + if (Settings.Shutdown) + { + CPU.Cycles = CPU.NextEvent; #ifndef USE_BLARGG_APU - if (IAPU.APUExecuting) + if (IAPU.APUExecuting) + { + ICPU.CPUExecuting = false; + do { - ICPU.CPUExecuting = false; - do - { - APU_EXECUTE1(); - } - while (APU.Cycles < CPU.NextEvent); - ICPU.CPUExecuting = true; + APU_EXECUTE1(); } -#endif - } - else - { -#ifndef SA1_OPCODES - CPU.Cycles += TWO_CYCLES; -#endif + while (APU.Cycles < CPU.NextEvent); + ICPU.CPUExecuting = true; } #endif } -#endif // SA1_OPCODES +#endif +#endif } // Usually an STP opcode // SNESAdvance speed hack, not implemented in Snes9xTYL | Snes9x-Euphoria (from the speed-hacks branch of CatSFC) -static void OpDB(void) +static void OpDB() { #if !defined NO_SPEEDHACKS && defined CPU_SHUTDOWN uint8_t NextByte = *CPU.PC++; @@ -4744,14 +3979,15 @@ static void OpDB(void) int8_t BranchOffset = (NextByte & 0x7F) | ((NextByte & 0x40) << 1); // ^ -64 .. +63, sign extend bit 6 into 7 for unpacking - int32_t TargetAddress = ((int32_t) (CPU.PC - CPU.PCBase) + BranchOffset) & 0xffff; + OpAddress = ((int32_t) (CPU.PC - CPU.PCBase) + BranchOffset) & 0xffff; switch (NextByte & 0x80) { case 0x00: // BNE BranchCheck1 (); - if (!CheckZero ()) { - CPU.PC = CPU.PCBase + TargetAddress; + if (!CheckZero ()) + { + CPU.PC = CPU.PCBase + OpAddress; #ifdef VAR_CYCLES CPU.Cycles += ONE_CYCLE; #else @@ -4764,8 +4000,9 @@ static void OpDB(void) return; case 0x80: // BEQ BranchCheck2 (); - if (CheckZero ()) { - CPU.PC = CPU.PCBase + TargetAddress; + if (CheckZero ()) + { + CPU.PC = CPU.PCBase + OpAddress; #ifdef VAR_CYCLES CPU.Cycles += ONE_CYCLE; #else @@ -4784,7 +4021,7 @@ static void OpDB(void) } // SNESAdvance speed hack, as implemented in Snes9xTYL / Snes9x-Euphoria (from the speed-hacks branch of CatSFC) -static void Op42(void) +static void Op42() { #if !defined NO_SPEEDHACKS && defined CPU_SHUTDOWN uint8_t NextByte = *CPU.PC++; @@ -4792,14 +4029,15 @@ static void Op42(void) ForceShutdown(); int8_t BranchOffset = 0xF0 | (NextByte & 0xF); // always negative - int32_t TargetAddress = ((int32_t) (CPU.PC - CPU.PCBase) + BranchOffset) & 0xffff; + OpAddress = ((int32_t) (CPU.PC - CPU.PCBase) + BranchOffset) & 0xffff; switch (NextByte & 0xF0) { case 0x10: // BPL BranchCheck1 (); - if (!CheckNegative ()) { - CPU.PC = CPU.PCBase + TargetAddress; + if (!CheckNegative ()) + { + CPU.PC = CPU.PCBase + OpAddress; #ifdef VAR_CYCLES CPU.Cycles += ONE_CYCLE; #else @@ -4812,8 +4050,9 @@ static void Op42(void) return; case 0x30: // BMI BranchCheck1 (); - if (CheckNegative ()) { - CPU.PC = CPU.PCBase + TargetAddress; + if (CheckNegative ()) + { + CPU.PC = CPU.PCBase + OpAddress; #ifdef VAR_CYCLES CPU.Cycles += ONE_CYCLE; #else @@ -4826,8 +4065,9 @@ static void Op42(void) return; case 0x50: // BVC BranchCheck0 (); - if (!CheckOverflow ()) { - CPU.PC = CPU.PCBase + TargetAddress; + if (!CheckOverflow ()) + { + CPU.PC = CPU.PCBase + OpAddress; #ifdef VAR_CYCLES CPU.Cycles += ONE_CYCLE; #else @@ -4840,8 +4080,9 @@ static void Op42(void) return; case 0x70: // BVS BranchCheck0 (); - if (CheckOverflow ()) { - CPU.PC = CPU.PCBase + TargetAddress; + if (CheckOverflow ()) + { + CPU.PC = CPU.PCBase + OpAddress; #ifdef VAR_CYCLES CPU.Cycles += ONE_CYCLE; #else @@ -4853,7 +4094,7 @@ static void Op42(void) } return; case 0x80: // BRA - CPU.PC = CPU.PCBase + TargetAddress; + CPU.PC = CPU.PCBase + OpAddress; #ifdef VAR_CYCLES CPU.Cycles += ONE_CYCLE; #else @@ -4865,8 +4106,9 @@ static void Op42(void) return; case 0x90: // BCC BranchCheck0 (); - if (!CheckCarry ()) { - CPU.PC = CPU.PCBase + TargetAddress; + if (!CheckCarry ()) + { + CPU.PC = CPU.PCBase + OpAddress; #ifdef VAR_CYCLES CPU.Cycles += ONE_CYCLE; #else @@ -4879,8 +4121,9 @@ static void Op42(void) return; case 0xB0: // BCS BranchCheck0 (); - if (CheckCarry ()) { - CPU.PC = CPU.PCBase + TargetAddress; + if (CheckCarry ()) + { + CPU.PC = CPU.PCBase + OpAddress; #ifdef VAR_CYCLES CPU.Cycles += ONE_CYCLE; #else @@ -4893,8 +4136,9 @@ static void Op42(void) return; case 0xD0: // BNE BranchCheck1 (); - if (!CheckZero ()) { - CPU.PC = CPU.PCBase + TargetAddress; + if (!CheckZero ()) + { + CPU.PC = CPU.PCBase + OpAddress; #ifdef VAR_CYCLES CPU.Cycles += ONE_CYCLE; #else @@ -4907,8 +4151,9 @@ static void Op42(void) return; case 0xF0: // BEQ BranchCheck2 (); - if (CheckZero ()) { - CPU.PC = CPU.PCBase + TargetAddress; + if (CheckZero ()) + { + CPU.PC = CPU.PCBase + OpAddress; #ifdef VAR_CYCLES CPU.Cycles += ONE_CYCLE; #else @@ -4926,11 +4171,11 @@ static void Op42(void) /*****************************************************************************/ /*****************************************************************************/ -/* CPU-S9xOpcodes Definitions */ +/* CPU-S9xOpcodes Definitions */ /*****************************************************************************/ SOpcodes S9xOpcodesM1X1[256] = { - {Op00}, {Op01M1}, {Op02}, {Op03M1}, {Op04M1}, + {Op00}, {Op01M1}, {Op02}, {Op03M1}, {Op04M1}, {Op05M1}, {Op06M1}, {Op07M1}, {Op08}, {Op09M1}, {Op0AM1}, {Op0B}, {Op0CM1}, {Op0DM1}, {Op0EM1}, {Op0FM1}, {Op10}, {Op11M1}, {Op12M1}, {Op13M1}, @@ -4986,58 +4231,58 @@ SOpcodes S9xOpcodesM1X1[256] = SOpcodes S9xOpcodesE1[256] = { - {Op00}, {Op01M1}, {Op02}, {Op03M1}, {Op04M1}, - {Op05M1}, {Op06M1}, {Op07M1}, {Op08E1}, {Op09M1}, - {Op0AM1}, {Op0BE1}, {Op0CM1}, {Op0DM1}, {Op0EM1}, - {Op0FM1}, {Op10}, {Op11M1}, {Op12M1}, {Op13M1}, - {Op14M1}, {Op15M1}, {Op16M1}, {Op17M1}, {Op18}, - {Op19M1}, {Op1AM1}, {Op1B}, {Op1CM1}, {Op1DM1}, - {Op1EM1}, {Op1FM1}, {Op20}, {Op21M1}, {Op22E1}, - {Op23M1}, {Op24M1}, {Op25M1}, {Op26M1}, {Op27M1}, - {Op28}, {Op29M1}, {Op2AM1}, {Op2BE1}, {Op2CM1}, - {Op2DM1}, {Op2EM1}, {Op2FM1}, {Op30}, {Op31M1}, - {Op32M1}, {Op33M1}, {Op34M1}, {Op35M1}, {Op36M1}, - {Op37M1}, {Op38}, {Op39M1}, {Op3AM1}, {Op3B}, - {Op3CM1}, {Op3DM1}, {Op3EM1}, {Op3FM1}, {Op40}, - {Op41M1}, {Op42}, {Op43M1}, {Op44X1}, {Op45M1}, - {Op46M1}, {Op47M1}, {Op48E1}, {Op49M1}, {Op4AM1}, - {Op4BE1}, {Op4C}, {Op4DM1}, {Op4EM1}, {Op4FM1}, - {Op50}, {Op51M1}, {Op52M1}, {Op53M1}, {Op54X1}, - {Op55M1}, {Op56M1}, {Op57M1}, {Op58}, {Op59M1}, - {Op5AE1}, {Op5B}, {Op5C}, {Op5DM1}, {Op5EM1}, - {Op5FM1}, {Op60}, {Op61M1}, {Op62E1}, {Op63M1}, - {Op64M1}, {Op65M1}, {Op66M1}, {Op67M1}, {Op68E1}, - {Op69M1}, {Op6AM1}, {Op6BE1}, {Op6C}, {Op6DM1}, - {Op6EM1}, {Op6FM1}, {Op70}, {Op71M1}, {Op72M1}, - {Op73M1}, {Op74M1}, {Op75M1}, {Op76M1}, {Op77M1}, - {Op78}, {Op79M1}, {Op7AE1}, {Op7B}, {Op7C}, - {Op7DM1}, {Op7EM1}, {Op7FM1}, {Op80}, {Op81M1}, - {Op82}, {Op83M1}, {Op84X1}, {Op85M1}, {Op86X1}, - {Op87M1}, {Op88X1}, {Op89M1}, {Op8AM1}, {Op8BE1}, - {Op8CX1}, {Op8DM1}, {Op8EX1}, {Op8FM1}, {Op90}, - {Op91M1}, {Op92M1}, {Op93M1}, {Op94X1}, {Op95M1}, - {Op96X1}, {Op97M1}, {Op98M1}, {Op99M1}, {Op9A}, - {Op9BX1}, {Op9CM1}, {Op9DM1}, {Op9EM1}, {Op9FM1}, - {OpA0X1}, {OpA1M1}, {OpA2X1}, {OpA3M1}, {OpA4X1}, - {OpA5M1}, {OpA6X1}, {OpA7M1}, {OpA8X1}, {OpA9M1}, - {OpAAX1}, {OpABE1}, {OpACX1}, {OpADM1}, {OpAEX1}, - {OpAFM1}, {OpB0}, {OpB1M1}, {OpB2M1}, {OpB3M1}, - {OpB4X1}, {OpB5M1}, {OpB6X1}, {OpB7M1}, {OpB8}, - {OpB9M1}, {OpBAX1}, {OpBBX1}, {OpBCX1}, {OpBDM1}, - {OpBEX1}, {OpBFM1}, {OpC0X1}, {OpC1M1}, {OpC2}, - {OpC3M1}, {OpC4X1}, {OpC5M1}, {OpC6M1}, {OpC7M1}, - {OpC8X1}, {OpC9M1}, {OpCAX1}, {OpCB}, {OpCCX1}, - {OpCDM1}, {OpCEM1}, {OpCFM1}, {OpD0}, {OpD1M1}, - {OpD2M1}, {OpD3M1}, {OpD4E1}, {OpD5M1}, {OpD6M1}, - {OpD7M1}, {OpD8}, {OpD9M1}, {OpDAE1}, {OpDB}, - {OpDC}, {OpDDM1}, {OpDEM1}, {OpDFM1}, {OpE0X1}, - {OpE1M1}, {OpE2}, {OpE3M1}, {OpE4X1}, {OpE5M1}, - {OpE6M1}, {OpE7M1}, {OpE8X1}, {OpE9M1}, {OpEA}, - {OpEB}, {OpECX1}, {OpEDM1}, {OpEEM1}, {OpEFM1}, - {OpF0}, {OpF1M1}, {OpF2M1}, {OpF3M1}, {OpF4E1}, - {OpF5M1}, {OpF6M1}, {OpF7M1}, {OpF8}, {OpF9M1}, - {OpFAE1}, {OpFB}, {OpFCE1}, {OpFDM1}, {OpFEM1}, - {OpFFM1} + {Op00}, {Op01M1}, {Op02}, {Op03M1}, {Op04M1}, + {Op05M1}, {Op06M1}, {Op07M1}, {Op08E1}, {Op09M1}, + {Op0AM1}, {Op0BE1}, {Op0CM1}, {Op0DM1}, {Op0EM1}, + {Op0FM1}, {Op10}, {Op11M1}, {Op12M1}, {Op13M1}, + {Op14M1}, {Op15M1}, {Op16M1}, {Op17M1}, {Op18}, + {Op19M1}, {Op1AM1}, {Op1B}, {Op1CM1}, {Op1DM1}, + {Op1EM1}, {Op1FM1}, {Op20}, {Op21M1}, {Op22E1}, + {Op23M1}, {Op24M1}, {Op25M1}, {Op26M1}, {Op27M1}, + {Op28}, {Op29M1}, {Op2AM1}, {Op2BE1}, {Op2CM1}, + {Op2DM1}, {Op2EM1}, {Op2FM1}, {Op30}, {Op31M1}, + {Op32M1}, {Op33M1}, {Op34M1}, {Op35M1}, {Op36M1}, + {Op37M1}, {Op38}, {Op39M1}, {Op3AM1}, {Op3B}, + {Op3CM1}, {Op3DM1}, {Op3EM1}, {Op3FM1}, {Op40}, + {Op41M1}, {Op42}, {Op43M1}, {Op44X1}, {Op45M1}, + {Op46M1}, {Op47M1}, {Op48E1}, {Op49M1}, {Op4AM1}, + {Op4BE1}, {Op4C}, {Op4DM1}, {Op4EM1}, {Op4FM1}, + {Op50}, {Op51M1}, {Op52M1}, {Op53M1}, {Op54X1}, + {Op55M1}, {Op56M1}, {Op57M1}, {Op58}, {Op59M1}, + {Op5AE1}, {Op5B}, {Op5C}, {Op5DM1}, {Op5EM1}, + {Op5FM1}, {Op60}, {Op61M1}, {Op62E1}, {Op63M1}, + {Op64M1}, {Op65M1}, {Op66M1}, {Op67M1}, {Op68E1}, + {Op69M1}, {Op6AM1}, {Op6BE1}, {Op6C}, {Op6DM1}, + {Op6EM1}, {Op6FM1}, {Op70}, {Op71M1}, {Op72M1}, + {Op73M1}, {Op74M1}, {Op75M1}, {Op76M1}, {Op77M1}, + {Op78}, {Op79M1}, {Op7AE1}, {Op7B}, {Op7C}, + {Op7DM1}, {Op7EM1}, {Op7FM1}, {Op80}, {Op81M1}, + {Op82}, {Op83M1}, {Op84X1}, {Op85M1}, {Op86X1}, + {Op87M1}, {Op88X1}, {Op89M1}, {Op8AM1}, {Op8BE1}, + {Op8CX1}, {Op8DM1}, {Op8EX1}, {Op8FM1}, {Op90}, + {Op91M1}, {Op92M1}, {Op93M1}, {Op94X1}, {Op95M1}, + {Op96X1}, {Op97M1}, {Op98M1}, {Op99M1}, {Op9A}, + {Op9BX1}, {Op9CM1}, {Op9DM1}, {Op9EM1}, {Op9FM1}, + {OpA0X1}, {OpA1M1}, {OpA2X1}, {OpA3M1}, {OpA4X1}, + {OpA5M1}, {OpA6X1}, {OpA7M1}, {OpA8X1}, {OpA9M1}, + {OpAAX1}, {OpABE1}, {OpACX1}, {OpADM1}, {OpAEX1}, + {OpAFM1}, {OpB0}, {OpB1M1}, {OpB2M1}, {OpB3M1}, + {OpB4X1}, {OpB5M1}, {OpB6X1}, {OpB7M1}, {OpB8}, + {OpB9M1}, {OpBAX1}, {OpBBX1}, {OpBCX1}, {OpBDM1}, + {OpBEX1}, {OpBFM1}, {OpC0X1}, {OpC1M1}, {OpC2}, + {OpC3M1}, {OpC4X1}, {OpC5M1}, {OpC6M1}, {OpC7M1}, + {OpC8X1}, {OpC9M1}, {OpCAX1}, {OpCB}, {OpCCX1}, + {OpCDM1}, {OpCEM1}, {OpCFM1}, {OpD0}, {OpD1M1}, + {OpD2M1}, {OpD3M1}, {OpD4E1}, {OpD5M1}, {OpD6M1}, + {OpD7M1}, {OpD8}, {OpD9M1}, {OpDAE1}, {OpDB}, + {OpDC}, {OpDDM1}, {OpDEM1}, {OpDFM1}, {OpE0X1}, + {OpE1M1}, {OpE2}, {OpE3M1}, {OpE4X1}, {OpE5M1}, + {OpE6M1}, {OpE7M1}, {OpE8X1}, {OpE9M1}, {OpEA}, + {OpEB}, {OpECX1}, {OpEDM1}, {OpEEM1}, {OpEFM1}, + {OpF0}, {OpF1M1}, {OpF2M1}, {OpF3M1}, {OpF4E1}, + {OpF5M1}, {OpF6M1}, {OpF7M1}, {OpF8}, {OpF9M1}, + {OpFAE1}, {OpFB}, {OpFCE1}, {OpFDM1}, {OpFEM1}, + {OpFFM1} }; SOpcodes S9xOpcodesM1X0[256] = diff --git a/source/display.h b/source/display.h index cee60bb..44e0900 100644 --- a/source/display.h +++ b/source/display.h @@ -8,7 +8,7 @@ uint32_t S9xReadJoypad(int32_t port); bool S9xReadMousePosition(int32_t which1_0_to_1, int32_t* x, int32_t* y, uint32_t* buttons); bool S9xReadSuperScopePosition(int32_t* x, int32_t* y, uint32_t* buttons); -void S9xInitDisplay(void); +void S9xInitDisplay(); void S9xDeinitDisplay(); void S9xToggleSoundChannel(int32_t channel); void S9xSetInfoString(const char* string); diff --git a/source/dma.c b/source/dma.c index 3800c70..e943975 100644 --- a/source/dma.c +++ b/source/dma.c @@ -59,7 +59,7 @@ void S9xDoDMA(uint8_t Channel) int32_t inc = d->AAddressFixed ? 0 : (!d->AAddressDecrement ? 1 : -1); - if ((d->ABank == 0x7E || d->ABank == 0x7F) && d->BAddress == 0x80) + if ((d->ABank == 0x7E || d->ABank == 0x7F) && d->BAddress == 0x80 && !d->TransferDirection) { d->AAddress += d->TransferBytes; //does an invalid DMA actually take time? @@ -301,9 +301,7 @@ void S9xDoDMA(uint8_t Channel) while (--count > 0); break; case 0x18: -#ifndef CORRECT_VRAM_READS IPPU.FirstVRAMRead = true; -#endif if (!PPU.VMA.FullGraphicCount) { do @@ -326,9 +324,7 @@ void S9xDoDMA(uint8_t Channel) } break; case 0x19: -#ifndef CORRECT_VRAM_READS IPPU.FirstVRAMRead = true; -#endif if (!PPU.VMA.FullGraphicCount) { do @@ -384,9 +380,7 @@ void S9xDoDMA(uint8_t Channel) if (d->BAddress == 0x18) { // Write to V-RAM -#ifndef CORRECT_VRAM_READS IPPU.FirstVRAMRead = true; -#endif if (!PPU.VMA.FullGraphicCount) { while (count > 1) @@ -632,8 +626,6 @@ update_address: d->TransferBytes = 0; CPU.InDMA = false; - - } void S9xStartHDMA() @@ -767,15 +759,6 @@ uint8_t S9xDoHDMA(uint8_t byte) continue; } - if (p->BAddress == 0x04) - { - if (SNESGameFixes.Uniracers) - { - PPU.OAMAddr = 0x10c; - PPU.OAMFlip = 0; - } - } - switch (p->TransferMode) { case 0: @@ -881,18 +864,12 @@ void S9xResetDMA() DMA [d].HDMAIndirectAddressing = false; DMA [d].AAddressFixed = true; DMA [d].AAddressDecrement = false; - DMA [d].TransferMode = 0xff; + DMA [d].TransferMode = 7; DMA [d].ABank = 0xff; DMA [d].AAddress = 0xffff; DMA [d].Address = 0xffff; DMA [d].BAddress = 0xff; DMA [d].TransferBytes = 0xffff; - } - for (c = 0x4300; c < 0x4380; c += 0x10) - { - for (d = c; d < c + 12; d++) - Memory.FillRAM [d] = 0xff; - - Memory.FillRAM [c + 0xf] = 0xff; + DMA [d].IndirectAddress = 0xffff; } } diff --git a/source/dma.h b/source/dma.h index c93ce64..7782ee2 100644 --- a/source/dma.h +++ b/source/dma.h @@ -3,7 +3,7 @@ #ifndef _DMA_H_ #define _DMA_H_ -void S9xResetDMA(void); +void S9xResetDMA(); uint8_t S9xDoHDMA(uint8_t); void S9xStartHDMA(); void S9xDoDMA(uint8_t); diff --git a/source/dsp1.c b/source/dsp1.c index 42f20c8..9e7f05b 100644 --- a/source/dsp1.c +++ b/source/dsp1.c @@ -12,21 +12,8 @@ void (*SetDSP)(uint8_t, uint16_t) = &DSP1SetByte; uint8_t(*GetDSP)(uint16_t) = &DSP1GetByte; -void S9xInitDSP1() -{ - static bool init = false; - - if (!init) - { - InitDSP(); - init = true; - } -} - void S9xResetDSP1() { - S9xInitDSP1(); - DSP1.waiting4command = true; DSP1.in_count = 0; DSP1.out_count = 0; @@ -67,136 +54,89 @@ void DSP1SetByte(uint8_t byte, uint16_t address) // Mario Kart uses 0x00, 0x02, 0x06, 0x0c, 0x28, 0x0a switch (byte) { - case 0x00: - DSP1.in_count = 2; - break; - case 0x30: - case 0x10: - DSP1.in_count = 2; - break; - case 0x20: - DSP1.in_count = 2; - break; - case 0x24: - case 0x04: - DSP1.in_count = 2; - break; - case 0x08: - DSP1.in_count = 3; - break; - case 0x18: - DSP1.in_count = 4; - break; - case 0x28: - DSP1.in_count = 3; - break; - case 0x38: - DSP1.in_count = 4; - break; - case 0x2c: - case 0x0c: - DSP1.in_count = 3; - break; - case 0x3c: - case 0x1c: - DSP1.in_count = 6; - break; - case 0x32: - case 0x22: - case 0x12: - case 0x02: - DSP1.in_count = 7; - break; + case 0x07: case 0x0a: + case 0x0f: + case 0x1f: + case 0x27: + case 0x2f: DSP1.in_count = 1; break; - case 0x3a: - case 0x2a: - case 0x1a: - DSP1. command = 0x1a; - DSP1.in_count = 1; - break; - case 0x16: - case 0x26: - case 0x36: - case 0x06: - DSP1.in_count = 3; - break; + case 0x00: + case 0x04: + case 0x0e: + case 0x10: case 0x1e: + case 0x20: + case 0x24: case 0x2e: + case 0x30: case 0x3e: - case 0x0e: DSP1.in_count = 2; break; - case 0x05: - case 0x35: - case 0x31: - case 0x01: - DSP1.in_count = 4; - break; - case 0x15: - case 0x11: - DSP1.in_count = 4; - break; - case 0x25: - case 0x21: - DSP1.in_count = 4; - break; + case 0x03: + case 0x06: + case 0x08: case 0x09: - case 0x39: - case 0x3d: + case 0x0b: + case 0x0c: case 0x0d: - DSP1.in_count = 3; - break; + case 0x13: + case 0x16: case 0x19: + case 0x1b: case 0x1d: - DSP1.in_count = 3; - break; + case 0x23: + case 0x26: + case 0x28: case 0x29: + case 0x2b: + case 0x2c: case 0x2d: - DSP1.in_count = 3; - break; case 0x33: - case 0x03: - DSP1.in_count = 3; - break; - case 0x13: - DSP1.in_count = 3; - break; - case 0x23: - DSP1.in_count = 3; - break; + case 0x36: + case 0x39: case 0x3b: - case 0x0b: - DSP1.in_count = 3; - break; - case 0x1b: + case 0x3d: DSP1.in_count = 3; break; - case 0x2b: - DSP1.in_count = 3; + case 0x01: + case 0x05: + case 0x11: + case 0x15: + case 0x18: + case 0x21: + case 0x25: + case 0x31: + case 0x35: + case 0x38: + DSP1.in_count = 4; break; - case 0x34: case 0x14: + case 0x1c: + case 0x34: + case 0x3c: DSP1.in_count = 6; break; - case 0x07: - case 0x0f: - DSP1.in_count = 1; + case 0x02: + case 0x12: + case 0x22: + case 0x32: + DSP1.in_count = 7; break; - case 0x27: - case 0x2F: + case 0x3a: + case 0x2a: + case 0x1a: + DSP1.command = 0x1a; DSP1.in_count = 1; break; case 0x17: case 0x37: case 0x3F: DSP1.command = 0x1f; - case 0x1f: DSP1.in_count = 1; break; default: - case 0x80: DSP1.in_count = 0; DSP1.waiting4command = true; DSP1.first_parameter = true; @@ -211,17 +151,12 @@ void DSP1SetByte(uint8_t byte, uint16_t address) DSP1.in_index++; } - if (DSP1.waiting4command || - (DSP1.first_parameter && byte == 0x80)) + if (DSP1.waiting4command || (DSP1.first_parameter && byte == 0x80)) { DSP1.waiting4command = true; DSP1.first_parameter = false; } - else if (DSP1.first_parameter && (DSP1.in_count != 0 || (DSP1.in_count == 0 - && DSP1.in_index == 0))) - { - } - else + else if (!(DSP1.first_parameter && (DSP1.in_count != 0 || (DSP1.in_count == 0 && DSP1.in_index == 0)))) { if (DSP1.in_count) { @@ -245,7 +180,6 @@ void DSP1SetByte(uint8_t byte, uint16_t address) DSP1.output [0] = Op00Result & 0xFF; DSP1.output [1] = (Op00Result >> 8) & 0xFF; break; - case 0x20: // Multiple Op20Multiplicand = (int16_t)(DSP1.parameters [0] | (DSP1.parameters[1] << 8)); Op20Multiplier = (int16_t)(DSP1.parameters [2] | (DSP1.parameters[3] << 8)); @@ -256,7 +190,6 @@ void DSP1SetByte(uint8_t byte, uint16_t address) DSP1.output [0] = Op20Result & 0xFF; DSP1.output [1] = (Op20Result >> 8) & 0xFF; break; - case 0x30: case 0x10: // Inverse Op10Coefficient = (int16_t)(DSP1.parameters [0] | (DSP1.parameters[1] << 8)); @@ -270,7 +203,6 @@ void DSP1SetByte(uint8_t byte, uint16_t address) DSP1.output [2] = (uint8_t)(((int16_t) Op10ExponentR) & 0xff); DSP1.output [3] = (uint8_t)((((int16_t) Op10ExponentR) >> 8) & 0xff); break; - case 0x24: case 0x04: // Sin and Cos of angle Op04Angle = (int16_t)(DSP1.parameters [0] | (DSP1.parameters[1] << 8)); @@ -284,7 +216,6 @@ void DSP1SetByte(uint8_t byte, uint16_t address) DSP1.output [2] = (uint8_t)(Op04Cos & 0xFF); DSP1.output [3] = (uint8_t)((Op04Cos >> 8) & 0xFF); break; - case 0x08: // Radius Op08X = (int16_t)(DSP1.parameters [0] | (DSP1.parameters[1] << 8)); Op08Y = (int16_t)(DSP1.parameters [2] | (DSP1.parameters[3] << 8)); @@ -298,9 +229,7 @@ void DSP1SetByte(uint8_t byte, uint16_t address) DSP1.output [2] = (uint8_t)(((int16_t) Op08Lh) & 0xFF); DSP1.output [3] = (uint8_t)((((int16_t) Op08Lh) >> 8) & 0xFF); break; - case 0x18: // Range - Op18X = (int16_t)(DSP1.parameters [0] | (DSP1.parameters[1] << 8)); Op18Y = (int16_t)(DSP1.parameters [2] | (DSP1.parameters[3] << 8)); Op18Z = (int16_t)(DSP1.parameters [4] | (DSP1.parameters[5] << 8)); @@ -312,7 +241,6 @@ void DSP1SetByte(uint8_t byte, uint16_t address) DSP1.output [0] = (uint8_t)(Op18D & 0xFF); DSP1.output [1] = (uint8_t)((Op18D >> 8) & 0xFF); break; - case 0x38: // Range Op38X = (int16_t)(DSP1.parameters [0] | (DSP1.parameters[1] << 8)); Op38Y = (int16_t)(DSP1.parameters [2] | (DSP1.parameters[3] << 8)); @@ -325,7 +253,6 @@ void DSP1SetByte(uint8_t byte, uint16_t address) DSP1.output [0] = (uint8_t)(Op38D & 0xFF); DSP1.output [1] = (uint8_t)((Op38D >> 8) & 0xFF); break; - case 0x28: // Distance (vector length) Op28X = (int16_t)(DSP1.parameters [0] | (DSP1.parameters[1] << 8)); Op28Y = (int16_t)(DSP1.parameters [2] | (DSP1.parameters[3] << 8)); @@ -337,7 +264,6 @@ void DSP1SetByte(uint8_t byte, uint16_t address) DSP1.output [0] = (uint8_t)(Op28R & 0xFF); DSP1.output [1] = (uint8_t)((Op28R >> 8) & 0xFF); break; - case 0x2c: case 0x0c: // Rotate (2D rotate) Op0CA = (int16_t)(DSP1.parameters [0] | (DSP1.parameters[1] << 8)); @@ -352,7 +278,6 @@ void DSP1SetByte(uint8_t byte, uint16_t address) DSP1.output [2] = (uint8_t)(Op0CY2 & 0xFF); DSP1.output [3] = (uint8_t)((Op0CY2 >> 8) & 0xFF); break; - case 0x3c: case 0x1c: // Polar (3D rotate) Op1CZ = (DSP1.parameters [0] | (DSP1.parameters[1] << 8)); @@ -373,7 +298,6 @@ void DSP1SetByte(uint8_t byte, uint16_t address) DSP1.output [4] = (uint8_t)(Op1CZAR & 0xFF); DSP1.output [5] = (uint8_t)((Op1CZAR >> 8) & 0xFF); break; - case 0x32: case 0x22: case 0x12: @@ -398,7 +322,6 @@ void DSP1SetByte(uint8_t byte, uint16_t address) DSP1.output [6] = (uint8_t)(Op02CY & 0xFF); DSP1.output [7] = (uint8_t)((Op02CY >> 8) & 0xFF); break; - case 0x3a: //1a Mirror case 0x2a: //1a Mirror case 0x1a: // Raster mode 7 matrix data @@ -418,7 +341,6 @@ void DSP1SetByte(uint8_t byte, uint16_t address) DSP1.output [7] = (uint8_t)((Op0AD >> 8) & 0xFF); DSP1.in_index = 0; break; - case 0x16: case 0x26: case 0x36: @@ -434,10 +356,9 @@ void DSP1SetByte(uint8_t byte, uint16_t address) DSP1.output [1] = (uint8_t)((Op06H >> 8) & 0xFF); DSP1.output [2] = (uint8_t)(Op06V & 0xFF); DSP1.output [3] = (uint8_t)((Op06V >> 8) & 0xFF); - DSP1.output [4] = (uint8_t)(Op06S & 0xFF); - DSP1.output [5] = (uint8_t)((Op06S >> 8) & 0xFF); + DSP1.output [4] = (uint8_t)(Op06M & 0xFF); + DSP1.output [5] = (uint8_t)((Op06M >> 8) & 0xFF); break; - case 0x1e: case 0x2e: case 0x3e: @@ -453,7 +374,6 @@ void DSP1SetByte(uint8_t byte, uint16_t address) DSP1.output [2] = (uint8_t)(Op0EY & 0xFF); DSP1.output [3] = (uint8_t)((Op0EY >> 8) & 0xFF); break; - // Extra commands used by Pilot Wings case 0x05: case 0x35: @@ -466,7 +386,6 @@ void DSP1SetByte(uint8_t byte, uint16_t address) DSPOp01(); break; - case 0x15: case 0x11: // Set attitude matrix B Op11m = (int16_t)(DSP1.parameters [0] | (DSP1.parameters[1] << 8)); @@ -476,7 +395,6 @@ void DSP1SetByte(uint8_t byte, uint16_t address) DSPOp11(); break; - case 0x25: case 0x21: // Set attitude matrix C Op21m = (int16_t)(DSP1.parameters [0] | (DSP1.parameters[1] << 8)); @@ -486,7 +404,6 @@ void DSP1SetByte(uint8_t byte, uint16_t address) DSPOp21(); break; - case 0x09: case 0x39: case 0x3d: @@ -505,7 +422,6 @@ void DSP1SetByte(uint8_t byte, uint16_t address) DSP1.output [4] = (uint8_t)(Op0DU & 0xFF); DSP1.output [5] = (uint8_t)((Op0DU >> 8) & 0xFF); break; - case 0x19: case 0x1d: // Objective matrix B Op1DX = (int16_t)(DSP1.parameters [0] | (DSP1.parameters[1] << 8)); @@ -522,7 +438,6 @@ void DSP1SetByte(uint8_t byte, uint16_t address) DSP1.output [4] = (uint8_t)(Op1DU & 0xFF); DSP1.output [5] = (uint8_t)((Op1DU >> 8) & 0xFF); break; - case 0x29: case 0x2d: // Objective matrix C Op2DX = (int16_t)(DSP1.parameters [0] | (DSP1.parameters[1] << 8)); @@ -539,7 +454,6 @@ void DSP1SetByte(uint8_t byte, uint16_t address) DSP1.output [4] = (uint8_t)(Op2DU & 0xFF); DSP1.output [5] = (uint8_t)((Op2DU >> 8) & 0xFF); break; - case 0x33: case 0x03: // Subjective matrix A Op03F = (int16_t)(DSP1.parameters [0] | (DSP1.parameters[1] << 8)); @@ -556,7 +470,6 @@ void DSP1SetByte(uint8_t byte, uint16_t address) DSP1.output [4] = (uint8_t)(Op03Z & 0xFF); DSP1.output [5] = (uint8_t)((Op03Z >> 8) & 0xFF); break; - case 0x13: // Subjective matrix B Op13F = (int16_t)(DSP1.parameters [0] | (DSP1.parameters[1] << 8)); Op13L = (int16_t)(DSP1.parameters [2] | (DSP1.parameters[3] << 8)); @@ -572,7 +485,6 @@ void DSP1SetByte(uint8_t byte, uint16_t address) DSP1.output [4] = (uint8_t)(Op13Z & 0xFF); DSP1.output [5] = (uint8_t)((Op13Z >> 8) & 0xFF); break; - case 0x23: // Subjective matrix C Op23F = (int16_t)(DSP1.parameters [0] | (DSP1.parameters[1] << 8)); Op23L = (int16_t)(DSP1.parameters [2] | (DSP1.parameters[3] << 8)); @@ -588,7 +500,6 @@ void DSP1SetByte(uint8_t byte, uint16_t address) DSP1.output [4] = (uint8_t)(Op23Z & 0xFF); DSP1.output [5] = (uint8_t)((Op23Z >> 8) & 0xFF); break; - case 0x3b: case 0x0b: Op0BX = (int16_t)(DSP1.parameters [0] | (DSP1.parameters[1] << 8)); @@ -601,7 +512,6 @@ void DSP1SetByte(uint8_t byte, uint16_t address) DSP1.output [0] = (uint8_t)(Op0BS & 0xFF); DSP1.output [1] = (uint8_t)((Op0BS >> 8) & 0xFF); break; - case 0x1b: Op1BX = (int16_t)(DSP1.parameters [0] | (DSP1.parameters[1] << 8)); Op1BY = (int16_t)(DSP1.parameters [2] | (DSP1.parameters[3] << 8)); @@ -613,7 +523,6 @@ void DSP1SetByte(uint8_t byte, uint16_t address) DSP1.output [0] = (uint8_t)(Op1BS & 0xFF); DSP1.output [1] = (uint8_t)((Op1BS >> 8) & 0xFF); break; - case 0x2b: Op2BX = (int16_t)(DSP1.parameters [0] | (DSP1.parameters[1] << 8)); Op2BY = (int16_t)(DSP1.parameters [2] | (DSP1.parameters[3] << 8)); @@ -625,7 +534,6 @@ void DSP1SetByte(uint8_t byte, uint16_t address) DSP1.output [0] = (uint8_t)(Op2BS & 0xFF); DSP1.output [1] = (uint8_t)((Op2BS >> 8) & 0xFF); break; - case 0x34: case 0x14: Op14Zr = (int16_t)(DSP1.parameters [0] | (DSP1.parameters[1] << 8)); @@ -645,7 +553,6 @@ void DSP1SetByte(uint8_t byte, uint16_t address) DSP1.output [4] = (uint8_t)(Op14Yrr & 0xFF); DSP1.output [5] = (uint8_t)((Op14Yrr >> 8) & 0xFF); break; - case 0x27: case 0x2F: Op2FUnknown = (int16_t)(DSP1.parameters [0] | (DSP1.parameters[1] << 8)); @@ -656,8 +563,6 @@ void DSP1SetByte(uint8_t byte, uint16_t address) DSP1.output [0] = (uint8_t)(Op2FSize & 0xFF); DSP1.output [1] = (uint8_t)((Op2FSize >> 8) & 0xFF); break; - - case 0x07: case 0x0F: Op0FRamsize = (int16_t)(DSP1.parameters [0] | (DSP1.parameters[1] << 8)); @@ -668,7 +573,6 @@ void DSP1SetByte(uint8_t byte, uint16_t address) DSP1.output [0] = (uint8_t)(Op0FPass & 0xFF); DSP1.output [1] = (uint8_t)((Op0FPass >> 8) & 0xFF); break; - default: break; } @@ -681,8 +585,7 @@ void DSP1SetByte(uint8_t byte, uint16_t address) uint8_t DSP1GetByte(uint16_t address) { uint8_t t; - if ((address & 0xf000) == 0x6000 || - (address & 0x7fff) < 0x4000) + if ((address & 0xf000) == 0x6000 || (address & 0x7fff) < 0x4000) { if (DSP1.out_count) { @@ -715,11 +618,10 @@ uint8_t DSP1GetByte(uint16_t address) DSP1.waiting4command = true; } else - { t = 0xff; - } } - else t = 0x80; + else + t = 0x80; return t; } @@ -735,28 +637,22 @@ void DSP2SetByte(uint8_t byte, uint16_t address) DSP1.waiting4command = false; switch (byte) { - case 0x01: - DSP1.in_count = 32; + default: + DSP1.in_count = 0; break; case 0x03: - DSP1.in_count = 1; - break; case 0x05: - DSP1.in_count = 1; - break; - case 0x09: - DSP1.in_count = 4; - break; case 0x06: DSP1.in_count = 1; break; - case 0x0D: + case 0x0d: DSP1.in_count = 2; break; - default: - printf("Op%02X\n", byte); - case 0x0f: - DSP1.in_count = 0; + case 0x09: + DSP1.in_count = 4; + break; + case 0x01: + DSP1.in_count = 32; break; } } @@ -863,8 +759,7 @@ void DSP2SetByte(uint8_t byte, uint16_t address) uint8_t DSP2GetByte(uint16_t address) { uint8_t t; - if ((address & 0xf000) == 0x6000 || - (address >= 0x8000 && address < 0xc000)) + if ((address & 0xf000) == 0x6000 || (address >= 0x8000 && address < 0xc000)) { if (DSP1.out_count) { @@ -876,253 +771,11 @@ uint8_t DSP2GetByte(uint16_t address) else t = 0xff; } - else t = 0x80; - return t; -} - -//Disable non-working chips? -#ifdef DSP_DUMMY_LOOPS -uint16_t Dsp3Rom[1024] = -{ - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, - 0x0040, 0x0080, 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, - 0x4000, 0x7fff, 0x4000, 0x2000, 0x1000, 0x0800, 0x0400, 0x0200, - 0x0100, 0x0080, 0x0040, 0x0020, 0x0001, 0x0008, 0x0004, 0x0002, - 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x8000, 0xffe5, 0x0100, 0x7fff, 0x7f02, 0x7e08, - 0x7d12, 0x7c1f, 0x7b30, 0x7a45, 0x795d, 0x7878, 0x7797, 0x76ba, - 0x75df, 0x7507, 0x7433, 0x7361, 0x7293, 0x71c7, 0x70fe, 0x7038, - 0x6f75, 0x6eb4, 0x6df6, 0x6d3a, 0x6c81, 0x6bca, 0x6b16, 0x6a64, - 0x69b4, 0x6907, 0x685b, 0x67b2, 0x670b, 0x6666, 0x65c4, 0x6523, - 0x6484, 0x63e7, 0x634c, 0x62b3, 0x621c, 0x6186, 0x60f2, 0x6060, - 0x5fd0, 0x5f41, 0x5eb5, 0x5e29, 0x5d9f, 0x5d17, 0x5c91, 0x5c0c, - 0x5b88, 0x5b06, 0x5a85, 0x5a06, 0x5988, 0x590b, 0x5890, 0x5816, - 0x579d, 0x5726, 0x56b0, 0x563b, 0x55c8, 0x5555, 0x54e4, 0x5474, - 0x5405, 0x5398, 0x532b, 0x52bf, 0x5255, 0x51ec, 0x5183, 0x511c, - 0x50b6, 0x5050, 0x4fec, 0x4f89, 0x4f26, 0x4ec5, 0x4e64, 0x4e05, - 0x4da6, 0x4d48, 0x4cec, 0x4c90, 0x4c34, 0x4bda, 0x4b81, 0x4b28, - 0x4ad0, 0x4a79, 0x4a23, 0x49cd, 0x4979, 0x4925, 0x48d1, 0x487f, - 0x482d, 0x47dc, 0x478c, 0x473c, 0x46ed, 0x469f, 0x4651, 0x4604, - 0x45b8, 0x456c, 0x4521, 0x44d7, 0x448d, 0x4444, 0x43fc, 0x43b4, - 0x436d, 0x4326, 0x42e0, 0x429a, 0x4255, 0x4211, 0x41cd, 0x4189, - 0x4146, 0x4104, 0x40c2, 0x4081, 0x4040, 0x3fff, 0x41f7, 0x43e1, - 0x45bd, 0x478d, 0x4951, 0x4b0b, 0x4cbb, 0x4e61, 0x4fff, 0x5194, - 0x5322, 0x54a9, 0x5628, 0x57a2, 0x5914, 0x5a81, 0x5be9, 0x5d4a, - 0x5ea7, 0x5fff, 0x6152, 0x62a0, 0x63ea, 0x6530, 0x6672, 0x67b0, - 0x68ea, 0x6a20, 0x6b53, 0x6c83, 0x6daf, 0x6ed9, 0x6fff, 0x7122, - 0x7242, 0x735f, 0x747a, 0x7592, 0x76a7, 0x77ba, 0x78cb, 0x79d9, - 0x7ae5, 0x7bee, 0x7cf5, 0x7dfa, 0x7efe, 0x7fff, 0x0000, 0x0324, - 0x0647, 0x096a, 0x0c8b, 0x0fab, 0x12c8, 0x15e2, 0x18f8, 0x1c0b, - 0x1f19, 0x2223, 0x2528, 0x2826, 0x2b1f, 0x2e11, 0x30fb, 0x33de, - 0x36ba, 0x398c, 0x3c56, 0x3f17, 0x41ce, 0x447a, 0x471c, 0x49b4, - 0x4c3f, 0x4ebf, 0x5133, 0x539b, 0x55f5, 0x5842, 0x5a82, 0x5cb4, - 0x5ed7, 0x60ec, 0x62f2, 0x64e8, 0x66cf, 0x68a6, 0x6a6d, 0x6c24, - 0x6dca, 0x6f5f, 0x70e2, 0x7255, 0x73b5, 0x7504, 0x7641, 0x776c, - 0x7884, 0x798a, 0x7a7d, 0x7b5d, 0x7c29, 0x7ce3, 0x7d8a, 0x7e1d, - 0x7e9d, 0x7f09, 0x7f62, 0x7fa7, 0x7fd8, 0x7ff6, 0x7fff, 0x7ff6, - 0x7fd8, 0x7fa7, 0x7f62, 0x7f09, 0x7e9d, 0x7e1d, 0x7d8a, 0x7ce3, - 0x7c29, 0x7b5d, 0x7a7d, 0x798a, 0x7884, 0x776c, 0x7641, 0x7504, - 0x73b5, 0x7255, 0x70e2, 0x6f5f, 0x6dca, 0x6c24, 0x6a6d, 0x68a6, - 0x66cf, 0x64e8, 0x62f2, 0x60ec, 0x5ed7, 0x5cb4, 0x5a82, 0x5842, - 0x55f5, 0x539b, 0x5133, 0x4ebf, 0x4c3f, 0x49b4, 0x471c, 0x447a, - 0x41ce, 0x3f17, 0x3c56, 0x398c, 0x36ba, 0x33de, 0x30fb, 0x2e11, - 0x2b1f, 0x2826, 0x2528, 0x2223, 0x1f19, 0x1c0b, 0x18f8, 0x15e2, - 0x12c8, 0x0fab, 0x0c8b, 0x096a, 0x0647, 0x0324, 0x7fff, 0x7ff6, - 0x7fd8, 0x7fa7, 0x7f62, 0x7f09, 0x7e9d, 0x7e1d, 0x7d8a, 0x7ce3, - 0x7c29, 0x7b5d, 0x7a7d, 0x798a, 0x7884, 0x776c, 0x7641, 0x7504, - 0x73b5, 0x7255, 0x70e2, 0x6f5f, 0x6dca, 0x6c24, 0x6a6d, 0x68a6, - 0x66cf, 0x64e8, 0x62f2, 0x60ec, 0x5ed7, 0x5cb4, 0x5a82, 0x5842, - 0x55f5, 0x539b, 0x5133, 0x4ebf, 0x4c3f, 0x49b4, 0x471c, 0x447a, - 0x41ce, 0x3f17, 0x3c56, 0x398c, 0x36ba, 0x33de, 0x30fb, 0x2e11, - 0x2b1f, 0x2826, 0x2528, 0x2223, 0x1f19, 0x1c0b, 0x18f8, 0x15e2, - 0x12c8, 0x0fab, 0x0c8b, 0x096a, 0x0647, 0x0324, 0x0000, 0xfcdc, - 0xf9b9, 0xf696, 0xf375, 0xf055, 0xed38, 0xea1e, 0xe708, 0xe3f5, - 0xe0e7, 0xdddd, 0xdad8, 0xd7da, 0xd4e1, 0xd1ef, 0xcf05, 0xcc22, - 0xc946, 0xc674, 0xc3aa, 0xc0e9, 0xbe32, 0xbb86, 0xb8e4, 0xb64c, - 0xb3c1, 0xb141, 0xaecd, 0xac65, 0xaa0b, 0xa7be, 0xa57e, 0xa34c, - 0xa129, 0x9f14, 0x9d0e, 0x9b18, 0x9931, 0x975a, 0x9593, 0x93dc, - 0x9236, 0x90a1, 0x8f1e, 0x8dab, 0x8c4b, 0x8afc, 0x89bf, 0x8894, - 0x877c, 0x8676, 0x8583, 0x84a3, 0x83d7, 0x831d, 0x8276, 0x81e3, - 0x8163, 0x80f7, 0x809e, 0x8059, 0x8028, 0x800a, 0x6488, 0x0080, - 0x03ff, 0x0116, 0x0002, 0x0080, 0x4000, 0x3fd7, 0x3faf, 0x3f86, - 0x3f5d, 0x3f34, 0x3f0c, 0x3ee3, 0x3eba, 0x3e91, 0x3e68, 0x3e40, - 0x3e17, 0x3dee, 0x3dc5, 0x3d9c, 0x3d74, 0x3d4b, 0x3d22, 0x3cf9, - 0x3cd0, 0x3ca7, 0x3c7f, 0x3c56, 0x3c2d, 0x3c04, 0x3bdb, 0x3bb2, - 0x3b89, 0x3b60, 0x3b37, 0x3b0e, 0x3ae5, 0x3abc, 0x3a93, 0x3a69, - 0x3a40, 0x3a17, 0x39ee, 0x39c5, 0x399c, 0x3972, 0x3949, 0x3920, - 0x38f6, 0x38cd, 0x38a4, 0x387a, 0x3851, 0x3827, 0x37fe, 0x37d4, - 0x37aa, 0x3781, 0x3757, 0x372d, 0x3704, 0x36da, 0x36b0, 0x3686, - 0x365c, 0x3632, 0x3609, 0x35df, 0x35b4, 0x358a, 0x3560, 0x3536, - 0x350c, 0x34e1, 0x34b7, 0x348d, 0x3462, 0x3438, 0x340d, 0x33e3, - 0x33b8, 0x338d, 0x3363, 0x3338, 0x330d, 0x32e2, 0x32b7, 0x328c, - 0x3261, 0x3236, 0x320b, 0x31df, 0x31b4, 0x3188, 0x315d, 0x3131, - 0x3106, 0x30da, 0x30ae, 0x3083, 0x3057, 0x302b, 0x2fff, 0x2fd2, - 0x2fa6, 0x2f7a, 0x2f4d, 0x2f21, 0x2ef4, 0x2ec8, 0x2e9b, 0x2e6e, - 0x2e41, 0x2e14, 0x2de7, 0x2dba, 0x2d8d, 0x2d60, 0x2d32, 0x2d05, - 0x2cd7, 0x2ca9, 0x2c7b, 0x2c4d, 0x2c1f, 0x2bf1, 0x2bc3, 0x2b94, - 0x2b66, 0x2b37, 0x2b09, 0x2ada, 0x2aab, 0x2a7c, 0x2a4c, 0x2a1d, - 0x29ed, 0x29be, 0x298e, 0x295e, 0x292e, 0x28fe, 0x28ce, 0x289d, - 0x286d, 0x283c, 0x280b, 0x27da, 0x27a9, 0x2777, 0x2746, 0x2714, - 0x26e2, 0x26b0, 0x267e, 0x264c, 0x2619, 0x25e7, 0x25b4, 0x2581, - 0x254d, 0x251a, 0x24e6, 0x24b2, 0x247e, 0x244a, 0x2415, 0x23e1, - 0x23ac, 0x2376, 0x2341, 0x230b, 0x22d6, 0x229f, 0x2269, 0x2232, - 0x21fc, 0x21c4, 0x218d, 0x2155, 0x211d, 0x20e5, 0x20ad, 0x2074, - 0x203b, 0x2001, 0x1fc7, 0x1f8d, 0x1f53, 0x1f18, 0x1edd, 0x1ea1, - 0x1e66, 0x1e29, 0x1ded, 0x1db0, 0x1d72, 0x1d35, 0x1cf6, 0x1cb8, - 0x1c79, 0x1c39, 0x1bf9, 0x1bb8, 0x1b77, 0x1b36, 0x1af4, 0x1ab1, - 0x1a6e, 0x1a2a, 0x19e6, 0x19a1, 0x195c, 0x1915, 0x18ce, 0x1887, - 0x183f, 0x17f5, 0x17ac, 0x1761, 0x1715, 0x16c9, 0x167c, 0x162e, - 0x15df, 0x158e, 0x153d, 0x14eb, 0x1497, 0x1442, 0x13ec, 0x1395, - 0x133c, 0x12e2, 0x1286, 0x1228, 0x11c9, 0x1167, 0x1104, 0x109e, - 0x1036, 0x0fcc, 0x0f5f, 0x0eef, 0x0e7b, 0x0e04, 0x0d89, 0x0d0a, - 0x0c86, 0x0bfd, 0x0b6d, 0x0ad6, 0x0a36, 0x098d, 0x08d7, 0x0811, - 0x0736, 0x063e, 0x0519, 0x039a, 0x0000, 0x7fff, 0x0100, 0x0080, - 0x021d, 0x00c8, 0x00ce, 0x0048, 0x0a26, 0x277a, 0x00ce, 0x6488, - 0x14ac, 0x0001, 0x00f9, 0x00fc, 0x00ff, 0x00fc, 0x00f9, 0xffff, - 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, - 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, - 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, - 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, - 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, - 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, - 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, - 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, - 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, - 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, - 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, - 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, - 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, - 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, - 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, - 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, - 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, - 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, - 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, - 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, - 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, - 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, - 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, - 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, - 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, - 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff - -}; - -void DSP3SetByte(uint8_t byte, uint16_t address) -{ - if ((address & 0xf000) == 0x6000 || - (address >= 0x8000 && address < 0xc000)) - { - if (DSP1.waiting4command) - { - DSP1.command = byte; - DSP1.in_index = 0; - DSP1.waiting4command = false; - switch (byte) - { - case 0x2F: - DSP1.in_count = 2; - break; - case 0x1F: - DSP1.in_count = 2; - break; - case 0x0F: - DSP1.in_count = 2; - break; - case 0x38: - DSP1.in_count = 4; - break; - default: - break; - } - } - else - { - DSP1.parameters [DSP1.in_index] = byte; - DSP1.in_index++; - } - - if (DSP1.in_count == DSP1.in_index) - { - // Actually execute the command - DSP1.waiting4command = true; - DSP1.out_index = 0; - switch (DSP1.command) - { - case 0x2F: - DSP1.out_count = 2; - break; - case 0x1F: - DSP1.out_count = 2048; - break; - case 0x0F: - DSP1.out_count = 2; - DSP1.output[0] = 0; - DSP1.output[1] = 0; - break; - case 0x38: - { - DSP1.out_count = 2; - // 176B - DSP1.output[0] = 0; - DSP1.output[1] = 0x80; - - break; - } - default: - break; - } - } - } -} - -uint8_t DSP3GetByte(uint16_t address) -{ - uint8_t t; - if ((address & 0xf000) == 0x6000 || - (address >= 0x8000 && address < 0xc000)) - { - if (DSP1.command == 0x38 && DSP1.out_index == 1) - t = 4; - - if (DSP1.out_count) - { - if (DSP1.command == 0x1f) - { - if ((DSP1.out_index % 2) != 0) - t = (uint8_t)Dsp3Rom[DSP1.out_index >> 1]; - else - t = Dsp3Rom[DSP1.out_index >> 1] >> 8; - DSP1.out_index++; - } - else - { - t = (uint8_t) DSP1.output [DSP1.out_index]; - DSP1.out_index++; - DSP1.out_index %= 512; - if (DSP1.out_count == DSP1.out_index) - DSP1.out_count = 0; - } - } - else - t = 0xff; - } else - { t = 0x80; - } return t; } -#endif - typedef struct { bool waiting4command; @@ -1151,8 +804,7 @@ void DSP4SetByte(uint8_t byte, uint16_t address) DSP4_init = true; } - if ((address & 0xf000) == 0x6000 || - (address >= 0x8000 && address < 0xc000)) + if ((address & 0xf000) == 0x6000 || (address >= 0x8000 && address < 0xc000)) { if (DSP4.out_index < DSP4.out_count) { @@ -1167,7 +819,7 @@ void DSP4SetByte(uint8_t byte, uint16_t address) DSP4.command |= (byte << 8); DSP4.in_index = 0; DSP4.waiting4command = false; - DSP4.half_command = 0; + DSP4.half_command = false; DSP4.out_count = 0; DSP4.out_index = 0; DSP4_Logic = 0; @@ -1181,11 +833,7 @@ void DSP4SetByte(uint8_t byte, uint16_t address) DSP4.in_count = 36; break; case 0x0003: - DSP4.in_count = 0; - break; case 0x0005: - DSP4.in_count = 0; - break; case 0x0006: DSP4.in_count = 0; break; @@ -1199,8 +847,6 @@ void DSP4SetByte(uint8_t byte, uint16_t address) DSP4.in_count = 14; break; case 0x000A: - DSP4.in_count = 6; - break; case 0x000B: DSP4.in_count = 6; break; @@ -1221,7 +867,7 @@ void DSP4SetByte(uint8_t byte, uint16_t address) else { DSP4.command = byte; - DSP4.half_command = 1; + DSP4.half_command = true; } } else @@ -1252,9 +898,8 @@ void DSP4SetByte(uint8_t byte, uint16_t address) DSP4.out_count = 4; DSP4_WRITE_WORD(0, product); DSP4_WRITE_WORD(2, product >> 16); + break; } - break; - // unknown: horizontal mapping command case 0x0011: { @@ -1271,40 +916,33 @@ void DSP4SetByte(uint8_t byte, uint16_t address) DSP4_WRITE_WORD(0, m); break; } - // track projection case 0x0001: DSP4_Op01(); break; - // track projection (pass 2) case 0x0007: DSP4_Op07(); break; - // zone projections (fuel/repair/lap/teleport/...) case 0x0008: DSP4_Op08(); break; - // sprite transformation case 0x0009: DSP4_Op09(); break; - // fast track projection case 0x000D: DSP4_Op0D(); break; - // internal memory management (01) case 0x0003: { // reset op09 data - op09_mode = 0; + op09_mode = false; break; } - // internal memory management (06) case 0x0005: { @@ -1316,15 +954,13 @@ void DSP4SetByte(uint8_t byte, uint16_t address) op06_OAM[lcv] = 0; break; } - // internal memory management (0D) case 0x000E: { // reset op09 data - op09_mode = 1; + op09_mode = true; break; } - // sprite OAM post-table data case 0x0006: { @@ -1334,7 +970,6 @@ void DSP4SetByte(uint8_t byte, uint16_t address) DSP4.output[lcv] = op06_OAM[lcv]; } break; - // unknown case 0x000A: { @@ -1372,7 +1007,7 @@ void DSP4SetByte(uint8_t byte, uint16_t address) DSP4_WRITE_WORD(4, oam); // OAM: size,msb data - DSP4_Op06(0, 0); + DSP4_Op06(false, false); } // 4p mode else @@ -1381,9 +1016,8 @@ void DSP4SetByte(uint8_t byte, uint16_t address) DSP4.out_count = 0; DSP4_WRITE_WORD(0, 0); } + break; } - break; - default: break; } diff --git a/source/dsp1emu.c b/source/dsp1emu.c index a2767b0..3e34795 100644 --- a/source/dsp1emu.c +++ b/source/dsp1emu.c @@ -6,9 +6,6 @@ #include <string.h> #include <stdlib.h> -#define __OPT__ -#define __OPT06__ - const uint16_t DSP1ROM[1024] = { 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, @@ -142,46 +139,9 @@ const uint16_t DSP1ROM[1024] = }; /***************************************************************************\ -* Math tables * -\***************************************************************************/ - -#define INCR 2048 -#define Angle(x) (((x)/(65536/INCR)) & (INCR-1)) -#define Cos(x) ((double) CosTable2[x]) -#define Sin(x) ((double) SinTable2[x]) -#ifdef PI -#undef PI -#endif -#define PI 3.1415926535897932384626433832795 -double CosTable2[INCR]; -double SinTable2[INCR]; - - -double Atan(double x) -{ - if ((x >= 1) || (x <= 1)) - return (x / (1 + 0.28 * x * x)); - else - return (PI / 2 - Atan(1 / x)); -} - -/***************************************************************************\ * DSP1 code * \***************************************************************************/ -void InitDSP(void) -{ -#ifdef __OPT__ - uint32_t i; - for (i = 0; i < INCR; i++) - { - CosTable2[i] = (cos((double)(2 * PI * i / INCR))); - SinTable2[i] = (sin((double)(2 * PI * i / INCR))); - } -#endif -} - - int16_t Op00Multiplicand; int16_t Op00Multiplier; int16_t Op00Result; @@ -189,7 +149,6 @@ int16_t Op00Result; void DSPOp00() { Op00Result = Op00Multiplicand * Op00Multiplier >> 15; - } int16_t Op20Multiplicand; @@ -200,7 +159,6 @@ void DSPOp20() { Op20Result = Op20Multiplicand * Op20Multiplier >> 15; Op20Result++; - } int16_t Op10Coefficient; @@ -208,8 +166,7 @@ int16_t Op10Exponent; int16_t Op10CoefficientR; int16_t Op10ExponentR; -void DSP1_Inverse(int16_t Coefficient, int16_t Exponent, int16_t* iCoefficient, - int16_t* iExponent) +void DSP1_Inverse(int16_t Coefficient, int16_t Exponent, int16_t* iCoefficient, int16_t* iExponent) { // Step One: Division by Zero if (Coefficient == 0x0000) @@ -308,22 +265,22 @@ const int16_t DSP1_MulTable[256] = const int16_t DSP1_SinTable[256] = { - 0x0000, 0x0324, 0x0647, 0x096a, 0x0c8b, 0x0fab, 0x12c8, 0x15e2, - 0x18f8, 0x1c0b, 0x1f19, 0x2223, 0x2528, 0x2826, 0x2b1f, 0x2e11, - 0x30fb, 0x33de, 0x36ba, 0x398c, 0x3c56, 0x3f17, 0x41ce, 0x447a, - 0x471c, 0x49b4, 0x4c3f, 0x4ebf, 0x5133, 0x539b, 0x55f5, 0x5842, - 0x5a82, 0x5cb4, 0x5ed7, 0x60ec, 0x62f2, 0x64e8, 0x66cf, 0x68a6, - 0x6a6d, 0x6c24, 0x6dca, 0x6f5f, 0x70e2, 0x7255, 0x73b5, 0x7504, - 0x7641, 0x776c, 0x7884, 0x798a, 0x7a7d, 0x7b5d, 0x7c29, 0x7ce3, - 0x7d8a, 0x7e1d, 0x7e9d, 0x7f09, 0x7f62, 0x7fa7, 0x7fd8, 0x7ff6, - 0x7fff, 0x7ff6, 0x7fd8, 0x7fa7, 0x7f62, 0x7f09, 0x7e9d, 0x7e1d, - 0x7d8a, 0x7ce3, 0x7c29, 0x7b5d, 0x7a7d, 0x798a, 0x7884, 0x776c, - 0x7641, 0x7504, 0x73b5, 0x7255, 0x70e2, 0x6f5f, 0x6dca, 0x6c24, - 0x6a6d, 0x68a6, 0x66cf, 0x64e8, 0x62f2, 0x60ec, 0x5ed7, 0x5cb4, - 0x5a82, 0x5842, 0x55f5, 0x539b, 0x5133, 0x4ebf, 0x4c3f, 0x49b4, - 0x471c, 0x447a, 0x41ce, 0x3f17, 0x3c56, 0x398c, 0x36ba, 0x33de, - 0x30fb, 0x2e11, 0x2b1f, 0x2826, 0x2528, 0x2223, 0x1f19, 0x1c0b, - 0x18f8, 0x15e2, 0x12c8, 0x0fab, 0x0c8b, 0x096a, 0x0647, 0x0324, + 0x0000, 0x0324, 0x0647, 0x096a, 0x0c8b, 0x0fab, 0x12c8, 0x15e2, + 0x18f8, 0x1c0b, 0x1f19, 0x2223, 0x2528, 0x2826, 0x2b1f, 0x2e11, + 0x30fb, 0x33de, 0x36ba, 0x398c, 0x3c56, 0x3f17, 0x41ce, 0x447a, + 0x471c, 0x49b4, 0x4c3f, 0x4ebf, 0x5133, 0x539b, 0x55f5, 0x5842, + 0x5a82, 0x5cb4, 0x5ed7, 0x60ec, 0x62f2, 0x64e8, 0x66cf, 0x68a6, + 0x6a6d, 0x6c24, 0x6dca, 0x6f5f, 0x70e2, 0x7255, 0x73b5, 0x7504, + 0x7641, 0x776c, 0x7884, 0x798a, 0x7a7d, 0x7b5d, 0x7c29, 0x7ce3, + 0x7d8a, 0x7e1d, 0x7e9d, 0x7f09, 0x7f62, 0x7fa7, 0x7fd8, 0x7ff6, + 0x7fff, 0x7ff6, 0x7fd8, 0x7fa7, 0x7f62, 0x7f09, 0x7e9d, 0x7e1d, + 0x7d8a, 0x7ce3, 0x7c29, 0x7b5d, 0x7a7d, 0x798a, 0x7884, 0x776c, + 0x7641, 0x7504, 0x73b5, 0x7255, 0x70e2, 0x6f5f, 0x6dca, 0x6c24, + 0x6a6d, 0x68a6, 0x66cf, 0x64e8, 0x62f2, 0x60ec, 0x5ed7, 0x5cb4, + 0x5a82, 0x5842, 0x55f5, 0x539b, 0x5133, 0x4ebf, 0x4c3f, 0x49b4, + 0x471c, 0x447a, 0x41ce, 0x3f17, 0x3c56, 0x398c, 0x36ba, 0x33de, + 0x30fb, 0x2e11, 0x2b1f, 0x2826, 0x2528, 0x2223, 0x1f19, 0x1c0b, + 0x18f8, 0x15e2, 0x12c8, 0x0fab, 0x0c8b, 0x096a, 0x0647, 0x0324, -0x0000, -0x0324, -0x0647, -0x096a, -0x0c8b, -0x0fab, -0x12c8, -0x15e2, -0x18f8, -0x1c0b, -0x1f19, -0x2223, -0x2528, -0x2826, -0x2b1f, -0x2e11, -0x30fb, -0x33de, -0x36ba, -0x398c, -0x3c56, -0x3f17, -0x41ce, -0x447a, @@ -349,8 +306,7 @@ int16_t DSP1_Sin(int16_t Angle) if (Angle == -32768) return 0; return -DSP1_Sin(-Angle); } - int32_t S = DSP1_SinTable[Angle >> 8] + (DSP1_MulTable[Angle & 0xff] * - DSP1_SinTable[0x40 + (Angle >> 8)] >> 15); + int32_t S = DSP1_SinTable[Angle >> 8] + (DSP1_MulTable[Angle & 0xff] * DSP1_SinTable[0x40 + (Angle >> 8)] >> 15); if (S > 32767) S = 32767; return (int16_t) S; } @@ -362,8 +318,7 @@ int16_t DSP1_Cos(int16_t Angle) if (Angle == -32768) return -32768; Angle = -Angle; } - int32_t S = DSP1_SinTable[0x40 + (Angle >> 8)] - (DSP1_MulTable[Angle & 0xff] * - DSP1_SinTable[Angle >> 8] >> 15); + int32_t S = DSP1_SinTable[0x40 + (Angle >> 8)] - (DSP1_MulTable[Angle & 0xff] * DSP1_SinTable[Angle >> 8] >> 15); if (S < -32768) S = -32767; return (int16_t) S; } @@ -502,50 +457,75 @@ int16_t SecAZS_E1; int16_t SecAZS_C2; int16_t SecAZS_E2; +int16_t Nx, Ny, Nz; +int16_t Gx, Gy, Gz; +int16_t C_Les, E_Les, G_Les; + const int16_t MaxAZS_Exp[16] = { 0x38b4, 0x38b7, 0x38ba, 0x38be, 0x38c0, 0x38c4, 0x38c7, 0x38ca, 0x38ce, 0x38d0, 0x38d4, 0x38d7, 0x38da, 0x38dd, 0x38e0, 0x38e4 }; -void DSP1_Parameter(int16_t Fx, int16_t Fy, int16_t Fz, int16_t Lfe, int16_t Les, - int16_t Aas, int16_t Azs, int16_t* Vof, int16_t* Vva, int16_t* Cx, int16_t* Cy) +void DSP1_Parameter(int16_t Fx, int16_t Fy, int16_t Fz, int16_t Lfe, int16_t Les, int16_t Aas, int16_t Azs, int16_t* Vof, int16_t* Vva, int16_t* Cx, int16_t* Cy) { - int16_t CSec, C, E; + int16_t CSec, C, E, MaxAZS, Aux; + int16_t LfeNx, LfeNy, LfeNz; + int16_t LesNx, LesNy, LesNz; + int16_t CentreZ; // Copy Zenith angle for clipping int16_t AZS = Azs; - // Store Sin and Cos of Azimuth and Zenith angles + // Store Sine and Cosine of Azimuth and Zenith angle SinAas = DSP1_Sin(Aas); CosAas = DSP1_Cos(Aas); SinAzs = DSP1_Sin(Azs); CosAzs = DSP1_Cos(Azs); + Nx = SinAzs * -SinAas >> 15; + Ny = SinAzs * CosAas >> 15; + Nz = CosAzs * 0x7fff >> 15; + + LfeNx = Lfe * Nx >> 15; + LfeNy = Lfe * Ny >> 15; + LfeNz = Lfe * Nz >> 15; + // Center of Projection - CentreX = Fx + (Lfe * (SinAzs * -SinAas >> 15) >> 15); - CentreY = Fy + (Lfe * (SinAzs * CosAas >> 15) >> 15); + CentreX = Fx + LfeNx; + CentreY = Fy + LfeNy; + CentreZ = Fz + LfeNz; + + LesNx = Les * Nx >> 15; + LesNy = Les * Ny >> 15; + LesNz = Les * Nz >> 15; + + Gx = CentreX - LesNx; + Gy = CentreY - LesNy; + Gz = CentreZ - LesNz; + + E_Les=0; + DSP1_Normalize(Les, &C_Les, &E_Les); + G_Les = Les; E = 0; - DSP1_Normalize(Fz + (Lfe * (CosAzs * 0x7fff >> 15) >> 15), &C, &E); + DSP1_Normalize(CentreZ, &C, &E); VPlane_C = C; VPlane_E = E; // Determine clip boundary and clip Zenith angle if necessary - int16_t MaxAZS = MaxAZS_Exp[-E]; + MaxAZS = MaxAZS_Exp[-E]; if (AZS < 0) { MaxAZS = -MaxAZS; if (AZS < MaxAZS + 1) AZS = MaxAZS + 1; } - else - { - if (AZS > MaxAZS) AZS = MaxAZS; - } + else if (AZS > MaxAZS) + AZS = MaxAZS; - // Store Sin and Cos of clipped Zenith angle + // Store Sine and Cosine of clipped Zenith angle SinAZS = DSP1_Sin(AZS); CosAZS = DSP1_Cos(AZS); @@ -570,7 +550,7 @@ void DSP1_Parameter(int16_t Fx, int16_t Fy, int16_t Fz, int16_t Lfe, int16_t Les C = Azs - MaxAZS; if (C >= 0) C--; - int16_t Aux = ~(C << 2); + Aux = ~(C << 2); C = Aux * DSP1ROM[0x0328] >> 15; C = (C * Aux >> 15) + DSP1ROM[0x0327]; @@ -595,7 +575,7 @@ void DSP1_Parameter(int16_t Fx, int16_t Fy, int16_t Fz, int16_t Lfe, int16_t Les *Vva = DSP1_Truncate(-C, E); - // Store Sec of clipped Zenith angle + // Store Secant of clipped Zenith angle DSP1_Inverse(CosAZS, 0, &SecAZS_C2, &SecAZS_E2); } @@ -638,8 +618,7 @@ int16_t Op02CY; void DSPOp02() { - DSP1_Parameter(Op02FX, Op02FY, Op02FZ, Op02LFE, Op02LES, Op02AAS, Op02AZS, - &Op02VOF, &Op02VVA, &Op02CX, &Op02CY); + DSP1_Parameter(Op02FX, Op02FY, Op02FZ, Op02LFE, Op02LES, Op02AAS, Op02AZS, &Op02VOF, &Op02VVA, &Op02CX, &Op02CY); } int16_t Op0AVS; @@ -654,115 +633,96 @@ void DSPOp0A() Op0AVS++; } +int16_t DSP1_ShiftR(int16_t C, int16_t E) +{ + return (C * DSP1ROM[0x0031 + E] >> 15); +} + +void DSP1_Project(int16_t X, int16_t Y, int16_t Z, int16_t *H, int16_t *V, int16_t *M) +{ + int32_t aux, aux4; + int16_t E, E2, E3, E4, E5, refE, E6, E7; + int16_t C2, C4, C6, C8, C9, C10, C11, C12, C16, C17, C18, C19, C20, C21, C22, C23, C24, C25, C26; + int16_t Px, Py, Pz; + + E4 = E3 = E2 = E = E5 = 0; + + DSP1_NormalizeDouble((int32_t) X - Gx, &Px, &E4); + DSP1_NormalizeDouble((int32_t) Y - Gy, &Py, &E); + DSP1_NormalizeDouble((int32_t) Z - Gz, &Pz, &E3); + Px>>=1; + E4--; // to avoid overflows when calculating the scalar products + Py>>=1; + E--; + Pz>>=1; + E3--; + + refE = MIN(E, E3); + refE = MIN(refE, E4); + + Px = DSP1_ShiftR(Px, E4 - refE); // normalize them to the same exponent + Py = DSP1_ShiftR(Py, E - refE); + Pz = DSP1_ShiftR(Pz, E3 - refE); + + C11 = -(Px * Nx >> 15); + C8 = -(Py * Ny >> 15); + C9 = -(Pz * Nz >> 15); + C12 = C11 + C8 + C9; // this cannot overflow! + + aux4 = C12; // de-normalization with 32-bit arithmetic + refE = 16 - refE; // refE can be up to 3 + if (refE >= 0) + aux4 <<= refE; + else + aux4 >>= -refE; + if (aux4 == -1) + aux4 = 0; // why? + aux4>>=1; + + aux = ((int16_t) G_Les) + aux4; // Les - the scalar product of P with the normal vector of the screen + DSP1_NormalizeDouble(aux, &C10, &E2); + E2 = 15 - E2; + + DSP1_Inverse(C10, 0, &C4, &E4); + C2 = C4 * C_Les >> 15; // scale factor + + // H + E7 = 0; + C16 = (Px * (CosAas * 0x7fff >> 15) >> 15); + C20 = (Py * (SinAas * 0x7fff >> 15) >> 15); + C17 = C16 + C20; // scalar product of P with the normalized horizontal vector of the screen... + + C18 = C17 * C2 >> 15; // ... multiplied by the scale factor + DSP1_Normalize(C18, &C19, &E7); + *H = DSP1_Truncate(C19, E_Les - E2 + refE + E7); + + // V + E6 = 0; + C21 = Px * (CosAzs * -SinAas >> 15) >> 15; + C22 = Py * (CosAzs * CosAas >> 15) >> 15; + C23 = Pz * (-SinAzs * 0x7fff >> 15) >> 15; + C24 = C21 + C22 + C23; // scalar product of P with the normalized vertical vector of the screen... + + C26 = C24 * C2 >> 15; // ... multiplied by the scale factor + DSP1_Normalize(C26, &C25, &E6); + *V = DSP1_Truncate(C25, E_Les - E2 + refE + E6); + + // M + DSP1_Normalize(C2, &C6, &E4); + *M = DSP1_Truncate(C6, E4 + E_Les - E2 - 7); // M is the scale factor divided by 2^7 +} + int16_t Op06X; int16_t Op06Y; int16_t Op06Z; int16_t Op06H; int16_t Op06V; -uint16_t Op06S; - -double ObjPX; -double ObjPY; -double ObjPZ; -double ObjPX1; -double ObjPY1; -double ObjPZ1; -double ObjPX2; -double ObjPY2; -double ObjPZ2; -double DivideOp06; -int32_t Temp; -int32_t tanval2; - -#ifdef __OPT06__ -void DSPOp06() -{ - ObjPX = Op06X - Op02FX; - ObjPY = Op06Y - Op02FY; - ObjPZ = Op06Z - Op02FZ; - - // rotate around Z - tanval2 = Angle(-Op02AAS + 32768); - ObjPX1 = (ObjPX * Cos(tanval2) + ObjPY * -Sin(tanval2)); - ObjPY1 = (ObjPX * Sin(tanval2) + ObjPY * Cos(tanval2)); - ObjPZ1 = ObjPZ; - - // rotate around X - tanval2 = Angle(-Op02AZS); - ObjPX2 = ObjPX1; - ObjPY2 = (ObjPY1 * Cos(tanval2) + ObjPZ1 * -Sin(tanval2)); - ObjPZ2 = (ObjPY1 * Sin(tanval2) + ObjPZ1 * Cos(tanval2)); - - ObjPZ2 = ObjPZ2 - Op02LFE; - - if (ObjPZ2 < 0) - { - double d; - Op06H = (int16_t)(-ObjPX2 * Op02LES / -(ObjPZ2)); - Op06V = (int16_t)(-ObjPY2 * Op02LES / -(ObjPZ2)); - d = (double)Op02LES; - d *= 256.0; - d /= (-ObjPZ2); - if (d > 65535.0) - d = 65535.0; - else if (d < 0.0) - d = 0.0; - Op06S = (uint16_t)d; - } - else - { - Op06H = 0; - Op06V = 14 * 16; - Op06S = 0xFFFF; - } - - -} -#else +int16_t Op06M; void DSPOp06() { - ObjPX = Op06X - Op02FX; - ObjPY = Op06Y - Op02FY; - ObjPZ = Op06Z - Op02FZ; - - // rotate around Z - tanval = (-Op02AAS + 32768) / 65536.0 * 6.2832; - ObjPX1 = (ObjPX * cos(tanval) + ObjPY * -sin(tanval)); - ObjPY1 = (ObjPX * sin(tanval) + ObjPY * cos(tanval)); - ObjPZ1 = ObjPZ; - - // rotate around X - tanval = (-Op02AZS) / 65536.0 * 6.2832; - ObjPX2 = ObjPX1; - ObjPY2 = (ObjPY1 * cos(tanval) + ObjPZ1 * -sin(tanval)); - ObjPZ2 = (ObjPY1 * sin(tanval) + ObjPZ1 * cos(tanval)); - - ObjPZ2 = ObjPZ2 - Op02LFE; - - if (ObjPZ2 < 0) - { - Op06H = (int16_t)(-ObjPX2 * Op02LES / -(ObjPZ2)); - Op06V = (int16_t)(-ObjPY2 * Op02LES / -(ObjPZ2)); - double d = (double)Op02LES; - d *= 256.0; - d /= (-ObjPZ2); - if (d > 65535.0) - d = 65535.0; - else if (d < 0.0) - d = 0.0; - Op06S = (uint16_t)d; - } - else - { - Op06H = 0; - Op06V = 14 * 16; - Op06S = 0xFFFF; - } - + DSP1_Project(Op06X, Op06Y, Op06Z, &Op06H, &Op06V, &Op06M); } -#endif - int16_t matrixC[3][3]; int16_t matrixB[3][3]; @@ -796,16 +756,12 @@ void DSPOp01() matrixA[0][1] = -((Op01m * SinAz >> 15) * CosAy >> 15); matrixA[0][2] = Op01m * SinAy >> 15; - matrixA[1][0] = ((Op01m * SinAz >> 15) * CosAx >> 15) + ((( - Op01m * CosAz >> 15) * SinAx >> 15) * SinAy >> 15); - matrixA[1][1] = ((Op01m * CosAz >> 15) * CosAx >> 15) - ((( - Op01m * SinAz >> 15) * SinAx >> 15) * SinAy >> 15); + matrixA[1][0] = ((Op01m * SinAz >> 15) * CosAx >> 15) + (((Op01m * CosAz >> 15) * SinAx >> 15) * SinAy >> 15); + matrixA[1][1] = ((Op01m * CosAz >> 15) * CosAx >> 15) - (((Op01m * SinAz >> 15) * SinAx >> 15) * SinAy >> 15); matrixA[1][2] = -((Op01m * SinAx >> 15) * CosAy >> 15); - matrixA[2][0] = ((Op01m * SinAz >> 15) * SinAx >> 15) - ((( - Op01m * CosAz >> 15) * CosAx >> 15) * SinAy >> 15); - matrixA[2][1] = ((Op01m * CosAz >> 15) * SinAx >> 15) + ((( - Op01m * SinAz >> 15) * CosAx >> 15) * SinAy >> 15); + matrixA[2][0] = ((Op01m * SinAz >> 15) * SinAx >> 15) - (((Op01m * CosAz >> 15) * CosAx >> 15) * SinAy >> 15); + matrixA[2][1] = ((Op01m * CosAz >> 15) * SinAx >> 15) + (((Op01m * SinAz >> 15) * CosAx >> 15) * SinAy >> 15); matrixA[2][2] = (Op01m * CosAx >> 15) * CosAy >> 15; } @@ -824,16 +780,12 @@ void DSPOp11() matrixB[0][1] = -((Op11m * SinAz >> 15) * CosAy >> 15); matrixB[0][2] = Op11m * SinAy >> 15; - matrixB[1][0] = ((Op11m * SinAz >> 15) * CosAx >> 15) + ((( - Op11m * CosAz >> 15) * SinAx >> 15) * SinAy >> 15); - matrixB[1][1] = ((Op11m * CosAz >> 15) * CosAx >> 15) - ((( - Op11m * SinAz >> 15) * SinAx >> 15) * SinAy >> 15); + matrixB[1][0] = ((Op11m * SinAz >> 15) * CosAx >> 15) + (((Op11m * CosAz >> 15) * SinAx >> 15) * SinAy >> 15); + matrixB[1][1] = ((Op11m * CosAz >> 15) * CosAx >> 15) - (((Op11m * SinAz >> 15) * SinAx >> 15) * SinAy >> 15); matrixB[1][2] = -((Op11m * SinAx >> 15) * CosAy >> 15); - matrixB[2][0] = ((Op11m * SinAz >> 15) * SinAx >> 15) - ((( - Op11m * CosAz >> 15) * CosAx >> 15) * SinAy >> 15); - matrixB[2][1] = ((Op11m * CosAz >> 15) * SinAx >> 15) + ((( - Op11m * SinAz >> 15) * CosAx >> 15) * SinAy >> 15); + matrixB[2][0] = ((Op11m * SinAz >> 15) * SinAx >> 15) - (((Op11m * CosAz >> 15) * CosAx >> 15) * SinAy >> 15); + matrixB[2][1] = ((Op11m * CosAz >> 15) * SinAx >> 15) + (((Op11m * SinAz >> 15) * CosAx >> 15) * SinAy >> 15); matrixB[2][2] = (Op11m * CosAx >> 15) * CosAy >> 15; } @@ -852,16 +804,12 @@ void DSPOp21() matrixC[0][1] = -((Op21m * SinAz >> 15) * CosAy >> 15); matrixC[0][2] = Op21m * SinAy >> 15; - matrixC[1][0] = ((Op21m * SinAz >> 15) * CosAx >> 15) + ((( - Op21m * CosAz >> 15) * SinAx >> 15) * SinAy >> 15); - matrixC[1][1] = ((Op21m * CosAz >> 15) * CosAx >> 15) - ((( - Op21m * SinAz >> 15) * SinAx >> 15) * SinAy >> 15); + matrixC[1][0] = ((Op21m * SinAz >> 15) * CosAx >> 15) + (((Op21m * CosAz >> 15) * SinAx >> 15) * SinAy >> 15); + matrixC[1][1] = ((Op21m * CosAz >> 15) * CosAx >> 15) - (((Op21m * SinAz >> 15) * SinAx >> 15) * SinAy >> 15); matrixC[1][2] = -((Op21m * SinAx >> 15) * CosAy >> 15); - matrixC[2][0] = ((Op21m * SinAz >> 15) * SinAx >> 15) - ((( - Op21m * CosAz >> 15) * CosAx >> 15) * SinAy >> 15); - matrixC[2][1] = ((Op21m * CosAz >> 15) * SinAx >> 15) + ((( - Op21m * SinAz >> 15) * CosAx >> 15) * SinAy >> 15); + matrixC[2][0] = ((Op21m * SinAz >> 15) * SinAx >> 15) - (((Op21m * CosAz >> 15) * CosAx >> 15) * SinAy >> 15); + matrixC[2][1] = ((Op21m * CosAz >> 15) * SinAx >> 15) + (((Op21m * SinAz >> 15) * CosAx >> 15) * SinAy >> 15); matrixC[2][2] = (Op21m * CosAx >> 15) * CosAy >> 15; } @@ -886,35 +834,23 @@ int16_t Op2DU; void DSPOp0D() { - Op0DF = (Op0DX * matrixA[0][0] >> 15) + (Op0DY * matrixA[0][1] >> 15) + - (Op0DZ * matrixA[0][2] >> 15); - Op0DL = (Op0DX * matrixA[1][0] >> 15) + (Op0DY * matrixA[1][1] >> 15) + - (Op0DZ * matrixA[1][2] >> 15); - Op0DU = (Op0DX * matrixA[2][0] >> 15) + (Op0DY * matrixA[2][1] >> 15) + - (Op0DZ * matrixA[2][2] >> 15); - + Op0DF = (Op0DX * matrixA[0][0] >> 15) + (Op0DY * matrixA[0][1] >> 15) + (Op0DZ * matrixA[0][2] >> 15); + Op0DL = (Op0DX * matrixA[1][0] >> 15) + (Op0DY * matrixA[1][1] >> 15) + (Op0DZ * matrixA[1][2] >> 15); + Op0DU = (Op0DX * matrixA[2][0] >> 15) + (Op0DY * matrixA[2][1] >> 15) + (Op0DZ * matrixA[2][2] >> 15); } void DSPOp1D() { - Op1DF = (Op1DX * matrixB[0][0] >> 15) + (Op1DY * matrixB[0][1] >> 15) + - (Op1DZ * matrixB[0][2] >> 15); - Op1DL = (Op1DX * matrixB[1][0] >> 15) + (Op1DY * matrixB[1][1] >> 15) + - (Op1DZ * matrixB[1][2] >> 15); - Op1DU = (Op1DX * matrixB[2][0] >> 15) + (Op1DY * matrixB[2][1] >> 15) + - (Op1DZ * matrixB[2][2] >> 15); - + Op1DF = (Op1DX * matrixB[0][0] >> 15) + (Op1DY * matrixB[0][1] >> 15) + (Op1DZ * matrixB[0][2] >> 15); + Op1DL = (Op1DX * matrixB[1][0] >> 15) + (Op1DY * matrixB[1][1] >> 15) + (Op1DZ * matrixB[1][2] >> 15); + Op1DU = (Op1DX * matrixB[2][0] >> 15) + (Op1DY * matrixB[2][1] >> 15) + (Op1DZ * matrixB[2][2] >> 15); } void DSPOp2D() { - Op2DF = (Op2DX * matrixC[0][0] >> 15) + (Op2DY * matrixC[0][1] >> 15) + - (Op2DZ * matrixC[0][2] >> 15); - Op2DL = (Op2DX * matrixC[1][0] >> 15) + (Op2DY * matrixC[1][1] >> 15) + - (Op2DZ * matrixC[1][2] >> 15); - Op2DU = (Op2DX * matrixC[2][0] >> 15) + (Op2DY * matrixC[2][1] >> 15) + - (Op2DZ * matrixC[2][2] >> 15); - + Op2DF = (Op2DX * matrixC[0][0] >> 15) + (Op2DY * matrixC[0][1] >> 15) + (Op2DZ * matrixC[0][2] >> 15); + Op2DL = (Op2DX * matrixC[1][0] >> 15) + (Op2DY * matrixC[1][1] >> 15) + (Op2DZ * matrixC[1][2] >> 15); + Op2DU = (Op2DX * matrixC[2][0] >> 15) + (Op2DY * matrixC[2][1] >> 15) + (Op2DZ * matrixC[2][2] >> 15); } int16_t Op03F; @@ -938,35 +874,23 @@ int16_t Op23Z; void DSPOp03() { - Op03X = (Op03F * matrixA[0][0] >> 15) + (Op03L * matrixA[1][0] >> 15) + - (Op03U * matrixA[2][0] >> 15); - Op03Y = (Op03F * matrixA[0][1] >> 15) + (Op03L * matrixA[1][1] >> 15) + - (Op03U * matrixA[2][1] >> 15); - Op03Z = (Op03F * matrixA[0][2] >> 15) + (Op03L * matrixA[1][2] >> 15) + - (Op03U * matrixA[2][2] >> 15); - + Op03X = (Op03F * matrixA[0][0] >> 15) + (Op03L * matrixA[1][0] >> 15) + (Op03U * matrixA[2][0] >> 15); + Op03Y = (Op03F * matrixA[0][1] >> 15) + (Op03L * matrixA[1][1] >> 15) + (Op03U * matrixA[2][1] >> 15); + Op03Z = (Op03F * matrixA[0][2] >> 15) + (Op03L * matrixA[1][2] >> 15) + (Op03U * matrixA[2][2] >> 15); } void DSPOp13() { - Op13X = (Op13F * matrixB[0][0] >> 15) + (Op13L * matrixB[1][0] >> 15) + - (Op13U * matrixB[2][0] >> 15); - Op13Y = (Op13F * matrixB[0][1] >> 15) + (Op13L * matrixB[1][1] >> 15) + - (Op13U * matrixB[2][1] >> 15); - Op13Z = (Op13F * matrixB[0][2] >> 15) + (Op13L * matrixB[1][2] >> 15) + - (Op13U * matrixB[2][2] >> 15); - + Op13X = (Op13F * matrixB[0][0] >> 15) + (Op13L * matrixB[1][0] >> 15) + (Op13U * matrixB[2][0] >> 15); + Op13Y = (Op13F * matrixB[0][1] >> 15) + (Op13L * matrixB[1][1] >> 15) + (Op13U * matrixB[2][1] >> 15); + Op13Z = (Op13F * matrixB[0][2] >> 15) + (Op13L * matrixB[1][2] >> 15) + (Op13U * matrixB[2][2] >> 15); } void DSPOp23() { - Op23X = (Op23F * matrixC[0][0] >> 15) + (Op23L * matrixC[1][0] >> 15) + - (Op23U * matrixC[2][0] >> 15); - Op23Y = (Op23F * matrixC[0][1] >> 15) + (Op23L * matrixC[1][1] >> 15) + - (Op23U * matrixC[2][1] >> 15); - Op23Z = (Op23F * matrixC[0][2] >> 15) + (Op23L * matrixC[1][2] >> 15) + - (Op23U * matrixC[2][2] >> 15); - + Op23X = (Op23F * matrixC[0][0] >> 15) + (Op23L * matrixC[1][0] >> 15) + (Op23U * matrixC[2][0] >> 15); + Op23Y = (Op23F * matrixC[0][1] >> 15) + (Op23L * matrixC[1][1] >> 15) + (Op23U * matrixC[2][1] >> 15); + Op23Z = (Op23F * matrixC[0][2] >> 15) + (Op23L * matrixC[1][2] >> 15) + (Op23U * matrixC[2][2] >> 15); } int16_t Op14Zr; @@ -986,8 +910,7 @@ void DSPOp14() DSP1_Inverse(DSP1_Cos(Op14Xr), 0, &CSec, &ESec); // Rotation Around Z - DSP1_NormalizeDouble(Op14U * DSP1_Cos(Op14Yr) - Op14F * DSP1_Sin(Op14Yr), &C, - &E); + DSP1_NormalizeDouble(Op14U * DSP1_Cos(Op14Yr) - Op14F * DSP1_Sin(Op14Yr), &C, &E); E = ESec - E; @@ -996,12 +919,10 @@ void DSPOp14() Op14Zrr = Op14Zr + DSP1_Truncate(C, E); // Rotation Around X - Op14Xrr = Op14Xr + (Op14U * DSP1_Sin(Op14Yr) >> 15) + (Op14F * DSP1_Cos( - Op14Yr) >> 15); + Op14Xrr = Op14Xr + (Op14U * DSP1_Sin(Op14Yr) >> 15) + (Op14F * DSP1_Cos(Op14Yr) >> 15); // Rotation Around Y - DSP1_NormalizeDouble(Op14U * DSP1_Cos(Op14Yr) + Op14F * DSP1_Sin(Op14Yr), &C, - &E); + DSP1_NormalizeDouble(Op14U * DSP1_Cos(Op14Yr) + Op14F * DSP1_Sin(Op14Yr), &C, &E); E = ESec - E; @@ -1068,23 +989,17 @@ int16_t Op2BS; void DSPOp0B() { - Op0BS = (Op0BX * matrixA[0][0] + Op0BY * matrixA[0][1] + Op0BZ * matrixA[0][2]) - >> 15; - + Op0BS = (Op0BX * matrixA[0][0] + Op0BY * matrixA[0][1] + Op0BZ * matrixA[0][2]) >> 15; } void DSPOp1B() { - Op1BS = (Op1BX * matrixB[0][0] + Op1BY * matrixB[0][1] + Op1BZ * matrixB[0][2]) - >> 15; - + Op1BS = (Op1BX * matrixB[0][0] + Op1BY * matrixB[0][1] + Op1BZ * matrixB[0][2]) >> 15; } void DSPOp2B() { - Op2BS = (Op2BX * matrixC[0][0] + Op2BY * matrixC[0][1] + Op2BZ * matrixC[0][2]) - >> 15; - + Op2BS = (Op2BX * matrixC[0][0] + Op2BY * matrixC[0][1] + Op2BZ * matrixC[0][2]) >> 15; } int16_t Op08X, Op08Y, Op08Z, Op08Ll, Op08Lh; @@ -1094,7 +1009,6 @@ void DSPOp08() int32_t Op08Size = (Op08X * Op08X + Op08Y * Op08Y + Op08Z * Op08Z) << 1; Op08Ll = Op08Size & 0xffff; Op08Lh = (Op08Size >> 16) & 0xffff; - } int16_t Op18X, Op18Y, Op18Z, Op18R, Op18D; @@ -1102,7 +1016,6 @@ int16_t Op18X, Op18Y, Op18Z, Op18R, Op18D; void DSPOp18() { Op18D = (Op18X * Op18X + Op18Y * Op18Y + Op18Z * Op18Z - Op18R * Op18R) >> 15; - } int16_t Op38X, Op38Y, Op38Z, Op38R, Op38D; @@ -1111,7 +1024,6 @@ void DSPOp38() { Op38D = (Op38X * Op38X + Op38Y * Op38Y + Op38Z * Op38Z - Op38R * Op38R) >> 15; Op38D++; - } int16_t Op28X; @@ -1126,19 +1038,18 @@ void DSPOp28() if (Radius == 0) Op28R = 0; else { - int16_t C, E; + int16_t C, E, Pos, Node1, Node2; DSP1_NormalizeDouble(Radius, &C, &E); if (E & 1) C = C * 0x4000 >> 15; - int16_t Pos = C * 0x0040 >> 15; + Pos = C * 0x0040 >> 15; - int16_t Node1 = DSP1ROM[0x00d5 + Pos]; - int16_t Node2 = DSP1ROM[0x00d6 + Pos]; + Node1 = DSP1ROM[0x00d5 + Pos]; + Node2 = DSP1ROM[0x00d6 + Pos]; Op28R = ((Node2 - Node1) * (C & 0x1ff) >> 9) + Node1; Op28R >>= (E >> 1); } - } int16_t Op1CX, Op1CY, Op1CZ; @@ -1169,7 +1080,6 @@ void DSPOp1C() Op1CZ1 = (Op1CZBR * DSP1_Cos(Op1CX) >> 15) - (Op1CYBR * DSP1_Sin(Op1CX) >> 15); Op1CYAR = Op1CY1; Op1CZAR = Op1CZ1; - } uint16_t Op0FRamsize; @@ -1178,7 +1088,6 @@ uint16_t Op0FPass; void DSPOp0F() { Op0FPass = 0x0000; - } int16_t Op2FUnknown; diff --git a/source/dsp2emu.c b/source/dsp2emu.c index d1b6410..9e3e137 100644 --- a/source/dsp2emu.c +++ b/source/dsp2emu.c @@ -130,13 +130,11 @@ bool DSP2Op0DHasLen = false; int32_t DSP2Op0DOutLen = 0; int32_t DSP2Op0DInLen = 0; -#ifndef DSP2_BIT_ACCURRATE_CODE - // Scale bitmap based on input length out output length void DSP2_Op0D() { - // (Modified) Overload's algorithm - use this unless doing hardware testing + // (Modified) Overload's algorithm int32_t i; @@ -150,51 +148,3 @@ void DSP2_Op0D() DSP1.output[i] = (pixel_low << 4) | pixel_high; } } - -#else - -void DSP2_Op0D() -{ - // Bit accurate hardware algorithm - uses fixed point math - // This should match the DSP2 Op0D output exactly - // I wouldn't recommend using this unless you're doing hardware debug. - // In some situations it has small visual artifacts that - // are not readily apparent on a TV screen but show up clearly - // on a monitor. Use Overload's scaling instead. - // This is for hardware verification testing. - // - // One note: the HW can do odd byte scaling but since we divide - // by two to get the count of bytes this won't work well for - // odd byte scaling (in any of the current algorithm implementations). - // So far I haven't seen Dungeon Master use it. - // If it does we can adjust the parameters and code to work with it - - - uint32_t multiplier; - uint32_t pixloc; - int32_t i, j; - uint8_t pixelarray[512]; - - if (DSP2Op0DInLen <= DSP2Op0DOutLen) - multiplier = 0x10000; // In our self defined fixed point 0x10000 == 1 - else - multiplier = (DSP2Op0DInLen << 17) / ((DSP2Op0DOutLen << 1) + 1); - - pixloc = 0; - for (i = 0; i < DSP2Op0DOutLen * 2; i++) - { - j = pixloc >> 16; - - if (j & 1) - pixelarray[i] = DSP1.parameters[j >> 1] & 0x0f; - else - pixelarray[i] = (DSP1.parameters[j >> 1] & 0xf0) >> 4; - - pixloc += multiplier; - } - - for (i = 0; i < DSP2Op0DOutLen; i++) - DSP1.output[i] = (pixelarray[i << 1] << 4) | pixelarray[(i << 1) + 1]; -} - -#endif diff --git a/source/dsp4emu.c b/source/dsp4emu.c index c2ba8c8..3b3d843 100644 --- a/source/dsp4emu.c +++ b/source/dsp4emu.c @@ -160,7 +160,7 @@ resume2: - 1.07629051 * project_focaly - 65.69315963); // approximate # of raster lines - segments = abs(project_y2 - project_y1); + segments = ABS(project_y2 - project_y1); // prevent overdraw if (project_y2 >= raster) segments = 0; @@ -341,7 +341,7 @@ resume2: - 1.07629051 * project_focaly - 65.69315963); // approximate # of raster lines - segments = abs(project_y2 - project_y1); + segments = ABS(project_y2 - project_y1); // prevent overdraw if (project_y2 >= raster) segments = 0; @@ -555,7 +555,7 @@ DSP4_WAIT(2) resume2: int16_t dx1 = 0, dx2 = 0, dx3, dx4; // # segments to traverse - segments = abs(y_left - path_y[0]); + segments = ABS(y_left - path_y[0]); // prevent overdraw if (y_left >= path_raster[0]) segments = 0; @@ -638,7 +638,7 @@ DSP4_WAIT(2) resume2: ////////////////////////////////////////////// // zone 2 - segments = abs(y_right - path_y[1]); + segments = ABS(y_right - path_y[1]); // prevent overdraw if (y_right >= path_raster[2]) segments = 0; @@ -863,7 +863,7 @@ resume2: - 1.07629051 * project_focaly - 65.69315963); // approximate # of raster lines - segments = abs(project_y2 - project_y1); + segments = ABS(project_y2 - project_y1); // prevent overdraw if (project_y2 >= raster) segments = 0; @@ -994,7 +994,8 @@ void DSP4_Op09() // convert track line to the window region project_y2 = center_y + multi_raster[multi_index1] * (viewport_bottom - center_y) / (0x33 - 0); - if (op09_mode == 0) project_y2 -= 2; + if (!op09_mode) + project_y2 -= 2; goto no_sprite; @@ -1138,7 +1139,7 @@ DSP4_WAIT(5) resume5: } // default sprite size: 16x16 - sprite_size = 1; + sprite_size = true; // convert tile data to OAM diff --git a/source/fxemu.c b/source/fxemu.c index 5b3aba3..d9c5082 100644 --- a/source/fxemu.c +++ b/source/fxemu.c @@ -9,10 +9,6 @@ /* The FxChip Emulator's internal variables */ struct FxRegs_s GSU; // This will be initialized when loading a ROM -uint32_t(**fx_ppfFunctionTable)(uint32_t) = 0; -void (**fx_ppfPlotTable)() = 0; -void (**fx_ppfOpcodeTable)() = 0; - void FxCacheWriteAccess(uint16_t vAddress) { if ((vAddress & 0x00f) == 0x00f) @@ -36,23 +32,30 @@ void fx_flushCache() void fx_updateRamBank(uint8_t Byte) { // Update BankReg and Bank pointer - GSU.vRamBankReg = (uint32_t)Byte & (FX_RAM_BANKS - 1); + GSU.vRamBankReg = (uint32_t) Byte & (FX_RAM_BANKS - 1); GSU.pvRamBank = GSU.apvRamBank[Byte & 0x3]; } +static void fx_readRegisterSpaceForCheck() +{ + R15 = GSU.pvRegisters[30]; + R15 |= ((uint32_t) GSU.pvRegisters[31]) << 8; + GSU.vStatusReg = (uint32_t) GSU.pvRegisters[GSU_SFR]; + GSU.vStatusReg |= ((uint32_t) GSU.pvRegisters[GSU_SFR + 1]) << 8; + GSU.vPrgBankReg = (uint32_t) GSU.pvRegisters[GSU_PBR]; +} -static void fx_readRegisterSpace() +static void fx_readRegisterSpaceForUse() { - int32_t i; - uint8_t* p; static uint32_t avHeight[] = { 128, 160, 192, 256 }; static uint32_t avMult[] = { 16, 32, 32, 64 }; + int32_t i; + uint8_t* p = GSU.pvRegisters; GSU.vErrorCode = 0; - /* Update R0-R15 */ - p = GSU.pvRegisters; - for (i = 0; i < 16; i++) + /* Update R0 - R14 */ + for (i = 0; i < 15; i++) { GSU.avReg[i] = *p++; GSU.avReg[i] += ((uint32_t)(*p++)) << 8; @@ -60,9 +63,6 @@ static void fx_readRegisterSpace() /* Update other registers */ p = GSU.pvRegisters; - GSU.vStatusReg = (uint32_t)p[GSU_SFR]; - GSU.vStatusReg |= ((uint32_t)p[GSU_SFR + 1]) << 8; - GSU.vPrgBankReg = (uint32_t)p[GSU_PBR]; GSU.vRomBankReg = (uint32_t)p[GSU_ROMBR]; GSU.vRamBankReg = ((uint32_t)p[GSU_RAMBR]) & (FX_RAM_BANKS - 1); GSU.vCacheBaseReg = (uint32_t)p[GSU_CBR]; @@ -99,10 +99,10 @@ static void fx_readRegisterSpace() GSU.pfPlot = fx_apfPlotTable[GSU.vMode]; GSU.pfRpix = fx_apfPlotTable[GSU.vMode + 5]; - fx_ppfOpcodeTable[0x04c] = GSU.pfPlot; - fx_ppfOpcodeTable[0x14c] = GSU.pfRpix; - fx_ppfOpcodeTable[0x24c] = GSU.pfPlot; - fx_ppfOpcodeTable[0x34c] = GSU.pfRpix; + fx_apfOpcodeTable[0x04c] = GSU.pfPlot; + fx_apfOpcodeTable[0x14c] = GSU.pfRpix; + fx_apfOpcodeTable[0x24c] = GSU.pfPlot; + fx_apfOpcodeTable[0x34c] = GSU.pfRpix; fx_computeScreenPointers(); } @@ -212,16 +212,14 @@ void fx_computeScreenPointers() case 0: for (i = 0; i < 32; i++) { - GSU.apvScreen[i] = GSU.pvScreenBase + - ((i & 0x10) << 9) + ((i & 0xf) << 8); + GSU.apvScreen[i] = GSU.pvScreenBase + ((i & 0x10) << 9) + ((i & 0xf) << 8); GSU.x[i] = ((i & 0x10) << 8) + ((i & 0xf) << 4); } break; case 1: for (i = 0; i < 32; i++) { - GSU.apvScreen[i] = GSU.pvScreenBase + - ((i & 0x10) << 10) + ((i & 0xf) << 9); + GSU.apvScreen[i] = GSU.pvScreenBase + ((i & 0x10) << 10) + ((i & 0xf) << 9); GSU.x[i] = ((i & 0x10) << 9) + ((i & 0xf) << 5); } break; @@ -229,8 +227,7 @@ void fx_computeScreenPointers() case 3: for (i = 0; i < 32; i++) { - GSU.apvScreen[i] = GSU.pvScreenBase + - ((i & 0x10) << 11) + ((i & 0xf) << 10); + GSU.apvScreen[i] = GSU.pvScreenBase + ((i & 0x10) << 11) + ((i & 0xf) << 10); GSU.x[i] = ((i & 0x10) << 10) + ((i & 0xf) << 6); } break; @@ -242,32 +239,44 @@ void fx_computeScreenPointers() } } -static void fx_writeRegisterSpace() +static void fx_writeRegisterSpaceAfterCheck() { - int32_t i; - uint8_t* p; + GSU.pvRegisters[30] = (uint8_t) R15; + GSU.pvRegisters[31] = (uint8_t) (R15 >> 8); + GSU.pvRegisters[GSU_SFR] = (uint8_t) GSU.vStatusReg; + GSU.pvRegisters[GSU_SFR + 1] = (uint8_t) (GSU.vStatusReg >> 8); + GSU.pvRegisters[GSU_PBR] = (uint8_t) GSU.vPrgBankReg; +} - p = GSU.pvRegisters; - for (i = 0; i < 16; i++) +static void fx_writeRegisterSpaceAfterUse() +{ + int32_t i; + uint8_t* p = GSU.pvRegisters; + for (i = 0; i < 15; i++) { *p++ = (uint8_t)GSU.avReg[i]; *p++ = (uint8_t)(GSU.avReg[i] >> 8); } /* Update status register */ - if (USEX16(GSU.vZero) == 0) SF(Z); - else CF(Z); - if (GSU.vSign & 0x8000) SF(S); - else CF(S); - if (GSU.vOverflow >= 0x8000 || GSU.vOverflow < -0x8000) SF(OV); - else CF(OV); - if (GSU.vCarry) SF(CY); - else CF(CY); + if (USEX16(GSU.vZero) == 0) + SF(Z); + else + CF(Z); + if (GSU.vSign & 0x8000) + SF(S); + else + CF(S); + if (GSU.vOverflow >= 0x8000 || GSU.vOverflow < -0x8000) + SF(OV); + else + CF(OV); + if (GSU.vCarry) + SF(CY); + else + CF(CY); p = GSU.pvRegisters; - p[GSU_SFR] = (uint8_t)GSU.vStatusReg; - p[GSU_SFR + 1] = (uint8_t)(GSU.vStatusReg >> 8); - p[GSU_PBR] = (uint8_t)GSU.vPrgBankReg; p[GSU_ROMBR] = (uint8_t)GSU.vRomBankReg; p[GSU_RAMBR] = (uint8_t)GSU.vRamBankReg; p[GSU_CBR] = (uint8_t)GSU.vCacheBaseReg; @@ -277,27 +286,8 @@ static void fx_writeRegisterSpace() /* Reset the FxChip */ void FxReset(struct FxInit_s* psFxInfo) { - int32_t i; - static uint32_t(**appfFunction[])(uint32_t) = - { - &fx_apfFunctionTable[0] - }; - static void (**appfPlot[])() = - { - &fx_apfPlotTable[0] - }; - static void (**appfOpcode[])() = - { - &fx_apfOpcodeTable[0] - }; - - /* Get function pointers for the current emulation mode */ - fx_ppfFunctionTable = appfFunction[psFxInfo->vFlags & 0x3]; - fx_ppfPlotTable = appfPlot[psFxInfo->vFlags & 0x3]; - fx_ppfOpcodeTable = appfOpcode[psFxInfo->vFlags & 0x3]; - /* Clear all internal variables */ - memset((uint8_t*)&GSU, 0, sizeof(struct FxRegs_s)); + memset((uint8_t*) &GSU, 0, sizeof(struct FxRegs_s)); /* Set default registers */ GSU.pvSreg = GSU.pvDreg = &R0; @@ -322,17 +312,18 @@ void FxReset(struct FxInit_s* psFxInfo) GSU.pvRegisters[0x3b] = 0; /* Make ROM bank table */ + int32_t i; for (i = 0; i < 256; i++) { uint32_t b = i & 0x7f; if (b >= 0x40) { - if (GSU.nRomBanks > 1) + if (GSU.nRomBanks > 2) b %= GSU.nRomBanks; else b &= 1; - GSU.apvRomBank[i] = &GSU.pvRom[ b << 16 ]; + GSU.apvRomBank[i] = &GSU.pvRom[b << 16]; } else { @@ -354,19 +345,17 @@ void FxReset(struct FxInit_s* psFxInfo) /* Set pointer to GSU cache */ GSU.pvCache = &GSU.pvRegisters[0x100]; - fx_readRegisterSpace(); + fx_readRegisterSpaceForCheck(); + fx_readRegisterSpaceForUse(); } static bool fx_checkStartAddress() { /* Check if we start inside the cache */ - if (GSU.bCacheActive && R15 >= GSU.vCacheBaseReg - && R15 < (GSU.vCacheBaseReg + 512)) + if (GSU.bCacheActive && R15 >= GSU.vCacheBaseReg && R15 < (GSU.vCacheBaseReg + 512)) return true; /* Check if we're in an unused area */ - if (GSU.vPrgBankReg < 0x40 && R15 < 0x8000) - return false; if (GSU.vPrgBankReg >= 0x60 && GSU.vPrgBankReg <= 0x6f) return false; if (GSU.vPrgBankReg >= 0x74) @@ -389,23 +378,26 @@ int32_t FxEmulate(uint32_t nInstructions) uint32_t vCount; /* Read registers and initialize GSU session */ - fx_readRegisterSpace(); + fx_readRegisterSpaceForCheck(); /* Check if the start address is valid */ if (!fx_checkStartAddress()) { CF(G); - fx_writeRegisterSpace(); + fx_writeRegisterSpaceAfterCheck(); return 0; } + fx_readRegisterSpaceForUse(); + /* Execute GSU session */ CF(IRQ); - vCount = fx_ppfFunctionTable[FX_FUNCTION_RUN](nInstructions); + vCount = fx_run(nInstructions); /* Store GSU registers */ - fx_writeRegisterSpace(); + fx_writeRegisterSpaceAfterCheck(); + fx_writeRegisterSpaceAfterUse(); /* Check for error code */ if (GSU.vErrorCode) @@ -414,33 +406,6 @@ int32_t FxEmulate(uint32_t nInstructions) return vCount; } -/* Step by step execution */ -int32_t FxStepOver(uint32_t nInstructions) -{ - uint32_t vCount; - fx_readRegisterSpace(); - - /* Check if the start address is valid */ - if (!fx_checkStartAddress()) - { - CF(G); - return 0; - } - - if (PIPE >= 0xf0) - GSU.vStepPoint = USEX16(R15 + 3); - else if ((PIPE >= 0x05 && PIPE <= 0x0f) || (PIPE >= 0xa0 && PIPE <= 0xaf)) - GSU.vStepPoint = USEX16(R15 + 2); - else - GSU.vStepPoint = USEX16(R15 + 1); - vCount = fx_ppfFunctionTable[FX_FUNCTION_STEP_OVER](nInstructions); - fx_writeRegisterSpace(); - if (GSU.vErrorCode) - return GSU.vErrorCode; - else - return vCount; -} - /* Errors */ int32_t FxGetErrorCode() { diff --git a/source/fxemu.h b/source/fxemu.h index 3c0511c..2176976 100644 --- a/source/fxemu.h +++ b/source/fxemu.h @@ -26,9 +26,6 @@ extern int32_t FxEmulate(uint32_t nInstructions); extern void FxCacheWriteAccess(uint16_t vAddress); extern void FxFlushCache(); /* Callled when the G flag in SFR is set to zero */ -/* Step by step execution */ -extern int32_t FxStepOver(uint32_t nInstructions); - /* Errors */ extern int32_t FxGetErrorCode(); extern int32_t FxGetIllegalAddress(); @@ -43,7 +40,7 @@ extern uint32_t FxGetDestinationRegisterIndex(); extern uint8_t FxPipe(); /* SCBR write seen. We need to update our cached screen pointers */ -extern void fx_dirtySCBR(void); +extern void fx_dirtySCBR(); /* Update RamBankReg and RAM Bank pointer */ extern void fx_updateRamBank(uint8_t Byte); diff --git a/source/fxinst.c b/source/fxinst.c index e78d932..86ccd38 100644 --- a/source/fxinst.c +++ b/source/fxinst.c @@ -10,13 +10,9 @@ extern struct FxRegs_s GSU; int32_t gsu_bank [512] = {0}; -/* Set this define if you wish the plot instruction to check for y-pos limits */ -/* (I don't think it's nessecary) */ -#define CHECK_LIMITS - /* Codes used: * - * rn = a GSU register (r0-r15) + * rn = a GSU register (r0 - r15) * #n = 4 bit immediate value * #pp = 8 bit immediate value * (yy) = 8 bit word address (0x0000 - 0x01fe) @@ -61,8 +57,8 @@ static void fx_cache() GSU.vCacheBaseReg = c; GSU.bCacheActive = true; } - R15++; CLRFLAGS; + R15++; } /* 03 - lsr - logic shift right */ @@ -102,7 +98,14 @@ static void fx_bra() } /* Branch on condition */ -#define BRA_COND(cond) uint8_t v = PIPE; R15++; FETCHPIPE; if(cond) R15 += SEX8(v); else R15++; +#define BRA_COND(cond) \ + uint8_t v = PIPE; \ + R15++; \ + FETCHPIPE; \ + if (cond) \ + R15 += SEX8(v); \ + else \ + R15++ #define TEST_S (GSU.vSign & 0x8000) #define TEST_Z (USEX16(GSU.vZero) == 0) @@ -172,14 +175,38 @@ static void fx_bvs() /* 10-1f - to rn - set register n as destination register */ /* 10-1f(B) - move rn - move one register to another (if B flag is set) */ #define FX_TO(reg) \ -if(TF(B)) { GSU.avReg[(reg)] = SREG; CLRFLAGS; } \ -else { GSU.pvDreg = &GSU.avReg[reg]; } R15++; + if (TF(B)) \ + { \ + GSU.avReg[(reg)] = SREG; \ + CLRFLAGS; \ + } \ + else \ + GSU.pvDreg = &GSU.avReg[reg]; \ + R15++ + #define FX_TO_R14(reg) \ -if(TF(B)) { GSU.avReg[(reg)] = SREG; CLRFLAGS; READR14; } \ -else { GSU.pvDreg = &GSU.avReg[reg]; } R15++; + if (TF(B)) \ + { \ + GSU.avReg[(reg)] = SREG; \ + CLRFLAGS; \ + READR14; \ + } \ + else \ + GSU.pvDreg = &GSU.avReg[reg]; \ + R15++ + #define FX_TO_R15(reg) \ -if(TF(B)) { GSU.avReg[(reg)] = SREG; CLRFLAGS; } \ -else { GSU.pvDreg = &GSU.avReg[reg]; R15++; } + if (TF(B)) \ + { \ + GSU.avReg[(reg)] = SREG; \ + CLRFLAGS; \ + } \ + else \ + { \ + GSU.pvDreg = &GSU.avReg[reg]; \ + R15++; \ + } + static void fx_to_r0() { FX_TO(0); @@ -246,7 +273,11 @@ static void fx_to_r15() } /* 20-2f - to rn - set register n as source and destination register */ -#define FX_WITH(reg) SF(B); GSU.pvSreg = GSU.pvDreg = &GSU.avReg[reg]; R15++; +#define FX_WITH(reg) \ + SF(B); \ + GSU.pvSreg = GSU.pvDreg = &GSU.avReg[reg]; \ + R15++ + static void fx_with_r0() { FX_WITH(0); @@ -314,10 +345,12 @@ static void fx_with_r15() /* 30-3b - stw (rn) - store word */ #define FX_STW(reg) \ -GSU.vLastRamAdr = GSU.avReg[reg]; \ -RAM(GSU.avReg[reg]) = (uint8_t)SREG; \ -RAM(GSU.avReg[reg]^1) = (uint8_t)(SREG>>8); \ -CLRFLAGS; R15++ + GSU.vLastRamAdr = GSU.avReg[reg]; \ + RAM(GSU.avReg[reg]) = (uint8_t) SREG; \ + RAM(GSU.avReg[reg] ^ 1) = (uint8_t) (SREG >> 8); \ + CLRFLAGS; \ + R15++ + static void fx_stw_r0() { FX_STW(0); @@ -369,9 +402,11 @@ static void fx_stw_r11() /* 30-3b(ALT1) - stb (rn) - store byte */ #define FX_STB(reg) \ -GSU.vLastRamAdr = GSU.avReg[reg]; \ -RAM(GSU.avReg[reg]) = (uint8_t)SREG; \ -CLRFLAGS; R15++ + GSU.vLastRamAdr = GSU.avReg[reg]; \ + RAM(GSU.avReg[reg]) = (uint8_t) SREG; \ + CLRFLAGS; \ + R15++ + static void fx_stb_r0() { FX_STB(0); @@ -429,7 +464,6 @@ static void fx_loop() R15 = R13; else R15++; - CLRFLAGS; } @@ -459,13 +493,16 @@ static void fx_alt3() } /* 40-4b - ldw (rn) - load word from RAM */ -#define FX_LDW(reg) uint32_t v; \ -GSU.vLastRamAdr = GSU.avReg[reg]; \ -v = (uint32_t)RAM(GSU.avReg[reg]); \ -v |= ((uint32_t)RAM(GSU.avReg[reg]^1))<<8; \ -R15++; DREG = v; \ -TESTR14; \ -CLRFLAGS +#define FX_LDW(reg) \ + uint32_t v; \ + GSU.vLastRamAdr = GSU.avReg[reg]; \ + v = (uint32_t) RAM(GSU.avReg[reg]); \ + v |= ((uint32_t) RAM(GSU.avReg[reg] ^ 1)) << 8; \ + R15++; \ + DREG = v; \ + TESTR14; \ + CLRFLAGS + static void fx_ldw_r0() { FX_LDW(0); @@ -516,12 +553,15 @@ static void fx_ldw_r11() } /* 40-4b(ALT1) - ldb (rn) - load byte */ -#define FX_LDB(reg) uint32_t v; \ -GSU.vLastRamAdr = GSU.avReg[reg]; \ -v = (uint32_t)RAM(GSU.avReg[reg]); \ -R15++; DREG = v; \ -TESTR14; \ -CLRFLAGS +#define FX_LDB(reg) \ + uint32_t v; \ + GSU.vLastRamAdr = GSU.avReg[reg]; \ + v = (uint32_t) RAM(GSU.avReg[reg]); \ + R15++; \ + DREG = v; \ + TESTR14; \ + CLRFLAGS + static void fx_ldb_r0() { FX_LDB(0); @@ -583,22 +623,24 @@ static void fx_plot_2bit() CLRFLAGS; R1++; -#ifdef CHECK_LIMITS - if (y >= GSU.vScreenHeight) return; -#endif if (GSU.vPlotOptionReg & 0x02) - c = (x ^ y) & 1 ? (uint8_t)(GSU.vColorReg >> 4) : (uint8_t)GSU.vColorReg; + c = (x ^ y) & 1 ? (uint8_t) (GSU.vColorReg >> 4) : (uint8_t)GSU.vColorReg; else - c = (uint8_t)GSU.vColorReg; + c = (uint8_t) GSU.vColorReg; - if (!(GSU.vPlotOptionReg & 0x01) && !(c & 0xf)) return; + if (!(GSU.vPlotOptionReg & 0x01) && !(c & 0xf)) + return; a = GSU.apvScreen[y >> 3] + GSU.x[x >> 3] + ((y & 7) << 1); v = 128 >> (x & 7); - if (c & 0x01) a[0] |= v; - else a[0] &= ~v; - if (c & 0x02) a[1] |= v; - else a[1] &= ~v; + if (c & 0x01) + a[0] |= v; + else + a[0] &= ~v; + if (c & 0x02) + a[1] |= v; + else + a[1] &= ~v; } /* 2c(ALT1) - rpix - read color of the pixel with R1,R2 as x,y */ @@ -611,9 +653,6 @@ static void fx_rpix_2bit() R15++; CLRFLAGS; -#ifdef CHECK_LIMITS - if (y >= GSU.vScreenHeight) return; -#endif a = GSU.apvScreen[y >> 3] + GSU.x[x >> 3] + ((y & 7) << 1); v = 128 >> (x & 7); @@ -636,9 +675,6 @@ static void fx_plot_4bit() CLRFLAGS; R1++; -#ifdef CHECK_LIMITS - if (y >= GSU.vScreenHeight) return; -#endif if (GSU.vPlotOptionReg & 0x02) c = (x ^ y) & 1 ? (uint8_t)(GSU.vColorReg >> 4) : (uint8_t)GSU.vColorReg; else @@ -649,14 +685,22 @@ static void fx_plot_4bit() a = GSU.apvScreen[y >> 3] + GSU.x[x >> 3] + ((y & 7) << 1); v = 128 >> (x & 7); - if (c & 0x01) a[0x00] |= v; - else a[0x00] &= ~v; - if (c & 0x02) a[0x01] |= v; - else a[0x01] &= ~v; - if (c & 0x04) a[0x10] |= v; - else a[0x10] &= ~v; - if (c & 0x08) a[0x11] |= v; - else a[0x11] &= ~v; + if (c & 0x01) + a[0x00] |= v; + else + a[0x00] &= ~v; + if (c & 0x02) + a[0x01] |= v; + else + a[0x01] &= ~v; + if (c & 0x04) + a[0x10] |= v; + else + a[0x10] &= ~v; + if (c & 0x08) + a[0x11] |= v; + else + a[0x11] &= ~v; } /* 4c(ALT1) - rpix - read color of the pixel with R1,R2 as x,y */ @@ -670,10 +714,6 @@ static void fx_rpix_4bit() R15++; CLRFLAGS; -#ifdef CHECK_LIMITS - if (y >= GSU.vScreenHeight) return; -#endif - a = GSU.apvScreen[y >> 3] + GSU.x[x >> 3] + ((y & 7) << 1); v = 128 >> (x & 7); @@ -697,35 +737,50 @@ static void fx_plot_8bit() CLRFLAGS; R1++; -#ifdef CHECK_LIMITS - if (y >= GSU.vScreenHeight) return; -#endif c = (uint8_t)GSU.vColorReg; if (!(GSU.vPlotOptionReg & 0x10)) { - if (!(GSU.vPlotOptionReg & 0x01) && !(c & 0xf)) return; + if (!(GSU.vPlotOptionReg & 0x01) && !(c & 0xf)) + return; } - else if (!(GSU.vPlotOptionReg & 0x01) && !c) return; + else if (!(GSU.vPlotOptionReg & 0x01) && !c) + return; a = GSU.apvScreen[y >> 3] + GSU.x[x >> 3] + ((y & 7) << 1); v = 128 >> (x & 7); - if (c & 0x01) a[0x00] |= v; - else a[0x00] &= ~v; - if (c & 0x02) a[0x01] |= v; - else a[0x01] &= ~v; - if (c & 0x04) a[0x10] |= v; - else a[0x10] &= ~v; - if (c & 0x08) a[0x11] |= v; - else a[0x11] &= ~v; - if (c & 0x10) a[0x20] |= v; - else a[0x20] &= ~v; - if (c & 0x20) a[0x21] |= v; - else a[0x21] &= ~v; - if (c & 0x40) a[0x30] |= v; - else a[0x30] &= ~v; - if (c & 0x80) a[0x31] |= v; - else a[0x31] &= ~v; + if (c & 0x01) + a[0x00] |= v; + else + a[0x00] &= ~v; + if (c & 0x02) + a[0x01] |= v; + else + a[0x01] &= ~v; + if (c & 0x04) + a[0x10] |= v; + else + a[0x10] &= ~v; + if (c & 0x08) + a[0x11] |= v; + else + a[0x11] &= ~v; + if (c & 0x10) + a[0x20] |= v; + else + a[0x20] &= ~v; + if (c & 0x20) + a[0x21] |= v; + else + a[0x21] &= ~v; + if (c & 0x40) + a[0x30] |= v; + else + a[0x30] &= ~v; + if (c & 0x80) + a[0x31] |= v; + else + a[0x31] &= ~v; } /* 4c(ALT1) - rpix - read color of the pixel with R1,R2 as x,y */ @@ -739,9 +794,6 @@ static void fx_rpix_8bit() R15++; CLRFLAGS; -#ifdef CHECK_LIMITS - if (y >= GSU.vScreenHeight) return; -#endif a = GSU.apvScreen[y >> 3] + GSU.x[x >> 3] + ((y & 7) << 1); v = 128 >> (x & 7); @@ -759,15 +811,9 @@ static void fx_rpix_8bit() } /* 4o - plot - plot pixel with R1,R2 as x,y and the color register as the color */ -static void fx_plot_obj() -{ - printf("ERROR fx_plot_obj called\n"); -} - /* 4c(ALT1) - rpix - read color of the pixel with R1,R2 as x,y */ -static void fx_rpix_obj() +static void fx_obj_func() { - printf("ERROR fx_rpix_obj called\n"); } /* 4d - swap - swap upper and lower byte of a register */ @@ -807,10 +853,7 @@ static void fx_cmode() GSU.vPlotOptionReg = SREG; if (GSU.vPlotOptionReg & 0x10) - { - /* OBJ Mode (for drawing into sprites) */ - GSU.vScreenHeight = 256; - } + GSU.vScreenHeight = 256; // OBJ Mode (for drawing into sprites) else GSU.vScreenHeight = GSU.vScreenRealHeight; @@ -833,14 +876,16 @@ static void fx_not() /* 50-5f - add rn - add, register + register */ #define FX_ADD(reg) \ -int32_t s = SUSEX16(SREG) + SUSEX16(GSU.avReg[reg]); \ -GSU.vCarry = s >= 0x10000; \ -GSU.vOverflow = ~(SREG ^ GSU.avReg[reg]) & (GSU.avReg[reg] ^ s) & 0x8000; \ -GSU.vSign = s; \ -GSU.vZero = s; \ -R15++; DREG = s; \ -TESTR14; \ -CLRFLAGS + int32_t s = SUSEX16(SREG) + SUSEX16(GSU.avReg[reg]); \ + GSU.vCarry = s >= 0x10000; \ + GSU.vOverflow = ~(SREG ^ GSU.avReg[reg]) & (GSU.avReg[reg] ^ s) & 0x8000; \ + GSU.vSign = s; \ + GSU.vZero = s; \ + R15++; \ + DREG = s; \ + TESTR14; \ + CLRFLAGS + static void fx_add_r0() { FX_ADD(0); @@ -908,14 +953,16 @@ static void fx_add_r15() /* 50-5f(ALT1) - adc rn - add with carry, register + register */ #define FX_ADC(reg) \ -int32_t s = SUSEX16(SREG) + SUSEX16(GSU.avReg[reg]) + SEX16(GSU.vCarry); \ -GSU.vCarry = s >= 0x10000; \ -GSU.vOverflow = ~(SREG ^ GSU.avReg[reg]) & (GSU.avReg[reg] ^ s) & 0x8000; \ -GSU.vSign = s; \ -GSU.vZero = s; \ -R15++; DREG = s; \ -TESTR14; \ -CLRFLAGS + int32_t s = SUSEX16(SREG) + SUSEX16(GSU.avReg[reg]) + SEX16(GSU.vCarry); \ + GSU.vCarry = s >= 0x10000; \ + GSU.vOverflow = ~(SREG ^ GSU.avReg[reg]) & (GSU.avReg[reg] ^ s) & 0x8000; \ + GSU.vSign = s; \ + GSU.vZero = s; \ + R15++; \ + DREG = s; \ + TESTR14; \ + CLRFLAGS + static void fx_adc_r0() { FX_ADC(0); @@ -983,14 +1030,16 @@ static void fx_adc_r15() /* 50-5f(ALT2) - add #n - add, register + immediate */ #define FX_ADD_I(imm) \ -int32_t s = SUSEX16(SREG) + imm; \ -GSU.vCarry = s >= 0x10000; \ -GSU.vOverflow = ~(SREG ^ imm) & (imm ^ s) & 0x8000; \ -GSU.vSign = s; \ -GSU.vZero = s; \ -R15++; DREG = s; \ -TESTR14; \ -CLRFLAGS + int32_t s = SUSEX16(SREG) + imm; \ + GSU.vCarry = s >= 0x10000; \ + GSU.vOverflow = ~(SREG ^ imm) & (imm ^ s) & 0x8000; \ + GSU.vSign = s; \ + GSU.vZero = s; \ + R15++; \ + DREG = s; \ + TESTR14; \ + CLRFLAGS + static void fx_add_i0() { FX_ADD_I(0); @@ -1058,14 +1107,16 @@ static void fx_add_i15() /* 50-5f(ALT3) - adc #n - add with carry, register + immediate */ #define FX_ADC_I(imm) \ -int32_t s = SUSEX16(SREG) + imm + SUSEX16(GSU.vCarry); \ -GSU.vCarry = s >= 0x10000; \ -GSU.vOverflow = ~(SREG ^ imm) & (imm ^ s) & 0x8000; \ -GSU.vSign = s; \ -GSU.vZero = s; \ -R15++; DREG = s; \ -TESTR14; \ -CLRFLAGS + int32_t s = SUSEX16(SREG) + imm + SUSEX16(GSU.vCarry); \ + GSU.vCarry = s >= 0x10000; \ + GSU.vOverflow = ~(SREG ^ imm) & (imm ^ s) & 0x8000; \ + GSU.vSign = s; \ + GSU.vZero = s; \ + R15++; \ + DREG = s; \ + TESTR14; \ + CLRFLAGS + static void fx_adc_i0() { FX_ADC_I(0); @@ -1133,14 +1184,16 @@ static void fx_adc_i15() /* 60-6f - sub rn - subtract, register - register */ #define FX_SUB(reg) \ -int32_t s = SUSEX16(SREG) - SUSEX16(GSU.avReg[reg]); \ -GSU.vCarry = s >= 0; \ -GSU.vOverflow = (SREG ^ GSU.avReg[reg]) & (SREG ^ s) & 0x8000; \ -GSU.vSign = s; \ -GSU.vZero = s; \ -R15++; DREG = s; \ -TESTR14; \ -CLRFLAGS + int32_t s = SUSEX16(SREG) - SUSEX16(GSU.avReg[reg]); \ + GSU.vCarry = s >= 0; \ + GSU.vOverflow = (SREG ^ GSU.avReg[reg]) & (SREG ^ s) & 0x8000; \ + GSU.vSign = s; \ + GSU.vZero = s; \ + R15++; \ + DREG = s; \ + TESTR14; \ + CLRFLAGS + static void fx_sub_r0() { FX_SUB(0); @@ -1208,14 +1261,16 @@ static void fx_sub_r15() /* 60-6f(ALT1) - sbc rn - subtract with carry, register - register */ #define FX_SBC(reg) \ -int32_t s = SUSEX16(SREG) - SUSEX16(GSU.avReg[reg]) - (SUSEX16(GSU.vCarry^1)); \ -GSU.vCarry = s >= 0; \ -GSU.vOverflow = (SREG ^ GSU.avReg[reg]) & (SREG ^ s) & 0x8000; \ -GSU.vSign = s; \ -GSU.vZero = s; \ -R15++; DREG = s; \ -TESTR14; \ -CLRFLAGS + int32_t s = SUSEX16(SREG) - SUSEX16(GSU.avReg[reg]) - (SUSEX16(GSU.vCarry ^ 1)); \ + GSU.vCarry = s >= 0; \ + GSU.vOverflow = (SREG ^ GSU.avReg[reg]) & (SREG ^ s) & 0x8000; \ + GSU.vSign = s; \ + GSU.vZero = s; \ + R15++; \ + DREG = s; \ + TESTR14; \ + CLRFLAGS + static void fx_sbc_r0() { FX_SBC(0); @@ -1283,14 +1338,16 @@ static void fx_sbc_r15() /* 60-6f(ALT2) - sub #n - subtract, register - immediate */ #define FX_SUB_I(imm) \ -int32_t s = SUSEX16(SREG) - imm; \ -GSU.vCarry = s >= 0; \ -GSU.vOverflow = (SREG ^ imm) & (SREG ^ s) & 0x8000; \ -GSU.vSign = s; \ -GSU.vZero = s; \ -R15++; DREG = s; \ -TESTR14; \ -CLRFLAGS + int32_t s = SUSEX16(SREG) - imm; \ + GSU.vCarry = s >= 0; \ + GSU.vOverflow = (SREG ^ imm) & (SREG ^ s) & 0x8000; \ + GSU.vSign = s; \ + GSU.vZero = s; \ + R15++; \ + DREG = s; \ + TESTR14; \ + CLRFLAGS + static void fx_sub_i0() { FX_SUB_I(0); @@ -1358,13 +1415,14 @@ static void fx_sub_i15() /* 60-6f(ALT3) - cmp rn - compare, register, register */ #define FX_CMP(reg) \ -int32_t s = SUSEX16(SREG) - SUSEX16(GSU.avReg[reg]); \ -GSU.vCarry = s >= 0; \ -GSU.vOverflow = (SREG ^ GSU.avReg[reg]) & (SREG ^ s) & 0x8000; \ -GSU.vSign = s; \ -GSU.vZero = s; \ -R15++; \ -CLRFLAGS; + int32_t s = SUSEX16(SREG) - SUSEX16(GSU.avReg[reg]); \ + GSU.vCarry = s >= 0; \ + GSU.vOverflow = (SREG ^ GSU.avReg[reg]) & (SREG ^ s) & 0x8000; \ + GSU.vSign = s; \ + GSU.vZero = s; \ + R15++; \ + CLRFLAGS + static void fx_cmp_r0() { FX_CMP(0); @@ -1446,12 +1504,14 @@ static void fx_merge() /* 71-7f - and rn - reister & register */ #define FX_AND(reg) \ -uint32_t v = SREG & GSU.avReg[reg]; \ -R15++; DREG = v; \ -GSU.vSign = v; \ -GSU.vZero = v; \ -TESTR14; \ -CLRFLAGS; + uint32_t v = SREG & GSU.avReg[reg]; \ + R15++; \ + DREG = v; \ + GSU.vSign = v; \ + GSU.vZero = v; \ + TESTR14; \ + CLRFLAGS + static void fx_and_r1() { FX_AND(1); @@ -1515,12 +1575,14 @@ static void fx_and_r15() /* 71-7f(ALT1) - bic rn - reister & ~register */ #define FX_BIC(reg) \ -uint32_t v = SREG & ~GSU.avReg[reg]; \ -R15++; DREG = v; \ -GSU.vSign = v; \ -GSU.vZero = v; \ -TESTR14; \ -CLRFLAGS; + uint32_t v = SREG & ~GSU.avReg[reg]; \ + R15++; \ + DREG = v; \ + GSU.vSign = v; \ + GSU.vZero = v; \ + TESTR14; \ + CLRFLAGS + static void fx_bic_r1() { FX_BIC(1); @@ -1584,12 +1646,14 @@ static void fx_bic_r15() /* 71-7f(ALT2) - and #n - reister & immediate */ #define FX_AND_I(imm) \ -uint32_t v = SREG & imm; \ -R15++; DREG = v; \ -GSU.vSign = v; \ -GSU.vZero = v; \ -TESTR14; \ -CLRFLAGS; + uint32_t v = SREG & imm; \ + R15++; \ + DREG = v; \ + GSU.vSign = v; \ + GSU.vZero = v; \ + TESTR14; \ + CLRFLAGS + static void fx_and_i1() { FX_AND_I(1); @@ -1653,12 +1717,14 @@ static void fx_and_i15() /* 71-7f(ALT3) - bic #n - reister & ~immediate */ #define FX_BIC_I(imm) \ -uint32_t v = SREG & ~imm; \ -R15++; DREG = v; \ -GSU.vSign = v; \ -GSU.vZero = v; \ -TESTR14; \ -CLRFLAGS; + uint32_t v = SREG & ~imm; \ + R15++; \ + DREG = v; \ + GSU.vSign = v; \ + GSU.vZero = v; \ + TESTR14; \ + CLRFLAGS + static void fx_bic_i1() { FX_BIC_I(1); @@ -1722,12 +1788,14 @@ static void fx_bic_i15() /* 80-8f - mult rn - 8 bit to 16 bit signed multiply, register * register */ #define FX_MULT(reg) \ -uint32_t v = (uint32_t)(SEX8(SREG) * SEX8(GSU.avReg[reg])); \ -R15++; DREG = v; \ -GSU.vSign = v; \ -GSU.vZero = v; \ -TESTR14; \ -CLRFLAGS; + uint32_t v = (uint32_t) (SEX8(SREG) * SEX8(GSU.avReg[reg])); \ + R15++; \ + DREG = v; \ + GSU.vSign = v; \ + GSU.vZero = v; \ + TESTR14; \ + CLRFLAGS + static void fx_mult_r0() { FX_MULT(0); @@ -1795,12 +1863,14 @@ static void fx_mult_r15() /* 80-8f(ALT1) - umult rn - 8 bit to 16 bit unsigned multiply, register * register */ #define FX_UMULT(reg) \ -uint32_t v = USEX8(SREG) * USEX8(GSU.avReg[reg]); \ -R15++; DREG = v; \ -GSU.vSign = v; \ -GSU.vZero = v; \ -TESTR14; \ -CLRFLAGS; + uint32_t v = USEX8(SREG) * USEX8(GSU.avReg[reg]); \ + R15++; \ + DREG = v; \ + GSU.vSign = v; \ + GSU.vZero = v; \ + TESTR14; \ + CLRFLAGS + static void fx_umult_r0() { FX_UMULT(0); @@ -1868,12 +1938,14 @@ static void fx_umult_r15() /* 80-8f(ALT2) - mult #n - 8 bit to 16 bit signed multiply, register * immediate */ #define FX_MULT_I(imm) \ -uint32_t v = (uint32_t) (SEX8(SREG) * ((int32_t)imm)); \ -R15++; DREG = v; \ -GSU.vSign = v; \ -GSU.vZero = v; \ -TESTR14; \ -CLRFLAGS; + uint32_t v = (uint32_t) (SEX8(SREG) * ((int32_t) imm)); \ + R15++; \ + DREG = v; \ + GSU.vSign = v; \ + GSU.vZero = v; \ + TESTR14; \ + CLRFLAGS + static void fx_mult_i0() { FX_MULT_I(0); @@ -1941,12 +2013,14 @@ static void fx_mult_i15() /* 80-8f(ALT3) - umult #n - 8 bit to 16 bit unsigned multiply, register * immediate */ #define FX_UMULT_I(imm) \ -uint32_t v = USEX8(SREG) * ((uint32_t)imm); \ -R15++; DREG = v; \ -GSU.vSign = v; \ -GSU.vZero = v; \ -TESTR14; \ -CLRFLAGS; + uint32_t v = USEX8(SREG) * ((uint32_t) imm); \ + R15++; \ + DREG = v; \ + GSU.vSign = v; \ + GSU.vZero = v; \ + TESTR14; \ + CLRFLAGS + static void fx_umult_i0() { FX_UMULT_I(0); @@ -2022,7 +2096,11 @@ static void fx_sbk() } /* 91-94 - link #n - R11 = R15 + immediate */ -#define FX_LINK_I(lkn) R11 = R15 + lkn; CLRFLAGS; R15++ +#define FX_LINK_I(lkn) \ + R11 = R15 + lkn; \ + CLRFLAGS; \ + R15++ + static void fx_link_i1() { FX_LINK_I(1); @@ -2099,8 +2177,9 @@ static void fx_ror() /* 98-9d - jmp rn - jump to address of register */ #define FX_JMP(reg) \ -R15 = GSU.avReg[reg]; \ -CLRFLAGS; + R15 = GSU.avReg[reg]; \ + CLRFLAGS + static void fx_jmp_r8() { FX_JMP(8); @@ -2128,10 +2207,13 @@ static void fx_jmp_r13() /* 98-9d(ALT1) - ljmp rn - set program bank to source register and jump to address of register */ #define FX_LJMP(reg) \ -GSU.vPrgBankReg = GSU.avReg[reg] & 0x7f; \ -GSU.pvPrgBank = GSU.apvRomBank[GSU.vPrgBankReg]; \ -R15 = SREG; \ -GSU.bCacheActive = false; fx_cache(); R15--; + GSU.vPrgBankReg = GSU.avReg[reg] & 0x7f; \ + GSU.pvPrgBank = GSU.apvRomBank[GSU.vPrgBankReg]; \ + R15 = SREG; \ + GSU.bCacheActive = false; \ + fx_cache(); \ + R15-- + static void fx_ljmp_r8() { FX_LJMP(8); @@ -2203,10 +2285,13 @@ static void fx_lmult() /* a0-af - ibt rn,#pp - immediate byte transfer */ #define FX_IBT(reg) \ -uint8_t v = PIPE; R15++; \ -FETCHPIPE; R15++; \ -GSU.avReg[reg] = SEX8(v); \ -CLRFLAGS; + uint8_t v = PIPE; \ + R15++; \ + FETCHPIPE; \ + R15++; \ + GSU.avReg[reg] = SEX8(v); \ + CLRFLAGS + static void fx_ibt_r0() { FX_IBT(0); @@ -2275,11 +2360,14 @@ static void fx_ibt_r15() /* a0-af(ALT1) - lms rn,(yy) - load word from RAM (short address) */ #define FX_LMS(reg) \ -GSU.vLastRamAdr = ((uint32_t)PIPE) << 1; \ -R15++; FETCHPIPE; R15++; \ -GSU.avReg[reg] = (uint32_t)RAM(GSU.vLastRamAdr); \ -GSU.avReg[reg] |= ((uint32_t)RAM(GSU.vLastRamAdr+1))<<8; \ -CLRFLAGS; + GSU.vLastRamAdr = ((uint32_t) PIPE) << 1; \ + R15++; \ + FETCHPIPE; \ + R15++; \ + GSU.avReg[reg] = (uint32_t) RAM(GSU.vLastRamAdr); \ + GSU.avReg[reg] |= ((uint32_t) RAM(GSU.vLastRamAdr + 1)) << 8; \ + CLRFLAGS + static void fx_lms_r0() { FX_LMS(0); @@ -2349,12 +2437,15 @@ static void fx_lms_r15() /* a0-af(ALT2) - sms (yy),rn - store word in RAM (short address) */ /* If rn == r15, is the value of r15 before or after the extra byte is read? */ #define FX_SMS(reg) \ -uint32_t v = GSU.avReg[reg]; \ -GSU.vLastRamAdr = ((uint32_t)PIPE) << 1; \ -R15++; FETCHPIPE; \ -RAM(GSU.vLastRamAdr) = (uint8_t)v; \ -RAM(GSU.vLastRamAdr+1) = (uint8_t)(v>>8); \ -CLRFLAGS; R15++; + uint32_t v = GSU.avReg[reg]; \ + GSU.vLastRamAdr = ((uint32_t) PIPE) << 1; \ + R15++; \ + FETCHPIPE; \ + RAM(GSU.vLastRamAdr) = (uint8_t) v; \ + RAM(GSU.vLastRamAdr + 1) = (uint8_t) (v >> 8); \ + CLRFLAGS; \ + R15++ + static void fx_sms_r0() { FX_SMS(0); @@ -2423,9 +2514,23 @@ static void fx_sms_r15() /* b0-bf - from rn - set source register */ /* b0-bf(B) - moves rn - move register to register, and set flags, (if B flag is set) */ #define FX_FROM(reg) \ -if(TF(B)) { uint32_t v = GSU.avReg[reg]; R15++; DREG = v; \ -GSU.vOverflow = (v&0x80) << 16; GSU.vSign = v; GSU.vZero = v; TESTR14; CLRFLAGS; } \ -else { GSU.pvSreg = &GSU.avReg[reg]; R15++; } + if (TF(B)) \ + { \ + uint32_t v = GSU.avReg[reg]; \ + R15++; \ + DREG = v; \ + GSU.vOverflow = (v & 0x80) << 16; \ + GSU.vSign = v; \ + GSU.vZero = v; \ + TESTR14; \ + CLRFLAGS; \ + } \ + else \ + { \ + GSU.pvSreg = &GSU.avReg[reg]; \ + R15++; \ + } + static void fx_from_r0() { FX_FROM(0); @@ -2505,11 +2610,14 @@ static void fx_hib() /* c1-cf - or rn */ #define FX_OR(reg) \ -uint32_t v = SREG | GSU.avReg[reg]; R15++; DREG = v; \ -GSU.vSign = v; \ -GSU.vZero = v; \ -TESTR14; \ -CLRFLAGS; + uint32_t v = SREG | GSU.avReg[reg]; \ + R15++; \ + DREG = v; \ + GSU.vSign = v; \ + GSU.vZero = v; \ + TESTR14; \ + CLRFLAGS + static void fx_or_r1() { FX_OR(1); @@ -2573,11 +2681,14 @@ static void fx_or_r15() /* c1-cf(ALT1) - xor rn */ #define FX_XOR(reg) \ -uint32_t v = SREG ^ GSU.avReg[reg]; R15++; DREG = v; \ -GSU.vSign = v; \ -GSU.vZero = v; \ -TESTR14; \ -CLRFLAGS; + uint32_t v = SREG ^ GSU.avReg[reg]; \ + R15++; \ + DREG = v; \ + GSU.vSign = v; \ + GSU.vZero = v; \ + TESTR14; \ + CLRFLAGS + static void fx_xor_r1() { FX_XOR(1); @@ -2641,11 +2752,14 @@ static void fx_xor_r15() /* c1-cf(ALT2) - or #n */ #define FX_OR_I(imm) \ -uint32_t v = SREG | imm; R15++; DREG = v; \ -GSU.vSign = v; \ -GSU.vZero = v; \ -TESTR14; \ -CLRFLAGS; + uint32_t v = SREG | imm; \ + R15++; \ + DREG = v; \ + GSU.vSign = v; \ + GSU.vZero = v; \ + TESTR14; \ + CLRFLAGS + static void fx_or_i1() { FX_OR_I(1); @@ -2709,11 +2823,14 @@ static void fx_or_i15() /* c1-cf(ALT3) - xor #n */ #define FX_XOR_I(imm) \ -uint32_t v = SREG ^ imm; R15++; DREG = v; \ -GSU.vSign = v; \ -GSU.vZero = v; \ -TESTR14; \ -CLRFLAGS; + uint32_t v = SREG ^ imm; \ + R15++; \ + DREG = v; \ + GSU.vSign = v; \ + GSU.vZero = v; \ + TESTR14; \ + CLRFLAGS + static void fx_xor_i1() { FX_XOR_I(1); @@ -2777,10 +2894,12 @@ static void fx_xor_i15() /* d0-de - inc rn - increase by one */ #define FX_INC(reg) \ -GSU.avReg[reg] += 1; \ -GSU.vSign = GSU.avReg[reg]; \ -GSU.vZero = GSU.avReg[reg]; \ -CLRFLAGS; R15++; + GSU.avReg[reg] += 1; \ + GSU.vSign = GSU.avReg[reg]; \ + GSU.vZero = GSU.avReg[reg]; \ + CLRFLAGS; \ + R15++ + static void fx_inc_r0() { FX_INC(0); @@ -2885,10 +3004,12 @@ static void fx_romb() /* e0-ee - dec rn - decrement by one */ #define FX_DEC(reg) \ -GSU.avReg[reg] -= 1; \ -GSU.vSign = GSU.avReg[reg]; \ -GSU.vZero = GSU.avReg[reg]; \ -CLRFLAGS; R15++; + GSU.avReg[reg] -= 1; \ + GSU.vSign = GSU.avReg[reg]; \ + GSU.vZero = GSU.avReg[reg]; \ + CLRFLAGS; \ + R15++ + static void fx_dec_r0() { FX_DEC(0); @@ -2988,8 +3109,7 @@ static void fx_getbl() { uint32_t v; #ifndef FX_DO_ROMBUFFER - uint32_t c; - c = (uint32_t)ROM(R14); + uint32_t c = (uint32_t)ROM(R14); #else uint32_t c = USEX8(GSU.vRomBuffer); #endif @@ -3019,10 +3139,16 @@ static void fx_getbs() /* f0-ff - iwt rn,#xx - immediate word transfer to register */ #define FX_IWT(reg) \ -uint32_t v = PIPE; R15++; FETCHPIPE; R15++; \ -v |= USEX8(PIPE) << 8; FETCHPIPE; R15++; \ -GSU.avReg[reg] = v; \ -CLRFLAGS; + uint32_t v = PIPE; \ + R15++; \ + FETCHPIPE; \ + R15++; \ + v |= USEX8(PIPE) << 8; \ + FETCHPIPE; \ + R15++; \ + GSU.avReg[reg] = v; \ + CLRFLAGS + static void fx_iwt_r0() { FX_IWT(0); @@ -3091,11 +3217,17 @@ static void fx_iwt_r15() /* f0-ff(ALT1) - lm rn,(xx) - load word from RAM */ #define FX_LM(reg) \ -GSU.vLastRamAdr = PIPE; R15++; FETCHPIPE; R15++; \ -GSU.vLastRamAdr |= USEX8(PIPE) << 8; FETCHPIPE; R15++; \ -GSU.avReg[reg] = RAM(GSU.vLastRamAdr); \ -GSU.avReg[reg] |= USEX8(RAM(GSU.vLastRamAdr^1)) << 8; \ -CLRFLAGS; + GSU.vLastRamAdr = PIPE; \ + R15++; \ + FETCHPIPE; \ + R15++; \ + GSU.vLastRamAdr |= USEX8(PIPE) << 8; \ + FETCHPIPE; \ + R15++; \ + GSU.avReg[reg] = RAM(GSU.vLastRamAdr); \ + GSU.avReg[reg] |= USEX8(RAM(GSU.vLastRamAdr ^ 1)) << 8; \ + CLRFLAGS + static void fx_lm_r0() { FX_LM(0); @@ -3165,12 +3297,18 @@ static void fx_lm_r15() /* f0-ff(ALT2) - sm (xx),rn - store word in RAM */ /* If rn == r15, is the value of r15 before or after the extra bytes are read? */ #define FX_SM(reg) \ -uint32_t v = GSU.avReg[reg]; \ -GSU.vLastRamAdr = PIPE; R15++; FETCHPIPE; R15++; \ -GSU.vLastRamAdr |= USEX8(PIPE) << 8; FETCHPIPE; \ -RAM(GSU.vLastRamAdr) = (uint8_t)v; \ -RAM(GSU.vLastRamAdr^1) = (uint8_t)(v>>8); \ -CLRFLAGS; R15++; + uint32_t v = GSU.avReg[reg]; \ + GSU.vLastRamAdr = PIPE; \ + R15++; \ + FETCHPIPE; \ + R15++; \ + GSU.vLastRamAdr |= USEX8(PIPE) << 8; \ + FETCHPIPE; \ + RAM(GSU.vLastRamAdr) = (uint8_t) v; \ + RAM(GSU.vLastRamAdr ^ 1) = (uint8_t) (v >> 8); \ + CLRFLAGS; \ + R15++ + static void fx_sm_r0() { FX_SM(0); @@ -3238,7 +3376,7 @@ static void fx_sm_r15() /*** GSU executions functions ***/ -static uint32_t fx_run(uint32_t nInstructions) +uint32_t fx_run(uint32_t nInstructions) { GSU.vCounter = nInstructions; READR14; @@ -3247,70 +3385,15 @@ static uint32_t fx_run(uint32_t nInstructions) return (nInstructions - GSU.vInstCount); } -static uint32_t fx_run_to_breakpoint(uint32_t nInstructions) -{ - uint32_t vCounter = 0; - while (TF(G) && vCounter < nInstructions) - { - vCounter++; - FX_STEP; - if (USEX16(R15) == GSU.vBreakPoint) - { - GSU.vErrorCode = FX_BREAKPOINT; - break; - } - } - return vCounter; -} - -static uint32_t fx_step_over(uint32_t nInstructions) -{ - uint32_t vCounter = 0; - while (TF(G) && vCounter < nInstructions) - { - vCounter++; - FX_STEP; - if (USEX16(R15) == GSU.vBreakPoint) - { - GSU.vErrorCode = FX_BREAKPOINT; - break; - } - if (USEX16(R15) == GSU.vStepPoint) - break; - } - return vCounter; -} - -#ifdef FX_FUNCTION_TABLE -uint32_t(*FX_FUNCTION_TABLE[])(uint32_t) = -#else -uint32_t(*fx_apfFunctionTable[])(uint32_t) = -#endif -{ - &fx_run, - &fx_run_to_breakpoint, - &fx_step_over, -}; - /*** Special table for the different plot configurations ***/ - -#ifdef FX_PLOT_TABLE -void (*FX_PLOT_TABLE[])() = -#else void (*fx_apfPlotTable[])() = -#endif { - &fx_plot_2bit, &fx_plot_4bit, &fx_plot_4bit, &fx_plot_8bit, &fx_plot_obj, - &fx_rpix_2bit, &fx_rpix_4bit, &fx_rpix_4bit, &fx_rpix_8bit, &fx_rpix_obj, + &fx_plot_2bit, &fx_plot_4bit, &fx_plot_4bit, &fx_plot_8bit, &fx_obj_func, + &fx_rpix_2bit, &fx_rpix_4bit, &fx_rpix_4bit, &fx_rpix_8bit, &fx_obj_func, }; /*** Opcode table ***/ - -#ifdef FX_OPCODE_TABLE -void (*FX_OPCODE_TABLE[])() = -#else void (*fx_apfOpcodeTable[])() = -#endif { /* * ALT0 Table diff --git a/source/fxinst.h b/source/fxinst.h index a78b6d4..ce9187d 100644 --- a/source/fxinst.h +++ b/source/fxinst.h @@ -337,28 +337,12 @@ struct FxRegs_s /* Execute instruction from the pipe, and fetch next byte to the pipe */ #define FX_STEP { uint32_t vOpcode = (uint32_t)PIPE; FETCHPIPE; \ -(*fx_ppfOpcodeTable[ (GSU.vStatusReg & 0x300) | vOpcode ])(); } \ +(*fx_apfOpcodeTable[ (GSU.vStatusReg & 0x300) | vOpcode ])(); } \ -#define FX_FUNCTION_RUN 0 -#define FX_FUNCTION_RUN_TO_BREAKPOINT 1 -#define FX_FUNCTION_STEP_OVER 2 - -extern uint32_t(**fx_ppfFunctionTable)(uint32_t); -extern void (**fx_ppfPlotTable)(); -extern void (**fx_ppfOpcodeTable)(); - -extern uint32_t(*fx_apfFunctionTable[])(uint32_t); extern void (*fx_apfOpcodeTable[])(); extern void (*fx_apfPlotTable[])(); -extern uint32_t(*fx_a_apfFunctionTable[])(uint32_t); -extern void (*fx_a_apfOpcodeTable[])(); -extern void (*fx_a_apfPlotTable[])(); -extern uint32_t(*fx_r_apfFunctionTable[])(uint32_t); -extern void (*fx_r_apfOpcodeTable[])(); -extern void (*fx_r_apfPlotTable[])(); -extern uint32_t(*fx_ar_apfFunctionTable[])(uint32_t); -extern void (*fx_ar_apfOpcodeTable[])(); -extern void (*fx_ar_apfPlotTable[])(); + +uint32_t fx_run(uint32_t nInstructions); /* Set this define if branches are relative to the instruction in the delay slot */ /* (I think they are) */ diff --git a/source/getset.h b/source/getset.h index b0abba5..7d28a04 100644 --- a/source/getset.h +++ b/source/getset.h @@ -37,9 +37,6 @@ INLINE uint8_t S9xGetByte(uint32_t Address) case MAP_CPU: return (S9xGetCPU(Address & 0xffff)); case MAP_DSP: -#ifdef DSP_DUMMY_LOOPS - printf("Get DSP Byte @ %06X\n", Address); -#endif return (S9xGetDSP(Address & 0xffff)); case MAP_SA1RAM: case MAP_LOROM_SRAM: @@ -54,7 +51,7 @@ INLINE uint8_t S9xGetByte(uint32_t Address) case MAP_BWRAM: return (*(Memory.BWRAM + ((Address & 0x7fff) - 0x6000))); case MAP_C4: - return (S9xGetC4(Address & 0xffff)); + return S9xGetC4(Address & 0xffff); case MAP_SPC7110_ROM: return S9xGetSPC7110Byte(Address); case MAP_SPC7110_DRAM: @@ -65,7 +62,6 @@ INLINE uint8_t S9xGetByte(uint32_t Address) return S9xGetSetaDSP(Address); case MAP_SETA_RISC: return S9xGetST018(Address); - case MAP_DEBUG: default: return OpenBus; } @@ -79,13 +75,11 @@ INLINE uint16_t S9xGetWord(uint32_t Address) return (OpenBus | (S9xGetByte(Address + 1) << 8)); } int32_t block; - uint8_t* GetAddress = Memory.Map [block = (Address >> MEMMAP_SHIFT) & - MEMMAP_MASK]; + uint8_t* GetAddress = Memory.Map [block = (Address >> MEMMAP_SHIFT) & MEMMAP_MASK]; if (!CPU.InDMA) CPU.Cycles += (Memory.MemorySpeed [block] << 1); - if (GetAddress >= (uint8_t*) MAP_LAST) { #ifdef CPU_SHUTDOWN @@ -95,25 +89,18 @@ INLINE uint16_t S9xGetWord(uint32_t Address) #ifdef FAST_LSB_WORD_ACCESS return (*(uint16_t*)(GetAddress + (Address & 0xffff))); #else - return (*(GetAddress + (Address & 0xffff)) | - (*(GetAddress + (Address & 0xffff) + 1) << 8)); + return (*(GetAddress + (Address & 0xffff)) | (*(GetAddress + (Address & 0xffff) + 1) << 8)); #endif } switch ((intptr_t) GetAddress) { case MAP_PPU: - return (S9xGetPPU(Address & 0xffff) | - (S9xGetPPU((Address + 1) & 0xffff) << 8)); + return (S9xGetPPU(Address & 0xffff) | (S9xGetPPU((Address + 1) & 0xffff) << 8)); case MAP_CPU: - return (S9xGetCPU(Address & 0xffff) | - (S9xGetCPU((Address + 1) & 0xffff) << 8)); + return (S9xGetCPU(Address & 0xffff) | (S9xGetCPU((Address + 1) & 0xffff) << 8)); case MAP_DSP: -#ifdef DSP_DUMMY_LOOPS - printf("Get DSP Word @ %06X\n", Address); -#endif - return (S9xGetDSP(Address & 0xffff) | - (S9xGetDSP((Address + 1) & 0xffff) << 8)); + return (S9xGetDSP(Address & 0xffff) | (S9xGetDSP((Address + 1) & 0xffff) << 8)); case MAP_SA1RAM: case MAP_LOROM_SRAM: //Address &0x7FFF -offset into bank @@ -123,10 +110,8 @@ INLINE uint16_t S9xGetWord(uint32_t Address) /* BJ: no FAST_LSB_WORD_ACCESS here, since if Memory.SRAMMask=0x7ff * then the high byte doesn't follow the low byte. */ return - (*(Memory.SRAM + ((((Address & 0xFF0000) >> 1) | (Address & 0x7FFF)) - &Memory.SRAMMask))) | - ((*(Memory.SRAM + (((((Address + 1) & 0xFF0000) >> 1) | (( - Address + 1) & 0x7FFF)) &Memory.SRAMMask))) << 8); + (*(Memory.SRAM + ((((Address & 0xFF0000) >> 1) | (Address & 0x7FFF)) & Memory.SRAMMask))) | + ((*(Memory.SRAM + (((((Address + 1) & 0xFF0000) >> 1) | ((Address + 1) & 0x7FFF)) & Memory.SRAMMask))) << 8); case MAP_RONLY_SRAM: case MAP_HIROM_SRAM: /* BJ: no FAST_LSB_WORD_ACCESS here, since if Memory.SRAMMask=0x7ff @@ -141,18 +126,14 @@ INLINE uint16_t S9xGetWord(uint32_t Address) #ifdef FAST_LSB_WORD_ACCESS return (*(uint16_t*)(Memory.BWRAM + ((Address & 0x7fff) - 0x6000))); #else - return (*(Memory.BWRAM + ((Address & 0x7fff) - 0x6000)) | - (*(Memory.BWRAM + (((Address + 1) & 0x7fff) - 0x6000)) << 8)); + return (*(Memory.BWRAM + ((Address & 0x7fff) - 0x6000)) | (*(Memory.BWRAM + (((Address + 1) & 0x7fff) - 0x6000)) << 8)); #endif case MAP_C4: - return (S9xGetC4(Address & 0xffff) | - (S9xGetC4((Address + 1) & 0xffff) << 8)); + return (S9xGetC4(Address & 0xffff) | (S9xGetC4((Address + 1) & 0xffff) << 8)); case MAP_SPC7110_ROM: - return (S9xGetSPC7110Byte(Address) | - (S9xGetSPC7110Byte(Address + 1)) << 8); + return (S9xGetSPC7110Byte(Address) | (S9xGetSPC7110Byte(Address + 1)) << 8); case MAP_SPC7110_DRAM: - return (S9xGetSPC7110(0x4800) | - (S9xGetSPC7110(0x4800) << 8)); + return (S9xGetSPC7110(0x4800) | (S9xGetSPC7110(0x4800) << 8)); case MAP_OBC_RAM: return GetOBC1(Address & 0xFFFF) | (GetOBC1((Address + 1) & 0xFFFF) << 8); case MAP_SETA_DSP: @@ -170,8 +151,7 @@ INLINE void S9xSetByte(uint8_t Byte, uint32_t Address) CPU.WaitAddress = NULL; #endif int32_t block; - uint8_t* SetAddress = Memory.WriteMap [block = ((Address >> MEMMAP_SHIFT) & - MEMMAP_MASK)]; + uint8_t* SetAddress = Memory.WriteMap [block = ((Address >> MEMMAP_SHIFT) & MEMMAP_MASK)]; if (!CPU.InDMA) CPU.Cycles += Memory.MemorySpeed [block]; @@ -203,24 +183,19 @@ INLINE void S9xSetByte(uint8_t Byte, uint32_t Address) S9xSetCPU(Byte, Address & 0xffff); return; case MAP_DSP: -#ifdef DSP_DUMMY_LOOPS - printf("DSP Byte: %02X to %06X\n", Byte, Address); -#endif S9xSetDSP(Byte, Address & 0xffff); return; case MAP_LOROM_SRAM: if (Memory.SRAMMask) { - *(Memory.SRAM + ((((Address & 0xFF0000) >> 1) | (Address & 0x7FFF))& - Memory.SRAMMask)) = Byte; + *(Memory.SRAM + ((((Address & 0xFF0000) >> 1) | (Address & 0x7FFF)) & Memory.SRAMMask)) = Byte; CPU.SRAMModified = true; } return; case MAP_HIROM_SRAM: if (Memory.SRAMMask) { - *(Memory.SRAM + (((Address & 0x7fff) - 0x6000 + - ((Address & 0xf0000) >> 3)) & Memory.SRAMMask)) = Byte; + *(Memory.SRAM + (((Address & 0x7fff) - 0x6000 + ((Address & 0xf0000) >> 3)) & Memory.SRAMMask)) = Byte; CPU.SRAMModified = true; } return; @@ -228,7 +203,6 @@ INLINE void S9xSetByte(uint8_t Byte, uint32_t Address) *(Memory.BWRAM + ((Address & 0x7fff) - 0x6000)) = Byte; CPU.SRAMModified = true; return; - case MAP_DEBUG: case MAP_SA1RAM: *(Memory.SRAM + (Address & 0xffff)) = Byte; SA1.Executing = !SA1.Waiting; @@ -266,8 +240,7 @@ INLINE void S9xSetWord(uint16_t Word, uint32_t Address) CPU.WaitAddress = NULL; #endif int32_t block; - uint8_t* SetAddress = Memory.WriteMap [block = ((Address >> MEMMAP_SHIFT) & - MEMMAP_MASK)]; + uint8_t* SetAddress = Memory.WriteMap [block = ((Address >> MEMMAP_SHIFT) & MEMMAP_MASK)]; if (!CPU.InDMA) CPU.Cycles += Memory.MemorySpeed [block] << 1; @@ -284,7 +257,7 @@ INLINE void S9xSetWord(uint16_t Word, uint32_t Address) SA1.WaitCounter = 0; } #ifdef FAST_LSB_WORD_ACCESS - *(uint16_t*) SetAddress = Word; + *(uint16_t*)SetAddress = Word; #else *SetAddress = (uint8_t) Word; *(SetAddress + 1) = Word >> 8; @@ -307,14 +280,11 @@ INLINE void S9xSetWord(uint16_t Word, uint32_t Address) S9xSetPPU(Word >> 8, (Address & 0xffff) + 1); return; case MAP_CPU: - S9xSetCPU((uint8_t) Word, (Address & 0xffff)); + S9xSetCPU((uint8_t) Word, Address & 0xffff); S9xSetCPU(Word >> 8, (Address & 0xffff) + 1); return; case MAP_DSP: -#ifdef DSP_DUMMY_LOOPS - printf("DSP Word: %04X to %06X\n", Word, Address); -#endif - S9xSetDSP((uint8_t) Word, (Address & 0xffff)); + S9xSetDSP((uint8_t) Word, Address & 0xffff); S9xSetDSP(Word >> 8, (Address & 0xffff) + 1); return; case MAP_LOROM_SRAM: @@ -322,11 +292,8 @@ INLINE void S9xSetWord(uint16_t Word, uint32_t Address) { /* BJ: no FAST_LSB_WORD_ACCESS here, since if Memory.SRAMMask=0x7ff * then the high byte doesn't follow the low byte. */ - *(Memory.SRAM + ((((Address & 0xFF0000) >> 1) | (Address & 0x7FFF))& - Memory.SRAMMask)) = (uint8_t) Word; - *(Memory.SRAM + (((((Address + 1) & 0xFF0000) >> 1) | (( - Address + 1) & 0x7FFF))& Memory.SRAMMask)) = Word >> 8; - + *(Memory.SRAM + ((((Address & 0xFF0000) >> 1) | (Address & 0x7FFF)) & Memory.SRAMMask)) = (uint8_t) Word; + *(Memory.SRAM + (((((Address + 1) & 0xFF0000) >> 1) | ((Address + 1) & 0x7FFF))& Memory.SRAMMask)) = Word >> 8; CPU.SRAMModified = true; } return; @@ -349,11 +316,10 @@ INLINE void S9xSetWord(uint16_t Word, uint32_t Address) *(uint16_t*)(Memory.BWRAM + ((Address & 0x7fff) - 0x6000)) = Word; #else *(Memory.BWRAM + ((Address & 0x7fff) - 0x6000)) = (uint8_t) Word; - *(Memory.BWRAM + (((Address + 1) & 0x7fff) - 0x6000)) = (uint8_t)(Word >> 8); + *(Memory.BWRAM + (((Address + 1) & 0x7fff) - 0x6000)) = (uint8_t) (Word >> 8); #endif CPU.SRAMModified = true; return; - case MAP_DEBUG: case MAP_SPC7110_DRAM: s7r.bank50[(Address & 0xffff)] = (uint8_t) Word; s7r.bank50[((Address + 1) & 0xffff)] = (uint8_t) Word; @@ -400,22 +366,21 @@ INLINE uint8_t* GetBasePointer(uint32_t Address) case MAP_PPU: //just a guess, but it looks like this should match the CPU as a source. case MAP_CPU: //fixes Ogre Battle's green lines case MAP_OBC_RAM: - return (Memory.FillRAM); + return Memory.FillRAM; case MAP_DSP: return (Memory.FillRAM - 0x6000); case MAP_SA1RAM: case MAP_LOROM_SRAM: - return (Memory.SRAM); + case MAP_SETA_DSP: + return Memory.SRAM; case MAP_BWRAM: return (Memory.BWRAM - 0x6000); case MAP_HIROM_SRAM: return (Memory.SRAM - 0x6000); case MAP_C4: return (Memory.C4RAM - 0x6000); - case MAP_SETA_DSP: - return Memory.SRAM; default: - return (0); + return NULL; } } @@ -431,7 +396,7 @@ INLINE uint8_t* S9xGetMemPointer(uint32_t Address) switch ((intptr_t) GetAddress) { case MAP_SPC7110_DRAM: - return &s7r.bank50[Address & 0x0000FFFF]; + return &s7r.bank50[Address & 0xffff]; case MAP_PPU: return (Memory.FillRAM + (Address & 0xffff)); case MAP_CPU: @@ -452,7 +417,7 @@ INLINE uint8_t* S9xGetMemPointer(uint32_t Address) case MAP_SETA_DSP: return Memory.SRAM + ((Address & 0xffff) & Memory.SRAMMask); default: - return (0); + return NULL; } } @@ -470,18 +435,12 @@ INLINE void S9xSetPCBase(uint32_t Address) switch ((intptr_t) GetAddress) { case MAP_PPU: - CPU.PCBase = Memory.FillRAM; - break; case MAP_CPU: CPU.PCBase = Memory.FillRAM; break; case MAP_DSP: CPU.PCBase = Memory.FillRAM - 0x6000; break; - case MAP_SA1RAM: - case MAP_LOROM_SRAM: - CPU.PCBase = Memory.SRAM; - break; case MAP_BWRAM: CPU.PCBase = Memory.BWRAM - 0x6000; break; diff --git a/source/gfx.c b/source/gfx.c index 5bd1a57..4b88295 100644 --- a/source/gfx.c +++ b/source/gfx.c @@ -336,7 +336,6 @@ bool S9xInitGFX() // then the value is zero, otherwise multiply the value by 2. Used by // the color subtraction code. -#if defined(OLD_COLOUR_BLENDING) for (r = 0; r <= MAX_RED; r++) { uint32_t r2 = r; @@ -362,49 +361,10 @@ bool S9xInitGFX() b2 = (b2 << 1) & MAX_BLUE; GFX.ZERO_OR_X2 [BUILD_PIXEL2(r, g, b)] = BUILD_PIXEL2(r2, g2, b2); - GFX.ZERO_OR_X2 [BUILD_PIXEL2(r, g, b) & ~ALPHA_BITS_MASK] = BUILD_PIXEL2(r2, g2, - b2); + GFX.ZERO_OR_X2 [BUILD_PIXEL2(r, g, b) & ~ALPHA_BITS_MASK] = BUILD_PIXEL2(MAX(1, r2), MAX(1, g2), MAX(1, b2)); } } } -#else - for (r = 0; r <= MAX_RED; r++) - { - uint32_t r2 = r; - if ((r2 & 0x10) == 0) - r2 = 0; - else - r2 = (r2 << 1) & MAX_RED; - - if (r2 == 0) - r2 = 1; - for (g = 0; g <= MAX_GREEN; g++) - { - uint32_t g2 = g; - if ((g2 & GREEN_HI_BIT) == 0) - g2 = 0; - else - g2 = (g2 << 1) & MAX_GREEN; - - if (g2 == 0) - g2 = 1; - for (b = 0; b <= MAX_BLUE; b++) - { - uint32_t b2 = b; - if ((b2 & 0x10) == 0) - b2 = 0; - else - b2 = (b2 << 1) & MAX_BLUE; - - if (b2 == 0) - b2 = 1; - GFX.ZERO_OR_X2 [BUILD_PIXEL2(r, g, b)] = BUILD_PIXEL2(r2, g2, b2); - GFX.ZERO_OR_X2 [BUILD_PIXEL2(r, g, b) & ~ALPHA_BITS_MASK] = BUILD_PIXEL2(r2, g2, - b2); - } - } - } -#endif // Build a lookup table that if the top bit of the color value is zero // then the value is zero, otherwise its just the value. @@ -439,7 +399,7 @@ bool S9xInitGFX() return (true); } -void S9xDeinitGFX(void) +void S9xDeinitGFX() { // Free any memory allocated in S9xInitGFX if (GFX.X2) @@ -495,8 +455,7 @@ void S9xStartScreenRefresh() if (PPU.BGMode == 5 || PPU.BGMode == 6) IPPU.Interlace = (Memory.FillRAM[0x2133] & 1); - if (Settings.SupportHiRes && (PPU.BGMode == 5 || PPU.BGMode == 6 - || IPPU.Interlace)) + if (Settings.SupportHiRes && (PPU.BGMode == 5 || PPU.BGMode == 6 || IPPU.Interlace)) { IPPU.RenderedScreenWidth = 512; IPPU.DoubleWidthPixels = true; @@ -519,8 +478,7 @@ void S9xStartScreenRefresh() GFX.PPLx2 = GFX.PPL << 1; } } - else if (!Settings.SupportHiRes && (PPU.BGMode == 5 || PPU.BGMode == 6 - || IPPU.Interlace)) + else if (!Settings.SupportHiRes && (PPU.BGMode == 5 || PPU.BGMode == 6 || IPPU.Interlace)) { IPPU.RenderedScreenWidth = 256; IPPU.DoubleWidthPixels = false; @@ -1495,19 +1453,13 @@ static void DrawBackgroundOffset(uint32_t BGMode, uint32_t bg, uint8_t Z1, uint8 // hardware limitation that the offsets cannot be set // for the tile at the left-hand edge of the screen. VOffset = LineData [Y].BG[bg].VOffset; - - //MKendora; use temp var to reduce memory accesses HOffset = LineHOffset; - //End MK - left_hand_edge = false; } else - { // All subsequent offset tile data is shifted left by one, // hence the - 1 below. - Quot2 = ((HOff + Left - 1) & OffsetMask) >> 3; if (Quot2 > 31) @@ -1520,11 +1472,7 @@ static void DrawBackgroundOffset(uint32_t BGMode, uint32_t bg, uint8_t Z1, uint8 if (BGMode == 4) { VOffset = LineData [Y].BG[bg].VOffset; - - //MKendora; use temp var to reduce memory accesses HOffset = LineHOffset; - //end MK - if ((HCellOffset & OffsetEnableMask)) { if (HCellOffset & 0x8000) @@ -1638,8 +1586,7 @@ static void DrawBackgroundOffset(uint32_t BGMode, uint32_t bg, uint8_t Z1, uint8 Left += Count; TotalCount += Count; - s += (IPPU.HalfWidthPixels ? (Offset + Count) >> 1 : (Offset + Count)) * - GFX.PixSize; + s += (IPPU.HalfWidthPixels ? (Offset + Count) >> 1 : (Offset + Count)) * GFX.PixSize; MaxCount = 8; } } @@ -1765,8 +1712,7 @@ static void DrawBackgroundMode5(uint32_t bg, uint8_t Z1, uint8_t Z2) continue; } - uint32_t s = (IPPU.HalfWidthPixels ? Left >> 1 : Left) * GFX.PixSize + Y * - GFX.PPL; + uint32_t s = (IPPU.HalfWidthPixels ? Left >> 1 : Left) * GFX.PixSize + Y * GFX.PPL; uint32_t HPos = (HOffset + Left * GFX.PixSize) & 0x3ff; uint32_t Quot = HPos >> 3; @@ -1985,7 +1931,6 @@ static void DrawBackground(uint32_t BGMode, uint32_t bg, uint8_t Z1, uint8_t Z2) { DrawBackgroundMosaic(BGMode, bg, Z1, Z2); return; - } switch (BGMode) { @@ -3108,7 +3053,7 @@ static void RenderScreen(uint8_t* Screen, bool sub, bool force_no_add, uint8_t D } } -void S9xUpdateScreen(void) +void S9xUpdateScreen() { int32_t x2 = 1; @@ -3542,13 +3487,13 @@ void S9xUpdateScreen(void) } // --if (SUB_OR_ADD(5)) else { + uint32_t y; // Subscreen not being added to back uint32_t back = IPPU.ScreenColors [0] | (IPPU.ScreenColors [0] << 16); pClip = &IPPU.Clip [0]; if (pClip->Count [5]) { - uint32_t y; for (y = starty; y <= endy; y++) { uint32_t b; @@ -3573,7 +3518,6 @@ void S9xUpdateScreen(void) } else { - uint32_t y; for (y = starty; y <= endy; y++) { uint16_t* p = (uint16_t*)(GFX.Screen + y * GFX.Pitch2); diff --git a/source/gfx.h b/source/gfx.h index c5f50cb..230d692 100644 --- a/source/gfx.h +++ b/source/gfx.h @@ -19,7 +19,7 @@ extern struct SGFX GFX; bool S9xInitGFX(); void S9xDeinitGFX(); -bool S9xInitUpdate(void); +bool S9xInitUpdate(); struct SGFX { diff --git a/source/globals.c b/source/globals.c index eecb297..b99e488 100644 --- a/source/globals.c +++ b/source/globals.c @@ -205,27 +205,26 @@ uint8_t APUROM [64] = 0xF4, 0xC4, 0xF4, 0xDD, 0x5D, 0xD0, 0xDB, 0x1F, 0x00, 0x00, 0xC0, 0xFF }; - // Raw SPC700 instruction cycle lengths uint16_t S9xAPUCycleLengths [256] = { /* 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f, */ - /* 00 */ 2, 8, 4, 5, 3, 4, 3, 6, 2, 6, 5, 4, 5, 4, 6, 8, - /* 10 */ 2, 8, 4, 5, 4, 5, 5, 6, 5, 5, 6, 5, 2, 2, 4, 6, - /* 20 */ 2, 8, 4, 5, 3, 4, 3, 6, 2, 6, 5, 4, 5, 4, 5, 4, - /* 30 */ 2, 8, 4, 5, 4, 5, 5, 6, 5, 5, 6, 5, 2, 2, 3, 8, - /* 40 */ 2, 8, 4, 5, 3, 4, 3, 6, 2, 6, 4, 4, 5, 4, 6, 6, - /* 50 */ 2, 8, 4, 5, 4, 5, 5, 6, 5, 5, 4, 5, 2, 2, 4, 3, - /* 60 */ 2, 8, 4, 5, 3, 4, 3, 6, 2, 6, 4, 4, 5, 4, 5, 5, - /* 70 */ 2, 8, 4, 5, 4, 5, 5, 6, 5, 5, 5, 5, 2, 2, 3, 6, - /* 80 */ 2, 8, 4, 5, 3, 4, 3, 6, 2, 6, 5, 4, 5, 2, 4, 5, + /* 00 */ 2, 8, 4, 5, 3, 4, 3, 6, 2, 6, 5, 4, 5, 4, 6, 8, + /* 10 */ 2, 8, 4, 5, 4, 5, 5, 6, 5, 5, 6, 5, 2, 2, 4, 6, + /* 20 */ 2, 8, 4, 5, 3, 4, 3, 6, 2, 6, 5, 4, 5, 4, 5, 4, + /* 30 */ 2, 8, 4, 5, 4, 5, 5, 6, 5, 5, 6, 5, 2, 2, 3, 8, + /* 40 */ 2, 8, 4, 5, 3, 4, 3, 6, 2, 6, 4, 4, 5, 4, 6, 6, + /* 50 */ 2, 8, 4, 5, 4, 5, 5, 6, 5, 5, 4, 5, 2, 2, 4, 3, + /* 60 */ 2, 8, 4, 5, 3, 4, 3, 6, 2, 6, 4, 4, 5, 4, 5, 5, + /* 70 */ 2, 8, 4, 5, 4, 5, 5, 6, 5, 5, 5, 5, 2, 2, 3, 6, + /* 80 */ 2, 8, 4, 5, 3, 4, 3, 6, 2, 6, 5, 4, 5, 2, 4, 5, /* 90 */ 2, 8, 4, 5, 4, 5, 5, 6, 5, 5, 5, 5, 2, 2, 12, 5, - /* a0 */ 3, 8, 4, 5, 3, 4, 3, 6, 2, 6, 4, 4, 5, 2, 4, 4, - /* b0 */ 2, 8, 4, 5, 4, 5, 5, 6, 5, 5, 5, 5, 2, 2, 3, 4, - /* c0 */ 3, 8, 4, 5, 4, 5, 4, 7, 2, 5, 6, 4, 5, 2, 4, 9, - /* d0 */ 2, 8, 4, 5, 5, 6, 6, 7, 4, 5, 4, 5, 2, 2, 6, 3, - /* e0 */ 2, 8, 4, 5, 3, 4, 3, 6, 2, 4, 5, 3, 4, 3, 4, 3, - /* f0 */ 2, 8, 4, 5, 4, 5, 5, 6, 3, 4, 5, 4, 2, 2, 4, 3 + /* a0 */ 3, 8, 4, 5, 3, 4, 3, 6, 2, 6, 4, 4, 5, 2, 4, 4, + /* b0 */ 2, 8, 4, 5, 4, 5, 5, 6, 5, 5, 5, 5, 2, 2, 3, 4, + /* c0 */ 3, 8, 4, 5, 4, 5, 4, 7, 2, 5, 6, 4, 5, 2, 4, 9, + /* d0 */ 2, 8, 4, 5, 5, 6, 6, 7, 4, 5, 4, 5, 2, 2, 6, 3, + /* e0 */ 2, 8, 4, 5, 3, 4, 3, 6, 2, 4, 5, 3, 4, 3, 4, 3, + /* f0 */ 2, 8, 4, 5, 4, 5, 5, 6, 3, 4, 5, 4, 2, 2, 4, 3 }; // Actual data used by CPU emulation, will be scaled by APUReset routine @@ -233,20 +232,20 @@ uint16_t S9xAPUCycleLengths [256] = uint16_t S9xAPUCycles [256] = { /* 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f, */ - /* 00 */ 2, 8, 4, 5, 3, 4, 3, 6, 2, 6, 5, 4, 5, 4, 6, 8, - /* 10 */ 2, 8, 4, 5, 4, 5, 5, 6, 5, 5, 6, 5, 2, 2, 4, 6, - /* 20 */ 2, 8, 4, 5, 3, 4, 3, 6, 2, 6, 5, 4, 5, 4, 5, 4, - /* 30 */ 2, 8, 4, 5, 4, 5, 5, 6, 5, 5, 6, 5, 2, 2, 3, 8, - /* 40 */ 2, 8, 4, 5, 3, 4, 3, 6, 2, 6, 4, 4, 5, 4, 6, 6, - /* 50 */ 2, 8, 4, 5, 4, 5, 5, 6, 5, 5, 4, 5, 2, 2, 4, 3, - /* 60 */ 2, 8, 4, 5, 3, 4, 3, 6, 2, 6, 4, 4, 5, 4, 5, 5, - /* 70 */ 2, 8, 4, 5, 4, 5, 5, 6, 5, 5, 5, 5, 2, 2, 3, 6, - /* 80 */ 2, 8, 4, 5, 3, 4, 3, 6, 2, 6, 5, 4, 5, 2, 4, 5, + /* 00 */ 2, 8, 4, 5, 3, 4, 3, 6, 2, 6, 5, 4, 5, 4, 6, 8, + /* 10 */ 2, 8, 4, 5, 4, 5, 5, 6, 5, 5, 6, 5, 2, 2, 4, 6, + /* 20 */ 2, 8, 4, 5, 3, 4, 3, 6, 2, 6, 5, 4, 5, 4, 5, 4, + /* 30 */ 2, 8, 4, 5, 4, 5, 5, 6, 5, 5, 6, 5, 2, 2, 3, 8, + /* 40 */ 2, 8, 4, 5, 3, 4, 3, 6, 2, 6, 4, 4, 5, 4, 6, 6, + /* 50 */ 2, 8, 4, 5, 4, 5, 5, 6, 5, 5, 4, 5, 2, 2, 4, 3, + /* 60 */ 2, 8, 4, 5, 3, 4, 3, 6, 2, 6, 4, 4, 5, 4, 5, 5, + /* 70 */ 2, 8, 4, 5, 4, 5, 5, 6, 5, 5, 5, 5, 2, 2, 3, 6, + /* 80 */ 2, 8, 4, 5, 3, 4, 3, 6, 2, 6, 5, 4, 5, 2, 4, 5, /* 90 */ 2, 8, 4, 5, 4, 5, 5, 6, 5, 5, 5, 5, 2, 2, 12, 5, - /* a0 */ 3, 8, 4, 5, 3, 4, 3, 6, 2, 6, 4, 4, 5, 2, 4, 4, - /* b0 */ 2, 8, 4, 5, 4, 5, 5, 6, 5, 5, 5, 5, 2, 2, 3, 4, - /* c0 */ 3, 8, 4, 5, 4, 5, 4, 7, 2, 5, 6, 4, 5, 2, 4, 9, - /* d0 */ 2, 8, 4, 5, 5, 6, 6, 7, 4, 5, 4, 5, 2, 2, 6, 3, - /* e0 */ 2, 8, 4, 5, 3, 4, 3, 6, 2, 4, 5, 3, 4, 3, 4, 3, - /* f0 */ 2, 8, 4, 5, 4, 5, 5, 6, 3, 4, 5, 4, 2, 2, 4, 3 + /* a0 */ 3, 8, 4, 5, 3, 4, 3, 6, 2, 6, 4, 4, 5, 2, 4, 4, + /* b0 */ 2, 8, 4, 5, 4, 5, 5, 6, 5, 5, 5, 5, 2, 2, 3, 4, + /* c0 */ 3, 8, 4, 5, 4, 5, 4, 7, 2, 5, 6, 4, 5, 2, 4, 9, + /* d0 */ 2, 8, 4, 5, 5, 6, 6, 7, 4, 5, 4, 5, 2, 2, 6, 3, + /* e0 */ 2, 8, 4, 5, 3, 4, 3, 6, 2, 4, 5, 3, 4, 3, 4, 3, + /* f0 */ 2, 8, 4, 5, 4, 5, 5, 6, 3, 4, 5, 4, 2, 2, 4, 3 }; diff --git a/source/memmap.c b/source/memmap.c index 4a96f66..3e2d392 100644 --- a/source/memmap.c +++ b/source/memmap.c @@ -6,10 +6,6 @@ #endif #include <ctype.h> -#ifdef __linux -#include <unistd.h> -#endif - #include "snes9x.h" #include "memmap.h" #include "cpuexec.h" @@ -28,87 +24,24 @@ #include <malloc.h> #endif +#define MAP_HIROM_SRAM_OR_NONE (Memory.SRAMSize == 0 ? (uint8_t*) MAP_NONE : (uint8_t*) MAP_HIROM_SRAM) +#define MAP_LOROM_SRAM_OR_NONE (Memory.SRAMSize == 0 ? (uint8_t*) MAP_NONE : (uint8_t*) MAP_LOROM_SRAM) +#define MAP_RONLY_SRAM_OR_NONE (Memory.SRAMSize == 0 ? (uint8_t*) MAP_NONE : (uint8_t*) MAP_RONLY_SRAM) + #include "fxemu.h" extern struct FxInit_s SuperFX; -#ifndef SET_UI_COLOR -#define SET_UI_COLOR(r,g,b) ; -#endif - static int32_t retry_count = 0; static uint8_t bytes0x2000 [0x2000]; -int32_t is_bsx(uint8_t*); -int32_t bs_name(uint8_t*); - -static int32_t check_char(uint32_t c) -{ - if ((c & 0x80) == 0) - return 0; - if ((c - 0x20) & 0x40) - return 1; - return 0; -} +static bool is_bsx(uint8_t*); +static bool bs_name(uint8_t*); void S9xDeinterleaveType2(bool reset); -uint32_t caCRC32(uint8_t* array, uint32_t size, uint32_t crc32); extern char* rom_filename; -const uint32_t crc32Table[256] = -{ - 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, - 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, - 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, - 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, - 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, - 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, - 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, - 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, - 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, - 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, - 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106, - 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, - 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, - 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, - 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, - 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, - 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, - 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, - 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, - 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, - 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, - 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, - 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, - 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, - 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, - 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, - 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e, - 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, - 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, - 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, - 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, - 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, - 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, - 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, - 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, - 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, - 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, - 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, - 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, - 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, - 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, - 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, - 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d -}; - void S9xDeinterleaveType1(int32_t TotalFileSize, uint8_t* base) { - if (Settings.DisplayColor == 0xffff) - { - Settings.DisplayColor = BUILD_PIXEL(0, 31, 0); - SET_UI_COLOR(0, 255, 0); - } - int32_t i; int32_t nblocks = TotalFileSize >> 16; uint8_t blocks [256]; @@ -152,12 +85,6 @@ void S9xDeinterleaveGD24(int32_t TotalFileSize, uint8_t* base) if (TotalFileSize != 0x300000) return; - if (Settings.DisplayColor == 0xffff) - { - Settings.DisplayColor = BUILD_PIXEL(0, 31, 31); - SET_UI_COLOR(0, 255, 255); - } - // DS2 DMA notes: base may or may not be 32-byte aligned uint8_t* tmp = (uint8_t*) malloc(0x80000); if (tmp) @@ -281,7 +208,7 @@ static char* Safe(const char* s) if (s == NULL) { - if (safe != NULL) + if (safe) { free(safe); safe = NULL; @@ -316,38 +243,30 @@ bool S9xInitMemory() { // DS2 DMA notes: These would do well to be allocated with 32 extra bytes // so they can be 32-byte aligned. [Neb] - Memory.RAM = (uint8_t*) malloc(0x20000); - Memory.SRAM = (uint8_t*) malloc(0x20000); - Memory.VRAM = (uint8_t*) malloc(0x10000); + Memory.RAM = (uint8_t*) calloc(0x20000, 1); + Memory.SRAM = (uint8_t*) calloc(0x20000, 1); + Memory.VRAM = (uint8_t*) calloc(0x10000, 1); + Memory.BSRAM = (uint8_t*) calloc(0x80000, 1); + // Don't bother initializing ROM, we will load a game anyway. #ifdef DS2_DMA - ROM = (uint8_t*) AlignedMalloc(MAX_ROM_SIZE + 0x200 + 0x8000, 32, - &PtrAdj.ROM); + Memory.ROM = (uint8_t*) AlignedMalloc(MAX_ROM_SIZE + 0x200 + 0x8000, 32, &PtrAdj.ROM); #else - Memory.ROM = (uint8_t*) malloc(MAX_ROM_SIZE + 0x200 + 0x8000); + Memory.ROM = (uint8_t*) malloc(MAX_ROM_SIZE + 0x200 + 0x8000); #endif - memset(Memory.RAM, 0, 0x20000); - memset(Memory.SRAM, 0, 0x20000); - memset(Memory.VRAM, 0, 0x10000); - // Don't bother memsetting ROM, we will load a game anyway. [Neb] - - Memory.BSRAM = (uint8_t*) malloc(0x80000); - memset(Memory.BSRAM, 0, 0x80000); - Memory.FillRAM = NULL; - IPPU.TileCache [TILE_2BIT] = (uint8_t*) malloc(MAX_2BIT_TILES * 128); - IPPU.TileCache [TILE_4BIT] = (uint8_t*) malloc(MAX_4BIT_TILES * 128); - IPPU.TileCache [TILE_8BIT] = (uint8_t*) malloc(MAX_8BIT_TILES * 128); + IPPU.TileCache [TILE_2BIT] = (uint8_t*) calloc(MAX_2BIT_TILES, 128); + IPPU.TileCache [TILE_4BIT] = (uint8_t*) calloc(MAX_4BIT_TILES, 128); + IPPU.TileCache [TILE_8BIT] = (uint8_t*) calloc(MAX_8BIT_TILES, 128); - IPPU.TileCached [TILE_2BIT] = (uint8_t*) malloc(MAX_2BIT_TILES); - IPPU.TileCached [TILE_4BIT] = (uint8_t*) malloc(MAX_4BIT_TILES); - IPPU.TileCached [TILE_8BIT] = (uint8_t*) malloc(MAX_8BIT_TILES); + IPPU.TileCached [TILE_2BIT] = (uint8_t*) calloc(MAX_2BIT_TILES, 1); + IPPU.TileCached [TILE_4BIT] = (uint8_t*) calloc(MAX_4BIT_TILES, 1); + IPPU.TileCached [TILE_8BIT] = (uint8_t*) calloc(MAX_8BIT_TILES, 1); - if (!Memory.RAM || !Memory.SRAM || !Memory.VRAM || !Memory.ROM || !Memory.BSRAM - || - !IPPU.TileCache [TILE_2BIT] || !IPPU.TileCache [TILE_4BIT] || - !IPPU.TileCache [TILE_8BIT] || !IPPU.TileCached [TILE_2BIT] || - !IPPU.TileCached [TILE_4BIT] || !IPPU.TileCached [TILE_8BIT]) + if (!Memory.RAM || !Memory.SRAM || !Memory.VRAM || !Memory.ROM || !Memory.BSRAM || + !IPPU.TileCache [TILE_2BIT] || !IPPU.TileCache [TILE_4BIT] || + !IPPU.TileCache [TILE_8BIT] || !IPPU.TileCached [TILE_2BIT] || + !IPPU.TileCached [TILE_4BIT] || !IPPU.TileCached [TILE_8BIT]) { S9xDeinitMemory(); return (false); @@ -362,24 +281,12 @@ bool S9xInitMemory() // unallocated memory (can cause crash on some ports). Memory.ROM += 0x8000; // still 32-byte aligned - Memory.C4RAM = Memory.ROM + 0x400000 + 8192 * 8; // still 32-byte aligned - Memory.ROM = Memory.ROM; - Memory.SRAM = Memory.SRAM; - SuperFX.pvRegisters = &Memory.FillRAM [0x3000]; SuperFX.nRamBanks = 2; // Most only use 1. 1=64KB, 2=128KB=1024Mb SuperFX.pvRam = Memory.SRAM; SuperFX.nRomBanks = (2 * 1024 * 1024) / (32 * 1024); SuperFX.pvRom = (uint8_t*) Memory.ROM; - memset(IPPU.TileCache [TILE_2BIT], 0, MAX_2BIT_TILES * 128); - memset(IPPU.TileCache [TILE_4BIT], 0, MAX_4BIT_TILES * 128); - memset(IPPU.TileCache [TILE_8BIT], 0, MAX_8BIT_TILES * 128); - - memset(IPPU.TileCached [TILE_2BIT], 0, MAX_2BIT_TILES); - memset(IPPU.TileCached [TILE_4BIT], 0, MAX_4BIT_TILES); - memset(IPPU.TileCached [TILE_8BIT], 0, MAX_8BIT_TILES); - Memory.SDD1Data = NULL; Memory.SDD1Index = NULL; @@ -420,39 +327,20 @@ void S9xDeinitMemory() Memory.BSRAM = NULL; } - if (IPPU.TileCache [TILE_2BIT]) + for (int t = 0; t < 2; t++) { - free(IPPU.TileCache [TILE_2BIT]); - IPPU.TileCache [TILE_2BIT] = NULL; - } - if (IPPU.TileCache [TILE_4BIT]) - { - free(IPPU.TileCache [TILE_4BIT]); - IPPU.TileCache [TILE_4BIT] = NULL; - } - if (IPPU.TileCache [TILE_8BIT]) - { - free(IPPU.TileCache [TILE_8BIT]); - IPPU.TileCache [TILE_8BIT] = NULL; - } - - if (IPPU.TileCached [TILE_2BIT]) - { - free(IPPU.TileCached [TILE_2BIT]); - IPPU.TileCached [TILE_2BIT] = NULL; - } - if (IPPU.TileCached [TILE_4BIT]) - { - free(IPPU.TileCached [TILE_4BIT]); - IPPU.TileCached [TILE_4BIT] = NULL; - } - if (IPPU.TileCached [TILE_8BIT]) - { - free(IPPU.TileCached [TILE_8BIT]); - IPPU.TileCached [TILE_8BIT] = NULL; + if (IPPU.TileCache[t]) + { + free(IPPU.TileCache[t]); + IPPU.TileCache[t] = NULL; + } + if (IPPU.TileCached[t]) + { + free(IPPU.TileCached[t]); + IPPU.TileCached[t] = NULL; + } } FreeSDD1Data(); - Safe(NULL); } void FreeSDD1Data() @@ -684,20 +572,6 @@ static uint32_t FileLoader(uint8_t* buffer, const char* filename, int32_t maxsiz } while (more && (ROMFile = fopen(fname, "rb")) != NULL); - - - if (Memory.HeaderCount == 0) - S9xMessage(S9X_INFO, S9X_HEADERS_INFO, "No ROM file header found."); - else - { - if (Memory.HeaderCount == 1) - S9xMessage(S9X_INFO, S9X_HEADERS_INFO, - "Found ROM file header (and ignored it)."); - else - S9xMessage(S9X_INFO, S9X_HEADERS_INFO, - "Found multiple ROM file headers (and ignored them)."); - } - return TotalFileSize; } #endif @@ -735,9 +609,6 @@ bool LoadROM( retry_count = 0; again: - Settings.DisplayColor = 0xffff; - SET_UI_COLOR(255, 255, 255); - #ifdef LOAD_FROM_MEMORY_TEST strncpy(Memory.ROMFilename, game->path, sizeof(Memory.ROMFilename)); @@ -748,17 +619,12 @@ again: if ((((game->size & 0x1FFF) == 0x200) && !Settings.ForceNoHeader) || Settings.ForceHeader) { - S9xMessage(S9X_INFO, S9X_HEADERS_INFO, - "Found ROM file header (and ignored it)."); TotalFileSize -= 0x200; - src += 0x200; + src += 0x200; Memory.HeaderCount = 1; } - else - { - S9xMessage(S9X_INFO, S9X_HEADERS_INFO, "No ROM file header found."); - } + if (TotalFileSize > MAX_ROM_SIZE) return false; @@ -768,7 +634,7 @@ again: TotalFileSize = FileLoader(Memory.ROM, filename, MAX_ROM_SIZE); if (!TotalFileSize) - return false; // it ends here + return false; // it ends here else if (!Settings.NoPatch) CheckForIPSPatch(filename, Memory.HeaderCount != 0, &TotalFileSize); #endif @@ -777,25 +643,6 @@ again: { Memory.ROM[0x7FD5] = 0x31; Memory.ROM[0x7FD6] = 0x02; - Settings.DisplayColor = BUILD_PIXEL(31, 0, 0); - SET_UI_COLOR(255, 0, 0); - S9xMessage(S9X_ERROR, S9X_ROM_CONFUSING_FORMAT_INFO, "Warning! Hacked Dump!"); - } - - if ((strncmp("HONKAKUHA IGO GOSEI", (char*)&Memory.ROM[0xFFC0], 19) == 0) && (Memory.ROM[0xFFD5] != 0x31)) - { - Memory.ROM[0xFFD5] = 0x31; - Memory.ROM[0xFFD6] = 0x02; - Settings.DisplayColor = BUILD_PIXEL(31, 0, 0); - SET_UI_COLOR(255, 0, 0); - S9xMessage(S9X_ERROR, S9X_ROM_CONFUSING_FORMAT_INFO, "Warning! Hacked Dump!"); - } - - if ((Memory.ROM[0x7FD5] == 0x42) && (Memory.ROM[0x7FD6] == 0x13) && (strncmp("METAL COMBAT", (char*)&Memory.ROM[0x7FC0], 12) == 0)) - { - Settings.DisplayColor = BUILD_PIXEL(31, 0, 0); - SET_UI_COLOR(255, 0, 0); - S9xMessage(S9X_ERROR, S9X_ROM_CONFUSING_FORMAT_INFO, "Warning! Hacked Dump!"); } #ifndef NO_SPEEDHACKS @@ -826,7 +673,6 @@ again: Memory.ROM[0x107505] = 0x42; Memory.ROM[0x107506] = 0x5B; Memory.ROM[0x107539] = 0x42; Memory.ROM[0x10753A] = 0x5B; Memory.ROM[0x107563] = 0x42; Memory.ROM[0x107564] = 0x5B; - Memory.ROM[0x1801D4] = 0x42; Memory.ROM[0x1801D5] = 0x10; Memory.ROM[0x18041D] = 0x42; Memory.ROM[0x18041E] = 0x79; } #endif @@ -835,8 +681,9 @@ again: int32_t lo_score = ScoreLoROM(true, 0); if (Memory.HeaderCount == 0 && !Settings.ForceNoHeader && - ((hi_score > lo_score && ScoreHiROM(true, 0) > hi_score) || - (hi_score <= lo_score && ScoreLoROM(true, 0) > lo_score))) + strncmp((char *) &Memory.ROM [0], "BANDAI SFC-ADX", 14) && + ((hi_score > lo_score && ScoreHiROM(true, 0) > hi_score) || + (hi_score <= lo_score && ScoreLoROM(true, 0) > lo_score))) { #ifdef DS2_DMA __dcache_writeback_all(); @@ -854,8 +701,6 @@ again: memmove(Memory.ROM, Memory.ROM + 512, TotalFileSize - 512); #endif TotalFileSize -= 512; - S9xMessage(S9X_INFO, S9X_HEADER_WARNING, - "Try specifying the -nhd command line option if the game doesn't work\n"); } Memory.CalculatedSize = TotalFileSize & ~0x1FFF; // round down to lower 0x2000 @@ -869,17 +714,11 @@ again: //If both vectors are invalid, it's type 1 LoROM if (Memory.ExtendedFormat == NOPE && + strncmp ((char *) &Memory.ROM [0], "BANDAI SFC-ADX", 14) && ((Memory.ROM[0x7FFC] | (Memory.ROM[0x7FFD] << 8)) < 0x8000) && - ((Memory.ROM[0xFFFC] | (Memory.ROM[0xFFFD] << 8)) < 0x8000)) - { - if (Settings.DisplayColor == 0xffff) - { - Settings.DisplayColor = BUILD_PIXEL(0, 31, 0); - SET_UI_COLOR(0, 255, 0); - } - if (!Settings.ForceInterleaved) - S9xDeinterleaveType1(TotalFileSize, Memory.ROM); - } + ((Memory.ROM[0xFFFC] | (Memory.ROM[0xFFFD] << 8)) < 0x8000) && + !Settings.ForceInterleaved) + S9xDeinterleaveType1(TotalFileSize, Memory.ROM); //CalculatedSize is now set, so rescore hi_score = ScoreHiROM(false, 0); @@ -954,26 +793,101 @@ again: !Settings.ForceInterleaved && !Settings.ForceInterleaved2 && !Settings.ForceNotInterleaved && - !Settings.ForcePAL && !Settings.ForceSuperFX && + !Settings.ForceNoSuperFX && !Settings.ForceDSP1 && + !Settings.ForceNoDSP1 && !Settings.ForceSA1 && + !Settings.ForceNoSA1 && !Settings.ForceC4 && - !Settings.ForceSDD1) + !Settings.ForceNoC4 && + !Settings.ForceSDD1 && + !Settings.ForceNoSDD1 && + !Settings.ForceInterleaveGD24) { - if (strncmp((char*) &Memory.ROM [0x7fc0], "YUYU NO QUIZ DE GO!GO!", 22) == 0) + /* スーファミターボ BIOS読み込み */ + if ((strncmp((char*) &Memory.ROM [0], "BANDAI SFC-ADX", 14) == 0) && + !(strncmp((char*) &Memory.ROM [0x10], "SFC-ADX BACKUP", 14) == 0)) + { + Memory.LoROM = true; + Memory.HiROM = false; + Interleaved = false; + Tales = false; + } + else if (strncmp ((char *) &Memory.ROM [0x7fc0], "YUYU NO QUIZ DE GO!GO!", 22) == 0 || + strncmp ((char *) &Memory.ROM [0x7fc0], "SP MOMOTAROU DENTETSU2", 22) == 0 || + strncmp ((char *) &Memory.ROM [0x7fc0], "SUPER FORMATION SOCCE", 21) == 0) + { + Memory.LoROM = true; + Memory.HiROM = false; + Interleaved = false; + } + /* BS Zooっと麻雀 */ + else if ((strncmp ((char *) &Memory.ROM [0xffc0], "Zooっと麻雀!", 16) == 0)|| + (strncmp ((char *) &Memory.ROM [0xffc0], "Zooっと麻雀!IVT", 15) == 0)) + { + Memory.LoROM = false; + Memory.HiROM = true; + } + /* 再BS探偵倶楽部 */ + else if (strncmp ((char *) &Memory.ROM [0xffc0], "再BS探偵倶楽部", 14) == 0) + { + Memory.LoROM = false; + Memory.HiROM = true; + } + /* BATMAN--REVENGE JOKER (USA) */ + else if (strncmp ((char *) &Memory.ROM [0xffc0], "BATMAN--REVENGE JOKER", 21) == 0) + { + Memory.LoROM = true; + Memory.HiROM = false; + Interleaved = true; + } + /* THE DUEL: TEST DRIVE */ + else if (strncmp ((char *) &Memory.ROM [0x7fc0], "THE DUEL: TEST DRIVE", 20) == 0) { Memory.LoROM = true; Memory.HiROM = false; Interleaved = false; } + /* ポパイ いじわる魔女シーハッグの巻 */ + else if (strncmp ((char *) &Memory.ROM [0x7fc0], "POPEYE IJIWARU MAJO", 19) == 0) + { + Memory.LoROM = true; + Memory.HiROM = false; + Interleaved = false; + } + /* Pop'nツインビー サンプル版 */ + else if(strncmp ((char *) &Memory.ROM [0x7fc0], "POPN TWINBEE", 12) == 0) + { + Memory.LoROM = true; + Memory.HiROM = false; + Interleaved = false; + } + /* Mario Early Years: Fun with Numbers */ + else if ((strncmp ((char *) &Memory.ROM [0x7fc0], "MEY Fun with Numbers", 20) == 0)) + { + int32_t i; + for (i = 0x87fc0; i < 0x87fe0; i++) + Memory.ROM [i] = 0; + } + else if(Memory.CalculatedSize == 0x100000 && strncmp ((char *) &Memory.ROM [0xffc0], "WWF SUPER WRESTLEMANIA", 22) == 0) + { + int32_t cvcount; + memcpy(&Memory.ROM[0x100000], Memory.ROM, 0x100000); + for(cvcount = 0; cvcount < 16; cvcount++) + { + memcpy(&Memory.ROM[0x8000 * cvcount], &Memory.ROM[0x10000 * cvcount + 0x100000 + 0x8000], 0x8000); + memcpy(&Memory.ROM[0x8000 * cvcount + 0x80000], &Memory.ROM[0x10000 * cvcount + 0x100000], 0x8000); + } + Memory.LoROM = true; + Memory.HiROM = false; + memset(&Memory.ROM[Memory.CalculatedSize], 0, MAX_ROM_SIZE - Memory.CalculatedSize); + } } if (!Settings.ForceNotInterleaved && Interleaved) { CPU.TriedInterleavedMode2 = true; - S9xMessage(S9X_INFO, S9X_ROM_INTERLEAVED_INFO, - "ROM image is in interleaved format - converting..."); if (Tales) { @@ -1003,11 +917,6 @@ again: } else { - if (Settings.DisplayColor == 0xffff) - { - Settings.DisplayColor = BUILD_PIXEL(0, 31, 0); - SET_UI_COLOR(0, 255, 0); - } bool t = Memory.LoROM; Memory.LoROM = Memory.HiROM; @@ -1024,8 +933,6 @@ again: { if (retry_count == 0) { - S9xMessage(S9X_INFO, S9X_ROM_CONFUSING_FORMAT_INFO, - "ROM lied about its type! Trying again."); Settings.ForceNotInterleaved = true; Settings.ForceInterleaved = false; retry_count++; @@ -1051,22 +958,13 @@ again: } /* compatibility wrapper */ -void S9xDeinterleaveMode2(void) +void S9xDeinterleaveMode2() { S9xDeinterleaveType2(true); } void S9xDeinterleaveType2(bool reset) { - if (Settings.DisplayColor == 0xffff || Settings.DisplayColor == BUILD_PIXEL(0, 31, 0)) - { - Settings.DisplayColor = BUILD_PIXEL(31, 14, 6); - SET_UI_COLOR(255, 119, 25); - - } - S9xMessage(S9X_INFO, S9X_ROM_INTERLEAVED_INFO, - "ROM image is in interleaved format - converting..."); - int32_t nblocks = Memory.CalculatedSize >> 16; int32_t step = 64; @@ -1145,15 +1043,6 @@ void S9xDeinterleaveType2(bool reset) } } -//CRC32 for char arrays -uint32_t caCRC32(uint8_t* array, uint32_t size, uint32_t crc32) -{ - uint32_t i; - for (i = 0; i < size; i++) - crc32 = ((crc32 >> 8) & 0x00FFFFFF) ^ crc32Table[(crc32 ^ array[i]) & 0xFF]; - return ~crc32; -} - void InitROM(bool Interleaved) { SuperFX.nRomBanks = Memory.CalculatedSize >> 15; @@ -1162,6 +1051,7 @@ void InitROM(bool Interleaved) Settings.SuperScopeMaster = Settings.SuperScope; Settings.DSP1Master = Settings.ForceDSP1; Settings.SuperFX = false; + Settings.DSP = 0; Settings.SA1 = false; Settings.C4 = false; Settings.SDD1 = false; @@ -1185,7 +1075,7 @@ void InitROM(bool Interleaved) if (!Settings.BS) { - Settings.BS = (-1 != is_bsx(Memory.ROM + 0x7FC0)); + Settings.BS = is_bsx(Memory.ROM + 0x7FC0); if (Settings.BS) { @@ -1194,7 +1084,7 @@ void InitROM(bool Interleaved) } else { - Settings.BS = (-1 != is_bsx(Memory.ROM + 0xFFC0)); + Settings.BS = is_bsx(Memory.ROM + 0xFFC0); if (Settings.BS) { Memory.HiROM = true; @@ -1211,9 +1101,52 @@ void InitROM(bool Interleaved) ParseSNESHeader(RomHeader); - // Try to auto-detect the DSP1 chip - if (!Settings.ForceNoDSP1 && - (Memory.ROMType & 0xf) >= 3 && (Memory.ROMType & 0xf0) == 0) + //// Detect and initialize chips + //// detection codes are compatible with NSRT + + // DSP1/2/3/4 + if (Memory.ROMType == 0x03) + { + if (Memory.ROMSpeed == 0x30) + Settings.DSP = 4; // DSP4 + else + Settings.DSP = 1; // DSP1 + } + else if (Memory.ROMType == 0x05) + { + if (Memory.ROMSpeed == 0x20) + Settings.DSP = 2; // DSP2 + else if (Memory.ROMSpeed == 0x30 && RomHeader[0x2a] == 0xb2) + Settings.DSP = 3; // DSP3 + else + Settings.DSP = 1; // DSP1 + } + + switch (Settings.DSP) + { + case 1: // DSP1 + SetDSP = &DSP1SetByte; + GetDSP = &DSP1GetByte; + break; + case 2: // DSP2 + SetDSP = &DSP2SetByte; + GetDSP = &DSP2GetByte; + break; + case 3: // DSP3 + //SetDSP = &DSP3SetByte; + //GetDSP = &DSP3GetByte; + break; + case 4: // DSP4 + SetDSP = &DSP4SetByte; + GetDSP = &DSP4GetByte; + break; + default: + SetDSP = NULL; + GetDSP = NULL; + break; + } + + if(!Settings.ForceNoDSP1 && Settings.DSP) Settings.DSP1Master = true; if (Memory.HiROM) @@ -1229,7 +1162,7 @@ void InitROM(bool Interleaved) } if (Settings.BS) - BSHiROMMap(); + BSLoROMMap(); else if (Settings.SPC7110) SPC7110HiROMMap(); else if ((Memory.ROMSpeed & ~0x10) == 0x25) @@ -1251,6 +1184,15 @@ void InitROM(bool Interleaved) if ((Memory.ROMType & 0xf0) == 0x10) Settings.SuperFX = !Settings.ForceNoSuperFX; + //OBC1 hack ROM + if (strncmp(Memory.ROMName, "METAL COMBAT", 12) == 0 && + Memory.ROMType == 0x13 && Memory.ROMSpeed == 0x42) + { + Settings.OBC1 = true; + Settings.SuperFX = Settings.ForceSuperFX; + Memory.ROMSpeed = 0x30; + } + Settings.SDD1 = Settings.ForceSDD1; if ((Memory.ROMType & 0xf0) == 0x40) Settings.SDD1 = !Settings.ForceNoSDD1; @@ -1275,10 +1217,7 @@ void InitROM(bool Interleaved) } } else - { Settings.SETA = ST_018; - Memory.SRAMSize = 2; - } } Settings.C4 = Settings.ForceC4; if ((Memory.ROMType & 0xf0) == 0xf0 && @@ -1323,18 +1262,34 @@ void InitROM(bool Interleaved) SRAM512KLoROMMap(); Settings.DSP1Master = false; } + else if (strncmp((char*) &Memory.ROM [0x7fc0], "DEZAEMON ", 10) == 0) + { + SRAM1024KLoROMMap(); + Settings.DSP1Master = false; + } else if (strncmp((char*) &Memory.ROM [0x7fc0], "ADD-ON BASE CASSETE", 19) == 0) { + strncpy(Memory.ROMName, (char *) &Memory.ROM[0x100010], ROM_NAME_LEN - 1); Settings.MultiPlayer5Master = false; Settings.MouseMaster = false; Settings.SuperScopeMaster = false; Settings.DSP1Master = false; + Memory.SRAMSize = 5; SufamiTurboLoROMMap(); - Memory.SRAMSize = 3; } + else if ((strncmp((char *) &Memory.ROM [0x7fc0], "ROCKMAN X ", 11) == 0)|| + (strncmp((char *) &Memory.ROM [0x7fc0], "MEGAMAN X ", 11) == 0)|| + (strncmp((char *) &Memory.ROM [0x7fc0], "demon's blazon", 14) == 0)|| + (strncmp((char *) &Memory.ROM [0x7fc0], "demon's crest", 13) == 0)) + CapcomProtectLoROMMap(); else if ((Memory.ROMSpeed & ~0x10) == 0x22 && strncmp(Memory.ROMName, "Super Street Fighter", 20) != 0) AlphaROMMap(); + else if (strncmp ((char *) &Memory.ROM [0x7fc0], "HITOMI3", 7) == 0) + { + Memory.SRAMSize = 3; + LoROMMap(); + } else if (Settings.BS) BSLoROMMap(); else @@ -1383,8 +1338,6 @@ void InitROM(bool Interleaved) sum1 &= 0xffff; Memory.CalculatedChecksum = sum1; } - //now take a CRC32 - Memory.ROMCRC32 = caCRC32(Memory.ROM, Memory.CalculatedSize, 0xFFFFFFFF); if (Settings.ForceNTSC) Settings.PAL = false; @@ -1426,29 +1379,12 @@ void InitROM(bool Interleaved) *p = 0; } - { - Memory.SRAMMask = Memory.SRAMSize ? - ((1 << (Memory.SRAMSize + 3)) * 128) - 1 : 0; - } - if ((Memory.ROMChecksum + Memory.ROMComplementChecksum != 0xffff) || - Memory.ROMChecksum != Memory.CalculatedChecksum || - ((uint32_t)Memory.CalculatedSize > (uint32_t)(((1 << (Memory.ROMSize - 7)) * 128) * 1024))) - { - if (Settings.DisplayColor == 0xffff || Settings.DisplayColor != BUILD_PIXEL(31, 0, 0)) - { - Settings.DisplayColor = BUILD_PIXEL(31, 31, 0); - SET_UI_COLOR(255, 255, 0); - } - } + Memory.SRAMMask = Memory.SRAMSize ? ((1 << (Memory.SRAMSize + 3)) * 128) - 1 : 0; #ifndef USE_BLARGG_APU IAPU.OneCycle = ONE_APU_CYCLE; #endif Settings.Shutdown = Settings.ShutdownMaster; - - SetDSP = &DSP1SetByte; - GetDSP = &DSP1GetByte; - ResetSpeedMap(); ApplyROMFixes(); sprintf(Memory.ROMName, "%s", Safe(Memory.ROMName)); @@ -1456,7 +1392,7 @@ void InitROM(bool Interleaved) sprintf(Memory.CompanyId, "%s", Safe(Memory.CompanyId)); sprintf(String, - "\"%s\" [%s] %s, %s, Type: %s, Mode: %s, TV: %s, S-RAM: %s, ROMId: %s Company: %2.2s CRC32: %08X", + "\"%s\" [%s] %s, %s, Type: %s, Mode: %s, TV: %s, S-RAM: %s, ROMId: %s Company: %2.2s", Memory.ROMName, (Memory.ROMChecksum + Memory.ROMComplementChecksum != 0xffff || Memory.ROMChecksum != Memory.CalculatedChecksum) ? "bad checksum" : "checksum ok", @@ -1467,10 +1403,9 @@ void InitROM(bool Interleaved) TVStandard(), StaticRAMSize(), Memory.ROMId, - Memory.CompanyId, - Memory.ROMCRC32); + Memory.CompanyId); - S9xMessage(S9X_INFO, S9X_ROM_INFO, String); + S9xMessage(String); Settings.ForceHeader = Settings.ForceHiROM = Settings.ForceLoROM = Settings.ForceInterleaved = Settings.ForceNoHeader = Settings.ForceNotInterleaved = @@ -1503,6 +1438,42 @@ void ResetSpeedMap() FixROMSpeed(); } +void map_space(uint32_t bank_s, uint32_t bank_e, uint32_t addr_s, uint32_t addr_e, uint8_t *data) +{ + uint32_t c, i, p; + + for (c = bank_s; c <= bank_e; c++) + { + for (i = addr_s; i <= addr_e; i += 0x1000) + { + p = (c << 4) | (i >> 12); + Memory.Map[p] = data; + Memory.BlockIsROM[p] = false; + Memory.BlockIsRAM[p] = true; + } + } +} + +void map_index(uint32_t bank_s, uint32_t bank_e, uint32_t addr_s, uint32_t addr_e, intptr_t index, int32_t type) +{ + uint32_t c, i, p; + bool isROM, isRAM; + + isROM = !((type == MAP_TYPE_I_O) || (type == MAP_TYPE_RAM)); + isRAM = !((type == MAP_TYPE_I_O) || (type == MAP_TYPE_ROM)); + + for (c = bank_s; c <= bank_e; c++) + { + for (i = addr_s; i <= addr_e; i += 0x1000) + { + p = (c << 4) | (i >> 12); + Memory.Map[p] = (uint8_t*) index; + Memory.BlockIsROM[p] = isROM; + Memory.BlockIsRAM[p] = isRAM; + } + } +} + void WriteProtectROM() { // memmove converted: Different mallocs [Neb] @@ -1519,25 +1490,38 @@ void MapRAM() if (Memory.LoROM && !Settings.SDD1) { - // Banks 70->77, S-RAM + // Banks 70->7d and f0->fe 0x0000-0x7FFF, S-RAM for (c = 0; c < 0x0f; c++) { for (i = 0; i < 8; i++) { - Memory.Map [(c << 4) + 0xF00 + i] = Memory.Map [(c << 4) + 0x700 + i] = (uint8_t*) MAP_LOROM_SRAM; + Memory.Map [(c << 4) + 0xF00 + i] = Memory.Map [(c << 4) + 0x700 + i] = MAP_LOROM_SRAM_OR_NONE; Memory.BlockIsRAM [(c << 4) + 0xF00 + i] = Memory.BlockIsRAM [(c << 4) + 0x700 + i] = true; Memory.BlockIsROM [(c << 4) + 0xF00 + i] = Memory.BlockIsROM [(c << 4) + 0x700 + i] = false; } } + if(Memory.CalculatedSize <= 0x200000) + { + // Banks 70->7d 0x8000-0xffff S-RAM + for (c = 0; c < 0x0e; c++) + { + for(i = 8; i < 16; i++) + { + Memory.Map [(c << 4) + 0x700 + i] = MAP_LOROM_SRAM_OR_NONE; + Memory.BlockIsRAM [(c << 4) + 0x700 + i] = true; + Memory.BlockIsROM [(c << 4) + 0x700 + i] = false; + } + } + } } - else if (Memory.LoROM && Settings.SDD1) + else if(Memory.LoROM && Settings.SDD1) { - // Banks 70->77, S-RAM + // Banks 70->7d 0x0000-0x7FFF, S-RAM for (c = 0; c < 0x0f; c++) { for (i = 0; i < 8; i++) { - Memory.Map [(c << 4) + 0x700 + i] = (uint8_t*) MAP_LOROM_SRAM; + Memory.Map [(c << 4) + 0x700 + i] = MAP_LOROM_SRAM_OR_NONE; Memory.BlockIsRAM [(c << 4) + 0x700 + i] = true; Memory.BlockIsROM [(c << 4) + 0x700 + i] = false; } @@ -1594,43 +1578,6 @@ void LoROMMap() { int32_t c; int32_t i; - int32_t j; - int32_t mask[4]; - for (j = 0; j < 4; j++) - mask[j] = 0x00ff; - - mask[0] = (Memory.CalculatedSize / 0x8000) - 1; - - int32_t x; - bool foundZeros; - bool pastZeros; - - for (j = 0; j < 3; j++) - { - x = 1; - foundZeros = false; - pastZeros = false; - - mask[j + 1] = mask[j]; - - while (x > 0x100 && !pastZeros) - { - if (mask[j]&x) - { - x <<= 1; - if (foundZeros) - pastZeros = true; - } - else - { - foundZeros = true; - pastZeros = false; - mask[j + 1] |= x; - x <<= 1; - } - } - } - // Banks 00->3f and 80->bf for (c = 0; c < 0x400; c += 16) @@ -1643,20 +1590,16 @@ void LoROMMap() Memory.Map [c + 2] = Memory.Map [c + 0x802] = (uint8_t*) MAP_PPU; if (Settings.SETA == ST_018) Memory.Map [c + 3] = Memory.Map [c + 0x803] = (uint8_t*) MAP_SETA_RISC; - else Memory.Map [c + 3] = Memory.Map [c + 0x803] = (uint8_t*) MAP_PPU; + else + Memory.Map [c + 3] = Memory.Map [c + 0x803] = (uint8_t*) MAP_PPU; Memory.Map [c + 4] = Memory.Map [c + 0x804] = (uint8_t*) MAP_CPU; Memory.Map [c + 5] = Memory.Map [c + 0x805] = (uint8_t*) MAP_CPU; - if (Settings.DSP1Master) - { - Memory.Map [c + 6] = Memory.Map [c + 0x806] = (uint8_t*) MAP_DSP; - Memory.Map [c + 7] = Memory.Map [c + 0x807] = (uint8_t*) MAP_DSP; - } - else if (Settings.C4) + if (Settings.C4) { Memory.Map [c + 6] = Memory.Map [c + 0x806] = (uint8_t*) MAP_C4; Memory.Map [c + 7] = Memory.Map [c + 0x807] = (uint8_t*) MAP_C4; } - else if (Settings.OBC1) + else if(Settings.OBC1) { Memory.Map [c + 6] = Memory.Map [c + 0x806] = (uint8_t*) MAP_OBC_RAM; Memory.Map [c + 7] = Memory.Map [c + 0x807] = (uint8_t*) MAP_OBC_RAM; @@ -1669,31 +1612,11 @@ void LoROMMap() for (i = c + 8; i < c + 16; i++) { - int32_t e = 3; - int32_t d = c >> 4; - while (d > mask[0]) - { - d &= mask[e]; - e--; - } - Memory.Map [i] = Memory.Map [i + 0x800] = Memory.ROM + (((d) - 1) * 0x8000); + Memory.Map [i] = Memory.Map [i + 0x800] = &Memory.ROM [(c << 11) % Memory.CalculatedSize] - 0x8000; Memory.BlockIsROM [i] = Memory.BlockIsROM [i + 0x800] = true; } } - if (Settings.DSP1Master) - { - // Banks 30->3f and b0->bf - for (c = 0x300; c < 0x400; c += 16) - { - for (i = c + 8; i < c + 16; i++) - { - Memory.Map [i] = Memory.Map [i + 0x800] = (uint8_t*) MAP_DSP; - Memory.BlockIsROM [i] = Memory.BlockIsROM [i + 0x800] = false; - } - } - } - // Banks 40->7f and c0->ff for (c = 0; c < 0x400; c += 16) { @@ -1701,93 +1624,63 @@ void LoROMMap() Memory.Map [i + 0x400] = Memory.Map [i + 0xc00] = &Memory.ROM [(c << 11) % Memory.CalculatedSize]; for (i = c + 8; i < c + 16; i++) - { - int32_t e = 3; - int32_t d = (c + 0x400) >> 4; - while (d > mask[0]) - { - d &= mask[e]; - e--; - } - - Memory.Map [i + 0x400] = Memory.Map [i + 0xc00] = Memory.ROM + (((d) - 1) * 0x8000); - } + Memory.Map [i + 0x400] = Memory.Map [i + 0xc00] = &Memory.ROM [((c << 11) + 0x200000) % Memory.CalculatedSize] - 0x8000; for (i = c; i < c + 16; i++) Memory.BlockIsROM [i + 0x400] = Memory.BlockIsROM [i + 0xc00] = true; } - if (Settings.DSP1Master) - { - for (c = 0; c < 0x100; c++) - { - Memory.Map [c + 0xe00] = (uint8_t*) MAP_DSP; - Memory.BlockIsROM [c + 0xe00] = false; - } - } - - int32_t sum = 0, k, l, bankcount; - bankcount = 1 << (Memory.ROMSize - 7); //Mbits - - //safety for corrupt headers - if (bankcount > 128) - bankcount = (Memory.CalculatedSize / 0x8000) / 4; - bankcount *= 4; //to banks - bankcount <<= 4; //Map banks - bankcount += 0x800; //normalize - for (k = 0x800; k < (bankcount); k += 16) - { - uint8_t* bank = 0x8000 + Memory.Map[k + 8]; - for (l = 0; l < 0x8000; l++) - sum += bank[l]; - } - Memory.CalculatedChecksum = sum & 0xFFFF; + if (Settings.DSP) + DSPMap(); MapRAM(); WriteProtectROM(); } -void SetaDSPMap() +void DSPMap() { - int32_t c; - int32_t i; - int32_t j; - int32_t mask[4]; - for (j = 0; j < 4; j++) - mask[j] = 0x00ff; - - mask[0] = (Memory.CalculatedSize / 0x8000) - 1; - - int32_t x; - bool foundZeros; - bool pastZeros; - - for (j = 0; j < 3; j++) + switch (Settings.DSP) { - x = 1; - foundZeros = false; - pastZeros = false; - - mask[j + 1] = mask[j]; - - while (x > 0x100 && !pastZeros) - { - if (mask[j]&x) + case 1: + if (Memory.HiROM) + { + map_index(0x00, 0x1f, 0x6000, 0x7fff, MAP_DSP, MAP_TYPE_I_O); + map_index(0x80, 0x9f, 0x6000, 0x7fff, MAP_DSP, MAP_TYPE_I_O); + break; + } + else if (Memory.CalculatedSize > 0x100000) { - x <<= 1; - if (foundZeros) - pastZeros = true; + map_index(0x60, 0x6f, 0x0000, 0x7fff, MAP_DSP, MAP_TYPE_I_O); + map_index(0xe0, 0xef, 0x0000, 0x7fff, MAP_DSP, MAP_TYPE_I_O); + break; } else { - foundZeros = true; - pastZeros = false; - mask[j + 1] |= x; - x <<= 1; + map_index(0x20, 0x3f, 0x8000, 0xffff, MAP_DSP, MAP_TYPE_I_O); + map_index(0xa0, 0xbf, 0x8000, 0xffff, MAP_DSP, MAP_TYPE_I_O); + break; } - } + case 2: + map_index(0x20, 0x3f, 0x6000, 0x6fff, MAP_DSP, MAP_TYPE_I_O); + map_index(0x20, 0x3f, 0x8000, 0xbfff, MAP_DSP, MAP_TYPE_I_O); + map_index(0xa0, 0xbf, 0x6000, 0x6fff, MAP_DSP, MAP_TYPE_I_O); + map_index(0xa0, 0xbf, 0x8000, 0xbfff, MAP_DSP, MAP_TYPE_I_O); + break; + case 3: + map_index(0x20, 0x3f, 0x8000, 0xffff, MAP_DSP, MAP_TYPE_I_O); + map_index(0xa0, 0xbf, 0x8000, 0xffff, MAP_DSP, MAP_TYPE_I_O); + break; + case 4: + map_index(0x30, 0x3f, 0x8000, 0xffff, MAP_DSP, MAP_TYPE_I_O); + map_index(0xb0, 0xbf, 0x8000, 0xffff, MAP_DSP, MAP_TYPE_I_O); + break; } +} +void SetaDSPMap() +{ + int32_t c; + int32_t i; // Banks 00->3f and 80->bf for (c = 0; c < 0x400; c += 16) @@ -1806,14 +1699,7 @@ void SetaDSPMap() for (i = c + 8; i < c + 16; i++) { - int32_t e = 3; - int32_t d = c >> 4; - while (d > mask[0]) - { - d &= mask[e]; - e--; - } - Memory.Map [i] = Memory.Map [i + 0x800] = Memory.ROM + (((d) - 1) * 0x8000); + Memory.Map [i] = Memory.Map [i + 0x800] = &Memory.ROM [(c << 11) % Memory.CalculatedSize] - 0x8000; Memory.BlockIsROM [i] = Memory.BlockIsROM [i + 0x800] = true; } } @@ -1822,17 +1708,7 @@ void SetaDSPMap() for (c = 0; c < 0x400; c += 16) { for (i = c + 8; i < c + 16; i++) - { - int32_t e = 3; - int32_t d = (c + 0x400) >> 4; - while (d > mask[0]) - { - d &= mask[e]; - e--; - } - - Memory.Map [i + 0x400] = Memory.Map [i + 0xc00] = Memory.ROM + (((d) - 1) * 0x8000); - } + Memory.Map [i + 0x400] = Memory.Map [i + 0xc00] = &Memory.ROM [((c << 11) + 0x200000) % Memory.CalculatedSize] - 0x8000; //only upper half is ROM for (i = c + 8; i < c + 16; i++) @@ -1859,22 +1735,6 @@ void SetaDSPMap() } } - int32_t sum = 0, k, l, bankcount; - bankcount = 1 << (Memory.ROMSize - 7); //Mbits - //safety for corrupt headers - if (bankcount > 128) - bankcount = (Memory.CalculatedSize / 0x8000) / 4; - bankcount *= 4; //to banks - bankcount <<= 4; //Map banks - bankcount += 0x800; //normalize - for (k = 0x800; k < (bankcount); k += 16) - { - uint8_t* bank = 0x8000 + Memory.Map[k + 8]; - for (l = 0; l < 0x8000; l++) - sum += bank[l]; - } - Memory.CalculatedChecksum = sum & 0xFFFF; - MapRAM(); WriteProtectROM(); } @@ -1907,15 +1767,14 @@ void BSLoROMMap() Memory.BlockIsRAM [c + 7] = Memory.BlockIsRAM [c + 0x807] = true; for (i = c + 8; i < c + 16; i++) { - Memory.Map [i] = Memory.Map [i + 0x800] = &Memory.ROM [(c << 11) % - Memory.CalculatedSize] - 0x8000; + Memory.Map [i] = Memory.Map [i + 0x800] = &Memory.ROM [(c << 11) % Memory.CalculatedSize] - 0x8000; Memory.BlockIsROM [i] = Memory.BlockIsROM [i + 0x800] = true; } } for (c = 0; c < 8; c++) { - Memory.Map[(c << 4) + 0x105] = (uint8_t*)MAP_LOROM_SRAM; + Memory.Map[(c << 4) + 0x105] = MAP_LOROM_SRAM_OR_NONE; Memory.BlockIsROM [(c << 4) + 0x105] = false; Memory.BlockIsRAM [(c << 4) + 0x105] = true; } @@ -1924,7 +1783,7 @@ void BSLoROMMap() { for (i = 0; i < 16; i++) { - Memory.Map[0x400 + i + (c << 4)] = (uint8_t*)MAP_LOROM_SRAM; + Memory.Map[0x400 + i + (c << 4)] = MAP_LOROM_SRAM_OR_NONE; Memory.BlockIsRAM[0x400 + i + (c << 4)] = true; Memory.BlockIsROM[0x400 + i + (c << 4)] = false; } @@ -1961,52 +1820,6 @@ void HiROMMap() { int32_t i; int32_t c; - int32_t j; - - int32_t mask[4]; - for (j = 0; j < 4; j++) - mask[j] = 0x00ff; - - mask[0] = (Memory.CalculatedSize / 0x10000) - 1; - - if (Settings.ForceSA1 || - (!Settings.ForceNoSA1 && (Memory.ROMSpeed & ~0x10) == 0x23 && - (Memory.ROMType & 0xf) > 3 && (Memory.ROMType & 0xf0) == 0x30)) - { - Settings.DisplayColor = BUILD_PIXEL(31, 0, 0); - SET_UI_COLOR(255, 0, 0); - } - - - int32_t x; - bool foundZeros; - bool pastZeros; - - for (j = 0; j < 3; j++) - { - x = 1; - foundZeros = false; - pastZeros = false; - - mask[j + 1] = mask[j]; - - while (x > 0x100 && !pastZeros) - { - if (mask[j]&x) - { - x <<= 1; - if (foundZeros) - pastZeros = true; - } - else - { - foundZeros = true; - pastZeros = false; - mask[j + 1] |= x; - x <<= 1; - } - } - } // Banks 00->3f and 80->bf for (c = 0; c < 0x400; c += 16) @@ -2020,28 +1833,12 @@ void HiROMMap() Memory.Map [c + 3] = Memory.Map [c + 0x803] = (uint8_t*) MAP_PPU; Memory.Map [c + 4] = Memory.Map [c + 0x804] = (uint8_t*) MAP_CPU; Memory.Map [c + 5] = Memory.Map [c + 0x805] = (uint8_t*) MAP_CPU; - - if (Settings.DSP1Master) - { - Memory.Map [c + 6] = Memory.Map [c + 0x806] = (uint8_t*) MAP_DSP; - Memory.Map [c + 7] = Memory.Map [c + 0x807] = (uint8_t*) MAP_DSP; - } - else - { - Memory.Map [c + 6] = Memory.Map [c + 0x806] = (uint8_t*) MAP_NONE; - Memory.Map [c + 7] = Memory.Map [c + 0x807] = (uint8_t*) MAP_NONE; - } + Memory.Map [c + 6] = Memory.Map [c + 0x806] = (uint8_t*) MAP_NONE; + Memory.Map [c + 7] = Memory.Map [c + 0x807] = (uint8_t*) MAP_NONE; for (i = c + 8; i < c + 16; i++) { - int32_t e = 3; - int32_t d = c >> 4; - while (d > mask[0]) - { - d &= mask[e]; - e--; - } - Memory.Map [i] = Memory.Map [i + 0x800] = Memory.ROM + (d * 0x10000); + Memory.Map [i] = Memory.Map [i + 0x800] = &Memory.ROM [(c << 12) % Memory.CalculatedSize]; Memory.BlockIsROM [i] = Memory.BlockIsROM [i + 0x800] = true; } } @@ -2049,10 +1846,10 @@ void HiROMMap() // Banks 30->3f and b0->bf, address ranges 6000->7fff is S-RAM. for (c = 0; c < 16; c++) { - Memory.Map [0x306 + (c << 4)] = (uint8_t*) MAP_HIROM_SRAM; - Memory.Map [0x307 + (c << 4)] = (uint8_t*) MAP_HIROM_SRAM; - Memory.Map [0xb06 + (c << 4)] = (uint8_t*) MAP_HIROM_SRAM; - Memory.Map [0xb07 + (c << 4)] = (uint8_t*) MAP_HIROM_SRAM; + Memory.Map [0x306 + (c << 4)] = MAP_HIROM_SRAM_OR_NONE; + Memory.Map [0x307 + (c << 4)] = MAP_HIROM_SRAM_OR_NONE; + Memory.Map [0xb06 + (c << 4)] = MAP_HIROM_SRAM_OR_NONE; + Memory.Map [0xb07 + (c << 4)] = MAP_HIROM_SRAM_OR_NONE; Memory.BlockIsRAM [0x306 + (c << 4)] = true; Memory.BlockIsRAM [0x307 + (c << 4)] = true; Memory.BlockIsRAM [0xb06 + (c << 4)] = true; @@ -2064,30 +1861,13 @@ void HiROMMap() { for (i = c; i < c + 16; i++) { - int32_t e = 3; - int32_t d = (c) >> 4; - while (d > mask[0]) - { - d &= mask[e]; - e--; - } - Memory.Map [i + 0x400] = Memory.Map [i + 0xc00] = Memory.ROM + (d * 0x10000); + Memory.Map [i + 0x400] = Memory.Map [i + 0xc00] = &Memory.ROM [(c << 12) % Memory.CalculatedSize]; Memory.BlockIsROM [i + 0x400] = Memory.BlockIsROM [i + 0xc00] = true; } } - int32_t bankmax = 0x40 + (1 << (Memory.ROMSize - 6)); - //safety for corrupt headers - if (bankmax > 128) - bankmax = 0x80; - int32_t sum = 0; - for (i = 0x40; i < bankmax; i++) - { - uint8_t* bank_low = (uint8_t*)Memory.Map[i << 4]; - for (c = 0; c < 0x10000; c++) - sum += bank_low[c]; - } - Memory.CalculatedChecksum = sum & 0xFFFF; + if (Settings.DSP) + DSPMap(); MapRAM(); WriteProtectROM(); @@ -2098,14 +1878,6 @@ void TalesROMMap(bool Interleaved) int32_t c; int32_t i; - if (Interleaved) - { - if (Settings.DisplayColor == 0xffff) - { - Settings.DisplayColor = BUILD_PIXEL(0, 31, 0); - SET_UI_COLOR(0, 255, 0); - } - } uint32_t OFFSET0 = 0x400000; uint32_t OFFSET1 = 0x400000; uint32_t OFFSET2 = 0x000000; @@ -2134,8 +1906,8 @@ void TalesROMMap(bool Interleaved) //ToP seems to use sram to skip intro??? if (c >= 0x300) { - Memory.Map [c + 6] = Memory.Map [c + 0x806] = (uint8_t*) MAP_HIROM_SRAM; - Memory.Map [c + 7] = Memory.Map [c + 0x807] = (uint8_t*) MAP_HIROM_SRAM; + Memory.Map [c + 6] = Memory.Map [c + 0x806] = MAP_HIROM_SRAM_OR_NONE; + Memory.Map [c + 7] = Memory.Map [c + 0x807] = MAP_HIROM_SRAM_OR_NONE; Memory.BlockIsRAM [6 + c] = Memory.BlockIsRAM [7 + c] = Memory.BlockIsRAM [0x806 + c] = Memory.BlockIsRAM [0x807 + c] = true; } @@ -2171,15 +1943,6 @@ void TalesROMMap(bool Interleaved) } } - if ((strncmp("TALES", (char*)Memory.Map[8] + 0xFFC0, 5) == 0)) - { - if (*(Memory.Map[8] + 0xFFDE) == *(Memory.Map[0x808] + 0xFFDE)) - { - Settings.DisplayColor = BUILD_PIXEL(31, 0, 0); - SET_UI_COLOR(255, 0, 0); - } - } - Memory.ROMChecksum = *(Memory.Map[8] + 0xFFDE) + (*(Memory.Map[8] + 0xFFDF) << 8); Memory.ROMComplementChecksum = *(Memory.Map[8] + 0xFFDC) + (*(Memory.Map[8] + 0xFFDD) << 8); @@ -2223,7 +1986,7 @@ void AlphaROMMap() for (i = c + 8; i < c + 16; i++) { - Memory.Map [i] = Memory.Map [i + 0x800] = &Memory.ROM [c << 11] - 0x8000; + Memory.Map [i] = Memory.Map [i + 0x800] = &Memory.ROM [(c << 11) % Memory.CalculatedSize] - 0x8000; Memory.BlockIsROM [i] = true; } } @@ -2248,13 +2011,10 @@ void DetectSuperFxRamSize() { if (Memory.ROM[0x7FDA] == 0x33) Memory.SRAMSize = Memory.ROM[0x7FBD]; + else if (strncmp(Memory.ROMName, "STAR FOX 2", 10) == 0) + Memory.SRAMSize = 6; else - { - if (strncmp(Memory.ROMName, "STAR FOX 2", 10) == 0) - Memory.SRAMSize = 6; - else - Memory.SRAMSize = 5; - } + Memory.SRAMSize = 5; } void SuperFXROMMap() @@ -2282,7 +2042,7 @@ void SuperFXROMMap() for (i = c + 8; i < c + 16; i++) { - Memory.Map [i] = Memory.Map [i + 0x800] = &Memory.ROM [c << 11] - 0x8000; + Memory.Map [i] = Memory.Map [i + 0x800] = &Memory.ROM [(c << 11) % Memory.CalculatedSize] - 0x8000; Memory.BlockIsROM [i] = Memory.BlockIsROM [i + 0x800] = true; } } @@ -2364,7 +2124,7 @@ void SA1ROMMap() Memory.Map [c + 7] = Memory.Map [c + 0x807] = (uint8_t*) MAP_BWRAM; for (i = c + 8; i < c + 16; i++) { - Memory.Map [i] = Memory.Map [i + 0x800] = &Memory.ROM [c << 11] - 0x8000; + Memory.Map [i] = Memory.Map [i + 0x800] = &Memory.ROM [(c << 11) % Memory.CalculatedSize] - 0x8000; Memory.BlockIsROM [i] = Memory.BlockIsROM [i + 0x800] = true; } } @@ -2444,7 +2204,7 @@ void LoROM24MBSMap() for (i = c + 8; i < c + 16; i++) { - Memory.Map [i] = Memory.Map [i + 0x800] = &Memory.ROM [c << 11] - 0x8000; + Memory.Map [i] = Memory.Map [i + 0x800] = &Memory.ROM [(c << 11) % Memory.CalculatedSize] - 0x8000; Memory.BlockIsROM [i] = Memory.BlockIsROM [i + 0x800] = true; } } @@ -2466,7 +2226,7 @@ void LoROM24MBSMap() for (i = c + 8; i < c + 16; i++) { - Memory.Map [i + 0x800] = &Memory.ROM [c << 11] - 0x8000 + 0x200000; + Memory.Map [i + 0x800] = &Memory.ROM [((c << 11) + 0x200000) % Memory.CalculatedSize] - 0x8000; Memory.BlockIsROM [i + 0x800] = true; } } @@ -2475,10 +2235,10 @@ void LoROM24MBSMap() for (c = 0; c < 0x400; c += 16) { for (i = c; i < c + 8; i++) - Memory.Map [i + 0x400] = Memory.Map [i + 0xc00] = &Memory.ROM [(c << 11) + 0x200000]; + Memory.Map [i + 0x400] = Memory.Map [i + 0xc00] = &Memory.ROM [((c << 11) + 0x200000) % Memory.CalculatedSize]; for (i = c + 8; i < c + 16; i++) - Memory.Map [i + 0x400] = Memory.Map [i + 0xc00] = &Memory.ROM [(c << 11) + 0x200000 - 0x8000]; + Memory.Map [i + 0x400] = Memory.Map [i + 0xc00] = &Memory.ROM [((c << 11) + 0x200000) % Memory.CalculatedSize] - 0x8000; for (i = c; i < c + 16; i++) Memory.BlockIsROM [i + 0x400] = Memory.BlockIsROM [i + 0xc00] = true; @@ -2518,10 +2278,10 @@ void SufamiTurboLoROMMap() for (c = 0; c < 0x400; c += 16) { for (i = c; i < c + 8; i++) - Memory.Map [i + 0x400] = Memory.Map [i + 0xc00] = &Memory.ROM [(c << 11) + 0x200000]; + Memory.Map [i + 0x400] = Memory.Map [i + 0xc00] = &Memory.ROM [((c << 11) + 0x200000) % Memory.CalculatedSize]; for (i = c + 8; i < c + 16; i++) - Memory.Map [i + 0x400] = Memory.Map [i + 0xc00] = &Memory.ROM [(c << 11) + 0x200000 - 0x8000]; + Memory.Map [i + 0x400] = Memory.Map [i + 0xc00] = &Memory.ROM [((c << 11) + 0x200000) % Memory.CalculatedSize] - 0x8000; for (i = c; i < c + 16; i++) Memory.BlockIsROM [i + 0x400] = Memory.BlockIsROM [i + 0xc00] = true; @@ -2550,7 +2310,7 @@ void SufamiTurboLoROMMap() // Banks 60->67, S-RAM for (c = 0; c < 0x80; c++) { - Memory.Map [c + 0x600] = (uint8_t*) MAP_LOROM_SRAM; + Memory.Map [c + 0x600] = MAP_LOROM_SRAM_OR_NONE; Memory.BlockIsRAM [c + 0x600] = true; Memory.BlockIsROM [c + 0x600] = false; } @@ -2579,7 +2339,7 @@ void SRAM512KLoROMMap() Memory.Map [c + 7] = Memory.Map [c + 0x807] = (uint8_t*) MAP_NONE; for (i = c + 8; i < c + 16; i++) { - Memory.Map [i] = Memory.Map [i + 0x800] = &Memory.ROM [c << 11] - 0x8000; + Memory.Map [i] = Memory.Map [i + 0x800] = &Memory.ROM [(c << 11) % Memory.CalculatedSize] - 0x8000; Memory.BlockIsROM [i] = Memory.BlockIsROM [i + 0x800] = true; } } @@ -2588,10 +2348,10 @@ void SRAM512KLoROMMap() for (c = 0; c < 0x400; c += 16) { for (i = c; i < c + 8; i++) - Memory.Map [i + 0x400] = Memory.Map [i + 0xc00] = &Memory.ROM [(c << 11) + 0x200000]; + Memory.Map [i + 0x400] = Memory.Map [i + 0xc00] = &Memory.ROM [((c << 11) + 0x200000) % Memory.CalculatedSize]; for (i = c + 8; i < c + 16; i++) - Memory.Map [i + 0x400] = Memory.Map [i + 0xc00] = &Memory.ROM [(c << 11) + 0x200000 - 0x8000]; + Memory.Map [i + 0x400] = Memory.Map [i + 0xc00] = &Memory.ROM [((c << 11) + 0x200000) % Memory.CalculatedSize] - 0x8000; for (i = c; i < c + 16; i++) Memory.BlockIsROM [i + 0x400] = Memory.BlockIsROM [i + 0xc00] = true; @@ -2601,78 +2361,61 @@ void SRAM512KLoROMMap() WriteProtectROM(); } -void BSHiROMMap() +void SRAM1024KLoROMMap() { int32_t c; int32_t i; - Memory.SRAMSize = 5; - // Banks 00->3f and 80->bf for (c = 0; c < 0x400; c += 16) { Memory.Map [c + 0] = Memory.Map [c + 0x800] = Memory.RAM; - Memory.BlockIsRAM [c + 0] = Memory.BlockIsRAM [c + 0x800] = true; Memory.Map [c + 1] = Memory.Map [c + 0x801] = Memory.RAM; - Memory.BlockIsRAM [c + 1] = Memory.BlockIsRAM [c + 0x801] = true; - - Memory.Map [c + 2] = Memory.Map [c + 0x802] = (uint8_t*) MAP_PPU; - Memory.Map [c + 3] = Memory.Map [c + 0x803] = (uint8_t*) MAP_PPU; - Memory.Map [c + 4] = Memory.Map [c + 0x804] = (uint8_t*) MAP_CPU; - // XXX: How large is SRAM?? - Memory.Map [c + 5] = Memory.Map [c + 0x805] = (uint8_t*) Memory.RAM; - Memory.BlockIsRAM [c + 5] = Memory.BlockIsRAM [c + 0x805] = true; - - Memory.Map [c + 6] = Memory.Map [c + 0x806] = (uint8_t*) Memory.RAM; - Memory.BlockIsRAM [c + 6] = Memory.BlockIsRAM [c + 0x806] = true; - Memory.Map [c + 7] = Memory.Map [c + 0x807] = (uint8_t*) Memory.RAM; - Memory.BlockIsRAM [c + 7] = Memory.BlockIsRAM [c + 0x807] = true; + Memory.BlockIsRAM [c + 0] = Memory.BlockIsRAM [c + 0x800] = Memory.BlockIsRAM [c + 0x400] = Memory.BlockIsRAM [c + 0xc00] = true; + Memory.BlockIsRAM [c + 1] = Memory.BlockIsRAM [c + 0x801] = Memory.BlockIsRAM [c + 0x401] = Memory.BlockIsRAM [c + 0xc01] = true; + + Memory.Map [c + 2] = Memory.Map [c + 0x802] = Memory.Map [c + 0x402] = Memory.Map [c + 0xc02] = (uint8_t*) MAP_PPU; + Memory.Map [c + 3] = Memory.Map [c + 0x803] = Memory.Map [c + 0x403] = Memory.Map [c + 0xc03] = (uint8_t*) MAP_PPU; + Memory.Map [c + 4] = Memory.Map [c + 0x804] = Memory.Map [c + 0x404] = Memory.Map [c + 0xc04] = (uint8_t*) MAP_CPU; + Memory.Map [c + 5] = Memory.Map [c + 0x805] = Memory.Map [c + 0x405] = Memory.Map [c + 0xc05] = (uint8_t*) MAP_CPU; + Memory.Map [c + 6] = Memory.Map [c + 0x806] = Memory.Map [c + 0x406] = Memory.Map [c + 0xc06] = (uint8_t*) MAP_NONE; + Memory.Map [c + 7] = Memory.Map [c + 0x807] = Memory.Map [c + 0x407] = Memory.Map [c + 0xc07] = (uint8_t*) MAP_NONE; for (i = c + 8; i < c + 16; i++) { - Memory.Map [i] = Memory.Map [i + 0x800] = &Memory.ROM [(c << 12) % Memory.CalculatedSize]; - Memory.BlockIsROM [i] = Memory.BlockIsROM [i + 0x800] = true; + Memory.Map [i] = Memory.Map [i + 0x800] = Memory.Map [i + 0x400] = Memory.Map [i + 0xc00] = &Memory.ROM [(c << 11) % Memory.CalculatedSize] - 0x8000; + Memory.BlockIsROM [i] = Memory.BlockIsROM [i + 0x800] = Memory.BlockIsROM [i + 0x400] = Memory.BlockIsROM [i + 0xc00] = true; } } - // Banks 60->7d offset 0000->7fff & 60->7f offset 8000->ffff PSRAM - // XXX: How large is PSRAM? + MapExtraRAM(); + WriteProtectROM(); +} - //not adjusted, but The Dumper says "4 Mbits" - for (c = 0x600; c < 0x7e0; c += 16) - { - for (i = c; i < c + 8; i++) - { - Memory.Map [i] = &Memory.ROM [0x400000 + (c << 11)]; - Memory.BlockIsRAM [i] = true; - } - for (i = c + 8; i < c + 16; i++) - { - Memory.Map [i] = &Memory.ROM [0x400000 + (c << 11) - 0x8000]; - Memory.BlockIsRAM [i] = true; - } - } +void CapcomProtectLoROMMap() +{ + int32_t c; + int32_t i; - // Banks 40->7f and c0->ff + // Banks 00->3f and 80->bf for (c = 0; c < 0x400; c += 16) { - for (i = c; i < c + 16; i++) + Memory.Map [c + 0] = Memory.Map [c + 0x800] = Memory.Map [c + 0x400] = Memory.Map [c + 0xc00] = Memory.RAM; + Memory.Map [c + 1] = Memory.Map [c + 0x801] = Memory.Map [c + 0x401] = Memory.Map [c + 0xc01] = Memory.RAM; + Memory.BlockIsRAM [c + 0] = Memory.BlockIsRAM [c + 0x800] = Memory.BlockIsRAM [c + 0x400] = Memory.BlockIsRAM [c + 0xc00] = true; + Memory.BlockIsRAM [c + 1] = Memory.BlockIsRAM [c + 0x801] = Memory.BlockIsRAM [c + 0x401] = Memory.BlockIsRAM [c + 0xc01] = true; + + Memory.Map [c + 2] = Memory.Map [c + 0x802] = Memory.Map [c + 0x402] = Memory.Map [c + 0xc02] = (uint8_t*) MAP_PPU; + Memory.Map [c + 3] = Memory.Map [c + 0x803] = Memory.Map [c + 0x403] = Memory.Map [c + 0xc03] = (uint8_t*) MAP_PPU; + Memory.Map [c + 4] = Memory.Map [c + 0x804] = Memory.Map [c + 0x404] = Memory.Map [c + 0xc04] = (uint8_t*) MAP_CPU; + Memory.Map [c + 5] = Memory.Map [c + 0x805] = Memory.Map [c + 0x405] = Memory.Map [c + 0xc05] = (uint8_t*) MAP_CPU; + Memory.Map [c + 6] = Memory.Map [c + 0x806] = Memory.Map [c + 0x406] = Memory.Map [c + 0xc06] = (uint8_t*) MAP_NONE; + Memory.Map [c + 7] = Memory.Map [c + 0x807] = Memory.Map [c + 0x407] = Memory.Map [c + 0xc07] = (uint8_t*) MAP_NONE; + for (i = c + 8; i < c + 16; i++) { - Memory.Map [i + 0x400] = Memory.Map [i + 0xc00] = &Memory.ROM [(c << 12) % Memory.CalculatedSize]; - Memory.BlockIsROM [i + 0x400] = Memory.BlockIsROM [i + 0xc00] = true; + Memory.Map [i] = Memory.Map [i + 0x800] = Memory.Map [i + 0x400] = Memory.Map [i + 0xc00] = &Memory.ROM [(c << 11) % Memory.CalculatedSize] - 0x8000; + Memory.BlockIsROM [i] = Memory.BlockIsROM [i + 0x800] = Memory.BlockIsROM [i + 0x400] = Memory.BlockIsROM [i + 0xc00] = true; } } - for (i = 0; i < 0x80; i++) - { - Memory.Map[0x700 + i] = &Memory.BSRAM[0x10000 * (i / 16)]; - Memory.BlockIsRAM[0x700 + i] = true; - Memory.BlockIsROM[0x700 + i] = false; - } - for (i = 0; i < 8; i++) - { - Memory.Map[0x205 + (i << 4)] = Memory.Map[0x285 + (i << 4)] = Memory.Map[0x305 + (i << 4)] = Memory.Map[0x385 + (i << 4)] = Memory.Map[0x705 + (i << 4)]; - Memory.BlockIsRAM[0x205 + (i << 4)] = Memory.BlockIsRAM[0x285 + (i << 4)] = Memory.BlockIsRAM[0x305 + (i << 4)] = Memory.BlockIsRAM[0x385 + (i << 4)] = true; - Memory.BlockIsROM[0x205 + (i << 4)] = Memory.BlockIsROM[0x285 + (i << 4)] = Memory.BlockIsROM[0x305 + (i << 4)] = Memory.BlockIsROM[0x385 + (i << 4)] = false; - } MapRAM(); WriteProtectROM(); @@ -2792,8 +2535,8 @@ void SPC7110HiROMMap() Memory.Map [c + 4] = Memory.Map [c + 0x804] = (uint8_t*) MAP_CPU; Memory.Map [c + 5] = Memory.Map [c + 0x805] = (uint8_t*) MAP_CPU; - Memory.Map [c + 6] = (uint8_t*) MAP_HIROM_SRAM; - Memory.Map [c + 7] = (uint8_t*) MAP_HIROM_SRAM; + Memory.Map [c + 6] = MAP_HIROM_SRAM_OR_NONE; + Memory.Map [c + 7] = MAP_HIROM_SRAM_OR_NONE; Memory.Map [c + 0x806] = Memory.Map [c + 0x807] = (uint8_t*) MAP_NONE; for (i = c + 8; i < c + 16; i++) @@ -2806,8 +2549,8 @@ void SPC7110HiROMMap() // Banks 30->3f and b0->bf, address ranges 6000->7fff is S-RAM. for (c = 0; c < 16; c++) { - Memory.Map [0x306 + (c << 4)] = (uint8_t*) MAP_HIROM_SRAM; - Memory.Map [0x307 + (c << 4)] = (uint8_t*) MAP_HIROM_SRAM; + Memory.Map [0x306 + (c << 4)] = MAP_HIROM_SRAM_OR_NONE; + Memory.Map [0x307 + (c << 4)] = MAP_HIROM_SRAM_OR_NONE; Memory.Map [0xb06 + (c << 4)] = (uint8_t*) MAP_NONE; Memory.Map [0xb07 + (c << 4)] = (uint8_t*) MAP_NONE; Memory.BlockIsRAM [0x306 + (c << 4)] = true; @@ -2856,17 +2599,17 @@ void SPC7110Sram(uint8_t newstate) { if (newstate & 0x80) { - Memory.Map[6] = (uint8_t*)MAP_HIROM_SRAM; - Memory.Map[7] = (uint8_t*)MAP_HIROM_SRAM; - Memory.Map[0x306] = (uint8_t*)MAP_HIROM_SRAM; - Memory.Map[0x307] = (uint8_t*)MAP_HIROM_SRAM; + Memory.Map[6] = MAP_HIROM_SRAM_OR_NONE; + Memory.Map[7] = MAP_HIROM_SRAM_OR_NONE; + Memory.Map[0x306] = MAP_HIROM_SRAM_OR_NONE; + Memory.Map[0x307] = MAP_HIROM_SRAM_OR_NONE; } else { - Memory.Map[6] = (uint8_t*)MAP_RONLY_SRAM; - Memory.Map[7] = (uint8_t*)MAP_RONLY_SRAM; - Memory.Map[0x306] = (uint8_t*)MAP_RONLY_SRAM; - Memory.Map[0x307] = (uint8_t*)MAP_RONLY_SRAM; + Memory.Map[6] = MAP_RONLY_SRAM_OR_NONE; + Memory.Map[7] = MAP_RONLY_SRAM_OR_NONE; + Memory.Map[0x306] = MAP_RONLY_SRAM_OR_NONE; + Memory.Map[0x307] = MAP_RONLY_SRAM_OR_NONE; } } @@ -2910,7 +2653,7 @@ const char* KartContents() static char tmp [30]; static const char* CoPro [16] = { - "DSP1", "SuperFX", "OBC1", "SA-1", "S-DD1", "S-RTC", "CoPro#6", + "DSP", "SuperFX", "OBC1", "SA-1", "S-DD1", "S-RTC", "CoPro#6", "CoPro#7", "CoPro#8", "CoPro#9", "CoPro#10", "CoPro#11", "CoPro#12", "CoPro#13", "CoPro#14", "CoPro-Custom" }; @@ -2929,6 +2672,8 @@ const char* KartContents() sprintf(tmp, "%s+%s", tmp, "SPC7110+RTC"); else if (Settings.SPC7110) sprintf(tmp, "%s+%s", tmp, "SPC7110"); + else if(Settings.C4) + sprintf(tmp, "%s+%s", tmp, "C4"); else if (Settings.SETA != 0) { switch (Settings.SETA) @@ -2945,7 +2690,12 @@ const char* KartContents() } } else if ((Memory.ROMType & 0xf) >= 3) - sprintf(tmp, "%s+%s", tmp, CoPro [(Memory.ROMType & 0xf0) >> 4]); + { + if (Memory.ROMType & 0xf0) + sprintf(tmp, "%s+%s", tmp, CoPro [(Memory.ROMType & 0xf0) >> 4]); + else + sprintf(tmp, "%s+DSP%d", tmp, Settings.DSP == 0 ? 1 : Settings.DSP); + } return (tmp); } @@ -2962,6 +2712,16 @@ const char* ROMID() return (Memory.ROMId); } +bool match_na(const char* str) +{ + return (strcmp(Memory.ROMName, str) == 0); +} + +bool match_id(const char* str) +{ + return (strncmp(Memory.ROMId, str, strlen(str)) == 0); +} + void ApplyROMFixes() { /* @@ -2975,104 +2735,19 @@ void ApplyROMFixes() [14:25:27] <@Nach> case 0x340f23e5: //Donkey Kong Country 3 (U) copier hack - handled */ - if (Memory.ROMCRC32 == 0x6810aa95 || Memory.ROMCRC32 == 0x340f23e5 || Memory.ROMCRC32 == 0x77fd806a || - strncmp(Memory.ROMName, "HIGHWAY BATTLE 2", 16) == 0 || - (strcmp(Memory.ROMName, "FX SKIING NINTENDO 96") == 0 - && Memory.ROM[0x7FDA] == 0)) - { - Settings.DisplayColor = BUILD_PIXEL(31, 0, 0); - SET_UI_COLOR(255, 0, 0); - } - - //Ambiguous chip function pointer assignments - - //DSP switching: - if (strncmp(Memory.ROMName, "DUNGEON MASTER", 14) == 0) - { - //Set DSP-2 - SetDSP = &DSP2SetByte; - GetDSP = &DSP2GetByte; - } - -#ifdef DSP_DUMMY_LOOPS - if (strncmp(ROMName, "SD\x0b6\x0de\x0dd\x0c0\x0de\x0d1GX", 10) == 0) - { - //Set DSP-3 - SetDSP = &DSP3SetByte; - GetDSP = &DSP3GetByte; - } -#endif - - if (strncmp(Memory.ROMName, "TOP GEAR 3000", 13) == 0 - || strncmp(Memory.ROMName, "PLANETS CHAMP TG3000", 20) == 0) - { - //Set DSP-4 - SetDSP = &DSP4SetByte; - GetDSP = &DSP4GetByte; - } - - //memory map corrections - if (strncmp(Memory.ROMName, "XBAND", 5) == 0) - { - int32_t c; - for (c = 0xE00; c < 0xE10; c++) - { - Memory.Map [c] = (uint8_t*) MAP_LOROM_SRAM; - Memory.BlockIsRAM [c] = true; - Memory.BlockIsROM [c] = false; - } - WriteProtectROM(); - } - //not MAD-1 compliant - if (strcmp(Memory.ROMName, "WANDERERS FROM YS") == 0) + if (match_na("WANDERERS FROM YS")) { int32_t c; for (c = 0; c < 0xE0; c++) { - Memory.Map[c + 0x700] = (uint8_t*)MAP_LOROM_SRAM; + Memory.Map[c + 0x700] = MAP_LOROM_SRAM_OR_NONE; Memory.BlockIsROM[c + 0x700] = false; Memory.BlockIsRAM[c + 0x700] = true; } WriteProtectROM(); } - if (strcmp(Memory.ROMName, "GOGO ACKMAN3") == 0 || - strcmp(Memory.ROMName, "HOME ALONE") == 0) - { - // Banks 00->3f and 80->bf - int32_t c; - for (c = 0; c < 0x400; c += 16) - { - Memory.Map [c + 6] = Memory.Map [c + 0x806] = Memory.SRAM; - Memory.Map [c + 7] = Memory.Map [c + 0x807] = Memory.SRAM; - Memory.BlockIsROM [c + 6] = Memory.BlockIsROM [c + 0x806] = false; - Memory.BlockIsROM [c + 7] = Memory.BlockIsROM [c + 0x807] = false; - Memory.BlockIsRAM [c + 6] = Memory.BlockIsRAM [c + 0x806] = true; - Memory.BlockIsRAM [c + 7] = Memory.BlockIsRAM [c + 0x807] = true; - } - WriteProtectROM(); - } - - if (strcmp(Memory.ROMName, "RADICAL DREAMERS") == 0 || - strcmp(Memory.ROMName, "TREASURE CONFLIX") == 0) - { - int32_t c; - - for (c = 0; c < 0x80; c++) - { - Memory.Map [c + 0x700] = Memory.ROM + 0x200000 + 0x1000 * (c & 0xf0); - Memory.BlockIsRAM [c + 0x700] = true; - Memory.BlockIsROM [c + 0x700] = false; - } - for (c = 0; c < 0x400; c += 16) - { - Memory.Map [c + 5] = Memory.Map [c + 0x805] = Memory.ROM + 0x300000; - Memory.BlockIsRAM [c + 5] = Memory.BlockIsRAM [c + 0x805] = true; - } - WriteProtectROM(); - } - if (strncmp(Memory.ROMName, "WAR 2410", 8) == 0) { Memory.Map [0x005] = (uint8_t*) Memory.RAM; @@ -3080,28 +2755,21 @@ void ApplyROMFixes() Memory.BlockIsROM [0x005] = false; } - if (strcmp(Memory.ROMName, "BATMAN--REVENGE JOKER") == 0) - { - Memory.HiROM = false; - Memory.LoROM = true; - LoROMMap(); - } - //NMI hacks CPU.NMITriggerPoint = 4; - if (strcmp(Memory.ROMName, "CACOMA KNIGHT") == 0) + if (match_na("CACOMA KNIGHT")) CPU.NMITriggerPoint = 25; //Disabling a speed-up // Games which spool sound samples between the SNES and sound CPU using // H-DMA as the sample is playing. - if (strcmp(Memory.ROMName, "EARTHWORM JIM 2") == 0 || - strcmp(Memory.ROMName, "PRIMAL RAGE") == 0 || - strcmp(Memory.ROMName, "CLAY FIGHTER") == 0 || - strcmp(Memory.ROMName, "ClayFighter 2") == 0 || + if (match_na("EARTHWORM JIM 2") || + match_na("PRIMAL RAGE") || + match_na("CLAY FIGHTER") || + match_na("ClayFighter 2") || strncasecmp(Memory.ROMName, "MADDEN", 6) == 0 || strncmp(Memory.ROMName, "NHL", 3) == 0 || - strcmp(Memory.ROMName, "WeaponLord") == 0 || + match_na("WeaponLord") || strncmp(Memory.ROMName, "WAR 2410", 8) == 0) Settings.Shutdown = false; @@ -3109,14 +2777,15 @@ void ApplyROMFixes() #ifndef USE_BLARGG_APU // Stunt Racer FX - if (strcmp(Memory.ROMId, "CQ ") == 0 || + if (match_id("CQ ") || // Illusion of Gaia strncmp(Memory.ROMId, "JG", 2) == 0 || - strcmp(Memory.ROMName, "GAIA GENSOUKI 1 JPN") == 0) + match_na("GAIA GENSOUKI 1 JPN")) IAPU.OneCycle = 13; - + else if (strcmp (Memory.ROMName, "UMIHARAKAWASE") == 0) + IAPU.OneCycle = 20; // RENDERING RANGER R2 - if (strcmp(Memory.ROMId, "AVCJ") == 0 || + else if (match_id("AVCJ") || //Mark Davis strncmp(Memory.ROMName, "THE FISHING MASTER", 18) == 0 || //needs >= actual APU timing. (21 is .002 Mhz slower) // Star Ocean @@ -3126,13 +2795,13 @@ void ApplyROMFixes() // Act Raiser 1 & 2 strncasecmp(Memory.ROMName, "ActRaiser", 9) == 0 || // Soulblazer - strcmp(Memory.ROMName, "SOULBLAZER - 1 USA") == 0 || - strcmp(Memory.ROMName, "SOULBLADER - 1") == 0 || + match_na("SOULBLAZER - 1 USA") || + match_na("SOULBLADER - 1") || // Terranigma strncmp(Memory.ROMId, "AQT", 3) == 0 || // Robotrek strncmp(Memory.ROMId, "E9 ", 3) == 0 || - strcmp(Memory.ROMName, "SLAP STICK 1 JPN") == 0 || + match_na("SLAP STICK 1 JPN") || // ZENNIHON PURORESU2 strncmp(Memory.ROMId, "APR", 3) == 0 || // Bomberman 4 @@ -3143,96 +2812,81 @@ void ApplyROMFixes() // Panic Bomber World strncmp(Memory.ROMId, "APB", 3) == 0 || ((strncmp(Memory.ROMName, "Parlor", 6) == 0 || - strcmp(Memory.ROMName, "HEIWA Parlor!Mini8") == 0 || + match_na("HEIWA Parlor!Mini8") || strncmp(Memory.ROMName, "SANKYO Fever! \xCC\xA8\xB0\xCA\xDE\xB0!", 21) == 0) && strcmp(Memory.CompanyId, "A0") == 0) || - strcmp(Memory.ROMName, "DARK KINGDOM") == 0 || - strcmp(Memory.ROMName, "ZAN3 SFC") == 0 || - strcmp(Memory.ROMName, "HIOUDEN") == 0 || - strcmp(Memory.ROMName, "\xC3\xDD\xBC\xC9\xB3\xC0") == 0 || //Tenshi no Uta - strcmp(Memory.ROMName, "FORTUNE QUEST") == 0 || - strcmp(Memory.ROMName, "FISHING TO BASSING") == 0 || + match_na("DARK KINGDOM") || + match_na("ZAN3 SFC") || + match_na("HIOUDEN") || + match_na("\xC3\xDD\xBC\xC9\xB3\xC0") || //Tenshi no Uta + match_na("FORTUNE QUEST") || + match_na("FISHING TO BASSING") || strncmp(Memory.ROMName, "TokyoDome '95Battle 7", 21) == 0 || - strcmp(Memory.ROMName, "OHMONO BLACKBASS") == 0 || + match_na("OHMONO BLACKBASS") || strncmp(Memory.ROMName, "SWORD WORLD SFC", 15) == 0 || - strcmp(Memory.ROMName, "MASTERS") == 0 || //Augusta 2 J - strcmp(Memory.ROMName, "SFC \xB6\xD2\xDD\xD7\xB2\xC0\xDE\xB0") == 0 || //Kamen Rider + match_na("MASTERS") || //Augusta 2 J + match_na("SFC \xB6\xD2\xDD\xD7\xB2\xC0\xDE\xB0") || //Kamen Rider strncmp(Memory.ROMName, "LETs PACHINKO(", 14) == 0) //A set of BS games IAPU.OneCycle = 15; #endif //Specific game fixes - Settings.StarfoxHack = strcmp(Memory.ROMName, "STAR FOX") == 0 || - strcmp(Memory.ROMName, "STAR WING") == 0; - Settings.WinterGold = strcmp(Memory.ROMName, "FX SKIING NINTENDO 96") == 0 || - strcmp(Memory.ROMName, "DIRT RACER") == 0 || + Settings.StarfoxHack = match_na("STAR FOX") || + match_na("STAR WING"); + Settings.WinterGold = match_na("FX SKIING NINTENDO 96") || + match_na("DIRT RACER") || Settings.StarfoxHack; - if ((strcmp(Memory.ROMName, "LEGEND") == 0 && !Settings.PAL) || - strcmp(Memory.ROMName, "King Arthurs World") == 0) + if((match_na("LEGEND") && !Settings.PAL)|| + match_na("King Arthurs World")) SNESGameFixes.EchoOnlyOutput = true; - Settings.DaffyDuck = (strcmp(Memory.ROMName, "DAFFY DUCK: MARV MISS") == 0) || - (strcmp(Memory.ROMName, "ROBOCOP VS THE TERMIN") == 0) || - (strcmp(Memory.ROMName, "ROBOCOP VS TERMINATOR") == 0); Settings.HBlankStart = (256 * Settings.H_Max) / SNES_HCOUNTER_MAX; //OAM hacks because we don't fully understand the //behavior of the SNES. - //Totally wacky display... - //seems to need a disproven behavior, so - //we're definitely overlooking some other bug? - if (strncmp(Memory.ROMName, "UNIRACERS", 9) == 0) - SNESGameFixes.Uniracers = true; - - //is this even useful now? - if (strcmp(Memory.ROMName, "ALIENS vs. PREDATOR") == 0) - SNESGameFixes.alienVSpredetorFix = true; - - if (strcmp(Memory.ROMName, "\xBD\xB0\xCA\xDF\xB0\xCC\xA7\xD0\xBD\xC0") == 0 || //Super Famista - strcmp(Memory.ROMName, "\xBD\xB0\xCA\xDF\xB0\xCC\xA7\xD0\xBD\xC0 2") == 0 || //Super Famista 2 - strcmp(Memory.ROMName, "ZENKI TENCHIMEIDOU") == 0 || - strcmp(Memory.ROMName, "GANBA LEAGUE") == 0) + if (match_na("\xBD\xB0\xCA\xDF\xB0\xCC\xA7\xD0\xBD\xC0") || //Super Famista + match_na("\xBD\xB0\xCA\xDF\xB0\xCC\xA7\xD0\xBD\xC0 2") || //Super Famista 2 + match_na("ZENKI TENCHIMEIDOU") || + match_na("GANBA LEAGUE")) SNESGameFixes.APU_OutPorts_ReturnValueFix = true; - - if (strcmp(Memory.ROMName, "FURAI NO SIREN") == 0) + else if (match_na("FURAI NO SIREN")) SNESGameFixes.SoundEnvelopeHeightReading2 = true; //CPU timing hacks Settings.H_Max = (SNES_CYCLES_PER_SCANLINE * Settings.CyclesPercentage) / 100; // A Couple of HDMA related hacks - Lantus - if ((strcmp(Memory.ROMName, "SFX SUPERBUTOUDEN2") == 0) || - (strcmp(Memory.ROMName, "ALIEN vs. PREDATOR") == 0) || - (strcmp(Memory.ROMName, "STONE PROTECTORS") == 0) || - (strcmp(Memory.ROMName, "SUPER BATTLETANK 2") == 0)) + if ((match_na("SFX SUPERBUTOUDEN2")) || + (match_na("ALIEN vs. PREDATOR")) || + (match_na("STONE PROTECTORS")) || + (match_na("SUPER BATTLETANK 2"))) Settings.H_Max = (SNES_CYCLES_PER_SCANLINE * 130) / 100; - - if (strcmp(Memory.ROMName, "HOME IMPROVEMENT") == 0) + else if (match_na("HOME IMPROVEMENT")) Settings.H_Max = (SNES_CYCLES_PER_SCANLINE * 200) / 100; - - if (strcmp(Memory.ROMId, "ASRJ") == 0 && Settings.CyclesPercentage == 100) + else if (match_id("ASRJ") && Settings.CyclesPercentage == 100) // Street Racer Settings.H_Max = (SNES_CYCLES_PER_SCANLINE * 95) / 100; - // Power Rangers Fight - if (strncmp(Memory.ROMId, "A3R", 3) == 0 || + else if (strncmp(Memory.ROMId, "A3R", 3) == 0 || // Clock Tower strncmp(Memory.ROMId, "AJE", 3) == 0) Settings.H_Max = (SNES_CYCLES_PER_SCANLINE * 103) / 100; - - if (strncmp(Memory.ROMId, "A3M", 3) == 0 && Settings.CyclesPercentage == 100) + else if (strncmp(Memory.ROMId, "A3M", 3) == 0 && Settings.CyclesPercentage == 100) // Mortal Kombat 3. Fixes cut off speech sample Settings.H_Max = (SNES_CYCLES_PER_SCANLINE * 110) / 100; - - if (strcmp(Memory.ROMName, "\x0bd\x0da\x0b2\x0d4\x0b0\x0bd\x0de") == 0 && + else if (match_na("\x0bd\x0da\x0b2\x0d4\x0b0\x0bd\x0de") && Settings.CyclesPercentage == 100) Settings.H_Max = (SNES_CYCLES_PER_SCANLINE * 101) / 100; - + else if (match_na("WILD TRAX") || + match_na("STAR FOX 2") || + match_na("YOSSY'S ISLAND") || + match_na("YOSHI'S ISLAND")) + CPU.TriedInterleavedMode2 = true; // Start Trek: Deep Sleep 9 - if (strncmp(Memory.ROMId, "A9D", 3) == 0 && Settings.CyclesPercentage == 100) + else if (strncmp(Memory.ROMId, "A9D", 3) == 0 && Settings.CyclesPercentage == 100) Settings.H_Max = (SNES_CYCLES_PER_SCANLINE * 110) / 100; //SA-1 Speedup settings @@ -3240,163 +2894,181 @@ void ApplyROMFixes() SA1.WaitByteAddress1 = NULL; SA1.WaitByteAddress2 = NULL; - /* Bass Fishing */ - if (strcmp(Memory.ROMId, "ZBPJ") == 0) - { - SA1.WaitAddress = SA1.Map [0x0093f1 >> MEMMAP_SHIFT] + 0x93f1; - SA1.WaitByteAddress1 = Memory.FillRAM + 0x304a; - } - /* DAISENRYAKU EXPERTWW2 */ - if (strcmp(Memory.ROMId, "AEVJ") == 0) - { - SA1.WaitAddress = SA1.Map [0x0ed18d >> MEMMAP_SHIFT] + 0xd18d; - SA1.WaitByteAddress1 = Memory.FillRAM + 0x3000; - } - /* debjk2 */ - if (strcmp(Memory.ROMId, "A2DJ") == 0) - SA1.WaitAddress = SA1.Map [0x008b62 >> MEMMAP_SHIFT] + 0x8b62; - /* Dragon Ballz HD */ - if (strcmp(Memory.ROMId, "AZIJ") == 0) - { - SA1.WaitAddress = SA1.Map [0x008083 >> MEMMAP_SHIFT] + 0x8083; - SA1.WaitByteAddress1 = Memory.FillRAM + 0x3020; - } - /* SFC SDGUNDAMGNEXT */ - if (strcmp(Memory.ROMId, "ZX3J") == 0) - { - SA1.WaitAddress = SA1.Map [0x0087f2 >> MEMMAP_SHIFT] + 0x87f2; - SA1.WaitByteAddress1 = Memory.FillRAM + 0x30c4; - } - /* ShougiNoHanamichi */ - if (strcmp(Memory.ROMId, "AARJ") == 0) - { - SA1.WaitAddress = SA1.Map [0xc1f85a >> MEMMAP_SHIFT] + 0xf85a; - SA1.WaitByteAddress1 = Memory.SRAM + 0x0c64; - SA1.WaitByteAddress2 = Memory.SRAM + 0x0c66; - } - /* KATO HIFUMI9DAN SYOGI */ - if (strcmp(Memory.ROMId, "A23J") == 0) - { - SA1.WaitAddress = SA1.Map [0xc25037 >> MEMMAP_SHIFT] + 0x5037; - SA1.WaitByteAddress1 = Memory.SRAM + 0x0c06; - SA1.WaitByteAddress2 = Memory.SRAM + 0x0c08; - } - /* idaten */ - if (strcmp(Memory.ROMId, "AIIJ") == 0) - { - SA1.WaitAddress = SA1.Map [0xc100be >> MEMMAP_SHIFT] + 0x00be; - SA1.WaitByteAddress1 = Memory.SRAM + 0x1002; - SA1.WaitByteAddress2 = Memory.SRAM + 0x1004; - } - /* igotais */ - if (strcmp(Memory.ROMId, "AITJ") == 0) - SA1.WaitAddress = SA1.Map [0x0080b7 >> MEMMAP_SHIFT] + 0x80b7; - /* J96 DREAM STADIUM */ - if (strcmp(Memory.ROMId, "AJ6J") == 0) - SA1.WaitAddress = SA1.Map [0xc0f74a >> MEMMAP_SHIFT] + 0xf74a; - /* JumpinDerby */ - if (strcmp(Memory.ROMId, "AJUJ") == 0) - SA1.WaitAddress = SA1.Map [0x00d926 >> MEMMAP_SHIFT] + 0xd926; - /* JKAKINOKI SHOUGI */ - if (strcmp(Memory.ROMId, "AKAJ") == 0) - SA1.WaitAddress = SA1.Map [0x00f070 >> MEMMAP_SHIFT] + 0xf070; - /* HOSHI NO KIRBY 3 & KIRBY'S DREAM LAND 3 JAP & US */ - if (strcmp(Memory.ROMId, "AFJJ") == 0 || strcmp(Memory.ROMId, "AFJE") == 0) - { - SA1.WaitAddress = SA1.Map [0x0082d4 >> MEMMAP_SHIFT] + 0x82d4; - SA1.WaitByteAddress1 = Memory.SRAM + 0x72a4; - } - /* KIRBY SUPER DELUXE JAP */ - if (strcmp(Memory.ROMId, "AKFJ") == 0) - { - SA1.WaitAddress = SA1.Map [0x008c93 >> MEMMAP_SHIFT] + 0x8c93; - SA1.WaitByteAddress1 = Memory.FillRAM + 0x300a; - SA1.WaitByteAddress2 = Memory.FillRAM + 0x300e; - } - /* KIRBY SUPER DELUXE US */ - if (strcmp(Memory.ROMId, "AKFE") == 0) - { - SA1.WaitAddress = SA1.Map [0x008cb8 >> MEMMAP_SHIFT] + 0x8cb8; - SA1.WaitByteAddress1 = Memory.FillRAM + 0x300a; - SA1.WaitByteAddress2 = Memory.FillRAM + 0x300e; - } - /* SUPER MARIO RPG JAP & US */ - if (strcmp(Memory.ROMId, "ARWJ") == 0 || strcmp(Memory.ROMId, "ARWE") == 0) - { - SA1.WaitAddress = SA1.Map [0xc0816f >> MEMMAP_SHIFT] + 0x816f; - SA1.WaitByteAddress1 = Memory.FillRAM + 0x3000; - } - /* marvelous.zip */ - if (strcmp(Memory.ROMId, "AVRJ") == 0) + if (Settings.SA1) { - SA1.WaitAddress = SA1.Map [0x0085f2 >> MEMMAP_SHIFT] + 0x85f2; - SA1.WaitByteAddress1 = Memory.FillRAM + 0x3024; - } - /* AUGUSTA3 MASTERS NEW */ - if (strcmp(Memory.ROMId, "AO3J") == 0) - { - SA1.WaitAddress = SA1.Map [0x00dddb >> MEMMAP_SHIFT] + 0xdddb; - SA1.WaitByteAddress1 = Memory.FillRAM + 0x37b4; - } - /* OSHABERI PARODIUS */ - if (strcmp(Memory.ROMId, "AJOJ") == 0) - SA1.WaitAddress = SA1.Map [0x8084e5 >> MEMMAP_SHIFT] + 0x84e5; - /* PANIC BOMBER WORLD */ - if (strcmp(Memory.ROMId, "APBJ") == 0) - SA1.WaitAddress = SA1.Map [0x00857a >> MEMMAP_SHIFT] + 0x857a; - /* PEBBLE BEACH NEW */ - if (strcmp(Memory.ROMId, "AONJ") == 0) - { - SA1.WaitAddress = SA1.Map [0x00df33 >> MEMMAP_SHIFT] + 0xdf33; - SA1.WaitByteAddress1 = Memory.FillRAM + 0x37b4; - } - /* PGA EUROPEAN TOUR */ - if (strcmp(Memory.ROMId, "AEPE") == 0) - { - SA1.WaitAddress = SA1.Map [0x003700 >> MEMMAP_SHIFT] + 0x3700; - SA1.WaitByteAddress1 = Memory.FillRAM + 0x3102; - } - /* PGA TOUR 96 */ - if (strcmp(Memory.ROMId, "A3GE") == 0) - { - SA1.WaitAddress = SA1.Map [0x003700 >> MEMMAP_SHIFT] + 0x3700; - SA1.WaitByteAddress1 = Memory.FillRAM + 0x3102; - } - /* POWER RANGERS 4 */ - if (strcmp(Memory.ROMId, "A4RE") == 0) - { - SA1.WaitAddress = SA1.Map [0x009899 >> MEMMAP_SHIFT] + 0x9899; - SA1.WaitByteAddress1 = Memory.FillRAM + 0x3000; - } - /* SD F1 GRAND PRIX */ - if (strcmp(Memory.ROMId, "AGFJ") == 0) - SA1.WaitAddress = SA1.Map [0x0181bc >> MEMMAP_SHIFT] + 0x81bc; - /* SHOUGI MARJONG */ - if (strcmp(Memory.ROMId, "ASYJ") == 0) - { - SA1.WaitAddress = SA1.Map [0x00f2cc >> MEMMAP_SHIFT] + 0xf2cc; - SA1.WaitByteAddress1 = Memory.SRAM + 0x7ffe; - SA1.WaitByteAddress2 = Memory.SRAM + 0x7ffc; - } - /* shogisai2 */ - if (strcmp(Memory.ROMId, "AX2J") == 0) - SA1.WaitAddress = SA1.Map [0x00d675 >> MEMMAP_SHIFT] + 0xd675; - /* SHINING SCORPION */ - if (strcmp(Memory.ROMId, "A4WJ") == 0) - SA1.WaitAddress = SA1.Map [0xc048be >> MEMMAP_SHIFT] + 0x48be; - /* SHIN SHOUGI CLUB */ - if (strcmp(Memory.ROMId, "AHJJ") == 0) - { - SA1.WaitAddress = SA1.Map [0xc1002a >> MEMMAP_SHIFT] + 0x002a; - SA1.WaitByteAddress1 = Memory.SRAM + 0x0806; - SA1.WaitByteAddress2 = Memory.SRAM + 0x0808; + /* Itoi Shigesato no Bass Tsuri No.1 (J) */ + if (match_id("ZBPJ")) + { + SA1.WaitAddress = SA1.Map [0x0093f1 >> MEMMAP_SHIFT] + 0x93f1; + SA1.WaitByteAddress1 = Memory.FillRAM + 0x304a; + } + /* Daisenryaku Expert WWII (J) */ + else if (match_id("AEVJ")) + { + SA1.WaitAddress = SA1.Map [0x0ed18d >> MEMMAP_SHIFT] + 0xd18d; + SA1.WaitByteAddress1 = Memory.FillRAM + 0x3000; + } + /* Derby Jockey 2 (J) */ + else if (match_id("A2DJ")) + SA1.WaitAddress = SA1.Map [0x008b62 >> MEMMAP_SHIFT] + 0x8b62; + /* Dragon Ball Z - Hyper Dimension (J) */ + else if (match_id("AZIJ")) + { + SA1.WaitAddress = SA1.Map [0x008083 >> MEMMAP_SHIFT] + 0x8083; + SA1.WaitByteAddress1 = Memory.FillRAM + 0x3020; + } + /* SD Gundam G NEXT (J) */ + else if (match_id("ZX3J")) + { + SA1.WaitAddress = SA1.Map [0x0087f2 >> MEMMAP_SHIFT] + 0x87f2; + SA1.WaitByteAddress1 = Memory.FillRAM + 0x30c4; + } + /* Shougi no Hanamichi (J) */ + else if (match_id("AARJ")) + { + SA1.WaitAddress = SA1.Map [0xc1f85a >> MEMMAP_SHIFT] + 0xf85a; + SA1.WaitByteAddress1 = Memory.SRAM + 0x0c64; + SA1.WaitByteAddress2 = Memory.SRAM + 0x0c66; + } + /* Asahi Shinbun Rensai Katou Hifumi Kudan Shougi Shingiryu (J) */ + if (match_id("A23J")) + { + SA1.WaitAddress = SA1.Map [0xc25037 >> MEMMAP_SHIFT] + 0x5037; + SA1.WaitByteAddress1 = Memory.SRAM + 0x0c06; + SA1.WaitByteAddress2 = Memory.SRAM + 0x0c08; + } + /* Taikyoku Igo - Idaten (J) */ + else if (match_id("AIIJ")) + { + SA1.WaitAddress = SA1.Map [0xc100be >> MEMMAP_SHIFT] + 0x00be; + SA1.WaitByteAddress1 = Memory.SRAM + 0x1002; + SA1.WaitByteAddress2 = Memory.SRAM + 0x1004; + } + /* Takemiya Masaki Kudan no Igo Taishou (J) */ + else if (match_id("AITJ")) + SA1.WaitAddress = SA1.Map [0x0080b7 >> MEMMAP_SHIFT] + 0x80b7; + /* J. League '96 Dream Stadium (J) */ + else if (match_id("AJ6J")) + SA1.WaitAddress = SA1.Map [0xc0f74a >> MEMMAP_SHIFT] + 0xf74a; + /* Jumpin' Derby (J) */ + else if (match_id("AJUJ")) + SA1.WaitAddress = SA1.Map [0x00d926 >> MEMMAP_SHIFT] + 0xd926; + /* Kakinoki Shougi (J) */ + else if (match_id("AKAJ")) + SA1.WaitAddress = SA1.Map [0x00f070 >> MEMMAP_SHIFT] + 0xf070; + /* Hoshi no Kirby 3 (J), Kirby's Dream Land 3 (U) */ + else if (match_id("AFJJ") || match_id("AFJE")) + { + SA1.WaitAddress = SA1.Map [0x0082d4 >> MEMMAP_SHIFT] + 0x82d4; + SA1.WaitByteAddress1 = Memory.SRAM + 0x72a4; + } + /* Hoshi no Kirby - Super Deluxe (J) */ + else if (match_id("AKFJ")) + { + SA1.WaitAddress = SA1.Map [0x008c93 >> MEMMAP_SHIFT] + 0x8c93; + SA1.WaitByteAddress1 = Memory.FillRAM + 0x300a; + SA1.WaitByteAddress2 = Memory.FillRAM + 0x300e; + } + /* Kirby Super Star (U) */ + else if (match_id("AKFE")) + { + SA1.WaitAddress = SA1.Map [0x008cb8 >> MEMMAP_SHIFT] + 0x8cb8; + SA1.WaitByteAddress1 = Memory.FillRAM + 0x300a; + SA1.WaitByteAddress2 = Memory.FillRAM + 0x300e; + } + /* Super Mario RPG (J), (U) */ + else if (match_id("ARWJ") || match_id("ARWE")) + { + SA1.WaitAddress = SA1.Map [0xc0816f >> MEMMAP_SHIFT] + 0x816f; + SA1.WaitByteAddress1 = Memory.FillRAM + 0x3000; + } + /* Marvelous (J) */ + else if (match_id("AVRJ")) + { + SA1.WaitAddress = SA1.Map [0x0085f2 >> MEMMAP_SHIFT] + 0x85f2; + SA1.WaitByteAddress1 = Memory.FillRAM + 0x3024; + } + /* Harukanaru Augusta 3 - Masters New (J) */ + else if (match_id("AO3J")) + { + SA1.WaitAddress = SA1.Map [0x00dddb >> MEMMAP_SHIFT] + 0xdddb; + SA1.WaitByteAddress1 = Memory.FillRAM + 0x37b4; + } + /* Jikkyou Oshaberi Parodius (J) */ + else if (match_id("AJOJ")) + SA1.WaitAddress = SA1.Map [0x8084e5 >> MEMMAP_SHIFT] + 0x84e5; + /* Super Bomberman - Panic Bomber W (J) */ + else if (match_id("APBJ")) + SA1.WaitAddress = SA1.Map [0x00857a >> MEMMAP_SHIFT] + 0x857a; + /* Pebble Beach no Hatou New - Tournament Edition (J) */ + else if (match_id("AONJ")) + { + SA1.WaitAddress = SA1.Map [0x00df33 >> MEMMAP_SHIFT] + 0xdf33; + SA1.WaitByteAddress1 = Memory.FillRAM + 0x37b4; + } + /* PGA European Tour (U) */ + else if (match_id("AEPE")) + { + SA1.WaitAddress = SA1.Map [0x003700 >> MEMMAP_SHIFT] + 0x3700; + SA1.WaitByteAddress1 = Memory.FillRAM + 0x3102; + } + /* PGA Tour 96 (U) */ + else if (match_id("A3GE")) + { + SA1.WaitAddress = SA1.Map [0x003700 >> MEMMAP_SHIFT] + 0x3700; + SA1.WaitByteAddress1 = Memory.FillRAM + 0x3102; + } + /* Power Rangers Zeo - Battle Racers (U) */ + else if (match_id("A4RE")) + { + SA1.WaitAddress = SA1.Map [0x009899 >> MEMMAP_SHIFT] + 0x9899; + SA1.WaitByteAddress1 = Memory.FillRAM + 0x3000; + } + /* SD F-1 Grand Prix (J) */ + else if (match_id("AGFJ")) + SA1.WaitAddress = SA1.Map [0x0181bc >> MEMMAP_SHIFT] + 0x81bc; + /* Saikousoku Shikou Shougi Mahjong (J) */ + else if (match_id("ASYJ")) + { + SA1.WaitAddress = SA1.Map [0x00f2cc >> MEMMAP_SHIFT] + 0xf2cc; + SA1.WaitByteAddress1 = Memory.SRAM + 0x7ffe; + SA1.WaitByteAddress2 = Memory.SRAM + 0x7ffc; + } + /* Shougi Saikyou II (J) */ + else if (match_id("AX2J")) + SA1.WaitAddress = SA1.Map [0x00d675 >> MEMMAP_SHIFT] + 0xd675; + /* Mini Yonku Shining Scorpion - Let's & Go!! (J) */ + else if (match_id("A4WJ")) + SA1.WaitAddress = SA1.Map [0xc048be >> MEMMAP_SHIFT] + 0x48be; + /* Shin Shougi Club (J) */ + else if (match_id("AHJJ")) + { + SA1.WaitAddress = SA1.Map [0xc1002a >> MEMMAP_SHIFT] + 0x002a; + SA1.WaitByteAddress1 = Memory.SRAM + 0x0806; + SA1.WaitByteAddress2 = Memory.SRAM + 0x0808; + } + /* ショウギサイキョウ */ + else if (match_id("AMSJ")) + SA1.WaitAddress = SA1.Map [0x00CD6A >> MEMMAP_SHIFT] + 0xCD6A; + /* ハブメイジンノオモシロショウギ */ + else if (match_id("IL")) + SA1.WaitAddress = SA1.Map [0x008549 >> MEMMAP_SHIFT] + 0x8549; + /* MASOUKISHIN */ + else if (match_id("ALXJ")) + { + SA1.WaitAddress = SA1.Map [0x00EC9C >> MEMMAP_SHIFT] + 0xEC9C; + SA1.WaitByteAddress1 = Memory.FillRAM + 0x3072; + } + /* SUPER SHOGI3 */ + else if (match_id("A3IJ")) + SA1.WaitAddress = SA1.Map [0x00F669 >> MEMMAP_SHIFT] + 0xF669; } //Other // Additional game fixes by sanmaiwashi ... - //Gundam Knight Story - if (strcmp(Memory.ROMName, "SFX \xC5\xB2\xC4\xB6\xDE\xDD\xC0\xDE\xD1\xD3\xC9\xB6\xDE\xC0\xD8 1") == 0) + // Gundam Knight Story + if (match_na("SFX \xC5\xB2\xC4\xB6\xDE\xDD\xC0\xDE\xD1\xD3\xC9\xB6\xDE\xC0\xD8 1")) { bytes0x2000 [0xb18] = 0x4c; bytes0x2000 [0xb19] = 0x4b; @@ -3404,135 +3076,149 @@ void ApplyROMFixes() SNESGameFixes.SRAMInitialValue = 0x6b; } - // HITOMI3 - if (strcmp(Memory.ROMName, "HITOMI3") == 0) - { - Memory.SRAMSize = 1; - Memory.SRAMMask = Memory.SRAMSize ? ((1 << (Memory.SRAMSize + 3)) * 128) - 1 : 0; - } - //sram value fixes - if (strcmp(Memory.ROMName, "SUPER DRIFT OUT") == 0 || - strcmp(Memory.ROMName, "SATAN IS OUR FATHER!") == 0 || - strcmp(Memory.ROMName, "goemon 4") == 0) + if (match_na("SUPER DRIFT OUT") || + match_na("SATAN IS OUR FATHER!") || + match_na("goemon 4")) SNESGameFixes.SRAMInitialValue = 0x00; -#define RomPatch(adr,ov,nv) \ - if (Memory.ROM [adr] == ov) \ - Memory.ROM [adr] = nv - - // Love Quest - if (strcmp(Memory.ROMName, "LOVE QUEST") == 0) - { - RomPatch(0x1385ec, 0xd0, 0xea); - RomPatch(0x1385ed, 0xb2, 0xea); - } - //BNE D0 into nops - - //seems like the next instruction is a BRA - //otherwise, this one's too complex for MKendora - // Nangoku Syonen Papuwa Kun - if (strcmp(Memory.ROMName, "NANGOKUSYONEN PAPUWA") == 0) - RomPatch(0x1f0d1, 0xa0, 0x6b); - //turns an LDY into an RTL? - - //this is a cmp on $00:2140 - // Super Batter Up - if (strcmp(Memory.ROMName, "Super Batter Up") == 0) - { - RomPatch(0x27ae0, 0xd0, 0xea); - RomPatch(0x27ae1, 0xfa, 0xea); - } - //BNE + if(Settings.BS && Memory.LoROM && + match_na("F-ZERO") && + Memory.ROMChecksum == 0xb10d && + Memory.ROMComplementChecksum == 0x4ef2) + Memory.ROM[0x7fd0] = 0xFF; // fix memory pack position bits } -int32_t is_bsx(uint8_t* p) +// 7FC0h or FFC0h +// +// FFC0h - FFCFh: CartName +// FFD0h : Memory pack location +// FFD1h - FFD5 : 00:00:00:00:00 (??) +// FFD6h : Month 10h, 20h, 30h... +// FFD7h : Day This byte / 8 low 3bits is unknown. +// FFD8h : ROMSpeed +// FFD9h : Satellaview ROM Type +// FFDAh : Maker ID +// FFDBh : ROM Version + +static bool is_bsx(uint8_t *p) // p == "0xFFC0" or "0x7FC0" ROM offset pointer { uint32_t c; + int32_t i; + bool b = false; + bool bb = false; + // Satellaview ROM Type if (p[0x19] & 0x4f) - goto notbsx; + return false; + + // Maker ID c = p[0x1a]; if ((c != 0x33) && (c != 0xff)) // 0x33 = Manufacturer: Nintendo - goto notbsx; + return false; + + // Month, Day c = (p[0x17] << 8) | p[0x16]; if ((c != 0x0000) && (c != 0xffff)) { if ((c & 0x040f) != 0) - goto notbsx; + return false; if ((c & 0xff) > 0xc0) - goto notbsx; + return false; } + + // ROMSpeed c = p[0x18]; if ((c & 0xce) || ((c & 0x30) == 0)) - goto notbsx; + return false; + + // Memory pack location + if(p[0x10] == 0) + return false; + + for(i = 0; i < 8; i++) + { + if(p[0x10] & (1 << i)) + { + if(bb) + return false; + else + b = true; + } + else if(b) + bb = true; + } + if ((p[0x15] & 0x03) != 0) - goto notbsx; + return false; c = p[0x13]; if ((c != 0x00) && (c != 0xff)) - goto notbsx; + return false; if (p[0x14] != 0x00) - goto notbsx; - if (bs_name(p) != 0) - goto notbsx; - return 0; // It's a Satellaview ROM! -notbsx: - return -1; + return false; + return bs_name(p); } -int32_t bs_name(uint8_t* p) +static bool bs_name(uint8_t* p) { - uint32_t c; int32_t lcount; - int32_t numv; // number of valid name characters seen so far - numv = 0; - for (lcount = 16; lcount > 0; lcount--) + for(lcount = 16; lcount > 0; lcount--) { - if (check_char(c = *p++) != 0) + //null strings + if(*p == 0) { - c = *p++; - if (c < 0x20) + if(lcount != 16) + p++; + else + return false; + } + //SJIS single byte char + else if((*p >= 0x20 && *p <= 0x7f) || + (*p >= 0xa0 && *p <= 0xdf)) + p++; + //SJIS multi byte char + else if(lcount >= 2) + { + if(((*p >= 0x81 && *p <= 0x9f) || + (*p >= 0xe0 && *p <= 0xfc)) && + ((*(p + 1) >= 0x40 && *(p + 1) <= 0x7e) || + (*(p + 1) >= 0x80 && *(p + 1) <= 0xfc))) { - if ((numv != 0x0b) || (c != 0)) // Dr. Mario Hack - goto notBsName; + p += 2; + lcount--; } - - numv++; - lcount--; - continue; + else + return false; } else - { - if (c == 0) - { - if (numv == 0) - goto notBsName; - continue; - } - - if (c < 0x20) - goto notBsName; - if (c >= 0x80) - { - if ((c < 0xa0) || (c >= 0xf0)) - goto notBsName; - } - numv++; - } + return false; } - if (numv > 0) - return 0; -notBsName: - return -1; + return true; } void ParseSNESHeader(uint8_t* RomHeader) { - Memory.SRAMSize = RomHeader [0x28]; - strncpy(Memory.ROMName, (char*) &RomHeader[0x10], ROM_NAME_LEN - 1); - Memory.ROMSpeed = RomHeader [0x25]; - Memory.ROMType = RomHeader [0x26]; - Memory.ROMSize = RomHeader [0x27]; + if(Settings.BS) + { + Memory.SRAMSize = 0x05; + strncpy(Memory.ROMName, (char *) &RomHeader[0x10], 17); + memset(&Memory.ROMName[0x11], 0, ROM_NAME_LEN - 1 - 17); + Memory.ROMSpeed = RomHeader [0x28]; + Memory.ROMType = 0xe5; + Memory.ROMSize = 1; + + uint32_t size_count; + for(size_count = 0x800; size_count < Memory.CalculatedSize; size_count <<= 1, ++Memory.ROMSize); + } + else + { + Memory.SRAMSize = RomHeader [0x28]; + strncpy(Memory.ROMName, (char*) &RomHeader[0x10], ROM_NAME_LEN - 1); + Memory.ROMSpeed = RomHeader [0x25]; + Memory.ROMType = RomHeader [0x26]; + Memory.ROMSize = RomHeader [0x27]; + } + Memory.ROMChecksum = RomHeader [0x2e] + (RomHeader [0x2f] << 8); Memory.ROMComplementChecksum = RomHeader [0x2c] + (RomHeader [0x2d] << 8); Memory.ROMRegion = RomHeader[0x29]; diff --git a/source/memmap.h b/source/memmap.h index 3a77033..3cf0138 100644 --- a/source/memmap.h +++ b/source/memmap.h @@ -55,10 +55,10 @@ bool LoadROM(const struct retro_game_info* game); #else bool LoadROM(const char*); #endif -void InitROM(bool); +void InitROM(bool); bool S9xInitMemory(); -void S9xDeinitMemory(); -void FreeSDD1Data(); +void S9xDeinitMemory(); +void FreeSDD1Data(); void WriteProtectROM(); void FixROMSpeed(); @@ -70,6 +70,7 @@ void JumboLoROMMap(bool); void LoROMMap(); void LoROM24MBSMap(); void SRAM512KLoROMMap(); +void SRAM1024KLoROMMap(); void SufamiTurboLoROMMap(); void HiROMMap(); void SuperFXROMMap(); @@ -81,6 +82,8 @@ void SPC7110HiROMMap(); void SPC7110Sram(uint8_t); void SetaDSPMap(); void ApplyROMFixes(); +void DSPMap(); +void CapcomProtectLoROMMap(); const char* TVStandard(); const char* Speed(); @@ -93,6 +96,7 @@ const char* Headers(); const char* ROMID(); const char* CompanyID(); void ParseSNESHeader(uint8_t*); + enum { MAP_PPU, MAP_CPU, MAP_DSP, MAP_LOROM_SRAM, MAP_HIROM_SRAM, @@ -100,7 +104,17 @@ enum MAP_BWRAM_BITMAP2, MAP_SA1RAM, MAP_SPC7110_ROM, MAP_SPC7110_DRAM, MAP_RONLY_SRAM, MAP_OBC_RAM, MAP_SETA_DSP, MAP_SETA_RISC, MAP_LAST }; -enum { MAX_ROM_SIZE = 0x800000 }; + +enum { + MAX_ROM_SIZE = 0x800000 +}; + +enum +{ + MAP_TYPE_I_O, + MAP_TYPE_ROM, + MAP_TYPE_RAM +}; typedef struct { diff --git a/source/messages.h b/source/messages.h deleted file mode 100644 index 00776ca..0000000 --- a/source/messages.h +++ /dev/null @@ -1,51 +0,0 @@ -#include "../copyright" - -#ifndef _messages_h_ -#define _messages_h_ - -/* Types of message sent to S9xMessage routine */ -enum -{ - S9X_TRACE, - S9X_DEBUG, - S9X_WARNING, - S9X_INFO, - S9X_ERROR, - S9X_FATAL_ERROR -}; - -/* Individual message numbers */ -enum -{ - S9X_ROM_INFO, - S9X_HEADERS_INFO, - S9X_ROM_CONFUSING_FORMAT_INFO, - S9X_ROM_INTERLEAVED_INFO, - S9X_SOUND_DEVICE_OPEN_FAILED, - S9X_APU_STOPPED, - S9X_USAGE, - S9X_GAME_GENIE_CODE_ERROR, - S9X_ACTION_REPLY_CODE_ERROR, - S9X_GOLD_FINGER_CODE_ERROR, - S9X_DEBUG_OUTPUT, - S9X_DMA_TRACE, - S9X_HDMA_TRACE, - S9X_WRONG_FORMAT, - S9X_WRONG_VERSION, - S9X_ROM_NOT_FOUND, - S9X_FREEZE_FILE_NOT_FOUND, - S9X_PPU_TRACE, - S9X_TRACE_DSP1, - S9X_FREEZE_ROM_NAME, - S9X_HEADER_WARNING, - S9X_NETPLAY_NOT_SERVER, - S9X_FREEZE_FILE_INFO, - S9X_TURBO_MODE, - S9X_SOUND_NOT_BUILT, - S9X_MOVIE_INFO, - S9X_WRONG_MOVIE_SNAPSHOT, - S9X_NOT_A_MOVIE_SNAPSHOT, - S9X_AVI_INFO -}; - -#endif diff --git a/source/obc1.c b/source/obc1.c index 2d46238..4263284 100644 --- a/source/obc1.c +++ b/source/obc1.c @@ -16,16 +16,12 @@ uint8_t GetOBC1(uint16_t Address) { case 0x7ff0: return OBC1_RAM[OBC1_BasePtr + (OBC1_Address << 2)]; - case 0x7ff1: return OBC1_RAM[OBC1_BasePtr + (OBC1_Address << 2) + 1]; - case 0x7ff2: return OBC1_RAM[OBC1_BasePtr + (OBC1_Address << 2) + 2]; - case 0x7ff3: return OBC1_RAM[OBC1_BasePtr + (OBC1_Address << 2) + 3]; - case 0x7ff4: return OBC1_RAM[OBC1_BasePtr + (OBC1_Address >> 2) + 0x200]; } @@ -38,29 +34,17 @@ void SetOBC1(uint8_t Byte, uint16_t Address) switch (Address) { case 0x7ff0: - { OBC1_RAM[OBC1_BasePtr + (OBC1_Address << 2)] = Byte; break; - } - case 0x7ff1: - { OBC1_RAM[OBC1_BasePtr + (OBC1_Address << 2) + 1] = Byte; break; - } - case 0x7ff2: - { OBC1_RAM[OBC1_BasePtr + (OBC1_Address << 2) + 2] = Byte; break; - } - case 0x7ff3: - { OBC1_RAM[OBC1_BasePtr + (OBC1_Address << 2) + 3] = Byte; break; - } - case 0x7ff4: { uint8_t Temp; @@ -69,7 +53,6 @@ void SetOBC1(uint8_t Byte, uint16_t Address) OBC1_RAM[OBC1_BasePtr + (OBC1_Address >> 2) + 0x200] = Temp; break; } - case 0x7ff5: { if (Byte & 1) @@ -80,14 +63,12 @@ void SetOBC1(uint8_t Byte, uint16_t Address) OBC1_RAM[0x1ff5] = Byte; break; } - case 0x7ff6: { OBC1_Address = Byte & 0x7f; OBC1_Shift = (Byte & 3) << 1; break; } - default: OBC1_RAM[Address & 0x1fff] = Byte; break; diff --git a/source/port.h b/source/port.h index b887fe1..622027f 100644 --- a/source/port.h +++ b/source/port.h @@ -30,10 +30,8 @@ #define _MAX_EXT PATH_MAX #define _MAX_PATH PATH_MAX -void _makepath(char* path, const char* drive, const char* dir, - const char* fname, const char* ext); -void _splitpath(const char* path, char* drive, char* dir, char* fname, - char* ext); +void _makepath(char* path, const char* drive, const char* dir, const char* fname, const char* ext); +void _splitpath(const char* path, char* drive, char* dir, char* fname, char* ext); #else /* __WIN32__ */ #define strcasecmp stricmp #define strncasecmp strnicmp @@ -53,7 +51,35 @@ void _splitpath(const char* path, char* drive, char* dir, char* fname, #include <libretro.h> -#define MIN(A,B) ((A) < (B) ? (A) : (B)) -#define MAX(A,B) ((A) > (B) ? (A) : (B)) +#define ABS(X) ((X) < 0 ? -(X) : (X)) +#define MIN(A,B) ((A) < (B) ? (A) : (B)) +#define MAX(A,B) ((A) > (B) ? (A) : (B)) + +/* Integer square root by Halleck's method, with Legalize's speedup */ +static inline int32_t _isqrt(int32_t val) +{ + int32_t squaredbit, remainder, root; + + if (val < 1) + return 0; + + squaredbit = 1 << 30; + remainder = val; + root = 0; + + while (squaredbit > 0) + { + if (remainder >= (squaredbit | root)) + { + remainder -= (squaredbit | root); + root >>= 1; + root |= squaredbit; + } else + root >>= 1; + squaredbit >>= 2; + } + + return root; +} #endif diff --git a/source/ppu.c b/source/ppu.c index 9ef69d5..80920b1 100644 --- a/source/ppu.c +++ b/source/ppu.c @@ -18,19 +18,19 @@ extern struct FxInit_s SuperFX; extern uint8_t mul_brightness [16][32]; -uint32_t justifiers = 0xFFFF00AA; +uint32_t justifiers = 0xffff00aa; uint8_t in_bit = 0; extern uint8_t* HDMAMemPointers [8]; void S9xLatchCounters(bool force) { - if (!force && !(Memory.FillRAM[0x4213] & 0x80)) return; + if (!force && !(Memory.FillRAM[0x4213] & 0x80)) + return; PPU.HVBeamCounterLatched = 1; PPU.VBeamPosLatched = (uint16_t) CPU.V_Counter; - PPU.HBeamPosLatched = (uint16_t)((CPU.Cycles * SNES_HCOUNTER_MAX) / - Settings.H_Max); + PPU.HBeamPosLatched = (uint16_t)((CPU.Cycles * SNES_HCOUNTER_MAX) / Settings.H_Max); Memory.FillRAM [0x213F] |= 0x40; } @@ -100,8 +100,7 @@ void S9xFixColourBrightness() IPPU.Red [i] = IPPU.XB [PPU.CGDATA [i] & 0x1f]; IPPU.Green [i] = IPPU.XB [(PPU.CGDATA [i] >> 5) & 0x1f]; IPPU.Blue [i] = IPPU.XB [(PPU.CGDATA [i] >> 10) & 0x1f]; - IPPU.ScreenColors [i] = BUILD_PIXEL(IPPU.Red [i], IPPU.Green [i], - IPPU.Blue [i]); + IPPU.ScreenColors [i] = BUILD_PIXEL(IPPU.Red [i], IPPU.Green [i], IPPU.Blue [i]); } } @@ -127,7 +126,6 @@ static void S9xSetSuperFX(uint8_t Byte, uint16_t Address) FxFlushCache(); } break; - case 0x3031: case 0x3033: case 0x3037: @@ -151,7 +149,6 @@ static void S9xSetSuperFX(uint8_t Byte, uint16_t Address) Memory.FillRAM [0x3000 + GSU_SFR] |= FLG_G; S9xSuperFXExec(); break; - default: if (Address >= 0x3100) FxCacheWriteAccess(Address); @@ -190,7 +187,6 @@ void S9xSetPPU(uint8_t Byte, uint16_t Address) } } break; - case 0x2101: // Sprite (OBJ) tile address if (Byte != Memory.FillRAM [0x2101]) @@ -202,7 +198,6 @@ void S9xSetPPU(uint8_t Byte, uint16_t Address) IPPU.OBJChanged = true; } break; - case 0x2102: // Sprite write address (low) PPU.OAMAddr = ((Memory.FillRAM[0x2103] & 1) << 8) | Byte; @@ -215,7 +210,6 @@ void S9xSetPPU(uint8_t Byte, uint16_t Address) IPPU.OBJChanged = true; } break; - case 0x2103: // Sprite register write address (high), sprite priority rotation // bit. @@ -242,12 +236,10 @@ void S9xSetPPU(uint8_t Byte, uint16_t Address) PPU.OAMReadFlip = 0; PPU.SavedOAMAddr = PPU.OAMAddr; break; - case 0x2104: // Sprite register write REGISTER_2104(Byte); break; - case 0x2105: // Screen mode (0 - 7), background tile sizes and background 3 // priority @@ -262,10 +254,9 @@ void S9xSetPPU(uint8_t Byte, uint16_t Address) // BJ: BG3Priority only takes effect if BGMode==1 and the bit is set PPU.BG3Priority = ((Byte & 0x0f) == 0x09); if (PPU.BGMode == 5 || PPU.BGMode == 6) - IPPU.Interlace = Memory.FillRAM[0x2133] & 1; + IPPU.Interlace = (bool) (Memory.FillRAM[0x2133] & 1); } break; - case 0x2106: // Mosaic pixel size and enable if (Byte != Memory.FillRAM [0x2106]) @@ -289,7 +280,6 @@ void S9xSetPPU(uint8_t Byte, uint16_t Address) PPU.BG[Address - 0x2107].SCBase = (Byte & 0x7c) << 8; } break; - case 0x210B: // [BG01NBA] if (Byte != Memory.FillRAM [0x210b]) { @@ -298,7 +288,6 @@ void S9xSetPPU(uint8_t Byte, uint16_t Address) PPU.BG[1].NameBase = ((Byte >> 4) & 7) << 12; } break; - case 0x210C: // [BG23NBA] if (Byte != Memory.FillRAM [0x210c]) { @@ -307,56 +296,44 @@ void S9xSetPPU(uint8_t Byte, uint16_t Address) PPU.BG[3].NameBase = ((Byte >> 4) & 7) << 12; } break; - - //This is the Theme Park fix - it appears all these registers //share a previous byte value for setting them. - case 0x210D: PPU.BG[0].HOffset = (Byte << 8) | PPU.BGnxOFSbyte; PPU.BGnxOFSbyte = Byte; break; - case 0x210E: PPU.BG[0].VOffset = (Byte << 8) | PPU.BGnxOFSbyte; PPU.BGnxOFSbyte = Byte; break; - case 0x210F: PPU.BG[1].HOffset = (Byte << 8) | PPU.BGnxOFSbyte; PPU.BGnxOFSbyte = Byte; break; - case 0x2110: PPU.BG[1].VOffset = (Byte << 8) | PPU.BGnxOFSbyte; PPU.BGnxOFSbyte = Byte; break; - case 0x2111: PPU.BG[2].HOffset = (Byte << 8) | PPU.BGnxOFSbyte; PPU.BGnxOFSbyte = Byte; break; - case 0x2112: PPU.BG[2].VOffset = (Byte << 8) | PPU.BGnxOFSbyte; PPU.BGnxOFSbyte = Byte; break; - case 0x2113: PPU.BG[3].HOffset = (Byte << 8) | PPU.BGnxOFSbyte; PPU.BGnxOFSbyte = Byte; break; - case 0x2114: PPU.BG[3].VOffset = (Byte << 8) | PPU.BGnxOFSbyte; PPU.BGnxOFSbyte = Byte; break; - //end Theme Park - case 0x2115: // VRAM byte/word access flag and increment - PPU.VMA.High = (Byte & 0x80) == 0 ? false : true; + PPU.VMA.High = (bool) (Byte & 0x80); switch (Byte & 3) { case 0: @@ -382,67 +359,28 @@ void S9xSetPPU(uint8_t Byte, uint16_t Address) else PPU.VMA.FullGraphicCount = 0; break; - case 0x2116: // VRAM read/write address (low) PPU.VMA.Address &= 0xFF00; PPU.VMA.Address |= Byte; -#ifdef CORRECT_VRAM_READS - if (PPU.VMA.FullGraphicCount) - { - uint32_t addr = PPU.VMA.Address; - uint32_t rem = addr & PPU.VMA.Mask1; - uint32_t address = (addr & ~PPU.VMA.Mask1) + - (rem >> PPU.VMA.Shift) + - ((rem & (PPU.VMA.FullGraphicCount - 1)) << 3); - IPPU.VRAMReadBuffer = READ_WORD(Memory.VRAM + ((address << 1) & 0xFFFF)); - } - else - IPPU.VRAMReadBuffer = READ_WORD(Memory.VRAM + ((PPU.VMA.Address << 1) & - 0xffff)); -#else IPPU.FirstVRAMRead = true; -#endif break; - case 0x2117: // VRAM read/write address (high) PPU.VMA.Address &= 0x00FF; PPU.VMA.Address |= Byte << 8; -#ifdef CORRECT_VRAM_READS - if (PPU.VMA.FullGraphicCount) - { - uint32_t addr = PPU.VMA.Address; - uint32_t rem = addr & PPU.VMA.Mask1; - uint32_t address = (addr & ~PPU.VMA.Mask1) + - (rem >> PPU.VMA.Shift) + - ((rem & (PPU.VMA.FullGraphicCount - 1)) << 3); - IPPU.VRAMReadBuffer = READ_WORD(Memory.VRAM + ((address << 1) & 0xFFFF)); - } - else - IPPU.VRAMReadBuffer = READ_WORD(Memory.VRAM + ((PPU.VMA.Address << 1) & - 0xffff)); -#else IPPU.FirstVRAMRead = true; -#endif break; - case 0x2118: // VRAM write data (low) -#ifndef CORRECT_VRAM_READS IPPU.FirstVRAMRead = true; -#endif REGISTER_2118(Byte); break; - case 0x2119: // VRAM write data (high) -#ifndef CORRECT_VRAM_READS IPPU.FirstVRAMRead = true; -#endif REGISTER_2119(Byte); break; - case 0x211a: // Mode 7 outside rotation area display mode and flipping if (Byte != Memory.FillRAM [0x211a]) @@ -451,8 +389,8 @@ void S9xSetPPU(uint8_t Byte, uint16_t Address) PPU.Mode7Repeat = Byte >> 6; if (PPU.Mode7Repeat == 1) PPU.Mode7Repeat = 0; - PPU.Mode7VFlip = (Byte & 2) >> 1; - PPU.Mode7HFlip = Byte & 1; + PPU.Mode7VFlip = (bool) (Byte & 2); + PPU.Mode7HFlip = (bool) (Byte & 1); } break; case 0x211b: @@ -481,18 +419,15 @@ void S9xSetPPU(uint8_t Byte, uint16_t Address) // Mode 7 centre of rotation Y (low & high) PPU.CentreY = ((PPU.CentreY >> 8) & 0xff) | (Byte << 8); break; - case 0x2121: // CG-RAM address - PPU.CGFLIP = 0; - PPU.CGFLIPRead = 0; + PPU.CGFLIP = false; + PPU.CGFLIPRead = false; PPU.CGADD = Byte; break; - case 0x2122: REGISTER_2122(Byte); break; - case 0x2123: // Window 1 and 2 enable for backgrounds 1 and 2 if (Byte != Memory.FillRAM [0x2123]) @@ -619,26 +554,16 @@ void S9xSetPPU(uint8_t Byte, uint16_t Address) return; } break; - case 0x212e: - // Window mask designation for main screen ? - case 0x212f: - // Window mask designation for sub-screen ? + case 0x212e: // Window mask designation for main screen ? + case 0x212f: // Window mask designation for sub-screen ? + case 0x2130: // Fixed colour addition or screen addition if (Byte != Memory.FillRAM [Address]) { FLUSH_REDRAW(); PPU.RecomputeClipWindows = true; } break; - case 0x2130: - // Fixed colour addition or screen addition - if (Byte != Memory.FillRAM [0x2130]) - { - FLUSH_REDRAW(); - PPU.RecomputeClipWindows = true; - } - break; - case 0x2131: - // Colour addition or subtraction select + case 0x2131: // Colour addition or subtraction select if (Byte != Memory.FillRAM[0x2131]) { FLUSH_REDRAW(); @@ -671,7 +596,8 @@ void S9xSetPPU(uint8_t Byte, uint16_t Address) else IPPU.RenderedScreenHeight = PPU.ScreenHeight; } - else PPU.ScreenHeight = SNES_HEIGHT; + else + PPU.ScreenHeight = SNES_HEIGHT; if ((Memory.FillRAM [0x2133] ^ Byte) & 3) { @@ -679,10 +605,9 @@ void S9xSetPPU(uint8_t Byte, uint16_t Address) if ((Memory.FillRAM [0x2133] ^ Byte) & 2) IPPU.OBJChanged = true; if (PPU.BGMode == 5 || PPU.BGMode == 6) - IPPU.Interlace = Byte & 1; - IPPU.InterlaceSprites = 0; + IPPU.Interlace = (bool) (Byte & 1); + IPPU.InterlaceSprites = false; } - } break; case 0x2134: @@ -829,11 +754,9 @@ void S9xSetPPU(uint8_t Byte, uint16_t Address) { S9xSetSuperFX(Byte, Address); return; - } } Memory.FillRAM[Address] = Byte; - } /******************************************************************************/ @@ -849,18 +772,13 @@ uint8_t S9xGetPPU(uint16_t Address) { switch (Address) { - case 0x2100: - case 0x2101: - case 0x2102: - case 0x2103: - return OpenBus; - case 0x2104: case 0x2105: case 0x2106: case 0x2108: case 0x2109: case 0x210a: + case 0x2114: case 0x2115: case 0x2116: case 0x2118: @@ -873,45 +791,6 @@ uint8_t S9xGetPPU(uint16_t Address) case 0x2129: case 0x212a: return PPU.OpenBus1; - - case 0x2107: - case 0x2117: - case 0x2121: - case 0x2122: - case 0x2123: - case 0x2127: - case 0x212b: - case 0x212c: - case 0x212d: - case 0x212e: - case 0x212f: - case 0x2130: - case 0x2131: - case 0x2132: - case 0x2133: - return OpenBus; - - case 0x210b: - case 0x210c: - case 0x210d: - case 0x210e: - case 0x210f: - case 0x2110: - case 0x2111: - case 0x2112: - case 0x2113: - return OpenBus; - - case 0x2114: - case 0x211b: - case 0x211c: - case 0x211d: - case 0x211e: - case 0x211f: - case 0x2120: - return OpenBus; - - case 0x2134: case 0x2135: case 0x2136: @@ -919,7 +798,6 @@ uint8_t S9xGetPPU(uint16_t Address) if (PPU.Need16x8Mulitply) { int32_t r = (int32_t) PPU.MatrixA * (int32_t)(PPU.MatrixB >> 8); - Memory.FillRAM[0x2134] = (uint8_t) r; Memory.FillRAM[0x2135] = (uint8_t)(r >> 8); Memory.FillRAM[0x2136] = (uint8_t)(r >> 16); @@ -929,7 +807,6 @@ uint8_t S9xGetPPU(uint16_t Address) case 0x2137: S9xLatchCounters(0); return OpenBus; - case 0x2138: // Read OAM (sprite) control data if (PPU.OAMAddr & 0x100) @@ -942,7 +819,7 @@ uint8_t S9xGetPPU(uint16_t Address) PPU.OAMAddr = (PPU.OAMAddr + 1) & 0x1ff; if (PPU.OAMPriorityRotation && PPU.FirstSprite != (PPU.OAMAddr >> 1)) { - PPU.FirstSprite = (PPU.OAMAddr & 0xFE) >> 1; + PPU.FirstSprite = (PPU.OAMAddr & 0xfe) >> 1; IPPU.OBJChanged = true; } } @@ -957,37 +834,17 @@ uint8_t S9xGetPPU(uint16_t Address) ++PPU.OAMAddr; if (PPU.OAMPriorityRotation && PPU.FirstSprite != (PPU.OAMAddr >> 1)) { - PPU.FirstSprite = (PPU.OAMAddr & 0xFE) >> 1; + PPU.FirstSprite = (PPU.OAMAddr & 0xfe) >> 1; IPPU.OBJChanged = true; } } } PPU.OAMFlip ^= 1; return (PPU.OpenBus1 = byte); - case 0x2139: // Read vram low byte -#ifdef CORRECT_VRAM_READS - byte = IPPU.VRAMReadBuffer & 0xff; - if (!PPU.VMA.High) - { - if (PPU.VMA.FullGraphicCount) - { - uint32_t addr = PPU.VMA.Address; - uint32_t rem = addr & PPU.VMA.Mask1; - uint32_t address = (addr & ~PPU.VMA.Mask1) + - (rem >> PPU.VMA.Shift) + - ((rem & (PPU.VMA.FullGraphicCount - 1)) << 3); - IPPU.VRAMReadBuffer = READ_WORD(Memory.VRAM + ((address << 1) & 0xFFFF)); - } - else - IPPU.VRAMReadBuffer = READ_WORD(Memory.VRAM + ((PPU.VMA.Address << 1) & - 0xffff)); - PPU.VMA.Address += PPU.VMA.Increment; - } -#else if (IPPU.FirstVRAMRead) - byte = Memory.VRAM[(PPU.VMA.Address << 1) & 0xFFFF]; + byte = Memory.VRAM[(PPU.VMA.Address << 1) & 0xffff]; else if (PPU.VMA.FullGraphicCount) { uint32_t addr = PPU.VMA.Address - 1; @@ -995,7 +852,7 @@ uint8_t S9xGetPPU(uint16_t Address) uint32_t address = (addr & ~PPU.VMA.Mask1) + (rem >> PPU.VMA.Shift) + ((rem & (PPU.VMA.FullGraphicCount - 1)) << 3); - byte = Memory.VRAM [((address << 1) - 2) & 0xFFFF]; + byte = Memory.VRAM [((address << 1) - 2) & 0xffff]; } else byte = Memory.VRAM[((PPU.VMA.Address << 1) - 2) & 0xffff]; @@ -1005,30 +862,9 @@ uint8_t S9xGetPPU(uint16_t Address) PPU.VMA.Address += PPU.VMA.Increment; IPPU.FirstVRAMRead = false; } -#endif - PPU.OpenBus1 = byte; - break; + return (PPU.OpenBus1 = byte); case 0x213A: // Read vram high byte -#ifdef CORRECT_VRAM_READS - byte = (IPPU.VRAMReadBuffer >> 8) & 0xff; - if (PPU.VMA.High) - { - if (PPU.VMA.FullGraphicCount) - { - uint32_t addr = PPU.VMA.Address; - uint32_t rem = addr & PPU.VMA.Mask1; - uint32_t address = (addr & ~PPU.VMA.Mask1) + - (rem >> PPU.VMA.Shift) + - ((rem & (PPU.VMA.FullGraphicCount - 1)) << 3); - IPPU.VRAMReadBuffer = READ_WORD(Memory.VRAM + ((address << 1) & 0xFFFF)); - } - else - IPPU.VRAMReadBuffer = READ_WORD(Memory.VRAM + ((PPU.VMA.Address << 1) & - 0xffff)); - PPU.VMA.Address += PPU.VMA.Increment; - } -#else if (IPPU.FirstVRAMRead) byte = Memory.VRAM[((PPU.VMA.Address << 1) + 1) & 0xffff]; else if (PPU.VMA.FullGraphicCount) @@ -1038,67 +874,52 @@ uint8_t S9xGetPPU(uint16_t Address) uint32_t address = (addr & ~PPU.VMA.Mask1) + (rem >> PPU.VMA.Shift) + ((rem & (PPU.VMA.FullGraphicCount - 1)) << 3); - byte = Memory.VRAM [((address << 1) - 1) & 0xFFFF]; + byte = Memory.VRAM [((address << 1) - 1) & 0xffff]; } else - byte = Memory.VRAM[((PPU.VMA.Address << 1) - 1) & 0xFFFF]; + byte = Memory.VRAM[((PPU.VMA.Address << 1) - 1) & 0xffff]; if (PPU.VMA.High) { PPU.VMA.Address += PPU.VMA.Increment; IPPU.FirstVRAMRead = false; } -#endif - PPU.OpenBus1 = byte; - break; - + return (PPU.OpenBus1 = byte); case 0x213B: // Read palette data if (PPU.CGFLIPRead) - byte = PPU.CGDATA [PPU.CGADD++] >> 8; + byte = (PPU.OpenBus2 & 0x80) | ((PPU.CGDATA[PPU.CGADD++] >> 8) & 0x7f); else byte = PPU.CGDATA [PPU.CGADD] & 0xff; - PPU.CGFLIPRead ^= 1; + PPU.CGFLIPRead = !PPU.CGFLIPRead; return (PPU.OpenBus2 = byte); - case 0x213C: // Horizontal counter value 0-339 if (PPU.HBeamFlip) - byte = (PPU.OpenBus2 & 0xfe) - | ((PPU.HBeamPosLatched >> 8) & 0x01); - + byte = (PPU.OpenBus2 & 0xfe) | ((PPU.HBeamPosLatched >> 8) & 0x01); else byte = (uint8_t)PPU.HBeamPosLatched; - PPU.OpenBus2 = byte; PPU.HBeamFlip ^= 1; - break; - + return (PPU.OpenBus2 = byte); case 0x213D: // Vertical counter value 0-262 if (PPU.VBeamFlip) - byte = (PPU.OpenBus2 & 0xfe) - | ((PPU.VBeamPosLatched >> 8) & 0x01); + byte = (PPU.OpenBus2 & 0xfe) | ((PPU.VBeamPosLatched >> 8) & 0x01); else byte = (uint8_t)PPU.VBeamPosLatched; - PPU.OpenBus2 = byte; PPU.VBeamFlip ^= 1; - break; - + return (PPU.OpenBus2 = byte); case 0x213E: // PPU time and range over flags FLUSH_REDRAW(); - - //so far, 5c77 version is always 1. - return (PPU.OpenBus1 = (Model->_5C77 | PPU.RangeTimeOver)); - + byte = (PPU.OpenBus1 & 0x10) | PPU.RangeTimeOver | Model->_5C77; + return (PPU.OpenBus1 = byte); case 0x213F: // NTSC/PAL and which field flags PPU.VBeamFlip = PPU.HBeamFlip = 0; - //neviksti found a 2 and a 3 here. SNEeSe uses a 3. - //XXX: field flags not emulated - return ((Settings.PAL ? 0x10 : 0) | (Memory.FillRAM[0x213f] & 0xc0) | - Model->_5C78) | (~PPU.OpenBus2 & 0x20); - + byte = (PPU.OpenBus2 & 0x20) | (Memory.FillRAM[0x213f] & 0xc0) | (Settings.PAL ? 0x10 : 0) | Model->_5C78; + Memory.FillRAM[0x213f] &= ~0x40; + return (PPU.OpenBus2 = byte); case 0x2140: case 0x2141: case 0x2142: @@ -1175,10 +996,7 @@ uint8_t S9xGetPPU(uint16_t Address) { if (SNESGameFixes.APU_OutPorts_ReturnValueFix && Address >= 0x2140 && Address <= 0x2143 && !CPU.V_Counter) - { - return (uint8_t)((Address & 1) ? ((rand() & 0xff00) >> 8) : - (rand() & 0xff)); - } + return (uint8_t)((Address & 1) ? ((rand() & 0xff00) >> 8) : (rand() & 0xff)); return (APU.OutPorts [Address & 3]); } @@ -1211,27 +1029,24 @@ uint8_t S9xGetPPU(uint16_t Address) return ((r >> 3) & 0xff); } return (Memory.FillRAM[Address]); - #else // SPCTOOL return (S9xAPUReadPort(Address & 3)); #endif //#ifndef USE_BLARGG_APU - case 0x2180: // Read WRAM byte = Memory.RAM [PPU.WRAM++]; PPU.WRAM &= 0x1FFFF; - break; - case 0x2181: - case 0x2182: - case 0x2183: + return byte; default: return OpenBus; } } else { - if (Settings.SA1) - return (S9xGetSA1(Address)); + if (Settings.SA1 && Address >= 0x2200) + return S9xGetSA1(Address); + else if (Settings.SRTC && Address == 2800) + return S9xGetSRTC(Address); if (Address <= 0x2fff || Address >= 0x3300) { @@ -1245,12 +1060,6 @@ uint8_t S9xGetPPU(uint16_t Address) if (Model->_5C77 == 2) return (0); return OpenBus; - case 0x2800: - // For Dai Kaijyu Monogatari II - if (Settings.SRTC) - return (S9xGetSRTC(Address)); - /*FALL*/ - default: return OpenBus; } @@ -1271,9 +1080,9 @@ uint8_t S9xGetPPU(uint16_t Address) CLEAR_IRQ_SOURCE(GSU_IRQ_SOURCE); Memory.FillRAM [0x3031] = byte & 0x7f; } - return (byte); + return byte; } - return (byte); + return byte; } /******************************************************************************/ @@ -1340,15 +1149,13 @@ void S9xSetCPU(uint8_t byte, uint16_t Address) PPU.HTimerEnabled = false; PPU.HTimerPosition = Settings.H_Max + 1; } - if (!Settings.DaffyDuck) + if (!(byte & 0x30)) CLEAR_IRQ_SOURCE(PPU_V_BEAM_IRQ_SOURCE | PPU_H_BEAM_IRQ_SOURCE); if ((byte & 0x80) && !(Memory.FillRAM [0x4200] & 0x80) && CPU.V_Counter >= PPU.ScreenHeight + FIRST_VISIBLE_LINE && - CPU.V_Counter <= PPU.ScreenHeight + - (SNESGameFixes.alienVSpredetorFix ? 25 : 15) - && //jyam 15->25 alien vs predetor + // NMI can trigger during VBlank as long as NMI_read ($4210) wasn't cleared. // Panic Bomberman clears the NMI pending flag @ scanline 230 before enabling // NMIs again. The NMI routine crashes the CPU if it is called without the NMI // pending flag being set... @@ -1357,16 +1164,16 @@ void S9xSetCPU(uint8_t byte, uint16_t Address) { CPU.Flags |= NMI_FLAG; CPU.NMIActive = true; - CPU.NMICycleCount = CPU.NMITriggerPoint; + CPU.NMICycleCount = CPU.Cycles + TWO_CYCLES; + break; } - break; case 0x4201: if ((byte & 0x80) == 0 && (Memory.FillRAM[0x4213] & 0x80) == 0x80) S9xLatchCounters(1); Memory.FillRAM[0x4201] = Memory.FillRAM[0x4213] = byte; break; case 0x4202: - // Multiplier (for multply) + // Multiplier (for multiply) break; case 0x4203: { @@ -1416,7 +1223,6 @@ void S9xSetCPU(uint8_t byte, uint16_t Address) if (PPU.HTimerEnabled && PPU.IRQHBeamPos != d) S9xUpdateHTimer(); break; - case 0x4208: d = PPU.IRQHBeamPos; PPU.IRQHBeamPos = (PPU.IRQHBeamPos & 0xFF) | ((byte & 1) << 8); @@ -1425,7 +1231,6 @@ void S9xSetCPU(uint8_t byte, uint16_t Address) S9xUpdateHTimer(); break; - case 0x4209: d = PPU.IRQVBeamPos; PPU.IRQVBeamPos = (PPU.IRQVBeamPos & 0xFF00) | byte; @@ -1440,7 +1245,6 @@ void S9xSetCPU(uint8_t byte, uint16_t Address) } } break; - case 0x420A: d = PPU.IRQVBeamPos; PPU.IRQVBeamPos = (PPU.IRQVBeamPos & 0xFF) | ((byte & 1) << 8); @@ -1455,7 +1259,6 @@ void S9xSetCPU(uint8_t byte, uint16_t Address) } } break; - case 0x420B: if ((byte & 0x01) != 0) S9xDoDMA(0); @@ -1480,19 +1283,18 @@ void S9xSetCPU(uint8_t byte, uint16_t Address) Memory.FillRAM[0x420c] = byte; IPPU.HDMA = byte; break; - case 0x420d: // Cycle speed 0 - 2.68Mhz, 1 - 3.58Mhz (banks 0x80 +) if ((byte & 1) != (Memory.FillRAM [0x420d] & 1)) { if (byte & 1) CPU.FastROMSpeed = ONE_CYCLE; - else CPU.FastROMSpeed = SLOW_ONE_CYCLE; + else + CPU.FastROMSpeed = SLOW_ONE_CYCLE; FixROMSpeed(); } break; - case 0x420e: case 0x420f: // --->>> Unknown @@ -1529,7 +1331,6 @@ void S9xSetCPU(uint8_t byte, uint16_t Address) case 0x421f: // Joypad values (read-only) return; - case 0x4300: case 0x4310: case 0x4320: @@ -1539,13 +1340,13 @@ void S9xSetCPU(uint8_t byte, uint16_t Address) case 0x4360: case 0x4370: d = (Address >> 4) & 0x7; - DMA[d].TransferDirection = (byte & 128) != 0 ? 1 : 0; - DMA[d].HDMAIndirectAddressing = (byte & 64) != 0 ? 1 : 0; - DMA[d].AAddressDecrement = (byte & 16) != 0 ? 1 : 0; - DMA[d].AAddressFixed = (byte & 8) != 0 ? 1 : 0; + DMA[d].TransferDirection = (bool) (byte & 0x80); + DMA[d].HDMAIndirectAddressing = (bool) (byte & 0x40); + Memory.FillRAM [Address | 0xf] = (byte & 0x20); + DMA[d].AAddressDecrement = (bool) (byte & 0x10); + DMA[d].AAddressFixed = (bool) (byte & 0x08); DMA[d].TransferMode = (byte & 7); break; - case 0x4301: case 0x4311: case 0x4321: @@ -1556,7 +1357,6 @@ void S9xSetCPU(uint8_t byte, uint16_t Address) case 0x4371: DMA[((Address >> 4) & 0x7)].BAddress = byte; break; - case 0x4302: case 0x4312: case 0x4322: @@ -1569,7 +1369,6 @@ void S9xSetCPU(uint8_t byte, uint16_t Address) DMA[d].AAddress &= 0xFF00; DMA[d].AAddress |= byte; break; - case 0x4303: case 0x4313: case 0x4323: @@ -1582,7 +1381,6 @@ void S9xSetCPU(uint8_t byte, uint16_t Address) DMA[d].AAddress &= 0xFF; DMA[d].AAddress |= byte << 8; break; - case 0x4304: case 0x4314: case 0x4324: @@ -1593,9 +1391,7 @@ void S9xSetCPU(uint8_t byte, uint16_t Address) case 0x4374: DMA[((Address >> 4) & 0x7)].ABank = byte; HDMAMemPointers[((Address >> 4) & 0x7)] = NULL; - break; - case 0x4305: case 0x4315: case 0x4325: @@ -1605,13 +1401,12 @@ void S9xSetCPU(uint8_t byte, uint16_t Address) case 0x4365: case 0x4375: d = (Address >> 4) & 0x7; - DMA[d].TransferBytes &= 0xFF00; + DMA[d].TransferBytes &= 0xff00; DMA[d].TransferBytes |= byte; DMA[d].IndirectAddress &= 0xff00; DMA[d].IndirectAddress |= byte; HDMAMemPointers[d] = NULL; break; - case 0x4306: case 0x4316: case 0x4326: @@ -1627,7 +1422,6 @@ void S9xSetCPU(uint8_t byte, uint16_t Address) DMA[d].IndirectAddress |= byte << 8; HDMAMemPointers[d] = NULL; break; - case 0x4307: case 0x4317: case 0x4327: @@ -1639,7 +1433,6 @@ void S9xSetCPU(uint8_t byte, uint16_t Address) DMA[d = ((Address >> 4) & 0x7)].IndirectBank = byte; HDMAMemPointers[d] = NULL; break; - case 0x4308: case 0x4318: case 0x4328: @@ -1653,7 +1446,6 @@ void S9xSetCPU(uint8_t byte, uint16_t Address) DMA[d].Address |= byte; HDMAMemPointers[d] = NULL; break; - case 0x4309: case 0x4319: case 0x4329: @@ -1667,7 +1459,6 @@ void S9xSetCPU(uint8_t byte, uint16_t Address) DMA[d].Address |= byte << 8; HDMAMemPointers[d] = NULL; break; - case 0x430A: case 0x431A: case 0x432A: @@ -1680,17 +1471,6 @@ void S9xSetCPU(uint8_t byte, uint16_t Address) DMA[d].LineCount = byte & 0x7f; DMA[d].Repeat = !(byte & 0x80); break; - - case 0x430F: - case 0x431F: - case 0x432F: - case 0x433F: - case 0x434F: - case 0x435F: - case 0x436F: - case 0x437F: - Address &= ~4; // Convert 43xF to 43xB - /* fall through */ case 0x430B: case 0x431B: case 0x432B: @@ -1699,9 +1479,17 @@ void S9xSetCPU(uint8_t byte, uint16_t Address) case 0x435B: case 0x436B: case 0x437B: - // Unknown, but they seem to be RAM-ish + case 0x430F: + case 0x431F: + case 0x432F: + case 0x433F: + case 0x434F: + case 0x435F: + case 0x436F: + case 0x437F: + Memory.FillRAM [Address | 0xf] = byte; break; - + /* fall through */ //These registers are used by both the S-DD1 and the SPC7110 case 0x4800: case 0x4801: @@ -1710,16 +1498,15 @@ void S9xSetCPU(uint8_t byte, uint16_t Address) if (Settings.SPC7110) S9xSetSPC7110(byte, Address); break; - case 0x4804: case 0x4805: case 0x4806: case 0x4807: if (Settings.SPC7110) S9xSetSPC7110(byte, Address); - else S9xSetSDD1MemoryMap(Address - 0x4804, byte & 7); + else + S9xSetSDD1MemoryMap(Address - 0x4804, byte & 7); break; - //these are used by the SPC7110 case 0x4808: case 0x4809: @@ -1765,7 +1552,6 @@ void S9xSetCPU(uint8_t byte, uint16_t Address) S9xSetSPC7110(byte, Address); break; } - default: break; } @@ -1778,6 +1564,7 @@ void S9xSetCPU(uint8_t byte, uint16_t Address) /******************************************************************************/ uint8_t S9xGetCPU(uint16_t Address) { + int32_t d; uint8_t byte; if (Address < 0x4200) @@ -1866,7 +1653,6 @@ uint8_t S9xGetCPU(uint16_t Address) case 0x420e: case 0x420f: return OpenBus; - case 0x4210: #ifdef CPU_SHUTDOWN CPU.WaitAddress = CPU.PCAtOpcodeStart; @@ -1874,31 +1660,19 @@ uint8_t S9xGetCPU(uint16_t Address) byte = Memory.FillRAM[0x4210]; Memory.FillRAM[0x4210] = Model->_5A22; //SNEeSe returns 2 for 5A22 version. - return ((byte & 0x80) - | (OpenBus & 0x70) - | Model->_5A22); - + return ((byte & 0x80) | (OpenBus & 0x70) | Model->_5A22); case 0x4211: - byte = (CPU.IRQActive & (PPU_V_BEAM_IRQ_SOURCE | PPU_H_BEAM_IRQ_SOURCE)) ? - 0x80 : 0; - // Super Robot Wars Ex ROM bug requires this. - byte |= CPU.Cycles >= Settings.HBlankStart ? 0x40 : 0; + byte = (CPU.IRQActive & (PPU_V_BEAM_IRQ_SOURCE | PPU_H_BEAM_IRQ_SOURCE)) ? 0x80 : 0; CLEAR_IRQ_SOURCE(PPU_V_BEAM_IRQ_SOURCE | PPU_H_BEAM_IRQ_SOURCE); - - // Maybe? Register Scan indicated open bus... - byte |= OpenBus & 0x3f; + byte |= OpenBus & 0x7f; return (byte); - case 0x4212: // V-blank, h-blank and joypads being read flags (read-only) #ifdef CPU_SHUTDOWN CPU.WaitAddress = CPU.PCAtOpcodeStart; #endif - return (REGISTER_4212() - | (OpenBus & 0x3E) - ); - + return (REGISTER_4212() | (OpenBus & 0x3E)); case 0x4213: // I/O port input - returns 0 wherever $4201 is 0, and 1 elsewhere // unless something else pulls it down (i.e. a gun) @@ -1919,8 +1693,8 @@ uint8_t S9xGetCPU(uint16_t Address) case 0x421d: case 0x421e: case 0x421f: - // Joypads 1-4 button and direction state. - /* fall through */ + // Joypads 1-4 button and direction state. + return (Memory.FillRAM [Address]); case 0x4300: case 0x4310: case 0x4320: @@ -1929,8 +1703,13 @@ uint8_t S9xGetCPU(uint16_t Address) case 0x4350: case 0x4360: case 0x4370: - // DMA direction, address type, fixed flag, - /* fall through */ + d = (Address >> 4) & 0x7; + return ((DMA[d].TransferDirection ? 0x80 : 0x00) | + (DMA[d].HDMAIndirectAddressing ? 0x40 : 0x00) | + ((uint8_t) Memory.FillRAM [Address]) | + (DMA[d].AAddressDecrement ? 0x10 : 0x00) | + (DMA[d].AAddressFixed ? 0x08 : 0x00) | + (DMA[d].TransferMode & 7)); case 0x4301: case 0x4311: case 0x4321: @@ -1939,7 +1718,7 @@ uint8_t S9xGetCPU(uint16_t Address) case 0x4351: case 0x4361: case 0x4371: - /* fall through */ + return DMA[((Address >> 4) & 0x7)].BAddress; case 0x4302: case 0x4312: case 0x4322: @@ -1948,7 +1727,7 @@ uint8_t S9xGetCPU(uint16_t Address) case 0x4352: case 0x4362: case 0x4372: - /* fall through */ + return (DMA[((Address >> 4) & 0x7)].AAddress & 0xFF); case 0x4303: case 0x4313: case 0x4323: @@ -1957,7 +1736,7 @@ uint8_t S9xGetCPU(uint16_t Address) case 0x4353: case 0x4363: case 0x4373: - /* fall through */ + return (DMA[((Address >> 4) & 0x7)].AAddress >> 8); case 0x4304: case 0x4314: case 0x4324: @@ -1966,7 +1745,7 @@ uint8_t S9xGetCPU(uint16_t Address) case 0x4354: case 0x4364: case 0x4374: - /* fall through */ + return DMA[((Address >> 4) & 0x7)].ABank; case 0x4305: case 0x4315: case 0x4325: @@ -1975,7 +1754,7 @@ uint8_t S9xGetCPU(uint16_t Address) case 0x4355: case 0x4365: case 0x4375: - /* fall through */ + return (DMA[((Address >> 4) & 0x7)].IndirectAddress & 0xff); case 0x4306: case 0x4316: case 0x4326: @@ -1984,7 +1763,16 @@ uint8_t S9xGetCPU(uint16_t Address) case 0x4356: case 0x4366: case 0x4376: - /* fall through */ + return (DMA[((Address >> 4) & 0x7)].IndirectAddress >> 8); + case 0x4307: + case 0x4317: + case 0x4327: + case 0x4337: + case 0x4347: + case 0x4357: + case 0x4367: + case 0x4377: + return DMA[((Address >> 4) & 0x7)].IndirectBank; case 0x4308: case 0x4318: case 0x4328: @@ -1993,7 +1781,7 @@ uint8_t S9xGetCPU(uint16_t Address) case 0x4358: case 0x4368: case 0x4378: - /* fall through */ + return (DMA[((Address >> 4) & 0x7)].Address & 0xFF); case 0x4309: case 0x4319: case 0x4329: @@ -2002,18 +1790,7 @@ uint8_t S9xGetCPU(uint16_t Address) case 0x4359: case 0x4369: case 0x4379: - return (Memory.FillRAM[Address]); - - case 0x4307: - case 0x4317: - case 0x4327: - case 0x4337: - case 0x4347: - case 0x4357: - case 0x4367: - case 0x4377: - return (DMA[(Address >> 4) & 7].IndirectBank); - + return (DMA[((Address >> 4) & 0x7)].Address >> 8); case 0x430A: case 0x431A: case 0x432A: @@ -2022,23 +1799,8 @@ uint8_t S9xGetCPU(uint16_t Address) case 0x435A: case 0x436A: case 0x437A: - { - int32_t d = (Address & 0x70) >> 4; - if (IPPU.HDMA & (1 << d)) - return (DMA[d].LineCount); - return (Memory.FillRAM[Address]); - } - - case 0x430F: - case 0x431F: - case 0x432F: - case 0x433F: - case 0x434F: - case 0x435F: - case 0x436F: - case 0x437F: - Address &= ~4; // Convert 43xF to 43xB - /* fall through */ + d = (Address >> 4) & 0x7; + return (DMA[d].LineCount ^ (DMA[d].Repeat ? 0x00 : 0x80)); case 0x430B: case 0x431B: case 0x432B: @@ -2047,9 +1809,15 @@ uint8_t S9xGetCPU(uint16_t Address) case 0x435B: case 0x436B: case 0x437B: - // Unknown, but they seem to be RAM-ish - return (Memory.FillRAM[Address]); - + case 0x430F: + case 0x431F: + case 0x432F: + case 0x433F: + case 0x434F: + case 0x435F: + case 0x436F: + case 0x437F: + return (uint8_t) Memory.FillRAM [Address | 0xf]; default: if (Address >= 0x4800 && Settings.SPC7110) return S9xGetSPC7110(Address); @@ -2066,7 +1834,7 @@ static void CommonPPUReset() PPU.BGMode = 0; PPU.BG3Priority = 0; PPU.Brightness = 0; - PPU.VMA.High = 0; + PPU.VMA.High = false; PPU.VMA.Increment = 1; PPU.VMA.Address = 0; PPU.VMA.FullGraphicCount = 0; @@ -2098,15 +1866,14 @@ static void CommonPPUReset() PPU.ClipWindow1Inside[4] = PPU.ClipWindow1Inside[5] = true; PPU.ClipWindow2Inside[4] = PPU.ClipWindow2Inside[5] = true; - PPU.CGFLIP = 0; + PPU.CGFLIP = false; int32_t c; for (c = 0; c < 256; c++) { IPPU.Red [c] = (c & 7) << 2; IPPU.Green [c] = ((c >> 3) & 7) << 2; IPPU.Blue [c] = ((c >> 6) & 2) << 3; - PPU.CGDATA [c] = IPPU.Red [c] | (IPPU.Green [c] << 5) | - (IPPU.Blue [c] << 10); + PPU.CGDATA [c] = IPPU.Red [c] | (IPPU.Green [c] << 5) | (IPPU.Blue [c] << 10); } PPU.FirstSprite = 0; @@ -2150,12 +1917,9 @@ static void CommonPPUReset() PPU.WRAM = 0; PPU.BG_Forced = 0; PPU.ForcedBlanking = true; - PPU.OBJThroughMain = false; - PPU.OBJThroughSub = false; PPU.OBJSizeSelect = 0; PPU.OBJNameSelect = 0; PPU.OBJNameBase = 0; - PPU.OBJAddition = false; PPU.OAMReadFlip = 0; PPU.BGnxOFSbyte = 0; memset(PPU.OAMData, 0, 512 + 32); @@ -2174,7 +1938,7 @@ static void CommonPPUReset() PPU.Window2Left = 1; PPU.Window2Right = 0; PPU.RecomputeClipWindows = true; - PPU.CGFLIPRead = 0; + PPU.CGFLIPRead = false; PPU.Need16x8Mulitply = false; PPU.MouseSpeed[0] = PPU.MouseSpeed[1] = 0; @@ -2182,7 +1946,7 @@ static void CommonPPUReset() IPPU.HDMA = 0; IPPU.HDMAStarted = false; IPPU.MaxBrightness = 0; - IPPU.LatchedBlanking = 0; + IPPU.LatchedBlanking = false; IPPU.OBJChanged = true; IPPU.RenderThisFrame = true; IPPU.DirectColourMapsNeedRebuild = true; @@ -2194,11 +1958,7 @@ static void CommonPPUReset() memset(IPPU.TileCached [TILE_2BIT], 0, MAX_2BIT_TILES); memset(IPPU.TileCached [TILE_4BIT], 0, MAX_4BIT_TILES); memset(IPPU.TileCached [TILE_8BIT], 0, MAX_8BIT_TILES); -#ifdef CORRECT_VRAM_READS - IPPU.VRAMReadBuffer = 0; // XXX: FIXME: anything better? -#else IPPU.FirstVRAMRead = false; -#endif IPPU.Interlace = false; IPPU.InterlaceSprites = false; IPPU.DoubleWidthPixels = false; @@ -2527,10 +2287,9 @@ void S9xUpdateJoypads() uint32_t i; for (i = 0; i < 5; i++) + { IPPU.Joypads [i] = S9xReadJoypad(i); - for (i = 0; i < 5; i++) - { if ((IPPU.Joypads [i] & (SNES_LEFT_MASK | SNES_RIGHT_MASK)) == (SNES_LEFT_MASK | SNES_RIGHT_MASK)) IPPU.Joypads [i] &= ~SNES_RIGHT_MASK; @@ -2543,10 +2302,8 @@ void S9xUpdateJoypads() if (IPPU.Controller == SNES_JOYPAD || IPPU.Controller == SNES_MULTIPLAYER5) { for (i = 0; i < 5; i++) - { if (IPPU.Joypads [i]) IPPU.Joypads [i] |= 0xffff0000; - } } // Read mouse position if enabled @@ -2599,7 +2356,6 @@ void S9xUpdateJoypads() Memory.FillRAM [0x421b] = 0; S9xUpdateJustifiers(); } - } @@ -2607,20 +2363,15 @@ void S9xSuperFXExec() { if (Settings.SuperFX) { - if ((Memory.FillRAM [0x3000 + GSU_SFR] & FLG_G) && - (Memory.FillRAM [0x3000 + GSU_SCMR] & 0x18) == 0x18) + if ((Memory.FillRAM [0x3000 + GSU_SFR] & FLG_G) && (Memory.FillRAM [0x3000 + GSU_SCMR] & 0x18) == 0x18) { if (!Settings.WinterGold || Settings.StarfoxHack) FxEmulate(~0); else FxEmulate((Memory.FillRAM [0x3000 + GSU_CLSR] & 1) ? 700 : 350); - int32_t GSUStatus = Memory.FillRAM [0x3000 + GSU_SFR] | - (Memory.FillRAM [0x3000 + GSU_SFR + 1] << 8); + int32_t GSUStatus = Memory.FillRAM [0x3000 + GSU_SFR] | (Memory.FillRAM [0x3000 + GSU_SFR + 1] << 8); if ((GSUStatus & (FLG_G | FLG_IRQ)) == FLG_IRQ) - { - // Trigger a GSU IRQ. - S9xSetIRQ(GSU_IRQ_SOURCE); - } + S9xSetIRQ(GSU_IRQ_SOURCE); // Trigger a GSU IRQ. } } } @@ -2681,17 +2432,16 @@ void REGISTER_2104(uint8_t byte) IPPU.OBJChanged = true; } } - else - { - if (PPU.OAMPriorityRotation && (PPU.OAMAddr & 1)) IPPU.OBJChanged = true; - } + else if (PPU.OAMPriorityRotation && (PPU.OAMAddr & 1)) + IPPU.OBJChanged = true; } else if (!(PPU.OAMFlip & 1)) { PPU.OAMWriteRegister &= 0xff00; PPU.OAMWriteRegister |= byte; PPU.OAMFlip |= 1; - if (PPU.OAMPriorityRotation && (PPU.OAMAddr & 1)) IPPU.OBJChanged = true; + if (PPU.OAMPriorityRotation && (PPU.OAMAddr & 1)) + IPPU.OBJChanged = true; } else { @@ -2853,22 +2603,19 @@ void REGISTER_2122(uint8_t Byte) } PPU.CGADD++; } - else + else if (Byte != (uint8_t)(PPU.CGDATA[PPU.CGADD] & 0xff)) { - if (Byte != (uint8_t)(PPU.CGDATA[PPU.CGADD] & 0xff)) - { - FLUSH_REDRAW(); - PPU.CGDATA[PPU.CGADD] &= 0x7F00; - PPU.CGDATA[PPU.CGADD] |= Byte; - IPPU.ColorsChanged = true; - IPPU.Red [PPU.CGADD] = IPPU.XB [Byte & 0x1f]; - IPPU.Green [PPU.CGADD] = IPPU.XB [(PPU.CGDATA[PPU.CGADD] >> 5) & 0x1f]; - IPPU.ScreenColors [PPU.CGADD] = (uint16_t) BUILD_PIXEL(IPPU.Red [PPU.CGADD], - IPPU.Green [PPU.CGADD], - IPPU.Blue [PPU.CGADD]); - } + FLUSH_REDRAW(); + PPU.CGDATA[PPU.CGADD] &= 0x7F00; + PPU.CGDATA[PPU.CGADD] |= Byte; + IPPU.ColorsChanged = true; + IPPU.Red [PPU.CGADD] = IPPU.XB [Byte & 0x1f]; + IPPU.Green [PPU.CGADD] = IPPU.XB [(PPU.CGDATA[PPU.CGADD] >> 5) & 0x1f]; + IPPU.ScreenColors [PPU.CGADD] = (uint16_t) BUILD_PIXEL(IPPU.Red [PPU.CGADD], + IPPU.Green [PPU.CGADD], + IPPU.Blue [PPU.CGADD]); } - PPU.CGFLIP ^= 1; + PPU.CGFLIP = !PPU.CGFLIP; } void REGISTER_2180(uint8_t Byte) diff --git a/source/ppu.h b/source/ppu.h index 1a83d6f..5101f02 100644 --- a/source/ppu.h +++ b/source/ppu.h @@ -18,9 +18,9 @@ extern uint16_t SignExtend [2]; #define PPU_H_BEAM_IRQ_SOURCE (1 << 0) #define PPU_V_BEAM_IRQ_SOURCE (1 << 1) -#define GSU_IRQ_SOURCE (1 << 2) -#define SA1_IRQ_SOURCE (1 << 7) -#define SA1_DMA_IRQ_SOURCE (1 << 5) +#define GSU_IRQ_SOURCE (1 << 2) +#define SA1_DMA_IRQ_SOURCE (1 << 5) +#define SA1_IRQ_SOURCE (1 << 7) struct ClipData { @@ -31,26 +31,22 @@ struct ClipData typedef struct { - bool ColorsChanged; - uint8_t HDMA; - bool HDMAStarted; - uint8_t MaxBrightness; - bool LatchedBlanking; - bool OBJChanged; - bool RenderThisFrame; - bool DirectColourMapsNeedRebuild; - uint32_t FrameCount; - uint32_t RenderedFramesCount; - uint32_t DisplayedRenderedFrameCount; - uint32_t SkippedFrames; - uint32_t FrameSkip; - uint8_t* TileCache [3]; - uint8_t* TileCached [3]; -#ifdef CORRECT_VRAM_READS - uint16_t VRAMReadBuffer; -#else - bool FirstVRAMRead; -#endif + bool ColorsChanged; + uint8_t HDMA; + bool HDMAStarted; + uint8_t MaxBrightness; + bool LatchedBlanking; + bool OBJChanged; + bool RenderThisFrame; + bool DirectColourMapsNeedRebuild; + uint32_t FrameCount; + uint32_t RenderedFramesCount; + uint32_t DisplayedRenderedFrameCount; + uint32_t SkippedFrames; + uint32_t FrameSkip; + uint8_t* TileCache [3]; + uint8_t* TileCached [3]; + bool FirstVRAMRead; bool DoubleHeightPixels; bool Interlace; bool InterlaceSprites; @@ -176,7 +172,7 @@ typedef struct bool ClipWindow1Inside [6]; bool ClipWindow2Inside [6]; bool RecomputeClipWindows; - uint8_t CGFLIPRead; + bool CGFLIPRead; uint16_t OBJNameSelect; bool Need16x8Mulitply; uint8_t Joypad3ButtonReadPos; diff --git a/source/sa1.c b/source/sa1.c index f7324b5..54ed836 100644 --- a/source/sa1.c +++ b/source/sa1.c @@ -13,7 +13,7 @@ static void S9xSA1ReadVariableLengthData(bool inc, bool no_shift); void S9xSA1Init() { SA1.NMIActive = false; - SA1.IRQActive = false; + SA1.IRQActive = 0; SA1.WaitingForInterrupt = false; SA1.Waiting = false; SA1.Flags = 0; @@ -413,7 +413,7 @@ void S9xSetSA1(uint8_t byte, uint32_t address) break; case 0x2231: if (byte & 0x80) - SA1.in_char_dma = false; + SA1.in_char_dma = 0; break; case 0x2236: Memory.FillRAM [address] = byte; @@ -426,7 +426,7 @@ void S9xSetSA1(uint8_t byte, uint32_t address) Memory.FillRAM [0x2300] |= 0x20; if (Memory.FillRAM [0x2201] & 0x20) S9xSetIRQ(SA1_DMA_IRQ_SOURCE); - SA1.in_char_dma = true; + SA1.in_char_dma = 1; } return; case 0x2237: @@ -476,7 +476,7 @@ void S9xSetSA1(uint8_t byte, uint32_t address) SA1.sum = SA1.op1 << 16; else { - uint64_t x = (SA1.op1 / (uint16_t) SA1.op2); + uint32_t x = (SA1.op1 / (uint16_t) SA1.op2); SA1.sum = x | ((SA1.op1 - (x * (uint16_t) SA1.op2)) << 16); } break; @@ -614,8 +614,7 @@ void S9xSA1ReadVariableLengthData(bool inc, bool no_shift) addr += (s >> 4) << 1; s &= 15; } - uint32_t data = S9xSA1GetWord(addr) | - (S9xSA1GetWord(addr + 2) << 16); + uint32_t data = S9xSA1GetWord(addr) | (S9xSA1GetWord(addr + 2) << 16); data >>= s; Memory.FillRAM [0x230c] = (uint8_t) data; diff --git a/source/sa1.h b/source/sa1.h index 2b83eb3..6eb9935 100644 --- a/source/sa1.h +++ b/source/sa1.h @@ -51,7 +51,7 @@ typedef struct int64_t sum; bool overflow; uint8_t VirtualBitmapFormat; - bool in_char_dma; + uint8_t in_char_dma; uint8_t variable_bit_pos; SSA1Registers Registers; } SSA1; @@ -78,6 +78,7 @@ void S9xSA1SetPCBase(uint32_t); uint8_t S9xGetSA1(uint32_t); void S9xSetSA1(uint8_t, uint32_t); +extern SOpcodes S9xSA1OpcodesE1 [256]; extern SOpcodes S9xSA1OpcodesM1X1 [256]; extern SOpcodes S9xSA1OpcodesM1X0 [256]; extern SOpcodes S9xSA1OpcodesM0X1 [256]; @@ -92,7 +93,7 @@ void S9xFixSA1AfterSnapshotLoad(); #define TIMER_IRQ_SOURCE (1 << 6) #define DMA_IRQ_SOURCE (1 << 5) -static inline void S9xSA1UnpackStatus(void) +static inline void S9xSA1UnpackStatus() { SA1._Zero = (SA1.Registers.PL & Zero) == 0; SA1._Negative = (SA1.Registers.PL & Negative); @@ -100,17 +101,17 @@ static inline void S9xSA1UnpackStatus(void) SA1._Overflow = (SA1.Registers.PL & Overflow) >> 6; } -static inline void S9xSA1PackStatus(void) +static inline void S9xSA1PackStatus() { SA1.Registers.PL &= ~(Zero | Negative | Carry | Overflow); SA1.Registers.PL |= SA1._Carry | ((SA1._Zero == 0) << 1) | (SA1._Negative & 0x80) | (SA1._Overflow << 6); } -static inline void S9xSA1FixCycles(void) +static inline void S9xSA1FixCycles() { if (SA1CheckEmulation()) - SA1.S9xOpcodes = S9xSA1OpcodesM1X1; + SA1.S9xOpcodes = S9xSA1OpcodesE1; else if (SA1CheckMemory()) { if (SA1CheckIndex()) diff --git a/source/sa1cpu.c b/source/sa1cpu.c index 478df1e..272eb52 100644 --- a/source/sa1cpu.c +++ b/source/sa1cpu.c @@ -8,6 +8,7 @@ #include "sa1.h" #define CPU SA1 #define ICPU SA1 + #define S9xGetByte S9xSA1GetByte #define S9xGetWord S9xSA1GetWord #define S9xSetByte S9xSA1SetByte @@ -46,69 +47,6 @@ #define StackRelative SA1StackRelative #define StackRelativeIndirectIndexed SA1StackRelativeIndirectIndexed -#define SetZN16 SA1SetZN16 -#define SetZN8 SA1SetZN8 -#define ADC8 SA1ADC8 -#define ADC16 SA1ADC16 -#define AND16 SA1AND16 -#define AND8 SA1AND8 -#define A_ASL16 SA1A_ASL16 -#define A_ASL8 SA1A_ASL8 -#define ASL16 SA1ASL16 -#define ASL8 SA1ASL8 -#define BIT16 SA1BIT16 -#define BIT8 SA1BIT8 -#define CMP16 SA1CMP16 -#define CMP8 SA1CMP8 -#define CMX16 SA1CMX16 -#define CMX8 SA1CMX8 -#define CMY16 SA1CMY16 -#define CMY8 SA1CMY8 -#define A_DEC16 SA1A_DEC16 -#define A_DEC8 SA1A_DEC8 -#define DEC16 SA1DEC16 -#define DEC8 SA1DEC8 -#define EOR16 SA1EOR16 -#define EOR8 SA1EOR8 -#define A_INC16 SA1A_INC16 -#define A_INC8 SA1A_INC8 -#define INC16 SA1INC16 -#define INC8 SA1INC8 -#define LDA16 SA1LDA16 -#define LDA8 SA1LDA8 -#define LDX16 SA1LDX16 -#define LDX8 SA1LDX8 -#define LDY16 SA1LDY16 -#define LDY8 SA1LDY8 -#define A_LSR16 SA1A_LSR16 -#define A_LSR8 SA1A_LSR8 -#define LSR16 SA1LSR16 -#define LSR8 SA1LSR8 -#define ORA16 SA1ORA16 -#define ORA8 SA1ORA8 -#define A_ROL16 SA1A_ROL16 -#define A_ROL8 SA1A_ROL8 -#define ROL16 SA1ROL16 -#define ROL8 SA1ROL8 -#define A_ROR16 SA1A_ROR16 -#define A_ROR8 SA1A_ROR8 -#define ROR16 SA1ROR16 -#define ROR8 SA1ROR8 -#define SBC16 SA1SBC16 -#define SBC8 SA1SBC8 -#define STA16 SA1STA16 -#define STA8 SA1STA8 -#define STX16 SA1STX16 -#define STX8 SA1STX8 -#define STY16 SA1STY16 -#define STY8 SA1STY8 -#define STZ16 SA1STZ16 -#define STZ8 SA1STZ8 -#define TSB16 SA1TSB16 -#define TSB8 SA1TSB8 -#define TRB16 SA1TRB16 -#define TRB8 SA1TRB8 - #undef VAR_CYCLES #define SA1_OPCODES diff --git a/source/seta010.c b/source/seta010.c index 0e64248..89ae4f8 100644 --- a/source/seta010.c +++ b/source/seta010.c @@ -30,12 +30,6 @@ const int16_t ST010_M7Scale[176] = 0x002d, 0x002c, 0x002c, 0x002c, 0x002c, 0x002b, 0x002b, 0x002b }; -// H-DMA hack -bool seta_hack; - -//temporary Op04 requirement -#include <math.h> - ST010_Regs ST010; uint8_t S9xGetST010(uint32_t Address) @@ -52,23 +46,23 @@ uint8_t S9xGetST010(uint32_t Address) const int16_t ST010_SinTable[256] = { - 0x0000, 0x0324, 0x0648, 0x096a, 0x0c8c, 0x0fab, 0x12c8, 0x15e2, - 0x18f9, 0x1c0b, 0x1f1a, 0x2223, 0x2528, 0x2826, 0x2b1f, 0x2e11, - 0x30fb, 0x33df, 0x36ba, 0x398c, 0x3c56, 0x3f17, 0x41ce, 0x447a, - 0x471c, 0x49b4, 0x4c3f, 0x4ebf, 0x5133, 0x539b, 0x55f5, 0x5842, - 0x5a82, 0x5cb3, 0x5ed7, 0x60eb, 0x62f1, 0x64e8, 0x66cf, 0x68a6, - 0x6a6d, 0x6c23, 0x6dc9, 0x6f5e, 0x70e2, 0x7254, 0x73b5, 0x7504, - 0x7641, 0x776b, 0x7884, 0x7989, 0x7a7c, 0x7b5c, 0x7c29, 0x7ce3, - 0x7d89, 0x7e1d, 0x7e9c, 0x7f09, 0x7f61, 0x7fa6, 0x7fd8, 0x7ff5, - 0x7fff, 0x7ff5, 0x7fd8, 0x7fa6, 0x7f61, 0x7f09, 0x7e9c, 0x7e1d, - 0x7d89, 0x7ce3, 0x7c29, 0x7b5c, 0x7a7c, 0x7989, 0x7884, 0x776b, - 0x7641, 0x7504, 0x73b5, 0x7254, 0x70e2, 0x6f5e, 0x6dc9, 0x6c23, - 0x6a6d, 0x68a6, 0x66cf, 0x64e8, 0x62f1, 0x60eb, 0x5ed7, 0x5cb3, - 0x5a82, 0x5842, 0x55f5, 0x539b, 0x5133, 0x4ebf, 0x4c3f, 0x49b4, - 0x471c, 0x447a, 0x41ce, 0x3f17, 0x3c56, 0x398c, 0x36ba, 0x33df, - 0x30fb, 0x2e11, 0x2b1f, 0x2826, 0x2528, 0x2223, 0x1f1a, 0x1c0b, - 0x18f8, 0x15e2, 0x12c8, 0x0fab, 0x0c8c, 0x096a, 0x0648, 0x0324, - 0x0000, -0x0324, -0x0648, -0x096b, -0x0c8c, -0x0fab, -0x12c8, -0x15e2, + 0x0000, 0x0324, 0x0648, 0x096a, 0x0c8c, 0x0fab, 0x12c8, 0x15e2, + 0x18f9, 0x1c0b, 0x1f1a, 0x2223, 0x2528, 0x2826, 0x2b1f, 0x2e11, + 0x30fb, 0x33df, 0x36ba, 0x398c, 0x3c56, 0x3f17, 0x41ce, 0x447a, + 0x471c, 0x49b4, 0x4c3f, 0x4ebf, 0x5133, 0x539b, 0x55f5, 0x5842, + 0x5a82, 0x5cb3, 0x5ed7, 0x60eb, 0x62f1, 0x64e8, 0x66cf, 0x68a6, + 0x6a6d, 0x6c23, 0x6dc9, 0x6f5e, 0x70e2, 0x7254, 0x73b5, 0x7504, + 0x7641, 0x776b, 0x7884, 0x7989, 0x7a7c, 0x7b5c, 0x7c29, 0x7ce3, + 0x7d89, 0x7e1d, 0x7e9c, 0x7f09, 0x7f61, 0x7fa6, 0x7fd8, 0x7ff5, + 0x7fff, 0x7ff5, 0x7fd8, 0x7fa6, 0x7f61, 0x7f09, 0x7e9c, 0x7e1d, + 0x7d89, 0x7ce3, 0x7c29, 0x7b5c, 0x7a7c, 0x7989, 0x7884, 0x776b, + 0x7641, 0x7504, 0x73b5, 0x7254, 0x70e2, 0x6f5e, 0x6dc9, 0x6c23, + 0x6a6d, 0x68a6, 0x66cf, 0x64e8, 0x62f1, 0x60eb, 0x5ed7, 0x5cb3, + 0x5a82, 0x5842, 0x55f5, 0x539b, 0x5133, 0x4ebf, 0x4c3f, 0x49b4, + 0x471c, 0x447a, 0x41ce, 0x3f17, 0x3c56, 0x398c, 0x36ba, 0x33df, + 0x30fb, 0x2e11, 0x2b1f, 0x2826, 0x2528, 0x2223, 0x1f1a, 0x1c0b, + 0x18f8, 0x15e2, 0x12c8, 0x0fab, 0x0c8c, 0x096a, 0x0648, 0x0324, + 0x0000, -0x0324, -0x0648, -0x096b, -0x0c8c, -0x0fab, -0x12c8, -0x15e2, -0x18f9, -0x1c0b, -0x1f1a, -0x2223, -0x2528, -0x2826, -0x2b1f, -0x2e11, -0x30fb, -0x33df, -0x36ba, -0x398d, -0x3c56, -0x3f17, -0x41ce, -0x447a, -0x471c, -0x49b4, -0x4c3f, -0x4ebf, -0x5133, -0x539b, -0x55f5, -0x5842, @@ -228,8 +222,7 @@ int16_t ST010_Cos(int16_t Theta) return ST010_SinTable[((Theta + 0x4000) >> 8) & 0xff]; } -void ST010_OP01(int16_t x0, int16_t y0, int16_t* x1, int16_t* y1, int16_t* Quadrant, - int16_t* Theta) +void ST010_OP01(int16_t x0, int16_t y0, int16_t* x1, int16_t* y1, int16_t* Quadrant, int16_t* Theta) { if ((x0 < 0) && (y0 < 0)) { @@ -258,8 +251,10 @@ void ST010_OP01(int16_t x0, int16_t y0, int16_t* x1, int16_t* y1, int16_t* Quadr while ((*x1 > 0x1f) || (*y1 > 0x1f)) { - if (*x1 > 1) *x1 >>= 1; - if (*y1 > 1) *y1 >>= 1; + if (*x1 > 1) + *x1 >>= 1; + if (*y1 > 1) + *y1 >>= 1; } if (*y1 == 0) *Quadrant += 0x4000; @@ -346,8 +341,7 @@ void S9xSetST010(uint32_t Address, uint8_t Byte) { #if defined(FAST_LSB_WORD_ACCESS) && !defined(ANDROID) /* TODO - FIXME */ - ST010_SortDrivers(*(int16_t*)&Memory.SRAM[0x0024], (uint16_t*)(Memory.SRAM + 0x0040), - (uint16_t*)(Memory.SRAM + 0x0080)); + ST010_SortDrivers(*(int16_t*)&Memory.SRAM[0x0024], (uint16_t*)(Memory.SRAM + 0x0040), (uint16_t*)(Memory.SRAM + 0x0080)); #else uint16_t Places[32]; uint16_t Positions = ST010_WORD(0x0024); @@ -391,13 +385,11 @@ void S9xSetST010(uint32_t Address, uint8_t Byte) #if defined(FAST_LSB_WORD_ACCESS) && !defined(ANDROID) /* TODO - FIXME */ ST010_Scale(*(int16_t*)&Memory.SRAM[0x0004], *(int16_t*)&Memory.SRAM[0x0000], - *(int16_t*)&Memory.SRAM[0x0002], - (int32_t*)&Memory.SRAM[0x0010], (int32_t*)&Memory.SRAM[0x0014]); + *(int16_t*)&Memory.SRAM[0x0002], (int32_t*)&Memory.SRAM[0x0010], (int32_t*)&Memory.SRAM[0x0014]); #else int32_t x1, y1; - ST010_Scale(ST010_WORD(0x0004), ST010_WORD(0x0000), ST010_WORD(0x0002), &x1, - &y1); + ST010_Scale(ST010_WORD(0x0004), ST010_WORD(0x0000), ST010_WORD(0x0002), &x1, &y1); Memory.SRAM[0x0010] = (uint8_t)(x1); Memory.SRAM[0x0011] = (uint8_t)(x1 >> 8); @@ -423,8 +415,7 @@ void S9xSetST010(uint32_t Address, uint8_t Byte) { #if defined(FAST_LSB_WORD_ACCESS) && !defined(ANDROID) /* TODO - FIXME */ - ST010_Multiply(*(int16_t*)&Memory.SRAM[0x0000], *(int16_t*)&Memory.SRAM[0x0002], - (int32_t*)&Memory.SRAM[0x0010]); + ST010_Multiply(*(int16_t*)&Memory.SRAM[0x0000], *(int16_t*)&Memory.SRAM[0x0002], (int32_t*)&Memory.SRAM[0x0010]); #else int32_t Product; @@ -501,13 +492,11 @@ void S9xSetST010(uint32_t Address, uint8_t Byte) #if defined(FAST_LSB_WORD_ACCESS) && !defined(ANDROID) /* TODO - FIXME */ ST010_Rotate(*(int16_t*)&Memory.SRAM[0x0004], *(int16_t*)&Memory.SRAM[0x0000], - *(int16_t*)&Memory.SRAM[0x0002], - (int16_t*)&Memory.SRAM[0x0010], (int16_t*)&Memory.SRAM[0x0012]); + *(int16_t*)&Memory.SRAM[0x0002], (int16_t*)&Memory.SRAM[0x0010], (int16_t*)&Memory.SRAM[0x0012]); #else int16_t x1, y1; - ST010_Rotate(ST010_WORD(0x0004), ST010_WORD(0x0000), ST010_WORD(0x0002), &x1, - &y1); + ST010_Rotate(ST010_WORD(0x0004), ST010_WORD(0x0000), ST010_WORD(0x0002), &x1, &y1); Memory.SRAM[0x0010] = (uint8_t)(x1); Memory.SRAM[0x0011] = (uint8_t)(x1 >> 8); @@ -562,7 +551,7 @@ void S9xSetST010(uint32_t Address, uint8_t Byte) x = Memory.SRAM[0] | (Memory.SRAM[1] << 8); y = Memory.SRAM[2] | (Memory.SRAM[3] << 8); #endif - square = (int16_t)sqrt((double)(y * y + x * x)); + square = (int16_t)_isqrt((int32_t) x * x + (int32_t) y * y); #if defined(FAST_LSB_WORD_ACCESS) && !defined(ANDROID) /* TODO - FIXME */ @@ -624,7 +613,7 @@ void S9xSetST010(uint32_t Address, uint8_t Byte) ST010_OP01(dy, dx, &a1, &b1, &c1, (int16_t*)&o1); // check for wrapping - if (abs(o1 - rot) > 0x8000) + if (ABS(o1 - rot) > 0x8000) { o1 += 0x8000; rot += 0x8000; @@ -636,12 +625,12 @@ void S9xSetST010(uint32_t Address, uint8_t Byte) old_speed = speed; // special case - if (abs(o1 - rot) == 0x8000) + if (ABS(o1 - rot) == 0x8000) speed = 0x100; // slow down for sharp curves - else if (abs(o1 - rot) >= 0x1000) + else if (ABS(o1 - rot) >= 0x1000) { - uint32_t slow = abs(o1 - rot); + uint32_t slow = ABS(o1 - rot); slow >>= 4; // scaling speed -= slow; } @@ -657,7 +646,7 @@ void S9xSetST010(uint32_t Address, uint8_t Byte) } // prevent negative/positive overflow - if (abs(old_speed - speed) > 0x8000) + if (ABS(old_speed - speed) > 0x8000) { if (old_speed < speed) speed = 0; else speed = 0xff00; @@ -717,13 +706,8 @@ void S9xSetST010(uint32_t Address, uint8_t Byte) Memory.SRAM[0x00D5] = (uint8_t)(speed >> 8); Memory.SRAM[0x00DC] = (uint8_t)(flags); Memory.SRAM[0x00DD] = (uint8_t)(flags >> 8); - break; } - - default: - printf("Unknown Op\n"); - break; } // lower signal: op processed diff --git a/source/seta011.c b/source/seta011.c index 26a0f54..a005f98 100644 --- a/source/seta011.c +++ b/source/seta011.c @@ -66,17 +66,9 @@ void S9xSetST011(uint32_t Address, uint8_t Byte) ST011.in_count = 4; break; case 0x04: - ST011.in_count = 0; - break; case 0x05: - ST011.in_count = 0; - break; case 0x06: - ST011.in_count = 0; - break; case 0x07: - ST011.in_count = 0; - break; case 0x0E: ST011.in_count = 0; break; @@ -107,13 +99,11 @@ void S9xSetST011(uint32_t Address, uint8_t Byte) int32_t lcv; for (lcv = 0; lcv < 9; lcv++) memcpy(board[lcv], ST011.parameters + lcv * 10, 9 * 1); + break; } - break; - // unknown case 0x02: break; - // unknown case 0x04: case 0x05: @@ -121,14 +111,12 @@ void S9xSetST011(uint32_t Address, uint8_t Byte) // outputs Memory.SRAM[0x12C] = 0x00; Memory.SRAM[0x12E] = 0x00; + break; } - break; - // unknown case 0x06: case 0x07: break; - // unknown case 0x0E: { diff --git a/source/seta018.c b/source/seta018.c index 00702d1..840e479 100644 --- a/source/seta018.c +++ b/source/seta018.c @@ -32,8 +32,6 @@ uint8_t S9xGetST018(uint32_t Address) else if (address == 0x3800) t = ST018.status; - printf("ST018 R: %06X %02X\n", Address, t); - return t; } @@ -41,9 +39,6 @@ void S9xSetST018(uint8_t Byte, uint32_t Address) { uint16_t address = (uint16_t) Address & 0xFFFF; static bool reset = false; - - printf("ST018 W: %06X %02X\n", Address, Byte); - line++; if (!reset) @@ -75,8 +70,6 @@ void S9xSetST018(uint8_t Byte, uint32_t Address) switch (ST018.command & 0xFFFFFF) { case 0x0100: - ST018.in_count = 0; - break; case 0xFF00: ST018.in_count = 0; break; diff --git a/source/snes9x.h b/source/snes9x.h index 1051af4..9d7019c 100644 --- a/source/snes9x.h +++ b/source/snes9x.h @@ -9,11 +9,8 @@ #include <libretro.h> -extern int cprintf(const char* fmt, ...); - #include "port.h" #include "65c816.h" -#include "messages.h" #define ROM_NAME_LEN 23 @@ -196,18 +193,19 @@ typedef struct bool SRTC; uint32_t ControllerOption; - bool ShutdownMaster; - bool MultiPlayer5Master; - bool SuperScopeMaster; - bool MouseMaster; - bool SuperFX; - bool DSP1Master; - bool SA1; - bool C4; - bool SDD1; - bool SPC7110; - bool SPC7110RTC; - bool OBC1; + bool ShutdownMaster; + bool MultiPlayer5Master; + bool SuperScopeMaster; + bool MouseMaster; + bool SuperFX; + bool DSP1Master; + bool SA1; + bool C4; + bool SDD1; + bool SPC7110; + bool SPC7110RTC; + bool OBC1; + uint8_t DSP; /* Sound options */ uint32_t SoundPlaybackRate; #ifdef USE_BLARGG_APU @@ -247,7 +245,6 @@ typedef struct bool StarfoxHack; bool WinterGold; bool BS; /* Japanese Satellite System games. */ - bool DaffyDuck; uint8_t APURAMInitialValue; bool SampleCatchup; bool JustifierMaster; @@ -265,11 +262,9 @@ typedef struct typedef struct { - uint8_t alienVSpredetorFix; uint8_t APU_OutPorts_ReturnValueFix; uint8_t SoundEnvelopeHeightReading2; uint8_t SRAMInitialValue; - uint8_t Uniracers; bool EchoOnlyOutput; } SSNESGameFixes; @@ -278,7 +273,7 @@ extern SCPUState CPU; extern SSNESGameFixes SNESGameFixes; extern char String [513]; -void S9xMessage(int32_t type, int32_t number, const char* message); +void S9xMessage(const char* message); void S9xSetPause(uint32_t mask); void S9xClearPause(uint32_t mask); diff --git a/source/soundux.c b/source/soundux.c index 237392e..9a2839e 100644 --- a/source/soundux.c +++ b/source/soundux.c @@ -381,8 +381,8 @@ void DecodeBlock(Channel* ch) int8_t* compressed = (int8_t*) &IAPU.RAM [ch->block_pointer]; filter = *compressed; - if ((ch->last_block = filter & 1)) - ch->loop = (filter & 2) != 0; + if ((ch->last_block = (bool) (filter & 1))) + ch->loop = (bool) (filter & 2); int16_t* raw = ch->block = ch->decoded; uint32_t i; @@ -480,7 +480,7 @@ static inline void MixStereo(int32_t sample_count) int32_t VL, VR; uint32_t freq0 = ch->frequency; - bool mod = pitch_mod & (1 << J); + uint8_t mod = pitch_mod & (1 << J); if (ch->needs_decode) { @@ -497,8 +497,7 @@ static inline void MixStereo(int32_t sample_count) ch->interpolate = 0; if (Settings.InterpolatedSound && freq0 < FIXED_POINT && !mod) - ch->interpolate = ((ch->next_sample - ch->sample) * - (int32_t) freq0) / (int32_t) FIXED_POINT; + ch->interpolate = ((ch->next_sample - ch->sample) * (int32_t) freq0) / (int32_t) FIXED_POINT; } VL = (ch->sample * ch-> left_vol_level) / 128; VR = (ch->sample * ch->right_vol_level) / 128; @@ -702,10 +701,8 @@ static inline void MixStereo(int32_t sample_count) { if (Settings.InterpolatedSound && freq < FIXED_POINT && !mod) { - ch->interpolate = ((ch->next_sample - ch->sample) * - (int32_t) freq) / (int32_t) FIXED_POINT; - ch->sample = (int16_t)(ch->sample + (((ch->next_sample - ch->sample) * - (int32_t)(ch->count)) / (int32_t) FIXED_POINT)); + ch->interpolate = ((ch->next_sample - ch->sample) * (int32_t) freq) / (int32_t) FIXED_POINT; + ch->sample = (int16_t)(ch->sample + (((ch->next_sample - ch->sample) * (int32_t)(ch->count)) / (int32_t) FIXED_POINT)); } else ch->interpolate = 0; @@ -931,7 +928,7 @@ bool S9xInitSound() { so.playback_rate = 0; S9xResetSound(true); - return (1); + return true; } bool S9xSetSoundMode(int32_t channel, int32_t mode) @@ -944,7 +941,7 @@ bool S9xSetSoundMode(int32_t channel, int32_t mode) if (ch->mode != MODE_NONE) { ch->mode = MODE_RELEASE; - return (true); + return true; } break; case MODE_DECREASE_LINEAR: @@ -957,18 +954,18 @@ bool S9xSetSoundMode(int32_t channel, int32_t mode) ch->mode = mode; if (ch->state != SOUND_SILENT) ch->state = mode; - return (true); + return true; } break; case MODE_ADSR: if (ch->mode == MODE_NONE || ch->mode == MODE_ADSR) { ch->mode = mode; - return (true); + return true; } } - return (false); + return false; } void S9xPlaySample(int32_t channel) diff --git a/source/spc700.c b/source/spc700.c index 7b1a8b7..517f606 100644 --- a/source/spc700.c +++ b/source/spc700.c @@ -2465,7 +2465,7 @@ void ApuFB() #include "apumem.h" #endif -void (*S9xApuOpcodes[256])(void) = +void (*S9xApuOpcodes[256])() = { Apu00, Apu01, Apu02, Apu03, Apu04, Apu05, Apu06, Apu07, Apu08, Apu09, Apu0A, Apu0B, Apu0C, Apu0D, Apu0E, Apu0F, diff --git a/source/spc700.h b/source/spc700.h index f1d7046..cbe6637 100644 --- a/source/spc700.h +++ b/source/spc700.h @@ -49,17 +49,14 @@ typedef union { -#ifdef MSB_FIRST struct { +#ifdef MSB_FIRST uint8_t Y, A; - } B; #else - struct - { uint8_t A, Y; - } B; #endif + } B; uint16_t W; } YAndA; @@ -76,11 +73,6 @@ typedef struct // Needed by ILLUSION OF GAIA #define ONE_APU_CYCLE 21 -// Needed by all games written by the software company called Human -#define ONE_APU_CYCLE_HUMAN 21 - -// 1.953us := 1.024065.54MHz - #ifdef SPCTOOL int32_t ESPC(int32_t); @@ -105,8 +97,8 @@ int32_t ESPC(int32_t); #define APU_EXECUTE() \ if (IAPU.APUExecuting) \ {\ - while (APU.Cycles <= CPU.Cycles) \ - APU_EXECUTE1(); \ + while (APU.Cycles <= CPU.Cycles) \ + APU_EXECUTE1(); \ } #endif diff --git a/source/spc7110.c b/source/spc7110.c index 1c87809..ffaf35f 100644 --- a/source/spc7110.c +++ b/source/spc7110.c @@ -40,9 +40,9 @@ char* osd_GetPackDir(); uint16_t cacheMegs = 5; //using function pointers to initialize cache management -void (*CleanUp7110)(void) = NULL; +void (*CleanUp7110)() = NULL; void (*LoadUp7110)(char*) = &SPC7110Load; -void (*Copy7110)(void) = NULL; +void (*Copy7110)() = NULL; //size and offset of the pack data //offset and size of reads from pack @@ -143,8 +143,7 @@ void S9xSpc7110Init() void MovePackData() { //log the last entry - Data7110* log = & - (decompack->tableEnts[decompack->idx].location[decompack->last_idx]); + Data7110* log = &(decompack->tableEnts[decompack->idx].location[decompack->last_idx]); if ((log->used_len + log->used_offset) < (decompack->last_offset + (uint16_t)s7r.bank50Internal)) { @@ -238,11 +237,9 @@ void ReadPackData() return; } - if (table_age_2 == 0 && table_age_3 == 0 && table_age_4 == 0 - && table_age_5 == 0) + if (table_age_2 == 0 && table_age_3 == 0 && table_age_4 == 0 && table_age_5 == 0) table_age_2 = table_age_3 = table_age_4 = table_age_5 = MAX_TABLES; - Data7110* log = & - (decompack->tableEnts[decompack->idx].location[decompack->last_idx]); + Data7110* log = &(decompack->tableEnts[decompack->idx].location[decompack->last_idx]); if ((log->used_len + log->used_offset) < (decompack->last_offset + (uint16_t)s7r.bank50Internal)) { @@ -292,8 +289,7 @@ void ReadPackData() fclose(fp); return; } - if (i != table_age_2 && i != table_age_3 && i != table_age_4 - && i != table_age_5) + if (i != table_age_2 && i != table_age_3 && i != table_age_4 && i != table_age_5) { if (table_age_5 != MAX_TABLES && decompack->binfiles[table_age_5]) { @@ -511,7 +507,6 @@ uint8_t S9xGetSPC7110(uint16_t Address) case 0x480C: s7r.reg480C ^= 0x80; return s7r.reg480C ^ 0x80; - //Data access port //reads from the data ROM (anywhere over the first 8 mbits //behavior is complex, will document later, @@ -764,7 +759,6 @@ uint8_t S9xGetSPC7110(uint16_t Address) //divisor high case 0x4827: return s7r.reg4827; - //result lowest case 0x4828: return s7r.reg4828; @@ -1125,11 +1119,9 @@ void S9xSetSPC7110(uint8_t data, uint16_t Address) } else { - uint32_t mul; uint16_t m1 = (uint16_t)((s7r.reg4824) | (s7r.reg4825 << 8)); uint16_t m2 = (uint16_t)((s7r.reg4820) | (s7r.reg4821 << 8)); - - mul = m1 * m2; + uint32_t mul = m1 * m2; s7r.reg4828 = (uint8_t)(mul & 0x000000FF); s7r.reg4829 = (uint8_t)((mul & 0x0000FF00) >> 8); s7r.reg482A = (uint8_t)((mul & 0x00FF0000) >> 16); @@ -1403,8 +1395,7 @@ void S9xUpdateRTC() // Keep track of game time by computing the number of seconds that pass on the system // clock and adding the same number of seconds to the RTC clock structure. - if (rtc_f9.init && 0 == (rtc_f9.reg[0x0D] & 0x01) - && 0 == (rtc_f9.reg[0x0F] & 0x03)) + if (rtc_f9.init && 0 == (rtc_f9.reg[0x0D] & 0x01) && 0 == (rtc_f9.reg[0x0F] & 0x03)) { cur_systime = time(NULL); @@ -1583,7 +1574,6 @@ bool Load7110Index(char* filename) decompack->tableEnts[i].location[index].size = size; decompack->tableEnts[i].location[index].used_len = 0; decompack->tableEnts[i].location[index].used_offset = 0; - } fclose(fp); return true; @@ -1604,8 +1594,7 @@ void SPC7110Load(char* dirname) memset(decompack, 0, sizeof(Pack7110)); #if !defined(_XBOX) && !defined(VITA) - if (-1 == chdir(dirname)) - S9xMessage(0, 0, "Graphics Pack not found!"); + chdir(dirname); #endif #ifndef _XBOX @@ -1661,8 +1650,7 @@ void SPC7110Open(char* dirname) memset(decompack, 0, sizeof(Pack7110)); #if !defined(_XBOX) && !defined(VITA) - if (-1 == chdir(dirname)) - S9xMessage(0, 0, "Graphics Pack not found!"); + chdir(dirname); #endif #ifndef _XBOX @@ -1701,9 +1689,7 @@ void SPC7110Grab(char* dirname) memset(decompack, 0, sizeof(Pack7110)); #if !defined(_XBOX) && !defined(VITA) - - if (-1 == chdir(dirname)) - S9xMessage(0, 0, "Graphics Pack not found!"); + chdir(dirname); #endif #ifndef _XBOX diff --git a/source/spc7110.h b/source/spc7110.h index 06a594a..351f29d 100644 --- a/source/spc7110.h +++ b/source/spc7110.h @@ -7,14 +7,14 @@ #define DECOMP_BUFFER_SIZE 0x10000 extern void (*LoadUp7110)(char*); -extern void (*CleanUp7110)(void); -extern void (*Copy7110)(void); +extern void (*CleanUp7110)(); +extern void (*Copy7110)(); extern uint16_t cacheMegs; -void Del7110Gfx(void); -void Close7110Gfx(void); -void Drop7110Gfx(void); +void Del7110Gfx(); +void Close7110Gfx(); +void Drop7110Gfx(); uint8_t S9xGetSPC7110(uint16_t Address); uint8_t S9xGetSPC7110Byte(uint32_t Address); uint8_t* Get7110BasePtr(uint32_t); diff --git a/source/srtc.c b/source/srtc.c index 78cb4a7..bbc05ee 100644 --- a/source/srtc.c +++ b/source/srtc.c @@ -285,7 +285,6 @@ void S9xUpdateSrtcTime() /**********************************************************************************************/ void S9xSetSRTC(uint8_t data, uint16_t Address) { - data &= 0x0F; // Data is only 4-bits, mask out unused bits. if (data >= 0xD) @@ -353,7 +352,6 @@ void S9xSetSRTC(uint8_t data, uint16_t Address) rtc.index = -1; rtc.mode = MODE_COMMAND_DONE; break; - case COMMAND_LOAD_RTC: // Disable RTC counter rtc.count_enable = false; @@ -361,7 +359,6 @@ void S9xSetSRTC(uint8_t data, uint16_t Address) rtc.index = 0; // Setup for writing rtc.mode = MODE_LOAD_RTC; break; - default: rtc.mode = MODE_COMMAND_DONE; // unrecognized command - need to implement. diff --git a/source/tile.c b/source/tile.c index ba3a1a7..43bcecb 100644 --- a/source/tile.c +++ b/source/tile.c @@ -17,16 +17,16 @@ static uint8_t ConvertTile(uint8_t* pCache, uint32_t TileAddr) uint32_t* p = (uint32_t*) pCache; uint32_t non_zero = 0; uint8_t line; + uint32_t p1; + uint32_t p2; + uint8_t pix; switch (BG.BitShift) { case 8: for (line = 8; line != 0; line--, tp += 2) { - uint32_t p1 = 0; - uint32_t p2 = 0; - uint8_t pix; - + p1 = p2 = 0; if ((pix = *(tp + 0))) { p1 |= odd_high[0][pix >> 4]; @@ -76,9 +76,7 @@ static uint8_t ConvertTile(uint8_t* pCache, uint32_t TileAddr) case 4: for (line = 8; line != 0; line--, tp += 2) { - uint32_t p1 = 0; - uint32_t p2 = 0; - uint8_t pix; + p1 = p2 = 0; if ((pix = *(tp + 0))) { p1 |= odd_high[0][pix >> 4]; @@ -108,9 +106,7 @@ static uint8_t ConvertTile(uint8_t* pCache, uint32_t TileAddr) case 2: for (line = 8; line != 0; line--, tp += 2) { - uint32_t p1 = 0; - uint32_t p2 = 0; - uint8_t pix; + p1 = p2 = 0; if ((pix = *(tp + 0))) { p1 |= odd_high[0][pix >> 4]; |