Simple C/C++ Q

Discussion in 'NDS - ROM Hacking and Translations' started by .::5pYd3r::., Aug 14, 2007.

Aug 14, 2007

Simple C/C++ Q by .::5pYd3r::. at 7:49 AM (1,086 Views / 0 Likes) 8 replies

  1. .::5pYd3r::.
    OP

    Member .::5pYd3r::. Viva La Pizza

    Joined:
    Jun 2, 2007
    Messages:
    766
    Location:
    The GREAT Southern Land :D
    Country:
    Australia
    What did i do wrong in this code, i'm trying to make an app that when u press the A button it changes the colour of the top screen to a random colour
    CODE// PALib Template Application

    // Includes
    #include    // Include for PA_Lib
    u8 Colour1 = 31;
    u8 Colour2 = 31;
    u8 Colour3 = 31;
    u32 max = 31;

    int main()
    {
    ÂÂÂÂint i;

    ÂÂÂÂconsoleDemoInit();

    ÂÂÂÂvideoSetMode(MODE_FB0);

    ÂÂÂÂvramSetBankA(VRAM_A_LCD);

    ÂÂÂÂprintf("WELCOME TO SpYdEr's first DS app\n");

    ÂÂÂÂprintf("Press A to change colour of the top screen\n");

    ÂÂÂÂif (Pad.Newpress.Anykey)

    Âu32 Colour1 = PA_RandMax(max);
    ÂÂÂÂ
    ÂÂÂÂfor(i = 0; i < 256 * 192; i++)
    ÂVRAM_A = RGB15(Colour1,Colour2,Colour3);

    ÂÂÂÂreturn 0;
    }
     
  2. OrGoN3

    Member OrGoN3 GBAtemp Maniac

    Joined:
    Apr 23, 2007
    Messages:
    1,003
    Country:
    United States
    I've never programmed for the DS, so I'm not sure, but I see one thing odd about the program. You define a global u8 Colour1 = 31;. But then later on you set u32 Colour1 = PA_RandMax(max);. So now you have to variables with different types? I assume those are types (u8, u32), which is an illegal operation in C++.
     
  3. test84

    Member test84 GBAtemp's last ninja 2.

    Joined:
    Sep 8, 2006
    Messages:
    3,685
    Location:
    Iran, Tehran.
    Country:
    Iran
    would you tell us the error code or the malfunction too?
    it will be easier to debug that way.
     
  4. .::5pYd3r::.
    OP

    Member .::5pYd3r::. Viva La Pizza

    Joined:
    Jun 2, 2007
    Messages:
    766
    Location:
    The GREAT Southern Land :D
    Country:
    Australia
    yeah i changed it but it still doesn't work [​IMG] , it looks like when i do Colour1 = PA_RandMax(31); it doesn't change the variable
     
  5. .::5pYd3r::.
    OP

    Member .::5pYd3r::. Viva La Pizza

    Joined:
    Jun 2, 2007
    Messages:
    766
    Location:
    The GREAT Southern Land :D
    Country:
    Australia
    ok well the malfunction is that when i run it and push a button it doesn't change colour
     
  6. .::5pYd3r::.
    OP

    Member .::5pYd3r::. Viva La Pizza

    Joined:
    Jun 2, 2007
    Messages:
    766
    Location:
    The GREAT Southern Land :D
    Country:
    Australia
    sorry for the triple post but here is the updated code and it still doesn't work
    CODE// PALib Template Application

    // Includes
    #include    // Include for PA_Lib
    u8 Colour1 = 31;
    u8 Colour2 = 31;
    u8 Colour3 = 31;

    int main()
    {
    ÂÂÂÂint i;

    ÂÂÂÂconsoleDemoInit();

    ÂÂÂÂvideoSetMode(MODE_FB0);

    ÂÂÂÂvramSetBankA(VRAM_A_LCD);

    ÂÂÂÂprintf("WELCOME TO SpYdEr's first DS app\n");

    ÂÂÂÂprintf("Press A to change colour of the top screen\n");

    ÂÂÂÂif(Pad.Newpress.Anykey)
    ÂÂÂÂ{ÂÂÂÂ
    ÂColour1 = PA_RandMax(31);
    ÂColour2 = PA_RandMax(31);
    ÂColour3 = PA_RandMax(31);
    ÂÂÂÂ}
    ÂÂÂÂfor(i = 0; i < 256 * 192; i++)
    ÂVRAM_A = RGB15(Colour1,Colour2,Colour3);

    ÂÂÂÂreturn 0;
    }
     
  7. BassAceGold

    Member BassAceGold Testicles

    Joined:
    Aug 14, 2006
    Messages:
    494
    Country:
    Canada
    If your using palib, why don't you use some of its functions?
    CODE// PALib Template Application

    // Includes
    #include    // Include for PA_Lib
    u8 Colour1 = 31;
    u8 Colour2 = 31;
    u8 Colour3 = 31;

    int main()
    {

    PA_Init(); Â Â// Initializes PA_Lib
    PA_InitVBL();
    PA_InitRand();
    PA_Init16bitBg (1,3);
    int x;
    int y;

    printf("WELCOME TO SpYdEr's first DS app\n");


    printf("Press A to change colour of the top screen\n");

    while(1){

    if(Pad.Newpress.Anykey)
    {
    Colour1 = PA_RandMax(31);
    Colour2 = PA_RandMax(31);
    Colour3 = PA_RandMax(31);
    }
    for(x=0;x
     
  8. .::5pYd3r::.
    OP

    Member .::5pYd3r::. Viva La Pizza

    Joined:
    Jun 2, 2007
    Messages:
    766
    Location:
    The GREAT Southern Land :D
    Country:
    Australia
    Thank You So much BassAceGold it works the only thing is that i don't know half of the stuff you put in and the text doesn't show on screen anymore but i can probably fix that by using PA_OutputSimpleText instead of printf
     
  9. BassAceGold

    Member BassAceGold Testicles

    Joined:
    Aug 14, 2006
    Messages:
    494
    Country:
    Canada
    Yeah i forgot to change the text stuff (its 2 am now [​IMG]) and if you need information on what i did you can find it in the palib documentation Here. Tutorials can also be found Here if you need more info.
     

Share This Page