From 502432d531e1b9b9feec3d494db8d61d6e8d1a3e Mon Sep 17 00:00:00 2001 From: "Carl.Kenner" Date: Tue, 5 May 2009 00:02:38 +0000 Subject: [PATCH] File system works, thanks to some code from VBA-Wii. Config file now loads and saves. Restructured so less wii-specific code throughout project. --- dosbox-wii.pnproj | 2 +- src/gui/sdlmain.cpp | 16 +--- src/misc/cross.cpp | 13 +++ src/platform/wii/wiihardware.cpp | 151 +++++++++++++++++++++++++++++++ src/platform/wii/wiihardware.h | 9 ++ src/shell/shell.cpp | 10 +- 6 files changed, 181 insertions(+), 20 deletions(-) create mode 100644 src/platform/wii/wiihardware.cpp create mode 100644 src/platform/wii/wiihardware.h diff --git a/dosbox-wii.pnproj b/dosbox-wii.pnproj index dacec55..c621791 100644 --- a/dosbox-wii.pnproj +++ b/dosbox-wii.pnproj @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/src/gui/sdlmain.cpp b/src/gui/sdlmain.cpp index 4ce79da..f5bde23 100644 --- a/src/gui/sdlmain.cpp +++ b/src/gui/sdlmain.cpp @@ -33,7 +33,7 @@ #include #endif #ifdef HW_RVL -#include +#include #endif #include "SDL.h" @@ -1467,6 +1467,9 @@ static void printconfiglocation() { //extern void UI_Init(void); int main(int argc, char* argv[]) { try { +#ifdef HW_RVL + WiiInit(); +#endif CommandLine com_line(argc,argv); Config myconf(&com_line); control=&myconf; @@ -1601,9 +1604,7 @@ int main(int argc, char* argv[]) { if(!parsed_anyconfigfile) { //Try to create the userlevel configfile. config_file.clear(); -#ifndef HW_RVL Cross::CreatePlatformConfigDir(config_path); -#endif Cross::GetPlatformConfigName(config_file); config_path += config_file; if(control->PrintConfig(config_path.c_str())) { @@ -1665,15 +1666,8 @@ int main(int argc, char* argv[]) { //Force visible mouse to end user. Somehow this sometimes doesn't happen SDL_WM_GrabInput(SDL_GRAB_OFF); SDL_ShowCursor(SDL_ENABLE); - #ifdef HW_RVL - printf("Press A to return to homebrew channel.\n"); - while (1) { - WPAD_ScanPads(); - u16 buttonsDown = WPAD_ButtonsDown(0); - if( buttonsDown & WPAD_BUTTON_A ) break; - if( buttonsDown & WPAD_BUTTON_HOME ) exit(0); - } + WiiFinished(); #endif SDL_Quit();//Let's hope sdl will quit as well when it catches an exception return 0; diff --git a/src/misc/cross.cpp b/src/misc/cross.cpp index 1f4d085..f908716 100644 --- a/src/misc/cross.cpp +++ b/src/misc/cross.cpp @@ -24,6 +24,10 @@ #include #include +#ifdef HW_RVL +#include "wiihardware.h" +#endif + #ifdef WIN32 #ifndef _WIN32_IE #define _WIN32_IE 0x0400 @@ -46,6 +50,9 @@ void Cross::GetPlatformConfigDir(std::string& in) { #elif defined(MACOSX) in = "~/Library/Preferences"; ResolveHomedir(in); +#elif defined(HW_RVL) + in = "sd:/DOSBox"; + ResolveHomedir(in); #else in = "~/.dosbox"; ResolveHomedir(in); @@ -58,6 +65,8 @@ void Cross::GetPlatformConfigName(std::string& in) { #define DEFAULT_CONFIG_FILE "dosbox-" VERSION ".conf" #elif defined(MACOSX) #define DEFAULT_CONFIG_FILE "DOSBox " VERSION " Preferences" +#elif defined(HW_RVL) +#define DEFAULT_CONFIG_FILE "dosbox-" VERSION ".conf" #else /*linux freebsd*/ #define DEFAULT_CONFIG_FILE "dosbox-" VERSION ".conf" #endif @@ -75,6 +84,10 @@ void Cross::CreatePlatformConfigDir(std::string& in) { in = "~/Library/Preferences/"; ResolveHomedir(in); //Don't create it. Assume it exists +#elif defined(HW_RVL) + in = "sd:/DOSBox"; + CreateDir(in); + //Don't create it. Assume it exists #else in = "~/.dosbox"; ResolveHomedir(in); diff --git a/src/platform/wii/wiihardware.cpp b/src/platform/wii/wiihardware.cpp new file mode 100644 index 0000000..16ca57d --- /dev/null +++ b/src/platform/wii/wiihardware.cpp @@ -0,0 +1,151 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "wiihardware.h" + +char rootdir[10]; + +enum { + METHOD_AUTO, + METHOD_SD, + METHOD_USB, + METHOD_DVD, + METHOD_SMB, + METHOD_MC_SLOTA, + METHOD_MC_SLOTB, + METHOD_SD_SLOTA, + METHOD_SD_SLOTB +}; + +bool unmountRequired[9] = { false, false, false, false, false, false, false, false, false }; +bool isMounted[9] = { false, false, false, false, false, false, false, false, false }; + +#ifdef HW_RVL + const DISC_INTERFACE* sd = &__io_wiisd; + const DISC_INTERFACE* usb = &__io_usbstorage; +#else + const DISC_INTERFACE* carda = &__io_gcsda; + const DISC_INTERFACE* cardb = &__io_gcsdb; +#endif + +/**************************************************************************** + * UnmountAllFAT + * Unmounts all FAT devices + ***************************************************************************/ +void UnmountAllFAT() +{ +#ifdef HW_RVL + fatUnmount("sd:/"); + fatUnmount("usb:/"); +#else + fatUnmount("carda:/"); + fatUnmount("cardb:/"); +#endif +} + +/**************************************************************************** + * MountFAT + * Checks if the device needs to be (re)mounted + * If so, unmounts the device + * Attempts to mount the device specified + * Sets libfat to use the device by default + ***************************************************************************/ + +bool MountFAT(int method) +{ + bool mounted = true; // assume our disc is already mounted + char name[10]; + const DISC_INTERFACE* disc = NULL; + + switch(method) + { +#ifdef HW_RVL + case METHOD_SD: + sprintf(name, "sd"); + disc = sd; + break; + case METHOD_USB: + sprintf(name, "usb"); + disc = usb; + break; +#else + case METHOD_SD_SLOTA: + sprintf(name, "carda"); + disc = carda; + break; + + case METHOD_SD_SLOTB: + sprintf(name, "cardb"); + disc = cardb; + break; +#endif + default: + return false; // unknown device + } + + sprintf(rootdir, "%s:/", name); + + if(unmountRequired[method]) + { + unmountRequired[method] = false; + fatUnmount(rootdir); + disc->shutdown(); + isMounted[method] = false; + } + if(!isMounted[method]) + { + if(!disc->startup()) + mounted = false; + else if(!fatMountSimple(name, disc)) + mounted = false; + } + + isMounted[method] = mounted; + return mounted; +} + +void MountAllFAT() +{ +#ifdef HW_RVL + MountFAT(METHOD_SD); + MountFAT(METHOD_USB); +#else + MountFAT(METHOD_SD_SLOTA); + MountFAT(METHOD_SD_SLOTB); +#endif +} + +void WiiInit() { + MountAllFAT(); +} + +bool WiiMessagePause(const char *s) { + if (s) printf(s); +#ifdef HW_RVL + while (1) { + WPAD_ScanPads(); + u16 buttonsDown = WPAD_ButtonsDown(0); + if( buttonsDown & WPAD_BUTTON_A ) return false; + if( buttonsDown & WPAD_BUTTON_HOME ) return true; + } +#else + return false; +#endif +} + +void WiiFinished() { + UnmountAllFAT(); +#ifdef HW_RVL + if (WiiMessagePause("Press A to return to homebrew channel.\n")) exit(0); +#endif +} diff --git a/src/platform/wii/wiihardware.h b/src/platform/wii/wiihardware.h new file mode 100644 index 0000000..d48c1f9 --- /dev/null +++ b/src/platform/wii/wiihardware.h @@ -0,0 +1,9 @@ +#ifndef WIIHARDWARE_H +#define WIIHARDWARE_H +#include + +void WiiInit(); +void WiiFinished(); +bool WiiMessagePause(const char *s); + +#endif diff --git a/src/shell/shell.cpp b/src/shell/shell.cpp index 0e34da2..dce87e9 100644 --- a/src/shell/shell.cpp +++ b/src/shell/shell.cpp @@ -22,7 +22,7 @@ #include #include #ifdef HW_RVL -#include +#include #endif #include "dosbox.h" #include "regs.h" @@ -635,13 +635,7 @@ void SHELL_Init() { SHELL_ProgramStart(&first_shell); #ifdef HW_RVL - printf("Press A to continue (or Home to exit).\n"); - while (1) { - WPAD_ScanPads(); - u16 buttonsDown = WPAD_ButtonsDown(0); - if( buttonsDown & WPAD_BUTTON_A ) break; - if( buttonsDown & WPAD_BUTTON_HOME ) exit(0); - } + WiiMessagePause("Press A to continue (or Home to exit).\n"); #endif first_shell->Run();