Mercurial > hg > sidinfo
annotate sidlib.h @ 133:9cfa0553e7f9
Add support for reading PSID/RSID v4 in sidlib.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 02 Jun 2017 02:39:15 +0300 |
parents | b3e034b8c4b9 |
children | 6418286a7e4c |
rev | line source |
---|---|
70
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1 /* |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2 * SIDInfoLib - Way too simplistic PSID/RSID file library |
97 | 3 * Written by Matti 'ccr' Hämäläinen <ccr@tnsp.org> |
131 | 4 * (C) Copyright 2014-2017 Tecnic Software productions (TNSP) |
70
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
5 */ |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
6 #ifndef SIDLIB_H |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
7 #define SIDLIB_H 1 |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
8 |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
9 #include "th_util.h" |
85
4c0ecb078591
Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents:
74
diff
changeset
|
10 #include "th_ioctx.h" |
70
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
11 #include "th_crypto.h" |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
12 |
85
4c0ecb078591
Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents:
74
diff
changeset
|
13 |
72 | 14 #ifdef __cplusplus |
15 extern "C" { | |
16 #endif | |
17 | |
70
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
18 |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
19 // Some constants |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
20 #define PSID_MAGIC_LEN 4 |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
21 #define PSID_STR_LEN 32 |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
22 #define PSID_BUFFER_SIZE (1024 * 16) |
86
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
23 |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
24 |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
25 typedef struct _SIDLibSLDBNode |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
26 { |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
27 th_md5hash_t hash; // MD5 hash-digest |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
28 int nlengths; // Number of lengths |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
29 int *lengths; // Lengths in seconds |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
30 struct _SIDLibSLDBNode *prev, *next; |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
31 } SIDLibSLDBNode; |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
32 |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
33 |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
34 typedef struct |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
35 { |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
36 SIDLibSLDBNode *nodes, |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
37 **pindex; |
100 | 38 size_t nnodes; |
86
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
39 } SIDLibSLDB; |
70
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
40 |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
41 |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
42 typedef struct |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
43 { |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
44 char magic[PSID_MAGIC_LEN + 1]; // "PSID" / "RSID" magic identifier |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
45 uint16_t |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
46 version, // Version number |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
47 dataOffset, // Start of actual c64 data in file |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
48 loadAddress, // Loading address |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
49 initAddress, // Initialization address |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
50 playAddress, // Play one frame |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
51 nSongs, // Number of subsongs |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
52 startSong; // Default starting song |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
53 uint32_t speed; // Speed |
128
2636185649c6
Add si_fread_str() helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
54 char *sidName; // Descriptive text-fields, ASCIIZ |
2636185649c6
Add si_fread_str() helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
55 char *sidAuthor; |
2636185649c6
Add si_fread_str() helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
56 char *sidCopyright; |
70
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
57 |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
58 // PSIDv2 data |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
59 uint16_t flags; // Flags |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
60 uint8_t startPage, pageLength; |
133
9cfa0553e7f9
Add support for reading PSID/RSID v4 in sidlib.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
61 uint8_t sid2Addr, sid3Addr; |
70
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
62 |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
63 // Extra data |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
64 BOOL isRSID; |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
65 size_t dataSize; // Total size of data - header |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
66 th_md5hash_t hash; // Songlength database hash |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
67 |
88
c5ff71d64e53
More work on sidlib SLDB code.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
68 SIDLibSLDBNode *lengths; // Songlength information node pointer |
c5ff71d64e53
More work on sidlib SLDB code.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
69 |
70
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
70 } PSIDHeader; |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
71 |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
72 |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
73 enum |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
74 { |
132
b3e034b8c4b9
Change how certain flags (for SID model and clock) are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
131
diff
changeset
|
75 PSF_PLAYER_TYPE = 0x01, // 0 = built-in, 1 = Compute! SIDPlayer MUS |
b3e034b8c4b9
Change how certain flags (for SID model and clock) are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
131
diff
changeset
|
76 PSF_PLAYSID_TUNE = 0x02, // 0 = Real C64-compatible, 1 = PlaySID specific (v2NG) |
70
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
77 |
132
b3e034b8c4b9
Change how certain flags (for SID model and clock) are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
131
diff
changeset
|
78 PSF_CLOCK_UNKNOWN = 0x00, // Video standard used (v2NG+) |
b3e034b8c4b9
Change how certain flags (for SID model and clock) are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
131
diff
changeset
|
79 PSF_CLOCK_PAL = 0x01, |
b3e034b8c4b9
Change how certain flags (for SID model and clock) are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
131
diff
changeset
|
80 PSF_CLOCK_NTSC = 0x02, |
b3e034b8c4b9
Change how certain flags (for SID model and clock) are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
131
diff
changeset
|
81 PSF_CLOCK_ANY = 0x03, |
b3e034b8c4b9
Change how certain flags (for SID model and clock) are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
131
diff
changeset
|
82 PSF_CLOCK_MASK = 0x03, |
70
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
83 |
132
b3e034b8c4b9
Change how certain flags (for SID model and clock) are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
131
diff
changeset
|
84 PSF_MODEL_UNKNOWN = 0x00, // SID model (v2NG+) |
b3e034b8c4b9
Change how certain flags (for SID model and clock) are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
131
diff
changeset
|
85 PSF_MODEL_MOS6581 = 0x01, |
b3e034b8c4b9
Change how certain flags (for SID model and clock) are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
131
diff
changeset
|
86 PSF_MODEL_MOS8580 = 0x02, |
b3e034b8c4b9
Change how certain flags (for SID model and clock) are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
131
diff
changeset
|
87 PSF_MODEL_ANY = 0x03, |
b3e034b8c4b9
Change how certain flags (for SID model and clock) are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
131
diff
changeset
|
88 PSF_MODEL_MASK = 0x03, |
70
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
89 }; |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
90 |
74 | 91 |
92 // | |
93 // Functions | |
94 // | |
126
c1462b7880e8
Make si_read_sid_file() to allocate the PSIDHeader struct itself, adjust
Matti Hamalainen <ccr@tnsp.org>
parents:
101
diff
changeset
|
95 int si_read_sid_file(th_ioctx *ctx, PSIDHeader **ppsid); |
c1462b7880e8
Make si_read_sid_file() to allocate the PSIDHeader struct itself, adjust
Matti Hamalainen <ccr@tnsp.org>
parents:
101
diff
changeset
|
96 void si_free_sid_file(PSIDHeader *psid); |
74 | 97 |
85
4c0ecb078591
Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents:
74
diff
changeset
|
98 const char * si_get_sid_clock_str(const int flags); |
4c0ecb078591
Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents:
74
diff
changeset
|
99 const char * si_get_sid_model_str(const int flags); |
70
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
100 |
88
c5ff71d64e53
More work on sidlib SLDB code.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
101 SIDLibSLDB * si_sldb_new(void); |
86
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
102 int si_sldb_read(th_ioctx *ctx, SIDLibSLDB *dbh); |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
103 int si_sldb_build_index(SIDLibSLDB *dbh); |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
104 void si_sldb_free(SIDLibSLDB *dbh); |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
105 SIDLibSLDBNode *si_sldb_get_by_hash(SIDLibSLDB *dbh, th_md5hash_t hash); |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
106 |
101
9d4d1783800b
Add si_sldb_{read,write}_bin() functions to write and read a binary format
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
107 int si_sldb_read_bin(th_ioctx *ctx, SIDLibSLDB *dbh); |
9d4d1783800b
Add si_sldb_{read,write}_bin() functions to write and read a binary format
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
108 int si_sldb_write_bin(th_ioctx *ctx, SIDLibSLDB *dbh); |
9d4d1783800b
Add si_sldb_{read,write}_bin() functions to write and read a binary format
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
109 |
70
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
110 |
72 | 111 #ifdef __cplusplus |
112 } | |
113 #endif | |
70
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
114 #endif // SIDLIB_H |