# HG changeset patch # User Robert McIntyre # Date 1331510851 18000 # Node ID 1ff2c546f5ad2cc8066b820d791a11df7814ceca # Parent 613353b7e012ab548aa5c0ca65851c3c2f341cb7 added tick(), which allows one to step through each opcode of gameboy diff -r 613353b7e012 -r 1ff2c546f5ad java/src/com/aurellem/gb/Gb.java --- a/java/src/com/aurellem/gb/Gb.java Sun Mar 11 13:53:27 2012 -0500 +++ b/java/src/com/aurellem/gb/Gb.java Sun Mar 11 19:07:31 2012 -0500 @@ -27,6 +27,12 @@ } public static native void step(); + + public static native int ntick(); + + public static boolean tick(){ + return (1 == ntick()); + } public static native void nstep(int keymask); diff -r 613353b7e012 -r 1ff2c546f5ad src/clojure/clojure.cpp --- a/src/clojure/clojure.cpp Sun Mar 11 13:53:27 2012 -0500 +++ b/src/clojure/clojure.cpp Sun Mar 11 19:07:31 2012 -0500 @@ -61,8 +61,16 @@ step(keymask); } +/* + * Class: com_aurellem_gb_Gb + * Method: ntick + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_com_aurellem_gb_Gb_ntick +(JNIEnv *env, jclass clazz){ + return tick(); - +} /* diff -r 613353b7e012 -r 1ff2c546f5ad src/common/System.h --- a/src/common/System.h Sun Mar 11 13:53:27 2012 -0500 +++ b/src/common/System.h Sun Mar 11 19:07:31 2012 -0500 @@ -13,7 +13,7 @@ struct EmulatedSystem { // main emulation function - void (*emuMain)(int); + int (*emuMain)(int); // reset emulator void (*emuReset)(bool); // clean up memory diff -r 613353b7e012 -r 1ff2c546f5ad src/gb/GB.cpp --- a/src/gb/GB.cpp Sun Mar 11 13:53:27 2012 -0500 +++ b/src/gb/GB.cpp Sun Mar 11 19:07:31 2012 -0500 @@ -15,7 +15,7 @@ #include "../common/Util.h" #include "../common/System.h" #include "../common/movie.h" -#include "../common/vbalua.h" +// #include "../common/vbalua.h" #ifdef __GNUC__ #define _stricmp strcasecmp @@ -1280,7 +1280,7 @@ void gbWriteMemory(register u16 address, register u8 value) { gbWriteMemoryWrapped(address, value); - CallRegisteredLuaMemHook(address, 1, value, LUAMEMHOOK_WRITE); + //CallRegisteredLuaMemHook(address, 1, value, LUAMEMHOOK_WRITE); } u8 gbReadMemory(register u16 address) @@ -3164,8 +3164,9 @@ return true; } -void gbEmulate(int ticksToStop) +int gbEmulate(int ticksToStop) { + int rlm_count = 0; //printf("RLM: Inside the GB!\n"); gbRegister tempRegister; u8 tempValue; @@ -3232,8 +3233,8 @@ } - for (;; ) - { + //for (;; ) + // { #ifndef FINAL_VERSION if (systemDebug) { @@ -3276,7 +3277,8 @@ else { opcode = gbReadOpcode(PC.W); - CallRegisteredLuaMemHook(PC.W, 1, opcode, LUAMEMHOOK_EXEC); + //printf("RLM: calling mem Hook ; %07d\n", rlm_count++); + //CallRegisteredLuaMemHook(PC.W, 1, opcode, LUAMEMHOOK_EXEC); PC.W++; if (IFF & 0x100) @@ -3304,7 +3306,7 @@ } if (!emulating) - return; + return 1; if (gbDmaTicks) { @@ -3774,31 +3776,31 @@ if ((gbInterrupt & 1) && (register_IE & 1)) { gbVblank_interrupt(); - continue; + return newFrame; } if ((gbInterrupt & 2) && (register_IE & 2)) { gbLcd_interrupt(); - continue; + return newFrame; } if ((gbInterrupt & 4) && (register_IE & 4)) { gbTimer_interrupt(); - continue; + return newFrame; } if ((gbInterrupt & 8) && (register_IE & 8)) { gbSerial_interrupt(); - continue; + return newFrame; } if ((gbInterrupt & 16) && (register_IE & 16)) { gbJoypad_interrupt(); - continue; + return newFrame; } } } @@ -3814,12 +3816,12 @@ { // old timing code if (ticksToStop > 0) - continue; + return newFrame; } else { if (!newFrame && (register_LCDC & 0x80) != 0) - continue; + return newFrame; } if (!(register_LCDC & 0x80)) @@ -3862,14 +3864,15 @@ } // makes sure frames are really divided across input sampling boundaries which occur at a constant rate - if (newFrame || useOldFrameTiming) - { + //if (newFrame || useOldFrameTiming) + // { /// extern void VBAOnEnteringFrameBoundary(); /// VBAOnEnteringFrameBoundary(); - break; - } - } + // break; + // } + // RLM removing for loop } + return newFrame; } @@ -3964,7 +3967,7 @@ gbWriteSaveState, // emuReadStateFromStream gbReadSaveStateFromStream, - // emuWriteStateToStream + // emuwritestatetostream gbWriteSaveStateToStream, // emuReadMemState gbReadMemSaveState, diff -r 613353b7e012 -r 1ff2c546f5ad src/gb/GB.h --- a/src/gb/GB.h Sun Mar 11 13:53:27 2012 -0500 +++ b/src/gb/GB.h Sun Mar 11 19:07:31 2012 -0500 @@ -22,7 +22,7 @@ } gbRegister; extern bool gbLoadRom(const char *); -extern void gbEmulate(int); +extern int gbEmulate(int); extern bool gbIsGameboyRom(const char *); extern void gbSoundReset(); extern void gbSoundSetQuality(int); diff -r 613353b7e012 -r 1ff2c546f5ad src/gb/gbCodes.h --- a/src/gb/gbCodes.h Sun Mar 11 13:53:27 2012 -0500 +++ b/src/gb/gbCodes.h Sun Mar 11 19:07:31 2012 -0500 @@ -1385,4 +1385,4 @@ systemMessage(0, N_("Unknown opcode %02x at %04x"), gbReadOpcode(PC.W-1),PC.W-1); emulating = false; - return; + return 1; diff -r 613353b7e012 -r 1ff2c546f5ad src/gb/gbCodesCB.h --- a/src/gb/gbCodesCB.h Sun Mar 11 13:53:27 2012 -0500 +++ b/src/gb/gbCodesCB.h Sun Mar 11 19:07:31 2012 -0500 @@ -1266,4 +1266,4 @@ systemMessage(0, N_("Unknown opcode %02x at %04x"), gbReadOpcode(PC.W-1),PC.W-1); emulating = false; - return; + return 1; diff -r 613353b7e012 -r 1ff2c546f5ad src/gba/GBA.cpp --- a/src/gba/GBA.cpp Sun Mar 11 13:53:27 2012 -0500 +++ b/src/gba/GBA.cpp Sun Mar 11 19:07:31 2012 -0500 @@ -3746,7 +3746,7 @@ extern void winlog(const char *, ...); #endif -void CPULoop(int _ticks) +void CPULoop2(int _ticks) { int32 ticks = _ticks; int32 clockTicks; @@ -4501,6 +4501,14 @@ } } + +// RLM: +int CPULoop(int _ticks){ + CPULoop2(_ticks); + return 1; +} + + struct EmulatedSystem GBASystem = { // emuMain diff -r 613353b7e012 -r 1ff2c546f5ad src/gba/GBA.h --- a/src/gba/GBA.h Sun Mar 11 13:53:27 2012 -0500 +++ b/src/gba/GBA.h Sun Mar 11 19:07:31 2012 -0500 @@ -86,7 +86,7 @@ extern bool CPULoadBios(const char *, bool); extern void CPUInit(); extern void CPUReset(bool userReset = false); -extern void CPULoop(int); +extern int CPULoop(int); extern void CPUCheckDMA(int, int); #ifdef PROFILING extern void cpuProfil(char *buffer, int, u32, int); diff -r 613353b7e012 -r 1ff2c546f5ad src/sdl/Drive.h --- a/src/sdl/Drive.h Sun Mar 11 13:53:27 2012 -0500 +++ b/src/sdl/Drive.h Sun Mar 11 19:07:31 2012 -0500 @@ -5,3 +5,5 @@ void step(int keymask); void shutdown(); + +int tick(); diff -r 613353b7e012 -r 1ff2c546f5ad src/sdl/SDL.cpp --- a/src/sdl/SDL.cpp Sun Mar 11 13:53:27 2012 -0500 +++ b/src/sdl/SDL.cpp Sun Mar 11 19:07:31 2012 -0500 @@ -2062,30 +2062,18 @@ SDL_Quit(); } +int tick () { + return theEmulator.emuMain(theEmulator.emuCount); +} void step () { if(!paused && active) { - if(debugger && theEmulator.emuHasDebugger) - dbgMain(); - else { - //printf("RLM: emulator main\n"); - theEmulator.emuMain(theEmulator.emuCount); - //printf("RLM: emulator main called\n"); - if(rewindSaveNeeded && rewindMemory && theEmulator.emuWriteMemState) { - rewindCount++; - if(rewindCount > 8) - rewindCount = 8; - if(theEmulator.emuWriteMemState && - theEmulator.emuWriteMemState(&rewindMemory[rewindPos*REWIND_SIZE], - REWIND_SIZE)) { - rewindPos = ++rewindPos & 7; - if(rewindCount == 8) - rewindTopPos = ++rewindTopPos & 7; - } - } - - rewindSaveNeeded = false; + //printf("RLM: emulator main\n"); + int frameComplete = 0; + while (!(frameComplete)){ + frameComplete = theEmulator.emuMain(theEmulator.emuCount); } + //printf("RLM: emulator main called\n"); } else { SDL_Delay(500); }