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.
46 struct SSA1Registers {
59 struct SOpcodes *S9xOpcodes;
71 bool8 WaitingForInterrupt;
77 uint8 *PCAtOpcodeStart;
80 uint8 *WaitByteAddress1;
81 uint8 *WaitByteAddress2;
85 uint8 *Map [MEMMAP_NUM_BLOCKS];
86 uint8 *WriteMap [MEMMAP_NUM_BLOCKS];
92 uint8 VirtualBitmapFormat;
94 uint8 variable_bit_pos;
97 extern struct SSA1Registers SA1Registers;
98 extern struct SSA1 SA1;
102 #define SA1CheckZero() (SA1._Zero == 0)
103 #define SA1CheckCarry() (SA1._Carry)
104 #define SA1CheckIRQ() (SA1Registers.PL & IRQ)
105 #define SA1CheckDecimal() (SA1Registers.PL & Decimal)
106 #define SA1CheckIndex() (SA1Registers.PL & IndexFlag)
107 #define SA1CheckMemory() (SA1Registers.PL & MemoryFlag)
108 #define SA1CheckOverflow() (SA1._Overflow)
109 #define SA1CheckNegative() (SA1._Negative & 0x80)
110 #define SA1CheckEmulation() (SA1Registers.P.W & Emulation)
112 #define SA1ClearFlags(f) (SA1Registers.P.W &= ~(f))
113 #define SA1SetFlags(f) (SA1Registers.P.W |= (f))
114 #define SA1CheckFlag(f) (SA1Registers.PL & (f))
118 uint8 S9xSA1GetByte (uint32);
119 uint16 S9xSA1GetWord (uint32);
120 void S9xSA1SetByte (uint8, uint32);
121 void S9xSA1SetWord (uint16, uint32);
122 void S9xSA1SetPCBase (uint32);
123 uint8 S9xGetSA1 (uint32);
124 void S9xSetSA1 (uint8, uint32);
126 extern struct SOpcodes S9xSA1OpcodesM1X1 [256];
127 extern struct SOpcodes S9xSA1OpcodesM1X0 [256];
128 extern struct SOpcodes S9xSA1OpcodesM0X1 [256];
129 extern struct SOpcodes S9xSA1OpcodesM0X0 [256];
131 void S9xSA1MainLoop ();
133 void S9xFixSA1AfterSnapshotLoad ();
134 void S9xSA1ExecuteDuringSleep ();
137 #define SNES_IRQ_SOURCE (1 << 7)
138 #define TIMER_IRQ_SOURCE (1 << 6)
139 #define DMA_IRQ_SOURCE (1 << 5)
141 STATIC inline void S9xSA1UnpackStatus()
143 SA1._Zero = (SA1Registers.PL & Zero) == 0;
144 SA1._Negative = (SA1Registers.PL & Negative);
145 SA1._Carry = (SA1Registers.PL & Carry);
146 SA1._Overflow = (SA1Registers.PL & Overflow) >> 6;
149 STATIC inline void S9xSA1PackStatus()
151 SA1Registers.PL &= ~(Zero | Negative | Carry | Overflow);
152 SA1Registers.PL |= SA1._Carry | ((SA1._Zero == 0) << 1) |
153 (SA1._Negative & 0x80) | (SA1._Overflow << 6);
156 STATIC inline void S9xSA1FixCycles ()
158 if (SA1CheckEmulation ())
159 SA1.S9xOpcodes = S9xSA1OpcodesM1X1;
161 if (SA1CheckMemory ())
163 if (SA1CheckIndex ())
164 SA1.S9xOpcodes = S9xSA1OpcodesM1X1;
166 SA1.S9xOpcodes = S9xSA1OpcodesM1X0;
170 if (SA1CheckIndex ())
171 SA1.S9xOpcodes = S9xSA1OpcodesM0X1;
173 SA1.S9xOpcodes = S9xSA1OpcodesM0X0;