changeset 93:4c60ebca1a9d

added function to get all the GB's memory.
author Robert McIntyre <rlm@mit.edu>
date Sun, 11 Mar 2012 20:16:09 -0500
parents 1ff2c546f5ad
children 612393a0d3a0
files clojure/com/aurellem/gb_driver.clj java/src/com/aurellem/gb/Gb.java src/clojure/clojure.cpp src/gb/GB.cpp src/gb/GB.h
diffstat 5 files changed, 41 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/gb_driver.clj	Sun Mar 11 19:07:31 2012 -0500
     1.2 +++ b/clojure/com/aurellem/gb_driver.clj	Sun Mar 11 20:16:09 2012 -0500
     1.3 @@ -130,17 +130,18 @@
     1.4  
     1.5  ;;;;;;;;;;;;;;; CPU data
     1.6  
     1.7 -
     1.8 -
     1.9  (defn cpu-data [size arr-fn]
    1.10    (let [store (int-array size)]
    1.11      (fn [state] (set-state! state) (arr-fn store) store)))
    1.12  
    1.13 +(def memory
    1.14 +  (cpu-date Gb/GB_MEMORY #(Gb/getMemory %)))
    1.15 +
    1.16  (def ram
    1.17 -  (cpu-data (Gb/getRAMSize) #(Gb/getRAM %)))
    1.18 +  (cpu-data Gb/RAM_SIZE #(Gb/getRAM %)))
    1.19  
    1.20  (def rom 
    1.21 -  (cpu-data (Gb/getROMSize) #(Gb/getROM %)))
    1.22 +  (cpu-data Gb/ROM_SIZE #(Gb/getROM %)))
    1.23  
    1.24  (def working-ram 
    1.25    (cpu-data Gb/WRAM_SIZE #(Gb/getWRAM %)))
     2.1 --- a/java/src/com/aurellem/gb/Gb.java	Sun Mar 11 19:07:31 2012 -0500
     2.2 +++ b/java/src/com/aurellem/gb/Gb.java	Sun Mar 11 20:16:09 2012 -0500
     2.3 @@ -93,9 +93,17 @@
     2.4      public static final int WRAM_SIZE = 0x8000;
     2.5  
     2.6      public static final int VRAM_SIZE = 0x4000;
     2.7 +    
     2.8 +    public static final int RAM_SIZE = 0x8000;
     2.9 +    
    2.10 +    public static final int ROM_SIZE = 0x100000;
    2.11  
    2.12      public static final int NUM_REGISTERS = 27;
    2.13  
    2.14 +    public static final int GB_MEMORY = 0x10000;
    2.15 +
    2.16 +    public static native void getMemory(int[] store);
    2.17 +
    2.18      public static native void getRAM(int[] store);
    2.19  
    2.20      public static native void getROM(int[] store);
     3.1 --- a/src/clojure/clojure.cpp	Sun Mar 11 19:07:31 2012 -0500
     3.2 +++ b/src/clojure/clojure.cpp	Sun Mar 11 20:16:09 2012 -0500
     3.3 @@ -130,6 +130,20 @@
     3.4    return getRamSize();
     3.5  }
     3.6  
     3.7 +
     3.8 +/*
     3.9 + * Class:     com_aurellem_gb_Gb
    3.10 + * Method:    getMemory
    3.11 + * Signature: ([I)V
    3.12 + */
    3.13 +JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_getMemory
    3.14 +(JNIEnv *env, jclass clazz, jintArray arr){
    3.15 +  jint *mem_store = env->GetIntArrayElements(arr, 0);
    3.16 +  storeMemory(mem_store);
    3.17 +  env->ReleaseIntArrayElements(arr, mem_store, 0);
    3.18 +}
    3.19 +
    3.20 +
    3.21  /*
    3.22   * Class:     com_aurellem_gb_Gb
    3.23   * Method:    getRAM
    3.24 @@ -150,9 +164,9 @@
    3.25   */
    3.26  JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_getROM
    3.27  (JNIEnv *env, jclass clazz, jintArray arr){
    3.28 -  jint *ram_store = env->GetIntArrayElements(arr, 0);
    3.29 -  storeRom(ram_store);
    3.30 -  env->ReleaseIntArrayElements(arr, ram_store, 0);
    3.31 +  jint *rom_store = env->GetIntArrayElements(arr, 0);
    3.32 +  storeRom(rom_store);
    3.33 +  env->ReleaseIntArrayElements(arr, rom_store, 0);
    3.34  }
    3.35  
    3.36  
     4.1 --- a/src/gb/GB.cpp	Sun Mar 11 19:07:31 2012 -0500
     4.2 +++ b/src/gb/GB.cpp	Sun Mar 11 20:16:09 2012 -0500
     4.3 @@ -46,7 +46,7 @@
     4.4  // mappers
     4.5  void (*mapper)(u16, u8)	   = NULL;
     4.6  void (*mapperRAM)(u16, u8) = NULL;
     4.7 -u8	 (*mapperReadRAM)(u16) = NULL;
     4.8 +u8   (*mapperReadRAM)(u16) = NULL;
     4.9  
    4.10  // registers
    4.11  gbRegister PC;
    4.12 @@ -55,7 +55,7 @@
    4.13  gbRegister BC;
    4.14  gbRegister DE;
    4.15  gbRegister HL;
    4.16 -u16		   IFF;
    4.17 +u16        IFF;
    4.18  // 0xff04
    4.19  u8 register_DIV = 0;
    4.20  // 0xff05
    4.21 @@ -3886,6 +3886,13 @@
    4.22    return gbRomSize;
    4.23  }
    4.24  
    4.25 +void storeMemory(int32* store){
    4.26 +  int i;
    4.27 +  for (i = 0; i < 0xFFFF; i++){
    4.28 +    store[i] = (int32) gbMemory[i];
    4.29 +  }
    4.30 +}
    4.31 +
    4.32  void storeRam(int32* store){
    4.33    int i;
    4.34    for (i = 0; i < gbRamSize; i++){
     5.1 --- a/src/gb/GB.h	Sun Mar 11 19:07:31 2012 -0500
     5.2 +++ b/src/gb/GB.h	Sun Mar 11 20:16:09 2012 -0500
     5.3 @@ -46,6 +46,8 @@
     5.4  
     5.5  extern int getRamSize();
     5.6  extern int getRomSize();
     5.7 +
     5.8 +extern void storeMemory(int32 *);
     5.9  extern void storeRam(int32 *);
    5.10  extern void storeRom(int32 *);
    5.11  extern void storeWRam(int32 *);