Skip to content

Commit eef0ef5

Browse files
committed
add support for rom.bin types. add support in mgb to overload the console, region and system.
1 parent 15df0c7 commit eef0ef5

5 files changed

Lines changed: 45 additions & 6 deletions

File tree

src/core/sms_vdp.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,8 @@ static void vdp_parse_sg_sprites(struct SMS_Core* sms, int line)
913913

914914
const uint16_t sprite_attribute_base_addr = vdp_get_sprite_attribute_base_addr(sms);
915915
const uint8_t sprite_size = vdp_get_sprite_height(sms);
916-
const int sprite_eof = 208;
916+
// https://konamiman.github.io/MSX2-Technical-Handbook/md/Chapter4a.html#sprite-attribute-table
917+
const int sprite_eof = 208; // 216 in mode 2
917918

918919
for (uint8_t i = 0; i < 128; i += 4)
919920
{

src/mgb/mgb.c

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ struct mgb
6868
// uint8_t sram_data[SMS_SAVE_SIZE_MAX];
6969
// size_t sram_size;
7070
// bool has_sram;
71+
72+
int region;
73+
int console;
74+
int system;
7175
};
7276

7377

@@ -315,7 +319,12 @@ static bool loadrom(const struct LoadRomConfig* config)
315319
system_hint = SMS_System_SG1000;
316320
}
317321

318-
if (!SMS_loadromEx(mgb.sms, mgb.rom_data, mgb.rom_size, system_hint, -1, -1))
322+
if (mgb.system != -1)
323+
{
324+
system_hint = mgb.system;
325+
}
326+
327+
if (!SMS_loadromEx(mgb.sms, mgb.rom_data, mgb.rom_size, system_hint, mgb.region, mgb.console))
319328
{
320329
mgb_log_err("[MGB] fail to gb load rom\n");
321330
goto fail;
@@ -798,7 +807,7 @@ static bool patch_rom(const struct LoadRomConfig* config)
798807
// cart ram. so we dump the ram and then re-load it.
799808
mgb_save_save_file(NULL);
800809

801-
if (!SMS_loadromEx(mgb.sms, data, new_size, -1, -1, -1))
810+
if (!SMS_loadromEx(mgb.sms, data, new_size, mgb.system, mgb.region, mgb.console))
802811
{
803812
goto fail;
804813
}
@@ -878,7 +887,12 @@ bool mgb_patch_rom_data(const char* path, const uint8_t* data, size_t size)
878887
bool mgb_init(struct SMS_Core* sms)
879888
{
880889
memset(&mgb, 0, sizeof(struct mgb));
890+
881891
mgb.sms = sms;
892+
mgb_set_region(-1);
893+
mgb_set_console(-1);
894+
mgb_set_system(-1);
895+
882896
return true;
883897
}
884898

@@ -1073,12 +1087,29 @@ struct StateInfo* mgb_load_state_info_file(const char* path, bool load_png)
10731087

10741088
void mgb_free_state_info(struct StateInfo* info)
10751089
{
1076-
if (info) {
1077-
if (info->png) {
1090+
if (info)
1091+
{
1092+
if (info->png)
1093+
{
10781094
free(info->png);
10791095
}
10801096

10811097
memset(info, 0, sizeof(*info));
10821098
free(info);
10831099
}
10841100
}
1101+
1102+
void mgb_set_region(int value)
1103+
{
1104+
mgb.region = value;
1105+
}
1106+
1107+
void mgb_set_console(int value)
1108+
{
1109+
mgb.console = value;
1110+
}
1111+
1112+
void mgb_set_system(int value)
1113+
{
1114+
mgb.system = value;
1115+
}

src/mgb/mgb.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ const char* mgb_rom_path(void);
110110
struct StateInfo* mgb_load_state_info_file(const char* path, bool load_png);
111111
void mgb_free_state_info(struct StateInfo* info);
112112

113+
// set to -1 (default) to auto detect.
114+
void mgb_set_region(int value);
115+
void mgb_set_console(int value);
116+
void mgb_set_system(int value);
117+
113118
#ifdef __cplusplus
114119
}
115120
#endif

src/mgb/util.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ enum ExtensionType util_get_extension_type(
230230
{ ".sms", ExtensionType_SMS },
231231
{ ".gg", ExtensionType_GG },
232232
{ ".sg", ExtensionType_SG },
233+
{ ".bin", ExtensionType_BIN },
233234

234235
// [zip]
235236
{ ".zip", ExtensionType_ZIP },

src/mgb/util.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ enum ExtensionType {
3636
ExtensionType_SMS = 1 << 12,
3737
ExtensionType_GG = 1 << 13,
3838
ExtensionType_SG = 1 << 14,
39-
ExtensionType_ROM = ExtensionType_SMS | ExtensionType_GG | ExtensionType_SG,
39+
ExtensionType_BIN = 1 << 15,
40+
ExtensionType_ROM = ExtensionType_SMS | ExtensionType_GG | ExtensionType_SG | ExtensionType_BIN,
4041

4142
ExtensionType_REGULAR = ExtensionType_UNK | ExtensionType_ROM |
4243
ExtensionType_SAVE | ExtensionType_RTC | ExtensionType_STATE |

0 commit comments

Comments
 (0)