[v0.93][ARM] Support printing ASCII on chips that have lots of attributes (if they have more than 2 different CPUs). Fix all ASCII arts (they were missing the last empty character)

This commit is contained in:
Dr-Noob
2020-11-28 12:24:13 +01:00
parent 7d7af00e68
commit 1d58b1808d
2 changed files with 40 additions and 23 deletions

View File

@@ -23,7 +23,7 @@
\ \
\ \
\ \
" "
#define INTEL_ASCII \ #define INTEL_ASCII \
" ################ \ " ################ \
@@ -44,7 +44,7 @@
#### #### \ #### #### \
##### ########## \ ##### ########## \
########## ################ \ ########## ################ \
############################### " ############################### "
#define SNAPDRAGON_ASCII \ #define SNAPDRAGON_ASCII \
" \ " \
@@ -65,7 +65,7 @@
@@@@@@@@@@@@@@@@####### \ @@@@@@@@@@@@@@@@####### \
@@@@########### \ @@@@########### \
\ \
" "
#define MEDIATEK_ASCII \ #define MEDIATEK_ASCII \
" \ " \
@@ -86,7 +86,7 @@
\ \
\ \
\ \
" "
#define EXYNOS_ASCII \ #define EXYNOS_ASCII \
" \ " \
@@ -107,7 +107,7 @@
\ \
\ \
\ \
" "
#define ARM_ASCII \ #define ARM_ASCII \
@@ -129,7 +129,7 @@
\ \
\ \
\ \
" "
#define UNKNOWN_ASCII \ #define UNKNOWN_ASCII \
" \ " \
@@ -150,7 +150,7 @@
\ \
\ \
\ \
" "
static const char* ASCII_ARRAY [] = { static const char* ASCII_ARRAY [] = {
AMD_ASCII, AMD_ASCII,

View File

@@ -22,6 +22,7 @@
#include <Windows.h> #include <Windows.h>
#endif #endif
#define max(a,b) (((a)>(b))?(a):(b))
#define MAX_ATTRIBUTES 100 #define MAX_ATTRIBUTES 100
#define COLOR_NONE "" #define COLOR_NONE ""
@@ -99,7 +100,7 @@ struct attribute {
}; };
struct ascii { struct ascii {
char art[NUMBER_OF_LINES][LINE_SIZE]; char art[NUMBER_OF_LINES][LINE_SIZE+1];
char color1_ascii[100]; char color1_ascii[100];
char color2_ascii[100]; char color2_ascii[100];
char color1_text[100]; char color1_text[100];
@@ -108,6 +109,7 @@ struct ascii {
char reset[100]; char reset[100];
struct attribute** attributes; struct attribute** attributes;
uint32_t n_attributes_set; uint32_t n_attributes_set;
uint32_t additional_spaces;
VENDOR vendor; VENDOR vendor;
STYLE style; STYLE style;
}; };
@@ -141,6 +143,7 @@ struct ascii* set_ascii(VENDOR vendor, STYLE style, struct colors* cs) {
char *COL_FANCY_1, *COL_FANCY_2, *COL_FANCY_3, *COL_FANCY_4, *COL_RETRO_1, *COL_RETRO_2, *COL_RETRO_3, *COL_RETRO_4; char *COL_FANCY_1, *COL_FANCY_2, *COL_FANCY_3, *COL_FANCY_4, *COL_RETRO_1, *COL_RETRO_2, *COL_RETRO_3, *COL_RETRO_4;
struct ascii* art = malloc(sizeof(struct ascii)); struct ascii* art = malloc(sizeof(struct ascii));
art->n_attributes_set = 0; art->n_attributes_set = 0;
art->additional_spaces = 0;
art->vendor = vendor; art->vendor = vendor;
art->attributes = malloc(sizeof(struct attribute *) * MAX_ATTRIBUTES); art->attributes = malloc(sizeof(struct attribute *) * MAX_ATTRIBUTES);
for(uint32_t i=0; i < MAX_ATTRIBUTES; i++) { for(uint32_t i=0; i < MAX_ATTRIBUTES; i++) {
@@ -277,7 +280,7 @@ struct ascii* set_ascii(VENDOR vendor, STYLE style, struct colors* cs) {
return NULL; return NULL;
} }
char tmp[NUMBER_OF_LINES*LINE_SIZE]; char tmp[NUMBER_OF_LINES * LINE_SIZE + 1];
#ifdef ARCH_X86 #ifdef ARCH_X86
if(art->vendor == CPU_VENDOR_INTEL) if(art->vendor == CPU_VENDOR_INTEL)
strcpy(tmp, INTEL_ASCII); strcpy(tmp, INTEL_ASCII);
@@ -488,7 +491,7 @@ void print_algorithm_samsung(struct ascii* art, int i, int n) {
if(art->art[n][i] == '#') if(art->art[n][i] == '#')
printf("%s%c%s", art->color1_ascii, art->ascii_chars[0], art->reset); printf("%s%c%s", art->color1_ascii, art->ascii_chars[0], art->reset);
else else
printf("%s%c%s",COLOR_BG_BLACK COLOR_FG_WHITE, art->art[n][i], art->reset); printf("%s%c%s","\x1b[48;2;10;10;10m" COLOR_FG_WHITE, art->art[n][i], art->reset);
} }
else else
printf("%c", art->art[n][i]); printf("%c", art->art[n][i]);
@@ -505,17 +508,33 @@ void print_ascii_arm(struct ascii* art, uint32_t la, void (*callback_print_algor
int attr_to_print = 0; int attr_to_print = 0;
int attr_type; int attr_type;
char* attr_value; char* attr_value;
uint32_t limit_up;
uint32_t limit_down;
uint32_t space_right; uint32_t space_right;
uint32_t space_up = (NUMBER_OF_LINES - art->n_attributes_set)/2; uint32_t space_up = (NUMBER_OF_LINES - art->n_attributes_set)/2;
uint32_t space_down = NUMBER_OF_LINES - art->n_attributes_set - space_up; uint32_t space_down = NUMBER_OF_LINES - art->n_attributes_set - space_up;
if(art->n_attributes_set > NUMBER_OF_LINES) {
limit_up = 0;
limit_down = art->n_attributes_set;
}
else {
limit_up = space_up;
limit_down = NUMBER_OF_LINES-space_down;
}
bool add_space = false; bool add_space = false;
uint32_t len = max(art->n_attributes_set, NUMBER_OF_LINES);
printf("\n"); for(uint32_t n=0; n < len; n++) {
for(uint32_t n=0;n<NUMBER_OF_LINES;n++) { if(n >= art->additional_spaces && n < NUMBER_OF_LINES + art->additional_spaces) {
for(int i=0;i<LINE_SIZE;i++) for(int i=0;i<LINE_SIZE;i++)
callback_print_algorithm(art, i, n); callback_print_algorithm(art, i, n-art->additional_spaces);
}
else {
for(int i=0;i<LINE_SIZE;i++) printf(" ");
}
if(n > space_up-1 && n < NUMBER_OF_LINES-space_down) { if(n >= limit_up && n < limit_down) {
attr_type = art->attributes[attr_to_print]->type; attr_type = art->attributes[attr_to_print]->type;
attr_value = art->attributes[attr_to_print]->value; attr_value = art->attributes[attr_to_print]->value;
attr_to_print++; attr_to_print++;
@@ -540,7 +559,6 @@ void print_ascii_arm(struct ascii* art, uint32_t la, void (*callback_print_algor
} }
else printf("\n"); else printf("\n");
} }
printf("\n");
} }
@@ -617,8 +635,7 @@ bool print_cpufetch_arm(struct cpuInfo* cpu, STYLE s, struct colors* cs) {
setAttribute(art,ATTRIBUTE_PEAK,pp); setAttribute(art,ATTRIBUTE_PEAK,pp);
if(art->n_attributes_set > NUMBER_OF_LINES) { if(art->n_attributes_set > NUMBER_OF_LINES) {
printBug("The number of attributes set is bigger than the max that can be displayed"); art->additional_spaces = (art->n_attributes_set - NUMBER_OF_LINES) / 2;
return false;
} }
if(cpu->hv->present) if(cpu->hv->present)
setAttribute(art, ATTRIBUTE_HYPERVISOR, cpu->hv->hv_name); setAttribute(art, ATTRIBUTE_HYPERVISOR, cpu->hv->hv_name);
@@ -645,8 +662,8 @@ bool print_cpufetch(struct cpuInfo* cpu, STYLE s, struct colors* cs) {
int len = sizeof(ASCII_ARRAY) / sizeof(ASCII_ARRAY[0]); int len = sizeof(ASCII_ARRAY) / sizeof(ASCII_ARRAY[0]);
for(int i=0; i < len; i++) { for(int i=0; i < len; i++) {
const char* ascii = ASCII_ARRAY[i]; const char* ascii = ASCII_ARRAY[i];
if(strlen(ascii) != (NUMBER_OF_LINES * LINE_SIZE)-1) { if(strlen(ascii) != (NUMBER_OF_LINES * LINE_SIZE)) {
printBug("ASCII art %d is wrong! ASCII length: %d, expected length: %d", i, strlen(ascii), (NUMBER_OF_LINES * LINE_SIZE)-1); printBug("ASCII art %d is wrong! ASCII length: %d, expected length: %d", i, strlen(ascii), (NUMBER_OF_LINES * LINE_SIZE));
return false; return false;
} }
} }