1 /*
2 ngp.c - NeoGeo Pocket support for uCON64
3 
4 Copyright (c) 1999 - 2001 NoisyB
5 Copyright (c) 2001        Gulliver
6 
7 
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12 
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22 #ifdef  _MSC_VER
23 #pragma warning(push)
24 #pragma warning(disable: 4668) // 'symbol' is not defined as a preprocessor macro, replacing with '0' for 'directives'
25 #endif
26 #include <string.h>
27 #ifdef  _MSC_VER
28 #pragma warning(pop)
29 #endif
30 #include "misc/archive.h"
31 #include "misc/file.h"
32 #include "ucon64_misc.h"
33 #include "console/ngp.h"
34 #include "backup/backup.h"
35 #include "backup/pl.h"
36 
37 
38 static st_ucon64_obj_t ngp_obj[] =
39   {
40     {UCON64_NGP, WF_SWITCH}
41   };
42 
43 const st_getopt2_t ngp_usage[] =
44   {
45     {
46       NULL, 0, 0, 0,
47       NULL, "Neo Geo Pocket/Neo Geo Pocket Color"/*"1998/1999 SNK http://www.neogeo.co.jp"*/,
48       NULL
49     },
50     {
51       UCON64_NGP_S, 0, 0, UCON64_NGP,
52       NULL, "force recognition",
53       &ngp_obj[0]
54     },
55     {NULL, 0, 0, 0, NULL, NULL, NULL}
56   };
57 
58 typedef struct st_ngp_header
59 {
60   char pad[48];
61 } st_ngp_header_t;
62 
63 #define NGP_HEADER_START 0
64 #define NGP_HEADER_LEN (sizeof (st_ngp_header_t))
65 
66 static st_ngp_header_t ngp_header;
67 
68 
69 int
ngp_init(st_ucon64_nfo_t * rominfo)70 ngp_init (st_ucon64_nfo_t *rominfo)
71 {
72   int result = -1;
73   unsigned int pos = (unsigned int) strlen (rominfo->misc);
74   char *snk_code = "COPYRIGHT BY SNK CORPORATION",
75        *third_code = " LICENSED BY SNK CORPORATION";
76 
77   rominfo->backup_header_len = UCON64_ISSET2 (ucon64.backup_header_len, unsigned int) ?
78                                  ucon64.backup_header_len : 0;
79 
80   ucon64_fread (&ngp_header, NGP_HEADER_START + rominfo->backup_header_len,
81                 NGP_HEADER_LEN, ucon64.fname);
82 
83   if (!strcmp ((char *) &OFFSET (ngp_header, 0), snk_code) ||
84       !strcmp ((char *) &OFFSET (ngp_header, 0), third_code))
85     result = 0;
86   else
87     result = -1;
88   if (ucon64.console == UCON64_NGP)
89     result = 0;
90 
91   rominfo->header_start = NGP_HEADER_START;
92   rominfo->header_len = NGP_HEADER_LEN;
93   rominfo->header = &ngp_header;
94 
95   // internal ROM name
96   strncpy (rominfo->name, (char *) &OFFSET (ngp_header, 0x24), 12);
97   rominfo->name[12] = '\0';
98 
99   // ROM maker
100   rominfo->maker = !strcmp ((char *) &OFFSET (ngp_header, 0), snk_code) ?
101                      "SNK" : "Third party";
102 
103   // misc stuff
104   sprintf (rominfo->misc + pos, "Mode: %s",
105            (OFFSET (ngp_header, 0x23) == 0x00) ? "Mono" :
106            (OFFSET (ngp_header, 0x23) == 0x10) ? "Color" :
107            "Unknown");
108 
109   rominfo->console_usage = ngp_usage[0].help;
110   rominfo->backup_usage = !rominfo->backup_header_len ? pl_usage[0].help : unknown_backup_usage[0].help;
111 
112   return result;
113 }
114