- Timestamp:
- 07/20/2017 04:19:40 PM (7 years ago)
- Branches:
- master
- Children:
- 51b6cfd
- Parents:
- a06aa8b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
emu/cpu.c
ra06aa8b rb909777 58 58 static uint8_t rom_data[ROM_SIZE]; 59 59 60 static uint32_t ram_rd_beg ;61 static uint32_t ram_rd_end ;62 static uint32_t ram_wr_beg ;63 static uint32_t ram_wr_end ;60 static uint32_t ram_rd_beg = 0x10000000; 61 static uint32_t ram_rd_end = 0x10000000; 62 static uint32_t ram_wr_beg = 0x10000000; 63 static uint32_t ram_wr_end = 0x10000000; 64 64 65 65 static uint32_t rom_rd_beg; … … 94 94 static void hw_init(void) 95 95 { 96 ver("initializing hardware"); 97 96 98 for (int32_t i = 0; i < ARRAY_COUNT(hw_map); ++i) { 97 99 hw_map[i].init(); … … 113 115 114 116 return (addr - hw->addr_beg) / 2; 117 } 118 119 static void bios_init(const char *bios) 120 { 121 ver("loading BIOS file %s", bios); 122 123 SDL_RWops *ops = SDL_RWFromFile(bios, "rb"); 124 125 if (ops == NULL) { 126 fail("error while opening BIOS file %s", bios); 127 } 128 129 if (SDL_ReadBE16(ops) != 0x601b) { 130 fail("invalid BIOS file %s", bios); 131 } 132 133 uint32_t text_len = SDL_ReadBE32(ops); 134 uint32_t data_len = SDL_ReadBE32(ops); 135 uint32_t bss_len = SDL_ReadBE32(ops); 136 137 SDL_ReadBE32(ops); 138 SDL_ReadBE32(ops); 139 140 uint32_t text_loc = SDL_ReadBE32(ops); 141 142 SDL_ReadBE16(ops); 143 144 uint32_t data_loc = SDL_ReadBE32(ops); 145 uint32_t bss_loc = SDL_ReadBE32(ops); 146 147 ver("text 0x%x@0x%x data 0x%x@0x%x bss 0x%x@0x%x", 148 text_len, text_loc, data_len, data_loc, bss_len, bss_loc); 149 150 size_t load_len = (size_t)SDL_RWsize(ops) - 36; 151 152 if (load_len != text_len + data_len) { 153 fail("corrupted BIOS file %s", bios); 154 } 155 156 size_t loaded = 0; 157 158 while (loaded < load_len) { 159 size_t n_rd = SDL_RWread(ops, rom_data + loaded, 1, load_len - loaded); 160 161 if (n_rd == 0) { 162 fail("error while reading BIOS file %s", bios); 163 } 164 165 loaded += n_rd; 166 } 167 168 SDL_RWclose(ops); 115 169 } 116 170 … … 182 236 if (reset) { 183 237 if (addr == 0) { 184 return RESET_SP; 185 } 186 187 if (addr == 4) { 238 addr += ROM_START; 239 } 240 241 else if (addr == 4) { 242 addr += ROM_START; 188 243 reset = false; 189 return RESET_PC;190 }191 192 fail("invalid reset sequence");244 } 245 else { 246 fail("invalid reset sequence"); 247 } 193 248 } 194 249 … … 301 356 } 302 357 303 void cpu_loop(void) 304 { 305 ver("initializing hardware"); 358 void cpu_loop(const char *bios) 359 { 360 ver("entering CPU loop"); 361 306 362 hw_init(); 363 bios_init(bios); 307 364 308 365 ver("starting CPU");
Note:
See TracChangeset
for help on using the changeset viewer.