Merge 7f88a7c7f88a52fbbcca9c09328ee1fe63a3bf01 into f9f16d7a552c5606caea52c2179ca2831b8e0177

This commit is contained in:
Extrems 2024-05-01 19:44:34 +01:00 committed by GitHub
commit 71c2b7ae37
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 49 additions and 120 deletions

View File

@ -7,7 +7,7 @@ ifeq ($(strip $(DEVKITPPC)),)
$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>devkitPPC) $(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>devkitPPC)
endif endif
include $(DEVKITPPC)/gamecube_rules include $(DEVKITPRO)/libogc2/gamecube_rules
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# TARGET is the name of the output # TARGET is the name of the output

View File

@ -44,6 +44,7 @@
#include "filesel.h" #include "filesel.h"
#include "file_slot.h" #include "file_slot.h"
#include <errno.h>
#include <iso9660.h> #include <iso9660.h>
#ifdef HW_RVL #ifdef HW_RVL
#include <di/di.h> #include <di/di.h>
@ -81,8 +82,6 @@ static u8 dvdInited = 0;
static u8 dvdMounted = 0; static u8 dvdMounted = 0;
#ifndef HW_RVL #ifndef HW_RVL
static u8 dvdBuffer[2048] ATTRIBUTE_ALIGN(32);
static bool dvdStartup() static bool dvdStartup()
{ {
DVD_Mount(); DVD_Mount();
@ -93,56 +92,6 @@ static bool dvdIsInserted()
{ {
return true; return true;
} }
static bool dvdReadSectors(u32 offset,u32 len,void *buffer)
{
vu32* const dvd = (u32*)0xCC006000;
offset = offset << 9;
len = len << 11;
/* DVD transfer must be done into a 32-byte aligned buffer */
while (len >= 2048)
{
DCInvalidateRange((void *)dvdBuffer, 2048);
dvd[0] = 0x2E;
dvd[1] = 0;
dvd[2] = 0xA8000000;
dvd[3] = offset;
dvd[4] = 2048;
dvd[5] = (u32) dvdBuffer;
dvd[6] = 2048;
dvd[7] = 3;
while (dvd[7] & 1);
if (dvd[0] & 4) return false;
memcpy (buffer, dvdBuffer, 2048);
len -= 2048;
buffer += 2048;
offset += 512;
}
/* Process remaining bytes (normally not needed since libiso9960 already deals with this but you never know) */
if (len)
{
/* DVD transfer length should be aligned to 32 bytes */
u32 dmasize = (len + 0x1f) & ~0x1f;
DCInvalidateRange((void *)dvdBuffer, dmasize);
dvd[0] = 0x2E;
dvd[1] = 0;
dvd[2] = 0xA8000000;
dvd[3] = offset;
dvd[4] = dmasize;
dvd[5] = (u32) dvdBuffer;
dvd[6] = dmasize;
dvd[7] = 3;
while (dvd[7] & 1);
if (dvd[0] & 4) return false;
memcpy (buffer, dvdBuffer, len);
}
return true;
}
#endif #endif
/*************************************************************************** /***************************************************************************
@ -165,7 +114,6 @@ static int MountDVD(void)
/* patch libogc DVD interface which appears to be broken on Gamecube */ /* patch libogc DVD interface which appears to be broken on Gamecube */
dvd->startup = (FN_MEDIUM_STARTUP)dvdStartup; dvd->startup = (FN_MEDIUM_STARTUP)dvdStartup;
dvd->isInserted = (FN_MEDIUM_ISINSERTED)dvdIsInserted; dvd->isInserted = (FN_MEDIUM_ISINSERTED)dvdIsInserted;
dvd->readSectors = (FN_MEDIUM_READSECTORS)dvdReadSectors;
#endif #endif
dvdInited = 1; dvdInited = 1;
} }
@ -284,11 +232,19 @@ int ParseDirectory(void)
return -1; return -1;
} }
struct dirent *entry = readdir(dir); struct dirent *entry = NULL;
/* list entries */ /* list entries */
while ((entry != NULL)&& (nbfiles < MAXFILES)) do
{ {
errno = 0;
/* next entry */
entry = readdir(dir);
if (entry == NULL)
{
continue;
}
/* filter entries */ /* filter entries */
if ((entry->d_name[0] != '.') if ((entry->d_name[0] != '.')
&& strncasecmp(".wav", &entry->d_name[strlen(entry->d_name) - 4], 4) && strncasecmp(".wav", &entry->d_name[strlen(entry->d_name) - 4], 4)
@ -303,10 +259,8 @@ int ParseDirectory(void)
} }
nbfiles++; nbfiles++;
} }
/* next entry */
entry = readdir(dir);
} }
while ((entry != NULL || errno == EOVERFLOW) && (nbfiles < MAXFILES));
/* close directory */ /* close directory */
closedir(dir); closedir(dir);

