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 > Programming a simple demo - need help please

#16015 - Killua - Fri Feb 06, 2004 10:28 am

Hi guys.

I'm currently programming a first gba demo. I do this using C, no HAM or SGADE libs, and no ASM as I can easily do C code but I'm too newb with asm to start with that...

The aim is to display a background, and a texte that slowly appears lines after lines from the top of the screen (actually even letters appearing from the top pixels to the bottom ones, just like every pixel lines are displayed one after one, would be even better). When the whole text is displayed, on keypress I switch the background and display a second text, the same way.

I want to finish this before valentine's day, as the background and text are intended for my gf :) I offered her a GBA this christmas (the third one in my house -_- GBA SP this time :p), and we bought a EZFA.

I started yesterday evening (devkitadvance, it was already installed), and currently I have 2 background displayed on keypress (J_LEFT display the 1st one and J_RIGHT the second one). And because I want to do this before valentine I don't want to jump into asm >_< I did my C code with the help of "The Pern Project".


Here is the point now :
Can you guys help me by providing some example sources/demos that does almost what I want ? I don't know yet how to display the text slowly from top to bottom, and if something like that already exists I'd like to know, It might save me a lot of time (because if I do this quickly, I may think about adding sound too). I've search many demos on this site, but too much of them are in asm too :/ I've seen AGBTTY a few minutes ago, though I'm at work and I'll check it deeper tonight ^_^

This is btw my idea, but I'm opened to suggestions, like displaying the text letter after letter (which should be easier right ?). Just tell me ^_^

Thanks a lot for any help you can provide me :)
_________________
Killua

#16018 - qw3rty - Fri Feb 06, 2004 11:22 am

the effect you want, could be done, by scrolling the BG depending on the rasterline (REG_VCOUNT).

make a 512x256 text-background, write your text in the "2nd" screen (2nd screen == 256 < x > 512)

the scroll code could look something like this :
Code:

#define BIT1 2
s16 x_scroll;
u16 y;
for (y = 0;y <= 256; y++)
{
     while (REG_VCOUNT != 160) //do while screen is drawn
     {
          if (REG_VCOUNT <= y)
         {
              x_scroll = 256;
         }
         else
         {
              x_scroll = 0;
         }
         while ((*DISPSTAT & BIT1) ==0); //wait for h-blank
         REG_BGxHOFS = x_scroll;  //exchange the "x" with the according number
         while ((*DISPSTAT & BIT1) != 0); //wait for next line to be drawn
     }

     while (REG_VCOUNT != 227); //wait for next frame
}


this code is untested, but it should give you the idea ;)

#16019 - Killua - Fri Feb 06, 2004 11:48 am

yep :) as I said I'm at work I'll test tonight :) ( currently almost 12am CET)
If you have other ideas until then, feel free to help ^_^
_________________
Killua

#16023 - qw3rty - Fri Feb 06, 2004 1:43 pm

I found a few mistakes :

Code:

#define BIT1 2
s16 x_scroll;
u16 y;
while (REG_VCOUNT != 227); //*ADDED* wait for end of current frame
for (y = 0;y <= 160; y++) //*CHANGED* upper border for y to 160 (last line visible)
{
     while (REG_VCOUNT != 160) //do while screen is drawn
     {
          if (REG_VCOUNT <= y)
         {
              x_scroll = 256;
         }
         else
         {
              x_scroll = 0;
         }
         while ((*DISPSTAT & BIT1) ==0); //wait for h-blank
         REG_BGxHOFS = x_scroll;  //exchange the "x" with the according number
         while ((*DISPSTAT & BIT1) != 0); //wait for next line to be drawn
     }

     while (REG_VCOUNT != 227); //wait for next frame
}


P.S. if you want to speed this up, change the stride of the for-loop (e.g. y+=2)....to slow it down, iterate y only every n-th frame....

#16038 - crossraleigh - Sat Feb 07, 2004 12:08 am

If you want a full text system where you can use a puts() function to write to a BG, there are lots of examples. tepples has AGBTTY, Dan has the PFont engine (which has variable-width font and still uses tile mode), and the SGADE has a Mode 0 print function.

You will certainly learn more if you write everything yourself, but if you use a library it will be a lot easier. In fact, the SGADE has SoBkgCreditScroll which does exactly what you want. (I think I know what you want anyway. qw3rty's code is doing strange things to the X ofset in H-blank, instead of changing the Y ofset in V-blank.) You could set it up in a dozen or so lines. (For an example see [url=http://cvs.sourceforge.net/viewcvs.py/*checkout*/sgade/RELEASE_1_02/sample/source/SampleEffectCredits.c?content-type=text%2Fplain&rev=1.3]SampleEffectsCredits.c[/url].)

#16039 - qw3rty - Sat Feb 07, 2004 12:58 am

if you want something like this :
http://qwerty.myvnc.com:66/test.bin

you could use my code...

#16040 - Killua - Sat Feb 07, 2004 1:43 am

that's it, though actually I used the mode 4 example from the pern project and I use 240x160 pictures
I guess I shouldn't use mode 4 for 256*256 pictures. Still I can't compile this code because of the *DISPSTAT (which is actually for me REG_DISPSTAT, from eloist's gba.h.

And I'd like not to use those libraries for now if I can do so, but well ... kinda fun but hard ^_^
_________________
Killua

#16041 - qw3rty - Sat Feb 07, 2004 1:46 am

hmmm....I assumed you were using a tile-background (mode 0-2) and not a bitmapped mode (mode 3-5)...my code only works for tile-backgrounds...

#16045 - Killua - Sat Feb 07, 2004 2:24 am

ok tried with mode 0 but still I have difficulties -_- is tile background better though for that kind of work ?
_________________
Killua

#16048 - crossraleigh - Sat Feb 07, 2004 4:17 am

Ah, after looking at the demo and re-reading the post I understand what he meant.

I think a simpler method is to set up a window and decrement the top Y coordinate of it each V-blank. Windows can be used to all sorts of nice effects: the vertical wipe you want, and horizontal and diagonal wipes; interlacing of images; growing diamond or circle transitions; on and on. You could even use both windows and make some sort of heart transition. darkcloud has some window effects on his website.