BYTE palette_load_from_file(const uTCHAR *file) { FILE *fp; memset((BYTE *) palette_base_file, 0x00, 64 * 3); if ((fp = ufopen(file, uL("rb"))) == NULL) { ufprintf(stderr, uL("ERROR: open file " uPERCENTs "\n"), file); return (EXIT_ERROR); } fseek(fp, 0, SEEK_END); if (ftell(fp) < (64 * 3)) { ufprintf(stderr, uL("ERROR: read file " uPERCENTs "\n"), file); fclose(fp); return (EXIT_ERROR); } rewind(fp); if (!(fread((BYTE *) palette_base_file, 64 * 3, 1, fp))) { ; } fclose(fp); return (EXIT_OK); }
/** * * dump some hex values -- also * show the ascii version of the dump. * */ void debug_hex_dump(unsigned char level, uint8_t *hextodump, int size) { int i; char buf[80]; int str_idx = 0; int chr_idx = 0; int count; int total; int tmp; if ((!(debug_level & level)) && (level != 0)) return; if (hextodump == NULL) return; /* Initialize constant fields */ memset(buf, ' ', sizeof(buf)); buf[4] = '|'; buf[54] = '|'; buf[72] = '\n'; buf[73] = 0; count = 0; total = 0; for (i = 0; i < size; i++) { if (count == 0) { str_idx = 6; chr_idx = 56; buf[0] = to_hex_char(total >> 8); buf[1] = to_hex_char(total >> 4); buf[2] = to_hex_char(total); } /* store the number */ tmp = hextodump[i]; buf[str_idx++] = to_hex_char(tmp >> 4); buf[str_idx++] = to_hex_char(tmp); str_idx++; /* store the character */ buf[chr_idx++] = isprint(tmp) ? tmp : '.'; total++; count++; if (count >= 16) { count = 0; ufprintf(logfile, buf, level); } }
void palette_save_on_file(const uTCHAR *file) { FILE *fp; if ((fp = ufopen(file, uL("wb"))) == NULL) { ufprintf(stderr, uL("ERROR: Impossible save palette file " uPERCENTs "\n"), file); return; } if (!(fwrite((BYTE *) palette_RGB, 64 * 3, 1, fp))) { ; } fclose(fp); }
/** * * Dump hex values, without the ascii versions. * */ void debug_hex_printf(uint32_t level, uint8_t *hextodump, int size) { int i; int len = 0; char *logstr = NULL; logstr = (char *)calloc(1, (size * 3) + 2); if (logstr == NULL) { printf("Couldn't allocate memory to store temporary logging string!\n"); return; } memset(logstr, 0x00, ((size * 3)+2)); if ((!(debug_level & level)) && (level != 0)) { free(logstr); return; } if (hextodump == NULL) { free(logstr); return; } for (i = 0; i < size; i++) { logstr[len++] = to_hex_char(hextodump[i] >> 4); logstr[len++] = to_hex_char(hextodump[i]); logstr[len++] = ' '; } logstr[len++] = '\n'; logstr[len] = 0; ufprintf(logfile, logstr, level); free(logstr); }