[Lapetus-cvs] lapetus cd.c,1.2,1.3 cd.h,1.2,1.3
Status: Inactive
Brought to you by:
cyberwarriorx
From: Theo B. <cyb...@us...> - 2008-01-09 05:04:28
|
Update of /cvsroot/lapetus/lapetus In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv5652 Modified Files: cd.c cd.h Log Message: -Moved sound functions and other fixes Index: cd.c =================================================================== RCS file: /cvsroot/lapetus/lapetus/cd.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- cd.c 3 Mar 2007 03:53:44 -0000 1.2 +++ cd.c 9 Jan 2008 05:04:21 -0000 1.3 @@ -436,6 +436,50 @@ ////////////////////////////////////////////////////////////////////////////// +int CDTransferDataBytes(u32 numbytes, u32 *buffer) +{ + u32 i; + int ret; + int numsectors=numbytes / sectorsizetbl[cdsectorsize]; + + if (numbytes % sectorsizetbl[cdsectorsize]) + numsectors++; + + // Setup a transfer from cd buffer to wram, then delete data + // from cd buffer + if ((ret = CDGetThenDeleteSectorData(0, 0, numsectors)) != 0) + return ret; + + // wait a bit + for (i = 0; i < 20000; i++) {} + + // Do transfer + for (i = 0; i < (numbytes >> 2); i++) + { + buffer[0] = CDB_REG_DATATRNS; // this can also be done in word units as well + buffer++; + } + + // Get the remainder + if (numbytes % 4) + { + u32 data; + u8 *datapointer=&data; + + data = CDB_REG_DATATRNS; + + for (i = 0; i < (numbytes % 4); i++) + ((u8 *)buffer)[i] = datapointer[i]; + } + + if ((ret = CDEndTransfer()) != 0) + return ret; + + return LAPETUS_ERR_OK; +} + +////////////////////////////////////////////////////////////////////////////// + int CDInit() { int ret; @@ -648,11 +692,15 @@ ////////////////////////////////////////////////////////////////////////////// -int CDReadSector(void *buffer, u32 FAD, int sectorsize, u32 numsectors) +int CDReadSector(void *buffer, u32 FAD, int sectorsize, u32 numbytes) { int ret; int done=0; - u32 sectorsread=0; + // Figure out how many sectors we actually have to read + int numsectors=numbytes / sectorsizetbl[cdsectorsize]; + + if (numbytes % sectorsizetbl[cdsectorsize] != 0) + numsectors++; if ((ret = CDSetSectorSize(sectorsize)) != 0) return ret; @@ -679,19 +727,25 @@ while (!done) { u32 sectorstoread=0; + u32 bytestoread; // Wait until there's data ready while ((sectorstoread = CDIsDataReady(0)) == 0) {} + if ((sectorstoread * sectorsizetbl[cdsectorsize]) > numbytes) + bytestoread = numbytes; + else + bytestoread = sectorstoread * sectorsizetbl[cdsectorsize]; + // Setup a transfer from cd buffer to wram, then delete data // from cd buffer - if ((ret = CDTransferData(sectorstoread, buffer)) != 0) + if ((ret = CDTransferDataBytes(bytestoread, buffer)) != 0) return ret; - sectorsread += sectorstoread; - buffer += sectorsizetbl[cdsectorsize]; + numbytes -= bytestoread; + buffer += bytestoread; - if (sectorsread >= numsectors) + if (numbytes == 0) done = 1; } @@ -700,56 +754,6 @@ ////////////////////////////////////////////////////////////////////////////// -// This could probably be moved to sound.c -void SoundExternalAudioEnable(u8 vol_l, u8 vol_r) -{ - volatile u16 *slot_ptr; - - vol_l &= 0x7; - vol_r &= 0x7; - - // Setup SCSP Slot 16 and Slot 17 for playing - slot_ptr = (volatile u16 *)(0x25B00000 + (0x20 * 16)); - slot_ptr[0] = 0x1000; - slot_ptr[1] = 0x0000; - slot_ptr[2] = 0x0000; - slot_ptr[3] = 0x0000; - slot_ptr[4] = 0x0000; - slot_ptr[5] = 0x0000; - slot_ptr[6] = 0x00FF; - slot_ptr[7] = 0x0000; - slot_ptr[8] = 0x0000; - slot_ptr[9] = 0x0000; - slot_ptr[10] = 0x0000; - slot_ptr[11] = 0x001F | (vol_l << 5); - slot_ptr[12] = 0x0000; - slot_ptr[13] = 0x0000; - slot_ptr[14] = 0x0000; - slot_ptr[15] = 0x0000; - - slot_ptr = (volatile u16 *)(0x25B00000 + (0x20 * 17)); - slot_ptr[0] = 0x1000; - slot_ptr[1] = 0x0000; - slot_ptr[2] = 0x0000; - slot_ptr[3] = 0x0000; - slot_ptr[4] = 0x0000; - slot_ptr[5] = 0x0000; - slot_ptr[6] = 0x00FF; - slot_ptr[7] = 0x0000; - slot_ptr[8] = 0x0000; - slot_ptr[9] = 0x0000; - slot_ptr[10] = 0x0000; - slot_ptr[11] = 0x000F | (vol_r << 5); - slot_ptr[12] = 0x0000; - slot_ptr[13] = 0x0000; - slot_ptr[14] = 0x0000; - slot_ptr[15] = 0x0000; - - *((volatile u16 *)(0x25B00400)) = 0x020F; -} - -////////////////////////////////////////////////////////////////////////////// - int PlayCDAudio(u8 audiotrack, u8 repeat, u8 vol_l, u8 vol_r) { cdcmd_struct cdcmd; Index: cd.h =================================================================== RCS file: /cvsroot/lapetus/lapetus/cd.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- cd.h 3 Mar 2007 03:54:13 -0000 1.2 +++ cd.h 9 Jan 2008 05:04:21 -0000 1.3 @@ -94,7 +94,7 @@ int CDStopDrive(); int CDStartDrive(); int IsCDPresent(); -int CDReadSector(void *buffer, u32 FAD, int sectorsize, u32 numsectors); +int CDReadSector(void *buffer, u32 FAD, int sectorsize, u32 numbytes); int PlayCDAudio(u8 audiotrack, u8 repeat, u8 vol_l, u8 vol_r); int StopCDAudio(void); #endif |