view src/clojure/clojure.cpp @ 84:26f002f2868c

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