Styling fixes, framebuffer fix

-Fixed a lot of styling problems related to indentation and spacing.
-Fixed a bug where the cakehax framebuffer structure was being
overwritten by the heap.
This commit is contained in:
Gabriel Marcano 2016-06-07 23:15:14 -04:00
parent 4f1fd1a32b
commit a471b28cd5
7 changed files with 71 additions and 55 deletions

View File

@ -46,7 +46,7 @@ CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
ASFLAGS := -g $(ARCH) ASFLAGS := -g $(ARCH)
LDFLAGS = -nostartfiles -g --specs=../stub.specs $(ARCH) -Wl,-Map,$(TARGET).map LDFLAGS = -nostartfiles -g --specs=../stub.specs $(ARCH) -Wl,-Map,$(TARGET).map
OCFLAGS= --set-section-flags .bss=alloc,load,contents OCFLAGS = --set-section-flags .bss=alloc,load,contents
LIBS := LIBS :=
@ -114,11 +114,11 @@ common:
a9lh: common a9lh: common
@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile EXEC_METHOD=A9LH @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile EXEC_METHOD=A9LH
cp $(OUTPUT).bin arm9loaderhax.bin @mv $(OUTPUT).bin uncart_arm9loaderhax.bin
brahma: common brahma: common
@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile EXEC_METHOD=BRAHMA @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile EXEC_METHOD=BRAHMA
cp $(OUTPUT).bin uncart_brahma.bin @mv $(OUTPUT).bin uncart_brahma.bin
release: release:
@rm -fr $(BUILD) $(OUTPUT).bin $(OUTPUT).elf @rm -fr $(BUILD) $(OUTPUT).bin $(OUTPUT).elf
@ -129,7 +129,8 @@ release:
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
clean: clean:
@echo clean ... @echo clean ...
@rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).bin arm9payload.bin uncart_brahma.bin @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).bin uncart_arm9loaderhax.bin \
uncart_brahma.bin
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------

View File

