gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Beginners > Visual HAM issues regarding brightness and rapid input/flip

#178239 - NeonHB - Thu Oct 16, 2014 4:23 am

Hi, my name is NeonHB and yesterday I signed up here in an attempt to seek for help with certain issues that I'm going through in Visual HAM. I'm new to making homebrew, and this is my first legit project that I'm trying to finish. What I'm trying to create is a short fiction in homebrew form, so it's not really a game, but rather a story. The story is already written in a text file in my PC, and I already have the main menu and the first few pages done along with the designs, fonts, and some of the code. Since all the text and designs are on the actual images themselves, it's only a matter of displaying images depending on the input received.


[Images not permitted - Click here to view it]
Home Menu above.

[Images not permitted - Click here to view it]
Page1 above.

[Images not permitted - Click here to view it]
Page2 above.


As shown on the images above, that's what I've passed over so far from the text file to the homebrew. The issue lies in the input and the brightness. I'm trying to make it so that every time you flip pages on the GBA, it fades from normal to dark and from dark to normal again, revealing the next page during the process. I looked through the Visual HAM samples, ripped out the code that works with the brightness from the brightness sample, and implemented it into my code to figure it out. It does something, but not the way I want it to.

You can download a ROM showing the brightness issue below. It's programmed to loop the fade in the main menu when you hold the A button. To me it seems like it fades really fast, giving a distorted/static effect. I'm not entirely sure.

download ROM with brightness issue

My other issue relates to the input. When you press a button to flip a page, it'll flip more pages than wanted in a rapid speed as if you were holding the button instead of tapping it. I thought of implementing a timer and having it count one second between image flips to prevent it from going so fast but I couldn't figure out the timer sample, nor do I think that it works because it doesn't even compile as-is and instead gives cryptic errors. The fade isn't a big killer for me but I'd at least like to figure out the rapid input/image flip. After I figure that out I can continue to pass over the story, start working on sounds and polish whatever needs to be polished at the time.

download ROM with input issue

Also, I have two separate programs despite them being the same exact homebrew to make it easier to figure out what's wrong. Below I'll leave the code for both programs.

Program with brightness-fade issue:

Code:

// Includes the main Visual HAM header file.
#include <mygba.h>

// Includes the image and palette of the Home Menu.
#include "C:/Users/Neon/Documents/Melody/Home/Home.pal.c"
#include "C:/Users/Neon/Documents/Melody/Home/Home.raw.c"

//Global Variables Below. All three are taken from the Visual Ham brightness sample.

u32 g_Frames=0;
u8  g_NewFrame=1;
u8  g_BrightIntensity=16;


int main(){

bool key_pressed = 0;


    ham_Init();

// Sets background mode to four.
    ham_SetBgMode(4);
   
// Loads Home Menu image and palette. Also Flips Home Menu Image.
    ham_LoadBGPal((void*)Home_Palette,256);
    ham_LoadBitmap((void*)Home_Bitmap);
    ham_FlipBGBuffer();

// While A is pressed the fade will start to loop.
while(key_pressed == 0){if (F_CTRLINPUT_A_PRESSED){

// Visual HAM Brightness sample starts here.
  // Loop
      // Its a new frame?
        if(g_NewFrame)
        {
            // Just to skip some frames
            if(!(g_Frames&7))
            {
                // Fade screen from normal to black
                if((g_BrightIntensity >= 32) && (g_BrightIntensity < 48))
                {
                    ham_SetFxMode(FX_LAYER_SELECT(1,1,1,1,1,0),         // Source layer
                                  FX_LAYER_SELECT(0,0,0,0,0,0),         // Target layer
                                  FX_MODE_DARKEN);                      // Effect mode

                    // Set the intensity of the source and target layer
                    ham_SetFxBrightnessLevel(g_BrightIntensity&15);     // intensity
                }
                else
                // Fade screen from black to normal


                    // Set the intensity of the source and target layer
                    ham_SetFxBrightnessLevel(64-g_BrightIntensity);     // intensity
                }
                else
                    g_BrightIntensity=0;

                // Increase bright helper variable
                g_BrightIntensity++;
}


}

}
    return 0;
}



Program with rapid input issue:



Code:
//Includes the main Visual HAM header file.
#include <mygba.h>

