Skip to content

Commit

Permalink
rom3M + brightness control
Browse files Browse the repository at this point in the history
  • Loading branch information
unresolvedsymbol committed Oct 19, 2020
1 parent 6e4ce45 commit 97447fe
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 49 deletions.
27 changes: 27 additions & 0 deletions arm7/source/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <nds.h>
#include <nds/arm7/serial.h>
#include <string.h>
#include "timer.h"
#include "sound.h"
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions arm9/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Binary file added arm9/data/IconBright.nbfc
Binary file not shown.
21 changes: 16 additions & 5 deletions arm9/source/gui/InGameMenu.vram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "IconPlay_nbfc.h"
#include "IconRestart_nbfc.h"
#include "IconPower_nbfc.h"
#include "IconBright_nbfc.h"
#include "../cp15.h"
#include "InGameMenu.h"

Expand All @@ -25,6 +26,7 @@ static const igm_action_t sActions[] =
{
{ "Resume" },
{ "Reset" },
{ "Brightness" },
{ "Quit to rom browser" }
};

Expand Down Expand Up @@ -253,10 +255,14 @@ int InGameMenu::Run()
sIconObjAddrs[1] = _uiContext->GetUIManager().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();

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -322,4 +333,4 @@ int InGameMenu::Run()
_uiContext->GetUIManager().VBlank();

return next;
}
}
12 changes: 6 additions & 6 deletions arm9/source/save/Save.vram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand All @@ -102,7 +102,7 @@ const save_type_t* save_findTag()
}
}
}
searchBufPtr = (searchBufPtr + 4) & 0xFFFFF;
searchBufPtr = (searchBufPtr + 4) & 0x3FFFF;
curAddr += 4;
}
return NULL;
Expand Down
38 changes: 4 additions & 34 deletions common/common_defs.s
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -72,4 +42,4 @@

#define CACHE_LINKED_LIST_NIL 4096 //0x8000

#endif
#endif

0 comments on commit 97447fe

Please sign in to comment.