The main goal was achieved - i got it typing by one letter after another, but when it came to the next line (or even next string), it duplicated what I've written before and overwriting it with typewriter effect. Seems like it memorizes the string and pastes it as an array of tiles.
There is another problem - each call takes amount of time before next string appears on the screen.
Here's the rom and the source code, If someone could help me with it, i would be very happy :3
Code: Select all
#include <genesis.h>
#define _countof(a) (sizeof(a)/sizeof(*(a)))
#define xcentr(i) (VDP_getScreenWidth()/8)/2-(strlen(i)/2)
void typewrite(const char *str, u16 y);
const char * letter[]=
{
"Dear santa,",
"I've been good all year.",
"Okay, most of the time.",
"Well, most in a while.",
"Oh... never mind,",
"I'll buy my own stuff!"
};
int main()
{
for(u16 i = 0; i < _countof(letter); i++)
typewrite(letter[i], i+10);
while(1)
VDP_waitVSync();
return 0;
}
static u16 text_basetile;
void typewrite(const char *str, u16 y)
{
u32 len;
u16 data[128];
const u8 *s;
u16 *d;
u16 i;
VDPPlan plan = PLAN_A;
u16 x = xcentr(str);
// get the horizontal plan size (in cell)
i = (plan.value == CONST_PLAN_WINDOW)?windowWidth:planWidth;
len = strlen(str);
// if string don't fit in plan, we cut it
if (len > (i - x))
len = i - x;
s = (const u8*) str;
d = data;
while(i--)
{
*d++ = TILE_FONTINDEX + (*s++ - 32);
VDP_setTileMapDataRectEx(plan, data, text_basetile, x, y, len, 1, len);
waitMs(50);
}
}