From 97447fe2d339f42ba306ccbd6300a21df883c6e3 Mon Sep 17 00:00:00 2001 From: unresolvedsymbol <48220091+unresolvedsymbol@users.noreply.github.com> Date: Mon, 19 Oct 2020 17:33:03 -0500 Subject: [PATCH] rom3M + brightness control --- arm7/source/main.cpp | 27 ++++++++++++++++++++ arm9/Makefile | 8 +++--- arm9/data/IconBright.nbfc | Bin 0 -> 128 bytes arm9/source/gui/InGameMenu.vram.cpp | 21 +++++++++++---- arm9/source/save/Save.vram.cpp | 12 ++++----- common/common_defs.s | 38 +++------------------------- 6 files changed, 57 insertions(+), 49 deletions(-) create mode 100644 arm9/data/IconBright.nbfc diff --git a/arm7/source/main.cpp b/arm7/source/main.cpp index 49b2a9a..6143081 100644 --- a/arm7/source/main.cpp +++ b/arm7/source/main.cpp @@ -1,4 +1,5 @@ #include +#include #include #include "timer.h" #include "sound.h" @@ -32,6 +33,20 @@ extern "C" void irq_vblank() extern "C" void my_irq_handler(); +int writePowerManagement(int reg, int cmd) +{ + int oldIME = enterCriticalSection(); + while (REG_SPICNT & SPI_BUSY); + REG_SPICNT = SPI_ENABLE | SPI_BAUD_1MHz | SPI_BYTE_MODE | SPI_CONTINUOUS | SPI_DEVICE_POWER; + REG_SPIDATA = reg; + while (REG_SPICNT & SPI_BUSY); + REG_SPICNT = SPI_ENABLE | SPI_BAUD_1MHz | SPI_BYTE_MODE | SPI_DEVICE_POWER; + REG_SPIDATA = cmd; + while (REG_SPICNT & SPI_BUSY); + leaveCriticalSection(oldIME); + return REG_SPIDATA & 0xFF; +} + int main() { //dmaFillWords(0, (void*)0x04000400, 0x100); @@ -282,6 +297,18 @@ int main() //case 0xC5://fifo_stop_sound_command //REG_SOUND[0].CNT = SOUND_CHANNEL_0_SETTINGS; // break; + case 0x0400010F: + { + u8 pm = writePowerManagement(4 | PM_READ_REGISTER, 0); + if (!(pm & (1 << 6))) + break; + u8 lvl = (pm & 3); + lvl++; + pm &= ~3; + pm |= lvl & 3; + writePowerManagement(4, pm); + break; + } } } return 0; diff --git a/arm9/Makefile b/arm9/Makefile index f47e039..8b4f6a0 100644 --- a/arm9/Makefile +++ b/arm9/Makefile @@ -168,28 +168,28 @@ $(ARM9ELF) : $(OFILES) #--------------------------------------------------------------------------------- @echo $(notdir $<) @$(bin2o) - arm-none-eabi-objcopy.exe --rename-section .rodata=.vram $(@) + $(OBJCOPY) --rename-section .rodata=.vram $(@) #--------------------------------------------------------------------------------- %.nbfc.o : %.nbfc #--------------------------------------------------------------------------------- @echo $(notdir $<) @$(bin2o) - arm-none-eabi-objcopy.exe --rename-section .rodata=.vram $(@) + $(OBJCOPY) --rename-section .rodata=.vram $(@) #--------------------------------------------------------------------------------- %.nbfs.o : %.nbfs #--------------------------------------------------------------------------------- @echo $(notdir $<) @$(bin2o) - arm-none-eabi-objcopy.exe --rename-section .rodata=.vram $(@) + $(OBJCOPY) --rename-section .rodata=.vram $(@) #--------------------------------------------------------------------------------- %.nbfp.o : %.nbfp #--------------------------------------------------------------------------------- @echo $(notdir $<) @$(bin2o) - arm-none-eabi-objcopy.exe --rename-section .rodata=.vram $(@) + $(OBJCOPY) --rename-section .rodata=.vram $(@) -include $(DEPSDIR)/*.d diff --git a/arm9/data/IconBright.nbfc b/arm9/data/IconBright.nbfc new file mode 100644 index 0000000000000000000000000000000000000000..65688bd3465200d358541023425c50890b45b994 GIT binary patch literal 128 zcmX|(feFAc48wFlL;wF~C**^EPGetUIManager().GetSubObjManager().Alloc(IconRestart_nbfc_size); for (int i = 0; i < IconRestart_nbfc_size / 2; i++) SPRITE_GFX_SUB[(sIconObjAddrs[1] >> 1) + i] = ((u16*)IconRestart_nbfc)[i]; + + sIconObjAddrs[2] = _uiContext->GetUIManager().GetSubObjManager().Alloc(IconBright_nbfc_size); + for (int i = 0; i < IconBright_nbfc_size / 2; i++) + SPRITE_GFX_SUB[(sIconObjAddrs[2] >> 1) + i] = ((u16*)IconBright_nbfc)[i]; - sIconObjAddrs[2] = _uiContext->GetUIManager().GetSubObjManager().Alloc(IconPower_nbfc_size); + sIconObjAddrs[3] = _uiContext->GetUIManager().GetSubObjManager().Alloc(IconPower_nbfc_size); for (int i = 0; i < IconPower_nbfc_size / 2; i++) - SPRITE_GFX_SUB[(sIconObjAddrs[2] >> 1) + i] = ((u16*)IconPower_nbfc)[i]; + SPRITE_GFX_SUB[(sIconObjAddrs[3] >> 1) + i] = ((u16*)IconPower_nbfc)[i]; _vramState = _uiContext->GetUIManager().GetSubObjManager().GetState(); @@ -289,11 +295,16 @@ int InGameMenu::Run() next = 2; else if(_selectedEntry == 1) next = 3; - else if(_selectedEntry == 2) + else if (_selectedEntry == 2) + next = 4; + else if(_selectedEntry == 3) next = 0; while(!(*((vu16*)0x04000130) & 1)); - break; + if (next != 4) + break; + else + REG_SEND_FIFO = 0x0400010F; } else if (_inputRepeater.GetTriggeredKeys() & KEY_B) { @@ -322,4 +333,4 @@ int InGameMenu::Run() _uiContext->GetUIManager().VBlank(); return next; -} \ No newline at end of file +} diff --git a/arm9/source/save/Save.vram.cpp b/arm9/source/save/Save.vram.cpp index c77d7cc..f5f0d82 100644 --- a/arm9/source/save/Save.vram.cpp +++ b/arm9/source/save/Save.vram.cpp @@ -46,19 +46,19 @@ const save_type_t* save_findTag() f_rewind(&vram_cd->fil); UINT read; u32 curAddr = 0; - if (f_read(&vram_cd->fil, vram_cd->cluster_cache, 512 * 1024, &read) != FR_OK) + if (f_read(&vram_cd->fil, vram_cd->cluster_cache, 128 * 1024, &read) != FR_OK) return NULL; int searchBufPtr = 0; while (curAddr < vram_cd->sd_info.gba_rom_size) { if (searchBufPtr == 0) { - if (f_read(&vram_cd->fil, vram_cd->cluster_cache + 512 * 1024, 512 * 1024, &read) != FR_OK) + if (f_read(&vram_cd->fil, vram_cd->cluster_cache + 128 * 1024, 128 * 1024, &read) != FR_OK) return NULL; } - else if (searchBufPtr == 512 * 1024) + else if (searchBufPtr == 128 * 1024) { - if (f_read(&vram_cd->fil, vram_cd->cluster_cache, 512 * 1024, &read) != FR_OK) + if (f_read(&vram_cd->fil, vram_cd->cluster_cache, 128 * 1024, &read) != FR_OK) return NULL; } @@ -89,7 +89,7 @@ const save_type_t* save_findTag() bool found = true; for (int j = 4; j < ((sSaveTypes[i].tagLength + 3) & ~3); j += 4) { - if (*(u32*)&sSaveTypes[i].tag[j] != *(u32*)&vram_cd->cluster_cache[(searchBufPtr + j) & 0xFFFFF]) + if (*(u32*)&sSaveTypes[i].tag[j] != *(u32*)&vram_cd->cluster_cache[(searchBufPtr + j) & 0x3FFFF]) { found = false; break; @@ -102,7 +102,7 @@ const save_type_t* save_findTag() } } } - searchBufPtr = (searchBufPtr + 4) & 0xFFFFF; + searchBufPtr = (searchBufPtr + 4) & 0x3FFFF; curAddr += 4; } return NULL; diff --git a/common/common_defs.s b/common/common_defs.s index 87b0058..ce558d4 100644 --- a/common/common_defs.s +++ b/common/common_defs.s @@ -3,50 +3,20 @@ //#define ARM7_DLDI -//#define USE_DSI_16MB -//#define USE_3DS_32MB - -#if defined(USE_DSI_16MB) -#define UNCACHED_OFFSET (-0x0A000000) -#define MAIN_MEMORY_BASE 0x0C000000 -#define MAIN_MEMORY_END 0x0D000000 -#elif defined(USE_3DS_32MB) -#define UNCACHED_OFFSET (-0x0A000000) -#define MAIN_MEMORY_BASE 0x0C000000 -#define MAIN_MEMORY_END 0x0E000000 -#else #define UNCACHED_OFFSET 0x00800000 #define MAIN_MEMORY_BASE 0x02000000 #define MAIN_MEMORY_END 0x02400000 -#endif -#define SD_CACHE_SIZE (1424 * 1024) +#define SD_CACHE_SIZE (400 * 1024) #define GBARUNNER_DATA_SIZE 0x1C0000 -#ifdef USE_3DS_32MB -#define MAIN_MEMORY_ADDRESS_ROM_DATA (MAIN_MEMORY_BASE + 0x00040000 + GBARUNNER_DATA_SIZE) -#else #define MAIN_MEMORY_ADDRESS_ROM_DATA (MAIN_MEMORY_BASE + 0x00040000) -#endif -#if defined(USE_DSI_16MB) -#define MAIN_MEMORY_ADDRESS_GBARUNNER_DATA (MAIN_MEMORY_BASE + 0x00E40000) -#elif defined(USE_3DS_32MB) -#define MAIN_MEMORY_ADDRESS_GBARUNNER_DATA (MAIN_MEMORY_BASE + 0x00040000) -#else -#define MAIN_MEMORY_ADDRESS_GBARUNNER_DATA (MAIN_MEMORY_BASE + 0x00240000) -#endif +#define MAIN_MEMORY_ADDRESS_GBARUNNER_DATA (MAIN_MEMORY_BASE + 0x00340000) + #define SAVE_DATA_SIZE 0x20000 -#ifdef USE_3DS_32MB -#define MAIN_MEMORY_ADDRESS_SAVE_DATA (MAIN_MEMORY_ADDRESS_GBARUNNER_DATA + GBARUNNER_DATA_SIZE - SAVE_DATA_SIZE) -#else #define MAIN_MEMORY_ADDRESS_SAVE_DATA (MAIN_MEMORY_END - SAVE_DATA_SIZE) -#endif -#ifdef USE_3DS_32MB -#define ROM_DATA_LENGTH (MAIN_MEMORY_END - MAIN_MEMORY_ADDRESS_ROM_DATA) -#else #define ROM_DATA_LENGTH (MAIN_MEMORY_ADDRESS_GBARUNNER_DATA - MAIN_MEMORY_ADDRESS_ROM_DATA) -#endif #define ROM_ADDRESS_MAX (0x08000000 + ROM_DATA_LENGTH) #define GBA_ADDR_TO_DS_HIGH ((MAIN_MEMORY_ADDRESS_ROM_DATA - 0x08000000) & 0xFF000000) @@ -72,4 +42,4 @@ #define CACHE_LINKED_LIST_NIL 4096 //0x8000 -#endif \ No newline at end of file +#endif