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.

Coding > Expert help needed. I want to do 3d tile scrolling....

#14875 - LOst? - Wed Jan 14, 2004 3:47 am

You know some game uses a cool effect when being in tile mode. Most of you have played Street Fighter II, and on the Las Vegas stage, the floor is scrolling like if it was in 3d. Many game seem to have this effect on GBA, and I wonder how I can make parts, and I mean parts of the background do that effect?

#14876 - tepples - Wed Jan 14, 2004 5:11 am

Street Fighter II and NBA Jam use the same raster trick that lots of pseudo-3D games since Pole Position have used: changing the horizontal scroll value during HBlank. Some older systems required cycle-timed code to do this, but the GBA hardware makes it really easy: just make an array of horizontal scroll values and use DMA channel 0 to copy them to the BG0HOFS register.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#14878 - LOst? - Wed Jan 14, 2004 6:17 am

tepples wrote:
Street Fighter II and NBA Jam use the same raster trick that lots of pseudo-3D games since Pole Position have used: changing the horizontal scroll value during HBlank. Some older systems required cycle-timed code to do this, but the GBA hardware makes it really easy: just make an array of horizontal scroll values and use DMA channel 0 to copy them to the BG0HOFS register.


Wow! I didn't know that. This is great. I must try this out. But how do I know the Hblank? Do you people have any hint. I want it to be as simple as possible

#14882 - yaustar - Wed Jan 14, 2004 9:30 am

You have heard uncer another name called 'Mode 7'on the Sness/gba. It however wasnt a mode such as mode 0 ,1 2 etc but more of the used that tepples has said above.
_________________
[Blog] [Portfolio]

#14887 - LOst? - Wed Jan 14, 2004 10:55 am

yaustar wrote:
You have heard uncer another name called 'Mode 7'on the Sness/gba. It however wasnt a mode such as mode 0 ,1 2 etc but more of the used that tepples has said above.


Mode 7. Isn't that what Mario Cart uses? I don't want to leave Mode 0, because of all the backgrounds. The only thing I want is to make one of the backgrounds do some cool paralax(sp?) scrolling like those you can see in the floor scrolling in Street Fighter II.

#14888 - yaustar - Wed Jan 14, 2004 12:30 pm

Mode 7 IS NOT a mode. I my have misprhased it in my initail post. It is a name for the technique in games like the mario kart. I am guessing (i havent seen it) in a lesser extent in SFII

I am not 100% on how it works but I think it works by taking the horizontal pixel lines of the screen and scaling it.

If we take fzero for example, the top line has been scaled right down, the next line has been scaled slighlty lessand so on. Thereby giving a similar effect as perspective.
_________________
[Blog] [Portfolio]

#14889 - LOst? - Wed Jan 14, 2004 1:05 pm

yaustar wrote:
Mode 7 IS NOT a mode. I my have misprhased it in my initail post. It is a name for the technique in games like the mario kart. I am guessing (i havent seen it) in a lesser extent in SFII

I am not 100% on how it works but I think it works by taking the horizontal pixel lines of the screen and scaling it.

If we take fzero for example, the top line has been scaled right down, the next line has been scaled slighlty lessand so on. Thereby giving a similar effect as perspective.


I have seen VisualBoy Advance telling that it is in mode 7. Maybe it was a bug?

And SFII had a already drawn perspective, so that it only needs to scroll each line in different speeds

#14890 - yaustar - Wed Jan 14, 2004 1:13 pm

Not sure about the VBA, I dont remember being taught a 'mode 7'. In SFII, it sounds like parrallex scrolling.

I take a read up on the 'Mode 7' as I am interested too...
_________________
[Blog] [Portfolio]

#14891 - yaustar - Wed Jan 14, 2004 1:31 pm

Just looked at some source, the math is still a tiny bit out of my league (until I understand it ;) ) It still says mode 1 in the map viewer...what game did you try?
_________________
[Blog] [Portfolio]

#14893 - LOst? - Wed Jan 14, 2004 1:42 pm

yaustar wrote:
Just looked at some source, the math is still a tiny bit out of my league (until I understand it ;) ) It still says mode 1 in the map viewer...what game did you try?


I fucked up my own game. I wrote incorrectly to the SetMode macro.

