annotate src/clojure/clojure.cpp @ 92:1ff2c546f5ad

added tick(), which allows one to step through each opcode of gameboy
author Robert McIntyre <rlm@mit.edu>
date Sun, 11 Mar 2012 19:07:31 -0500
parents 95cb2152d7cd
children 4c60ebca1a9d
rev   line source
rlm@49 1 #include "com_aurellem_gb_Gb.h"
rlm@49 2 #include "../sdl/Drive.h"
rlm@56 3 #include "../gb/GB.h"
rlm@49 4
rlm@49 5 #include <string.h>
rlm@49 6
rlm@49 7 #define UNUSED(x) (void)(x)
rlm@49 8
rlm@49 9
rlm@49 10 /*
rlm@49 11 * Class: com_aurellem_gb_Gb
rlm@49 12 * Method: sayHello
rlm@49 13 * Signature: ()V
rlm@49 14 */
rlm@49 15 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_sayHello
rlm@49 16 (JNIEnv *env, jclass clazz){
rlm@49 17 UNUSED(env);UNUSED(clazz);
rlm@49 18 printf("Hello from GB\n");
rlm@49 19 }
rlm@49 20
rlm@49 21 /*
rlm@49 22 * Class: com_aurellem_gb_Gb
rlm@49 23 * Method: startEmulator
rlm@49 24 * Signature: (Ljava/lang/String;)V
rlm@49 25 */
rlm@49 26 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_startEmulator
rlm@49 27 (JNIEnv *env, jclass clazz, jstring str){
rlm@49 28 UNUSED(env);UNUSED(clazz);UNUSED(str);
rlm@49 29
rlm@49 30 const char *_romName = env->GetStringUTFChars(str, 0);
rlm@49 31 size_t len = strlen(_romName);
rlm@49 32
rlm@49 33 char romName[len + 1];
rlm@49 34
rlm@49 35 strcpy(romName, _romName);
rlm@49 36
rlm@49 37 char* arguments[] = {"vba-rlm", romName};
rlm@49 38 runVBA(2, arguments);
rlm@49 39 }
rlm@49 40
rlm@55 41
rlm@55 42
rlm@55 43
rlm@53 44 /*
rlm@53 45 * Class: com_aurellem_gb_Gb
rlm@53 46 * Method: step
rlm@53 47 * Signature: ()V
rlm@53 48 */
rlm@83 49 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_step
rlm@53 50 (JNIEnv *env, jclass clazz){
rlm@53 51 step();
rlm@53 52 }
rlm@53 53
rlm@53 54 /*
rlm@53 55 * Class: com_aurellem_gb_Gb
rlm@55 56 * Method: step
rlm@55 57 * Signature: (I)V
rlm@55 58 */
rlm@83 59 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_nstep
rlm@55 60 (JNIEnv *env, jclass clazz, jint keymask){
rlm@55 61 step(keymask);
rlm@55 62 }
rlm@55 63
rlm@92 64 /*
rlm@92 65 * Class: com_aurellem_gb_Gb
rlm@92 66 * Method: ntick
rlm@92 67 * Signature: ()I
rlm@92 68 */
rlm@92 69 JNIEXPORT jint JNICALL Java_com_aurellem_gb_Gb_ntick
rlm@92 70 (JNIEnv *env, jclass clazz){
rlm@92 71 return tick();
rlm@55 72
rlm@92 73 }
rlm@55 74
rlm@55 75
rlm@55 76 /*
rlm@55 77 * Class: com_aurellem_gb_Gb
rlm@53 78 * Method: shutdown
rlm@53 79 * Signature: ()V
rlm@53 80 */
rlm@53 81 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_shutdown
rlm@53 82 (JNIEnv *env, jclass clazz){
rlm@53 83 shutdown();
rlm@56 84
rlm@53 85 }
rlm@53 86
rlm@56 87 /*
rlm@56 88 * Class: com_aurellem_gb_Gb
rlm@56 89 * Method: saveState
rlm@76 90 * Signature: (Ljava/nio/ByteBuffer;I)J
rlm@56 91 */
rlm@76 92 JNIEXPORT jlong JNICALL Java_com_aurellem_gb_Gb_saveState
rlm@56 93 (JNIEnv *env, jclass clazz, jobject buffer, jint size){
rlm@56 94 char* buffer_address =
rlm@56 95 ((char*) env->GetDirectBufferAddress(buffer));
rlm@76 96 long limit = gbWriteMemSaveStatePos(buffer_address, size);
rlm@76 97 return limit;
rlm@56 98 }
rlm@53 99
rlm@56 100 /*
rlm@56 101 * Class: com_aurellem_gb_Gb
rlm@56 102 * Method: loadState
rlm@56 103 * Signature: (Ljava/nio/ByteBuffer;)V
rlm@56 104 */
rlm@56 105 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_loadState
rlm@56 106 (JNIEnv *env, jclass clazz, jobject buffer, jint size){
rlm@56 107 char* buffer_address =
rlm@56 108 ((char*) env->GetDirectBufferAddress(buffer));
rlm@56 109 gbReadMemSaveState(buffer_address, size);
rlm@56 110 }
rlm@55 111
rlm@55 112
rlm@59 113 /*
rlm@59 114 * Class: com_aurellem_gb_Gb
rlm@59 115 * Method: getROMSize
rlm@59 116 * Signature: ()I
rlm@59 117 */
rlm@59 118 JNIEXPORT jint JNICALL Java_com_aurellem_gb_Gb_getROMSize
rlm@59 119 (JNIEnv *env, jclass clazz){
rlm@59 120 return getRomSize();
rlm@59 121 }
rlm@55 122
rlm@59 123 /*
rlm@59 124 * Class: com_aurellem_gb_Gb
rlm@59 125 * Method: getRAMSize
rlm@59 126 * Signature: ()I
rlm@59 127 */
rlm@59 128 JNIEXPORT jint JNICALL Java_com_aurellem_gb_Gb_getRAMSize
rlm@59 129 (JNIEnv *env, jclass clazz){
rlm@59 130 return getRamSize();
rlm@59 131 }
rlm@56 132
rlm@60 133 /*
rlm@60 134 * Class: com_aurellem_gb_Gb
rlm@60 135 * Method: getRAM
rlm@60 136 * Signature: ([I)V
rlm@60 137 */
rlm@60 138 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_getRAM
rlm@60 139 (JNIEnv *env, jclass clazz, jintArray arr){
rlm@60 140 jint *ram_store = env->GetIntArrayElements(arr, 0);
rlm@60 141 storeRam(ram_store);
rlm@60 142 env->ReleaseIntArrayElements(arr, ram_store, 0);
rlm@60 143 }
rlm@56 144
rlm@59 145
rlm@61 146 /*
rlm@61 147 * Class: com_aurellem_gb_Gb
rlm@61 148 * Method: getROM
rlm@61 149 * Signature: ([I)V
rlm@61 150 */
rlm@61 151 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_getROM
rlm@61 152 (JNIEnv *env, jclass clazz, jintArray arr){
rlm@61 153 jint *ram_store = env->GetIntArrayElements(arr, 0);
rlm@61 154 storeRom(ram_store);
rlm@61 155 env->ReleaseIntArrayElements(arr, ram_store, 0);
rlm@61 156 }
rlm@59 157
rlm@61 158
rlm@61 159 /*
rlm@61 160 * Class: com_aurellem_gb_Gb
rlm@61 161 * Method: getWRAM
rlm@61 162 * Signature: ([I)V
rlm@61 163 */
rlm@61 164 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_getWRAM
rlm@61 165 (JNIEnv *env, jclass clazz, jintArray arr){
rlm@61 166 jint *ram_store = env->GetIntArrayElements(arr, 0);
rlm@61 167 storeWRam(ram_store);
rlm@61 168 env->ReleaseIntArrayElements(arr, ram_store, 0);
rlm@61 169 }
rlm@61 170
rlm@61 171
rlm@61 172 /*
rlm@61 173 * Class: com_aurellem_gb_Gb
rlm@61 174 * Method: getVRAM
rlm@61 175 * Signature: ([I)V
rlm@61 176 */
rlm@61 177 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_getVRAM
rlm@61 178 (JNIEnv *env, jclass clazz, jintArray arr){
rlm@61 179 jint *ram_store = env->GetIntArrayElements(arr, 0);
rlm@61 180 storeVRam(ram_store);
rlm@61 181 env->ReleaseIntArrayElements(arr, ram_store, 0);
rlm@61 182 }
rlm@61 183
rlm@61 184
rlm@62 185 /*
rlm@62 186 * Class: com_aurellem_gb_Gb
rlm@62 187 * Method: getRegisters
rlm@62 188 * Signature: ([I)V
rlm@62 189 */
rlm@62 190 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_getRegisters
rlm@62 191 (JNIEnv *env, jclass clazz, jintArray arr){
rlm@62 192 jint *registers_store = env->GetIntArrayElements(arr, 0);
rlm@62 193 storeRegisters(registers_store);
rlm@62 194 env->ReleaseIntArrayElements(arr, registers_store, 0);
rlm@62 195 }
rlm@61 196
rlm@62 197