Skip to content

Commit

Permalink
Added gba frame and screen darkening support
Browse files Browse the repository at this point in the history
  • Loading branch information
Gericom committed Oct 4, 2019
1 parent d6234c8 commit 0c697a9
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 16 deletions.
4 changes: 4 additions & 0 deletions arm9/source/emu/irq.s
Expand Up @@ -347,6 +347,9 @@ cap_control:
mov r2, #0x84
strneb r2, [r12, #0x242]
streqb r2, [r12, #0x243]
movne r2, #0x00
moveq r2, #0x81
strb r2, [r12, #0x249]
orr r1, #0x80000000
str r1, [r12, #0x64]

Expand All @@ -370,6 +373,7 @@ cap_control:
mov r3, r1, lsr #3
mov r3, r3, lsl #5
add r3, r3, r0, lsr #3
add r3, #512
orr r3, #0xF000 //fully visible
strh r3, [r2], #4

Expand Down
3 changes: 2 additions & 1 deletion arm9/source/gui/FileBrowser.h
Expand Up @@ -39,7 +39,8 @@ class FileBrowser
void LoadBios();
void LoadFolder(const char* path);
void CreateLoadSave(const char* path, const save_type_t* saveType);
void LoadGame(const char* path);
void LoadFrame(u32 id);
void LoadGame(const char* path, u32 id);
void UpdateCover();
void InvalidateCover();
public:
Expand Down
46 changes: 44 additions & 2 deletions arm9/source/gui/FileBrowser.vram.cpp
Expand Up @@ -21,6 +21,7 @@
#include "save/Save.h"
#include "bios.h"
#include "gamePatches.h"
#include "settings.h"
#include "FileBrowser.h"

static int compDirEntries(const FILINFO*& dir1, const FILINFO*& dir2)
Expand Down Expand Up @@ -167,10 +168,51 @@ void FileBrowser::CreateLoadSave(const char* path, const save_type_t* saveType)
#endif
}

void FileBrowser::LoadGame(const char* path)
void FileBrowser::LoadFrame(u32 id)
{
char framePath[] = "/_gba/frames/ABCD.bin";
*(vu8*)0x04000242 = 0x84;
*(vu8*)0x04000248 = 0x80; //H to lcdc
*(vu8*)0x04000249 = 0x81; //I to bg
if(!gEmuSettingFrame)
goto noframe;

framePath[13] = id & 0xFF;
framePath[14] = (id >> 8) & 0xFF;
framePath[15] = (id >> 16) & 0xFF;
framePath[16] = (id >> 24) & 0xFF;

if (f_stat(framePath, NULL) == FR_OK)
f_open(&vram_cd->fil, framePath, FA_OPEN_EXISTING | FA_READ);
else if (f_stat("/_gba/frames/default.bin", NULL) == FR_OK)
f_open(&vram_cd->fil, "/_gba/frames/default.bin", FA_OPEN_EXISTING | FA_READ);
else
goto noframe;

UINT br;
f_read(&vram_cd->fil, (void*)MAIN_MEMORY_ADDRESS_ROM_DATA, 512, &br);
arm9_memcpy16((u16*)0x06898000, (u16*)MAIN_MEMORY_ADDRESS_ROM_DATA, 256);
f_read(&vram_cd->fil, (void*)MAIN_MEMORY_ADDRESS_ROM_DATA, 2048, &br);
arm9_memcpy16((u16*)0x0620B800, (u16*)MAIN_MEMORY_ADDRESS_ROM_DATA, 1024);
f_read(&vram_cd->fil, (void*)MAIN_MEMORY_ADDRESS_ROM_DATA, 0x2A00, &br);
arm9_memcpy16((u16*)0x06208000, (u16*)MAIN_MEMORY_ADDRESS_ROM_DATA, 0x2A00 >> 1);

*(vu8*)0x04000248 = 0x82;; //H to extpltt
return;

noframe:
for(int i = 0; i < 128; i++)
((u32*)0x06898000)[i] = 0;
*(vu8*)0x04000248 = 0x82;; //H to extpltt
}

void FileBrowser::LoadGame(const char* path, u32 id)
{
if(_coverLoadState == COVER_LOAD_STATE_LOAD)
f_close(&vram_cd->fil);

LoadFrame(id);

if (f_open(&vram_cd->fil, path, FA_OPEN_EXISTING | FA_READ) != FR_OK)
_uiContext->FatalError("Error while opening rom!");
vram_cd->sd_info.gba_rom_size = vram_cd->fil.obj.objsize;
Expand Down Expand Up @@ -334,7 +376,7 @@ int FileBrowser::Run()
}
else
{
LoadGame(_sortedEntries[_selectedEntry]->fname);
LoadGame(_sortedEntries[_selectedEntry]->fname, _ids[_selectedEntry]);
break;
}
}
Expand Down
2 changes: 2 additions & 0 deletions arm9/source/gui/SettingsScreen.vram.cpp
Expand Up @@ -24,9 +24,11 @@ static settings_item_t sEmulationItems[] =
{
{ SETTINGS_ITEM_MODE_CHECK, "Display game on bottom screen", "", &gEmuSettingUseBottomScreen },
//{ SETTINGS_ITEM_MODE_CHECK, "Enable autosaving", "Writes back the save to sd after a game saves", &gEmuSettingAutoSave },
{ SETTINGS_ITEM_MODE_CHECK, "Enable border frame", "Enables the usage of gba border frames", &gEmuSettingFrame },
{ SETTINGS_ITEM_MODE_CHECK, "Enable center and mask", "Centers the game with a border. Adds 1 frame delay", &gEmuSettingCenterMask },
{ SETTINGS_ITEM_MODE_CHECK, "Enable DS main memory i-cache", "Boosts speed, but causes timing bugs in a few games", &gEmuSettingMainMemICache },
{ SETTINGS_ITEM_MODE_CHECK, "Enable wram i-cache", "Boosts speed, but some games may crash", &gEmuSettingWramICache },
{ SETTINGS_ITEM_MODE_CHECK, "Simulate GBA colors", "Darkens the colors to simulate a GBA screen", &gEmuSettingGbaColors },
{ SETTINGS_ITEM_MODE_CHECK, "Skip bios intro", "Directly boot the game without playing the intro", &gEmuSettingSkipIntro }
};

Expand Down
2 changes: 2 additions & 0 deletions arm9/source/settings.h
Expand Up @@ -3,8 +3,10 @@
extern u32 gEmuSettingUseBottomScreen;
//extern u32 gEmuSettingAutoSave;
extern u32 gEmuSettingCenterMask;
extern u32 gEmuSettingFrame;
extern u32 gEmuSettingMainMemICache;
extern u32 gEmuSettingWramICache;
extern u32 gEmuSettingGbaColors;
extern u32 gEmuSettingSkipIntro;

void settings_initialize();
Expand Down
19 changes: 19 additions & 0 deletions arm9/source/settings.vram.cpp
Expand Up @@ -14,24 +14,37 @@ static const char* sEmulationSectionName = "emulation";
//settings are globals such that they can be easily accessed from assembly
static const char* sEmuSettingUseBottomScreenName = "useBottomScreen";
u32 gEmuSettingUseBottomScreen;

static const char* sEmuSettingAutoSaveName = "autoSave";
u32 gEmuSettingAutoSave;

static const char* sEmuSettingFrameName = "frame";
u32 gEmuSettingFrame;

static const char* sEmuSettingCenterMaskName = "centerMask";
u32 gEmuSettingCenterMask;

static const char* sEmuSettingGbaColorsName = "gbaColors";
u32 gEmuSettingGbaColors;

static const char* sEmuSettingMainMemICacheName = "mainMemICache";
u32 gEmuSettingMainMemICache;

static const char* sEmuSettingWramICacheName = "wramICache";
u32 gEmuSettingWramICache;

static const char* sEmuSettingSkipIntroName = "skipIntro";
u32 gEmuSettingSkipIntro;

static void loadDefaultSettings()
{
gEmuSettingUseBottomScreen = false;
gEmuSettingAutoSave = true;
gEmuSettingFrame = true;
gEmuSettingCenterMask = true;
gEmuSettingMainMemICache = true;
gEmuSettingWramICache = true;
gEmuSettingGbaColors = false;
gEmuSettingSkipIntro = false;
}

Expand All @@ -52,12 +65,16 @@ static void iniPropertyCallback(void* arg, const char* section, const char* key,
gEmuSettingUseBottomScreen = parseBoolean(value, false);
else if(!strcmp(key, sEmuSettingAutoSaveName))
gEmuSettingAutoSave = parseBoolean(value, true);
else if(!strcmp(key, sEmuSettingFrameName))
gEmuSettingFrame = parseBoolean(value, true);
else if(!strcmp(key, sEmuSettingCenterMaskName))
gEmuSettingCenterMask = parseBoolean(value, true);
else if(!strcmp(key, sEmuSettingMainMemICacheName))
gEmuSettingMainMemICache = parseBoolean(value, true);
else if(!strcmp(key, sEmuSettingWramICacheName))
gEmuSettingWramICache = parseBoolean(value, true);
else if(!strcmp(key, sEmuSettingGbaColorsName))
gEmuSettingGbaColors = parseBoolean(value, false);
else if(!strcmp(key, sEmuSettingSkipIntroName))
gEmuSettingSkipIntro = parseBoolean(value, false);
}
Expand All @@ -80,9 +97,11 @@ bool settings_save()
writer.WriteSection(sEmulationSectionName);
writer.WriteBooleanProperty(sEmuSettingUseBottomScreenName, gEmuSettingUseBottomScreen);
//writer.WriteBooleanProperty(sEmuSettingAutoSaveName, gEmuSettingAutoSave);
writer.WriteBooleanProperty(sEmuSettingFrameName, gEmuSettingFrame);
writer.WriteBooleanProperty(sEmuSettingCenterMaskName, gEmuSettingCenterMask);
writer.WriteBooleanProperty(sEmuSettingMainMemICacheName, gEmuSettingMainMemICache);
writer.WriteBooleanProperty(sEmuSettingWramICacheName, gEmuSettingWramICache);
writer.WriteBooleanProperty(sEmuSettingGbaColorsName, gEmuSettingGbaColors);
writer.WriteBooleanProperty(sEmuSettingSkipIntroName, gEmuSettingSkipIntro);
f_close(&vram_cd->fil);
return true;
Expand Down
28 changes: 15 additions & 13 deletions arm9/source/setup.s
Expand Up @@ -102,7 +102,7 @@ itcm_setup_copyloop:
strb r1, [r0]

//setup display capture
ldr r0,= 0x320000
ldr r0,= (0x320000 | (1 << 19))
ldr r1,= 0x4000064
str r0, [r1]

Expand Down Expand Up @@ -397,14 +397,6 @@ dldi_name_copy:
ldr r0,= pu_data_permissions
mcr p15, 0, r0, c5, c0, 2

ldr r0,= 0x04001000
ldr r1,= 0x10801
str r1, [r0]

ldr r0,= 0x0400100E
ldr r1,= 0x4400
strh r1, [r0]

ldr r0,= 0x04001030
ldr r1,= 0x100
strh r1, [r0]
Expand All @@ -418,9 +410,11 @@ dldi_name_copy:

//more displaycap stuff
ldr r0,= 0x04001000
ldr r1,= 0x13823
ldr r1,= 0x40013923 //0x13923
str r1, [r0]
ldr r1,= 0x4084
ldr r1,= 0x1788
strh r1, [r0, #0x8]
ldr r1,= (0x4084 | (1 << 10))
strh r1, [r0, #0xE]

ldr r2,= gEmuSettingCenterMask
Expand All @@ -440,7 +434,7 @@ dldi_name_copy:
strh r1, [r0, #0x44]
mov r1, #0x18
strh r1, [r0, #0x48]
mov r1, #(1 << 5)
mov r1, #1 //(1 << 5)
strh r1, [r0, #0x4A]
mov r1, #0x10
strh r1, [r0, #0x54]
Expand All @@ -467,6 +461,7 @@ skip_center_mask:
mov r3, r1, lsr #3
mov r3, r3, lsl #5
add r3, r3, r0, lsr #3
add r3, #512
orr r3, #0xF000 //fully visible
strh r3, [r2], #4

Expand All @@ -481,7 +476,7 @@ skip_center_mask:
//disable vram h and i
ldr r0,= 0x04000248
mov r1, #0x00
strb r1, [r0]
//strb r1, [r0]
strb r1, [r0, #1]

//disable the 3d geometry and render engine and swap the screens
Expand Down Expand Up @@ -509,6 +504,13 @@ skip_center_mask:
ldr r1,= 0x801F
strh r1, [r0]

ldr r2,= gEmuSettingGbaColors
ldr r2, [r2]
cmp r2, #1
eoreq r0, #0x1000
ldreq r1,= 0x8008
streqh r1, [r0]

//Copy GBA Bios in place
// ldr r0,= bios_tmp
// mov r1, #0x4000
Expand Down

0 comments on commit 0c697a9

Please sign in to comment.