annotate 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
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@488 28 UNUSED(clazz);
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@93 133
rlm@93 134 /*
rlm@93 135 * Class: com_aurellem_gb_Gb
rlm@93 136 * Method: getMemory
rlm@93 137 * Signature: ([I)V
rlm@93 138 */
rlm@93 139 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_getMemory
rlm@93 140 (JNIEnv *env, jclass clazz, jintArray arr){
rlm@93 141 jint *mem_store = env->GetIntArrayElements(arr, 0);
rlm@93 142 storeMemory(mem_store);
rlm@93 143 env->ReleaseIntArrayElements(arr, mem_store, 0);
rlm@93 144 }
rlm@93 145
rlm@96 146 /*
rlm@96 147 * Class: com_aurellem_gb_Gb
rlm@96 148 * Method: writeMemory
rlm@96 149 * Signature: ([I)V
rlm@96 150 */
rlm@96 151 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_writeMemory
rlm@96 152 (JNIEnv *env, jclass clazz, jintArray arr){
rlm@96 153 jint *new_memory = env->GetIntArrayElements(arr, 0);
rlm@96 154 writeMemory(new_memory);
rlm@96 155 env->ReleaseIntArrayElements(arr, new_memory, 0);
rlm@96 156 }
rlm@96 157
rlm@93 158
rlm@60 159 /*
rlm@60 160 * Class: com_aurellem_gb_Gb
rlm@60 161 * Method: getRAM
rlm@60 162 * Signature: ([I)V
rlm@60 163 */
rlm@60 164 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_getRAM
rlm@60 165 (JNIEnv *env, jclass clazz, jintArray arr){
rlm@60 166 jint *ram_store = env->GetIntArrayElements(arr, 0);
rlm@60 167 storeRam(ram_store);
rlm@60 168 env->ReleaseIntArrayElements(arr, ram_store, 0);
rlm@60 169 }
rlm@56 170
rlm@59 171
rlm@61 172 /*
rlm@61 173 * Class: com_aurellem_gb_Gb
rlm@61 174 * Method: getROM
rlm@61 175 * Signature: ([I)V
rlm@61 176 */
rlm@61 177 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_getROM
rlm@61 178 (JNIEnv *env, jclass clazz, jintArray arr){
rlm@93 179 jint *rom_store = env->GetIntArrayElements(arr, 0);
rlm@93 180 storeRom(rom_store);
rlm@93 181 env->ReleaseIntArrayElements(arr, rom_store, 0);
rlm@61 182 }
rlm@59 183
rlm@61 184
rlm@61 185 /*
rlm@61 186 * Class: com_aurellem_gb_Gb
rlm@191 187 * Method: writeROM
rlm@191 188 * Signature: ([I)V
rlm@191 189 */
rlm@191 190 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_writeROM
rlm@191 191 (JNIEnv *env, jclass clazz, jintArray arr){
rlm@191 192 jint *new_rom = env->GetIntArrayElements(arr, 0);
rlm@191 193 writeRom(new_rom);
rlm@191 194 env->ReleaseIntArrayElements(arr, new_rom, 0);
rlm@191 195 }
rlm@191 196
rlm@191 197
rlm@191 198
rlm@191 199 /*
rlm@191 200 * Class: com_aurellem_gb_Gb
rlm@61 201 * Method: getWRAM
rlm@61 202 * Signature: ([I)V
rlm@61 203 */
rlm@61 204 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_getWRAM
rlm@61 205 (JNIEnv *env, jclass clazz, jintArray arr){
rlm@61 206 jint *ram_store = env->GetIntArrayElements(arr, 0);
rlm@61 207 storeWRam(ram_store);
rlm@61 208 env->ReleaseIntArrayElements(arr, ram_store, 0);
rlm@61 209 }
rlm@61 210
rlm@61 211
rlm@61 212 /*
rlm@61 213 * Class: com_aurellem_gb_Gb
rlm@61 214 * Method: getVRAM
rlm@61 215 * Signature: ([I)V
rlm@61 216 */
rlm@61 217 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_getVRAM
rlm@61 218 (JNIEnv *env, jclass clazz, jintArray arr){
rlm@61 219 jint *ram_store = env->GetIntArrayElements(arr, 0);
rlm@61 220 storeVRam(ram_store);
rlm@61 221 env->ReleaseIntArrayElements(arr, ram_store, 0);
rlm@61 222 }
rlm@61 223
rlm@61 224
rlm@62 225 /*
rlm@62 226 * Class: com_aurellem_gb_Gb
rlm@62 227 * Method: getRegisters
rlm@62 228 * Signature: ([I)V
rlm@62 229 */
rlm@62 230 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_getRegisters
rlm@62 231 (JNIEnv *env, jclass clazz, jintArray arr){
rlm@62 232 jint *registers_store = env->GetIntArrayElements(arr, 0);
rlm@62 233 storeRegisters(registers_store);
rlm@62 234 env->ReleaseIntArrayElements(arr, registers_store, 0);
rlm@62 235 }
rlm@61 236
rlm@62 237
rlm@100 238 /*
rlm@100 239 * Class: com_aurellem_gb_Gb
rlm@100 240 * Method: writeRegisters
rlm@100 241 * Signature: ([I)V
rlm@100 242 */
rlm@100 243 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_writeRegisters
rlm@100 244 (JNIEnv *env, jclass clazz, jintArray arr){
rlm@100 245 jint *new_registers = env->GetIntArrayElements(arr, 0);
rlm@100 246 setRegisters(new_registers);
rlm@100 247 env->ReleaseIntArrayElements(arr, new_registers, 0);
rlm@100 248 }
rlm@100 249
rlm@488 250
rlm@488 251 int intensity[32] = {
rlm@488 252 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x5e, 0x6c, 0x7a, 0x88, 0x94,
rlm@488 253 0xa0, 0xae, 0xb7, 0xbf, 0xc6, 0xce, 0xd3, 0xd9, 0xdf, 0xe3, 0xe7,
rlm@488 254 0xeb, 0xef, 0xf3, 0xf6, 0xf9, 0xfb, 0xfd, 0xfe, 0xff, 0xff };
rlm@488 255
rlm@488 256 int influence[3][3] =
rlm@488 257 {
rlm@488 258 {16,4,4},
rlm@488 259 {8,16,8},
rlm@488 260 {0,8,16}
rlm@488 261 };
rlm@488 262
rlm@488 263 int* translateRGB(int* rgb, int* store){
rlm@488 264
rlm@488 265 int m[3][3];
rlm@488 266 int i,j;
rlm@488 267
rlm@488 268 for (i=0;i<3;i++){
rlm@488 269 for (j=0;j<3;j++){
rlm@488 270 m[i][j] = (intensity[rgb[i]>>3]*influence[i][j]) >> 5;}}
rlm@488 271
rlm@488 272 for (i=0;i<3;i++)
rlm@488 273 {
rlm@488 274 if (m[0][i]>m[1][i])
rlm@488 275 {
rlm@488 276 j=m[0][i];
rlm@488 277 m[0][i]=m[1][i];
rlm@488 278 m[1][i]=j;
rlm@488 279 }
rlm@488 280
rlm@488 281 if (m[1][i]>m[2][i])
rlm@488 282 {
rlm@488 283 j=m[1][i];
rlm@488 284 m[1][i]=m[2][i];
rlm@488 285 m[2][i]=j;
rlm@488 286 }
rlm@488 287
rlm@488 288 if (m[0][i]>m[1][i])
rlm@488 289 {
rlm@488 290 j=m[0][i];
rlm@488 291 m[0][i]=m[1][i];
rlm@488 292 m[1][i]=j;
rlm@488 293 }
rlm@488 294
rlm@488 295 store[i]=(((m[0][i]+m[1][i]*2+m[2][i]*4)*5) >> 4)+32;
rlm@488 296 }
rlm@488 297 return store;
rlm@488 298 }
rlm@488 299
rlm@488 300 /*
rlm@488 301 * Class: com_aurellem_gb_Gb
rlm@488 302 * Method: translateRGB
rlm@488 303 * Signature: ([I[I)V
rlm@488 304 */
rlm@488 305 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_translateRGB
rlm@488 306 (JNIEnv *env, jclass clazz, jintArray rgb, jintArray store){
rlm@488 307 jint *RGB_Arr = env->GetIntArrayElements(rgb, 0);
rlm@488 308 jint *store_Arr = env->GetIntArrayElements(store,0);
rlm@488 309 translateRGB(RGB_Arr, store_Arr);
rlm@488 310 env->ReleaseIntArrayElements(rgb, RGB_Arr, 0);
rlm@488 311 env->ReleaseIntArrayElements(store, store_Arr, 0);
rlm@488 312 }
rlm@496 313
rlm@496 314
rlm@496 315 /*
rlm@496 316 * Class: com_aurellem_gb_Gb
rlm@496 317 * Method: getPixels
rlm@496 318 * Signature: ([I)V
rlm@496 319 */
rlm@496 320 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_getPixels
rlm@496 321 (JNIEnv *env, jclass clazz, jintArray arr){
rlm@496 322 jint *pixel_store = env->GetIntArrayElements(arr, 0);
rlm@496 323 getPixels32(pixel_store);
rlm@496 324 env->ReleaseIntArrayElements(arr, pixel_store, 0);
rlm@496 325 }
rlm@496 326
rlm@496 327 /*
rlm@496 328 * Class: com_aurellem_gb_Gb
rlm@496 329 * Method: nwritePNG
rlm@496 330 * Signature: (Ljava/lang/String;)V
rlm@496 331 */
rlm@496 332 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_nwritePNG
rlm@496 333 (JNIEnv *env, jclass clazz, jstring filename){
rlm@496 334 const char *_filename = env->GetStringUTFChars(filename, 0);
rlm@496 335 gbWritePNGFile(_filename);
rlm@496 336 }
rlm@496 337
rlm@496 338