From 10562f5898173de0ea84c1277ed2d3851c39ddbc Mon Sep 17 00:00:00 2001 From: Tal Hayon Date: Thu, 30 Dec 2021 12:48:00 +0200 Subject: [PATCH 1/2] Tried to decompile dispCtrlSet --- .../dispCtrlSet.inc} | 0 include/screen.h | 37 +++++++------- src/interrupts.c | 50 ++++++++++++++++++- src/manager/managerC.c | 16 +++--- 4 files changed, 74 insertions(+), 29 deletions(-) rename asm/{dispCtrlSet.s => non_matching/dispCtrlSet.inc} (100%) diff --git a/asm/dispCtrlSet.s b/asm/non_matching/dispCtrlSet.inc similarity index 100% rename from asm/dispCtrlSet.s rename to asm/non_matching/dispCtrlSet.inc diff --git a/include/screen.h b/include/screen.h index f308f19d..4c9dc293 100644 --- a/include/screen.h +++ b/include/screen.h @@ -5,10 +5,10 @@ #include "fade.h" typedef struct { - u16 displayControl; - u8 filler2[0x2]; - u16 unk4; - u16 displayControlMask; + u16 displayControl; // 0x0 + u8 filler2[0x2]; // 0x2 + u16 unk4; // 0x4 + u16 displayControlMask; // 0x6 } LcdControls; typedef struct { @@ -28,22 +28,19 @@ typedef struct { } BgAffSettings; typedef struct { - u16 bg2dx; - u16 bg2dmx; - u16 bg2dy; - u16 bg2dmy; - u16 bg2xPointLeastSig; - u16 bg2xPointMostSig; - u16 bg2yPointLeastSig; - u16 bg2yPointMostSig; - u16 bg3dx; - u16 bg3dmx; - u16 bg3dy; - u16 bg3dmy; - u16 bg3xPointLeastSig; - u16 bg3xPointMostSig; - u16 bg3yPointLeastSig; - u16 bg3yPointMostSig; + u16 dx; + u16 dmx; + u16 dy; + u16 dmy; + u16 xPointLeastSig; + u16 xPointMostSig; + u16 yPointLeastSig; + u16 yPointMostSig; +} BgTransformationSettings; + +typedef struct { + BgTransformationSettings bg2; + BgTransformationSettings bg3; u16 window0HorizontalDimensions; u16 window1HorizontalDimensions; u16 window0VerticalDimensions; diff --git a/src/interrupts.c b/src/interrupts.c index 85c3c16c..90556e62 100644 --- a/src/interrupts.c +++ b/src/interrupts.c @@ -117,7 +117,55 @@ void sub_08016CA8(BgSettings* bg) { } } -ASM_FUNC("asm/dispCtrlSet.s", void DispCtrlSet(void)); +NONMATCH("asm/non_matching/dispCtrlSet.inc", void DispCtrlSet(void)) { + BgControls* controls; + u16 tmp = gScreen.lcd.displayControl & gScreen.lcd.displayControlMask; + REG_DISPCNT = tmp; + + REG_BG0CNT = gScreen.bg0.control; + REG_BG1CNT = gScreen.bg1.control; + REG_BG2CNT = gScreen.bg2.control; + REG_BG3CNT = gScreen.bg3.control; + REG_BG0HOFS = gScreen.bg0.xOffset; + REG_BG0VOFS = gScreen.bg0.yOffset; + REG_BG1HOFS = gScreen.bg1.xOffset; + REG_BG1VOFS = gScreen.bg1.yOffset; + REG_BG2HOFS = gScreen.bg2.xOffset; + REG_BG2VOFS = gScreen.bg2.yOffset; + REG_BG3HOFS = gScreen.bg3.xOffset; + REG_BG3VOFS = gScreen.bg3.yOffset; + + controls = &(gScreen.controls); + REG_BG2PA = controls->bg2.dx; + REG_BG2PB = controls->bg2.dmx; + REG_BG2PC = controls->bg2.dy; + REG_BG2PD = controls->bg2.dmy; + REG_BG2X_L = controls->bg2.xPointLeastSig; + REG_BG2X_H = controls->bg2.xPointMostSig; + REG_BG2Y_L = controls->bg2.yPointLeastSig; + REG_BG2Y_H = controls->bg2.yPointMostSig; + + REG_BG3PA = controls->bg3.dx; + REG_BG3PB = controls->bg3.dmx; + REG_BG3PC = controls->bg3.dy; + REG_BG3PD = controls->bg3.dmy; + REG_BG3X_L = controls->bg3.xPointLeastSig; + REG_BG3X_H = controls->bg3.xPointMostSig; + REG_BG3Y_L = controls->bg3.yPointLeastSig; + REG_BG3Y_H = controls->bg3.yPointMostSig; + + REG_WIN0H = controls->window0HorizontalDimensions; + REG_WIN1H = controls->window1HorizontalDimensions; + REG_WIN0V = controls->window0VerticalDimensions; + REG_WIN1V = controls->window1VerticalDimensions; + REG_WININ = controls->windowInsideControl; + REG_WINOUT = controls->windowOutsideControl; + REG_MOSAIC = controls->mosaicSize; + REG_BLDCNT = controls->layerFXControl; + REG_BLDALPHA = controls->alphaBlend; + REG_BLDY = controls->layerBrightness; +} +END_NONMATCH // Load any resources that were requested with LoadResourceAsync void LoadResources(void) { diff --git a/src/manager/managerC.c b/src/manager/managerC.c index d7c3f867..fc77cfc6 100644 --- a/src/manager/managerC.c +++ b/src/manager/managerC.c @@ -237,14 +237,14 @@ void sub_08058BC8(ManagerC* this) { tmp++; } while (++tmp3 < 0xA0u); tmp = &gUnk_02017BA0[gUnk_03003DE4[0] * 0xA0]; - gScreen.controls.bg2dx = tmp->pa; - gScreen.controls.bg2dmx = tmp->pb; - gScreen.controls.bg2dy = tmp->pc; - gScreen.controls.bg2dmy = tmp->pd; - gScreen.controls.bg2xPointLeastSig = ((union SplitWord*)&tmp->dx)->HALF.LO; - gScreen.controls.bg2xPointMostSig = ((union SplitWord*)&tmp->dx)->HALF.HI; - gScreen.controls.bg2yPointLeastSig = ((union SplitWord*)&tmp->dy)->HALF.LO; - gScreen.controls.bg2yPointMostSig = ((union SplitWord*)&tmp->dy)->HALF.HI; + gScreen.controls.bg2.dx = tmp->pa; + gScreen.controls.bg2.dmx = tmp->pb; + gScreen.controls.bg2.dy = tmp->pc; + gScreen.controls.bg2.dmy = tmp->pd; + gScreen.controls.bg2.xPointLeastSig = ((union SplitWord*)&tmp->dx)->HALF.LO; + gScreen.controls.bg2.xPointMostSig = ((union SplitWord*)&tmp->dx)->HALF.HI; + gScreen.controls.bg2.yPointLeastSig = ((union SplitWord*)&tmp->dy)->HALF.LO; + gScreen.controls.bg2.yPointMostSig = ((union SplitWord*)&tmp->dy)->HALF.HI; } const u16 gUnk_08108300[4] = { 0xA4, 0x4C, 0xF4, 0x9C }; From 76a10a280874c7524a9d0210c45b8c8a9eed8a29 Mon Sep 17 00:00:00 2001 From: Tal Hayon Date: Fri, 31 Dec 2021 01:10:21 +0200 Subject: [PATCH 2/2] Fix offset comments --- include/screen.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/screen.h b/include/screen.h index 4c9dc293..784224a8 100644 --- a/include/screen.h +++ b/include/screen.h @@ -5,10 +5,10 @@ #include "fade.h" typedef struct { - u16 displayControl; // 0x0 - u8 filler2[0x2]; // 0x2 - u16 unk4; // 0x4 - u16 displayControlMask; // 0x6 + /*0x00*/ u16 displayControl; + /*0x02*/ u8 filler2[0x2]; + /*0x04*/ u16 unk4; + /*0x06*/ u16 displayControlMask; } LcdControls; typedef struct {