2 * Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
4 * (c) Copyright 1996 - 2001 Gary Henderson (gary.henderson@ntlworld.com) and
5 * Jerremy Koot (jkoot@snes9x.com)
7 * Super FX C emulator code
8 * (c) Copyright 1997 - 1999 Ivar (ivar@snes9x.com) and
10 * Super FX assembler emulator code (c) Copyright 1998 zsKnight and _Demo_.
12 * DSP1 emulator code (c) Copyright 1998 Ivar, _Demo_ and Gary Henderson.
13 * C4 asm and some C emulation code (c) Copyright 2000 zsKnight and _Demo_.
14 * C4 C code (c) Copyright 2001 Gary Henderson (gary.henderson@ntlworld.com).
16 * DOS port code contains the works of other authors. See headers in
19 * Snes9x homepage: http://www.snes9x.com
21 * Permission to use, copy, modify and distribute Snes9x in both binary and
22 * source form, for non-commercial purposes, is hereby granted without fee,
23 * providing that this license information and copyright notice appear with
24 * all copies and any derived work.
26 * This software is provided 'as-is', without any express or implied
27 * warranty. In no event shall the authors be held liable for any damages
28 * arising from the use of this software.
30 * Snes9x is freeware for PERSONAL USE only. Commercial users should
31 * seek permission of the copyright holders first. Commercial use includes
32 * charging money for Snes9x or software derived from Snes9x.
34 * The copyright holders request that bug fixes and improvements to the code
35 * should be forwarded to them so everyone can benefit from the modifications
38 * Super NES and Super Nintendo Entertainment System are trademarks of
39 * Nintendo Co., Limited and its subsidiary companies.
44 //EXTERN_C long OpAddress;
46 STATIC INLINE long FASTCALL Immediate8 (struct SRegisters * reg, struct SICPU * icpu, struct SCPUState * cpu)
48 long OpAddress = icpu->ShiftedPB + cpu->PC - cpu->PCBase;
53 STATIC INLINE long FASTCALL Immediate16 (struct SRegisters * reg, struct SICPU * icpu, struct SCPUState * cpu)
55 long OpAddress = icpu->ShiftedPB + cpu->PC - cpu->PCBase;
60 STATIC INLINE long FASTCALL Relative (struct SRegisters * reg, struct SICPU * icpu, struct SCPUState * cpu)
62 int8 Int8 = *cpu->PC++;
64 cpu->Cycles += cpu->MemSpeed;
66 return ((int) (cpu->PC - cpu->PCBase) + Int8) & 0xffff;
69 STATIC INLINE long FASTCALL RelativeLong (struct SRegisters * reg, struct SICPU * icpu, struct SCPUState * cpu)
71 #ifdef FAST_LSB_WORD_ACCESS
72 long OpAddress = *(uint16 *) cpu->PC;
74 long OpAddress = *cpu->PC + (*(cpu->PC + 1) << 8);
77 cpu->Cycles += cpu->MemSpeedx2 + ONE_CYCLE;
80 OpAddress += (cpu->PC - cpu->PCBase);
85 STATIC INLINE long FASTCALL AbsoluteIndexedIndirect (struct SRegisters * reg, struct SICPU * icpu, struct SCPUState * cpu)
87 #ifdef FAST_LSB_WORD_ACCESS
88 long OpAddress = (reg->X.W + *(uint16 *) cpu->PC) & 0xffff;
90 long OpAddress = (reg->X.W + *cpu->PC + (*(cpu->PC + 1) << 8)) & 0xffff;
93 cpu->Cycles += cpu->MemSpeedx2;
96 return S9xGetWord (icpu->ShiftedPB + OpAddress, cpu);
99 STATIC INLINE long FASTCALL AbsoluteIndirectLong (struct SRegisters * reg, struct SICPU * icpu, struct SCPUState * cpu)
101 #ifdef FAST_LSB_WORD_ACCESS
102 long OpAddress = *(uint16 *) cpu->PC;
104 long OpAddress = *cpu->PC + (*(cpu->PC + 1) << 8);
108 cpu->Cycles += cpu->MemSpeedx2;
111 return S9xGetWord (OpAddress, cpu) | (S9xGetByte (OpAddress + 2, cpu) << 16);
114 STATIC INLINE long FASTCALL AbsoluteIndirect (struct SRegisters * reg, struct SICPU * icpu, struct SCPUState * cpu)
116 #ifdef FAST_LSB_WORD_ACCESS
117 long OpAddress = *(uint16 *) cpu->PC;
119 long OpAddress = *cpu->PC + (*(cpu->PC + 1) << 8);
123 cpu->Cycles += cpu->MemSpeedx2;
126 return S9xGetWord (OpAddress, cpu) + icpu->ShiftedPB;
129 STATIC INLINE long FASTCALL Absolute (struct SRegisters * reg, struct SICPU * icpu, struct SCPUState * cpu)
131 #ifdef FAST_LSB_WORD_ACCESS
132 long OpAddress = *(uint16 *) cpu->PC + icpu->ShiftedDB;
134 long OpAddress = *cpu->PC + (*(cpu->PC + 1) << 8) + icpu->ShiftedDB;
138 cpu->Cycles += cpu->MemSpeedx2;
143 STATIC INLINE long FASTCALL AbsoluteLong (struct SRegisters * reg, struct SICPU * icpu, struct SCPUState * cpu)
145 #ifdef FAST_LSB_WORD_ACCESS
146 long OpAddress = (*(uint32 *) cpu->PC) & 0xffffff;
148 long OpAddress = *cpu->PC + (*(cpu->PC + 1) << 8) + (*(cpu->PC + 2) << 16);
152 cpu->Cycles += cpu->MemSpeedx2 + cpu->MemSpeed;
157 STATIC INLINE long FASTCALL Direct(struct SRegisters * reg, struct SICPU * icpu, struct SCPUState * cpu)
159 long OpAddress = (*cpu->PC++ + reg->D.W) & 0xffff;
161 cpu->Cycles += cpu->MemSpeed;
163 // if (reg->DL != 0) cpu->Cycles += ONE_CYCLE;
167 STATIC INLINE long FASTCALL DirectIndirectIndexed (struct SRegisters * reg, struct SICPU * icpu, struct SCPUState * cpu)
169 long OpAddress = (*cpu->PC++ + reg->D.W) & 0xffff;
171 cpu->Cycles += cpu->MemSpeed;
174 OpAddress = icpu->ShiftedDB + S9xGetWord (OpAddress, cpu) + reg->Y.W;
176 // if (reg->DL != 0) cpu->Cycles += ONE_CYCLE;
177 // XXX: always add one if STA
178 // XXX: else Add one cycle if crosses page boundary
182 STATIC INLINE long FASTCALL DirectIndirectIndexedLong (struct SRegisters * reg, struct SICPU * icpu, struct SCPUState * cpu)
184 long OpAddress = (*cpu->PC++ + reg->D.W) & 0xffff;
186 cpu->Cycles += cpu->MemSpeed;
189 OpAddress = S9xGetWord (OpAddress, cpu) + (S9xGetByte (OpAddress + 2, cpu) << 16) +
191 // if (reg->DL != 0) cpu->Cycles += ONE_CYCLE;
195 STATIC INLINE long FASTCALL DirectIndexedIndirect(struct SRegisters * reg, struct SICPU * icpu, struct SCPUState * cpu)
197 long OpAddress = (*cpu->PC++ + reg->D.W + reg->X.W) & 0xffff;
199 cpu->Cycles += cpu->MemSpeed;
202 OpAddress = S9xGetWord (OpAddress, cpu) + icpu->ShiftedDB;
206 // cpu->Cycles += TWO_CYCLES;
208 cpu->Cycles += ONE_CYCLE;
213 STATIC INLINE long FASTCALL DirectIndexedX (struct SRegisters * reg, struct SICPU * icpu, struct SCPUState * cpu)
215 long OpAddress = (*cpu->PC++ + reg->D.W + reg->X.W) & 0xffff;
217 cpu->Cycles += cpu->MemSpeed;
222 // cpu->Cycles += TWO_CYCLES;
224 cpu->Cycles += ONE_CYCLE;
229 STATIC INLINE long FASTCALL DirectIndexedY (struct SRegisters * reg, struct SICPU * icpu, struct SCPUState * cpu)
231 long OpAddress = (*cpu->PC++ + reg->D.W + reg->Y.W) & 0xffff;
233 cpu->Cycles += cpu->MemSpeed;
238 // cpu->Cycles += TWO_CYCLES;
240 cpu->Cycles += ONE_CYCLE;
245 STATIC INLINE long FASTCALL AbsoluteIndexedX (struct SRegisters * reg, struct SICPU * icpu, struct SCPUState * cpu)
247 #ifdef FAST_LSB_WORD_ACCESS
248 long OpAddress = icpu->ShiftedDB + *(uint16 *) cpu->PC + reg->X.W;
250 long OpAddress = icpu->ShiftedDB + *cpu->PC + (*(cpu->PC + 1) << 8) +
255 cpu->Cycles += cpu->MemSpeedx2;
257 // XXX: always add one cycle for ROL, LSR, etc
258 // XXX: else is cross page boundary add one cycle
262 STATIC INLINE long FASTCALL AbsoluteIndexedY (struct SRegisters * reg, struct SICPU * icpu, struct SCPUState * cpu)
264 #ifdef FAST_LSB_WORD_ACCESS
265 long OpAddress = icpu->ShiftedDB + *(uint16 *) cpu->PC + reg->Y.W;
267 long OpAddress = icpu->ShiftedDB + *cpu->PC + (*(cpu->PC + 1) << 8) +
272 cpu->Cycles += cpu->MemSpeedx2;
274 // XXX: always add cycle for STA
275 // XXX: else is cross page boundary add one cycle
279 STATIC INLINE long FASTCALL AbsoluteLongIndexedX (struct SRegisters * reg, struct SICPU * icpu, struct SCPUState * cpu)
281 #ifdef FAST_LSB_WORD_ACCESS
282 long OpAddress = (*(uint32 *) cpu->PC + reg->X.W) & 0xffffff;
284 long OpAddress = (*cpu->PC + (*(cpu->PC + 1) << 8) + (*(cpu->PC + 2) << 16) + reg->X.W) & 0xffffff;
288 cpu->Cycles += cpu->MemSpeedx2 + cpu->MemSpeed;
293 STATIC INLINE long FASTCALL DirectIndirect (struct SRegisters * reg, struct SICPU * icpu, struct SCPUState * cpu)
295 long OpAddress = (*cpu->PC++ + reg->D.W) & 0xffff;
297 cpu->Cycles += cpu->MemSpeed;
299 OpAddress = S9xGetWord (OpAddress, cpu) + icpu->ShiftedDB;
301 // if (reg->DL != 0) cpu->Cycles += ONE_CYCLE;
305 STATIC INLINE long FASTCALL DirectIndirectLong (struct SRegisters * reg, struct SICPU * icpu, struct SCPUState * cpu)
307 long OpAddress = (*cpu->PC++ + reg->D.W) & 0xffff;
309 cpu->Cycles += cpu->MemSpeed;
311 OpAddress = S9xGetWord (OpAddress, cpu) +
312 (S9xGetByte (OpAddress + 2, cpu) << 16);
313 // if (reg->DL != 0) cpu->Cycles += ONE_CYCLE;
317 STATIC INLINE long FASTCALL StackRelative (struct SRegisters * reg, struct SICPU * icpu, struct SCPUState * cpu)
319 long OpAddress = (*cpu->PC++ + reg->S.W) & 0xffff;
321 cpu->Cycles += cpu->MemSpeed;
322 cpu->Cycles += ONE_CYCLE;
327 STATIC INLINE long FASTCALL StackRelativeIndirectIndexed (struct SRegisters * reg, struct SICPU * icpu, struct SCPUState * cpu)
329 long OpAddress = (*cpu->PC++ + reg->S.W) & 0xffff;
331 cpu->Cycles += cpu->MemSpeed;
332 cpu->Cycles += TWO_CYCLES;
334 OpAddress = (S9xGetWord (OpAddress, cpu) + icpu->ShiftedDB +
335 reg->Y.W) & 0xffffff;