Fix flickering (#44)

This commit is contained in:
Pk11 2020-02-04 01:21:07 -06:00 committed by GitHub
parent 1fd1e534fc
commit e60993ec3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 59 additions and 55 deletions

View File

@ -52,6 +52,8 @@ static int dmMaxCursors = -1;
static u8 gbaFixedValue = 0; static u8 gbaFixedValue = 0;
extern PrintConsole topConsole, bottomConsole;
void dm_drawTopScreen(void) { void dm_drawTopScreen(void) {
/*if (!ramDumped) { /*if (!ramDumped) {
printf ("Dumping RAM..."); printf ("Dumping RAM...");
@ -61,8 +63,11 @@ void dm_drawTopScreen(void) {
consoleClear(); consoleClear();
ramDumped = true; ramDumped = true;
}*/ }*/
consoleClear();
printf ("\x1B[42m"); // Print green color printf ("\x1B[42m"); // Print green color
printf ("________________________________"); printf ("___________________________%s", RetTime().c_str());
printf ("\x1b[0;0H"); printf ("\x1b[0;0H");
printf ("[root]"); printf ("[root]");
printf ("\x1B[47m"); // Print foreground white color printf ("\x1B[47m"); // Print foreground white color
@ -111,6 +116,8 @@ void dm_drawTopScreen(void) {
} }
void dm_drawBottomScreen(void) { void dm_drawBottomScreen(void) {
consoleClear();
printf ("\x1B[47m"); // Print foreground white color printf ("\x1B[47m"); // Print foreground white color
printf ("\x1b[23;0H"); printf ("\x1b[23;0H");
printf (titleName); printf (titleName);
@ -208,9 +215,9 @@ void driveMenu (void) {
if (dmCursorPosition > dmMaxCursors) dmCursorPosition = 0; // Wrap around to top of list if (dmCursorPosition > dmMaxCursors) dmCursorPosition = 0; // Wrap around to top of list
if (!dmTextPrinted) { if (!dmTextPrinted) {
consoleInit(NULL, 1, BgType_Text4bpp, BgSize_T_256x256, 15, 0, false, true); consoleSelect(&bottomConsole);
dm_drawBottomScreen(); dm_drawBottomScreen();
consoleInit(NULL, 0, BgType_Text4bpp, BgSize_T_256x256, 15, 0, true, true); consoleSelect(&topConsole);
dm_drawTopScreen(); dm_drawTopScreen();
dmTextPrinted = true; dmTextPrinted = true;
@ -328,9 +335,9 @@ void driveMenu (void) {
screenshotbmp(snapPath); screenshotbmp(snapPath);
// Seamlessly swap top and bottom screens // Seamlessly swap top and bottom screens
lcdMainOnBottom(); lcdMainOnBottom();
consoleInit(NULL, 1, BgType_Text4bpp, BgSize_T_256x256, 15, 0, true, true); consoleSelect(&bottomConsole);
dm_drawBottomScreen(); dm_drawBottomScreen();
consoleInit(NULL, 1, BgType_Text4bpp, BgSize_T_256x256, 15, 0, false, true); consoleSelect(&topConsole);
dm_drawTopScreen(); dm_drawTopScreen();
printf("\x1B[42m"); // Print green color for time text printf("\x1B[42m"); // Print green color for time text
printf("\x1b[0;27H"); printf("\x1b[0;27H");

View File

@ -11,6 +11,8 @@
#include "read_card.h" #include "read_card.h"
#include "tonccpy.h" #include "tonccpy.h"
extern PrintConsole topConsole, bottomConsole;
void ndsCardSaveDump(const char* filename) { void ndsCardSaveDump(const char* filename) {
std::ofstream output(filename, std::ofstream::binary); std::ofstream output(filename, std::ofstream::binary);
if(output.is_open()) { if(output.is_open()) {
@ -49,7 +51,8 @@ void ndsCardDump(void) {
printf ("\x1b[0;27H"); printf ("\x1b[0;27H");
printf ("\x1B[42m"); // Print green color printf ("\x1B[42m"); // Print green color
printf ("_____"); // Clear time printf ("_____"); // Clear time
consoleInit(NULL, 1, BgType_Text4bpp, BgSize_T_256x256, 15, 0, false, true); consoleSelect(&bottomConsole);
consoleClear();
printf ("\x1B[47m"); // Print foreground white color printf ("\x1B[47m"); // Print foreground white color
printf("Dump NDS card ROM to\n"); printf("Dump NDS card ROM to\n");
printf("\"%s:/gm9i/out\"?\n", (sdMounted ? "sd" : "fat")); printf("\"%s:/gm9i/out\"?\n", (sdMounted ? "sd" : "fat"));
@ -173,7 +176,8 @@ void gbaCartDump(void) {
printf ("\x1b[0;27H"); printf ("\x1b[0;27H");
printf ("\x1B[42m"); // Print green color printf ("\x1B[42m"); // Print green color
printf ("_____"); // Clear time printf ("_____"); // Clear time
consoleInit(NULL, 1, BgType_Text4bpp, BgSize_T_256x256, 15, 0, false, true); consoleSelect(&bottomConsole);
consoleClear();
printf ("\x1B[47m"); // Print foreground white color printf ("\x1B[47m"); // Print foreground white color
printf("Dump GBA cart ROM to\n"); printf("Dump GBA cart ROM to\n");
printf("\"fat:/gm9i/out\"?\n"); printf("\"fat:/gm9i/out\"?\n");

View File

@ -23,20 +23,20 @@ bool clipboardInNitro = false;
void printBytes(int bytes) void printBytes(int bytes)
{ {
if (abs(bytes) == 1) if (bytes == 1)
iprintf("%d Byte", bytes); iprintf("%4d Byte", bytes);
else if (abs(bytes) < 1024) else if (bytes < 1024)
iprintf("%d Bytes", bytes); iprintf("%3d Bytes", bytes);
else if (abs(bytes) < 1024 * 1024) else if (bytes < 1024 * 1024)
printf("%.1f KB", (float)bytes / 1024); printf("%6d KB", bytes / 1024);
else if (abs(bytes) < 1024 * 1024 * 1024) else if (bytes < 1024 * 1024 * 1024)
printf("%.1f MB", (float)bytes / 1024 / 1024); printf("%6d MB", bytes / 1024 / 1024);
else else
printf("%.1f GB", (float)bytes / 1024 / 1024 / 1024); printf("%6d GB", bytes / 1024 / 1024 / 1024);
} }
off_t getFileSize(const char *fileName) off_t getFileSize(const char *fileName)

View File

@ -45,8 +45,7 @@
#define OPTIONS_ENTRIES_START_ROW 2 #define OPTIONS_ENTRIES_START_ROW 2
#define ENTRY_PAGE_LENGTH 10 #define ENTRY_PAGE_LENGTH 10
bool bigJump = false; bool bigJump = false;
extern PrintConsole topConsole, bottomConsole;
using namespace std;
static char path[PATH_MAX]; static char path[PATH_MAX];
@ -133,12 +132,11 @@ void getDirectoryContents (vector<DirEntry>& dirContents) {
void showDirectoryContents (const vector<DirEntry>& dirContents, int fileOffset, int startRow) { void showDirectoryContents (const vector<DirEntry>& dirContents, int fileOffset, int startRow) {
getcwd(path, PATH_MAX); getcwd(path, PATH_MAX);
// Clear the screen consoleClear();
iprintf ("\x1b[2J");
// Print the path // Print the path
printf ("\x1B[42m"); // Print green color printf ("\x1B[42m"); // Print green color
printf ("________________________________"); printf ("___________________________%s", RetTime().c_str());
printf ("\x1b[0;0H"); printf ("\x1b[0;0H");
if (strlen(path) < SCREEN_COLS) { if (strlen(path) < SCREEN_COLS) {
iprintf ("%s", path); iprintf ("%s", path);
@ -152,7 +150,6 @@ void showDirectoryContents (const vector<DirEntry>& dirContents, int fileOffset,
// Print directory listing // Print directory listing
for (int i = 0; i < ((int)dirContents.size() - startRow) && i < ENTRIES_PER_SCREEN; i++) { for (int i = 0; i < ((int)dirContents.size() - startRow) && i < ENTRIES_PER_SCREEN; i++) {
const DirEntry* entry = &dirContents.at(i + startRow); const DirEntry* entry = &dirContents.at(i + startRow);
char entryName[SCREEN_COLS + 1];
// Set row // Set row
iprintf ("\x1b[%d;0H", i + ENTRIES_START_ROW); iprintf ("\x1b[%d;0H", i + ENTRIES_START_ROW);
@ -164,9 +161,7 @@ void showDirectoryContents (const vector<DirEntry>& dirContents, int fileOffset,
printf ("\x1B[40m"); // Print foreground black color printf ("\x1B[40m"); // Print foreground black color
} }
strncpy (entryName, entry->name.c_str(), SCREEN_COLS); printf ("%.*s", SCREEN_COLS, entry->name.c_str());
entryName[SCREEN_COLS] = '\0';
printf (entryName);
if (strcmp(entry->name.c_str(), "..") == 0) { if (strcmp(entry->name.c_str(), "..") == 0) {
printf ("\x1b[%d;28H", i + ENTRIES_START_ROW); printf ("\x1b[%d;28H", i + ENTRIES_START_ROW);
printf ("(..)"); printf ("(..)");
@ -192,7 +187,8 @@ int fileBrowse_A(DirEntry* entry, char path[PATH_MAX]) {
printf ("\x1b[0;27H"); printf ("\x1b[0;27H");
printf ("\x1B[42m"); // Print green color printf ("\x1B[42m"); // Print green color
printf ("_____"); // Clear time printf ("_____"); // Clear time
consoleInit(NULL, 1, BgType_Text4bpp, BgSize_T_256x256, 15, 0, false, true); consoleSelect(&bottomConsole);
consoleClear();
printf ("\x1B[47m"); // Print foreground white color printf ("\x1B[47m"); // Print foreground white color
char fullPath[256]; char fullPath[256];
snprintf(fullPath, sizeof(fullPath), "%s%s", path, entry->name.c_str()); snprintf(fullPath, sizeof(fullPath), "%s%s", path, entry->name.c_str());
@ -319,10 +315,12 @@ bool fileBrowse_paste(char destPath[256]) {
int optionOffset = 0; int optionOffset = 0;
int maxCursors = -1; int maxCursors = -1;
consoleClear();
printf ("\x1b[0;27H"); printf ("\x1b[0;27H");
printf ("\x1B[42m"); // Print green color printf ("\x1B[42m"); // Print green color
printf ("_____"); // Clear time printf ("_____"); // Clear time
consoleInit(NULL, 1, BgType_Text4bpp, BgSize_T_256x256, 15, 0, false, true); consoleSelect(&bottomConsole);
printf ("\x1B[47m"); // Print foreground white color printf ("\x1B[47m"); // Print foreground white color
printf(clipboardFolder ? "Paste folder here?" : "Paste file here?"); printf(clipboardFolder ? "Paste folder here?" : "Paste file here?");
printf("\n\n"); printf("\n\n");
@ -398,37 +396,26 @@ void recRemove(DirEntry* entry, std::vector<DirEntry> dirContents) {
} }
void fileBrowse_drawBottomScreen(DirEntry* entry) { void fileBrowse_drawBottomScreen(DirEntry* entry) {
consoleClear();
printf ("\x1B[47m"); // Print foreground white color printf ("\x1B[47m"); // Print foreground white color
printf ("\x1b[22;0H"); printf ("\x1b[22;0H");
printf (titleName); printf ("%s\n", titleName);
printf ("\n"); printf ("X - DELETE/[+R] RENAME file\n");
printf ("X - DELETE/[+R] RENAME file"); printf ("%s/[+R] CREATE entry%s", clipboardOn ? "Y - PASTE file" : "Y - COPY file", clipboardOn ? "" : "\n");
printf ("\n"); printf ("R+A - Directory options\n");
printf (clipboardOn ? "Y - PASTE file" : "Y - COPY file"); printf ("%s\n", SCREENSHOTTEXT);
printf ("/[+R] CREATE entry"); printf ("%s\n", clipboardOn ? "SELECT - Clear Clipboard" : "SELECT - Restore Clipboard");
if (!clipboardOn) {
printf ("\n");
}
printf ("R+A - Directory options");
printf ("\n");
printf (SCREENSHOTTEXT);
printf ("\n");
printf (clipboardOn ? "SELECT - Clear Clipboard" : "SELECT - Restore Clipboard");
printf ("\n");
if (!isDSiMode() && isRegularDS) { if (!isDSiMode() && isRegularDS) {
printf (POWERTEXT_DS); printf (POWERTEXT_DS);
} else if (is3DS) { } else if (is3DS) {
printf (POWERTEXT_3DS); printf ("%s\n%s", POWERTEXT_3DS, HOMETEXT);
printf ("\n");
printf (HOMETEXT);
} else { } else {
printf (POWERTEXT); printf (POWERTEXT);
} }
printf (entry->isDirectory ? "\x1B[34m" : "\x1B[40m"); // Print background blue color or foreground black color printf (entry->isDirectory ? "\x1B[34m" : "\x1B[40m"); // Print background blue color or foreground black color
printf ("\x1b[0;0H"); printf ("\x1b[0;0H");
printf (entry->name.c_str()); printf ("%s\n", entry->name.c_str());
printf ("\n");
if (strcmp(entry->name.c_str(), "..") != 0) { if (strcmp(entry->name.c_str(), "..") != 0) {
if (entry->isDirectory) { if (entry->isDirectory) {
printf ("(dir)"); printf ("(dir)");
@ -459,9 +446,9 @@ string browseForFile (void) {
while (true) { while (true) {
DirEntry* entry = &dirContents.at(fileOffset); DirEntry* entry = &dirContents.at(fileOffset);
consoleInit(NULL, 1, BgType_Text4bpp, BgSize_T_256x256, 15, 0, false, true); consoleSelect(&bottomConsole);
fileBrowse_drawBottomScreen(entry); fileBrowse_drawBottomScreen(entry);
consoleInit(NULL, 0, BgType_Text4bpp, BgSize_T_256x256, 15, 0, true, true); consoleSelect(&topConsole);
showDirectoryContents (dirContents, fileOffset, screenOffset); showDirectoryContents (dirContents, fileOffset, screenOffset);
stored_SCFG_MC = REG_SCFG_MC; stored_SCFG_MC = REG_SCFG_MC;
@ -514,11 +501,9 @@ string browseForFile (void) {
// Scroll screen if needed // Scroll screen if needed
if (fileOffset < screenOffset) { if (fileOffset < screenOffset) {
screenOffset = fileOffset; screenOffset = fileOffset;
showDirectoryContents (dirContents, fileOffset, screenOffset);
} }
if (fileOffset > screenOffset + ENTRIES_PER_SCREEN - 1) { if (fileOffset > screenOffset + ENTRIES_PER_SCREEN - 1) {
screenOffset = fileOffset - ENTRIES_PER_SCREEN + 1; screenOffset = fileOffset - ENTRIES_PER_SCREEN + 1;
showDirectoryContents (dirContents, fileOffset, screenOffset);
} }
getcwd(path, PATH_MAX); getcwd(path, PATH_MAX);
@ -600,6 +585,8 @@ string browseForFile (void) {
keyboardHide(); keyboardHide();
consoleClear(); consoleClear();
consoleInit(&bottomConsole, 0, BgType_Text4bpp, BgSize_T_256x256, 15, 0, false, true);
if (newName[0] != '\0') { if (newName[0] != '\0') {
// Check for unsupported characters // Check for unsupported characters
for (int i = 0; i < (int)sizeof(newName); i++) { for (int i = 0; i < (int)sizeof(newName); i++) {
@ -627,7 +614,8 @@ string browseForFile (void) {
printf ("\x1b[0;27H"); printf ("\x1b[0;27H");
printf ("\x1B[42m"); // Print green color printf ("\x1B[42m"); // Print green color
printf ("_____"); // Clear time printf ("_____"); // Clear time
consoleInit(NULL, 1, BgType_Text4bpp, BgSize_T_256x256, 15, 0, false, true); consoleSelect(&bottomConsole);
consoleClear();
printf ("\x1B[47m"); // Print foreground white color printf ("\x1B[47m"); // Print foreground white color
iprintf("Delete \"%s\"?\n", entry->name.c_str()); iprintf("Delete \"%s\"?\n", entry->name.c_str());
printf ("(<A> yes, <B> no)"); printf ("(<A> yes, <B> no)");
@ -692,6 +680,8 @@ string browseForFile (void) {
keyboardHide(); keyboardHide();
consoleClear(); consoleClear();
consoleInit(&bottomConsole, 0, BgType_Text4bpp, BgSize_T_256x256, 15, 0, false, true);
if (newName[0] != '\0') { if (newName[0] != '\0') {
if (mkdir(newName, 0777) == 0) { if (mkdir(newName, 0777) == 0) {
getDirectoryContents (dirContents); getDirectoryContents (dirContents);
@ -748,9 +738,9 @@ string browseForFile (void) {
screenshotbmp(snapPath); screenshotbmp(snapPath);
// Seamlessly swap top and bottom screens // Seamlessly swap top and bottom screens
lcdMainOnBottom(); lcdMainOnBottom();
consoleInit(NULL, 1, BgType_Text4bpp, BgSize_T_256x256, 15, 0, true, true); consoleSelect(&bottomConsole);
fileBrowse_drawBottomScreen(entry); fileBrowse_drawBottomScreen(entry);
consoleInit(NULL, 1, BgType_Text4bpp, BgSize_T_256x256, 15, 0, false, true); consoleSelect(&topConsole);
showDirectoryContents (dirContents, fileOffset, screenOffset); showDirectoryContents (dirContents, fileOffset, screenOffset);
printf("\x1B[42m"); // Print green color for time text printf("\x1B[42m"); // Print green color for time text
printf ("\x1b[0;26H"); printf ("\x1b[0;26H");

View File

@ -50,6 +50,8 @@ bool applaunch = false;
static int bg3; static int bg3;
PrintConsole topConsole, bottomConsole;
using namespace std; using namespace std;
//--------------------------------------------------------------------------------- //---------------------------------------------------------------------------------
@ -99,7 +101,7 @@ int main(int argc, char **argv) {
// Subscreen as a console // Subscreen as a console
videoSetModeSub(MODE_0_2D); videoSetModeSub(MODE_0_2D);
vramSetBankH(VRAM_H_SUB_BG); vramSetBankH(VRAM_H_SUB_BG);
consoleInit(NULL, 0, BgType_Text4bpp, BgSize_T_256x256, 15, 0, false, true); consoleInit(&bottomConsole, 0, BgType_Text4bpp, BgSize_T_256x256, 15, 0, false, true);
// Display GM9i logo // Display GM9i logo
bg3 = bgInit(3, BgType_Bmp16, BgSize_B16_256x256, 1, 0); bg3 = bgInit(3, BgType_Bmp16, BgSize_B16_256x256, 1, 0);
@ -156,6 +158,7 @@ int main(int argc, char **argv) {
// Top screen as a console // Top screen as a console
videoSetMode(MODE_0_2D); videoSetMode(MODE_0_2D);
vramSetBankG(VRAM_G_MAIN_BG); vramSetBankG(VRAM_G_MAIN_BG);
consoleInit(&topConsole, 0, BgType_Text4bpp, BgSize_T_256x256, 15, 0, true, true);
keysSetRepeat(25,5); keysSetRepeat(25,5);