2014-12-14 02:37:52 -08:00
|
|
|
#include <3ds.h>
|
|
|
|
|
2014-10-29 23:07:11 -07:00
|
|
|
#include "output.h"
|
|
|
|
|
2014-11-21 22:24:04 -08:00
|
|
|
#include <cmath>
|
2014-12-14 02:37:52 -08:00
|
|
|
#include <fstream>
|
2014-11-21 22:24:04 -08:00
|
|
|
|
2014-12-14 02:37:52 -08:00
|
|
|
#include "draw.h"
|
2014-12-10 22:24:26 -08:00
|
|
|
#include "common/string_funcs.h"
|
2014-10-29 23:07:11 -07:00
|
|
|
|
2014-12-14 02:37:52 -08:00
|
|
|
static FILE* log_file;
|
|
|
|
|
2014-12-10 22:24:26 -08:00
|
|
|
static std::string buffer_top;
|
|
|
|
static std::string buffer_bottom;
|
2014-10-29 23:07:11 -07:00
|
|
|
|
2014-12-10 22:24:26 -08:00
|
|
|
static std::string& GetTextBuffer(gfxScreen_t screen)
|
2014-10-29 23:07:11 -07:00
|
|
|
{
|
2014-12-10 22:24:26 -08:00
|
|
|
switch (screen) {
|
|
|
|
case GFX_TOP: return buffer_top;
|
|
|
|
case GFX_BOTTOM: return buffer_bottom;
|
2014-11-21 22:24:04 -08:00
|
|
|
}
|
2014-12-10 22:24:26 -08:00
|
|
|
return buffer_top;
|
2014-10-29 23:07:11 -07:00
|
|
|
}
|
|
|
|
|
2014-12-14 02:37:52 -08:00
|
|
|
static void DrawBuffer(gfxScreen_t screen)
|
2014-10-29 23:07:11 -07:00
|
|
|
{
|
2014-12-14 02:37:52 -08:00
|
|
|
Rect screen_size = GetScreenSize(screen);
|
2014-12-10 22:24:26 -08:00
|
|
|
std::string& text_buffer = GetTextBuffer(screen);
|
|
|
|
|
|
|
|
int lines = Common::CountLines(text_buffer);
|
2014-12-14 02:37:52 -08:00
|
|
|
while (lines > (screen_size.h / fontDefault.height - 3)) {
|
2014-12-10 22:24:26 -08:00
|
|
|
Common::DeleteFirstLine(&text_buffer);
|
2014-11-22 12:38:59 -08:00
|
|
|
lines--;
|
2014-11-22 00:58:29 -08:00
|
|
|
}
|
2014-12-14 02:37:52 -08:00
|
|
|
DrawText(screen, GFX_LEFT, nullptr, text_buffer, screen_size.h - fontDefault.height * 3, 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InitOutput()
|
|
|
|
{
|
|
|
|
sdmcInit();
|
|
|
|
log_file = fopen("hwtest_log.txt", "w");
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrawBuffers()
|
|
|
|
{
|
|
|
|
FillScreen(GFX_TOP, 0x00, 0x66, 0x88);
|
|
|
|
DrawBuffer(GFX_TOP);
|
|
|
|
|
|
|
|
FillScreen(GFX_BOTTOM, 0x00, 0x00, 0x00);
|
|
|
|
DrawBuffer(GFX_BOTTOM);
|
|
|
|
|
|
|
|
gfxFlushBuffers();
|
|
|
|
gfxSwapBuffers();
|
2014-10-31 22:20:21 -07:00
|
|
|
}
|
2014-10-29 23:07:11 -07:00
|
|
|
|
2014-12-14 02:37:52 -08:00
|
|
|
void ClearScreen(gfxScreen_t screen, u8 bg_r, u8 bg_g, u8 bg_b)
|
2014-10-31 22:20:21 -07:00
|
|
|
{
|
2014-12-14 02:37:52 -08:00
|
|
|
FillScreen(screen, bg_r, bg_g, bg_b);
|
|
|
|
GetTextBuffer(screen).clear();
|
2014-11-22 00:58:29 -08:00
|
|
|
gfxFlushBuffers();
|
|
|
|
gfxSwapBuffers();
|
2014-10-29 23:07:11 -07:00
|
|
|
}
|
2014-10-30 00:25:12 -07:00
|
|
|
|
2014-12-14 02:37:52 -08:00
|
|
|
void ClearScreens()
|
|
|
|
{
|
|
|
|
ClearScreen(GFX_TOP, 0x00, 0x66, 0x88);
|
|
|
|
ClearScreen(GFX_BOTTOM, 0x00, 0x00, 0x00);
|
|
|
|
}
|
|
|
|
|
2014-12-10 22:24:26 -08:00
|
|
|
void Print(gfxScreen_t screen, const std::string& text)
|
2014-10-30 00:25:12 -07:00
|
|
|
{
|
2014-12-10 22:24:26 -08:00
|
|
|
GetTextBuffer(screen) += text;
|
2014-12-14 02:37:52 -08:00
|
|
|
DrawBuffers();
|
|
|
|
}
|
2014-10-30 00:25:12 -07:00
|
|
|
|
2014-12-14 02:37:52 -08:00
|
|
|
void Log(gfxScreen_t screen, const std::string& text)
|
|
|
|
{
|
|
|
|
Print(screen, text);
|
|
|
|
LogToFile(text);
|
2014-10-31 22:20:21 -07:00
|
|
|
}
|
|
|
|
|
2014-12-14 02:37:52 -08:00
|
|
|
void LogToFile(const std::string& text)
|
2014-10-31 22:20:21 -07:00
|
|
|
{
|
2014-12-14 02:37:52 -08:00
|
|
|
svcOutputDebugString(text.c_str(), text.length());
|
|
|
|
fprintf(log_file, "%s", text.c_str());
|
2014-10-30 00:25:12 -07:00
|
|
|
}
|
2014-10-30 14:55:01 -07:00
|
|
|
|
2014-12-14 02:37:52 -08:00
|
|
|
void DeinitOutput()
|
2014-10-30 14:55:01 -07:00
|
|
|
{
|
2014-12-14 02:37:52 -08:00
|
|
|
fclose(log_file);
|
|
|
|
sdmcExit();
|
2014-10-30 14:55:01 -07:00
|
|
|
}
|