- Timestamp:
- 07/20/2017 04:19:40 PM (7 years ago)
- Branches:
- master
- Children:
- 51b6cfd
- Parents:
- a06aa8b
- Location:
- emu
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
emu/all.h
ra06aa8b rb909777 52 52 extern void sdl_quit(void); 53 53 54 extern void cpu_loop( void);54 extern void cpu_loop(const char *bios); 55 55 56 56 extern void fpu_init(void); -
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"); -
emu/main.c
ra06aa8b rb909777 18 18 #include <all.h> 19 19 20 typedef struct { 21 const char *name; 22 bool *flag; 23 } verb_flag_t; 24 25 static verb_flag_t verb_flags[] = { 26 { "sdl", &sdl_verbose }, 27 { "cpu", &cpu_verbose }, 28 { "fpu", &fpu_verbose }, 29 { "vid", &vid_verbose }, 30 { "tim", &tim_verbose }, 31 { "lcd", &lcd_verbose }, 32 { "ser", &ser_verbose }, 33 { "mid", &mid_verbose }, 34 { "fdd", &fdd_verbose }, 35 { "snd", &snd_verbose }, 36 { "led", &led_verbose }, 37 { "kbd", &kbd_verbose } 38 }; 39 40 static const char *bios = "bios.abs"; 41 42 static void usage(FILE *fh) 43 { 44 fprintf(fh, "usage: buchla [-h] [-v comp [-v comp [...]]] [-b bios]\n"); 45 fprintf(fh, "where comp is one of: "); 46 47 for (int32_t i = 0; i < ARRAY_COUNT(verb_flags); ++i) { 48 fprintf(fh, "%s, ", verb_flags[i].name); 49 } 50 51 fprintf(fh, "all\n"); 52 } 53 54 static void parse_args(int32_t argc, char *argv[]) 55 { 56 for (int32_t i = 0; i < argc; ++i) { 57 if (strcmp(argv[i], "-h") == 0) { 58 usage(stdout); 59 exit(0); 60 } 61 62 if (strcmp(argv[i], "-b") == 0) { 63 if (++i == argc) { 64 usage(stderr); 65 fprintf(stderr, "missing argument to -b\n"); 66 exit(1); 67 } 68 69 bios = argv[i]; 70 continue; 71 } 72 73 if (strcmp(argv[i], "-v") == 0) { 74 if (++i == argc) { 75 usage(stderr); 76 fprintf(stderr, "missing argument to -v\n"); 77 exit(1); 78 } 79 80 int32_t k; 81 82 if (strcmp(argv[i], "all") == 0) { 83 for (k = 0; k < ARRAY_COUNT(verb_flags); ++k) { 84 *verb_flags[k].flag = true; 85 } 86 87 continue; 88 } 89 90 for (k = 0; k < ARRAY_COUNT(verb_flags); ++k) { 91 if (strcmp(argv[i], verb_flags[k].name) == 0) { 92 *verb_flags[k].flag = true; 93 break; 94 } 95 } 96 97 if (k == ARRAY_COUNT(verb_flags)) { 98 usage(stderr); 99 fprintf(stderr, "invalid argument to -v: %s\n", argv[i]); 100 exit(1); 101 } 102 103 continue; 104 } 105 } 106 } 107 20 108 int32_t main(int32_t argc, char *argv[]) 21 109 { 22 (void)argc; 23 (void)argv; 24 110 parse_args(argc, argv); 25 111 sdl_init(); 26 112 27 cpu_verbose = true; 28 cpu_loop(); 113 cpu_loop(bios); 29 114 30 115 sdl_quit();
Note:
See TracChangeset
for help on using the changeset viewer.