Skip to content

Commit

Permalink
Merge pull request #39 from HandsomeMatt/master
Browse files Browse the repository at this point in the history
mostly UI changes and bug fixes
  • Loading branch information
handsomematt authored Sep 5, 2017
2 parents 496b061 + bada287 commit be6bd52
Show file tree
Hide file tree
Showing 7 changed files with 3,168 additions and 183 deletions.
2 changes: 1 addition & 1 deletion flashcart_core
3,213 changes: 3,080 additions & 133 deletions source/common/font.h

Large diffs are not rendered by default.

74 changes: 53 additions & 21 deletions source/common/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,38 @@ void ClearScreen(uint8_t *screen, int color)
}
}

void DrawRectangle(uint8_t* screen, int x, int y, int width, int height, int color)
{
for (int yy = 0; yy < height; yy++) {
int xDisplacement = (x * BYTES_PER_PIXEL * SCREEN_HEIGHT);
int yDisplacement = ((SCREEN_HEIGHT - (y + yy) - 1) * BYTES_PER_PIXEL);
u8* screenPos = screen + xDisplacement + yDisplacement;
for (int xx = width - 1; xx >= 0; xx--) {
*(screenPos + 0) = color >> 16; // B
*(screenPos + 1) = color >> 8; // G
*(screenPos + 2) = color & 0xFF; // R
screenPos += BYTES_PER_PIXEL * SCREEN_HEIGHT;
}
}
}