View File

@ -70,21 +70,9 @@ static u8 brm_format[0x40] =
*****************************************************************************/ *****************************************************************************/
static int CardMount(int slot) static int CardMount(int slot)
{ {
int tries = 0; while (CARD_ProbeEx(slot, NULL, NULL) == CARD_ERROR_BUSY);
#ifdef HW_RVL if (CARD_Mount(slot, SysArea, NULL) == CARD_ERROR_READY)
*(unsigned long *) (0xCD006800) |= 1 << 13; /*** Disable Encryption ***/ return 1;
#else
*(unsigned long *) (0xCC006800) |= 1 << 13; /*** Disable Encryption ***/
#endif
while (tries < 10)
{
VIDEO_WaitVSync ();
if (CARD_Mount(slot, SysArea, NULL) == CARD_ERROR_READY)
return 1;
else
EXI_ProbeReset ();
tries++;
}
return 0; return 0;
} }
@ -309,7 +297,6 @@ void slot_autodetect(int slot, int device, t_slot *ptr)
sprintf(filename,"MD-%04X.srm", rominfo.realchecksum); sprintf(filename,"MD-%04X.srm", rominfo.realchecksum);
/* Initialise the CARD system */ /* Initialise the CARD system */
memset(&SysArea, 0, CARD_WORKAREA);
CARD_Init("GENP", "00"); CARD_Init("GENP", "00");
/* CARD slot */ /* CARD slot */
@ -325,7 +312,7 @@ void slot_autodetect(int slot, int device, t_slot *ptr)
/* Retrieve date & close */ /* Retrieve date & close */
card_stat CardStatus; card_stat CardStatus;
CARD_GetStatus(device, CardFile.filenum, &CardStatus); CARD_GetStatus(device, CardFile.filenum, &CardStatus);
time_t rawtime = CardStatus.time; time_t rawtime = CardStatus.time + 946684800;
struct tm *timeinfo = localtime(&rawtime); struct tm *timeinfo = localtime(&rawtime);
ptr->year = 1900 + timeinfo->tm_year; ptr->year = 1900 + timeinfo->tm_year;
ptr->month = timeinfo->tm_mon + 1; ptr->month = timeinfo->tm_mon + 1;
@ -373,7 +360,6 @@ int slot_delete(int slot, int device)
sprintf(filename,"MD-%04X.srm", rominfo.realchecksum); sprintf(filename,"MD-%04X.srm", rominfo.realchecksum);
/* Initialise the CARD system */ /* Initialise the CARD system */
memset(&SysArea, 0, CARD_WORKAREA);
CARD_Init("GENP", "00"); CARD_Init("GENP", "00");
/* CARD slot */ /* CARD slot */
@ -477,7 +463,6 @@ int slot_load(int slot, int device)
/* Initialise the CARD system */ /* Initialise the CARD system */
char action[64]; char action[64];
memset(&SysArea, 0, CARD_WORKAREA);
CARD_Init("GENP", "00"); CARD_Init("GENP", "00");
/* CARD slot */ /* CARD slot */
@ -530,12 +515,7 @@ int slot_load(int slot, int device)
} }
/* Read file sectors */ /* Read file sectors */
while (filesize > 0) CARD_Read(&CardFile, &in[done], filesize, done);
{
CARD_Read(&CardFile, &in[done], SectorSize, done);
done += SectorSize;
filesize -= SectorSize;
}
/* Close file */ /* Close file */
CARD_Close(&CardFile); CARD_Close(&CardFile);
@ -715,7 +695,6 @@ int slot_save(int slot, int device)
/* Initialise the CARD system */ /* Initialise the CARD system */
char action[64]; char action[64];
memset(&SysArea, 0, CARD_WORKAREA);
CARD_Init("GENP", "00"); CARD_Init("GENP", "00");
/* CARD slot */ /* CARD slot */
@ -763,6 +742,7 @@ int slot_save(int slot, int device)
/* compress file */ /* compress file */
compress2 ((Bytef *)&out[2112 + 4], &filesize, (Bytef *)buffer, done, 9); compress2 ((Bytef *)&out[2112 + 4], &filesize, (Bytef *)buffer, done, 9);
done = 0;
/* Adjust file size */ /* Adjust file size */
filesize = filesize + 4 + 2112; filesize = filesize + 4 + 2112;
@ -820,20 +800,24 @@ int slot_save(int slot, int device)
time(&rawtime); time(&rawtime);
card_stat CardStatus; card_stat CardStatus;
CARD_GetStatus(device, CardFile.filenum, &CardStatus); CARD_GetStatus(device, CardFile.filenum, &CardStatus);
CardStatus.icon_addr = 0x0; CardStatus.icon_addr = 0;
CardStatus.icon_fmt = 2; CardStatus.icon_fmt = CARD_ICON_RGB;
CardStatus.icon_speed = 1; CardStatus.icon_speed = CARD_SPEED_FAST;
CardStatus.comment_addr = 2048; CardStatus.comment_addr = 2048;
CardStatus.time = rawtime; CardStatus.time = rawtime - 946684800;
CARD_SetStatus(device, CardFile.filenum, &CardStatus); CARD_SetStatus(device, CardFile.filenum, &CardStatus);
/* Write file sectors */ /* Write file sectors */
#ifdef HW_RVL
while (filesize > 0) while (filesize > 0)
{ {
CARD_Write(&CardFile, &out[done], SectorSize, done); CARD_Write(&CardFile, &out[done], SectorSize, done);
filesize -= SectorSize; filesize -= SectorSize;
done += SectorSize; done += SectorSize;
} }
#else
CARD_Write(&CardFile, &out[done], filesize, done);
#endif
/* Close file */ /* Close file */
CARD_Close(&CardFile); CARD_Close(&CardFile);

