|
本帖最后由 jiangzhengwenjz 于 2019-7-10 06:09 编辑
GF偶尔会编写这样的程序,昨天在这个上面浪费了很多时间,来记录一下- ROM:0810FE50 @ struct WindowTemplate __fastcall SetWindowTemplateFields(u8 bg, u8 left, u8 top, u8 width, u8 height, u8 paletteNum, u16 baseBlock)
- ROM:0810FE50 SetWindowTemplateFields: @ CODE XREF: sub_809D654+34p
- ROM:0810FE50 @ money_box_build_and_print+2Ep ...
- ROM:0810FE50
- ROM:0810FE50 var_28 = -0x28
- ROM:0810FE50 var_24 = -0x24
- ROM:0810FE50 w = 0
- ROM:0810FE50 h = 4
- ROM:0810FE50 palID = 8
- ROM:0810FE50 FillerStartTile = 0xC
- ROM:0810FE50
- ROM:0810FE50 PUSH {R4-R7,LR}
- ROM:0810FE52 MOV R7, R10
- ROM:0810FE54 MOV R6, R9
- ROM:0810FE56 MOV R5, R8
- ROM:0810FE58 PUSH {R5-R7}
- ROM:0810FE5A SUB SP, SP, #8
- ROM:0810FE5C LDR R4, [SP,#0x28+w]
- ROM:0810FE5E MOV R12, R4
- ROM:0810FE60 LDR R4, [SP,#0x28+h]
- ROM:0810FE62 MOV R9, R4
- ROM:0810FE64 LDR R4, [SP,#0x28+palID]
- ROM:0810FE66 MOV R10, R4
- ROM:0810FE68 LDR R7, [SP,#0x28+FillerStartTile]
- ROM:0810FE6A LSLS R1, R1, #0x18
- ROM:0810FE6C LSRS R1, R1, #0x18
- ROM:0810FE6E LSLS R2, R2, #0x18
- ROM:0810FE70 LSLS R3, R3, #0x18
- ROM:0810FE72 MOV R4, R9
- ROM:0810FE74 LSLS R4, R4, #0x18
- ROM:0810FE76 LSRS R4, R4, #0x18
- ROM:0810FE78 MOV R9, R4
- ROM:0810FE7A MOV R4, R10
- ROM:0810FE7C LSLS R4, R4, #0x18
- ROM:0810FE7E MOV R10, R4
- ROM:0810FE80 LDR R4, =0xFFFFFF00
- ROM:0810FE82 MOV R8, R4
- ROM:0810FE84 MOV R5, R8
- ROM:0810FE86 LDR R4, [SP,#0x28+var_28]
- ROM:0810FE88 ANDS R5, R4
- ROM:0810FE8A ORRS R5, R1
- ROM:0810FE8C STR R5, [SP,#0x28+var_28]
- ROM:0810FE8E LSRS R2, R2, #0x10
- ROM:0810FE90 LDR R6, =0xFFFF00FF
- ROM:0810FE92 MOVS R4, R6
- ROM:0810FE94 ANDS R4, R5
- ROM:0810FE96 ORRS R4, R2
- ROM:0810FE98 STR R4, [SP,#0x28+var_28]
- ROM:0810FE9A LSRS R3, R3, #8
- ROM:0810FE9C LDR R1, =0xFF00FFFF
- ROM:0810FE9E ANDS R1, R4
- ROM:0810FEA0 ORRS R1, R3
- ROM:0810FEA2 STR R1, [SP,#0x28+var_28]
- ROM:0810FEA4 MOV R2, R12
- ROM:0810FEA6 LSLS R2, R2, #0x18
- ROM:0810FEA8 MOV R12, R2
- ROM:0810FEAA LDR R2, =0xFFFFFF
- ROM:0810FEAC ANDS R1, R2
- ROM:0810FEAE MOV R4, R12
- ROM:0810FEB0 ORRS R4, R1
- ROM:0810FEB2 STR R4, [SP,#0x28+var_28]
- ROM:0810FEB4 LDR R1, [SP,#0x28+var_24]
- ROM:0810FEB6 MOV R2, R8
- ROM:0810FEB8 ANDS R1, R2
- ROM:0810FEBA MOV R4, R9
- ROM:0810FEBC ORRS R1, R4
- ROM:0810FEBE MOV R8, R1
- ROM:0810FEC0 STR R1, [SP,#0x28+var_24]
- ROM:0810FEC2 MOV R1, R10
- ROM:0810FEC4 LSRS R1, R1, #0x10
- ROM:0810FEC6 MOV R2, R8
- ROM:0810FEC8 ANDS R6, R2
- ROM:0810FECA ORRS R6, R1
- ROM:0810FECC STR R6, [SP,#0x28+var_24]
- ROM:0810FECE LSLS R2, R7, #0x10
- ROM:0810FED0 LDR R1, =0xFFFF
- ROM:0810FED2 ANDS R6, R1
- ROM:0810FED4 ORRS R6, R2
- ROM:0810FED6 STR R6, [SP,#0x28+var_24]
- ROM:0810FED8 LDR R1, [SP,#0x28+var_28]
- ROM:0810FEDA LDR R2, [SP,#0x28+var_24]
- ROM:0810FEDC STR R1, [R0]
- ROM:0810FEDE STR R2, [R0,#4]
- ROM:0810FEE0 ADD SP, SP, #8
- ROM:0810FEE2 POP {R3-R5}
- ROM:0810FEE4 MOV R8, R3
- ROM:0810FEE6 MOV R9, R4
- ROM:0810FEE8 MOV R10, R5
- ROM:0810FEEA POP {R4-R7}
- ROM:0810FEEC POP {R2}
- ROM:0810FEEE BX R2
- ROM:0810FEEE @ End of function SetWindowTemplateFields
- ROM:0810FEEE
- ROM:0810FEEE @ ---------------------------------------------------------------------------
- ROM:0810FEF0 dword_810FEF0: .long 0xFFFFFF00 @ DATA XREF: SetWindowTemplateFields+30r
- ROM:0810FEF4 dword_810FEF4: .long 0xFFFF00FF @ DATA XREF: SetWindowTemplateFields+40r
- ROM:0810FEF8 dword_810FEF8: .long 0xFF00FFFF @ DATA XREF: SetWindowTemplateFields+4Cr
- ROM:0810FEFC dword_810FEFC: .long 0xFFFFFF @ DATA XREF: SetWindowTemplateFields+5Ar
- ROM:0810FF00 dword_810FF00: .long 0xFFFF @ DATA XREF: SetWindowTemplateFields+80r
复制代码 调用:- ROM:080F78E0 @ u8 __fastcall sub_80F78E0(u8 height)
- ROM:080F78E0 sub_80F78E0: @ CODE XREF: sub_806F01C+58p
- ROM:080F78E0
- ROM:080F78E0 height = -0x28
- ROM:080F78E0 pal = -0x24
- ROM:080F78E0 palID = -0x20
- ROM:080F78E0 baseblock = -0x1C
- ROM:080F78E0 template = -0x18
- ROM:080F78E0 var_14 = -0x14
- ROM:080F78E0 windowTemplate = -0x10
- ROM:080F78E0
- ROM:080F78E0 PUSH {R4,LR}
- ROM:080F78E2 SUB SP, SP, #0x20
- ROM:080F78E4 LSLS R0, R0, #0x18
- ROM:080F78E6 LSRS R1, R0, #0x18
- ROM:080F78E8 LDR R4, =sStartMenuWindowId
- ROM:080F78EA LDRB R0, [R4]
- ROM:080F78EC CMP R0, #0xFF
- ROM:080F78EE BNE loc_80F792A
- ROM:080F78F0 MOVS R0, #7
- ROM:080F78F2 STR R0, [SP,#0x28+height] @ height
- ROM:080F78F4 LSLS R0, R1, #0x19
- ROM:080F78F6 MOVS R1, #0xFF000000
- ROM:080F78FA ADDS R0, R0, R1
- ROM:080F78FC LSRS R0, R0, #0x18
- ROM:080F78FE STR R0, [SP,#0x28+pal] @ paletteNum
- ROM:080F7900 MOVS R0, #0xF
- ROM:080F7902 STR R0, [SP,#0x28+palID] @ baseBlock
- ROM:080F7904 LDR R0, =0x13D
- ROM:080F7906 STR R0, [SP,#0x28+baseblock] @ baseBlock
- ROM:080F7908 ADD R0, SP, #0x28+template @ bg
- ROM:080F790A MOVS R1, #0 @ left
- ROM:080F790C MOVS R2, #0x16 @ top
- ROM:080F790E MOVS R3, #1 @ width
- ROM:080F7910 BL SetWindowTemplateFields
- ROM:080F7914 LDR R0, [SP,#0x28+template]
- ROM:080F7916 LDR R1, [SP,#0x28+var_14]
- ROM:080F7918 STR R0, [SP,#0x28+windowTemplate]
- ROM:080F791A STR R1, [SP,#0x28+windowTemplate.window.height]
- ROM:080F791C ADD R0, SP, #0x28+windowTemplate @ template
- ROM:080F791E BL AddWindow
- ROM:080F7922 STRB R0, [R4]
- ROM:080F7924 LDRB R0, [R4] @ windowId
- ROM:080F7926 BL PutWindowTilemap
- ROM:080F792A
- ROM:080F792A loc_80F792A: @ CODE XREF: sub_80F78E0+Ej
- ROM:080F792A LDRB R0, [R4]
- ROM:080F792C ADD SP, SP, #0x20
- ROM:080F792E POP {R4}
- ROM:080F7930 POP {R1}
- ROM:080F7932 BX R1
- ROM:080F7932 @ End of function sub_80F78E0
- ROM:080F7932
- ROM:080F7932 @ ---------------------------------------------------------------------------
- ROM:080F7934 off_80F7934: .long sStartMenuWindowId @ DATA XREF: sub_80F78E0+8r
- ROM:080F7938 @ u16 TextStartTile
- ROM:080F7938 TextStartTile: .long 0x13D @ DATA XREF: sub_80F78E0+24r
复制代码 可见虽然保留了r0, r1的值,64位的WindowTemplate的返回值依然是通过栈传递来实现的,传递参数时则是留出r0提供栈空间访问,从r1开始才是参数,所以很容易误判成接受一个指针参数。
附反编译出的C函数:- struct WindowTemplate SetWindowTemplateFields(u8 bg, u8 left, u8 top, u8 width, u8 height, u8 paletteNum, u16 baseBlock)
- {
- struct WindowTemplate template;
- template.bg = bg;
- template.tilemapLeft = left;
- template.tilemapTop = top;
- template.width = width;
- template.height = height;
- template.paletteNum = paletteNum;
- template.baseBlock = baseBlock;
- return template;
- }
复制代码- u8 sub_80F78E0(u8 height)
- {
- if (sStartMenuWindowId == 0xFF)
- {
- struct WindowTemplate template = SetWindowTemplateFields(0, 0x16, 1, 7, height * 2 - 1, DLG_WINDOW_PALETTE_NUM, 0x13D);
- sStartMenuWindowId = AddWindow(&template);
- PutWindowTilemap(sStartMenuWindowId);
- }
- return sStartMenuWindowId;
- }
复制代码 |
|