MCPcopy Create free account
hub / github.com/Stewmath/GameYob / runOpcode

Function runOpcode

arm9/source/gbcpu.cpp:207–2854  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

205u8* haltBugAddr = NULL;
206u8* firstPcAddr DTCM_BSS;
207int runOpcode(int cycles) {
208 cyclesToExecute = cycles;
209 // Having these commonly-used registers in local variables should improve speed
210 u8* pcAddr;
211 pcAddr = &memory[gbRegs.pc.w>>12][gbRegs.pc.w&0xfff];
212 firstPcAddr = pcAddr;
213 int locSP=gbRegs.sp.w;
214 int locF =gbRegs.af.b.l;
215
216 int totalCycles=0;
217
218 while (totalCycles < cyclesToExecute)
219 {
220 u8 opcode = *pcAddr;
221 pcAddr++;
222 totalCycles += opCycles[opcode];
223
224 switch(opcode)
225 {
226 // 8-bit loads
227 case 0x06: // LD B, n 8
228 case 0x0E: // LD C, n 8
229 case 0x16: // LD D, n 8
230 case 0x1E: // LD E, n 8
231 case 0x26: // LD H, n 8
232 case 0x2E: // LD L, n 8
233 (*numberedGbReg(opcode>>3)) = readPC();
234 break;
235 case 0x3E: // LD A, n 8
236 gbRegs.af.b.h = readPC();
237 break;
238 /* These are equivalent to NOPs. */
239 case 0x7F: // LD A, A 4
240 case 0x40: // LD B, B 4
241 case 0x49: // LD C, C 4
242 case 0x52: // LD D, D 4
243 case 0x5B: // LD E, E 4
244 case 0x64: // LD H, H 4
245 case 0x6D: // LD L, L 4
246 break;
247 case 0x78: // LD A, B 4
248 gbRegs.af.b.h = gbRegs.bc.b.h;
249 break;
250 case 0x79: // LD A, C 4
251 gbRegs.af.b.h = gbRegs.bc.b.l;
252 break;
253 case 0x7A: // LD A, D 4
254 gbRegs.af.b.h = gbRegs.de.b.h;
255 break;
256 case 0x7B: // LD A, E 4
257 gbRegs.af.b.h = gbRegs.de.b.l;
258 break;
259 case 0x7C: // LD A, H 4
260 gbRegs.af.b.h = gbRegs.hl.b.h;
261 break;
262 case 0x7D: // LD A, L 4
263 gbRegs.af.b.h = gbRegs.hl.b.l;
264 break;

Callers 1

runEmulFunction · 0.85

Calls 10

readMemoryFunction · 0.85
writeMemoryFunction · 0.85
readIOFunction · 0.85
writeIOFunction · 0.85
quickWriteFunction · 0.85
quickReadFunction · 0.85
quickRead16Function · 0.85
setDoubleSpeedFunction · 0.85
disableInterruptsFunction · 0.85
enableInterruptsFunction · 0.85

Tested by

no test coverage detected