256 colour mode?

I had a quick try to make my plasma code work in 256 colour mode, but the screen does not update correctly.

it seems to still only use 16 colours and the buffer does not seem to align properly.

#include "Pokitto.h"

Pokitto::Core game;

unsigned short pal[256];
//char buff[110*86];
char buff[72*58];
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;
		game.display.screenbuffer[i]=0;
	}
	srand(game.getTime());
	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);
	}
}
int main(){
	game.begin();

	game.display.width = 72;
	game.display.height = 58;
	//game.setFrameRate(60);
	game.display.persistence = 1 ;

	make_pal();
    game.display.load565Palette(pal);

    make_plasma();
    int colNum = 0;

    while (game.isRunning()) {
        if (game.update()) {
            for(int y=0; y<game.display.height; y+=1){
                for(int x=0; x<game.display.width; x+=1){
                    game.display.drawPixel(x,y,pal[(colNum+buff[x+game.display.width*y])&255]);
                }
            }
            colNum+=2;
            colNum&=255;
        }

    }
    return 1;
}
1 Like

What settings are you using for the project?

#define PROJ_HIRES              0       // 1 = high resolution (220x176) , 0 = low resolution fast mode (110x88)
#define PROJ_ENABLE_SOUND       1       // 0 = all sound functions disabled
#define PROJ_STREAMING_MUSIC    1       // 1 = enable streaming music from SD card
#define PROJ_GBSOUND            0       // 1 = use Gamebuino-compatible sound interrupt (choose this or the one below)
#define PROJ_ENABLE_SYNTH       1       // 1 = use Rboy-compatible sound interrupt
#define PROJ_GAMEBUINO          0       // 1 if you are making a Gamebuino-based graphics mode (84x48)
#define PROJ_MODE_256_COLOR 1

I’ve started trying to create 256 colour 110x88 mode. I’m failing a lot :stuck_out_tongue: