workaround a problem with the harmattan gcc
[drnoksnes] / sa1.h
1 /*
2  * Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
3  *
4  * (c) Copyright 1996 - 2001 Gary Henderson (gary.henderson@ntlworld.com) and
5  *                           Jerremy Koot (jkoot@snes9x.com)
6  *
7  * Super FX C emulator code 
8  * (c) Copyright 1997 - 1999 Ivar (ivar@snes9x.com) and
9  *                           Gary Henderson.
10  * Super FX assembler emulator code (c) Copyright 1998 zsKnight and _Demo_.
11  *
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).
15  *
16  * DOS port code contains the works of other authors. See headers in
17  * individual files.
18  *
19  * Snes9x homepage: http://www.snes9x.com
20  *
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.
25  *
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.
29  *
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.
33  *
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
36  * in future versions.
37  *
38  * Super NES and Super Nintendo Entertainment System are trademarks of
39  * Nintendo Co., Limited and its subsidiary companies.
40  */
41 #ifndef _sa1_h_
42 #define _sa1_h_
43
44 #include "memmap.h"
45
46 START_EXTERN_C
47
48 struct SSA1Registers {
49     uint8   PB;
50     uint8   DB;
51     pair    P;
52     pair    A;
53     pair    D;
54     pair    S;
55     pair    X;
56     pair    Y;
57     uint16  PC;
58 };
59
60 struct SSA1 {
61     struct  SOpcodes *S9xOpcodes;
62     uint8   _Carry;
63     uint8   _Zero;
64     uint8   _Negative;
65     uint8   _Overflow;
66     bool8   CPUExecuting;
67     uint32  ShiftedPB;
68     uint32  ShiftedDB;
69     uint32  Flags;
70     bool8   Executing;
71     bool8   NMIActive;
72     bool8   IRQActive;
73     bool8   WaitingForInterrupt;
74     bool8   Waiting;
75 //    uint8   WhichEvent;
76     uint8   *PC;
77     uint8   *PCBase;
78     uint8   *BWRAM;
79     uint8   *PCAtOpcodeStart;
80     uint8   *WaitAddress;
81     uint32  WaitCounter;
82     uint8   *WaitByteAddress1;
83     uint8   *WaitByteAddress2;
84 //    long    Cycles;
85 //    long    NextEvent;
86 //    long    V_Counter;
87     uint8   *Map [MEMMAP_NUM_BLOCKS];
88     uint8   *WriteMap [MEMMAP_NUM_BLOCKS];
89     int16   op1;
90     int16   op2;
91     int     arithmetic_op;
92     int64   sum;
93     bool8   overflow;
94     uint8   VirtualBitmapFormat;
95     bool8   in_char_dma;
96     uint8   variable_bit_pos;
97 };
98
99 extern struct SSA1Registers SA1Registers;
100 extern struct SSA1 SA1;
101
102 END_EXTERN_C
103
104 #ifdef USE_SA1
105
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)
115
116 #define SA1ClearFlags(f) (SA1Registers.P.W &= ~(f))
117 #define SA1SetFlags(f)   (SA1Registers.P.W |=  (f))
118 #define SA1CheckFlag(f)  (SA1Registers.PL & (f))
119
120
121 START_EXTERN_C
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);
129
130 extern struct SOpcodes S9xSA1OpcodesM1X1 [256];
131 extern struct SOpcodes S9xSA1OpcodesM1X0 [256];
132 extern struct SOpcodes S9xSA1OpcodesM0X1 [256];
133 extern struct SOpcodes S9xSA1OpcodesM0X0 [256];
134
135 void S9xSA1MainLoop ();
136 void S9xSA1Init ();
137 void S9xFixSA1AfterSnapshotLoad ();
138 void S9xSA1ExecuteDuringSleep ();
139 END_EXTERN_C
140
141 #define SNES_IRQ_SOURCE     (1 << 7)
142 #define TIMER_IRQ_SOURCE    (1 << 6)
143 #define DMA_IRQ_SOURCE      (1 << 5)
144
145 STATIC inline void S9xSA1UnpackStatus()
146 {
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;
151 }
152
153 STATIC inline void S9xSA1PackStatus()
154 {
155     SA1Registers.PL &= ~(Zero | Negative | Carry | Overflow);
156     SA1Registers.PL |= SA1._Carry | ((SA1._Zero == 0) << 1) |
157                        (SA1._Negative & 0x80) | (SA1._Overflow << 6);
158 }
159
160 STATIC inline void S9xSA1FixCycles ()
161 {
162     if (SA1CheckEmulation ())
163         SA1.S9xOpcodes = S9xSA1OpcodesM1X1;
164     else
165     if (SA1CheckMemory ())
166     {
167         if (SA1CheckIndex ())
168             SA1.S9xOpcodes = S9xSA1OpcodesM1X1;
169         else
170             SA1.S9xOpcodes = S9xSA1OpcodesM1X0;
171     }
172     else
173     {
174         if (SA1CheckIndex ())
175             SA1.S9xOpcodes = S9xSA1OpcodesM0X1;
176         else
177             SA1.S9xOpcodes = S9xSA1OpcodesM0X0;
178     }
179 }
180
181 #endif // USE_SA1
182
183 #endif