Вы находитесь на странице: 1из 5

S.M.B.I.I.

: SAVE MY BATTERY INTELLIGENTLY INMEDIATELY


PLUG-IN PARA AHORRO DE BATERÍA PARA LA PSP CUANDO SE VIAJA

NELSON G. LOMBARDO

Resumen. Este trabajo tiene la finalidad de poder documentar el plug-in SMBII para PsP. Intenta dejar información
sobre el plug-in como así ciertos tips técnicos y demás.

1. Motivación
Luego de revisar, encontré muchos plugins que hacen lo mismo, pero todos utilizaban configuraciones por pantalla
y combinaciones de teclas que no me agradaban. Decidí entonces, construir una versión ligera del afamado SMB1. Este
contiene en su primer release, un concepto asociado sencillo:
Sin configuración.
Sin información por pantalla.
Captura de las teclas no agobiantes.
No apaga la PsP.

2. ¿Para qué sirve?


Si tienes que viajar, y necesitar extender algunos minutos más tu batería, este puede ser tu plug-in.
Toma la ejecución normal de tus back-ups y homebrews, y si después de algunos segundos no has usado ningún
botón, la pantalla se ira “apagando” y el clock del CPU irá disminuyendo hasta unos 25 MHz.
Al iniciar la pantalla se pondrá 14 de potencia, y siempre estará a este nivel, excepto cuando no uses al PsP...
El plug-in no permite que se apague la PsP, el plug-in se esta escribiendo con la finalidad de extender el uso de la
batería mientras usamos nuestro equipo en un viaje. Si quieres que se apague, te invito a que recurras a otros plug-ins
o bien otros métodos.

3. Teoría de funcionamiento
3.1. Idea. Bueno la figura 3.1 nos representa la idea, el concepto por el que me guíe.
Profundizando un poco más sobre el funcionamiento del bucle, podemos observar el diagrama de flujo del mismo
en la figura 3.2.
3.2. El dilema en la lectura de los botones. Bueno, como el principio de funcionamiento del plug-in es no
interceder en el funcionamiento sino sólo en el ahorro de energía, es fundamental que la revisión del uso de los botones
sea de manera transparente.
En busca de hacer la captura transparente y de una forma reutilizable, pude por suerte la misma duda en los foros
de QJ, y uno de los grandes maestros de la scene la contesta. En las referencias pueden encontrar al información.
En este caso aumente el tiempo en que el bucle se ejecuta y utilice la función “sceCtrlPeekBufferPositive”.
3.3. Modo de depuración. El plug-in se puede compilar para que aporte alguna información del funcionamiento
y así depurarlo en caso de hacer modificaciones. Para acceder a esto, se cambia el valor de debugmode al principio por
1 y se compila con el “modo” depuración, con 0 compilas normalmente.

4. El código del plug-in

/∗ SMBII 0 . 0 . 0 _06012011 ( s u p e r a l p h a v e r s i o n )

∗ L i c e n s e d under GPL v2 .
∗ Author : n e l s o n . lombardo@gmail . com
∗ Blog : h t t p : / / e t e c h −n e l s o n . b l o g s p o t . com/
∗ Tag : SMBII

∗ Info :
∗ This i s a l i g h t v e r s i o n o f t h e SMB p l u g i n .
∗ This p l u g i n was c r e a t e d f o r use when you t r a v e l i n g .
∗ Maximize t h e use o f b a t t e r y i s e s s e n c i a l !
∗ You don ’ t g e t a s c r e e n i n f o r m a t i o n , don ’ t can c o n f i g u r e them w i t h t h e b u t t o n s , n o t h i n g .
∗ A c t i v e t h e p l u g i n and make y o u r s e l f t o p l a y your f a v o r i t e games or homebrews .
∗ Him make t h e r e s t . . . ; )
∗/
#d e f i n e debugmode 0
#include < s t d l i b . h>
#include <t i m e . h>

Date: 06/01/2011.
1
http://hakuryu188-dev.blogspot.com/

i
Figura 3.1. Capa superior del diagrama de flujo.

