gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > Correct method for plotting pixels in mode 0?

#145074 - Ruben - Sun Nov 11, 2007 5:17 am

I was wondering whether this is a correct (slow) method for plotting in mode 0:
Code:
PLOT(X,Y,C,T) CBB[(Y<<1)+(X>>2)+(T<<4)] |= (C<<((X&3)<<2))

Because I've tried that a bit and it seems to work fine when doing plotting like:
Code:
int main() {
 PLOT(2, 1, 2, 3);
 PLOT(2, 2, 2, 3);
}

But it doesn't seem to work when working with image arrays. Any ideas?

PS:
In case you don't understand the bit-shifts...
Code:
PLOT(X,Y,C,T) CBB[(Y*2)+(X/4)+(T*16)] |= (C<<((X%4)*4))

#145674 - Ruben - Tue Nov 20, 2007 7:53 am

Oops. My bad. I kinda forgot a few more statements :S. So here's the solution that I think works fine lol...
Code:
#define PLOT_4BPP(X,Y,C) CBB[((X&7)>>2)+((Y&7)<<1)+((X>>3)<<4)+((Y>>3)<<9)] |= (C<<((X&3)<<2))