/* * Wii DVD interface API * Copyright (C) 2008 Jeff Epler * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include "wdvd.h" #include "common.h" static int di_fd = -1; static s32 di_hid = 0; extern void bwait(void); #define DEBUG #ifdef DEBUG #include #define debug_wait(fmt, args...) \ (fprintf(stderr, "%s:%d:" fmt, __FUNCTION__, __LINE__, ##args), fflush(stderr), bwait()) #define debug_printf(fmt, args...) \ (fprintf(stderr, "%s:%d:" fmt, __FUNCTION__, __LINE__, ##args), fflush(stderr)) #else #define debug_wait(fmt, args...) #define debug_printf(fmt, args...) #endif // DEBUG bool WDVD_Init() { if(di_fd >= 0) return 1; di_fd = IOS_Open("/dev/di", 0); if(di_fd < 0) { debug_printf("IOS_Open(/dev/di) failed with code %d\n", di_fd); return 0; } di_hid = iosCreateHeap(0x10000); if(!di_hid) { IOS_Close(di_fd); di_fd = -1; debug_printf("iosCreateHeap(0x20) failed with code %d\n", di_hid); return 0; } debug_printf("fd=%d hid=%d\n", di_fd, di_hid); return 1; } bool WDVD_LowClosePartition() { char *inbuf = iosAlloc(di_hid, 0x20); if(!inbuf) return false; ((u32*)inbuf)[0x00] = 0x8C000000; int result = IOS_Ioctl( di_fd, 0x8C, inbuf, 0x20, 0, 0); iosFree(di_hid, inbuf); return result; } bool WDVD_Reset() { char *inbuf = iosAlloc(di_hid, 0x20); char *outbuf = iosAlloc(di_hid, 0x20); if(!inbuf || !outbuf) goto out; ((u32*)inbuf)[0x00] = 0x8A000000; ((u32*)inbuf)[0x01] = 1; int result = IOS_Ioctl( di_fd, 0x8A, inbuf, 0x20, outbuf, 0x20); if(outbuf) iosFree(di_hid, outbuf); if(inbuf) iosFree(di_hid, inbuf); return result; out: if(outbuf) iosFree(di_hid, outbuf); if(inbuf) iosFree(di_hid, inbuf); return false; } #define max(a,b) ((a) > (b) ? (a) : (b)) int WDVD_LowUnencryptedRead(void *buf, u32 len, u64 offset) { debug_printf("(%p %x %llx)\n", buf, len, offset); if(offset & 3) { debug_wait("Unaligned read: %llx\n", offset); return -1; } char *inbuf = iosAlloc(di_hid, 0x20); char *outbuf = iosAlloc(di_hid, max(len, 0x20)); int result = 0; debug_printf("%p %p\n", inbuf, outbuf); if(!inbuf || !outbuf) { result = -1; goto out; } ((u32*)inbuf)[0] = 0x8d000000; ((u32*)inbuf)[1] = len; ((u32*)inbuf)[2] = offset >> 2; memset(outbuf, 0xaa, len); result = IOS_Ioctl(di_fd, 0x8d, inbuf, 0x20, outbuf, len); debug_printf("-> %d\n", result); if(result >= 0) { memcpy(buf, outbuf, len); #ifdef DEBUG for(int i=0; i> 2; memset(outbuf, 0xaa, len); result = IOS_Ioctl(di_fd, 0x71, inbuf, 0x20, outbuf, len); debug_printf("WDVD_LowRead() -> %d\n", result); if(result >= 0) { memcpy(buf, outbuf, len); #ifdef DEBUG for(int i=0; i>2] = 0x8b000000; inbuf[(0x40>>2)+1] = offset >> 2; int result = IOS_Ioctlv( di_fd, 0x8b, 3, 2, (ioctlv*)buffer); debug_printf("IOS_Ioctlv -> %d\n", result); iosFree(di_hid, buffer); return result; }