Reverted buffer change to string.

This commit is contained in:
archshift 2014-11-22 12:21:12 -08:00
parent 8cc32a952f
commit 5ec2f38c9a
4 changed files with 84 additions and 80 deletions

View File

@ -22,26 +22,26 @@ int main()
print(GFX_TOP, "Press A to begin...\n");
while (aptMainLoop()) {
drawFrames();
drawFrames();
hidScanInput();
if (hidKeysDown() & KEY_START) {
break;
} else if (hidKeysDown() & KEY_A) {
clearScreen(GFX_TOP);
hidScanInput();
if (hidKeysDown() & KEY_START) {
break;
} else if (hidKeysDown() & KEY_A) {
clearScreen(GFX_TOP);
if (testCounter < (sizeof(tests) / sizeof(tests[0]))) {
tests[testCounter]();
testCounter++;
} else {
break;
}
if (testCounter < (sizeof(tests) / sizeof(tests[0]))) {
tests[testCounter]();
testCounter++;
} else {
break;
}
print(GFX_TOP, "\n");
print(GFX_TOP, "Press A to continue...\n");
}
print(GFX_TOP, "\n");
print(GFX_TOP, "Press A to continue...\n");
}
gspWaitForEvent(GSPEVENT_VBlank0, false);
gspWaitForEvent(GSPEVENT_VBlank0, false);
}
clearScreens();

View File