#include <math . h>


#include <p s p k e r n e l . h>
#include <p s p c t r l . h>
#include <psppower . h>
#i f ( debugmode==1)
#include <pspdebug . h>
#include <p s p d i s p l a y . h>
#e n d i f
// Some d e f i n e t o h e l p w r i t e t h e code
#d e f i n e DEATHZONE 50
#d e f i n e HALFZONE 127
// FIVE_SECS ∗ DELTA ~ 6 s e c o n d s
#d e f i n e SECS 60
#d e f i n e DELTA 100000
#d e f i n e ON 1
#d e f i n e OFF 0
// E x i s t s 8 l e v e l s o f cpu c l o c k s . . .
#d e f i n e CPU1 20
#d e f i n e CPU2 75
#d e f i n e CPU3 100
#d e f i n e CPU4 133
#d e f i n e CPU5 222
#d e f i n e CPU6 266
#d e f i n e CPU7 300
#d e f i n e CPU8 333
// C r e a t i n g a p rx module
PSP_MODULE_INFO( "PRX" , 0 x1000 , 1 , 1 ) ;
PSP_MAIN_THREAD_ATTR( 0 ) ;
// Function p r o t o t y p e s :
void S e t t i n g C p u C l o c k ( unsigned char t i m e s ) ; // S e t t i n g t h e Cpu C l o c k s
void SettingLEDs ( unsigned char LED) ;
unsigned char I n i t T i m e s ( i n t CPU) ;
// The ’ main ’ f u n c t i o n
i n t main_thread ( S c e S i z e a r g s , void ∗ a r g p )
{
unsigned char t i m e s , t , maxtime ;
int c u r r e n t l e v e l , r e t ;
S c e C t r l D a t a pad , o l d p a d ;
sceCtrlSetSamplingCycle (0) ;
s c e C t r l S e t S a m p l i n g M o d e (PSP_CTRL_MODE_ANALOG) ;
// s i x s e c o n d s t o s t a r t !
sceKernelDelayThread (10000000) ;
// I need g e t t h e c l o c k s a t t h e f i r s t time . . .
t = InitTime s ( scePowerGetCpuClockFrequencyInt ( ) ) ;
s c e C t r l P e e k B u f f e r P o s i t i v e (& oldpad , 1 ) ;
times = t ;
maxtime = 0 ;
#i f ( debugmode==1)
pspDebugScreenInit () ;
p s p D e b u g S c r e e n S e t B a c k C o l o r ( 0xFFFFFFFF) ;
p s p D e b u g S c r e e n S e t T e x t C o l o r ( 0 x0 00 00 00 0 ) ;
#e n d i f
// The main l o o p .

ii
Figura 3.2. Conceptualizando el bucle principal.

while ( 1 )
{
#i f ( debugmode==1)
pspDebugScreenSetXY ( 0 , 0 ) ;
p s p D e b u g S c r e e n P r i n t f ( " SMBII r u n n i n g . . . %d %d %d " , maxtime , t i m e s , t ) ;
#e n d i f
ret = 0;
s c e C t r l P e e k B u f f e r P o s i t i v e (&pad , 1 ) ;
i f ( ( pad . Ly < (HALFZONE−DEATHZONE) ) | | ( pad . Ly > (HALFZONE+DEATHZONE) ) ) { r e t ++;}
i f ( ( pad . Lx < (HALFZONE−DEATHZONE) ) | | ( pad . Lx > (HALFZONE+DEATHZONE) ) ) { r e t ++;}
// Check a l l b u t t o n s . . .
i f ( ( pad . B u t t o n s & PSP_CTRL_VOLDOWN && ! ( o l d p a d . B u t t o n s & PSP_CTRL_VOLDOWN) ) | |
( ( pad . B u t t o n s & PSP_CTRL_VOLUP) && ! ( o l d p a d . B u t t o n s & PSP_CTRL_VOLUP) ) | |
( ( pad . B u t t o n s & PSP_CTRL_HOME) && ! ( o l d p a d . B u t t o n s & PSP_CTRL_HOME) ) | |
( ( pad . B u t t o n s & PSP_CTRL_START) && ! ( o l d p a d . B u t t o n s & PSP_CTRL_START) ) | |
( ( pad . B u t t o n s & PSP_CTRL_SELECT) && ! ( o l d p a d . B u t t o n s & PSP_CTRL_SELECT) ) | |
( ( pad . B u t t o n s & PSP_CTRL_SCREEN) && ! ( o l d p a d . B u t t o n s & PSP_CTRL_SCREEN) ) | |
( ( pad . B u t t o n s & PSP_CTRL_NOTE) && ! ( o l d p a d . B u t t o n s & PSP_CTRL_NOTE) ) | |
( ( pad . B u t t o n s & PSP_CTRL_RTRIGGER) && ! ( o l d p a d . B u t t o n s & PSP_CTRL_RTRIGGER) ) ||
( ( pad . B u t t o n s & PSP_CTRL_LTRIGGER) && ! ( o l d p a d . B u t t o n s & PSP_CTRL_LTRIGGER) ) ||
( ( pad . B u t t o n s & PSP_CTRL_CROSS) && ! ( o l d p a d . B u t t o n s & PSP_CTRL_CROSS) ) | |

iii
( ( pad . B u t t o n s & PSP_CTRL_CIRCLE) && ! ( o l d p a d . B u t t o n s & PSP_CTRL_CIRCLE) ) | |
( ( pad . B u t t o n s & PSP_CTRL_TRIANGLE) && ! ( o l d p a d . B u t t o n s & PSP_CTRL_TRIANGLE) ) | |
( ( pad . B u t t o n s & PSP_CTRL_SQUARE) && ! ( pad . B u t t o n s & PSP_CTRL_SQUARE) ) | |
( ( pad . B u t t o n s & PSP_CTRL_UP) && ! ( o l d p a d . B u t t o n s & PSP_CTRL_UP) ) | |
( ( pad . B u t t o n s & PSP_CTRL_DOWN) && ! ( o l d p a d . B u t t o n s & PSP_CTRL_DOWN) ) | |
( ( pad . B u t t o n s & PSP_CTRL_LEFT) && ! ( o l d p a d . B u t t o n s & PSP_CTRL_LEFT) ) | |
( ( pad . B u t t o n s & PSP_CTRL_RIGHT) && ! ( o l d p a d . B u t t o n s & PSP_CTRL_RIGHT) ) ) { r e t ++;}
if ( r e t >0)
{
times = t ;
maxtime = 0 ;
SettingCpuClock ( times ) ; // CPU c l o c k l o w e r
sceDisplaySetBrightness (25 , 0) ;
}
if ( maxtime == SECS)
{
s c e P o w e r T i c k (PSP_POWER_TICK_DISPLAY) ;
i f ( s c e P o w e r G e t B a t t e r y L i f e P e r c e n t ( ) <30) { SettingLEDs (OFF) ; }
e l s e { SettingLEDs (ON) ; }
t i m e s ++;
i f ( times > 8) { times = 8 ; }
SettingCpuClock ( times ) ; // CPU c l o c k l o w e r
s c e D i s p l a y S e t B r i g h t n e s s ( 1 6 / t i m e s −2 ,0) ;
maxtime = 0 ;
}
e l s e { maxtime++; }
// End o f Trend B a t t e r y //
s c e K e r n e l D e l a y T h r e a d (DELTA) ; // 100 uSeconds
o l d p a d = pad ;
}
return 0 ;
}
// Part o f code
i n t m o d u l e _ s t a r t ( S c e S i z e a r g s , void ∗ a r g p )
{
i n t t h i d = s c e K e r n e l C r e a t e T h r e a d ( "PRX" , main_thread , 0 x30 , 0 x1000 , 0 , NULL) ;
i f ( t h i d >= 0 ) s c e K e r n e l S t a r t T h r e a d ( t h i d , a r g s , a r g p ) ;
return 0 ;
}
void S e t t i n g C p u C l o c k ( unsigned char t i m e s )
{
switch ( t i m e s )
{
case 1 :
s c e P o w e r S e t C l o c k F r e q u e n c y (CPU8, CPU8, CPU8/ 2 ) ;
break ;
case 2 :
s c e P o w e r S e t C l o c k F r e q u e n c y (CPU7, CPU7, CPU7/ 2 ) ;
break ;
case 3 :
s c e P o w e r S e t C l o c k F r e q u e n c y (CPU6, CPU6, CPU6/ 2 ) ;
break ;
case 4 :
s c e P o w e r S e t C l o c k F r e q u e n c y (CPU5, CPU5, CPU5/ 2 ) ;
break ;
case 5 :
s c e P o w e r S e t C l o c k F r e q u e n c y (CPU4, CPU4, CPU4/ 2 ) ;
break ;
case 6 :
s c e P o w e r S e t C l o c k F r e q u e n c y (CPU3, CPU3, CPU3/ 2 ) ;
break ;
case 7 :
s c e P o w e r S e t C l o c k F r e q u e n c y (CPU2, CPU2, CPU2/ 2 ) ;
break ;
case 8 :
s c e P o w e r S e t C l o c k F r e q u e n c y (CPU1, CPU1, CPU1/ 2 ) ;
break ;
}
}