View File

@ -791,7 +791,7 @@ int GUI_UpdateMenu(gui_menu *menu)
if (button->state & BUTTON_OVER_SFX) if (button->state & BUTTON_OVER_SFX)
{ {
ASND_SetVoice(ASND_GetFirstUnusedVoice(),VOICE_MONO_16BIT,22050,0,(u8 *)button_over_pcm,button_over_pcm_size, ASND_SetVoice(ASND_GetFirstUnusedVoice(),VOICE_MONO_16BIT,22050,0,(u8 *)button_over_pcm,button_over_pcm_size,
((int)config.sfx_volume * 255) / 100,((int)config.sfx_volume * 255) / 100,NULL); ((int)config.sfx_volume * MAX_VOLUME) / 100,((int)config.sfx_volume * MAX_VOLUME) / 100,NULL);
} }
} }
else if (selected < (max_buttons + 2)) else if (selected < (max_buttons + 2))
@ -801,7 +801,7 @@ int GUI_UpdateMenu(gui_menu *menu)
if (button->state & BUTTON_OVER_SFX) if (button->state & BUTTON_OVER_SFX)
{ {
ASND_SetVoice(ASND_GetFirstUnusedVoice(),VOICE_MONO_16BIT,22050,0,(u8 *)button_over_pcm,button_over_pcm_size, ASND_SetVoice(ASND_GetFirstUnusedVoice(),VOICE_MONO_16BIT,22050,0,(u8 *)button_over_pcm,button_over_pcm_size,
((int)config.sfx_volume * 255) / 100,((int)config.sfx_volume * 255) / 100,NULL); ((int)config.sfx_volume * MAX_VOLUME) / 100,((int)config.sfx_volume * MAX_VOLUME) / 100,NULL);
} }
} }
@ -832,7 +832,7 @@ int GUI_UpdateMenu(gui_menu *menu)
if (button->state & BUTTON_SELECT_SFX) if (button->state & BUTTON_SELECT_SFX)
{ {
ASND_SetVoice(ASND_GetFirstUnusedVoice(),VOICE_MONO_16BIT,22050,0,(u8 *)button_select_pcm,button_select_pcm_size, ASND_SetVoice(ASND_GetFirstUnusedVoice(),VOICE_MONO_16BIT,22050,0,(u8 *)button_select_pcm,button_select_pcm_size,
((int)config.sfx_volume * 255) / 100,((int)config.sfx_volume * 255) / 100,NULL); ((int)config.sfx_volume * MAX_VOLUME) / 100,((int)config.sfx_volume * MAX_VOLUME) / 100,NULL);
} }
} }
} }
@ -1183,7 +1183,7 @@ int GUI_OptionWindow(gui_menu *parent, char *title, char *infos, char *items[],
if (selected >= 0) if (selected >= 0)
{ {
ASND_SetVoice(ASND_GetFirstUnusedVoice(),VOICE_MONO_16BIT,22050,0,(u8 *)button_over_pcm,button_over_pcm_size, ASND_SetVoice(ASND_GetFirstUnusedVoice(),VOICE_MONO_16BIT,22050,0,(u8 *)button_over_pcm,button_over_pcm_size,
((int)config.sfx_volume * 255) / 100,((int)config.sfx_volume * 255) / 100,NULL); ((int)config.sfx_volume * MAX_VOLUME) / 100,((int)config.sfx_volume * MAX_VOLUME) / 100,NULL);
} }
} }
@ -1455,7 +1455,7 @@ void GUI_OptionBox(gui_menu *parent, optioncallback cb, char *title, void *optio
/* play sound effect */ /* play sound effect */
ASND_SetVoice(ASND_GetFirstUnusedVoice(),VOICE_MONO_16BIT,22050,0,(u8 *)button_over_pcm,button_over_pcm_size, ASND_SetVoice(ASND_GetFirstUnusedVoice(),VOICE_MONO_16BIT,22050,0,(u8 *)button_over_pcm,button_over_pcm_size,
((int)config.sfx_volume * 255) / 100,((int)config.sfx_volume * 255) / 100,NULL); ((int)config.sfx_volume * MAX_VOLUME) / 100,((int)config.sfx_volume * MAX_VOLUME) / 100,NULL);
/* option callback */ /* option callback */
if (cb) if (cb)
@ -1700,7 +1700,7 @@ void GUI_OptionBox2(gui_menu *parent, char *text_1, char *text_2, s16 *option_1,
modified = 0; modified = 0;
/* play sound effect */ /* play sound effect */
ASND_SetVoice(ASND_GetFirstUnusedVoice(),VOICE_MONO_16BIT,22050,0,(u8 *)button_over_pcm,button_over_pcm_size, ASND_SetVoice(ASND_GetFirstUnusedVoice(),VOICE_MONO_16BIT,22050,0,(u8 *)button_over_pcm,button_over_pcm_size,
((int)config.sfx_volume * 255) / 100,((int)config.sfx_volume * 255) / 100,NULL); ((int)config.sfx_volume * MAX_VOLUME) / 100,((int)config.sfx_volume * MAX_VOLUME) / 100,NULL);
} }
} }