@ -10,13 +10,14 @@
#include "text.h"
static std::string bufferTop;
static std::string bufferBottom;
static char bufferTop[8192];
static char bufferBottom[8192];
static int cnt;
static int countLines(const std::string& str)
{
if (str.empty())
return 0;
return 0;
int cnt = 1;
for (const char& c : str) {
@ -29,7 +30,7 @@ static int countLines(const std::string& str)
static void deleteFirstLine(std::string* str)
{
if (str->empty())
return;
return;
size_t linebreak = str->find_first_of('\n');
@ -41,32 +42,36 @@ static void deleteFirstLine(std::string* str)
*str = str->substr(linebreak + 1);
}
static void drawFrame(gfxScreen_t screen, u8 b, u8 g, u8 r)
static void drawFrame(gfxScreen_t screen, char b, char g, char r)
{
int screenWidth;
std::string textBuffer;
if (screen == GFX_TOP) {
screenWidth = 400;
textBuffer = bufferTop;
screenWidth = 400;
textBuffer = bufferTop;
} else {
screenWidth = 320;
textBuffer = bufferBottom;
screenWidth = 320;
textBuffer = bufferBottom;
}
// Fill screen with color (TODO: find more efficient way to do this)
u8* bufAdr = gfxGetFramebuffer(screen, GFX_LEFT, NULL, NULL);
for (int i = 0; i < screenWidth * 240 * 3; i += 3) {
bufAdr[i] = b;
bufAdr[i+1] = g;
bufAdr[i+2] = r;
int x, y;
for (x = 1; x < screenWidth; x++) {
for (y = 1; y < 240; y++) {
u32 v=(y + x * 240) * 3;
bufAdr[v] = b;
bufAdr[v+1] = g;
bufAdr[v+2] = r;
}
}
int lines = countLines(textBuffer);
while (lines > (240 / fontDefault.height - 3)) {
deleteFirstLine(&textBuffer);
lines--;
x = countLines(textBuffer);
while (x > (240 / fontDefault.height - 3)) {
deleteFirstLine(&textBuffer);
x--;
}
gfxDrawText(screen, GFX_LEFT, NULL, textBuffer.c_str(), 240 - fontDefault.height * 3, 10);
cnt++;
}
void drawFrames()
@ -79,7 +84,7 @@ void drawFrames()
void print(gfxScreen_t screen, const char* format, ...)
{
std::string& textBuffer = (screen == GFX_TOP) ? bufferTop : bufferBottom;
char* textBuffer = (screen == GFX_TOP) ? bufferTop : bufferBottom;
va_list arguments;
char newStr[512];
@ -87,7 +92,7 @@ void print(gfxScreen_t screen, const char* format, ...)
vsprintf(newStr, format, arguments);
va_end(arguments);
textBuffer += newStr;
sprintf(&textBuffer[strlen(textBuffer)], newStr);
svcOutputDebugString(newStr, strlen(newStr));
drawFrames();
@ -95,8 +100,7 @@ void print(gfxScreen_t screen, const char* format, ...)
void clearScreen(gfxScreen_t screen)
{
std::string& textBuffer = (screen == GFX_TOP) ? bufferTop : bufferBottom;
textBuffer.clear();
bufferTop[0] = 0;
drawFrames();
}

View File

@ -21,63 +21,63 @@ static void TestSDMC()
// Open SDMC
TestResult("SDMC", "Opening archive", [&]{
return FSUSER_OpenArchive(NULL, &sdmcArchive);
return FSUSER_OpenArchive(NULL, &sdmcArchive);
});
// Create Directory
TestResult("SDMC", "Creating directory", [&]{
return FSUSER_CreateDirectory(NULL, sdmcArchive, dirPath);
return FSUSER_CreateDirectory(NULL, sdmcArchive, dirPath);
});
// Open Directory
TestResult("SDMC", "Opening directory handle", [&]{
return FSUSER_OpenDirectory(NULL, &dirHandle, sdmcArchive, dirPath);
return FSUSER_OpenDirectory(NULL, &dirHandle, sdmcArchive, dirPath);
});
// Open File
TestResult("SDMC", "Opening file handle", [&]{
return FSUSER_OpenFile(NULL, &fileHandle, sdmcArchive, filePath, FS_OPEN_WRITE | FS_OPEN_CREATE, 0);
return FSUSER_OpenFile(NULL, &fileHandle, sdmcArchive, filePath, FS_OPEN_WRITE | FS_OPEN_CREATE, 0);
});
// Write File
TestResult("SDMC", "Writing data to file", [&]{
const char* stringWritten = "A string\n";
return FSFILE_Write(fileHandle, &bytesWritten, 0, stringWritten, strlen(stringWritten), FS_WRITE_FLUSH);
const char* stringWritten = "A string\n";
return FSFILE_Write(fileHandle, &bytesWritten, 0, stringWritten, strlen(stringWritten), FS_WRITE_FLUSH);
});
// Check File Size
TestResult("SDMC", "Getting size of file", [&]{
return FSFILE_GetSize(fileHandle, &fileSize);
return FSFILE_GetSize(fileHandle, &fileSize);
});
// Verify File Size
Test("SDMC", "Verifying size with written bytes", [&]{
return fileSize == bytesWritten;
return fileSize == bytesWritten;
});
// Close File
TestResult("SDMC", "Closing file handle", [&]{
return FSFILE_Close(fileHandle);
return FSFILE_Close(fileHandle);
});
// Close Directory
TestResult("SDMC", "Closing directory handle", [&]{
return FSDIR_Close(dirHandle);
return FSDIR_Close(dirHandle);
});
// Delete File
TestResult("SDMC", "Deleting file", [&]{
return FSUSER_DeleteFile(NULL, sdmcArchive, filePath);
});
return FSUSER_DeleteFile(NULL, sdmcArchive, filePath);
});
// Delete Directory
TestResult("SDMC", "Deleting directory", [&]{
return FSUSER_DeleteDirectory(NULL, sdmcArchive, dirPath);
return FSUSER_DeleteDirectory(NULL, sdmcArchive, dirPath);
});
// Close SDMC
TestResult("SDMC", "Closing archive", [&]{
return FSUSER_CloseArchive(NULL, &sdmcArchive);
return FSUSER_CloseArchive(NULL, &sdmcArchive);
});
}
@ -85,13 +85,13 @@ static void TestSDMC()
void TestAll()
{
TestResult("FS", "Initializing service", [&]{
return fsInit();
return fsInit();
});
TestSDMC();
TestResult("FS", "Exiting service", [&]{
return fsExit();
return fsExit();
});
}

View File

@ -12,22 +12,22 @@ int drawCharacter(u8* fb, font_s* font, char c, s16 x, s16 y, u16 w, u16 h)
charDesc_s* cd = &font->desc[(int)c];
if (!cd->data)
return 0;
return 0;
x += cd->xo; y += font->height - cd->yo - cd->h;
if (x < 0 || x + cd->w >= w || y < -cd->h || y >= h + cd->h)
return 0;
return 0;
u8* charData = cd->data;
s16 cy = y, ch = cd->h, cyo = 0;
if (y < 0) {
cy = 0;
cyo = -y;
ch = cd->h-cyo;
cy = 0;
cyo = -y;
ch = cd->h-cyo;
} else if (y + ch > h) {
ch = h - y;
ch = h - y;
}
fb += (x * h + cy) * 3;
@ -37,18 +37,18 @@ int drawCharacter(u8* fb, font_s* font, char c, s16 x, s16 y, u16 w, u16 h)
int i, j;
for (i = 0; i < cd->w; i++) {
charData += cyo;
for(j = 0; j < ch; j++) {
u8 v = *(charData++);
if (v) {
fb[0] = (fb[0] * (0xFF - v) + (b * v)) >> 8;
fb[1] = (fb[1] * (0xFF - v) + (g * v)) >> 8;
fb[2] = (fb[2] * (0xFF - v) + (r * v)) >> 8;
}
fb += 3;
}
charData += (cd->h - (cyo + ch));
fb += (h - ch) * 3;
charData += cyo;
for(j = 0; j < ch; j++) {
u8 v = *(charData++);
if (v) {
fb[0] = (fb[0] * (0xFF - v) + (b * v)) >> 8;
fb[1] = (fb[1] * (0xFF - v) + (g * v)) >> 8;
fb[2] = (fb[2] * (0xFF - v) + (r * v)) >> 8;
}
fb += 3;
}
charData += (cd->h - (cyo + ch));
fb += (h - ch) * 3;
}
return cd->xa;
}
@ -56,26 +56,26 @@ int drawCharacter(u8* fb, font_s* font, char c, s16 x, s16 y, u16 w, u16 h)
void drawString(u8* fb, font_s* f, const char* str, s16 x, s16 y, u16 w, u16 h)
{
if (!f || !fb || !str)
return;
return;
int k, dx = 0, dy = 0;
int length = strlen(str);
for (k = 0; k < length; k++)
{
dx += drawCharacter(fb, f, str[k], x + dx, y + dy, w, h);
if(str[k]=='\n') {
dx = 0;
dy -= f->height;
}
dx += drawCharacter(fb, f, str[k], x + dx, y + dy, w, h);
if(str[k]=='\n') {
dx = 0;
dy -= f->height;
}
}
}
void gfxDrawText(gfxScreen_t screen, gfx3dSide_t side, font_s* font, const char* str, s16 x, s16 y)
{
if(!str)
return;
return;
if(!font)
font = &fontDefault;
font = &fontDefault;
u16 fbWidth, fbHeight;
u8* fbAdr = gfxGetFramebuffer(screen, side, &fbWidth, &fbHeight);