unsigned char I n i t T i m e s ( i n t CPU)


{
i f ( (CPU <= CPU8)&&(CPU > CPU7) ) { return 1;}
i f ( (CPU <= CPU7)&&(CPU > CPU6) ) { return 2;}
i f ( (CPU <= CPU6)&&(CPU > CPU5) ) { return 3;}
i f ( (CPU <= CPU5)&&(CPU > CPU4) ) { return 4;}
i f ( (CPU <= CPU4)&&(CPU > CPU3) ) { return 5;}
i f ( (CPU <= CPU3)&&(CPU > CPU2) ) { return 6;}
i f ( (CPU <= CPU2)&&(CPU > CPU1) ) { return 7;}
i f (CPU <= CPU1) { return 8;}
return 1 ;
}
// LED ’ s On or O f f . . .
void SettingLEDs ( unsigned char LED)
{
sc eS ysc on Ct r l L E D ( 1 , LED) ;
sc eS ysc on Ct r l L E D ( 2 , LED) ;
sc eS ysc on Ct r l L E D ( 0 , LED) ;
}

iv
5. Instalación
Para la instalación tomas el archivo SMBII.prx y lo copias dentro de:
ms0 : / SEPLUGINS/

Luego dentro de esta carpeta existen 3 archivos (de no existir lo creas), llamados:
GAME. t x t
GAME150 . t x t
VHS. t x t
POPS . t x t

