changeset 62:4699c7bab77d

added code to retrieve CPU registers
author Robert McIntyre <rlm@mit.edu>
date Wed, 07 Mar 2012 20:10:21 -0600
parents dc8b383ecefa
children c44cf1f5954c
files clojure/com/aurellem/gb_driver.clj java/src/com/aurellem/gb/Gb.java org/todo.org src/clojure/clojure.cpp src/gb/GB.cpp src/gb/GB.h
diffstat 6 files changed, 58 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/gb_driver.clj	Wed Mar 07 19:53:39 2012 -0600
     1.2 +++ b/clojure/com/aurellem/gb_driver.clj	Wed Mar 07 20:10:21 2012 -0600
     1.3 @@ -2,19 +2,16 @@
     1.4    (:import com.aurellem.gb.Gb)
     1.5    (:import (java.nio IntBuffer ByteOrder)))
     1.6  
     1.7 -
     1.8 -(defn init-vba []
     1.9 +(defn vba-init []
    1.10    (Gb/loadVBA)
    1.11    (future
    1.12      (Gb/startEmulator "/home/r/proj/pokemon-escape/roms/yellow.gbc")))
    1.13  
    1.14 -
    1.15  (defn get-ram []
    1.16    (let [ram-store (int-array (Gb/getRAMSize))]
    1.17      (Gb/getRAM ram-store)
    1.18      ram-store))
    1.19  
    1.20 -
    1.21  (defn get-rom []
    1.22    (let [rom-store (int-array (Gb/getROMSize))]
    1.23      (Gb/getRAM rom-store)
    1.24 @@ -28,4 +25,9 @@
    1.25  (defn get-video-ram []
    1.26    (let [ram-store (int-array Gb/VRAM_SIZE)]
    1.27      (Gb/getVRAM ram-store)
    1.28 -    ram-store))
    1.29 \ No newline at end of file
    1.30 +    ram-store))
    1.31 +
    1.32 +(defn get-registers []
    1.33 +  (let [register-store (int-array Gb/NUM_REGISTERS)]
    1.34 +    (Gb/getRegisters register-store)
    1.35 +    register-store))
    1.36 \ No newline at end of file
     2.1 --- a/java/src/com/aurellem/gb/Gb.java	Wed Mar 07 19:53:39 2012 -0600
     2.2 +++ b/java/src/com/aurellem/gb/Gb.java	Wed Mar 07 20:10:21 2012 -0600
     2.3 @@ -60,6 +60,8 @@
     2.4  
     2.5      public static final int VRAM_SIZE = 0x4000;
     2.6  
     2.7 +    public static final int NUM_REGISTERS = 27;
     2.8 +
     2.9      public static native void getRAM(int[] store);
    2.10  
    2.11      public static native void getROM(int[] store);
    2.12 @@ -67,5 +69,6 @@
    2.13      public static native void getWRAM(int[] store);
    2.14  
    2.15      public static native void getVRAM(int[] store);
    2.16 -
    2.17 +    
    2.18 +    public static native void getRegisters(int[] store);
    2.19  }
     3.1 --- a/org/todo.org	Wed Mar 07 19:53:39 2012 -0600
     3.2 +++ b/org/todo.org	Wed Mar 07 20:10:21 2012 -0600
     3.3 @@ -7,15 +7,15 @@
     3.4  
     3.5  ** additional functionality
     3.6   - [X] step the simulator
     3.7 - - [ ] get CPU data
     3.8 + - [X] get CPU data (registers)
     3.9   - [X] get RAM / ROM data
    3.10   - [X] save / load state (use savestates)
    3.11 - - [ ] write current frame
    3.12 - - [ ] write sound
    3.13 + - [ ] write current frame as image
    3.14 + - [ ] write sound to wav file
    3.15   - [X] send button presses to the GB
    3.16  
    3.17  * high level
    3.18 - - [ ] write vbm files
    3.19 + - [ ] write vbm files from clojure
    3.20   - [ ] remove battery backup files
    3.21  
    3.22  
    3.23 @@ -33,6 +33,5 @@
    3.24  getFrame() --- returns a BufferedImage of data which represents the
    3.25  current frame.
    3.26  
    3.27 -
    3.28  step(int buttons) --- steps the game while pressing the chosen button(s)
    3.29  
     4.1 --- a/src/clojure/clojure.cpp	Wed Mar 07 19:53:39 2012 -0600
     4.2 +++ b/src/clojure/clojure.cpp	Wed Mar 07 20:10:21 2012 -0600
     4.3 @@ -173,4 +173,16 @@
     4.4  }
     4.5  
     4.6  
     4.7 +/*
     4.8 + * Class:     com_aurellem_gb_Gb
     4.9 + * Method:    getRegisters
    4.10 + * Signature: ([I)V
    4.11 + */
    4.12 +JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_getRegisters
    4.13 +(JNIEnv *env, jclass clazz, jintArray arr){
    4.14 +  jint *registers_store = env->GetIntArrayElements(arr, 0);
    4.15 +  storeRegisters(registers_store);
    4.16 +  env->ReleaseIntArrayElements(arr, registers_store, 0);
    4.17 +}
    4.18  
    4.19 +
     5.1 --- a/src/gb/GB.cpp	Wed Mar 07 19:53:39 2012 -0600
     5.2 +++ b/src/gb/GB.cpp	Wed Mar 07 20:10:21 2012 -0600
     5.3 @@ -3899,9 +3899,36 @@
     5.4    }
     5.5  }
     5.6  
     5.7 -
     5.8 -
     5.9 -
    5.10 +void storeRegisters(int32* store){
    5.11 +  store[0] = (int32) PC.W;
    5.12 +  store[1] = (int32) SP.W;
    5.13 +  store[2] = (int32) AF.W;
    5.14 +  store[3] = (int32) BC.W;
    5.15 +  store[4] = (int32) DE.W;
    5.16 +  store[5] = (int32) HL.W;
    5.17 +  store[6] = (int32) register_DIV;
    5.18 +  store[7] = (int32) register_TIMA;
    5.19 +  store[8] = (int32) register_TMA;
    5.20 +  store[9] = (int32) register_TAC;
    5.21 +  store[10] = (int32) register_IF;
    5.22 +  store[11] = (int32) register_LCDC;
    5.23 +  store[12] = (int32) register_STAT;
    5.24 +  store[13] = (int32) register_SCY;
    5.25 +  store[14] = (int32) register_SCX;
    5.26 +  store[15] = (int32) register_LY;
    5.27 +  store[16] = (int32) register_LYC;
    5.28 +  store[17] = (int32) register_DMA;
    5.29 +  store[18] = (int32) register_WY;
    5.30 +  store[19] = (int32) register_WX;
    5.31 +  store[20] = (int32) register_VBK;
    5.32 +  store[21] = (int32) register_HDMA1;
    5.33 +  store[22] = (int32) register_HDMA2;
    5.34 +  store[23] = (int32) register_HDMA3;
    5.35 +  store[24] = (int32) register_HDMA4;
    5.36 +  store[25] = (int32) register_HDMA5;
    5.37 +  store[26] = (int32) register_SVBK;
    5.38 +  store[27] = (int32) register_IE;
    5.39 +}
    5.40  
    5.41  struct EmulatedSystem GBSystem =
    5.42    {
     6.1 --- a/src/gb/GB.h	Wed Mar 07 19:53:39 2012 -0600
     6.2 +++ b/src/gb/GB.h	Wed Mar 07 20:10:21 2012 -0600
     6.3 @@ -50,6 +50,7 @@
     6.4  extern void storeRom(int32 *);
     6.5  extern void storeWRam(int32 *);
     6.6  extern void storeVRam(int32 *);
     6.7 +extern void storeRegisters(int32 *);
     6.8  
     6.9  extern struct EmulatedSystem GBSystem;
    6.10  extern struct EmulatedSystemCounters &GBSystemCounters;