#57271 - blacksun - Fri Oct 14, 2005 6:36 pm
I would like to set pixels on a text background layer. I have been doing this in Mode 3 to write text onto the screen without using sprites. The reason I can't use sprites is because I will exceed my sprite limit. I can't make the numbers tiles because they aren't 8x8 and the spacing needs to be 1 pixel.
#57279 - poslundc - Fri Oct 14, 2005 7:29 pm
Not sure what your question is, but this thread talks about some different strategies for displaying variable-width text on the GBA.
Dan.
#57304 - blacksun - Fri Oct 14, 2005 9:31 pm
Well, in Mode 3 I write text by just plotting pixels in the Video Buffer. Easy enough. On a text background i know you use tiles and maps to draw the background. Is there a way to just plot pixels on a text background instead of manipulating the tiles?
#57314 - poslundc - Fri Oct 14, 2005 10:06 pm
You can plot pixels, but you need to plot them into a tile which is displayed on the screen. This is inconvenient, but not hard to wrap your head around if you give it some thought.
Just assign a unique tile to each "slot" displayable in your BG map - 30 across by 20 down = 600 tiles. Then when you want to plot your pixel, first determine which tile you have to write to, then determine where on that tile you have to write.
The hardest part is that (in 16-colour mode) you need to write four pixels at a time, because VRAM only allows 16-bit writes and your pixels are 4-bits each. This makes plotting an individual pixel some work, because you need to load in the correct u16 from VRAM, bitwise-AND out the four bits in question and bitwise-OR in the new bits. This is no different from having to address two pixels at a time in Mode 4, though. Because of this behaviour, it's generally adviseable to try to design your system so that you paint an entire tile at a time with your output contents, rather than trying to plot individual pixels all over the place.
Dan.
#57327 - ScottLininger - Fri Oct 14, 2005 11:08 pm
Here's some (incomplete and somewhat retarded) code to do like dan is saying... But maybe it will make it more concrete. :)
-Scott
Code: |
// set up mode 0 and point a background (3 in this case)
// to a memory location (block 31 in this case)
SetMode(MODE_0 | BG3_ENABLE );
u16* bg3map =(u16*)ScreenBaseBlock(31);
// set up a u16 that will contain our actual pixel data
// note that each u16 contains the data for 4 pixels
u16* tileData =(u16*)CharBaseBlock(0);
// set up our Registers to use the above memory locations
REG_BG3CNT = BG_COLOR16 | TEXTBG_SIZE_256x256 | (31 << SCREEN_SHIFT) | (0 << CHAR_SHIFT) | BIT1;
// loop across a 30 columns and 20 rows, and set
// a unique tile into each of your 8x8 cells
int row,col;
int tileIndex = 0;
for (row=0;row<20;row++) {
for (col=0;col<30;col++) {
bg3map[row*30 + col] = tileIndex + (DESIREDPALETTEINDEX<<12);
tileIndex++;
}
}
// a couple defines to avoid "magic numbers"
#define PIXELSPERTILE 64
#define TOTALCOLS 30
void PlotPixel(int screenX, int screenY, unsigned short int c) {
int tileX,tileY,interiorX,interiorY,pixelNumber,myIndex,myPixel;
tileX = screenX/8; // figure out the "column" we're writing to
tileY = screenY/8; // figure out the "row"
interiorX = screenX - tileX*8; // figure our X offset within the tile
interiorY = screenY - tileY*8; // figure our Y offset withing the tile
// this next bit calculates the pixel "index" as if the tileData
// were a u4 array
pixelNumber = tileY*(TOTALCOLS*PIXELSPERTILE) +
tileX*PIXELSPERTILE + interiorY*8 + interiorX;
// divide by 4 to get the u16 index
// (remember that this u16 contains 4 pixels worth of data)
myIndex = pixelNumber>>2;
// remember which of the 4 pixels we're trying to write to
myPixel = pixelNumber - myIndex*4;
// pull a copy of the "original" color, since we need to change
// only one 4-bit section of the thing
u16 originalColor = tileData[myIndex];
// do some bit math to mask out our pixel and then add it to
// our new color to set just that one pixel
if (myPixel==0) {
tileData[myIndex] = (originalColor & 0xFFF0) + c;
} else if (myPixel==1) {
tileData[myIndex] = (originalColor & 0xFF0F) + (c<<4);
} else if (myPixel==2) {
tileData[myIndex] = (originalColor & 0xF0FF) + (c<<8);
} else if (myPixel==3) {
tileData[myIndex] = (originalColor & 0x0FFF) + (c<<12);
}
}
|
#58850 - thegamefreak0134 - Wed Oct 26, 2005 7:51 pm
Just what spacing are the numbers tiles? If they are multiples of 8, you can still use tiles. Just use more than one tile per number.
_________________
What if the hokey-pokey really is what it's all about?
[url=http:/www.darknovagames.com/index.php?action=recruit&clanid=1]Support Zeta on DarkNova![/url]