diff --git a/src/loadcart.c b/src/loadcart.c index 3efc154..0335b82 100644 --- a/src/loadcart.c +++ b/src/loadcart.c @@ -784,7 +784,7 @@ APPEND static u8* deferred_decompress_rom(u8 *nes_header, u8 *cachebase, int pag u8* compdest = cachebase; u8* mem_end = (u8*)0x02040000; u8* cache_end_of_rom; - + u8 *const VRAM = (u8*)0x06000000; //VRAM macro is defined in Libgba, so we #undef-ed it to use it here u8 *const vrom_bank_0 = VRAM + 0x0A000; //8k size u8 *const vrom_bank_1 = VRAM + 0x0E000; //8k size (24k with vrom_bank_2 folllowing it) @@ -815,7 +815,12 @@ APPEND static u8* deferred_decompress_rom(u8 *nes_header, u8 *cachebase, int pag romsize1 = filesize; romsize2 = 0; } - bool do_vram_copy = false; + int do_vram_copy = 0; + + if (nes_header + 32 + filesize >= mem_end) + { + do_vram_copy = 2; + } //rom_is_compressed=1; ewram_owner_is_sram=0; @@ -834,15 +839,21 @@ APPEND static u8* deferred_decompress_rom(u8 *nes_header, u8 *cachebase, int pag { if (comptype == 2) { - if (romsize2 >= 32768) + //if (filesize >= 180*1024) { - do_vram_copy = true; - u8 *last32k_compressed = compsrc + filesize - 4; - DEFERRED_CALL(memcpy32,VRAM + 0x0000, last32k_compressed - 0x8000, 0x2000); - DEFERRED_CALL(memcpy32,VRAM + 0x4000, last32k_compressed - 0x6000, 0x2000); - DEFERRED_CALL(memcpy32,VRAM + 0x14000, last32k_compressed - 0x4000, 0x4000); + if (romsize2 >= 32768) + { + if (do_vram_copy == 0) + { + do_vram_copy = 1; + u8 *last32k_compressed = compsrc + filesize - 4; + DEFERRED_CALL(memcpy32,VRAM + 0x0000, last32k_compressed - 0x8000, 0x2000); + DEFERRED_CALL(memcpy32,VRAM + 0x4000, last32k_compressed - 0x6000, 0x2000); + DEFERRED_CALL(memcpy32,VRAM + 0x14000, last32k_compressed - 0x4000, 0x4000); + } + } + copysize -= 0x8000; } - copysize -= 0x8000; } compcopy = mem_end - copysize; //compcopy = end_of_cache - filesize; @@ -979,8 +990,8 @@ APPEND static u8* deferred_decompress_rom(u8 *nes_header, u8 *cachebase, int pag DEFERRED_CALL(simpleswap32,VRAM + 0x4000, cachebase + 3 * 16384 + 0x2000, 0x2000); DEFERRED_CALL(simpleswap32,VRAM + 0x14000, cachebase + 3 * 16384 + 0x4000, 0x4000); - int compsrc2_bytepos = (u32)compsrc2 & 3; - u8 *compsrc2_aligned = (u8*)((u32)(compsrc2) & ~0x3); + int compsrc2_bytepos = (u32)compsrc2 & 0xFF; + u8 *compsrc2_aligned = (u8*)((u32)(compsrc2) & ~0xFF); u8 *mem_end = (u8*)0x02040000; u8 *compsrc2_new_aligned = compsrc2_aligned - 0x8000; u8 *compsrc2_new = compsrc2_new_aligned + compsrc2_bytepos; @@ -1062,8 +1073,8 @@ APPEND static u8* deferred_decompress_rom(u8 *nes_header, u8 *cachebase, int pag DEFERRED_CALL(simpleswap32,VRAM + 0x4000, cachebase + 4 * 16384 + 0x2000, 0x2000); DEFERRED_CALL(simpleswap32,VRAM + 0x14000, cachebase + 4 * 16384 + 0x4000, 0x4000); - int compsrc2_bytepos = (u32)compsrc2 & 3; - u8 *compsrc2_aligned = (u8*)((u32)(compsrc2) & ~0x3); + int compsrc2_bytepos = (u32)compsrc2 & 0xFF; + u8 *compsrc2_aligned = (u8*)((u32)(compsrc2) & ~0xFF); u8 *mem_end = (u8*)0x02040000; u8 *compsrc2_new_aligned = compsrc2_aligned - 0x8000; u8 *compsrc2_new = compsrc2_new_aligned + compsrc2_bytepos; @@ -1350,6 +1361,7 @@ static u8* decompress_rom(u8 *nes_header, u8 *cachebase, int page_size, int comp u8 *moveDest = memoryToMove + amountToAdvance; u8 *memoryToCopy = vrom_bank_2; memmove32(moveDest, memoryToMove, 7 * 16384); + memcpy32(memoryToMove, vrom_bank_2, amountToAdvance); cache_end_of_rom = 14 * 16384 + cachebase + 256; //okay because 224K > 192K } @@ -2318,11 +2330,11 @@ APPEND_DATA const unsigned char MapperNumberOverlayList[] = { 4, 64, 74, 118, 119, 206, 245, 249, 100, 18, 19, 69, 210, 100, - 16, 65, 163, 100, + 16, 163, 100, 1, 15, 67, 105, 100, 9, 10, 17, 22, 33, 42, 73, 75, 80, 228, 100, 0, 2, 3, 7, 11, 32, 34, 40, 66, 68, 70, 71, 76, 77, 78, 79, 82, 86, 88, 92, 99, 151, 152, 180, 232, 100, - 21, 23, 24, 25, 26, 72, 85, 87, 93, 94, 97, 184, 100, + 21, 23, 24, 25, 26, 65, 72, 85, 87, 93, 94, 97, 184, 100, 5, 100, 20, }; diff --git a/src/main.c b/src/main.c index 469c25a..290f6dd 100644 --- a/src/main.c +++ b/src/main.c @@ -126,7 +126,9 @@ APPEND void C_entry() *MEM_PALETTE=0; //black background (avoids blue flash when doing multiboot) REG_DISPCNT=0; //screen ON, MODE0 + #if !COMPY memset32((u32*)0x6000000,0,0x18000); //clear vram (fixes graphics junk) + #endif //Warning: VRAM code must be loaded at some point #if !COMPY diff --git a/src/ui.c b/src/ui.c index ced8c1c..fd62231 100644 --- a/src/ui.c +++ b/src/ui.c @@ -970,7 +970,7 @@ void go_multiboot() u8 *emu_src=(u8*)mb_binary; u8 *emu_dest=(u8*)0x02000000; u32 emu_size=(u32)mb_binary_end - (u32)mb_binary; - u32 max_mb_size=0x40000 - emu_size; + u32 max_mb_size=0x40000 - emu_size + 0x8000; int i; int key; @@ -979,11 +979,16 @@ void go_multiboot() romsize += 48; if (pogoshell) romsize = pogoshell_filesize; romsize =((romsize-1)|3)+1; + u32 romsize_truncated = romsize; + if (romsize + emu_size > 0x40000) + { + romsize_truncated = 0x40000 - emu_size; + } if (romsize>max_mb_size) { cls(1); - drawtext(8, "Game is too big to multiboot",0); + drawtext(8, "Game is too big to multiboot.",0); for(i=0;i<90;i++) //wait a while { waitframe(); @@ -1009,12 +1014,22 @@ void go_multiboot() REG_DM1CNT_H=0; REG_DM2CNT_H=0; REG_DM3CNT_H=0; + REG_DISPCNT = 0; memset32((void*)0x06000000, 0, 0x18000); + if (romsize > 32768) + { + u8 *chunk = rom_addr + romsize - 0x8000; + memcpy32((void*)0x06000000, chunk + 0x0000, 0x2000); + memcpy32((void*)0x06004000, chunk + 0x2000, 0x2000); + memcpy32((void*)0x06014000, chunk + 0x4000, 0x4000); + } + memcpy32(emu_dest,emu_src,emu_size); - memcpy32(emu_dest+emu_size,rom_addr,romsize); - u8 *src = emu_dest+emu_size+romsize; + memcpy32(emu_dest+emu_size,rom_addr,romsize_truncated); + u8 *src = emu_dest+emu_size+romsize_truncated; u8 *end = (u8*)0x02040000; memset32(src, 0, end - src); + __asm ( "mov r0,#0xF6" "\n" //Reset all except for VRAM and EWRAM @@ -1051,7 +1066,7 @@ void go_multiboot() if (rom_size>size) { cls(1); - drawtext(8, "Game is too big to multiboot",0); + drawtext(8, "Game is too big to multiboot.",0); drawtext(9," Attempt anyway?",0); drawtext(10," A=YES, B=NO",0); oldkey=~REG_P1; //reset key input