void eeprom_config_init(bool restore_default) { uint16_t i; uint8_t *config_ptr = config_raw; for (i=0;i<CONFIG_RAW_SIZE;i++) { if (restore_default) { *config_ptr = config_default(i); // default value } else { *config_ptr = config_value(i); if ((*config_ptr < config_min(i)) //min || (*config_ptr > config_max(i))) //max { *config_ptr = config_default(i); // default value } } eeprom_config_save(i); // update if default value is restored config_ptr++; } }
int main(int argc, char **argv) { int32_t ch, index, excl_index; const char *name; bool load_default, exclusive; load_default = true; exclusive = false; index = 0; while (1) { if ((ch = getopt_long_only(argc, argv, "", opt_field, &index)) < 0) break; switch (ch) { case OPT_LOG: log_load(optarg); break; case OPT_CONFIG: config_load(optarg); load_default = false; break; case OPT_EXCL: if (exclusive) error("Cannot use --%s with --%s", opt_field[index].name, opt_field[excl_index].name); exclusive = true; excl_index = index; case OPT_NRML: name = opt_field[index].name; if (opt_field[index].has_arg) config_set(name, optarg); else config_set(name, "true"); break; case OPT_VERSION: version(); return 1; case OPT_HELP: default: usage(); return 1; } } if (load_default) config_default(); mt_init(); store_load(); bucket_load(); crypt_load(); volume_load(); return 0; }
/*! ******************************************************************************* * Update configuration storage * * \note ******************************************************************************/ void eeprom_config_save(uint8_t idx) { if (idx<CONFIG_RAW_SIZE) { if (config_raw[idx] != config_value(idx)) { if ((config_raw[idx] < config_min(idx)) //min || (config_raw[idx] > config_max(idx))) { //max config_raw[idx] = config_default(idx); // default value } config_write(idx, config_raw[idx]); } } }
void eeprom_config_init(bool restore_default) { uint16_t i; uint8_t *config_ptr = config_raw; #if (NANODE == 1 || JEENODE == 1) // set to allow erase and write in one operation EECR |= (EEPM1 | EEPM0); #endif for (i=0;i<CONFIG_RAW_SIZE;i++) { if (restore_default) { *config_ptr = config_default(i); // default value } else { *config_ptr = config_value(i); if ((*config_ptr < config_min(i)) //min || (*config_ptr > config_max(i))) { //max *config_ptr = config_default(i); // default value } } eeprom_config_save(i); // update if default value is restored config_ptr++; } }
/*! ******************************************************************************* * Update configuration data as stored in EEPROM * * \note * @param uint8_t integer - address (offset) within first 256 bytes of EEPROM ******************************************************************************/ void eeprom_config_save(uint8_t idx) { if (idx<CONFIG_RAW_SIZE) { if (config_raw[idx] != config_value(idx)) { // Data in EEPROM different here if ((config_raw[idx] < config_min(idx)) //min || (config_raw[idx] > config_max(idx))) { //max config_raw[idx] = config_default(idx); // default value - set if value to be written is out of range } config_write(idx, config_raw[idx]); } } }
bool Emulator_Init() { LOG_DBG("Emulator_Init()\n"); config_default(); init_machine(); int size = cart.romsize; cart.romsize = 0; struct stat st; stat(current_rom, &st); reloadrom(st.st_size, current_rom); mode_switch = MODE_EMULATION; emulator_loaded = true; need_load_rom = false; return 1; }
static void blursk_init(void) { #if 0 if (blursk_window) return; #endif #ifdef DUMPCORE signal(SIGSEGV, SIG_DFL); #endif /* Get the configuration and create the image buffers */ //config_read(NULL, NULL); //preset_read(); config_default(&config); img_resize(config.width, config.height); #if 0 /* Create the window */ blursk_window = gtk_window_new(config.window_title ? GTK_WINDOW_TOPLEVEL : GTK_WINDOW_DIALOG); gtk_window_set_title(GTK_WINDOW(blursk_window), PACKAGE); gtk_window_set_policy(GTK_WINDOW(blursk_window), TRUE, TRUE, TRUE); gtk_signal_connect(GTK_OBJECT(blursk_window), "destroy", GTK_SIGNAL_FUNC(blursk_destroy_cb), NULL); gtk_signal_connect(GTK_OBJECT(blursk_window), "destroy", GTK_SIGNAL_FUNC(gtk_widget_destroyed), &blursk_window); gtk_signal_connect(GTK_OBJECT(blursk_window), "configure_event", GTK_SIGNAL_FUNC(resize_cb), NULL); /* Put a drawing area in the window */ area = gtk_drawing_area_new(); gtk_drawing_area_size(GTK_DRAWING_AREA(area), img_physwidth, img_physheight); gtk_container_add(GTK_CONTAINER(blursk_window),area); gtk_widget_show(area); /* Arrange for key & mouse events to be detected */ gtk_signal_connect(GTK_OBJECT(blursk_window), "selection_received", GTK_SIGNAL_FUNC(selection_cb), NULL); gtk_signal_connect(GTK_OBJECT(blursk_window), "key_press_event", GTK_SIGNAL_FUNC(key_cb), NULL); gtk_signal_connect(GTK_OBJECT(blursk_window), "button_press_event", GTK_SIGNAL_FUNC(mousebutton_cb), NULL); gtk_signal_connect(GTK_OBJECT(blursk_window), "button_release_event", GTK_SIGNAL_FUNC(mousebutton_cb), NULL); gtk_signal_connect(GTK_OBJECT(blursk_window), "motion_notify_event", GTK_SIGNAL_FUNC(mousemove_cb), NULL); gtk_widget_set_events(blursk_window, GDK_KEY_PRESS_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_BUTTON1_MOTION_MASK); /* Initialize the drawing area */ gtk_widget_realize(area); bg_pixmap = gdk_pixmap_create_from_xpm_d(area->window, NULL, NULL, blursk_xmms_logo_xpm); gdk_window_set_back_pixmap(area->window, bg_pixmap, 0); /* Move the window to its usual place, if any. If portions are beyond * the edge of the screen, then move it to make everything visible. */ if (config.x != -1 || config.y != -1) { if (config.x < 0) config.x = 0; else if (config.x + img_physwidth >= gdk_screen_width()) config.x = gdk_screen_width() - img_physwidth; if (config.y < 0) config.y = 0; else if (config.y + img_physheight >= gdk_screen_height()) config.y = gdk_screen_height() - img_physheight; gtk_widget_realize(blursk_window); gtk_window_reposition(GTK_WINDOW(blursk_window), config.x, config.y); } /* Show it! */ gtk_widget_show(blursk_window); /* Determine whether fullscreen operation is supported. */ can_fullscreen = xmms_fullscreen_init(blursk_window); #endif if( blursk_bitmap == NULL ) blursk_bitmap = new os::Bitmap( config.width, config.height, os::CS_RGB32 ); color_genmap(TRUE); }
int main(int argc, char **argv) { struct config conf; const char*config_filename; struct packet pkt = {0,}; char buf[64] = {0,}; int16_t crc; int default_cfg = 0; int bad_pkts_cnt = 0; int pkt_cnt = 0; if(argc == 2 && !strcmp("--help", argv[1])) { puts("Usage: quadcontrol [config_file.cfg]"); exit(1); } if(argc == 2) config_filename = argv[1]; else config_filename = CONFIG_DEFAULT_FILE; if(config_load(config_filename, &conf)) { fputs("WARNING: Could not load configuration file. Reverting to defaults.\n", stderr); config_default(&conf); config_save(CONFIG_DEFAULT_FILE, &conf); default_cfg = 1; } if(signal(SIGINT, sig_handler) == SIG_ERR) { fputs("ERROR: Could not set a signal handler.\n", stderr); exit(1); } if(joystick_init(conf.joystick_device)) { perror("could not open joystick device"); exit(1); } joystick_set_axis_mapping(conf.joystick_mapping); joystick_set_axis_calibration(conf.joystick_calibration); if(default_cfg) { joystick_calibrate(conf.joystick_calibration); config_save(CONFIG_DEFAULT_FILE, &conf); } if(serial_init(conf.serial_device, conf.serial_speed)) { perror("could not open serial port"); exit(1); } link_init(); active = 1; while(active) { // Prepare & send a packet memset(&pkt, 0, PACKET_TOTAL_SIZE); #ifdef REQUEST_REPORTS // Report request if(pkt_cnt % 2 == 0) { pkt.type = PT_REPORT | RPT_IMU; /*printf("\nreport request sent\n");*/ } else #endif { pkt.type = PT_JOYSTICK; pkt.data.joy.throttle = joystick_get_control_val(THROTTLE_AXIS); pkt.data.joy.yaw = joystick_get_control_val(YAW_AXIS); pkt.data.joy.pitch = joystick_get_control_val(PITCH_AXIS); pkt.data.joy.roll = joystick_get_control_val(ROLL_AXIS); pkt.data.joy.buttons = joystick_get_buttons(); #ifdef SHOW_JOY printf("\nthrottle: %6d\tyaw:%6d\tpitch:%6d\troll:%6d\tbuttons:%6d", pkt.data.joy.throttle, pkt.data.joy.yaw, pkt.data.joy.pitch, pkt.data.joy.roll, pkt.data.joy.buttons); #endif } crc = link_crc(&pkt); serial_write((const uint8_t*) &pkt, PACKET_TOTAL_SIZE); serial_write((const uint8_t*) &crc, CRC_SIZE); #ifdef SHOW_SEND_RAW printf("\nsent: "); for(int i = 0; i < PACKET_TOTAL_SIZE; ++i) printf("%.2x ", ((uint8_t*)(&pkt))[i]); printf("\tcrc = %.2x", crc); #endif // Show response from the radio int cnt = serial_read(buf, sizeof(buf)); if(cnt > 0) { #ifdef SHOW_RECV_RAW // HEX version printf("\treceived: "); for(int i = 0; i < cnt; ++i) printf("%.2x ", (uint8_t) buf[i]); // ASCII version printf(" ("); for(int i = 0; i < cnt; ++i) printf("%c", buf[i]); printf(")"); #endif if(cnt == 1 && buf[0] == 'E') printf("\n!!! DRONE IS NOT RESPONDING !!!\n"); // Parse reports if(buf[0] == 'T' && buf[1] == 'R') { struct packet* pkt = (struct packet*) &buf[2]; if(pkt->type & PT_REPORT) { int report_type = pkt->type & ~PT_REPORT; switch(report_type) { case RPT_MOTOR: printf("motors = FL: %d FR:%d BL:%d BR:%d\n", pkt->data.rpt_motor.fl, pkt->data.rpt_motor.fr, pkt->data.rpt_motor.bl, pkt->data.rpt_motor.br); break; case RPT_IMU: printf("imu = yaw: %d pitch:%d roll:%d\n", pkt->data.rpt_imu.yaw, pkt->data.rpt_imu.pitch, pkt->data.rpt_imu.roll); break; default: printf("invalid report type\n"); break; } } } memset(buf, 0, sizeof(buf)); bad_pkts_cnt = 0; } else { if(++bad_pkts_cnt == 10) { printf("\n!!! CONTROLLER IS NOT RESPONDING !!!\n"); //link_init(); } } ++pkt_cnt; fflush(stdout); usleep(45000); } serial_close(); joystick_close(); config_save(CONFIG_DEFAULT_FILE, &conf); return 1; }
/*************************************************************************** * M A I N * ***************************************************************************/ int main (int argc, char *argv[]) { #ifdef HW_RVL /* enable 64-byte fetch mode for L2 cache */ L2Enhance(); /* initialize DI interface */ DI_UseCache(0); DI_Init(); sprintf(osd_version, "%s (IOS %d)", VERSION, IOS_GetVersion()); #else sprintf(osd_version, "%s (GCN)", VERSION); #endif /* initialize video engine */ gx_video_Init(); #ifndef HW_RVL /* initialize DVD interface */ DVD_Init(); #endif /* initialize input engine */ gx_input_Init(); /* initialize FAT devices */ int retry = 0; int fatMounted = 0; /* try to mount FAT devices during 3 seconds */ while (!fatMounted && (retry < 12)) { fatMounted = fatInitDefault(); usleep(250000); retry++; } if (fatMounted) { /* base directory */ char pathname[MAXPATHLEN]; sprintf (pathname, DEFAULT_PATH); DIR *dir = opendir(pathname); if (dir) closedir(dir); else mkdir(pathname,S_IRWXU); /* default SRAM & Savestate files directories */ sprintf (pathname, "%s/saves",DEFAULT_PATH); dir = opendir(pathname); if (dir) closedir(dir); else mkdir(pathname,S_IRWXU); sprintf (pathname, "%s/saves/md",DEFAULT_PATH); dir = opendir(pathname); if (dir) closedir(dir); else mkdir(pathname,S_IRWXU); sprintf (pathname, "%s/saves/ms",DEFAULT_PATH); dir = opendir(pathname); if (dir) closedir(dir); else mkdir(pathname,S_IRWXU); sprintf (pathname, "%s/saves/gg",DEFAULT_PATH); dir = opendir(pathname); if (dir) closedir(dir); else mkdir(pathname,S_IRWXU); sprintf (pathname, "%s/saves/sg",DEFAULT_PATH); dir = opendir(pathname); if (dir) closedir(dir); else mkdir(pathname,S_IRWXU); sprintf (pathname, "%s/saves/cd",DEFAULT_PATH); dir = opendir(pathname); if (dir) closedir(dir); else mkdir(pathname,S_IRWXU); /* default Snapshot files directories */ sprintf (pathname, "%s/snaps",DEFAULT_PATH); dir = opendir(pathname); if (dir) closedir(dir); else mkdir(pathname,S_IRWXU); sprintf (pathname, "%s/snaps/md",DEFAULT_PATH); dir = opendir(pathname); if (dir) closedir(dir); else mkdir(pathname,S_IRWXU); sprintf (pathname, "%s/snaps/ms",DEFAULT_PATH); dir = opendir(pathname); if (dir) closedir(dir); else mkdir(pathname,S_IRWXU); sprintf (pathname, "%s/snaps/gg",DEFAULT_PATH); dir = opendir(pathname); if (dir) closedir(dir); else mkdir(pathname,S_IRWXU); sprintf (pathname, "%s/snaps/sg",DEFAULT_PATH); dir = opendir(pathname); if (dir) closedir(dir); else mkdir(pathname,S_IRWXU); sprintf (pathname, "%s/snaps/cd",DEFAULT_PATH); dir = opendir(pathname); if (dir) closedir(dir); else mkdir(pathname,S_IRWXU); /* default Cheat files directories */ sprintf (pathname, "%s/cheats",DEFAULT_PATH); dir = opendir(pathname); if (dir) closedir(dir); else mkdir(pathname,S_IRWXU); sprintf (pathname, "%s/cheats/md",DEFAULT_PATH); dir = opendir(pathname); if (dir) closedir(dir); else mkdir(pathname,S_IRWXU); sprintf (pathname, "%s/cheats/ms",DEFAULT_PATH); dir = opendir(pathname); if (dir) closedir(dir); else mkdir(pathname,S_IRWXU); sprintf (pathname, "%s/cheats/gg",DEFAULT_PATH); dir = opendir(pathname); if (dir) closedir(dir); else mkdir(pathname,S_IRWXU); sprintf (pathname, "%s/cheats/sg",DEFAULT_PATH); dir = opendir(pathname); if (dir) closedir(dir); else mkdir(pathname,S_IRWXU); sprintf (pathname, "%s/cheats/cd",DEFAULT_PATH); dir = opendir(pathname); if (dir) closedir(dir); else mkdir(pathname,S_IRWXU); /* default BIOS ROM files directories */ sprintf (pathname, "%s/bios",DEFAULT_PATH); dir = opendir(pathname); if (dir) closedir(dir); else mkdir(pathname,S_IRWXU); /* default LOCK-ON ROM files directories */ sprintf (pathname, "%s/lock-on",DEFAULT_PATH); dir = opendir(pathname); if (dir) closedir(dir); else mkdir(pathname,S_IRWXU); } /* initialize sound engine */ gx_audio_Init(); /* initialize genesis plus core */ history_default(); config_default(); init_machine(); /* auto-load last ROM file */ if (config.autoload) { SILENT = 1; if (OpenDirectory(TYPE_RECENT, -1)) { if (LoadFile(0)) { reloadrom(); gx_video_Start(); gx_audio_Start(); ConfigRequested = 0; } } SILENT = 0; } /* show disclaimer */ if (ConfigRequested) { legal(); } #ifdef HW_RVL /* power button callback */ SYS_SetPowerCallback(PowerOff_cb); #endif /* reset button callback */ SYS_SetResetCallback(Reset_cb); /* main emulation loop */ run_emulation(); /* we should never return anyway */ return 0; }
/* * Initialise the FPU for this machine. */ BOOT_CODE bool_t Arch_initFpu(void) { /* Enable FPU / SSE / SSE2 / SSE3 / SSSE3 / SSE4 Extensions. */ write_cr4(read_cr4() | CR4_OSFXSR); /* Enable the FPU in general. */ write_cr0((read_cr0() & ~CR0_EMULATION) | CR0_MONITOR_COPROC | CR0_NUMERIC_ERROR); enableFpu(); /* Initialize the fpu state */ finit(); if (config_set(CONFIG_XSAVE)) { uint64_t xsave_features; uint32_t xsave_instruction; uint64_t desired_features = config_default(CONFIG_XSAVE_FEATURE_SET, 1); /* check for XSAVE support */ if (!(x86_cpuid_ecx(1, 0) & BIT(26))) { printf("XSAVE not supported\n"); return false; } /* enable XSAVE support */ write_cr4(read_cr4() | CR4_OSXSAVE); /* check feature mask */ xsave_features = ((uint64_t)x86_cpuid_edx(0x0d, 0x0) << 32) | x86_cpuid_eax(0x0d, 0x0); if ((xsave_features & desired_features) != desired_features) { printf("Requested feature mask is 0x%llx, but only 0x%llx supported\n", desired_features, (long long)xsave_features); return false; } /* enable feature mask */ write_xcr0(desired_features); /* validate the xsave buffer size and instruction */ if (x86_cpuid_ebx(0x0d, 0x0) != CONFIG_XSAVE_SIZE) { printf("XSAVE buffer set set to %d, but should be %d\n", CONFIG_XSAVE_SIZE, x86_cpuid_ecx(0x0d, 0x0)); return false; } /* check if a specialized XSAVE instruction was requested */ xsave_instruction = x86_cpuid_eax(0x0d, 0x1); if (config_set(CONFIG_XSAVE_XSAVEOPT)) { if (!(xsave_instruction & BIT(0))) { printf("XSAVEOPT requested, but not supported\n"); return false; } } else if (config_set(CONFIG_XSAVE_XSAVEC)) { if (!(xsave_instruction & BIT(1))) { printf("XSAVEC requested, but not supported\n"); return false; } } else if (config_set(CONFIG_XSAVE_XSAVES)) { if (!(xsave_instruction & BIT(3))) { printf("XSAVES requested, but not supported\n"); return false; } /* initialize the XSS MSR */ x86_wrmsr(IA32_XSS_MSR, desired_features); } /* Load a NULL fpu state so that the idle thread ends up * with a sensible FPU state and we can optimize our * switch of it */ memzero(&x86KSnullFpuState, sizeof(x86KSnullFpuState)); loadFpuState(&x86KSnullFpuState); } else { /* Store the null fpu state */ saveFpuState(&x86KSnullFpuState); } /* Set the FPU to lazy switch mode */ disableFpu(); return true; }
int main (int argc, char *argv[]) { #ifdef HW_RVL /* initialize DVDX */ DI_Init(); #endif /* initialize hardware */ gx_video_Init(); gx_input_Init(); #ifdef HW_DOL DVD_Init (); dvd_drive_detect(); #endif /* initialize FAT devices */ if (fatInitDefault()) { /* check for default directories */ DIR_ITER *dir = NULL; /* base directory */ char pathname[MAXPATHLEN]; sprintf (pathname, DEFAULT_PATH); dir = diropen(pathname); if (dir == NULL) mkdir(pathname,S_IRWXU); else dirclose(dir); /* SRAM & Savestate files directory */ sprintf (pathname, "%s/saves",DEFAULT_PATH); dir = diropen(pathname); if (dir == NULL) mkdir(pathname,S_IRWXU); else dirclose(dir); /* Snapshot files directory */ sprintf (pathname, "%s/snaps",DEFAULT_PATH); dir = diropen(pathname); if (dir == NULL) mkdir(pathname,S_IRWXU); else dirclose(dir); /* Cheat files directory */ sprintf (pathname, "%s/cheats",DEFAULT_PATH); dir = diropen(pathname); if (dir == NULL) mkdir(pathname,S_IRWXU); else dirclose(dir); } /* initialize sound engine */ gx_audio_Init(); /* initialize core engine */ legal(); config_default(); history_default(); init_machine(); /* run any injected rom */ if (cart.romsize) { ARAMFetch((char *)cart.rom, (void *)0x8000, cart.romsize); reloadrom (cart.romsize,"INJECT.bin"); gx_video_Start(); gx_audio_Start(); frameticker = 1; } else { /* Main Menu */ ConfigRequested = 1; } /* initialize GUI engine */ GUI_Initialize(); #ifdef HW_RVL /* Power button callback */ SYS_SetPowerCallback(Power_Off); #endif /* main emulation loop */ while (1) { /* Main Menu request */ if (ConfigRequested) { /* stop video & audio */ gx_audio_Stop(); gx_video_Stop(); /* show menu */ MainMenu (); ConfigRequested = 0; /* start video & audio */ gx_audio_Start(); gx_video_Start(); frameticker = 1; } if (frameticker > 1) { /* skip frame */ system_frame(1); --frameticker; } else { while (frameticker < 1) usleep(10); /* render frame */ system_frame(0); --frameticker; /* update video */ gx_video_Update(); } /* update audio */ gx_audio_Update(); } return 0; }
// parse options and trigger actions void parse_options (int argc, char *argv[]) { int option_index = 0, option_id = 0; static struct option long_options[] = { { "in", required_argument, NULL, 'i' }, { "out", required_argument, NULL, 'o' }, { "filetype", required_argument, NULL, 't' }, { "format", required_argument, NULL, 'f' }, { "threads", required_argument, NULL, 'n' }, { "color", no_argument, NULL, 'c' }, { "base", no_argument, NULL, 'b' }, { "verbose", no_argument, NULL, 'v' }, { "help", no_argument, NULL, 'h' }, { 0, 0, 0, 0 } }; if (argc <= 0 || !argv) { debug_printf (MESSAGE_ERROR, stderr, "fatal: No parameters\n"); exit (1); } config_default (&config); while (option_id >= 0) { option_id = getopt_long (argc, argv, "i:o:t:f:n:cbvh", long_options, &option_index); switch (option_id) { case 'i': config.filename_input = optarg; break; case 'o': config.filename_output = optarg; break; case 't': config.filetype = 1; break; case 'f': if (optarg == NULL) config.format = GADGET_CACHE_LINE; else if (strcmp (optarg, "line") == 0) config.format = GADGET_CACHE_LINE; else if (strcmp (optarg, "stack") == 0) config.format = GADGET_CACHE_STACK; break; case 'n': config.n_threads = strtol (optarg, NULL, 10); break; case 'c': config.color = GADGET_CACHE_COLOR; break; case 'b': config.base_address = GADGET_CACHE_BASE; break; case 'v': if (config.verbose_level < 3) config.verbose_level++; break; case 'h': usage(argv[0]); exit(1); break; default: break; } } if (config.verbose_level > 0) debug_set_verbose_level (config.verbose_level); if (config.n_threads == LONG_MIN || config.n_threads == LONG_MAX || config.n_threads <= 0 || config.n_threads > 8) { debug_printf (MESSAGE_ERROR, stderr, "error: n_threads should be between 0-8\n"); exit (1); } if (config.filename_input == NULL) { debug_printf (MESSAGE_ERROR, stderr, "error: --input not defined\n"); exit(-1); } if (config.format == 0) { debug_printf (MESSAGE_ERROR, stderr, "fatal: format should be either 'stack' or 'line'\n"); exit (1); } }