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.
47 #define DO_HBLANK_CHECK() \
48 if (CPU.Cycles >= CPU.NextEvent) \
49 S9xDoHBlankProcessing ();
57 #if !defined(CONF_BUILD_ASM_CORE) || !CONF_BUILD_ASM_CORE
59 struct SOpcodes *S9xOpcodes;
70 uint32 FrameAdvanceCount;
74 void S9xMainLoop (void);
76 void S9xDoHBlankProcessing ();
77 void S9xClearIRQ (uint32);
78 void S9xSetIRQ (uint32);
80 extern struct SOpcodes S9xOpcodesM1X1 [256];
81 extern struct SOpcodes S9xOpcodesM1X0 [256];
82 extern struct SOpcodes S9xOpcodesM0X1 [256];
83 extern struct SOpcodes S9xOpcodesM0X0 [256];
86 extern uint8 S9xE1M1X1 [256];
87 extern uint8 S9xE0M1X0 [256];
88 extern uint8 S9xE0M1X1 [256];
89 extern uint8 S9xE0M0X0 [256];
90 extern uint8 S9xE0M0X1 [256];
93 extern struct SICPU ICPU;
96 STATIC inline void CLEAR_IRQ_SOURCE (uint32 M)
100 CPU.Flags &= ~IRQ_PENDING_FLAG;
103 #if !CONF_BUILD_ASM_CPU
104 STATIC inline void S9xUnpackStatus()
106 ICPU._Zero = (Registers.PL & Zero) == 0;
107 ICPU._Negative = (Registers.PL & Negative);
108 ICPU._Carry = (Registers.PL & Carry);
109 ICPU._Overflow = (Registers.PL & Overflow) >> 6;
112 STATIC inline void S9xPackStatus()
114 Registers.PL &= ~(Zero | Negative | Carry | Overflow);
115 Registers.PL |= ICPU._Carry | ((ICPU._Zero == 0) << 1) |
116 (ICPU._Negative & 0x80) | (ICPU._Overflow << 6);
119 STATIC inline void S9xFixCycles ()
121 if (CheckEmulation ())
124 ICPU.Speed = S9xE1M1X1;
126 ICPU.S9xOpcodes = S9xOpcodesM1X1;
134 ICPU.Speed = S9xE0M1X1;
136 ICPU.S9xOpcodes = S9xOpcodesM1X1;
141 ICPU.Speed = S9xE0M1X0;
143 ICPU.S9xOpcodes = S9xOpcodesM1X0;
151 ICPU.Speed = S9xE0M0X1;
153 ICPU.S9xOpcodes = S9xOpcodesM0X1;
158 ICPU.Speed = S9xE0M0X0;
160 ICPU.S9xOpcodes = S9xOpcodesM0X0;
166 STATIC inline void S9xReschedule ()
171 if (CPU.WhichEvent == HBLANK_START_EVENT ||
172 CPU.WhichEvent == HTIMER_AFTER_EVENT)
174 which = HBLANK_END_EVENT;
175 max = Settings.H_Max;
179 which = HBLANK_START_EVENT;
180 max = Settings.HBlankStart;
183 if (PPU.HTimerEnabled &&
184 (long) PPU.HTimerPosition < max &&
185 (long) PPU.HTimerPosition > CPU.NextEvent &&
186 (!PPU.VTimerEnabled ||
187 (PPU.VTimerEnabled && CPU.V_Counter == PPU.IRQVBeamPos)))
189 which = (long) PPU.HTimerPosition < Settings.HBlankStart ?
190 HTIMER_BEFORE_EVENT : HTIMER_AFTER_EVENT;
191 max = PPU.HTimerPosition;
194 CPU.WhichEvent = which;