annotate src/clojure/clojure.cpp @ 595:96ee9d72aeb9

saving progress.... sleepy time :)
author Robert McIntyre <rlm@mit.edu>
date Sat, 01 Sep 2012 13:32:19 -0500
parents fa7676dbf6f2
children
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@522 5
rlm@49 6 #include <string.h>
rlm@49 7
rlm@49 8 #define UNUSED(x) (void)(x)
rlm@49 9
rlm@49 10
rlm@49 11 /*
rlm@49 12 * Class: com_aurellem_gb_Gb
rlm@49 13 * Method: sayHello
rlm@49 14 * Signature: ()V
rlm@49 15 */
rlm@49 16 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_sayHello
rlm@49 17 (JNIEnv *env, jclass clazz){
rlm@49 18 UNUSED(env);UNUSED(clazz);
rlm@49 19 printf("Hello from GB\n");
rlm@49 20 }
rlm@49 21
rlm@49 22 /*
rlm@49 23 * Class: com_aurellem_gb_Gb
rlm@49 24 * Method: startEmulator
rlm@49 25 * Signature: (Ljava/lang/String;)V
rlm@49 26 */
rlm@49 27 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_startEmulator
rlm@49 28 (JNIEnv *env, jclass clazz, jstring str){
rlm@488 29 UNUSED(clazz);
rlm@49 30
rlm@49 31 const char *_romName = env->GetStringUTFChars(str, 0);
rlm@49 32 size_t len = strlen(_romName);
rlm@49 33
rlm@49 34 char romName[len + 1];
rlm@49 35
rlm@49 36 strcpy(romName, _romName);
rlm@49 37
rlm@49 38 char* arguments[] = {"vba-rlm", romName};
rlm@49 39 runVBA(2, arguments);
rlm@49 40 }
rlm@49 41
rlm@55 42
rlm@55 43
rlm@55 44
rlm@53 45 /*
rlm@53 46 * Class: com_aurellem_gb_Gb
rlm@53 47 * Method: step
rlm@53 48 * Signature: ()V
rlm@53 49 */
rlm@83 50 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_step
rlm@53 51 (JNIEnv *env, jclass clazz){
rlm@53 52 step();
rlm@53 53 }
rlm@53 54
rlm@53 55 /*
rlm@53 56 * Class: com_aurellem_gb_Gb
rlm@55 57 * Method: step
rlm@55 58 * Signature: (I)V
rlm@55 59 */
rlm@83 60 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_nstep
rlm@55 61 (JNIEnv *env, jclass clazz, jint keymask){
rlm@55 62 step(keymask);
rlm@55 63 }
rlm@55 64
rlm@92 65 /*
rlm@92 66 * Class: com_aurellem_gb_Gb
rlm@92 67 * Method: ntick
rlm@92 68 * Signature: ()I
rlm@92 69 */
rlm@92 70 JNIEXPORT jint JNICALL Java_com_aurellem_gb_Gb_ntick
rlm@92 71 (JNIEnv *env, jclass clazz){
rlm@92 72 return tick();
rlm@55 73
rlm@92 74 }
rlm@55 75
rlm@55 76
rlm@55 77 /*
rlm@55 78 * Class: com_aurellem_gb_Gb
rlm@53 79 * Method: shutdown
rlm@53 80 * Signature: ()V
rlm@53 81 */
rlm@53 82 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_shutdown
rlm@53 83 (JNIEnv *env, jclass clazz){
rlm@53 84 shutdown();
rlm@56 85
rlm@53 86 }
rlm@53 87
rlm@56 88 /*
rlm@56 89 * Class: com_aurellem_gb_Gb
rlm@56 90 * Method: saveState
rlm@76 91 * Signature: (Ljava/nio/ByteBuffer;I)J
rlm@56 92 */
rlm@76 93 JNIEXPORT jlong JNICALL Java_com_aurellem_gb_Gb_saveState
rlm@56 94 (JNIEnv *env, jclass clazz, jobject buffer, jint size){
rlm@56 95 char* buffer_address =
rlm@56 96 ((char*) env->GetDirectBufferAddress(buffer));
rlm@76 97 long limit = gbWriteMemSaveStatePos(buffer_address, size);
rlm@76 98 return limit;
rlm@56 99 }
rlm@53 100
rlm@56 101 /*
rlm@56 102 * Class: com_aurellem_gb_Gb
rlm@56 103 * Method: loadState
rlm@56 104 * Signature: (Ljava/nio/ByteBuffer;)V
rlm@56 105 */
rlm@56 106 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_loadState
rlm@56 107 (JNIEnv *env, jclass clazz, jobject buffer, jint size){
rlm@56 108 char* buffer_address =
rlm@56 109 ((char*) env->GetDirectBufferAddress(buffer));
rlm@56 110 gbReadMemSaveState(buffer_address, size);
rlm@56 111 }
rlm@55 112
rlm@55 113
rlm@59 114 /*
rlm@59 115 * Class: com_aurellem_gb_Gb
rlm@59 116 * Method: getROMSize
rlm@59 117 * Signature: ()I
rlm@59 118 */
rlm@59 119 JNIEXPORT jint JNICALL Java_com_aurellem_gb_Gb_getROMSize
rlm@59 120 (JNIEnv *env, jclass clazz){
rlm@59 121 return getRomSize();
rlm@59 122 }
rlm@55 123
rlm@59 124 /*
rlm@59 125 * Class: com_aurellem_gb_Gb
rlm@59 126 * Method: getRAMSize
rlm@59 127 * Signature: ()I
rlm@59 128 */
rlm@59 129 JNIEXPORT jint JNICALL Java_com_aurellem_gb_Gb_getRAMSize
rlm@59 130 (JNIEnv *env, jclass clazz){
rlm@59 131 return getRamSize();
rlm@59 132 }
rlm@56 133
rlm@93 134
rlm@93 135 /*
rlm@93 136 * Class: com_aurellem_gb_Gb
rlm@93 137 * Method: getMemory
rlm@93 138 * Signature: ([I)V
rlm@93 139 */
rlm@93 140 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_getMemory
rlm@93 141 (JNIEnv *env, jclass clazz, jintArray arr){
rlm@93 142 jint *mem_store = env->GetIntArrayElements(arr, 0);
rlm@93 143 storeMemory(mem_store);
rlm@93 144 env->ReleaseIntArrayElements(arr, mem_store, 0);
rlm@93 145 }
rlm@93 146
rlm@96 147 /*
rlm@96 148 * Class: com_aurellem_gb_Gb
rlm@96 149 * Method: writeMemory
rlm@96 150 * Signature: ([I)V
rlm@96 151 */
rlm@96 152 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_writeMemory
rlm@96 153 (JNIEnv *env, jclass clazz, jintArray arr){
rlm@96 154 jint *new_memory = env->GetIntArrayElements(arr, 0);
rlm@96 155 writeMemory(new_memory);
rlm@96 156 env->ReleaseIntArrayElements(arr, new_memory, 0);
rlm@96 157 }
rlm@96 158
rlm@93 159
rlm@60 160 /*
rlm@60 161 * Class: com_aurellem_gb_Gb
rlm@60 162 * Method: getRAM
rlm@60 163 * Signature: ([I)V
rlm@60 164 */
rlm@60 165 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_getRAM
rlm@60 166 (JNIEnv *env, jclass clazz, jintArray arr){
rlm@60 167 jint *ram_store = env->GetIntArrayElements(arr, 0);
rlm@60 168 storeRam(ram_store);
rlm@60 169 env->ReleaseIntArrayElements(arr, ram_store, 0);
rlm@60 170 }
rlm@56 171
rlm@59 172
rlm@61 173 /*
rlm@61 174 * Class: com_aurellem_gb_Gb
rlm@61 175 * Method: getROM
rlm@61 176 * Signature: ([I)V
rlm@61 177 */
rlm@61 178 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_getROM
rlm@61 179 (JNIEnv *env, jclass clazz, jintArray arr){
rlm@93 180 jint *rom_store = env->GetIntArrayElements(arr, 0);
rlm@93 181 storeRom(rom_store);
rlm@93 182 env->ReleaseIntArrayElements(arr, rom_store, 0);
rlm@61 183 }
rlm@59 184
rlm@61 185
rlm@61 186 /*
rlm@61 187 * Class: com_aurellem_gb_Gb
rlm@191 188 * Method: writeROM
rlm@191 189 * Signature: ([I)V
rlm@191 190 */
rlm@191 191 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_writeROM
rlm@191 192 (JNIEnv *env, jclass clazz, jintArray arr){
rlm@191 193 jint *new_rom = env->GetIntArrayElements(arr, 0);
rlm@191 194 writeRom(new_rom);
rlm@191 195 env->ReleaseIntArrayElements(arr, new_rom, 0);
rlm@191 196 }
rlm@191 197
rlm@191 198
rlm@191 199
rlm@191 200 /*
rlm@191 201 * Class: com_aurellem_gb_Gb
rlm@61 202 * Method: getWRAM
rlm@61 203 * Signature: ([I)V
rlm@61 204 */
rlm@61 205 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_getWRAM
rlm@61 206 (JNIEnv *env, jclass clazz, jintArray arr){
rlm@61 207 jint *ram_store = env->GetIntArrayElements(arr, 0);
rlm@61 208 storeWRam(ram_store);
rlm@61 209 env->ReleaseIntArrayElements(arr, ram_store, 0);
rlm@61 210 }
rlm@61 211
rlm@61 212
rlm@61 213 /*
rlm@61 214 * Class: com_aurellem_gb_Gb
rlm@61 215 * Method: getVRAM
rlm@61 216 * Signature: ([I)V
rlm@61 217 */
rlm@61 218 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_getVRAM
rlm@61 219 (JNIEnv *env, jclass clazz, jintArray arr){
rlm@61 220 jint *ram_store = env->GetIntArrayElements(arr, 0);
rlm@61 221 storeVRam(ram_store);
rlm@61 222 env->ReleaseIntArrayElements(arr, ram_store, 0);
rlm@61 223 }
rlm@61 224
rlm@61 225
rlm@62 226 /*
rlm@62 227 * Class: com_aurellem_gb_Gb
rlm@62 228 * Method: getRegisters
rlm@62 229 * Signature: ([I)V
rlm@62 230 */
rlm@62 231 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_getRegisters
rlm@62 232 (JNIEnv *env, jclass clazz, jintArray arr){
rlm@62 233 jint *registers_store = env->GetIntArrayElements(arr, 0);
rlm@62 234 storeRegisters(registers_store);
rlm@62 235 env->ReleaseIntArrayElements(arr, registers_store, 0);
rlm@62 236 }
rlm@61 237
rlm@62 238
rlm@100 239 /*
rlm@100 240 * Class: com_aurellem_gb_Gb
rlm@100 241 * Method: writeRegisters
rlm@100 242 * Signature: ([I)V
rlm@100 243 */
rlm@100 244 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_writeRegisters
rlm@100 245 (JNIEnv *env, jclass clazz, jintArray arr){
rlm@100 246 jint *new_registers = env->GetIntArrayElements(arr, 0);
rlm@100 247 setRegisters(new_registers);
rlm@100 248 env->ReleaseIntArrayElements(arr, new_registers, 0);
rlm@100 249 }
rlm@100 250
rlm@488 251
rlm@488 252 int intensity[32] = {
rlm@488 253 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x5e, 0x6c, 0x7a, 0x88, 0x94,
rlm@488 254 0xa0, 0xae, 0xb7, 0xbf, 0xc6, 0xce, 0xd3, 0xd9, 0xdf, 0xe3, 0xe7,
rlm@488 255 0xeb, 0xef, 0xf3, 0xf6, 0xf9, 0xfb, 0xfd, 0xfe, 0xff, 0xff };
rlm@488 256
rlm@488 257 int influence[3][3] =
rlm@488 258 {
rlm@488 259 {16,4,4},
rlm@488 260 {8,16,8},
rlm@488 261 {0,8,16}
rlm@488 262 };
rlm@488 263
rlm@488 264 int* translateRGB(int* rgb, int* store){
rlm@488 265
rlm@488 266 int m[3][3];
rlm@488 267 int i,j;
rlm@488 268
rlm@488 269 for (i=0;i<3;i++){
rlm@488 270 for (j=0;j<3;j++){
rlm@488 271 m[i][j] = (intensity[rgb[i]>>3]*influence[i][j]) >> 5;}}
rlm@488 272
rlm@488 273 for (i=0;i<3;i++)
rlm@488 274 {
rlm@488 275 if (m[0][i]>m[1][i])
rlm@488 276 {
rlm@488 277 j=m[0][i];
rlm@488 278 m[0][i]=m[1][i];
rlm@488 279 m[1][i]=j;
rlm@488 280 }
rlm@488 281
rlm@488 282 if (m[1][i]>m[2][i])
rlm@488 283 {
rlm@488 284 j=m[1][i];
rlm@488 285 m[1][i]=m[2][i];
rlm@488 286 m[2][i]=j;
rlm@488 287 }
rlm@488 288
rlm@488 289 if (m[0][i]>m[1][i])
rlm@488 290 {
rlm@488 291 j=m[0][i];
rlm@488 292 m[0][i]=m[1][i];
rlm@488 293 m[1][i]=j;
rlm@488 294 }
rlm@488 295
rlm@488 296 store[i]=(((m[0][i]+m[1][i]*2+m[2][i]*4)*5) >> 4)+32;
rlm@488 297 }
rlm@488 298 return store;
rlm@488 299 }
rlm@488 300
rlm@488 301 /*
rlm@488 302 * Class: com_aurellem_gb_Gb
rlm@488 303 * Method: translateRGB
rlm@488 304 * Signature: ([I[I)V
rlm@488 305 */
rlm@488 306 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_translateRGB
rlm@488 307 (JNIEnv *env, jclass clazz, jintArray rgb, jintArray store){
rlm@488 308 jint *RGB_Arr = env->GetIntArrayElements(rgb, 0);
rlm@488 309 jint *store_Arr = env->GetIntArrayElements(store,0);
rlm@488 310 translateRGB(RGB_Arr, store_Arr);
rlm@488 311 env->ReleaseIntArrayElements(rgb, RGB_Arr, 0);
rlm@488 312 env->ReleaseIntArrayElements(store, store_Arr, 0);
rlm@488 313 }
rlm@496 314
rlm@496 315
rlm@496 316 /*
rlm@496 317 * Class: com_aurellem_gb_Gb
rlm@496 318 * Method: getPixels
rlm@496 319 * Signature: ([I)V
rlm@496 320 */
rlm@496 321 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_getPixels
rlm@496 322 (JNIEnv *env, jclass clazz, jintArray arr){
rlm@496 323 jint *pixel_store = env->GetIntArrayElements(arr, 0);
rlm@496 324 getPixels32(pixel_store);
rlm@496 325 env->ReleaseIntArrayElements(arr, pixel_store, 0);
rlm@496 326 }
rlm@496 327
rlm@496 328 /*
rlm@496 329 * Class: com_aurellem_gb_Gb
rlm@496 330 * Method: nwritePNG
rlm@496 331 * Signature: (Ljava/lang/String;)V
rlm@496 332 */
rlm@496 333 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_nwritePNG
rlm@496 334 (JNIEnv *env, jclass clazz, jstring filename){
rlm@496 335 const char *_filename = env->GetStringUTFChars(filename, 0);
rlm@496 336 gbWritePNGFile(_filename);
rlm@496 337 }
rlm@496 338
rlm@496 339
rlm@522 340
rlm@522 341 /*
rlm@522 342 * Class: com_aurellem_gb_Gb
rlm@522 343 * Method: readMemory
rlm@522 344 * Signature: (I)I
rlm@522 345 */
rlm@522 346 JNIEXPORT jint JNICALL Java_com_aurellem_gb_Gb_readMemory
rlm@522 347 (JNIEnv *env, jclass clazz, jint address){
rlm@522 348 return (jint) gbReadMemory((u16) address);
rlm@522 349 }
rlm@523 350
rlm@523 351 /*
rlm@523 352 * Class: com_aurellem_gb_Gb
rlm@523 353 * Method: getFrameSound
rlm@524 354 * Signature: ([B)V
rlm@523 355 */
rlm@523 356 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_getFrameSound
rlm@524 357 (JNIEnv *env, jclass clazz, jbyteArray arr){
rlm@524 358 jbyte *sound_store = env->GetByteArrayElements(arr, 0);
rlm@523 359 int i;
rlm@524 360
rlm@524 361
rlm@524 362 u8* soundBytes = (u8*) soundFrameSound;
rlm@524 363 for (i = 0; i < 44100*2; i++){
rlm@524 364 sound_store[i] = (jbyte) soundBytes[i];
rlm@523 365 }
rlm@524 366
rlm@524 367 /*
rlm@525 368 u8* soundBytes = (u8*) soundFinalWave;
rlm@525 369 for (i = 0; i < 1470*2 ; i++){
rlm@524 370 sound_store[i] = (jbyte) soundBytes[i];
rlm@525 371 }
rlm@524 372 */
rlm@524 373
rlm@524 374 env->ReleaseByteArrayElements(arr, sound_store, 0);
rlm@523 375 }
rlm@523 376
rlm@523 377
rlm@523 378 /*
rlm@523 379 * Class: com_aurellem_gb_Gb
rlm@523 380 * Method: getSoundFrameWritten
rlm@523 381 * Signature: ()I
rlm@523 382 */
rlm@523 383 JNIEXPORT jint JNICALL Java_com_aurellem_gb_Gb_getSoundFrameWritten
rlm@523 384 (JNIEnv *env, jclass clazz){
rlm@523 385 return soundFrameSoundWritten;
rlm@523 386 }
rlm@523 387
rlm@523 388 /*
rlm@523 389 * Class: com_aurellem_gb_Gb
rlm@523 390 * Method: setSoundFrameWritten
rlm@523 391 * Signature: (I)V
rlm@523 392 */
rlm@523 393 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_setSoundFrameWritten
rlm@523 394 (JNIEnv *env, jclass clazz , jint newSoundFrameWritten){
rlm@523 395 soundFrameSoundWritten = newSoundFrameWritten;
rlm@523 396 }
rlm@523 397
rlm@525 398
rlm@525 399 /*
rlm@525 400 * Class: com_aurellem_gb_Gb
rlm@525 401 * Method: getFrameSound2
rlm@525 402 * Signature: ([B)V
rlm@525 403 */
rlm@525 404 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_getFrameSound2
rlm@525 405 (JNIEnv *env, jclass clazz, jbyteArray arr){
rlm@525 406 setbuf(stdout, NULL);
rlm@525 407
rlm@525 408 jbyte *sound_store = env->GetByteArrayElements(arr, 0);
rlm@525 409 int i;
rlm@525 410
rlm@525 411 for (i = 0; i < 1470*2; i++){
rlm@525 412 sound_store[i] = (jbyte) soundCopyBuffer[i];
rlm@525 413 }
rlm@525 414
rlm@525 415 env->ReleaseByteArrayElements(arr, sound_store, 0);
rlm@525 416
rlm@525 417 }