Mercurial > vba-clojure
view src/clojure/clojure.cpp @ 542:614eddc5b38c
working on generating first major video.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Mon, 25 Jun 2012 16:08:56 -0500 |
parents | fa7676dbf6f2 |
children |
line wrap: on
line source
1 #include "com_aurellem_gb_Gb.h"2 #include "../sdl/Drive.h"3 #include "../gb/GB.h"6 #include <string.h>8 #define UNUSED(x) (void)(x)11 /*12 * Class: com_aurellem_gb_Gb13 * Method: sayHello14 * Signature: ()V15 */16 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_sayHello17 (JNIEnv *env, jclass clazz){18 UNUSED(env);UNUSED(clazz);19 printf("Hello from GB\n");20 }22 /*23 * Class: com_aurellem_gb_Gb24 * Method: startEmulator25 * Signature: (Ljava/lang/String;)V26 */27 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_startEmulator28 (JNIEnv *env, jclass clazz, jstring str){29 UNUSED(clazz);31 const char *_romName = env->GetStringUTFChars(str, 0);32 size_t len = strlen(_romName);34 char romName[len + 1];36 strcpy(romName, _romName);38 char* arguments[] = {"vba-rlm", romName};39 runVBA(2, arguments);40 }45 /*46 * Class: com_aurellem_gb_Gb47 * Method: step48 * Signature: ()V49 */50 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_step51 (JNIEnv *env, jclass clazz){52 step();53 }55 /*56 * Class: com_aurellem_gb_Gb57 * Method: step58 * Signature: (I)V59 */60 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_nstep61 (JNIEnv *env, jclass clazz, jint keymask){62 step(keymask);63 }65 /*66 * Class: com_aurellem_gb_Gb67 * Method: ntick68 * Signature: ()I69 */70 JNIEXPORT jint JNICALL Java_com_aurellem_gb_Gb_ntick71 (JNIEnv *env, jclass clazz){72 return tick();74 }77 /*78 * Class: com_aurellem_gb_Gb79 * Method: shutdown80 * Signature: ()V81 */82 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_shutdown83 (JNIEnv *env, jclass clazz){84 shutdown();86 }88 /*89 * Class: com_aurellem_gb_Gb90 * Method: saveState91 * Signature: (Ljava/nio/ByteBuffer;I)J92 */93 JNIEXPORT jlong JNICALL Java_com_aurellem_gb_Gb_saveState94 (JNIEnv *env, jclass clazz, jobject buffer, jint size){95 char* buffer_address =96 ((char*) env->GetDirectBufferAddress(buffer));97 long limit = gbWriteMemSaveStatePos(buffer_address, size);98 return limit;99 }101 /*102 * Class: com_aurellem_gb_Gb103 * Method: loadState104 * Signature: (Ljava/nio/ByteBuffer;)V105 */106 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_loadState107 (JNIEnv *env, jclass clazz, jobject buffer, jint size){108 char* buffer_address =109 ((char*) env->GetDirectBufferAddress(buffer));110 gbReadMemSaveState(buffer_address, size);111 }114 /*115 * Class: com_aurellem_gb_Gb116 * Method: getROMSize117 * Signature: ()I118 */119 JNIEXPORT jint JNICALL Java_com_aurellem_gb_Gb_getROMSize120 (JNIEnv *env, jclass clazz){121 return getRomSize();122 }124 /*125 * Class: com_aurellem_gb_Gb126 * Method: getRAMSize127 * Signature: ()I128 */129 JNIEXPORT jint JNICALL Java_com_aurellem_gb_Gb_getRAMSize130 (JNIEnv *env, jclass clazz){131 return getRamSize();132 }135 /*136 * Class: com_aurellem_gb_Gb137 * Method: getMemory138 * Signature: ([I)V139 */140 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_getMemory141 (JNIEnv *env, jclass clazz, jintArray arr){142 jint *mem_store = env->GetIntArrayElements(arr, 0);143 storeMemory(mem_store);144 env->ReleaseIntArrayElements(arr, mem_store, 0);145 }147 /*148 * Class: com_aurellem_gb_Gb149 * Method: writeMemory150 * Signature: ([I)V151 */152 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_writeMemory153 (JNIEnv *env, jclass clazz, jintArray arr){154 jint *new_memory = env->GetIntArrayElements(arr, 0);155 writeMemory(new_memory);156 env->ReleaseIntArrayElements(arr, new_memory, 0);157 }160 /*161 * Class: com_aurellem_gb_Gb162 * Method: getRAM163 * Signature: ([I)V164 */165 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_getRAM166 (JNIEnv *env, jclass clazz, jintArray arr){167 jint *ram_store = env->GetIntArrayElements(arr, 0);168 storeRam(ram_store);169 env->ReleaseIntArrayElements(arr, ram_store, 0);170 }173 /*174 * Class: com_aurellem_gb_Gb175 * Method: getROM176 * Signature: ([I)V177 */178 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_getROM179 (JNIEnv *env, jclass clazz, jintArray arr){180 jint *rom_store = env->GetIntArrayElements(arr, 0);181 storeRom(rom_store);182 env->ReleaseIntArrayElements(arr, rom_store, 0);183 }186 /*187 * Class: com_aurellem_gb_Gb188 * Method: writeROM189 * Signature: ([I)V190 */191 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_writeROM192 (JNIEnv *env, jclass clazz, jintArray arr){193 jint *new_rom = env->GetIntArrayElements(arr, 0);194 writeRom(new_rom);195 env->ReleaseIntArrayElements(arr, new_rom, 0);196 }200 /*201 * Class: com_aurellem_gb_Gb202 * Method: getWRAM203 * Signature: ([I)V204 */205 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_getWRAM206 (JNIEnv *env, jclass clazz, jintArray arr){207 jint *ram_store = env->GetIntArrayElements(arr, 0);208 storeWRam(ram_store);209 env->ReleaseIntArrayElements(arr, ram_store, 0);210 }213 /*214 * Class: com_aurellem_gb_Gb215 * Method: getVRAM216 * Signature: ([I)V217 */218 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_getVRAM219 (JNIEnv *env, jclass clazz, jintArray arr){220 jint *ram_store = env->GetIntArrayElements(arr, 0);221 storeVRam(ram_store);222 env->ReleaseIntArrayElements(arr, ram_store, 0);223 }226 /*227 * Class: com_aurellem_gb_Gb228 * Method: getRegisters229 * Signature: ([I)V230 */231 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_getRegisters232 (JNIEnv *env, jclass clazz, jintArray arr){233 jint *registers_store = env->GetIntArrayElements(arr, 0);234 storeRegisters(registers_store);235 env->ReleaseIntArrayElements(arr, registers_store, 0);236 }239 /*240 * Class: com_aurellem_gb_Gb241 * Method: writeRegisters242 * Signature: ([I)V243 */244 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_writeRegisters245 (JNIEnv *env, jclass clazz, jintArray arr){246 jint *new_registers = env->GetIntArrayElements(arr, 0);247 setRegisters(new_registers);248 env->ReleaseIntArrayElements(arr, new_registers, 0);249 }252 int intensity[32] = {253 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x5e, 0x6c, 0x7a, 0x88, 0x94,254 0xa0, 0xae, 0xb7, 0xbf, 0xc6, 0xce, 0xd3, 0xd9, 0xdf, 0xe3, 0xe7,255 0xeb, 0xef, 0xf3, 0xf6, 0xf9, 0xfb, 0xfd, 0xfe, 0xff, 0xff };257 int influence[3][3] =258 {259 {16,4,4},260 {8,16,8},261 {0,8,16}262 };264 int* translateRGB(int* rgb, int* store){266 int m[3][3];267 int i,j;269 for (i=0;i<3;i++){270 for (j=0;j<3;j++){271 m[i][j] = (intensity[rgb[i]>>3]*influence[i][j]) >> 5;}}273 for (i=0;i<3;i++)274 {275 if (m[0][i]>m[1][i])276 {277 j=m[0][i];278 m[0][i]=m[1][i];279 m[1][i]=j;280 }282 if (m[1][i]>m[2][i])283 {284 j=m[1][i];285 m[1][i]=m[2][i];286 m[2][i]=j;287 }289 if (m[0][i]>m[1][i])290 {291 j=m[0][i];292 m[0][i]=m[1][i];293 m[1][i]=j;294 }296 store[i]=(((m[0][i]+m[1][i]*2+m[2][i]*4)*5) >> 4)+32;297 }298 return store;299 }301 /*302 * Class: com_aurellem_gb_Gb303 * Method: translateRGB304 * Signature: ([I[I)V305 */306 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_translateRGB307 (JNIEnv *env, jclass clazz, jintArray rgb, jintArray store){308 jint *RGB_Arr = env->GetIntArrayElements(rgb, 0);309 jint *store_Arr = env->GetIntArrayElements(store,0);310 translateRGB(RGB_Arr, store_Arr);311 env->ReleaseIntArrayElements(rgb, RGB_Arr, 0);312 env->ReleaseIntArrayElements(store, store_Arr, 0);313 }316 /*317 * Class: com_aurellem_gb_Gb318 * Method: getPixels319 * Signature: ([I)V320 */321 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_getPixels322 (JNIEnv *env, jclass clazz, jintArray arr){323 jint *pixel_store = env->GetIntArrayElements(arr, 0);324 getPixels32(pixel_store);325 env->ReleaseIntArrayElements(arr, pixel_store, 0);326 }328 /*329 * Class: com_aurellem_gb_Gb330 * Method: nwritePNG331 * Signature: (Ljava/lang/String;)V332 */333 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_nwritePNG334 (JNIEnv *env, jclass clazz, jstring filename){335 const char *_filename = env->GetStringUTFChars(filename, 0);336 gbWritePNGFile(_filename);337 }341 /*342 * Class: com_aurellem_gb_Gb343 * Method: readMemory344 * Signature: (I)I345 */346 JNIEXPORT jint JNICALL Java_com_aurellem_gb_Gb_readMemory347 (JNIEnv *env, jclass clazz, jint address){348 return (jint) gbReadMemory((u16) address);349 }351 /*352 * Class: com_aurellem_gb_Gb353 * Method: getFrameSound354 * Signature: ([B)V355 */356 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_getFrameSound357 (JNIEnv *env, jclass clazz, jbyteArray arr){358 jbyte *sound_store = env->GetByteArrayElements(arr, 0);359 int i;362 u8* soundBytes = (u8*) soundFrameSound;363 for (i = 0; i < 44100*2; i++){364 sound_store[i] = (jbyte) soundBytes[i];365 }367 /*368 u8* soundBytes = (u8*) soundFinalWave;369 for (i = 0; i < 1470*2 ; i++){370 sound_store[i] = (jbyte) soundBytes[i];371 }372 */374 env->ReleaseByteArrayElements(arr, sound_store, 0);375 }378 /*379 * Class: com_aurellem_gb_Gb380 * Method: getSoundFrameWritten381 * Signature: ()I382 */383 JNIEXPORT jint JNICALL Java_com_aurellem_gb_Gb_getSoundFrameWritten384 (JNIEnv *env, jclass clazz){385 return soundFrameSoundWritten;386 }388 /*389 * Class: com_aurellem_gb_Gb390 * Method: setSoundFrameWritten391 * Signature: (I)V392 */393 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_setSoundFrameWritten394 (JNIEnv *env, jclass clazz , jint newSoundFrameWritten){395 soundFrameSoundWritten = newSoundFrameWritten;396 }399 /*400 * Class: com_aurellem_gb_Gb401 * Method: getFrameSound2402 * Signature: ([B)V403 */404 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_getFrameSound2405 (JNIEnv *env, jclass clazz, jbyteArray arr){406 setbuf(stdout, NULL);408 jbyte *sound_store = env->GetByteArrayElements(arr, 0);409 int i;411 for (i = 0; i < 1470*2; i++){412 sound_store[i] = (jbyte) soundCopyBuffer[i];413 }415 env->ReleaseByteArrayElements(arr, sound_store, 0);417 }