Added ability to print to top or bottom screen.

This commit is contained in:
archshift 2014-10-31 22:20:21 -07:00
parent 238957c65a
commit e1848bcfc9
6 changed files with 73 additions and 50 deletions

View File

@ -1,5 +1,4 @@
#ifndef FONT_H
#define FONT_H
#pragma once
typedef struct {
char c;
@ -19,5 +18,3 @@ extern u8 font1Data[];
extern charDesc_s font1Desc[];
extern font_s fontDefault;
#endif

View File

@ -18,19 +18,19 @@ int main()
gfxInit();
gfxSet3D(false);
clearScreen();
print("Press A to begin...\n");
clearScreens();
print(GFX_TOP, "Press A to begin...\n");
APP_STATUS status;
while ((status = aptGetStatus()) != APP_EXITING) {
if (status == APP_RUNNING) {
drawFrame();
drawFrames();
hidScanInput();
if (hidKeysDown() & KEY_B) {
break;
} else if (hidKeysDown() & KEY_A) {
clearScreen();
clearScreen(GFX_TOP);
if (testCounter < (sizeof(tests) / sizeof(tests[0]))) {
tests[testCounter]();
@ -39,8 +39,8 @@ int main()
break;
}
print("\n");
print("Press A to continue...\n");
print(GFX_TOP, "\n");
print(GFX_TOP, "Press A to continue...\n");
}
} else if (status == APP_SUSPENDING) {
@ -53,7 +53,7 @@ int main()
gspWaitForEvent(GSPEVENT_VBlank0, false);
}
clearScreen();
clearScreens();
gfxExit();
hidExit();
aptExit();

View File

@ -8,7 +8,8 @@
#include "text.h"
static char superStr[8192];
static char bufferTop[8192];
static char bufferBottom[8192];
static int cnt;
static int countLines(const char* str)
@ -35,48 +36,70 @@ static void cutLine(char* str)
memmove(str, str2, strlen(str2) + 1);
}
void drawFrame()
static void drawFrame(gfxScreen_t screen, char b, char g, char r)
{
u8* bufAdr = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
int screenWidth;
char* textBuffer;
if (screen == GFX_TOP) {
screenWidth = 400;
textBuffer = bufferTop;
} else {
screenWidth = 320;
textBuffer = bufferBottom;
}
u8* bufAdr = gfxGetFramebuffer(screen, GFX_LEFT, NULL, NULL);
int x, y;
for (x = 1; x < 400; x++) {
for (x = 1; x < screenWidth; x++) {
for (y = 1; y < 240; y++) {
u32 v=(y + x * 240) * 3;
bufAdr[v] = 0x88;
bufAdr[v+1] = 0x66;
bufAdr[v+2] = 0x00;
bufAdr[v] = b;
bufAdr[v+1] = g;
bufAdr[v+2] = r;
}
}
x = countLines(superStr);
x = countLines(textBuffer);
while (x > (240 / fontDefault.height - 3)) {
cutLine(superStr);
cutLine(textBuffer);
x--;
}
gfxDrawText(GFX_TOP, GFX_LEFT, NULL, superStr, 240 - fontDefault.height * 3, 10);
gfxDrawText(screen, GFX_LEFT, NULL, textBuffer, 240 - fontDefault.height * 3, 10);
cnt++;
}
void drawFrames()
{
drawFrame(GFX_TOP, 0x88, 0x66, 0x00);
drawFrame(GFX_BOTTOM, 0x00, 0x00, 0x00);
gfxFlushBuffers();
gfxSwapBuffers();
}
void print(const char* format, ...)
void print(gfxScreen_t screen, const char* format, ...)
{
char* textBuffer = (screen == GFX_TOP) ? bufferTop : bufferBottom;
va_list arguments;
char new_str[512];
char newStr[512];
va_start(arguments, format);
vsprintf(new_str, format, arguments);
vsprintf(newStr, format, arguments);
va_end(arguments);
sprintf(&superStr[strlen(superStr)], new_str);
svcOutputDebugString(new_str, strlen(new_str));
sprintf(&textBuffer[strlen(textBuffer)], newStr);
svcOutputDebugString(newStr, strlen(newStr));
drawFrame();
drawFrames();
}
void clearScreen()
void clearScreen(gfxScreen_t screen)
{
superStr[0] = 0;
drawFrame();
bufferTop[0] = 0;
drawFrames();
}
void clearScreens()
{
clearScreen(GFX_TOP);
clearScreen(GFX_BOTTOM);
}

View File

@ -1,8 +1,8 @@
#ifndef OUTPUT_H
#define OUTPUT_H
#pragma once
void drawFrame();
void print(const char* format, ...);
void clearScreen();
#include <3ds/gfx.h>
#endif
void drawFrames();
void print(gfxScreen_t screen, const char* format, ...);
void clearScreen(gfxScreen_t screen);
void clearScreens();

View File

@ -19,7 +19,7 @@ void FS_TestAll()
void FS_TestInit()
{
unsigned int initResult = fsInit();
print("fsInit - [%u]\n", initResult);
print(GFX_TOP, "fsInit - [%u]\n", initResult);
}
void FS_TestSdmcOpen()
@ -27,32 +27,38 @@ void FS_TestSdmcOpen()
sdmcArchive = (FS_archive) { 0x00000009, { PATH_EMPTY, 1, (u8*) "" } };
unsigned int openResult = FSUSER_OpenArchive(NULL, &sdmcArchive);
print("FSUSER_OpenArchive - [%u]\n", openResult);
print(GFX_TOP, "FSUSER_OpenArchive - [%u]\n", openResult);
}
void FS_TestSdmcOpenFile()
{
Handle fileHandle;
Handle fileHandleC, fileHandleW, fileHandleR;
FS_path filePath = FS_makePath(PATH_CHAR, "/new_file.txt");
unsigned int openResult = FSUSER_OpenFile(NULL, &fileHandle, sdmcArchive, filePath, 2, 0);
print("FSUSER_OpenFile - [%u]\n", openResult);
svcCloseHandle(fileHandle);
unsigned int openResultC = FSUSER_OpenFile(NULL, &fileHandleC, sdmcArchive, filePath, 2, 0);
print(GFX_TOP, "FSUSER_OpenFile (create flag) - '%s' - [%u]\n", filePath.data, openResultC);
svcCloseHandle(fileHandleC);
unsigned int openResultW = FSUSER_OpenFile(NULL, &fileHandleW, sdmcArchive, filePath, 1, 0);
print(GFX_TOP, "FSUSER_OpenFile (write flag) - '%s' - [%u]\n", filePath.data, openResultW);
svcCloseHandle(fileHandleW);
}
void FS_TestSdmcCreateDir()
{
unsigned int createResult = FSUSER_CreateDirectory(NULL, sdmcArchive, FS_makePath(PATH_CHAR, "/new_dir"));
print("FSUSER_CreateDirectory - [%u]\n", createResult);
FS_path dirPath = FS_makePath(PATH_CHAR, "/new_dir");
unsigned int createResult = FSUSER_CreateDirectory(NULL, sdmcArchive, dirPath);
print(GFX_TOP, "FSUSER_CreateDirectory - '%s' - [%u]\n", dirPath.data, createResult);
}
void FS_TestSdmcClose()
{
unsigned int closeResult = FSUSER_CloseArchive(NULL, &sdmcArchive);
print("FSUSER_CloseArchive - [%u]\n", closeResult);
print(GFX_TOP, "FSUSER_CloseArchive - [%u]\n", closeResult);
}
void FS_TestExit()
{
unsigned int exitResult = fsExit();
print("fsExit - [%u]", exitResult);
print(GFX_TOP, "fsExit - [%u]", exitResult);
}

View File

@ -1,5 +1,4 @@
#ifndef TEST_FS_H
#define TEST_FS_H
#pragma once
void FS_TestAll();
@ -20,5 +19,3 @@ void FS_TestSdmcOpenDir();
void FS_TestSdmcClose();
void FS_TestExit();
#endif