int snapshot_write(char *name) { const int version = SETTINGS_VERSION; int result = FALSE; int file = -1; snapshot_t buffer = { DPData : DPData, settings : settings, menu_order : menu_order, }; if ((file = FIO_OpenFile(name, O_CREAT | O_WRONLY , 644)) == -1) goto end; if (FIO_WriteFile(file, (void*)&version, sizeof(version)) != sizeof(version)) goto end; if (FIO_WriteFile(file, (void*)&buffer, sizeof(buffer)) != sizeof(buffer)) goto end; if (FIO_CloseFile(file) == -1) goto end; result = TRUE; end: if (file != -1) FIO_CloseFile(file); return result; }
void cmodes_write() { const int version = SNAPSHOT_VERSION; int file = -1; if ((file = FIO_OpenFile(MKPATH_NEW(CMODES_CONFIG), O_CREAT | O_WRONLY)) == -1) if (status.folder_exists || (file = FIO_OpenFile(MKPATH_OLD(CMODES_CONFIG), O_CREAT | O_WRONLY)) == -1) goto end; FIO_WriteFile(file, (void*)&version, sizeof(version)); FIO_WriteFile(file, (void*)&cmodes_config, sizeof(cmodes_config)); FIO_CloseFile(file); end: if (file != -1) FIO_CloseFile(file); }
void start_debug_mode() { int file; char filename[20] = "A:/DEBUG.LOG"; // default name //int filesize; time_t t; struct tm tm; time(&t); localtime_r(&t, &tm); if (settings.logfile_mode == LOGFILE_MODE_NEW) sprintf(filename, "A:/%02d%02d%02d%02d.LOG", tm.tm_mon+1, tm.tm_mday, tm.tm_hour, tm.tm_min); // O_APPEND is not working in VxWorks, so we seek to the end later file = FIO_OpenFile(filename, O_CREAT | O_WRONLY , 644); if(file > 0) { if (settings.logfile_mode == LOGFILE_MODE_APPEND) FIO_SeekFile(file, 0, 2/*SEEK_END*/); // redirect stdout and stderr to our file ioGlobalStdSet(1, file); ioGlobalStdSet(2, file); } char separator[] = "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n"; printf(separator); printf("::::: %04d-%02d-%02d %02d:%02d:%02d :::::\n", tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); printf(separator); printf("\n"); beep(); }
void cmodes_read() { int id; int version = 0; int file = -1; cmodes_config_t buffer; for (id = 0; id < CMODES_MAX; id ++) { sprintf(cmodes_default.names[id], "%s %X", LP_WORD(L_S_CMODE_NAME), id); cmodes_default.order[id] = id; } for (id = 0; id < CMODES_MODES; id ++) { cmodes_default.assign[id] = CMODE_NONE; } cmodes_config = cmodes_default; if ((file = FIO_OpenFile(MKPATH_NEW(CMODES_CONFIG), O_RDONLY)) == -1) if ((file = FIO_OpenFile(MKPATH_OLD(CMODES_CONFIG), O_RDONLY)) == -1) goto end; if (FIO_ReadFile(file, &version, sizeof(version)) != sizeof(version)) goto end; if (version != SNAPSHOT_VERSION) goto end; if (FIO_ReadFile(file, &buffer, sizeof(buffer)) != sizeof(buffer)) goto end; cmodes_config = buffer; end: if (file != -1) FIO_CloseFile(file); }
//dump ram and rom void dumpmemo() { FIO_RemoveFile("B:/RAMDUMP.BIN"); int f = FIO_CreateFile("B:/RAMDUMP.BIN"); if (f!=-1) { FIO_WriteFile(f, (void*)0xFFFF0000, 4); FIO_WriteFile(f, (void*)4, 0x1900-4); FIO_WriteFile(f, (void*)0x1900, 32*1024*1024-0x1900); FIO_CloseFile(f); } f = FIO_OpenFile("B:/ROMDUMP.BIN", 0, 0644); FIO_CloseFile(f); if (f==-1) { f = FIO_CreateFile("B:/ROMDUMP.BIN"); FIO_WriteFile(f, (void*)0xFF800000, 8*1024*1024); FIO_CloseFile(f); } }
void dump_memory() { char filename[20] = "A:/12345678.MEM"; time_t t; struct tm tm; time(&t); localtime_r(&t, &tm); sprintf(filename, "A:/%02d%02d%02d%02d.MEM", tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); debug_log("Dumping memory to %s.\n", filename); int file = FIO_OpenFile(filename, O_CREAT | O_WRONLY , 644); if (file == -1) { debug_log("ERROR: can't open file for writing (%s)", filename); beep(); beep(); } else { int addr=0; int power_off_state = DPData.auto_power_off; send_to_intercom(IC_SET_AUTO_POWER_OFF, false); while (addr<0x800000) { // dump 8MB of RAM char buf[0x800]; // i don't know why, but if we try to pass the mem address (addr) directly to // FIO_WriteFile, we get zero-filled file... so we need local buffer as a proxy // note: do not increase the size of the local buffer too much, because it is in the stack LEDBLUE ^= 2; memcpy(buf, (void*)addr, 0x800); FIO_WriteFile(file, buf, 0x800); addr += 0x800; } FIO_CloseFile(file); send_to_intercom(IC_SET_AUTO_POWER_OFF, power_off_state); } beep(); }
int snapshot_read(char *name, snapshot_t *snapshot) { int result = FALSE; int file = -1; int version = 0; snapshot_t buffer; if ((file = FIO_OpenFile(name, O_RDONLY, 644)) == -1) goto end; if (FIO_ReadFile(file, &version, sizeof(version)) != sizeof(version)) goto end; if (version != SETTINGS_VERSION) goto end; if (FIO_ReadFile(file, &buffer, sizeof(buffer)) != sizeof(buffer)) goto end; *snapshot = buffer; result = TRUE; #if SETTINGS_VERSION == 0x4A int nt; // Temporal fix for those affected by issue #333 // Remove after increasing the version of the settings file if (snapshot->menu_order.named_temps[0] == 0 && snapshot->menu_order.named_temps[1] == 0) for (nt = 0; nt < LENGTH(snapshot->menu_order.named_temps); nt++) snapshot->menu_order.named_temps[nt] = nt; #endif end: if (file != -1) FIO_CloseFile(file); return result; }
void start_up() { // Check and create our 400PLUS folder status.folder_exists = check_create_folder(); // Recover persisting information persist_read(); // Read settings from file settings_read(); // If configured, start debug mode if (settings.debug_on_poweron) start_debug_mode(); // If configured, restore AEB if (settings.persist_aeb) send_to_intercom(IC_SET_AE_BKT, persist.aeb); // Enable IR remote // i'm not sure where to call this? perhaps this isn't the right place. if (settings.remote_enable) remote_on(); // Enable extended ISOs // Enable (hidden) CFn.8 for ISO H send_to_intercom(IC_SET_CF_EXTEND_ISO, 1); // Enable realtime ISO change send_to_intercom(IC_SET_REALTIME_ISO_0, 0); send_to_intercom(IC_SET_REALTIME_ISO_1, 0); // Set current language enqueue_action(lang_pack_init); // Read custom modes configuration from file enqueue_action(cmodes_read); // And optionally apply a custom mode enqueue_action(cmode_recall); // turn off the blue led after it was lighten by our hack_task_MainCtrl() eventproc_EdLedOff(); #ifdef MEMSPY debug_log("starting memspy task"); CreateTask("memspy", 0x1e, 0x1000, memspy_task, 0); #endif #if 0 debug_log("=== DUMPING DDD ==="); printf_DDD_log( (void*)(int)(0x00007604+0x38) ); debug_log("maindlg @ 0x%08X, handler @ 0x%08X", hMainDialog, hMainDialog->event_handler); debug_log("dumping"); long *addr = (long*) 0x7F0000; int file = FIO_OpenFile("A:/dump.bin", O_CREAT | O_WRONLY , 644); if (file != -1) { FIO_WriteFile(file, addr, 0xFFFF); FIO_CloseFile(file); beep(); } #endif }
static int script_load_symbols(void* tcc, void* script_state, char *filename) { uint32_t size = 0; FILE* file = NULL; char *buf = NULL; uint32_t count = 0; uint32_t pos = 0; if( FIO_GetFileSize( filename, &size ) != 0 ) { console_printf("Error loading '%s': File does not exist\n", filename); return -1; } buf = fio_malloc(size); if(!buf) { console_printf("Error loading '%s': File too large\n", filename); return -1; } file = FIO_OpenFile(filename, O_RDONLY | O_SYNC); if(!file) { console_printf("Error loading '%s': File does not exist\n", filename); fio_free(buf); return -1; } FIO_ReadFile(file, buf, size); FIO_CloseFile(file); while(buf[pos]) { char address_buf[16]; char symbol_buf[128]; uint32_t length = 0; uint32_t address = 0; while(buf[pos + length] && buf[pos + length] != ' ' && length < sizeof(address_buf)) { address_buf[length] = buf[pos + length]; length++; } address_buf[length] = '\000'; pos += length + 1; length = 0; while(buf[pos + length] && buf[pos + length] != '\r' && buf[pos + length] != '\n' && length < sizeof(symbol_buf)) { symbol_buf[length] = buf[pos + length]; length++; } symbol_buf[length] = '\000'; pos += length + 1; length = 0; while(buf[pos + length] && (buf[pos + length] == '\r' || buf[pos + length] == '\n')) { pos++; } sscanf(address_buf, "%x", &address); module_exec(tcc, "tcc_add_symbol", 3, script_state, symbol_buf, (void*)address); count++; } /* ToDo: parse the old plugin sections as all needed OS stubs are already described there */ module_exec(tcc, "tcc_add_symbol", 3, script_state, "strcpy", &strcpy); module_exec(tcc, "tcc_add_symbol", 3, script_state, "strlen", &strlen); fio_free(buf); return 0; }
static int dng_show(char* filename) { uint32_t size; if( FIO_GetFileSize( filename, &size ) != 0 ) return 0; FILE* f = FIO_OpenFile(filename, O_RDONLY | O_SYNC); void* buf = 0; /* should be big enough for the header */ int header_maxsize = 65536; int* header = fio_malloc(header_maxsize); if (!header) return 0; int rc = FIO_ReadFile(f, header, header_maxsize); if( rc != header_maxsize ) goto err; if (header[0] != 0x002A4949 && header[1] != 0x00000008) { bmp_printf(FONT_MED, 0, 0, "Not a CHDK DNG"); goto err; } raw_info.width = 0; raw_info.height = 0; int strip_offset = 0; int off = 8; for (int ifd = 0; off; ifd++) off = tif_parse_ifd(ifd, (void*)header, off, &strip_offset); fio_free(header); header = 0; if (!strip_offset) goto err; if (!raw_info.width) goto err; if (!raw_info.height) goto err; int raw_size = raw_info.width * raw_info.height * 14/8; buf = fio_malloc(raw_size); if (!buf) goto err; FIO_SeekSkipFile(f, strip_offset, SEEK_SET); rc = FIO_ReadFile(f, buf, raw_size); if (rc != raw_size) goto err; FIO_CloseFile(f); f = 0; info_led_on(); /* fixme: this step is really slow */ reverse_bytes_order(buf, raw_size); info_led_off(); raw_info.buffer = buf; raw_set_geometry(raw_info.width, raw_info.height, raw_info.active_area.x1, raw_info.width - raw_info.active_area.x2, raw_info.active_area.y1, raw_info.height - raw_info.active_area.y2); raw_force_aspect_ratio_1to1(); vram_clear_lv(); raw_preview_fast_ex((void*)-1, (void*)-1, -1, -1, RAW_PREVIEW_COLOR_HALFRES); fio_free(buf); buf = 0; raw_set_dirty(); bmp_printf(FONT_MED, 600, 460, " %dx%d ", raw_info.jpeg.width, raw_info.jpeg.height); return 1; err: if (f) FIO_CloseFile(f); if (header) fio_free(header); if (buf) fio_free(buf); raw_set_dirty(); return 0; }