blob: 817cff6c2bd6af999bbc3bb52b398c4ebc38f2cd (
plain)
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
|
#ifdef CRSID_PLATFORM_PC
int cRSID_loadSIDfile (unsigned char* SIDfileData, char* filename, int maxlen) {
static signed short Data;
static signed int SizeCnt;
static FILE *SIDfile;
if ( (SIDfile=fopen(filename,"rb")) == NULL ) return CRSID_ERROR_LOAD;
SizeCnt=0;
while ( (Data=fgetc(SIDfile)) != EOF ) {
if (SizeCnt >= maxlen) return CRSID_ERROR_LOAD;
SIDfileData[SizeCnt] = Data; SizeCnt++;
}
fclose(SIDfile);
return SizeCnt;
}
#endif
cRSID_SIDheader* cRSID_processSIDfile(cRSID_C64instance* C64, unsigned char* filedata, int filesize) {
int i;
unsigned short SIDdataOffset;
cRSID_SIDheader* SIDheader;
static const char MagicStringPSID[]="PSID";
//static const char MagicStringRSID[]="RSID";
C64->SIDheader = SIDheader = (cRSID_SIDheader*) filedata;
for (i=0x0000; i < 0xA000; ++i) C64->RAMbank[i]=0; //fresh start (maybe some bugged SIDs want 0 at certain RAM-locations)
for (i=0xC000; i < 0xD000; ++i) C64->RAMbank[i]=0;
if ( SIDheader->MagicString[0] != 'P' && SIDheader->MagicString[0] != 'R' ) return NULL;
for (i=1; i < (int)(sizeof(MagicStringPSID)-1); ++i) { if (SIDheader->MagicString[i] != MagicStringPSID[i]) return NULL; }
C64->RealSIDmode = ( SIDheader->MagicString[0] == 'R' );
if (SIDheader->LoadAddressH==0 && SIDheader->LoadAddressL==0) { //load-address taken from first 2 bytes of the C64 PRG
C64->LoadAddress = (filedata[SIDheader->HeaderSize+1]<<8) + (filedata[SIDheader->HeaderSize+0]);
SIDdataOffset = SIDheader->HeaderSize+2;
}
else { //load-adress taken from SID-header
C64->LoadAddress = (SIDheader->LoadAddressH<<8) + (SIDheader->LoadAddressL);
SIDdataOffset = SIDheader->HeaderSize;
}
for (i=SIDdataOffset; i<filesize; ++i) C64->RAMbank [ C64->LoadAddress + (i-SIDdataOffset) ] = filedata[i];
i = C64->LoadAddress + (filesize-SIDdataOffset);
C64->EndAddress = (i<0x10000) ? i : 0xFFFF;
C64->PSIDdigiMode = ( !C64->RealSIDmode && (SIDheader->ModelFormatStandard & 2) );
return C64->SIDheader;
}
|