forked from gianlucag/SidBerry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SidFile.h
executable file
·79 lines (68 loc) · 1.99 KB
/
SidFile.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//============================================================================
// Description : SID file parser
// Author : Gianluca Ghettini
//============================================================================
#include <iostream>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
using namespace std;
#define PSID_MIN_HEADER_LENGTH 118 // Version 1
#define PSID_MAX_HEADER_LENGTH 124 // Version 2
// Offsets of fields in header (all fields big-endian)
enum {
SIDFILE_PSID_ID = 0, // 'PSID'
SIDFILE_PSID_VERSION = 4, // 1 or 2
SIDFILE_PSID_LENGTH = 6, // Header length
SIDFILE_PSID_START = 8, // C64 load address
SIDFILE_PSID_INIT = 10, // C64 init routine address
SIDFILE_PSID_MAIN = 12, // C64 replay routine address
SIDFILE_PSID_NUMBER = 14, // Number of subsongs
SIDFILE_PSID_DEFSONG = 16, // Main subsong number
SIDFILE_PSID_SPEED = 18, // Speed flags (1 bit/song)
SIDFILE_PSID_NAME = 22, // Module name (ISO Latin1 character set)
SIDFILE_PSID_AUTHOR = 54, // Author name (dto.)
SIDFILE_PSID_COPYRIGHT = 86, // Copyright info (dto.)
SIDFILE_PSID_FLAGS = 118, // Flags (only in version 2 header)
SIDFILE_PSID_RESERVED = 120
};
enum {
SIDFILE_OK,
SIDFILE_ERROR_FILENOTFOUND,
SIDFILE_ERROR_MALFORMED
};
enum {
SIDFILE_SPEED_50HZ,
SIDFILE_SPEED_60HZ
};
class SidFile
{
private:
string moduleName;
string authorName;
string copyrightInfo;
int numOfSongs;
int firstSong;
uint16_t initAddr;
uint16_t playAddr;
uint64_t loadAddr;
uint32_t speedFlags;
uint8_t dataBuffer[0x10000];
uint16_t dataLength;
uint16_t Read16(const uint8_t *p, int offset);
uint32_t Read32(const uint8_t *p, int offset);
bool IsPSIDHeader(const uint8_t *p);
public:
SidFile();
int Parse(string file);
string GetModuleName();
string GetAuthorName();
string GetCopyrightInfo();
int GetSongSpeed(int songNum);
int GetNumOfSongs();
uint8_t *GetDataPtr();
uint16_t GetDataLength();
uint16_t GetLoadAddress();
uint16_t GetInitAddress();
uint16_t GetPlayAddress();
};