-
Notifications
You must be signed in to change notification settings - Fork 9
/
ident.c
1007 lines (851 loc) · 38.3 KB
/
ident.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <kernel.h>
#include <errno.h>
#include <sifrpc.h>
#include <loadfile.h>
#include <libcdvd.h>
#include <libpad.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <sbv_patches.h>
#include <osd_config.h>
#include <timer.h>
#include <limits.h>
#include <libgs.h>
#include <speedregs.h>
#include <smapregs.h>
#include <dev9regs.h>
#include "sysman/sysinfo.h"
#include "SYSMAN_rpc.h"
#include "main.h"
#include "ident.h"
#include "pad.h"
#include "graphics.h"
#include "libcdvd_add.h"
#include "dvdplayer.h"
#include "OSDInit.h"
#include "ps1.h"
#include "modelname.h"
#include "UI.h"
#include "menu.h"
#include "crc16.h"
#include "dbms.h"
extern struct UIDrawGlobal UIDrawGlobal;
#define GS_REG_CSR (volatile u64 *)0x12001000 // System Status
int GetEEInformation(struct SystemInformation *SystemInformation)
{
unsigned short int revision;
unsigned int value;
revision = GetCop0(15);
SystemInformation->mainboard.ee.implementation = revision >> 8;
SystemInformation->mainboard.ee.revision = revision & 0xFF;
asm("cfc1 %0, $0\n"
: "=r"(revision)
:);
SystemInformation->mainboard.ee.FPUImplementation = revision >> 8;
SystemInformation->mainboard.ee.FPURevision = revision & 0xFF;
value = GetCop0(16);
SystemInformation->mainboard.ee.ICacheSize = value >> 9 & 3;
SystemInformation->mainboard.ee.DCacheSize = value >> 6 & 3;
SystemInformation->mainboard.ee.RAMSize = GetMemorySize();
SystemInformation->mainboard.MachineType = MachineType();
revision = (*GS_REG_CSR) >> 16;
SystemInformation->mainboard.gs.revision = revision & 0xFF;
SystemInformation->mainboard.gs.id = revision >> 8;
ee_kmode_enter();
SystemInformation->EE_F520 = *(volatile unsigned int *)0xB000F520;
SystemInformation->EE_F540 = *(volatile unsigned int *)0xB000F540;
SystemInformation->EE_F550 = *(volatile unsigned int *)0xB000F550;
ee_kmode_exit();
return 0;
}
static u16 CalculateCRCOfROM(void *buffer1, void *buffer2, void *start, unsigned int length)
{
u16 crc;
unsigned int i, size, prevSize;
void *pDestBuffer, *pSrcBuffer;
for (i = 0, prevSize = size, crc = CRC16_INITIAL_CHECKSUM, pDestBuffer = buffer1, pSrcBuffer = start; i < length; i += size, pSrcBuffer += size)
{
size = length - i > MEM_IO_BLOCK_SIZE ? MEM_IO_BLOCK_SIZE : length - i;
SysmanSync(0);
while (SysmanReadMemory(pSrcBuffer, pDestBuffer, size, 1) != 0)
nopdelay();
pDestBuffer = (pDestBuffer == buffer1) ? buffer2 : buffer1;
if (i > 0)
crc = CalculateCRC16(UNCACHED_SEG(pDestBuffer), prevSize, crc);
prevSize = size;
}
pDestBuffer = (pDestBuffer == buffer1) ? buffer2 : buffer1;
SysmanSync(0);
return ReflectAndXORCRC16(CalculateCRC16(UNCACHED_SEG(pDestBuffer), prevSize, crc));
}
int CheckROM(const struct PS2IDBMainboardEntry *entry)
{
const struct PS2IDBMainboardEntry *other;
if ((other = PS2IDBMS_LookupMatchingROM(entry)) != NULL)
{
if ((entry->BOOT_ROM.IsExists && (other->BOOT_ROM.crc16 != entry->BOOT_ROM.crc16)) || (other->DVD_ROM.IsExists && (other->DVD_ROM.crc16 != entry->DVD_ROM.crc16)))
{
printf("CheckROM: ROM mismatch:\n");
if (entry->BOOT_ROM.IsExists)
printf(" BOOT: 0x%04x 0x%04x\n", other->BOOT_ROM.crc16, entry->BOOT_ROM.crc16);
if (other->DVD_ROM.IsExists)
printf(" DVD: 0x%04x 0x%04x\n", other->DVD_ROM.crc16, entry->DVD_ROM.crc16);
return 1;
}
}
return 0;
}
int GetPeripheralInformation(struct SystemInformation *SystemInformation)
{
t_SysmanHardwareInfo hwinfo;
int result, fd, i;
u32 stat;
void *buffer1, *buffer2;
char *pNewline;
SysmanGetHardwareInfo(&hwinfo);
memcpy(&SystemInformation->mainboard.iop, &hwinfo.iop, sizeof(SystemInformation->mainboard.iop));
memcpy(SystemInformation->ROMs, hwinfo.ROMs, sizeof(SystemInformation->ROMs));
memcpy(&SystemInformation->erom, &hwinfo.erom, sizeof(SystemInformation->erom));
memcpy(&SystemInformation->mainboard.BOOT_ROM, &hwinfo.BOOT_ROM, sizeof(SystemInformation->mainboard.BOOT_ROM));
memcpy(&SystemInformation->mainboard.DVD_ROM, &hwinfo.DVD_ROM, sizeof(SystemInformation->mainboard.DVD_ROM));
memcpy(&SystemInformation->mainboard.ssbus, &hwinfo.ssbus, sizeof(SystemInformation->mainboard.ssbus));
memcpy(&SystemInformation->mainboard.iLink, &hwinfo.iLink, sizeof(SystemInformation->mainboard.iLink));
memcpy(&SystemInformation->mainboard.usb, &hwinfo.usb, sizeof(SystemInformation->mainboard.usb));
memcpy(&SystemInformation->mainboard.spu2, &hwinfo.spu2, sizeof(SystemInformation->mainboard.spu2));
SystemInformation->mainboard.BoardInf = hwinfo.BoardInf;
SystemInformation->mainboard.MPUBoardID = hwinfo.MPUBoardID;
SystemInformation->mainboard.ROMGEN_MonthDate = hwinfo.ROMGEN_MonthDate;
SystemInformation->mainboard.ROMGEN_Year = hwinfo.ROMGEN_Year;
SystemInformation->mainboard.status = 0;
buffer1 = memalign(64, MEM_IO_BLOCK_SIZE);
buffer2 = memalign(64, MEM_IO_BLOCK_SIZE);
if (SystemInformation->mainboard.BOOT_ROM.IsExists)
{
SystemInformation->mainboard.BOOT_ROM.crc16 = CalculateCRCOfROM(buffer1, buffer2, (void *)SystemInformation->mainboard.BOOT_ROM.StartAddress, SystemInformation->mainboard.BOOT_ROM.size);
DEBUG_PRINTF("BOOT ROM CRC16: 0x%04x\n", SystemInformation->mainboard.BOOT_ROM.crc16);
}
if (SystemInformation->mainboard.DVD_ROM.IsExists)
{
SystemInformation->mainboard.DVD_ROM.crc16 = CalculateCRCOfROM(buffer1, buffer2, (void *)SystemInformation->mainboard.DVD_ROM.StartAddress, SystemInformation->mainboard.DVD_ROM.size);
DEBUG_PRINTF("DVD ROM CRC16: 0x%04x\n", SystemInformation->mainboard.DVD_ROM.crc16);
}
free(buffer1);
free(buffer2);
//Initialize model name
if (ModelNameInit() == 0)
{
//Get model name
strncpy(SystemInformation->mainboard.ModelName, ModelNameGet(), sizeof(SystemInformation->mainboard.ModelName) - 1);
SystemInformation->mainboard.ModelName[sizeof(SystemInformation->mainboard.ModelName) - 1] = '\0';
}
else
{
SystemInformation->mainboard.status |= PS2IDB_STAT_ERR_MNAME;
SystemInformation->mainboard.ModelName[0] = '\0';
}
//Get DVD Player version
strncpy(SystemInformation->DVDPlayerVer, DVDPlayerGetVersion(), sizeof(SystemInformation->DVDPlayerVer) - 1);
SystemInformation->DVDPlayerVer[sizeof(SystemInformation->DVDPlayerVer) - 1] = '\0';
if ((pNewline = strrchr(SystemInformation->DVDPlayerVer, '\n')) != NULL)
*pNewline = '\0'; //The DVD player version may have a newline in it.
//Get OSD Player version
strncpy(SystemInformation->OSDVer, OSDGetVersion(), sizeof(SystemInformation->OSDVer) - 1);
SystemInformation->OSDVer[sizeof(SystemInformation->OSDVer) - 1] = '\0';
if ((pNewline = strrchr(SystemInformation->OSDVer, '\n')) != NULL)
*pNewline = '\0'; //The OSDVer may have a newline in it.
//Get PS1DRV version
strncpy(SystemInformation->PS1DRVVer, PS1DRVGetVersion(), sizeof(SystemInformation->PS1DRVVer) - 1);
SystemInformation->PS1DRVVer[sizeof(SystemInformation->PS1DRVVer) - 1] = '\0';
memset(SystemInformation->ConsoleID, 0, sizeof(SystemInformation->ConsoleID));
memset(SystemInformation->iLinkID, 0, sizeof(SystemInformation->iLinkID));
memset(SystemInformation->SMAP_MAC_address, 0, sizeof(SystemInformation->SMAP_MAC_address));
memset(SystemInformation->mainboard.MECHACONVersion, 0, sizeof(SystemInformation->mainboard.MECHACONVersion));
memset(SystemInformation->DSPVersion, 0, sizeof(SystemInformation->DSPVersion));
memset(SystemInformation->mainboard.MRenewalDate, 0, sizeof(SystemInformation->mainboard.MRenewalDate));
if (sceGetDspVersion(SystemInformation->DSPVersion, &stat) == 0 || (stat & 0x80) != 0)
{
printf("Failed to read DSP version. Stat: %x\n", stat);
SystemInformation->mainboard.status |= PS2IDB_STAT_ERR_MVER;
}
if (sceCdAltMV(SystemInformation->mainboard.MECHACONVersion, &stat) == 0 || (stat & 0x80) != 0)
{
// ignore stat. DTL-H3010x set errored stat & 0x80, which is not true.
if ((stat & 0x80) != 0)
{
SystemInformation->mainboard.MECHACONVersion[0] = SystemInformation->mainboard.MECHACONVersion[0] - 0x80;
}
}
if (sceCdReadConsoleID(SystemInformation->ConsoleID, &result) == 0 || (result & 0x80))
{
printf("Failed to read console ID. Stat: %x\n", result);
SystemInformation->mainboard.status |= PS2IDB_STAT_ERR_CONSOLEID;
}
if (sceCdRI(SystemInformation->iLinkID, &result) == 0 || (result & 0x80))
{
printf("Failed to read i.Link ID. Stat: %x\n", result);
SystemInformation->mainboard.status |= PS2IDB_STAT_ERR_ILINKID;
}
if (SystemInformation->mainboard.MECHACONVersion[1] >= 5)
{ //v5.x MECHACON (SCPH-50000 and later) supports Mechacon Renewal Date.
if (sceCdAltReadRenewalDate(SystemInformation->mainboard.MRenewalDate, &result) == 0 || (result & 0x80))
{
printf("Failed to read M Renewal Date. Stat: %x\n", result);
SystemInformation->mainboard.status |= PS2IDB_STAT_ERR_MRENEWDATE;
}
/*mechacon 5.8 and 5.9 are the same chip patched with dex flag, so 5.8 and 5.9 -> 5.8 */
SystemInformation->mainboard.MECHACONVersion[2] = SystemInformation->mainboard.MECHACONVersion[2] & 0xFE;
}
SysmanGetMACAddress(SystemInformation->SMAP_MAC_address);
SystemInformation->mainboard.ADD010 = 0xFFFF;
if (GetADD010(SystemInformation->mainboard.MECHACONVersion[1] >= 5 ? 0x001 : 0x010, &SystemInformation->mainboard.ADD010) != 0)
{
printf("Failed to read ADD0x010.\n");
SystemInformation->mainboard.status |= PS2IDB_STAT_ERR_ADD010;
}
//Get the mainboard and chassis names, MODEL ID, console MODEL ID and EMCS ID.
SystemInformation->mainboard.ModelID[0] = SystemInformation->iLinkID[1];
SystemInformation->mainboard.ModelID[1] = SystemInformation->iLinkID[2];
SystemInformation->mainboard.ModelID[2] = SystemInformation->iLinkID[3];
SystemInformation->mainboard.ConModelID[0] = SystemInformation->ConsoleID[0];
SystemInformation->mainboard.ConModelID[1] = SystemInformation->ConsoleID[1];
SystemInformation->mainboard.EMCSID = SystemInformation->ConsoleID[7];
strcpy(SystemInformation->mainboard.MainboardName, GetMainboardModelDesc(&SystemInformation->mainboard));
strcpy(SystemInformation->chassis, GetChassisDesc(&SystemInformation->mainboard));
CheckROM(&SystemInformation->mainboard);
return 0;
}
int DumpRom(const char *filename, const struct SystemInformation *SystemInformation, struct DumpingStatus *DumpingStatus, unsigned int DumpingRegion)
{
FILE *file;
int result = 0;
unsigned int BytesToRead, BytesRemaining, ROMSize, prevSize;
const unsigned char *MemDumpStart;
void *buffer1, *buffer2, *pBuffer;
switch (DumpingRegion)
{
case DUMP_REGION_BOOT_ROM:
ROMSize = SystemInformation->mainboard.BOOT_ROM.size;
MemDumpStart = (const unsigned char *)SystemInformation->mainboard.BOOT_ROM.StartAddress;
break;
case DUMP_REGION_DVD_ROM:
ROMSize = SystemInformation->mainboard.DVD_ROM.size;
MemDumpStart = (const unsigned char *)SystemInformation->mainboard.DVD_ROM.StartAddress;
break;
default:
return -EINVAL;
}
buffer1 = memalign(64, MEM_IO_BLOCK_SIZE);
buffer2 = memalign(64, MEM_IO_BLOCK_SIZE);
BytesRemaining = ROMSize;
if ((file = fopen(filename, "wb")) != NULL)
{
for (pBuffer = buffer1, prevSize = BytesRemaining; BytesRemaining > 0; MemDumpStart += BytesToRead, BytesRemaining -= BytesToRead)
{
BytesToRead = BytesRemaining > MEM_IO_BLOCK_SIZE ? MEM_IO_BLOCK_SIZE : BytesRemaining;
SysmanSync(0);
while (SysmanReadMemory(MemDumpStart, pBuffer, BytesToRead, 1) != 0)
nopdelay();
RedrawDumpingScreen(SystemInformation, DumpingStatus);
pBuffer = pBuffer == buffer1 ? buffer2 : buffer1;
if (BytesRemaining < ROMSize)
{
if (fwrite(UNCACHED_SEG(pBuffer), 1, prevSize, file) != prevSize)
{
result = -EIO;
break;
}
DumpingStatus[DumpingRegion].progress = 1.00f - (float)BytesRemaining / ROMSize;
}
prevSize = BytesToRead;
}
if (result == 0)
{
pBuffer = pBuffer == buffer1 ? buffer2 : buffer1;
SysmanSync(0);
if (fwrite(UNCACHED_SEG(pBuffer), 1, prevSize, file) == prevSize)
DumpingStatus[DumpingRegion].progress = 1.00f - (float)BytesRemaining / ROMSize;
else
result = -EIO;
}
fclose(file);
}
else
result = -ENOENT;
DumpingStatus[DumpingRegion].status = (result == 0) ? 1 : result;
free(buffer1);
free(buffer2);
return result;
}
int GetADD010(u16 address, u16 *word)
{
unsigned char stat;
if (sceCdReadNVM(address, word, &stat) != 1 || stat != 0)
return -1;
return 0;
}
int DumpMECHACON_EEPROM(const char *filename)
{
FILE *file;
int result;
unsigned char stat;
unsigned short int i;
static unsigned short int IOBuffer[512];
result = 0;
if ((file = fopen(filename, "wb")) != NULL)
{
for (i = 0; i < 512; i++)
{
if (sceCdReadNVM(i, &IOBuffer[i], &stat) != 1 || stat != 0)
{
result = -EIO;
break;
}
}
if (fwrite(IOBuffer, 1, sizeof(IOBuffer), file) != sizeof(IOBuffer))
{
result = EIO;
}
fclose(file);
}
else
result = -ENOENT;
return result;
}
int WriteNewMainboardDBRecord(const char *path, const struct PS2IDBMainboardEntry *SystemInformation)
{
FILE *file;
int result;
struct PS2IDB_NewMainboardEntryHeader header;
if ((file = fopen(path, "wb")) != NULL)
{
header.magic[0] = '2';
header.magic[1] = 'N';
header.version = PS2IDB_NEWENT_FORMAT_VERSION;
if (fwrite(&header, sizeof(struct PS2IDB_NewMainboardEntryHeader), 1, file) == 1)
{
result = fwrite(SystemInformation, sizeof(struct PS2IDBMainboardEntry), 1, file) == 1 ? 0 : EIO;
}
else
result = EIO;
fclose(file);
}
else
result = EIO;
return result;
}
const char *GetiLinkSpeedDesc(unsigned char speed)
{
static const char *speeds[] = {
"S100",
"S200",
"S400",
"Unknown"};
if (speed > 3)
speed = 3;
return speeds[speed];
}
const char *GetiLinkComplianceLvlDesc(unsigned char level)
{
static const char *levels[] = {
"IEEE1394-1995",
"IEEE1394A-2000",
"Unknown"};
if (level > 2)
level = 2;
return levels[level];
}
const char *GetiLinkVendorDesc(unsigned int vendor)
{
const char *description;
switch (vendor)
{
case 0x00A0B8:
description = "LSI Logic";
break;
default:
description = "Unknown";
}
return description;
}
const char *GetSSBUSIFDesc(unsigned char revision)
{
const char *description;
if ((description = PS2IDBMS_LookupComponentModel(PS2IDB_COMPONENT_SSBUSIF, revision)) == NULL)
{
description = "Missing";
}
return description;
}
const char *GetSPEEDDesc(unsigned short int revision)
{
const char *description;
if ((description = PS2IDBMS_LookupComponentModel(PS2IDB_COMPONENT_SPEED, revision)) == NULL)
{
description = "Missing";
}
return description;
}
const char *GetSPEEDCapsDesc(unsigned short int caps)
{
static char capsbuffer[64];
unsigned int i;
unsigned char capability, NumCapabilities;
static const char *capabilities[] = {
"SMAP",
"ATA",
"Unknown",
"UART",
"DVR",
"Flash",
"Unknown"};
if (caps != 0)
{
capsbuffer[0] = '\0';
for (i = 0, NumCapabilities = 0; i < 8; i++)
{
if (caps >> i & 1)
{
if (NumCapabilities > 0)
strcat(capsbuffer, ", ");
capability = (i < 6) ? i : 6;
strcat(capsbuffer, capabilities[capability]);
NumCapabilities++;
}
}
}
else
strcpy(capsbuffer, "None");
return capsbuffer;
}
const char *GetPHYVendDesc(unsigned int oui)
{
const char *description;
if ((description = PS2IDBMS_LookupComponentModel(PS2IDB_COMPONENT_ETH_PHY_VEND, oui)) == NULL)
{
description = "Unknown";
}
return description;
}
const char *GetPHYModelDesc(unsigned int oui, unsigned char model)
{
unsigned int revision;
const char *description;
if ((description = PS2IDBMS_LookupComponentModel(PS2IDB_COMPONENT_ETH_PHY_MODEL, oui << 8 | model)) == NULL)
{
description = "Unknown";
}
return description;
}
const char *GetGSChipDesc(unsigned short int revision)
{
const char *description;
if ((description = PS2IDBMS_LookupComponentModel(PS2IDB_COMPONENT_GS, revision)) == NULL)
{
description = "Missing";
}
return description;
}
const char *GetEEChipDesc(unsigned short int revision)
{
const char *description;
if ((description = PS2IDBMS_LookupComponentModel(PS2IDB_COMPONENT_EE, revision)) == NULL)
{
description = "Missing";
}
return description;
}
const char *GetIOPChipDesc(unsigned short int revision)
{
const char *description;
if ((description = PS2IDBMS_LookupComponentModel(PS2IDB_COMPONENT_IOP, revision)) == NULL)
{
description = "Missing";
}
return description;
}
const char *GetSPU2ChipDesc(unsigned short int revision)
{
const char *description;
if ((description = PS2IDBMS_LookupComponentModel(PS2IDB_COMPONENT_SPU2, revision)) == NULL)
{
description = "Missing";
}
return description;
}
const char *GetMECHACONChipDesc(unsigned short int revision)
{
const char *description;
if ((description = PS2IDBMS_LookupComponentModel(PS2IDB_COMPONENT_MECHACON, revision)) == NULL)
{
description = "Missing";
}
return description;
}
const char *GetSystemTypeDesc(unsigned char type)
{
const char *description;
if ((description = PS2IDBMS_LookupComponentModel(PS2IDB_COMPONENT_SYSTEM_TYPE, type)) == NULL)
{
description = "Unknown";
}
return description;
}
const char *GetRegionDesc(unsigned char region)
{
const char *description;
if ((description = PS2IDBMS_LookupComponentModel(PS2IDB_COMPONENT_MG_REGION, region)) == NULL)
{
description = "Unknown";
}
return description;
}
const char *GetMainboardModelDesc(const struct PS2IDBMainboardEntry *SystemInformation)
{
const char *description;
const struct PS2IDBMainboardEntry *ModelData;
if ((ModelData = PS2IDBMS_LookupMainboardModel(SystemInformation)) != NULL)
description = ModelData->MainboardName;
else if (!strncmp(SystemInformation->romver, "0170", 4) || !strncmp(SystemInformation->romver, "0190", 4))
description = "Sticker"; //SCPH-5xxxx can be retrieved from sticker
else
description = "Missing";
return description;
}
const char *GetMRPDesc(unsigned short int id)
{
const char *description;
if ((description = PS2IDBMS_LookupComponentModel(PS2IDB_COMPONENT_MRP_BOARD, id & 0xF8)) == NULL)
{
description = "Unknown";
}
return description;
}
const char *GetChassisDesc(const struct PS2IDBMainboardEntry *SystemInformation)
{
const char *description;
if (!strcmp(SystemInformation->MainboardName, "GH-001") || !strcmp(SystemInformation->MainboardName, "GH-003"))
description = "A-chassis"; //SCPH-10000 and SCPH-15000
else if (!strcmp(SystemInformation->MainboardName, "GH-003") && strncmp("0101", SystemInformation->romver, 4))
description = "A-chassis+"; //SCPH-18000 with GH-003
else if (!strcmp(SystemInformation->MainboardName, "GH-008"))
description = "AB-chassis"; //SCPH-18000
else if (!strcmp(SystemInformation->MainboardName, "GH-004") || !strcmp(SystemInformation->MainboardName, "GH-005"))
description = "B-chassis"; //SCPH-30000
else if (!strcmp(SystemInformation->MainboardName, "GH-006") || !strcmp(SystemInformation->MainboardName, "GH-007"))
description = "C-chassis"; //SCPH-30000
else if (!strcmp(SystemInformation->MainboardName, "GH-010") || !strcmp(SystemInformation->MainboardName, "GH-011") || !strcmp(SystemInformation->MainboardName, "GH-012") || !strcmp(SystemInformation->MainboardName, "GH-013") || !strcmp(SystemInformation->MainboardName, "GH-014") || !strcmp(SystemInformation->MainboardName, "GH-016"))
description = "D-chassis"; //SCPH-30000, SCPH-30000R and SCPH-35000
else if (!strcmp(SystemInformation->MainboardName, "GH-015"))
description = "F-chassis"; //SCPH-30000 and SCPH-30000R
else if (!strcmp(SystemInformation->MainboardName, "GH-016"))
description = "DR-chassis"; //SCPH-30000
else if (!strcmp(SystemInformation->MainboardName, "GH-017") || !strcmp(SystemInformation->MainboardName, "GH-019") || !strcmp(SystemInformation->MainboardName, "GH-022"))
description = "G-chassis"; //SCPH-37000 and SCPH-39000
else if (!strcmp(SystemInformation->MainboardName, "GH-023"))
description = "H-chassis"; //SCPH-50000
else if (!strcmp(SystemInformation->MainboardName, "GH-026"))
description = "I-chassis"; //SCPH-50000a
else if (!strcmp(SystemInformation->MainboardName, "GH-029"))
description = "J-chassis"; //SCPH-50000b
else if (!strncmp(SystemInformation->MainboardName, "GH-032", 6) || !strncmp(SystemInformation->MainboardName, "GH-035", 6))
description = "K-chassis"; //SCPH-70000
else if (!strncmp(SystemInformation->MainboardName, "GH-037", 6) || !strncmp(SystemInformation->MainboardName, "GH-040", 6) || !strncmp(SystemInformation->MainboardName, "GH-041", 6))
description = "L-chassis"; //SCPH-75000
else if (!strncmp(SystemInformation->MainboardName, "GH-051", 6) || !strncmp(SystemInformation->MainboardName, "GH-052", 6))
description = "M-chassis"; //SCPH-77000
else if (!strncmp(SystemInformation->MainboardName, "GH-061", 6) || !strncmp(SystemInformation->MainboardName, "GH-062", 6))
description = "N-chassis"; //SCPH-79000
else if (!strncmp(SystemInformation->MainboardName, "GH-070", 6) || !strncmp(SystemInformation->MainboardName, "GH-071", 6))
description = "P-chassis"; //SCPH-90000, TVcombo
else if (!strncmp(SystemInformation->MainboardName, "GH-072", 6))
description = "R-chassis"; //SCPH-90000
else if (!strncmp(SystemInformation->MainboardName, "XPD-", 4))
description = "X-chassis"; //PSX
else if (!strncmp(SystemInformation->romver, "0170", 4) || !strncmp(SystemInformation->romver, "0190", 4))
description = "Sticker"; //SCPH-5xxxx can be retrieved from sticker
else
description = "Unknown";
return description;
}
const char *GetModelIDDesc(unsigned int id)
{
const char *description;
if ((description = PS2IDBMS_LookupComponentModel(PS2IDB_COMPONENT_MODEL_ID, id)) == NULL)
{
description = "Sticker";
}
return description;
}
const char *GetEMCSIDDesc(unsigned char id)
{
const char *description;
if ((description = PS2IDBMS_LookupComponentModel(PS2IDB_COMPONENT_EMCS_ID, id)) == NULL)
{
description = "Sticker";
}
return description;
}
const char *GetADD010Desc(unsigned short int id)
{
const char *description;
if ((description = PS2IDBMS_LookupComponentModel(PS2IDB_COMPONENT_ADD010, id)) == NULL)
{
description = "Unknown";
}
return description;
}
const char *GetDSPDesc(unsigned char revision)
{
static const char *revisions[] = {
"CXD1869Q",
"CXD1869AQ",
"CXD1869BQ/CXD1886Q-1/CXD1886",
"CXD3098Q/CXD1886Q-1/CXD3098AQ",
"Missing"};
if (revision > 4)
revision = 4;
return revisions[revision];
}
unsigned int CalculateCPUCacheSize(unsigned char value)
{ //2^(12+value)
return (1U << (12 + value));
}
int WriteSystemInformation(FILE *stream, const struct SystemInformation *SystemInformation)
{
unsigned int i, modelID;
// unsigned short int conModelID;
u32 Serial;
int MayBeModded;
const char *dvdplVer;
const char *OSDVer;
MayBeModded = CheckROM(&SystemInformation->mainboard);
//Header
fputs("Log file generated by Playstation 2 Ident v" PS2IDENT_VERSION ", built on "__DATE__
" "__TIME__
"\r\n\r\n",
stream);
fprintf(stream, "ROMVER: %s\r\n", SystemInformation->mainboard.romver);
//ROM region sizes
fprintf(stream, "ROM region sizes:\r\n");
for (i = 0; i <= 2; i++)
{
fprintf(stream, " ROM%u: ", i);
if (SystemInformation->ROMs[i].IsExists)
fprintf(stream, "%p (%u bytes)\r\n", SystemInformation->ROMs[i].StartAddress, SystemInformation->ROMs[i].size);
else
fputs("<Not detected>\r\n", stream);
}
fprintf(stream, " EROM: ");
if (SystemInformation->erom.IsExists)
fprintf(stream, "%p (%u bytes)\r\n", SystemInformation->erom.StartAddress, SystemInformation->erom.size);
else
fprintf(stream, "<Not detected>\r\n");
//Physical ROM chip sizes
fputs("ROM chip sizes:\r\n"
" Boot ROM: ",
stream);
if (SystemInformation->mainboard.BOOT_ROM.IsExists)
{
fprintf(stream, "%p (%u Mbit) CRC16: 0x%04x\r\n",
SystemInformation->mainboard.BOOT_ROM.StartAddress, SystemInformation->mainboard.BOOT_ROM.size / 1024 / 128,
SystemInformation->mainboard.BOOT_ROM.crc16);
}
else
fputs("<Not detected>\r\n", stream);
fputs(" DVD ROM: ", stream);
if (SystemInformation->mainboard.DVD_ROM.IsExists)
{
fprintf(stream, "%p (%u Mbit) CRC16: 0x%04x\r\n",
SystemInformation->mainboard.DVD_ROM.StartAddress, SystemInformation->mainboard.DVD_ROM.size / 1024 / 128,
SystemInformation->mainboard.DVD_ROM.crc16);
}
else
fputs("<Not detected>\r\n", stream);
//Version numbers
dvdplVer = SystemInformation->DVDPlayerVer[0] == '\0' ? "-" : SystemInformation->DVDPlayerVer;
OSDVer = SystemInformation->OSDVer[0] == '\0' ? "-" : SystemInformation->OSDVer;
fprintf(stream, " DVD Player: %s\r\n"
" OSDVer: %s\r\n"
" PS1DRV: %s\r\n",
dvdplVer, OSDVer, SystemInformation->PS1DRVVer);
//Chip revisions
fprintf(stream, "EE/GS:\r\n"
" Implementation: 0x%02x\r\n"
" Revision: %u.%u (%s)\r\n"
" EE_F520: 0x%08x\r\n"
" EE_F540: 0x%08x\r\n"
" EE_F550: 0x%08x\r\n"
" FPU implementation: 0x%02x\r\n"
" FPU revision: %u.%u\r\n"
" ICache size: 0x%02x (%u KB)\r\n"
" DCache size: 0x%02x (%u KB)\r\n"
" RAM size: %u bytes\r\n"
" GS revision: %u.%02u (%s)\r\n"
" GS ID: 0x%02x\r\n",
SystemInformation->mainboard.ee.implementation, SystemInformation->mainboard.ee.revision >> 4, SystemInformation->mainboard.ee.revision & 0xF, GetEEChipDesc((unsigned short int)(SystemInformation->mainboard.ee.implementation) << 8 | SystemInformation->mainboard.ee.revision),
SystemInformation->EE_F520, SystemInformation->EE_F540, SystemInformation->EE_F550,
SystemInformation->mainboard.ee.FPUImplementation, SystemInformation->mainboard.ee.FPURevision >> 4, SystemInformation->mainboard.ee.FPURevision & 0xF,
SystemInformation->mainboard.ee.ICacheSize, CalculateCPUCacheSize(SystemInformation->mainboard.ee.ICacheSize) / 1024,
SystemInformation->mainboard.ee.DCacheSize, CalculateCPUCacheSize(SystemInformation->mainboard.ee.DCacheSize) / 1024,
SystemInformation->mainboard.ee.RAMSize,
SystemInformation->mainboard.gs.revision >> 4, SystemInformation->mainboard.gs.revision & 0xF,
GetGSChipDesc((u16)(SystemInformation->mainboard.gs.id) << 8 | SystemInformation->mainboard.gs.revision),
SystemInformation->mainboard.gs.id);
fprintf(stream, "IOP:\r\n"
" Implementation: 0x%02x\r\n"
" Revision: %u.%u (%s)\r\n"
" RAM size: %u bytes\r\n"
" SSBUS I/F revision: %u.%u (%s)\r\n",
SystemInformation->mainboard.iop.revision >> 8,
(SystemInformation->mainboard.iop.revision & 0xFF) >> 4, SystemInformation->mainboard.iop.revision & 0xF, GetIOPChipDesc(SystemInformation->mainboard.iop.revision),
SystemInformation->mainboard.iop.RAMSize,
SystemInformation->mainboard.ssbus.revision >> 4, SystemInformation->mainboard.ssbus.revision & 0xF,
GetSSBUSIFDesc(SystemInformation->mainboard.ssbus.revision));
fputs(" AIF revision: ", stream);
if (SystemInformation->mainboard.ssbus.status & PS2DB_SSBUS_HAS_AIF)
fprintf(stream, "%u\r\n", SystemInformation->mainboard.ssbus.AIFRevision);
else
fputs("<Not detected>\r\n", stream);
if (!(SystemInformation->mainboard.status & PS2IDB_STAT_ERR_MVER))
{
fprintf(stream, "MECHACON:\r\n"
" Revision: %u.%02u (%s)\r\n"
" MagicGate region: 0x%02x (%s)\r\n"
" System type: 0x%02x (%s)\r\n"
" DSP revision: %u (%s)\r\n",
SystemInformation->mainboard.MECHACONVersion[1], SystemInformation->mainboard.MECHACONVersion[2], GetMECHACONChipDesc((unsigned int)(SystemInformation->mainboard.MECHACONVersion[1]) << 8 | (unsigned int)(SystemInformation->mainboard.MECHACONVersion[2])),
SystemInformation->mainboard.MECHACONVersion[0], GetRegionDesc(SystemInformation->mainboard.MECHACONVersion[0]),
SystemInformation->mainboard.MECHACONVersion[3], GetSystemTypeDesc(SystemInformation->mainboard.MECHACONVersion[3]),
SystemInformation->DSPVersion[1],GetDSPDesc(SystemInformation->DSPVersion[1]));
}
else
{
fputs("MECHACON:\r\n"
" Revision: -.-\r\n"
" MagicGate region: -\r\n"
" System type: -\r\n"
" DSP revision: -\r\n",
stream);
}
fprintf(stream, " M Renewal Date: ");
if (SystemInformation->mainboard.MECHACONVersion[1] < 5 || (SystemInformation->mainboard.status & PS2IDB_STAT_ERR_MRENEWDATE))
fprintf(stream, "----/--/-- --:--\r\n");
else
fprintf(stream, "20%02x/%02x/%02x %02x:%02x\r\n", SystemInformation->mainboard.MRenewalDate[0], SystemInformation->mainboard.MRenewalDate[1], SystemInformation->mainboard.MRenewalDate[2], SystemInformation->mainboard.MRenewalDate[3], SystemInformation->mainboard.MRenewalDate[4]);
fputs("Mainboard:\r\n"
" Model name: ",
stream);
if (!(SystemInformation->mainboard.status & PS2IDB_STAT_ERR_MNAME))
fprintf(stream, "%s\r\n", SystemInformation->mainboard.ModelName);
else
fputs("-\r\n", stream);
fprintf(stream, " Mainboard model: %s\r\n"
" Chassis: %s\r\n"
" ROMGEN: %04x-%04x\r\n"
" Machine type: 0x%08x\r\n"
" BoardInf: 0x%02x (%s)\r\n"
" MPU Board ID: 0x%04x\r\n"
" SPU2 revision: 0x%02x (%s)\r\n",
SystemInformation->mainboard.MainboardName, SystemInformation->chassis,
SystemInformation->mainboard.ROMGEN_MonthDate, SystemInformation->mainboard.ROMGEN_Year, SystemInformation->mainboard.MachineType,
SystemInformation->mainboard.BoardInf, GetMRPDesc(SystemInformation->mainboard.BoardInf), SystemInformation->mainboard.MPUBoardID,
SystemInformation->mainboard.spu2.revision, GetSPU2ChipDesc(SystemInformation->mainboard.spu2.revision));
fputs(" ADD0x010: ", stream);
if (!(SystemInformation->mainboard.status & PS2IDB_STAT_ERR_ADD010))
{
fprintf(stream, "0x%04x (%s)\r\n",
SystemInformation->mainboard.ADD010, GetADD010Desc(SystemInformation->mainboard.ADD010));
}
else
{
fputs("-\r\n", stream);
}
//i.Link Model ID
fputs(" i.Link Model ID: ", stream);
if (!(SystemInformation->mainboard.status & PS2IDB_STAT_ERR_ILINKID))
{
modelID = SystemInformation->mainboard.ModelID[0] | SystemInformation->mainboard.ModelID[1] << 8 | SystemInformation->mainboard.ModelID[2] << 16;
fprintf(stream, "0x%06x (%s)\r\n", modelID, GetModelIDDesc(modelID));
}
else
{
fputs("-\r\n", stream);
}
//SDMI Model ID (only 1 last byte, but we will keep 2 bytes)
if (!(SystemInformation->mainboard.status & PS2IDB_STAT_ERR_CONSOLEID))
{
// conModelID = SystemInformation->mainboard.ConModelID[0] | SystemInformation->mainboard.ConModelID[1] << 8;
Serial = (SystemInformation->ConsoleID[6]) << 16 | (SystemInformation->ConsoleID[5]) << 8 | (SystemInformation->ConsoleID[4]);
fprintf(stream, " Console Model ID: 0x%02x\r\n"
" SDMI Company ID: %02x-%02x-%02x\r\n"
" EMCS ID: 0x%02x (%s)\r\n"
" Serial range: %03dxxxx\r\n"
,
// conModelID,
SystemInformation->mainboard.ConModelID[0],
SystemInformation->mainboard.ConModelID[3], SystemInformation->mainboard.ConModelID[2], SystemInformation->mainboard.ConModelID[1],
SystemInformation->mainboard.EMCSID, GetEMCSIDDesc(SystemInformation->mainboard.EMCSID),
Serial/10000);
}
else
{
fputs(" Console Model ID: -\r\n"
" SDMI Company ID: -\r\n"
" EMCS ID: -\r\n"
" Serial range: -\r\n",
stream);
}
fprintf(stream, " USB HC revision: %u.%u\r\n",
SystemInformation->mainboard.usb.HcRevision >> 4, SystemInformation->mainboard.usb.HcRevision & 0xF);
if (SystemInformation->mainboard.ssbus.status & PS2DB_SSBUS_HAS_SPEED)
{
fprintf(stream, "DEV9:\r\n"
" MAC vendor: %02x:%02x:%02x\r\n"
" SPEED revision: 0x%04x (%s)\r\n"
" SPEED capabilities: %04x.%04x (%s)\r\n",
SystemInformation->SMAP_MAC_address[0],SystemInformation->SMAP_MAC_address[1],SystemInformation->SMAP_MAC_address[2],
SystemInformation->mainboard.ssbus.SPEED.rev1, GetSPEEDDesc(SystemInformation->mainboard.ssbus.SPEED.rev1), SystemInformation->mainboard.ssbus.SPEED.rev3, SystemInformation->mainboard.ssbus.SPEED.rev8, GetSPEEDCapsDesc(SystemInformation->mainboard.ssbus.SPEED.rev3));
fprintf(stream, " PHY OUI: 0x%06x (%s)\r\n"
" PHY model: 0x%02x (%s)\r\n"
" PHY revision: 0x%02x\r\n",
SystemInformation->mainboard.ssbus.SPEED.SMAP_PHY_OUI, GetPHYVendDesc(SystemInformation->mainboard.ssbus.SPEED.SMAP_PHY_OUI), SystemInformation->mainboard.ssbus.SPEED.SMAP_PHY_VMDL, GetPHYModelDesc(SystemInformation->mainboard.ssbus.SPEED.SMAP_PHY_OUI, SystemInformation->mainboard.ssbus.SPEED.SMAP_PHY_VMDL), SystemInformation->mainboard.ssbus.SPEED.SMAP_PHY_REV);
}
else
{
fprintf(stream, "DEV9:\r\n ***No expansion device connected***\r\n");
}
fprintf(stream, "i.Link:\r\n"
" Ports: %u\r\n"
" Max speed: %u (%s)\r\n"
" Compliance level: %u (%s)\r\n"
" Vendor ID: 0x%06x (%s)\r\n"
" Product ID: 0x%06x\r\n",
SystemInformation->mainboard.iLink.NumPorts,
SystemInformation->mainboard.iLink.MaxSpeed,
GetiLinkSpeedDesc(SystemInformation->mainboard.iLink.MaxSpeed),
SystemInformation->mainboard.iLink.ComplianceLevel,
GetiLinkComplianceLvlDesc(SystemInformation->mainboard.iLink.ComplianceLevel),
SystemInformation->mainboard.iLink.VendorID,
GetiLinkVendorDesc(SystemInformation->mainboard.iLink.VendorID),
SystemInformation->mainboard.iLink.ProductID);
if (SystemInformation->mainboard.status || MayBeModded)
{
fprintf(stream, "Remarks:\r\n");
if (SystemInformation->mainboard.status & PS2IDB_STAT_ERR_MVER)
fprintf(stream, " Unable to get MECHACON version.\r\n");
if (SystemInformation->mainboard.status & PS2IDB_STAT_ERR_MNAME)
fprintf(stream, " Unable to get model name.\r\n");
if (SystemInformation->mainboard.status & PS2IDB_STAT_ERR_MRENEWDATE)
fprintf(stream, " Unable to get M renewal date.\r\n");
if (SystemInformation->mainboard.status & PS2IDB_STAT_ERR_ILINKID)
fprintf(stream, " Unable to get i.Link ID.\r\n");
if (SystemInformation->mainboard.status & PS2IDB_STAT_ERR_CONSOLEID)
fprintf(stream, " Unable to get console ID.\r\n");
if (SystemInformation->mainboard.status & PS2IDB_STAT_ERR_ADD010)