Dentro de estos archivos agregas el texto:


ms0 : / SEPLUGINS/SMBII . prx 1

Y según sea el archivo donde lo agregas, será donde se ejecutara el plug-in. O sea, si lo agregas a VHS.txt, cuando
entres al XMB se ejecutará. Para deshabilitar lo cambias por:
ms0 : / SEPLUGINS/SMBII . prx 0

O utilizas el menú recovery de tu CFW.

6. Difusión
2
Los chicos de TPS me están ayudando con la difusión del plug-in. Son una nueva comunidad de homebrew para la
PsP y están intentando trabajar de forma diferente a otras comunidades.

7. Licencia
Este texto y el plug-in esta bajo la GPL3 v3 o superior según sea el caso. Siempre manteniendo mi libertad y la
suya como pilar fundamental para la transmición del conocimiento.

8. Versión
0.0.0_06012011

Referencias
[1] http://forums.qj.net/zx-81s-homebrew-releases/146232-development-question.html
[2] http://psp.jim.sh/pspsdk-doc/group__Ctrl.html

E-mail address: nelson.lombardo@gmail.com


URL: http://etech-nelson.blogspot.com/

2
http://totalpspscene.ucoz.com/
3
http://www.gnu.org/licenses/gpl.html

Вам также может понравиться