From 787dd53a46bdd4fed3c99832fa3f0f66c80c992b Mon Sep 17 00:00:00 2001 From: dimok321 <15055714+dimok789@users.noreply.github.com> Date: Fri, 17 Sep 2010 17:48:16 +0000 Subject: [PATCH] *Removed Metaphrasis (not used anymore) *Changed WPAD/PAD handle and moved functions to appropiate locations *some code optimizations --- HBC/META.XML | 4 +- gui.pnproj | 2 +- source/Metaphrasis.cpp | 382 ----------------------------------- source/Metaphrasis.h | 116 ----------- source/input.cpp | 49 +++++ source/input.h | 2 + source/main.cpp | 9 +- source/menu.cpp | 116 +++++------ source/settings/Settings.cpp | 68 +++---- source/video.cpp | 31 +-- 10 files changed, 150 insertions(+), 629 deletions(-) delete mode 100644 source/Metaphrasis.cpp delete mode 100644 source/Metaphrasis.h diff --git a/HBC/META.XML b/HBC/META.XML index aafff896..29ed8b3a 100644 --- a/HBC/META.XML +++ b/HBC/META.XML @@ -2,8 +2,8 @@ USB Loader GX USB Loader GX Team - 1.0 r946 - 201009171539 + 1.0 r947 + 201009171621 Loads games from USB-devices USB Loader GX is a libwiigui based USB iso loader with a wii-like GUI. You can install games to your HDDs and boot them with shorter loading times. The interactive GUI is completely controllable with WiiMote, Classic Controller or GC Controller. diff --git a/gui.pnproj b/gui.pnproj index 5f8f37d0..94a1d5be 100644 --- a/gui.pnproj +++ b/gui.pnproj @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/source/Metaphrasis.cpp b/source/Metaphrasis.cpp deleted file mode 100644 index ba71a992..00000000 --- a/source/Metaphrasis.cpp +++ /dev/null @@ -1,382 +0,0 @@ -/* - * Metaphrasis is a static conversion class for transforming RGBA image - * buffers into verious GX texture formats for Wii homebrew development. - * Copyright (C) 2008 Armin Tamzarian - * - * This file is part of Metaphrasis. - * - * Metaphrasis 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 3 of the License, or - * (at your option) any later version. - * - * Metaphrasis 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 Metaphrasis. If not, see . - */ - -#include "Metaphrasis.h" - -/** - * Default constructor for the Metaphrasis class. - */ - -Metaphrasis::Metaphrasis() { -} - -/** - * Default destructor for the Metaphrasis class. - */ - -Metaphrasis::~Metaphrasis() { -} - -/** - * Convert the specified RGBA data buffer into the I4 texture format - * - * This routine converts the RGBA data buffer into the I4 texture format and returns a pointer to the converted buffer. - * - * @param rgbaBuffer Buffer containing the temporarily rendered RGBA data. - * @param bufferWidth Pixel width of the data buffer. - * @param bufferHeight Pixel height of the data buffer. - * @return A pointer to the allocated buffer. - */ - -uint32_t* Metaphrasis::convertBufferToI4(uint32_t* rgbaBuffer, uint16_t bufferWidth, uint16_t bufferHeight) { - uint32_t bufferSize = bufferWidth * bufferHeight >> 1; - uint32_t* dataBufferI4 = (uint32_t *)memalign(32, bufferSize); - memset(dataBufferI4, 0x00, bufferSize); - - uint32_t *src = (uint32_t *)rgbaBuffer; - uint8_t *dst = (uint8_t *)dataBufferI4; - - for (uint16_t y = 0; y < bufferHeight; y += 8) { - for (uint16_t x = 0; x < bufferWidth; x += 8) { - for (uint16_t rows = 0; rows < 8; rows++) { - *dst++ = (src[((y + rows) * bufferWidth) + (x + 0)] & 0xf0) | ((src[((y + rows) * bufferWidth) + (x + 1)] & 0xf0) >> 4); - *dst++ = (src[((y + rows) * bufferWidth) + (x + 2)] & 0xf0) | ((src[((y + rows) * bufferWidth) + (x + 3)] & 0xf0) >> 4); - *dst++ = (src[((y + rows) * bufferWidth) + (x + 4)] & 0xf0) | ((src[((y + rows) * bufferWidth) + (x + 5)] & 0xf0) >> 4); - *dst++ = (src[((y + rows) * bufferWidth) + (x + 5)] & 0xf0) | ((src[((y + rows) * bufferWidth) + (x + 7)] & 0xf0) >> 4); - } - } - } - DCFlushRange(dataBufferI4, bufferSize); - - return dataBufferI4; -} - -/** - * Convert the specified RGBA data buffer into the I8 texture format - * - * This routine converts the RGBA data buffer into the I8 texture format and returns a pointer to the converted buffer. - * - * @param rgbaBuffer Buffer containing the temporarily rendered RGBA data. - * @param bufferWidth Pixel width of the data buffer. - * @param bufferHeight Pixel height of the data buffer. - * @return A pointer to the allocated buffer. - */ - -uint32_t* Metaphrasis::convertBufferToI8(uint32_t* rgbaBuffer, uint16_t bufferWidth, uint16_t bufferHeight) { - uint32_t bufferSize = bufferWidth * bufferHeight; - uint32_t* dataBufferI8 = (uint32_t *)memalign(32, bufferSize); - memset(dataBufferI8, 0x00, bufferSize); - - uint32_t *src = (uint32_t *)rgbaBuffer; - uint8_t *dst = (uint8_t *)dataBufferI8; - - for (uint16_t y = 0; y < bufferHeight; y += 4) { - for (uint16_t x = 0; x < bufferWidth; x += 8) { - for (uint16_t rows = 0; rows < 4; rows++) { - *dst++ = src[((y + rows) * bufferWidth) + (x + 0)] & 0xff; - *dst++ = src[((y + rows) * bufferWidth) + (x + 1)] & 0xff; - *dst++ = src[((y + rows) * bufferWidth) + (x + 2)] & 0xff; - *dst++ = src[((y + rows) * bufferWidth) + (x + 3)] & 0xff; - *dst++ = src[((y + rows) * bufferWidth) + (x + 4)] & 0xff; - *dst++ = src[((y + rows) * bufferWidth) + (x + 5)] & 0xff; - *dst++ = src[((y + rows) * bufferWidth) + (x + 6)] & 0xff; - *dst++ = src[((y + rows) * bufferWidth) + (x + 7)] & 0xff; - } - } - } - DCFlushRange(dataBufferI8, bufferSize); - - return dataBufferI8; -} - -/** - * Downsample the specified RGBA value data buffer to an IA4 value. - * - * This routine downsamples the given RGBA data value into the IA4 texture data format. - * - * @param rgba A 32-bit RGBA value to convert to the IA4 format. - * @return The IA4 value of the given RGBA value. - */ - -uint8_t Metaphrasis::convertRGBAToIA4(uint32_t rgba) { - uint8_t i, a; - - i = (rgba >> 8) & 0xf0; - a = (rgba ) & 0xff; - - return i | (a >> 4); -} - -/** - * Convert the specified RGBA data buffer into the IA4 texture format - * - * This routine converts the RGBA data buffer into the IA4 texture format and returns a pointer to the converted buffer. - * - * @param rgbaBuffer Buffer containing the temporarily rendered RGBA data. - * @param bufferWidth Pixel width of the data buffer. - * @param bufferHeight Pixel height of the data buffer. - * @return A pointer to the allocated buffer. - */ - -uint32_t* Metaphrasis::convertBufferToIA4(uint32_t* rgbaBuffer, uint16_t bufferWidth, uint16_t bufferHeight) { - uint32_t bufferSize = bufferWidth * bufferHeight; - uint32_t* dataBufferIA4 = (uint32_t *)memalign(32, bufferSize); - memset(dataBufferIA4, 0x00, bufferSize); - - uint32_t *src = (uint32_t *)rgbaBuffer; - uint8_t *dst = (uint8_t *)dataBufferIA4; - - for (uint16_t y = 0; y < bufferHeight; y += 4) { - for (uint16_t x = 0; x < bufferWidth; x += 8) { - for (uint16_t rows = 0; rows < 4; rows++) { - *dst++ = Metaphrasis::convertRGBAToIA4(src[((y + rows) * bufferWidth) + (x + 0)]); - *dst++ = Metaphrasis::convertRGBAToIA4(src[((y + rows) * bufferWidth) + (x + 1)]); - *dst++ = Metaphrasis::convertRGBAToIA4(src[((y + rows) * bufferWidth) + (x + 2)]); - *dst++ = Metaphrasis::convertRGBAToIA4(src[((y + rows) * bufferWidth) + (x + 3)]); - *dst++ = Metaphrasis::convertRGBAToIA4(src[((y + rows) * bufferWidth) + (x + 4)]); - *dst++ = Metaphrasis::convertRGBAToIA4(src[((y + rows) * bufferWidth) + (x + 5)]); - *dst++ = Metaphrasis::convertRGBAToIA4(src[((y + rows) * bufferWidth) + (x + 6)]); - *dst++ = Metaphrasis::convertRGBAToIA4(src[((y + rows) * bufferWidth) + (x + 7)]); - } - } - } - DCFlushRange(dataBufferIA4, bufferSize); - - return dataBufferIA4; -} - -/** - * Downsample the specified RGBA value data buffer to an IA8 value. - * - * This routine downsamples the given RGBA data value into the IA8 texture data format. - * - * @param rgba A 32-bit RGBA value to convert to the IA8 format. - * @return The IA8 value of the given RGBA value. - */ - -uint16_t Metaphrasis::convertRGBAToIA8(uint32_t rgba) { - uint8_t i, a; - - i = (rgba >> 8) & 0xff; - a = (rgba ) & 0xff; - - return (i << 8) | a; -} - -/** - * Convert the specified RGBA data buffer into the IA8 texture format - * - * This routine converts the RGBA data buffer into the IA8 texture format and returns a pointer to the converted buffer. - * - * @param rgbaBuffer Buffer containing the temporarily rendered RGBA data. - * @param bufferWidth Pixel width of the data buffer. - * @param bufferHeight Pixel height of the data buffer. - * @return A pointer to the allocated buffer. - */ - -uint32_t* Metaphrasis::convertBufferToIA8(uint32_t* rgbaBuffer, uint16_t bufferWidth, uint16_t bufferHeight) { - uint32_t bufferSize = (bufferWidth * bufferHeight) << 1; - uint32_t* dataBufferIA8 = (uint32_t *)memalign(32, bufferSize); - memset(dataBufferIA8, 0x00, bufferSize); - - uint32_t *src = (uint32_t *)rgbaBuffer; - uint16_t *dst = (uint16_t *)dataBufferIA8; - - for (uint16_t y = 0; y < bufferHeight; y += 4) { - for (uint16_t x = 0; x < bufferWidth; x += 4) { - for (uint16_t rows = 0; rows < 4; rows++) { - *dst++ = Metaphrasis::convertRGBAToIA8(src[((y + rows) * bufferWidth) + (x + 0)]); - *dst++ = Metaphrasis::convertRGBAToIA8(src[((y + rows) * bufferWidth) + (x + 1)]); - *dst++ = Metaphrasis::convertRGBAToIA8(src[((y + rows) * bufferWidth) + (x + 2)]); - *dst++ = Metaphrasis::convertRGBAToIA8(src[((y + rows) * bufferWidth) + (x + 3)]); - } - } - } - DCFlushRange(dataBufferIA8, bufferSize); - - return dataBufferIA8; -} - -/** - * Convert the specified RGBA data buffer into the RGBA8 texture format - * - * This routine converts the RGBA data buffer into the RGBA8 texture format and returns a pointer to the converted buffer. - * - * @param rgbaBuffer Buffer containing the temporarily rendered RGBA data. - * @param bufferWidth Pixel width of the data buffer. - * @param bufferHeight Pixel height of the data buffer. - * @return A pointer to the allocated buffer. - */ - -uint32_t* Metaphrasis::convertBufferToRGBA8(uint32_t* rgbaBuffer, uint16_t bufferWidth, uint16_t bufferHeight) { - uint32_t bufferSize = (bufferWidth * bufferHeight) << 2; - uint32_t* dataBufferRGBA8 = (uint32_t *)memalign(32, bufferSize); - memset(dataBufferRGBA8, 0x00, bufferSize); - - uint8_t *src = (uint8_t *)rgbaBuffer; - uint8_t *dst = (uint8_t *)dataBufferRGBA8; - - for (uint16_t block = 0; block < bufferHeight; block += 4) { - for (uint16_t i = 0; i < bufferWidth; i += 4) { - for (uint16_t c = 0; c < 4; c++) { - for (uint16_t ar = 0; ar < 4; ar++) { - *dst++ = src[(((i + ar) + ((block + c) * bufferWidth)) * 4) + 3]; - *dst++ = src[((i + ar) + ((block + c) * bufferWidth)) * 4]; - } - } - for (uint16_t c = 0; c < 4; c++) { - for (uint16_t gb = 0; gb < 4; gb++) { - *dst++ = src[(((i + gb) + ((block + c) * bufferWidth)) * 4) + 1]; - *dst++ = src[(((i + gb) + ((block + c) * bufferWidth)) * 4) + 2]; - } - } - } - } - DCFlushRange(dataBufferRGBA8, bufferSize); - - return dataBufferRGBA8; -} - -/** - * Downsample the specified RGBA value data buffer to an RGB565 value. - * - * This routine downsamples the given RGBA data value into the RGB565 texture data format. - * Attribution for this routine is given fully to NoNameNo of GRRLIB Wii library. - * - * @param rgba A 32-bit RGBA value to convert to the RGB565 format. - * @return The RGB565 value of the given RGBA value. - */ - -uint16_t Metaphrasis::convertRGBAToRGB565(uint32_t rgba) { - uint8_t r, g, b; - - r = (((rgba >> 24) & 0xff) * 31) / 255; - g = (((rgba >> 16) & 0xff) * 63) / 255; - b = (((rgba >> 8) & 0xff) * 31) / 255; - - return (((r << 6) | g ) << 5 ) | b; -} - -/** - * Convert the specified RGBA data buffer into the RGB565 texture format - * - * This routine converts the RGBA data buffer into the RGB565 texture format and returns a pointer to the converted buffer. - * - * @param rgbaBuffer Buffer containing the temporarily rendered RGBA data. - * @param bufferWidth Pixel width of the data buffer. - * @param bufferHeight Pixel height of the data buffer. - * @return A pointer to the allocated buffer. - */ - -uint32_t* Metaphrasis::convertBufferToRGB565(uint32_t* rgbaBuffer, uint16_t bufferWidth, uint16_t bufferHeight) { - uint32_t bufferSize = (bufferWidth * bufferHeight) << 1; - uint32_t* dataBufferRGB565 = (uint32_t *)memalign(32, bufferSize); - memset(dataBufferRGB565, 0x00, bufferSize); - - uint32_t *src = (uint32_t *)rgbaBuffer; - uint16_t *dst = (uint16_t *)dataBufferRGB565; - - for (uint16_t y = 0; y < bufferHeight; y += 4) { - for (uint16_t x = 0; x < bufferWidth; x += 4) { - for (uint16_t rows = 0; rows < 4; rows++) { - *dst++ = Metaphrasis::convertRGBAToRGB565(src[((y + rows) * bufferWidth) + (x + 0)]); - *dst++ = Metaphrasis::convertRGBAToRGB565(src[((y + rows) * bufferWidth) + (x + 1)]); - *dst++ = Metaphrasis::convertRGBAToRGB565(src[((y + rows) * bufferWidth) + (x + 2)]); - *dst++ = Metaphrasis::convertRGBAToRGB565(src[((y + rows) * bufferWidth) + (x + 3)]); - } - } - } - DCFlushRange(dataBufferRGB565, bufferSize); - - return dataBufferRGB565; -} - -/** - * Downsample the specified RGBA value data buffer to an RGB5A3 value. - * - * This routine downsamples the given RGBA data value into the RGB5A3 texture data format. - * Attribution for this routine is given fully to WiiGator via the TehSkeen forum. - * - * @param rgba A 32-bit RGBA value to convert to the RGB5A3 format. - * @return The RGB5A3 value of the given RGBA value. - */ - -uint16_t Metaphrasis::convertRGBAToRGB5A3(uint32_t rgba) { - uint32_t r, g, b, a; - uint16_t color; - - r = (rgba >> 24) & 0xff; - g = (rgba >> 16) & 0xff; - b = (rgba >> 8) & 0xff; - a = (rgba ) & 0xff; - - if (a > 0xe0) { - r = r >> 3; - g = g >> 3; - b = b >> 3; - - color = (r << 10) | (g << 5) | b; - color |= 0x8000; - } else { - r = r >> 4; - g = g >> 4; - b = b >> 4; - a = a >> 5; - - color = (a << 12) | (r << 8) | (g << 4) | b; - } - - return color; -} - -/** - * Convert the specified RGBA data buffer into the RGB5A3 texture format - * - * This routine converts the RGBA data buffer into the RGB5A3 texture format and returns a pointer to the converted buffer. - * - * @param rgbaBuffer Buffer containing the temporarily rendered RGBA data. - * @param bufferWidth Pixel width of the data buffer. - * @param bufferHeight Pixel height of the data buffer. - * @return A pointer to the allocated buffer. - */ - -uint32_t* Metaphrasis::convertBufferToRGB5A3(uint32_t* rgbaBuffer, uint16_t bufferWidth, uint16_t bufferHeight) { - uint32_t bufferSize = (bufferWidth * bufferHeight) << 1; - uint32_t* dataBufferRGB5A3 = (uint32_t *)memalign(32, bufferSize); - memset(dataBufferRGB5A3, 0x00, bufferSize); - - uint32_t *src = (uint32_t *)rgbaBuffer; - uint16_t *dst = (uint16_t *)dataBufferRGB5A3; - - for (uint16_t y = 0; y < bufferHeight; y += 4) { - for (uint16_t x = 0; x < bufferWidth; x += 4) { - for (uint16_t rows = 0; rows < 4; rows++) { - *dst++ = Metaphrasis::convertRGBAToRGB5A3(src[((y + rows) * bufferWidth) + (x + 0)]); - *dst++ = Metaphrasis::convertRGBAToRGB5A3(src[((y + rows) * bufferWidth) + (x + 1)]); - *dst++ = Metaphrasis::convertRGBAToRGB5A3(src[((y + rows) * bufferWidth) + (x + 2)]); - *dst++ = Metaphrasis::convertRGBAToRGB5A3(src[((y + rows) * bufferWidth) + (x + 3)]); - } - } - } - DCFlushRange(dataBufferRGB5A3, bufferSize); - - return dataBufferRGB5A3; -} diff --git a/source/Metaphrasis.h b/source/Metaphrasis.h deleted file mode 100644 index a5ed5939..00000000 --- a/source/Metaphrasis.h +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Metaphrasis is a static conversion class for transforming RGBA image - * buffers into verious GX texture formats for Wii homebrew development. - * Copyright (C) 2008 Armin Tamzarian - * - * This file is part of Metaphrasis. - * - * Metaphrasis 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 3 of the License, or - * (at your option) any later version. - * - * Metaphrasis 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 Metaphrasis. If not, see . - */ - -/** \mainpage Metaphrasis - * - * \section sec_intro Introduction - * - * Metaphrasis is a static conversion class for transforming RGBA image buffers into verious GX texture formats for Wii homebrew development. - *
- * Metaphrasis is written in C++ and makes use of a community standard and newly developed algorithms for conversion of 32-bit RGBA data buffers into various GX texture formats common to both the Gamecube and Wii platforms. - *

