diff options
| author | red031000 <rubenru09@aol.com> | 2020-06-07 17:28:17 +0100 | 
|---|---|---|
| committer | red031000 <rubenru09@aol.com> | 2020-06-07 17:28:17 +0100 | 
| commit | 1c7bd60010bb429bd6cbcfad889bef9e7058cb89 (patch) | |
| tree | fff29ec53e2f943ea73c977e1870c10b985dbd19 /arm9 | |
| parent | 292a0f16f5492c0b89b11f4eec9bc8397874f9f0 (diff) | |
| parent | c2d3d0fb118d3f9ff14f8f5293f54d0c37421a70 (diff) | |
Merge branch 'master' of https://github.com/martmists/pokediamond
Diffstat (limited to 'arm9')
| -rw-r--r-- | arm9/Makefile | 18 | ||||
| -rw-r--r-- | arm9/arm9.lcf | 3 | ||||
| -rw-r--r-- | arm9/asm/pokemon.s | 60 | ||||
| -rw-r--r-- | arm9/lib/Makefile | 89 | ||||
| -rw-r--r-- | arm9/lib/syscall/_svc_mw.s | 121 | ||||
| -rw-r--r-- | arm9/modules/01/src/module_01.cpp | 14 | 
6 files changed, 259 insertions, 46 deletions
| diff --git a/arm9/Makefile b/arm9/Makefile index df04770c..0b880bd3 100644 --- a/arm9/Makefile +++ b/arm9/Makefile @@ -186,7 +186,8 @@ OBJCOPY := $(CROSS)objcopy  ASFLAGS = -proc arm5te -i ..  CFLAGS = -O4,p -proc arm946e -fp soft -lang c99 -Cpp_exceptions off -i ../include -ir ../include-mw -ir lib/include -interworking -DFS_IMPLEMENT -enum int -W all -D$(GAME_VERSION) -D$(GAME_LANGUAGE)  CXXFLAGS = -O4,p -proc arm946e -fp soft -lang c99 -Cpp_exceptions off -i ../include -ir ../include-mw -ir lib/include -interworking -DFS_IMPLEMENT -enum int -W all -D$(GAME_VERSION) -D$(GAME_LANGUAGE) -LDFLAGS = -map -nodead -w off -proc v5te -interworking -map -symtab -m _start +LDFLAGS = -nodead -w off -proc v5te -interworking -map closure,unused -symtab sort -m _start +# LIBS := -Llib -lsyscall  ####################### Other Tools ######################### @@ -202,7 +203,8 @@ TOOLBASE = $(TOOLDIRS:$(TOOLS_DIR)/%=%)  TOOLS = $(foreach tool,$(TOOLBASE),$(TOOLS_DIR)/$(tool)/$(tool)$(EXE))  export LM_LICENSE_FILE := $(TOOLS_DIR)/mwccarm/license.dat -export MWCIncludes := lib/include +export MWCIncludes := $(CURDIR)/lib/include +export MWLibraries := $(CURDIR)/lib  ######################### Targets ########################### @@ -217,24 +219,28 @@ NODEP := 1  endif  .PRECIOUS: $(ROM) -.PHONY: all clean mostlyclean tidy tools $(TOOLDIRS) patch_mwasmarm +.PHONY: all libs clean mostlyclean tidy tools $(TOOLDIRS) patch_mwasmarm  MAKEFLAGS += --no-print-directory -all: $(ROM) +all: libs $(ROM)  ifeq ($(COMPARE),1)  	@$(SHA1SUM) -c $(TARGET).sha1  	@echo $(ROM): OK  endif +libs: +	$(MAKE) -C lib +  clean: mostlyclean -	make -C $(TOOLS_DIR)/mwasmarm_patcher clean +	$(MAKE) -C $(TOOLS_DIR)/mwasmarm_patcher clean  mostlyclean: tidy  	find . \( -iname '*.1bpp' -o -iname '*.4bpp' -o -iname '*.8bpp' -o -iname '*.gbapal' -o -iname '*.lz' \) -exec $(RM) {} +  tidy:  	$(RM) -r $(BUILD_DIR) +	$(MAKE) clean -C lib  tools: $(TOOLDIRS) @@ -277,7 +283,7 @@ $(BUILD_DIR)/$(LD_SCRIPT): $(LD_SCRIPT)  	$(CPP) $(VERSION_CFLAGS) -MMD -MP -MT $@ -MF $@.d -I include/ -I . -DBUILD_DIR=$(BUILD_DIR) -o $@ $<  $(ROM): $(O_FILES) $(BUILD_DIR)/$(LD_SCRIPT) $(BIN_FILES) -	$(LD) $(LDFLAGS) $(BUILD_DIR)/$(LD_SCRIPT) -o $(ELF) $(O_FILES) $(BIN_FILES) +	$(LD) $(LDFLAGS) $(LIBS) $(BUILD_DIR)/$(LD_SCRIPT) -o $(ELF) $(O_FILES) $(BIN_FILES)  	$(OBJCOPY) --update-section arm9=$@ -j arm9 $(foreach ov,$(OVERLAYS),--update-section $(ov)=$(BUILD_DIR)/$(ov).sbin -j $(ov)) $(ELF) 2>/dev/null  # Make sure build directory exists before compiling anything diff --git a/arm9/arm9.lcf b/arm9/arm9.lcf index fced9d86..9fb4de49 100644 --- a/arm9/arm9.lcf +++ b/arm9/arm9.lcf @@ -117,7 +117,8 @@ SECTIONS {  		ALIGNALL(4); . = ALIGN(32);  		SDK_STATIC_START = .;  		SDK_STATIC_TEXT_START = .; -		secure.o (.text) +		/* libsyscall.a (.text) */ +		secure.o (.text) /* is actually libsyscall with nitro encryption */  		crt0.o (.text)  		crt0.o (.rodata)  		* (.version) diff --git a/arm9/asm/pokemon.s b/arm9/asm/pokemon.s index 8bcaa0c7..3b50e07b 100644 --- a/arm9/asm/pokemon.s +++ b/arm9/asm/pokemon.s @@ -4103,12 +4103,12 @@ FUN_02068758: ; 0x02068758  	mov r1, #0x15  	bl FUN_02068678  	add r1, r4, #0x0 -	bl FUN_02068788 +	bl GetExpByGrowthRateAndLevel  	pop {r4, pc}  	.balign 4 -	thumb_func_start FUN_0206876C -FUN_0206876C: ; 0x0206876C +	thumb_func_start LoadGrowthTable +LoadGrowthTable: ; 0x0206876C  	push {r3-r5, lr}  	add r5, r0, #0x0  	add r4, r1, #0x0 @@ -4117,14 +4117,14 @@ FUN_0206876C: ; 0x0206876C  	bl ErrorHandling  _0206877A:  	add r0, r4, #0x0 -	mov r1, #0x3 +	mov r1, #0x3 ; NARC_POKETOOL_PERSONAL_GROWTBL  	add r2, r5, #0x0  	bl ReadWholeNarcMemberByIdPair  	pop {r3-r5, pc}  	.balign 4 -	thumb_func_start FUN_02068788 -FUN_02068788: ; 0x02068788 +	thumb_func_start GetExpByGrowthRateAndLevel +GetExpByGrowthRateAndLevel: ; 0x02068788  	push {r4-r6, lr}  	add r6, r0, #0x0  	add r5, r1, #0x0 @@ -4143,7 +4143,7 @@ _0206879E:  	add r4, r0, #0x0  	add r0, r6, #0x0  	add r1, r4, #0x0 -	bl FUN_0206876C +	bl LoadGrowthTable  	lsl r0, r5, #0x2  	ldr r5, [r4, r0]  	add r0, r4, #0x0 @@ -4209,7 +4209,7 @@ FUN_02068824: ; 0x02068824  	add r4, r2, #0x0  	bl FUN_02068538  	ldr r1, _0206884C ; =UNK_021C5AC0 -	bl FUN_0206876C +	bl LoadGrowthTable  	ldr r2, _02068850 ; =UNK_021C5AC0 + 4  	mov r1, #0x1  _02068838: @@ -5169,7 +5169,7 @@ _02068F1A:  	lsr r1, r2, #0x1  	add r1, #0x48  	lsl r0, r3, #0x1 -	mov r4, #0x79 +	mov r4, #0x79 ; NARC_POKETOOL_POKEGRA_HEIGHT_O  	add r3, r1, r0  	b _02068FCA  _02068F26: @@ -5180,7 +5180,7 @@ _02068F2C:  	lsr r1, r2, #0x1  	add r1, #0x4e  	lsl r0, r3, #0x1 -	mov r4, #0x79 +	mov r4, #0x79 ; NARC_POKETOOL_POKEGRA_HEIGHT_O  	add r3, r1, r0  	b _02068FCA  _02068F38: @@ -5189,7 +5189,7 @@ _02068F38:  	mov r3, #0x0  _02068F3E:  	add r2, #0x54 -	mov r4, #0x79 +	mov r4, #0x79 ; NARC_POKETOOL_POKEGRA_HEIGHT_O  	add r3, r2, r3  	b _02068FCA  _02068F46: @@ -5198,7 +5198,7 @@ _02068F46:  	mov r3, #0x0  _02068F4C:  	add r2, #0x58 -	mov r4, #0x79 +	mov r4, #0x79 ; NARC_POKETOOL_POKEGRA_HEIGHT_O  	add r3, r2, r3  	b _02068FCA  _02068F54: @@ -5207,7 +5207,7 @@ _02068F54:  	mov r3, #0x0  _02068F5A:  	add r2, #0x5c -	mov r4, #0x79 +	mov r4, #0x79 ; NARC_POKETOOL_POKEGRA_HEIGHT_O  	add r3, r2, r3  	b _02068FCA  _02068F62: @@ -5218,7 +5218,7 @@ _02068F68:  	lsr r1, r2, #0x1  	add r1, #0x60  	lsl r0, r3, #0x1 -	mov r4, #0x79 +	mov r4, #0x79 ; NARC_POKETOOL_POKEGRA_HEIGHT_O  	add r3, r1, r0  	b _02068FCA  _02068F74: @@ -5228,7 +5228,7 @@ _02068F74:  _02068F7A:  	lsl r0, r2, #0x1  	add r0, #0x40 -	mov r4, #0x79 +	mov r4, #0x79 ; NARC_POKETOOL_POKEGRA_HEIGHT_O  	add r3, r3, r0  	b _02068FCA  _02068F84: @@ -5238,7 +5238,7 @@ _02068F84:  _02068F8A:  	lsr r1, r2, #0x1  	lsl r0, r3, #0x1 -	mov r4, #0x79 +	mov r4, #0x79 ; NARC_POKETOOL_POKEGRA_HEIGHT_O  	add r3, r1, r0  	b _02068FCA  _02068F94: @@ -5249,7 +5249,7 @@ _02068F9A:  	lsr r1, r2, #0x1  	add r1, #0x8  	lsl r0, r3, #0x1 -	mov r4, #0x79 +	mov r4, #0x79 ; NARC_POKETOOL_POKEGRA_HEIGHT_O  	add r3, r1, r0  	b _02068FCA  _02068FA6: @@ -5257,15 +5257,15 @@ _02068FA6:  	bls _02068FAC  	mov r3, #0x0  _02068FAC: -	mov r4, #0x79 +	mov r4, #0x79 ; NARC_POKETOOL_POKEGRA_HEIGHT_O  	add r3, #0x84  	b _02068FCA  _02068FB2: -	mov r4, #0x79 +	mov r4, #0x79 ; NARC_POKETOOL_POKEGRA_HEIGHT_O  	mov r3, #0x84  	b _02068FCA  _02068FB8: -	mov r4, #0x5 +	mov r4, #0x5 ; NARC_POKETOOL_POKEGRA_HEIGHT  	cmp r1, #0x1  	beq _02068FC2  	mov r1, #0x1 @@ -5324,7 +5324,7 @@ FUN_02069010: ; 0x02069010  	add r4, r0, #0x0  	str r3, [sp, #0x0]  	add r0, sp, #0x4 -	mov r1, #0x72 +	mov r1, #0x72 ; NARC_POKETOOL_POKEANM_POKEANM  	mov r2, #0x0  	mul r3, r5  	bl ReadFromNarcMemberByIdPair @@ -5348,7 +5348,7 @@ FUN_02069038: ; 0x02069038  	add r7, r1, #0x0  	str r3, [sp, #0x0]  	add r0, #0x2 -	mov r1, #0x72 +	mov r1, #0x72 ; NARC_POKETOOL_POKEANM_POKEANM  	mov r2, #0x0  	mul r3, r6  	bl ReadFromNarcMemberByIdPair @@ -5470,7 +5470,7 @@ FUN_020690E8: ; 0x020690E8  	bl FUN_02068678  	mov r1, #0x64  	add r5, r0, #0x0 -	bl FUN_02068788 +	bl GetExpByGrowthRateAndLevel  	ldr r1, [sp, #0x4]  	cmp r1, r0  	bls _02069138 @@ -5489,7 +5489,7 @@ _02069138:  	pop {r3-r5, pc}  _02069146:  	add r0, r5, #0x0 -	bl FUN_02068788 +	bl GetExpByGrowthRateAndLevel  	ldr r1, [sp, #0x4]  	cmp r1, r0  	blo _02069162 @@ -6781,7 +6781,7 @@ FUN_02069B40: ; 0x02069B40  	mov r0, #0x2  	str r0, [sp, #0x0]  	add r0, sp, #0x4 -	mov r1, #0x6d +	mov r1, #0x6d ; NARC_POKETOOL_POKEZUKAN  	mov r2, #0x0  	lsl r3, r3, #0x1  	bl ReadFromNarcMemberByIdPair @@ -6804,7 +6804,7 @@ FUN_02069B60: ; 0x02069B60  	mov r0, #0x2  	str r0, [sp, #0x0]  	add r0, sp, #0x4 -	mov r1, #0x91 +	mov r1, #0x91 ; NARC_POKETOOL_SHINZUKAN  	lsl r3, r3, #0x1  	bl ReadFromNarcMemberByIdPair  _02069B7E: @@ -7396,7 +7396,7 @@ FUN_02069F9C: ; 0x02069F9C  	bl ConvertUnownOrArceusSpecies  	add r2, r0, #0x0  	add r0, r4, #0x0 -	mov r1, #0x21 +	mov r1, #0x21 ; NARC_POKETOOL_PERSONAL_WOTBL  	bl ReadWholeNarcMemberByIdPair  	pop {r4, pc} @@ -7875,7 +7875,7 @@ FUN_0206A370: ; 0x0206A370  	ldr r3, _0206A37C ; =ReadWholeNarcMemberByIdPair  	add r2, r0, #0x0  	add r0, r1, #0x0 -	mov r1, #0x2 +	mov r1, #0x2 ; NARC_POKETOOL_PERSONAL_PERSONAL  	bx r3  	nop  _0206A37C: .word ReadWholeNarcMemberByIdPair @@ -7887,7 +7887,7 @@ FUN_0206A380: ; 0x0206A380  	bl ConvertUnownOrArceusSpecies  	add r2, r0, #0x0  	add r0, r4, #0x0 -	mov r1, #0x2 +	mov r1, #0x2 ; NARC_POKETOOL_PERSONAL_PERSONAL  	bl ReadWholeNarcMemberByIdPair  	pop {r4, pc} @@ -7896,7 +7896,7 @@ FUN_0206A394: ; 0x0206A394  	ldr r3, _0206A3A0 ; =ReadWholeNarcMemberByIdPair  	add r2, r0, #0x0  	add r0, r1, #0x0 -	mov r1, #0x22 +	mov r1, #0x22 ; NARC_POKETOOL_PERSONAL_EVO  	bx r3  	nop  _0206A3A0: .word ReadWholeNarcMemberByIdPair diff --git a/arm9/lib/Makefile b/arm9/lib/Makefile new file mode 100644 index 00000000..c0e95ade --- /dev/null +++ b/arm9/lib/Makefile @@ -0,0 +1,89 @@ + + +# Try to include devkitarm if installed +TOOLCHAIN := $(DEVKITARM) + +ifneq (,$(wildcard $(TOOLCHAIN)/base_tools)) +include $(TOOLCHAIN)/base_tools +endif + +### Default target ### + +default: all + +# If you are using WSL, it is recommended you build with NOWINE=1. +WSLENV ?= no +ifeq ($(WSLENV),) +NOWINE = 1 +else +NOWINE = 0 +endif + +ifeq ($(OS),Windows_NT) +EXE := .exe +WINE := +else +EXE := +WINE := wine +endif + +ifeq ($(NOWINE),1) +WINE := +endif + +# Compare result of arm9, arm7, and ROM to sha1 hash(s) +COMPARE ?= 1 + +##################### Compiler Options ####################### + +MWCCVERSION = 1.2/sp2p3 + +CROSS   := arm-none-eabi- + +MWCCARM  = ../../tools/mwccarm/$(MWCCVERSION)/mwccarm.exe +# Argh... due to EABI version shenanigans, we can't use GNU LD to link together +# MWCC built objects and GNU built ones. mwldarm, however, doesn't care, so we +# have to use mwldarm for now. +# TODO: Is there a hack workaround to let us go back to GNU LD? Ideally, the +# only dependency should be MWCCARM. +MWLDARM  = ../../tools/mwccarm/$(MWCCVERSION)/mwldarm.exe +MWASMARM = ../../tools/mwccarm/$(MWCCVERSION)/mwasmarm.exe +NARCCOMP = ../../tools/narccomp/narccomp$(EXE) +SCANINC = ../../tools/scaninc/scaninc$(EXE) + +AS      = $(WINE) $(MWASMARM) +CC      = $(WINE) $(MWCCARM) +CPP     := cpp -P +LD      = $(WINE) $(MWLDARM) +AR      := $(CROSS)ar +OBJDUMP := $(CROSS)objdump +OBJCOPY := $(CROSS)objcopy + +# ./tools/mwccarm/2.0/base/mwasmarm.exe -proc arm5te asm/arm9_thumb.s -o arm9.o +ASFLAGS = -proc arm5te -ir ../.. +CFLAGS = -O4,p -proc arm946e -fp soft -lang c99 -Cpp_exceptions off -i include -ir include-mw -ir arm9/lib/include -W all +LDFLAGS = -library -nodead -w off -proc v5te -interworking -pic +ARFLAGS = rcS + +export MWCIncludes := include + +################ Targets ################# + +LIBS := libsyscall.a +.PHONY: all clean + +all: $(LIBS) + +clean: +	$(RM) $(LIBS) $(LIBS:%.a=%/*.o) + +libsyscall.a: syscall/_svc_mw.o + +%.a: +	$(AR) $(ARFLAGS) -o $@ $^ + +%.o: %.c +	$(CC) $(CFLAGS) -o $@ $< + +%.o: %.s +	$(AS) $(ASFLAGS) -o $@ $< diff --git a/arm9/lib/syscall/_svc_mw.s b/arm9/lib/syscall/_svc_mw.s new file mode 100644 index 00000000..c1e36b4b --- /dev/null +++ b/arm9/lib/syscall/_svc_mw.s @@ -0,0 +1,121 @@ +	.include "asm/macros.inc" + +	.text +	; NITRO SYSCALL LIBRARY +	; VERSION 3.2 + +	; Secure area +	.space 0x800 + +	non_word_aligned_thumb_func_start SVC_SoftReset +SVC_SoftReset: +	swi 0 +	bx lr +	thumb_func_end SVC_SoftReset + +	non_word_aligned_thumb_func_start SVC_WaitByLoop +SVC_WaitByLoop: +	swi 3 +	bx lr +	thumb_func_end SVC_WaitByLoop + +	non_word_aligned_thumb_func_start SVC_WaitIntr +SVC_WaitIntr: +	mov r2, #0 +	swi 4 +	bx lr +	thumb_func_end SVC_WaitIntr + +	non_word_aligned_thumb_func_start SVC_WaitVBlankIntr +SVC_WaitVBlankIntr: +	mov r2, #0 +	swi 5 +	bx lr +	thumb_func_end SVC_WaitVBlankIntr + +	non_word_aligned_thumb_func_start SVC_Halt +SVC_Halt: +	swi 6 +	bx lr +	thumb_func_end SVC_Halt + +	non_word_aligned_thumb_func_start SVC_Div +SVC_Div: +	swi 9 +	bx lr +	thumb_func_end SVC_Div + +	non_word_aligned_thumb_func_start SVC_DimRem +SVC_DivRem: +	swi 9 +	add r0, r1, #0 +	bx lr +	thumb_func_end SVC_DivRem + +	non_word_aligned_thumb_func_start SVC_CpuSet +SVC_CpuSet: +	swi 11 +	bx lr +	thumb_func_end SVC_CpuSet + +	non_word_aligned_thumb_func_start SVC_CpuFastSet +SVC_CpuFastSet: +	swi 12 +	bx lr +	thumb_func_end SVC_CpuFastSet + +	non_word_aligned_thumb_func_start SVC_Sqrt +SVC_Sqrt: +	swi 13 +	bx lr +	thumb_func_end SVC_Sqrt + +	non_word_aligned_thumb_func_start SVC_GetCRC16 +SVC_GetCRC16: +	swi 14 +	bx lr +	thumb_func_end SVC_GetCRC16 + +	non_word_aligned_thumb_func_start IsMemExpanded +IsMemExpanded: +	swi 15 +	bx lr +	thumb_func_end IsMemExpanded + +	non_word_aligned_thumb_func_start SVC_UnpackBits +SVC_UnpackBits: +	swi 16 +	bx lr +	thumb_func_end SVC_UnpackBits + +	non_word_aligned_thumb_func_start SVC_UncompressLZ8 +SVC_UncompressLZ8: +	swi 17 +	bx lr +	thumb_func_end SVC_UncompressLZ8 + +	non_word_aligned_thumb_func_start SVC_UncompressLZ16FromDevice +SVC_UncompressLZ16FromDevice: +	swi 18 +	bx lr +	thumb_func_end SVC_UncompressLZ16FromDevice + +	non_word_aligned_thumb_func_start SVC_UncompressHuffmanFromDevice +SVC_UncompressHuffmanFromDevice: +	swi 19 +	bx lr +	thumb_func_end SVC_UncompressHuffmanFromDevice + +	non_word_aligned_thumb_func_start SVC_UncompressRL8 +SVC_UncompressRL8: +	swi 20 +	bx lr +	thumb_func_end SVC_UncompressRL8 + +	non_word_aligned_thumb_func_start SVC_UncompressRL16FromDevice +SVC_UncompressRL16FromDevice: +	swi 21 +	bx lr +	thumb_func_end SVC_UncompressRL16FromDevice + +	.balign 4, 0 ; Don't pad with nop diff --git a/arm9/modules/01/src/module_01.cpp b/arm9/modules/01/src/module_01.cpp index 9da5f8d5..1f9f0edc 100644 --- a/arm9/modules/01/src/module_01.cpp +++ b/arm9/modules/01/src/module_01.cpp @@ -1,11 +1,7 @@  #include "global.h" -#include "FS_overlay.h" +#include "sinit.h" -class Unk021D7500 { -    u32 unk0; -    u32 unk4; -public: -    THUMB_FUNC Unk021D7500() { unk4++; } -}; - -static Unk021D7500 UNK_021D7500; +THUMB_FUNC static void NitroStaticInit(void) { +    static u32 var[2]; +    var[1]++; +} | 
