Greatly improved readability of main.c

This commit is contained in:
archshift 2014-10-29 22:34:08 -07:00
parent 4b99487f8a
commit ea24bf9f92

View File

@ -16,39 +16,52 @@ s32 pcCos(u16 v)
return costable[v&0x1FF];
}
int countLines(char* str)
int countLines(const char* str)
{
if(!str)return 0;
int cnt; for(cnt=1;*str=='\n'?++cnt:*str;str++);
if (!str)
return 0;
int cnt = 1;
while (*str == '\n' ? ++cnt : *str)
str++;
return cnt;
}
void cutLine(char* str)
{
if(!str || !*str)return;
char* str2=str; for(;*str2&&*(str2+1)&&*str2!='\n';str2++); str2++;
memmove(str,str2,strlen(str2)+1);
if (!str || !*str)
return;
char* str2 = str;
while ((*str2) && (*(str2 + 1)) && (*str2 != '\n'))
str2++;
str2++;
memmove(str, str2, strlen(str2) + 1);
}
void drawFrame()
{
u8* bufAdr=gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
u8* bufAdr = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
int i, j;
for(i=1;i<400;i++)
int x, y;
for (x = 1; x < 400; x++)
{
for(j=1;j<240;j++)
for (y = 1; y < 240; y++)
{
u32 v=(j+i*240)*3;
bufAdr[v]=(pcCos(i+cnt)+4096)/32;
bufAdr[v+1]=(pcCos(j-256+cnt)+4096)/64;
bufAdr[v+2]=(pcCos(i+128-cnt)+4096)/32;
u32 v=(y + x * 240) * 3;
bufAdr[v] = (pcCos(x + cnt) + 4096) / 32;
bufAdr[v+1] = (pcCos(y - 256 + cnt) + 4096) / 64;
bufAdr[v+2] = (pcCos(x + 128 - cnt) + 4096) / 32;
}
}
gfxDrawText(GFX_TOP, GFX_LEFT, NULL, "ftPONY v0.0002\n", 240-fontDefault.height*1, 10);
i = countLines(superStr);
while(i>240/fontDefault.height-3){cutLine(superStr);i--;}
gfxDrawText(GFX_TOP, GFX_LEFT, NULL, superStr, 240-fontDefault.height*3, 20);
gfxDrawText(GFX_TOP, GFX_LEFT, NULL, "ftPONY v0.0002\n", 240 - fontDefault.height * 1, 10);
x = countLines(superStr);
while (x > (240 / fontDefault.height - 3)) {
cutLine(superStr);
x--;
}
gfxDrawText(GFX_TOP, GFX_LEFT, NULL, superStr, 240 - fontDefault.height * 3, 20);
cnt++;
gfxFlushBuffers();
@ -60,7 +73,6 @@ int main()
srvInit();
aptInit();
hidInit(NULL);
irrstInit(NULL);
gfxInit();
gfxSet3D(false);
@ -79,9 +91,9 @@ int main()
superStr[0]=0;
APP_STATUS status;
while((status=aptGetStatus()) != APP_EXITING)
while ((status=aptGetStatus()) != APP_EXITING)
{
if(status == APP_RUNNING)
if (status == APP_RUNNING)
{
drawFrame();
@ -94,7 +106,7 @@ int main()
);
}
}
else if(status == APP_SUSPENDING)
else if (status == APP_SUSPENDING)
{
aptReturnToMenu();
}
@ -106,7 +118,6 @@ int main()
}
gfxExit();
irrstExit();
hidExit();
aptExit();
srvExit();