changeset 53:9d0ec2614443

enabled stepping from clojure
author Robert McIntyre <rlm@mit.edu>
date Wed, 07 Mar 2012 02:31:39 -0600
parents ee70875e0d3e
children 88218735d220
files java/src/com/aurellem/gb/Gb.java src/clojure/clojure.cpp src/sdl/Drive.h src/sdl/SDL.cpp
diffstat 4 files changed, 87 insertions(+), 51 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/java/src/com/aurellem/gb/Gb.java	Wed Mar 07 02:12:59 2012 -0600
     1.2 +++ b/java/src/com/aurellem/gb/Gb.java	Wed Mar 07 02:31:39 2012 -0600
     1.3 @@ -26,5 +26,8 @@
     1.4      }
     1.5  
     1.6  
     1.7 +    public static native void step();
     1.8 +
     1.9 +    public static native void shutdown();
    1.10  
    1.11  }
     2.1 --- a/src/clojure/clojure.cpp	Wed Mar 07 02:12:59 2012 -0600
     2.2 +++ b/src/clojure/clojure.cpp	Wed Mar 07 02:31:39 2012 -0600
     2.3 @@ -37,3 +37,24 @@
     2.4    runVBA(2, arguments);
     2.5  }
     2.6  
     2.7 +/*
     2.8 + * Class:     com_aurellem_gb_Gb
     2.9 + * Method:    step
    2.10 + * Signature: ()V
    2.11 + */
    2.12 +JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_step
    2.13 +(JNIEnv *env, jclass clazz){
    2.14 +  step();
    2.15 +}
    2.16 +
    2.17 +/*
    2.18 + * Class:     com_aurellem_gb_Gb
    2.19 + * Method:    shutdown
    2.20 + * Signature: ()V
    2.21 + */
    2.22 +JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_shutdown
    2.23 +(JNIEnv *env, jclass clazz){
    2.24 +  shutdown();
    2.25 +}
    2.26 +
    2.27 +
     3.1 --- a/src/sdl/Drive.h	Wed Mar 07 02:12:59 2012 -0600
     3.2 +++ b/src/sdl/Drive.h	Wed Mar 07 02:31:39 2012 -0600
     3.3 @@ -1,2 +1,5 @@
     3.4  int runVBA(int, char**);
     3.5  
     3.6 +void step();
     3.7 +
     3.8 +void shutdown();
     4.1 --- a/src/sdl/SDL.cpp	Wed Mar 07 02:12:59 2012 -0600
     4.2 +++ b/src/sdl/SDL.cpp	Wed Mar 07 02:31:39 2012 -0600
     4.3 @@ -2043,6 +2043,60 @@
     4.4    renderedFrames = 0;
     4.5    }
     4.6  
     4.7 +
     4.8 +void shutdown () {
     4.9 +fprintf(stderr,"Shutting down\n");
    4.10 +  remoteCleanUp();
    4.11 +  soundShutdown();
    4.12 +
    4.13 +  if(gbRom != NULL || rom != NULL) {
    4.14 +    sdlWriteBattery();
    4.15 +    theEmulator.emuCleanUp();
    4.16 +  }
    4.17 +
    4.18 +  if(delta) {
    4.19 +    free(delta);
    4.20 +    delta = NULL;
    4.21 +  }
    4.22 +  
    4.23 +  SDL_Quit();
    4.24 +}
    4.25 +
    4.26 +
    4.27 +void step () {
    4.28 +  if(!paused && active) {
    4.29 +    if(debugger && theEmulator.emuHasDebugger)
    4.30 +      dbgMain();
    4.31 +    else {
    4.32 +      //printf("RLM: emulator main\n");
    4.33 +      theEmulator.emuMain(theEmulator.emuCount);
    4.34 +      //printf("RLM: emulator main called\n");
    4.35 +      if(rewindSaveNeeded && rewindMemory && theEmulator.emuWriteMemState) {
    4.36 +	rewindCount++;
    4.37 +	if(rewindCount > 8)
    4.38 +	  rewindCount = 8;
    4.39 +	if(theEmulator.emuWriteMemState &&
    4.40 +	   theEmulator.emuWriteMemState(&rewindMemory[rewindPos*REWIND_SIZE], 
    4.41 +					REWIND_SIZE)) {
    4.42 +	  rewindPos = ++rewindPos & 7;
    4.43 +	  if(rewindCount == 8)
    4.44 +	    rewindTopPos = ++rewindTopPos & 7;
    4.45 +	}
    4.46 +      }
    4.47 +
    4.48 +      rewindSaveNeeded = false;
    4.49 +    }
    4.50 +  } else {
    4.51 +    SDL_Delay(500);
    4.52 +  }
    4.53 +  sdlPollEvents();
    4.54 +  if(mouseCounter) {
    4.55 +    mouseCounter--;
    4.56 +    if(mouseCounter == 0)
    4.57 +      SDL_ShowCursor(SDL_DISABLE);
    4.58 +  }
    4.59 +}
    4.60 +
    4.61  int main(int argc, char **argv)
    4.62  {
    4.63    fprintf(stderr, "VisualBoyAdvance version %s [SDL]\n", PACKAGE_VERSION);
    4.64 @@ -2651,57 +2705,7 @@
    4.65      fprintf (stderr, "I got a filename OMG!\nCalling VBAMovieOpen...\n");
    4.66      VBAMovieOpen(moviefile, true);
    4.67    }
    4.68 -
    4.69 -  while(emulating) {
    4.70 -    if(!paused && active) {
    4.71 -      if(debugger && theEmulator.emuHasDebugger)
    4.72 -        dbgMain();
    4.73 -      else {
    4.74 -	//printf("RLM: emulator main\n");
    4.75 -	theEmulator.emuMain(theEmulator.emuCount);
    4.76 -	//printf("RLM: emulator main called\n");
    4.77 -        if(rewindSaveNeeded && rewindMemory && theEmulator.emuWriteMemState) {
    4.78 -          rewindCount++;
    4.79 -          if(rewindCount > 8)
    4.80 -            rewindCount = 8;
    4.81 -          if(theEmulator.emuWriteMemState &&
    4.82 -             theEmulator.emuWriteMemState(&rewindMemory[rewindPos*REWIND_SIZE], 
    4.83 -                                       REWIND_SIZE)) {
    4.84 -            rewindPos = ++rewindPos & 7;
    4.85 -            if(rewindCount == 8)
    4.86 -              rewindTopPos = ++rewindTopPos & 7;
    4.87 -          }
    4.88 -        }
    4.89 -
    4.90 -        rewindSaveNeeded = false;
    4.91 -      }
    4.92 -    } else {
    4.93 -      SDL_Delay(500);
    4.94 -    }
    4.95 -    sdlPollEvents();
    4.96 -    if(mouseCounter) {
    4.97 -      mouseCounter--;
    4.98 -      if(mouseCounter == 0)
    4.99 -        SDL_ShowCursor(SDL_DISABLE);
   4.100 -    }
   4.101 -  }
   4.102 -  
   4.103 -  emulating = 0;
   4.104 -  fprintf(stderr,"Shutting down\n");
   4.105 -  remoteCleanUp();
   4.106 -  soundShutdown();
   4.107 -
   4.108 -  if(gbRom != NULL || rom != NULL) {
   4.109 -    sdlWriteBattery();
   4.110 -    theEmulator.emuCleanUp();
   4.111 -  }
   4.112 -
   4.113 -  if(delta) {
   4.114 -    free(delta);
   4.115 -    delta = NULL;
   4.116 -  }
   4.117 -  
   4.118 -  SDL_Quit();
   4.119 +  step();
   4.120    return 0;
   4.121  }
   4.122  
   4.123 @@ -2711,6 +2715,11 @@
   4.124  }
   4.125  
   4.126  
   4.127 +
   4.128 +
   4.129 +
   4.130 +
   4.131 +
   4.132  void systemMessage(int num, const char *msg, ...)
   4.133  {
   4.134    char buffer[2048];