#define FORM1_SIZE 2048 /* Size of an XA mode 1 form 1 sector. */ /* This macro gives the number of sectors a file of length x bytes takes up. */ #define Sectors(x) ((x+FORM1_SIZE-1)/FORM1_SIZE) /* ------------------------------------------------------------------------ */ unsigned long* LoadFile(char *name, unsigned long* size) /* Loadfile() loads the file specified by 'name' (full path) from CD into */ /* memory pointed to by 'buffer'. It is the responsibility of the caller to */ /* make sure that 'buffer' is large enough to hold the data loaded. The */ /* function loads a whole number of sectors from CD (ie chunks of 2k) so */ /* be careful about the size of the thing you're loading and the size of the */ /* buffer. This function is synchronous (blocking). */ /* The function returns 0 if it can't find the file, or if something goes */ /* wrong with the CD commands (CD doesn't acknowledge, won't seek, won't */ /* start reading, or alternatively the number of bytes in the file (*not* */ /* the number of sectors) if it reads successfully. */ { CdlFILE fp; /* libcd file struct, including the length. */ u_long addr; int numSectors; /* Number of sectors the file takes up. */ int mode = 0; /* The mode word for CdRead. */ if (!CdSearchFile(&fp, name)) /* Find the stream file on CD. */ { printf("Couldn't find %s.\n",name); return 0; /* Return 0 if file not found. */ } *size = fp.size; /* Get the file length too. */ /* Call Cd control (blocking) to seek to the logical file position. */ /* If the CD doesn't acknowledge, return 0 for an error code. */ if (!CdControlB(CdlSeekL,(unsigned char *)&fp.pos, 0)) return 0; /* Work out the number of sectors from the length of the file on CD. */ numSectors = Sectors(*size); /* Make up the CD mode word (just double speed flag). */ mode |= CdlModeSpeed; /* Call CdRead() to read the sectors into the buffer at double speed. */ /* If the CD doesn't respond, then return 0. */ addr = (unsigned long *)AllocMem(*size); if(!CdRead(numSectors,(unsigned long *)addr,mode)) return 0; /* Block until the CD has finished reading (ie make the call block). */ while (CdReadSync(1,0) > 0 ); VSync(3); return (unsigned long *)addr; } /* ------------------------------------------------------------------------ */ u_long AllocMem(u_long size) { /* - Type: PRIVATE * - * - Param: size = (In) No. of bytes to allocate. * - * - Ret: Base of allocated mem. * - * - Usage: Allocate "size" bytes from the heap. */ u_long mem = __heapbase; if ((size & 3) != 0) size = (size + 4) & 0xfffffffc; #ifdef DEBUG if ((__heapbase + size) >= (0x80000000 + _ramsize - _stacksize)) printf("ERROR: MOVIE -- Not enough memory, can't allocate %d bytes!\n", size); else printf("Allocated %d bytes. Free memory = %d bytes.\n", size, (0x80000000 + _ramsize - _stacksize) - (__heapbase + size) ); #endif __heapbase += size; return mem; } /* ------------------------------------------------------------------------ */