Replaced all tab occurrences with spaces.

This commit is contained in:
archshift 2014-11-22 00:58:29 -08:00
parent e193e1992f
commit 8cc32a952f
8 changed files with 464 additions and 464 deletions

View File

@ -2,8 +2,8 @@
#include "font.h" #include "font.h"
font_s fontDefault = { font_s fontDefault = {
font1Data, font1Data,
font1Desc, font1Desc,
16, 16,
{ 0xFF, 0xFF, 0xFF } { 0xFF, 0xFF, 0xFF }
}; };

View File

@ -1,16 +1,16 @@
#pragma once #pragma once
struct charDesc_s { struct charDesc_s {
char c; char c;
int x, y, w, h, xo, yo, xa; int x, y, w, h, xo, yo, xa;
u8* data; u8* data;
}; };
struct font_s { struct font_s {
u8* data; u8* data;
charDesc_s* desc; charDesc_s* desc;
u8 height; u8 height;
u8 color[3]; u8 color[3];
}; };
extern u8 font1Data[]; extern u8 font1Data[];

File diff suppressed because one or more lines are too long

View File

@ -7,47 +7,47 @@
static unsigned int testCounter = 0; static unsigned int testCounter = 0;
static void (*tests[]) (void) = { static void (*tests[]) (void) = {
FS::TestAll FS::TestAll
}; };
int main() int main()
{ {
srvInit(); srvInit();
aptInit(); aptInit();
hidInit(NULL); hidInit(NULL);
gfxInit(); gfxInit();
gfxSet3D(false); gfxSet3D(false);
clearScreens(); clearScreens();
print(GFX_TOP, "Press A to begin...\n"); print(GFX_TOP, "Press A to begin...\n");
while (aptMainLoop()) { while (aptMainLoop()) {
drawFrames(); drawFrames();
hidScanInput(); hidScanInput();
if (hidKeysDown() & KEY_START) { if (hidKeysDown() & KEY_START) {
break; break;
} else if (hidKeysDown() & KEY_A) { } else if (hidKeysDown() & KEY_A) {
clearScreen(GFX_TOP); clearScreen(GFX_TOP);
if (testCounter < (sizeof(tests) / sizeof(tests[0]))) { if (testCounter < (sizeof(tests) / sizeof(tests[0]))) {
tests[testCounter](); tests[testCounter]();
testCounter++; testCounter++;
} else { } else {
break; break;
} }
print(GFX_TOP, "\n"); print(GFX_TOP, "\n");
print(GFX_TOP, "Press A to continue...\n"); print(GFX_TOP, "Press A to continue...\n");
} }
gspWaitForEvent(GSPEVENT_VBlank0, false); gspWaitForEvent(GSPEVENT_VBlank0, false);
} }
clearScreens(); clearScreens();
gfxExit(); gfxExit();
hidExit(); hidExit();
aptExit(); aptExit();
srvExit(); srvExit();
return 0; return 0;
} }

View File