View File

@ -702,7 +702,7 @@ static void update_screen_w(void)
static void update_bgm(void) static void update_bgm(void)
{ {
SetVolumeOgg(((int)config.bgm_volume * 255) / 100); SetVolumeOgg(((int)config.bgm_volume * MAX_VOLUME) / 100);
} }
static void prefmenu () static void prefmenu ()
@ -718,10 +718,10 @@ static void prefmenu ()
else if (config.s_auto == 1) sprintf (items[2].text, "Auto Saves: SRAM ONLY"); else if (config.s_auto == 1) sprintf (items[2].text, "Auto Saves: SRAM ONLY");
else sprintf (items[2].text, "Auto Saves: NONE"); else sprintf (items[2].text, "Auto Saves: NONE");
#ifdef HW_RVL #ifdef HW_RVL
if (config.l_device == 1) sprintf (items[3].text, "ROM Load Device: USB"); if (config.l_device == TYPE_USB) sprintf (items[3].text, "ROM Load Device: USB");
else if (config.l_device == 2) sprintf (items[3].text, "ROM Load Device: DVD"); else if (config.l_device == TYPE_DVD) sprintf (items[3].text, "ROM Load Device: DVD");
#else #else
if (config.l_device == 1) sprintf (items[3].text, "ROM Load Device: DVD"); if (config.l_device == TYPE_DVD) sprintf (items[3].text, "ROM Load Device: DVD");
#endif #endif
else sprintf (items[3].text, "ROM Load Device: SD"); else sprintf (items[3].text, "ROM Load Device: SD");
if (config.s_device == 1) sprintf (items[4].text, "Saves Device: MCARD A"); if (config.s_device == 1) sprintf (items[4].text, "Saves Device: MCARD A");
@ -771,12 +771,12 @@ static void prefmenu ()
case 3: /*** Default ROM device ***/ case 3: /*** Default ROM device ***/
#ifdef HW_RVL #ifdef HW_RVL
config.l_device = (config.l_device + 1) % 3; config.l_device = (config.l_device + 1) % (TYPE_DVD + 1);
if (config.l_device == 1) sprintf (items[3].text, "ROM Load Device: USB"); if (config.l_device == TYPE_USB) sprintf (items[3].text, "ROM Load Device: USB");
else if (config.l_device == 2) sprintf (items[3].text, "ROM Load Device: DVD"); else if (config.l_device == TYPE_DVD) sprintf (items[3].text, "ROM Load Device: DVD");
#else #else
config.l_device ^= 1; config.l_device ^= 1;
if (config.l_device == 1) sprintf (items[3].text, "ROM Load Device: DVD"); if (config.l_device == TYPE_DVD) sprintf (items[3].text, "ROM Load Device: DVD");
#endif #endif
else sprintf (items[3].text, "ROM Load Device: SD"); else sprintf (items[3].text, "ROM Load Device: SD");
break; break;
@ -871,21 +871,13 @@ static void prefmenu ()
} }
/* stop DVD drive when not in use */ /* stop DVD drive when not in use */
if (config.l_device != 2) if (config.l_device != TYPE_DVD)
{ {
#ifdef HW_RVL #ifdef HW_RVL
DI_StopMotor(); DI_StopMotor();
#else #else
vu32* const dvd = (u32*)0xCC006000; dvdcmdblk blk;
dvd[0] = 0x2e; DVD_StopMotor(&blk);
dvd[1] = 0;
dvd[2] = 0xe3000000;
dvd[3] = 0;
dvd[4] = 0;
dvd[5] = 0;
dvd[6] = 0;
dvd[7] = 1;
while (dvd[7] & 1);
#endif #endif
} }