Do you need interrupts and "bios enable" to program mode 7?

#14894 - yaustar - Wed Jan 14, 2004 2:39 pm

I only know the thoery behind mode 7. I am afraid I ahve no practical use of it. THere is some source from teh main site and on Dovoto's pern project as well. You should find your anwsers there.

sorry
_________________
[Blog] [Portfolio]

#14899 - poslundc - Wed Jan 14, 2004 4:34 pm

OK, here we go.

Mode 7 is a technique, not a mode, to add perspective to a rotation background and give it a pseudo-3D look. Because it requires a rotation background, you must be either in Mode 1 or Mode 2 to make use of it.

The basic strategy is that during VBlank (or during the frame if you are double-buffered) a list of settings for each parameter (PA, PB, PC, PD, X and Y) is generated, with different values calculated for each of the 160 scanlines.

Then as the screen is being displayed, either using HBlank interrupts or HDMA, the settings for the background are changed for every scanline.

There are a bunch of tutorials and demos on the subject floating around, so have a look for them. No one has documented it in a really straightforward and spoonfeeding way (ie. not like the Pern tutorials or anything), so it's not for the faint of heart.

Dan.

#14902 - LOst? - Wed Jan 14, 2004 4:48 pm

poslundc wrote:
either using HBlank interrupts or HDMA, the settings for the background are changed for every scanline.


So, now when I don't want to do mode 7, just do some scanline scrolling effects, how do I use HDMA, or HBlank in a good way?

#14903 - poslundc - Wed Jan 14, 2004 5:03 pm

Uh, you use it in exactly the same way I described. You just change the HOFS and VOFS registers if you want to do simple scrolling effects.

Dan.

#14918 - tepples - Wed Jan 14, 2004 8:15 pm

Street Fighter II does not use Mode 7 in-game. There's a difference between Pole Position scrolling and Mode 7. Go rent a Namco Museum title containing Pole Position and closely observe its in-game road graphics, which consist of a largely static screen that warps horizontally and palette-animates to show the advancing road. Then compare F-Zero or Super Mario Kart, which treats the floor as a giant texture. You'll find that Street Fighter II's effect resembles Pole Position's more than Super Mario Kart's.

Pole Position scrolling, which can be done in any of the GBA's graphics modes, merely involves changing BG0HOFS (or BG2X) on Hblank. Rad Racer scrolling, which allows for hills, involves changing both BG0HOFS (or BG2X) and BG0VOFS (or BG2Y) on Hblank. Even the NES, with its one text background layer, could do Pole Position and Rad Racer scrolling.

"Mode 7" is so called because it was numbered 7 on the Super NES, but it's numbered 1 or 2 on the GBA, depending on how many text layers you want to replace with rot/scale layers. It involves rotation and scaling of each scanline (BG2PA, BG2PC, BG2X, BG2Y).

I think LOst? is looking for some sample code to do Pole Position scrolling on the GBA.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#14940 - XeroxBoy - Thu Jan 15, 2004 12:51 am

This tutorial tells you what you need to do.

#14959 - LOst? - Thu Jan 15, 2004 9:05 am

tepples wrote:
Street Fighter II does not use Mode 7 in-game. There's a difference between Pole Position scrolling and Mode 7. Go rent a Namco Museum title containing Pole Position and closely observe its in-game road graphics, which consist of a largely static screen that warps horizontally and palette-animates to show the advancing road. Then compare F-Zero or Super Mario Kart, which treats the floor as a giant texture. You'll find that Street Fighter II's effect resembles Pole Position's more than Super Mario Kart's.

Pole Position scrolling, which can be done in any of the GBA's graphics modes, merely involves changing BG0HOFS (or BG2X) on Hblank. Rad Racer scrolling, which allows for hills, involves changing both BG0HOFS (or BG2X) and BG0VOFS (or BG2Y) on Hblank. Even the NES, with its one text background layer, could do Pole Position and Rad Racer scrolling.

"Mode 7" is so called because it was numbered 7 on the Super NES, but it's numbered 1 or 2 on the GBA, depending on how many text layers you want to replace with rot/scale layers. It involves rotation and scaling of each scanline (BG2PA, BG2PC, BG2X, BG2Y).

