annotate sidinfo.c @ 58:5ea07110f0cf

Cosmetics.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 26 Dec 2015 22:57:23 +0200
parents c10c79c266d3
children 718cdb563531
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
1 /*
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
2 * SIDInfo - PSID/RSID information displayer
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
3 * Written by Matti 'ccr' Hämäläinen
56
d2148880c71e Update copyright year.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
4 * (C) Copyright 2014-2015 Tecnic Software productions (TNSP)
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
5 */
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 #include "th_args.h"
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 #include "th_endian.h"
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
8 #include "th_string.h"
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 #include "th_crypto.h"
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10
28
6240788fe172 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
11 // Some constants
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
12 #define PSID_MAGIC_LEN 4
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
13 #define PSID_STR_LEN 32
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
14 #define PSID_BUFFER_SIZE (1024 * 16)
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
15
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16
28
6240788fe172 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
17 // Flags for various information fields
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
18 enum
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
19 {
35
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
20 SIF_NONE = 0,
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
21
35
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
22 SIF_TYPE = 0x00000001,
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
23 SIF_VERSION = 0x00000002,
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
24 SIF_DATA_OFFS = 0x00000004,
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
25 SIF_LOAD_ADDR = 0x00000008,
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
26 SIF_INIT_ADDR = 0x00000010,
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
27 SIF_PLAY_ADDR = 0x00000020,
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
28 SIF_SONGS = 0x00000040,
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
29 SIF_START_SONG = 0x00000080,
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
30 SIF_SPEEDS = 0x00000100,
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
31 SIF_SID_NAME = 0x00000200,
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
32 SIF_SID_AUTHOR = 0x00000400,
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
33 SIF_SID_COPYRIGHT = 0x00000800,
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
34 SIF_PLAYER_TYPE = 0x00001000,
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
35 SIF_PLAYSID_TUNE = 0x00002000,
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
36 SIF_VIDEO_CLOCK = 0x00004000,
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
37 SIF_SID_MODEL = 0x00008000,
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
38
35
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
39 SIF_DATA_SIZE = 0x00100000,
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
40 SIF_HASH = 0x00200000,
51
485c8ed6d3fe Portability fix.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
41 SIF_FILENAME = 0x01000000,
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
42
51
485c8ed6d3fe Portability fix.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
43 SIF_ALL = 0x0fffffff,
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
44 };
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
45
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
46
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 typedef struct
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 {
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
49 uint32_t flag;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
50 char *name;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
51 char *lname;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
52 } PSFOption;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
53
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
54
45
ed8c803a948c Static constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
55 static const PSFOption optPSFlags[] =
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
56 {
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
57 { SIF_FILENAME , "Filename" , NULL },
35
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
58 { SIF_TYPE , "Type" , NULL },
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
59 { SIF_VERSION , "Version" , NULL },
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
60 { SIF_PLAYER_TYPE , "PlayerType" , "Player type" },
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
61 { SIF_PLAYSID_TUNE , "PlayerCompat", "Player compatibility" },
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
62 { SIF_VIDEO_CLOCK , "VideoClock" , "Video clock speed" },
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
63 { SIF_SID_MODEL , "SIDModel" , "SID model" },
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
64
35
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
65 { SIF_DATA_OFFS , "DataOffs" , "Data offset" },
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
66 { SIF_DATA_SIZE , "DataSize" , "Data size" },
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
67 { SIF_LOAD_ADDR , "LoadAddr" , "Load address" },
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
68 { SIF_INIT_ADDR , "InitAddr" , "Init address" },
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
69 { SIF_PLAY_ADDR , "PlayAddr" , "Play address" },
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
70 { SIF_SONGS , "Songs" , "Songs" },
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
71 { SIF_START_SONG , "StartSong" , "Start song" },
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
72 { SIF_SID_NAME , "Name" , NULL },
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
73 { SIF_SID_AUTHOR , "Author" , NULL },
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
74 { SIF_SID_COPYRIGHT , "Copyright" , NULL },
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
75 { SIF_HASH , "Hash" , NULL },
28
6240788fe172 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
76
35
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
77 { SIF_ALL , "All" , NULL },
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
78 };
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
79
45
ed8c803a948c Static constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
80 static const int noptPSFlags = sizeof(optPSFlags) / sizeof(optPSFlags[0]);
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
81
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
82
28
6240788fe172 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
83 // Option variables
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
84 BOOL optParsable = FALSE,
7
36c43f085b28 Add NoPrefix option -n.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
85 optNoNamePrefix = FALSE,
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
86 optHexadecimal = FALSE,
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
87 optOneLine = FALSE;
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
88 char *optFieldSep = NULL;
35
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
89 uint32_t optFields = SIF_ALL;
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
90 int optNFiles = 0;
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
91
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
92
28
6240788fe172 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
93 // Define option arguments
44
7b137e4e817c Fix to match the changes in th_args API.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
94 static const th_optarg_t optList[] =
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
95 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
96 { 0, '?', "help", "Show this help", OPT_NONE },
24
16d6b5029543 Disable verbose option for now, it does not do anything at the moment.
Matti Hamalainen <ccr@tnsp.org>
parents: 23
diff changeset
97 // { 1, 'v', "verbose", "Be more verbose", OPT_NONE },
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
98 { 2, 'p', "parsable", "Output in script-parsable format", OPT_NONE },
7
36c43f085b28 Add NoPrefix option -n.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
99 { 5, 'n', "noprefix", "Output without field name prefix", OPT_NONE },
33
39d9df17c8b1 Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
100 { 6, 'l', "line", "Output in one line format, -l <field separator>", OPT_ARGREQ },
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
101 { 3, 'f', "fields", "Show only specified field(s)", OPT_ARGREQ },
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
102 { 4, 'x', "hex", "Use hexadecimal values", OPT_NONE },
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
103 };
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
104
44
7b137e4e817c Fix to match the changes in th_args API.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
105 static const int optListN = sizeof(optList) / sizeof(optList[0]);
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
106
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
107
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
108 void argShowHelp(void)
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
109 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
110 int index, n;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
111
20
6058339ffe0e Update usage.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
112 th_print_banner(stdout, th_prog_name, "[options] <sid filename> [sid filename #2 ..]");
44
7b137e4e817c Fix to match the changes in th_args API.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
113 th_args_help(stdout, optList, optListN, 0);
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
114 printf(
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
115 "\n"
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
116 "Available fields:\n");
3
dbe35d78e621 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
117
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
118 for (index = n = 0; index < noptPSFlags; index++)
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
119 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
120 const PSFOption *opt = &optPSFlags[index];
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
121 printf("%s%s", opt->name, (index < noptPSFlags - 1) ? ", " : "\n\n");
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
122 if (++n > 5)
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
123 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
124 printf("\n");
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
125 n = 0;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
126 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
127 }
58
5ea07110f0cf Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
128
5
2892e994243c Add usage example.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
129 printf("Example: %s -x -p -f hash,copyright somesidfile.sid\n", th_prog_name);
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
130 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
131
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
132
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
133 int argMatchPSField(const char *field)
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
134 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
135 int index, found = -1;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
136 size_t len = strlen(field);
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
137 for (index = 0; index < noptPSFlags; index++)
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
138 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
139 const PSFOption *opt = &optPSFlags[index];
48
af1e12c8ebf1 Use th_strncasecmp().
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
140 if (th_strncasecmp(opt->name, field, len) == 0)
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
141 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
142 if (found >= 0)
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
143 return -2;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
144 found = index;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
145 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
146 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
147
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
148 return found;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
149 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
150
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
151
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
152 BOOL argParsePSField(char *opt, char *end, uint32_t *fields)
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
153 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
154 // Trim whitespace
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
155 if (end != NULL)
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
156 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
157 *end = 0;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
158 for (end--; end > opt && *end && th_isspace(*end); end--)
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
159 *end = 0;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
160 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
161 while (*opt && th_isspace(*opt)) opt++;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
162
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
163 // Match field name
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
164 int found = argMatchPSField(opt);
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
165 switch (found)
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
166 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
167 case -1:
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
168 THERR("No such field '%s'.\n", opt);
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
169 return FALSE;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
170
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
171 case -2:
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
172 THERR("Field '%s' is ambiguous.\n", opt);
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
173 return FALSE;
3
dbe35d78e621 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
174
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
175 default:
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
176 *fields |= optPSFlags[found].flag;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
177 return TRUE;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
178 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
179 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
180
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
181
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
182 BOOL argHandleOpt(const int optN, char *optArg, char *currArg)
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
183 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
184 switch (optN)
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
185 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
186 case 0:
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
187 argShowHelp();
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
188 exit(0);
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
189 break;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
190
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
191 case 1:
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
192 th_verbosityLevel++;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
193 break;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
194
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
195 case 2:
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
196 optParsable = TRUE;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
197 break;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
198
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
199 case 3:
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
200 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
201 char *start = optArg;
35
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
202 optFields = SIF_NONE;
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
203
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
204 while (*start)
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
205 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
206 char *end = strchr(start, ',');
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
207
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
208 if (!argParsePSField(start, end, &optFields))
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
209 return FALSE;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
210
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
211 if (!end)
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
212 break;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
213
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
214 start = end + 1;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
215 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
216 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
217 break;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
218
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
219 case 4:
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
220 optHexadecimal = TRUE;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
221 break;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
222
7
36c43f085b28 Add NoPrefix option -n.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
223 case 5:
36c43f085b28 Add NoPrefix option -n.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
224 optNoNamePrefix = TRUE;
36c43f085b28 Add NoPrefix option -n.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
225 break;
36c43f085b28 Add NoPrefix option -n.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
226
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
227 case 6:
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
228 optOneLine = TRUE;
33
39d9df17c8b1 Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
229 optFieldSep = optArg;
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
230 break;
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
231
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
232 default:
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
233 THERR("Unknown option '%s'.\n", currArg);
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
234 return FALSE;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
235 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
236
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
237 return TRUE;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
238 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
239
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
240
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
241 typedef struct
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
242 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
243 char magic[PSID_MAGIC_LEN + 1]; // "PSID" / "RSID" magic identifier
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
244 uint16_t
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
245 version, // Version number
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
246 dataOffset, // Start of actual c64 data in file
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
247 loadAddress, // Loading address
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
248 initAddress, // Initialization address
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
249 playAddress, // Play one frame
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
250 nSongs, // Number of subsongs
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
251 startSong; // Default starting song
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
252 uint32_t speed; // Speed
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
253 char sidName[PSID_STR_LEN + 1]; // Descriptive text-fields, ASCIIZ
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
254 char sidAuthor[PSID_STR_LEN + 1];
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
255 char sidCopyright[PSID_STR_LEN + 1];
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
256
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
257 // PSIDv2 data
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
258 uint16_t flags; // Flags
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
259 uint8_t startPage, pageLength;
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
260 uint16_t reserved;
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
261
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
262 // Extra data
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
263 BOOL isRSID;
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
264 size_t dataSize; // Total size of data - header
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
265 th_md5hash_t hash; // Songlength database hash
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
266
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
267 } PSIDHeader;
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
268
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
269
35
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
270 enum
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
271 {
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
272 PSF_PLAYER_TYPE = 0x0001, // 0 = built-in, 1 = Compute! SIDPlayer MUS
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
273 PSF_PLAYSID_TUNE = 0x0002, // 0 = Real C64-compatible, 1 = PlaySID specific (v2NG)
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
274
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
275 PSF_CLOCK_UNKNOWN = 0x0000, // Video standard used (v2NG)
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
276 PSF_CLOCK_PAL = 0x0004,
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
277 PSF_CLOCK_NTSC = 0x0008,
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
278 PSF_CLOCK_ANY = 0x000c,
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
279 PSF_CLOCK_MASK = 0x000c,
58
5ea07110f0cf Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
280
35
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
281 PSF_MODEL_UNKNOWN = 0x0000, // SID model (v2NG)
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
282 PSF_MODEL_MOS6581 = 0x0010,
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
283 PSF_MODEL_MOS8580 = 0x0020,
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
284 PSF_MODEL_ANY = 0x0030,
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
285 PSF_MODEL_MASK = 0x0030,
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
286 };
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
287
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
288
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
289 static void siAppendHash16(th_md5state_t *state, uint16_t data)
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
290 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
291 uint8_t ib8[2];
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
292 ib8[0] = data & 0xff;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
293 ib8[1] = data >> 8;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
294 th_md5_append(state, (uint8_t *) &ib8, sizeof(ib8));
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
295 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
296
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
297
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
298 int siReadPSIDFile(FILE *inFile, PSIDHeader *psid)
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
299 {
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
300 th_md5state_t state;
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
301 uint8_t tmp8, *fileData = NULL;
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
302 int index, ret = -1;
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
303 size_t read;
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
304 BOOL first;
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
305
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
306 memset(psid, 0, sizeof(*psid));
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
307
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
308 if ((fileData = (uint8_t *) th_malloc(PSID_BUFFER_SIZE)) == NULL)
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
309 {
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
310 THERR("Error allocating temporary data buffer of %d bytes.\n", PSID_BUFFER_SIZE);
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
311 goto error;
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
312 }
3
dbe35d78e621 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
313
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
314 // Read PSID header in
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
315 if (!th_fread_str(inFile, (uint8_t *) psid->magic, PSID_MAGIC_LEN) ||
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
316 !th_fread_be16(inFile, &psid->version) ||
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
317 !th_fread_be16(inFile, &psid->dataOffset) ||
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
318 !th_fread_be16(inFile, &psid->loadAddress) ||
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
319 !th_fread_be16(inFile, &psid->initAddress) ||
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
320 !th_fread_be16(inFile, &psid->playAddress) ||
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
321 !th_fread_be16(inFile, &psid->nSongs) ||
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
322 !th_fread_be16(inFile, &psid->startSong) ||
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
323 !th_fread_be32(inFile, &psid->speed))
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
324 {
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
325 THERR("Could not read PSID/RSID header.\n");
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
326 goto error;
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
327 }
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
328
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
329 psid->magic[PSID_MAGIC_LEN] = 0;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
330
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
331 if ((psid->magic[0] != 'R' && psid->magic[0] != 'P') ||
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
332 psid->magic[1] != 'S' || psid->magic[2] != 'I' || psid->magic[3] != 'D' ||
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
333 psid->version < 1 || psid->version > 3)
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
334 {
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
335 THERR("Not a supported PSID or RSID file.\n");
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
336 goto error;
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
337 }
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
338
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
339 psid->isRSID = psid->magic[0] == 'R';
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
340
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
341 if (!th_fread_str(inFile, (uint8_t *)psid->sidName, PSID_STR_LEN) ||
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
342 !th_fread_str(inFile, (uint8_t *)psid->sidAuthor, PSID_STR_LEN) ||
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
343 !th_fread_str(inFile, (uint8_t *)psid->sidCopyright, PSID_STR_LEN))
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
344 {
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
345 THERR("Error reading SID file header.\n");
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
346 goto error;
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
347 }
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
348
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
349 psid->sidName[PSID_STR_LEN] = 0;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
350 psid->sidAuthor[PSID_STR_LEN] = 0;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
351 psid->sidCopyright[PSID_STR_LEN] = 0;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
352
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
353 // Check if we need to load PSIDv2NG header ...
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
354 if (psid->version >= 2)
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
355 {
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
356 // Yes, we need to
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
357 if (!th_fread_be16(inFile, &psid->flags) ||
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
358 !th_fread_byte(inFile, &psid->startPage) ||
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
359 !th_fread_byte(inFile, &psid->pageLength) ||
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
360 !th_fread_be16(inFile, &psid->reserved))
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
361 {
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
362 THERR("Error reading PSID/RSID v2+ extra header data.\n");
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
363 goto error;
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
364 }
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
365 }
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
366
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
367 // Initialize MD5-hash calculation
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
368 th_md5_init(&state);
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
369
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
370 // Process actual data
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
371 psid->dataSize = 0;
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
372 first = TRUE;
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
373 do
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
374 {
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
375 read = fread(fileData, sizeof(uint8_t), PSID_BUFFER_SIZE, inFile);
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
376 psid->dataSize += read;
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
377
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
378 if (first && psid->loadAddress == 0)
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
379 {
8
cfc74ec918dc Fix handling of "large" SID files.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
380 if (read < 4)
cfc74ec918dc Fix handling of "large" SID files.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
381 {
cfc74ec918dc Fix handling of "large" SID files.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
382 THERR("Error reading song data, unexpectedly small file.\n");
cfc74ec918dc Fix handling of "large" SID files.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
383 goto error;
cfc74ec918dc Fix handling of "large" SID files.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
384 }
58
5ea07110f0cf Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
385
39
3ce9d2198193 Grab the actual loading address from data block if PSID header loadAddr value is 0.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
386 // Grab the actual load address
3ce9d2198193 Grab the actual loading address from data block if PSID header loadAddr value is 0.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
387 psid->loadAddress = TH_LE16_TO_NATIVE(*(uint16_t *) fileData);
8
cfc74ec918dc Fix handling of "large" SID files.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
388
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
389 // Strip load address (2 first bytes)
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
390 th_md5_append(&state, &fileData[2], read - 2);
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
391 first = FALSE;
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
392 }
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
393 else
8
cfc74ec918dc Fix handling of "large" SID files.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
394 if (read > 0)
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
395 {
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
396 // Append "as is"
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
397 th_md5_append(&state, fileData, read);
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
398 }
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
399 } while (read > 0 && !feof(inFile));
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
400
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
401 // Append header data to hash
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
402 siAppendHash16(&state, psid->initAddress);
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
403 siAppendHash16(&state, psid->playAddress);
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
404 siAppendHash16(&state, psid->nSongs);
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
405
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
406 // Append song speed data to hash
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
407 tmp8 = psid->isRSID ? 60 : 0;
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
408 for (index = 0; index < psid->nSongs && index < 32; index++)
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
409 {
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
410 if (psid->isRSID)
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
411 tmp8 = 60;
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
412 else
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
413 tmp8 = (psid->speed & (1 << index)) ? 60 : 0;
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
414
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
415 th_md5_append(&state, &tmp8, sizeof(tmp8));
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
416 }
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
417
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
418 // Rest of songs (more than 32)
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
419 for (index = 32; index < psid->nSongs; index++)
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
420 th_md5_append(&state, &tmp8, sizeof(tmp8));
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
421
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
422 // PSIDv2NG specific
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
423 if (psid->version >= 2)
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
424 {
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
425 // REFER TO SIDPLAY HEADERS FOR MORE INFORMATION
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
426 tmp8 = (psid->flags >> 2) & 3;
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
427 if (tmp8 == 2)
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
428 th_md5_append(&state, &tmp8, sizeof(tmp8));
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
429 }
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
430
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
431 // Calculate the hash
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
432 th_md5_finish(&state, psid->hash);
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
433 ret = 0;
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
434
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
435 error:
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
436 // Free buffer
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
437 th_free(fileData);
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
438 return ret;
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
439 }
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
440
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
441
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
442 const char *siGetSIDClockStr(int flags)
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
443 {
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
444 switch (flags & PSF_CLOCK_MASK)
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
445 {
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
446 case PSF_CLOCK_UNKNOWN : return "Unknown";
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
447 case PSF_CLOCK_PAL : return "PAL 50Hz";
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
448 case PSF_CLOCK_NTSC : return "NTSC 60Hz";
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
449 case PSF_CLOCK_ANY : return "PAL / NTSC";
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
450 default : return "?";
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
451 }
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
452 }
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
453
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
454
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
455 const char *siGetSIDModelStr(int flags)
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
456 {
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
457 switch (flags & PSF_MODEL_MASK)
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
458 {
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
459 case PSF_MODEL_UNKNOWN : return "Unknown";
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
460 case PSF_MODEL_MOS6581 : return "MOS6581";
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
461 case PSF_MODEL_MOS8580 : return "MOS8580";
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
462 case PSF_MODEL_ANY : return "MOS6581 / MOS8580";
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
463 default : return "?";
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
464 }
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
465 }
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
466
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
467
31
727c012d5de4 Rename a function.
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
468 static void siPrintFieldPrefix(FILE *outFile, const char *name)
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
469 {
7
36c43f085b28 Add NoPrefix option -n.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
470 if (!optNoNamePrefix)
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
471 fprintf(outFile, optParsable ? "%s=" : "%-20s : ", name);
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
472 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
473
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
474
33
39d9df17c8b1 Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
475 static void siPrintFieldSeparator(FILE *outFile)
39d9df17c8b1 Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
476 {
39d9df17c8b1 Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
477 fprintf(outFile, optOneLine ? optFieldSep : "\n");
39d9df17c8b1 Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
478 }
39d9df17c8b1 Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
479
39d9df17c8b1 Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
480
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
481 static void siPrintPSIDInfoLine(FILE *outFile, BOOL *shown, const int xindex, const char *xfmt, const char *xaltfmt, ...)
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
482 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
483 const PSFOption *opt = &optPSFlags[xindex];
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
484 if (optFields & opt->flag)
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
485 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
486 va_list ap;
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
487 const char *fmt = optHexadecimal ? (xaltfmt != NULL ? xaltfmt : xfmt) : xfmt;
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
488
31
727c012d5de4 Rename a function.
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
489 siPrintFieldPrefix(outFile, (optParsable || opt->lname == NULL) ? opt->name : opt->lname);
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
490
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
491 va_start(ap, xaltfmt);
57
c10c79c266d3 Remove useless code.
Matti Hamalainen <ccr@tnsp.org>
parents: 56
diff changeset
492 vfprintf(outFile, fmt, ap);
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
493 va_end(ap);
3
dbe35d78e621 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
494
33
39d9df17c8b1 Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
495 siPrintFieldSeparator(outFile);
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
496 *shown = TRUE;
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
497 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
498 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
499
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
500 #define PR(xfmt, xaltfmt, ...) siPrintPSIDInfoLine(outFile, shown, xindex, xfmt, xaltfmt, __VA_ARGS__ )
9
c1fba4abf56f Make filename printing optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
501
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
502 void siPrintPSIDInformationField(FILE *outFile, const char *filename, const PSIDHeader *psid, BOOL *shown, const int xindex)
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
503 {
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
504 switch (xindex)
35
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
505 {
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
506 case 0: PR("%s", NULL, filename); break;
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
507 case 1: PR("%s", NULL, psid->magic); break;
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
508 case 2: PR("%d.%d", NULL, (psid->version & 0xff), (psid->version >> 8)); break;
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
509 case 3: PR("%s", NULL, (psid->flags & PSF_PLAYER_TYPE) ? "Compute! SIDPlayer MUS" : "Normal built-in"); break;
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
510 case 4:
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
511 if (psid->version >= 2)
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
512 PR("%s", NULL, (psid->flags & PSF_PLAYSID_TUNE) ? "PlaySID" : "C64 compatible");
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
513 break;
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
514 case 5:
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
515 if (psid->version >= 2)
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
516 PR("%s", NULL, siGetSIDClockStr(psid->flags));
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
517 break;
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
518 case 6:
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
519 if (psid->version >= 2)
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
520 PR("%s", NULL, siGetSIDModelStr(psid->flags));
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
521 break;
35
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
522
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
523 case 7: PR("%d", "$%08x", psid->dataOffset); break;
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
524 case 8: PR("%d", "$%08x", psid->dataSize); break;
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
525 case 9: PR("%d", "$%04x", psid->loadAddress); break;
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
526 case 10: PR("%d", "$%04x", psid->initAddress); break;
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
527 case 11: PR("%d", "$%04x", psid->playAddress); break;
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
528 case 12: PR("%d", "$%04x", psid->nSongs); break;
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
529 case 13: PR("%d", "$%04x", psid->startSong); break;
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
530 case 14: PR("%s", NULL, psid->sidName); break;
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
531 case 15: PR("%s", NULL, psid->sidAuthor); break;
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
532 case 16: PR("%s", NULL, psid->sidCopyright); break;
35
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
533
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
534 case 17:
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
535 {
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
536 const PSFOption *opt = &optPSFlags[xindex];
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
537 if (optFormatStack || (optFields & opt->flag))
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
538 {
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
539 siPrintFieldPrefix(outFile, "Hash");
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
540 th_md5_print(outFile, psid->hash);
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
541 siPrintFieldSeparator(outFile);
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
542 }
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
543 }
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
544 break;
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
545 }
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
546 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
547
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
548
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
549 BOOL argHandleFile(char *filename)
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
550 {
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
551 static PSIDHeader psid;
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
552 FILE *inFile = NULL, *outFile;
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
553 int index;
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
554 BOOL shown = FALSE;
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
555
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
556 optNFiles++;
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
557 outFile = stdout;
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
558
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
559 if ((inFile = fopen(filename, "rb")) == NULL)
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
560 {
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
561 THERR("Could not open file '%s'.\n", filename);
27
4dd463eebb74 Fix argument handling when file does not exist.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
562 return TRUE;
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
563 }
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
564
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
565 // Read PSID data
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
566 if (siReadPSIDFile(inFile, &psid) != 0)
23
832c26cb1637 Improve option handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
567 {
832c26cb1637 Improve option handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
568 THERR("Error reading %s\n", filename);
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
569 goto error;
23
832c26cb1637 Improve option handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
570 }
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
571
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
572 // Output
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
573 {
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
574 for (index = 0; index < noptPSFlags - 1; index++)
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
575 siPrintPSIDInformationField(outFile, filename, &psid, &shown, index);
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
576 if (shown && optOneLine)
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
577 fprintf(outFile, "\n");
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
578 }
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
579
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
580 // Shutdown
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
581 error:
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
582 if (inFile != NULL)
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
583 fclose(inFile);
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
584
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
585 return TRUE;
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
586 }
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
587
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
588
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
589 int main(int argc, char *argv[])
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
590 {
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
591 // Initialize
50
e843b39235db Bump version.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
592 th_init("SIDInfo", "PSID/RSID information displayer", "0.5.3", NULL, NULL);
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
593 th_verbosityLevel = 0;
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
594
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
595 // Parse command line arguments
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
596 if (!th_args_process(argc, argv, optList, optListN,
23
832c26cb1637 Improve option handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
597 argHandleOpt, argHandleFile, OPTH_ONLY_OPTS))
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
598 return -1;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
599
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
600 if (optOneLine)
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
601 {
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
602 optParsable = FALSE;
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
603 optNoNamePrefix = TRUE;
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
604 }
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
605
23
832c26cb1637 Improve option handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
606 // Process files
832c26cb1637 Improve option handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
607 if (!th_args_process(argc, argv, optList, optListN,
832c26cb1637 Improve option handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
608 argHandleOpt, argHandleFile, OPTH_ONLY_OTHER))
832c26cb1637 Improve option handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
609 return -2;
832c26cb1637 Improve option handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
610
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
611 if (optNFiles == 0)
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
612 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
613 argShowHelp();
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
614 THERR("No filename(s) specified.\n");
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
615 }
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
616
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
617 return 0;
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
618 }