/* * Class: com_Revsoft_Wabbitemu_CalcInterface * Method: CreateRom * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V */ JNIEXPORT jint JNICALL Java_com_Revsoft_Wabbitemu_calc_CalcInterface_CreateRom (JNIEnv *env, jclass classObj, jstring jOsPath, jstring jBootPath, jstring jRomPath, jint model) { checkThread(); const char *osPath = env->GetStringUTFChars(jOsPath, JNI_FALSE); const char *bootPath = env->GetStringUTFChars(jBootPath, JNI_FALSE); const char *romPath = env->GetStringUTFChars(jRomPath, JNI_FALSE); //Do not allow more than one calc currently if (lpCalc) { calc_slot_free(lpCalc); } lpCalc = calc_slot_new(); calc_init_model(lpCalc, model, NULL); //slot stuff strcpy(lpCalc->rom_path, romPath); lpCalc->active = TRUE; lpCalc->model = (CalcModel) model; lpCalc->cpu.pio.model = model; FILE *file = fopen(bootPath, "rb"); if (file == NULL) { calc_slot_free(lpCalc); lpCalc = NULL; return -1; } writeboot(file, &lpCalc->mem_c, -1); fclose(file); remove(bootPath); TIFILE_t *tifile = importvar(osPath, FALSE); if (tifile == NULL) { calc_slot_free(lpCalc); lpCalc = NULL; return -2; } int link_error = forceload_os(&lpCalc->cpu, tifile); if (link_error != LERR_SUCCESS) { calc_slot_free(lpCalc); lpCalc = NULL; return -2; } calc_erase_certificate(lpCalc->mem_c.flash,lpCalc->mem_c.flash_size); calc_reset(lpCalc); //write the output from file MFILE *romfile = ExportRom((char *) romPath, lpCalc); if (romfile != NULL) { mclose(romfile); calc_slot_free(lpCalc); lpCalc = NULL; return 0; } calc_slot_free(lpCalc); lpCalc = NULL; return -3; }
bool WabbitemuApp::OnInit() { wxImage::AddHandler(new wxPNGHandler); //stolen from the windows version ParseCommandLineArgs(); memset(frames, 0, sizeof(frames)); LPCALC lpCalc = calc_slot_new(); LoadSettings(lpCalc); WabbitemuFrame *frame; int result = rom_load(lpCalc, lpCalc->rom_path); if (result == TRUE) { frame = gui_frame(lpCalc); } else { calc_slot_free(lpCalc); BOOL loadedRom = FALSE; if (parsedArgs.num_rom_files > 0) { for (int i = 0; i < parsedArgs.num_rom_files; i++) { if (rom_load(lpCalc, parsedArgs.rom_files[i])) { gui_frame(lpCalc); loadedRom = TRUE; break; } } } if (!loadedRom) { bool success = DoRomWizard(); if (!success) { return FALSE; } } } LoadCommandlineFiles((INT_PTR) lpCalc, LoadToLPCALC); timer = new wxTimer(); timer->Connect(wxEVT_TIMER, (wxObjectEventFunction) &WabbitemuApp::OnTimer); timer->Start(TPF, false); return TRUE; }
BOOL rom_load(LPCALC lpCalc, LPCTSTR FileName) { if (lpCalc == NULL) { return FALSE; } TIFILE_t* tifile = newimportvar(FileName, FALSE); if (tifile == NULL) { return FALSE; } lpCalc->speed = 100; if (lpCalc->active) { calc_slot_free(lpCalc); } lpCalc->model = tifile->model; if (tifile->type == SAV_TYPE) { lpCalc->active = TRUE; switch (tifile->model) { case TI_82: case TI_83: { int size; char *rom = GetRomOnly(tifile->save, &size); char VerString[64]; FindRomVersion( tifile->model, VerString, (unsigned char *) rom, size); calc_init_83(lpCalc, VerString); break; } case TI_73: case TI_83P: calc_init_83p(lpCalc); break; case TI_84PSE: case TI_83PSE: calc_init_83pse(lpCalc); break; case TI_84P: calc_init_84p(lpCalc); break; case TI_85: case TI_86: calc_init_86(lpCalc); break; default: FreeTiFile(tifile); return FALSE; } LoadSlot(tifile->save, lpCalc); #ifdef WINVER StringCbCopy(lpCalc->rom_path, sizeof(lpCalc->rom_path), FileName); #else _tcscpy_s(lpCalc->rom_path, FileName); #endif FindRomVersion(tifile->model, lpCalc->rom_version, lpCalc->mem_c.flash, lpCalc->mem_c.flash_size); } else if (tifile->type == ROM_TYPE) { switch (tifile->model) { case TI_81: calc_init_81(lpCalc, tifile->rom->version); memcpy( lpCalc->cpu.mem_c->flash, tifile->rom->data, (lpCalc->cpu.mem_c->flash_size<=tifile->rom->size)?lpCalc->cpu.mem_c->flash_size:tifile->rom->size); break; case TI_82: case TI_83: calc_init_83(lpCalc, tifile->rom->version); memcpy( lpCalc->cpu.mem_c->flash, tifile->rom->data, (lpCalc->cpu.mem_c->flash_size<=tifile->rom->size)?lpCalc->cpu.mem_c->flash_size:tifile->rom->size); break; case TI_85: case TI_86: calc_init_86(lpCalc); memcpy( lpCalc->cpu.mem_c->flash, tifile->rom->data, (lpCalc->cpu.mem_c->flash_size<=tifile->rom->size)?lpCalc->cpu.mem_c->flash_size:tifile->rom->size); break; case TI_73: case TI_83P: calc_init_83p(lpCalc); memcpy( lpCalc->cpu.mem_c->flash, tifile->rom->data, (lpCalc->cpu.mem_c->flash_size<=tifile->rom->size)?lpCalc->cpu.mem_c->flash_size:tifile->rom->size); calc_erase_certificate(lpCalc->cpu.mem_c->flash,lpCalc->cpu.mem_c->flash_size); break; case TI_84P: calc_init_84p(lpCalc); memcpy( lpCalc->cpu.mem_c->flash, tifile->rom->data, (lpCalc->cpu.mem_c->flash_size<=tifile->rom->size)?lpCalc->cpu.mem_c->flash_size:tifile->rom->size); calc_erase_certificate(lpCalc->cpu.mem_c->flash,lpCalc->cpu.mem_c->flash_size); break; case TI_84PSE: case TI_83PSE: calc_init_83pse(lpCalc); memcpy( lpCalc->cpu.mem_c->flash, tifile->rom->data, (lpCalc->cpu.mem_c->flash_size<=tifile->rom->size)?lpCalc->cpu.mem_c->flash_size:tifile->rom->size); calc_erase_certificate(lpCalc->cpu.mem_c->flash,lpCalc->cpu.mem_c->flash_size); break; default: FreeTiFile(tifile); return FALSE; } lpCalc->active = TRUE; memcpy(lpCalc->rom_version, tifile->rom->version, sizeof(lpCalc->rom_version)); #ifdef WINVER StringCbCopy(lpCalc->rom_path, sizeof(lpCalc->rom_path), FileName); #else _tcscpy_s(lpCalc->rom_path, FileName); #endif } else { lpCalc = NULL; return FALSE; } if (lpCalc != NULL) { lpCalc->cpu.pio.model = lpCalc->model; #ifdef WINVER extern keyprog_t keygrps[256]; extern keyprog_t defaultkeys[256]; extern keyprog_t keysti86[256]; if (lpCalc->model == TI_86 || lpCalc->model == TI_85) { memcpy(keygrps, keysti86, sizeof(keyprog_t) * 256); } else { memcpy(keygrps, defaultkeys, sizeof(keyprog_t) * 256); } #endif if (lpCalc->model >= TI_73) { check_bootfree_and_update(lpCalc); } if (tifile->save == NULL) { calc_reset(lpCalc); if (lpCalc->auto_turn_on) { calc_turn_on(lpCalc); } } } FreeTiFile(tifile); return TRUE; }