#9193 - jonathan_ingram - Wed Jul 30, 2003 2:34 pm
Hello,
Please can anyone help me out with the method you draw to the screen using mode 4......I'm currently using mode 3 and the syntax goes as such:
setMode(SCREENMODE3 | BG@ENABLE);
VideoBuffer( x + y*240) = RGB(31,31,31);
Would draw a white pixel at x,y.....do you have to load the palette as an array for mode4? Because if i simply switch SCREENMODE3 to SCREENMODE4 nothing is drawn to the screen.
It's a bit of a trivial problem i know but if someone could help it'd be appreciated. Cheers.
#9195 - niltsair - Wed Jul 30, 2003 2:39 pm
Mode4 is paletted which means you have to :
-Load 256colors in the palette video memory
-Instead of writing colors to the screen, you write index to your palette.
#9197 - jonathan_ingram - Wed Jul 30, 2003 2:47 pm
Got it (i think, should 240 be replaced with 120?)
Something like this?
void plotPixel(int x, int y, int c)
{
setMode(SCREENMODE4 | BG2ENABLE);
VideoBuffer(x + y*240) = c;
}
Where c is the the reference to the colour location in the loaded palette?
Also which mode 3, 4 or 5 is best for double buffering? To my knowledge 3 has none, 4 and 5 have, so which is recommended?
#9200 - niltsair - Wed Jul 30, 2003 3:06 pm
A little thing to be aware, video memory can only written 16bits at a time. So, if you only want to write 1 pixel in mode 4, then you have to read 2pixels values, replace one, write them back.
Mode 4 work fullscreen with double-buffering. There's a possibility to do the same in mode 5, but ti will mean to scale the background. You could also create your own double-buffering while still using mode 3. The GBA has 256k of external ram, you could use it to draw your things there, and then send it to the screen on VCount interrupt.
#9201 - jonathan_ingram - Wed Jul 30, 2003 3:11 pm
Thanks, especially for the mode 3 double buffering idea.
#9202 - niltsair - Wed Jul 30, 2003 3:21 pm
By sending it to the screen, I meant using Dma and not a loop ;-)
#9204 - tepples - Wed Jul 30, 2003 5:02 pm
Mode 3 graphics can be double-buffered in either of two ways:- through a software page flip, that is, a DMA copy from RAM, or
- through a hardware page flip, which involves stretching the screen by a factor of 2 horizontally (BGAFFINE[2].pa = 0x80) and then scrolling to each of the buffers (BGAFFINE[2].x_origin = 120 << 8).
The second method is similar to the "rotated mode 5" but doesn't involve a rotation.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#9217 - Archeious - Wed Jul 30, 2003 9:57 pm
jonathan_ingram wrote: |
Hello,
Please can anyone help me out with the method you draw to the screen using mode 4......I'm currently using mode 3 and the syntax goes as such:
setMode(SCREENMODE3 | BG@ENABLE);
VideoBuffer( x + y*240) = RGB(31,31,31);
Would draw a white pixel at x,y.....do you have to load the palette as an array for mode4? Because if i simply switch SCREENMODE3 to SCREENMODE4 nothing is drawn to the screen.
It's a bit of a trivial problem i know but if someone could help it'd be appreciated. Cheers. |
You just have to remember that the GBA has to transfer 16bit at a time. So you have to pull the word and mask off the offensive bit and mask in the correct bits.
Code: |
void plotPixel(u16 x, u16 y, u8 c)
{
u16 tempPixel;
setMode(SCREENMODE4 | BG2ENABLE);
// Mask off lowest bit to assure the value is word aligned
tempPixel =VideoBuffer[(x && 0xFFFE) + y*240];
// If x is odd then the new pixel is the second byte in the word
if (x && 0x0001)
{
tempPixel = tempPixel & 0xFF00; // mask off second byte
tempPixel = tempPixel | c; // OR the color into the temp pixel
} else {
tempPixel = tempPixel & 0x00FF; // mask off the first byte
tempPixel = tempPixel | ( c << 8); // shift the color 8 and then OR it.
}
VideoBuffer[(x && 0xFFFE) + y*240] = tempPixel; // move the entire word back into the video memory
} |