// Includes the images and palettes of the Home Menu, Page 1 and Page 2.
#include "C:/Users/Neon/Documents/Melody/Home/Home.pal.c"
#include "C:/Users/Neon/Documents/Melody/Home/Home.raw.c"
#include "C:/Users/Neon/Documents/Melody/Page1/Page1.pal.c"
#include "C:/Users/Neon/Documents/Melody/Page1/Page1.raw.c"
#include "C:/Users/Neon/Documents/Melody/Page2/Page2.pal.c"
#include "C:/Users/Neon/Documents/Melody/Page2/Page2.raw.c"

int main()

{

bool key_pressed = 0;

    ham_Init();

// Sets up the background mode to four.
    ham_SetBgMode(4);
   

// Loads Home Menu image and palette. Also Flips Home Menu Image.
    ham_LoadBGPal((void*)Home_Palette,256);   
    ham_LoadBitmap((void*)Home_Bitmap);   
    ham_FlipBGBuffer();



while (key_pressed ==0)

// If any button is pressed in the Home Menu, it will go to page 1.

{

if (F_CTRLINPUT_A_PRESSED
            || F_CTRLINPUT_B_PRESSED
            || F_CTRLINPUT_UP_PRESSED
            || F_CTRLINPUT_DOWN_PRESSED
            || F_CTRLINPUT_LEFT_PRESSED
            || F_CTRLINPUT_RIGHT_PRESSED
            || F_CTRLINPUT_START_PRESSED
            || F_CTRLINPUT_SELECT_PRESSED
            || F_CTRLINPUT_L_PRESSED
            || F_CTRLINPUT_R_PRESSED)
           
{   
   
// Loads Page1 image and palette. Also Flips Page1 Image, assuming that any button was pressed in the Home Menu.
         ham_LoadBGPal((void*)Page1_Palette,256);
         ham_LoadBitmap((void*)Page1_Bitmap);
         ham_FlipBGBuffer();
         
// If R is pressed, it will load Page 2 from within Page 1.
                    if (F_CTRLINPUT_R_PRESSED)

                                              {
// Loads Page2 image and palette. Also Flips Page2 Image, assuming that R was pressed in Page 1
                                           ham_LoadBGPal((void*)Page2_Palette,256);
                                           ham_LoadBitmap((void*)Page2_Bitmap);
                                           ham_FlipBGBuffer();

}

}

}
       
    return 0;
} // End of main()



Any help is appreciated.

#178240 - elhobbs - Thu Oct 16, 2014 11:33 am

Any particular reason you are using ham instead of libgba and devkitarm? Am I correct that you are targeting the gba? If so then you may want to switch.

#178241 - NeonHB - Thu Oct 16, 2014 3:25 pm

elhobbs wrote:
Any particular reason you are using ham instead of libgba and devkitarm? Am I correct that you are targeting the gba? If so then you may want to switch.


There is no reason in particular. I started studying GBA programming a few months back and came across Visual HAM first. Everything was going well until now. Yes, I am targeting the GBA. I'll take that suggestion.

#178243 - NeonHB - Fri Oct 17, 2014 6:49 am

I installed devkitARM and looked for tutorials online but not many, if not none of what I've found are noob friendly. It's probably going to take me a long time to fully understand it all and get used to it so I'm going to research while finding workarounds in Visual HAM.

Speaking of workarounds, I may have found a way to stop the rapid input. Basically I placed the pages in separate functions and called the functions when an input is received. On the actual homebrew, when a button is pressed the screen goes black for a second and then back to normal, revealing the next page.

Code example below:

Code:

#include <mygba.h>


#include "C:/Users/Neon/Documents/Melody/Home/Home.pal.c"
#include "C:/Users/Neon/Documents/Melody/Home/Home.raw.c"
#include "C:/Users/Neon/Documents/Melody/Page1/Page1.pal.c"
#include "C:/Users/Neon/Documents/Melody/Page1/Page1.raw.c"
#include "C:/Users/Neon/Documents/Melody/Page2/Page2.pal.c"
#include "C:/Users/Neon/Documents/Melody/Page2/Page2.raw.c"
#include "C:/Users/Neon/Documents/Melody/Page3/Page3.pal.c"
#include "C:/Users/Neon/Documents/Melody/Page3/Page3.raw.c"

// DECLARATION
int Page1(void);
int Page2(void);
int Page3(void);


