//----------------------------------------------------------------------------- // Memory_Alloc (int size) // Allocate memory using malloc(), abort if unavailable //----------------------------------------------------------------------------- void *Memory_Alloc (int size) { byte *p; if ((p = malloc (size)) == NULL) { meka_errno = MEKA_ERR_MEMORY; Quit_Msg (meka_strerror()); } return (p); }
void Blitters_Init() { ConsolePrint(Msg_Get(MSG_Blitters_Loading)); Blitters.list = NULL; Blitters.current = NULL; // Open and read file t_tfile * tf; if ((tf = tfile_read (Blitters.filename)) == NULL) Quit_Msg("%s", meka_strerror()); ConsolePrint("\n"); // Parse each line int line_cnt = 0; for (t_list* lines = tf->data_lines; lines; lines = lines->next) { const char* line = (char*)lines->elem; line_cnt += 1; int i, j; char s1 [256], s2 [256]; for (i = 0, j = 0; line [i] != 0 && line [i] != ';'; i ++) if ((line [0] == '[') || (line [i] != ' ' && line [i] != '\t')) s2 [j ++] = line [i]; s2 [j] = 0; if (StrIsNull (s2)) continue; strcpy(s1, s2); StrLower(s1); switch (Blitters_Parse_Line (s1, s2)) { case MEKA_ERR_UNKNOWN: tfile_free(tf); Quit_Msg(Msg_Get(MSG_Blitters_Error_Unrecognized), line_cnt); case MEKA_ERR_MISSING: tfile_free(tf); Quit_Msg(Msg_Get(MSG_Blitters_Error_Missing), line_cnt); case MEKA_ERR_VALUE_INCORRECT: tfile_free(tf); Quit_Msg(Msg_Get(MSG_Blitters_Error_Incorrect_Value), line_cnt); } } // Free file data tfile_free(tf); // Requires at least 1 blitter if (Blitters.count == 0) Quit_Msg("%s", Msg_Get(MSG_Blitters_Error_Not_Enough)); // Current blitter if (Blitters.blitter_configuration_name != NULL) Blitters.current = Blitters_FindBlitterByName(Blitters.blitter_configuration_name); if (Blitters.current == NULL) Blitters.current = (t_blitter*)Blitters.list->elem; // first }
//----------------------------------------------------------------------------- // DB_Load (const char *filename) // Initialize and load given Meka DB file //----------------------------------------------------------------------------- void DB_Load (const char *filename) { t_tfile * tf; t_list * lines; char * line; int line_cnt; ConsolePrint (Msg_Get (MSG_DB_Loading)); // Open and read file tf = tfile_read (filename); if (tf == NULL) { ConsolePrintf ("%s\n", meka_strerror()); return; } // Ok ConsolePrint ("\n"); // Parse each line line_cnt = 0; for (lines = tf->data_lines; lines; lines = lines->next) { line_cnt += 1; line = lines->elem; // Strip comments // FIXME // Trim spaces? // FIXME // Skip empty lines //if (line[0] == EOSTR) // continue; if (DB_Load_Line (line) == 0) { tfile_free (tf); Quit_Msg (Msg_Get (MSG_DB_SyntaxError), line_cnt); } } // Free file data tfile_free(tf); // FIXME - Uncomment for counting progress of DB transition //ConsolePrintf ("ENTRIES NEW = %d, OLD = %d\n", DB.entries_counter_format_new, DB.entries_counter_format_old); //Quit(); }
//----------------------------------------------------------------------------- // VLFN_DataBase_Load (void) // Load VLFN database from MEKA.FDB file. //----------------------------------------------------------------------------- void VLFN_DataBase_Load (void) { t_tfile * tf; t_list * lines; char * line; int line_cnt; ConsolePrint (Msg_Get (MSG_FDB_Loading)); // Open and read file tf = tfile_read (VLFN_DataBase.filename); if (tf == NULL) { ConsolePrintf ("%s\n", meka_strerror()); return; } // Ok ConsolePrint ("\n"); // Parse each line line_cnt = 0; for (lines = tf->data_lines; lines; lines = lines->next) { char * w; line_cnt += 1; line = lines->elem; w = parse_getword(NULL, 0, &line, "/", ';', 0); if (w == NULL) continue; else { char buf[1024]; char * file_name; u32 crc_crc32; t_meka_crc crc_mekacrc; // Save allocated filename file_name = w; // Get CRCs crc_crc32 = 0; crc_mekacrc.v[0] = crc_mekacrc.v[1] = 0; while ((w = parse_getword(buf, 1024, &line, "/", ';', 0)) != NULL) { if (!strncmp(w, "MEKACRC:", 8)) { if (sscanf(w + 8, "%08X%08X", &crc_mekacrc.v[0], &crc_mekacrc.v[1]) != 2) continue; // Syntax error } else if (!strncmp(w, "CRC32:", 6)) { if (sscanf(w + 6, "%08x", &crc_crc32) != 1) continue; // Syntax error } } // Requires at least MekaCRC // (to be changed by CRC32 when MekaCRC is dropped) if (crc_mekacrc.v[0] == 0 && crc_mekacrc.v[1] == 0) continue; { // Find DB entry t_db_entry *db_entry = DB_Entry_Find (crc_crc32, &crc_mekacrc); if (db_entry) { // Create VLFN entry t_vlfn_entry * entry; entry = VLFN_Entry_New (file_name, db_entry); list_add (&VLFN_DataBase.entries, entry); } } } } // Free file data tfile_free (tf); }
void Load_Inputs_Src_List (void) { int i; char w[256]; t_input_src * input_src = NULL; t_tfile * tf; t_list * lines; int line_cnt; // Open and read file ConsolePrint (Msg_Get (MSG_Inputs_Src_Loading)); tf = tfile_read (Inputs.FileName); if (tf == NULL) Quit_Msg (meka_strerror()); ConsolePrint ("\n"); // Parse each line line_cnt = 0; for (lines = tf->data_lines; lines; lines = lines->next) { char *line; line_cnt += 1; line = lines->elem; if (StrNull(line)) continue; if (line[0] == '[' && line[strlen(line) - 1] == ']') { input_src = Inputs_Sources_Add (StrNDup (line + 1, strlen(line) - 2)); // ConsolePrintf ("new source --> %s <--\n", CurSrc->Name); continue; } strlwr(line); if (!parse_getword(w, sizeof(w), &line, "=", ';', PARSE_FLAGS_NONE)) continue; for (i = 0; Inputs_Src_List_KeyWords[i]; i++) if (strcmp(w, Inputs_Src_List_KeyWords[i]) == 0) { // FIXME: this is ugly if (input_src == NULL && strcmp (w, "joy_driver") != 0 && strcmp (w, "mouse_speed_x") != 0 && strcmp (w, "mouse_speed_y") != 0 && strcmp (w, "cabinet_mode") != 0) { tfile_free(tf); Quit_Msg (Msg_Get (MSG_Inputs_Src_Missing), line_cnt); } parse_skip_spaces(&line); if (!parse_getword(w, sizeof(w), &line, "", ';', PARSE_FLAGS_NONE)) { tfile_free(tf); Quit_Msg (Msg_Get (MSG_Inputs_Src_Equal), line_cnt); } switch (Load_Inputs_Src_Parse_Var(i, w, input_src)) { case MEKA_ERR_SYNTAX: tfile_free(tf); Quit_Msg (Msg_Get (MSG_Inputs_Src_Syntax_Param), line_cnt); case MEKA_ERR_INCOHERENT : tfile_free(tf); Quit_Msg (Msg_Get (MSG_Inputs_Src_Inconsistency), line_cnt); break; // FIXME: EMPTY is not handled there } break; } if (!Inputs_Src_List_KeyWords [i]) { tfile_free(tf); Quit_Msg (Msg_Get (MSG_Inputs_Src_Unrecognized), line_cnt, w); } } // Free file data tfile_free(tf); // Verify that we have enough inputs sources if (Inputs.Sources_Max == 0) Quit_Msg (Msg_Get (MSG_Inputs_Src_Not_Enough)); }
// Load media/ROM from given filename. // If user_verbose if false, avoid printing stuff to the message box // Note: path to ROM filename must be set in 'g_env.Paths.MediaImageFile' before calling this bool Load_ROM(t_load_mode load_mode, bool user_verbose) { // Set file global flag Loading_UserVerbose = user_verbose; switch (load_mode) { case LOAD_MODE_COMMANDLINE: if (user_verbose) ConsolePrint(Msg_Get(MSG_LoadROM_Loading)); break; case LOAD_MODE_GUI: // FIXME: do not save Backed Memory in non-verbose mode // This mode is only used by the file browser. This way we avoid loading // and saving all battery backed memory when doing a "Load All". // Of course, this is a little hack but it's better this way. if (user_verbose) BMemory_Save(); break; } if (Load_ROM_Main() != MEKA_ERR_OK) { switch (load_mode) { case LOAD_MODE_COMMANDLINE: Quit_Msg("%s\n\"%s\"\n", meka_strerror(), g_env.Paths.MediaImageFile); return false; case LOAD_MODE_GUI: Msg(MSGT_USER, Msg_Get(MSG_Error_Base), meka_strerror()); return false; } } // If we are already in SF-7000 mode, do not reset (allows hot switching disks) const bool reset = (g_driver->id != DRV_SF7000); // Miscellaneous stuff (including reset) Load_ROM_Misc(reset); if (load_mode == LOAD_MODE_COMMANDLINE) { if (user_verbose) ConsolePrint("\n"); if (opt.State_Load != -1) { opt.State_Current = opt.State_Load; // Note: we're not calling the function to avoid displaying the 'slot change' message opt.State_Load = -1; SaveState_Load(); } } // Verbose if (user_verbose) { // Display success message char filename[FILENAME_LEN]; StrPath_RemoveDirectory(filename, g_env.Paths.MediaImageFile); if (g_driver->id != DRV_SF7000) Msg(MSGT_USER, Msg_Get(MSG_LoadROM_Success), filename); else Msg(MSGT_USER, Msg_Get(MSG_LoadDisk_Success), filename); // Display data from DB if (DB.current_entry) { // Name Msg(MSGT_USER, "\"%s\"", DB_Entry_GetCurrentName (DB.current_entry)); // Comment if (DB.current_entry->comments) Msg(MSGT_USER_LOG, Msg_Get(MSG_LoadROM_Comment), DB.current_entry->comments); // Show SMS-GG mode info if (DB.current_entry->flags & DB_FLAG_SMSGG_MODE) { if (DB.current_entry->comments) // Append to comment message Msg(MSGT_USER_LOG, "%s", Msg_Get(MSG_LoadROM_SMSGG_Mode_Comment)); else // Print the comment marker before Msg(MSGT_USER_LOG, Msg_Get(MSG_LoadROM_Comment), Msg_Get(MSG_LoadROM_SMSGG_Mode_Comment)); } // Show BAD ROM warning if (DB.current_entry->flags & DB_FLAG_BAD) { Msg(MSGT_USER_LOG, "%s", Msg_Get(MSG_LoadROM_Warning)); Msg(MSGT_USER_LOG, "%s", Msg_Get(MSG_LoadROM_Bad_Dump_Long)); Msg(MSGT_STATUS_BAR, "%s", Msg_Get(MSG_LoadROM_Bad_Dump_Short)); } // Show Product Number if (DB.current_entry->product_no && g_config.show_product_number) Msg(MSGT_USER_LOG, Msg_Get(MSG_LoadROM_Product_Num), DB.current_entry->product_no); } // Show SDSC Header if (user_verbose) SDSC_Read_and_Display(); } // Automatically change input peripheral depending on MEKA.NAM entry // FIXME: we don't do it at all if !user_verbose, to save us from passing // the verbose flag all down to inputs peripherals changing functions. // Since the verbose flag is only cleared by the file browser "Load All" // functionality, it is ok to avoid changing inputs. if (user_verbose) Input_ROM_Change(); return true; }