Mercurial > repos > blastem
comparison system.c @ 1117:928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 22 Dec 2016 19:51:25 -0800 |
parents | 2eb54e24914e |
children | 4490c9c12272 |
comparison
equal
deleted
inserted
replaced
1116:fe8c79f82c22 | 1117:928a65750345 |
---|---|
1 #include <string.h> | 1 #include <string.h> |
2 #include "system.h" | 2 #include "system.h" |
3 #include "genesis.h" | 3 #include "genesis.h" |
4 #include "sms.h" | |
5 | |
6 uint8_t safe_cmp(char *str, long offset, uint8_t *buffer, long filesize) | |
7 { | |
8 long len = strlen(str); | |
9 return filesize >= offset+len && !memcmp(str, buffer + offset, len); | |
10 } | |
4 | 11 |
5 system_type detect_system_type(uint8_t *rom, long filesize) | 12 system_type detect_system_type(uint8_t *rom, long filesize) |
6 { | 13 { |
7 if (filesize >= 0x104 && !memcmp("SEGA", rom + 0x100, 4)) { | 14 if (safe_cmp("SEGA", 0x100, rom, filesize)) { |
8 //TODO: Differentiate between vanilla Genesis and Sega CD/32X games | 15 //TODO: Differentiate between vanilla Genesis and Sega CD/32X games |
9 return SYSTEM_GENESIS; | 16 return SYSTEM_GENESIS; |
10 } | 17 } |
11 //TODO: Detect SMS and Jaguar ROMs here | 18 if (safe_cmp("TMR SEGA", 0x1FF0, rom, filesize) |
19 || safe_cmp("TMR SEGA", 0x3FF0, rom, filesize) | |
20 || safe_cmp("TMR SEGA", 0x7FF0, rom, filesize) | |
21 ) { | |
22 return SYSTEM_SMS; | |
23 } | |
24 //TODO: Detect Jaguar ROMs here | |
12 | 25 |
13 //More certain checks failed, look for a valid 68K reset vector | 26 //More certain checks failed, look for a valid 68K reset vector |
14 if (filesize >= 8) { | 27 if (filesize >= 8) { |
15 uint32_t reset = rom[4] << 24 | rom[5] << 16 | rom[6] << 8 | rom[7]; | 28 uint32_t reset = rom[4] << 24 | rom[5] << 16 | rom[6] << 8 | rom[7]; |
16 if (!(reset & 1) && reset < filesize) { | 29 if (!(reset & 1) && reset < filesize) { |
25 { | 38 { |
26 switch (stype) | 39 switch (stype) |
27 { | 40 { |
28 case SYSTEM_GENESIS: | 41 case SYSTEM_GENESIS: |
29 return &(alloc_config_genesis(rom, rom_size, lock_on, lock_on_size, opts, force_region, info_out))->header; | 42 return &(alloc_config_genesis(rom, rom_size, lock_on, lock_on_size, opts, force_region, info_out))->header; |
43 #ifndef NO_Z80 | |
44 case SYSTEM_SMS: | |
45 return &(alloc_configure_sms(rom, rom_size, lock_on, lock_on_size, opts, force_region, info_out))->header; | |
46 #endif | |
30 default: | 47 default: |
31 return NULL; | 48 return NULL; |
32 } | 49 } |
33 } | 50 } |