You call "CdRead2Addr" as that is your primary function.
IE: int main() { CdRead2Addr(arguments go here); return 0; }
Code: Select all
/*=========================================================
Sony PlayStation 1 Source Code
===========================================================
CD-ROM RAM Copy Routines
-----------------------------------------------------------
Developers / Programmer.............: Shadow
Software Development Kit............: Psy-Q 4.6
First Release (as v1.0).............: 10/MAY/2016
Current Version.....................: 1.0
-----------------------------------------------------------*/
// RAM address storage location of the to be loaded TEX1 data
// NOTE: this is at the 1 MB location, but use anything that is available.
u_long TEX1 = 0x80100000L;
// CD-ROM prototypes
CdlFILE* CdRead2Addr(char *fname, void *address);
int _read2(long byte, void *sectbuf, int mode);
// copy the 't_tex.tim' into TEX1
CdRead2Addr("\\TEXTURES\\T_TEX.TIM;1", (u_long *)TEX1);
///////////////////////////////////////////////////////////
// Read a file to a hardcoded address
///////////////////////////////////////////////////////////
CdlFILE* CdRead2Addr(char *fname, void *address)
{
int mode = CdlModeSpeed;
int cnt, i;
for (i=0; i<10; i++) // retry ten times
{
if (CdSearchFile(&fp, fname) == 0) continue;
// set target position
CdControl(CdlSetloc, (u_char *)&(fp.pos), 0);
cnt = _read2(fp.size, address, mode); // read
if(cnt==0) return(&fp); // success
}
printf("\nCan not read the file: %s", fname);
return 0; // fail
}
int _read2(long byte, void *sectbuf, int mode)
{
int nsector,cnt;
nsector=(byte+2047)/2048;
// read start
CdRead(nsector, sectbuf, mode);
while((cnt=CdReadSync(1,NULL))>0) VSync(0);
return cnt;
}