Skip to content

Commit

Permalink
Add remainder of streaming audio functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Extrems committed Dec 21, 2023
1 parent 8df1e46 commit b54f960
Show file tree
Hide file tree
Showing 2 changed files with 187 additions and 10 deletions.
14 changes: 12 additions & 2 deletions gc/ogc/dvd.h
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,20 @@ s32 DVD_SeekAbsPrio(dvdcmdblk *block,s64 offset,s32 prio);
DVD_SeekAbsAsyncPrio(block,offset,cb,2)
s32 DVD_SeekAbsAsyncPrio(dvdcmdblk *block,s64 offset,dvdcbcallback cb,s32 prio);
s32 DVD_CancelAllAsync(dvdcbcallback cb);
s32 DVD_PrepareStreamAbsAsync(dvdcmdblk *block,u32 len,s64 offset,dvdcbcallback cb);
s32 DVD_PrepareStreamAbs(dvdcmdblk *block,u32 len,s64 offset);
s32 DVD_StopStreamAtEndAsync(dvdcmdblk *block,dvdcbcallback cb);
s32 DVD_PrepareStreamAbsAsync(dvdcmdblk *block,u32 len,s64 offset,dvdcbcallback cb);
s32 DVD_CancelStream(dvdcmdblk *block);
s32 DVD_CancelStreamAsync(dvdcmdblk *block,dvdcbcallback cb);
s32 DVD_StopStreamAtEnd(dvdcmdblk *block);
s32 DVD_StopStreamAtEndAsync(dvdcmdblk *block,dvdcbcallback cb);
s32 DVD_GetStreamErrorStatus(dvdcmdblk *block);
s32 DVD_GetStreamErrorStatusAsync(dvdcmdblk *block,dvdcbcallback cb);
s32 DVD_GetStreamPlayAddr(dvdcmdblk *block);
s32 DVD_GetStreamPlayAddrAsync(dvdcmdblk *block,dvdcbcallback cb);
s32 DVD_GetStreamStartAddr(dvdcmdblk *block);
s32 DVD_GetStreamStartAddrAsync(dvdcmdblk *block,dvdcbcallback cb);
s32 DVD_GetStreamLength(dvdcmdblk *block);
s32 DVD_GetStreamLengthAsync(dvdcmdblk *block,dvdcbcallback cb);
s32 DVD_ReadDiskID(dvdcmdblk *block,dvddiskid *id,dvdcbcallback cb);
u32 DVD_SetAutoInvalidation(u32 auto_inv);
dvddiskid* DVD_GetCurrentDiskID(void);
Expand Down
183 changes: 175 additions & 8 deletions libogc/dvd.c
Original file line number Diff line number Diff line change
Expand Up @@ -924,11 +924,12 @@ static void __dvd_statebusycb(s32 result)

val = _diReg[8];
if(__dvd_currcmd==0x000a || __dvd_currcmd==0x000b) val <<= 2;
__dvd_executing->txdsize = val;