@ -15,21 +15,21 @@ static std::string bufferBottom;
static int countLines(const std::string& str) static int countLines(const std::string& str)
{ {
if (str.empty()) if (str.empty())
return 0; return 0;
int cnt = 1; int cnt = 1;
for (const char& c : str) { for (const char& c : str) {
if (c == '\n') cnt++; if (c == '\n') cnt++;
} }
return cnt; return cnt;
} }
static void deleteFirstLine(std::string* str) static void deleteFirstLine(std::string* str)
{ {
if (str->empty()) if (str->empty())
return; return;
size_t linebreak = str->find_first_of('\n'); size_t linebreak = str->find_first_of('\n');
@ -43,65 +43,65 @@ static void deleteFirstLine(std::string* str)
static void drawFrame(gfxScreen_t screen, u8 b, u8 g, u8 r) static void drawFrame(gfxScreen_t screen, u8 b, u8 g, u8 r)
{ {
int screenWidth; int screenWidth;
std::string textBuffer; std::string textBuffer;
if (screen == GFX_TOP) { if (screen == GFX_TOP) {
screenWidth = 400; screenWidth = 400;
textBuffer = bufferTop; textBuffer = bufferTop;
} else { } else {
screenWidth = 320; screenWidth = 320;
textBuffer = bufferBottom; textBuffer = bufferBottom;
} }
// Fill screen with color (TODO: find more efficient way to do this) // Fill screen with color (TODO: find more efficient way to do this)
u8* bufAdr = gfxGetFramebuffer(screen, GFX_LEFT, NULL, NULL); u8* bufAdr = gfxGetFramebuffer(screen, GFX_LEFT, NULL, NULL);
for (int i = 0; i < screenWidth * 240 * 3; i += 3) { for (int i = 0; i < screenWidth * 240 * 3; i += 3) {
bufAdr[i] = b; bufAdr[i] = b;
bufAdr[i+1] = g; bufAdr[i+1] = g;
bufAdr[i+2] = r; bufAdr[i+2] = r;
} }
int lines = countLines(textBuffer); int lines = countLines(textBuffer);
while (lines > (240 / fontDefault.height - 3)) { while (lines > (240 / fontDefault.height - 3)) {
deleteFirstLine(&textBuffer); deleteFirstLine(&textBuffer);
lines--; lines--;
} }
gfxDrawText(screen, GFX_LEFT, NULL, textBuffer.c_str(), 240 - fontDefault.height * 3, 10); gfxDrawText(screen, GFX_LEFT, NULL, textBuffer.c_str(), 240 - fontDefault.height * 3, 10);
} }
void drawFrames() void drawFrames()
{ {
drawFrame(GFX_TOP, 0x88, 0x66, 0x00); drawFrame(GFX_TOP, 0x88, 0x66, 0x00);
drawFrame(GFX_BOTTOM, 0x00, 0x00, 0x00); drawFrame(GFX_BOTTOM, 0x00, 0x00, 0x00);
gfxFlushBuffers(); gfxFlushBuffers();
gfxSwapBuffers(); gfxSwapBuffers();
} }
void print(gfxScreen_t screen, const char* format, ...) void print(gfxScreen_t screen, const char* format, ...)
{ {
std::string& textBuffer = (screen == GFX_TOP) ? bufferTop : bufferBottom; std::string& textBuffer = (screen == GFX_TOP) ? bufferTop : bufferBottom;
va_list arguments; va_list arguments;
char newStr[512]; char newStr[512];
va_start(arguments, format); va_start(arguments, format);
vsprintf(newStr, format, arguments); vsprintf(newStr, format, arguments);
va_end(arguments); va_end(arguments);
textBuffer += newStr; textBuffer += newStr;
svcOutputDebugString(newStr, strlen(newStr)); svcOutputDebugString(newStr, strlen(newStr));
drawFrames(); drawFrames();
} }
void clearScreen(gfxScreen_t screen) void clearScreen(gfxScreen_t screen)
{ {
std::string& textBuffer = (screen == GFX_TOP) ? bufferTop : bufferBottom; std::string& textBuffer = (screen == GFX_TOP) ? bufferTop : bufferBottom;
textBuffer.clear(); textBuffer.clear();
drawFrames(); drawFrames();
} }
void clearScreens() void clearScreens()
{ {
clearScreen(GFX_TOP); clearScreen(GFX_TOP);
clearScreen(GFX_BOTTOM); clearScreen(GFX_BOTTOM);
} }

View File

@ -6,10 +6,10 @@
void Test(std::string group, std::string name, std::function<bool (void)> test) void Test(std::string group, std::string name, std::function<bool (void)> test)
{ {
print(GFX_TOP, "%s: %s - %s\n", group.c_str(), name.c_str(), test() ? "SUCCESS" : "FAILURE"); print(GFX_TOP, "%s: %s - %s\n", group.c_str(), name.c_str(), test() ? "SUCCESS" : "FAILURE");
} }
void TestResult(std::string group, std::string name, std::function<int (void)> test) void TestResult(std::string group, std::string name, std::function<int (void)> test)
{ {
print(GFX_TOP, "%s: %s - %s\n", group.c_str(), name.c_str(), test() == 0 ? "SUCCESS" : "FAILURE"); print(GFX_TOP, "%s: %s - %s\n", group.c_str(), name.c_str(), test() == 0 ? "SUCCESS" : "FAILURE");
} }

View File

@ -8,91 +8,91 @@ namespace FS {
static void TestSDMC() static void TestSDMC()
{ {
FS_archive sdmcArchive = (FS_archive) { 0x00000009, { PATH_EMPTY, 1, (u8*) "" } }; FS_archive sdmcArchive = (FS_archive) { 0x00000009, { PATH_EMPTY, 1, (u8*) "" } };
FS_path dirPath = FS_makePath(PATH_CHAR, "/new_dir"); FS_path dirPath = FS_makePath(PATH_CHAR, "/new_dir");
Handle dirHandle; Handle dirHandle;
FS_path filePath = FS_makePath(PATH_CHAR, "/new_dir/new_file.txt"); FS_path filePath = FS_makePath(PATH_CHAR, "/new_dir/new_file.txt");
Handle fileHandle; Handle fileHandle;
u64 fileSize; u64 fileSize;
u32 bytesWritten; u32 bytesWritten;
// Open SDMC // Open SDMC
TestResult("SDMC", "Opening archive", [&]{ TestResult("SDMC", "Opening archive", [&]{
return FSUSER_OpenArchive(NULL, &sdmcArchive); return FSUSER_OpenArchive(NULL, &sdmcArchive);
}); });
// Create Directory // Create Directory
TestResult("SDMC", "Creating directory", [&]{ TestResult("SDMC", "Creating directory", [&]{
return FSUSER_CreateDirectory(NULL, sdmcArchive, dirPath); return FSUSER_CreateDirectory(NULL, sdmcArchive, dirPath);
}); });
// Open Directory // Open Directory
TestResult("SDMC", "Opening directory handle", [&]{ TestResult("SDMC", "Opening directory handle", [&]{
return FSUSER_OpenDirectory(NULL, &dirHandle, sdmcArchive, dirPath); return FSUSER_OpenDirectory(NULL, &dirHandle, sdmcArchive, dirPath);
}); });
// Open File // Open File
TestResult("SDMC", "Opening file handle", [&]{ 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 // Write File
TestResult("SDMC", "Writing data to file", [&]{ TestResult("SDMC", "Writing data to file", [&]{
const char* stringWritten = "A string\n"; const char* stringWritten = "A string\n";
return FSFILE_Write(fileHandle, &bytesWritten, 0, stringWritten, strlen(stringWritten), FS_WRITE_FLUSH); return FSFILE_Write(fileHandle, &bytesWritten, 0, stringWritten, strlen(stringWritten), FS_WRITE_FLUSH);
}); });
// Check File Size // Check File Size
TestResult("SDMC", "Getting size of file", [&]{ TestResult("SDMC", "Getting size of file", [&]{
return FSFILE_GetSize(fileHandle, &fileSize); return FSFILE_GetSize(fileHandle, &fileSize);
}); });
// Verify File Size // Verify File Size
Test("SDMC", "Verifying size with written bytes", [&]{ Test("SDMC", "Verifying size with written bytes", [&]{
return fileSize == bytesWritten; return fileSize == bytesWritten;
}); });
// Close File // Close File
TestResult("SDMC", "Closing file handle", [&]{ TestResult("SDMC", "Closing file handle", [&]{
return FSFILE_Close(fileHandle); return FSFILE_Close(fileHandle);
}); });
// Close Directory // Close Directory
TestResult("SDMC", "Closing directory handle", [&]{ TestResult("SDMC", "Closing directory handle", [&]{
return FSDIR_Close(dirHandle); return FSDIR_Close(dirHandle);
}); });
// Delete File // Delete File
TestResult("SDMC", "Deleting file", [&]{ TestResult("SDMC", "Deleting file", [&]{
return FSUSER_DeleteFile(NULL, sdmcArchive, filePath); return FSUSER_DeleteFile(NULL, sdmcArchive, filePath);
}); });
// Delete Directory // Delete Directory
TestResult("SDMC", "Deleting directory", [&]{ TestResult("SDMC", "Deleting directory", [&]{
return FSUSER_DeleteDirectory(NULL, sdmcArchive, dirPath); return FSUSER_DeleteDirectory(NULL, sdmcArchive, dirPath);
}); });
// Close SDMC // Close SDMC
TestResult("SDMC", "Closing archive", [&]{ TestResult("SDMC", "Closing archive", [&]{
return FSUSER_CloseArchive(NULL, &sdmcArchive); return FSUSER_CloseArchive(NULL, &sdmcArchive);
}); });
} }
void TestAll() void TestAll()
{ {
TestResult("FS", "Initializing service", [&]{ TestResult("FS", "Initializing service", [&]{
return fsInit(); return fsInit();
}); });
TestSDMC(); TestSDMC();
TestResult("FS", "Exiting service", [&]{ TestResult("FS", "Exiting service", [&]{
return fsExit(); return fsExit();
}); });
} }
} // namespace } // namespace

View File

@ -9,76 +9,76 @@
//this code is not meant to be readable //this code is not meant to be readable
int drawCharacter(u8* fb, font_s* font, char c, s16 x, s16 y, u16 w, u16 h) int drawCharacter(u8* fb, font_s* font, char c, s16 x, s16 y, u16 w, u16 h)
{ {
charDesc_s* cd = &font->desc[(int)c]; charDesc_s* cd = &font->desc[(int)c];
if (!cd->data) if (!cd->data)
return 0; return 0;
x += cd->xo; y += font->height - cd->yo - cd->h; x += cd->xo; y += font->height - cd->yo - cd->h;
if (x < 0 || x + cd->w >= w || y < -cd->h || y >= h + cd->h) if (x < 0 || x + cd->w >= w || y < -cd->h || y >= h + cd->h)
return 0; return 0;
u8* charData = cd->data; u8* charData = cd->data;
s16 cy = y, ch = cd->h, cyo = 0; s16 cy = y, ch = cd->h, cyo = 0;
if (y < 0) { if (y < 0) {
cy = 0; cy = 0;
cyo = -y; cyo = -y;
ch = cd->h-cyo; ch = cd->h-cyo;
} else if (y + ch > h) { } else if (y + ch > h) {
ch = h - y; ch = h - y;
} }
fb += (x * h + cy) * 3; fb += (x * h + cy) * 3;
const u8 r = font->color[0]; const u8 r = font->color[0];
const u8 g = font->color[1]; const u8 g = font->color[1];
const u8 b = font->color[2]; const u8 b = font->color[2];
int i, j; int i, j;
for (i = 0; i < cd->w; i++) { for (i = 0; i < cd->w; i++) {
charData += cyo; charData += cyo;
for(j = 0; j < ch; j++) { for(j = 0; j < ch; j++) {
u8 v = *(charData++); u8 v = *(charData++);
if (v) { if (v) {
fb[0] = (fb[0] * (0xFF - v) + (b * v)) >> 8; fb[0] = (fb[0] * (0xFF - v) + (b * v)) >> 8;
fb[1] = (fb[1] * (0xFF - v) + (g * v)) >> 8; fb[1] = (fb[1] * (0xFF - v) + (g * v)) >> 8;
fb[2] = (fb[2] * (0xFF - v) + (r * v)) >> 8; fb[2] = (fb[2] * (0xFF - v) + (r * v)) >> 8;
} }
fb += 3; fb += 3;
} }
charData += (cd->h - (cyo + ch)); charData += (cd->h - (cyo + ch));
fb += (h - ch) * 3; fb += (h - ch) * 3;
} }
return cd->xa; return cd->xa;
} }
void drawString(u8* fb, font_s* f, const char* str, 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) if (!f || !fb || !str)
return; return;
int k, dx = 0, dy = 0; int k, dx = 0, dy = 0;
int length = strlen(str); int length = strlen(str);
for (k = 0; k < length; k++) for (k = 0; k < length; k++)
{ {
dx += drawCharacter(fb, f, str[k], x + dx, y + dy, w, h); dx += drawCharacter(fb, f, str[k], x + dx, y + dy, w, h);
if(str[k]=='\n') { if(str[k]=='\n') {
dx = 0; dx = 0;
dy -= f->height; dy -= f->height;
} }
} }
} }
void gfxDrawText(gfxScreen_t screen, gfx3dSide_t side, font_s* font, const char* str, s16 x, s16 y) void gfxDrawText(gfxScreen_t screen, gfx3dSide_t side, font_s* font, const char* str, s16 x, s16 y)
{ {
if(!str) if(!str)
return; return;
if(!font) if(!font)
font = &fontDefault; font = &fontDefault;
u16 fbWidth, fbHeight; u16 fbWidth, fbHeight;
u8* fbAdr = gfxGetFramebuffer(screen, side, &fbWidth, &fbHeight); u8* fbAdr = gfxGetFramebuffer(screen, side, &fbWidth, &fbHeight);
drawString(fbAdr, font, str, y, x, fbHeight, fbWidth); drawString(fbAdr, font, str, y, x, fbHeight, fbWidth);
} }