Commit 71cb3d6c authored by PoroCYon's avatar PoroCYon
Browse files

add stuff

parent 59c82632
*.rom
*.elf
*.nds
build/
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif
export TARGET := $(shell basename $(CURDIR))
export TOPDIR := $(CURDIR)
# specify a directory which contains the nitro filesystem
# this is relative to the Makefile
NITRO_FILES :=
# These set the information text in the nds file
GAME_TITLE := HGSS IR tests
GAME_SUBTITLE1 := TiTAN
GAME_SUBTITLE2 := Internal use only!
include $(DEVKITARM)/ds_rules
.PHONY: checkarm7 checkarm9 clean
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
all: checkarm7 checkarm9 $(TARGET).nds
#---------------------------------------------------------------------------------
checkarm7:
$(MAKE) -C arm7
#---------------------------------------------------------------------------------
checkarm9:
$(MAKE) -C arm9
#---------------------------------------------------------------------------------
$(TARGET).nds : $(NITRO_FILES) arm7/$(TARGET).elf arm9/$(TARGET).elf
ndstool -c $(TARGET).nds -7 arm7/$(TARGET).elf -9 arm9/$(TARGET).elf \
-b $(GAME_ICON) "$(GAME_TITLE);$(GAME_SUBTITLE1);$(GAME_SUBTITLE2)" \
$(_ADDFILES)
#---------------------------------------------------------------------------------
arm7/$(TARGET).elf:
$(MAKE) -C arm7
#---------------------------------------------------------------------------------
arm9/$(TARGET).elf:
$(MAKE) -C arm9
#---------------------------------------------------------------------------------
clean:
$(MAKE) -C arm9 clean
$(MAKE) -C arm7 clean
rm -f $(TARGET).nds $(TARGET).arm7 $(TARGET).arm9
# Pokéwalker ROM dumper
Allows one to dump both Pokéwalker ROMs using a HGSS/BW/B2W2 cartridge and a DS running homebrew
\ No newline at end of file
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif
include $(DEVKITARM)/ds_rules
#---------------------------------------------------------------------------------
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# INCLUDES is a list of directories containing extra header files
# DATA is a list of directories containing binary files
# all directories are relative to this makefile
#---------------------------------------------------------------------------------
BUILD := build
SOURCES := source
INCLUDES := include build ../../libdsi/include
DATA :=
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -mthumb-interwork
CFLAGS := -g -Wall -O2\
-mcpu=arm7tdmi -mtune=arm7tdmi -fomit-frame-pointer\
-ffast-math \
$(ARCH)
CFLAGS += $(INCLUDE) -DARM7
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -fno-rtti
ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=ds_arm7.specs -g $(ARCH) -Wl,--nmagic -Wl,-Map,$(notdir $*).map
LIBS := -lfat -lnds7
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(LIBNDS)
#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------
export ARM7ELF := $(CURDIR)/$(TARGET).elf
export DEPSDIR := $(CURDIR)/$(BUILD)
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir))
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
export OFILES := $(addsuffix .o,$(BINFILES)) \
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I$(CURDIR)/$(BUILD)
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
export LD := $(CC)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
export LD := $(CXX)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------
.PHONY: $(BUILD) clean
#---------------------------------------------------------------------------------
$(BUILD):
@[ -d $@ ] || mkdir -p $@
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr $(BUILD) *.elf
#---------------------------------------------------------------------------------
else
DEPENDS := $(OFILES:.o=.d)
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(ARM7ELF) : $(OFILES)
@echo linking $(notdir $@)
@$(LD) $(LDFLAGS) $(OFILES) $(LIBPATHS) $(LIBS) -o $@
#---------------------------------------------------------------------------------
# you need a rule like this for each extension you use as binary data
#---------------------------------------------------------------------------------
%.bin.o : %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)
-include $(DEPENDS)
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------
default ARM7 core
Copyright (C) 2005 - 2010
Michael Noland (joat)
Jason Rogers (dovoto)
Dave Murphy (WinterMute)
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you
must not claim that you wrote the original software. If you use
this software in a product, an acknowledgment in the product
documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
---------------------------------------------------------------------------------*/
#include <nds.h>
#include "nwram.h"
volatile static bool exitflag = false;
static void VblankHandler(void) {
}
static void VcountHandler() {
inputGetAndSend();
}
static void powerButtonCB() {
exitflag = true;
}
int main() {
REG_MBK_PROT=0;//allow ARM9 rw
// clear sound registers
dmaFillWords(0, (void*)0x04000400, 0x100);
REG_SOUNDCNT |= SOUND_ENABLE;
writePowerManagement(PM_CONTROL_REG, (readPowerManagement(PM_CONTROL_REG) & ~PM_SOUND_MUTE) | PM_SOUND_AMP);
powerOn(POWER_SOUND);
readUserSettings();
ledBlink(0);
irqInit();
// Start the RTC tracking IRQ
initClockIRQ();
fifoInit();
//touchInit();
//mmInstall(FIFO_MAXMOD);
SetYtrigger(80);
//installWifiFIFO();
installSoundFIFO();
installSystemFIFO();
irqSet(IRQ_VCOUNT, VcountHandler);
irqSet(IRQ_VBLANK, VblankHandler);
irqEnable( IRQ_VBLANK | IRQ_VCOUNT /*| IRQ_NETWORK*/);
if (isDSiMode()) {
irqEnableAUX(IRQ_I2C);
setPowerButtonCB(powerButtonCB);
}
ledBlink(0);
// Keep the ARM7 mostly idle
while (!exitflag) {
if (!(REG_KEYINPUT & (KEY_SELECT | KEY_START | KEY_L | KEY_R))) {
exitflag = true;
}
swiWaitForVBlank();
}
return 0;
}
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif
include $(DEVKITARM)/ds_rules
#---------------------------------------------------------------------------------
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# INCLUDES is a list of directories containing extra header files
# DATA is a list of directories containing binary files
# all directories are relative to this makefile
#---------------------------------------------------------------------------------
BUILD := build
SOURCES := source
INCLUDES := include ../../libdsi/include
DATA :=
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -mthumb -mthumb-interwork
CFLAGS := -g -Wall -O2\
-march=armv5te -mtune=arm946e-s -fomit-frame-pointer\
-ffast-math \
$(ARCH)
CFLAGS += $(INCLUDE) -DARM9
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
ASFLAGS := -g $(ARCH) -march=armv5te -mtune=arm946e-s
LDFLAGS = -specs=dsi_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project
#---------------------------------------------------------------------------------
LIBS := -lfilesystem -lfat -lnds9
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(LIBNDS)
#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------
export ARM9ELF := $(CURDIR)/$(TARGET).elf
export DEPSDIR := $(CURDIR)/$(BUILD)
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
export LD := $(CC)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
export LD := $(CXX)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------
export OFILES := $(addsuffix .o,$(BINFILES)) \
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I$(CURDIR)/$(BUILD)
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
.PHONY: $(BUILD) clean
#---------------------------------------------------------------------------------
$(BUILD):
@[ -d $@ ] || mkdir -p $@
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr $(BUILD) *.elf *.nds* *.bin
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(ARM9ELF) : $(OFILES)
@echo linking $(notdir $@)
@$(LD) $(LDFLAGS) $(OFILES) $(LIBPATHS) $(LIBS) -o $@
#---------------------------------------------------------------------------------
# you need a rule like this for each extension you use as binary data
#---------------------------------------------------------------------------------
%.bin.o : %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)
-include $(DEPSDIR)/*.d
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------
/*
* savegame_manager: a tool to backup and restore savegames from Nintendo
* DS cartridges. Nintendo DS and all derivative names are trademarks
* by Nintendo. EZFlash 3-in-1 is a trademark by EZFlash.
*
* auxspi.h: Header for auxspi.cpp
*
* Copyright (C) Pokedoc (2010)
*/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
This is a thin reimplementation of the AUXSPI protocol at low levels.
It is used to implement various experimental procedures to test accessing the HG/SS save chip. */
#ifndef SPI_BUS_H
#define SPI_BUS_H
#include <stdint.h>
#include <stdbool.h>
// This is a handy typedef for nonstandard SPI buses, i.e. games with some
// extra hardware on the cartridge. The following values mean:
// AUXSPI_DEFAULT: A regular game with no exotic hardware.
// AUXSPI_INFRARED: A game with an infrared transceiver.
// Games known to use this hardware:
// - Personal Trainer: Walking (aka Laufrhytmus DS, Walk With Me, ...)
// - Pokemon HeartGold/SoulSilver/Black/White
// AUXSPI_BBDX: A game with what seems to be an extra protection against reading
// out the chip. Exclusively found on Band Brothers DX.
// AUXSPI_BLUETOOTH: A game with a Bluetooth transceiver. The only game using this
// hardware is Pokemon Typing DS.
//
// NOTE: This library does *not* support BBDX (I do have the game, but did not find the
// time to reverse engineer this; besides, a separate homebrew for this game already exists),
// and also *not* BLUETOOTH (the game is Japan-only, and I am from Europe. Plus I can't
// read Japanese. And it is unlikely that this game will ever make it here.)
//
enum auxspi_extra {
AUXSPI_DEFAULT,
AUXSPI_INFRARED,
AUXSPI_BBDX,
AUXSPI_BLUETOOTH,
AUXSPI_FLASH_CARD = 999
};
// These functions reimplement relevant parts of "card.cpp", in a way that is easier to modify.
uint8_t auxspi_save_type(enum auxspi_extra extra);
uint32_t auxspi_save_size(enum auxspi_extra extra);
uint8_t auxspi_save_size_log_2(enum auxspi_extra extra);
uint32_t auxspi_save_jedec_id(enum auxspi_extra extra);
uint8_t auxspi_save_status_register(enum auxspi_extra extra);
void auxspi_read_data (uint32_t addr, void* buf, uint32_t size,
uint8_t type, enum auxspi_extra extra);
void auxspi_write_data(uint32_t addr, const void* buf, uint32_t size,
uint8_t type, enum auxspi_extra extra);
// These functions are used to identify exotic hardware.
enum auxspi_extra auxspi_has_extra(void);
void auxspi_disable_extra(enum auxspi_extra extra);
void auxspi_disable_infrared(void);
#endif
#ifndef IR_H_
#define IR_H_
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include "auxspi.h"
bool auxspi_init_ir(bool wait_on_empty_slot, enum auxspi_extra* extra, uint8_t* savetype);
uint8_t auxspi_xfer_ir/*_base*/(uint8_t val, bool hold/*, bool reinit*/);
/*#define auxspi_xfer(val, hold, ...) auxspi_xfer_base(val, hold, (0, ##__VA_ARGS__))*/
enum ir_cmdtype {
ir_cmd_beacon = 0xfc,
ir_cmd_syn = 0xfa
};
enum ir_extra {
ir_extra_mosi = 0x01,
ir_extra_miso = 0x02,
ir_extra_addrhi = 0x80
};
size_t ir_cmd1(uint8_t* rxbuf /* either at least size 256, or NULL! */);
void ir_cmd2(size_t size, const uint8_t* txbuf);
uint8_t ir_cmd8(void);
inline static uint16_t ir_stat(void) {
uint8_t lo = ir_cmd8(),
hi = ir_cmd8();
return lo | ((uint16_t)hi << 8);
}
void ir_init(void);
#define IR_XOR_KEY 0xaa
uint16_t ir_calc_crc(uint8_t type, uint8_t extra, uint32_t sessid,
const uint8_t* payload, size_t payload_len);
void ir_send_syn(uint32_t sessid_gm);
bool ir_recv_ack(uint32_t* sessid_pw);
#endif
#ifndef PW_H_
#define PW_H_
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#define PW_XOR_KEY 0xaa
#define PW_XOR_KEY16 0xaaaa
#define PW_XOR_KEY32 0xaaaaaaaa
enum pw_cmdtype {
pw_cmd_beacon = 0xfc,
pw_cmd_syn = 0xfa,
pw_cmd_ack = 0xf8,
pw_cmd_rst = 0xf4,
pw_cmd_ping = 0x24,
pw_cmd_pong = 0x26,
pw_sploit_cmd_dump_res = 0x3c,
pw_cmd_kill = 0x56,
pw_cmd_close = 0x66,
pw_cmd_cloack = 0x68,
pw_cmd_geninf_req = 0x20,
pw_cmd_geninf_res = 0x22,
pw_cmd_memwrite_req = 0x06,
pw_cmd_memwrite_res = 0x06,
pw_cmd_eepread_req = 0x0c,
pw_cmd_eepread_res = 0x0e
};
enum pw_extra {
pw_extra_g2w = 0x01,
pw_extra_w2g = 0x02,
pw_extra_addrhi = 0x80
};
bool pw_scan(void);
uint16_t pw_calc_crc(uint8_t type, uint8_t extra, uint32_t sessid,
const uint8_t* payload, size_t payload_len);
void pw_send_syn(uint32_t sessid_gm); // fa
bool pw_recv_ack(uint32_t* sessid_pw); // f8
void pw_conn_rst(uint32_t sessid); // 0xf4
typedef void (*pw_wait_f)(size_t i);
extern size_t pw_poll_tries;
extern pw_wait_f pw_poll_wait;
void pw_poll_wait_default(size_t i);
bool pw_do_synack(uint32_t* sessid_glob);
bool pw_pingpong(uint32_t sessid); // 0x24/0x26
void pw_conn_kill(uint32_t sessid); // 0x56
bool pw_conn_end (uint32_t sessid); // 0x66/0x68
// cmd 0x20/0x22
__attribute__((__packed__)) struct pw_geninfo { // aka "IDENTITY DATA"
uint32_t _unk0[2];
uint16_t _unka[2];
uint16_t trainer_tid;
uint16_t trainer_sid;
uint8_t uuid[0x28];
uint8_t event_bitfields[0x10];
uint16_t trainer_name[8];
uint8_t _unk1[3];
uint8_t flags;
uint8_t proto_ver_maj;
uint8_t _unk2;
uint8_t proto_ver_min;
uint8_t _unk3;
uint32_t last_sync_time;
uint32_t step_count;
};
bool pw_get_geninfo(uint32_t sessid, struct pw_geninfo* geninf);
bool pw_write_mem(uint32_t sessid, uint16_t addr, size_t size, const uint8_t* data); // 0x06
bool pw_read_eeprom(uint32_t sessid, uint16_t addr, size_t size, uint8_t* dest);
// NOTE: does ASCII only!
char pw_charconv_w2a(uint16_t wch);
uint16_t pw_charconv_a2w(char a);