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 > Help with drawing a simple tiled background

#178484 - themanwhoran - Wed Sep 23, 2015 3:38 pm

Hi everyone, I'm new to the GBAdev forums. I know the C programming language fairly well but I am having trouble drawing a background on my GBA game. I am trying to make a football field kicking game where the ball moves back and forth on the screen and you have to press the button at the right time to kick the goal correctly. So far I have drawn a background image in Usenti ( http://i.imgur.com/VqWPmFT.png ) and exported it to a tilemap. I got this as the export ( https://www.mediafire.com/folder/cm1dfdjq9a4b6/fieldbgexport ). I have been following TONC's tutorial to make GBA games but I will admit it's a little technical and confusing for me. Anyway using the tutorial for making backgrounds as a model I tried to display my background using this ( http://i.imgur.com/vKS5r6V.png ) as my source code and got this outputnin the emulator ( http://i.imgur.com/V767GzB.png ). If someone could help me through this problem and explain where I went wrong that would be amazing. I have been stuck on this for a while and it would be great if I could understand more what I am coding, I have been copying TONC's code and halfway understanding what I am doing but I guess all the concepts I should have been studying up on have finally caught up to me. Here is a download link for my entire project ( http://www.mediafire.com/download/gzk4c94997c499l/feildgoalgame_2.0.zip )

#178485 - sverx - Thu Sep 24, 2015 10:49 am

I wonder if the problem arises from the original image which is true color instead of palettized. Try saving it as a 16-color image...
_________________
libXM7|NDS programming tutorial (Italiano)|Waimanu DS / GBA|A DS Homebrewer's Diary

#178486 - themanwhoran - Fri Sep 25, 2015 3:02 pm

sverx wrote:
Try saving it as a 16-color image...


Here is the output when I save it as a 16 color image. ( http://i.imgur.com/fLaHLlj.png )

I think it is a problem with where I place the tiles. Notice how pieces of the sun are pasted on the other side of the screen and the letters across the field are jumbled. Perhaps a problem with my source code.Thoughts?

#178487 - sverx - Mon Sep 28, 2015 10:24 am

BG0 can't be 'affine', so you probably want to make it 'text'. Not sure if that's the problem anyway...

also, I meant you could save your image as 16 colors using your own palette, not 'windows' one :)
_________________
libXM7|NDS programming tutorial (Italiano)|Waimanu DS / GBA|A DS Homebrewer's Diary

#178491 - themanwhoran - Fri Oct 02, 2015 3:02 pm

sverx wrote:
BG0 can't be 'affine', so you probably want to make it 'text'. Not sure if that's the problem anyway...

Ok I'm not quite sure what you mean by change it to 'text' the only other function I have access to is BG_REG. (http://i.imgur.com/dBFYBch.png) I did this and it didn't change anything. One thing I have noticed is that when I compile I get a warning "incompatible implicit declaration of built-in function memcpy" which should mean that memcpy has not been defined. I looked through my header files and, sure enough, I could not find memcpy. However, when I compiled TONC's background demo ( http://www.mediafire.com/download/7it8nkf0xf1s4i8/brin_demo.zip ), which has the same header files as me there is no warning

sverx wrote:
also, I meant you could save your image as 16 colors using your own palette, not 'windows' one :)

Forgive my stupidity but I cannot figure out how to do this. I figured that the box on the right was for creating pallattes, and the '16' button changes it to a 16 color image but when I color pick the colors from my image and hit the '16' button I get this as export ( http://i.imgur.com/pBIbSng.png ). Thank you so much for your help and sorry for being such a noob. I really appreciate that you are willing to help me.

#178492 - sverx - Tue Oct 06, 2015 9:58 am

BG_REG_32 seems correct. But I really can't get what's wrong. I suspect there could be a bug in usenti (I use 'grit' instead... you might want to try that too...)
_________________
libXM7|NDS programming tutorial (Italiano)|Waimanu DS / GBA|A DS Homebrewer's Diary

#178495 - elhobbs - Tue Oct 06, 2015 6:04 pm

I think tonc provides an arm asm version of memcpy.

#178507 - themanwhoran - Fri Oct 16, 2015 3:29 pm

elhobbs wrote:
I think tonc provides an arm asm version of memcpy.

Again, forgive my stupidity, but asm? As in assembly language? I am using C on my project, is it possible to integrate assembly into my code? Thank you for the help.

#178510 - gauauu - Mon Oct 19, 2015 6:48 pm

themanwhoran wrote:

Again, forgive my stupidity, but asm? As in assembly language? I am using C on my project, is it possible to integrate assembly into my code? Thank you for the help.


Yeah, it's not complicated to integrate assembly language. I'm not expert on it, but if you are using devkitPro's standard makefiles, adding an assembly language file with a .s file will automatically get compiled properly. Then you can add a header file that declares the function, and then call it like a regular C function.

Some examples, thanks to Cearn:

In ndscpy.s
Code:

@ ---------------------------------------------------------------------
@ EXTERN_C void ndscpy(const void *srcv, void *dstv, uint size);
@ ---------------------------------------------------------------------

   @ .section .iwram, "ax", %progbits
   .text
   .arm
   .balign 32
   .global ndscpy
ndscpy:
   cmp      r2, #0
   bxeq   lr
   stmfd   sp!, {r4-r9}
/*  ....etc, rest of assembly function ommitted */


Then in ndscpy.h:

Code:

void ndscpy  (const void *srcv, void *dstv, unsigned int size);


Then you can call it like any normal function:
Code:

   ndscpy(src, dest, length);