void DrawCharacter(uint8_t *screen, int character, int x, int y, int color, int bgcolor)
{
for (int yy = 0; yy < 8; yy++)
for (int yy = 0; yy < FONT_HEIGHT; yy++)
{
int xDisplacement = (x * BYTES_PER_PIXEL * SCREEN_HEIGHT);
int yDisplacement = ((SCREEN_HEIGHT - (y + yy) - 1) * BYTES_PER_PIXEL);
uint8_t *screenPos = screen + xDisplacement + yDisplacement;

uint8_t charPos = font[character * 8 + yy];
for (int xx = 7; xx >= 0; xx--)
uint8_t charPos = font[character * FONT_HEIGHT + yy];
for (int xx = 7; xx >= (8 - FONT_WIDTH); xx--)
{
if ((charPos >> xx) & 1)
{
*(screenPos + 0) = color >> 16; //B
*(screenPos + 1) = color >> 8; //G
*(screenPos + 2) = color & 0xFF; //R
}
else
{
} else if (bgcolor != COLOR_TRANSPARENT) {
*(screenPos + 0) = bgcolor >> 16; //B
*(screenPos + 1) = bgcolor >> 8; //G
*(screenPos + 2) = bgcolor & 0xFF; //R
Expand Down Expand Up @@ -83,21 +96,7 @@ void DrawHex(uint8_t *screen, unsigned int hex, int x, int y, int color, int bgc
void DrawHexWithName(uint8_t *screen, const char *str, unsigned int hex, int x, int y, int color, int bgcolor)
{
DrawString(screen, str, x, y, color, bgcolor);
DrawHex(screen, hex,x + strlen(str) * 8, y, color, bgcolor);
}

void ShowProgress(uint8_t *screen, uint32_t current, uint32_t total)
{
const uint32_t progX = SCREEN_WIDTH - 40;
const uint32_t progY = SCREEN_HEIGHT - 20;

if (total > 0) {
char progStr[8];
snprintf(progStr, 8, "%3lu%%", (current * 100) / total);
DrawString(screen, progStr, progX, progY, STD_COLOR_FONT, STD_COLOR_BG);
} else {
DrawString(screen, " ", progX, progY, STD_COLOR_FONT, STD_COLOR_BG);
}
DrawHex(screen, hex,x + strlen(str) * FONT_WIDTH, y, color, bgcolor);
}

uint32_t GetDrawStringHeight(const char* str) {
Expand Down Expand Up @@ -170,4 +169,37 @@ bool ShowPrompt(uint8_t *screen, bool ask, const char *format, ...)
ClearScreen(screen, STD_COLOR_BG);

return ret;
}

void ShowProgress(uint8_t *screen, uint32_t current, uint32_t total, const char* status)
{
const uint8_t bar_width = 240;
const uint8_t bar_height = 12;
const uint16_t bar_pos_x = (SCREEN_WIDTH - bar_width) / 2;
const uint16_t bar_pos_y = (SCREEN_HEIGHT / 2) - (bar_height / 2);
const uint16_t text_pos_x = bar_pos_x + (bar_width/2) - (FONT_WIDTH*2);
const uint16_t text_pos_y = bar_pos_y + 1;

static uint32_t last_prog_width = 0;
uint32_t prog_width = ((total > 0) && (current <= total)) ? (current * (bar_width-4)) / total : 0;
uint32_t prog_percent = ((total > 0) && (current <= total)) ? (current * 100) / total : 0;

DrawString(screen, status, bar_pos_x, bar_pos_y - FONT_HEIGHT - 4, STD_COLOR_FONT, STD_COLOR_BG);

// draw the initial outline
if (current == 0 || last_prog_width > prog_width)
{
ClearScreen(screen, STD_COLOR_BG);
DrawRectangle(screen, bar_pos_x, bar_pos_y, bar_width, bar_height, STD_COLOR_FONT);
DrawRectangle(screen, bar_pos_x + 1, bar_pos_y + 1, bar_width - 2, bar_height - 2, STD_COLOR_BG);
}

// only draw the rectangle if it's changed.
if (current == 0 || last_prog_width != prog_width)
{
DrawRectangle(screen, bar_pos_x + 2, bar_pos_y + 2, prog_width, bar_height - 4, COLOR_GREEN);
DrawStringF(screen, text_pos_x, text_pos_y, STD_COLOR_FONT, COLOR_TRANSPARENT, "%3lu%%", prog_percent);
}

last_prog_width = prog_width;
}
10 changes: 5 additions & 5 deletions source/common/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ extern uint8_t *top_screen, *bottom_screen;
#define SCREEN_SIZE_TOP (BYTES_PER_PIXEL*SCREEN_WIDTH_TOP)
#define SCREEN_SIZE_BOT (BYTES_PER_PIXEL*SCREEN_WIDTH_BOT)

#define FONT_WIDTH 8
#define FONT_HEIGHT 10

#define RGB(r,g,b) (r<<24|b<<16|g<<8|r)

#define COLOR_BLACK RGB(0x00, 0x00, 0x00)
Expand Down Expand Up @@ -45,15 +42,18 @@ extern uint8_t *top_screen, *bottom_screen;
#define STD_COLOR_FONT COLOR_WHITE

void ClearScreen(uint8_t *screen, int color);
void DrawRectangle(uint8_t* screen, int x, int y, int width, int height, int color);

void DrawCharacter(uint8_t *screen, int character, int x, int y, int color, int bgcolor);
void DrawHex(uint8_t *screen, unsigned int hex, int x, int y, int color, int bgcolor);
void DrawString(uint8_t *screen, const char *str, int x, int y, int color, int bgcolor);
void DrawStringF(uint8_t *screen, int x, int y, int color, int bgcolor, const char *format, ...);
void DrawHexWithName(uint8_t *screen, const char *str, unsigned int hex, int x, int y, int color, int bgcolor);
void ShowProgress(uint8_t *screen, uint32_t current, uint32_t total);

uint32_t GetDrawStringHeight(const char* str);
uint32_t GetDrawStringWidth(const char* str);

void ShowString(uint8_t *screen, const char *format, ...);
bool ShowPrompt(uint8_t *screen, bool ask, const char *format, ...);
bool ShowPrompt(uint8_t *screen, bool ask, const char *format, ...);

void ShowProgress(uint8_t* screen, uint32_t current, uint32_t total, const char* status);
6 changes: 0 additions & 6 deletions source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ void ntrboot_dump_flash() {
if (mem == NULL)
ShowPrompt(BOTTOM_SCREEN, false, "Failed to allocate memory");

ShowProgress(TOP_SCREEN, 0, 0);
selected_flashcart->readFlash(0, length, mem);

ShowPrompt(BOTTOM_SCREEN, false, "Read from flash successfully.");
Expand All @@ -154,7 +153,6 @@ void ntrboot_dump_flash() {
fclose(f);

free(mem);
ShowProgress(TOP_SCREEN, 0, 0);

DrawStringF(TOP_SCREEN, 10, 150, COLOR_GREEN, STD_COLOR_BG, "Dump Complete!");
ELM_Unmount();
Expand Down Expand Up @@ -190,15 +188,13 @@ void ntrboot_restore_flash() {
uint8_t* flash_memp = flash_mem;

DrawStringF(TOP_SCREEN, 10, 40, STD_COLOR_FONT, STD_COLOR_BG, "Reading...");
ShowProgress(TOP_SCREEN, 0, 0);
selected_flashcart->readFlash(0, length, flash_memp);

int written_chunk = 0;
const int chunk_size = 64*1024;
for(uint32_t j=0; j<length; j+=chunk_size)
{
DrawStringF(TOP_SCREEN, 10, 50, STD_COLOR_FONT, STD_COLOR_BG, "Checking %08X", j);
ShowProgress(TOP_SCREEN, j, length);
if(memcmp(flash_memp+j,memp+j,chunk_size) != 0)
{
DrawStringF(TOP_SCREEN, 10, 60, STD_COLOR_FONT, STD_COLOR_BG, "Writing chunk %08X", j);
Expand Down Expand Up @@ -264,9 +260,7 @@ void ntrboot_inject() {

DrawStringF(TOP_SCREEN, 10, 80, COLOR_GREEN, STD_COLOR_BG, "Injecting...");

ShowProgress(TOP_SCREEN, 0, 0);
selected_flashcart->injectNtrBoot((uint8_t *)blowfish_retail_bin, firm, firm_size);
ShowProgress(TOP_SCREEN, 0, 0);

DrawStringF(TOP_SCREEN, 10, 90, COLOR_GREEN, STD_COLOR_BG, "Injection Complete!");
} else
Expand Down
42 changes: 27 additions & 15 deletions source/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,23 @@ bool menu_show_intro_warning()
{
ClearScreen(TOP_SCREEN, COLOR_RED);

DrawStringF(TOP_SCREEN, 10, 10, COLOR_BLACK, COLOR_RED, "ntrboot flasher [%s]", NTRBOOT_FLASHER_VERSION);
DrawStringF(TOP_SCREEN, 10, 20, COLOR_BLACK, COLOR_RED, "flashcart_core [%s]", FLASHCART_CORE_VERSION);
DrawStringF(TOP_SCREEN, 10, 10, COLOR_WHITE, COLOR_RED, "WARNING: READ THIS BEFORE CONTINUING");
DrawStringF(TOP_SCREEN, 10, 20, COLOR_WHITE, COLOR_RED, "------------------------------------");

DrawStringF(TOP_SCREEN, 10, 40, COLOR_BLACK, COLOR_RED, "WARNING");
DrawStringF(TOP_SCREEN, 10, 50, COLOR_BLACK, COLOR_RED, "-------");
DrawStringF(TOP_SCREEN, 10, 70, COLOR_BLACK, COLOR_RED, "This software writes directly to\nyour flashcart to inject ntrboot.");
DrawStringF(TOP_SCREEN, 10, 90, COLOR_BLACK, COLOR_RED, "In rare cases this may brick your\nflashcart and leave it unusable.");
DrawStringF(TOP_SCREEN, 10, 130, COLOR_BLACK, COLOR_RED, "<A> Continue <B> Exit");
DrawStringF(TOP_SCREEN, 10, 40, COLOR_WHITE, COLOR_RED, "If you don't know what you're doing: STOP. Open your browser to");
DrawStringF(TOP_SCREEN, 10, 50, COLOR_WHITE, COLOR_RED, "http://3ds.guide and follow the steps provided there.");

return (WaitButton(BUTTON_A | BUTTON_B) & BUTTON_A) == BUTTON_A;
DrawStringF(TOP_SCREEN, 10, 70, COLOR_WHITE, COLOR_RED, "This software writes directly to your flashcart. It's possible");
DrawStringF(TOP_SCREEN, 10, 80, COLOR_WHITE, COLOR_RED, "you may brick your flashcart, rendering it unusable.");

DrawStringF(TOP_SCREEN, 10, 100, COLOR_WHITE, COLOR_RED, "ALWAYS KEEP A BACKUP");

DrawStringF(TOP_SCREEN, 10, 120, COLOR_WHITE, COLOR_RED, "<A> Continue <B> Exit");

while (HID_STATE != 0); // bug fix: wait for the HID_STATE to reset
bool retval = (WaitButton(BUTTON_A | BUTTON_B) & BUTTON_A) == BUTTON_A;
ClearScreen(TOP_SCREEN, COLOR_BLACK);
return retval;
}

int8_t menu_select_flashcart()
Expand All @@ -35,9 +42,14 @@ int8_t menu_select_flashcart()

int deviceOption = 0;
while(true)
{
DrawStringF(TOP_SCREEN, 0, 0, COLOR_WHITE, COLOR_BLUE, " Select your flashcart: ");
DrawStringF(TOP_SCREEN, 0, SCREEN_HEIGHT-FONT_HEIGHT, COLOR_WHITE, COLOR_RED, " Press <B> to Exit. ");
{
DrawRectangle(TOP_SCREEN, 0, 0, SCREEN_WIDTH_TOP, 12, COLOR_BLUE);

DrawStringF(TOP_SCREEN, 10, 1, COLOR_WHITE, COLOR_BLUE, "Select your flashcart:");
DrawStringF(TOP_SCREEN, 270, 1, COLOR_WHITE, COLOR_BLUE, "<A> Select <B> Exit");

DrawStringF(TOP_SCREEN, 10, SCREEN_HEIGHT-23, COLOR_BLACK, COLOR_LIGHTGREY, "ntrboot_flasher: %s", NTRBOOT_FLASHER_VERSION);
DrawStringF(TOP_SCREEN, 10, SCREEN_HEIGHT-11, COLOR_BLACK, COLOR_LIGHTGREY, "flashcart_core: %s", FLASHCART_CORE_VERSION);

// todo: scroll through this, we can only have 23 on the screen at once
int i = 0;
Expand All @@ -48,13 +60,13 @@ int8_t menu_select_flashcart()
{
ClearScreen(BOTTOM_SCREEN, STD_COLOR_BG);

DrawStringF(BOTTOM_SCREEN, 0, 0, COLOR_WHITE, COLOR_BLUE, " Selected Cart Info ");
DrawRectangle(BOTTOM_SCREEN, 0, 0, SCREEN_WIDTH_TOP, 12, COLOR_BLUE);
DrawStringF(BOTTOM_SCREEN, 106, 0, COLOR_WHITE, COLOR_BLUE, "Selected Cart Info");

DrawStringF(BOTTOM_SCREEN, 10, 20, STD_COLOR_FONT, STD_COLOR_BG, "Name: %s", (*it)->getName());
DrawStringF(BOTTOM_SCREEN, 10, 30, STD_COLOR_FONT, STD_COLOR_BG, "Author: %s", (*it)->getAuthor());

DrawStringF(BOTTOM_SCREEN, 10, 50, STD_COLOR_FONT, STD_COLOR_BG, "Description:");
DrawStringF(BOTTOM_SCREEN, 10, 70, STD_COLOR_FONT, STD_COLOR_BG, (*it)->getDescription());

DrawStringF(BOTTOM_SCREEN, 10, 50, STD_COLOR_FONT, STD_COLOR_BG, (*it)->getDescription());
}
}

Expand Down
4 changes: 2 additions & 2 deletions source/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ void Flashcart::sendCommand(const uint8_t *cmdbuf, uint16_t response_len, uint8_
NTR_SendCommand(cmdbuf, response_len, flags, resp);
}

void Flashcart::showProgress(uint32_t current, uint32_t total) {
ShowProgress(TOP_SCREEN, current, total);
void Flashcart::showProgress(uint32_t current, uint32_t total, const char* status_string) {
ShowProgress(BOTTOM_SCREEN, current, total, status_string);
}

0 comments on commit be6bd52

Please sign in to comment.