I'm having a problem with double-buffering on the GBA!
Because of my love of low-level programming I decided to go with the GBA and it's memory... video memory being an unsigned short at 0x6000000.
I made a random-pixel-plotter program... only to mess up making a double-buffer:
#include <cstdlib>
#include <ctime>
#include <cstring>
#include "GBA_Main.hpp"
GBA::uShort *pVideo = NULL;
GBA::uShort *pBackVideo = (GBA::uShort*)malloc(sizeof(GBA::uShort) * 240 * 160);
int main(void) {
srand(time(0));
GBA::SetMode(GBA::VIDEO_MODE3 | GBA::VIDEO_BACKGROUND2);
pVideo = GBA::GetVideo();
while(true) {
for (unsigned i = 0; i < 240; i++)
for (unsigned j = 0; j < 160; j++)
*(/*pBack*/pVideo + j * 240 + i) = GBA::Rgb16(rand() % 256, rand() % 256, rand() % 256);
//memcpy(pVideo, pBackVideo, 240 * 160 * sizeof(GBA::uShort));
}
free(pBackVideo);
return 0;
}
This is the whole two programs in one piece.... The /*pBack*/pVideo is pBackVideo on the other program, and the memcpy is not commented out...
Now, progam one returns this:(yes, the code above)
The other one WITH the double buffer is this:
Any ideas as to why?
THANKS! This is programmed in C++ in Visual HAM.
EDIT:
And her is the GBA header file, it's purely mine: (from scratch, not some lib)
#ifndef GBA_MAIN_HPP
#define GBA_MAIN_HPP
namespace GBA {
typedef unsigned short uShort;
typedef unsigned long uLong;
inline uShort *GetVideo() {
return (uShort*)0x6000000;
}
inline uLong *GetSetting() {
return (uLong*)0x4000000;
}
const int VIDEO_MODE3 = 0x3;
const int VIDEO_BACKGROUND2 = 0x400;
inline void SetMode(const uLong Type) {
*GetSetting() = Type;
}
inline uShort Rgb16(uShort r, uShort g, uShort b) {
return (r | (g << 5) | (b << 10));
}
}
#endif