Seite 2 von 4 ErsteErste 1 2 3 4 LetzteLetzte
Zeige Ergebnis 31 bis 60 von 99

Post some C samples

This is a discussion on Post some C samples within the Developer's Dungeon forums, part of the PSP Development Forum category; here is an example of rebooting the PSP (THERE ARE 100 ways ) I found this one the best: scepower.S ...

  
  1. #31
    The Unique Developer
    Points: 7.101, Level: 55
    Level completed: 76%, Points required for next Level: 49
    Overall activity: 0%

    Registriert seit
    Oct 2006
    Ort
    Canada
    Beiträge
    1.059
    Points
    7.101
    Level
    55
    Downloads
    0
    Uploads
    0

    Standard

    here is an example of rebooting the PSP (THERE ARE 100 ways ) I found this one the best:


    scepower.S
    Code:
    .set noreorder
    
    #include "pspstub.s"
    
    STUB_START "scePower", 0x40010000, 0x20005
    STUB_FUNC 0x0442D852, scePower_0442D852
    STUB_END
    scepower.h
    Code:
    #ifndef PSP_POWER_H
    #define PSP_POWER_H
    
    
    #ifdef __cplusplus
    extern "C" {
    #endif
    /*
    Simply reboots the PSP
    @code
    @unknown - unknown just pass 50000 or any more then 0 only tested that
    
    */
    
    int scePower_0442D852(int unknown);
    
    #ifdef __cplusplus
    }
    #endif
    
    #endif
    usage:
    Code:
    //this should work tested 100% success
    scePower_0442D852(50000);
    Thanks to moonlight for finding the functions address .....

    Best,
    TUW


    Malloc.Us Network Administrator

    Decryption of the Encrypted


    You are the unseen, the unstoppable and in power of your code. The God of your software.

  2. #32
    Developer
    Points: 5.661, Level: 48
    Level completed: 56%, Points required for next Level: 89
    Overall activity: 0%

    Registriert seit
    Mar 2006
    Beiträge
    134
    Points
    5.661
    Level
    48
    Downloads
    0
    Uploads
    0

    Standard

    Does anybody have a function to do a FloodFill like you get in paint applications...?

    If there is one kicking around it would really save me some time...

    Cheers
    ADePSP
    Geändert von ADePSP (12-14-2006 um 11:44 AM Uhr)

  3. #33
    Art
    Art ist offline
    Bush Programmer
    Points: 60.149, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Overall activity: 0%

    Registriert seit
    Nov 2005
    Beiträge
    3.658
    Points
    60.149
    Level
    100
    Downloads
    0
    Uploads
    0

    Standard

    That's interesting.. I just came to ask for the same thing.
    I want a routine to floodfill circles.

  4. #34
    Your Fate is Grim...
    Points: 11.640, Level: 70
    Level completed: 98%, Points required for next Level: 10
    Overall activity: 0%

    Registriert seit
    Oct 2005
    Beiträge
    2.269
    Points
    11.640
    Level
    70
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von ADePSP
    Does anybody have a function to do a FloodFill like you get in paint applications...?

    If there is one kicking around it would really save me some time...

    Cheers
    ADePSP

    well the concept isnt too hard. just take a point, and go in a circular motion around it until you hit a pixel taht not the same color. im oo lazy to write actual code.
    --------------------------------------------------------------------------------------

  5. #35
    Art
    Art ist offline
    Bush Programmer
    Points: 60.149, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Overall activity: 0%

    Registriert seit
    Nov 2005
    Beiträge
    3.658
    Points
    60.149
    Level
    100
    Downloads
    0
    Uploads
    0

    Standard

    That's not how it's done, that would be slow as hell.
    the filling is done in pixel wide horizontal lines.
    You can see a floodfill happening live on a computer that is old and slow enough.

  6. #36
    Developer
    Points: 5.569, Level: 48
    Level completed: 10%, Points required for next Level: 181
    Overall activity: 0%

    Registriert seit
    Aug 2005
    Beiträge
    119
    Points
    5.569
    Level
    48
    Downloads
    0
    Uploads
    0

    Standard

    If your doing a lot of matrix math in your app, it might help to speed up things a bit with the help of the VFPU on the psp. The VFPU is a special coprocessor that deals specifically with vector and matrix math, and trig functions as well.

    For example, I use this routine a lot in my game SnakeSP to translate and rotate the snake segments in one shot:

    Code:
    void matTransRotZ(ScePspFMatrix4 *m, ScePspFVector3 *t, float rz)
    {
    	__asm__ volatile (
    		"vmidt.q M200\n"
    		"ulv.q   C100, %1\n"
    		"vmov.t  C230, C100\n"
    		// M200 = translation matrix
    
    		"mtv  %2, S100\n"
    		"vcst.s S101, VFPU_2_PI\n"
    		"vmul.s S100, S101, S100\n"
    		"vrot.q C000, S100, [ c, s, 0, 0]\n"
    		"vrot.q C010, S100, [-s, c, 0, 0]\n"
    		// M000 = rotate Z matrix
    		"vmmul.q M100, M200, M000\n"
    		// M100 = final trans/rotate matrix
    
    		"usv.q C100,  0 + %0\n"
    		"usv.q C110, 16 + %0\n"
    		"usv.q C120, 32 + %0\n"
    		"usv.q C130, 48 + %0\n"
    		: "+m"(*m) : "m"(*t), "r"(rz));
    }
    
    ScePspFMatrix4 mModel;
    ScePspFVector3 trans = { -1.0f, 2.0f, -30.0f };
    
    matTransRotz(&mModel, &trans, 45 * (GU_PI/180.0f));
    sceGuSetMatrix(GU_MODEL, &mModel);
    Another little routine I use that does sin and cos in one shot (way faster than calling sinf/cosf seperately on same angle)

    Code:
    void vsincos(ScePspFVector4 *result, float r) {
    	__asm__ volatile (
    		"mtv %1, S100\n"
    		"vcst.s S101, VFPU_2_PI\n"
    		"vmul.s S100, S101, S100\n"
    		"vrot.q C110, S100, [ s, c, 0, 0]\n"
    		"usv.q C110, 0 + %0\n"
    		: "+m"(*result) : "r"(r));
    }
    
    ScePspFVector4 res;
    float f, triglut[256][2];
    int x;
    
    for (x=0; x<256; x++) {
       f = x * ((M_PI*2)/256.0f);
       vsincos(&res, f);
       triglut[x][0] = res.x; // sin value in x component
       triglut[x][1] = res.y; // cos value in y component
    }
    Some other tips to improve performance when dealing with floating point math:

    1) Stay away from doubles. The psp has hardware that can only handle 32 bit floats, and the vfpu also works with 32bit floats...when you introduce doubles, gcc will step in and throw in emulated code to handle them. The psp has no native support for double.
    2) use the f versions of math functions...for example: sinf, cosf, floorf, atan2f...without those f's, you are really telling the compiler to use the double versions of those functions, again hitting performance with emulated code.
    3) on any floating point constants, use the f postfix character..like 3.0f, 0.5f. Without it, gcc will generate double format numbers, again using emulated code to handle them.
    4) avoid divides where you can. Its much faster to multiply with the inverse of a number. For example:

    f = x / 4.0f;

    can be rewritten as:

    f = x * 0.25f; // 1/4 = 0.25

    To give an idea of how drastic an improvement these tips produce...the first builds of my game, SnakeSP, could not handle more than 70 segments on screen before framerates dropped. Someone pointed out to me to switch to all floats, and now the game can draw 300 translated, rotated segments at 60 frames per second..I've yet to see the game slow down on me, and I've heard of longer chains with no slowdown.

    EDIT: I'm putting together a collection of all the little helper routines I use in my projects. If you want, I'll post here

    Zitat Zitat von ADePSP
    Does anybody have a function to do a FloodFill like you get in paint applications...?

    If there is one kicking around it would really save me some time...

    Cheers
    ADePSP
    Do a search on google for michael abrash. He published a book a long time ago called Graphics Programming Black Book. That will turn up links to pdf's to the chapters in that book, including quite a few pages describing all sorts of different floodfill algorithms. There's also some pretty good routines in there like fast line drawing, circles, raster polygons, zbuffer techniques, line and polygon clipping, depth sorting...theres a LOT of good material in that book related to graphics programming.
    Geändert von MrMr[iCE] (12-20-2006 um 09:16 PM Uhr) Grund: Automerged Doublepost

  7. #37
    is not posting very often
    Points: 33.152, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Overall activity: 99,6%

    Registriert seit
    Feb 2006
    Ort
    omnipresent
    Beiträge
    5.162
    Points
    33.152
    Level
    100
    Downloads
    0
    Uploads
    0

    Standard

    tuw- what is "pspstub.s"
    What did we think the world would look like in 2015?

    Zitat Zitat von Abe
    Either way, if you don't know, don't guess. Stick to answering questions about stuff you're qualified to answer, like Pokemon questions or something along those lines.
    http://forums.qj.net/501501-post26.html

  8. #38
    QJ Gamer Bronze
    Points: 7.047, Level: 55
    Level completed: 49%, Points required for next Level: 103
    Overall activity: 0%

    Registriert seit
    Jun 2006
    Beiträge
    144
    Points
    7.047
    Level
    55
    Downloads
    0
    Uploads
    0

    Standard

    it's a SDK file. don't bother about it. It just defines the PSP_STUB macros.
    Adrahil - Software architect and specialist in Reverse Engineering.
    Spoiler for Guilt of a Dev:
    17:17 < InsertWittyName> Can't pin user error on a dev ;)
    17:18 < InsertWittyName> Lesson learnt on both sides I would say.
    17:18 < InsertWittyName> You learnt to treat the end-user as a retarded fish.
    17:18 < InsertWittyName> They learnt to read readme's ;)

    Spoiler for me:
    17:12 <+dot_blank> are you the long haired pimp ;)

  9. #39
    QJ Gamer Silver
    Points: 10.263, Level: 67
    Level completed: 54%, Points required for next Level: 187
    Overall activity: 0%

    Registriert seit
    Jun 2006
    Ort
    UK
    Beiträge
    2.326
    Points
    10.263
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    MrMrIce mentioned the Graphics Prgramming Blacnk Book. If anyone is still looking for it, you can find it here:

    http://www.gamedev.net/reference/art...rticle1698.asp

  10. #40
    Heroes never die
    Points: 8.645, Level: 62
    Level completed: 65%, Points required for next Level: 105
    Overall activity: 0%

    Registriert seit
    Aug 2006
    Ort
    ...........
    Beiträge
    1.323
    Points
    8.645
    Level
    62
    Downloads
    0
    Uploads
    0

    Standard

    dunno i just posted it in the help thread so why not here;)
    Code:
    #include <psprtc.h>
    #include <psphprm.h>
    #include <math.h>
    #include <pspkernel.h>
    #include <pspdebug.h>
    #include <pspctrl.h>
    #include <pspdisplay.h>
    
    #define printf pspDebugScreenPrintf
    int getcurrenthour()
    {
    /*by hallo007*/
                        pspTime rtime;
                        sceRtcGetCurrentClockLocalTime(&rtime);
                        int hour = rtime.hour;		
                        return hour;
    }
    int getCurrentMinutes()
    {
    /*by hallo007*/
                        pspTime rtime;
                        sceRtcGetCurrentClockLocalTime(&rtime);
                        int minutes = rtime.minutes;
                        return minutes;
    }
    char * printfCurrentTime()
    {
    /*by hallo007*/
                        char timeText[200];
                        sprintf(timeText , "%i : %i" , getCurrentHour() , getcurrentMinutes());
                        return timetext;
    }

  11. #41
    words are stones in my <3
    Points: 35.274, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    Spokane
    Beiträge
    5.008
    Points
    35.274
    Level
    100
    My Mood
    Lonely
    Downloads
    1
    Uploads
    0

    Standard

    Optimised ;)
    Code:
    #include <psprtc.h>
    #include <psphprm.h> // this really needed for RTC functions?
    
    int getcurrenthour() {
          pspTime rtime;
          sceRtcGetCurrentClockLocalTime(&rtime);
          return int(rtime.hour);
    }
    int getCurrentMinutes() {
          pspTime rtime;
          sceRtcGetCurrentClockLocalTime(&rtime);
          return int(rtime.minutes);
    }
    char *CurrentTime() {
          char timeText[8];
          snprintf(timeText, 8, "%i : %i" , getCurrentHour() , getcurrentMinutes());
          return timeText;
    }
    
    
    ...
    
    //example:
    //printf ( CurrentTime );
    I believe those will work. Just small, not 100% needed otpimizations.

    ...at what speed must I live.. to be able to see you again?...

    Projects

    You can support my Open World 3D RPG for PSP by voting for it here


  12. #42
    QJ Gamer Bronze
    Points: 7.047, Level: 55
    Level completed: 49%, Points required for next Level: 103
    Overall activity: 0%

    Registriert seit
    Jun 2006
    Beiträge
    144
    Points
    7.047
    Level
    55
    Downloads
    0
    Uploads
    0

    Standard

    Code:
    #include <psprtc.h>
    #include <psphprm.h> // this really needed for RTC functions?
    
    char *CurrentTime() {
          char timeText[8];
          pspTime rtime;
          sceRtcGetCurrentClockLocalTime(&rtime);
          snprintf(timeText, 8, "%i : %i" , rtime.hour , rtime.minutes);
          return timeText;
    }
    
    
    ...
    
    //example:
    //printf ( CurrentTime );
    Calling function twice is not what i call optimisation :P Just use it once every time you need it. And, the optimisations you had done didn't optimise anything as GCC does all of it by itself ;)
    Adrahil - Software architect and specialist in Reverse Engineering.
    Spoiler for Guilt of a Dev:
    17:17 < InsertWittyName> Can't pin user error on a dev ;)
    17:18 < InsertWittyName> Lesson learnt on both sides I would say.
    17:18 < InsertWittyName> You learnt to treat the end-user as a retarded fish.
    17:18 < InsertWittyName> They learnt to read readme's ;)

    Spoiler for me:
    17:12 <+dot_blank> are you the long haired pimp ;)

  13. #43
    Heroes never die
    Points: 8.645, Level: 62
    Level completed: 65%, Points required for next Level: 105
    Overall activity: 0%

    Registriert seit
    Aug 2006
    Ort
    ...........
    Beiträge
    1.323
    Points
    8.645
    Level
    62
    Downloads
    0
    Uploads
    0

    Standard

    #include <psphprm.h> // this really needed for RTC functions?
    I think the app wont compille without this

  14. #44
    QJ Gamer Silver
    Points: 10.921, Level: 69
    Level completed: 18%, Points required for next Level: 329
    Overall activity: 0%

    Registriert seit
    May 2006
    Ort
    Behind you.
    Beiträge
    1.814
    Points
    10.921
    Level
    69
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von adrahil
    Code:
    #include <psprtc.h>
    #include <psphprm.h> // this really needed for RTC functions?
    
    char *CurrentTime() {
          char timeText[8];
          pspTime rtime;
          sceRtcGetCurrentClockLocalTime(&rtime);
          snprintf(timeText, 8, "%i : %i" , rtime.hour , rtime.minutes);
          return timeText;
    }
    
    
    ...
    
    //example:
    //printf ( CurrentTime );
    Calling function twice is not what i call optimisation :P Just use it once every time you need it. And, the optimisations you had done didn't optimise anything as GCC does all of it by itself ;)
    As someone in the C help thread pointed out, that is wrong. The char ends when you do return timeText, so it displays the battery scrambled (like the problem i had and others did too).
    Here is the time code that worked for me:

    Code:
    void CurrentTime( char * timeText) {
          pspTime rtime;
          sceRtcGetCurrentClockLocalTime(&rtime);
          if ( rtime.minutes > 9) {
          snprintf(timeText, 8, "%i:%i" , rtime.hour , rtime.minutes);
          }
          if ( rtime.minutes < 10) {
          snprintf(timeText, 8, "%i:0%i" , rtime.hour , rtime.minutes);
          }      
    }
    
    //later in main loop
    char aTime[16] = "";
    CurrentTime( aTime );
    printf( aTime);
    I also made it so that if the minutes are less than 10 (single digits), add a zero before the minutes. If the minutes are greater than 9 (double digits), keep it the way it is.
    Geändert von SuperBatXS (03-29-2007 um 06:09 PM Uhr)
    Calypso - Enjoy the excellent 2D space shooter:
    http://dl.qj.net/Calypso-v1-PSP-Home...6542/catid/195

    "Quoting yourself in your signature means you love to masterbate while looking at the mirror." -me (oh, wait...)

  15. #45
    QJ Gamer Platinum
    Points: 25.089, Level: 95
    Level completed: 74%, Points required for next Level: 261
    Overall activity: 18,0%

    Registriert seit
    Sep 2005
    Ort
    Edinburgh, UK
    Beiträge
    2.388
    Points
    25.089
    Level
    95
    Downloads
    0
    Uploads
    0

    Standard

    Or easier, of course:

    Code:
    void CurrentTime( char * timeText) {
          pspTime rtime;
          sceRtcGetCurrentClockLocalTime(&rtime);
          snprintf(timeText, 8, "%i:%02i" , rtime.hour , rtime.minutes);
    }
    Learn about printf modifiers. They're your friends.

  16. #46
    QJ Gamer Silver
    Points: 10.921, Level: 69
    Level completed: 18%, Points required for next Level: 329
    Overall activity: 0%

    Registriert seit
    May 2006
    Ort
    Behind you.
    Beiträge
    1.814
    Points
    10.921
    Level
    69
    Downloads
    0
    Uploads
    0

    Standard

    Hey, first of all, i would like to thank the C help thread for helping me learn file writing X to Y bytes. I thought it would be necessary to post an example, for it could help and a lot of people who are confused with this like i was. Anyways, this helps you learn this in 5 easy steps.

    File I/O: Writing X to Y Bytes in a file

    In the number "123456789", what if you wanted to replace the 5 with a 0 ("123406789")? Using simple file i/o writing functions, we can easily do this.

    1) Assign your file a variable:
    Code:
    FILE* example;
    In this function, we declare a file with the name "example".

    2) Open your the file you assigned the "example" variable to.
    Code:
    example = fopen("./example.txt","r+b");
    Also, note that there is a "r+b". Here are some simple definitions:
    "r"- open a file for reading only
    "w"- open a file for writing only
    "b"- open a file in binary mode
    "rb"- open a file for reading only in binary mode
    "wb"- open a file for writing only in binary mode
    "r+b"- open a file for reading and writing in binary mode

    Note: If you don't use "r+b" in this case, and you use "wb" instead, then you can not read the bytes from X to Y (you must read the file for writing X to Y bytes; hard to learn at first).

    3) After opening your file, add this line:
    Code:
    fseek(example, 4, SEEK_SET);
    "fseek- "Reposition stream's position indicator." This requires 3 parameters, the pointer to an open file, the offset (how many bytes from the origin) and the origin." from psp-programming
    SEEK_SET goes to the beginning of the file.
    The "4" goes, literally, four characters right from the beginning of the file. After adding this line, you can edit the next character, in this case, being "5".

    4) Now, this code (fprintf) lets you write a character to the example variable we indicated earlier:
    Code:
    fprintf(example, "0");
    Note: the "0" is the character that we want to write in place of the 5. Any number or letters that you want can be replaced by the zero to write to the file (of course, it would be writing to the file after the fourth character that we "fseek"ed earlier).

    5) Close the file before continuing the program:
    fclose(example);
    Yes, it took me around 5 hours to figure this out (until the C help thread helped). As sad as my situation was, hopefully this will help you learn this in less than 5 minutes.
    Btw, what is up with "5" today? Is this a coincidence or what?

    Anyways, i hope this helps. ;)
    Geändert von SuperBatXS (05-13-2007 um 11:06 AM Uhr)
    Calypso - Enjoy the excellent 2D space shooter:
    http://dl.qj.net/Calypso-v1-PSP-Home...6542/catid/195

    "Quoting yourself in your signature means you love to masterbate while looking at the mirror." -me (oh, wait...)

  17. #47
    QJ Gamer Silver
    Points: 10.263, Level: 67
    Level completed: 54%, Points required for next Level: 187
    Overall activity: 0%

    Registriert seit
    Jun 2006
    Ort
    UK
    Beiträge
    2.326
    Points
    10.263
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    For more info:
    http://www.cppreference.com/stdio/fopen.html
    http://www.cppreference.com/stdio/fseek.html

    This is actually a C++ snippet taken from various sources. It is used to easily create a Singleton design pattern:
    Code:
    /**
        @file
            singleton.hpp
        @brief
            Template class to create a singleton class
            Taken from: http://www.gamedev.net/reference/articles/article1954.asp
    		which in turn is taken from Game Programming Gems
        @author
            Steven Yau
        @date
            17 Mar 2007
    */
    
    #ifndef SINGLETON_HPP
    #define SINGLETON_HPP
    
    #include <cassert>
    
    namespace Core
    {
    	template<typename T>
    	class cSingleton
    	{
    		static T* m_Singleton;
    
    	public:
    		cSingleton()
    		{
    			assert( !m_Singleton );
    			// use a cunning trick to get the singleton pointing to the start of
    			// the whole, rather than the start of the Singleton part of the object
    			int offset = (int)(T*)1 - (int)(cSingleton <T>*)(T*)1;
    			m_Singleton = (T*)((int)this + offset);
    		}
    
    		~cSingleton()
    		{
    			assert( m_Singleton );
    			m_Singleton = 0;
    		}
    
    		static T& GetSingleton()
    		{
    			assert( m_Singleton );
    			return *m_Singleton;
    		}
    
    		static T* GetSingletonPtr()
    		{
    			assert( m_Singleton );
    			return m_Singleton;
    		}
    	};
    
    	template <typename T> T* cSingleton <T>::m_Singleton = 0;
    }
    
    #endif // SINGLETON_HPP
    
    /*
    Usage: Taken from http://www.ogre3d.org/wiki/index.php/Singleton
    
    How to use it
    [edit]
    Making a class a singleton
    
    Pretend we want to convert the class MyManager to a Singleton.
    
    class MyManager
    {
    public:
        MyManager();
        void doSomething();
    }
    
    So we need to extend and instatiate the Ogre::Singleton template and override the singleton access methods.
    Our header file will look like this:
    
    #include <OgreSingleton.h>
    class MyManager : public Ogre::Singleton<MyManager>
    {
    public:
        MyManager();
        void doSomething();
        static MyManager& getSingleton(void);
        static MyManager* getSingletonPtr(void);
    }
    
    You don't have to override getSingleton() and getSingletonPtr() if your Singleton is not used outside
    of your EXE/DLL, but else you have to. The source file would now look like this:
    
    #include "MyManager.h"
    
    template<> MyManager* Singleton<MyManager>::ms_Singleton = 0;
    MyManager* MyManager::getSingletonPtr(void)
    {
        return ms_Singleton;
    }
    MyManager& MyManager::getSingleton(void)
    {
        assert( ms_Singleton );  return ( *ms_Singleton );
    }
    
    // The rest of your implementation is following.
    ...
    
    [todo] Do some more explaining.
    [edit]
    Using a singleton
    
    // Creating the manager. This may only be called once!
    new MyManager();
    
    // Obtaining a reference to the manager instance
    MyManager& mgr = MyManager::getSingleton();
    
    // Obtaining a pointer to the manager instance
    MyManager* pMgr = MyManager::getSingletonPtr();
    
    Note: You may call the Singleton constructor only once. Calling it more often will result in a runtime
    exception. There is another semantical difference between getSingleton() and getSingletonPtr(): If the
    constructor is not called beforehand getSingletonPtr() will return a NULL-Pointer and getSingleton()
    will throw a runtime exception. So it is probably better to use getSingleton() most of the time, even
    though it is slightly slower. But you get a clearer response when you set something up wrongly.
    */

  18. #48
    The Unique Developer
    Points: 7.101, Level: 55
    Level completed: 76%, Points required for next Level: 49
    Overall activity: 0%

    Registriert seit
    Oct 2006
    Ort
    Canada
    Beiträge
    1.059
    Points
    7.101
    Level
    55
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Glynnder
    tuw- what is "pspstub.s"
    As Adra said before, pspstub.S defines the PSP_STUB macros. Its located in /local/pspdev/sdk/includes/ . The function has changed from 2.xx to 3.xx , so I'll repeat my example with some changes.


    scepower.S
    Code:
    .set noreorder
    
    #include "pspstub.s"
    
    STUB_START "scePower_driver", 0x40010000, 0x20005
    STUB_FUNC 0x0442D852, scePower_0442D852
    STUB_END
    scepower.h
    Code:
    #ifndef PSP_POWER_H
    #define PSP_POWER_H
    
    
    #ifdef __cplusplus
    extern "C" {
    #endif
    /*
    Simply reboots the PSP
    @code:
    scePower_0442D852(); // The function has changed through 2.xx to 3.xx from 3.xx they're not using any arguments to reboot the system.
    
    */
    
    int scePower_0442D852(void);
    
    #ifdef __cplusplus
    }
    #endif
    
    #endif
    Yes I'm surprised it worked for me on 2.71 although I was stubbing it from the wrong library .



    Best,
    TUW
    Malloc.Us Network Administrator

    Decryption of the Encrypted


    You are the unseen, the unstoppable and in power of your code. The God of your software.

  19. #49
    QJ Gamer Silver
    Points: 10.921, Level: 69
    Level completed: 18%, Points required for next Level: 329
    Overall activity: 0%

    Registriert seit
    May 2006
    Ort
    Behind you.
    Beiträge
    1.814
    Points
    10.921
    Level
    69
    Downloads
    0
    Uploads
    0

    Standard

    Here is a little something SG57 made to load a lot of images quickly:

    Zitat Zitat von SG57
    Because, Yeldarb's tutroails taught them. And usually, if you have a ton of images to load, you should jsut use a buffer:
    Code:
    Image *image[10];
    char image_name[7];
    
    ...
    
    for ( i=0; i<10; i++ ) {
         sprintf ( image_name, "%i.png",i+1 );
         image[i] = loadImage(image_name);
    }
    Much quicker then manually loading 10 images. This will load 10 images, named to 1.png, 2.png, 3.png, etc...
    Btw, don't forget to add "int i = 0;" anywhere before the "i" is used.
    Geändert von SuperBatXS (04-04-2007 um 05:55 PM Uhr)
    Calypso - Enjoy the excellent 2D space shooter:
    http://dl.qj.net/Calypso-v1-PSP-Home...6542/catid/195

    "Quoting yourself in your signature means you love to masterbate while looking at the mirror." -me (oh, wait...)

  20. #50
    Heroes never die
    Points: 8.645, Level: 62
    Level completed: 65%, Points required for next Level: 105
    Overall activity: 0%

    Registriert seit
    Aug 2006
    Ort
    ...........
    Beiträge
    1.323
    Points
    8.645
    Level
    62
    Downloads
    0
    Uploads
    0

    Standard Get firmware version

    I hope i got them all

    Code:
    int getFirmwareVersion(void)
    {
    	switch(sceKernelDevkitVersion())
    	{
            case 0x01000300:
                 return 100;
            case 0x01050001:
                 return 150;
            case 0x01050100:
                 return 151;
            case 0x01050200:
                 return 152;
    	case 0x02000010:
                 return 200;
    	case 0x02000110:
                 return 201;             
            case 0x02050010:
                 return 250;
            case 0x02060010:
                 return 260;
            case 0x02070010:
                 return 270;
            case 0x02070110:
                 return 271;
            case 0x02080010:
                 return 280;
            case 0x02080110:
                 return 281;
            case 0x02080210:
                 return 282;		
    	case 0x03000010:
                 return 300;
            case 0x03000110:
                 return 301;
            case 0x03000210:
                 return 302;
            case 0x03000310:
                 return 303;     
            case 0x03010010:
                 return 310; 
            case 0x03010110:
                 return 311;
            case 0x03030010:
                 return 330;
            default:
    	     return 0;//unkow firmware                                
    	}
    	return 0;
    }
    a firmware version is build like this
    firstnumber-point-secondnumer-thirtnumber


    0x0firstnumber0secondnumb er0thirdnumber10:

    enjoy:Punk:

  21. #51
    sceKernelExitGame();
    Points: 19.955, Level: 89
    Level completed: 21%, Points required for next Level: 395
    Overall activity: 0%

    Registriert seit
    Jan 2006
    Ort
    New York
    Beiträge
    3.126
    Points
    19.955
    Level
    89
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von TMNT
    Here is a little something SG57 made to load a lot of images quickly:



    Btw, don't forget to add "int i = 0;" anywhere before the "i" is used.
    That could be optimized like this:

    Code:
    Image *image[10];
    int *numberPtr = 0 
    int *endPtr = 10;
    ...
    
    while( numberPtr < endPtr )
    {
         image[i] = loadImage(image_name);
         numberPtr = endPtr++;
    }
    The compiler my optimize it all ready though ;)

  22. #52
    QJ Gamer Silver
    Points: 10.263, Level: 67
    Level completed: 54%, Points required for next Level: 187
    Overall activity: 0%

    Registriert seit
    Jun 2006
    Ort
    UK
    Beiträge
    2.326
    Points
    10.263
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    Code:
    Image *image[10];
    int *numberPtr = 0 
    int *endPtr = 10;
    ...
    
    while( numberPtr < endPtr )
    {
         image[i] = loadImage(image_name);
         numberPtr = endPtr++;
    }
    Bad! Bad! Bad! You are making integer pointers point to random parts of memory and I can't see it making any logical sense nor compiling.

    TMNT: No, it is slower then loading it manually because you are calling sprintf 10 times.

  23. #53
    QJ Gamer Silver
    Points: 10.921, Level: 69
    Level completed: 18%, Points required for next Level: 329
    Overall activity: 0%

    Registriert seit
    May 2006
    Ort
    Behind you.
    Beiträge
    1.814
    Points
    10.921
    Level
    69
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von yaustar
    Code:
    Image *image[10];
    int *numberPtr = 0 
    int *endPtr = 10;
    ...
    
    while( numberPtr < endPtr )
    {
         image[i] = loadImage(image_name);
         numberPtr = endPtr++;
    }
    Bad! Bad! Bad! You are making integer pointers point to random parts of memory and I can't see it making any logical sense nor compiling.

    TMNT: No, it is slower then loading it manually because you are calling sprintf 10 times.
    Oh......so then how would i make it faster? Is a code that is fast for image buffering that you know of/can make? The one SG57 posted was, in my opinion, the best, but apparently it's not anymore now that you made me realize it. Thanks. ;)
    Calypso - Enjoy the excellent 2D space shooter:
    http://dl.qj.net/Calypso-v1-PSP-Home...6542/catid/195

    "Quoting yourself in your signature means you love to masterbate while looking at the mirror." -me (oh, wait...)

  24. #54
    QJ Gamer Silver
    Points: 10.263, Level: 67
    Level completed: 54%, Points required for next Level: 187
    Overall activity: 0%

    Registriert seit
    Jun 2006
    Ort
    UK
    Beiträge
    2.326
    Points
    10.263
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    Arguably, the 'fastest' way is to manually unroll the loop:
    Code:
    image[0] = loadImage("1.png");
    image[1] = loadImage("2.png");
    image[2] = loadImage("3.png");
    image[3] = loadImage("4.png");
    image[4] = loadImage("5.png");
    // etc
    But is not very maintainable. SG57's function is more maintainable and is the method that I would use. The performance offset is minor compared to maintainability.

  25. #55
    sceKernelExitGame();
    Points: 19.955, Level: 89
    Level completed: 21%, Points required for next Level: 395
    Overall activity: 0%

    Registriert seit
    Jan 2006
    Ort
    New York
    Beiträge
    3.126
    Points
    19.955
    Level
    89
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von yaustar
    Code:
    Image *image[10];
    int *numberPtr = 0 
    int *endPtr = 10;
    ...
    
    while( numberPtr < endPtr )
    {
         image[i] = loadImage(image_name);
         numberPtr = endPtr++;
    }
    Bad! Bad! Bad! You are making integer pointers point to random parts of memory and I can't see it making any logical sense nor compiling.

    TMNT: No, it is slower then loading it manually because you are calling sprintf 10 times.
    Hmmm, I read in an optimization article that showed something almost exactly like that, except it printed the pointer, instead of using it as an index of the array, must of been a bad resource (I wish I could remember where the article was).... Thanks for correcting me!

  26. #56
    Heroes never die
    Points: 8.645, Level: 62
    Level completed: 65%, Points required for next Level: 105
    Overall activity: 0%

    Registriert seit
    Aug 2006
    Ort
    ...........
    Beiträge
    1.323
    Points
    8.645
    Level
    62
    Downloads
    0
    Uploads
    0

    Standard

    Code:
    char *getOeFirmware()
    {
          	switch(sctrlSEGetVersion())
    	{
                  case 0x00000100:
                         return "2.71 SE-A";
                  case 0x00000200:
                         return "2.71 SE-B";
                  case 0x00000300:
                         return "2.71 SE-C";
    }
    return 0;
    }
    this is the only i found out at themoment , as soon as i get my psp back i will update this

  27. #57
    QJ Gamer Silver
    Points: 10.263, Level: 67
    Level completed: 54%, Points required for next Level: 187
    Overall activity: 0%

    Registriert seit
    Jun 2006
    Ort
    UK
    Beiträge
    2.326
    Points
    10.263
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Bronx
    Hmmm, I read in an optimization article that showed something almost exactly like that, except it printed the pointer, instead of using it as an index of the array, must of been a bad resource (I wish I could remember where the article was).... Thanks for correcting me!
    You are probably thinking along the lines of this:
    Code:
    int Blah[10];
    
    int * pBlahStart  = &Blah[0];
    int * pBlahEnd    = &Blah[9];
    
    while( pBlahStart <= pBlahEnd )
    {
        (*pBlahStart) = 0;
        ++pBlahStart;
    }
    -= Double Post =-
    Zitat Zitat von hallo007
    Code:
    char *getOeFirmware()
    {
          	switch(sctrlSEGetVersion())
    	{
                  case 0x00000100:
                         return "2.71 SE-A";
                  case 0x00000200:
                         return "2.71 SE-B";
                  case 0x00000300:
                         return "2.71 SE-C";
    }
    return 0;
    }
    this is the only i found out at themoment , as soon as i get my psp back i will update this
    Not 100% on how C would normally handle C strings but this may cause problems. You are returning a pointer to a C string that is local to the function. This means as soon as the function finishes, the string that is on the stack gets popped off and whatever you assigned the pointer address to is now pointing to garbage.

    ie
    Code:
    char * firmware = getOeFirmware();
    int Blah = 10;
    printf( firmware ); // firmware may now point to garbage
    Geändert von yaustar (04-11-2007 um 10:04 AM Uhr) Grund: Automerged Doublepost

  28. #58
    QJ Gamer Silver
    Points: 10.921, Level: 69
    Level completed: 18%, Points required for next Level: 329
    Overall activity: 0%

    Registriert seit
    May 2006
    Ort
    Behind you.
    Beiträge
    1.814
    Points
    10.921
    Level
    69
    Downloads
    0
    Uploads
    0

    Standard

    Um, i was asked to go to another thread to ask this, and i thought it would be appropriate here- Could anyone give me the source to loading a simple eboot in 3.10 oe-a?
    Calypso - Enjoy the excellent 2D space shooter:
    http://dl.qj.net/Calypso-v1-PSP-Home...6542/catid/195

    "Quoting yourself in your signature means you love to masterbate while looking at the mirror." -me (oh, wait...)

  29. #59
    Developer
    Points: 19.136, Level: 87
    Level completed: 58%, Points required for next Level: 214
    Overall activity: 33,0%

    Registriert seit
    Dec 2005
    Beiträge
    1.899
    Points
    19.136
    Level
    87
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von hallo007
    I hope i got them all

    Code:
    int getFirmwareVersion(void)
    {
    	switch(sceKernelDevkitVersion())
    	{
            case 0x01000300:
                 return 100;
            case 0x01050001:
                 return 150;
            case 0x01050100:
                 return 151;
            case 0x01050200:
                 return 152;
    	case 0x02000010:
                 return 200;
    	case 0x02000110:
                 return 201;             
            case 0x02050010:
                 return 250;
            case 0x02060010:
                 return 260;
            case 0x02070010:
                 return 270;
            case 0x02070110:
                 return 271;
            case 0x02080010:
                 return 280;
            case 0x02080110:
                 return 281;
            case 0x02080210:
                 return 282;		
    	case 0x03000010:
                 return 300;
            case 0x03000110:
                 return 301;
            case 0x03000210:
                 return 302;
            case 0x03000310:
                 return 303;     
            case 0x03010010:
                 return 310; 
            case 0x03010110:
                 return 311;
            case 0x03030010:
                 return 330;
            default:
    	     return 0;//unkow firmware                                
    	}
    	return 0;
    }
    a firmware version is build like this
    firstnumber-point-secondnumer-thirtnumber


    0x0firstnumber0secondnumb er0thirdnumber10:

    enjoy:Punk:
    You could write it like this so any new firmwars come along, no need to add another case, your software allways up to date
    Code:
    int getFirmwareVersion(void)
    {
       u32 firmware=(u32) sceKernelDevkitVersion();
    // Return BCD as DEC
       return (int)(((firmware&0x0f000000)>>24)*100)+(((firmware&0x000f0000)>>16)*10)+((firmware&0x00000f00)>>8));
    }
    -= Double Post =-
    Zitat Zitat von Art
    Here is an elipse drawing routine I flogged from a LUA thread in this
    area and converted it to C, and fixed that rouge pixel that hangs out
    the right hand side of smaller circles/elipses. I also modified so you define
    the center instead of top left corner.
    Code:
    void draw_elipse() {
    
    int exx = centerx - mma;
    int eyy = centery - mma;
    
    int x0 = exx+(mma);
    int y0 = eyy+(mma);
    int stretch = mma + mma;
    
    int theta;
    for(theta=0; theta<60; theta++) {
    xo = (cos(theta)*stretch)+x0;
    yo = (sin(theta)*mma)+y0;
    DRAW PIXEL HERE xo,yo
    }
    
    xo = tballx + stretch;
    yo = tbally;
    DRAW BLANK (coverup) PIXEL HERE xo,yo
    }
    Cheers,
    Art.


    Here is the correct way of drawing elipses.
    Notice no SIN, COS or float is used, SIN, COS and float, floats should only be used when it is the only way and best way of doing somthink, like in this drawOval you will see that integer can do the same job and actually draw it better.

    try use floats only when you have to use them, don't use them as a quick way of solving somethink, if integers can no matter how complex can do the same job better use intergers.

    Code:
    void Graphics::drawOval(int x, int y, int width, int height)
    {
       int xc=x, yc=y;
       long a=(long)width, b=(long)height, aa=a*a, bb=b*b, aa2=aa<<1, bb2=bb<<1, 
          d=bb-aa*b+(aa>>2), dx=0, dy=aa2*b; 
       
       x = 0, y = height;
       
       while (dx < dy) { 
          *(u32*)pixel(xc+x, yc+y)=foreColor;
          *(u32*)pixel(xc-x, yc-y)=foreColor;
          
          if (d > 0L) { 
             y--; 
             dy -= aa2; 
             d -= dy; 
          } 
          x++; 
          *(u32*)pixel(xc+x, yc-y)=foreColor;
          *(u32*)pixel(xc-x, yc+y)=foreColor; 
          
          dx += bb2; 
          d += bb + dx; 
       }
       
       while (y > 0L) { 
          *(u32*)pixel(xc+x, yc+y)=foreColor;
          *(u32*)pixel(xc-x, yc-y)=foreColor;
          
          if (d < 0L) { 
             x++; 
             dx += bb2; 
             d += dx; 
          }
          y--; 
          *(u32*)pixel(xc+x, yc-y)=foreColor;
          *(u32*)pixel(xc-x, yc+y)=foreColor;
          
          dy -= aa2; 
          d += aa - dy; 
       }
    }
    Geändert von xart (04-12-2007 um 08:30 AM Uhr) Grund: Automerged Doublepost

  30. #60
    QJ Gamer Silver
    Points: 10.263, Level: 67
    Level completed: 54%, Points required for next Level: 187
    Overall activity: 0%

    Registriert seit
    Jun 2006
    Ort
    UK
    Beiträge
    2.326
    Points
    10.263
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    Here is the correct way of drawing elipses.
    Notice no SIN, COS or float is used, SIN, COS and float are a big no no in game coding.
    I disagree with the float part. Float should only be avoided if the platform has no FPU. If it does, the floats are likely to be faster then integers as it has to cast/emulate(? I can't remember) integers up to floats to compute.


 
Seite 2 von 4 ErsteErste 1 2 3 4 LetzteLetzte

Tags for this Thread

Forumregeln

  • Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
  • Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
  • Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
  • Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.
  •  





Alle Zeitangaben in WEZ -8. Es ist jetzt 08:56 PM Uhr.

Use of this Web site constitutes acceptance of the TERMS & CONDITIONS and PRIVACY POLICY
Copyright © , Caputo Media, LLC. All Rights Reserved. Cluster .