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.
48 struct SSA1Registers {
61 struct SOpcodes *S9xOpcodes;
73 bool8 WaitingForInterrupt;
79 uint8 *PCAtOpcodeStart;
82 uint8 *WaitByteAddress1;
83 uint8 *WaitByteAddress2;
87 uint8 *Map [MEMMAP_NUM_BLOCKS];
88 uint8 *WriteMap [MEMMAP_NUM_BLOCKS];
94 uint8 VirtualBitmapFormat;
96 uint8 variable_bit_pos;
99 extern struct SSA1Registers SA1Registers;
100 extern struct SSA1 SA1;
106 #define SA1CheckZero() (SA1._Zero == 0)
107 #define SA1CheckCarry() (SA1._Carry)
108 #define SA1CheckIRQ() (SA1Registers.PL & IRQ)
109 #define SA1CheckDecimal() (SA1Registers.PL & Decimal)
110 #define SA1CheckIndex() (SA1Registers.PL & IndexFlag)
111 #define SA1CheckMemory() (SA1Registers.PL & MemoryFlag)
112 #define SA1CheckOverflow() (SA1._Overflow)
113 #define SA1CheckNegative() (SA1._Negative & 0x80)
114 #define SA1CheckEmulation() (SA1Registers.P.W & Emulation)
116 #define SA1ClearFlags(f) (SA1Registers.P.W &= ~(f))
117 #define SA1SetFlags(f) (SA1Registers.P.W |= (f))
118 #define SA1CheckFlag(f) (SA1Registers.PL & (f))
122 uint8 S9xSA1GetByte (uint32);
123 uint16 S9xSA1GetWord (uint32);
124 void S9xSA1SetByte (uint8, uint32);
125 void S9xSA1SetWord (uint16, uint32);
126 void S9xSA1SetPCBase (uint32);
127 uint8 S9xGetSA1 (uint32);
128 void S9xSetSA1 (uint8, uint32);
130 extern struct SOpcodes S9xSA1OpcodesM1X1 [256];
131 extern struct SOpcodes S9xSA1OpcodesM1X0 [256];
132 extern struct SOpcodes S9xSA1OpcodesM0X1 [256];
133 extern struct SOpcodes S9xSA1OpcodesM0X0 [256];
135 void S9xSA1MainLoop ();
137 void S9xFixSA1AfterSnapshotLoad ();
138 void S9xSA1ExecuteDuringSleep ();
141 #define SNES_IRQ_SOURCE (1 << 7)
142 #define TIMER_IRQ_SOURCE (1 << 6)
143 #define DMA_IRQ_SOURCE (1 << 5)
145 STATIC inline void S9xSA1UnpackStatus()
147 SA1._Zero = (SA1Registers.PL & Zero) == 0;
148 SA1._Negative = (SA1Registers.PL & Negative);
149 SA1._Carry = (SA1Registers.PL & Carry);
150 SA1._Overflow = (SA1Registers.PL & Overflow) >> 6;
153 STATIC inline void S9xSA1PackStatus()
155 SA1Registers.PL &= ~(Zero | Negative | Carry | Overflow);
156 SA1Registers.PL |= SA1._Carry | ((SA1._Zero == 0) << 1) |
157 (SA1._Negative & 0x80) | (SA1._Overflow << 6);
160 STATIC inline void S9xSA1FixCycles ()
162 if (SA1CheckEmulation ())
163 SA1.S9xOpcodes = S9xSA1OpcodesM1X1;
165 if (SA1CheckMemory ())
167 if (SA1CheckIndex ())
168 SA1.S9xOpcodes = S9xSA1OpcodesM1X1;
170 SA1.S9xOpcodes = S9xSA1OpcodesM1X0;
174 if (SA1CheckIndex ())
175 SA1.S9xOpcodes = S9xSA1OpcodesM0X1;
177 SA1.S9xOpcodes = S9xSA1OpcodesM0X0;