I’m still trying to figure this stuff out myself, but these are my observations:
-
As far as I know, in the current version of the emulator, only the fast mode (110 by 88) is guaranteed to work.
-
It looks like the display.directPixel function writes a pixel to the screen without going through the pixel logic. Use display.drawPixel instead.
-
It appears that you need the " if (game.update()) { " check if you are doing graphics updates.
This version appears to work (but it is very green…)
#include "pokitto.h"
Pokitto::Core game;
unsigned short pal[256];
char buff[220*174];
int PntClr(int x, int y){
return buff[x+game.display.width*y];
}
void Dot (int x, int y, int c){
// create a buffer for the screen image
buff[x+game.display.width*y]=c;
}
int RandMinMax(int min, int max){
return rand() % max + min;
}
int Adjust (int xa, int ya, int x, int y, int xb, int yb){
if(PntClr(x, y) != 0) return 0;
int q = abs(xa - xb) + abs(ya - yb);
int v = (PntClr(xa, ya) + PntClr(xb, yb)) / 2 + (RandMinMax(0,q*10)) / 10;
if (v < 1) v = 1;
if (v > 255) v = 255;
Dot(x, y, v);
return 1;
}
void SubDivide (int x1, int y1, int x2, int y2){
if ((x2 - x1 < 2) && (y2 - y1 < 2)) return;
int x = (x1 + x2) / 2;
int y = (y1 + y2) / 2;
Adjust(x1, y1, x, y1, x2, y1);
Adjust(x1, y2, x, y2, x2, y2);
Adjust(x2, y1, x2, y, x2, y2);
Adjust(x1, y1, x1, y, x1, y2);
if(PntClr(x, y) == 0) {
int v = PntClr(x1, y1) + PntClr(x2, y1) + PntClr(x2, y2);
v = v + PntClr(x1, y2) + PntClr(x1, y) + PntClr(x, y1);
v = v + PntClr(x2, y) + PntClr(x, y2);
v = v / 8;
Dot(x, y, v);
}
SubDivide(x1, y1, x, y);
SubDivide(x, y, x2, y2);
SubDivide(x, y1, x2, y);
SubDivide(x1, y, x, y2);
}
void make_plasma(void){
int i=0;
for(i=0; i<game.display.width*game.display.height; i++) {
buff[i]=0;
}
srand(1890462285);
Dot(0, 0, RandMinMax(0,255) + 1);
Dot(game.display.width-1, 0, RandMinMax(0,255) + 1);
Dot(game.display.width-1, game.display.height-1, RandMinMax(0,255) + 1);
Dot(0, game.display.height-1, RandMinMax(0,255) + 1);
SubDivide(0, 0, game.display.width-1, game.display.height-1);
}
void make_pal(void){
int a,s,r,g,b;
for(a=0; a<=63; a++){
s = 0; r = a; g = 63-a; b = 0; pal[a+s] = game.display.RGBto565(r*4,g*4,b*4);
s = 64; r = 63-a; g = 0; b = a; pal[a+s] = game.display.RGBto565(r*4,g*4,b*4);
s = 128; r = 0; g = 0; b = 63-a; pal[a+s] = game.display.RGBto565(r*4,g*4,b*4);
s = 192; r = 0; g = a; b = 0; pal[a+s] = game.display.RGBto565(r*4,g*4,b*4);
}
game.display.load565Palette(&pal[0]);
}
int main(){
game.begin();
game.display.setColorDepth(8); // is this needed in the simulator?
game.display.width = 110; // full size
game.display.height = 88;
game.setFrameRate(30); // doesn't matter what this is, speed isn't an issue with this demo
make_pal();
make_plasma();
while (game.isRunning()) {
if (game.update()) {
game.display.rotatePalette(1);
for(int y=0; y<game.display.height; y++){
for(int x=0; x<game.display.width; x++){
//game.display.directPixel(x,y,buff[x+220*y]);
game.display.drawPixel(x,y,buff[x+110*y]);
}
}
}
}
return 1;
}
Catsfolly