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 ()
48 long OpAddress = ICPU.ShiftedPB + CPU.PC - CPU.PCBase;
53 STATIC INLINE long FASTCALL Immediate16 ()
55 long OpAddress = ICPU.ShiftedPB + CPU.PC - CPU.PCBase;
60 STATIC INLINE long FASTCALL Relative ()
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 ()
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 ()
87 #ifdef FAST_LSB_WORD_ACCESS
88 long OpAddress = (Registers.X.W + *(uint16 *) CPU.PC) & 0xffff;
90 long OpAddress = (Registers.X.W + *CPU.PC + (*(CPU.PC + 1) << 8)) & 0xffff;
93 CPU.Cycles += CPU.MemSpeedx2;
96 return S9xGetWord (ICPU.ShiftedPB + OpAddress);
99 STATIC INLINE long FASTCALL AbsoluteIndirectLong ()
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) | (S9xGetByte (OpAddress + 2) << 16);
114 STATIC INLINE long FASTCALL AbsoluteIndirect ()
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) + ICPU.ShiftedPB;
129 STATIC INLINE long FASTCALL Absolute ()
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 ()
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()
159 long OpAddress = (*CPU.PC++ + Registers.D.W) & 0xffff;
161 CPU.Cycles += CPU.MemSpeed;
163 // if (Registers.DL != 0) CPU.Cycles += ONE_CYCLE;
167 STATIC INLINE long FASTCALL DirectIndirectIndexed ()
169 long OpAddress = (*CPU.PC++ + Registers.D.W) & 0xffff;
171 CPU.Cycles += CPU.MemSpeed;
174 OpAddress = ICPU.ShiftedDB + S9xGetWord (OpAddress) + Registers.Y.W;
176 // if (Registers.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 ()
184 long OpAddress = (*CPU.PC++ + Registers.D.W) & 0xffff;
186 CPU.Cycles += CPU.MemSpeed;
189 OpAddress = S9xGetWord (OpAddress) + (S9xGetByte (OpAddress + 2) << 16) +
191 // if (Registers.DL != 0) CPU.Cycles += ONE_CYCLE;
195 STATIC INLINE long FASTCALL DirectIndexedIndirect()
197 long OpAddress = (*CPU.PC++ + Registers.D.W + Registers.X.W) & 0xffff;
199 CPU.Cycles += CPU.MemSpeed;
202 OpAddress = S9xGetWord (OpAddress) + ICPU.ShiftedDB;
205 // if (Registers.DL != 0)
206 // CPU.Cycles += TWO_CYCLES;
208 CPU.Cycles += ONE_CYCLE;
213 STATIC INLINE long FASTCALL DirectIndexedX ()
215 long OpAddress = (*CPU.PC++ + Registers.D.W + Registers.X.W) & 0xffff;
217 CPU.Cycles += CPU.MemSpeed;
221 // if (Registers.DL != 0)
222 // CPU.Cycles += TWO_CYCLES;
224 CPU.Cycles += ONE_CYCLE;
229 STATIC INLINE long FASTCALL DirectIndexedY ()
231 long OpAddress = (*CPU.PC++ + Registers.D.W + Registers.Y.W) & 0xffff;
233 CPU.Cycles += CPU.MemSpeed;
237 // if (Registers.DL != 0)
238 // CPU.Cycles += TWO_CYCLES;
240 CPU.Cycles += ONE_CYCLE;
245 STATIC INLINE long FASTCALL AbsoluteIndexedX ()
247 #ifdef FAST_LSB_WORD_ACCESS
248 long OpAddress = ICPU.ShiftedDB + *(uint16 *) CPU.PC + Registers.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 ()
264 #ifdef FAST_LSB_WORD_ACCESS
265 long OpAddress = ICPU.ShiftedDB + *(uint16 *) CPU.PC + Registers.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 ()
281 #ifdef FAST_LSB_WORD_ACCESS
282 long OpAddress = (*(uint32 *) CPU.PC + Registers.X.W) & 0xffffff;
284 long OpAddress = (*CPU.PC + (*(CPU.PC + 1) << 8) + (*(CPU.PC + 2) << 16) + Registers.X.W) & 0xffffff;
288 CPU.Cycles += CPU.MemSpeedx2 + CPU.MemSpeed;
293 STATIC INLINE long FASTCALL DirectIndirect ()
295 long OpAddress = (*CPU.PC++ + Registers.D.W) & 0xffff;
297 CPU.Cycles += CPU.MemSpeed;
299 OpAddress = S9xGetWord (OpAddress) + ICPU.ShiftedDB;
301 // if (Registers.DL != 0) CPU.Cycles += ONE_CYCLE;
305 STATIC INLINE long FASTCALL DirectIndirectLong ()
307 long OpAddress = (*CPU.PC++ + Registers.D.W) & 0xffff;
309 CPU.Cycles += CPU.MemSpeed;
311 OpAddress = S9xGetWord (OpAddress) +
312 (S9xGetByte (OpAddress + 2) << 16);
313 // if (Registers.DL != 0) CPU.Cycles += ONE_CYCLE;
317 STATIC INLINE long FASTCALL StackRelative ()
319 long OpAddress = (*CPU.PC++ + Registers.S.W) & 0xffff;
321 CPU.Cycles += CPU.MemSpeed;
322 CPU.Cycles += ONE_CYCLE;
327 STATIC INLINE long FASTCALL StackRelativeIndirectIndexed ()
329 long OpAddress = (*CPU.PC++ + Registers.S.W) & 0xffff;
331 CPU.Cycles += CPU.MemSpeed;
332 CPU.Cycles += TWO_CYCLES;
334 OpAddress = (S9xGetWord (OpAddress) + ICPU.ShiftedDB +
335 Registers.Y.W) & 0xffffff;