// MAIN FUNCTION
int main(){
   

    ham_Init();
    ham_SetBgMode(4);
    ham_LoadBGPal((void*)Home_Palette,256);
    ham_LoadBitmap((void*)Home_Bitmap);
    ham_FlipBGBuffer();
     
      while(1){if (F_CTRLINPUT_UP_PRESSED
            || F_CTRLINPUT_DOWN_PRESSED
            || F_CTRLINPUT_LEFT_PRESSED
            || F_CTRLINPUT_RIGHT_PRESSED
            || F_CTRLINPUT_R_PRESSED
            || F_CTRLINPUT_L_PRESSED
            || F_CTRLINPUT_A_PRESSED
            || F_CTRLINPUT_B_PRESSED
            || F_CTRLINPUT_START_PRESSED
            || F_CTRLINPUT_SELECT_PRESSED){break;}}
           
            Page1();

    return 0;
}



// PAGE 1 FUNCTION
int Page1() {

    bool key_pressed = 0;

    ham_Init();
    ham_SetBgMode(4);

    ham_LoadBGPal((void*)Page1_Palette,256);
    ham_LoadBitmap((void*)Page1_Bitmap);
    ham_FlipBGBuffer();

     while(key_pressed == 0){if (F_CTRLINPUT_R_PRESSED){
     Page2();}}
    return 0;
}



// PAGE 2 FUNCTION
int Page2() {
bool key_pressed = 0;
    ham_Init();
    ham_SetBgMode(4);
    ham_LoadBGPal((void*)Page2_Palette,256);
    ham_LoadBitmap((void*)Page2_Bitmap);
    ham_FlipBGBuffer();
   
      while(key_pressed == 0){if (F_CTRLINPUT_R_PRESSED){Page3();}
                              if (F_CTRLINPUT_L_PRESSED){Page1();}
                              }


    return 0;
}

// PAGE 3 FUNCTION
int Page3() {
   
    bool key_pressed = 0;
    ham_Init();
    ham_SetBgMode(4);
    ham_LoadBGPal((void*)Page3_Palette,256);
    ham_LoadBitmap((void*)Page3_Bitmap);
    ham_FlipBGBuffer();

      while(key_pressed == 0){if (F_CTRLINPUT_R_PRESSED){Page1();}
                              if (F_CTRLINPUT_L_PRESSED){Page2();}
                              }


    return 0;
}

#178244 - gauauu - Mon Oct 20, 2014 2:55 pm

NeonHB wrote:
I installed devkitARM and looked for tutorials online but not many, if not none of what I've found are noob friendly.


Your best bet is TONC: http://www.coranac.com/tonc/text/

#178245 - NeonHB - Tue Oct 21, 2014 6:35 am

gauauu wrote:
NeonHB wrote:
I installed devkitARM and looked for tutorials online but not many, if not none of what I've found are noob friendly.


Your best bet is TONC: http://www.coranac.com/tonc/text/


Hm. Lua for the GBA is something I'd like to look at later on. Thanks for the link.

#178246 - sverx - Tue Oct 21, 2014 9:55 am

Lua? Check the link again ;)
_________________
libXM7|NDS programming tutorial (Italiano)|Waimanu DS / GBA|A DS Homebrewer's Diary

#178247 - NeonHB - Wed Oct 22, 2014 4:53 am

sverx wrote:
Lua? Check the link again ;)


Oh. I was looking at this, I guess it's something else then.

Other Languages wrote:
There is dragonBASIC, which provides a BASIC-like syntax. This should be suitable for small projects, but I'm not sure it can be used for full games like a Mario clone. You can find a FreePascal for GBA/NDS at itaprogaming.free.fr, and instructions for using Forth or Lua at www.torlus.com. Finally, there is (or at least was) something called Catalpult at www.nocturnal-central.com. This is a very complete environment with an emulator and I think I've seen a debugger there as well. I think this could be compared to GameMaker, but then again I may be wrong.

#178578 - theycallmeyoggi - Sat Mar 05, 2016 3:09 pm

Hey, sorry I'm not answering your question but since you've at least got it to output something I figured you'd know the answer to this question. Where did you put your .vhw files. I put mine in a a folder I made called 'vhmworkspace'. However when I try to build the program, nothing happens. I already have it running on windows xp so thats not the problem. If you have any advice please reply, thank you.