Mercurial > repos > blastem
comparison blastem.c @ 764:bb60259e8edf
Initial work on ROM database
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 02 Jul 2015 19:19:06 -0700 |
parents | cee1275f5d08 |
children | dc54387ee1cd |
comparison
equal
deleted
inserted
replaced
762:206c449eaa81 | 764:bb60259e8edf |
---|---|
11 #include "render.h" | 11 #include "render.h" |
12 #include "blastem.h" | 12 #include "blastem.h" |
13 #include "gdb_remote.h" | 13 #include "gdb_remote.h" |
14 #include "gst.h" | 14 #include "gst.h" |
15 #include "util.h" | 15 #include "util.h" |
16 #include "romdb.h" | |
16 #include <stdio.h> | 17 #include <stdio.h> |
17 #include <stdlib.h> | 18 #include <stdlib.h> |
18 #include <string.h> | 19 #include <string.h> |
19 | 20 |
20 #define BLASTEM_VERSION "0.2.0" | 21 #define BLASTEM_VERSION "0.2.0" |
62 | 63 |
63 uint16_t * dst = cart; | 64 uint16_t * dst = cart; |
64 while (filesize > 0) { | 65 while (filesize > 0) { |
65 fread(block, 1, SMD_BLOCK_SIZE, f); | 66 fread(block, 1, SMD_BLOCK_SIZE, f); |
66 for (uint8_t *low = block, *high = (block+SMD_BLOCK_SIZE/2), *end = block+SMD_BLOCK_SIZE; high < end; high++, low++) { | 67 for (uint8_t *low = block, *high = (block+SMD_BLOCK_SIZE/2), *end = block+SMD_BLOCK_SIZE; high < end; high++, low++) { |
67 *(dst++) = *high << 8 | *low; | 68 *(dst++) = *low << 8 | *high; |
68 } | 69 } |
69 filesize -= SMD_BLOCK_SIZE; | 70 filesize -= SMD_BLOCK_SIZE; |
70 } | 71 } |
71 return 1; | 72 return 1; |
73 } | |
74 | |
75 void byteswap_rom() | |
76 { | |
77 for(unsigned short * cur = cart; cur - cart < CARTRIDGE_WORDS; ++cur) | |
78 { | |
79 *cur = (*cur >> 8) | (*cur << 8); | |
80 } | |
72 } | 81 } |
73 | 82 |
74 int load_rom(char * filename) | 83 int load_rom(char * filename) |
75 { | 84 { |
76 uint8_t header[10]; | 85 uint8_t header[10]; |
101 return load_smd_rom(filesize, f); | 110 return load_smd_rom(filesize, f); |
102 } | 111 } |
103 } | 112 } |
104 fread(cart, 2, filesize/2, f); | 113 fread(cart, 2, filesize/2, f); |
105 fclose(f); | 114 fclose(f); |
106 for(unsigned short * cur = cart; cur - cart < (filesize/2); ++cur) | |
107 { | |
108 *cur = (*cur >> 8) | (*cur << 8); | |
109 } | |
110 //TODO: Mirror ROM | |
111 return 1; | 115 return 1; |
112 } | 116 } |
113 | 117 |
114 uint16_t read_dma_value(uint32_t address) | 118 uint16_t read_dma_value(uint32_t address) |
115 { | 119 { |
1063 } | 1067 } |
1064 m68k_reset(context); | 1068 m68k_reset(context); |
1065 } | 1069 } |
1066 } | 1070 } |
1067 | 1071 |
1068 char title[64]; | 1072 char *title; |
1069 | 1073 |
1070 #define TITLE_START 0x150 | 1074 #define TITLE_START 0x150 |
1071 #define TITLE_END (TITLE_START+48) | 1075 #define TITLE_END (TITLE_START+48) |
1072 | 1076 |
1073 void update_title() | 1077 void update_title(char *rom_name) |
1074 { | 1078 { |
1075 uint16_t *last = cart + TITLE_END/2 - 1; | 1079 if (title) { |
1076 while(last > cart + TITLE_START/2 && *last == 0x2020) | 1080 free(title); |
1077 { | 1081 title = NULL; |
1078 last--; | 1082 } |
1079 } | 1083 title = alloc_concat(rom_name, " - BlastEm"); |
1080 uint16_t *start = cart + TITLE_START/2; | |
1081 char *cur = title; | |
1082 char last_char = ' '; | |
1083 for (; start != last; start++) | |
1084 { | |
1085 if ((last_char != ' ' || (*start >> 8) != ' ') && (*start >> 8) < 0x80) { | |
1086 *(cur++) = *start >> 8; | |
1087 last_char = *start >> 8; | |
1088 } | |
1089 if (last_char != ' ' || (*start & 0xFF) != ' ' && (*start & 0xFF) < 0x80) { | |
1090 *(cur++) = *start; | |
1091 last_char = *start & 0xFF; | |
1092 } | |
1093 } | |
1094 *(cur++) = *start >> 8; | |
1095 if ((*start & 0xFF) != ' ') { | |
1096 *(cur++) = *start; | |
1097 } | |
1098 strcpy(cur, " - BlastEm"); | |
1099 } | 1084 } |
1100 | 1085 |
1101 #define REGION_START 0x1F0 | 1086 #define REGION_START 0x1F0 |
1102 | 1087 |
1103 int detect_specific_region(char region) | 1088 int detect_specific_region(char region) |
1269 } | 1254 } |
1270 if (!loaded) { | 1255 if (!loaded) { |
1271 fputs("You must specify a ROM filename!\n", stderr); | 1256 fputs("You must specify a ROM filename!\n", stderr); |
1272 return 1; | 1257 return 1; |
1273 } | 1258 } |
1259 tern_node *rom_db = load_rom_db(); | |
1260 rom_info info = configure_rom(rom_db, cart); | |
1261 byteswap_rom(); | |
1274 if (force_version) { | 1262 if (force_version) { |
1275 version_reg = force_version; | 1263 version_reg = force_version; |
1276 } else { | 1264 } else { |
1277 detect_region(); | 1265 detect_region(); |
1278 } | 1266 } |
1279 update_title(); | 1267 update_title(info.name); |
1280 int def_width = 0; | 1268 int def_width = 0; |
1281 char *config_width = tern_find_ptr(config, "videowidth"); | 1269 char *config_width = tern_find_ptr(config, "videowidth"); |
1282 if (config_width) { | 1270 if (config_width) { |
1283 def_width = atoi(config_width); | 1271 def_width = atoi(config_width); |
1284 } | 1272 } |