Mercurial > vba-linux
view src/win32/RomInfo.cpp @ 1:f9f4f1b99eed
importing src directory
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 03 Mar 2012 10:31:27 -0600 |
parents | |
children |
line wrap: on
line source
1 // RomInfo.cpp : implementation file2 //4 #include "stdafx.h"5 #include "resource.h"6 #include "RomInfo.h"7 #include "WinResUtil.h"9 extern int32 gbRomSize;11 struct WinGBACompanyName12 {13 LPCTSTR code;14 LPCTSTR name;15 };17 static WinGBACompanyName winGBARomInfoCompanies[] = {18 { "01", "Nintendo" },19 { "02", "Rocket Games" },20 { "08", "Capcom" },21 { "09", "Hot B Co." },22 { "0A", "Jaleco" },23 { "0B", "Coconuts Japan" },24 { "0C", "Coconuts Japan/G.X.Media" },25 { "0H", "Starfish" },26 { "0L", "Warashi Inc." },27 { "0N", "Nowpro" },28 { "0P", "Game Village" },29 { "13", "Electronic Arts Japan" },30 { "18", "Hudson Soft Japan" },31 { "19", "S.C.P." },32 { "1A", "Yonoman" },33 { "1G", "SMDE" },34 { "1P", "Creatures Inc." },35 { "1Q", "TDK Deep Impresion" },36 { "20", "Destination Software" },37 { "22", "VR 1 Japan" },38 { "25", "San-X" },39 { "28", "Kemco Japan" },40 { "29", "Seta" },41 { "2H", "Ubisoft Japan" },42 { "2K", "NEC InterChannel" },43 { "2L", "Tam" },44 { "2M", "Jordan" },45 { "2N", "Smilesoft" },46 { "2Q", "Mediakite" },47 { "36", "Codemasters" },48 { "37", "GAGA Communications" },49 { "38", "Laguna" },50 { "39", "Telstar Fun and Games" },51 { "41", "Ubi Soft Entertainment" },52 { "42", "Sunsoft" },53 { "47", "Spectrum Holobyte" },54 { "49", "IREM" },55 { "4D", "Malibu Games" },56 { "4F", "Eidos/U.S. Gold" },57 { "4J", "Fox Interactive" },58 { "4K", "Time Warner Interactive" },59 { "4Q", "Disney" },60 { "4S", "Black Pearl" },61 { "4X", "GT Interactive" },62 { "4Y", "RARE" },63 { "4Z", "Crave Entertainment" },64 { "50", "Absolute Entertainment" },65 { "51", "Acclaim" },66 { "52", "Activision" },67 { "53", "American Sammy Corp." },68 { "54", "Take 2 Interactive" },69 { "55", "Hi Tech" },70 { "56", "LJN LTD." },71 { "58", "Mattel" },72 { "5A", "Mindscape/Red Orb Ent." },73 { "5C", "Taxan" },74 { "5D", "Midway" },75 { "5F", "American Softworks" },76 { "5G", "Majesco Sales Inc" },77 { "5H", "3DO" },78 { "5K", "Hasbro" },79 { "5L", "NewKidCo" },80 { "5M", "Telegames" },81 { "5N", "Metro3D" },82 { "5P", "Vatical Entertainment" },83 { "5Q", "LEGO Media" },84 { "5S", "Xicat Interactive" },85 { "5T", "Cryo Interactive" },86 { "5W", "Red Storm Ent./BKN Ent." },87 { "5X", "Microids" },88 { "5Z", "Conspiracy Entertainment Corp." },89 { "60", "Titus Interactive Studios" },90 { "61", "Virgin Interactive" },91 { "62", "Maxis" },92 { "64", "LucasArts Entertainment" },93 { "67", "Ocean" },94 { "69", "Electronic Arts" },95 { "6E", "Elite Systems Ltd." },96 { "6F", "Electro Brain" },97 { "6G", "The Learning Company" },98 { "6H", "BBC" },99 { "6J", "Software 2000" },100 { "6L", "BAM! Entertainment" },101 { "6M", "Studio 3" },102 { "6Q", "Classified Games" },103 { "6S", "TDK Mediactive" },104 { "6U", "DreamCatcher" },105 { "6V", "JoWood Productions" },106 { "6W", "SEGA" },107 { "6X", "Wannado Edition" },108 { "6Y", "LSP" },109 { "6Z", "ITE Media" },110 { "70", "Infogrames" },111 { "71", "Interplay" },112 { "72", "JVC Musical Industries Inc" },113 { "73", "Parker Brothers" },114 { "75", "SCI" },115 { "78", "THQ" },116 { "79", "Accolade" },117 { "7A", "Triffix Ent. Inc." },118 { "7C", "Microprose Software" },119 { "7D", "Universal Interactive Studios" },120 { "7F", "Kemco" },121 { "7G", "Rage Software" },122 { "7H", "Encore" },123 { "7J", "Zoo" },124 { "7K", "BVM" },125 { "7L", "Simon & Schuster Interactive" },126 { "7M", "Asmik Ace Entertainment Inc./AIA" },127 { "7N", "Empire Interactive" },128 { "7Q", "Jester Interactive" },129 { "7T", "Scholastic" },130 { "7U", "Ignition Entertainment" },131 { "7W", "Stadlbauer" },132 { "80", "Misawa" },133 { "83", "LOZC" },134 { "8B", "Bulletproof Software" },135 { "8C", "Vic Tokai Inc." },136 { "8J", "General Entertainment" },137 { "8N", "Success" },138 { "8P", "SEGA Japan" },139 { "91", "Chun Soft" },140 { "92", "Video System" },141 { "93", "BEC" },142 { "96", "Yonezawa/S'pal" },143 { "97", "Kaneko" },144 { "99", "Victor Interactive Software" },145 { "9A", "Nichibutsu/Nihon Bussan" },146 { "9B", "Tecmo" },147 { "9C", "Imagineer" },148 { "9F", "Nova" },149 { "9H", "Bottom Up" },150 { "9L", "Hasbro Japan" },151 { "9N", "Marvelous Entertainment" },152 { "9P", "Keynet Inc." },153 { "9Q", "Hands-On Entertainment" },154 { "A0", "Telenet" },155 { "A1", "Hori" },156 { "A4", "Konami" },157 { "A6", "Kawada" },158 { "A7", "Takara" },159 { "A9", "Technos Japan Corp." },160 { "AA", "JVC" },161 { "AC", "Toei Animation" },162 { "AD", "Toho" },163 { "AF", "Namco" },164 { "AG", "Media Rings Corporation" },165 { "AH", "J-Wing" },166 { "AK", "KID" },167 { "AL", "MediaFactory" },168 { "AP", "Infogrames Hudson" },169 { "AQ", "Kiratto. Ludic Inc" },170 { "B0", "Acclaim Japan" },171 { "B1", "ASCII" },172 { "B2", "Bandai" },173 { "B4", "Enix" },174 { "B6", "HAL Laboratory" },175 { "B7", "SNK" },176 { "B9", "Pony Canyon Hanbai" },177 { "BA", "Culture Brain" },178 { "BB", "Sunsoft" },179 { "BD", "Sony Imagesoft" },180 { "BF", "Sammy" },181 { "BG", "Magical" },182 { "BJ", "Compile" },183 { "BL", "MTO Inc." },184 { "BN", "Sunrise Interactive" },185 { "BP", "Global A Entertainment" },186 { "BQ", "Fuuki" },187 { "C0", "Taito" },188 { "C2", "Kemco" },189 { "C3", "Square Soft" },190 { "C5", "Data East" },191 { "C6", "Tonkin House" },192 { "C8", "Koei" },193 { "CA", "Konami/Palcom/Ultra" },194 { "CB", "Vapinc/NTVIC" },195 { "CC", "Use Co.,Ltd." },196 { "CD", "Meldac" },197 { "CE", "FCI/Pony Canyon" },198 { "CF", "Angel" },199 { "CM", "Konami Computer Entertainment Osaka" },200 { "CP", "Enterbrain" },201 { "D1", "Sofel" },202 { "D2", "Quest" },203 { "D3", "Sigma Enterprises" },204 { "D4", "Ask Kodansa" },205 { "D6", "Naxat" },206 { "D7", "Copya System" },207 { "D9", "Banpresto" },208 { "DA", "TOMY" },209 { "DB", "LJN Japan" },210 { "DD", "NCS" },211 { "DF", "Altron Corporation" },212 { "DH", "Gaps Inc." },213 { "DN", "ELF" },214 { "E2", "Yutaka" },215 { "E3", "Varie" },216 { "E5", "Epoch" },217 { "E7", "Athena" },218 { "E8", "Asmik Ace Entertainment Inc." },219 { "E9", "Natsume" },220 { "EA", "King Records" },221 { "EB", "Atlus" },222 { "EC", "Epic/Sony Records" },223 { "EE", "IGS" },224 { "EL", "Spike" },225 { "EM", "Konami Computer Entertainment Tokyo" },226 { "EN", "Alphadream Corporation" },227 { "F0", "A Wave" },228 { "G1", "PCCW" },229 { "G4", "KiKi Co Ltd" },230 { "G5", "Open Sesame Inc." },231 { "G6", "Sims" },232 { "G7", "Broccoli" },233 { "G8", "Avex" },234 { "G9", "D3 Publisher" },235 { "GB", "Konami Computer Entertainment Japan" },236 { "GD", "Square-Enix" },237 { "HY", "Sachen" },238 { NULL, NULL }239 };241 static LPCTSTR winGBARomInfoFindMakerCode(LPCTSTR code)242 {243 int i = 0;244 while (winGBARomInfoCompanies[i].code)245 {246 if (!strcmp(winGBARomInfoCompanies[i].code, code))247 return winGBARomInfoCompanies[i].name;248 i++;249 }250 return (LPCTSTR)winResLoadString(IDS_UNKNOWN);251 }253 /////////////////////////////////////////////////////////////////////////////254 // RomInfoGB dialog256 RomInfoGB::RomInfoGB(u8 *rom, CWnd *pParent /*=NULL*/)257 : CDialog(RomInfoGB::IDD, pParent)258 {259 //{{AFX_DATA_INIT(RomInfoGB)260 // NOTE: the ClassWizard will add member initialization here261 //}}AFX_DATA_INIT262 this->rom = rom;263 }265 void RomInfoGB::DoDataExchange(CDataExchange *pDX)266 {267 CDialog::DoDataExchange(pDX);268 //{{AFX_DATA_MAP(RomInfoGB)269 // NOTE: the ClassWizard will add DDX and DDV calls here270 //}}AFX_DATA_MAP271 }273 BEGIN_MESSAGE_MAP(RomInfoGB, CDialog)274 //{{AFX_MSG_MAP(RomInfoGB)275 ON_BN_CLICKED(ID_OK, OnOk)276 //}}AFX_MSG_MAP277 END_MESSAGE_MAP()279 /////////////////////////////////////////////////////////////////////////////280 // RomInfoGB message handlers282 void RomInfoGB::OnOk()283 {284 EndDialog(TRUE);285 }287 BOOL RomInfoGB::OnInitDialog()288 {289 CDialog::OnInitDialog();291 char buffer[128];293 strncpy(buffer, (const char *)&rom[0x134], 15);294 buffer[15] = 0;295 GetDlgItem(IDC_ROM_TITLE)->SetWindowText(buffer);297 sprintf(buffer, "%02x", rom[0x143]);298 GetDlgItem(IDC_ROM_COLOR)->SetWindowText(buffer);300 strncpy(buffer, (const char *)&rom[0x144], 2);301 buffer[2] = 0;302 GetDlgItem(IDC_ROM_MAKER_CODE)->SetWindowText(buffer);304 if (rom[0x14b] != 0x33)305 {306 sprintf(buffer, "%02X", rom[0x14b]);307 GetDlgItem(IDC_ROM_MAKER_CODE)->SetWindowText(buffer);308 }309 GetDlgItem(IDC_ROM_MAKER_NAME2)->SetWindowText(winGBARomInfoFindMakerCode(buffer));311 sprintf(buffer, "%02x", rom[0x146]);312 GetDlgItem(IDC_ROM_UNIT_CODE)->SetWindowText(buffer);314 CString type = winResLoadString(IDS_UNKNOWN);315 switch (rom[0x147])316 {317 case 0x00:318 type = "ROM";319 break;320 case 0x01:321 type = "ROM+MBC1";322 break;323 case 0x02:324 type = "ROM+MBC1+RAM";325 break;326 case 0x03:327 type = "ROM+MBC1+RAM+BATT";328 break;329 case 0x05:330 type = "ROM+MBC2";331 break;332 case 0x06:333 type = "ROM+MBC2+BATT";334 break;335 case 0x0f:336 type = "ROM+MBC3+TIMER+BATT";337 break;338 case 0x10:339 type = "ROM+MBC3+TIMER+RAM+BATT";340 break;341 case 0x11:342 type = "ROM+MBC3";343 break;344 case 0x12:345 type = "ROM+MBC3+RAM";346 break;347 case 0x13:348 type = "ROM+MBC3+RAM+BATT";349 break;350 case 0x19:351 type = "ROM+MBC5";352 break;353 case 0x1a:354 type = "ROM+MBC5+RAM";355 break;356 case 0x1b:357 type = "ROM+MBC5+RAM+BATT";358 break;359 case 0x1c:360 type = "ROM+MBC5+RUMBLE";361 break;362 case 0x1d:363 type = "ROM+MBC5+RUMBLE+RAM";364 break;365 case 0x1e:366 type = "ROM+MBC5+RUMBLE+RAM+BATT";367 break;368 case 0x22:369 type = "ROM+MBC7+BATT";370 break;371 case 0xfe:372 type = "ROM+HuC-3";373 break;374 case 0xff:375 type = "ROM+HuC-1";376 break;377 }378 sprintf(buffer, "%02x (%s)", rom[0x147], (const char *)type);379 GetDlgItem(IDC_ROM_DEVICE_TYPE)->SetWindowText(buffer);381 type = winResLoadString(IDS_UNKNOWN);382 switch (rom[0x148])383 {384 case 0:385 type = "32K";386 break;387 case 1:388 type = "64K";389 break;390 case 2:391 type = "128K";392 break;393 case 3:394 type = "256K";395 break;396 case 4:397 type = "512K";398 break;399 case 5:400 type = "1M";401 break;402 case 6:403 type = "2M";404 break;405 case 7:406 type = "4M";407 break;408 }410 sprintf(buffer, "%02x (%s)", rom[0x148], (const char *)type);411 GetDlgItem(IDC_ROM_SIZE)->SetWindowText(buffer);413 type = winResLoadString(IDS_UNKNOWN);414 switch (rom[0x149])415 {416 case 0:417 type = winResLoadString(IDS_NONE);418 break;419 case 1:420 type = "2K";421 break;422 case 2:423 type = "8K";424 break;425 case 3:426 type = "32K";427 break;428 case 4:429 type = "128K";430 break;431 case 5:432 type = "64K";433 break;434 }436 sprintf(buffer, "%02x (%s)", rom[0x149], (const char *)type);437 GetDlgItem(IDC_ROM_RAM_SIZE)->SetWindowText(buffer);439 sprintf(buffer, "%02x", rom[0x14a]);440 GetDlgItem(IDC_ROM_DEST_CODE)->SetWindowText(buffer);442 sprintf(buffer, "%02x", rom[0x14b]);443 GetDlgItem(IDC_ROM_LIC_CODE)->SetWindowText(buffer);445 sprintf(buffer, "%02x", rom[0x14c]);446 GetDlgItem(IDC_ROM_VERSION)->SetWindowText(buffer);448 u8 crc8 = 25;449 int i;450 for (i = 0x134; i < 0x14d; i++)451 {452 crc8 = (crc8 + rom[i]) & 0xFF;453 }455 crc8 = 256 - crc8;457 sprintf(buffer, "%02x (%02x)", crc8, rom[0x14d]);458 GetDlgItem(IDC_ROM_CRC)->SetWindowText(buffer);460 u16 crc16 = 0;461 for (i = 0; i < gbRomSize; i++)462 {463 crc16 = (crc16 + rom[i]) & 0xFFFF;464 }466 crc16 -= rom[0x14e];467 crc16 -= rom[0x14f];468 sprintf(buffer, "%04x (%04x)", crc16, (rom[0x14e] << 8) | rom[0x14f]);469 GetDlgItem(IDC_ROM_CHECKSUM)->SetWindowText(buffer);471 CenterWindow();473 return TRUE; // return TRUE unless you set the focus to a control474 // EXCEPTION: OCX Property Pages should return FALSE475 }477 /////////////////////////////////////////////////////////////////////////////478 // RomInfoGBA dialog480 RomInfoGBA::RomInfoGBA(u8 *rom, CWnd *pParent /*=NULL*/)481 : CDialog(RomInfoGBA::IDD, pParent)482 {483 //{{AFX_DATA_INIT(RomInfoGBA)484 // NOTE: the ClassWizard will add member initialization here485 //}}AFX_DATA_INIT486 this->rom = rom;487 }489 void RomInfoGBA::DoDataExchange(CDataExchange *pDX)490 {491 CDialog::DoDataExchange(pDX);492 //{{AFX_DATA_MAP(RomInfoGBA)493 // NOTE: the ClassWizard will add DDX and DDV calls here494 //}}AFX_DATA_MAP495 }497 BEGIN_MESSAGE_MAP(RomInfoGBA, CDialog)498 //{{AFX_MSG_MAP(RomInfoGBA)499 ON_BN_CLICKED(ID_OK, OnOk)500 //}}AFX_MSG_MAP501 END_MESSAGE_MAP()503 /////////////////////////////////////////////////////////////////////////////504 // RomInfoGBA message handlers506 void RomInfoGBA::OnOk()507 {508 EndDialog(TRUE);509 }511 BOOL RomInfoGBA::OnInitDialog()512 {513 CDialog::OnInitDialog();515 char buffer[13];517 strncpy(buffer, (const char *)&rom[0xa0], 12);518 buffer[12] = 0;519 GetDlgItem(IDC_ROM_TITLE)->SetWindowText(buffer);521 strncpy(buffer, (const char *)&rom[0xac], 4);522 buffer[4] = 0;523 GetDlgItem(IDC_ROM_GAME_CODE)->SetWindowText(buffer);525 strncpy(buffer, (const char *)&rom[0xb0], 2);526 buffer[2] = 0;527 GetDlgItem(IDC_ROM_MAKER_CODE)->SetWindowText(buffer);529 GetDlgItem(IDC_ROM_MAKER_NAME)->SetWindowText(winGBARomInfoFindMakerCode(buffer));531 sprintf(buffer, "%02x", rom[0xb3]);532 GetDlgItem(IDC_ROM_UNIT_CODE)->SetWindowText(buffer);534 sprintf(buffer, "%02x", rom[0xb4]);535 GetDlgItem(IDC_ROM_DEVICE_TYPE)->SetWindowText(buffer);537 sprintf(buffer, "%02x", rom[0xbc]);538 GetDlgItem(IDC_ROM_VERSION)->SetWindowText(buffer);540 u8 crc = 0x19;541 for (int i = 0xa0; i < 0xbd; i++)542 {543 crc = (crc + rom[i]) & 0xff;544 }546 crc = (-crc) & 0xff;548 sprintf(buffer, "%02x (%02x)", crc, rom[0xbd]);549 GetDlgItem(IDC_ROM_CRC)->SetWindowText(buffer);550 CenterWindow();552 return TRUE; // return TRUE unless you set the focus to a control553 // EXCEPTION: OCX Property Pages should return FALSE554 }