block = __dvd_executing;
__dvd_executing = &__dvd_dummycmdblk;
block->state = DVD_STATE_END;
if(block->cb) block->cb(val,block);
if(block->cb) block->cb(block->txdsize,block);
__dvd_stateready();
return;
}
Expand Down Expand Up @@ -2378,7 +2379,7 @@ s32 DVD_ReadDiskID(dvdcmdblk *block,dvddiskid *id,dvdcbcallback cb)
s32 DVD_ReadAbsAsyncPrio(dvdcmdblk *block,void *buf,u32 len,s64 offset,dvdcbcallback cb,s32 prio)
{
#ifdef _DVD_DEBUG
printf("DVD_ReadAbsAsyncPrio(%p,%p,%d,%d,%d)\n",block,buf,len,offset,prio);
printf("DVD_ReadAbsAsyncPrio(%p,%p,%d,%d,%p,%d)\n",block,buf,len,offset,cb,prio);
#endif
block->cmd = 0x0001;
block->buf = (void*)buf;
Expand All @@ -2393,7 +2394,7 @@ s32 DVD_ReadAbsAsyncPrio(dvdcmdblk *block,void *buf,u32 len,s64 offset,dvdcbcall
s32 DVD_ReadAbsAsyncForBS(dvdcmdblk *block,void *buf,u32 len,s64 offset,dvdcbcallback cb)
{
#ifdef _DVD_DEBUG
printf("DVD_ReadAbsAsyncForBS(%p,%p,%d,%d)\n",block,buf,len,offset);
printf("DVD_ReadAbsAsyncForBS(%p,%p,%d,%d,%p)\n",block,buf,len,offset,cb);
#endif
block->cmd = 0x0004;
block->buf = (void*)buf;
Expand All @@ -2407,6 +2408,9 @@ s32 DVD_ReadAbsAsyncForBS(dvdcmdblk *block,void *buf,u32 len,s64 offset,dvdcbcal

s32 DVD_SeekAbsAsyncPrio(dvdcmdblk *block,s64 offset,dvdcbcallback cb,s32 prio)
{
#ifdef _DVD_DEBUG
printf("DVD_SeekAbsAsyncPrio(%p,%d,%p,%d)\n",block,offset,cb,prio);
#endif
block->cmd = 0x0002;
block->offset = offset;
block->cb = cb;
Expand All @@ -2424,9 +2428,7 @@ s32 DVD_InquiryAsync(dvdcmdblk *block,dvddrvinfo *info,dvdcbcallback cb)
block->len = DVD_DRVINFSIZE;
block->txdsize = 0;
block->cb = cb;
#ifdef _DVD_DEBUG
printf("DVD_InquiryAsync(%p,%p)\n",block,block->cb);
#endif

return __issuecommand(2,block);
}

Expand Down Expand Up @@ -2555,6 +2557,39 @@ s32 DVD_PrepareStreamAbs(dvdcmdblk *block,u32 len,s64 offset)
return ret;
}

s32 DVD_CancelStreamAsync(dvdcmdblk *block,dvdcbcallback cb)
{
#ifdef _DVD_DEBUG
printf("DVD_CancelStreamAsync(%p,%p)\n",block,cb);
#endif
block->cmd = 0x0007;
block->cb = cb;
return __issuecommand(1,block);
}

s32 DVD_CancelStream(dvdcmdblk *block)
{
s32 ret,state;
u32 level;
#ifdef _DVD_DEBUG
printf("DVD_CancelStream(%p)\n",block);
#endif
ret = DVD_CancelStreamAsync(block,__dvd_synccb);
if(!ret) return DVD_ERROR_FATAL;

_CPU_ISR_Disable(level);
do {
state = block->state;
if(state==DVD_STATE_END) ret = DVD_ERROR_OK;
else if(state==DVD_STATE_FATAL_ERROR) ret = DVD_ERROR_FATAL;
else if(state==DVD_STATE_CANCELED) ret = DVD_ERROR_CANCELED;
else LWP_ThreadSleep(__dvd_wait_queue);
} while(state!=DVD_STATE_END && state!=DVD_STATE_FATAL_ERROR && state!=DVD_STATE_CANCELED);
_CPU_ISR_Restore(level);

return ret;
}

s32 DVD_StopStreamAtEndAsync(dvdcmdblk *block,dvdcbcallback cb)
{
#ifdef _DVD_DEBUG
Expand Down Expand Up @@ -2588,6 +2623,138 @@ s32 DVD_StopStreamAtEnd(dvdcmdblk *block)
return ret;
}

s32 DVD_GetStreamErrorStatusAsync(dvdcmdblk *block,dvdcbcallback cb)
{
#ifdef _DVD_DEBUG
printf("DVD_GetStreamErrorStatusAsync(%p,%p)\n",block,cb);
#endif
block->cmd = 0x0009;
block->cb = cb;
return __issuecommand(1,block);
}

s32 DVD_GetStreamErrorStatus(dvdcmdblk *block)
{
s32 ret,state;
u32 level;
#ifdef _DVD_DEBUG
printf("DVD_GetStreamErrorStatus(%p)\n",block);
#endif
ret = DVD_GetStreamErrorStatusAsync(block,__dvd_synccb);
if(!ret) return DVD_ERROR_FATAL;

_CPU_ISR_Disable(level);
do {
state = block->state;
if(state==DVD_STATE_END) ret = block->txdsize;
else if(state==DVD_STATE_FATAL_ERROR) ret = DVD_ERROR_FATAL;
else if(state==DVD_STATE_CANCELED) ret = DVD_ERROR_CANCELED;
else LWP_ThreadSleep(__dvd_wait_queue);
} while(state!=DVD_STATE_END && state!=DVD_STATE_FATAL_ERROR && state!=DVD_STATE_CANCELED);
_CPU_ISR_Restore(level);

return ret;
}

s32 DVD_GetStreamPlayAddrAsync(dvdcmdblk *block,dvdcbcallback cb)
{
#ifdef _DVD_DEBUG
printf("DVD_GetStreamPlayAddrAsync(%p,%p)\n",block,cb);
#endif
block->cmd = 0x000a;
block->cb = cb;
return __issuecommand(1,block);
}

s32 DVD_GetStreamPlayAddr(dvdcmdblk *block)
{
s32 ret,state;
u32 level;
#ifdef _DVD_DEBUG
printf("DVD_GetStreamPlayAddr(%p)\n",block);
#endif
ret = DVD_GetStreamPlayAddrAsync(block,__dvd_synccb);
if(!ret) return DVD_ERROR_FATAL;

_CPU_ISR_Disable(level);
do {
state = block->state;
if(state==DVD_STATE_END) ret = block->txdsize;
else if(state==DVD_STATE_FATAL_ERROR) ret = DVD_ERROR_FATAL;
else if(state==DVD_STATE_CANCELED) ret = DVD_ERROR_CANCELED;
else LWP_ThreadSleep(__dvd_wait_queue);
} while(state!=DVD_STATE_END && state!=DVD_STATE_FATAL_ERROR && state!=DVD_STATE_CANCELED);
_CPU_ISR_Restore(level);

return ret;
}

s32 DVD_GetStreamStartAddrAsync(dvdcmdblk *block,dvdcbcallback cb)
{
#ifdef _DVD_DEBUG
printf("DVD_GetStreamStartAddrAsync(%p,%p)\n",block,cb);
#endif
block->cmd = 0x000b;
block->cb = cb;
return __issuecommand(1,block);
}

s32 DVD_GetStreamStartAddr(dvdcmdblk *block)
{
s32 ret,state;
u32 level;
#ifdef _DVD_DEBUG
printf("DVD_GetStreamStartAddr(%p)\n",block);
#endif
ret = DVD_GetStreamStartAddrAsync(block,__dvd_synccb);
if(!ret) return DVD_ERROR_FATAL;

_CPU_ISR_Disable(level);
do {
state = block->state;
if(state==DVD_STATE_END) ret = block->txdsize;
else if(state==DVD_STATE_FATAL_ERROR) ret = DVD_ERROR_FATAL;
else if(state==DVD_STATE_CANCELED) ret = DVD_ERROR_CANCELED;
else LWP_ThreadSleep(__dvd_wait_queue);
} while(state!=DVD_STATE_END && state!=DVD_STATE_FATAL_ERROR && state!=DVD_STATE_CANCELED);
_CPU_ISR_Restore(level);

return ret;
}

s32 DVD_GetStreamLengthAsync(dvdcmdblk *block,dvdcbcallback cb)
{
#ifdef _DVD_DEBUG
printf("DVD_GetStreamLengthAsync(%p,%p)\n",block,cb);
#endif
block->cmd = 0x000c;
block->cb = cb;
return __issuecommand(1,block);
}

s32 DVD_GetStreamLength(dvdcmdblk *block)
{
s32 ret,state;
u32 level;
#ifdef _DVD_DEBUG
printf("DVD_GetStreamLength(%p)\n",block);
#endif
ret = DVD_GetStreamLengthAsync(block,__dvd_synccb);
if(!ret) return DVD_ERROR_FATAL;

_CPU_ISR_Disable(level);
do {
state = block->state;
if(state==DVD_STATE_END) ret = block->txdsize;
else if(state==DVD_STATE_FATAL_ERROR) ret = DVD_ERROR_FATAL;
else if(state==DVD_STATE_CANCELED) ret = DVD_ERROR_CANCELED;
else LWP_ThreadSleep(__dvd_wait_queue);
} while(state!=DVD_STATE_END && state!=DVD_STATE_FATAL_ERROR && state!=DVD_STATE_CANCELED);
_CPU_ISR_Restore(level);

return ret;
}

s32 DVD_StopMotorAsync(dvdcmdblk *block,dvdcbcallback cb)
{
#ifdef _DVD_DEBUG
Expand Down Expand Up @@ -2727,7 +2894,7 @@ s32 DVD_SetGCMOffset(dvdcmdblk *block,s64 offset)
s32 DVD_GcodeReadAsync(dvdcmdblk *block,void *buf,u32 len,u32 offset,dvdcbcallback cb)
{
#ifdef _DVD_DEBUG
printf("DVD_GcodeReadAsync(%p,%p,%d,%d)\n",block,buf,len,offset);
printf("DVD_GcodeReadAsync(%p,%p,%d,%d,%p)\n",block,buf,len,offset,cb);
#endif
block->cmd = 0x0014;
block->buf = (void*)buf;
Expand Down Expand Up @@ -2765,7 +2932,7 @@ s32 DVD_GcodeRead(dvdcmdblk *block,void *buf,u32 len,u32 offset)
s32 DVD_GcodeWriteAsync(dvdcmdblk *block,const void *buf,u32 len,u32 offset,dvdcbcallback cb)
{
#ifdef _DVD_DEBUG
printf("DVD_GcodeWriteAsync(%p,%p,%d,%d)\n",block,buf,len,offset);
printf("DVD_GcodeWriteAsync(%p,%p,%d,%d,%p)\n",block,buf,len,offset,cb);
#endif
block->cmd = 0x0015;
block->buf = (void*)buf;
Expand Down

0 comments on commit b54f960

Please sign in to comment.