2008-12-11 18:38:29 +01:00
|
|
|
/*
|
|
|
|
* dvd.c
|
|
|
|
*
|
2009-05-13 16:26:55 +02:00
|
|
|
* Low-level DVD access
|
2008-08-07 14:26:07 +02:00
|
|
|
*
|
2009-05-13 16:26:55 +02:00
|
|
|
* Softdev (2006)
|
|
|
|
* Eke-Eke (2007,2008,2009)
|
2008-08-07 14:26:07 +02:00
|
|
|
*
|
2009-05-13 16:26:55 +02:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
2008-12-11 18:38:29 +01:00
|
|
|
*
|
2009-05-13 16:26:55 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2008-12-11 18:38:29 +01:00
|
|
|
*
|
2009-05-13 16:26:55 +02:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2008-12-11 18:38:29 +01:00
|
|
|
*
|
|
|
|
********************************************************************************/
|
|
|
|
|
2008-08-07 14:26:07 +02:00
|
|
|
#include "shared.h"
|
2009-05-19 18:14:43 +02:00
|
|
|
#include "gui.h"
|
2008-12-10 19:16:30 +01:00
|
|
|
|
2008-08-19 19:15:08 +02:00
|
|
|
#ifndef HW_RVL
|
2008-12-10 19:16:30 +01:00
|
|
|
static u64 DvdMaxOffset = 0x57057C00; /* 1.4 GB max. by default */
|
2008-08-20 22:25:17 +02:00
|
|
|
static vu32* const dvd = (u32*)0xCC006000; /* DVD I/O Address base */
|
|
|
|
static u8 *inquiry=(unsigned char *)0x80000004; /* pointer to drive ID */
|
2008-08-07 14:26:07 +02:00
|
|
|
#else
|
2008-08-20 22:25:17 +02:00
|
|
|
static u64 DvdMaxOffset = 0x118244F00LL; /* 4.7 GB max. */
|
2008-08-07 14:26:07 +02:00
|
|
|
#endif
|
|
|
|
|
2008-08-20 22:25:17 +02:00
|
|
|
static u8 DVDreadbuffer[2048] ATTRIBUTE_ALIGN (32); /* data buffer for all DVD operations */
|
|
|
|
|
2008-08-19 19:15:08 +02:00
|
|
|
|
2008-08-07 14:26:07 +02:00
|
|
|
/***************************************************************************
|
|
|
|
* dvd_read
|
|
|
|
*
|
|
|
|
* Read DVD disc sectors
|
|
|
|
***************************************************************************/
|
2008-08-19 19:15:08 +02:00
|
|
|
u32 dvd_read (void *dst, u32 len, u64 offset)
|
2008-08-07 14:26:07 +02:00
|
|
|
{
|
2008-08-11 20:02:04 +02:00
|
|
|
/*** We only allow 2k reads **/
|
|
|
|
if (len > 2048) return 0;
|
2008-08-07 14:26:07 +02:00
|
|
|
|
2008-08-11 20:02:04 +02:00
|
|
|
/*** Let's not read past end of DVD ***/
|
2008-08-07 14:26:07 +02:00
|
|
|
if(offset < DvdMaxOffset)
|
|
|
|
{
|
2008-08-11 20:02:04 +02:00
|
|
|
unsigned char *buffer = (unsigned char *) (unsigned int) DVDreadbuffer;
|
|
|
|
DCInvalidateRange((void *)buffer, len);
|
2008-08-19 19:15:08 +02:00
|
|
|
|
|
|
|
#ifndef HW_RVL
|
2008-08-17 22:17:49 +02:00
|
|
|
dvd[0] = 0x2E;
|
2008-08-11 20:02:04 +02:00
|
|
|
dvd[1] = 0;
|
|
|
|
dvd[2] = 0xA8000000;
|
|
|
|
dvd[3] = (u32)(offset >> 2);
|
|
|
|
dvd[4] = len;
|
|
|
|
dvd[5] = (u32) buffer;
|
|
|
|
dvd[6] = len;
|
2008-08-17 22:17:49 +02:00
|
|
|
dvd[7] = 3;
|
2008-08-11 20:02:04 +02:00
|
|
|
|
|
|
|
/*** Enable reading with DMA ***/
|
2009-05-23 19:29:53 +02:00
|
|
|
while (dvd[7] & 1) usleep(10);
|
2009-04-13 19:29:09 +02:00
|
|
|
memcpy (dst, buffer, len);
|
2008-08-11 20:02:04 +02:00
|
|
|
|
|
|
|
/*** Ensure it has completed ***/
|
|
|
|
if (dvd[0] & 0x4) return 0;
|
|
|
|
|
2008-08-19 19:15:08 +02:00
|
|
|
#else
|
2008-08-20 22:25:17 +02:00
|
|
|
if (DI_ReadDVD(buffer, len >> 11, (u32)(offset >> 11))) return 0;
|
2008-08-19 19:15:08 +02:00
|
|
|
memcpy (dst, buffer, len);
|
2009-04-13 19:29:09 +02:00
|
|
|
#endif
|
2008-08-19 19:15:08 +02:00
|
|
|
return 1;
|
2008-08-11 20:02:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* dvd_motor_off
|
|
|
|
*
|
|
|
|
* Stop the DVD Motor
|
|
|
|
*
|
|
|
|
* This can be used to prevent the Disc from spinning during playtime
|
|
|
|
****************************************************************************/
|
|
|
|
void dvd_motor_off( )
|
|
|
|
{
|
2009-05-23 19:29:53 +02:00
|
|
|
GUI_MsgBoxOpen("Information", "Stopping DVD drive ...", 1);
|
2008-12-14 19:23:07 +01:00
|
|
|
|
2008-08-19 19:15:08 +02:00
|
|
|
#ifndef HW_RVL
|
2008-12-10 19:16:30 +01:00
|
|
|
dvd[0] = 0x2e;
|
|
|
|
dvd[1] = 0;
|
|
|
|
dvd[2] = 0xe3000000;
|
|
|
|
dvd[3] = 0;
|
|
|
|
dvd[4] = 0;
|
|
|
|
dvd[5] = 0;
|
|
|
|
dvd[6] = 0;
|
|
|
|
dvd[7] = 1; // Do immediate
|
2009-05-23 19:29:53 +02:00
|
|
|
while (dvd[7] & 1) usleep(10);
|
2008-12-10 19:16:30 +01:00
|
|
|
|
|
|
|
/*** PSO Stops blackscreen at reload ***/
|
|
|
|
dvd[0] = 0x14;
|
|
|
|
dvd[1] = 0;
|
2008-08-19 19:15:08 +02:00
|
|
|
|
|
|
|
#else
|
|
|
|
DI_StopMotor();
|
2008-08-07 14:26:07 +02:00
|
|
|
#endif
|
2009-05-20 17:11:06 +02:00
|
|
|
|
2009-05-19 18:14:43 +02:00
|
|
|
GUI_MsgBoxClose();
|
2008-08-19 19:15:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef HW_RVL
|
|
|
|
/****************************************************************************
|
|
|
|
* uselessinquiry
|
|
|
|
*
|
|
|
|
* As the name suggests, this function is quite useless.
|
|
|
|
* It's only purpose is to stop any pending DVD interrupts while we use the
|
|
|
|
* memcard interface.
|
|
|
|
*
|
|
|
|
* libOGC tends to foul up if you don't, and sometimes does if you do!
|
|
|
|
****************************************************************************/
|
|
|
|
void uselessinquiry ()
|
|
|
|
{
|
|
|
|
dvd[0] = 0;
|
|
|
|
dvd[1] = 0;
|
|
|
|
dvd[2] = 0x12000000;
|
|
|
|
dvd[3] = 0;
|
|
|
|
dvd[4] = 0x20;
|
|
|
|
dvd[5] = 0x80000000;
|
|
|
|
dvd[6] = 0x20;
|
|
|
|
dvd[7] = 1;
|
|
|
|
|
2009-05-23 19:29:53 +02:00
|
|
|
while (dvd[7] & 1) usleep(10);
|
2008-08-19 19:15:08 +02:00
|
|
|
}
|
2008-08-07 14:26:07 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* dvd_drive_detect()
|
|
|
|
*
|
|
|
|
* Detect the DVD Drive Type
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
void dvd_drive_detect()
|
|
|
|
{
|
2008-08-17 22:17:49 +02:00
|
|
|
dvd[0] = 0x2e;
|
2008-08-07 14:26:07 +02:00
|
|
|
dvd[1] = 0;
|
|
|
|
dvd[2] = 0x12000000;
|
|
|
|
dvd[3] = 0;
|
|
|
|
dvd[4] = 0x20;
|
|
|
|
dvd[5] = 0x80000000;
|
|
|
|
dvd[6] = 0x20;
|
|
|
|
dvd[7] = 3;
|
2009-05-23 19:29:53 +02:00
|
|
|
while( dvd[7] & 1 ) usleep(10);
|
2008-08-17 22:17:49 +02:00
|
|
|
DCFlushRange((void *)0x80000000, 32);
|
2008-08-07 14:26:07 +02:00
|
|
|
|
2008-08-17 22:17:49 +02:00
|
|
|
int driveid = (int)inquiry[2];
|
2008-08-07 14:26:07 +02:00
|
|
|
|
|
|
|
if ((driveid == 4) || (driveid == 6) || (driveid == 8))
|
|
|
|
{
|
|
|
|
/* Gamecube DVD Drive (1.4 GB)*/
|
|
|
|
DvdMaxOffset = 0x57057C00;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Wii DVD Drive (4.7GB) */
|
|
|
|
DvdMaxOffset = 0x118244F00LL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|