View File

@ -218,6 +218,6 @@ void gx_audio_Stop(void)
{ {
PauseOgg(0); PauseOgg(0);
PlayOgg((char *)Bg_music_ogg, Bg_music_ogg_size, 0, OGG_INFINITE_TIME); PlayOgg((char *)Bg_music_ogg, Bg_music_ogg_size, 0, OGG_INFINITE_TIME);
SetVolumeOgg(((int)config.bgm_volume * 255) / 100); SetVolumeOgg(((int)config.bgm_volume * MAX_VOLUME) / 100);
} }
} }

View File

@ -359,8 +359,7 @@ static u8 screenDisplayList[32] ATTRIBUTE_ALIGN(32) =
static void vi_callback(u32 cnt) static void vi_callback(u32 cnt)
{ {
/* get audio DMA remaining length */ /* get audio DMA remaining length */
vu16* const _dspReg = (u16*)0xCC005000; u16 remain = AUDIO_GetDMABytesLeft() / 32;
u16 remain = _dspReg[29];
/* adjust desired output samplerate if audio playback is not perfectly in sync with video */ /* adjust desired output samplerate if audio playback is not perfectly in sync with video */
if (remain > 0) if (remain > 0)
@ -1885,7 +1884,7 @@ void gx_video_Init(void)
/* Configure VI */ /* Configure VI */
VIDEO_Configure(vmode); VIDEO_Configure(vmode);
/* Initialize font first (to ensure IPL font buffer is allocated in MEM1 as DMA from EXI bus to MEM2 is apparently not possible) */ /* Initialize font first (to ensure IPL font buffer is allocated in MEM1 as DMA from EXI bus to MEM2 is apparently not possible with libogc) */
FONT_Init(); FONT_Init();
/* Allocate framebuffers */ /* Allocate framebuffers */
@ -1893,7 +1892,7 @@ void gx_video_Init(void)
xfb[1] = (u32 *) MEM_K0_TO_K1((u32 *) SYS_AllocateFramebuffer(&TV50hz_576i)); xfb[1] = (u32 *) MEM_K0_TO_K1((u32 *) SYS_AllocateFramebuffer(&TV50hz_576i));
/* Define a console */ /* Define a console */
console_init(xfb[0], 20, 64, 640, 574, 574 * 2); console_init(xfb[0], 0, 0, vmode->fbWidth, vmode->xfbHeight, vmode->fbWidth * VI_DISPLAY_PIX_SZ);
/* Clear framebuffer to black */ /* Clear framebuffer to black */
VIDEO_ClearFrameBuffer(vmode, xfb[0], COLOR_BLACK); VIDEO_ClearFrameBuffer(vmode, xfb[0], COLOR_BLACK);

View File

@ -452,7 +452,7 @@ int PlayOgg(char * buf, int buflen, int time_pos, int mode)
private_ogg.mode = mode; private_ogg.mode = mode;
private_ogg.eof = 0; private_ogg.eof = 0;
private_ogg.volume = 127; private_ogg.volume = MID_VOLUME;
private_ogg.flag = 0; private_ogg.flag = 0;
private_ogg.seek_time = -1; private_ogg.seek_time = -1;