view src/clojure/clojure.cpp @ 517:bc24e4d605e9

switched tile and pallette assembly.
author Robert McIntyre <rlm@mit.edu>
date Fri, 22 Jun 2012 21:25:47 -0500
parents a6d060a64246
children 5596cd4a3fc6
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(clazz);
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 }
64 /*
65 * Class: com_aurellem_gb_Gb
66 * Method: ntick
67 * Signature: ()I
68 */
69 JNIEXPORT jint JNICALL Java_com_aurellem_gb_Gb_ntick
70 (JNIEnv *env, jclass clazz){
71 return tick();
73 }
76 /*
77 * Class: com_aurellem_gb_Gb
78 * Method: shutdown
79 * Signature: ()V
80 */
81 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_shutdown
82 (JNIEnv *env, jclass clazz){
83 shutdown();
85 }
87 /*
88 * Class: com_aurellem_gb_Gb
89 * Method: saveState
90 * Signature: (Ljava/nio/ByteBuffer;I)J
91 */
92 JNIEXPORT jlong JNICALL Java_com_aurellem_gb_Gb_saveState
93 (JNIEnv *env, jclass clazz, jobject buffer, jint size){
94 char* buffer_address =
95 ((char*) env->GetDirectBufferAddress(buffer));
96 long limit = gbWriteMemSaveStatePos(buffer_address, size);
97 return limit;
98 }
100 /*
101 * Class: com_aurellem_gb_Gb
102 * Method: loadState
103 * Signature: (Ljava/nio/ByteBuffer;)V
104 */
105 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_loadState
106 (JNIEnv *env, jclass clazz, jobject buffer, jint size){
107 char* buffer_address =
108 ((char*) env->GetDirectBufferAddress(buffer));
109 gbReadMemSaveState(buffer_address, size);
110 }
113 /*
114 * Class: com_aurellem_gb_Gb
115 * Method: getROMSize
116 * Signature: ()I
117 */
118 JNIEXPORT jint JNICALL Java_com_aurellem_gb_Gb_getROMSize
119 (JNIEnv *env, jclass clazz){
120 return getRomSize();
121 }
123 /*
124 * Class: com_aurellem_gb_Gb
125 * Method: getRAMSize
126 * Signature: ()I
127 */
128 JNIEXPORT jint JNICALL Java_com_aurellem_gb_Gb_getRAMSize
129 (JNIEnv *env, jclass clazz){
130 return getRamSize();
131 }
134 /*
135 * Class: com_aurellem_gb_Gb
136 * Method: getMemory
137 * Signature: ([I)V
138 */
139 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_getMemory
140 (JNIEnv *env, jclass clazz, jintArray arr){
141 jint *mem_store = env->GetIntArrayElements(arr, 0);
142 storeMemory(mem_store);
143 env->ReleaseIntArrayElements(arr, mem_store, 0);
144 }
146 /*
147 * Class: com_aurellem_gb_Gb
148 * Method: writeMemory
149 * Signature: ([I)V
150 */
151 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_writeMemory
152 (JNIEnv *env, jclass clazz, jintArray arr){
153 jint *new_memory = env->GetIntArrayElements(arr, 0);
154 writeMemory(new_memory);
155 env->ReleaseIntArrayElements(arr, new_memory, 0);
156 }
159 /*
160 * Class: com_aurellem_gb_Gb
161 * Method: getRAM
162 * Signature: ([I)V
163 */
164 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_getRAM
165 (JNIEnv *env, jclass clazz, jintArray arr){
166 jint *ram_store = env->GetIntArrayElements(arr, 0);
167 storeRam(ram_store);
168 env->ReleaseIntArrayElements(arr, ram_store, 0);
169 }
172 /*
173 * Class: com_aurellem_gb_Gb
174 * Method: getROM
175 * Signature: ([I)V
176 */
177 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_getROM
178 (JNIEnv *env, jclass clazz, jintArray arr){
179 jint *rom_store = env->GetIntArrayElements(arr, 0);
180 storeRom(rom_store);
181 env->ReleaseIntArrayElements(arr, rom_store, 0);
182 }
185 /*
186 * Class: com_aurellem_gb_Gb
187 * Method: writeROM
188 * Signature: ([I)V
189 */
190 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_writeROM
191 (JNIEnv *env, jclass clazz, jintArray arr){
192 jint *new_rom = env->GetIntArrayElements(arr, 0);
193 writeRom(new_rom);
194 env->ReleaseIntArrayElements(arr, new_rom, 0);
195 }
199 /*
200 * Class: com_aurellem_gb_Gb
201 * Method: getWRAM
202 * Signature: ([I)V
203 */
204 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_getWRAM
205 (JNIEnv *env, jclass clazz, jintArray arr){
206 jint *ram_store = env->GetIntArrayElements(arr, 0);
207 storeWRam(ram_store);
208 env->ReleaseIntArrayElements(arr, ram_store, 0);
209 }
212 /*
213 * Class: com_aurellem_gb_Gb
214 * Method: getVRAM
215 * Signature: ([I)V
216 */
217 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_getVRAM
218 (JNIEnv *env, jclass clazz, jintArray arr){
219 jint *ram_store = env->GetIntArrayElements(arr, 0);
220 storeVRam(ram_store);
221 env->ReleaseIntArrayElements(arr, ram_store, 0);
222 }
225 /*
226 * Class: com_aurellem_gb_Gb
227 * Method: getRegisters
228 * Signature: ([I)V
229 */
230 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_getRegisters
231 (JNIEnv *env, jclass clazz, jintArray arr){
232 jint *registers_store = env->GetIntArrayElements(arr, 0);
233 storeRegisters(registers_store);
234 env->ReleaseIntArrayElements(arr, registers_store, 0);
235 }
238 /*
239 * Class: com_aurellem_gb_Gb
240 * Method: writeRegisters
241 * Signature: ([I)V
242 */
243 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_writeRegisters
244 (JNIEnv *env, jclass clazz, jintArray arr){
245 jint *new_registers = env->GetIntArrayElements(arr, 0);
246 setRegisters(new_registers);
247 env->ReleaseIntArrayElements(arr, new_registers, 0);
248 }
251 int intensity[32] = {
252 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x5e, 0x6c, 0x7a, 0x88, 0x94,
253 0xa0, 0xae, 0xb7, 0xbf, 0xc6, 0xce, 0xd3, 0xd9, 0xdf, 0xe3, 0xe7,
254 0xeb, 0xef, 0xf3, 0xf6, 0xf9, 0xfb, 0xfd, 0xfe, 0xff, 0xff };
256 int influence[3][3] =
257 {
258 {16,4,4},
259 {8,16,8},
260 {0,8,16}
261 };
263 int* translateRGB(int* rgb, int* store){
265 int m[3][3];
266 int i,j;
268 for (i=0;i<3;i++){
269 for (j=0;j<3;j++){
270 m[i][j] = (intensity[rgb[i]>>3]*influence[i][j]) >> 5;}}
272 for (i=0;i<3;i++)
273 {
274 if (m[0][i]>m[1][i])
275 {
276 j=m[0][i];
277 m[0][i]=m[1][i];
278 m[1][i]=j;
279 }
281 if (m[1][i]>m[2][i])
282 {
283 j=m[1][i];
284 m[1][i]=m[2][i];
285 m[2][i]=j;
286 }
288 if (m[0][i]>m[1][i])
289 {
290 j=m[0][i];
291 m[0][i]=m[1][i];
292 m[1][i]=j;
293 }
295 store[i]=(((m[0][i]+m[1][i]*2+m[2][i]*4)*5) >> 4)+32;
296 }
297 return store;
298 }
300 /*
301 * Class: com_aurellem_gb_Gb
302 * Method: translateRGB
303 * Signature: ([I[I)V
304 */
305 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_translateRGB
306 (JNIEnv *env, jclass clazz, jintArray rgb, jintArray store){
307 jint *RGB_Arr = env->GetIntArrayElements(rgb, 0);
308 jint *store_Arr = env->GetIntArrayElements(store,0);
309 translateRGB(RGB_Arr, store_Arr);
310 env->ReleaseIntArrayElements(rgb, RGB_Arr, 0);
311 env->ReleaseIntArrayElements(store, store_Arr, 0);
312 }
315 /*
316 * Class: com_aurellem_gb_Gb
317 * Method: getPixels
318 * Signature: ([I)V
319 */
320 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_getPixels
321 (JNIEnv *env, jclass clazz, jintArray arr){
322 jint *pixel_store = env->GetIntArrayElements(arr, 0);
323 getPixels32(pixel_store);
324 env->ReleaseIntArrayElements(arr, pixel_store, 0);
325 }
327 /*
328 * Class: com_aurellem_gb_Gb
329 * Method: nwritePNG
330 * Signature: (Ljava/lang/String;)V
331 */
332 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_nwritePNG
333 (JNIEnv *env, jclass clazz, jstring filename){
334 const char *_filename = env->GetStringUTFChars(filename, 0);
335 gbWritePNGFile(_filename);
336 }