I think LOst? is looking for some sample code to do Pole Position scrolling on the GBA.


So you call it Pole Position. That's good to know (didn't see it in your first post) :)

When is the Hblank occuring? Before drawing or after? I know very little about the Hblank.

I just want to do this Pole Position (only in horizontal) effect on one background, as the same time as I, every frame, change both its BG0HOFS and BG0VOFS position. Can someone explain to me how I can do this, and how it works?

#14969 - poslundc - Thu Jan 15, 2004 3:55 pm

LOst? wrote:
When is the Hblank occuring? Before drawing or after?


Uh... both really. There is an HBlank before every scanline is drawn. But there is also an HBlank after every scanline is drawn. It depends on how you want to look at it. :P

Quote:
I know very little about the Hblank.


http://www.cs.rit.edu/~tjh8300/CowBite/CowBiteSpec.htm
http://www.work.de/nocash/gbatek.htm

Quote:
I just want to do this Pole Position (only in horizontal) effect on one background, as the same time as I, every frame, change both its BG0HOFS and BG0VOFS position. Can someone explain to me how I can do this, and how it works?


You might try adding your numbers. :D

Dan.

#14970 - LOst? - Thu Jan 15, 2004 4:09 pm

poslundc wrote:
LOst? wrote:
When is the Hblank occuring? Before drawing or after?


Uh... both really. There is an HBlank before every scanline is drawn. But there is also an HBlank after every scanline is drawn. It depends on how you want to look at it. :P

Quote:
I know very little about the Hblank.


http://www.cs.rit.edu/~tjh8300/CowBite/CowBiteSpec.htm
http://www.work.de/nocash/gbatek.htm

Quote:
I just want to do this Pole Position (only in horizontal) effect on one background, as the same time as I, every frame, change both its BG0HOFS and BG0VOFS position. Can someone explain to me how I can do this, and how it works?


You might try adding your numbers. :D

Dan.


It was a better reply than: RTFM

But still, I know how to add numbers, and scrolling is not the problem. It's that I just want the effect to be in one bg, and not the whole display. That must be possible right?

#14973 - poslundc - Thu Jan 15, 2004 4:35 pm

LOst? wrote:
It's that I just want the effect to be in one bg, and not the whole display. That must be possible right?


You said that you were changing REG_BG0HOFS and REG_BG0VOFS. If you look in either of those specifications you'll see that these are the registers that control the position of background 0, not the entire display. This is also something you should have learned from the Pern or gbajunkie tutorials.

Sorry, I'm not trying to sound condescending, but are you sure you're ready for these kind of advanced effects? If I was dodgy in my former reply it's because it seems like you're asking how to run before being able to walk.

Dan.

#14974 - tepples - Thu Jan 15, 2004 4:46 pm

poslundc wrote:
There is an HBlank before every scanline is drawn. But there is also an HBlank after every scanline is drawn.

From DMA's point of view, Hblank takes place after each scanline is drawn. You'll want to copy the first scanline's data in manually during Vblank and then set up the transfer starting at &(scanline_xscrolls[1]). If you'll be combining it with vertical scrolling, you will want to start the transfer earlier or later in the array.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#14977 - LOst? - Thu Jan 15, 2004 4:56 pm

tepples wrote:
poslundc wrote:
There is an HBlank before every scanline is drawn. But there is also an HBlank after every scanline is drawn.

From DMA's point of view, Hblank takes place after each scanline is drawn. You'll want to copy the first scanline's data in manually during Vblank and then set up the transfer starting at &(scanline_xscrolls[1]). If you'll be combining it with vertical scrolling, you will want to start the transfer earlier or later in the array.


Thanks for the info =)

And poslundc, I take your advice seriously. And I know how to walk, and now I will run. I've been walking since 1998, dreaming of doing a tile based game for a console not even created back then ;)

#14981 - poslundc - Thu Jan 15, 2004 5:33 pm

LOst? wrote:
And poslundc, I take your advice seriously. And I know how to walk, and now I will run. I've been walking since 1998, dreaming of doing a tile based game for a console not even created back then ;)


By "walking" I meant knowing the basics, not dreaming of the exceptional.

Dan.

