MCPcopy Create free account
hub / github.com/TASEmulators/fceux / WriteHeaderData

Function WriteHeaderData

src/drivers/win/header_editor.cpp:939–1681  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

937}
938
939bool WriteHeaderData(HWND hwnd, iNES_HEADER* header)
940{
941 // Temporary buffers
942 char buf[256];
943
944 iNES_HEADER _header;
945 memset(&_header, 0, sizeof(iNES_HEADER));
946
947 // Check iNES 2.0
948 bool ines20 = IsDlgButtonChecked(hwnd, IDC_RADIO_VERSION_INES20) == BST_CHECKED;
949 // iNES 1.0 unofficial byte available
950 bool unofficial = !ines20 && IsDlgButtonChecked(hwnd, IDC_CHECK_UNOFFICIAL) == BST_CHECKED;
951
952 // iNES 2.0 signature
953 if (ines20)
954 _header.ROM_type2 |= 8;
955
956 // Mapper
957 int mapper;
958 if (!GetComboBoxListItemData(hwnd, IDC_MAPPER_COMBO, &mapper, buf, header))
959 {
960 if (header) {
961 MessageBox(hwnd, "The mapper# you have entered is invalid. Please enter a decimal number or select an item from the dropdown list.", "Error", MB_OK | MB_ICONERROR);
962 SetFocus(GetDlgItem(hwnd, IDC_MAPPER_COMBO));
963 SendDlgItemMessage(hwnd, IDC_MAPPER_COMBO, EM_SETSEL, 0, -1);
964 }
965 else
966 SetDlgItemText(hwnd, IDC_HEX_HEADER_EDIT, "");
967 return false;
968 }
969
970 if (mapper < 4096)
971 {
972 _header.ROM_type |= (mapper & 0xF) << 4;
973 _header.ROM_type2 |= (mapper & 0xF0);
974 if (mapper >= 256)
975 {
976 if (ines20)
977 _header.ROM_type3 |= mapper >> 8;
978 else
979 {
980 if (header) {
981 sprintf(buf, "Mapper# should be less than %d in iNES %d.0 format.", 256, 1);
982 MessageBox(hwnd, buf, "Error", MB_OK | MB_ICONERROR);
983 SetFocus(GetDlgItem(hwnd, IDC_MAPPER_COMBO));
984 SendDlgItemMessage(hwnd, IDC_MAPPER_COMBO, EM_SETSEL, 0, -1);
985 }
986 else
987 SetDlgItemText(hwnd, IDC_HEX_HEADER_EDIT, "");
988
989 return false;
990 }
991 }
992 }
993 else {
994 if (header) {
995 sprintf(buf, "Mapper# should be less than %d in iNES %d.0 format.", 4096, 2);
996 MessageBox(hwnd, buf, "Error", MB_OK | MB_ICONERROR);

Callers 2

HeaderEditorProcFunction · 0.85
saveFileAsMethod · 0.85

Calls 3

GetComboBoxListItemDataFunction · 0.85
GetDlgItemTextFunction · 0.85
GetComboBoxByteSizeFunction · 0.85

Tested by

no test coverage detected