- * This library was developed in-full by Armin Tamzarian with the support of developers in \#wiibrew on EFnet, Chaosteil of libwiisprite, and DrTwox of GRRLIB. - * - * \section sec_installation_source Installation (Source Code) - * - * -# Extract the Metaphrasis archive. - * -# Copy the contents of the src directory into your project's development path. - * -# Include the Metaphrasis header file in your code using syntax such as the following: - * \code - * #include "Metaphrasis.h" - * \endcode - * - * \section sec_installation_library Installation (Library) - * - * -# Extract the Metaphrasis archive. - * -# Copy the contents of the lib directory into your devKitPro/libogc directory. - * -# Include the Metaphrasis header file in your code using syntax such as the following: - * \code - * #include "Metaphrasis.h" - * \endcode - * - * \section sec_usage Usage - * - * -# Create a buffer full of 32-bit RGBA values noting both the pixel height and width of the buffer. - * -# Call one of the many conversion routines from within your code. (Note: All methods within the Metaphrasis class are static and thus no class instance need be allocated) - * \code - * uint32_t* rgba8Buffer = Metaphrasis::convertBufferToRGBA8(rgbaBuffer, bufferWidth, bufferHeight); - * \endcode - * -# Free your temporary RGBA value buffer if you no longer need said values. - * - * Currently supported conversion routines are as follows: - * \li convertBufferToI4 - * \li convertBufferToI8 - * \li convertBufferToIA4 - * \li convertBufferToIA8 - * \li convertBufferToRGBA8 - * \li convertBufferToRGB565 - * \li convertBufferToRGB5A3 - * - * \section sec_license License - * - * Metaphrasis is distributed under the GNU Lesser General Public License. - * - * \section sec_contact Contact - * - * If you have any suggestions, questions, or comments regarding this library feel free to e-mail me at tamzarian1989 [at] gmail [dawt] com. - */ - -#ifndef METAPHRASIS_H_ -#define METAPHRASIS_H_ - -#include -#include -#include -#include - -/*! \class Metaphrasis - * \brief A static conversion class for transforming RGBA image buffers into verious GX texture formats for - * Wii homebrew development. - * \author Armin Tamzarian - * \version 0.1.0 - * - * Metaphrasis is a static conversion class for transforming RGBA image buffers into verious GX texture formats for - * Wii homebrew development. Metaphrasis is written in C++ and makes use of a community standard and newly developed - * algorithms for conversion of 32-bit RGBA data buffers into various GX texture formats common to both the Gamecube - * and Wii platforms. - */ -class Metaphrasis { -public: - Metaphrasis(); - virtual ~Metaphrasis(); - - static uint32_t* convertBufferToI4(uint32_t* rgbaBuffer, uint16_t bufferWidth, uint16_t bufferHeight); - static uint32_t* convertBufferToI8(uint32_t* rgbaBuffer, uint16_t bufferWidth, uint16_t bufferHeight); - static uint32_t* convertBufferToIA4(uint32_t* rgbaBuffer, uint16_t bufferWidth, uint16_t bufferHeight); - static uint32_t* convertBufferToIA8(uint32_t* rgbaBuffer, uint16_t bufferWidth, uint16_t bufferHeight); - static uint32_t* convertBufferToRGBA8(uint32_t* rgbaBuffer, uint16_t bufferWidth, uint16_t bufferHeight); - static uint32_t* convertBufferToRGB565(uint32_t* rgbaBuffer, uint16_t bufferWidth, uint16_t bufferHeight); - static uint32_t* convertBufferToRGB5A3(uint32_t* rgbaBuffer, uint16_t bufferWidth, uint16_t bufferHeight); - - static uint8_t convertRGBAToIA4(uint32_t rgba); - static uint16_t convertRGBAToIA8(uint32_t rgba); - static uint16_t convertRGBAToRGB565(uint32_t rgba); - static uint16_t convertRGBAToRGB5A3(uint32_t rgba); - -}; - -#endif /*METAPHRASIS_H_*/ diff --git a/source/input.cpp b/source/input.cpp index b8ea2289..2ad140c5 100644 --- a/source/input.cpp +++ b/source/input.cpp @@ -24,6 +24,55 @@ int rumbleRequest[4] = {0,0,0,0}; GuiTrigger userInput[4]; static int rumbleCount[4] = {0,0,0,0}; +/**************************************************************************** + * UpdatePads + * + * called by postRetraceCallback in InitGCVideo - scans gcpad and wpad + ***************************************************************************/ +void UpdatePads() +{ + WPAD_ScanPads(); + PAD_ScanPads(); + + for (int i=3; i >= 0; i--) + { + memcpy(&userInput[i].wpad, WPAD_Data(i), sizeof(WPADData)); + userInput[i].chan = i; + userInput[i].pad.btns_d = PAD_ButtonsDown(i); + userInput[i].pad.btns_u = PAD_ButtonsUp(i); + userInput[i].pad.btns_h = PAD_ButtonsHeld(i); + userInput[i].pad.stickX = PAD_StickX(i); + userInput[i].pad.stickY = PAD_StickY(i); + userInput[i].pad.substickX = PAD_SubStickX(i); + userInput[i].pad.substickY = PAD_SubStickY(i); + userInput[i].pad.triggerL = PAD_TriggerL(i); + userInput[i].pad.triggerR = PAD_TriggerR(i); + + if(Settings.rumble == RumbleOn) + DoRumble(i); + } +} + +/**************************************************************************** + * SetupPads + * + * Sets up userInput triggers for use + ***************************************************************************/ +void SetupPads() +{ + PAD_Init(); + WPAD_Init(); + + // read wiimote accelerometer and IR data + WPAD_SetDataFormat(WPAD_CHAN_ALL,WPAD_FMT_BTNS_ACC_IR); + WPAD_SetVRes(WPAD_CHAN_ALL, screenwidth, screenheight); + + for(int i=0; i < 4; i++) + { + userInput[i].chan = i; + } +} + /**************************************************************************** * ShutoffRumble ***************************************************************************/ diff --git a/source/input.h b/source/input.h index b82c6263..ce3c54de 100644 --- a/source/input.h +++ b/source/input.h @@ -17,6 +17,8 @@ extern int rumbleRequest[4]; +void SetupPads(); +void UpdatePads(); void ShutoffRumble(); void DoRumble(int i); diff --git a/source/main.cpp b/source/main.cpp index 516aae96..dc72848a 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -70,7 +70,6 @@ u8 dbvideo =0; int main(int argc, char *argv[]) { MEM2_init(48); - PAD_Init(); InitVideo(); setlocale(LC_ALL, "en.UTF-8"); geckoinit = InitGecko(); @@ -124,7 +123,6 @@ int main(int argc, char *argv[]) printf("\n\tCheck for an existing cIOS"); CheckForCIOS(); - printf("\n\tcIOS = %u (Rev %u)",IOS_GetVersion(), IOS_GetRevision()); // Let's load the cIOS now if(LoadAppCIOS() < 0) @@ -134,6 +132,8 @@ int main(int argc, char *argv[]) Sys_BackToLoader(); } + printf("\n\tLoaded cIOS = %u (Rev %u)",IOS_GetVersion(), IOS_GetRevision()); + printf("\n\tWaiting for USB: "); if (MountWBFS() < 0) { @@ -152,12 +152,9 @@ int main(int argc, char *argv[]) //! Init the rest of the System Sys_Init(); - Wpad_Init(); + SetupPads(); InitAudio(); - WPAD_SetDataFormat(WPAD_CHAN_ALL,WPAD_FMT_BTNS_ACC_IR); - WPAD_SetVRes(WPAD_CHAN_ALL, screenwidth, screenheight); - char *fontPath = NULL; asprintf(&fontPath, "%sfont.ttf", CFG.theme_path); SetupDefaultFont(fontPath); diff --git a/source/menu.cpp b/source/menu.cpp index 2f9b3963..dda4acf2 100644 --- a/source/menu.cpp +++ b/source/menu.cpp @@ -106,72 +106,74 @@ void HaltGui() { * * Primary thread to allow GUI to respond to state changes, and draws GUI ***************************************************************************/ -static void * UpdateGUI (void *arg) { - while (1) { - if (guiHalt) { +static void * UpdateGUI (void *arg) +{ + int i; + + while (!ExitRequested) + { + if (guiHalt) + { LWP_SuspendThread(guithread); + continue; } - else { - if (!ExitRequested) { - mainWindow->Draw(); - if (Settings.tooltips == TooltipsOn && THEME.show_tooltip != 0 && mainWindow->GetState() != STATE_DISABLED) - mainWindow->DrawTooltip(); - for (int i=3; i >= 0; i--) { // so that player 1's cursor appears on top! - if (userInput[i].wpad.ir.valid) - Menu_DrawImg(userInput[i].wpad.ir.x-48, userInput[i].wpad.ir.y-48, 200.0, - 96, 96, pointer[i]->GetImage(), userInput[i].wpad.ir.angle, CFG.widescreen? 0.8 : 1, 1, 255,0,0,0,0,0,0,0,0); - if (Settings.rumble == RumbleOn) { - DoRumble(i); - } - } + mainWindow->Draw(); + if (Settings.tooltips == TooltipsOn && THEME.show_tooltip != 0 && mainWindow->GetState() != STATE_DISABLED) + mainWindow->DrawTooltip(); - Menu_Render(); - - for (int i=0; i < 4; i++) - mainWindow->Update(&userInput[i]); - - if(bgMusic) - bgMusic->UpdateState(); - - } else { - for (int a = 5; a < 255; a += 10) { - if (strcmp(headlessID,"")==0) - mainWindow->Draw(); - Menu_DrawRectangle(0,0,screenwidth,screenheight,(GXColor) {0, 0, 0, a},1); - Menu_Render(); - } - mainWindow->RemoveAll(); - ShutoffRumble(); - return 0; + for (i = 3; i >= 0; i--) + { + if (userInput[i].wpad.ir.valid) + { + Menu_DrawImg(userInput[i].wpad.ir.x-48, userInput[i].wpad.ir.y-48, 200.0, + 96, 96, pointer[i]->GetImage(), userInput[i].wpad.ir.angle, CFG.widescreen? 0.8 : 1, 1, 255,0,0,0,0,0,0,0,0); } } - switch (Settings.screensaver) { - case 1: - WPad_SetIdleTime(180); - break; - case 2: - WPad_SetIdleTime(300); - break; - case 3: - WPad_SetIdleTime(600); - break; - case 4: - WPad_SetIdleTime(1200); - break; - case 5: - WPad_SetIdleTime(1800); - break; - case 6: - WPad_SetIdleTime(3600); - break; + Menu_Render(); + UpdatePads(); + + for (i=0; i < 4; i++) + mainWindow->Update(&userInput[i]); + + if(bgMusic) + bgMusic->UpdateState(); + + switch (Settings.screensaver) + { + case 1: + WPad_SetIdleTime(180); + break; + case 2: + WPad_SetIdleTime(300); + break; + case 3: + WPad_SetIdleTime(600); + break; + case 4: + WPad_SetIdleTime(1200); + break; + case 5: + WPad_SetIdleTime(1800); + break; + case 6: + WPad_SetIdleTime(3600); + break; } - - - } + + for (i = 5; i < 255; i += 10) + { + if (strcmp(headlessID,"")==0) + mainWindow->Draw(); + Menu_DrawRectangle(0,0,screenwidth,screenheight,(GXColor) {0, 0, 0, i},1); + Menu_Render(); + } + mainWindow->RemoveAll(); + ShutoffRumble(); + return NULL; } @@ -181,7 +183,7 @@ static void * UpdateGUI (void *arg) { * Startup GUI threads ***************************************************************************/ void InitGUIThreads() { - LWP_CreateThread(&guithread, UpdateGUI, NULL, NULL, 32768, LWP_PRIO_HIGHEST); + LWP_CreateThread(&guithread, UpdateGUI, NULL, NULL, 65536, LWP_PRIO_HIGHEST); InitProgressThread(); InitNetworkThread(); diff --git a/source/settings/Settings.cpp b/source/settings/Settings.cpp index 3281d9f3..c70396f3 100644 --- a/source/settings/Settings.cpp +++ b/source/settings/Settings.cpp @@ -78,7 +78,7 @@ int MenuSettings() int opt_override = Settings.titlesOverride; // backup partition index u8 settingspartitionold = Settings.partition; - + enum { @@ -293,8 +293,9 @@ int MenuSettings() GuiWindow w(screenwidth, screenheight); int pageToDisplay = 1; - while ( pageToDisplay > 0) { //set pageToDisplay to 0 to quit - VIDEO_WaitVSync (); + while ( pageToDisplay > 0) + { + usleep(100); menu = MENU_NONE; @@ -611,7 +612,7 @@ int MenuSettings() while (menu == MENU_NONE) { - VIDEO_WaitVSync (); + usleep(100); if (shutdown == 1) Sys_Shutdown(); @@ -645,7 +646,6 @@ int MenuSettings() optionBrowser2.SetClickable(true); ResumeGui(); - VIDEO_WaitVSync (); optionBrowser2.SetEffect(EFFECT_FADE, 20); while (optionBrowser2.GetEffect() > 0) usleep(50); @@ -656,7 +656,7 @@ int MenuSettings() bool firstRun = true; while (!exit) { - VIDEO_WaitVSync (); + usleep(100); returnhere = 1; @@ -867,7 +867,7 @@ int MenuSettings() static const char *opts[settings_screensaver_max] = {trNOOP("OFF"),trNOOP("3 min"),trNOOP("5 min"),trNOOP("10 min"),trNOOP("20 min"),trNOOP("30 min"),trNOOP("1 hour")}; options2.SetValue(Idx,"%s",tr(opts[Settings.screensaver])); } - + if(ret == ++Idx || firstRun) { if(firstRun) options2.SetName(Idx, "%s",tr("Mark new games")); @@ -913,14 +913,13 @@ int MenuSettings() optionBrowser2.SetClickable(true); ResumeGui(); - VIDEO_WaitVSync (); optionBrowser2.SetEffect(EFFECT_FADE, 20); while (optionBrowser2.GetEffect() > 0) usleep(50); bool firstRun = true; while (!exit) { - VIDEO_WaitVSync (); + usleep(100); if (shutdown == 1) Sys_Shutdown(); @@ -1012,7 +1011,7 @@ int MenuSettings() else options2.SetValue(Idx, "********"); } - + if (ret == ++Idx || firstRun) { if (firstRun) options2.SetName(Idx, "%s", tr("Partition")); @@ -1024,16 +1023,16 @@ int MenuSettings() } while (!IsValidPartition(partitions.pinfo[Settings.partition].fs_type, Settings.cios)); } - + PartInfo pInfo = partitions.pinfo[Settings.partition]; f32 partition_size = partitions.pentry[Settings.partition].size * (partitions.sector_size / GB_SIZE); - + // Get the partition name and it's size in GB's options2.SetValue(Idx,"%s%d (%.2fGB)", pInfo.fs_type == FS_TYPE_FAT32 ? "FAT" : pInfo.fs_type == FS_TYPE_NTFS ? "NTFS" : "WBFS", pInfo.index, partition_size); } - + if (ret == ++Idx || firstRun) { if (firstRun) options2.SetName(Idx, "%s", tr("FAT: Use directories")); @@ -1111,14 +1110,13 @@ int MenuSettings() optionBrowser2.SetClickable(true); ResumeGui(); - VIDEO_WaitVSync (); optionBrowser2.SetEffect(EFFECT_FADE, 20); while (optionBrowser2.GetEffect() > 0) usleep(50); bool firstRun = true; while (!exit) { - VIDEO_WaitVSync (); + usleep(100); if (shutdown == 1) Sys_Shutdown(); @@ -1168,7 +1166,7 @@ int MenuSettings() { char entered[20]; memset(entered, 0, 20); - + //password check to unlock Install,Delete and Format w.Remove(&optionBrowser2); w.Remove(&backBtn); @@ -1281,7 +1279,6 @@ int MenuSettings() optionBrowser2.SetClickable(true); ResumeGui(); - VIDEO_WaitVSync (); optionBrowser2.SetEffect(EFFECT_FADE, 20); while (optionBrowser2.GetEffect() > 0) usleep(50); @@ -1289,7 +1286,7 @@ int MenuSettings() bool firstRun = true; while (!exit) { - VIDEO_WaitVSync (); + usleep(100); bool returnhere = true; @@ -1335,9 +1332,9 @@ int MenuSettings() w.SetEffect(EFFECT_FADE, -20); while (w.GetEffect()>0) usleep(50); mainWindow->Remove(&w); - + returnhere = MenuBackgroundMusic(); - + HaltGui(); mainWindow->Append(&w); w.SetEffect(EFFECT_FADE, 20); @@ -1346,7 +1343,7 @@ int MenuSettings() } else WindowPrompt(tr("No SD-Card inserted!"),tr("Insert an SD-Card to use this option."),tr("OK")); } - + char * filename = strrchr(Settings.ogg_path, '/'); if(filename) { @@ -1424,7 +1421,7 @@ int MenuSettings() else options2.SetValue(Idx,"%s", tr("OFF")); } - + if(ret == ++Idx || firstRun) { if(firstRun) options2.SetName(Idx, "%s",tr("Music Loop Mode")); @@ -1460,7 +1457,7 @@ int MenuSettings() } options2.SetValue(Idx,tr(" ")); } - + firstRun = false; } } @@ -1501,7 +1498,6 @@ int MenuSettings() optionBrowser2.SetClickable(true); ResumeGui(); - VIDEO_WaitVSync (); optionBrowser2.SetEffect(EFFECT_FADE, 20); while (optionBrowser2.GetEffect() > 0) usleep(50); @@ -1510,7 +1506,7 @@ int MenuSettings() bool firstRun = true; while (!exit) { - VIDEO_WaitVSync (); + usleep(100); if (shutdown == 1) Sys_Shutdown(); @@ -1926,7 +1922,7 @@ int MenuSettings() } options2.SetValue(Idx, "%s", Settings.BcaCodepath); } - + if(ret == ++Idx || firstRun) { if(firstRun) options2.SetName(Idx, "%s", tr("WIP Patches Path")); @@ -2096,6 +2092,7 @@ int MenuSettings() cfg_save_global(); menu = MENU_DISCLIST; pageToDisplay = 0; + backBtn.ResetState(); break; } @@ -2184,14 +2181,14 @@ int MenuSettings() w.SetEffect(EFFECT_FADE, -20); while (w.GetEffect()>0) usleep(50); - // if partition has changed, Reinitialize it + // if partition has changed, Reinitialize it if (Settings.partition != settingspartitionold) { PartInfo pinfo = partitions.pinfo[Settings.partition]; partitionEntry pentry = partitions.pentry[Settings.partition]; WBFS_OpenPart(pinfo.part_fs, pinfo.index, pentry.sector, pentry.size, (char *) &game_partition); load_from_fs = pinfo.part_fs; } - + // if language has changed, reload titles char opt_langnew[100]; strcpy(opt_langnew,Settings.language_path); @@ -2380,8 +2377,9 @@ int GameSettings(struct discHdr * header) struct Game_CFG* game_cfg = CFG_get_game_opt(header->id); int pageToDisplay = 1; - while ( pageToDisplay > 0) { //set pageToDisplay to 0 to quit - VIDEO_WaitVSync (); + while ( pageToDisplay > 0) + { + usleep(100); menu = MENU_NONE; @@ -2466,7 +2464,7 @@ int GameSettings(struct discHdr * header) iosChoice = i250; else if (Settings.cios == ios223) iosChoice = i223; - else + else iosChoice = i249; parentalcontrolChoice = 0; fix002 = Settings.error002; @@ -2485,7 +2483,7 @@ int GameSettings(struct discHdr * header) while (menu == MENU_NONE) { - VIDEO_WaitVSync (); + usleep(100); if (shutdown == 1) Sys_Shutdown(); @@ -2512,7 +2510,6 @@ int GameSettings(struct discHdr * header) optionBrowser2.SetClickable(true); ResumeGui(); - VIDEO_WaitVSync (); optionBrowser2.SetEffect(EFFECT_FADE, 20); while (optionBrowser2.GetEffect() > 0) usleep(50); @@ -2523,7 +2520,7 @@ int GameSettings(struct discHdr * header) bool firstRun = true; while (!exit) { - VIDEO_WaitVSync (); + usleep(100); returnhere = 1; @@ -2798,7 +2795,7 @@ int GameSettings(struct discHdr * header) while (!exit) { - VIDEO_WaitVSync (); + usleep(100); if (shutdown == 1) Sys_Shutdown(); @@ -3012,6 +3009,7 @@ int GameSettings(struct discHdr * header) { menu = MENU_DISCLIST; pageToDisplay = 0; + backBtn.ResetState(); break; } diff --git a/source/video.cpp b/source/video.cpp index 2d9f2a50..782c897e 100644 --- a/source/video.cpp +++ b/source/video.cpp @@ -33,33 +33,6 @@ u32 frameCount = 0; u8 * gameScreenTex = NULL; // a GX texture screen capture of the game u8 * gameScreenTex2 = NULL; // a GX texture screen capture of the game (copy) -/**************************************************************************** - * UpdatePadsCB - * - * called by postRetraceCallback in InitGCVideo - scans gcpad and wpad - ***************************************************************************/ -static void -UpdatePadsCB () { - frameCount++; - WPAD_ScanPads(); - PAD_ScanPads(); - - for (int i=3; i >= 0; i--) { - memcpy(&userInput[i].wpad, WPAD_Data(i), sizeof(WPADData)); - - userInput[i].chan = i; - userInput[i].pad.btns_d = PAD_ButtonsDown(i); - userInput[i].pad.btns_u = PAD_ButtonsUp(i); - userInput[i].pad.btns_h = PAD_ButtonsHeld(i); - userInput[i].pad.stickX = PAD_StickX(i); - userInput[i].pad.stickY = PAD_StickY(i); - userInput[i].pad.substickX = PAD_SubStickX(i); - userInput[i].pad.substickY = PAD_SubStickY(i); - userInput[i].pad.triggerL = PAD_TriggerL(i); - userInput[i].pad.triggerR = PAD_TriggerR(i); - } -} - /**************************************************************************** * StartGX * @@ -182,9 +155,6 @@ InitVideo () { VIDEO_ClearFrameBuffer (vmode, xfb[1], COLOR_BLACK); VIDEO_SetNextFramebuffer (xfb[0]); - // video callback - VIDEO_SetPostRetraceCallback ((VIRetraceCallback)UpdatePadsCB); - VIDEO_SetBlack (FALSE); VIDEO_Flush (); VIDEO_WaitVSync (); @@ -251,6 +221,7 @@ void Menu_Render() { VIDEO_SetNextFramebuffer(xfb[whichfb]); VIDEO_Flush(); VIDEO_WaitVSync(); + frameCount++; } /****************************************************************************