#14985 - LOst? - Thu Jan 15, 2004 7:15 pm

poslundc wrote:
LOst? wrote:
And poslundc, I take your advice seriously. And I know how to walk, and now I will run. I've been walking since 1998, dreaming of doing a tile based game for a console not even created back then ;)


By "walking" I meant knowing the basics, not dreaming of the exceptional.

Dan.


You don't need to know things you won't use. I haven't needed interrupts before... *deletes CRT0.S* ... but now I need interrupts. *Tries to restore the file, but fails*

#14988 - Miked0801 - Thu Jan 15, 2004 7:43 pm

Quote:

You don't need to know things you won't use.


I love that. I shouldn't have taken calculus and physics as I wouldn't have needed them - but wait, now that know those things, it's amazing what things I can accomplish with them.

You can't know that you don't need something without some knowledge of it. Interrupts are such an integral part of GBA programming that I can't see anyone doning anything long term without some knowledge. Yes, I could probably do a tic-tac-toe game without knowledge of interrupts, but things get soooo much easier when I can have an interrupt occur to trigger my BG music (Timers), send information over the serial cable to the other player who's playing head-to-head against me (serial/timers), update the screen efficiently without causing visual glitching (vblank), or do some kick @ss screen effects (hblank.) (Run on sentence alert!)

Sorry to stand on the soapbox about this issue, but I've had some similiar conversations with 1st year programmers who "know" everything (look up sophmore) and don't need any help with anything. You are coming across this way and it worries me a bit.

Mike

#14998 - tepples - Thu Jan 15, 2004 11:13 pm

LOst? wrote:
You don't need to know things you won't use. I haven't needed interrupts before... *deletes CRT0.S* ... but now I need interrupts. *Tries to restore the file, but fails*

I use GBA interrupts without any crt0 support. Read the CowBite spec to see how you too can write your own ISR in ARM code in IWRAM.

