changeset 96:cb487c4ce5c0

added write-memory!, which allows me to write any value to the gameboy's memory-mapped rom or ram.
author Robert McIntyre <rlm@mit.edu>
date Sun, 11 Mar 2012 23:27:19 -0500
parents b74a578d0c88
children abb5add24b26
files clojure/com/aurellem/gb_driver.clj clojure/com/aurellem/inspect.clj java/src/com/aurellem/gb/Gb.java src/clojure/clojure.cpp src/gb/GB.cpp src/gb/GB.h
diffstat 6 files changed, 53 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/gb_driver.clj	Sun Mar 11 23:10:44 2012 -0500
     1.2 +++ b/clojure/com/aurellem/gb_driver.clj	Sun Mar 11 23:27:19 2012 -0500
     1.3 @@ -155,6 +155,13 @@
     1.4  (def registers
     1.5    (cpu-data Gb/NUM_REGISTERS #(Gb/getRegisters %)))
     1.6  
     1.7 +
     1.8 +(defn write-memory! [new-memory]
     1.9 +  (let [store (int-array new-memory)]
    1.10 +    (assert (= Gb/GB_MEMORY) (count new-memory))
    1.11 +    (Gb/writeMemory new-memory)))
    1.12 +    
    1.13 +
    1.14  ;; TODO add register names
    1.15  
    1.16  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
     2.1 --- a/clojure/com/aurellem/inspect.clj	Sun Mar 11 23:10:44 2012 -0500
     2.2 +++ b/clojure/com/aurellem/inspect.clj	Sun Mar 11 23:27:19 2012 -0500
     2.3 @@ -37,27 +37,27 @@
     2.4  
     2.5  ;; trying to find how items are represented in memory
     2.6  
     2.7 -(def empty-inventory @current-state)
     2.8 +(comment
     2.9 +  (def empty-inventory @current-state)
    2.10 +  
    2.11 +  (def one-potion @current-state)
    2.12 +  
    2.13 +  (def two-potions @current-state)
    2.14 +  
    2.15 +  (def three-potions @current-state)
    2.16 +  
    2.17 +  (def four-potions @current-state)
    2.18 +  
    2.19 +  (def five-potions @current-state)
    2.20 +  
    2.21 +  
    2.22 +  ;; result
    2.23 +  (def canidates
    2.24 +    (apply common-differences
    2.25 +           (map (comp vec memory)
    2.26 +                [empty-inventory one-potion two-potions three-potions
    2.27 +                 four-potions five-potions])))
    2.28  
    2.29 -(def one-potion @current-state)
    2.30 -
    2.31 -(def two-potions @current-state)
    2.32 -
    2.33 -(def three-potions @current-state)
    2.34 -
    2.35 -(def four-potions @current-state)
    2.36 -
    2.37 -(def five-potions @current-state)
    2.38 -  
    2.39 -
    2.40 -;; result
    2.41 -(def canidates
    2.42 -  (apply common-differences
    2.43 -         (map (comp vec memory)
    2.44 -              [empty-inventory one-potion two-potions three-potions
    2.45 -               four-potions five-potions])))
    2.46 -
    2.47 -(comment
    2.48    [55875 (37 15 49 27 14 44)]
    2.49    [55876 (30 1 49 56 55 23)]
    2.50    [49158 (154 191 78 135 70 73)]
     3.1 --- a/java/src/com/aurellem/gb/Gb.java	Sun Mar 11 23:10:44 2012 -0500
     3.2 +++ b/java/src/com/aurellem/gb/Gb.java	Sun Mar 11 23:27:19 2012 -0500
     3.3 @@ -104,6 +104,8 @@
     3.4  
     3.5      public static native void getMemory(int[] store);
     3.6  
     3.7 +    public static native void writeMemory(int[] newMemory);
     3.8 +
     3.9      public static native void getRAM(int[] store);
    3.10  
    3.11      public static native void getROM(int[] store);
     4.1 --- a/src/clojure/clojure.cpp	Sun Mar 11 23:10:44 2012 -0500
     4.2 +++ b/src/clojure/clojure.cpp	Sun Mar 11 23:27:19 2012 -0500
     4.3 @@ -143,6 +143,18 @@
     4.4    env->ReleaseIntArrayElements(arr, mem_store, 0);
     4.5  }
     4.6  
     4.7 +/*
     4.8 + * Class:     com_aurellem_gb_Gb
     4.9 + * Method:    writeMemory
    4.10 + * Signature: ([I)V
    4.11 + */
    4.12 +JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_writeMemory
    4.13 +(JNIEnv *env, jclass clazz, jintArray arr){
    4.14 +  jint *new_memory = env->GetIntArrayElements(arr, 0);
    4.15 +  writeMemory(new_memory);
    4.16 +  env->ReleaseIntArrayElements(arr, new_memory, 0);
    4.17 +}
    4.18 +
    4.19  
    4.20  /*
    4.21   * Class:     com_aurellem_gb_Gb
     5.1 --- a/src/gb/GB.cpp	Sun Mar 11 23:10:44 2012 -0500
     5.2 +++ b/src/gb/GB.cpp	Sun Mar 11 23:27:19 2012 -0500
     5.3 @@ -3896,6 +3896,16 @@
     5.4    }
     5.5  }
     5.6  
     5.7 +void writeMemory(int32* newMemory){
     5.8 +  int i;
     5.9 +  int j;
    5.10 +  for (i = 0; i < 0x10; i++){
    5.11 +    for (j = 0; j< 0x1000; j++){
    5.12 +      gbMemoryMap[i][j] = (u8)(0xFF & newMemory[i*0x1000 + j]);
    5.13 +    }
    5.14 +  }
    5.15 +}
    5.16 +
    5.17  void storeRam(int32* store){
    5.18    int i;
    5.19    for (i = 0; i < gbRamSize; i++){
     6.1 --- a/src/gb/GB.h	Sun Mar 11 23:10:44 2012 -0500
     6.2 +++ b/src/gb/GB.h	Sun Mar 11 23:27:19 2012 -0500
     6.3 @@ -48,6 +48,8 @@
     6.4  extern int getRomSize();
     6.5  
     6.6  extern void storeMemory(int32 *);
     6.7 +extern void writeMemory(int32 *);
     6.8 +
     6.9  extern void storeRam(int32 *);
    6.10  extern void storeRom(int32 *);
    6.11  extern void storeWRam(int32 *);