Small optimizations

This commit is contained in:
Such Meme, Many Skill
2020-05-04 13:55:26 +02:00
parent 6681a35b2c
commit 9799e2b47e
19 changed files with 302 additions and 288 deletions

View File

@@ -41,7 +41,7 @@ u32 gfx_message(u32 color, const char* message, ...){
return hidWait()->buttons;
}
u32 gfx_errDisplay(char *src_func, int err, int loc){
u32 gfx_errDisplay(const char *src_func, int err, int loc){
if (!printerrors)
return 0;
@@ -58,14 +58,14 @@ u32 gfx_errDisplay(char *src_func, int err, int loc){
if (loc)
gfx_printf("Loc: %d\n", loc);
gfx_printf("\nPress any button to return");
gfx_printf("\nPress any button to return\n");
RESETCOLOR;
return hidWait()->buttons;
}
int gfx_makewaitmenu(char *hiddenmessage, int timer){
int gfx_makewaitmenu(const char *hiddenmessage, int timer){
u32 start = get_tmr_s();
Inputs *input = NULL;
@@ -86,7 +86,7 @@ int gfx_makewaitmenu(char *hiddenmessage, int timer){
}
}
void gfx_printlength(int size, char *toprint){
void gfx_printlength(int size, const char *toprint){
char *temp;
temp = (char*) malloc (size + 1);
@@ -102,7 +102,7 @@ void gfx_printlength(int size, char *toprint){
free(temp);
}
void gfx_printandclear(char *in, int length, int endX){
void gfx_printandclear(const char *in, int length, int endX){
u32 x, y;
gfx_printlength(length, in);
@@ -126,12 +126,6 @@ void gfx_printandclear(char *in, int length, int endX){
*/
}
void gfx_printfilesize(int size, char *type){
SWAPCOLOR(COLOR_VIOLET);
gfx_printf("\a%4d\e%s", size, type);
RESETCOLOR;
}
static u32 sideY = 0;
void _gfx_sideSetYAuto(){
u32 getX, getY;
@@ -147,7 +141,7 @@ u32 gfx_sideGetY(){
return sideY;
}
void gfx_sideprintf(char* message, ...){
void gfx_sideprintf(const char* message, ...){
va_list ap;
va_start(ap, message);
@@ -158,7 +152,7 @@ void gfx_sideprintf(char* message, ...){
va_end(ap);
}
void gfx_sideprintandclear(char* message, int length){
void gfx_sideprintandclear(const char* message, int length){
gfx_con_setpos(800, sideY);
gfx_printandclear(message, length, 1279);
gfx_putc('\n');
@@ -180,7 +174,7 @@ void gfx_drawScrollBar(int minView, int maxView, int count){
gfx_boxGrey(740, 16 + offsetSize, 755, 16 + barSize + offsetSize, 0x66);
}
int gfx_defaultWaitMenu(char *message, int time){
int gfx_defaultWaitMenu(const char *message, int time){
gfx_clearscreen();
SWAPCOLOR(COLOR_ORANGE);
gfx_printf("\n%s\n\nPress B to return\n", message);

View File

@@ -4,20 +4,20 @@
#define SWAPCOLOR(color) gfx_printf("%k", color)
#define SWAPBGCOLOR(color) gfx_printf("%K", color)
#define SWAPALLCOLOR(fg, bg) gfx_printf("%k%K", fg, bg)
#define RESETCOLOR gfx_printf("%k%K", COLOR_WHITE, COLOR_DEFAULT)
void gfx_clearscreen();
u32 gfx_message(u32 color, const char* message, ...);
u32 gfx_errDisplay(char *src_func, int err, int loc);
int gfx_makewaitmenu(char *hiddenmessage, int timer);
void gfx_printlength(int size, char *toprint);
void gfx_printandclear(char *in, int length, int endX);
void gfx_printfilesize(int size, char *type);
u32 gfx_errDisplay(const char *src_func, int err, int loc);
int gfx_makewaitmenu(const char *hiddenmessage, int timer);
void gfx_printlength(int size, const char *toprint);
void gfx_printandclear(const char *in, int length, int endX);
void gfx_sideSetY(u32 setY);
u32 gfx_sideGetY();
void gfx_sideprintf(char* message, ...);
void gfx_sideprintandclear(char* message, int length);
void gfx_sideprintf(const char* message, ...);
void gfx_sideprintandclear(const char* message, int length);
void gfx_drawScrollBar(int minView, int maxView, int count);
int gfx_defaultWaitMenu(char *message, int time);
int gfx_defaultWaitMenu(const char *message, int time);
extern int printerrors;

View File

@@ -9,81 +9,59 @@
#include "../../soc/gpio.h"
#include "../../hid/hid.h"
#include "../fs/fsutils.h"
#include "../utils/menuUtils.h"
extern void sd_unmount();
extern bool sd_inited;
void _printentry(menu_entry *entry, bool highlighted, bool refresh, char *path){
u64 size;
u16 sizes = 0;
u32 color = (entry->property & ISMENU) ? entry->storage : ((entry->property & ISDIR) ? COLOR_WHITE : COLOR_VIOLET);
/*
if (entry.property & ISMENU)
SWAPCOLOR(entry.storage);
else if (entry.property & ISDIR)
SWAPCOLOR(COLOR_WHITE);
else {
SWAPCOLOR(COLOR_VIOLET);
}
*/
#pragma GCC push_options
#pragma GCC optimize ("O2")
if (!(entry->property & ISMENU && entry->property & ISDIR)){
if (entry->property & ISNULL){
size = fsutil_getfilesize(fsutil_getnextloc(path, entry->name));
while (size > 1024){
size /= 1024;
sizes++;
}
void _printentry(menu_entry *entry, bool highlighted, bool refresh, const char *path){
u32 color = (entry->isMenu) ? entry->storage : ((entry->isDir) ? COLOR_WHITE : COLOR_VIOLET);
if (sizes > 3)
sizes = 0;
SWAPALLCOLOR((highlighted) ? COLOR_DEFAULT : color, (highlighted) ? color : COLOR_DEFAULT);
entry->property |= (1 << (4 + sizes));
entry->storage = size;
SETBIT(entry->property, ISNULL, 0);
}
for (sizes = 4; sizes < 8; sizes++)
if ((entry->property & (1 << sizes)))
break;
}
/*
if (highlighted){
SWAPBGCOLOR(COLOR_WHITE);
if ((entry.property & ISMENU) ? entry.storage == COLOR_WHITE : entry.property & ISDIR)
SWAPCOLOR(COLOR_DEFAULT);
}
else
SWAPBGCOLOR(COLOR_DEFAULT);
*/
SWAPCOLOR((highlighted) ? COLOR_DEFAULT : color);
SWAPBGCOLOR((highlighted) ? color : COLOR_DEFAULT);
if (!(entry->property & ISMENU))
gfx_printf("%c ", (entry->property & ISDIR) ? 30 : 31);
if (!(entry->isMenu))
gfx_printf("%c ", (entry->isDir) ? 30 : 31);
if (refresh)
gfx_printandclear(entry->name, 37, 720);
else
gfx_printlength(37, entry->name);
if (entry->property & ISDIR || entry->property & ISMENU)
if (entry->property & (ISMENU | ISDIR))
gfx_printf("\n");
else {
SWAPCOLOR(COLOR_BLUE);
SWAPBGCOLOR(COLOR_DEFAULT);
if (entry->isNull){
u64 totalSize;
u32 sizeType = 0;
totalSize = fsutil_getfilesize(fsutil_getnextloc(path, entry->name));
while (totalSize > 1024){
totalSize /= 1024;
sizeType++;
}
if (sizeType > 3)
sizeType = 3;
entry->size = sizeType;
entry->storage = totalSize;
SETBIT(entry->property, ISNULL, 0);
}
SWAPALLCOLOR(COLOR_BLUE, COLOR_DEFAULT);
gfx_printf("\a%4d", entry->storage);
gfx_con.fntsz = 8;
gfx_printf("\n\e%s\n", gfx_file_size_names[sizes - 4]);
gfx_printf("\n\e%s\n", gfx_file_size_names[entry->size]);
gfx_con.fntsz = 16;
}
}
bool disableB = false;
int menu_make(menu_entry *entries, int amount, char *toptext){
int menu_make(menu_entry *entries, int amount, const char *toptext){
int currentpos = 0, offset = 0, delay = 300, minscreen = 0, maxscreen = 39, calculatedamount = 0;
u32 scrolltimer, timer, sideY;
bool refresh = true;
@@ -92,23 +70,9 @@ int menu_make(menu_entry *entries, int amount, char *toptext){
gfx_clearscreen();
for (int i = 0; i < amount; i++)
if (!(entries[i].property & ISMENU))
calculatedamount++;
calculatedamount = mu_countObjects(entries, ISMENU);
gfx_con_setpos(0, 16);
/*
if (calculatedamount){
SWAPCOLOR(COLOR_DEFAULT);
SWAPBGCOLOR(COLOR_WHITE);
gfx_printf("%3d entries\n", calculatedamount);
RESETCOLOR;
}
else
gfx_printf("\n");
*/
SWAPCOLOR(COLOR_GREEN);
gfx_printlength(42, toptext);
@@ -162,7 +126,7 @@ int menu_make(menu_entry *entries, int amount, char *toptext){
if (refresh || currentfolder == NULL || !calculatedamount){
for (int i = 0 + offset; i < amount && i < 40 + offset; i++)
if (!(entries[i].property & ISHIDE))
if (!(entries[i].isHide))
_printentry(&entries[i], (i == currentpos), refresh, toptext);
}
else {
@@ -182,12 +146,12 @@ int menu_make(menu_entry *entries, int amount, char *toptext){
RESETCOLOR;
sideY = gfx_sideGetY();
if (!(entries[currentpos].property & ISMENU)){
if (!(entries[currentpos].isMenu)){
gfx_sideprintf("Current selection:\n");
SWAPCOLOR(COLOR_YELLOW);
gfx_sideprintandclear(entries[currentpos].name, 28);
RESETCOLOR;
gfx_sideprintf("Type: %s", (entries[currentpos].property & ISDIR) ? "Dir " : "File");
gfx_sideprintf("Type: %s", (entries[currentpos].isDir) ? "Dir " : "File");
gfx_sideSetY(sideY);
}
else
@@ -256,4 +220,6 @@ int menu_make(menu_entry *entries, int amount, char *toptext){
minerva_periodic_training();
//return (mode) ? currentpos : entries[currentpos].property;
return currentpos;
}
}
#pragma GCC pop_options

View File

@@ -1,4 +1,4 @@
#pragma once
#include "../common/types.h"
int menu_make(menu_entry *entries, int amount, char *toptext);
int menu_make(menu_entry *entries, int amount, const char *toptext);