changeset 56:ba4fdfb722ed

emabled loading and saving CPU state from clojure.
author Robert McIntyre <rlm@mit.edu>
date Wed, 07 Mar 2012 14:18:44 -0600
parents 719d910c90f8
children b0473c3a0df0
files java/src/com/aurellem/gb/Gb.java src/clojure/clojure.cpp
diffstat 2 files changed, 49 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/java/src/com/aurellem/gb/Gb.java	Wed Mar 07 13:24:32 2012 -0600
     1.2 +++ b/java/src/com/aurellem/gb/Gb.java	Wed Mar 07 14:18:44 2012 -0600
     1.3 @@ -1,7 +1,7 @@
     1.4  package com.aurellem.gb;
     1.5  
     1.6  import java.nio.ByteBuffer;
     1.7 -
     1.8 +import java.nio.ByteOrder;
     1.9  
    1.10  public class Gb {
    1.11   
    1.12 @@ -25,11 +25,30 @@
    1.13  	System.loadLibrary("vba");
    1.14      }
    1.15  
    1.16 -
    1.17      public static native void step();
    1.18  
    1.19      public static native void step(int keymask);
    1.20  
    1.21      public static native void shutdown();
    1.22  
    1.23 +    public static native void saveState(ByteBuffer buffer, int size);
    1.24 +
    1.25 +    public static native void loadState(ByteBuffer buffer, int size);
    1.26 +
    1.27 +    public static final int SAVE_SIZE = 9000;
    1.28 +
    1.29 +    public static ByteBuffer saveState(){
    1.30 +	ByteBuffer buf = 
    1.31 +	    ByteBuffer.allocateDirect(SAVE_SIZE)
    1.32 +	              .order(ByteOrder.nativeOrder());
    1.33 +	buf.clear();
    1.34 +	saveState(buf, SAVE_SIZE);
    1.35 +	buf.flip();
    1.36 +	return buf;
    1.37 +    }
    1.38 +
    1.39 +    public static void loadState(ByteBuffer saveState){
    1.40 +	loadState(saveState, SAVE_SIZE);
    1.41 +    }
    1.42 +
    1.43  }
     2.1 --- a/src/clojure/clojure.cpp	Wed Mar 07 13:24:32 2012 -0600
     2.2 +++ b/src/clojure/clojure.cpp	Wed Mar 07 14:18:44 2012 -0600
     2.3 @@ -1,5 +1,6 @@
     2.4  #include "com_aurellem_gb_Gb.h"
     2.5  #include "../sdl/Drive.h"
     2.6 +#include "../gb/GB.h"
     2.7  
     2.8  #include <string.h>
     2.9  
    2.10 @@ -72,9 +73,36 @@
    2.11  JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_shutdown
    2.12  (JNIEnv *env, jclass clazz){
    2.13    shutdown();
    2.14 +
    2.15  }
    2.16  
    2.17 +/*
    2.18 + * Class:     com_aurellem_gb_Gb
    2.19 + * Method:    saveState
    2.20 + * Signature: (Ljava/nio/ByteBuffer;)V
    2.21 + */
    2.22 +JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_saveState
    2.23 +(JNIEnv *env, jclass clazz, jobject buffer, jint size){
    2.24 +  char* buffer_address = 
    2.25 +    ((char*) env->GetDirectBufferAddress(buffer));
    2.26 +  gbWriteMemSaveState(buffer_address, size);
    2.27 +}
    2.28  
    2.29 +/*
    2.30 + * Class:     com_aurellem_gb_Gb
    2.31 + * Method:    loadState
    2.32 + * Signature: (Ljava/nio/ByteBuffer;)V
    2.33 + */
    2.34 +JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_loadState
    2.35 +(JNIEnv *env, jclass clazz, jobject buffer, jint size){
    2.36 +  char* buffer_address = 
    2.37 +    ((char*) env->GetDirectBufferAddress(buffer));
    2.38 +  gbReadMemSaveState(buffer_address, size);
    2.39 +}
    2.40  
    2.41  
    2.42  
    2.43 +
    2.44 +
    2.45 +
    2.46 +