44import java .util .Map ;
55
66public enum GameVersion {
7-
7+
88 // ==================================
99 // Black Version & White Version
1010 // ==================================
@@ -29,21 +29,35 @@ public enum GameVersion {
2929 // Black Version 2 & White Version 2
3030 // ==================================
3131
32- BLACK_2_JAPANESE (23 , 1 , "IREJ" , "ブラック2" , true ),
33- BLACK_2_ENGLISH (23 , 2 , "IREO" , "Black Version 2" , true ),
34- BLACK_2_FRENCH (23 , 3 , "IREF" , "Version Noire 2" , true ),
35- BLACK_2_ITALIAN (23 , 4 , "IREI" , "Versione Nera 2" , true ),
36- BLACK_2_GERMAN (23 , 5 , "IRED" , "Schwarze Edition 2" , true ),
37- BLACK_2_SPANISH (23 , 7 , "IRES" , "Edicion Negra 2" , true ),
38- BLACK_2_KOREAN (23 , 8 , "IREK" , "블랙2" , true ),
39-
40- WHITE_2_JAPANESE (22 , 1 , "IRDJ" , "ホワイト2" , true ),
41- WHITE_2_ENGLISH (22 , 2 , "IRDO" , "White Version 2" , true ),
42- WHITE_2_FRENCH (22 , 3 , "IRDF" , "Version Blanche 2" , true ),
43- WHITE_2_ITALIAN (22 , 4 , "IRDI" , "Versione Bianca 2" , true ),
44- WHITE_2_GERMAN (22 , 5 , "IRDD" , "Weisse Edition 2" , true ),
45- WHITE_2_SPANISH (22 , 7 , "IRDS" , "Edicion Blanca 2" , true ),
46- WHITE_2_KOREAN (22 , 8 , "IRDK" , "화이트2" , true );
32+ BLACK_2_JAPANESE (23 , 1 , "IREJ" , "ブラック2" ),
33+ BLACK_2_ENGLISH (23 , 2 , "IREO" , "Black Version 2" ),
34+ BLACK_2_FRENCH (23 , 3 , "IREF" , "Version Noire 2" ),
35+ BLACK_2_ITALIAN (23 , 4 , "IREI" , "Versione Nera 2" ),
36+ BLACK_2_GERMAN (23 , 5 , "IRED" , "Schwarze Edition 2" ),
37+ BLACK_2_SPANISH (23 , 7 , "IRES" , "Edicion Negra 2" ),
38+ BLACK_2_KOREAN (23 , 8 , "IREK" , "블랙2" ),
39+
40+ WHITE_2_JAPANESE (22 , 1 , "IRDJ" , "ホワイト2" ),
41+ WHITE_2_ENGLISH (22 , 2 , "IRDO" , "White Version 2" ),
42+ WHITE_2_FRENCH (22 , 3 , "IRDF" , "Version Blanche 2" ),
43+ WHITE_2_ITALIAN (22 , 4 , "IRDI" , "Versione Bianca 2" ),
44+ WHITE_2_GERMAN (22 , 5 , "IRDD" , "Weisse Edition 2" ),
45+ WHITE_2_SPANISH (22 , 7 , "IRDS" , "Edicion Blanca 2" ),
46+ WHITE_2_KOREAN (22 , 8 , "IRDK" , "화이트2" );
47+
48+ // Masks
49+ public static final int BW_MASK = 0b110011111111;
50+ public static final int B2W2_MASK = 0b001111111111;
51+ public static final int ALL_MASK = BW_MASK | B2W2_MASK ;
52+ public static final int JAP_MASK = 0b111100000001;
53+ public static final int ENG_MASK = 0b111100000010;
54+ public static final int FRE_MASK = 0b111100000100;
55+ public static final int ITA_MASK = 0b111100001000;
56+ public static final int GER_MASK = 0b111100010000;
57+ public static final int SPA_MASK = 0b111101000000;
58+ public static final int KOR_MASK = 0b111110000000;
59+ public static final int JAP_KOR_MASK = JAP_MASK | KOR_MASK ;
60+ public static final int NA_EUR_MASK = ENG_MASK | FRE_MASK | ITA_MASK | GER_MASK | SPA_MASK ;
4761
4862 // Lookup maps
4963 private static final Map <String , GameVersion > mapBySerial = new HashMap <>();
@@ -52,34 +66,32 @@ public enum GameVersion {
5266 static {
5367 for (GameVersion version : values ()) {
5468 mapBySerial .put (version .getSerial (), version );
55- mapByCodes .put (version .getRomCode () << version . getLanguageCode (), version );
69+ mapByCodes .put (version .getBits (), version );
5670 }
5771 }
5872
5973 private final int romCode ;
6074 private final int languageCode ; // Values are not tested
6175 private final String serial ;
6276 private final String displayName ;
63- private final boolean isVersion2 ;
6477
65- private GameVersion (int romCode , int languageCode , String serial , String displayName , boolean isVersion2 ) {
78+ private GameVersion (int romCode , int languageCode , String serial , String displayName ) {
6679 this .romCode = romCode ;
6780 this .languageCode = languageCode ;
6881 this .serial = serial ;
6982 this .displayName = displayName ;
70- this .isVersion2 = isVersion2 ;
71- }
72-
73- private GameVersion (int romCode , int languageCode , String serial , String displayName ) {
74- this (romCode , languageCode , serial , displayName , false );
7583 }
7684
7785 public static GameVersion lookup (String serial ) {
7886 return mapBySerial .get (serial );
7987 }
8088
8189 public static GameVersion lookup (int romCode , int languageCode ) {
82- return mapByCodes .get (romCode << languageCode );
90+ return mapByCodes .get (getBits (romCode , languageCode ));
91+ }
92+
93+ private static int getBits (int romCode , int languageCode ) {
94+ return (1 << (8 - (romCode - 23 ))) | (1 << languageCode - 1 ) & 0b111111111111;
8395 }
8496
8597 public int getRomCode () {
@@ -99,6 +111,15 @@ public String getDisplayName() {
99111 }
100112
101113 public boolean isVersion2 () {
102- return isVersion2 ;
114+ return checkMask (B2W2_MASK );
115+ }
116+
117+ public boolean checkMask (int mask ) {
118+ int bits = getBits ();
119+ return (bits & mask ) == bits ;
120+ }
121+
122+ public int getBits () {
123+ return getBits (romCode , languageCode );
103124 }
104125}
0 commit comments