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.

DS development > Software and Hardware

#104317 - TheWopr - Thu Sep 28, 2006 12:57 am

I'm sure this is one of the most complicated topics of the DS. Taking your program that works fine on your computer and watching it fail on your DS. I've run across this same problem, due to the lack of tutorials that talk about this, i was wondering if anyone could look over my code. I commented just about everything to make it easy to understand.

I'll go over what does work for now. It does draw to the background in order to create the background color, blue. It just receive input, restarting the game using select works and starting with start works too. It doesn't draw the players though, maybe something with transparency? One more thing is that I'm testing this on an M3 SD phat. And before people take the obvious answer, i did start of my program with powerON(POWER_ALL)

Heres a link to my code, feel free to look through it or even reuse if you want....woprDS

#104321 - josath - Thu Sep 28, 2006 1:57 am

When you draw to a 16bit background in mode 5, you need to set bit 15 if you want it to not be transparent. for example, replace this code:

Code:
        for(int i = 0; i < LENGTH; i++){
                BG_GFX[(int)(player[i].getX() + ((int)player[i].getY()  )*256)    ] = player[i].getColor(); //Topleft pixel
                BG_GFX[(int)(player[i].getX() + ((int)player[i].getY()  )*256) + 1] = player[i].getColor(); //Topright pixel
                BG_GFX[(int)(player[i].getX() + ((int)player[i].getY()+1)*256)    ] = player[i].getColor(); //Botleft pixel
                BG_GFX[(int)(player[i].getX() + ((int)player[i].getY()+1)*256) + 1] = player[i].getColor(); //Botright pixel
        }

with:
Code:
        for(int i = 0; i < LENGTH; i++){

                // it's probably faster to do this once instead of 4 times
                int pixel = (int)player[i].getX() +
                                (int)player[i].getY()*256;

                // again, put it all in one statement to make it faster i guess
                BG_GFX[pixel] = BG_GFX[pixel+1]
                  = BG_GFX[pixel+256] = BG_GFX[pixel+257]
                  = player[i].getColor() | BIT(15); // add in bit 15 to make it visible
        }

#104325 - TheWopr - Thu Sep 28, 2006 2:30 am

Wow >.< thats how i feel right now. I even set the BIT(15) on earlier draw functions. Thanks for finding that though, it always helps to get a second look. That code should make things run faster though, thanks josath :D

#104330 - TheWopr - Thu Sep 28, 2006 2:47 am

Ok your code made sense, but unfortunately it still does not draw the players when i'm running it on hardware >.< any other ideas?

#104336 - josath - Thu Sep 28, 2006 3:03 am

try adding this code for the main bitmap background:
Code:
        BG3_XDX = 1 << 8;
        BG3_XDY = 0;
        BG3_YDX = 0;
        BG3_YDY = 1 << 8;
    //our bitmap looks a bit better if we center it so scroll down (256 - 192) / 2
        BG3_CX = 0;
        BG3_CY = 0;

these set up the scaling & scrolling registers to default settings (offset:0,0, scaling: 100%x100%), perhaps the hardware has different defaults

#104400 - TheWopr - Thu Sep 28, 2006 6:35 pm

Alright what you said makes sense, so i added it bu unfortunately it still doesn't work >.<, I don't really have any ideas, this is my first program for the DS after all, any more help would be great.

#104401 - josath - Thu Sep 28, 2006 6:43 pm

I can't see anything else obviously missing. my only suggestions are:
1. make sure other homebrew works
2. if you still can't figure it out, take one of the libnds or someone's example, make sure it works, then slowly add in your code into the example, making sure it works as you add each new piece.

#104406 - TheWopr - Thu Sep 28, 2006 7:05 pm

Ok i've been looking at other tutuorials and i've seen that some of them use VRAM_A[i] for their drawing function and some use BG_GFX[i], could this have anything to do with it? And if so, whats the difference between them anyway.

#104479 - TheWopr - Fri Sep 29, 2006 4:52 pm

Anyone got any ideas? I can't really move forward with my project until I get it working on an actual DS

#104520 - josath - Sat Sep 30, 2006 1:35 am

If you're really stuck, and there's nothing else you can do, I'd suggest you try my #2 as above.

#104525 - knight0fdragon - Sat Sep 30, 2006 3:00 am

I just tested your code, josath is correct, you need to set the affine matrix to its identity
_________________
http://www.myspace.com/knight0fdragonds

MK DS FC: Dragon 330772 075464
AC WW FC: Anthony SamsClub 1933-3433-9458
MPFH: Dragon 0215 4231 1206