Correction: IWRAM not EWRAM. The entry point to your ISR should be in ARM instructions (because that's what the GBA BIOS assumes) in some sort of RAM (so that you can handle removed-cart interrupts properly). IWRAM is faster than EWRAM, and though VRAM is dual-ported and faster than EWRAM, DevKit Advance provides no way to link code for copying to spare VRAM.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.


Last edited by tepples on Fri Jan 16, 2004 6:36 pm; edited 1 time in total

#15031 - LOst? - Fri Jan 16, 2004 8:03 am

tepples wrote:
LOst? wrote:
You don't need to know things you won't use. I haven't needed interrupts before... *deletes CRT0.S* ... but now I need interrupts. *Tries to restore the file, but fails*

I use GBA interrupts without any crt0 support. Read the CowBite spec to see how you too can write your own ISR in ARM code in EWRAM.


I will, thanks!

#15059 - batblaster - Fri Jan 16, 2004 7:01 pm

Dear Friends,

In advance i'm sorry for my bad enghlish. I've readed a lot all the question writed in this posts, i've used a lot hblank to make my intro and a new intro i'm coding, ( my 1st intro is available here on gbadev). The problem i've found is :

I've coded The SNES HDMA and is very very different of the GBA DMA i never found a way to use DMA0 or DMA3 like a real HDMA, if you use DMA to change a BG color on Each Scanline reading from an existing table did not work... Now i'm in vacation but i can post the code very soon... DMA function , in according with Nintendo official document, appear very different of the HDMA of SNES

"From The Pern Project Tutorial"

Bit 25: DMA repeat - this will cause the DMA to repeat every Hblank or Vblank if you have that specified in your timing bits.
Bits 23-24: These control your how your source counter is affected by each transfer (by transfer I mean each word copied).


00-increment-the source counter is incremented after each transfer
01-decrement-the source counter is decremented after each transfer
10-fixed-good for memory fills as the same data will get copied each frame
11-invalid value


Bits 21-22: These control your how your destination counter is affected by each transfer.


00-increment-the destination counter is incremented after each transfer
01-decrement
10-fixed- direct sound FIFO access
11-this value is different for the Destination control. When set it will increment. At the end of the transfer (this time I mean the entire DMA) it will be reset to its initial value. This is what we will be using for mode 7 effects.

"End of Part"


Ok my question is :

I've a table of color to make some raster effect posted in ram, i change and manage color each VBL , i want to reload the table each time automatically using DMA, if you try to do you can but you can't restart at the right time and you can't tell to destination (color 0 of the palette for BG effect) to do not increment or decrement...

I've maded a lot of modify and maded a lot of macro to manage DMA in the right mode but no good things...

Using Hblank interrupt is very simple and i doit see my intro to look but all code go in IWRAM if you want the code work on Real HW and maybe the tables too...

SNES use the HDMA in a simple mode, source table , destination (HW register) , lenght , channel number , start... That's all , very simple

If someone have a solution or real example to show me on how to use DMA not only for copy of move BGX i'm very HAPPY...

Batblaster...

TO LOst?:

Init an Interrupt handler to the HBLANK interrupt

void hblank_intr(void)
{
write here your code like :
U32 VCnt ( i do not remember the VCNT address sorry)
IF(VCnt>40)
BG0SCROLLX--;
}

Is only for example , from the line 40 your bg0 scroll one pixel on each scanline... Manage all in a table and you can make nice effect...

Sorry Again for my bad english and sorry for not right code but i'm in vacation 10.000 km distance of my house...

Bye...
_________________
Batblaster / 7 Raven Studios Co. Ltd
------------------------------------------

#15060 - DekuTree64 - Fri Jan 16, 2004 7:33 pm

Hmm, DMA always worked fine for my mode7/scrolling effects. Just set it like
Code:
REG_DM0CNT_H = 0;      //disable first
REG_DM0SAD = (u32)hofsTable;
REG_DM0DAD = (u32)(&REG_BG0HOFS);
REG_DM0CNT = 1 | BIT22 | BIT25 | BIT29 | BIT31;

That would first disable DMA0 (if it's still enabled, you can't reset the source pos to the start of the table. This is probably where your troubles came from), then set the src/dest, set it to copy one 16-bit value at a time, dest fixed, inc src, repeat on HBL, and of course, enable. You have to do this every VBlank, or it will just continue copying from past the end of hofsTable, and therefore get unpredictable scroll values.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#15063 - batblaster - Fri Jan 16, 2004 7:38 pm

Hi DekuTree64

Try to make the same for the Palette 0 entries to change a color on heach scanline and check if work...

I've tried many many times with the DMA but nothing good all wrong colors... Using Hblank interrupt works hehehe simple...

If you do please write me the code heheh thanks...

[/list]
_________________
Batblaster / 7 Raven Studios Co. Ltd
------------------------------------------

#15080 - DekuTree64 - Fri Jan 16, 2004 10:03 pm

Code:
#include "gba.h"

int AgbMain()
{
   REG_DISPCNT = 0;
   u16 cTab[160];
   s32 i, frame = 0;
   while(1)
   {
      for(i = 0; i < 160; i++)
         cTab[i] = RGB(((frame >> 1) - i + 16) & 7,
            (i - frame + 8) & 15, ((frame >> 2) + i) & 31);   //plain ol' color equation
      while(REG_VCOUNT == 160);
      while(REG_VCOUNT != 160);   //just VSync
      REG_DM0CNT_H = 0;
      REG_DM0DAD = 0x5000000;
      REG_DM0SAD = (u32)(cTab + 1);   //because the first HBlank happens at the END of the first line
      REG_DM0CNT = 1 | BIT22 | BIT25 | BIT29 | BIT31;
      ((u16*)0x5000000)[0] = cTab[0];   //set pal for first line
      frame++;
   }
   return 0;
}


Try that out, it does a little scrolling color effect. Tested and working in VBA, so if it still won't work, I have no idea why.
Good luck^_^
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#15186 - batblaster - Sun Jan 18, 2004 6:26 pm

Hey DekuTree64,

Many many thanks now i understand why did not work mine hehehe great and good work... Is funny to found any time new good programmer and good guys... Thanks again a lot...
_________________
Batblaster / 7 Raven Studios Co. Ltd
------------------------------------------

#15305 - LOst? - Tue Jan 20, 2004 7:13 pm

Thankyou, Thankyou, Thankyou all!

I've got the pole position to work, with interrupts and all. And it's so fucking great! I cry everytime I see it in action.

Thanks!