# HG changeset patch # User Robert McIntyre # Date 1331172621 21600 # Node ID 4699c7bab77d4d66c955ffabede52e86866cc4c6 # Parent dc8b383ecefa34eb9d3b290ca07612d62c284c3e added code to retrieve CPU registers diff -r dc8b383ecefa -r 4699c7bab77d clojure/com/aurellem/gb_driver.clj --- a/clojure/com/aurellem/gb_driver.clj Wed Mar 07 19:53:39 2012 -0600 +++ b/clojure/com/aurellem/gb_driver.clj Wed Mar 07 20:10:21 2012 -0600 @@ -2,19 +2,16 @@ (:import com.aurellem.gb.Gb) (:import (java.nio IntBuffer ByteOrder))) - -(defn init-vba [] +(defn vba-init [] (Gb/loadVBA) (future (Gb/startEmulator "/home/r/proj/pokemon-escape/roms/yellow.gbc"))) - (defn get-ram [] (let [ram-store (int-array (Gb/getRAMSize))] (Gb/getRAM ram-store) ram-store)) - (defn get-rom [] (let [rom-store (int-array (Gb/getROMSize))] (Gb/getRAM rom-store) @@ -28,4 +25,9 @@ (defn get-video-ram [] (let [ram-store (int-array Gb/VRAM_SIZE)] (Gb/getVRAM ram-store) - ram-store)) \ No newline at end of file + ram-store)) + +(defn get-registers [] + (let [register-store (int-array Gb/NUM_REGISTERS)] + (Gb/getRegisters register-store) + register-store)) \ No newline at end of file diff -r dc8b383ecefa -r 4699c7bab77d java/src/com/aurellem/gb/Gb.java --- a/java/src/com/aurellem/gb/Gb.java Wed Mar 07 19:53:39 2012 -0600 +++ b/java/src/com/aurellem/gb/Gb.java Wed Mar 07 20:10:21 2012 -0600 @@ -60,6 +60,8 @@ public static final int VRAM_SIZE = 0x4000; + public static final int NUM_REGISTERS = 27; + public static native void getRAM(int[] store); public static native void getROM(int[] store); @@ -67,5 +69,6 @@ public static native void getWRAM(int[] store); public static native void getVRAM(int[] store); - + + public static native void getRegisters(int[] store); } diff -r dc8b383ecefa -r 4699c7bab77d org/todo.org --- a/org/todo.org Wed Mar 07 19:53:39 2012 -0600 +++ b/org/todo.org Wed Mar 07 20:10:21 2012 -0600 @@ -7,15 +7,15 @@ ** additional functionality - [X] step the simulator - - [ ] get CPU data + - [X] get CPU data (registers) - [X] get RAM / ROM data - [X] save / load state (use savestates) - - [ ] write current frame - - [ ] write sound + - [ ] write current frame as image + - [ ] write sound to wav file - [X] send button presses to the GB * high level - - [ ] write vbm files + - [ ] write vbm files from clojure - [ ] remove battery backup files @@ -33,6 +33,5 @@ getFrame() --- returns a BufferedImage of data which represents the current frame. - step(int buttons) --- steps the game while pressing the chosen button(s) diff -r dc8b383ecefa -r 4699c7bab77d src/clojure/clojure.cpp --- a/src/clojure/clojure.cpp Wed Mar 07 19:53:39 2012 -0600 +++ b/src/clojure/clojure.cpp Wed Mar 07 20:10:21 2012 -0600 @@ -173,4 +173,16 @@ } +/* + * Class: com_aurellem_gb_Gb + * Method: getRegisters + * Signature: ([I)V + */ +JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_getRegisters +(JNIEnv *env, jclass clazz, jintArray arr){ + jint *registers_store = env->GetIntArrayElements(arr, 0); + storeRegisters(registers_store); + env->ReleaseIntArrayElements(arr, registers_store, 0); +} + diff -r dc8b383ecefa -r 4699c7bab77d src/gb/GB.cpp --- a/src/gb/GB.cpp Wed Mar 07 19:53:39 2012 -0600 +++ b/src/gb/GB.cpp Wed Mar 07 20:10:21 2012 -0600 @@ -3899,9 +3899,36 @@ } } - - - +void storeRegisters(int32* store){ + store[0] = (int32) PC.W; + store[1] = (int32) SP.W; + store[2] = (int32) AF.W; + store[3] = (int32) BC.W; + store[4] = (int32) DE.W; + store[5] = (int32) HL.W; + store[6] = (int32) register_DIV; + store[7] = (int32) register_TIMA; + store[8] = (int32) register_TMA; + store[9] = (int32) register_TAC; + store[10] = (int32) register_IF; + store[11] = (int32) register_LCDC; + store[12] = (int32) register_STAT; + store[13] = (int32) register_SCY; + store[14] = (int32) register_SCX; + store[15] = (int32) register_LY; + store[16] = (int32) register_LYC; + store[17] = (int32) register_DMA; + store[18] = (int32) register_WY; + store[19] = (int32) register_WX; + store[20] = (int32) register_VBK; + store[21] = (int32) register_HDMA1; + store[22] = (int32) register_HDMA2; + store[23] = (int32) register_HDMA3; + store[24] = (int32) register_HDMA4; + store[25] = (int32) register_HDMA5; + store[26] = (int32) register_SVBK; + store[27] = (int32) register_IE; +} struct EmulatedSystem GBSystem = { diff -r dc8b383ecefa -r 4699c7bab77d src/gb/GB.h --- a/src/gb/GB.h Wed Mar 07 19:53:39 2012 -0600 +++ b/src/gb/GB.h Wed Mar 07 20:10:21 2012 -0600 @@ -50,6 +50,7 @@ extern void storeRom(int32 *); extern void storeWRam(int32 *); extern void storeVRam(int32 *); +extern void storeRegisters(int32 *); extern struct EmulatedSystem GBSystem; extern struct EmulatedSystemCounters &GBSystemCounters;