annotate sidlib.h @ 223:a76276ff7ba8

Rename PSID_* constant defines to SIDLIB_PSID_*.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 27 Dec 2019 12:15:51 +0200
parents 3a01518fffe0
children 4bec78f45188
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
171
d86ade7d0dfd Change copyright blurbs slightly.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
3 * Programmed and designed by Matti 'ccr' Hämäläinen <ccr@tnsp.org>
214
98563979859b Bump copyright years.
Matti Hamalainen <ccr@tnsp.org>
parents: 171
diff changeset
4 * (C) Copyright 2014-2019 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
d5a34a3a602d Add C++ include guards.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
14 #ifdef __cplusplus
d5a34a3a602d Add C++ include guards.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
15 extern "C" {
d5a34a3a602d Add C++ include guards.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
16 #endif
d5a34a3a602d Add C++ include guards.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
17
70
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18
220
e79a93971d27 Cosmetic reorganization.
Matti Hamalainen <ccr@tnsp.org>
parents: 214
diff changeset
19 //
70
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 // Some constants
220
e79a93971d27 Cosmetic reorganization.
Matti Hamalainen <ccr@tnsp.org>
parents: 214
diff changeset
21 //
223
a76276ff7ba8 Rename PSID_* constant defines to SIDLIB_PSID_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 222
diff changeset
22 #define SIDLIB_PSID_MAGIC_LEN 4
a76276ff7ba8 Rename PSID_* constant defines to SIDLIB_PSID_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 222
diff changeset
23 #define SIDLIB_PSID_STR_LEN 32
a76276ff7ba8 Rename PSID_* constant defines to SIDLIB_PSID_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 222
diff changeset
24 #define SIDLIB_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
25
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
26
220
e79a93971d27 Cosmetic reorganization.
Matti Hamalainen <ccr@tnsp.org>
parents: 214
diff changeset
27 enum
e79a93971d27 Cosmetic reorganization.
Matti Hamalainen <ccr@tnsp.org>
parents: 214
diff changeset
28 {
e79a93971d27 Cosmetic reorganization.
Matti Hamalainen <ccr@tnsp.org>
parents: 214
diff changeset
29 // Player flags
e79a93971d27 Cosmetic reorganization.
Matti Hamalainen <ccr@tnsp.org>
parents: 214
diff changeset
30 PSF_PLAYER_TYPE = 0x01, // 0 = built-in, 1 = Compute! SIDPlayer MUS
e79a93971d27 Cosmetic reorganization.
Matti Hamalainen <ccr@tnsp.org>
parents: 214
diff changeset
31 PSF_PLAYSID_TUNE = 0x02, // 0 = Real C64-compatible, 1 = PlaySID specific (v2NG)
e79a93971d27 Cosmetic reorganization.
Matti Hamalainen <ccr@tnsp.org>
parents: 214
diff changeset
32
e79a93971d27 Cosmetic reorganization.
Matti Hamalainen <ccr@tnsp.org>
parents: 214
diff changeset
33 // Video standard used (v2NG+)
e79a93971d27 Cosmetic reorganization.
Matti Hamalainen <ccr@tnsp.org>
parents: 214
diff changeset
34 PSF_CLOCK_UNKNOWN = 0x00,
e79a93971d27 Cosmetic reorganization.
Matti Hamalainen <ccr@tnsp.org>
parents: 214
diff changeset
35 PSF_CLOCK_PAL = 0x01,
e79a93971d27 Cosmetic reorganization.
Matti Hamalainen <ccr@tnsp.org>
parents: 214
diff changeset
36 PSF_CLOCK_NTSC = 0x02,
e79a93971d27 Cosmetic reorganization.
Matti Hamalainen <ccr@tnsp.org>
parents: 214
diff changeset
37 PSF_CLOCK_ANY = 0x03,
e79a93971d27 Cosmetic reorganization.
Matti Hamalainen <ccr@tnsp.org>
parents: 214
diff changeset
38 PSF_CLOCK_MASK = 0x03,
e79a93971d27 Cosmetic reorganization.
Matti Hamalainen <ccr@tnsp.org>
parents: 214
diff changeset
39
e79a93971d27 Cosmetic reorganization.
Matti Hamalainen <ccr@tnsp.org>
parents: 214
diff changeset
40 // SID model (v2NG+)
e79a93971d27 Cosmetic reorganization.
Matti Hamalainen <ccr@tnsp.org>
parents: 214
diff changeset
41 PSF_MODEL_UNKNOWN = 0x00,
e79a93971d27 Cosmetic reorganization.
Matti Hamalainen <ccr@tnsp.org>
parents: 214
diff changeset
42 PSF_MODEL_MOS6581 = 0x01,
e79a93971d27 Cosmetic reorganization.
Matti Hamalainen <ccr@tnsp.org>
parents: 214
diff changeset
43 PSF_MODEL_MOS8580 = 0x02,
e79a93971d27 Cosmetic reorganization.
Matti Hamalainen <ccr@tnsp.org>
parents: 214
diff changeset
44 PSF_MODEL_ANY = 0x03,
e79a93971d27 Cosmetic reorganization.
Matti Hamalainen <ccr@tnsp.org>
parents: 214
diff changeset
45 PSF_MODEL_MASK = 0x03,
e79a93971d27 Cosmetic reorganization.
Matti Hamalainen <ccr@tnsp.org>
parents: 214
diff changeset
46 };
e79a93971d27 Cosmetic reorganization.
Matti Hamalainen <ccr@tnsp.org>
parents: 214
diff changeset
47
e79a93971d27 Cosmetic reorganization.
Matti Hamalainen <ccr@tnsp.org>
parents: 214
diff changeset
48
e79a93971d27 Cosmetic reorganization.
Matti Hamalainen <ccr@tnsp.org>
parents: 214
diff changeset
49 //
e79a93971d27 Cosmetic reorganization.
Matti Hamalainen <ccr@tnsp.org>
parents: 214
diff changeset
50 // Structures
e79a93971d27 Cosmetic reorganization.
Matti Hamalainen <ccr@tnsp.org>
parents: 214
diff changeset
51 //
86
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
52 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
53 {
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
54 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
55 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
56 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
57 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
58 } SIDLibSLDBNode;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
59
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
60
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
61 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
62 {
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
63 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
64 **pindex;
100
be62e4abe3a9 Rename a structure member.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
65 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
66 } SIDLibSLDB;
70
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69 typedef struct
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 {
223
a76276ff7ba8 Rename PSID_* constant defines to SIDLIB_PSID_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 222
diff changeset
71 char magic[SIDLIB_PSID_MAGIC_LEN + 1]; // "PSID" / "RSID" magic identifier
70
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72 uint16_t
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 version, // Version number
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 dataOffset, // Start of actual c64 data in file
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75 loadAddress, // Loading address
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 initAddress, // Initialization address
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 playAddress, // Play one frame
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 nSongs, // Number of subsongs
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 startSong; // Default starting song
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 uint32_t speed; // Speed
128
2636185649c6 Add si_fread_str() helper function.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
81 char *sidName; // Descriptive text-fields, ASCIIZ
2636185649c6 Add si_fread_str() helper function.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
82 char *sidAuthor;
2636185649c6 Add si_fread_str() helper function.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
83 char *sidCopyright;
70
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84
144
6418286a7e4c Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
85 // PSIDv2+ data
70
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 uint16_t flags; // Flags
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 uint8_t startPage, pageLength;
133
9cfa0553e7f9 Add support for reading PSID/RSID v4 in sidlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
88 uint8_t sid2Addr, sid3Addr;
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 // Extra data
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91 BOOL isRSID;
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 size_t dataSize; // Total size of data - header
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 th_md5hash_t hash; // Songlength database hash
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94
88
c5ff71d64e53 More work on sidlib SLDB code.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
95 SIDLibSLDBNode *lengths; // Songlength information node pointer
c5ff71d64e53 More work on sidlib SLDB code.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
96
70
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 } PSIDHeader;
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99
74
5d61d8dbc77f Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
100 //
5d61d8dbc77f Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
101 // Functions
5d61d8dbc77f Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
102 //
222
3a01518fffe0 Rename sidlib functions from si_* prefix to sidlib_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 221
diff changeset
103 BOOL sidlib_read_sid_file(th_ioctx *ctx, PSIDHeader **ppsid, const BOOL newSLDB);
3a01518fffe0 Rename sidlib functions from si_* prefix to sidlib_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 221
diff changeset
104 void sidlib_free_sid_file(PSIDHeader *psid);
74
5d61d8dbc77f Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
105
222
3a01518fffe0 Rename sidlib functions from si_* prefix to sidlib_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 221
diff changeset
106 const char * sidlib_get_sid_clock_str(const int flags);
3a01518fffe0 Rename sidlib functions from si_* prefix to sidlib_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 221
diff changeset
107 const char * sidlib_get_sid_model_str(const int flags);
70
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108
222
3a01518fffe0 Rename sidlib functions from si_* prefix to sidlib_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 221
diff changeset
109 SIDLibSLDB * sidlib_sldb_new(void);
3a01518fffe0 Rename sidlib functions from si_* prefix to sidlib_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 221
diff changeset
110 int sidlib_sldb_read(th_ioctx *ctx, SIDLibSLDB *dbh);
3a01518fffe0 Rename sidlib functions from si_* prefix to sidlib_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 221
diff changeset
111 int sidlib_sldb_build_index(SIDLibSLDB *dbh);
3a01518fffe0 Rename sidlib functions from si_* prefix to sidlib_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 221
diff changeset
112 void sidlib_sldb_free(SIDLibSLDB *dbh);
3a01518fffe0 Rename sidlib functions from si_* prefix to sidlib_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 221
diff changeset
113 SIDLibSLDBNode * sidlib_sldb_get_by_hash(SIDLibSLDB *dbh, th_md5hash_t hash);
86
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
114
222
3a01518fffe0 Rename sidlib functions from si_* prefix to sidlib_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 221
diff changeset
115 int sidlib_sldb_read_bin(th_ioctx *ctx, SIDLibSLDB *dbh);
3a01518fffe0 Rename sidlib functions from si_* prefix to sidlib_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 221
diff changeset
116 int sidlib_sldb_write_bin(th_ioctx *ctx, const SIDLibSLDB *dbh);
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
117
70
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118
72
d5a34a3a602d Add C++ include guards.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
119 #ifdef __cplusplus
d5a34a3a602d Add C++ include guards.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
120 }
d5a34a3a602d Add C++ include guards.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
121 #endif
70
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 #endif // SIDLIB_H