The variables declared at the top, what are they? I wanted to put a comment to the side of each to indicate what their purpose is.
I'm trying to understand this in English. This is a critical part of the kernel and I want to make sure that I understand the modifications that I'm doing.
Goal is to get each ramtile assigned for blitting (which already works), get that new ramtile id and then modify them prior to the kernel actually blitting it. Think: Simple color palette changes.
Could someone with better knowledge explain this function better? I think it would also be good to reserve a ramtile (id 0) to work with and modify and then blit that tile to the screen. I would then need to copy that tile id to the next available ramtile id. I have a card game that I am working on that does something like this except the function is to rotate the tile. I'm doing that in user-land. The BlitSprite function runs immediately pre-vsync, right? How much time do I actually have? I'll have a 32x28 sized vram if that helps.
Code: Select all
void BlitSprite(u8 flags, u8 sprindex, u8 xpos, u8 ypos)
{
u8 bx; //
u8 by; //
u8 dx; //
u8 dy; //
u8 bt; //
u8 x; //
u8 y; //
u8 tx; //
u8 ty; //
u8 wx; //
u8 wy; //
u16 ramPtr; //
u8 ssx; //
u8 ssy; //
/* if sprite is off, then don't draw it */
if ((flags & SPRITE_OFF) != 0U){ return; }
/* get tile's screen section offsets */
ssx = xpos;
ssy = ypos;
tx = 1U;
ty = 1U;
/* get the BG tiles that are overlapped by the sprite,
** supporting wrapping (so sprites located just below zero X
** or Y would clip on the left). In a scrolling config. only
** TILE_WIDTH = 8 is really supported due to the "weird" VRAM
** layout, VRAM_TILES_H is also fixed 32 this case. */
bx = ssx / TILE_WIDTH;
dx = ssx % TILE_WIDTH;
if (dx != 0U){ tx++; }
by = ((u8)((ssy + TILE_HEIGHT) & 0xFFU) / TILE_HEIGHT) - 1U;
dy = ssy % TILE_HEIGHT;
if (dy != 0U){ ty++; }
/* Output sprite tiles */
for (y = 0U; y < ty; y++){
wy = by + y;
if (wy < VRAM_TILES_V){
for (x = 0U; x < tx; x++){
wx = bx + x;
if (wx < VRAM_TILES_H){
ramPtr = (wy * VRAM_TILES_H) + wx;
bt = vram[ramPtr];
/* if no ram free ignore tile */
if (
//
(
(bt >= RAM_TILES_COUNT)
|
(bt < user_ram_tiles_c)
)
&&
//
(free_tile_index < RAM_TILES_COUNT)
){
if (bt >= RAM_TILES_COUNT){
/* tile is mapped to flash. Copy it to next free RAM tile. */
CopyFlashTile(bt - RAM_TILES_COUNT, free_tile_index);
}
else if (bt < user_ram_tiles_c){
/* tile is a user ram tile. Copy it to next free RAM tile. */
CopyRamTile(bt, free_tile_index);
}
#if (RTLIST_ENABLE != 0)
ram_tiles_restore[free_tile_index].addr = (&vram[ramPtr]);
ram_tiles_restore[free_tile_index].tileIndex = bt;
#endif
vram[ramPtr] = free_tile_index;
bt = free_tile_index;
free_tile_index++;
}
if (
// Is this a ram tile?
(bt < RAM_TILES_COUNT)
&&
//
(bt >= user_ram_tiles_c)
){
BlitSpritePart(
bt,
((u16)(flags) << 8) + sprindex,
((u16)(y) << 8) + x ,
((u16)(dy) << 8) + dx
) ;
}
}
} /* end for X */
}
} /* end for Y */
}