JNIEXPORT void JNICALL Java_uk_org_cardboardbox_wonderdroid_WonderSwan_load(JNIEnv * env, jclass obj, jstring filename, jboolean iswsc, jstring name, jint year, jint month, jint day, jint blood, jint sex) { if (iswsc) { LOGD("Emulating a WonderSwan Color"); wsc = 1; wsVMode = 0x7; } else { wsVMode = 0x0; } // char convertedfilename[] = filename; char temp[512]; const jbyte *str; str = (*env)->GetStringUTFChars(env, filename, NULL); if (str == NULL) { //return NULL; /* OutOfMemoryError already thrown */ //break; } snprintf(temp, sizeof(temp), "Loading %s", str); LOGD(temp); FILE* file = fopen(str, "r"); if (file != NULL) { LOGD("The file loaded!!!"); } struct stat st; stat(str, &st); rom_size = st.st_size; //rom_size = uppow2(fp->size); // rom_size = 4 * 1024 * 1024; //sprintf(tempstring, "size of rom: %d", rom_size); // LOGD(tempstring); if (wsCartROM != NULL) { free(wsCartROM); } wsCartROM = (uint8_t *) calloc(1, rom_size); fread(wsCartROM, sizeof(uint8_t), rom_size, file); fclose(file); uint8_t header[10]; memcpy(header, wsCartROM + rom_size - 10, 10); sram_size = 0; eeprom_size = 0; switch (header[5]) { case 0x01: sram_size = 8 * 1024; break; case 0x02: sram_size = 32 * 1024; break; case 0x03: sram_size = 16 * 65536; break; case 0x04: sram_size = 32 * 65536; break; // Dicing Knight! case 0x10: eeprom_size = 128; break; case 0x20: eeprom_size = 2 * 1024; break; case 0x50: eeprom_size = 1024; break; } // sprintf(tempstring, "SRAM size is 0x%x", sram_size); // LOGD(tempstring); // sprintf(tempstring, "EEPROM size is 0x%x", eeprom_size); // LOGD(tempstring); if (header[6] & 0x1) { //LOGD("Game orientation is vertical"); } else { //LOGD("Game orientation is horizontal"); } v30mz_init(WSwan_readmem20, WSwan_writemem20, WSwan_readport, WSwan_writeport); // sprintf(tempstring, "WSwan_MemoryInit(%d, %d)", wsc, sram_size); // LOGD(tempstring); WSwan_MemoryInit(wsc, sram_size); // EEPROM and SRAM are loaded in this func. const jbyte *namestr; str = (*env)->GetStringUTFChars(env, name, NULL); if (str == NULL) { //return NULL; /* OutOfMemoryError already thrown */ //break; } WSwan_EEPROMInit("", (uint16_t) year, (uint8_t) month, (uint8_t) day, (uint8_t) sex, (uint8_t) blood); // LOGD("WSwan_GfxInit()"); WSwan_GfxInit(); // LOGD("WSwan_SoundInit()"); wswan_soundinit(); // LOGD("wsMakeTiles()"); wsMakeTiles(); //LOGD("reset()"); //reset(); }
static int Load(const char *name, MDFNFILE *fp) { uint32 real_rom_size; if(fp->size < 65536) { MDFN_PrintError(_("%s ROM image is too small."), MDFNGameInfo->fullname); return(0); } if(!memcmp(fp->data + fp->size - 0x20, "WSRF", 4)) { const uint8 *wsr_footer = fp->data + fp->size - 0x20; IsWSR = TRUE; WSRCurrentSong = wsr_footer[0x5]; Player_Init(256, "", "", ""); } else IsWSR = false; real_rom_size = (fp->size + 0xFFFF) & ~0xFFFF; rom_size = round_up_pow2(real_rom_size); //fp->size); wsCartROM = (uint8 *)calloc(1, rom_size); // This real_rom_size vs rom_size funny business is intended primarily for handling // WSR files. if(real_rom_size < rom_size) memset(wsCartROM, 0xFF, rom_size - real_rom_size); memcpy(wsCartROM + (rom_size - real_rom_size), fp->data, fp->size); MDFN_printf(_("ROM: %dKiB\n"), real_rom_size / 1024); md5_context md5; md5.starts(); md5.update(wsCartROM, rom_size); md5.finish(MDFNGameInfo->MD5); MDFN_printf(_("ROM MD5: 0x%s\n"), md5_context::asciistr(MDFNGameInfo->MD5, 0).c_str()); uint8 header[10]; memcpy(header, wsCartROM + rom_size - 10, 10); { const char *developer_name = "???"; for(unsigned int x = 0; x < sizeof(Developers) / sizeof(DLEntry); x++) { if(Developers[x].id == header[0]) { developer_name = Developers[x].name; break; } } MDFN_printf(_("Developer: %s (0x%02x)\n"), developer_name, header[0]); } uint32 SRAMSize = 0; eeprom_size = 0; switch(header[5]) { case 0x01: SRAMSize = 8*1024; break; case 0x02: SRAMSize = 32*1024; break; case 0x03: SRAMSize = 16 * 65536; break; case 0x04: SRAMSize = 32 * 65536; break; // Dicing Knight! case 0x10: eeprom_size = 128; break; case 0x20: eeprom_size = 2*1024; break; case 0x50: eeprom_size = 1024; break; } //printf("%02x\n", header[5]); if(eeprom_size) MDFN_printf(_("EEPROM: %d bytes\n"), eeprom_size); if(SRAMSize) MDFN_printf(_("Battery-backed RAM: %d bytes\n"), SRAMSize); MDFN_printf(_("Recorded Checksum: 0x%04x\n"), header[8] | (header[9] << 8)); { uint16 real_crc = 0; for(unsigned int i = 0; i < rom_size - 2; i++) real_crc += wsCartROM[i]; MDFN_printf(_("Real Checksum: 0x%04x\n"), real_crc); } if((header[8] | (header[9] << 8)) == 0x8de1 && (header[0]==0x01)&&(header[2]==0x27)) /* Detective Conan */ { //puts("HAX"); /* WS cpu is using cache/pipeline or there's protected ROM bank where pointing CS */ wsCartROM[0xfffe8]=0xea; wsCartROM[0xfffe9]=0x00; wsCartROM[0xfffea]=0x00; wsCartROM[0xfffeb]=0x00; wsCartROM[0xfffec]=0x20; } if(!IsWSR) { if(header[6] & 0x1) MDFNGameInfo->rotated = MDFN_ROTATE90; } MDFNMP_Init(16384, (1 << 20) / 1024); #ifdef WANT_DEBUGGER WSwanDBG_Init(); #endif v30mz_init(WSwan_readmem20, WSwan_writemem20, WSwan_readport, WSwan_writeport); WSwan_MemoryInit(MDFN_GetSettingB("wswan.language"), wsc, SRAMSize, IsWSR); // EEPROM and SRAM are loaded in this func. WSwan_GfxInit(); MDFNGameInfo->fps = (uint32)((uint64)3072000 * 65536 * 256 / (159*256)); MDFNGameInfo->GameSetMD5Valid = FALSE; WSwan_SoundInit(); wsMakeTiles(); Reset(); return(1); }