#38338 - utilizes - Sat Mar 26, 2005 12:53 pm
Hello. I have been doing Mode 4 games for a few months now, but now I wish to go onto scrolling. I used the Webbesen tutorial. I have read the FAQ but it does not detail how to do it. Could somebody please tell me how to do this ot show me a place where I can learn this?
I have looked at the Pern Project, but recently the scrolling is not there, and I never had the chance to look at it.
Thank you for your hopeful replies,
Utilizes.
#38339 - Wriggler - Sat Mar 26, 2005 1:32 pm
Look for a tutorial on Mode 0 graphics. You'll need to load tiles and maps into memory in a certain way, and then it's just a case of updating a single register to do scrolling. It's easy, once you've got it all set up.
Ben
#38343 - Kyoufu Kawa - Sat Mar 26, 2005 3:08 pm
Code: |
#define REG_BG0HOFS 0x04000010 //found in several forms in several available headers
u16 myScrollCounter;
//elsewhere...
myScrollCounter++; //or whatever you wanted to do...
//after VBlank...
*(vu16 *)REG_BG0HOFS = myScrollCounter;
|
Quick and easy. Thankyoudrivethrough.
Edit: That's the register thingy Wriggler just mentioned.
#38345 - utilizes - Sat Mar 26, 2005 3:19 pm
Thank you! Can scrolling be done only in Mode 0?
#38346 - Kyoufu Kawa - Sat Mar 26, 2005 3:30 pm
Very muchly not. Lemme look it up...
Nope. Scrolling in this manner works for any non-rotscale background layer, so that's all four layers in mode 0 and the first two in mode 1. Any rotating/scaling layer needs a different approach, which applies to BG2 in mode 1 and BG2 and 3 in mode 2, which lacks BGs 0 and 1.
I suggest, unless you need a rotscaling layer, that you stick to mode 0.
Last edited by Kyoufu Kawa on Sat Mar 26, 2005 3:34 pm; edited 1 time in total
#38347 - ymalik - Sat Mar 26, 2005 3:30 pm
No, you can do it mode 4, too, but it's just easier in mode 0. In mode 4 you'll have to work with two buffers in VRAM: when one buffer is being drawn, update the second buffer, and then swap the two buffer (this requires simply flipping a big in a register). Of course, if you want to scroll a massive image in mode 0, that's much harder.
#38350 - Kyoufu Kawa - Sat Mar 26, 2005 3:36 pm
Yeah, massive maps kill a newbie a day. But at least Util now knows how to work the registers.
#38356 - utilizes - Sat Mar 26, 2005 4:11 pm
I now understand how it works and what it should do, but i do not know how to implement it. I have looked at the tutorial "Backgrounds in Modes 0-1-2" but it does not show how to actually do it. Could one of you please point me in the right direction?
#38371 - ymalik - Sat Mar 26, 2005 7:41 pm
Try scrolling around in 256x256 background first. Load the tileset and tilemap data created from gfx2gba and based on the arrow key, either decrement or increment the x, y values. Then load the x, y values into the offset registers of the background. Checkout chapter 6 of Harbour's book to how to do it.
#38375 - utilizes - Sat Mar 26, 2005 8:07 pm
As I have never done tile modes, i really do not understand the J Harbour E-Book chapter you just mentioned. Also, I use devkitadv. As for some reason I can't download anything from the gbadev.org site (it says the HTTP referrer doesn't allow me to do anything).. I can't download any source codes. Does anyone have alternate addresses for code? Thank you..
#38409 - ymalik - Sun Mar 27, 2005 4:39 am
If you're new to GBA programming, I recommend using HAM. This has everything you need to start developing.
#38415 - utilizes - Sun Mar 27, 2005 9:07 am
But I can cope fine with DevkitAdv, just not scrolling.. Oh well, I will give it a try.. Still, if anyone does have any code for me, you know who I am.
#38427 - ymalik - Sun Mar 27, 2005 6:14 pm
Here is some code:
http://www.cs.stevens.edu/~ymalik/tilemode0.zip
It is from Harbour's book with some modifications.
#38431 - utilizes - Sun Mar 27, 2005 8:22 pm
Thanks for that file, and it works with DevKit Adv, but there is one problem. WhenI try to change the background, it looks absolutely nothing like the one I actually made. could you try changing the background, and if it works tell me how?
Thanks.
#38453 - ymalik - Mon Mar 28, 2005 1:27 am
That's probably because you are using an 8 BPP image. Use a program like PictView32 to reduce the palette to 4 BPP. Make sure to run gfx2gba with the -c16 option. Also, make sure you that you change the amount of bytes copied in the the call to DMAFastCopy that copies the tile set. If you want to use an 8 BPP image, then you'll have to change REG_BG0CNT and the two calls to DMAFastCopy that deal with the palette and tile set.
#38478 - utilizes - Mon Mar 28, 2005 9:31 am
OK, thanks. I'll try it out now.
Yay, it works. But it only displays half of the image.. I coudln't work out how to use that utility you suggested, so I used paint and saved it as a 16-color Bitmap, which did the job.
See Below Now.
EDIT : Actually, I just found a nicer way to do it : Use less than 16 colours in a palette in Photoshop Elements, and it'll let you save as 8 BPP anyway. I've also resloved the half image.
Also, i have now resolved the problem I had. It only seemed to happen with the map I tried to use borrowed from J Harbour. however, when I use my own, it works.
EDIT #2 : most simple maps work, but more complex ones only show about half..
#38490 - ymalik - Mon Mar 28, 2005 3:35 pm
You're getting half of image because you probably haven't changed how many tiles you're copying in the call to DMAFastCopy():
Code: |
//copy the tile images into the tile memory
DMAFastCopy((void*)Tiles, (void*)CharBaseBlock(0),
12064/4, DMA_32NOW);
|
You'll have to change the "12064" to whatever number of bytes is in the array generated by gfx2gba.
#38595 - utilizes - Tue Mar 29, 2005 12:39 pm
This is all very good so far, and I can modify the backgrounds to my needs. However, I can't seem to work otu how to use sprites with this background. I'm trying to do it the way I did in Mode 4 things by including "gba.h" and then showing the attributes and WaitForVblank()ing and CopyOAM()ing but it doesn't seem to work.
#38599 - ymalik - Tue Mar 29, 2005 2:37 pm
Why don't you post some code? It should be the same in mode 0 as well. I also recommend using PictView32 because it seems to save most of the important colors. For example, the map I had in my zip file was actually a 8 BPP image, but when I reduced the palette in MSPaint, the beige became gray. Do PVW32Con [file to covert] -w --c16. PictView is also from the command line so you can do batch processing.
#38607 - utilizes - Tue Mar 29, 2005 3:57 pm
Instead of using the Paint feature (which screwed up all of my colours totally), I found a nice way in Photoshop Elements, where you make it Indexed colours, draw your map in another window, then put only the colours which are in the other window into your palette, by cutting the current colours (ctrl+click rears its head on Windows) and then use the colour-dropper tool to get the colours from the other image. You could also draw your image in that window at choose Exact in the Palette Menu, but you can't always select it. Then, you can choose which colours you feel are important (up to 16 of them) and choose them. Then, when you choose to save as .bmp, it allows you to choose the value you want, which if you used under 16 colours, will be the only available one : 8BPP.
The code I use for putting my sprites up is as follows :
Code: |
//this sets out the attributes
sprites[0].attribute0 = COLOR_256 | SQUARE | 50;
sprites[0].attribute1 = SIZE_8 | 50;
sprites[0].attribute2 = 512;
//then I copy it over
WaitForVsync();
CopyOAM();
|
I like to use pcx2gba for my sprites, instead of gfx2gba which I use for my maps. I find it is far easier for sprites as there are often lots of them, and you can just drag the sprite onto the executable.
Maybe the reason my sprites don't show up is that I'm not doing this right.
Do I have to use tiled options with gfx2gba perhaps? If so, what would I do?
If you want to see my definitions, it is just from http://www.webbesen.dk/gba's tutorial.
#38651 - ymalik - Tue Mar 29, 2005 11:48 pm
Show what's in CopyOAM() .
In mode 3-5, the character data memory is cut by half, so the sprite name begins at 512. Perhaps you are refering to the wrong sprite. Make sure you are copying the character data to the proper location.
#38686 - utilizes - Wed Mar 30, 2005 10:42 am
this is CopyOAM(); :
Code: |
void CopyOAM(void)
{
u16 loop;
u16* temp;
temp = (u16*)sprites;
for(loop = 0; loop < 128*4; loop++) {
OAM_Mem[loop] = temp[loop];
}
}
|
#38695 - ymalik - Wed Mar 30, 2005 2:47 pm
Are you copying the character data into the right location? Perhaps you are copying it at the beggining of tile 0, but you are using tile 512, instead.
By the way, you can use DMA to copy in the OAM data:
DMA_COPY(3, (void *) sprites, (void *) OAM, 128<<2, DMA16_NOW);
#38700 - utilizes - Wed Mar 30, 2005 4:31 pm
So what should I be writing for my sprites?
#38705 - ymalik - Wed Mar 30, 2005 7:03 pm
Post your code for copying the character data as well. Later on in the day when I'll have time I'll post a demo of space invaders-like game that I made that should give you a good idea of how to store character data.
#38757 - utilizes - Thu Mar 31, 2005 12:18 pm
This is what I do :
Code: |
memcpy( (u16 *)0x06014000, &spriteData, sizeof(spriteData) );
|
#38777 - Miked0801 - Thu Mar 31, 2005 6:38 pm
as an side, what is the sizeof() of your struct? It doesn't matter yet, but I have the feeling your swinging a sledge hammer at a thumb tack...
#38780 - ymalik - Thu Mar 31, 2005 7:09 pm
Miked0801 wrote: |
as an side, what is the sizeof() of your struct? It doesn't matter yet, but I have the feeling your swinging a sledge hammer at a thumb tack... |
Yes, is your spriteData a constant pointer or just a regular pointer?
#38823 - Miked0801 - Fri Apr 01, 2005 1:59 am
Not the point - I have a feeling that it is a standard 2 byte oam struct for which memcpy is the wrong tool for copying. It might be the larger struct which contains the affine data, but even that is not worthy of memcpy.
#38845 - utilizes - Fri Apr 01, 2005 11:13 am
How do I find the sizeof of it though? Ive looked in the pcx2sprite output file, and it doesn't have the sizeof attribute there, and I can't find it anywhere else. However, it is somewhere as DevKitAdv would kick up a fight otherwise.
#38904 - Miked0801 - Fri Apr 01, 2005 8:31 pm
Look at your assembler output or printf() it to the screen.
#39031 - utilizes - Sun Apr 03, 2005 10:34 am
You can't printf to gba screen, and I don't know where this assembler output is..
#39039 - tepples - Sun Apr 03, 2005 5:34 pm
utilizes wrote: |
You can't printf to gba screen |
You can with sprintf() and a bare-bones terminal emulator.
Quote: |
and I don't know where this assembler output is.. |
Take the command that says 'gcc -c' and turn it into 'gcc -S' instead.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#39077 - utilizes - Mon Apr 04, 2005 9:46 am
OK. It is 1024 then.
#39118 - Miked0801 - Mon Apr 04, 2005 6:24 pm
Huh? 1K for a sprite struct? Seems very high. Are you sure you didn't make an endian mistake? 0x04 0x00 is very close to 0x00 0x04
#39260 - utilizes - Wed Apr 06, 2005 6:11 pm
#39274 - tepples - Wed Apr 06, 2005 9:16 pm
1024 bytes is the size of OAM. It contains 128 structures, each of 8 bytes.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#39314 - utilizes - Thu Apr 07, 2005 10:29 am
So what should I look for in the S output?