workaround a problem with the harmattan gcc
[drnoksnes] / os9x_asm_cpu.cpp
1 #include "snes9x.h"
2 #include "apu.h"
3 #include "ppu.h"
4 #include "cpuexec.h"
5 //#include "cpuops.h"
6
7 #include "os9x_asm_cpu.h"
8
9 //#define __debug_c_irq__
10 //#define __debug_c_nmi__
11 //#define __debug_c_hblank__
12 //#define __debug_c_io__
13
14 START_EXTERN_C
15
16 void asm_S9xSetPCBase(uint32 Address)
17 {
18 #ifdef __debug_c_setpc__
19         printf("spcb\n");
20 #endif
21         S9xSetPCBase(Address);  
22 }
23
24
25 #if 0
26 #define PushW(w) \
27     S9xSetWord (w, Registers.S.W - 1);\
28     Registers.S.W -= 2;
29 #define PushB(b)\
30     S9xSetByte (b, Registers.S.W--);
31
32
33 void asm_S9xMainLoop(void)
34 {
35         //S9xPackStatus();
36         //printf("asmMainLoop Enter(0x%08x).\n", CPU.Flags);
37         asmMainLoop(&CPU);
38         //printf("asmMainLoop Exit(0x%08x, %d).\n", CPU.PC - CPU.PCBase, CPU.Cycles);
39         //S9xUnpackStatus();    
40 }
41
42 void asm_S9xDoHBlankProcessing(void)
43 {       
44 #ifdef __debug_c_hblank__
45         printf("hblank\n");
46 #endif  
47 //      S9xUnpackStatus(); // not needed
48         S9xDoHBlankProcessing();        
49 //      S9xPackStatus();        
50 }
51
52
53 uint8 asm_S9xGetByte(uint32 Address)
54 {
55 #ifdef __debug_c_io__
56         printf("gb\n");
57 #endif  
58         return S9xGetByte(Address);     
59 }
60
61 uint16 asm_S9xGetWord(uint32 Address)
62 {
63 #ifdef __debug_c_io__
64         printf("gw\n");
65 #endif  
66         return S9xGetWord(Address);     
67 }
68
69
70 void asm_S9xSetByte(uint32 Address,uint8 value)
71 {       
72 #ifdef __debug_c_io__
73         printf("sb\n");         
74 #endif
75         S9xSetByte(value,Address);      
76 }
77
78 void asm_S9xSetWord(uint32 Address,uint16 value)
79 {       
80 #ifdef __debug_c_io__
81         printf("sw\n");
82 #endif  
83         S9xSetWord(value,Address);
84 }
85
86
87 void asm_S9xOpcode_NMI(void)
88 {       
89 #ifdef __debug_c_nmi__
90         printf("nmi\n");
91 #endif  
92 //      S9xUnpackStatus(); // not needed
93
94         if (!CheckEmulation())
95     {
96         PushB (Registers.PB);
97         PushW (CPU.PC - CPU.PCBase);
98 //      S9xPackStatus ();
99         PushB (Registers.PL);
100         ClearDecimal ();
101         SetIRQ ();
102
103         Registers.PB = 0;
104 //      c = 0; // unused
105 #ifdef USE_SA1
106         if (Settings.SA1 && (Memory.FillRAM [0x2209] & 0x20))
107             S9xSetPCBase (Memory.FillRAM [0x220c] |
108                           (Memory.FillRAM [0x220d] << 8));
109         else
110 #endif
111                 S9xSetPCBase (S9xGetWord (0xFFEA));
112 #ifdef VAR_CYCLES
113         CPU.Cycles += TWO_CYCLES;
114 #else
115         CPU.Cycles += 8;
116 #endif
117     }
118     else
119     {
120         PushW (CPU.PC - CPU.PCBase);
121 //      S9xPackStatus (); // not needed
122         PushB (Registers.PL);
123         ClearDecimal ();
124         SetIRQ ();
125
126         Registers.PB = 0;
127 //      ICPU.ShiftedPB = 0; // unused
128 #ifdef USE_SA1
129         if (Settings.SA1 && (Memory.FillRAM [0x2209] & 0x20))
130             S9xSetPCBase (Memory.FillRAM [0x220c] |
131                           (Memory.FillRAM [0x220d] << 8));
132         else
133 #endif
134             S9xSetPCBase (S9xGetWord (0xFFFA));
135 #ifdef VAR_CYCLES
136         CPU.Cycles += ONE_CYCLE;
137 #else
138         CPU.Cycles += 6;
139 #endif
140     }
141
142 //      S9xPackStatus(); // not needed
143 }
144
145 void asm_S9xOpcode_IRQ(void)
146 {
147 #ifdef __debug_c_irq__
148         printf("irq\n");
149 #endif  
150 //      S9xUnpackStatus(); // not needed
151
152     if (!CheckEmulation())
153     {
154         PushB (Registers.PB);
155         PushW (CPU.PC - CPU.PCBase);
156 //      S9xPackStatus (); // not needed
157         PushB (Registers.PL);
158         ClearDecimal ();
159         SetIRQ ();
160
161         Registers.PB = 0;
162 //      ICPU.ShiftedPB = 0; // unused
163
164 #ifdef USE_SA1
165         if (Settings.SA1 && (Memory.FillRAM [0x2209] & 0x40))
166             S9xSetPCBase (Memory.FillRAM [0x220e] | 
167                           (Memory.FillRAM [0x220f] << 8));
168         else
169 #endif
170                 S9xSetPCBase (S9xGetWord (0xFFEE));
171 #ifdef VAR_CYCLES
172         CPU.Cycles += TWO_CYCLES;
173 #else
174         CPU.Cycles += 8;
175 #endif
176     }
177     else
178     {
179         PushW (CPU.PC - CPU.PCBase);
180 //      S9xPackStatus (); // not needed
181         PushB (Registers.PL);
182         ClearDecimal ();
183         SetIRQ ();
184
185         Registers.PB = 0;
186 //      ICPU.ShiftedPB = 0; // unused
187
188 #ifdef USE_SA1
189         if (Settings.SA1 && (Memory.FillRAM [0x2209] & 0x40))
190             S9xSetPCBase (Memory.FillRAM [0x220e] | 
191                           (Memory.FillRAM [0x220f] << 8));
192         else
193 #endif
194                 S9xSetPCBase (S9xGetWord (0xFFFE));
195 #ifdef VAR_CYCLES
196         CPU.Cycles += ONE_CYCLE;
197 #else
198         CPU.Cycles += 6;
199 #endif
200     }
201         
202 //      S9xPackStatus(); // not needed
203 }
204 #endif
205
206
207 #ifndef ASM_SPC700
208
209 void asm_APU_EXECUTE(void)
210 {
211 #ifdef __debug_c_apuex__        
212         printf("apuexec\n");
213 #endif
214         if(CPU.APU_APUExecuting != 1) return;
215
216         while (CPU.APU_Cycles <= CPU.Cycles)
217         {
218                 APU_EXECUTE1();
219         }
220 }
221
222 void asm_APU_EXECUTE2(void)
223 {
224         if(CPU.APU_APUExecuting != 1) return;
225
226         ICPU.CPUExecuting = FALSE;
227         do
228         {
229             APU_EXECUTE1();
230         } while (CPU.APU_Cycles < CPU.NextEvent);
231         ICPU.CPUExecuting = TRUE;
232 }
233
234 #endif
235
236 END_EXTERN_C