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 > I'm really failing with the GBA ;.;

#25975 - LOst? - Thu Sep 02, 2004 5:07 am

Everything has to do with the way you set up the game loop, and the way you use interrupts. I have no control over what's being executed first.

An example would be my biggest dream: To have a scanline based scrolling engine.

At first I used multiple Interrupts with that CRT.S, and it didn't really give that much CPU time at all for the effects i wanted. I got flickering scanlines and stuff. I'm still very unhappy with the way you set up interrupts. But I have no other choices than to go along with that CRT.S because I don't want to learn that assembler, just to get a result worse than the current one.

With over 48 hours of fixing the HBlank, I got the effect I really wanted, except it did only work in Visualboy Advance. Any other emulator would crash or show the scanlines the wrong way.
On the real hardware, the result was.... okay. That stupid scanline number 0 wouldn't scroll correct >.<;;; And that was my main goal with those 48 hours >.<;;;;;;

I also spent 9 hours debugging a commercial game to find out how they did the scanline scrolling.
They do it with something called HDMA. I tried to use HDMA myself with these flags just like they did:
DMA0(&(REG_BG0HOFS), &VTable [0], 0x1, DMA_TIMEING_HBLANK | DMA_ENABLE | DMA_REPEATE | DMA_DEST_FIXED | DMA_SOURCE_INCREMENT);

And the result: BAD! It didn't even sync the frame, and then I had tried using the VBlank and the Vcounter in all ways I could find to make it sync, but still...... BAD.

PLUS! The scanline 0 was not scrolling in the same way as the rest of the scanlines. So.......?

WTF is wrong with the GBA? Why is is so unsychronized?

#25976 - DekuTree64 - Thu Sep 02, 2004 6:37 am

That top scanline is caused by the fact that HBlank occurrs at the END of the scanline, and the last scanline before the top of the screen is the one at the bottom of the screen, so you have to sort of shift your table back one space to get the right values on each scanline.
I think either HBL interrupt or HDMA occurrs even during VBlank, but I can't remember which. Seems like it was DMA, and you have to restart that manually on VBlank anyway, so it doesn't cause any table problems.
If you want to do much anytyhing but set a couple of registers or something, you'll most likely have to write your interrupt routine in ASM. ARM ASM is really fun and understandable compared to x86 though, ldr is the only confusing instruction, because you have to load symbols, and then the values stored at those symbols and such. Not too bad though.

Anyway, HDMA is better if you only want to change one register each scanline, but won't do you much good if you want to do a lot of different things.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#25978 - poslundc - Thu Sep 02, 2004 1:49 pm

DekuTree64 wrote:
That top scanline is caused by the fact that HBlank occurrs at the END of the scanline, and the last scanline before the top of the screen is the one at the bottom of the screen, so you have to sort of shift your table back one space to get the right values on each scanline.


Also: you should set up the display of your first line during VBlank so that it is displayed before the first HBlank occurs.

Quote:
I think either HBL interrupt or HDMA occurrs even during VBlank, but I can't remember which. Seems like it was DMA, and you have to restart that manually on VBlank anyway, so it doesn't cause any table problems.


HBlank interrupts occur throughout all 225 scanlines. HDMA occurs only in the 160 VDraw scanlines.

Quote:
If you want to do much anytyhing but set a couple of registers or something, you'll most likely have to write your interrupt routine in ASM. ARM ASM is really fun and understandable compared to x86 though, ldr is the only confusing instruction, because you have to load symbols, and then the values stored at those symbols and such. Not too bad though.


When I first started working with HBlank interrupts and they worked on software but not so well on hardware, it turned out to be because of speed. HBlank is incredibly short, and interrupts have to be incredibly fast. ASM is definitely the way to go.

Quote:
Anyway, HDMA is better if you only want to change one register each scanline, but won't do you much good if you want to do a lot of different things.


Word.

Dan.

#25985 - MumblyJoe - Thu Sep 02, 2004 4:57 pm

Out of interest could you describe the effect you are aiming for? Maybe someone can come up with a more abstract idea for doing it.
_________________
www.hungrydeveloper.com
Version 2.0 now up - guaranteed at least 100% more pleasing!

#26001 - LOst? - Thu Sep 02, 2004 10:56 pm

MumblyJoe wrote:
Out of interest could you describe the effect you are aiming for? Maybe someone can come up with a more abstract idea for doing it.


http://www.logotypes.se/tmp/gbahdma.avi

Here is a video I recorded. The commercial game here uses one background (BG3 as shown) to scroll the clouds in different speeds, but also makes a cool water ripple effect. All of this is done by HDMA.

I can't seem to get HDMA to be synchronized with the Vblank, so it isn't easy to fix the top scanline problem when HDMA starts the frame after the last Vblank, or before... Not really at the same visible frame.