Mercurial > repos > blastem
comparison blastem.c @ 776:cbf97d335444
Full support for Sega mapper when it comes to data. Code in remapped sections may not work reliably. SSF2 now works.
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 20 Jul 2015 21:15:34 -0700 |
parents | 41dc895e85ff |
children | 79b10b421d3c |
comparison
equal
deleted
inserted
replaced
775:22728a57d7f3 | 776:cbf97d335444 |
---|---|
32 #define LINES_NTSC 262 | 32 #define LINES_NTSC 262 |
33 #define LINES_PAL 312 | 33 #define LINES_PAL 312 |
34 | 34 |
35 #define MAX_SOUND_CYCLES 100000 | 35 #define MAX_SOUND_CYCLES 100000 |
36 | 36 |
37 uint16_t cart[CARTRIDGE_WORDS]; | 37 uint16_t *cart; |
38 uint16_t ram[RAM_WORDS]; | 38 uint16_t ram[RAM_WORDS]; |
39 uint8_t z80_ram[Z80_RAM_BYTES]; | 39 uint8_t z80_ram[Z80_RAM_BYTES]; |
40 | 40 |
41 int headless = 0; | 41 int headless = 0; |
42 int exit_after = 0; | 42 int exit_after = 0; |
71 filesize -= SMD_BLOCK_SIZE; | 71 filesize -= SMD_BLOCK_SIZE; |
72 } | 72 } |
73 return filesize; | 73 return filesize; |
74 } | 74 } |
75 | 75 |
76 void byteswap_rom() | 76 void byteswap_rom(int filesize) |
77 { | 77 { |
78 for(unsigned short * cur = cart; cur - cart < CARTRIDGE_WORDS; ++cur) | 78 for(unsigned short * cur = cart; cur - cart < filesize/2; ++cur) |
79 { | 79 { |
80 *cur = (*cur >> 8) | (*cur << 8); | 80 *cur = (*cur >> 8) | (*cur << 8); |
81 } | 81 } |
82 } | 82 } |
83 | 83 |
86 uint8_t header[10]; | 86 uint8_t header[10]; |
87 FILE * f = fopen(filename, "rb"); | 87 FILE * f = fopen(filename, "rb"); |
88 if (!f) { | 88 if (!f) { |
89 return 0; | 89 return 0; |
90 } | 90 } |
91 fread(header, 1, sizeof(header), f); | 91 if (sizeof(header) != fread(header, 1, sizeof(header), f)) { |
92 fprintf(stderr, "Error reading from %s\n", filename); | |
93 exit(1); | |
94 } | |
92 fseek(f, 0, SEEK_END); | 95 fseek(f, 0, SEEK_END); |
93 long filesize = ftell(f); | 96 long filesize = ftell(f); |
94 if (filesize/2 > CARTRIDGE_WORDS) { | |
95 //carts bigger than 4MB not currently supported | |
96 filesize = CARTRIDGE_WORDS*2; | |
97 } | |
98 fseek(f, 0, SEEK_SET); | 97 fseek(f, 0, SEEK_SET); |
99 if (header[1] == SMD_MAGIC1 && header[8] == SMD_MAGIC2 && header[9] == SMD_MAGIC3) { | 98 if (header[1] == SMD_MAGIC1 && header[8] == SMD_MAGIC2 && header[9] == SMD_MAGIC3) { |
100 int i; | 99 int i; |
101 for (i = 3; i < 8; i++) { | 100 for (i = 3; i < 8; i++) { |
102 if (header[i] != 0) { | 101 if (header[i] != 0) { |
109 exit(1); | 108 exit(1); |
110 } | 109 } |
111 return load_smd_rom(filesize, f); | 110 return load_smd_rom(filesize, f); |
112 } | 111 } |
113 } | 112 } |
114 fread(cart, 2, filesize/2, f); | 113 cart = malloc(filesize); |
114 if (filesize != fread(cart, 1, filesize, f)) { | |
115 fprintf(stderr, "Error reading from %s\n", filename); | |
116 exit(1); | |
117 } | |
115 fclose(f); | 118 fclose(f); |
116 return filesize; | 119 return filesize; |
117 } | 120 } |
118 | 121 |
119 uint16_t read_dma_value(uint32_t address) | 122 uint16_t read_dma_value(uint32_t address) |
837 m68k_context *context = init_68k_context(&opts); | 840 m68k_context *context = init_68k_context(&opts); |
838 gen->m68k = context; | 841 gen->m68k = context; |
839 | 842 |
840 context->video_context = gen->vdp; | 843 context->video_context = gen->vdp; |
841 context->system = gen; | 844 context->system = gen; |
842 //cartridge ROM | 845 for (int i = 0; i < rom->map_chunks; i++) |
843 context->mem_pointers[0] = cart; | 846 { |
844 context->target_cycle = context->sync_cycle = gen->frame_end > gen->max_cycles ? gen->frame_end : gen->max_cycles; | 847 if (rom->map[i].flags & MMAP_PTR_IDX) { |
845 //work RAM | 848 context->mem_pointers[rom->map[i].ptr_index] = rom->map[i].buffer; |
846 context->mem_pointers[1] = ram; | 849 } |
847 //save RAM/map | 850 } |
848 context->mem_pointers[2] = rom->map[1].buffer; | |
849 context->mem_pointers[3] = (uint16_t *)gen->save_storage; | |
850 | 851 |
851 if (statefile) { | 852 if (statefile) { |
852 uint32_t pc = load_gst(gen, statefile); | 853 uint32_t pc = load_gst(gen, statefile); |
853 if (!pc) { | 854 if (!pc) { |
854 fprintf(stderr, "Failed to load save state %s\n", statefile); | 855 fprintf(stderr, "Failed to load save state %s\n", statefile); |
1024 fputs("You must specify a ROM filename!\n", stderr); | 1025 fputs("You must specify a ROM filename!\n", stderr); |
1025 return 1; | 1026 return 1; |
1026 } | 1027 } |
1027 tern_node *rom_db = load_rom_db(); | 1028 tern_node *rom_db = load_rom_db(); |
1028 rom_info info = configure_rom(rom_db, cart, rom_size, base_map, sizeof(base_map)/sizeof(base_map[0])); | 1029 rom_info info = configure_rom(rom_db, cart, rom_size, base_map, sizeof(base_map)/sizeof(base_map[0])); |
1029 byteswap_rom(); | 1030 byteswap_rom(rom_size); |
1030 set_region(&info, force_version); | 1031 set_region(&info, force_version); |
1031 update_title(info.name); | 1032 update_title(info.name); |
1032 int def_width = 0; | 1033 int def_width = 0; |
1033 char *config_width = tern_find_path(config, "video\0width\0").ptrval; | 1034 char *config_width = tern_find_path(config, "video\0width\0").ptrval; |
1034 if (config_width) { | 1035 if (config_width) { |