Changeset b909777 in buchla-emu for emu/cpu.c


Ignore:
Timestamp:
07/20/2017 04:19:40 PM (7 years ago)
Author:
Thomas Lopatic <thomas@…>
Branches:
master
Children:
51b6cfd
Parents:
a06aa8b
Message:

Parse command line options. Load BIOS file.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • emu/cpu.c

    ra06aa8b rb909777  
    5858static uint8_t rom_data[ROM_SIZE];
    5959
    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;
     60static uint32_t ram_rd_beg = 0x10000000;
     61static uint32_t ram_rd_end = 0x10000000;
     62static uint32_t ram_wr_beg = 0x10000000;
     63static uint32_t ram_wr_end = 0x10000000;
    6464
    6565static uint32_t rom_rd_beg;
     
    9494static void hw_init(void)
    9595{
     96        ver("initializing hardware");
     97
    9698        for (int32_t i = 0; i < ARRAY_COUNT(hw_map); ++i) {
    9799                hw_map[i].init();
     
    113115
    114116        return (addr - hw->addr_beg) / 2;
     117}
     118
     119static 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);
    115169}
    116170
     
    182236        if (reset) {
    183237                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;
    188243                        reset = false;
    189                         return RESET_PC;
    190                 }
    191 
    192                 fail("invalid reset sequence");
     244                }
     245                else {
     246                        fail("invalid reset sequence");
     247                }
    193248        }
    194249
     
    301356}
    302357
    303 void cpu_loop(void)
    304 {
    305         ver("initializing hardware");
     358void cpu_loop(const char *bios)
     359{
     360        ver("entering CPU loop");
     361
    306362        hw_init();
     363        bios_init(bios);
    307364
    308365        ver("starting CPU");
Note: See TracChangeset for help on using the changeset viewer.