├── .gitignore ├── BootSplash ├── Bot00.bmp ├── Bot01.bmp ├── Bot02.bmp ├── Bot03.bmp ├── Bot04.bmp ├── Bot05.bmp ├── Bot06.bmp ├── Bot07.bmp ├── Bot08.bmp ├── Bot09.bmp ├── Bot10.bmp ├── DSi18.bmp ├── DSi19.bmp ├── DSi20.bmp ├── DSi21.bmp ├── DSi22.bmp ├── DSi23.bmp ├── DSi24.bmp ├── DSi25.bmp ├── DSi26.bmp ├── DSi27.bmp ├── DSi28.bmp ├── DSi29.bmp ├── DSi30.bmp ├── DSi31.bmp ├── DSi32.bmp ├── DSi33.bmp ├── DSi34.bmp ├── DSi35.bmp ├── DSi36.bmp ├── Top00.bmp ├── Top01.bmp ├── Top02.bmp ├── Top03.bmp ├── Top04.bmp ├── Top05.bmp ├── Top06.bmp ├── Top07.bmp ├── Top08.bmp ├── Top09.bmp ├── Top10.bmp ├── Top11.bmp ├── Top12.bmp ├── Top13.bmp ├── Top14.bmp ├── Top15.bmp ├── Top16.bmp ├── Top17.bmp ├── Top18.bmp ├── Top19.bmp ├── Top20.bmp ├── Top21.bmp ├── Top22.bmp ├── Top23.bmp ├── Top24.bmp ├── Top25.bmp ├── Top26.bmp ├── Top27.bmp ├── Top28.bmp ├── Top29.bmp ├── Top30.bmp ├── Top31.bmp ├── Top32.bmp ├── Top33.bmp ├── Top34.bmp ├── Top35.bmp ├── Top36.bmp └── Top37.bmp ├── BootStrap ├── EZ5V2.dldi ├── Makefile ├── README.TXT ├── TTCARDIOLibrary.dldi ├── ak2_sd.dldi ├── arm7 │ ├── Makefile │ ├── ds_arm7_ram.ld │ ├── ds_arm7_ram.specs │ └── source │ │ └── template.c ├── arm9 │ ├── Makefile │ └── source │ │ └── bootstrap.c ├── mpcf.dldi └── r4tfv2.dldi ├── COPYING ├── HomebrewMenu.pnproj ├── HomebrewMenu.pnps ├── Makefile ├── README.md ├── arm7 ├── Makefile ├── ds_arm7_ram.ld ├── ds_arm7_ram.specs └── source │ └── main.c ├── arm9 ├── Makefile └── source │ ├── bios_decompress_callback.c │ ├── bios_decompress_callback.h │ ├── bootsplash.cpp │ ├── bootsplash.h │ ├── file_browse.cpp │ ├── file_browse.h │ ├── iconTitle.c │ ├── iconTitle.h │ ├── inifile.cpp │ ├── inifile.h │ ├── main.cpp │ ├── nds_loader_arm9.c │ ├── nds_loader_arm9.h │ ├── stringtool.cpp │ └── stringtool.h ├── bootloader ├── Makefile ├── load.ld └── source │ ├── arm7clear.s │ ├── arm9clear.arm.c │ ├── bios.s │ ├── boot.c │ ├── boot.h │ ├── card.h │ ├── disc_io.h │ ├── dldi_patcher.c │ ├── dldi_patcher.h │ ├── fat.c │ ├── fat.h │ ├── io_dldi.h │ ├── io_dldi.s │ ├── load_crt0.s │ ├── sdmmc.c │ └── sdmmc.h ├── bootstub ├── Makefile └── bootstub.s ├── build_cia.bat ├── build_cia.sh ├── conf └── hbmenu.ini ├── dlditool.exe ├── exclude.lst ├── gfx ├── font6x8.grit ├── font6x8.png ├── hbmenu_banner.grit └── hbmenu_banner.png ├── icon.bmp ├── license.txt ├── make_cia.exe ├── music ├── dsboot.wav └── dsiboot.wav ├── patch_ndsheader_dsiware.py ├── resources └── hbmenu_banner.xcf └── testfiles ├── argvTest.nds ├── test1.argv └── test2.argv /.gitignore: -------------------------------------------------------------------------------- 1 | *.DAT 2 | *.NDS 3 | *.nds 4 | *.elf 5 | *.bin 6 | *.bz2 7 | bootloader/build 8 | BootStrap/arm7/build 9 | BootStrap/arm9/build 10 | data 11 | build 12 | *.cia 13 | nds-hb-menu.nds_header.txt 14 | nds-hb-menu-dsi.nds_header.txt 15 | bootstrap.nds_after_patch_header.txt 16 | bootstrap.nds_before_patch_header.txt 17 | nds-hb-menu-dsiTest_header.txt 18 | VBinDiff.exe 19 | nds-hb-menu.nds_header.txt 20 | nds-hb-menu.nds_header.txt 21 | nds-hb-menu-ds.nds_header.txt 22 | nds-hb-menu.nds_header.txt 23 | -------------------------------------------------------------------------------- /BootSplash/Bot00.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Bot00.bmp -------------------------------------------------------------------------------- /BootSplash/Bot01.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Bot01.bmp -------------------------------------------------------------------------------- /BootSplash/Bot02.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Bot02.bmp -------------------------------------------------------------------------------- /BootSplash/Bot03.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Bot03.bmp -------------------------------------------------------------------------------- /BootSplash/Bot04.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Bot04.bmp -------------------------------------------------------------------------------- /BootSplash/Bot05.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Bot05.bmp -------------------------------------------------------------------------------- /BootSplash/Bot06.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Bot06.bmp -------------------------------------------------------------------------------- /BootSplash/Bot07.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Bot07.bmp -------------------------------------------------------------------------------- /BootSplash/Bot08.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Bot08.bmp -------------------------------------------------------------------------------- /BootSplash/Bot09.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Bot09.bmp -------------------------------------------------------------------------------- /BootSplash/Bot10.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Bot10.bmp -------------------------------------------------------------------------------- /BootSplash/DSi18.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/DSi18.bmp -------------------------------------------------------------------------------- /BootSplash/DSi19.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/DSi19.bmp -------------------------------------------------------------------------------- /BootSplash/DSi20.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/DSi20.bmp -------------------------------------------------------------------------------- /BootSplash/DSi21.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/DSi21.bmp -------------------------------------------------------------------------------- /BootSplash/DSi22.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/DSi22.bmp -------------------------------------------------------------------------------- /BootSplash/DSi23.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/DSi23.bmp -------------------------------------------------------------------------------- /BootSplash/DSi24.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/DSi24.bmp -------------------------------------------------------------------------------- /BootSplash/DSi25.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/DSi25.bmp -------------------------------------------------------------------------------- /BootSplash/DSi26.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/DSi26.bmp -------------------------------------------------------------------------------- /BootSplash/DSi27.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/DSi27.bmp -------------------------------------------------------------------------------- /BootSplash/DSi28.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/DSi28.bmp -------------------------------------------------------------------------------- /BootSplash/DSi29.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/DSi29.bmp -------------------------------------------------------------------------------- /BootSplash/DSi30.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/DSi30.bmp -------------------------------------------------------------------------------- /BootSplash/DSi31.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/DSi31.bmp -------------------------------------------------------------------------------- /BootSplash/DSi32.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/DSi32.bmp -------------------------------------------------------------------------------- /BootSplash/DSi33.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/DSi33.bmp -------------------------------------------------------------------------------- /BootSplash/DSi34.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/DSi34.bmp -------------------------------------------------------------------------------- /BootSplash/DSi35.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/DSi35.bmp -------------------------------------------------------------------------------- /BootSplash/DSi36.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/DSi36.bmp -------------------------------------------------------------------------------- /BootSplash/Top00.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Top00.bmp -------------------------------------------------------------------------------- /BootSplash/Top01.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Top01.bmp -------------------------------------------------------------------------------- /BootSplash/Top02.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Top02.bmp -------------------------------------------------------------------------------- /BootSplash/Top03.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Top03.bmp -------------------------------------------------------------------------------- /BootSplash/Top04.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Top04.bmp -------------------------------------------------------------------------------- /BootSplash/Top05.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Top05.bmp -------------------------------------------------------------------------------- /BootSplash/Top06.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Top06.bmp -------------------------------------------------------------------------------- /BootSplash/Top07.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Top07.bmp -------------------------------------------------------------------------------- /BootSplash/Top08.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Top08.bmp -------------------------------------------------------------------------------- /BootSplash/Top09.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Top09.bmp -------------------------------------------------------------------------------- /BootSplash/Top10.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Top10.bmp -------------------------------------------------------------------------------- /BootSplash/Top11.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Top11.bmp -------------------------------------------------------------------------------- /BootSplash/Top12.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Top12.bmp -------------------------------------------------------------------------------- /BootSplash/Top13.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Top13.bmp -------------------------------------------------------------------------------- /BootSplash/Top14.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Top14.bmp -------------------------------------------------------------------------------- /BootSplash/Top15.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Top15.bmp -------------------------------------------------------------------------------- /BootSplash/Top16.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Top16.bmp -------------------------------------------------------------------------------- /BootSplash/Top17.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Top17.bmp -------------------------------------------------------------------------------- /BootSplash/Top18.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Top18.bmp -------------------------------------------------------------------------------- /BootSplash/Top19.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Top19.bmp -------------------------------------------------------------------------------- /BootSplash/Top20.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Top20.bmp -------------------------------------------------------------------------------- /BootSplash/Top21.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Top21.bmp -------------------------------------------------------------------------------- /BootSplash/Top22.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Top22.bmp -------------------------------------------------------------------------------- /BootSplash/Top23.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Top23.bmp -------------------------------------------------------------------------------- /BootSplash/Top24.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Top24.bmp -------------------------------------------------------------------------------- /BootSplash/Top25.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Top25.bmp -------------------------------------------------------------------------------- /BootSplash/Top26.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Top26.bmp -------------------------------------------------------------------------------- /BootSplash/Top27.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Top27.bmp -------------------------------------------------------------------------------- /BootSplash/Top28.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Top28.bmp -------------------------------------------------------------------------------- /BootSplash/Top29.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Top29.bmp -------------------------------------------------------------------------------- /BootSplash/Top30.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Top30.bmp -------------------------------------------------------------------------------- /BootSplash/Top31.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Top31.bmp -------------------------------------------------------------------------------- /BootSplash/Top32.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Top32.bmp -------------------------------------------------------------------------------- /BootSplash/Top33.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Top33.bmp -------------------------------------------------------------------------------- /BootSplash/Top34.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Top34.bmp -------------------------------------------------------------------------------- /BootSplash/Top35.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Top35.bmp -------------------------------------------------------------------------------- /BootSplash/Top36.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Top36.bmp -------------------------------------------------------------------------------- /BootSplash/Top37.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootSplash/Top37.bmp -------------------------------------------------------------------------------- /BootStrap/EZ5V2.dldi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootStrap/EZ5V2.dldi -------------------------------------------------------------------------------- /BootStrap/Makefile: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------- 2 | .SUFFIXES: 3 | #--------------------------------------------------------------------------------- 4 | ifeq ($(strip $(DEVKITARM)),) 5 | $(error "Please set DEVKITARM in your environment. export DEVKITARM=devkitARM") 6 | endif 7 | 8 | include $(DEVKITARM)/ds_rules 9 | 10 | export TARGET := bootstrap 11 | export TOPDIR := $(CURDIR) 12 | 13 | 14 | .PHONY: $(TARGET).arm7.elf $(TARGET).arm9.elf 15 | 16 | #--------------------------------------------------------------------------------- 17 | # main targets 18 | #--------------------------------------------------------------------------------- 19 | all: _DS_MENU.DAT ez5sys.bin akmenu4.nds TTMENU.DAT _BOOT_MP.NDS 20 | 21 | _DS_MENU.DAT : $(TARGET).nds 22 | @dlditool r4tfv2.dldi $< 23 | @r4denc $< $@ 24 | 25 | ez5sys.bin : $(TARGET).nds 26 | @cp $< $@ 27 | @dlditool EZ5V2.dldi $@ 28 | 29 | akmenu4.nds : $(TARGET).nds 30 | @cp $< $@ 31 | @dlditool ak2_sd.dldi $@ 32 | 33 | TTMENU.DAT : $(TARGET).nds 34 | @cp $< $@ 35 | @dlditool TTCARDIOLibrary.dldi $@ 36 | 37 | _BOOT_MP.NDS : $(TARGET).nds 38 | @cp $< $@ 39 | @dlditool mpcf.dldi $@ 40 | 41 | 42 | 43 | #--------------------------------------------------------------------------------- 44 | $(TARGET).nds : $(TARGET).arm7.elf $(TARGET).arm9.elf 45 | ndstool -c $(TARGET).nds -7 $(TARGET).arm7.elf -9 $(TARGET).arm9.elf 46 | 47 | #--------------------------------------------------------------------------------- 48 | $(TARGET).arm7.elf: 49 | $(MAKE) -C arm7 50 | 51 | #--------------------------------------------------------------------------------- 52 | $(TARGET).arm9.elf: 53 | $(MAKE) -C arm9 54 | 55 | #--------------------------------------------------------------------------------- 56 | clean: 57 | $(MAKE) -C arm9 clean 58 | $(MAKE) -C arm7 clean 59 | rm -f $(TARGET).nds $(TARGET).arm7.elf $(TARGET).arm9.elf _DS_MENU.DAT ez5sys.bin akmenu4.nds TTMENU.DAT _BOOT_MP.NDS 60 | 61 | -------------------------------------------------------------------------------- /BootStrap/README.TXT: -------------------------------------------------------------------------------- 1 | This subfolder builds bootstrap code for some popular DS flash cards and should be reasonably easy to modify for others. Essentially it's just a matter of patching the bootstrap code with the appropriate dldi. 2 | 3 | The main issues users will have here is where the card menu is encrypted in some way or if the supplied dldi has been built with arm9 code. Hbmenu uses the arm7 to load code in order to allow the maximum use of memory. 4 | 5 | The encoder/decoder for the R4 menu is available in devkitPro svn. 6 | 7 | svn co https://devkitpro.svn.sourceforge.net/svnroot/devkitpro/trunk/projects/tools/r4denc r4denc 8 | 9 | compile this and place it somewhere in your path. -------------------------------------------------------------------------------- /BootStrap/TTCARDIOLibrary.dldi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootStrap/TTCARDIOLibrary.dldi -------------------------------------------------------------------------------- /BootStrap/ak2_sd.dldi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootStrap/ak2_sd.dldi -------------------------------------------------------------------------------- /BootStrap/arm7/Makefile: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------- 2 | .SUFFIXES: 3 | #--------------------------------------------------------------------------------- 4 | ifeq ($(strip $(DEVKITARM)),) 5 | $(error "Please set DEVKITARM in your environment. export DEVKITARM=devkitARM") 6 | endif 7 | 8 | include $(DEVKITARM)/ds_rules 9 | 10 | #--------------------------------------------------------------------------------- 11 | # BUILD is the directory where object files & intermediate files will be placed 12 | # SOURCES is a list of directories containing source code 13 | # INCLUDES is a list of directories containing extra header files 14 | # DATA is a list of directories containing binary files 15 | # all directories are relative to this makefile 16 | #--------------------------------------------------------------------------------- 17 | BUILD := build 18 | SOURCES := source 19 | INCLUDES := include build 20 | DATA := 21 | 22 | #--------------------------------------------------------------------------------- 23 | # options for code generation 24 | #--------------------------------------------------------------------------------- 25 | ARCH := -mthumb-interwork 26 | 27 | CFLAGS := -g -Wall -O2\ 28 | -mcpu=arm7tdmi -mtune=arm7tdmi -fomit-frame-pointer\ 29 | -ffast-math \ 30 | $(ARCH) 31 | 32 | CFLAGS += $(INCLUDE) -DARM7 33 | CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -fno-rtti 34 | 35 | 36 | ASFLAGS := -g $(ARCH) 37 | LDFLAGS = -specs=../ds_arm7_ram.specs -g $(ARCH) -Wl,-Map,$(TARGET).map -Wl,--section-start,.init=0x2380000 38 | 39 | LIBS := -lnds7 40 | 41 | #--------------------------------------------------------------------------------- 42 | # list of directories containing libraries, this must be the top level containing 43 | # include and lib 44 | #--------------------------------------------------------------------------------- 45 | LIBDIRS := $(LIBNDS) 46 | 47 | 48 | #--------------------------------------------------------------------------------- 49 | # no real need to edit anything past this point unless you need to add additional 50 | # rules for different file extensions 51 | #--------------------------------------------------------------------------------- 52 | ifneq ($(BUILD),$(notdir $(CURDIR))) 53 | #--------------------------------------------------------------------------------- 54 | 55 | export ARM7ELF := $(TOPDIR)/$(TARGET).arm7.elf 56 | export DEPSDIR := $(CURDIR)/$(BUILD) 57 | 58 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) 59 | 60 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 61 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 62 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 63 | BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) 64 | 65 | export OFILES := $(addsuffix .o,$(BINFILES)) \ 66 | $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) 67 | 68 | export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ 69 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 70 | -I$(CURDIR)/$(BUILD) 71 | 72 | export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) 73 | 74 | #--------------------------------------------------------------------------------- 75 | # use CXX for linking C++ projects, CC for standard C 76 | #--------------------------------------------------------------------------------- 77 | ifeq ($(strip $(CPPFILES)),) 78 | #--------------------------------------------------------------------------------- 79 | export LD := $(CC) 80 | #--------------------------------------------------------------------------------- 81 | else 82 | #--------------------------------------------------------------------------------- 83 | export LD := $(CXX) 84 | #--------------------------------------------------------------------------------- 85 | endif 86 | #--------------------------------------------------------------------------------- 87 | 88 | .PHONY: $(BUILD) clean 89 | 90 | #--------------------------------------------------------------------------------- 91 | $(BUILD): 92 | @[ -d $@ ] || mkdir -p $@ 93 | @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 94 | 95 | #--------------------------------------------------------------------------------- 96 | clean: 97 | @echo clean ... 98 | @rm -fr $(BUILD) *.elf 99 | 100 | 101 | #--------------------------------------------------------------------------------- 102 | else 103 | 104 | DEPENDS := $(OFILES:.o=.d) 105 | 106 | #--------------------------------------------------------------------------------- 107 | # main targets 108 | #--------------------------------------------------------------------------------- 109 | $(ARM7ELF) : $(OFILES) 110 | @echo linking $(notdir $@) 111 | @$(LD) $(LDFLAGS) $(OFILES) $(LIBPATHS) $(LIBS) -o $@ 112 | 113 | 114 | #--------------------------------------------------------------------------------- 115 | # you need a rule like this for each extension you use as binary data 116 | #--------------------------------------------------------------------------------- 117 | %.bin.o : %.bin 118 | #--------------------------------------------------------------------------------- 119 | @echo $(notdir $<) 120 | @$(bin2o) 121 | 122 | -include $(DEPENDS) 123 | 124 | #--------------------------------------------------------------------------------------- 125 | endif 126 | #--------------------------------------------------------------------------------------- -------------------------------------------------------------------------------- /BootStrap/arm7/ds_arm7_ram.ld: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm") 2 | OUTPUT_ARCH(arm) 3 | ENTRY(_start) 4 | 5 | MEMORY { 6 | rom : ORIGIN = 0x08000000, LENGTH = 32M 7 | ram : ORIGIN = 0x2380000, LENGTH = 128K 8 | iwram : ORIGIN = 0x037f8000, LENGTH = 96K 9 | } 10 | 11 | __iwram_start = ORIGIN(iwram); 12 | __iwram_top = ORIGIN(iwram)+ LENGTH(iwram); 13 | 14 | __sp_irq = __iwram_top - 0x100; 15 | __sp_svc = __sp_irq - 0x100; 16 | __sp_usr = __sp_svc - 0x100; 17 | 18 | __irq_flags = 0x04000000 - 8; 19 | __irq_flagsaux = 0x04000000 - 0x40; 20 | __irq_vector = 0x04000000 - 4; 21 | 22 | SECTIONS 23 | { 24 | .init : 25 | { 26 | __text_start = . ; 27 | KEEP (*(.init)) 28 | . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ 29 | } >ram = 0xff 30 | .plt : { *(.plt) } >ram = 0xff 31 | 32 | .text : /* ALIGN (4): */ 33 | { 34 | *(.text .stub .text.* .gnu.linkonce.t.*) 35 | KEEP (*(.text.*personality*)) 36 | /* .gnu.warning sections are handled specially by elf32.em. */ 37 | *(.gnu.warning) 38 | *(.glue_7t) *(.glue_7) *(.vfp11_veneer) 39 | . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ 40 | } >ram = 0xff 41 | 42 | .fini : 43 | { 44 | KEEP (*(.fini)) 45 | } >ram =0xff 46 | 47 | __text_end = . ; 48 | 49 | .rodata : 50 | { 51 | *(.rodata) 52 | *all.rodata*(*) 53 | *(.roda) 54 | *(.rodata.*) 55 | *(.gnu.linkonce.r*) 56 | SORT(CONSTRUCTORS) 57 | . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ 58 | } >ram = 0xff 59 | 60 | .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >ram 61 | __exidx_start = .; 62 | .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } >ram 63 | __exidx_end = .; 64 | 65 | /* Ensure the __preinit_array_start label is properly aligned. We 66 | could instead move the label definition inside the section, but 67 | the linker would then create the section even if it turns out to 68 | be empty, which isn't pretty. */ 69 | . = ALIGN(32 / 8); 70 | PROVIDE (__preinit_array_start = .); 71 | .preinit_array : { KEEP (*(.preinit_array)) } >ram = 0xff 72 | PROVIDE (__preinit_array_end = .); 73 | PROVIDE (__init_array_start = .); 74 | .init_array : { KEEP (*(.init_array)) } >ram = 0xff 75 | PROVIDE (__init_array_end = .); 76 | PROVIDE (__fini_array_start = .); 77 | .fini_array : { KEEP (*(.fini_array)) } >ram = 0xff 78 | PROVIDE (__fini_array_end = .); 79 | 80 | .ctors : 81 | { 82 | /* gcc uses crtbegin.o to find the start of the constructors, so 83 | we make sure it is first. Because this is a wildcard, it 84 | doesn't matter if the user does not actually link against 85 | crtbegin.o; the linker won't look for a file to match a 86 | wildcard. The wildcard also means that it doesn't matter which 87 | directory crtbegin.o is in. */ 88 | KEEP (*crtbegin.o(.ctors)) 89 | KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors)) 90 | KEEP (*(SORT(.ctors.*))) 91 | KEEP (*(.ctors)) 92 | . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ 93 | } >ram = 0xff 94 | 95 | .dtors : 96 | { 97 | KEEP (*crtbegin.o(.dtors)) 98 | KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors)) 99 | KEEP (*(SORT(.dtors.*))) 100 | KEEP (*(.dtors)) 101 | . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ 102 | } >ram = 0xff 103 | 104 | .eh_frame : 105 | { 106 | KEEP (*(.eh_frame)) 107 | . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ 108 | } >ram = 0xff 109 | 110 | .gcc_except_table : 111 | { 112 | *(.gcc_except_table) 113 | . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ 114 | } >ram = 0xff 115 | .jcr : { KEEP (*(.jcr)) } >ram = 0 116 | .got : { *(.got.plt) *(.got) } >ram = 0 117 | 118 | .data ALIGN(4) : { 119 | __data_start = ABSOLUTE(.); 120 | *(.data) 121 | *(.data.*) 122 | *(.gnu.linkonce.d*) 123 | CONSTRUCTORS 124 | . = ALIGN(4); 125 | __data_end = ABSOLUTE(.) ; 126 | } >ram = 0xff 127 | 128 | .bss ALIGN(4) : 129 | { 130 | __bss_start = ABSOLUTE(.); 131 | __bss_start__ = ABSOLUTE(.); 132 | *(.dynbss) 133 | *(.gnu.linkonce.b*) 134 | *(.bss*) 135 | *(COMMON) 136 | . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ 137 | __bss_end__ = ABSOLUTE(.); 138 | __end__ = ABSOLUTE(.); 139 | } >ram 140 | 141 | /* Stabs debugging sections. */ 142 | .stab 0 : { *(.stab) } 143 | .stabstr 0 : { *(.stabstr) } 144 | .stab.excl 0 : { *(.stab.excl) } 145 | .stab.exclstr 0 : { *(.stab.exclstr) } 146 | .stab.index 0 : { *(.stab.index) } 147 | .stab.indexstr 0 : { *(.stab.indexstr) } 148 | .comment 0 : { *(.comment) } 149 | /* DWARF debug sections. 150 | Symbols in the DWARF debugging sections are relative to the beginning 151 | of the section so we begin them at 0. */ 152 | /* DWARF 1 */ 153 | .debug 0 : { *(.debug) } 154 | .line 0 : { *(.line) } 155 | /* GNU DWARF 1 extensions */ 156 | .debug_srcinfo 0 : { *(.debug_srcinfo) } 157 | .debug_sfnames 0 : { *(.debug_sfnames) } 158 | /* DWARF 1.1 and DWARF 2 */ 159 | .debug_aranges 0 : { *(.debug_aranges) } 160 | .debug_pubnames 0 : { *(.debug_pubnames) } 161 | /* DWARF 2 */ 162 | .debug_info 0 : { *(.debug_info) } 163 | .debug_abbrev 0 : { *(.debug_abbrev) } 164 | .debug_line 0 : { *(.debug_line) } 165 | .debug_frame 0 : { *(.debug_frame) } 166 | .debug_str 0 : { *(.debug_str) } 167 | .debug_loc 0 : { *(.debug_loc) } 168 | .debug_macinfo 0 : { *(.debug_macinfo) } 169 | /* SGI/MIPS DWARF 2 extensions */ 170 | .debug_weaknames 0 : { *(.debug_weaknames) } 171 | .debug_funcnames 0 : { *(.debug_funcnames) } 172 | .debug_typenames 0 : { *(.debug_typenames) } 173 | .debug_varnames 0 : { *(.debug_varnames) } 174 | .stack 0x80000 : { _stack = .; *(.stack) } 175 | /* These must appear regardless of . */ 176 | } 177 | -------------------------------------------------------------------------------- /BootStrap/arm7/ds_arm7_ram.specs: -------------------------------------------------------------------------------- 1 | %rename link old_link 2 | 3 | *link: 4 | %(old_link) -T ../ds_arm7_ram.ld%s --gc-sections 5 | 6 | *startfile: 7 | ds_arm7_crt0%O%s crti%O%s crtbegin%O%s 8 | 9 | -------------------------------------------------------------------------------- /BootStrap/arm7/source/template.c: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------------- 2 | 3 | default ARM7 core 4 | 5 | Copyright (C) 2005 - 2010 6 | Michael Noland (joat) 7 | Jason Rogers (dovoto) 8 | Dave Murphy (WinterMute) 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any 12 | damages arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any 15 | purpose, including commercial applications, and to alter it and 16 | redistribute it freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you 19 | must not claim that you wrote the original software. If you use 20 | this software in a product, an acknowledgment in the product 21 | documentation would be appreciated but is not required. 22 | 23 | 2. Altered source versions must be plainly marked as such, and 24 | must not be misrepresented as being the original software. 25 | 26 | 3. This notice may not be removed or altered from any source 27 | distribution. 28 | 29 | ---------------------------------------------------------------------------------*/ 30 | #include 31 | // #include 32 | 33 | //--------------------------------------------------------------------------------- 34 | void VcountHandler() { 35 | //--------------------------------------------------------------------------------- 36 | inputGetAndSend(); 37 | } 38 | /* 39 | void ResetSlot() { 40 | unsigned int * ROMCTRL=(unsigned int*)0x40001A4; 41 | unsigned int * SCFG_ROM=(unsigned int*)0x4004000; 42 | unsigned int * SCFG_CLK=(unsigned int*)0x4004004; 43 | unsigned int * SCFG_EXT=(unsigned int*)0x4004008; 44 | unsigned int * SCFG_MC=(unsigned int*)0x4004010; 45 | 46 | // Wait for arm9. 47 | fifoWaitValue32(FIFO_USER_02); 48 | 49 | //Power Off Slot 50 | int backup =*SCFG_EXT; 51 | *SCFG_EXT=0xFFFFFFFF; 52 | 53 | while(*SCFG_MC&0x0C != 0x0C); // wait until state<>3 54 | if(*SCFG_MC&0x0C != 0x08) return; // exit if state<>2 55 | 56 | *SCFG_MC = 0x0C; // set state=3 57 | while(*SCFG_MC&0x0C != 0x00); // wait until state=0 58 | 59 | // Tells arm9 to continue after powering off slot. (so that card init does not occur too soon) 60 | fifoSendValue32(FIFO_USER_01, 1); 61 | 62 | // Power On Slot 63 | while(*SCFG_MC&0x0C != 0x0C); // wait until state<>3 64 | if(*SCFG_MC&0x0C != 0x00) return; // exit if state<>0 65 | 66 | *SCFG_MC = 0x04; // wait 1ms, then set state=1 67 | while(*SCFG_MC&0x0C != 0x04); 68 | 69 | *SCFG_MC = 0x08; // wait 10ms, then set state=2 70 | while(*SCFG_MC&0x0C != 0x08); 71 | 72 | *ROMCTRL = 0x20000000; // wait 27ms, then set ROMCTRL=20000000h 73 | 74 | while(*ROMCTRL&0x8000000 != 0x8000000); 75 | 76 | *SCFG_EXT=backup; 77 | } 78 | */ 79 | 80 | //--------------------------------------------------------------------------------- 81 | int main() { 82 | //--------------------------------------------------------------------------------- 83 | unsigned int * SCFG_CLK=(unsigned int*)0x4004004; 84 | unsigned int * SCFG_EXT=(unsigned int*)0x4004008; 85 | 86 | // SCFG_EXT 87 | // 0x92A00000 : NTR 88 | // 0x93FFFF07 : TWL 89 | // 0x93FF0F07 : max accessible in NTR mode 90 | if(*SCFG_EXT == 0x92A00000) { 91 | *SCFG_EXT |= 0x830F0100; // NAND ACCESS 92 | // SCFG_CLK 93 | // 0x0180 : NTR 94 | // 0x0187 : TWL 95 | // 96 | *SCFG_CLK |= 1; 97 | } 98 | 99 | irqInit(); 100 | 101 | // read User Settings from firmware 102 | readUserSettings(); 103 | 104 | // Start the RTC tracking IRQ 105 | initClockIRQ(); 106 | 107 | fifoInit(); 108 | 109 | SetYtrigger(80); 110 | 111 | installSystemFIFO(); 112 | 113 | irqSet(IRQ_VCOUNT, VcountHandler); 114 | 115 | irqEnable( IRQ_VBLANK | IRQ_VCOUNT | IRQ_NETWORK); 116 | 117 | //Card Reset. Enable if needed. 118 | //ResetSlot(); 119 | 120 | // Keep the ARM7 mostly idle 121 | while (1) swiWaitForVBlank(); 122 | } 123 | 124 | -------------------------------------------------------------------------------- /BootStrap/arm9/Makefile: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------- 2 | .SUFFIXES: 3 | #--------------------------------------------------------------------------------- 4 | ifeq ($(strip $(DEVKITARM)),) 5 | $(error "Please set DEVKITARM in your environment. export DEVKITARM=devkitARM") 6 | endif 7 | 8 | include $(DEVKITARM)/ds_rules 9 | 10 | #--------------------------------------------------------------------------------- 11 | # BUILD is the directory where object files & intermediate files will be placed 12 | # SOURCES is a list of directories containing source code 13 | # INCLUDES is a list of directories containing extra header files 14 | # DATA is a list of directories containing binary files 15 | # all directories are relative to this makefile 16 | #--------------------------------------------------------------------------------- 17 | BUILD := build 18 | SOURCES := source ../../arm9/source 19 | INCLUDES := include ../../arm9/source 20 | DATA := ../../data 21 | 22 | 23 | #--------------------------------------------------------------------------------- 24 | # options for code generation 25 | #--------------------------------------------------------------------------------- 26 | ARCH := -mthumb -mthumb-interwork 27 | 28 | CFLAGS := -g -Wall -O2\ 29 | -march=armv5te -mtune=arm946e-s -fomit-frame-pointer\ 30 | -ffast-math \ 31 | $(ARCH) 32 | 33 | CFLAGS += $(INCLUDE) -DARM9 -D_NO_BOOTSTUB_ 34 | CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions 35 | 36 | ASFLAGS := -g $(ARCH) -march=armv5te -mtune=arm946e-s 37 | 38 | LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(TARGET).map -Wl,--section-start,.init=0x02000450,--nmagic 39 | 40 | #--------------------------------------------------------------------------------- 41 | # any extra libraries we wish to link with the project 42 | #--------------------------------------------------------------------------------- 43 | LIBS := -lfat -lnds9 44 | 45 | #--------------------------------------------------------------------------------- 46 | # list of directories containing libraries, this must be the top level containing 47 | # include and lib 48 | #--------------------------------------------------------------------------------- 49 | LIBDIRS := $(LIBNDS) 50 | 51 | #--------------------------------------------------------------------------------- 52 | # no real need to edit anything past this point unless you need to add additional 53 | # rules for different file extensions 54 | #--------------------------------------------------------------------------------- 55 | ifneq ($(BUILD),$(notdir $(CURDIR))) 56 | #--------------------------------------------------------------------------------- 57 | 58 | export ARM9ELF := $(TOPDIR)/$(TARGET).arm9.elf 59 | export DEPSDIR := $(CURDIR)/$(BUILD) 60 | 61 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ 62 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) 63 | 64 | CFILES := bootstrap.c nds_loader_arm9.c 65 | CPPFILES := 66 | PNGFILES := 67 | SFILES := 68 | BINFILES := load.bin 69 | 70 | 71 | #--------------------------------------------------------------------------------- 72 | # use CXX for linking C++ projects, CC for standard C 73 | #--------------------------------------------------------------------------------- 74 | ifeq ($(strip $(CPPFILES)),) 75 | #--------------------------------------------------------------------------------- 76 | export LD := $(CC) 77 | #--------------------------------------------------------------------------------- 78 | else 79 | #--------------------------------------------------------------------------------- 80 | export LD := $(CXX) 81 | #--------------------------------------------------------------------------------- 82 | endif 83 | #--------------------------------------------------------------------------------- 84 | 85 | export OFILES := $(addsuffix .o,$(BINFILES)) \ 86 | $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) 87 | 88 | export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ 89 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 90 | -I$(CURDIR)/$(BUILD) 91 | 92 | export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) 93 | 94 | .PHONY: $(BUILD) bootloader clean 95 | 96 | #--------------------------------------------------------------------------------- 97 | $(BUILD): 98 | @[ -d $@ ] || mkdir -p $@ 99 | @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 100 | 101 | #--------------------------------------------------------------------------------- 102 | clean: 103 | @echo clean ... 104 | @rm -fr $(BUILD) *.elf *.nds* *.bin 105 | 106 | ../../data: 107 | @mkdir -p ../data 108 | 109 | bootloader: ../../data 110 | @$(MAKE) -C ../../bootloader 111 | #--------------------------------------------------------------------------------- 112 | else 113 | 114 | #--------------------------------------------------------------------------------- 115 | # main targets 116 | #--------------------------------------------------------------------------------- 117 | $(ARM9ELF) : $(OFILES) 118 | @echo linking $(notdir $@) 119 | @$(LD) $(LDFLAGS) $(OFILES) $(LIBPATHS) $(LIBS) -o $@ 120 | 121 | #--------------------------------------------------------------------------------- 122 | # you need a rule like this for each extension you use as binary data 123 | #--------------------------------------------------------------------------------- 124 | %.bin.o : %.bin 125 | #--------------------------------------------------------------------------------- 126 | @echo $(notdir $<) 127 | @$(bin2o) 128 | 129 | -include $(DEPSDIR)/*.d 130 | 131 | #--------------------------------------------------------------------------------------- 132 | endif 133 | #--------------------------------------------------------------------------------------- 134 | -------------------------------------------------------------------------------- /BootStrap/arm9/source/bootstrap.c: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------- 2 | 3 | Copyright (C) 2010 Dave "WinterMute" Murphy 4 | 5 | This program is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU General Public License 7 | as published by the Free Software Foundation; either version 2 8 | of the License, or (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | 19 | ------------------------------------------------------------------*/ 20 | 21 | #include 22 | #include 23 | 24 | #include 25 | 26 | // #include 27 | 28 | #include "nds_loader_arm9.h" 29 | 30 | // Disabled by default 31 | /* 32 | void WaitForCart() { 33 | 34 | unsigned int * SCFG_MC=(unsigned int*)0x4004010; 35 | 36 | // Hold in loop until cartridge detected. (this is skipped if there's one already inserted at boot) 37 | printf("No cartridge detected!\nPlease insert a cartridge to\ncontinue."); 38 | do { 39 | swiWaitForVBlank(); 40 | } while (*SCFG_MC == 0x11); 41 | } 42 | 43 | // Waits for a preset amount of time then waits for arm7 to send fifo for FIFO_USER_01 44 | // This means it has powered off slot and has continued the card reset. 45 | // This ensures arm9 doesn't attempt to init card too soon when it's not ready. 46 | void WaitForSlot() { 47 | 48 | // Tell Arm7 it's ready to start card reset. 49 | fifoSendValue32(FIFO_USER_02, 1); 50 | 51 | // Waits for arm7 to power off slot before continuing 52 | fifoWaitValue32(FIFO_USER_01); 53 | // Wait for half a second to make sure Power On sequence on arm7 is complete. 54 | for (int i = 0; i < 30; i++) { 55 | swiWaitForVBlank(); 56 | } 57 | } 58 | */ 59 | 60 | int main( int argc, char **argv) { 61 | 62 | //unsigned int * SCFG_MC=(unsigned int*)0x4004010; 63 | 64 | consoleDemoInit(); 65 | 66 | // Cart Init Stuff. Enable if cart reset needed. 67 | // if(*SCFG_MC == 0x11) { WaitForCart(); } 68 | 69 | // WaitForSlot(); 70 | 71 | if (fatInitDefault()) { 72 | runNdsFile("/Boot.nds", 0, NULL); 73 | } else { 74 | printf("SD init failed!\nLauncher not patched!"); 75 | } 76 | while(1) swiWaitForVBlank(); 77 | 78 | // Alternate exit loop. Stops program if no cart inserted. Enable if making a Stage3 BootStrap for a flashcart. 79 | // Can also be used for other purposes requiring cart reset. Disable original exit loop before using this. 80 | /* 81 | if (*SCFG_MC == 0x11) { 82 | printf("Cartridge Not Inserted!\nReboot and try again!"); 83 | } else { 84 | if (fatInitDefault()) { 85 | runNdsFile("Boot.nds", 0, NULL); 86 | } else { 87 | printf("SD init failed!\nLauncher not patched!"); 88 | } 89 | } 90 | 91 | while(1) swiWaitForVBlank(); 92 | */ 93 | } 94 | 95 | -------------------------------------------------------------------------------- /BootStrap/mpcf.dldi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootStrap/mpcf.dldi -------------------------------------------------------------------------------- /BootStrap/r4tfv2.dldi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/BootStrap/r4tfv2.dldi -------------------------------------------------------------------------------- /HomebrewMenu.pnproj: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /HomebrewMenu.pnps: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------- 2 | .SUFFIXES: 3 | #--------------------------------------------------------------------------------- 4 | .SECONDARY: 5 | 6 | ifeq ($(strip $(DEVKITARM)),) 7 | $(error "Please set DEVKITARM in your environment. export DEVKITARM=devkitARM") 8 | endif 9 | 10 | include $(DEVKITARM)/ds_rules 11 | 12 | export HBMENU_MAJOR := 0 13 | export HBMENU_MINOR := 5 14 | export HBMENU_PATCH := 0 15 | 16 | 17 | VERSION := $(HBMENU_MAJOR).$(HBMENU_MINOR).$(HBMENU_PATCH) 18 | #--------------------------------------------------------------------------------- 19 | # TARGET is the name of the output 20 | # BUILD is the directory where object files & intermediate files will be placed 21 | # SOURCES is a list of directories containing source code 22 | # INCLUDES is a list of directories containing extra header files 23 | # DATA is a list of directories containing binary files embedded using bin2o 24 | # GRAPHICS is a list of directories containing image files to be converted with grit 25 | #--------------------------------------------------------------------------------- 26 | TARGET := hbmenu 27 | BUILD := build 28 | SOURCES := source 29 | INCLUDES := include 30 | DATA := data 31 | GRAPHICS := gfx 32 | 33 | #--------------------------------------------------------------------------------- 34 | # options for code generation 35 | #--------------------------------------------------------------------------------- 36 | ARCH := -mthumb -mthumb-interwork 37 | 38 | CFLAGS := -g -Wall -O2\ 39 | -march=armv5te -mtune=arm946e-s -fomit-frame-pointer\ 40 | -ffast-math \ 41 | $(ARCH) 42 | 43 | CFLAGS += $(INCLUDE) -DARM9 44 | CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions 45 | 46 | ASFLAGS := -g $(ARCH) 47 | LDFLAGS = -specs=ds_arm9.specs -g -Wl,--gc-sections $(ARCH) -Wl,-Map,$(notdir $*.map) 48 | 49 | #--------------------------------------------------------------------------------- 50 | # any extra libraries we wish to link with the project (order is important) 51 | #--------------------------------------------------------------------------------- 52 | LIBS := -lfat -lnds9 53 | 54 | 55 | #--------------------------------------------------------------------------------- 56 | # list of directories containing libraries, this must be the top level containing 57 | # include and lib 58 | #--------------------------------------------------------------------------------- 59 | LIBDIRS := $(LIBNDS) 60 | 61 | #--------------------------------------------------------------------------------- 62 | # no real need to edit anything past this point unless you need to add additional 63 | # rules for different file extensions 64 | #--------------------------------------------------------------------------------- 65 | ifneq ($(BUILD),$(notdir $(CURDIR))) 66 | #--------------------------------------------------------------------------------- 67 | 68 | export OUTPUT := $(CURDIR)/$(TARGET) 69 | 70 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ 71 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) \ 72 | $(foreach dir,$(GRAPHICS),$(CURDIR)/$(dir)) 73 | 74 | export DEPSDIR := $(CURDIR)/$(BUILD) 75 | 76 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 77 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 78 | PNGFILES := $(foreach dir,$(GRAPHICS),$(notdir $(wildcard $(dir)/*.png))) 79 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 80 | BINFILES := load.bin bootstub.bin 81 | 82 | #--------------------------------------------------------------------------------- 83 | # use CXX for linking C++ projects, CC for standard C 84 | #--------------------------------------------------------------------------------- 85 | ifeq ($(strip $(CPPFILES)),) 86 | #--------------------------------------------------------------------------------- 87 | export LD := $(CC) 88 | #--------------------------------------------------------------------------------- 89 | else 90 | #--------------------------------------------------------------------------------- 91 | export LD := $(CXX) 92 | #--------------------------------------------------------------------------------- 93 | endif 94 | #--------------------------------------------------------------------------------- 95 | 96 | export OFILES := $(addsuffix .o,$(BINFILES)) \ 97 | $(PNGFILES:.png=.o) \ 98 | $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) 99 | 100 | export INCLUDE := $(foreach dir,$(INCLUDES),-iquote $(CURDIR)/$(dir)) \ 101 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 102 | -I$(CURDIR)/$(BUILD) 103 | 104 | export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) 105 | 106 | icons := $(wildcard *.bmp) 107 | 108 | ifneq (,$(findstring $(TARGET).bmp,$(icons))) 109 | export GAME_ICON := $(CURDIR)/$(TARGET).bmp 110 | else 111 | ifneq (,$(findstring icon.bmp,$(icons))) 112 | export GAME_ICON := $(CURDIR)/icon.bmp 113 | endif 114 | endif 115 | 116 | export GAME_TITLE := $(TARGET) 117 | 118 | .PHONY: bootloader bootstub BootStrap clean 119 | 120 | all: bootloader bootstub BootStrap $(TARGET).nds 121 | 122 | dist: all 123 | @rm -fr hbmenu 124 | @mkdir hbmenu 125 | @cp hbmenu.nds hbmenu/BOOT.NDS 126 | @cp BootStrap/_BOOT_MP.NDS BootStrap/TTMENU.DAT BootStrap/_DS_MENU.DAT BootStrap/ez5sys.bin BootStrap/akmenu4.nds hbmenu 127 | @tar -cvjf hbmenu-$(VERSION).tar.bz2 hbmenu testfiles README.md COPYING -X exclude.lst 128 | 129 | $(TARGET).nds: $(TARGET).arm7 $(TARGET).arm9 130 | ndstool -c $(TARGET).nds -7 $(TARGET).arm7.elf -9 $(TARGET).arm9.elf -b icon.bmp "NDS HB MENU;Runs in TWL_FIRM MOD or DSI mode;made by devkitpro" 131 | 132 | $(TARGET).arm7: arm7/$(TARGET).elf 133 | cp arm7/$(TARGET).elf $(TARGET).arm7.elf 134 | 135 | $(TARGET).arm9: arm9/$(TARGET).elf 136 | cp arm9/$(TARGET).elf $(TARGET).arm9.elf 137 | 138 | #--------------------------------------------------------------------------------- 139 | arm7/$(TARGET).elf: 140 | @$(MAKE) -C arm7 141 | 142 | #--------------------------------------------------------------------------------- 143 | arm9/$(TARGET).elf: 144 | @$(MAKE) -C arm9 145 | 146 | #--------------------------------------------------------------------------------- 147 | #$(BUILD): 148 | #@[ -d $@ ] || mkdir -p $@ 149 | #@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 150 | 151 | #--------------------------------------------------------------------------------- 152 | clean: 153 | @echo clean ... 154 | @rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds $(TARGET).arm9 data 155 | @$(MAKE) -C bootloader clean 156 | @$(MAKE) -C bootstub clean 157 | @$(MAKE) -C BootStrap clean 158 | $(MAKE) -C arm9 clean 159 | $(MAKE) -C arm7 clean 160 | 161 | data: 162 | @mkdir -p data 163 | 164 | bootloader: data 165 | @$(MAKE) -C bootloader 166 | 167 | bootstub: data 168 | @$(MAKE) -C bootstub 169 | 170 | BootStrap: 171 | @$(MAKE) -C BootStrap 172 | 173 | #--------------------------------------------------------------------------------- 174 | else 175 | 176 | #--------------------------------------------------------------------------------- 177 | # main targets 178 | #--------------------------------------------------------------------------------- 179 | #$(OUTPUT).nds : $(OUTPUT).elf 180 | #$(OUTPUT).elf : $(OFILES) 181 | 182 | #--------------------------------------------------------------------------------- 183 | %.bin.o : %.bin 184 | #--------------------------------------------------------------------------------- 185 | @echo $(notdir $<) 186 | $(bin2o) 187 | 188 | #--------------------------------------------------------------------------------- 189 | # This rule creates assembly source files using grit 190 | # grit takes an image file and a .grit describing how the file is to be processed 191 | # add additional rules like this for each image extension 192 | # you use in the graphics folders 193 | #--------------------------------------------------------------------------------- 194 | %.s %.h : %.png %.grit 195 | #--------------------------------------------------------------------------------- 196 | grit $< -fts -o$* 197 | 198 | -include $(DEPSDIR)/*.d 199 | 200 | #--------------------------------------------------------------------------------------- 201 | endif 202 | #--------------------------------------------------------------------------------------- 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Homebrew Menu 2 | The Homebrew Menu is a simple launcher menu which can be used to replace the menu on several DS flashcards. This menu supports the argv protocol needed for devkitARM compiled applications to make use of nitrofs as well as providing a soft reset feature where applications can exit back to the menu. Exiting to the menu is as simple as returning from main() or calling exit(0). 3 | 4 | Currently the menu is a simple text based interface but we intend to improve this in the near future. Wintermute and Normmatt have discussed using the UI code from akaio for hbmenu and we hope to do this fairly soon. 5 | 6 | Installation on your card is a simple matter of copying BOOT.NDS and the appropriate bootstrap file from the hbmenu folder in this archive. At present we have bootstrap launchers for the original R4, ezflash 5, dstt and Acekard 2(i). Copying all the files will give you a single SD card which will boot the Homebrew Menu on all 4 cards. 7 | 8 | The Homebrew Menu also supports passing arguments to launched .nds files via .argv files. The testfiles folder has an nds file which lists arguments and some sample .argv files. These are simple text files which start with the name of the nds file to run and a list of arguments to pass to the application. Here's a quick sample .argv file. 9 | ```shell 10 | # This is a comment 11 | # commands can be placed on multiple lines 12 | # first the name of the nds file to run 13 | # this can include a path relative to the .argv file 14 | # absolute paths are not currently supported 15 | argvTest.nds 16 | 17 | # a single argument 18 | argument1 19 | 20 | # multiple arguments separated by spaces 21 | argument2 argument3 22 | 23 | # multiple arguments separated by tabs 24 | argument4 argument5 25 | 26 | # or even separated by both tabs and spaces 27 | argument6 argument7 argument8 28 | ``` 29 | 30 | # License 31 | Note: While the GPL license allows you to distribute modified versions of this program it would be appreciated if any improvements are contributed to devkitPro. Ultimately the community as a whole is better served by having a single official source for tools, applications and libraries. 32 | 33 | The latest sources may be obtained from devkitPro git using the command: `git clone git@github.com:devkitPro/nds-hb-menu.git` 34 | 35 | ``` 36 | Copyright (C) 2005 - 2011 37 | Michael "Chishm" Chisholm 38 | Dave "WinterMute" Murphy 39 | 40 | This program is free software; you can redistribute it and/or 41 | modify it under the terms of the GNU General Public License 42 | as published by the Free Software Foundation; either version 2 43 | of the License, or (at your option) any later version. 44 | 45 | This program is distributed in the hope that it will be useful, 46 | but WITHOUT ANY WARRANTY; without even the implied warranty of 47 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 48 | GNU General Public License for more details. 49 | 50 | You should have received a copy of the GNU General Public License 51 | along with this program; if not, write to the Free Software 52 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 53 | ``` 54 | -------------------------------------------------------------------------------- /arm7/Makefile: -------------------------------------------------------------------------------- 1 | export ARM7_MAJOR := 0 2 | export ARM7_MINOR := 6 3 | export ARM7_PATCH := 0 4 | 5 | VERSTRING := $(ARM7_MAJOR).$(ARM7_MINOR).$(ARM7_PATCH) 6 | #--------------------------------------------------------------------------------- 7 | .SUFFIXES: 8 | #--------------------------------------------------------------------------------- 9 | ifeq ($(strip $(DEVKITARM)),) 10 | $(error "Please set DEVKITARM in your environment. export DEVKITARM=devkitARM) 11 | endif 12 | 13 | include $(DEVKITARM)/ds_rules 14 | #--------------------------------------------------------------------------------- 15 | # TARGET is the name of the output 16 | # BUILD is the directory where object files & intermediate files will be placed 17 | # SOURCES is a list of directories containing source code 18 | # INCLUDES is a list of directories containing extra header files 19 | #--------------------------------------------------------------------------------- 20 | TARGET := hbmenu 21 | BUILD := build 22 | SOURCES := source 23 | INCLUDES := include build 24 | 25 | #--------------------------------------------------------------------------------- 26 | # options for code generation 27 | #--------------------------------------------------------------------------------- 28 | ARCH := -march=armv4t -mthumb -mthumb-interwork 29 | 30 | CFLAGS := -g -Wall -O2\ 31 | -mcpu=arm7tdmi -mtune=arm7tdmi -fomit-frame-pointer\ 32 | -ffast-math \ 33 | $(ARCH) 34 | 35 | CFLAGS += $(INCLUDE) -DARM7 36 | 37 | ASFLAGS := -g $(ARCH) 38 | LDFLAGS = -specs=../ds_arm7_ram.specs -g $(ARCH) -Wl,--nmagic -Wl,-Map,$(notdir $*).map 39 | 40 | 41 | #--------------------------------------------------------------------------------- 42 | # any extra libraries we wish to link with the project 43 | #--------------------------------------------------------------------------------- 44 | LIBS := -lmm7 -lnds7 45 | 46 | 47 | #--------------------------------------------------------------------------------- 48 | # list of directories containing libraries, this must be the top level containing 49 | # include and lib 50 | #--------------------------------------------------------------------------------- 51 | LIBDIRS := $(LIBNDS) 52 | 53 | 54 | #--------------------------------------------------------------------------------- 55 | # no real need to edit anything past this point unless you need to add additional 56 | # rules for different file extensions 57 | #--------------------------------------------------------------------------------- 58 | ifneq ($(BUILD),$(notdir $(CURDIR))) 59 | #--------------------------------------------------------------------------------- 60 | 61 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) 62 | 63 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 64 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 65 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 66 | 67 | export OFILES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) 68 | 69 | export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ 70 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 71 | -I$(CURDIR)/$(BUILD) 72 | 73 | export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) 74 | 75 | export DEPSDIR := $(CURDIR)/$(BUILD) 76 | 77 | export OUTPUT := $(CURDIR)/$(TARGET) 78 | 79 | #--------------------------------------------------------------------------------- 80 | # use CXX for linking C++ projects, CC for standard C 81 | #--------------------------------------------------------------------------------- 82 | ifeq ($(strip $(CPPFILES)),) 83 | #--------------------------------------------------------------------------------- 84 | export LD := $(CC) 85 | #--------------------------------------------------------------------------------- 86 | else 87 | #--------------------------------------------------------------------------------- 88 | export LD := $(CXX) 89 | #--------------------------------------------------------------------------------- 90 | endif 91 | #--------------------------------------------------------------------------------- 92 | 93 | .PHONY: all $(BUILD) clean 94 | 95 | all : $(BUILD) 96 | 97 | #--------------------------------------------------------------------------------- 98 | $(BUILD): 99 | @[ -d $@ ] || mkdir -p $@ 100 | @$(MAKE) -C $(BUILD) -f $(CURDIR)/Makefile 101 | 102 | 103 | #--------------------------------------------------------------------------------- 104 | dist: all 105 | #--------------------------------------------------------------------------------- 106 | @tar --exclude=*CVS* --exclude=.svn -cvjf default_arm7-src-$(VERSTRING).tar.bz2 source Makefile 107 | @tar -cvjf default_arm7-$(VERSTRING).tar.bz2 default.elf 108 | 109 | #--------------------------------------------------------------------------------- 110 | install: all 111 | #--------------------------------------------------------------------------------- 112 | cp $(TARGET).elf $(LIBNDS) 113 | 114 | #--------------------------------------------------------------------------------- 115 | clean: 116 | @echo clean ... 117 | @rm -fr $(BUILD) $(TARGET).elf $(TARGET).arm7 118 | 119 | 120 | #--------------------------------------------------------------------------------- 121 | else 122 | 123 | DEPENDS := $(OFILES:.o=.d) 124 | 125 | #--------------------------------------------------------------------------------- 126 | # main targets 127 | #--------------------------------------------------------------------------------- 128 | 129 | $(OUTPUT).elf : $(OFILES) $(LIBNDS)/lib/libnds7.a 130 | 131 | -include $(DEPENDS) 132 | 133 | #--------------------------------------------------------------------------------------- 134 | endif 135 | #--------------------------------------------------------------------------------------- 136 | -------------------------------------------------------------------------------- /arm7/ds_arm7_ram.ld: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm") 2 | OUTPUT_ARCH(arm) 3 | ENTRY(_start) 4 | 5 | MEMORY { 6 | rom : ORIGIN = 0x08000000, LENGTH = 32M 7 | ram : ORIGIN = 0x2380000, LENGTH = 128K 8 | iwram : ORIGIN = 0x037f8000, LENGTH = 96K 9 | } 10 | 11 | __iwram_start = ORIGIN(iwram); 12 | __iwram_top = ORIGIN(iwram)+ LENGTH(iwram); 13 | 14 | __sp_irq = __iwram_top - 0x100; 15 | __sp_svc = __sp_irq - 0x100; 16 | __sp_usr = __sp_svc - 0x100; 17 | 18 | __irq_flags = 0x04000000 - 8; 19 | __irq_flagsaux = 0x04000000 - 0x40; 20 | __irq_vector = 0x04000000 - 4; 21 | 22 | SECTIONS 23 | { 24 | .init : 25 | { 26 | __text_start = . ; 27 | KEEP (*(.init)) 28 | . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ 29 | } >ram = 0xff 30 | .plt : { *(.plt) } >ram = 0xff 31 | 32 | .text : /* ALIGN (4): */ 33 | { 34 | *(.text .stub .text.* .gnu.linkonce.t.*) 35 | KEEP (*(.text.*personality*)) 36 | /* .gnu.warning sections are handled specially by elf32.em. */ 37 | *(.gnu.warning) 38 | *(.glue_7t) *(.glue_7) *(.vfp11_veneer) 39 | . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ 40 | } >ram = 0xff 41 | 42 | .fini : 43 | { 44 | KEEP (*(.fini)) 45 | } >ram =0xff 46 | 47 | __text_end = . ; 48 | 49 | .rodata : 50 | { 51 | *(.rodata) 52 | *all.rodata*(*) 53 | *(.roda) 54 | *(.rodata.*) 55 | *(.gnu.linkonce.r*) 56 | SORT(CONSTRUCTORS) 57 | . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ 58 | } >ram = 0xff 59 | 60 | .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >ram 61 | __exidx_start = .; 62 | .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } >ram 63 | __exidx_end = .; 64 | 65 | /* Ensure the __preinit_array_start label is properly aligned. We 66 | could instead move the label definition inside the section, but 67 | the linker would then create the section even if it turns out to 68 | be empty, which isn't pretty. */ 69 | . = ALIGN(32 / 8); 70 | PROVIDE (__preinit_array_start = .); 71 | .preinit_array : { KEEP (*(.preinit_array)) } >ram = 0xff 72 | PROVIDE (__preinit_array_end = .); 73 | PROVIDE (__init_array_start = .); 74 | .init_array : { KEEP (*(.init_array)) } >ram = 0xff 75 | PROVIDE (__init_array_end = .); 76 | PROVIDE (__fini_array_start = .); 77 | .fini_array : { KEEP (*(.fini_array)) } >ram = 0xff 78 | PROVIDE (__fini_array_end = .); 79 | 80 | .ctors : 81 | { 82 | /* gcc uses crtbegin.o to find the start of the constructors, so 83 | we make sure it is first. Because this is a wildcard, it 84 | doesn't matter if the user does not actually link against 85 | crtbegin.o; the linker won't look for a file to match a 86 | wildcard. The wildcard also means that it doesn't matter which 87 | directory crtbegin.o is in. */ 88 | KEEP (*crtbegin.o(.ctors)) 89 | KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors)) 90 | KEEP (*(SORT(.ctors.*))) 91 | KEEP (*(.ctors)) 92 | . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ 93 | } >ram = 0xff 94 | 95 | .dtors : 96 | { 97 | KEEP (*crtbegin.o(.dtors)) 98 | KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors)) 99 | KEEP (*(SORT(.dtors.*))) 100 | KEEP (*(.dtors)) 101 | . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ 102 | } >ram = 0xff 103 | 104 | .eh_frame : 105 | { 106 | KEEP (*(.eh_frame)) 107 | . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ 108 | } >ram = 0xff 109 | 110 | .gcc_except_table : 111 | { 112 | *(.gcc_except_table) 113 | . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ 114 | } >ram = 0xff 115 | .jcr : { KEEP (*(.jcr)) } >ram = 0 116 | .got : { *(.got.plt) *(.got) } >ram = 0 117 | 118 | .data ALIGN(4) : { 119 | __data_start = ABSOLUTE(.); 120 | *(.data) 121 | *(.data.*) 122 | *(.gnu.linkonce.d*) 123 | CONSTRUCTORS 124 | . = ALIGN(4); 125 | __data_end = ABSOLUTE(.) ; 126 | } >ram = 0xff 127 | 128 | .bss ALIGN(4) : 129 | { 130 | __bss_start = ABSOLUTE(.); 131 | __bss_start__ = ABSOLUTE(.); 132 | *(.dynbss) 133 | *(.gnu.linkonce.b*) 134 | *(.bss*) 135 | *(COMMON) 136 | . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ 137 | __bss_end__ = ABSOLUTE(.); 138 | __end__ = ABSOLUTE(.); 139 | } >ram 140 | 141 | /* Stabs debugging sections. */ 142 | .stab 0 : { *(.stab) } 143 | .stabstr 0 : { *(.stabstr) } 144 | .stab.excl 0 : { *(.stab.excl) } 145 | .stab.exclstr 0 : { *(.stab.exclstr) } 146 | .stab.index 0 : { *(.stab.index) } 147 | .stab.indexstr 0 : { *(.stab.indexstr) } 148 | .comment 0 : { *(.comment) } 149 | /* DWARF debug sections. 150 | Symbols in the DWARF debugging sections are relative to the beginning 151 | of the section so we begin them at 0. */ 152 | /* DWARF 1 */ 153 | .debug 0 : { *(.debug) } 154 | .line 0 : { *(.line) } 155 | /* GNU DWARF 1 extensions */ 156 | .debug_srcinfo 0 : { *(.debug_srcinfo) } 157 | .debug_sfnames 0 : { *(.debug_sfnames) } 158 | /* DWARF 1.1 and DWARF 2 */ 159 | .debug_aranges 0 : { *(.debug_aranges) } 160 | .debug_pubnames 0 : { *(.debug_pubnames) } 161 | /* DWARF 2 */ 162 | .debug_info 0 : { *(.debug_info) } 163 | .debug_abbrev 0 : { *(.debug_abbrev) } 164 | .debug_line 0 : { *(.debug_line) } 165 | .debug_frame 0 : { *(.debug_frame) } 166 | .debug_str 0 : { *(.debug_str) } 167 | .debug_loc 0 : { *(.debug_loc) } 168 | .debug_macinfo 0 : { *(.debug_macinfo) } 169 | /* SGI/MIPS DWARF 2 extensions */ 170 | .debug_weaknames 0 : { *(.debug_weaknames) } 171 | .debug_funcnames 0 : { *(.debug_funcnames) } 172 | .debug_typenames 0 : { *(.debug_typenames) } 173 | .debug_varnames 0 : { *(.debug_varnames) } 174 | .stack 0x80000 : { _stack = .; *(.stack) } 175 | /* These must appear regardless of . */ 176 | } 177 | -------------------------------------------------------------------------------- /arm7/ds_arm7_ram.specs: -------------------------------------------------------------------------------- 1 | %rename link old_link 2 | 3 | *link: 4 | %(old_link) -T ../ds_arm7_ram.ld%s --gc-sections 5 | 6 | *startfile: 7 | ds_arm7_crt0%O%s crti%O%s crtbegin%O%s 8 | 9 | -------------------------------------------------------------------------------- /arm7/source/main.c: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------------- 2 | 3 | default ARM7 core 4 | 5 | Copyright (C) 2005 - 2010 6 | Michael Noland (joat) 7 | Jason Rogers (dovoto) 8 | Dave Murphy (WinterMute) 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any 12 | damages arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any 15 | purpose, including commercial applications, and to alter it and 16 | redistribute it freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you 19 | must not claim that you wrote the original software. If you use 20 | this software in a product, an acknowledgment in the product 21 | documentation would be appreciated but is not required. 22 | 23 | 2. Altered source versions must be plainly marked as such, and 24 | must not be misrepresented as being the original software. 25 | 26 | 3. This notice may not be removed or altered from any source 27 | distribution. 28 | 29 | ---------------------------------------------------------------------------------*/ 30 | #include 31 | #include 32 | 33 | //--------------------------------------------------------------------------------- 34 | void VblankHandler(void) { 35 | //--------------------------------------------------------------------------------- 36 | 37 | } 38 | 39 | //--------------------------------------------------------------------------------- 40 | void VcountHandler() { 41 | //--------------------------------------------------------------------------------- 42 | inputGetAndSend(); 43 | } 44 | 45 | volatile bool exitflag = false; 46 | 47 | //--------------------------------------------------------------------------------- 48 | void powerButtonCB() { 49 | //--------------------------------------------------------------------------------- 50 | exitflag = true; 51 | } 52 | 53 | //--------------------------------------------------------------------------------- 54 | int main() { 55 | //--------------------------------------------------------------------------------- 56 | nocashMessage("ARM7 main.c main"); 57 | 58 | REG_SCFG_ROM = 0x703; 59 | REG_SCFG_CLK = 0x0187; 60 | // REG_SCFG_EXT = 0x93A40000; 61 | 62 | // SCFG_CLK 63 | // 0x0180 : NTR 64 | // 0x0181 : NTR+SD 65 | // 0x0187 : TWL 66 | // REG_SCFG_CLK = 0x0181; 67 | 68 | // clear sound registers 69 | dmaFillWords(0, (void*)0x04000400, 0x100); 70 | 71 | REG_SOUNDCNT |= SOUND_ENABLE; 72 | writePowerManagement(PM_CONTROL_REG, ( readPowerManagement(PM_CONTROL_REG) & ~PM_SOUND_MUTE ) | PM_SOUND_AMP ); 73 | powerOn(POWER_SOUND); 74 | 75 | readUserSettings(); 76 | ledBlink(0); 77 | 78 | irqInit(); 79 | // Start the RTC tracking IRQ 80 | initClockIRQ(); 81 | 82 | fifoInit(); 83 | 84 | mmInstall(FIFO_MAXMOD); 85 | 86 | SetYtrigger(80); 87 | 88 | installSoundFIFO(); 89 | installSystemFIFO(); 90 | 91 | fifoWaitValue32(FIFO_USER_01); 92 | if(fifoCheckValue32(FIFO_USER_02)) { dsi_resetSlot1(); } 93 | fifoSendValue32(FIFO_USER_03, 1); 94 | 95 | fifoWaitValue32(FIFO_USER_07); 96 | if(fifoCheckValue32(FIFO_USER_04)) { REG_SCFG_CLK = 0x0181; } 97 | if(fifoCheckValue32(FIFO_USER_05)) { 98 | REG_SCFG_EXT = 0x13A40000; 99 | } else { 100 | if(fifoCheckValue32(FIFO_USER_06)) { REG_SCFG_EXT = 0x93FFFB06; } else { REG_SCFG_EXT = 0x93A40000; } 101 | } 102 | 103 | irqSet(IRQ_VCOUNT, VcountHandler); 104 | irqSet(IRQ_VBLANK, VblankHandler); 105 | 106 | irqEnable( IRQ_VBLANK | IRQ_VCOUNT | IRQ_NETWORK); 107 | 108 | setPowerButtonCB(powerButtonCB); 109 | 110 | // Keep the ARM7 mostly idle 111 | while (!exitflag) { 112 | if ( 0 == (REG_KEYINPUT & (KEY_SELECT | KEY_START | KEY_L | KEY_R))) { 113 | exitflag = true; 114 | } 115 | // fifocheck(); 116 | swiWaitForVBlank(); 117 | } 118 | return 0; 119 | } 120 | 121 | -------------------------------------------------------------------------------- /arm9/Makefile: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------- 2 | .SUFFIXES: 3 | #--------------------------------------------------------------------------------- 4 | 5 | ifeq ($(strip $(DEVKITARM)),) 6 | $(error "Please set DEVKITARM in your environment. export DEVKITARM=devkitARM") 7 | endif 8 | 9 | include $(DEVKITARM)/ds_rules 10 | 11 | #--------------------------------------------------------------------------------- 12 | # TARGET is the name of the output 13 | # BUILD is the directory where object files & intermediate files will be placed 14 | # SOURCES is a list of directories containing source code 15 | # INCLUDES is a list of directories containing extra header files 16 | # MAXMOD_SOUNDBANK contains a directory of music and sound effect files 17 | #--------------------------------------------------------------------------------- 18 | TARGET := hbmenu 19 | BUILD := build 20 | SOURCES := source 21 | INCLUDES := include 22 | DATA := ../data 23 | GRAPHICS := ../gfx 24 | IMAGES := ../BootSplash 25 | MUSIC := ../music 26 | 27 | #--------------------------------------------------------------------------------- 28 | # options for code generation 29 | #--------------------------------------------------------------------------------- 30 | ARCH := -mthumb -mthumb-interwork 31 | 32 | CFLAGS := -g -Wall -O2\ 33 | -march=armv5te -mtune=arm946e-s -fomit-frame-pointer\ 34 | -ffast-math \ 35 | $(ARCH) 36 | 37 | CFLAGS += $(INCLUDE) -DARM9 38 | CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions 39 | 40 | ASFLAGS := -g $(ARCH) 41 | LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) 42 | 43 | #--------------------------------------------------------------------------------- 44 | # any extra libraries we wish to link with the project (order is important) 45 | #--------------------------------------------------------------------------------- 46 | LIBS := -lfat -lmm9 -lnds9 47 | 48 | 49 | #--------------------------------------------------------------------------------- 50 | # list of directories containing libraries, this must be the top level containing 51 | # include and lib 52 | #--------------------------------------------------------------------------------- 53 | LIBDIRS := $(LIBNDS) 54 | 55 | #--------------------------------------------------------------------------------- 56 | # no real need to edit anything past this point unless you need to add additional 57 | # rules for different file extensions 58 | #--------------------------------------------------------------------------------- 59 | ifneq ($(BUILD),$(notdir $(CURDIR))) 60 | #--------------------------------------------------------------------------------- 61 | 62 | export OUTPUT := $(CURDIR)/$(TARGET) 63 | 64 | export AUDIOFILES := $(foreach dir,$(notdir $(wildcard $(MUSIC)/*.*)),$(CURDIR)/$(MUSIC)/$(dir)) 65 | 66 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ 67 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) \ 68 | $(foreach dir,$(GRAPHICS),$(CURDIR)/$(dir)) 69 | 70 | export DEPSDIR := $(CURDIR)/$(BUILD) 71 | 72 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 73 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 74 | PNGFILES := $(foreach dir,$(GRAPHICS),$(notdir $(wildcard $(dir)/*.png))) 75 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 76 | BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) soundbank.bin 77 | BMPFILES := $(foreach dir,$(IMAGES),$(notdir $(wildcard $(dir)/*.bmp))) 78 | 79 | #--------------------------------------------------------------------------------- 80 | # use CXX for linking C++ projects, CC for standard C 81 | #--------------------------------------------------------------------------------- 82 | ifeq ($(strip $(CPPFILES)),) 83 | #--------------------------------------------------------------------------------- 84 | export LD := $(CC) 85 | #--------------------------------------------------------------------------------- 86 | else 87 | #--------------------------------------------------------------------------------- 88 | export LD := $(CXX) 89 | #--------------------------------------------------------------------------------- 90 | endif 91 | #--------------------------------------------------------------------------------- 92 | 93 | export OFILES := $(addsuffix .o,$(BINFILES)) \ 94 | $(PNGFILES:.png=.o) $(BMPFILES:.bmp=.o) \ 95 | $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) 96 | 97 | export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ 98 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 99 | -I$(CURDIR)/$(BUILD) 100 | 101 | export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) 102 | 103 | 104 | export OUTPUT := $(CURDIR)/$(TARGET) 105 | 106 | .PHONY: $(BUILD) clean 107 | 108 | all : $(BUILD) 109 | 110 | #--------------------------------------------------------------------------------- 111 | $(BUILD): 112 | @[ -d $@ ] || mkdir -p $@ 113 | @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 114 | 115 | #--------------------------------------------------------------------------------- 116 | clean: 117 | @echo clean ... 118 | @rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds 119 | 120 | #--------------------------------------------------------------------------------- 121 | else 122 | 123 | #--------------------------------------------------------------------------------- 124 | # main targets 125 | #--------------------------------------------------------------------------------- 126 | $(OUTPUT).elf : $(OFILES) 127 | 128 | #--------------------------------------------------------------------------------- 129 | # graphics 130 | #--------------------------------------------------------------------------------- 131 | # Main Boot Splash sequence 132 | Bot00.s : ../$(IMAGES)/Bot00.bmp 133 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 134 | 135 | Bot01.s : ../$(IMAGES)/Bot01.bmp 136 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 137 | 138 | Bot02.s : ../$(IMAGES)/Bot02.bmp 139 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 140 | 141 | Bot03.s : ../$(IMAGES)/Bot03.bmp 142 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 143 | 144 | Bot04.s : ../$(IMAGES)/Bot04.bmp 145 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 146 | 147 | Bot05.s : ../$(IMAGES)/Bot05.bmp 148 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 149 | 150 | Bot06.s : ../$(IMAGES)/Bot06.bmp 151 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 152 | 153 | Bot07.s : ../$(IMAGES)/Bot07.bmp 154 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 155 | 156 | Bot08.s : ../$(IMAGES)/Bot08.bmp 157 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 158 | 159 | Bot09.s : ../$(IMAGES)/Bot09.bmp 160 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 161 | 162 | Bot10.s : ../$(IMAGES)/Bot10.bmp 163 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 164 | 165 | Top00.s : ../$(IMAGES)/Top00.bmp 166 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 167 | 168 | Top01.s : ../$(IMAGES)/Top01.bmp 169 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 170 | 171 | Top02.s : ../$(IMAGES)/Top02.bmp 172 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 173 | 174 | Top03.s : ../$(IMAGES)/Top03.bmp 175 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 176 | 177 | Top04.s : ../$(IMAGES)/Top04.bmp 178 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 179 | 180 | Top05.s : ../$(IMAGES)/Top05.bmp 181 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 182 | 183 | Top06.s : ../$(IMAGES)/Top06.bmp 184 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 185 | 186 | Top07.s : ../$(IMAGES)/Top07.bmp 187 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 188 | 189 | Top08.s : ../$(IMAGES)/Top08.bmp 190 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 191 | 192 | Top09.s : ../$(IMAGES)/Top09.bmp 193 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 194 | 195 | Top10.s : ../$(IMAGES)/Top10.bmp 196 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 197 | 198 | Top11.s : ../$(IMAGES)/Top11.bmp 199 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 200 | 201 | Top12.s : ../$(IMAGES)/Top12.bmp 202 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 203 | 204 | Top13.s : ../$(IMAGES)/Top13.bmp 205 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 206 | 207 | Top14.s : ../$(IMAGES)/Top14.bmp 208 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 209 | 210 | Top15.s : ../$(IMAGES)/Top15.bmp 211 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 212 | 213 | Top16.s : ../$(IMAGES)/Top16.bmp 214 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 215 | 216 | Top17.s : ../$(IMAGES)/Top17.bmp 217 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 218 | 219 | Top18.s : ../$(IMAGES)/Top18.bmp 220 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 221 | 222 | Top19.s : ../$(IMAGES)/Top19.bmp 223 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 224 | 225 | Top20.s : ../$(IMAGES)/Top20.bmp 226 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 227 | 228 | Top21.s : ../$(IMAGES)/Top21.bmp 229 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 230 | 231 | Top22.s : ../$(IMAGES)/Top22.bmp 232 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 233 | 234 | Top23.s : ../$(IMAGES)/Top23.bmp 235 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 236 | 237 | Top24.s : ../$(IMAGES)/Top24.bmp 238 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 239 | 240 | Top25.s : ../$(IMAGES)/Top25.bmp 241 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 242 | 243 | Top26.s : ../$(IMAGES)/Top26.bmp 244 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 245 | 246 | Top27.s : ../$(IMAGES)/Top27.bmp 247 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 248 | 249 | Top28.s : ../$(IMAGES)/Top28.bmp 250 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 251 | 252 | Top29.s : ../$(IMAGES)/Top29.bmp 253 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 254 | 255 | Top30.s : ../$(IMAGES)/Top30.bmp 256 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 257 | 258 | Top31.s : ../$(IMAGES)/Top31.bmp 259 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 260 | 261 | Top32.s : ../$(IMAGES)/Top32.bmp 262 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 263 | 264 | Top33.s : ../$(IMAGES)/Top33.bmp 265 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 266 | 267 | Top34.s : ../$(IMAGES)/Top34.bmp 268 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 269 | 270 | Top35.s : ../$(IMAGES)/Top35.bmp 271 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 272 | 273 | Top36.s : ../$(IMAGES)/Top36.bmp 274 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 275 | 276 | Top37.s : ../$(IMAGES)/Top37.bmp 277 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 278 | 279 | # DSi BootSplash. Used if TWL mode detected 280 | DSi18.s : ../$(IMAGES)/DSi18.bmp 281 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 282 | 283 | DSi19.s : ../$(IMAGES)/DSi19.bmp 284 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 285 | 286 | DSi20.s : ../$(IMAGES)/DSi20.bmp 287 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 288 | 289 | DSi21.s : ../$(IMAGES)/DSi21.bmp 290 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 291 | 292 | DSi22.s : ../$(IMAGES)/DSi22.bmp 293 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 294 | 295 | DSi23.s : ../$(IMAGES)/DSi23.bmp 296 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 297 | 298 | DSi24.s : ../$(IMAGES)/DSi24.bmp 299 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 300 | 301 | DSi25.s : ../$(IMAGES)/DSi25.bmp 302 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 303 | 304 | DSi26.s : ../$(IMAGES)/DSi26.bmp 305 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 306 | 307 | DSi27.s : ../$(IMAGES)/DSi27.bmp 308 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 309 | 310 | DSi28.s : ../$(IMAGES)/DSi28.bmp 311 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 312 | 313 | DSi29.s : ../$(IMAGES)/DSi29.bmp 314 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 315 | 316 | DSi30.s : ../$(IMAGES)/DSi30.bmp 317 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 318 | 319 | DSi31.s : ../$(IMAGES)/DSi31.bmp 320 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 321 | 322 | DSi32.s : ../$(IMAGES)/DSi32.bmp 323 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 324 | 325 | DSi33.s : ../$(IMAGES)/DSi33.bmp 326 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 327 | 328 | DSi34.s : ../$(IMAGES)/DSi34.bmp 329 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 330 | 331 | DSi35.s : ../$(IMAGES)/DSi35.bmp 332 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 333 | 334 | DSi36.s : ../$(IMAGES)/DSi36.bmp 335 | grit $< -gB8 -gzl -gTff00ff -fts -o $@ -q 336 | 337 | #--------------------------------------------------------------------------------- 338 | # rule to build soundbank from music files 339 | #--------------------------------------------------------------------------------- 340 | soundbank.bin : $(AUDIOFILES) 341 | #--------------------------------------------------------------------------------- 342 | @mmutil $^ -d -osoundbank.bin -hsoundbank.h 343 | #--------------------------------------------------------------------------------- 344 | %.bin.o : %.bin 345 | #--------------------------------------------------------------------------------- 346 | @echo $(notdir $<) 347 | $(bin2o) 348 | 349 | #--------------------------------------------------------------------------------- 350 | # This rule creates assembly source files using grit 351 | # grit takes an image file and a .grit describing how the file is to be processed 352 | # add additional rules like this for each image extension 353 | # you use in the graphics folders 354 | #--------------------------------------------------------------------------------- 355 | %.s %.h : %.png %.grit 356 | #--------------------------------------------------------------------------------- 357 | grit $< -fts -o$* 358 | 359 | -include $(DEPSDIR)/*.d 360 | 361 | #--------------------------------------------------------------------------------------- 362 | endif 363 | #--------------------------------------------------------------------------------------- 364 | -------------------------------------------------------------------------------- /arm9/source/bios_decompress_callback.c: -------------------------------------------------------------------------------- 1 | /* 2 | NitroHax -- Cheat tool for the Nintendo DS 3 | Copyright (C) 2008 Michael "Chishm" Chisholm 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . 17 | */ 18 | 19 | #include "bios_decompress_callback.h" 20 | 21 | int getSizeBiosCallback (uint8 * source, uint16 * dest, uint32 r2) 22 | { 23 | return *((int*)source); 24 | } 25 | 26 | uint8 readByteBiosCallback (uint8 * source) 27 | { 28 | return *source; 29 | } 30 | 31 | TDecompressionStream decompressBiosCallback = 32 | { 33 | getSizeBiosCallback, 34 | (void*)0, 35 | readByteBiosCallback 36 | } ; 37 | 38 | 39 | -------------------------------------------------------------------------------- /arm9/source/bios_decompress_callback.h: -------------------------------------------------------------------------------- 1 | /* 2 | NitroHax -- Cheat tool for the Nintendo DS 3 | Copyright (C) 2008 Michael "Chishm" Chisholm 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . 17 | */ 18 | 19 | #ifndef BIOS_DECOMPRESS_CALLBACK_H 20 | #define BIOS_DECOMPRESS_CALLBACK_H 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | #include 27 | #include 28 | 29 | extern TDecompressionStream decompressBiosCallback; 30 | 31 | 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | 37 | #endif // BIOS_DECOMPRESS_CALLBACK_H 38 | 39 | -------------------------------------------------------------------------------- /arm9/source/bootsplash.h: -------------------------------------------------------------------------------- 1 | /* 2 | NitroHax -- Cheat tool for the Nintendo DS 3 | Copyright (C) 2008 Michael "Chishm" Chisholm 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . 17 | */ 18 | 19 | #ifndef BOOTSPLASH_H 20 | #define BOOTSPLASH_H 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | void vramcpy_ui (void* dest, const void* src, int size); 27 | void BootJingle (void); 28 | void BootJingleDSi (void); 29 | void BootSplashDSi (void); 30 | void BootSplashDS (bool SetNTRSplash); 31 | void BootSplashInit (bool UseNTRSplash); 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | 37 | #endif // BOOTSPLASH_H 38 | 39 | -------------------------------------------------------------------------------- /arm9/source/file_browse.cpp: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------- 2 | Copyright (C) 2005 - 2013 3 | Michael "Chishm" Chisholm 4 | Dave "WinterMute" Murphy 5 | Claudio "sverx" 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License 9 | as published by the Free Software Foundation; either version 2 10 | of the License, or (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software 19 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 | 21 | ------------------------------------------------------------------*/ 22 | 23 | #include "file_browse.h" 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include 32 | 33 | #include "iconTitle.h" 34 | 35 | #define SCREEN_COLS 32 36 | #define ENTRIES_PER_SCREEN 22 37 | #define ENTRIES_START_ROW 2 38 | #define ENTRY_PAGE_LENGTH 10 39 | 40 | using namespace std; 41 | 42 | struct DirEntry { 43 | string name; 44 | bool isDirectory; 45 | } ; 46 | 47 | bool nameEndsWith (const string& name, const vector extensionList) { 48 | 49 | if (name.size() == 0) return false; 50 | 51 | if (extensionList.size() == 0) return true; 52 | 53 | for (int i = 0; i < (int)extensionList.size(); i++) { 54 | const string ext = extensionList.at(i); 55 | if ( strcasecmp (name.c_str() + name.size() - ext.size(), ext.c_str()) == 0) return true; 56 | } 57 | return false; 58 | } 59 | 60 | bool dirEntryPredicate (const DirEntry& lhs, const DirEntry& rhs) { 61 | 62 | if (!lhs.isDirectory && rhs.isDirectory) { 63 | return false; 64 | } 65 | if (lhs.isDirectory && !rhs.isDirectory) { 66 | return true; 67 | } 68 | return strcasecmp(lhs.name.c_str(), rhs.name.c_str()) < 0; 69 | } 70 | 71 | void getDirectoryContents (vector& dirContents, const vector extensionList) { 72 | struct stat st; 73 | 74 | dirContents.clear(); 75 | 76 | DIR *pdir = opendir ("."); 77 | 78 | if (pdir == NULL) { 79 | iprintf ("Unable to open the directory.\n"); 80 | } else { 81 | 82 | while(true) { 83 | DirEntry dirEntry; 84 | 85 | struct dirent* pent = readdir(pdir); 86 | if(pent == NULL) break; 87 | 88 | stat(pent->d_name, &st); 89 | dirEntry.name = pent->d_name; 90 | dirEntry.isDirectory = (st.st_mode & S_IFDIR) ? true : false; 91 | 92 | if (dirEntry.name.compare(".") != 0 && (dirEntry.isDirectory || nameEndsWith(dirEntry.name, extensionList))) { 93 | dirContents.push_back (dirEntry); 94 | } 95 | 96 | } 97 | 98 | closedir(pdir); 99 | } 100 | 101 | sort(dirContents.begin(), dirContents.end(), dirEntryPredicate); 102 | } 103 | 104 | void getDirectoryContents (vector& dirContents) { 105 | vector extensionList; 106 | getDirectoryContents (dirContents, extensionList); 107 | } 108 | 109 | void showDirectoryContents (const vector& dirContents, int startRow) { 110 | char path[PATH_MAX]; 111 | 112 | 113 | getcwd(path, PATH_MAX); 114 | 115 | // Clear the screen 116 | iprintf ("\x1b[2J"); 117 | 118 | // Print the path 119 | if (strlen(path) < SCREEN_COLS) { 120 | iprintf ("%s", path); 121 | } else { 122 | iprintf ("%s", path + strlen(path) - SCREEN_COLS); 123 | } 124 | 125 | // Move to 2nd row 126 | iprintf ("\x1b[1;0H"); 127 | // Print line of dashes 128 | iprintf ("--------------------------------"); 129 | 130 | // Print directory listing 131 | for (int i = 0; i < ((int)dirContents.size() - startRow) && i < ENTRIES_PER_SCREEN; i++) { 132 | const DirEntry* entry = &dirContents.at(i + startRow); 133 | char entryName[SCREEN_COLS + 1]; 134 | 135 | // Set row 136 | iprintf ("\x1b[%d;0H", i + ENTRIES_START_ROW); 137 | 138 | if (entry->isDirectory) { 139 | strncpy (entryName, entry->name.c_str(), SCREEN_COLS); 140 | entryName[SCREEN_COLS - 3] = '\0'; 141 | iprintf (" [%s]", entryName); 142 | } else { 143 | strncpy (entryName, entry->name.c_str(), SCREEN_COLS); 144 | entryName[SCREEN_COLS - 1] = '\0'; 145 | iprintf (" %s", entryName); 146 | } 147 | } 148 | } 149 | 150 | static bool browseDsiSd = true; 151 | 152 | void getHeader (u32* ndsHeader) { 153 | cardParamCommand (CARD_CMD_DUMMY, 0, 154 | CARD_ACTIVATE | CARD_CLK_SLOW | CARD_BLK_SIZE(1) | CARD_DELAY1(0x1FFF) | CARD_DELAY2(0x3F), 155 | NULL, 0); 156 | 157 | cardParamCommand(CARD_CMD_HEADER_READ, 0, 158 | CARD_ACTIVATE | CARD_nRESET | CARD_CLK_SLOW | CARD_BLK_SIZE(1) | CARD_DELAY1(0x1FFF) | CARD_DELAY2(0x3F), 159 | ndsHeader, 512); 160 | 161 | } 162 | 163 | string browseForFile (const vector extensionList) { 164 | int pressed = 0; 165 | int screenOffset = 0; 166 | int fileOffset = 0; 167 | vector dirContents; 168 | 169 | getDirectoryContents (dirContents, extensionList); 170 | showDirectoryContents (dirContents, screenOffset); 171 | 172 | while (true) { 173 | // Clear old cursors 174 | for (int i = ENTRIES_START_ROW; i < ENTRIES_PER_SCREEN + ENTRIES_START_ROW; i++) { 175 | iprintf ("\x1b[%d;0H ", i); 176 | } 177 | // Show cursor 178 | iprintf ("\x1b[%d;0H*", fileOffset - screenOffset + ENTRIES_START_ROW); 179 | 180 | iconTitleUpdate (dirContents.at(fileOffset).isDirectory,dirContents.at(fileOffset).name.c_str()); 181 | 182 | // Power saving loop. Only poll the keys once per frame and sleep the CPU if there is nothing else to do 183 | do { 184 | scanKeys(); 185 | pressed = keysDownRepeat(); 186 | swiWaitForVBlank(); 187 | } while (!pressed); 188 | 189 | if (pressed & KEY_UP) fileOffset -= 1; 190 | if (pressed & KEY_DOWN) fileOffset += 1; 191 | if (pressed & KEY_LEFT) fileOffset -= ENTRY_PAGE_LENGTH; 192 | if (pressed & KEY_RIGHT) fileOffset += ENTRY_PAGE_LENGTH; 193 | 194 | if (fileOffset < 0) fileOffset = dirContents.size() - 1; // Wrap around to bottom of list 195 | if (fileOffset > ((int)dirContents.size() - 1)) fileOffset = 0; // Wrap around to top of list 196 | 197 | // Scroll screen if needed 198 | if (fileOffset < screenOffset) { 199 | screenOffset = fileOffset; 200 | showDirectoryContents (dirContents, screenOffset); 201 | } 202 | if (fileOffset > screenOffset + ENTRIES_PER_SCREEN - 1) { 203 | screenOffset = fileOffset - ENTRIES_PER_SCREEN + 1; 204 | showDirectoryContents (dirContents, screenOffset); 205 | } 206 | 207 | if (pressed & KEY_A) { 208 | DirEntry* entry = &dirContents.at(fileOffset); 209 | if (entry->isDirectory) { 210 | iprintf("Entering directory\n"); 211 | // Enter selected directory 212 | chdir (entry->name.c_str()); 213 | getDirectoryContents (dirContents, extensionList); 214 | screenOffset = 0; 215 | fileOffset = 0; 216 | showDirectoryContents (dirContents, screenOffset); 217 | } else { 218 | // Clear the screen 219 | iprintf ("\x1b[2J"); 220 | // Return the chosen file 221 | return entry->name; 222 | } 223 | } 224 | 225 | if (pressed & KEY_B) { 226 | // Go up a directory 227 | chdir (".."); 228 | getDirectoryContents (dirContents, extensionList); 229 | screenOffset = 0; 230 | fileOffset = 0; 231 | showDirectoryContents (dirContents, screenOffset); 232 | } 233 | 234 | if (pressed & KEY_SELECT) { 235 | // boost cpu 236 | REG_SCFG_CLK |= 1; 237 | // Clear the screen 238 | iprintf ("\x1b[2J"); 239 | iprintf ("ARM9 cpu boosted"); 240 | for (int i = 0; i < 60; i++) { swiWaitForVBlank(); } 241 | 242 | getDirectoryContents (dirContents, extensionList); 243 | screenOffset = 0; 244 | fileOffset = 0; 245 | showDirectoryContents (dirContents, screenOffset); 246 | } 247 | 248 | if (pressed & KEY_START) { 249 | 250 | if(browseDsiSd) { 251 | // init the slot1 card 252 | //sysSetCardOwner (BUS_OWNER_ARM9); 253 | //iprintf ("\x1b[2J"); 254 | //iprintf ("Init slot1 card"); 255 | 256 | // Delay half a second for the DS card to stabilise 257 | //for (int i = 0; i < 30; i++) { swiWaitForVBlank(); } 258 | //u32 ndsHeader[0x80]; 259 | //getHeader (ndsHeader); 260 | 261 | chdir ("fat:/"); 262 | getDirectoryContents (dirContents, extensionList); 263 | screenOffset = 0; 264 | fileOffset = 0; 265 | showDirectoryContents (dirContents, screenOffset); 266 | browseDsiSd = false; 267 | } else { 268 | chdir ("sd:/"); 269 | getDirectoryContents (dirContents, extensionList); 270 | screenOffset = 0; 271 | fileOffset = 0; 272 | showDirectoryContents (dirContents, screenOffset); 273 | browseDsiSd = true; 274 | } 275 | } 276 | } 277 | } 278 | -------------------------------------------------------------------------------- /arm9/source/file_browse.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------- 2 | Copyright (C) 2005 - 2010 3 | Michael "Chishm" Chisholm 4 | Dave "WinterMute" Murphy 5 | 6 | This program is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU General Public License 8 | as published by the Free Software Foundation; either version 2 9 | of the License, or (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | 20 | ------------------------------------------------------------------*/ 21 | 22 | #ifndef FILE_BROWSE_H 23 | #define FILE_BROWSE_H 24 | 25 | #include 26 | #include 27 | 28 | std::string browseForFile (const std::vector extensionList); 29 | 30 | 31 | 32 | #endif //FILE_BROWSE_H 33 | -------------------------------------------------------------------------------- /arm9/source/iconTitle.c: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------- 2 | Copyright (C) 2005 - 2013 3 | Michael "Chishm" Chisholm 4 | Dave "WinterMute" Murphy 5 | Claudio "sverx" 6 | Michael "mtheall" Theall 7 | 8 | This program is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU General Public License 10 | as published by the Free Software Foundation; either version 2 11 | of the License, or (at your option) any later version. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program; if not, write to the Free Software 20 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 | 22 | ------------------------------------------------------------------*/ 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include "hbmenu_banner.h" 30 | #include "font6x8.h" 31 | 32 | #define TITLE_POS_X (2*8) 33 | #define TITLE_POS_Y (17*8) 34 | 35 | #define ICON_POS_X 32 36 | #define ICON_POS_Y 80 37 | 38 | #define TEXT_WIDTH ((32-4)*8/6) 39 | 40 | static int bg2, bg3; 41 | static u16 *sprite; 42 | static tNDSBanner banner; 43 | 44 | static inline void writecharRS (int row, int col, u16 car) { 45 | // get map pointer 46 | u16 *gfx = bgGetMapPtr(bg2); 47 | // get old pair of values from VRAM 48 | u16 oldval = gfx[row*(512/8/2)+(col/2)]; 49 | 50 | // clear the half we will update 51 | oldval &= (col%2) ? 0x00FF : 0xFF00; 52 | // apply the updated half 53 | oldval |= (col%2) ? (car<<8) : car; 54 | 55 | // write back to VRAM 56 | gfx[row*(512/8/2)+col/2] = oldval; 57 | } 58 | 59 | static inline void writeRow (int rownum, const char* text) { 60 | int i,len,p=0; 61 | len=strlen(text); 62 | 63 | if (len>TEXT_WIDTH) 64 | len=TEXT_WIDTH; 65 | 66 | // clear left part 67 | for (i=0;i<(TEXT_WIDTH-len)/2;i++) 68 | writecharRS (rownum, i, 0); 69 | 70 | // write centered text 71 | for (i=(TEXT_WIDTH-len)/2;i<((TEXT_WIDTH-len)/2+len);i++) 72 | writecharRS (rownum, i, text[p++]-' '); 73 | 74 | // clear right part 75 | for (i=((TEXT_WIDTH-len)/2+len);i>> HBMenu+ <<<==="); 133 | writeRow (2,"(this text should disappear..."); 134 | writeRow (3,"...otherwise, trouble!)"); 135 | } 136 | 137 | 138 | void iconTitleUpdate (int isdir, const char* name) { 139 | writeRow (0,name); 140 | writeRow (1,""); 141 | writeRow (2,""); 142 | writeRow (3,""); 143 | 144 | if (isdir) { 145 | // text 146 | writeRow (2,"[directory]"); 147 | // icon 148 | clearIcon(); 149 | } else if(strlen(name) >= 5 && strcasecmp(name + strlen(name) - 5, ".argv") == 0) { 150 | // look through the argv file for the corresponding nds file 151 | FILE *fp; 152 | char *line = NULL, *p = NULL; 153 | size_t size = 0; 154 | ssize_t rc; 155 | 156 | // open the argv file 157 | fp = fopen(name,"rb"); 158 | if(fp == NULL) { 159 | writeRow(2, "(can't open file!)"); 160 | clearIcon(); 161 | fclose(fp); return; 162 | } 163 | 164 | // read each line 165 | while((rc = __getline(&line, &size, fp)) > 0) { 166 | // remove comments 167 | if((p = strchr(line, '#')) != NULL) 168 | *p = 0; 169 | 170 | // skip leading whitespace 171 | for(p = line; *p && isspace((int)*p); ++p) 172 | ; 173 | 174 | if(*p) 175 | break; 176 | } 177 | 178 | // done with the file at this point 179 | fclose(fp); 180 | 181 | if(p && *p) { 182 | // we found an argument 183 | struct stat st; 184 | 185 | // truncate everything after first argument 186 | strtok(p, "\n\r\t "); 187 | 188 | if(strlen(p) < 4 || strcasecmp(p + strlen(p) - 4, ".nds") != 0) { 189 | // this is not an nds file! 190 | writeRow(2, "(invalid argv file!)"); 191 | clearIcon(); 192 | } else { 193 | // let's see if this is a file or directory 194 | rc = stat(p, &st); 195 | if(rc != 0) { 196 | // stat failed 197 | writeRow(2, "(can't find argument!)"); 198 | clearIcon(); 199 | } else if(S_ISDIR(st.st_mode)) { 200 | // this is a directory! 201 | writeRow(2, "(invalid argv file!)"); 202 | clearIcon(); 203 | } else { 204 | iconTitleUpdate(false, p); 205 | } 206 | } 207 | } else { 208 | writeRow(2, "(no argument!)"); 209 | clearIcon(); 210 | } 211 | // clean up the allocated line 212 | free(line); 213 | } else { 214 | // this is an nds file! 215 | FILE *fp; 216 | unsigned int Icon_title_offset; 217 | int ret; 218 | 219 | // open file for reading info 220 | fp=fopen (name,"rb"); 221 | if (fp==NULL) { 222 | // text 223 | writeRow (2,"(can't open file!)"); 224 | // icon 225 | clearIcon(); 226 | fclose (fp); return; 227 | } 228 | 229 | ret=fseek (fp, offsetof(tNDSHeader, bannerOffset), SEEK_SET); 230 | if (ret==0) 231 | ret=fread (&Icon_title_offset, sizeof(int), 1, fp); // read if seek succeed 232 | else 233 | ret=0; // if seek fails set to !=1 234 | 235 | if (ret!=1) { 236 | // text 237 | writeRow (2,"(can't read file!)"); 238 | // icon 239 | clearIcon(); 240 | fclose (fp); return; 241 | } 242 | 243 | if (Icon_title_offset==0) { 244 | // text 245 | writeRow (2,"(no title/icon)"); 246 | // icon 247 | clearIcon(); 248 | fclose (fp); return; 249 | } 250 | 251 | ret=fseek (fp,Icon_title_offset,SEEK_SET); 252 | if (ret==0) 253 | ret=fread (&banner, sizeof(banner), 1, fp); // read if seek succeed 254 | else 255 | ret=0; // if seek fails set to !=1 256 | 257 | if (ret!=1) { 258 | // text 259 | writeRow (2,"(can't read icon/title!)"); 260 | // icon 261 | clearIcon(); 262 | fclose (fp); return; 263 | } 264 | 265 | // close file! 266 | fclose (fp); 267 | 268 | // turn unicode into ascii (kind of) 269 | // and convert 0x0A into 0x00 270 | int i; 271 | char *p = (char*)banner.titles[0]; 272 | for (i = 0; i < sizeof(banner.titles[0]); i = i+2) { 273 | if ((p[i] == 0x0A) || (p[i] == 0xFF)) 274 | p[i/2] = 0; 275 | else 276 | p[i/2] = p[i]; 277 | } 278 | 279 | // text 280 | for(i = 0; i < 3; ++i) { 281 | writeRow (i+1, p); 282 | p += strlen(p)+1; 283 | } 284 | 285 | // icon 286 | DC_FlushAll(); 287 | dmaCopy(banner.icon, sprite, sizeof(banner.icon)); 288 | dmaCopy(banner.palette, SPRITE_PALETTE, sizeof(banner.palette)); 289 | } 290 | } 291 | -------------------------------------------------------------------------------- /arm9/source/iconTitle.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------- 2 | Copyright (C) 2005 - 2013 3 | Michael "Chishm" Chisholm 4 | Dave "WinterMute" Murphy 5 | Claudio "sverx" 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License 9 | as published by the Free Software Foundation; either version 2 10 | of the License, or (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software 19 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 | 21 | ------------------------------------------------------------------*/ 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | void iconTitleInit (void); 27 | void iconTitleUpdate (int isdir, const char* name); 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif -------------------------------------------------------------------------------- /arm9/source/inifile.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | inifile.cpp 3 | Copyright (C) 2007 Acekard, www.acekard.com 4 | Copyright (C) 2007-2009 somebody 5 | Copyright (C) 2009 yellow wood goblin 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . 19 | */ 20 | 21 | #include 22 | #include 23 | #include "inifile.h" 24 | #include "stringtool.h" 25 | 26 | static bool freadLine(FILE* f,std::string& str) 27 | { 28 | str.clear(); 29 | __read: 30 | char p=0; 31 | 32 | size_t readed=fread(&p,1,1,f); 33 | if(0==readed) 34 | { 35 | str=""; 36 | return false; 37 | } 38 | if('\n'==p||'\r'==p) 39 | { 40 | str=""; 41 | return true; 42 | } 43 | 44 | while(p!='\n'&&p!='\r'&&readed) 45 | { 46 | str+=p; 47 | readed=fread(&p,1,1,f); 48 | } 49 | 50 | if(str.empty()||""==str) 51 | { 52 | goto __read; 53 | } 54 | 55 | return true; 56 | } 57 | 58 | static void trimString(std::string& str) 59 | { 60 | size_t first=str.find_first_not_of(" \t"),last; 61 | if(first==str.npos) 62 | { 63 | str=""; 64 | } 65 | else 66 | { 67 | last=str.find_last_not_of(" \t"); 68 | if(first>0||(last+1)0) 91 | { 92 | m_FileContainer.clear(); 93 | } 94 | } 95 | 96 | void CIniFile::SetString(const std::string& Section,const std::string& Item,const std::string& Value) 97 | { 98 | if(GetFileString(Section,Item)!=Value) 99 | { 100 | SetFileString(Section,Item,Value); 101 | m_bModified=true; 102 | } 103 | } 104 | 105 | void CIniFile::SetInt(const std::string& Section,const std::string& Item,int Value) 106 | { 107 | std::string strtemp=formatString("%d",Value); 108 | 109 | if(GetFileString(Section,Item)!=strtemp) 110 | { 111 | SetFileString(Section,Item,strtemp); 112 | m_bModified=true; 113 | } 114 | } 115 | 116 | std::string CIniFile::GetString(const std::string& Section,const std::string& Item) 117 | { 118 | return GetFileString(Section,Item); 119 | } 120 | 121 | std::string CIniFile::GetString(const std::string& Section,const std::string& Item,const std::string& DefaultValue) 122 | { 123 | std::string temp=GetString(Section,Item); 124 | if(!m_bLastResult) 125 | { 126 | SetString(Section,Item,DefaultValue); 127 | temp=DefaultValue; 128 | } 129 | return temp; 130 | } 131 | 132 | void CIniFile::GetStringVector(const std::string& Section,const std::string& Item,std::vector< std::string >& strings,char delimiter) 133 | { 134 | std::string strValue=GetFileString(Section,Item); 135 | strings.clear(); 136 | size_t pos; 137 | while((pos=strValue.find(delimiter),strValue.npos!=pos)) 138 | { 139 | const std::string string=strValue.substr(0,pos); 140 | if(string.length()) 141 | { 142 | strings.push_back(string); 143 | } 144 | strValue=strValue.substr(pos+1,strValue.npos); 145 | } 146 | if(strValue.length()) 147 | { 148 | strings.push_back(strValue); 149 | } 150 | } 151 | 152 | void CIniFile::SetStringVector(const std::string& Section,const std::string& Item,std::vector& strings,char delimiter) 153 | { 154 | std::string strValue; 155 | for(size_t ii=0;ii2&&'0'==value[0]&&('x'==value[1]||'X'==value[1])) 167 | return strtol(value.c_str(),NULL,16); 168 | else 169 | return strtol(value.c_str(),NULL,10); 170 | } 171 | 172 | int CIniFile::GetInt(const std::string& Section,const std::string& Item,int DefaultValue) 173 | { 174 | int temp; 175 | temp=GetInt(Section,Item); 176 | if(!m_bLastResult) 177 | { 178 | SetInt(Section,Item,DefaultValue); 179 | temp=DefaultValue; 180 | } 181 | return temp; 182 | } 183 | 184 | bool CIniFile::LoadIniFile(const std::string& FileName) 185 | { 186 | //dbg_printf("load %s\n",FileName.c_str()); 187 | if(FileName!="") m_sFileName=FileName; 188 | 189 | FILE* f=fopen(FileName.c_str(),"rb"); 190 | 191 | if(NULL==f) return false; 192 | 193 | //check for utf8 bom. 194 | char bom[3]; 195 | if(fread(bom,3,1,f)==1&&bom[0]==0xef&&bom[1]==0xbb&&bom[2]==0xbf) ; 196 | else fseek(f,0,SEEK_SET); 197 | 198 | std::string strline(""); 199 | m_FileContainer.clear(); 200 | 201 | while(freadLine(f,strline)) 202 | { 203 | trimString(strline); 204 | if(strline!=""&&';'!=strline[0]&&'/'!=strline[0]&&'!'!=strline[0]) m_FileContainer.push_back(strline); 205 | } 206 | 207 | fclose(f); 208 | 209 | m_bLastResult=false; 210 | m_bModified=false; 211 | 212 | return true; 213 | } 214 | 215 | bool CIniFile::SaveIniFileModified(const std::string& FileName) 216 | { 217 | if(m_bModified==true) 218 | { 219 | return SaveIniFile(FileName); 220 | } 221 | 222 | return true; 223 | } 224 | 225 | bool CIniFile::SaveIniFile(const std::string& FileName) 226 | { 227 | if(FileName!="") 228 | m_sFileName=FileName; 229 | 230 | FILE* f=fopen(m_sFileName.c_str(),"wb"); 231 | if(NULL==f) 232 | { 233 | return false; 234 | } 235 | 236 | for(size_t ii=0;ii0) 242 | { 243 | if(!m_FileContainer[ii-1].empty()&&m_FileContainer[ii-1]!="") 244 | fwrite("\r\n",1,2,f); 245 | } 246 | if(!strline.empty()&&strline!="") 247 | { 248 | fwrite(strline.c_str(),1,strline.length(),f); 249 | fwrite("\r\n",1,2,f); 250 | } 251 | } 252 | 253 | fclose(f); 254 | 255 | m_bModified=false; 256 | 257 | return true; 258 | } 259 | 260 | std::string CIniFile::GetFileString(const std::string& Section,const std::string& Item) 261 | { 262 | std::string strline; 263 | std::string strSection; 264 | std::string strItem; 265 | std::string strValue; 266 | 267 | size_t ii=0; 268 | size_t iFileLines=m_FileContainer.size(); 269 | 270 | if(m_bReadOnly) 271 | { 272 | cSectionCache::iterator it=m_Cache.find(Section); 273 | if((it!=m_Cache.end())) ii=it->second; 274 | } 275 | 276 | m_bLastResult=false; 277 | 278 | if(iFileLines>=0) 279 | { 280 | while(ii0&&rBracketPos!=std::string::npos) 287 | { 288 | strSection=strline.substr(1,rBracketPos-1); 289 | if(m_bReadOnly) m_Cache.insert(std::make_pair(strSection,ii-1)); 290 | if(strSection==Section) 291 | { 292 | while(ii0&&rBracketPos!=std::string::npos) 342 | { 343 | strSection=strline.substr(1,rBracketPos-1); 344 | if(strSection==Section) 345 | { 346 | while(ii 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | #include 32 | 33 | #include "nds_loader_arm9.h" 34 | #include "file_browse.h" 35 | 36 | #include "hbmenu_banner.h" 37 | 38 | #include "iconTitle.h" 39 | 40 | #include "bootsplash.h" 41 | #include "inifile.h" 42 | 43 | using namespace std; 44 | 45 | //--------------------------------------------------------------------------------- 46 | void stop (void) { 47 | //--------------------------------------------------------------------------------- 48 | while (1) { 49 | swiWaitForVBlank(); 50 | } 51 | } 52 | 53 | char filePath[PATH_MAX]; 54 | 55 | //--------------------------------------------------------------------------------- 56 | void doPause() { 57 | //--------------------------------------------------------------------------------- 58 | iprintf("Press start...\n"); 59 | while(1) { 60 | scanKeys(); 61 | if(keysDown() & KEY_START) 62 | break; 63 | swiWaitForVBlank(); 64 | } 65 | scanKeys(); 66 | } 67 | 68 | void runFile(string filename) { 69 | vector argarray; 70 | 71 | if ( strcasecmp (filename.c_str() + filename.size() - 5, ".argv") == 0) { 72 | FILE *argfile = fopen(filename.c_str(),"rb"); 73 | char str[PATH_MAX], *pstr; 74 | const char seps[]= "\n\r\t "; 75 | 76 | while( fgets(str, PATH_MAX, argfile) ) { 77 | // Find comment and end string there 78 | if( (pstr = strchr(str, '#')) ) 79 | *pstr= '\0'; 80 | 81 | // Tokenize arguments 82 | pstr= strtok(str, seps); 83 | 84 | while( pstr != NULL ) { 85 | argarray.push_back(strdup(pstr)); 86 | pstr= strtok(NULL, seps); 87 | } 88 | } 89 | fclose(argfile); 90 | filename = argarray.at(0); 91 | } else { 92 | argarray.push_back(strdup(filename.c_str())); 93 | } 94 | 95 | if ( strcasecmp (filename.c_str() + filename.size() - 4, ".nds") != 0 || argarray.size() == 0 ) { 96 | iprintf("no nds file specified\n"); 97 | } else { 98 | iprintf("Running %s with %d parameters\n", argarray[0], argarray.size()); 99 | int err = runNdsFile (argarray[0], argarray.size(), (const char **)&argarray[0]); 100 | iprintf("Start failed. Error %i\n", err); 101 | doPause(); 102 | } 103 | } 104 | 105 | std::string ReplaceAll(std::string str, const std::string& from, const std::string& to) { 106 | size_t start_pos = 0; 107 | while((start_pos = str.find(from, start_pos)) != std::string::npos) { 108 | str.replace(start_pos, from.length(), to); 109 | start_pos += to.length(); // Handles case where 'to' is a substring of 'from' 110 | } 111 | return str; 112 | } 113 | 114 | 115 | //--------------------------------------------------------------------------------- 116 | int main(int argc, char **argv) { 117 | //--------------------------------------------------------------------------------- 118 | // REG_SCFG_CLK = 0x80; 119 | REG_SCFG_CLK = 0x85; 120 | 121 | bool UseNTRSplash = true; 122 | bool TriggerExit = false; 123 | std::string bootstrapPath = ""; 124 | 125 | if (fatInitDefault()) { 126 | CIniFile hbmenuini( "sd:/_nds/hbmenu.ini" ); 127 | 128 | bootstrapPath = hbmenuini.GetString( "TWL-HOMEBREWMENU", "BOOTSTRAP_INI", ""); 129 | 130 | if(hbmenuini.GetInt("TWL-HOMEBREWMENU","NTR_CLOCK",0) == 0) { UseNTRSplash = false; } 131 | if(hbmenuini.GetInt("TWL-HOMEBREWMENU","DISABLE_ANIMATION",0) == 0) { BootSplashInit(UseNTRSplash); } 132 | if(hbmenuini.GetInt("TWL-HOMEBREWMENU","NTR_CLOCK",0) == 1) { 133 | REG_SCFG_CLK = 0x80; 134 | fifoSendValue32(FIFO_USER_04, 1); 135 | } 136 | 137 | if(hbmenuini.GetInt("TWL-HOMEBREWMENU","RESET_SLOT1",0) == 1) { 138 | if(REG_SCFG_MC == 0x11) { 139 | consoleDemoInit(); 140 | printf("Please insert a cartridge...\n"); 141 | do { swiWaitForVBlank(); } 142 | while (REG_SCFG_MC == 0x11); 143 | } 144 | fifoSendValue32(FIFO_USER_02, 1); 145 | } 146 | 147 | fifoSendValue32(FIFO_USER_01, 1); 148 | fifoWaitValue32(FIFO_USER_03); 149 | 150 | // Only time SCFG should be locked is for compatiblity with NTR retail stuff. 151 | // So NTR SCFG values (that preserve SD access) are always used when locking. 152 | // Locking Arm9 SCFG kills SD access. So that will not occur here. 153 | if(hbmenuini.GetInt("TWL-HOMEBREWMENU","LOCK_ARM7_SCFG_EXT",0) == 1) { 154 | fifoSendValue32(FIFO_USER_05, 1); 155 | REG_SCFG_EXT = 0x83000000; 156 | } else { 157 | if(hbmenuini.GetInt("TWL-HOMEBREWMENU","ENABLE_ALL_TWLSCFG",0) == 1) { 158 | fifoSendValue32(FIFO_USER_06, 1); 159 | REG_SCFG_EXT = 0x8307F100; 160 | } else { 161 | REG_SCFG_EXT = 0x83000000; 162 | } 163 | } 164 | // Tell Arm7 to apply changes. 165 | fifoSendValue32(FIFO_USER_07, 1); 166 | 167 | for (int i = 0; i < 20; i++) { swiWaitForVBlank(); } 168 | } 169 | 170 | // overwrite reboot stub identifier 171 | extern u64 *fake_heap_end; 172 | *fake_heap_end = 0; 173 | 174 | defaultExceptionHandler(); 175 | 176 | int pathLen; 177 | std::string filename; 178 | 179 | iconTitleInit(); 180 | 181 | // Subscreen as a console 182 | videoSetModeSub(MODE_0_2D); 183 | vramSetBankH(VRAM_H_SUB_BG); 184 | consoleInit(NULL, 0, BgType_Text4bpp, BgSize_T_256x256, 15, 0, false, true); 185 | 186 | if (!fatInitDefault()) { 187 | iprintf ("fatinitDefault failed!\n"); 188 | 189 | doPause(); 190 | 191 | TriggerExit = true; 192 | } 193 | 194 | keysSetRepeat(25,5); 195 | 196 | vector extensionList; 197 | extensionList.push_back(".nds"); 198 | extensionList.push_back(".argv"); 199 | 200 | while(1) { 201 | 202 | if(TriggerExit) { 203 | do { swiWaitForVBlank(); scanKeys(); } while (!keysDown()); 204 | break; 205 | } 206 | 207 | filename = browseForFile(extensionList); 208 | 209 | // Construct a command line 210 | getcwd (filePath, PATH_MAX); 211 | pathLen = strlen (filePath); 212 | vector argarray; 213 | 214 | if ( strcasecmp (filename.c_str() + filename.size() - 5, ".argv") == 0) { 215 | FILE *argfile = fopen(filename.c_str(),"rb"); 216 | char str[PATH_MAX], *pstr; 217 | const char seps[]= "\n\r\t "; 218 | 219 | while( fgets(str, PATH_MAX, argfile) ) { 220 | // Find comment and end string there 221 | if( (pstr = strchr(str, '#')) ) 222 | *pstr= '\0'; 223 | 224 | // Tokenize arguments 225 | pstr= strtok(str, seps); 226 | 227 | while( pstr != NULL ) { 228 | argarray.push_back(strdup(pstr)); 229 | pstr= strtok(NULL, seps); 230 | } 231 | } 232 | fclose(argfile); 233 | filename = argarray.at(0); 234 | } else { 235 | argarray.push_back(strdup(filename.c_str())); 236 | } 237 | 238 | if ( strcasecmp (filename.c_str() + filename.size() - 4, ".nds") != 0 || argarray.size() == 0 ) { 239 | iprintf("no nds file specified\n"); 240 | } else { 241 | char *name = argarray.at(0); 242 | strcpy (filePath + pathLen, name); 243 | free(argarray.at(0)); 244 | argarray.at(0) = filePath; 245 | 246 | if (bootstrapPath.size()>0) { 247 | CIniFile bootstrapini( bootstrapPath ); 248 | std::string path = filePath; 249 | path = ReplaceAll( path, "sd:/", "fat:/"); 250 | bootstrapini.SetString("NDS-BOOTSTRAP", "NDS_PATH",path); 251 | filename = bootstrapini.GetString("NDS-BOOTSTRAP", "BOOTSTRAP_PATH",""); 252 | filename = ReplaceAll( filename, "fat:/", "sd:/"); 253 | bootstrapini.SaveIniFile( bootstrapPath); 254 | runFile(filename); 255 | } 256 | 257 | iprintf ("Running %s with %d parameters\n", argarray[0], argarray.size()); 258 | int err = runNdsFile (argarray[0], argarray.size(), (const char **)&argarray[0]); 259 | iprintf ("Start failed. Error %i\n", err); 260 | 261 | } 262 | 263 | while(argarray.size() !=0 ) { 264 | free(argarray.at(0)); 265 | argarray.erase(argarray.begin()); 266 | } 267 | 268 | while (1) { 269 | swiWaitForVBlank(); 270 | scanKeys(); 271 | if (!(keysHeld() & KEY_A)) break; 272 | } 273 | } 274 | 275 | return 0; 276 | } 277 | -------------------------------------------------------------------------------- /arm9/source/nds_loader_arm9.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------- 2 | Copyright (C) 2005 - 2010 3 | Michael "Chishm" Chisholm 4 | Dave "WinterMute" Murphy 5 | 6 | This program is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU General Public License 8 | as published by the Free Software Foundation; either version 2 9 | of the License, or (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | 20 | ------------------------------------------------------------------*/ 21 | 22 | #ifndef NDS_LOADER_ARM9_H 23 | #define NDS_LOADER_ARM9_H 24 | 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | #define LOAD_DEFAULT_NDS 0 31 | 32 | int runNds (const void* loader, u32 loaderSize, u32 cluster, bool initDisc, bool dldiPatchNds, int argc, const char** argv); 33 | 34 | int runNdsFile (const char* filename, int argc, const char** argv); 35 | 36 | bool installBootStub(bool havedsiSD); 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | #endif // NDS_LOADER_ARM7_H 43 | -------------------------------------------------------------------------------- /arm9/source/stringtool.cpp: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------------- 2 | 3 | 4 | Copyright (C) 2007 Acekard, www.acekard.com 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | 24 | 25 | ---------------------------------------------------------------------------------*/ 26 | 27 | #include "stringtool.h" 28 | #include 29 | #include 30 | #include 31 | 32 | std::string formatString( const char* fmt, ... ) 33 | { 34 | const char * f = fmt; 35 | va_list argList; 36 | va_start(argList, fmt); 37 | char * ptempStr = NULL; 38 | size_t max_len = vasiprintf( &ptempStr, f, argList); 39 | std::string str( ptempStr ); 40 | str.resize( max_len ); 41 | free( ptempStr ); 42 | va_end(argList); 43 | return str; 44 | } 45 | 46 | -------------------------------------------------------------------------------- /arm9/source/stringtool.h: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------------- 2 | 3 | 4 | Copyright (C) 2007 Acekard, www.acekard.com 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | 24 | 25 | ---------------------------------------------------------------------------------*/ 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | #ifndef _STRINGTOOL_H_ 36 | #define _STRINGTOOL_H_ 37 | 38 | #include 39 | 40 | std::string formatString( const char* fmt, ... ); 41 | 42 | 43 | 44 | #endif//_STRINGTOOL_H_ 45 | -------------------------------------------------------------------------------- /bootloader/Makefile: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------- 2 | .SUFFIXES: 3 | #--------------------------------------------------------------------------------- 4 | ifeq ($(strip $(DEVKITARM)),) 5 | $(error "Please set DEVKITARM in your environment. export DEVKITARM=devkitARM) 6 | endif 7 | 8 | -include $(DEVKITARM)/ds_rules 9 | 10 | #--------------------------------------------------------------------------------- 11 | # BUILD is the directory where object files & intermediate files will be placed 12 | # SOURCES is a list of directories containing source code 13 | # INCLUDES is a list of directories containing extra header files 14 | #--------------------------------------------------------------------------------- 15 | TARGET := load 16 | BUILD := build 17 | SOURCES := source source/patches 18 | INCLUDES := build 19 | SPECS := specs 20 | 21 | #--------------------------------------------------------------------------------- 22 | # options for code generation 23 | #--------------------------------------------------------------------------------- 24 | ARCH := -mthumb -mthumb-interwork 25 | 26 | CFLAGS := -g -Wall -Os\ 27 | -mcpu=arm7tdmi -mtune=arm7tdmi -fomit-frame-pointer\ 28 | -ffast-math \ 29 | $(ARCH) 30 | 31 | CFLAGS += $(INCLUDE) -DARM7 32 | 33 | ASFLAGS := -g $(ARCH) 34 | LDFLAGS = -nostartfiles -T $(TOPDIR)/load.ld -g $(ARCH) -Wl,-Map,$(TARGET).map 35 | 36 | LIBS := 37 | 38 | #--------------------------------------------------------------------------------- 39 | # list of directories containing libraries, this must be the top level containing 40 | # include and lib 41 | #--------------------------------------------------------------------------------- 42 | LIBDIRS := $(LIBNDS) 43 | 44 | 45 | #--------------------------------------------------------------------------------- 46 | # no real need to edit anything past this point unless you need to add additional 47 | # rules for different file extensions 48 | #--------------------------------------------------------------------------------- 49 | ifneq ($(BUILD),$(notdir $(CURDIR))) 50 | #--------------------------------------------------------------------------------- 51 | 52 | export TOPDIR := $(CURDIR) 53 | export LOADBIN := $(CURDIR)/../data/$(TARGET).bin 54 | export LOADELF := $(CURDIR)/$(TARGET).elf 55 | export DEPSDIR := $(CURDIR)/$(BUILD) 56 | 57 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) 58 | 59 | export CC := $(PREFIX)gcc 60 | export CXX := $(PREFIX)g++ 61 | export AR := $(PREFIX)ar 62 | export OBJCOPY := $(PREFIX)objcopy 63 | 64 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 65 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 66 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 67 | 68 | export OFILES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) 69 | 70 | export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ 71 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 72 | -I$(CURDIR)/$(BUILD) 73 | 74 | export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) 75 | 76 | #--------------------------------------------------------------------------------- 77 | # use CC for linking standard C 78 | #--------------------------------------------------------------------------------- 79 | export LD := $(CC) 80 | #--------------------------------------------------------------------------------- 81 | 82 | .PHONY: $(BUILD) clean 83 | 84 | #--------------------------------------------------------------------------------- 85 | $(BUILD): 86 | @[ -d $@ ] || mkdir -p $@ 87 | @$(MAKE) -C $(BUILD) -f $(CURDIR)/Makefile 88 | 89 | #--------------------------------------------------------------------------------- 90 | clean: 91 | @echo clean ... 92 | @rm -fr $(BUILD) *.elf 93 | 94 | 95 | #--------------------------------------------------------------------------------- 96 | else 97 | 98 | DEPENDS := $(OFILES:.o=.d) 99 | 100 | #--------------------------------------------------------------------------------- 101 | # main targets 102 | #--------------------------------------------------------------------------------- 103 | $(LOADBIN) : $(LOADELF) 104 | @$(OBJCOPY) -O binary $< $@ 105 | @echo built ... $(notdir $@) 106 | 107 | 108 | $(LOADELF) : $(OFILES) 109 | @echo linking $(notdir $@) 110 | @$(LD) $(LDFLAGS) $(OFILES) $(LIBPATHS) $(LIBS) -o $@ 111 | 112 | 113 | 114 | -include $(DEPENDS) 115 | #--------------------------------------------------------------------------------------- 116 | endif 117 | #--------------------------------------------------------------------------------------- -------------------------------------------------------------------------------- /bootloader/load.ld: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm") 2 | OUTPUT_ARCH(arm) 3 | ENTRY(_start) 4 | 5 | MEMORY { 6 | 7 | vram : ORIGIN = 0x06000000, LENGTH = 128K 8 | } 9 | 10 | __vram_start = ORIGIN(vram); 11 | __vram_top = ORIGIN(vram)+ LENGTH(vram); 12 | __sp_irq = __vram_top - 0x60; 13 | __sp_svc = __sp_irq - 0x100; 14 | __sp_usr = __sp_svc - 0x100; 15 | 16 | __irq_flags = __vram_top - 8; 17 | __irq_vector = __vram_top - 4; 18 | 19 | SECTIONS 20 | { 21 | .init : 22 | { 23 | __text_start = . ; 24 | KEEP (*(.init)) 25 | . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ 26 | } >vram = 0xff 27 | 28 | .plt : 29 | { 30 | *(.plt) 31 | } >vram = 0xff 32 | 33 | .text : /* ALIGN (4): */ 34 | { 35 | 36 | *(.text*) 37 | *(.stub) 38 | /* .gnu.warning sections are handled specially by elf32.em. */ 39 | *(.gnu.warning) 40 | *(.gnu.linkonce.t*) 41 | *(.glue_7) 42 | *(.glue_7t) 43 | . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ 44 | } >vram = 0xff 45 | 46 | .fini : 47 | { 48 | KEEP (*(.fini)) 49 | } >vram =0xff 50 | 51 | __text_end = . ; 52 | 53 | .rodata : 54 | { 55 | *(.rodata) 56 | *all.rodata*(*) 57 | *(.roda) 58 | *(.rodata.*) 59 | *(.gnu.linkonce.r*) 60 | SORT(CONSTRUCTORS) 61 | . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ 62 | } >vram = 0xff 63 | 64 | .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >vram 65 | __exidx_start = .; 66 | .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } >vram 67 | __exidx_end = .; 68 | 69 | /* Ensure the __preinit_array_start label is properly aligned. We 70 | could instead move the label definition inside the section, but 71 | the linker would then create the section even if it turns out to 72 | be empty, which isn't pretty. */ 73 | . = ALIGN(32 / 8); 74 | PROVIDE (__preinit_array_start = .); 75 | .preinit_array : { KEEP (*(.preinit_array)) } >vram = 0xff 76 | PROVIDE (__preinit_array_end = .); 77 | PROVIDE (__init_array_start = .); 78 | .init_array : { KEEP (*(.init_array)) } >vram = 0xff 79 | PROVIDE (__init_array_end = .); 80 | PROVIDE (__fini_array_start = .); 81 | .fini_array : { KEEP (*(.fini_array)) } >vram = 0xff 82 | PROVIDE (__fini_array_end = .); 83 | 84 | .ctors : 85 | { 86 | /* gcc uses crtbegin.o to find the start of the constructors, so 87 | we make sure it is first. Because this is a wildcard, it 88 | doesn't matter if the user does not actually link against 89 | crtbegin.o; the linker won't look for a file to match a 90 | wildcard. The wildcard also means that it doesn't matter which 91 | directory crtbegin.o is in. */ 92 | KEEP (*crtbegin.o(.ctors)) 93 | KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors)) 94 | KEEP (*(SORT(.ctors.*))) 95 | KEEP (*(.ctors)) 96 | . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ 97 | } >vram = 0xff 98 | 99 | .dtors : 100 | { 101 | KEEP (*crtbegin.o(.dtors)) 102 | KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors)) 103 | KEEP (*(SORT(.dtors.*))) 104 | KEEP (*(.dtors)) 105 | . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ 106 | } >vram = 0xff 107 | 108 | .eh_frame : 109 | { 110 | KEEP (*(.eh_frame)) 111 | . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ 112 | } >vram = 0xff 113 | 114 | .gcc_except_table : 115 | { 116 | *(.gcc_except_table) 117 | . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ 118 | } >vram = 0xff 119 | .jcr : { KEEP (*(.jcr)) } >vram = 0 120 | .got : { *(.got.plt) *(.got) } >vram = 0 121 | 122 | 123 | .vram ALIGN(4) : 124 | { 125 | __vram_start = ABSOLUTE(.) ; 126 | *(.vram) 127 | *vram.*(.text) 128 | . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ 129 | __vram_end = ABSOLUTE(.) ; 130 | } >vram = 0xff 131 | 132 | 133 | .data ALIGN(4) : { 134 | __data_start = ABSOLUTE(.); 135 | *(.data) 136 | *(.data.*) 137 | *(.gnu.linkonce.d*) 138 | CONSTRUCTORS 139 | . = ALIGN(4); 140 | __data_end = ABSOLUTE(.) ; 141 | } >vram = 0xff 142 | 143 | 144 | 145 | .bss ALIGN(4) : 146 | { 147 | __bss_start = ABSOLUTE(.); 148 | __bss_start__ = ABSOLUTE(.); 149 | *(.dynbss) 150 | *(.gnu.linkonce.b*) 151 | *(.bss*) 152 | *(COMMON) 153 | . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ 154 | } >vram 155 | 156 | __bss_end = . ; 157 | __bss_end__ = . ; 158 | 159 | _end = . ; 160 | __end__ = . ; 161 | PROVIDE (end = _end); 162 | 163 | /* Stabs debugging sections. */ 164 | .stab 0 : { *(.stab) } 165 | .stabstr 0 : { *(.stabstr) } 166 | .stab.excl 0 : { *(.stab.excl) } 167 | .stab.exclstr 0 : { *(.stab.exclstr) } 168 | .stab.index 0 : { *(.stab.index) } 169 | .stab.indexstr 0 : { *(.stab.indexstr) } 170 | .comment 0 : { *(.comment) } 171 | /* DWARF debug sections. 172 | Symbols in the DWARF debugging sections are relative to the beginning 173 | of the section so we begin them at 0. */ 174 | /* DWARF 1 */ 175 | .debug 0 : { *(.debug) } 176 | .line 0 : { *(.line) } 177 | /* GNU DWARF 1 extensions */ 178 | .debug_srcinfo 0 : { *(.debug_srcinfo) } 179 | .debug_sfnames 0 : { *(.debug_sfnames) } 180 | /* DWARF 1.1 and DWARF 2 */ 181 | .debug_aranges 0 : { *(.debug_aranges) } 182 | .debug_pubnames 0 : { *(.debug_pubnames) } 183 | /* DWARF 2 */ 184 | .debug_info 0 : { *(.debug_info) } 185 | .debug_abbrev 0 : { *(.debug_abbrev) } 186 | .debug_line 0 : { *(.debug_line) } 187 | .debug_frame 0 : { *(.debug_frame) } 188 | .debug_str 0 : { *(.debug_str) } 189 | .debug_loc 0 : { *(.debug_loc) } 190 | .debug_macinfo 0 : { *(.debug_macinfo) } 191 | /* SGI/MIPS DWARF 2 extensions */ 192 | .debug_weaknames 0 : { *(.debug_weaknames) } 193 | .debug_funcnames 0 : { *(.debug_funcnames) } 194 | .debug_typenames 0 : { *(.debug_typenames) } 195 | .debug_varnames 0 : { *(.debug_varnames) } 196 | .stack 0x80000 : { _stack = .; *(.stack) } 197 | /* These must appear regardless of . */ 198 | } 199 | -------------------------------------------------------------------------------- /bootloader/source/arm7clear.s: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------- 2 | 3 | Copyright (C) 2005 Michael "Chishm" Chisholm 4 | 5 | This program is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU General Public License 7 | as published by the Free Software Foundation; either version 2 8 | of the License, or (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | 19 | If you use this code, please give due credit and email me about your 20 | project at chishm@hotmail.com 21 | ------------------------------------------------------------------*/ 22 | 23 | .arm 24 | .global arm7clearRAM 25 | .type arm7clearRAM STT_FUNC 26 | arm7clearRAM: 27 | 28 | push {r0-r9} 29 | // clear exclusive IWRAM 30 | // 0380:0000 to 0380:FFFF, total 64KiB 31 | mov r0, #0 32 | mov r1, #0 33 | mov r2, #0 34 | mov r3, #0 35 | mov r4, #0 36 | mov r5, #0 37 | mov r6, #0 38 | mov r7, #0 39 | mov r8, #0x03800000 40 | sub r8, #0x00008000 41 | mov r9, #0x03800000 42 | orr r9, r9, #0x10000 43 | clear_IWRAM_loop: 44 | stmia r8!, {r0, r1, r2, r3, r4, r5, r6, r7} 45 | cmp r8, r9 46 | blt clear_IWRAM_loop 47 | 48 | // clear most of EWRAM - except after RAM end - 0xc000, which has the bootstub 49 | mov r8, #0x02000000 50 | 51 | ldr r9,=0x4004008 52 | ldr r9,[r9] 53 | ands r9,r9,#0x8000 54 | bne dsi_mode 55 | 56 | mov r9, #0x02400000 57 | b ds_mode 58 | dsi_mode: 59 | mov r9, #0x03000000 60 | ds_mode: 61 | sub r9, #0x0000c000 62 | clear_EWRAM_loop: 63 | stmia r8!, {r0, r1, r2, r3, r4, r5, r6, r7} 64 | cmp r8, r9 65 | blt clear_EWRAM_loop 66 | 67 | pop {r0-r9} 68 | 69 | bx lr 70 | 71 | -------------------------------------------------------------------------------- /bootloader/source/arm9clear.arm.c: -------------------------------------------------------------------------------- 1 | #define ARM9 2 | #undef ARM7 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include "boot.h" 15 | 16 | /*------------------------------------------------------------------------- 17 | resetMemory2_ARM9 18 | Clears the ARM9's DMA channels and resets video memory 19 | Written by Darkain. 20 | Modified by Chishm: 21 | * Changed MultiNDS specific stuff 22 | --------------------------------------------------------------------------*/ 23 | void __attribute__ ((long_call)) __attribute__((naked)) __attribute__((noreturn)) resetMemory2_ARM9 (void) 24 | { 25 | register int i; 26 | 27 | //clear out ARM9 DMA channels 28 | for (i=0; i<4; i++) { 29 | DMA_CR(i) = 0; 30 | DMA_SRC(i) = 0; 31 | DMA_DEST(i) = 0; 32 | TIMER_CR(i) = 0; 33 | TIMER_DATA(i) = 0; 34 | } 35 | 36 | VRAM_CR = (VRAM_CR & 0xffff0000) | 0x00008080 ; 37 | 38 | u16 *mainregs = (u16*)0x04000000; 39 | u16 *subregs = (u16*)0x04001000; 40 | 41 | for (i=0; i<43; i++) { 42 | mainregs[i] = 0; 43 | subregs[i] = 0; 44 | } 45 | 46 | REG_DISPSTAT = 0; 47 | 48 | VRAM_A_CR = 0; 49 | VRAM_B_CR = 0; 50 | // Don't mess with the ARM7's VRAM 51 | // VRAM_C_CR = 0; 52 | VRAM_D_CR = 0; 53 | VRAM_E_CR = 0; 54 | VRAM_F_CR = 0; 55 | VRAM_G_CR = 0; 56 | VRAM_H_CR = 0; 57 | VRAM_I_CR = 0; 58 | REG_POWERCNT = 0x820F; 59 | 60 | //set shared ram to ARM7 61 | WRAM_CR = 0x03; 62 | 63 | // Return to passme loop 64 | *((vu32*)0x02FFFE04) = (u32)0xE59FF018; // ldr pc, 0x02FFFE24 65 | *((vu32*)0x02FFFE24) = (u32)0x02FFFE04; // Set ARM9 Loop address 66 | 67 | asm volatile( 68 | "\tbx %0\n" 69 | : : "r" (0x02FFFE04) 70 | ); 71 | while(1); 72 | } 73 | 74 | /*------------------------------------------------------------------------- 75 | startBinary_ARM9 76 | Jumps to the ARM9 NDS binary in sync with the display and ARM7 77 | Written by Darkain. 78 | Modified by Chishm: 79 | * Removed MultiNDS specific stuff 80 | --------------------------------------------------------------------------*/ 81 | void __attribute__ ((long_call)) __attribute__((noreturn)) __attribute__((naked)) startBinary_ARM9 (void) 82 | { 83 | REG_IME=0; 84 | REG_EXMEMCNT = 0xE880; 85 | // set ARM9 load address to 0 and wait for it to change again 86 | ARM9_START_FLAG = 0; 87 | while(REG_VCOUNT!=191); 88 | while(REG_VCOUNT==191); 89 | while ( ARM9_START_FLAG != 1 ); 90 | VoidFn arm9code = *(VoidFn*)(0x2FFFE24); 91 | arm9code(); 92 | while(1); 93 | } 94 | 95 | -------------------------------------------------------------------------------- /bootloader/source/bios.s: -------------------------------------------------------------------------------- 1 | .text 2 | .align 4 3 | 4 | .thumb 5 | 6 | @--------------------------------------------------------------------------------- 7 | .global swiDelay 8 | .thumb_func 9 | @--------------------------------------------------------------------------------- 10 | swiDelay: 11 | @--------------------------------------------------------------------------------- 12 | swi 0x03 13 | bx lr 14 | -------------------------------------------------------------------------------- /bootloader/source/boot.c: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------- 2 | boot.c 3 | 4 | BootLoader 5 | Loads a file into memory and runs it 6 | 7 | All resetMemory and startBinary functions are based 8 | on the MultiNDS loader by Darkain. 9 | Original source available at: 10 | http://cvs.sourceforge.net/viewcvs.py/ndslib/ndslib/examples/loader/boot/main.cpp 11 | 12 | License: 13 | Copyright (C) 2005 Michael "Chishm" Chisholm 14 | 15 | This program is free software; you can redistribute it and/or 16 | modify it under the terms of the GNU General Public License 17 | as published by the Free Software Foundation; either version 2 18 | of the License, or (at your option) any later version. 19 | 20 | This program is distributed in the hope that it will be useful, 21 | but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | GNU General Public License for more details. 24 | 25 | You should have received a copy of the GNU General Public License 26 | along with this program; if not, write to the Free Software 27 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 28 | 29 | If you use this code, please give due credit and email me about your 30 | project at chishm@hotmail.com 31 | 32 | Helpful information: 33 | This code runs from VRAM bank C on ARM7 34 | ------------------------------------------------------------------*/ 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #define ARM9 42 | #undef ARM7 43 | #include 44 | #include 45 | #include 46 | #undef ARM9 47 | #define ARM7 48 | #include 49 | 50 | #include "fat.h" 51 | #include "dldi_patcher.h" 52 | #include "card.h" 53 | #include "boot.h" 54 | 55 | void arm7clearRAM(); 56 | int sdmmc_sdcard_readsectors(u32 sector_no, u32 numsectors, void *out); 57 | int sdmmc_sdcard_init(); 58 | void sdmmc_controller_init(); 59 | 60 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 61 | // Important things 62 | #define TEMP_MEM 0x02FFE000 63 | #define NDS_HEAD 0x02FFFE00 64 | #define TEMP_ARM9_START_ADDRESS (*(vu32*)0x02FFFFF4) 65 | 66 | 67 | const char* bootName = "BOOT.NDS"; 68 | 69 | extern unsigned long _start; 70 | extern unsigned long storedFileCluster; 71 | extern unsigned long initDisc; 72 | extern unsigned long wantToPatchDLDI; 73 | extern unsigned long argStart; 74 | extern unsigned long argSize; 75 | extern unsigned long dsiSD; 76 | 77 | //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 78 | // Firmware stuff 79 | 80 | #define FW_READ 0x03 81 | 82 | void boot_readFirmware (uint32 address, uint8 * buffer, uint32 size) { 83 | uint32 index; 84 | 85 | // Read command 86 | while (REG_SPICNT & SPI_BUSY); 87 | REG_SPICNT = SPI_ENABLE | SPI_CONTINUOUS | SPI_DEVICE_NVRAM; 88 | REG_SPIDATA = FW_READ; 89 | while (REG_SPICNT & SPI_BUSY); 90 | 91 | // Set the address 92 | REG_SPIDATA = (address>>16) & 0xFF; 93 | while (REG_SPICNT & SPI_BUSY); 94 | REG_SPIDATA = (address>>8) & 0xFF; 95 | while (REG_SPICNT & SPI_BUSY); 96 | REG_SPIDATA = (address) & 0xFF; 97 | while (REG_SPICNT & SPI_BUSY); 98 | 99 | for (index = 0; index < size; index++) { 100 | REG_SPIDATA = 0; 101 | while (REG_SPICNT & SPI_BUSY); 102 | buffer[index] = REG_SPIDATA & 0xFF; 103 | } 104 | REG_SPICNT = 0; 105 | } 106 | 107 | 108 | static inline void copyLoop (u32* dest, const u32* src, u32 size) { 109 | size = (size +3) & ~3; 110 | do { 111 | *dest++ = *src++; 112 | } while (size -= 4); 113 | } 114 | 115 | //#define resetCpu() __asm volatile("\tswi 0x000000\n"); 116 | 117 | /*------------------------------------------------------------------------- 118 | passArgs_ARM7 119 | Copies the command line arguments to the end of the ARM9 binary, 120 | then sets a flag in memory for the loaded NDS to use 121 | --------------------------------------------------------------------------*/ 122 | void passArgs_ARM7 (void) { 123 | u32 ARM9_DST = *((u32*)(NDS_HEAD + 0x028)); 124 | u32 ARM9_LEN = *((u32*)(NDS_HEAD + 0x02C)); 125 | u32* argSrc; 126 | u32* argDst; 127 | 128 | if (!argStart || !argSize) return; 129 | 130 | argSrc = (u32*)(argStart + (int)&_start); 131 | 132 | argDst = (u32*)((ARM9_DST + ARM9_LEN + 3) & ~3); // Word aligned 133 | 134 | copyLoop(argDst, argSrc, argSize); 135 | 136 | __system_argv->argvMagic = ARGV_MAGIC; 137 | __system_argv->commandLine = (char*)argDst; 138 | __system_argv->length = argSize; 139 | } 140 | 141 | 142 | 143 | 144 | /*------------------------------------------------------------------------- 145 | resetMemory_ARM7 146 | Clears all of the NDS's RAM that is visible to the ARM7 147 | Written by Darkain. 148 | Modified by Chishm: 149 | * Added STMIA clear mem loop 150 | --------------------------------------------------------------------------*/ 151 | void resetMemory_ARM7 (void) 152 | { 153 | int i; 154 | u8 settings1, settings2; 155 | u32 settingsOffset = 0; 156 | 157 | REG_IME = 0; 158 | 159 | for (i=0; i<16; i++) { 160 | SCHANNEL_CR(i) = 0; 161 | SCHANNEL_TIMER(i) = 0; 162 | SCHANNEL_SOURCE(i) = 0; 163 | SCHANNEL_LENGTH(i) = 0; 164 | } 165 | 166 | REG_SOUNDCNT = 0; 167 | 168 | //clear out ARM7 DMA channels and timers 169 | for (i=0; i<4; i++) { 170 | DMA_CR(i) = 0; 171 | DMA_SRC(i) = 0; 172 | DMA_DEST(i) = 0; 173 | TIMER_CR(i) = 0; 174 | TIMER_DATA(i) = 0; 175 | } 176 | 177 | arm7clearRAM(); 178 | 179 | REG_IE = 0; 180 | REG_IF = ~0; 181 | (*(vu32*)(0x04000000-4)) = 0; //IRQ_HANDLER ARM7 version 182 | (*(vu32*)(0x04000000-8)) = ~0; //VBLANK_INTR_WAIT_FLAGS, ARM7 version 183 | REG_POWERCNT = 1; //turn off power to stuff 184 | 185 | // Get settings location 186 | boot_readFirmware((u32)0x00020, (u8*)&settingsOffset, 0x2); 187 | settingsOffset *= 8; 188 | 189 | // Reload DS Firmware settings 190 | boot_readFirmware(settingsOffset + 0x070, &settings1, 0x1); 191 | boot_readFirmware(settingsOffset + 0x170, &settings2, 0x1); 192 | 193 | if ((settings1 & 0x7F) == ((settings2+1) & 0x7F)) { 194 | boot_readFirmware(settingsOffset + 0x000, (u8*)0x02FFFC80, 0x70); 195 | } else { 196 | boot_readFirmware(settingsOffset + 0x100, (u8*)0x02FFFC80, 0x70); 197 | } 198 | } 199 | 200 | 201 | void loadBinary_ARM7 (u32 fileCluster) 202 | { 203 | u32 ndsHeader[0x170>>2]; 204 | 205 | // read NDS header 206 | fileRead ((char*)ndsHeader, fileCluster, 0, 0x170); 207 | // read ARM9 info from NDS header 208 | u32 ARM9_SRC = ndsHeader[0x020>>2]; 209 | char* ARM9_DST = (char*)ndsHeader[0x028>>2]; 210 | u32 ARM9_LEN = ndsHeader[0x02C>>2]; 211 | // read ARM7 info from NDS header 212 | u32 ARM7_SRC = ndsHeader[0x030>>2]; 213 | char* ARM7_DST = (char*)ndsHeader[0x038>>2]; 214 | u32 ARM7_LEN = ndsHeader[0x03C>>2]; 215 | 216 | // Load binaries into memory 217 | fileRead(ARM9_DST, fileCluster, ARM9_SRC, ARM9_LEN); 218 | fileRead(ARM7_DST, fileCluster, ARM7_SRC, ARM7_LEN); 219 | 220 | // first copy the header to its proper location, excluding 221 | // the ARM9 start address, so as not to start it 222 | TEMP_ARM9_START_ADDRESS = ndsHeader[0x024>>2]; // Store for later 223 | ndsHeader[0x024>>2] = 0; 224 | dmaCopyWords(3, (void*)ndsHeader, (void*)NDS_HEAD, 0x170); 225 | } 226 | 227 | /*------------------------------------------------------------------------- 228 | startBinary_ARM7 229 | Jumps to the ARM7 NDS binary in sync with the display and ARM9 230 | Written by Darkain. 231 | Modified by Chishm: 232 | * Removed MultiNDS specific stuff 233 | --------------------------------------------------------------------------*/ 234 | void startBinary_ARM7 (void) { 235 | REG_IME=0; 236 | while(REG_VCOUNT!=191); 237 | while(REG_VCOUNT==191); 238 | // copy NDS ARM9 start address into the header, starting ARM9 239 | *((vu32*)0x02FFFE24) = TEMP_ARM9_START_ADDRESS; 240 | ARM9_START_FLAG = 1; 241 | // Start ARM7 242 | VoidFn arm7code = *(VoidFn*)(0x2FFFE34); 243 | arm7code(); 244 | } 245 | 246 | int sdmmc_sd_readsectors(u32 sector_no, u32 numsectors, void *out); 247 | //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 248 | // Main function 249 | bool sdmmc_inserted() { 250 | return true; 251 | } 252 | 253 | bool sdmmc_startup() { 254 | sdmmc_controller_init(); 255 | return sdmmc_sdcard_init() == 0; 256 | } 257 | 258 | bool sdmmc_readsectors(u32 sector_no, u32 numsectors, void *out) { 259 | return sdmmc_sdcard_readsectors(sector_no, numsectors, out) == 0; 260 | } 261 | 262 | int main (void) { 263 | if (dsiSD) { 264 | _io_dldi.fn_readSectors = sdmmc_readsectors; 265 | _io_dldi.fn_isInserted = sdmmc_inserted; 266 | _io_dldi.fn_startup = sdmmc_startup; 267 | } 268 | 269 | u32 fileCluster = storedFileCluster; 270 | // Init card 271 | if(!FAT_InitFiles(initDisc)) 272 | { 273 | return -1; 274 | } 275 | if ((fileCluster < CLUSTER_FIRST) || (fileCluster >= CLUSTER_EOF)) /* Invalid file cluster specified */ 276 | { 277 | fileCluster = getBootFileCluster(bootName); 278 | } 279 | if (fileCluster == CLUSTER_FREE) 280 | { 281 | return -1; 282 | } 283 | 284 | // ARM9 clears its memory part 2 285 | // copy ARM9 function to RAM, and make the ARM9 jump to it 286 | copyLoop((void*)TEMP_MEM, (void*)resetMemory2_ARM9, resetMemory2_ARM9_size); 287 | (*(vu32*)0x02FFFE24) = (u32)TEMP_MEM; // Make ARM9 jump to the function 288 | // Wait until the ARM9 has completed its task 289 | while ((*(vu32*)0x02FFFE24) == (u32)TEMP_MEM); 290 | 291 | // Get ARM7 to clear RAM 292 | resetMemory_ARM7(); 293 | 294 | // ARM9 enters a wait loop 295 | // copy ARM9 function to RAM, and make the ARM9 jump to it 296 | copyLoop((void*)TEMP_MEM, (void*)startBinary_ARM9, startBinary_ARM9_size); 297 | (*(vu32*)0x02FFFE24) = (u32)TEMP_MEM; // Make ARM9 jump to the function 298 | 299 | // Load the NDS file 300 | loadBinary_ARM7(fileCluster); 301 | 302 | // Patch with DLDI if desired 303 | if (wantToPatchDLDI) { 304 | dldiPatchBinary ((u8*)((u32*)NDS_HEAD)[0x0A], ((u32*)NDS_HEAD)[0x0B]); 305 | } 306 | 307 | // Pass command line arguments to loaded program 308 | passArgs_ARM7(); 309 | 310 | startBinary_ARM7(); 311 | 312 | return 0; 313 | } 314 | 315 | -------------------------------------------------------------------------------- /bootloader/source/boot.h: -------------------------------------------------------------------------------- 1 | #ifndef _BOOT_H_ 2 | #define _BOOT_H_ 3 | 4 | #define resetMemory2_ARM9_size 0x400 5 | void __attribute__ ((long_call)) __attribute__((naked)) __attribute__((noreturn)) resetMemory2_ARM9(); 6 | #define startBinary_ARM9_size 0x100 7 | void __attribute__ ((long_call)) __attribute__((noreturn)) __attribute__((naked)) startBinary_ARM9 (); 8 | #define ARM9_START_FLAG (*(vu8*)0x02FFFDFB) 9 | 10 | #endif // _BOOT_H_ 11 | -------------------------------------------------------------------------------- /bootloader/source/card.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------- 2 | 3 | Copyright (C) 2005 Michael "Chishm" Chisholm 4 | 5 | This program is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU General Public License 7 | as published by the Free Software Foundation; either version 2 8 | of the License, or (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | 19 | If you use this code, please give due credit and email me about your 20 | project at chishm@hotmail.com 21 | ------------------------------------------------------------------*/ 22 | 23 | #ifndef CARD_H 24 | #define CARD_H 25 | 26 | #include "disc_io.h" 27 | #include "io_dldi.h" 28 | 29 | static inline bool CARD_StartUp (void) { 30 | return _io_dldi.fn_startup(); 31 | } 32 | 33 | static inline bool CARD_IsInserted (void) { 34 | return _io_dldi.fn_isInserted(); 35 | } 36 | 37 | static inline bool CARD_ReadSector (u32 sector, void *buffer) { 38 | return _io_dldi.fn_readSectors(sector, 1, buffer); 39 | } 40 | 41 | static inline bool CARD_ReadSectors (u32 sector, int count, void *buffer) { 42 | return _io_dldi.fn_readSectors(sector, count, buffer); 43 | } 44 | 45 | #endif // CARD_H 46 | -------------------------------------------------------------------------------- /bootloader/source/disc_io.h: -------------------------------------------------------------------------------- 1 | /* 2 | disc_io.h 3 | Interface template for low level disc functions. 4 | 5 | Copyright (c) 2006 Michael "Chishm" Chisholm 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation and/or 14 | other materials provided with the distribution. 15 | 3. The name of the author may not be used to endorse or promote products derived 16 | from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 20 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 26 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | 2006-07-11 - Chishm 29 | * Original release 30 | 31 | 2006-07-16 - Chishm 32 | * Renamed _CF_USE_DMA to _IO_USE_DMA 33 | * Renamed _CF_ALLOW_UNALIGNED to _IO_ALLOW_UNALIGNED 34 | */ 35 | 36 | #ifndef _DISC_IO_H 37 | #define _DISC_IO_H 38 | 39 | #include 40 | #define BYTES_PER_SECTOR 512 41 | 42 | //---------------------------------------------------------------------- 43 | // Customisable features 44 | 45 | // Use DMA to read the card, remove this line to use normal reads/writes 46 | // #define _IO_USE_DMA 47 | 48 | // Allow buffers not alligned to 16 bits when reading files. 49 | // Note that this will slow down access speed, so only use if you have to. 50 | // It is also incompatible with DMA 51 | #define _IO_ALLOW_UNALIGNED 52 | 53 | #if defined _IO_USE_DMA && defined _IO_ALLOW_UNALIGNED 54 | #error "You can't use both DMA and unaligned memory" 55 | #endif 56 | 57 | #define FEATURE_MEDIUM_CANREAD 0x00000001 58 | #define FEATURE_MEDIUM_CANWRITE 0x00000002 59 | #define FEATURE_SLOT_GBA 0x00000010 60 | #define FEATURE_SLOT_NDS 0x00000020 61 | 62 | typedef bool (* FN_MEDIUM_STARTUP)(void) ; 63 | typedef bool (* FN_MEDIUM_ISINSERTED)(void) ; 64 | typedef bool (* FN_MEDIUM_READSECTORS)(u32 sector, u32 numSectors, void* buffer) ; 65 | typedef bool (* FN_MEDIUM_WRITESECTORS)(u32 sector, u32 numSectors, const void* buffer) ; 66 | typedef bool (* FN_MEDIUM_CLEARSTATUS)(void) ; 67 | typedef bool (* FN_MEDIUM_SHUTDOWN)(void) ; 68 | 69 | struct IO_INTERFACE_STRUCT { 70 | unsigned long ioType ; 71 | unsigned long features ; 72 | FN_MEDIUM_STARTUP fn_startup ; 73 | FN_MEDIUM_ISINSERTED fn_isInserted ; 74 | FN_MEDIUM_READSECTORS fn_readSectors ; 75 | FN_MEDIUM_WRITESECTORS fn_writeSectors ; 76 | FN_MEDIUM_CLEARSTATUS fn_clearStatus ; 77 | FN_MEDIUM_SHUTDOWN fn_shutdown ; 78 | } ; 79 | 80 | typedef struct IO_INTERFACE_STRUCT IO_INTERFACE ; 81 | 82 | #endif // define _DISC_IO_H 83 | -------------------------------------------------------------------------------- /bootloader/source/dldi_patcher.c: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------- 2 | 3 | Copyright (C) 2005 Michael "Chishm" Chisholm 4 | 5 | This program is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU General Public License 7 | as published by the Free Software Foundation; either version 2 8 | of the License, or (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | 19 | If you use this code, please give due credit and email me about your 20 | project at chishm@hotmail.com 21 | ------------------------------------------------------------------*/ 22 | 23 | #include 24 | #include 25 | #include "dldi_patcher.h" 26 | 27 | #define FIX_ALL 0x01 28 | #define FIX_GLUE 0x02 29 | #define FIX_GOT 0x04 30 | #define FIX_BSS 0x08 31 | 32 | enum DldiOffsets { 33 | DO_magicString = 0x00, // "\xED\xA5\x8D\xBF Chishm" 34 | DO_magicToken = 0x00, // 0xBF8DA5ED 35 | DO_magicShortString = 0x04, // " Chishm" 36 | DO_version = 0x0C, 37 | DO_driverSize = 0x0D, 38 | DO_fixSections = 0x0E, 39 | DO_allocatedSpace = 0x0F, 40 | 41 | DO_friendlyName = 0x10, 42 | 43 | DO_text_start = 0x40, // Data start 44 | DO_data_end = 0x44, // Data end 45 | DO_glue_start = 0x48, // Interworking glue start -- Needs address fixing 46 | DO_glue_end = 0x4C, // Interworking glue end 47 | DO_got_start = 0x50, // GOT start -- Needs address fixing 48 | DO_got_end = 0x54, // GOT end 49 | DO_bss_start = 0x58, // bss start -- Needs setting to zero 50 | DO_bss_end = 0x5C, // bss end 51 | 52 | // IO_INTERFACE data 53 | DO_ioType = 0x60, 54 | DO_features = 0x64, 55 | DO_startup = 0x68, 56 | DO_isInserted = 0x6C, 57 | DO_readSectors = 0x70, 58 | DO_writeSectors = 0x74, 59 | DO_clearStatus = 0x78, 60 | DO_shutdown = 0x7C, 61 | DO_code = 0x80 62 | }; 63 | 64 | static addr_t readAddr (data_t *mem, addr_t offset) { 65 | return ((addr_t*)mem)[offset/sizeof(addr_t)]; 66 | } 67 | 68 | static void writeAddr (data_t *mem, addr_t offset, addr_t value) { 69 | ((addr_t*)mem)[offset/sizeof(addr_t)] = value; 70 | } 71 | 72 | 73 | static addr_t quickFind (const data_t* data, const data_t* search, size_t dataLen, size_t searchLen) { 74 | const int* dataChunk = (const int*) data; 75 | int searchChunk = ((const int*)search)[0]; 76 | addr_t i; 77 | addr_t dataChunkEnd = (addr_t)(dataLen / sizeof(int)); 78 | 79 | for ( i = 0; i < dataChunkEnd; i++) { 80 | if (dataChunk[i] == searchChunk) { 81 | if ((i*sizeof(int) + searchLen) > dataLen) { 82 | return -1; 83 | } 84 | if (memcmp (&data[i*sizeof(int)], search, searchLen) == 0) { 85 | return i*sizeof(int); 86 | } 87 | } 88 | } 89 | 90 | return -1; 91 | } 92 | 93 | static const data_t dldiMagicString[] = "\xED\xA5\x8D\xBF Chishm"; // Normal DLDI file 94 | static const data_t dldiMagicLoaderString[] = "\xEE\xA5\x8D\xBF Chishm"; // Different to a normal DLDI file 95 | #define DEVICE_TYPE_DLDI 0x49444C44 96 | 97 | extern const u32 _io_dldi; 98 | 99 | bool dldiPatchBinary (data_t *binData, u32 binSize) { 100 | 101 | addr_t memOffset; // Offset of DLDI after the file is loaded into memory 102 | addr_t patchOffset; // Position of patch destination in the file 103 | addr_t relocationOffset; // Value added to all offsets within the patch to fix it properly 104 | addr_t ddmemOffset; // Original offset used in the DLDI file 105 | addr_t ddmemStart; // Start of range that offsets can be in the DLDI file 106 | addr_t ddmemEnd; // End of range that offsets can be in the DLDI file 107 | addr_t ddmemSize; // Size of range that offsets can be in the DLDI file 108 | addr_t addrIter; 109 | 110 | data_t *pDH; 111 | data_t *pAH; 112 | 113 | size_t dldiFileSize = 0; 114 | 115 | // Find the DLDI reserved space in the file 116 | patchOffset = quickFind (binData, dldiMagicString, binSize, sizeof(dldiMagicLoaderString)); 117 | 118 | if (patchOffset < 0) { 119 | // does not have a DLDI section 120 | return false; 121 | } 122 | 123 | pDH = (data_t*)(((u32*)(&_io_dldi)) - 24); 124 | pAH = &(binData[patchOffset]); 125 | 126 | if (*((u32*)(pDH + DO_ioType)) == DEVICE_TYPE_DLDI) { 127 | // No DLDI patch 128 | return false; 129 | } 130 | 131 | if (pDH[DO_driverSize] > pAH[DO_allocatedSpace]) { 132 | // Not enough space for patch 133 | return false; 134 | } 135 | 136 | dldiFileSize = 1 << pDH[DO_driverSize]; 137 | 138 | memOffset = readAddr (pAH, DO_text_start); 139 | if (memOffset == 0) { 140 | memOffset = readAddr (pAH, DO_startup) - DO_code; 141 | } 142 | ddmemOffset = readAddr (pDH, DO_text_start); 143 | relocationOffset = memOffset - ddmemOffset; 144 | 145 | ddmemStart = readAddr (pDH, DO_text_start); 146 | ddmemSize = (1 << pDH[DO_driverSize]); 147 | ddmemEnd = ddmemStart + ddmemSize; 148 | 149 | // Remember how much space is actually reserved 150 | pDH[DO_allocatedSpace] = pAH[DO_allocatedSpace]; 151 | // Copy the DLDI patch into the application 152 | memcpy (pAH, pDH, dldiFileSize); 153 | 154 | // Fix the section pointers in the header 155 | writeAddr (pAH, DO_text_start, readAddr (pAH, DO_text_start) + relocationOffset); 156 | writeAddr (pAH, DO_data_end, readAddr (pAH, DO_data_end) + relocationOffset); 157 | writeAddr (pAH, DO_glue_start, readAddr (pAH, DO_glue_start) + relocationOffset); 158 | writeAddr (pAH, DO_glue_end, readAddr (pAH, DO_glue_end) + relocationOffset); 159 | writeAddr (pAH, DO_got_start, readAddr (pAH, DO_got_start) + relocationOffset); 160 | writeAddr (pAH, DO_got_end, readAddr (pAH, DO_got_end) + relocationOffset); 161 | writeAddr (pAH, DO_bss_start, readAddr (pAH, DO_bss_start) + relocationOffset); 162 | writeAddr (pAH, DO_bss_end, readAddr (pAH, DO_bss_end) + relocationOffset); 163 | // Fix the function pointers in the header 164 | writeAddr (pAH, DO_startup, readAddr (pAH, DO_startup) + relocationOffset); 165 | writeAddr (pAH, DO_isInserted, readAddr (pAH, DO_isInserted) + relocationOffset); 166 | writeAddr (pAH, DO_readSectors, readAddr (pAH, DO_readSectors) + relocationOffset); 167 | writeAddr (pAH, DO_writeSectors, readAddr (pAH, DO_writeSectors) + relocationOffset); 168 | writeAddr (pAH, DO_clearStatus, readAddr (pAH, DO_clearStatus) + relocationOffset); 169 | writeAddr (pAH, DO_shutdown, readAddr (pAH, DO_shutdown) + relocationOffset); 170 | 171 | // Put the correct DLDI magic string back into the DLDI header 172 | memcpy (pAH, dldiMagicString, sizeof (dldiMagicString)); 173 | 174 | if (pDH[DO_fixSections] & FIX_ALL) { 175 | // Search through and fix pointers within the data section of the file 176 | for (addrIter = (readAddr(pDH, DO_text_start) - ddmemStart); addrIter < (readAddr(pDH, DO_data_end) - ddmemStart); addrIter++) { 177 | if ((ddmemStart <= readAddr(pAH, addrIter)) && (readAddr(pAH, addrIter) < ddmemEnd)) { 178 | writeAddr (pAH, addrIter, readAddr(pAH, addrIter) + relocationOffset); 179 | } 180 | } 181 | } 182 | 183 | if (pDH[DO_fixSections] & FIX_GLUE) { 184 | // Search through and fix pointers within the glue section of the file 185 | for (addrIter = (readAddr(pDH, DO_glue_start) - ddmemStart); addrIter < (readAddr(pDH, DO_glue_end) - ddmemStart); addrIter++) { 186 | if ((ddmemStart <= readAddr(pAH, addrIter)) && (readAddr(pAH, addrIter) < ddmemEnd)) { 187 | writeAddr (pAH, addrIter, readAddr(pAH, addrIter) + relocationOffset); 188 | } 189 | } 190 | } 191 | 192 | if (pDH[DO_fixSections] & FIX_GOT) { 193 | // Search through and fix pointers within the Global Offset Table section of the file 194 | for (addrIter = (readAddr(pDH, DO_got_start) - ddmemStart); addrIter < (readAddr(pDH, DO_got_end) - ddmemStart); addrIter++) { 195 | if ((ddmemStart <= readAddr(pAH, addrIter)) && (readAddr(pAH, addrIter) < ddmemEnd)) { 196 | writeAddr (pAH, addrIter, readAddr(pAH, addrIter) + relocationOffset); 197 | } 198 | } 199 | } 200 | 201 | if (pDH[DO_fixSections] & FIX_BSS) { 202 | // Initialise the BSS to 0 203 | memset (&pAH[readAddr(pDH, DO_bss_start) - ddmemStart] , 0, readAddr(pDH, DO_bss_end) - readAddr(pDH, DO_bss_start)); 204 | } 205 | 206 | return true; 207 | } 208 | -------------------------------------------------------------------------------- /bootloader/source/dldi_patcher.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------- 2 | 3 | Copyright (C) 2005 Michael "Chishm" Chisholm 4 | 5 | This program is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU General Public License 7 | as published by the Free Software Foundation; either version 2 8 | of the License, or (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | 19 | If you use this code, please give due credit and email me about your 20 | project at chishm@hotmail.com 21 | ------------------------------------------------------------------*/ 22 | 23 | #ifndef DLDI_PATCHER_H 24 | #define DLDI_PATCHER_H 25 | 26 | #include 27 | 28 | typedef signed int addr_t; 29 | typedef unsigned char data_t; 30 | bool dldiPatchBinary (data_t *binData, u32 binSize); 31 | 32 | #endif // DLDI_PATCHER_H 33 | -------------------------------------------------------------------------------- /bootloader/source/fat.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------- 2 | fat.h 3 | 4 | NDS MP 5 | GBAMP NDS Firmware Hack Version 2.12 6 | An NDS aware firmware patch for the GBA Movie Player. 7 | By Michael Chisholm (Chishm) 8 | 9 | Filesystem code based on GBAMP_CF.c by Chishm (me). 10 | 11 | License: 12 | Copyright (C) 2005 Michael "Chishm" Chisholm 13 | 14 | This program is free software; you can redistribute it and/or 15 | modify it under the terms of the GNU General Public License 16 | as published by the Free Software Foundation; either version 2 17 | of the License, or (at your option) any later version. 18 | 19 | This program is distributed in the hope that it will be useful, 20 | but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | GNU General Public License for more details. 23 | 24 | You should have received a copy of the GNU General Public License 25 | along with this program; if not, write to the Free Software 26 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 27 | 28 | If you use this code, please give due credit and email me about your 29 | project at chishm@hotmail.com 30 | ------------------------------------------------------------------*/ 31 | 32 | #ifndef FAT_H 33 | #define FAT_H 34 | 35 | #include 36 | 37 | #define CLUSTER_FREE 0x00000000 38 | #define CLUSTER_EOF 0x0FFFFFFF 39 | #define CLUSTER_FIRST 0x00000002 40 | 41 | bool FAT_InitFiles (bool initCard); 42 | u32 getBootFileCluster (const char* bootName); 43 | u32 fileRead (char* buffer, u32 cluster, u32 startOffset, u32 length); 44 | u32 FAT_ClustToSect (u32 cluster); 45 | 46 | #endif // FAT_H 47 | -------------------------------------------------------------------------------- /bootloader/source/io_dldi.h: -------------------------------------------------------------------------------- 1 | /* 2 | io_dldi.h 3 | 4 | Reserved space for post-compilation adding of an extra driver 5 | 6 | Copyright (c) 2006 Michael "Chishm" Chisholm 7 | 8 | Redistribution and use in source and binary forms, with or without modification, 9 | are permitted provided that the following conditions are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright notice, 12 | this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the documentation and/or 15 | other materials provided with the distribution. 16 | 3. The name of the author may not be used to endorse or promote products derived 17 | from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 20 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 21 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | 2006-12-22 - Chishm 30 | * Original release 31 | */ 32 | 33 | #ifndef IO_DLDI_H 34 | #define IO_DLDI_H 35 | 36 | // 'DLDD' 37 | #define DEVICE_TYPE_DLDD 0x49444C44 38 | 39 | #include "disc_io.h" 40 | 41 | // export interface 42 | extern IO_INTERFACE _io_dldi ; 43 | 44 | #endif // define IO_DLDI_H 45 | -------------------------------------------------------------------------------- /bootloader/source/io_dldi.s: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------- 2 | 3 | Copyright (C) 2005 Michael "Chishm" Chisholm 4 | 5 | This program is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU General Public License 7 | as published by the Free Software Foundation; either version 2 8 | of the License, or (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | 19 | If you use this code, please give due credit and email me about your 20 | project at chishm@hotmail.com 21 | ------------------------------------------------------------------*/ 22 | 23 | @--------------------------------------------------------------------------------- 24 | .align 4 25 | .arm 26 | .global _dldi_start 27 | .global _io_dldi 28 | @--------------------------------------------------------------------------------- 29 | .equ FEATURE_MEDIUM_CANREAD, 0x00000001 30 | .equ FEATURE_MEDIUM_CANWRITE, 0x00000002 31 | .equ FEATURE_SLOT_GBA, 0x00000010 32 | .equ FEATURE_SLOT_NDS, 0x00000020 33 | 34 | 35 | _dldi_start: 36 | 37 | @--------------------------------------------------------------------------------- 38 | @ Driver patch file standard header -- 16 bytes 39 | .word 0xBF8DA5EE @ Magic number to identify this region, *different to normal DLDI* 40 | .asciz " Chishm" @ Identifying Magic string (8 bytes with null terminator) 41 | .byte 0x01 @ Version number 42 | .byte 0x0e @ 16KiB @ Log [base-2] of the size of this driver in bytes. 43 | .byte 0x00 @ Sections to fix 44 | .byte 0x0e @ 16KiB @ Log [base-2] of the allocated space in bytes. 45 | 46 | @--------------------------------------------------------------------------------- 47 | @ Text identifier - can be anything up to 47 chars + terminating null -- 16 bytes 48 | .align 4 49 | .asciz "Loader (No interface)" 50 | 51 | @--------------------------------------------------------------------------------- 52 | @ Offsets to important sections within the data -- 32 bytes 53 | .align 6 54 | .word _dldi_start @ data start 55 | .word _dldi_end @ data end 56 | .word 0x00000000 @ Interworking glue start -- Needs address fixing 57 | .word 0x00000000 @ Interworking glue end 58 | .word 0x00000000 @ GOT start -- Needs address fixing 59 | .word 0x00000000 @ GOT end 60 | .word 0x00000000 @ bss start -- Needs setting to zero 61 | .word 0x00000000 @ bss end 62 | 63 | @--------------------------------------------------------------------------------- 64 | @ IO_INTERFACE data -- 32 bytes 65 | _io_dldi: 66 | .ascii "DLDI" @ ioType 67 | .word 0x00000000 @ Features 68 | .word _DLDI_startup @ 69 | .word _DLDI_isInserted @ 70 | .word _DLDI_readSectors @ Function pointers to standard device driver functions 71 | .word _DLDI_writeSectors @ 72 | .word _DLDI_clearStatus @ 73 | .word _DLDI_shutdown @ 74 | 75 | @--------------------------------------------------------------------------------- 76 | 77 | _DLDI_startup: 78 | _DLDI_isInserted: 79 | _DLDI_readSectors: 80 | _DLDI_writeSectors: 81 | _DLDI_clearStatus: 82 | _DLDI_shutdown: 83 | mov r0, #0x00 @ Return false for every function 84 | bx lr 85 | 86 | 87 | 88 | @--------------------------------------------------------------------------------- 89 | .align 90 | .pool 91 | 92 | .space (_dldi_start + 16384) - . @ Fill to 16KiB 93 | 94 | _dldi_end: 95 | .end 96 | @--------------------------------------------------------------------------------- 97 | -------------------------------------------------------------------------------- /bootloader/source/load_crt0.s: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------- 2 | 3 | Copyright (C) 2005 Michael "Chishm" Chisholm 4 | 5 | This program is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU General Public License 7 | as published by the Free Software Foundation; either version 2 8 | of the License, or (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | 19 | If you use this code, please give due credit and email me about your 20 | project at chishm@hotmail.com 21 | ------------------------------------------------------------------*/ 22 | 23 | @--------------------------------------------------------------------------------- 24 | .section ".init" 25 | .global _start 26 | .global storedFileCluster 27 | .global initDisc 28 | .global wantToPatchDLDI 29 | .global argStart 30 | .global argSize 31 | .global dsiSD 32 | @--------------------------------------------------------------------------------- 33 | .align 4 34 | .arm 35 | @--------------------------------------------------------------------------------- 36 | _start: 37 | @--------------------------------------------------------------------------------- 38 | b startUp 39 | 40 | storedFileCluster: 41 | .word 0x0FFFFFFF @ default BOOT.NDS 42 | initDisc: 43 | .word 0x00000001 @ init the disc by default 44 | wantToPatchDLDI: 45 | .word 0x00000001 @ by default patch the DLDI section of the loaded NDS 46 | @ Used for passing arguments to the loaded app 47 | argStart: 48 | .word _end - _start 49 | argSize: 50 | .word 0x00000000 51 | dldiOffset: 52 | .word _dldi_start - _start 53 | dsiSD: 54 | .word 0 55 | 56 | startUp: 57 | mov r0, #0x04000000 58 | mov r1, #0 59 | str r1, [r0,#0x208] @ REG_IME 60 | str r1, [r0,#0x210] @ REG_IE 61 | str r1, [r0,#0x218] @ REG_AUXIE 62 | 63 | mov r0, #0x12 @ Switch to IRQ Mode 64 | msr cpsr, r0 65 | ldr sp, =__sp_irq @ Set IRQ stack 66 | 67 | mov r0, #0x13 @ Switch to SVC Mode 68 | msr cpsr, r0 69 | ldr sp, =__sp_svc @ Set SVC stack 70 | 71 | mov r0, #0x1F @ Switch to System Mode 72 | msr cpsr, r0 73 | ldr sp, =__sp_usr @ Set user stack 74 | 75 | ldr r0, =__bss_start @ Clear BSS section to 0x00 76 | ldr r1, =__bss_end 77 | sub r1, r1, r0 78 | bl ClearMem 79 | 80 | mov r0, #0 @ int argc 81 | mov r1, #0 @ char *argv[] 82 | ldr r3, =main 83 | bl _blx_r3_stub @ jump to user code 84 | 85 | @ If the user ever returns, restart 86 | b _start 87 | 88 | @--------------------------------------------------------------------------------- 89 | _blx_r3_stub: 90 | @--------------------------------------------------------------------------------- 91 | bx r3 92 | 93 | @--------------------------------------------------------------------------------- 94 | @ Clear memory to 0x00 if length != 0 95 | @ r0 = Start Address 96 | @ r1 = Length 97 | @--------------------------------------------------------------------------------- 98 | ClearMem: 99 | @--------------------------------------------------------------------------------- 100 | mov r2, #3 @ Round down to nearest word boundary 101 | add r1, r1, r2 @ Shouldnt be needed 102 | bics r1, r1, r2 @ Clear 2 LSB (and set Z) 103 | bxeq lr @ Quit if copy size is 0 104 | 105 | mov r2, #0 106 | ClrLoop: 107 | stmia r0!, {r2} 108 | subs r1, r1, #4 109 | bne ClrLoop 110 | bx lr 111 | 112 | @--------------------------------------------------------------------------------- 113 | @ Copy memory if length != 0 114 | @ r1 = Source Address 115 | @ r2 = Dest Address 116 | @ r4 = Dest Address + Length 117 | @--------------------------------------------------------------------------------- 118 | CopyMemCheck: 119 | @--------------------------------------------------------------------------------- 120 | sub r3, r4, r2 @ Is there any data to copy? 121 | @--------------------------------------------------------------------------------- 122 | @ Copy memory 123 | @ r1 = Source Address 124 | @ r2 = Dest Address 125 | @ r3 = Length 126 | @--------------------------------------------------------------------------------- 127 | CopyMem: 128 | @--------------------------------------------------------------------------------- 129 | mov r0, #3 @ These commands are used in cases where 130 | add r3, r3, r0 @ the length is not a multiple of 4, 131 | bics r3, r3, r0 @ even though it should be. 132 | bxeq lr @ Length is zero, so exit 133 | CIDLoop: 134 | ldmia r1!, {r0} 135 | stmia r2!, {r0} 136 | subs r3, r3, #4 137 | bne CIDLoop 138 | bx lr 139 | 140 | @--------------------------------------------------------------------------------- 141 | .align 142 | .pool 143 | .end 144 | @--------------------------------------------------------------------------------- 145 | -------------------------------------------------------------------------------- /bootloader/source/sdmmc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "sdmmc.h" 3 | 4 | 5 | static struct mmcdevice deviceSD; 6 | 7 | /*mmcdevice *getMMCDevice(int drive) { 8 | if(drive==0) return &deviceNAND; 9 | return &deviceSD; 10 | } 11 | */ 12 | //--------------------------------------------------------------------------------- 13 | int __attribute__((noinline)) geterror(struct mmcdevice *ctx) { 14 | //--------------------------------------------------------------------------------- 15 | //if(ctx->error == 0x4) return -1; 16 | //else return 0; 17 | return (ctx->error << 29) >> 31; 18 | } 19 | 20 | 21 | //--------------------------------------------------------------------------------- 22 | void __attribute__((noinline)) setTarget(struct mmcdevice *ctx) { 23 | //--------------------------------------------------------------------------------- 24 | sdmmc_mask16(REG_SDPORTSEL,0x3,(u16)ctx->devicenumber); 25 | setckl(ctx->clk); 26 | if (ctx->SDOPT == 0) { 27 | sdmmc_mask16(REG_SDOPT, 0, 0x8000); 28 | } else { 29 | sdmmc_mask16(REG_SDOPT, 0x8000, 0); 30 | } 31 | 32 | } 33 | 34 | 35 | //--------------------------------------------------------------------------------- 36 | void __attribute__((noinline)) sdmmc_send_command(struct mmcdevice *ctx, u32 cmd, u32 args) { 37 | //--------------------------------------------------------------------------------- 38 | int i; 39 | bool getSDRESP = (cmd << 15) >> 31; 40 | u16 flags = (cmd << 15) >> 31; 41 | const bool readdata = cmd & 0x20000; 42 | const bool writedata = cmd & 0x40000; 43 | 44 | if (readdata || writedata) 45 | flags |= TMIO_STAT0_DATAEND; 46 | 47 | ctx->error = 0; 48 | while (sdmmc_read16(REG_SDSTATUS1) & TMIO_STAT1_CMD_BUSY); //mmc working? 49 | sdmmc_write16(REG_SDIRMASK0,0); 50 | sdmmc_write16(REG_SDIRMASK1,0); 51 | sdmmc_write16(REG_SDSTATUS0,0); 52 | sdmmc_write16(REG_SDSTATUS1,0); 53 | 54 | #ifdef DATA32_SUPPORT 55 | if (readdata) 56 | sdmmc_mask16(REG_SDDATACTL32, 0x1000, 0x800); 57 | if (writedata) 58 | sdmmc_mask16(REG_SDDATACTL32, 0x800, 0x1000); 59 | #else 60 | sdmmc_mask16(REG_SDDATACTL32,0x1800,0); 61 | #endif 62 | 63 | sdmmc_write16(REG_SDCMDARG0,args &0xFFFF); 64 | sdmmc_write16(REG_SDCMDARG1,args >> 16); 65 | sdmmc_write16(REG_SDCMD,cmd &0xFFFF); 66 | 67 | u32 size = ctx->size; 68 | u16 *dataPtr = (u16*)ctx->data; 69 | #ifdef DATA32_SUPPORT 70 | u32 *dataPtr32 = (u32*)ctx->data; 71 | #endif 72 | 73 | bool useBuf = ( 0 != dataPtr ); 74 | #ifdef DATA32_SUPPORT 75 | bool useBuf32 = (useBuf && (0 == (3 & ((u32)dataPtr)))); 76 | #endif 77 | 78 | u16 status0 = 0; 79 | while(true) { 80 | u16 status1 = sdmmc_read16(REG_SDSTATUS1); 81 | if (status1 & TMIO_STAT1_RXRDY) { 82 | if (readdata && useBuf) { 83 | sdmmc_mask16(REG_SDSTATUS1, TMIO_STAT1_RXRDY, 0); 84 | //sdmmc_write16(REG_SDSTATUS1,~TMIO_STAT1_RXRDY); 85 | if (size > 0x1FF) { 86 | #ifdef DATA32_SUPPORT 87 | if (useBuf32) { 88 | for(i = 0; i<0x200; i+=4) 89 | *dataPtr32++ = sdmmc_read32(REG_SDFIFO32); 90 | } else { 91 | #endif 92 | for(i = 0; i<0x200; i+=2) 93 | *dataPtr++ = sdmmc_read16(REG_SDFIFO); 94 | #ifdef DATA32_SUPPORT 95 | } 96 | #endif 97 | size -= 0x200; 98 | } 99 | } 100 | } 101 | 102 | if (status1 & TMIO_STAT1_TXRQ) { 103 | if (writedata && useBuf) { 104 | sdmmc_mask16(REG_SDSTATUS1, TMIO_STAT1_TXRQ, 0); 105 | //sdmmc_write16(REG_SDSTATUS1,~TMIO_STAT1_TXRQ); 106 | if (size > 0x1FF) { 107 | #ifdef DATA32_SUPPORT 108 | for (i = 0; i<0x200; i+=4) 109 | sdmmc_write32(REG_SDFIFO32,*dataPtr32++); 110 | #else 111 | for (i = 0; i<0x200; i+=2) 112 | sdmmc_write16(REG_SDFIFO,*dataPtr++); 113 | #endif 114 | size -= 0x200; 115 | } 116 | } 117 | } 118 | if (status1 & TMIO_MASK_GW) { 119 | ctx->error |= 4; 120 | break; 121 | } 122 | 123 | if (!(status1 & TMIO_STAT1_CMD_BUSY)) { 124 | status0 = sdmmc_read16(REG_SDSTATUS0); 125 | if (sdmmc_read16(REG_SDSTATUS0) & TMIO_STAT0_CMDRESPEND) 126 | ctx->error |= 0x1; 127 | if (status0 & TMIO_STAT0_DATAEND) 128 | ctx->error |= 0x2; 129 | 130 | if ((status0 & flags) == flags) 131 | break; 132 | } 133 | } 134 | ctx->stat0 = sdmmc_read16(REG_SDSTATUS0); 135 | ctx->stat1 = sdmmc_read16(REG_SDSTATUS1); 136 | sdmmc_write16(REG_SDSTATUS0,0); 137 | sdmmc_write16(REG_SDSTATUS1,0); 138 | 139 | if (getSDRESP != 0) { 140 | ctx->ret[0] = sdmmc_read16(REG_SDRESP0) | (sdmmc_read16(REG_SDRESP1) << 16); 141 | ctx->ret[1] = sdmmc_read16(REG_SDRESP2) | (sdmmc_read16(REG_SDRESP3) << 16); 142 | ctx->ret[2] = sdmmc_read16(REG_SDRESP4) | (sdmmc_read16(REG_SDRESP5) << 16); 143 | ctx->ret[3] = sdmmc_read16(REG_SDRESP6) | (sdmmc_read16(REG_SDRESP7) << 16); 144 | } 145 | } 146 | 147 | 148 | //--------------------------------------------------------------------------------- 149 | int sdmmc_cardinserted() { 150 | //--------------------------------------------------------------------------------- 151 | return 1; //sdmmc_cardready; 152 | } 153 | 154 | //--------------------------------------------------------------------------------- 155 | void sdmmc_controller_init() { 156 | //--------------------------------------------------------------------------------- 157 | deviceSD.isSDHC = 0; 158 | deviceSD.SDOPT = 0; 159 | deviceSD.res = 0; 160 | deviceSD.initarg = 0; 161 | deviceSD.clk = 0x80; 162 | deviceSD.devicenumber = 0; 163 | 164 | *(vu16*)(SDMMC_BASE + REG_SDDATACTL32) &= 0xF7FFu; 165 | *(vu16*)(SDMMC_BASE + REG_SDDATACTL32) &= 0xEFFFu; 166 | *(vu16*)(SDMMC_BASE + REG_SDDATACTL32) |= 0x402u; 167 | 168 | *(vu16*)(SDMMC_BASE + REG_SDDATACTL) = (*(vu16*)(SDMMC_BASE + 0xd8) & 0xFFDD) | 2; 169 | 170 | #ifdef DATA32_SUPPORT 171 | *(vu16*)(SDMMC_BASE + REG_SDDATACTL32) &= 0xFFFFu; 172 | *(vu16*)(SDMMC_BASE + REG_SDDATACTL) &= 0xFFDFu; 173 | *(vu16*)(SDMMC_BASE + REG_SDBLKLEN32) = 512; 174 | #else 175 | *(vu16*)(SDMMC_BASE + REG_SDDATACTL32) &= 0xFFFDu; 176 | *(vu16*)(SDMMC_BASE + REG_SDDATACTL) &= 0xFFDDu; 177 | *(vu16*)(SDMMC_BASE + REG_SDBLKLEN32) = 0; 178 | #endif 179 | *(vu16*)(SDMMC_BASE + REG_SDBLKCOUNT32) = 1; //SDBLKCOUNT32 180 | *(vu16*)(SDMMC_BASE + REG_SDRESET) &= 0xFFFEu; //SDRESET 181 | *(vu16*)(SDMMC_BASE + REG_SDRESET) |= 1u; //SDRESET 182 | *(vu16*)(SDMMC_BASE + REG_SDIRMASK0) |= TMIO_MASK_ALL; 183 | *(vu16*)(SDMMC_BASE + REG_SDIRMASK1) |= TMIO_MASK_ALL>>16; 184 | *(vu16*)(SDMMC_BASE + 0x0fc) |= 0xDBu; //SDCTL_RESERVED7 185 | *(vu16*)(SDMMC_BASE + 0x0fe) |= 0xDBu; //SDCTL_RESERVED8 186 | *(vu16*)(SDMMC_BASE + REG_SDPORTSEL) &= 0xFFFCu; //SDPORTSEL 187 | #ifdef DATA32_SUPPORT 188 | *(vu16*)(SDMMC_BASE + REG_SDCLKCTL) = 0x20; 189 | *(vu16*)(SDMMC_BASE + REG_SDOPT) = 0x40EE; 190 | #else 191 | *(vu16*)(SDMMC_BASE + REG_SDCLKCTL) = 0x40; //Nintendo sets this to 0x20 192 | *(vu16*)(SDMMC_BASE + REG_SDOPT) = 0x40EB; //Nintendo sets this to 0x40EE 193 | #endif 194 | *(vu16*)(SDMMC_BASE + REG_SDPORTSEL) &= 0xFFFCu; ////SDPORTSEL 195 | *(vu16*)(SDMMC_BASE + REG_SDBLKLEN) = 512; //SDBLKLEN 196 | *(vu16*)(SDMMC_BASE + REG_SDSTOP) = 0; //SDSTOP 197 | 198 | setTarget(&deviceSD); 199 | } 200 | 201 | //--------------------------------------------------------------------------------- 202 | static u32 calcSDSize(u8* csd, int type) { 203 | //--------------------------------------------------------------------------------- 204 | u32 result = 0; 205 | if (type == -1) type = csd[14] >> 6; 206 | switch (type) { 207 | case 0: 208 | { 209 | u32 block_len = csd[9] & 0xf; 210 | block_len = 1 << block_len; 211 | u32 mult = (csd[4] >> 7) | ((csd[5] & 3) << 1); 212 | mult = 1 << (mult + 2); 213 | result = csd[8] & 3; 214 | result = (result << 8) | csd[7]; 215 | result = (result << 2) | (csd[6] >> 6); 216 | result = (result + 1) * mult * block_len / 512; 217 | } 218 | break; 219 | case 1: 220 | result = csd[7] & 0x3f; 221 | result = (result << 8) | csd[6]; 222 | result = (result << 8) | csd[5]; 223 | result = (result + 1) * 1024; 224 | break; 225 | } 226 | return result; 227 | } 228 | 229 | //--------------------------------------------------------------------------------- 230 | int sdmmc_sdcard_init() { 231 | //--------------------------------------------------------------------------------- 232 | setTarget(&deviceSD); 233 | swiDelay(0xF000); 234 | sdmmc_send_command(&deviceSD,0,0); 235 | sdmmc_send_command(&deviceSD,0x10408,0x1AA); 236 | //u32 temp = (deviceSD.ret[0] == 0x1AA) << 0x1E; 237 | u32 temp = (deviceSD.error & 0x1) << 0x1E; 238 | 239 | //int count = 0; 240 | u32 temp2 = 0; 241 | do { 242 | do { 243 | sdmmc_send_command(&deviceSD,0x10437,deviceSD.initarg << 0x10); 244 | sdmmc_send_command(&deviceSD,0x10769,0x00FF8000 | temp); 245 | temp2 = 1; 246 | } while ( !(deviceSD.error & 1) ); 247 | 248 | } while((deviceSD.ret[0] & 0x80000000) == 0); 249 | //do 250 | //{ 251 | // sdmmc_send_command(&deviceSD,0x10437,deviceSD.initarg << 0x10); 252 | // sdmmc_send_command(&deviceSD,0x10769,0x00FF8000 | temp); 253 | // 254 | //} 255 | //while(!(deviceSD.ret[0] & 0x80000000)); 256 | 257 | if(!((deviceSD.ret[0] >> 30) & 1) || !temp) 258 | temp2 = 0; 259 | 260 | deviceSD.isSDHC = temp2; 261 | //deviceSD.isSDHC = (deviceSD.ret[0] & 0x40000000); 262 | 263 | sdmmc_send_command(&deviceSD,0x10602,0); 264 | if (deviceSD.error & 0x4) return -1; 265 | 266 | sdmmc_send_command(&deviceSD,0x10403,0); 267 | if (deviceSD.error & 0x4) return -1; 268 | deviceSD.initarg = deviceSD.ret[0] >> 0x10; 269 | 270 | sdmmc_send_command(&deviceSD,0x10609,deviceSD.initarg << 0x10); 271 | if (deviceSD.error & 0x4) return -1; 272 | 273 | deviceSD.total_size = calcSDSize((u8*)&deviceSD.ret[0],-1); 274 | deviceSD.clk = 1; 275 | setckl(1); 276 | 277 | sdmmc_send_command(&deviceSD,0x10507,deviceSD.initarg << 0x10); 278 | if (deviceSD.error & 0x4) return -1; 279 | 280 | sdmmc_send_command(&deviceSD,0x10437,deviceSD.initarg << 0x10); 281 | if (deviceSD.error & 0x4) return -1; 282 | 283 | deviceSD.SDOPT = 1; 284 | sdmmc_send_command(&deviceSD,0x10446,0x2); 285 | if (deviceSD.error & 0x4) return -1; 286 | 287 | sdmmc_send_command(&deviceSD,0x1040D,deviceSD.initarg << 0x10); 288 | if (deviceSD.error & 0x4) return -1; 289 | 290 | sdmmc_send_command(&deviceSD,0x10410,0x200); 291 | if (deviceSD.error & 0x4) return -1; 292 | deviceSD.clk |= 0x200; 293 | 294 | return 0; 295 | 296 | } 297 | 298 | 299 | int __attribute__((noinline)) sdmmc_sdcard_readsectors(u32 sector_no, u32 numsectors, void *out) { 300 | if (deviceSD.isSDHC == 0) 301 | sector_no <<= 9; 302 | setTarget(&deviceSD); 303 | sdmmc_write16(REG_SDSTOP,0x100); 304 | 305 | #ifdef DATA32_SUPPORT 306 | sdmmc_write16(REG_SDBLKCOUNT32,numsectors); 307 | sdmmc_write16(REG_SDBLKLEN32,0x200); 308 | #endif 309 | 310 | sdmmc_write16(REG_SDBLKCOUNT,numsectors); 311 | deviceSD.data = out; 312 | deviceSD.size = numsectors << 9; 313 | sdmmc_send_command(&deviceSD,0x33C12,sector_no); 314 | return geterror(&deviceSD); 315 | } -------------------------------------------------------------------------------- /bootloader/source/sdmmc.h: -------------------------------------------------------------------------------- 1 | #ifndef __SDMMC_H__ 2 | #define __SDMMC_H__ 3 | 4 | #include 5 | 6 | #define SDMMC_BASE 0x04004800 7 | 8 | 9 | #define REG_SDCMD 0x00 10 | #define REG_SDPORTSEL 0x02 11 | #define REG_SDCMDARG 0x04 12 | #define REG_SDCMDARG0 0x04 13 | #define REG_SDCMDARG1 0x06 14 | #define REG_SDSTOP 0x08 15 | #define REG_SDRESP 0x0c 16 | #define REG_SDBLKCOUNT 0x0a 17 | 18 | #define REG_SDRESP0 0x0c 19 | #define REG_SDRESP1 0x0e 20 | #define REG_SDRESP2 0x10 21 | #define REG_SDRESP3 0x12 22 | #define REG_SDRESP4 0x14 23 | #define REG_SDRESP5 0x16 24 | #define REG_SDRESP6 0x18 25 | #define REG_SDRESP7 0x1a 26 | 27 | #define REG_SDSTATUS0 0x1c 28 | #define REG_SDSTATUS1 0x1e 29 | 30 | #define REG_SDIRMASK0 0x20 31 | #define REG_SDIRMASK1 0x22 32 | #define REG_SDCLKCTL 0x24 33 | 34 | #define REG_SDBLKLEN 0x26 35 | #define REG_SDOPT 0x28 36 | #define REG_SDFIFO 0x30 37 | 38 | #define REG_SDDATACTL 0xd8 39 | #define REG_SDRESET 0xe0 40 | #define REG_SDPROTECTED 0xf6 //bit 0 determines if sd is protected or not? 41 | 42 | #define REG_SDDATACTL32 0x100 43 | #define REG_SDBLKLEN32 0x104 44 | #define REG_SDBLKCOUNT32 0x108 45 | #define REG_SDFIFO32 0x10C 46 | 47 | #define REG_CLK_AND_WAIT_CTL 0x138 48 | #define REG_RESET_SDIO 0x1e0 49 | //The below defines are from linux kernel drivers/mmc tmio_mmc.h. 50 | /* Definitions for values the CTRL_STATUS register can take. */ 51 | #define TMIO_STAT0_CMDRESPEND 0x0001 52 | #define TMIO_STAT0_DATAEND 0x0004 53 | #define TMIO_STAT0_CARD_REMOVE 0x0008 54 | #define TMIO_STAT0_CARD_INSERT 0x0010 55 | #define TMIO_STAT0_SIGSTATE 0x0020 56 | #define TMIO_STAT0_WRPROTECT 0x0080 57 | #define TMIO_STAT0_CARD_REMOVE_A 0x0100 58 | #define TMIO_STAT0_CARD_INSERT_A 0x0200 59 | #define TMIO_STAT0_SIGSTATE_A 0x0400 60 | 61 | #define TMIO_STAT1_CMD_IDX_ERR 0x0001 62 | #define TMIO_STAT1_CRCFAIL 0x0002 63 | #define TMIO_STAT1_STOPBIT_ERR 0x0004 64 | #define TMIO_STAT1_DATATIMEOUT 0x0008 65 | #define TMIO_STAT1_RXOVERFLOW 0x0010 66 | #define TMIO_STAT1_TXUNDERRUN 0x0020 67 | #define TMIO_STAT1_CMDTIMEOUT 0x0040 68 | #define TMIO_STAT1_RXRDY 0x0100 69 | #define TMIO_STAT1_TXRQ 0x0200 70 | #define TMIO_STAT1_ILL_FUNC 0x2000 71 | #define TMIO_STAT1_CMD_BUSY 0x4000 72 | #define TMIO_STAT1_ILL_ACCESS 0x8000 73 | 74 | //Comes from TWLSDK mongoose.tef DWARF info 75 | #define SDMC_NORMAL 0x00000000 76 | #define SDMC_ERR_COMMAND 0x00000001 77 | #define SDMC_ERR_CRC 0x00000002 78 | #define SDMC_ERR_END 0x00000004 79 | #define SDMC_ERR_TIMEOUT 0x00000008 80 | #define SDMC_ERR_FIFO_OVF 0x00000010 81 | #define SDMC_ERR_FIFO_UDF 0x00000020 82 | #define SDMC_ERR_WP 0x00000040 83 | #define SDMC_ERR_ABORT 0x00000080 84 | #define SDMC_ERR_FPGA_TIMEOUT 0x00000100 85 | #define SDMC_ERR_PARAM 0x00000200 86 | #define SDMC_ERR_R1_STATUS 0x00000800 87 | #define SDMC_ERR_NUM_WR_SECTORS 0x00001000 88 | #define SDMC_ERR_RESET 0x00002000 89 | #define SDMC_ERR_ILA 0x00004000 90 | #define SDMC_ERR_INFO_DETECT 0x00008000 91 | 92 | #define SDMC_STAT_ERR_UNKNOWN 0x00080000 93 | #define SDMC_STAT_ERR_CC 0x00100000 94 | #define SDMC_STAT_ERR_ECC_FAILED 0x00200000 95 | #define SDMC_STAT_ERR_CRC 0x00800000 96 | #define SDMC_STAT_ERR_OTHER 0xf9c70008 97 | 98 | #define TMIO_MASK_ALL 0x837f031d 99 | 100 | #define TMIO_MASK_GW (TMIO_STAT1_ILL_ACCESS | TMIO_STAT1_CMDTIMEOUT | TMIO_STAT1_TXUNDERRUN | TMIO_STAT1_RXOVERFLOW | \ 101 | TMIO_STAT1_DATATIMEOUT | TMIO_STAT1_STOPBIT_ERR | TMIO_STAT1_CRCFAIL | TMIO_STAT1_CMD_IDX_ERR) 102 | 103 | #define TMIO_MASK_READOP (TMIO_STAT1_RXRDY | TMIO_STAT1_DATAEND) 104 | #define TMIO_MASK_WRITEOP (TMIO_STAT1_TXRQ | TMIO_STAT1_DATAEND) 105 | 106 | typedef struct mmcdevice { 107 | u8* data; 108 | u32 size; 109 | u32 error; 110 | u16 stat0; 111 | u16 stat1; 112 | u32 ret[4]; 113 | u32 initarg; 114 | u32 isSDHC; 115 | u32 clk; 116 | u32 SDOPT; 117 | u32 devicenumber; 118 | u32 total_size; //size in sectors of the device 119 | u32 res; 120 | } mmcdevice; 121 | 122 | void sdmmc_controller_init(); 123 | void sdmmc_initirq(); 124 | int sdmmc_cardinserted(); 125 | 126 | int sdmmc_sdcard_init(); 127 | int sdmmc_sdcard_readsectors(u32 sector_no, u32 numsectors, void *out); 128 | int sdmmc_sdcard_writesectors(u32 sector_no, u32 numsectors, void *in); 129 | 130 | extern u32 sdmmc_cid[]; 131 | extern int sdmmc_curdevice; 132 | 133 | //--------------------------------------------------------------------------------- 134 | static inline u16 sdmmc_read16(u16 reg) { 135 | //--------------------------------------------------------------------------------- 136 | return *(vu16*)(SDMMC_BASE + reg); 137 | } 138 | 139 | //--------------------------------------------------------------------------------- 140 | static inline void sdmmc_write16(u16 reg, u16 val) { 141 | //--------------------------------------------------------------------------------- 142 | *(vu16*)(SDMMC_BASE + reg) = val; 143 | } 144 | 145 | //--------------------------------------------------------------------------------- 146 | static inline u32 sdmmc_read32(u16 reg) { 147 | //--------------------------------------------------------------------------------- 148 | return *(vu32*)(SDMMC_BASE + reg); 149 | } 150 | 151 | //--------------------------------------------------------------------------------- 152 | static inline void sdmmc_write32(u16 reg, u32 val) { 153 | //--------------------------------------------------------------------------------- 154 | *(vu32*)(SDMMC_BASE + reg) = val; 155 | } 156 | 157 | //--------------------------------------------------------------------------------- 158 | static inline void sdmmc_mask16(u16 reg, u16 clear, u16 set) { 159 | //--------------------------------------------------------------------------------- 160 | u16 val = sdmmc_read16(reg); 161 | val &= ~clear; 162 | val |= set; 163 | sdmmc_write16(reg, val); 164 | } 165 | 166 | 167 | //--------------------------------------------------------------------------------- 168 | static inline void setckl(u32 data) { 169 | //--------------------------------------------------------------------------------- 170 | sdmmc_mask16(REG_SDCLKCTL, 0x100, 0); 171 | sdmmc_mask16(REG_SDCLKCTL, 0x2FF, data & 0x2FF); 172 | sdmmc_mask16(REG_SDCLKCTL, 0x0, 0x100); 173 | } 174 | 175 | #endif 176 | -------------------------------------------------------------------------------- /bootstub/Makefile: -------------------------------------------------------------------------------- 1 | include $(DEVKITARM)/base_tools 2 | 3 | TARGET := bootstub 4 | 5 | ../data/$(TARGET).bin: $(TARGET).elf 6 | $(OBJCOPY) -O binary $< $@ 7 | 8 | $(TARGET).elf: $(TARGET).s Makefile 9 | $(CC) -Wl,-Ttext=0 -x assembler-with-cpp -nostartfiles -nostdlib $(TARGET).s -o $@ 10 | 11 | 12 | clean: 13 | rm -f $(TARGET).elf $(TARGET).bin 14 | -------------------------------------------------------------------------------- /bootstub/bootstub.s: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------- 2 | 3 | Copyright (C) 2010 Dave "WinterMute" Murphy 4 | 5 | This program is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU General Public License 7 | as published by the Free Software Foundation; either version 2 8 | of the License, or (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | 19 | ------------------------------------------------------------------*/ 20 | .global _start 21 | 22 | //----------------------------------------------------------------- 23 | _start: 24 | //----------------------------------------------------------------- 25 | .ascii "bootstub" 26 | .word hook7from9 - _start 27 | .word hook9from7 - _start 28 | _loader_size: 29 | .word 0 30 | 31 | .arch armv4t 32 | .cpu arm7tdmi 33 | 34 | //----------------------------------------------------------------- 35 | hook9from7: 36 | //----------------------------------------------------------------- 37 | ldr r0, arm9bootaddr 38 | adr r1, hook7from9 39 | str r1, [r0] 40 | 41 | mov r3, #0x04000000 42 | ldr r0, resetcode 43 | str r0, [r3, #0x188] 44 | add r3, r3, #0x180 45 | 46 | adr r0, waitcode_start 47 | ldr r1, arm7base 48 | adr r2, waitcode_end 49 | 1: ldr r4, [r0],#4 50 | str r4, [r1],#4 51 | cmp r2, r0 52 | bne 1b 53 | 54 | ldr r1, arm7base 55 | bx r1 56 | 57 | //----------------------------------------------------------------- 58 | waitcode_start: 59 | //----------------------------------------------------------------- 60 | push {lr} 61 | mov r2, #1 62 | bl waitsync 63 | 64 | mov r0, #0x100 65 | strh r0, [r3] 66 | 67 | mov r2, #0 68 | bl waitsync 69 | 70 | mov r0, #0 71 | strh r0, [r3] 72 | pop {lr} 73 | 74 | bx lr 75 | 76 | waitsync: 77 | ldrh r0, [r3] 78 | and r0, r0, #0x000f 79 | cmp r0, r2 80 | bne waitsync 81 | bx lr 82 | waitcode_end: 83 | 84 | arm7base: 85 | .word 0x037f8000 86 | arm7bootaddr: 87 | .word 0x02FFFE34 88 | arm9bootaddr: 89 | .word 0x02FFFE24 90 | tcmpudisable: 91 | .word 0x2078 92 | 93 | resetcode: 94 | .word 0x0c04000c 95 | 96 | //----------------------------------------------------------------- 97 | hook7from9: 98 | //----------------------------------------------------------------- 99 | mov r12, #0x04000000 100 | strb r12, [r12,#0x208] 101 | 102 | .arch armv5te 103 | .cpu arm946e-s 104 | 105 | ldr r1, tcmpudisable @ disable TCM and protection unit 106 | mcr p15, 0, r1, c1, c0 107 | 108 | @ Disable cache 109 | mov r0, #0 110 | mcr p15, 0, r0, c7, c5, 0 @ Instruction cache 111 | mcr p15, 0, r0, c7, c6, 0 @ Data cache 112 | mcr p15, 0, r0, c3, c0, 0 @ write buffer 113 | 114 | @ Wait for write buffer to empty 115 | mcr p15, 0, r0, c7, c10, 4 116 | 117 | add r3, r12, #0x180 @ r3 = 4000180 118 | 119 | mov r0,#0x80 120 | strb r0,[r3,#0x242-0x180] 121 | 122 | adr r0, _loader 123 | ldr r2, _loader_size 124 | mov r1, #0x06800000 125 | add r1, r1, #0x40000 126 | add r2, r0, r2 127 | _copyloader: 128 | ldr r4, [r0], #4 129 | str r4, [r1], #4 130 | cmp r0, r2 131 | blt _copyloader 132 | 133 | mov r0,#0x82 134 | strb r0,[r3,#0x242-0x180] 135 | 136 | ldrh r0,[r3,#0x204-0x180] 137 | orr r0,r0,#(1<<11) | (1<<7) 138 | strh r0,[r3,#0x204-0x180] 139 | 140 | 141 | ldr r0, arm7bootaddr 142 | mov r1, #0x06000000 143 | str r1, [r0] 144 | 145 | ldr r0, resetcode 146 | str r0, [r12, #0x188] 147 | 148 | mov r2, #1 149 | bl waitsync 150 | 151 | mov r0, #0x100 152 | strh r0, [r3] 153 | 154 | mov r2, #0 155 | bl waitsync 156 | 157 | mov r0, #0 158 | strh r0, [r3] 159 | 160 | // set up and enter passme loop 161 | 162 | ldr r0,arm9branchaddr 163 | ldr r1,branchinst 164 | str r1,[r0] 165 | str r0,[r0,#0x20] 166 | 167 | bx r0 168 | 169 | branchinst: 170 | .word 0xE59FF018 171 | 172 | arm9branchaddr: 173 | .word 0x02fffe04 174 | 175 | 176 | _loader: 177 | -------------------------------------------------------------------------------- /build_cia.bat: -------------------------------------------------------------------------------- 1 | bash build_cia.sh -------------------------------------------------------------------------------- /build_cia.sh: -------------------------------------------------------------------------------- 1 | GAME_TITLE="NDS HB MENU" 2 | GAME_SUBTITLE1="Start in DSI then switch to DS mode" 3 | GAME_SUBTITLE2="made by devkitpro" 4 | GAME_INFO="KHNE 01 NTRHOMEBREW" 5 | 6 | cp bootstrap/bootstrap.*.elf . 7 | $DEVKITARM/bin/ndstool -c bootstrap.nds -7 bootstrap.arm7.elf -9 bootstrap.arm9.elf -g $GAME_INFO -b icon.bmp "$GAME_TITLE;$GAME_SUBTITLE1;$GAME_SUBTITLE2" -r9 0x2000000 -r7 0x2380000 -e9 0x2000000 -e7 0x2380000 8 | python patch_ndsheader_dsiware.py --read bootstrap.nds > bootstrap.nds_before_patch_header.txt 9 | python patch_ndsheader_dsiware.py --mode dsi bootstrap.nds 10 | python patch_ndsheader_dsiware.py --read bootstrap.nds > bootstrap.nds_after_patch_header.txt 11 | 12 | $DEVKITARM/bin/ndstool -c nds-hb-menu.nds -7 hbmenu.arm7.elf -9 hbmenu.arm9.elf -g $GAME_INFO -b icon.bmp "$GAME_TITLE;$GAME_SUBTITLE1;$GAME_SUBTITLE2" 13 | cp nds-hb-menu.nds hbmenu_ntr.nds 14 | cp nds-hb-menu.nds hbmenu_ntr_r4.nds 15 | cp nds-hb-menu.nds hbmenu_ntr_nogba.nds 16 | 17 | ./dlditool.exe BootStrap/r4tfv2.dldi nds-hb-menu-dsi-r4.nds 18 | 19 | python patch_ndsheader_dsiware.py --mode dsi hbmenu_ntr.nds 20 | python patch_ndsheader_dsiware.py --mode dsi hbmenu_ntr_r4.nds 21 | python patch_ndsheader_dsiware.py --mode dsinogba hbmenu_ntr_nogba.nds 22 | 23 | ./make_cia.exe --srl=hbmenu_ntr.nds 24 | ./make_cia.exe --srl=hbmenu_ntr_r4.nds 25 | ./make_cia.exe --srl=bootstrap.nds -------------------------------------------------------------------------------- /conf/hbmenu.ini: -------------------------------------------------------------------------------- 1 | [TWL-HOMEBREWMENU] 2 | NTR_CLOCK = 0 3 | DISABLE_ANIMATION = 1 4 | RESET_SLOT1 = 0 5 | LOCK_ARM7_SCFG_EXT = 0 6 | ENABLE_ALL_TWLSCFG = 0 7 | BOOTSTRAP_INI = sd:/_nds/nds-bootstrap.ini 8 | -------------------------------------------------------------------------------- /dlditool.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/dlditool.exe -------------------------------------------------------------------------------- /exclude.lst: -------------------------------------------------------------------------------- 1 | *.svn* 2 | *.DS_Store* 3 | *.bz2 4 | exclude.lst 5 | -------------------------------------------------------------------------------- /gfx/font6x8.grit: -------------------------------------------------------------------------------- 1 | -gB8 2 | -gTFFFFFF 3 | # use lz77 compression 4 | -gzl 5 | -------------------------------------------------------------------------------- /gfx/font6x8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/gfx/font6x8.png -------------------------------------------------------------------------------- /gfx/hbmenu_banner.grit: -------------------------------------------------------------------------------- 1 | -W3 2 | # disable alpha and set opaque bit for all pixels 3 | -gT! 4 | 5 | # use lz77 compression 6 | -gzl 7 | 8 | # 16 bit bitmap 9 | -gB16 10 | -------------------------------------------------------------------------------- /gfx/hbmenu_banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/gfx/hbmenu_banner.png -------------------------------------------------------------------------------- /icon.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/icon.bmp -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | Copyright (C) 2005 - 2013 2 | Michael "Chishm" Chisholm 3 | Dave "WinterMute" Murphy 4 | Claudio "sverx" 5 | 6 | This program is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU General Public License 8 | as published by the Free Software Foundation; either version 2 9 | of the License, or (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US 19 | -------------------------------------------------------------------------------- /make_cia.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/make_cia.exe -------------------------------------------------------------------------------- /music/dsboot.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/music/dsboot.wav -------------------------------------------------------------------------------- /music/dsiboot.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/music/dsiboot.wav -------------------------------------------------------------------------------- /resources/hbmenu_banner.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/resources/hbmenu_banner.xcf -------------------------------------------------------------------------------- /testfiles/argvTest.nds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahezard/nds-hb-menu/75e6404af2d4b9d9d46398cdb339a8512cc43bee/testfiles/argvTest.nds -------------------------------------------------------------------------------- /testfiles/test1.argv: -------------------------------------------------------------------------------- 1 | # This is a comment 2 | # This is a straightforward command line, name of nds file followed by parameters 3 | # this can include a path relative to the .argv file 4 | # absolute paths are not currently supported 5 | 6 | argvTest.nds bunch of parameters go here -------------------------------------------------------------------------------- /testfiles/test2.argv: -------------------------------------------------------------------------------- 1 | # This is a comment 2 | # lines consisting only of whitespace will also be ignored 3 | # commands can be placed on multiple lines 4 | # first the name of the nds file to run 5 | # this can include a path relative to the .argv file 6 | # absolute paths are not currently supported 7 | 8 | argvTest.nds 9 | 10 | # a single argument 11 | argument1 12 | 13 | # multiple arguments separated by spaces 14 | argument2 argument3 15 | 16 | # multiple arguments separated by tabs 17 | argument4 argument5 18 | 19 | # or even separated by both tabs and spaces 20 | argument6 argument7 argument8 21 | 22 | 23 | --------------------------------------------------------------------------------