⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 memory.c

📁 psp上的GBA模拟器
💻 C
📖 第 1 页 / 共 5 页
字号:
      break;                                                                  \                                                                              \    case 0x06:                                                                \      /* VRAM */                                                              \      address &= 0x1FFFF;                                                     \      if(address >= 0x18000)                                                  \        address -= 0x8000;                                                    \                                                                              \      write_vram##type();                                                     \      break;                                                                  \                                                                              \    case 0x07:                                                                \      /* OAM RAM */                                                           \      oam_update = 1;                                                         \      address##type(oam_ram, address & 0x3FF) = value;                        \      break;                                                                  \                                                                              \    case 0x08:                                                                \      /* gamepak ROM or RTC */                                                \      write_rtc##type();                                                      \      break;                                                                  \                                                                              \    case 0x09 ... 0x0C:                                                       \      /* gamepak ROM space */                                                 \      break;                                                                  \                                                                              \    case 0x0D:                                                                \      write_eeprom(address, value);                                           \      break;                                                                  \                                                                              \    case 0x0E:                                                                \      write_backup##type();                                                   \      break;                                                                  \  }                                                                           \u8 function_cc read_memory8(u32 address){  u8 value;  read_memory(8);  return value;}u16 function_cc read_memory16_signed(u32 address){  u16 value;  if(address & 0x01)  {    return (s8)read_memory8(address);  }  else  {    read_memory(16);  }  return value;}// unaligned reads are actually 32bitu32 function_cc read_memory16(u32 address){  u32 value;  if(address & 0x01)  {    address &= ~0x01;    read_memory(16);    ror(value, value, 8);  }  else  {    read_memory(16);  }  return value;}u32 function_cc read_memory32(u32 address){  u32 value;  if(address & 0x03)  {    u32 rotate = (address & 0x03) * 8;    address &= ~0x03;    read_memory(32);    ror(value, value, rotate);  }  else  {    read_memory(32);  }  return value;}cpu_alert_type function_cc write_memory8(u32 address, u8 value){  write_memory(8);  return CPU_ALERT_NONE;}cpu_alert_type function_cc write_memory16(u32 address, u16 value){  write_memory(16);  return CPU_ALERT_NONE;}cpu_alert_type function_cc write_memory32(u32 address, u32 value){  write_memory(32);  return CPU_ALERT_NONE;}char backup_filename[512];u32 load_backup(char *name){  file_open(backup_file, name, read);  if(file_check_valid(backup_file))  {    u32 backup_size = file_length(name, backup_file);    file_read(backup_file, gamepak_backup, backup_size);    file_close(backup_file);    // The size might give away what kind of backup it is.    switch(backup_size)    {      case 0x200:        backup_type = BACKUP_EEPROM;        eeprom_size = EEPROM_512_BYTE;        break;      case 0x2000:        backup_type = BACKUP_EEPROM;        eeprom_size = EEPROM_8_KBYTE;        break;      case 0x8000:        backup_type = BACKUP_SRAM;        sram_size = SRAM_SIZE_32KB;        break;      // Could be either flash or SRAM, go with flash      case 0x10000:        backup_type = BACKUP_FLASH;        sram_size = FLASH_SIZE_64KB;        break;      case 0x20000:        backup_type = BACKUP_FLASH;        flash_size = FLASH_SIZE_128KB;        break;    }    return 1;  }  else  {    backup_type = BACKUP_NONE;    memset(gamepak_backup, 0xFF, 1024 * 128);  }  return 0;}u32 save_backup(char *name){  if(backup_type != BACKUP_NONE)  {    file_open(backup_file, name, write);    if(file_check_valid(backup_file))    {      u32 backup_size;      switch(backup_type)      {        case BACKUP_SRAM:          if(sram_size == SRAM_SIZE_32KB)            backup_size = 0x8000;          else            backup_size = 0x10000;          break;        case BACKUP_FLASH:          if(flash_size == FLASH_SIZE_64KB)            backup_size = 0x10000;          else            backup_size = 0x20000;          break;        case BACKUP_EEPROM:          if(eeprom_size == EEPROM_512_BYTE)            backup_size = 0x200;          else            backup_size = 0x2000;          break;      }      file_write(backup_file, gamepak_backup, backup_size);      file_close(backup_file);      return 1;    }  }  return 0;}void update_backup(){  if(backup_update != (write_backup_delay + 1))    backup_update--;  if(backup_update == 0)  {    save_backup(backup_filename);    backup_update = write_backup_delay + 1;  }}void update_backup_force(){  save_backup(backup_filename);}#define CONFIG_FILENAME "game_config.txt"u8 *skip_spaces(u8 *line_ptr){  while(*line_ptr == ' ')    line_ptr++;  return line_ptr;}s32 parse_config_line(u8 *current_line, u8 *current_variable, u8 *current_value){  u8 *line_ptr = current_line;  u8 *line_ptr_new;  if((current_line[0] == 0) || (current_line[0] == '#'))    return -1;  line_ptr_new = strchr(line_ptr, ' ');  if(line_ptr_new == NULL)    return -1;  *line_ptr_new = 0;  strcpy(current_variable, line_ptr);  line_ptr_new = skip_spaces(line_ptr_new + 1);  if(*line_ptr_new != '=')    return -1;  line_ptr_new = skip_spaces(line_ptr_new + 1);  strcpy(current_value, line_ptr_new);  line_ptr_new = current_value + strlen(current_value) - 1;  if(*line_ptr_new == '\n')  {    line_ptr_new--;    *line_ptr_new = 0;  }  if(*line_ptr_new == '\r')    *line_ptr_new = 0;  return 0;}s32 load_game_config(u8 *gamepak_title, u8 *gamepak_code, u8 *gamepak_maker){  u8 current_line[256];  u8 current_variable[256];  u8 current_value[256];  u8 config_path[512];  u8 *line_ptr;  u32 fgets_value;  FILE *config_file;  idle_loop_target_pc = 0xFFFFFFFF;  iwram_stack_optimize = 1;  bios_rom[0x39] = 0x00;  bios_rom[0x2C] = 0x00;  translation_gate_targets = 0;  flash_device_id = FLASH_DEVICE_MACRONIX_64KB;#ifdef PSP_BUILD  sprintf(config_path, "%s/%s", main_path, CONFIG_FILENAME);#else  sprintf(config_path, "%s\\%s", main_path, CONFIG_FILENAME);#endif  config_file = fopen(config_path, "rb");  if(config_file)  {    while(fgets(current_line, 256, config_file))    {      if(parse_config_line(current_line, current_variable, current_value)       != -1)      {        if(strcmp(current_variable, "game_name") ||         strcmp(current_value, gamepak_title))          continue;        if(!fgets(current_line, 256, config_file) ||         (parse_config_line(current_line, current_variable,           current_value) == -1) ||         strcmp(current_variable, "game_code") ||         strcmp(current_value, gamepak_code))          continue;        if(!fgets(current_line, 256, config_file) ||         (parse_config_line(current_line, current_variable,           current_value) == -1) ||         strcmp(current_variable, "vender_code") ||          strcmp(current_value, gamepak_maker))          continue;        while(fgets(current_line, 256, config_file))        {          if(parse_config_line(current_line, current_variable, current_value)           != -1)          {            if(!strcmp(current_variable, "game_name"))            {              fclose(config_file);              return 0;            }            if(!strcmp(current_variable, "idle_loop_eliminate_target"))              idle_loop_target_pc = strtol(current_value, NULL, 16);            if(!strcmp(current_variable, "translation_gate_target"))            {              if(translation_gate_targets < MAX_TRANSLATION_GATES)              {                translation_gate_target_pc[translation_gate_targets] =                 strtol(current_value, NULL, 16);                translation_gate_targets++;              }            }            if(!strcmp(current_variable, "iwram_stack_optimize") &&              !strcmp(current_value, "no"))            {                iwram_stack_optimize = 0;            }            if(!strcmp(current_variable, "flash_rom_type") &&              !strcmp(current_value, "128KB"))            {              flash_device_id = FLASH_DEVICE_MACRONIX_128KB;            }            if(!strcmp(current_variable, "bios_rom_hack_39") &&              !strcmp(current_value, "yes"))            {              bios_rom[0x39] = 0xC0;            }            if(!strcmp(current_variable, "bios_rom_hack_2C") &&              !strcmp(current_value, "yes"))            {               bios_rom[0x2C] = 0x02;            }          }        }        fclose(config_file);        return 0;      }    }    fclose(config_file);  }  return -1;}s32 load_gamepak_raw(char *name){  file_open(gamepak_file, name, read);  if(file_check_valid(gamepak_file))  {    u32 gamepak_size = file_length(name, gamepak_file);    // First, close the last one if it was open, we won't    // be needing it anymore.    if(file_check_valid(gamepak_file_large))      file_close(gamepak_file_large);    // If it's a big file size keep it don't close it, we'll    // probably want to load it later    if(gamepak_size <= gamepak_ram_buffer_size)    {      file_read(gamepak_file, gamepak_rom, gamepak_size);      file_close(gamepak_file);#ifdef PSP_BUILD        gamepak_file_large = -1;#else        gamepak_file_large = NULL;#endif    }    else    {      // Read in just enough for the header      file_read(gamepak_file, gamepak_rom, 0x100);      gamepak_file_large = gamepak_file;    }    return gamepak_size;  }  return -1;}u8 gamepak_title[13];u8 gamepak_code[5];u8 gamepak_maker[3];u8 gamepak_filename[512];u32 load_gamepak(char *name){  char *dot_position = strrchr(name, '.');  s32 file_size;  u8 chea

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -