#6892 - hzx - Wed Jun 04, 2003 8:45 am
hello
i feel myself as a mega-newbie, because i totally stucked with a code. It wants to be a mode3 double buffer, in which you always draw into the background buffer and then copy it to VideoBuffer on VBlank. Here it is:
u16 *DrawBuffer = (u16 *)0x02000000;
// Backbuffer in EWRAM, because it is bigger than 32K
void Wkey() {
while ((*KEYS) & 1) {
};
}
// just for debugging purposes
void CopyDrawBuffer() {
REG_DMA3SAD = (u32)DrawBuffer;
REG_DMA3DAD = 0x06000000;
REG_DMA3CNT = 38400 | DMA_ENABLE;
}
// use DMA to copy the backbuffer to VideoBuffer
void DMAClearDrawBuffer() {
REG_DMA3SAD = 0x05000000;
REG_DMA3DAD = (u32)DrawBuffer;
REG_DMA3CNT = 38400 | DMA_ENABLE | DMA_SOURCE_FIXED;
}
// this one clears the backbuffer. Takes the zero value from the Palette[0]
void StupidClear() {
int i;
for (i = 0; i < 38400; i++) {
DrawBuffer[i] = 0;
}
}
// a debug clearscreen, filling background buffer with zeros
int main() {
int i;
SetMode(MODE_3 | BG2_ENABLE);
i = 1000; // for a little demonstration
while(1) {
DrawBuffer[i] = RGB16(31,31,31);
WaitForVSync();
CopyDrawBuffer();
Wkey();
i++;
DMAClearDrawBuffer();
// StupidClear();
}
So, when i run the code, the screen remains blank until the first keypress, which is strange, because the CopyDrawBuffer should display the white pixel in the 1000th position of VideoBuffer. After the first keypress, the code works as it is expected, BUT! only with the stupid clear routine - the DMA version clears the screen though, the program doesnt work at all. Maybe i am missing some oblivious, but i cannot see it. Somebody can help me?
_________________
.hzx
#6896 - djei-dot - Wed Jun 04, 2003 10:40 am
Mode 3 doesn't have a backbuffer. You have to use mode 4.