#16647 - Musashi - Sat Feb 21, 2004 11:59 pm
I was wondering if anyone could figure out why this code doesn't work.
//Loading palettes
palettes[0] = sadfacePalette;
//Loading images
images[0] = sadface;
images[1] = happyface;
//Setting the mode to 4
SetMode(MODE_4 | BG2_ENABLE);
int i,j;
int x,y;
//Copy the palette into memory
for(i=0; i < 256; i++) BGPaletteMem[i] = palettes[0][i];
for(x=0; x < 120; x++) {
for(y=0; y < 160; y++) {
FrontBuffer[(y)*120+(x)] = images[0][(y)*120+(x)];
}
}
for(x=0; x < 120; x++) {
for(y=0; y < 160; y++) {
BackBuffer[(y)*120+(x)] = images[1][(y)*120+(x)];
}
}
waitForKey(KEY_START);
VSynch();
REG_DISPCNT |= BACKBUFFER;
waitForKey(KEY_START);
REG_DISPCNT |= FRONTBUFFER;
waitForKey(KEY_START);
the waitForKey function.. umm.. waits for a key and I think that's all you need to know. What happens when I run the rom is the first picture (the sad face) displays fine but the second picture overlays the first when I try to switch over to the back buffer. Please Help!
-Travis
#16648 - yaustar - Sun Feb 22, 2004 1:22 am
Shouldn't there be an inifite loop somewhere
eg
Code: |
while(1)
{
//do code
} |
From what I can guess, You exit the program and that is it...no more flipping
PS use code tags...;)
_________________
[Blog] [Portfolio]
#16650 - Musashi - Sun Feb 22, 2004 1:44 am
This code is organized much better (and its all here!) but it still has the same problem.
Code: |
#include "gba.h"
#include "keypad.h"
#include "dispcnt.h"
#include "sadface.h"
#include "happyface.h"
void waitForKey(int key);
void waitForKey(int key) {
while(*KEYS & key);
*KEYS ^= key;
}
void main() {
int i,x,y;
//Set the mode and enable background 2
SetMode(MODE_4 | BG2_ENABLE);
//Load palette into memory
for(i = 0; i < 256; i++) BGPaletteMem[i] = sadfacePalette[i];
//Load the first image into the front buffer
for(x = 0; x < 120; x++) {
for(y = 0; y < 160; y++) {
FrontBuffer[y*120+x] = sadface[y*120+x];
}
}
//Load the second image into the back buffer
for(x = 0; x < 120; x++) {
for(y = 0; y < 160; y++) {
BackBuffer[y*120+x] = happyface[y*120+x];
}
}
//wait to push start
waitForKey(KEY_START);
//switch to the backbuffer
SetMode(MODE_4 | BG2_ENABLE | BACKBUFFER);
while(1);
}
|
#16652 - yaustar - Sun Feb 22, 2004 2:00 am
Your while loop is doing nothing so it still has the same problem as last time..
_________________
[Blog] [Portfolio]
#16653 - poslundc - Sun Feb 22, 2004 2:48 am
The waitForKey() function loops infinitely until a keypress occurs, so it should work, even if it isn't really good style.
In any case, I'm not aware of how you could get the image in one buffer to overlay the image of another, not by accident anyway, and especially not if the first image is displaying correctly.
Do the images use the same palettes? It could be because you aren't copying in the other palette when you switch buffers. Other than that, your image data could be encoded incorrectly.
Dan.
#16663 - Musashi - Sun Feb 22, 2004 5:24 am
Quote: |
The waitForKey() function loops infinitely until a keypress occurs, so it should work, even if it isn't really good style. |
That's what I was shooting for.
Quote: |
Do the images use the same palettes? It could be because you aren't copying in the other palette when you switch buffers. Other than that, your image data could be encoded incorrectly. |
I'm pretty sure they use the same palette, they're both black and white so it will be pretty close. I also think I used the copy both pictures to one bitmap and get the palette from that trick. I'll try again just to be safe.
Quote: |
In any case, I'm not aware of how you could get the image in one buffer to overlay the image of another, not by accident anyway, and especially not if the first image is displaying correctly. |
You underestimate what I can do by accident :o)
#16666 - 628man - Sun Feb 22, 2004 5:47 am
This part is of interest
Code: |
void waitForKey(int key) {
while(*KEYS & key);
*KEYS ^= key;
}
|
What is *KEYS? Is that the keyboard register? I think it's READ ONLY, so you can't change it. You have to wait for a press and wait for a release.
If you wait for a press multiple times in a row, it's likely the key is still down. You have to wait for the release either before or after your function, ie while(! (*KEYS & key) );
#16667 - Musashi - Sun Feb 22, 2004 7:11 am
yeah, its the keyboard register. That's a good point. The key press thing seems to be working though since I only press it once. I agree its not coded well. The page flipping problem remains though.
#16668 - Musashi - Sun Feb 22, 2004 7:19 am
I reloaded the palette for the second picture and it fixed the problem, mostly. But a little bit of ghosting still occurs. What's up with that?
#16669 - Musashi - Sun Feb 22, 2004 7:31 am
Holy shit finally got it to work, thanks everyone for your help. This forum rocks.