summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartmists <martmists@gmail.com>2020-04-11 22:27:52 +0200
committerMartmists <martmists@gmail.com>2020-04-11 22:27:52 +0200
commit01801ea04f2a03a1fb9e9a6e08bcd00fa22a73c0 (patch)
tree397f9fd6ef52b05ea97900ad5feaa814a4869c11
parent876d5c3812657b8723a684a41111cd8695eddc70 (diff)
Add buildable stuff
-rw-r--r--INSTALL.md12
-rw-r--r--Makefile79
-rw-r--r--README.md4
-rw-r--r--asm/rom.s5
-rw-r--r--asm/rom_header.s115
-rw-r--r--pokediamond.lcf16
6 files changed, 227 insertions, 4 deletions
diff --git a/INSTALL.md b/INSTALL.md
index 4c84c23b..05073d81 100644
--- a/INSTALL.md
+++ b/INSTALL.md
@@ -1,7 +1,13 @@
-# Prerequisites
+#### 1. Copy baserom(s) into root folder
-# Installation
+Put a clean copy of Pokemon Diamond (US) nds rom at `./baserom.us.nds`.
-# Notes
+#### 2. Install MWCC compiler
+The build system requires the use of the Metrowerk C Compiler 2.0/base to compile matching files. We cannot distribute the correct compiler here so join the PRET discord and download the pinned mwccarm.zip zip in #pokediamond and extract it to tools/. Run each of the executables so they ask for a license.dat and provide the one in the rar (it may also ask for it when compiling). This only needs to be done once.
+In the future, a GCC option will be available so MWCC is not required to build, however it is required for a matching ROM.
+
+#### 3. Build ROM
+
+Run `make` to build the ROM. \ No newline at end of file
diff --git a/Makefile b/Makefile
new file mode 100644
index 00000000..03388c21
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,79 @@
+# Makefile to build Pokemon Diamond image
+
+### Default target ###
+
+default: all
+
+################ Target Executable and Sources ###############
+
+BUILD_DIR := build
+
+TARGET := pokediamond.us
+
+ROM := $(BUILD_DIR)/$(TARGET).nds
+ELF := $(BUILD_DIR)/$(TARGET).elf
+LD_SCRIPT := pokediamond.lcf
+
+# Directories containing source files
+SRC_DIRS := src
+ASM_DIRS := asm
+
+C_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.c))
+S_FILES := $(foreach dir,$(ASM_DIRS),$(wildcard $(dir)/*.s))
+
+# Object files
+O_FILES := $(foreach file,$(C_FILES),$(BUILD_DIR)/$(file:.c=.o)) \
+ $(foreach file,$(S_FILES),$(BUILD_DIR)/$(file:.s=.o)) \
+
+##################### Compiler Options #######################
+
+MWCCVERSION := 2.0/base
+
+CROSS := arm-linux-gnueabi-
+
+# TODO: Replace mwldarm with gnu ld
+
+MWLDARM := ./tools/mwccarm/$(MWCCVERSION)/mwldarm.exe
+MWCCARM := ./tools/mwccarm/$(MWCCVERSION)/mwccarm.exe
+
+AS := $(CROSS)as
+CC := $(MWCCARM)
+CPP := cpp -P
+LD := $(MWLDARM)
+AR := $(CROSS)ar
+OBJDUMP := $(CROSS)objdump
+OBJCOPY := $(CROSS)objcopy
+
+CFLAGS = -c -O4,p -proc arm946e -thumb -fp soft -lang c -Cpp_exceptions off
+
+####################### Other Tools #########################
+
+# DS TOOLS
+TOOLS_DIR = tools
+SHA1SUM = sha1sum
+
+######################### Targets ###########################
+
+all: $(ROM)
+ @$(SHA1SUM) -c $(TARGET).sha1
+
+clean:
+ $(RM) -r $(BUILD_DIR)
+
+ALL_DIRS := $(BUILD_DIR) $(addprefix $(BUILD_DIR)/,$(SRC_DIRS) $(ASM_DIRS))
+
+$(BUILD_DIR)/%.o: %.s
+ $(AS) $(ASFLAGS) -MD $(BUILD_DIR)/$*.d -o $@ $<
+
+$(ELF): $(O_FILES) $(LD_SCRIPT)
+ $(MWLDARM) -LC:/pokediamond/$(BUILD_DIR)/asm/ $(O_FILES) $(LD_SCRIPT) -o $@ -nodead
+
+$(ROM): $(ELF)
+ $(OBJCOPY) -O binary $< $@
+
+# Make sure build directory exists before compiling anything
+DUMMY != mkdir -p $(ALL_DIRS)
+
+### Debug Print ###
+
+print-% : ; $(info $* is a $(flavor $*) variable set to [$($*)]) @true
diff --git a/README.md b/README.md
index a6341a91..bc6fe58b 100644
--- a/README.md
+++ b/README.md
@@ -30,5 +30,7 @@ Gen 4 decompilation projects:
## Contacts
-You can find us on [Discord (#decomp)](https://discord.gg/prUAgd5).
+You can find us on:
+* [Discord (VoidMatrix, #decomp)](https://discord.gg/prUAgd5).
+* [Discord (PRET, #pokediamond)](https://discord.gg/d5dubZ3)
diff --git a/asm/rom.s b/asm/rom.s
new file mode 100644
index 00000000..618c24a6
--- /dev/null
+++ b/asm/rom.s
@@ -0,0 +1,5 @@
+/* rom.s TODO: Disassemble */
+
+.section .text
+
+.incbin "baserom.nds", 0x200, 0x3FFFE00
diff --git a/asm/rom_header.s b/asm/rom_header.s
new file mode 100644
index 00000000..e850d0f8
--- /dev/null
+++ b/asm/rom_header.s
@@ -0,0 +1,115 @@
+/* ROM HEADER for Pokemon Diamond (US) */
+
+.section .text
+
+.balign 4
+GameTitle:
+.asciz "POKEMON D"
+
+.balign 4
+GameCode:
+.ascii "ADAE"
+
+MakerCode:
+.ascii "01"
+
+UnitCode:
+.byte 0
+DeviceType:
+.byte 0
+DeviceCapacity:
+.byte 9
+/*reserved*/
+.space 9
+
+RomVersion:
+.byte 5
+
+/*reserved*/
+.space 1
+
+ARM9ROMOffset:
+.word 0x00004000
+ARM9EntryAddress:
+.word 0x02000800
+ARM9RAMAddress:
+.word 0x02000000
+ARM9CodeSize:
+.word 0x00107724
+ARM7ROMOffset:
+.word 0x0030D000
+ARM7EntryAddress:
+.word 0x02380000
+ARM7RAMAddress:
+.word 0x02380000
+ARM7CodeSize:
+.word 0x0002931C
+FileNameTableOffset:
+.word 0x00336400
+FileNameTableSize:
+.word 0x0000157F
+FATOffset:
+.word 0x00337A00
+FATSize:
+.word 0x00000B20
+ARM9OverlayOffset:
+.word 0x0010B800
+ARM9OverlaySize:
+.word 0x00000AE0
+ARM7OverlayOffset:
+.word 0x00000000
+ARM7OverlaySize:
+.word 0x00000000
+ROMControlInfo1:
+.word 0x00416657
+ROMControlInfo2:
+.word 0x081808F8
+IconTitleOffset:
+.word 0x00338600
+SecureAreaCC:
+.short 0x5931
+ROMControlInfo3:
+.short 0x0D7E
+ARM9AutoLoadHook:
+.word 0x02000A74
+ARM7AutoLoadHook:
+.word 0x02380158
+SecureAreaDisable:
+.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+ApplicationEndOffset:
+.word 0x03A55EC0
+ROMHeaderSize:
+.word 0x00004000
+
+/* should be 36 bytes here but again theres stuff here. TODO: Identify */
+.byte 0x68, 0x4B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+.byte 0x00, 0x00, 0x00, 0x00
+
+PassMeAutobootDetect:
+.word 0x00000000
+
+/* reserved */
+.space 16
+
+NintendoLogo:
+.byte 0x24, 0xFF, 0xAE, 0x51, 0x69, 0x9A, 0xA2, 0x21, 0x3D, 0x84, 0x82, 0x0A, 0x84, 0xE4, 0x09, 0xAD
+.byte 0x11, 0x24, 0x8B, 0x98, 0xC0, 0x81, 0x7F, 0x21, 0xA3, 0x52, 0xBE, 0x19, 0x93, 0x09, 0xCE, 0x20
+.byte 0x10, 0x46, 0x4A, 0x4A, 0xF8, 0x27, 0x31, 0xEC, 0x58, 0xC7, 0xE8, 0x33, 0x82, 0xE3, 0xCE, 0xBF
+.byte 0x85, 0xF4, 0xDF, 0x94, 0xCE, 0x4B, 0x09, 0xC1, 0x94, 0x56, 0x8A, 0xC0, 0x13, 0x72, 0xA7, 0xFC
+.byte 0x9F, 0x84, 0x4D, 0x73, 0xA3, 0xCA, 0x9A, 0x61, 0x58, 0x97, 0xA3, 0x27, 0xFC, 0x03, 0x98, 0x76
+.byte 0x23, 0x1D, 0xC7, 0x61, 0x03, 0x04, 0xAE, 0x56, 0xBF, 0x38, 0x84, 0x00, 0x40, 0xA7, 0x0E, 0xFD
+.byte 0xFF, 0x52, 0xFE, 0x03, 0x6F, 0x95, 0x30, 0xF1, 0x97, 0xFB, 0xC0, 0x85, 0x60, 0xD6, 0x80, 0x25
+.byte 0xA9, 0x63, 0xBE, 0x03, 0x01, 0x4E, 0x38, 0xE2, 0xF9, 0xA2, 0x34, 0xFF, 0xBB, 0x3E, 0x03, 0x44
+.byte 0x78, 0x00, 0x90, 0xCB, 0x88, 0x11, 0x3A, 0x94, 0x65, 0xC0, 0x7C, 0x63, 0x87, 0xF0, 0x3C, 0xAF
+.byte 0xD6, 0x25, 0xE4, 0x8B, 0x38, 0x0A, 0xAC, 0x72, 0x21, 0xD4, 0xF8, 0x07
+
+LogoCRC:
+.short 0xCF56
+HeaderCRC:
+.short 0xCA37
+
+/* reserved */
+.global __startup
+__startup:
+.space 160 /* hack so it builds */
diff --git a/pokediamond.lcf b/pokediamond.lcf
new file mode 100644
index 00000000..e398b286
--- /dev/null
+++ b/pokediamond.lcf
@@ -0,0 +1,16 @@
+/* Linker Script for Pokemon Diamond */
+
+MEMORY {
+ header (RWX) : ORIGIN=0, LENGTH=0
+ rom_main (RWX) : ORIGIN=512, LENGTH=0
+}
+
+SECTIONS {
+ .header:{
+ rom_header.o (.text)
+ } > header
+
+ .rom_main:{
+ rom.o (.text)
+ } > rom_main
+}