@@ -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)
878887bool 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
10741088void 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+ }
0 commit comments