@ -10,8 +10,30 @@
#include "font.h" #include "font.h"
#include "draw.h" #include "draw.h"
u8 *TOP_SCREEN0;
u8 *TOP_SCREEN1;
u8 *BOT_SCREEN0;
u8 *BOT_SCREEN1;
size_t current_y = 0; size_t current_y = 0;
void DrawInit(void)
{
#ifdef BRAHMA
TOP_SCREEN0 = (u8*)(0x20000000);
TOP_SCREEN1 = (u8*)(0x20046500);
BOT_SCREEN0 = (u8*)(0x2008CA00);
BOT_SCREEN1 = (u8*)(0x200C4E00);
#elif A9LH
TOP_SCREEN0 = (u8*)(*(u32*)0x23FFFE00);
TOP_SCREEN1 = (u8*)(*(u32*)0x23FFFE00);
BOT_SCREEN0 = (u8*)(*(u32*)0x23FFFE08);
BOT_SCREEN1 = (u8*)(*(u32*)0x23FFFE08);
#else
#error "BRAHMA or A9LH must be defined!"
#endif
}
void ClearScreen(unsigned char *screen, int color) void ClearScreen(unsigned char *screen, int color)
{ {
int i; int i;

View File

@ -14,22 +14,14 @@
#define RGB(r,g,b) (r<<24|b<<16|g<<8|r) #define RGB(r,g,b) (r<<24|b<<16|g<<8|r)
#ifdef BRAHMA extern u8 *TOP_SCREEN0;
#define TOP_SCREEN0 (u8*)(0x20000000) extern u8 *TOP_SCREEN1;
#define TOP_SCREEN1 (u8*)(0x20046500) extern u8 *BOT_SCREEN0;
#define BOT_SCREEN0 (u8*)(0x2008CA00) extern u8 *BOT_SCREEN1;
#define BOT_SCREEN1 (u8*)(0x200C4E00)
#endif
#ifdef A9LH
#define TOP_SCREEN0 (u8*)(*(u32*)0x23FFFE00)
#define TOP_SCREEN1 (u8*)(*(u32*)0x23FFFE00)
#define BOT_SCREEN0 (u8*)(*(u32*)0x23FFFE08)
#define BOT_SCREEN1 (u8*)(*(u32*)0x23FFFE08)
#endif
extern size_t current_y; extern size_t current_y;
void DrawInit(void);
void ClearScreen(unsigned char *screen, int color); void ClearScreen(unsigned char *screen, int color);
void DrawCharacter(unsigned char *screen, int character, size_t x, size_t y, int color, int bgcolor); void DrawCharacter(unsigned char *screen, int character, size_t x, size_t y, int color, int bgcolor);
void DrawHex(unsigned char *screen, unsigned int hex, size_t x, size_t y, int color, int bgcolor); void DrawHex(unsigned char *screen, unsigned int hex, size_t x, size_t y, int color, int bgcolor);

View File

@ -127,7 +127,6 @@ static void __attribute__((noinline)) sdmmc_send_command(struct mmcdevice *ctx,
u16 data = *dataPtr++; u16 data = *dataPtr++;
data |= *dataPtr++ << 8; data |= *dataPtr++ << 8;
sdmmc_write16(REG_SDFIFO,data); sdmmc_write16(REG_SDFIFO,data);
} }
#endif #endif
size -= 0x200; size -= 0x200;

View File

@ -9,7 +9,7 @@
static int read_count = 0; static int read_count = 0;
static inline void CTR_CmdC5() static void CTR_CmdC5()
{ {
static const u32 c5_cmd[4] = { 0xC5000000, 0x00000000, 0x00000000, 0x00000000 }; static const u32 c5_cmd[4] = { 0xC5000000, 0x00000000, 0x00000000, 0x00000000 };
CTR_SendCommand(c5_cmd, 0, 1, 0x100002C, NULL); CTR_SendCommand(c5_cmd, 0, 1, 0x100002C, NULL);

View File

@ -20,6 +20,7 @@ static FATFS fs;
static FIL file; static FIL file;
static void ClearTop(void) { static void ClearTop(void) {
ClearScreen(TOP_SCREEN0, RGB(255, 255, 255));
ClearScreen(TOP_SCREEN1, RGB(255, 255, 255)); ClearScreen(TOP_SCREEN1, RGB(255, 255, 255));
current_y = 0; current_y = 0;
} }
@ -57,7 +58,7 @@ static int dump_cart_region(u32 start_sector, u32 end_sector, FIL* output_file,
Cart_Dummy(); Cart_Dummy();
Cart_Dummy(); Cart_Dummy();
//If there is less data to read than the current read_size, fix it // If there is less data to read than the current read_size, fix it
if (end_sector - current_sector < read_size) if (end_sector - current_sector < read_size)
{ {
read_size = end_sector - current_sector; read_size = end_sector - current_sector;
@ -86,15 +87,18 @@ static int dump_cart_region(u32 start_sector, u32 end_sector, FIL* output_file,
} }
int main() { int main() {
// Saves the framebuffer information somewhere safe.
DrawInit();
// Arbitrary target buffer // Arbitrary target buffer
// aligning to 32 bits in case other parts of the software assume alignment // aligning to 32 bits in case other parts of the software assume alignment
const u32 target_buf_size = 16u * 1024u * 1024u; // 16MB const u32 target_buf_size = 16u * 1024u * 1024u; // 16MB
u32 * const target = memalign(32, target_buf_size); u32* const target = memalign(4, target_buf_size);
u32 * const ncchHeaderData = memalign(32, sizeof(NCCH_HEADER)); u32* const ncchHeaderData = memalign(4, sizeof(NCCH_HEADER));
NCCH_HEADER * const ncchHeader = (NCCH_HEADER*)ncchHeaderData; NCCH_HEADER* const ncchHeader = (NCCH_HEADER*)ncchHeaderData;
NCSD_HEADER * const ncsdHeader = (NCSD_HEADER*)target; NCSD_HEADER* const ncsdHeader = (NCSD_HEADER*)target;
restart_program: restart_program:
// Setup boring stuff - clear the screen, initialize SD output, etc... // Setup boring stuff - clear the screen, initialize SD output, etc...
@ -115,8 +119,7 @@ restart_program:
Debug("Done reading NCCH header."); Debug("Done reading NCCH header.");
// Check that the NCCH header magic is there // Check that the NCCH header magic is there
if (strncmp((const char*)(ncchHeader->magic), "NCCH", 4)) if (strncmp((const char*)(ncchHeader->magic), "NCCH", 4)) {
{
Debug("NCCH magic not found in header!!!"); Debug("NCCH magic not found in header!!!");
Debug("Press A to continue anyway."); Debug("Press A to continue anyway.");
if (!(InputWait() & BUTTON_A)) if (!(InputWait() & BUTTON_A))
@ -147,8 +150,7 @@ restart_program:
Debug(""); Debug("");
u32 input; u32 input;
do do {
{
Debug("Press A to dump all of ROM, B for only the"); Debug("Press A to dump all of ROM, B for only the");
Debug("trimmed version."); Debug("trimmed version.");
input = InputWait(); input = InputWait();
@ -158,23 +160,23 @@ restart_program:
const u32 mediaUnit = 0x200 * (1u << ncsdHeader->partition_flags[MEDIA_UNIT_SIZE]); //Correctly set the media unit size const u32 mediaUnit = 0x200 * (1u << ncsdHeader->partition_flags[MEDIA_UNIT_SIZE]); //Correctly set the media unit size
//Calculate the actual size by counting the adding the size of each partition, plus the initial offset
//size is in media units
u32 cartSize; u32 cartSize;
// Maximum number of blocks in a single file // Maximum number of blocks in a single file
u32 file_max_blocks; u32 file_max_blocks;
if (input & BUTTON_B) if (input & BUTTON_B) {
{ // Calculate the actual size by counting the adding the size of each
// partition, plus the initial offset size is in media units
// The 3DS carts have up to 8 partitions in their carts
cartSize = ncsdHeader->offsetsize_table[0].offset; cartSize = ncsdHeader->offsetsize_table[0].offset;
for(int i = 0; i < 8; i++){ for(size_t i = 0; i < 8; i++) {
cartSize += ncsdHeader->offsetsize_table[i].size; cartSize += ncsdHeader->offsetsize_table[i].size;
} }
Debug("Cart data size: %llu MB", (u64)cartSize * (u64)mediaUnit / 1024ull / 1024ull); Debug("Cart data size: %llu MB", (u64)cartSize * (u64)mediaUnit / 1024ull / 1024ull);
// Maximum number of blocks in a single file // Maximum number of blocks in a single file
file_max_blocks = 0xFFFFFFFFu / mediaUnit; // 4GiB - 513 file_max_blocks = 0xFFFFFFFFu / mediaUnit + mediaUnit; // 4GiB - 512
} }
else else
{ {