if(!hasCopiedStub)
{
memcpy((void *)ARM11_STUB_ADDRESS, arm11Stub, 0x30);
- ctr_cache_clean_and_flush_all();
+ ctr_cache_clean_and_flush_all();
hasCopiedStub = true;
}
}
WAIT_FOR_ARM9();
}
- ctr_cache_clean_and_flush_all();
+ ctr_cache_clean_and_flush_all();
invokeArm11Function(ARM11);
}
WAIT_FOR_ARM9();
}
- ctr_cache_clean_and_flush_all();
+ ctr_cache_clean_and_flush_all();
invokeArm11Function(ARM11);
}
bright = brightness[config->options[OPTION_BRIGHTNESS]];
- stride = 240 * 3;
- if (mode == RGBA8)
- stride = 240 * 4;
+ stride = 240 * 3;
+ if (mode == RGBA8)
+ stride = 240 * 4;
init_top = MAKE_FRAMEBUFFER_PIXFMT(mode, 0, 1);
init_bottom = MAKE_FRAMEBUFFER_PIXFMT(mode, 0, 0);
if (!framebuffers) {
// Look ma, dynamically allocating the CakeHax struct! (joking)
- // We literally just discard the previous state - for sanity's sake.
+ // We literally just discard the previous state - for sanity's sake.
// On chainload, it is needed to copy the framebuffer struct.
framebuffers = malloc(sizeof(struct framebuffers));
}
//Disable interrupts
__asm(".word 0xF10C01C0");
- PDN_GPU_CNT = 0x1007F; //bit0: Enable GPU regs 0x10400000+, bit16 turn on LCD backlight?
- LCD_REG(0x14) = 0x00000001; //UNKNOWN register, maybe LCD related? 0x10202000
- LCD_REG(0xC) &= 0xFFFEFFFE; //UNKNOWN register, maybe LCD related?
-
- LCD_TOP_CONF_BRIGHTNESS = bright;
- LCD_BOT_CONF_BRIGHTNESS = bright;
- LCD_TOP_CONF_REG(0x44) = 0x1023E; //unknown
- LCD_BOT_CONF_REG(0x44) = 0x1023E; //unknown
-
- // Top screen
- PDC0_FRAMEBUFFER_SETUP_REG(0x00) = 0x000001c2; //unknown
- PDC0_FRAMEBUFFER_SETUP_REG(0x04) = 0x000000d1; //unknown
- PDC0_FRAMEBUFFER_SETUP_REG(0x08) = 0x000001c1;
- PDC0_FRAMEBUFFER_SETUP_REG(0x0c) = 0x000001c1;
- PDC0_FRAMEBUFFER_SETUP_REG(0x10) = 0x00000000;
- PDC0_FRAMEBUFFER_SETUP_REG(0x14) = 0x000000cf;
- PDC0_FRAMEBUFFER_SETUP_REG(0x18) = 0x000000d1;
- PDC0_FRAMEBUFFER_SETUP_REG(0x1c) = 0x01c501c1;
- PDC0_FRAMEBUFFER_SETUP_REG(0x20) = 0x00010000;
- PDC0_FRAMEBUFFER_SETUP_REG(0x24) = 0x0000019d;
- PDC0_FRAMEBUFFER_SETUP_REG(0x28) = 0x00000002;
- PDC0_FRAMEBUFFER_SETUP_REG(0x2c) = 0x00000192;
- PDC0_FRAMEBUFFER_SETUP_REG(0x30) = 0x00000192;
- PDC0_FRAMEBUFFER_SETUP_REG(0x34) = 0x00000192;
- PDC0_FRAMEBUFFER_SETUP_REG(0x38) = 0x00000001;
- PDC0_FRAMEBUFFER_SETUP_REG(0x3c) = 0x00000002;
- PDC0_FRAMEBUFFER_SETUP_REG(0x40) = 0x01960192;
- PDC0_FRAMEBUFFER_SETUP_REG(0x44) = 0x00000000;
- PDC0_FRAMEBUFFER_SETUP_REG(0x48) = 0x00000000;
- PDC0_FRAMEBUFFER_SETUP_DIMS = (240u << 16) | (400u);
- PDC0_FRAMEBUFFER_SETUP_REG(0x60) = 0x01c100d1;
- PDC0_FRAMEBUFFER_SETUP_REG(0x64) = 0x01920002;
- PDC0_FRAMEBUFFER_SETUP_FBA_ADDR_1 = 0x18300000;
- PDC0_FRAMEBUFFER_SETUP_FB_FORMAT = init_top;
- PDC0_FRAMEBUFFER_SETUP_REG(0x74) = 0x00010501;
- PDC0_FRAMEBUFFER_SETUP_FB_SELECT = 0;
- PDC0_FRAMEBUFFER_SETUP_FB_STRIDE = stride;
- PDC0_FRAMEBUFFER_SETUP_REG(0x9C) = 0x00000000;
-
- // Disco register
- for(volatile uint32_t i = 0; i < 256; i++)
- PDC0_FRAMEBUFFER_SETUP_DISCO = 0x10101 * i;
-
- // Bottom screen
- PDC1_FRAMEBUFFER_SETUP_REG(0x00) = 0x000001c2;
- PDC1_FRAMEBUFFER_SETUP_REG(0x04) = 0x000000d1;
- PDC1_FRAMEBUFFER_SETUP_REG(0x08) = 0x000001c1;
- PDC1_FRAMEBUFFER_SETUP_REG(0x0c) = 0x000001c1;
- PDC1_FRAMEBUFFER_SETUP_REG(0x10) = 0x000000cd;
- PDC1_FRAMEBUFFER_SETUP_REG(0x14) = 0x000000cf;
- PDC1_FRAMEBUFFER_SETUP_REG(0x18) = 0x000000d1;
- PDC1_FRAMEBUFFER_SETUP_REG(0x1c) = 0x01c501c1;
- PDC1_FRAMEBUFFER_SETUP_REG(0x20) = 0x00010000;
- PDC1_FRAMEBUFFER_SETUP_REG(0x24) = 0x0000019d;
- PDC1_FRAMEBUFFER_SETUP_REG(0x28) = 0x00000052;
- PDC1_FRAMEBUFFER_SETUP_REG(0x2c) = 0x00000192;
- PDC1_FRAMEBUFFER_SETUP_REG(0x30) = 0x00000192;
- PDC1_FRAMEBUFFER_SETUP_REG(0x34) = 0x0000004f;
- PDC1_FRAMEBUFFER_SETUP_REG(0x38) = 0x00000050;
- PDC1_FRAMEBUFFER_SETUP_REG(0x3c) = 0x00000052;
- PDC1_FRAMEBUFFER_SETUP_REG(0x40) = 0x01980194;
- PDC1_FRAMEBUFFER_SETUP_REG(0x44) = 0x00000000;
- PDC1_FRAMEBUFFER_SETUP_REG(0x48) = 0x00000011;
- PDC1_FRAMEBUFFER_SETUP_DIMS = (240u << 16) | 320u;
- PDC1_FRAMEBUFFER_SETUP_REG(0x60) = 0x01c100d1;
- PDC1_FRAMEBUFFER_SETUP_REG(0x64) = 0x01920052;
- PDC1_FRAMEBUFFER_SETUP_FBA_ADDR_1 = 0x1835dc00;
- PDC1_FRAMEBUFFER_SETUP_FB_FORMAT = init_bottom;
- PDC1_FRAMEBUFFER_SETUP_REG(0x74) = 0x00010501;
- PDC1_FRAMEBUFFER_SETUP_FB_SELECT = 0;
- PDC1_FRAMEBUFFER_SETUP_FB_STRIDE = stride;
- PDC1_FRAMEBUFFER_SETUP_REG(0x9C) = 0x00000000;
-
- // Disco register
- for(volatile uint32_t i = 0; i < 256; i++)
- PDC1_FRAMEBUFFER_SETUP_DISCO = 0x10101 * i;
-
- PDC0_FRAMEBUFFER_SETUP_FBA_ADDR_1 = 0x18300000;
- PDC0_FRAMEBUFFER_SETUP_FBA_ADDR_2 = 0x18300000;
- PDC0_FRAMEBUFFER_SETUP_FBB_ADDR_1 = 0x18300000;
- PDC0_FRAMEBUFFER_SETUP_FBB_ADDR_2 = 0x18300000;
-
- PDC1_FRAMEBUFFER_SETUP_FBA_ADDR_1 = 0x1835dc00;
- PDC1_FRAMEBUFFER_SETUP_FBA_ADDR_2 = 0x1835dc00;
+ PDN_GPU_CNT = 0x1007F; //bit0: Enable GPU regs 0x10400000+, bit16 turn on LCD backlight?
+ LCD_REG(0x14) = 0x00000001; //UNKNOWN register, maybe LCD related? 0x10202000
+ LCD_REG(0xC) &= 0xFFFEFFFE; //UNKNOWN register, maybe LCD related?
+
+ LCD_TOP_CONF_BRIGHTNESS = bright;
+ LCD_BOT_CONF_BRIGHTNESS = bright;
+ LCD_TOP_CONF_REG(0x44) = 0x1023E; //unknown
+ LCD_BOT_CONF_REG(0x44) = 0x1023E; //unknown
+
+ // Top screen
+ PDC0_FRAMEBUFFER_SETUP_REG(0x00) = 0x000001c2; //unknown
+ PDC0_FRAMEBUFFER_SETUP_REG(0x04) = 0x000000d1; //unknown
+ PDC0_FRAMEBUFFER_SETUP_REG(0x08) = 0x000001c1;
+ PDC0_FRAMEBUFFER_SETUP_REG(0x0c) = 0x000001c1;
+ PDC0_FRAMEBUFFER_SETUP_REG(0x10) = 0x00000000;
+ PDC0_FRAMEBUFFER_SETUP_REG(0x14) = 0x000000cf;
+ PDC0_FRAMEBUFFER_SETUP_REG(0x18) = 0x000000d1;
+ PDC0_FRAMEBUFFER_SETUP_REG(0x1c) = 0x01c501c1;
+ PDC0_FRAMEBUFFER_SETUP_REG(0x20) = 0x00010000;
+ PDC0_FRAMEBUFFER_SETUP_REG(0x24) = 0x0000019d;
+ PDC0_FRAMEBUFFER_SETUP_REG(0x28) = 0x00000002;
+ PDC0_FRAMEBUFFER_SETUP_REG(0x2c) = 0x00000192;
+ PDC0_FRAMEBUFFER_SETUP_REG(0x30) = 0x00000192;
+ PDC0_FRAMEBUFFER_SETUP_REG(0x34) = 0x00000192;
+ PDC0_FRAMEBUFFER_SETUP_REG(0x38) = 0x00000001;
+ PDC0_FRAMEBUFFER_SETUP_REG(0x3c) = 0x00000002;
+ PDC0_FRAMEBUFFER_SETUP_REG(0x40) = 0x01960192;
+ PDC0_FRAMEBUFFER_SETUP_REG(0x44) = 0x00000000;
+ PDC0_FRAMEBUFFER_SETUP_REG(0x48) = 0x00000000;
+ PDC0_FRAMEBUFFER_SETUP_DIMS = (240u << 16) | (400u);
+ PDC0_FRAMEBUFFER_SETUP_REG(0x60) = 0x01c100d1;
+ PDC0_FRAMEBUFFER_SETUP_REG(0x64) = 0x01920002;
+ PDC0_FRAMEBUFFER_SETUP_FBA_ADDR_1 = 0x18300000;
+ PDC0_FRAMEBUFFER_SETUP_FB_FORMAT = init_top;
+ PDC0_FRAMEBUFFER_SETUP_REG(0x74) = 0x00010501;
+ PDC0_FRAMEBUFFER_SETUP_FB_SELECT = 0;
+ PDC0_FRAMEBUFFER_SETUP_FB_STRIDE = stride;
+ PDC0_FRAMEBUFFER_SETUP_REG(0x9C) = 0x00000000;
+
+ // Disco register
+ for(volatile uint32_t i = 0; i < 256; i++)
+ PDC0_FRAMEBUFFER_SETUP_DISCO = 0x10101 * i;
+
+ // Bottom screen
+ PDC1_FRAMEBUFFER_SETUP_REG(0x00) = 0x000001c2;
+ PDC1_FRAMEBUFFER_SETUP_REG(0x04) = 0x000000d1;
+ PDC1_FRAMEBUFFER_SETUP_REG(0x08) = 0x000001c1;
+ PDC1_FRAMEBUFFER_SETUP_REG(0x0c) = 0x000001c1;
+ PDC1_FRAMEBUFFER_SETUP_REG(0x10) = 0x000000cd;
+ PDC1_FRAMEBUFFER_SETUP_REG(0x14) = 0x000000cf;
+ PDC1_FRAMEBUFFER_SETUP_REG(0x18) = 0x000000d1;
+ PDC1_FRAMEBUFFER_SETUP_REG(0x1c) = 0x01c501c1;
+ PDC1_FRAMEBUFFER_SETUP_REG(0x20) = 0x00010000;
+ PDC1_FRAMEBUFFER_SETUP_REG(0x24) = 0x0000019d;
+ PDC1_FRAMEBUFFER_SETUP_REG(0x28) = 0x00000052;
+ PDC1_FRAMEBUFFER_SETUP_REG(0x2c) = 0x00000192;
+ PDC1_FRAMEBUFFER_SETUP_REG(0x30) = 0x00000192;
+ PDC1_FRAMEBUFFER_SETUP_REG(0x34) = 0x0000004f;
+ PDC1_FRAMEBUFFER_SETUP_REG(0x38) = 0x00000050;
+ PDC1_FRAMEBUFFER_SETUP_REG(0x3c) = 0x00000052;
+ PDC1_FRAMEBUFFER_SETUP_REG(0x40) = 0x01980194;
+ PDC1_FRAMEBUFFER_SETUP_REG(0x44) = 0x00000000;
+ PDC1_FRAMEBUFFER_SETUP_REG(0x48) = 0x00000011;
+ PDC1_FRAMEBUFFER_SETUP_DIMS = (240u << 16) | 320u;
+ PDC1_FRAMEBUFFER_SETUP_REG(0x60) = 0x01c100d1;
+ PDC1_FRAMEBUFFER_SETUP_REG(0x64) = 0x01920052;
+ PDC1_FRAMEBUFFER_SETUP_FBA_ADDR_1 = 0x1835dc00;
+ PDC1_FRAMEBUFFER_SETUP_FB_FORMAT = init_bottom;
+ PDC1_FRAMEBUFFER_SETUP_REG(0x74) = 0x00010501;
+ PDC1_FRAMEBUFFER_SETUP_FB_SELECT = 0;
+ PDC1_FRAMEBUFFER_SETUP_FB_STRIDE = stride;
+ PDC1_FRAMEBUFFER_SETUP_REG(0x9C) = 0x00000000;
+
+ // Disco register
+ for(volatile uint32_t i = 0; i < 256; i++)
+ PDC1_FRAMEBUFFER_SETUP_DISCO = 0x10101 * i;
+
+ PDC0_FRAMEBUFFER_SETUP_FBA_ADDR_1 = 0x18300000;
+ PDC0_FRAMEBUFFER_SETUP_FBA_ADDR_2 = 0x18300000;
+ PDC0_FRAMEBUFFER_SETUP_FBB_ADDR_1 = 0x18300000;
+ PDC0_FRAMEBUFFER_SETUP_FBB_ADDR_2 = 0x18300000;
+
+ PDC1_FRAMEBUFFER_SETUP_FBA_ADDR_1 = 0x1835dc00;
+ PDC1_FRAMEBUFFER_SETUP_FBA_ADDR_2 = 0x1835dc00;
// Set not-actually cakebrah framebuffers. Meh.
framebuffers->top_left = (uint8_t *)0x18300000;
WAIT_FOR_ARM9();
}
- ctr_cache_clean_and_flush_all();
+ ctr_cache_clean_and_flush_all();
invokeArm11Function(ARM11);
clearScreens();
// Copy CakeHax struct where it is expected (at 0x23FFFE00)
// It's very very likely we'll corrupt memory with this, but we aren't coming back anyways as of the
// next call, so not my problem
- memcpy((void*)0x23FFFE00, framebuffers, sizeof(struct framebuffers));
+ memcpy((void*)0x23FFFE00, framebuffers, sizeof(struct framebuffers));
((void(*)(void*, uint32_t))0x24F00000)(chain_data, size + 256 + 8); // Size of payload + argv.
}
void chainload_menu() {
- if (chains == NULL) {
- chains = malloc(sizeof(struct options_s) * 100);
- list_chain_build(PATH_CHAINS);
- }
+ if (chains == NULL) {
+ chains = malloc(sizeof(struct options_s) * 100);
+ list_chain_build(PATH_CHAINS);
+ }
show_menu(chains, NULL);
}
f_unlink(config_file_path);
if (!(conf_handle = fopen(config_file_path, "w")))
- while(1);
+ while(1);
fwrite(config, 1, sizeof(struct config_file) + FCRAM_SPACING / 2, conf_handle);
void
sha256sum(void* sum, void* data, uint32_t size)
{
- sha_init(SHA256_MODE);
+ sha_init(SHA256_MODE);
sha_update(data, size);
sha_get(sum);
}
use_aeskey(0x06);
set_ctr(ctr);
- ctr_decrypt(firm, firm, firm_b_size / AES_BLOCK_SIZE, AES_CNT_CTRNAND_MODE, ctr);
+ ctr_decrypt(firm, firm, firm_b_size / AES_BLOCK_SIZE, AES_CNT_CTRNAND_MODE, ctr);
if (memcmp((char*) & firm->magic, "FIRM", 4))
abort(" Decryption failed on FIRM.\n");
int
decrypt_cetk_key(void *key, const void *cetk)
{
- static int got_cetk = 0;
- uint8_t iv[AES_BLOCK_SIZE] = { 0 };
- uint32_t sigtype = __builtin_bswap32(*(const uint32_t *)cetk);
+ static int got_cetk = 0;
+ uint8_t iv[AES_BLOCK_SIZE] = { 0 };
+ uint32_t sigtype = __builtin_bswap32(*(const uint32_t *)cetk);
- if (sigtype != SIG_TYPE_RSA2048_SHA256)
- return 1;
+ if (sigtype != SIG_TYPE_RSA2048_SHA256)
+ return 1;
- const ticket_h *ticket = (const ticket_h *)((const uint8_t*)cetk + sizeof(sigtype) + 0x13C);
- if (ticket->ticketCommonKeyYIndex != 1)
- return 1;
+ const ticket_h *ticket = (const ticket_h *)((const uint8_t*)cetk + sizeof(sigtype) + 0x13C);
+ if (ticket->ticketCommonKeyYIndex != 1)
+ return 1;
- if (got_cetk == 0) {
- fprintf(stderr, " Retrieving 0x3D KeyY...\n");
- extract_slot0x3DkeyY();
- got_cetk = 1;
- }
+ if (got_cetk == 0) {
+ fprintf(stderr, " Retrieving 0x3D KeyY...\n");
+ extract_slot0x3DkeyY();
+ got_cetk = 1;
+ }
- use_aeskey(0x3D);
+ use_aeskey(0x3D);
- memcpy(iv, ticket->titleID, sizeof(ticket->titleID));
- memcpy(key, ticket->titleKey, sizeof(ticket->titleKey));
+ memcpy(iv, ticket->titleID, sizeof(ticket->titleID));
+ memcpy(key, ticket->titleKey, sizeof(ticket->titleKey));
- cbc_decrypt(key, key, 1, AES_CNT_TITLEKEY_DECRYPT_MODE, iv);
+ cbc_decrypt(key, key, 1, AES_CNT_TITLEKEY_DECRYPT_MODE, iv);
- fprintf(stderr, " Extracted titlekey from cetk.\n");
+ fprintf(stderr, " Extracted titlekey from cetk.\n");
- return 0;
+ return 0;
}
int
fprintf(stderr, "FIRM load triggered.\n");
- firm_loc = malloc(firm_size);
+ firm_loc = malloc(firm_size);
fprintf(stderr, "Loading NATIVE_FIRM\n");
if (load_firm(firm_loc, PATH_NATIVE_F, PATH_NATIVE_FIRMKEY, PATH_NATIVE_CETK, &firm_size, NATIVE_FIRM_TITLEID) != 0) {
find_proc9(firm_loc, &firm_proc9, &firm_p9_exefs);
fprintf(stderr, " Ver: %x, %u\n", get_firm_info(firm_loc)->version, get_firm_info(firm_loc)->console );
- twl_firm_loc = malloc(twl_firm_size);
+ twl_firm_loc = malloc(twl_firm_size);
fprintf(stderr, "TWL_FIRM\n");
if (load_firm(twl_firm_loc, PATH_TWL_F, PATH_TWL_FIRMKEY, PATH_TWL_CETK, &twl_firm_size, TWL_FIRM_TITLEID) != 0) {
fprintf(stderr, " Ver: %x, %u\n", get_firm_info(twl_firm_loc)->version, get_firm_info(twl_firm_loc)->console );
}
- agb_firm_loc = malloc(agb_firm_size);
+ agb_firm_loc = malloc(agb_firm_size);
fprintf(stderr, "AGB_FIRM\n");
if (load_firm(agb_firm_loc, PATH_AGB_F, PATH_AGB_FIRMKEY, PATH_AGB_CETK, &agb_firm_size, AGB_FIRM_TITLEID) != 0) {
uint32_t len = fsize(f);
- uint8_t* patch_loc = malloc(len);
+ uint8_t* patch_loc = malloc(len);
fread(patch_loc, 1, len, f);
fclose(f);
#include <ctr9/ctr_irq.h>
void dump_state_printf(uint32_t* regs) {
- fprintf(stderr, " cpsr:%x sp:%x lr:%x\n"
+ fprintf(stderr, " cpsr:%x sp:%x lr:%x\n"
" r0:%x r1:%x r2:%x r3:%x\n"
" r4:%x r5:%x r6:%x r7:%x\n"
" r8:%x r9:%x r10:%x r11:%x\n"
}
void reset_INT(_UNUSED uint32_t* regs) {
- fprintf(stderr, "Reset called.\n");
+ fprintf(stderr, "Reset called.\n");
}
void undef_INT(uint32_t* regs) {
- fprintf(stderr, "Undefined instruction.\n");
- dump_state_printf(regs);
- abort("Cannot continue. Halting.\n");
+ fprintf(stderr, "Undefined instruction.\n");
+ dump_state_printf(regs);
+ abort("Cannot continue. Halting.\n");
}
void swi_INT(_UNUSED uint32_t* regs) {
- fprintf(stderr, "SWI called. Returning.\n");
+ fprintf(stderr, "SWI called. Returning.\n");
}
void preabrt_INT(uint32_t* regs) {
- fprintf(stderr, "Prefetch Abort.\n");
- dump_state_printf(regs);
- abort("Cannot continue. Halting.\n");
+ fprintf(stderr, "Prefetch Abort.\n");
+ dump_state_printf(regs);
+ abort("Cannot continue. Halting.\n");
}
void databrt_INT(uint32_t* regs) {
- fprintf(stderr, "Data abort.\n");
- dump_state_printf(regs);
- abort("Cannot continue. Halting.\n");
+ fprintf(stderr, "Data abort.\n");
+ dump_state_printf(regs);
+ abort("Cannot continue. Halting.\n");
}
void fiq_INT(_UNUSED uint32_t* regs) {
- fprintf(stderr, "FIQ called. Returning.\n");
+ fprintf(stderr, "FIQ called. Returning.\n");
}
void install_interrupts() {
- ctr_interrupt_prepare();
+ ctr_interrupt_prepare();
ctr_irq_initialize();
ctr_interrupt_set(CTR_INTERRUPT_RESET, reset_INT);
};
void config_main_menu() {
- show_menu(config_opts, NULL);
+ show_menu(config_opts, NULL);
save_config(); // Save config when exiting.
{
uint32_t nandSize = getMMCDevice(0)->total_size;
- uint8_t *emunand_temp = (uint8_t*)malloc(2048);
+ uint8_t *emunand_temp = (uint8_t*)malloc(2048);
uint32_t offset;
if (nandSize > 0x200000)
}
void free(void* ptr) {
- if (ptr == NULL) return;
+ if (ptr == NULL) return;
free_block* block = (free_block*)(((char*)ptr) - sizeof(free_block ));
block->next = free_block_list_head.next;
static uint8_t alphamap[256] = {0};
void std_init() {
- for(uint16_t i=0; i < 0x100; i++) {
- alphamap[i] = 0;
- if (i > 0x7F)
- alphamap[i] = i - 0x7F;
- }
+ for(uint16_t i=0; i < 0x100; i++) {
+ alphamap[i] = 0;
+ if (i > 0x7F)
+ alphamap[i] = i - 0x7F;
+ }
top_bg = malloc(TOP_SIZE);
bottom_bg = malloc(BOTTOM_SIZE);
unsigned int c_font_w = (new_w / 8) + (new_w % 8 ? 1 : 0);
- font_data = malloc(c_font_w * new_h * (256 - ' '));
+ font_data = malloc(c_font_w * new_h * (256 - ' '));
fread(font_data, 1, c_font_w * new_h * (256 - ' '), f); // Skip non-printing chars.
int
ansi_statemach(void* buf, const int c)
{
- int* state = NULL, *val = NULL;
+ int* state = NULL, *val = NULL;
uint8_t *color = NULL;
uint8_t color_tmp = 0;
if (buf == stdout) {
color = &color_top;
- state = &stdout_state;
- val = &stdout_val;
+ state = &stdout_state;
+ val = &stdout_val;
} else if (buf == stderr) {
color = &color_bottom;
- state = &stderr_state;
- val = &stderr_val;
+ state = &stderr_state;
+ val = &stderr_val;
} else {
return 0;
}
- switch(*state) {
- case TEXT:
- if (c == '\x1b') {
- *state = ANSI_NEXT;
- return 1;
- }
- return 0;
- case ANSI_NEXT:
- if (c == '[') {
- *state = ANSI_PARSE;
- *val = 0;
- return 1;
- }
- // INVALID; this is a bad ansi sequence. Term early.
- *state = TEXT;
- return 0;
- case ANSI_END:
- if (c == ';') {
- *state = ANSI_PARSE; // Another code coming up.
- } else if(c >= 0x40 && c <= 0x7E) {
- *state = TEXT;
- }
-
- return 1;
- case ANSI_PARSE:
- if (c >= '0' && c <= '9') {
- *val *= 10;
- *val += (c - '0');
-
- *state = ANSI_PARSE;
-
- if (*val == 0) {
- // Reset formatting.
- *color = 0xf0;
- *state = ANSI_END;
- }
-
- if (*val >= 10) {
- switch(*val / 10) {
- case 3: // Foreground color
- *color &= 0x0f; // Remove fg color.
- *color |= ((*val % 30) & 0xf) << 4;
+ switch(*state) {
+ case TEXT:
+ if (c == '\x1b') {
+ *state = ANSI_NEXT;
+ return 1;
+ }
+ return 0;
+ case ANSI_NEXT:
+ if (c == '[') {
+ *state = ANSI_PARSE;
+ *val = 0;
+ return 1;
+ }
+ // INVALID; this is a bad ansi sequence. Term early.
+ *state = TEXT;
+ return 0;
+ case ANSI_END:
+ if (c == ';') {
+ *state = ANSI_PARSE; // Another code coming up.
+ } else if(c >= 0x40 && c <= 0x7E) {
+ *state = TEXT;
+ }
+
+ return 1;
+ case ANSI_PARSE:
+ if (c >= '0' && c <= '9') {
+ *val *= 10;
+ *val += (c - '0');
+
+ *state = ANSI_PARSE;
+
+ if (*val == 0) {
+ // Reset formatting.
+ *color = 0xf0;
+ *state = ANSI_END;
+ }
+
+ if (*val >= 10) {
+ switch(*val / 10) {
+ case 3: // Foreground color
+ *color &= 0x0f; // Remove fg color.
+ *color |= ((*val % 30) & 0xf) << 4;
break;
- case 4: // Background color
- *color &= 0xf0; // Remove bg color.
- *color |= ((*val % 40) & 0xf);
+ case 4: // Background color
+ *color &= 0xf0; // Remove bg color.
+ *color |= ((*val % 40) & 0xf);
break;
default: // ???
break;
- }
- *state = ANSI_END;
- }
- }
- return 1;
+ }
+ *state = ANSI_END;
+ }
+ }
+ return 1;
default:
*state = TEXT;
return 1;
- }
+ }
return 0; // Should not be reached.
}
void
putc(void *buf, int c)
{
- if(ansi_statemach(buf, c) == 1) // Inside ANSI escape?
- return;
+ if(ansi_statemach(buf, c) == 1) // Inside ANSI escape?
+ return;
if (buf == stdout || buf == stderr) {
if (kill_output)