- Timestamp:
- 09/10/2017 10:49:20 PM (7 years ago)
- Branches:
- master
- Children:
- 0529a19, 3311af2
- Parents:
- 67fecc3
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
emu/cpu.c
r67fecc3 r0d83ce8 24 24 int32_t cpu_verbose = 0; 25 25 26 #define MIDAS_ABS "midas.abs" 27 26 28 #define CPU_FREQ 7000000 27 29 #define PER_SEC 100000 … … 51 53 hw_write_t write; 52 54 } hw_t; 55 56 typedef struct { 57 uint32_t text_loc; 58 uint32_t text_len; 59 uint32_t data_loc; 60 uint32_t data_len; 61 uint32_t bss_loc; 62 uint32_t bss_len; 63 size_t load_len; 64 SDL_RWops *ops; 65 } abs_t; 53 66 54 67 static uint64_t freq; … … 136 149 } 137 150 151 static void open_abs(const char *path, abs_t *abs) 152 { 153 abs->ops = SDL_RWFromFile(path, "rb"); 154 155 if (abs->ops == NULL) { 156 fail("error while opening .abs file %s", path); 157 } 158 159 if (SDL_ReadBE16(abs->ops) != 0x601b) { 160 fail("invalid .abs file %s", path); 161 } 162 163 abs->text_len = SDL_ReadBE32(abs->ops); 164 abs->data_len = SDL_ReadBE32(abs->ops); 165 abs->bss_len = SDL_ReadBE32(abs->ops); 166 167 SDL_ReadBE32(abs->ops); 168 SDL_ReadBE32(abs->ops); 169 170 abs->text_loc = SDL_ReadBE32(abs->ops); 171 172 SDL_ReadBE16(abs->ops); 173 174 abs->data_loc = SDL_ReadBE32(abs->ops); 175 abs->bss_loc = SDL_ReadBE32(abs->ops); 176 177 inf("text 0x%x:0x%x data 0x%x:0x%x bss 0x%x:0x%x", 178 abs->text_loc, abs->text_len, abs->data_loc, abs->data_len, abs->bss_loc, abs->bss_len); 179 180 abs->load_len = (size_t)SDL_RWsize(abs->ops) - 36; 181 } 182 183 static void load_abs(const char *path, abs_t *abs, uint8_t *data) 184 { 185 size_t loaded = 0; 186 187 while (loaded < abs->load_len) { 188 size_t n_rd = SDL_RWread(abs->ops, data + loaded, 1, abs->load_len - loaded); 189 190 if (n_rd == 0) { 191 fail("error while reading .abs file %s", path); 192 } 193 194 loaded += n_rd; 195 } 196 197 SDL_RWclose(abs->ops); 198 } 199 138 200 static void bios_init(void) 139 201 { 140 202 inf("loading BIOS file %s", bios); 141 203 142 SDL_RWops *ops = SDL_RWFromFile(bios, "rb"); 143 144 if (ops == NULL) { 145 fail("error while opening BIOS file %s", bios); 146 } 147 148 if (SDL_ReadBE16(ops) != 0x601b) { 204 abs_t abs; 205 open_abs(bios, &abs); 206 207 if (abs.text_loc != ROM_START || abs.text_loc + abs.text_len != abs.data_loc || 208 abs.load_len != abs.text_len + abs.data_len || abs.load_len > ROM_SIZE) { 149 209 fail("invalid BIOS file %s", bios); 150 210 } 151 211 152 uint32_t text_len = SDL_ReadBE32(ops); 153 uint32_t data_len = SDL_ReadBE32(ops); 154 uint32_t bss_len = SDL_ReadBE32(ops); 155 156 SDL_ReadBE32(ops); 157 SDL_ReadBE32(ops); 158 159 uint32_t text_loc = SDL_ReadBE32(ops); 160 161 SDL_ReadBE16(ops); 162 163 uint32_t data_loc = SDL_ReadBE32(ops); 164 uint32_t bss_loc = SDL_ReadBE32(ops); 165 166 inf("BIOS text 0x%x:0x%x data 0x%x:0x%x bss 0x%x:0x%x", 167 text_loc, text_len, data_loc, data_len, bss_loc, bss_len); 168 169 size_t load_len = (size_t)SDL_RWsize(ops) - 36; 170 171 if (text_loc != ROM_START || text_loc + text_len != data_loc || 172 load_len != text_len + data_len || load_len > ROM_SIZE) { 173 fail("invalid BIOS file %s", bios); 174 } 175 176 size_t loaded = 0; 177 178 while (loaded < load_len) { 179 size_t n_rd = SDL_RWread(ops, rom_data + loaded, 1, load_len - loaded); 180 181 if (n_rd == 0) { 182 fail("error while reading BIOS file %s", bios); 183 } 184 185 loaded += n_rd; 186 } 187 188 SDL_RWclose(ops); 189 190 rom_ro_beg = text_loc; 191 rom_ro_end = text_loc + text_len + data_len; 192 rom_rw_beg = bss_loc; 193 rom_rw_end = bss_loc + bss_len; 212 load_abs(bios, &abs, rom_data); 213 214 rom_ro_beg = abs.text_loc; 215 rom_ro_end = abs.text_loc + abs.text_len + abs.data_len; 216 rom_rw_beg = abs.bss_loc; 217 rom_rw_end = abs.bss_loc + abs.bss_len; 194 218 195 219 ver("rom_ro_beg 0x%08x rom_ro_end 0x%08x", rom_ro_beg, rom_ro_end); 196 220 ver("rom_rw_beg 0x%08x rom_rw_end 0x%08x", rom_rw_beg, rom_rw_end); 221 } 222 223 static void midas_init(void) 224 { 225 SDL_RWops *ops = SDL_RWFromFile(MIDAS_ABS, "rb"); 226 227 if (ops == NULL) { 228 return; 229 } 230 231 SDL_RWclose(ops); 232 233 inf("loading MIDAS file " MIDAS_ABS); 234 235 abs_t abs; 236 open_abs(MIDAS_ABS, &abs); 237 238 if (abs.text_loc != APP_START || 239 abs.text_loc + abs.text_len != abs.data_loc || 240 abs.data_loc + abs.data_len != abs.bss_loc || 241 abs.load_len != abs.text_len + abs.data_len || 242 abs.bss_loc + abs.bss_len > RAM_SIZE) { 243 fail("invalid MIDAS file " MIDAS_ABS); 244 } 245 246 load_abs(MIDAS_ABS, &abs, ram_data + APP_START - RAM_START); 247 248 ram_ro_beg = ram_rw_beg = APP_START; 249 ram_ro_end = ram_rw_end = RAM_START + RAM_SIZE; 197 250 } 198 251 … … 666 719 hw_init(); 667 720 bios_init(); 721 midas_init(); 668 722 669 723 m68k_init();
Note:
See TracChangeset
for help on using the changeset viewer.