about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorFIX94 <fix94.1@gmail.com>2016-04-08 00:19:16 +0200
committerFIX94 <fix94.1@gmail.com>2016-04-08 00:19:16 +0200
commitdb276d8e521ae6b8ea9fb40c33d6961d713f31b7 (patch)
tree464ed30d0f26d20f48cad7b6efef2dd13b060ee8
parent9d737f20c4566fdabac90549f6e9e476a3bb0d4f (diff)
downloadgen3uploader-db276d8e521ae6b8ea9fb40c33d6961d713f31b7.tar.gz
gen3uploader-db276d8e521ae6b8ea9fb40c33d6961d713f31b7.tar.bz2
gen3uploader-db276d8e521ae6b8ea9fb40c33d6961d713f31b7.zip
first commit, enjoy
-rw-r--r--Makefile131
-rw-r--r--Makefile.gc131
-rw-r--r--Makefile.wii131
-rw-r--r--README.md6
-rw-r--r--build.bat10
-rw-r--r--gba/Makefile168
-rw-r--r--gba/source/main.c94
-rw-r--r--source/main.c400
8 files changed, 1070 insertions, 1 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f7dcdae --- /dev/null +++ b/Makefile
@@ -0,0 +1,131 @@
1#---------------------------------------------------------------------------------
2# Clear the implicit built in rules
3#---------------------------------------------------------------------------------
4.SUFFIXES:
5#---------------------------------------------------------------------------------
6ifeq ($(strip $(DEVKITPPC)),)
7$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>devkitPPC")
8endif
9
10include $(DEVKITPPC)/wii_rules
11
12#---------------------------------------------------------------------------------
13# TARGET is the name of the output
14# BUILD is the directory where object files & intermediate files will be placed
15# SOURCES is a list of directories containing source code
16# INCLUDES is a list of directories containing extra header files
17#---------------------------------------------------------------------------------
18TARGET := boot
19BUILD := build
20SOURCES := source
21DATA := data
22INCLUDES := source
23
24#---------------------------------------------------------------------------------
25# options for code generation
26#---------------------------------------------------------------------------------
27
28CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE)
29CXXFLAGS = $(CFLAGS)
30
31LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map
32
33#---------------------------------------------------------------------------------
34# any extra libraries we wish to link with the project
35#---------------------------------------------------------------------------------
36LIBS := -lfat -logc
37
38
39#---------------------------------------------------------------------------------
40# list of directories containing libraries, this must be the top level containing
41# include and lib
42#---------------------------------------------------------------------------------
43LIBDIRS := $(DEVKITPPC)/lib $(CURDIR)
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#---------------------------------------------------------------------------------
49ifneq ($(BUILD),$(notdir $(CURDIR)))
50#---------------------------------------------------------------------------------
51
52export OUTPUT := $(CURDIR)/$(TARGET)
53
54export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
55 $(foreach dir,$(DATA),$(CURDIR)/$(dir))
56
57export DEPSDIR := $(CURDIR)/$(BUILD)
58
59#---------------------------------------------------------------------------------
60# automatically build a list of object files for our project
61#---------------------------------------------------------------------------------
62CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
63CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
64sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
65SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S)))
66BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
67
68#---------------------------------------------------------------------------------
69# use CXX for linking C++ projects, CC for standard C
70#---------------------------------------------------------------------------------
71ifeq ($(strip $(CPPFILES)),)
72 export LD := $(CC)
73else
74 export LD := $(CXX)
75endif
76
77export OFILES := $(addsuffix .o,$(BINFILES)) \
78 $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \
79 $(sFILES:.s=.o) $(SFILES:.S=.o)
80
81#---------------------------------------------------------------------------------
82# build a list of include paths
83#---------------------------------------------------------------------------------
84export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
85 $(foreach dir,$(LIBDIRS),-I$(dir)/include) \
86 -I$(CURDIR)/$(BUILD) \
87 -I$(LIBOGC_INC)
88
89#---------------------------------------------------------------------------------
90# build a list of library paths
91#---------------------------------------------------------------------------------
92export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \
93 -L$(LIBOGC_LIB)
94
95export OUTPUT := $(CURDIR)/$(TARGET)
96.PHONY: $(BUILD) clean
97
98#---------------------------------------------------------------------------------
99$(BUILD):
100 @[ -d $@ ] || mkdir -p $@
101 @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
102
103#---------------------------------------------------------------------------------
104clean:
105 @echo clean ...
106 @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol $(CURDIR)/data/gba_mb.gba
107
108#---------------------------------------------------------------------------------
109else
110
111DEPENDS := $(OFILES:.o=.d)
112
113#---------------------------------------------------------------------------------
114# main targets
115#---------------------------------------------------------------------------------
116$(OUTPUT).dol: $(OUTPUT).elf
117$(OUTPUT).elf: $(OFILES)
118
119#---------------------------------------------------------------------------------
120# This rule links in binary data with the .jpg extension
121#---------------------------------------------------------------------------------
122%.gba.o : %.gba
123#---------------------------------------------------------------------------------
124 @echo $(notdir $<)
125 $(bin2o)
126
127-include $(DEPENDS)
128
129#---------------------------------------------------------------------------------
130endif
131#---------------------------------------------------------------------------------
diff --git a/Makefile.gc b/Makefile.gc new file mode 100644 index 0000000..82e10f1 --- /dev/null +++ b/Makefile.gc
@@ -0,0 +1,131 @@
1#---------------------------------------------------------------------------------
2# Clear the implicit built in rules
3#---------------------------------------------------------------------------------
4.SUFFIXES:
5#---------------------------------------------------------------------------------
6ifeq ($(strip $(DEVKITPPC)),)
7$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>devkitPPC")
8endif
9
10include $(DEVKITPPC)/gamecube_rules
11
12#---------------------------------------------------------------------------------
13# TARGET is the name of the output
14# BUILD is the directory where object files & intermediate files will be placed
15# SOURCES is a list of directories containing source code
16# INCLUDES is a list of directories containing extra header files
17#---------------------------------------------------------------------------------
18TARGET := linkcabledump_gc
19BUILD := build
20SOURCES := source
21DATA := data
22INCLUDES := source
23
24#---------------------------------------------------------------------------------
25# options for code generation
26#---------------------------------------------------------------------------------
27
28CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE)
29CXXFLAGS = $(CFLAGS)
30
31LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map
32
33#---------------------------------------------------------------------------------
34# any extra libraries we wish to link with the project
35#---------------------------------------------------------------------------------
36LIBS := -lfat -logc
37
38
39#---------------------------------------------------------------------------------
40# list of directories containing libraries, this must be the top level containing
41# include and lib
42#---------------------------------------------------------------------------------
43LIBDIRS := $(DEVKITPPC)/lib $(CURDIR)
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#---------------------------------------------------------------------------------
49ifneq ($(BUILD),$(notdir $(CURDIR)))
50#---------------------------------------------------------------------------------
51
52export OUTPUT := $(CURDIR)/$(TARGET)
53
54export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
55 $(foreach dir,$(DATA),$(CURDIR)/$(dir))
56
57export DEPSDIR := $(CURDIR)/$(BUILD)
58
59#---------------------------------------------------------------------------------
60# automatically build a list of object files for our project
61#---------------------------------------------------------------------------------
62CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
63CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
64sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
65SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S)))
66BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
67
68#---------------------------------------------------------------------------------
69# use CXX for linking C++ projects, CC for standard C
70#---------------------------------------------------------------------------------
71ifeq ($(strip $(CPPFILES)),)
72 export LD := $(CC)
73else
74 export LD := $(CXX)
75endif
76
77export OFILES := $(addsuffix .o,$(BINFILES)) \
78 $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \
79 $(sFILES:.s=.o) $(SFILES:.S=.o)
80
81#---------------------------------------------------------------------------------
82# build a list of include paths
83#---------------------------------------------------------------------------------
84export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
85 $(foreach dir,$(LIBDIRS),-I$(dir)/include) \
86 -I$(CURDIR)/$(BUILD) \
87 -I$(LIBOGC_INC)
88
89#---------------------------------------------------------------------------------
90# build a list of library paths
91#---------------------------------------------------------------------------------
92export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \
93 -L$(LIBOGC_LIB)
94
95export OUTPUT := $(CURDIR)/$(TARGET)
96.PHONY: $(BUILD) clean
97
98#---------------------------------------------------------------------------------
99$(BUILD):
100 @[ -d $@ ] || mkdir -p $@
101 @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile.gc
102
103#---------------------------------------------------------------------------------
104clean:
105 @echo clean ...
106 @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol
107
108#---------------------------------------------------------------------------------
109else
110
111DEPENDS := $(OFILES:.o=.d)
112
113#---------------------------------------------------------------------------------
114# main targets
115#---------------------------------------------------------------------------------
116$(OUTPUT).dol: $(OUTPUT).elf
117$(OUTPUT).elf: $(OFILES)
118
119#---------------------------------------------------------------------------------
120# This rule links in binary data with the .jpg extension
121#---------------------------------------------------------------------------------
122%.gba.o : %.gba
123#---------------------------------------------------------------------------------
124 @echo $(notdir $<)
125 $(bin2o)
126
127-include $(DEPENDS)
128
129#---------------------------------------------------------------------------------
130endif
131#---------------------------------------------------------------------------------
diff --git a/Makefile.wii b/Makefile.wii new file mode 100644 index 0000000..341c37b --- /dev/null +++ b/Makefile.wii
@@ -0,0 +1,131 @@
1#---------------------------------------------------------------------------------
2# Clear the implicit built in rules
3#---------------------------------------------------------------------------------
4.SUFFIXES:
5#---------------------------------------------------------------------------------
6ifeq ($(strip $(DEVKITPPC)),)
7$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>devkitPPC")
8endif
9
10include $(DEVKITPPC)/wii_rules
11
12#---------------------------------------------------------------------------------
13# TARGET is the name of the output
14# BUILD is the directory where object files & intermediate files will be placed
15# SOURCES is a list of directories containing source code
16# INCLUDES is a list of directories containing extra header files
17#---------------------------------------------------------------------------------
18TARGET := linkcabledump_wii
19BUILD := build
20SOURCES := source
21DATA := data
22INCLUDES := source
23
24#---------------------------------------------------------------------------------
25# options for code generation
26#---------------------------------------------------------------------------------
27
28CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE)
29CXXFLAGS = $(CFLAGS)
30
31LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map
32
33#---------------------------------------------------------------------------------
34# any extra libraries we wish to link with the project
35#---------------------------------------------------------------------------------
36LIBS := -lfat -logc
37
38
39#---------------------------------------------------------------------------------
40# list of directories containing libraries, this must be the top level containing
41# include and lib
42#---------------------------------------------------------------------------------
43LIBDIRS := $(DEVKITPPC)/lib $(CURDIR)
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#---------------------------------------------------------------------------------
49ifneq ($(BUILD),$(notdir $(CURDIR)))
50#---------------------------------------------------------------------------------
51
52export OUTPUT := $(CURDIR)/$(TARGET)
53
54export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
55 $(foreach dir,$(DATA),$(CURDIR)/$(dir))
56
57export DEPSDIR := $(CURDIR)/$(BUILD)
58
59#---------------------------------------------------------------------------------
60# automatically build a list of object files for our project
61#---------------------------------------------------------------------------------
62CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
63CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
64sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
65SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S)))
66BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
67
68#---------------------------------------------------------------------------------
69# use CXX for linking C++ projects, CC for standard C
70#---------------------------------------------------------------------------------
71ifeq ($(strip $(CPPFILES)),)
72 export LD := $(CC)
73else
74 export LD := $(CXX)
75endif
76
77export OFILES := $(addsuffix .o,$(BINFILES)) \
78 $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \
79 $(sFILES:.s=.o) $(SFILES:.S=.o)
80
81#---------------------------------------------------------------------------------
82# build a list of include paths
83#---------------------------------------------------------------------------------
84export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
85 $(foreach dir,$(LIBDIRS),-I$(dir)/include) \
86 -I$(CURDIR)/$(BUILD) \
87 -I$(LIBOGC_INC)
88
89#---------------------------------------------------------------------------------
90# build a list of library paths
91#---------------------------------------------------------------------------------
92export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \
93 -L$(LIBOGC_LIB)
94
95export OUTPUT := $(CURDIR)/$(TARGET)
96.PHONY: $(BUILD) clean
97
98#---------------------------------------------------------------------------------
99$(BUILD):
100 @[ -d $@ ] || mkdir -p $@
101 @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile.wii
102
103#---------------------------------------------------------------------------------
104clean:
105 @echo clean ...
106 @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol
107
108#---------------------------------------------------------------------------------
109else
110
111DEPENDS := $(OFILES:.o=.d)
112
113#---------------------------------------------------------------------------------
114# main targets
115#---------------------------------------------------------------------------------
116$(OUTPUT).dol: $(OUTPUT).elf
117$(OUTPUT).elf: $(OFILES)
118
119#---------------------------------------------------------------------------------
120# This rule links in binary data with the .jpg extension
121#---------------------------------------------------------------------------------
122%.gba.o : %.gba
123#---------------------------------------------------------------------------------
124 @echo $(notdir $<)
125 $(bin2o)
126
127-include $(DEPENDS)
128
129#---------------------------------------------------------------------------------
130endif
131#---------------------------------------------------------------------------------
diff --git a/README.md b/README.md index 0d0ac36..6598337 100644 --- a/README.md +++ b/README.md
@@ -1,2 +1,6 @@
1# gba-link-cable-dumper 1# gba-link-cable-dumper
2a gc and wii homebrew app to dump gba roms via the gc gba link cable 2a gc and wii homebrew app to dump gba roms via the gc gba link cable.
3
4# Usage
5just have a gc controller in port 1 and a gba without a game inserted in port 2.
6The gba files dumped will be placed in a folder called "dumps" on your main device (sd gecko on gamecube and sd/usb on wii).
diff --git a/build.bat b/build.bat new file mode 100644 index 0000000..aece78f --- /dev/null +++ b/build.bat
@@ -0,0 +1,10 @@
1cd gba
2make clean
3make
4cd ..
5mv -f gba/gba_mb.gba data/gba_mb.gba
6make -f Makefile.gc clean
7make -f Makefile.gc
8make -f Makefile.wii clean
9make -f Makefile.wii
10pause \ No newline at end of file
diff --git a/gba/Makefile b/gba/Makefile new file mode 100644 index 0000000..99dfbb6 --- /dev/null +++ b/gba/Makefile
@@ -0,0 +1,168 @@
1#---------------------------------------------------------------------------------
2# Clear the implicit built in rules
3#---------------------------------------------------------------------------------
4.SUFFIXES:
5#---------------------------------------------------------------------------------
6ifeq ($(strip $(DEVKITARM)),)
7$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM)
8endif
9
10include $(DEVKITARM)/gba_rules
11
12#---------------------------------------------------------------------------------
13# TARGET is the name of the output, if this ends with _mb a multiboot image is generated
14# BUILD is the directory where object files & intermediate files will be placed
15# SOURCES is a list of directories containing source code
16# DATA is a list of directories containing data files
17# INCLUDES is a list of directories containing header files
18#---------------------------------------------------------------------------------
19TARGET := $(shell basename $(CURDIR))_mb
20BUILD := build
21SOURCES := source
22DATA :=
23GRAPHICS := gfx
24INCLUDES :=
25
26#---------------------------------------------------------------------------------
27# options for code generation
28#---------------------------------------------------------------------------------
29ARCH := -mthumb -mthumb-interwork
30
31CFLAGS := -g -Wall -O3\
32 -mcpu=arm7tdmi -mtune=arm7tdmi\
33 -fomit-frame-pointer\
34 -ffast-math \
35 $(ARCH)
36
37CFLAGS += $(INCLUDE)
38
39CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
40
41ASFLAGS := $(ARCH)
42LDFLAGS = -g $(ARCH) -Wl,-Map,$(notdir $@).map
43
44#---------------------------------------------------------------------------------
45# any extra libraries we wish to link with the project
46#---------------------------------------------------------------------------------
47LIBS := -lgba
48
49#---------------------------------------------------------------------------------
50# list of directories containing libraries, this must be the top level containing
51# include and lib
52#---------------------------------------------------------------------------------
53LIBDIRS := $(LIBGBA)
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#---------------------------------------------------------------------------------
59ifneq ($(BUILD),$(notdir $(CURDIR)))
60#---------------------------------------------------------------------------------
61
62export OUTPUT := $(CURDIR)/$(TARGET)
63export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
64 $(foreach dir,$(DATA),$(CURDIR)/$(dir))
65
66export DEPSDIR := $(CURDIR)/$(BUILD)
67
68#---------------------------------------------------------------------------------
69# automatically build a list of object files for our project
70#---------------------------------------------------------------------------------
71CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
72CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
73SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
74BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
75BMPFILES := $(foreach dir,$(GRAPHICS),$(notdir $(wildcard $(dir)/*.bmp)))
76
77#---------------------------------------------------------------------------------
78# use CXX for linking C++ projects, CC for standard C
79#---------------------------------------------------------------------------------
80ifeq ($(strip $(CPPFILES)),)
81#---------------------------------------------------------------------------------
82 export LD := $(CC)
83#---------------------------------------------------------------------------------
84else
85#---------------------------------------------------------------------------------
86 export LD := $(CXX)
87#---------------------------------------------------------------------------------
88endif
89#---------------------------------------------------------------------------------
90
91export OFILES := $(addsuffix .o,$(BINFILES)) \
92 $(BMPFILES:.bmp=.o) \
93 $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
94
95#---------------------------------------------------------------------------------
96# build a list of include paths
97#---------------------------------------------------------------------------------
98export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
99 $(foreach dir,$(LIBDIRS),-I$(dir)/include) \
100 -I$(CURDIR)/$(BUILD)
101
102#---------------------------------------------------------------------------------
103# build a list of library paths
104#---------------------------------------------------------------------------------
105export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
106
107.PHONY: $(BUILD) clean
108
109#---------------------------------------------------------------------------------
110$(BUILD):
111 @[ -d $@ ] || mkdir -p $@
112 @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
113
114all : $(BUILD)
115#---------------------------------------------------------------------------------
116clean:
117 @echo clean ...
118 @rm -fr $(BUILD) $(TARGET).elf $(TARGET).gba
119
120#---------------------------------------------------------------------------------
121else
122
123DEPENDS := $(OFILES:.o=.d)
124
125#---------------------------------------------------------------------------------
126# main targets
127#---------------------------------------------------------------------------------
128$(OUTPUT).gba : $(OUTPUT).elf
129
130$(OUTPUT).elf : $(OFILES)
131
132
133#---------------------------------------------------------------------------------
134# The bin2o rule should be copied and modified
135# for each extension used in the data directories
136#---------------------------------------------------------------------------------
137
138#---------------------------------------------------------------------------------
139# This rule links in binary data with the .bin extension
140#---------------------------------------------------------------------------------
141%.bin.o : %.bin
142#---------------------------------------------------------------------------------
143 @echo $(notdir $<)
144 @$(bin2o)
145
146#---------------------------------------------------------------------------------
147# This rule links in binary data with the .raw extension
148#---------------------------------------------------------------------------------
149%.raw.o : %.raw
150#---------------------------------------------------------------------------------
151 @echo $(notdir $<)
152 @$(bin2o)
153
154#---------------------------------------------------------------------------------
155# This rule creates assembly source files using grit
156# grit takes an image file and a .grit describing how the file is to be processed
157# add additional rules like this for each image extension
158# you use in the graphics folders
159#---------------------------------------------------------------------------------
160%.s %.h : %.bmp %.grit
161#---------------------------------------------------------------------------------
162 grit $< -fts -o$*
163
164-include $(DEPENDS)
165
166#---------------------------------------------------------------------------------
167endif
168#---------------------------------------------------------------------------------
diff --git a/gba/source/main.c b/gba/source/main.c new file mode 100644 index 0000000..9d05189 --- /dev/null +++ b/gba/source/main.c
@@ -0,0 +1,94 @@
1
2#include <gba_console.h>
3#include <gba_video.h>
4#include <gba_interrupt.h>
5#include <gba_systemcalls.h>
6#include <gba_input.h>
7#include <gba_sio.h>
8#include <stdio.h>
9#include <stdlib.h>
10
11u32 getGameSize(void)
12{
13 if(*(vu32*)(0x08000004) != 0x51AEFF24)
14 return 0;
15 u32 i;
16 for(i = (1<<20); i < (1<<25); i<<=1)
17 {
18 vu16 *rompos = (vu16*)(0x08000000+i);
19 int j;
20 bool romend = true;
21 for(j = 0; j < 0x1000; j++)
22 {
23 if(rompos[j] != j)
24 {
25 romend = false;
26 break;
27 }
28 }
29 if(romend) break;
30 }
31 return i;
32}
33//---------------------------------------------------------------------------------
34// Program entry point
35//---------------------------------------------------------------------------------
36int main(void) {
37//---------------------------------------------------------------------------------
38
39 // the vblank interrupt must be enabled for VBlankIntrWait() to work
40 // since the default dispatcher handles the bios flags no vblank handler
41 // is required
42 irqInit();
43 irqEnable(IRQ_VBLANK);
44
45 consoleDemoInit();
46 REG_JOYTR = 0;
47 // ansi escape sequence to set print co-ordinates
48 // /x1b[line;columnH
49 u32 i;
50 iprintf("\x1b[9;10HROM Dumper\n");
51 iprintf("\x1b[10;5HPlease look at the TV\n");
52 REG_HS_CTRL |= 6;
53 while (1) {
54 if((REG_HS_CTRL&4))
55 {
56 REG_HS_CTRL |= 4;
57 u32 gamesize = getGameSize();
58 REG_JOYTR = gamesize;
59 while((REG_HS_CTRL&4) == 0) ;
60 REG_HS_CTRL |= 4;
61 if(gamesize == 0)
62 {
63 REG_JOYTR = 0;
64 continue; //nothing to read
65 }
66 //game in, send header
67 for(i = 0; i < 0xC0; i+=4)
68 {
69 REG_JOYTR = *(vu32*)(0x08000000+i);
70 while((REG_HS_CTRL&4) == 0) ;
71 REG_HS_CTRL |= 4;
72 }
73 //wait for other side to choose
74 while((REG_HS_CTRL&2) == 0) ;
75 REG_HS_CTRL |= 2;
76 if(REG_JOYRE == 0)
77 {
78 REG_JOYTR = 0;
79 continue; //nothing to read
80 }
81 //dump the game
82 for(i = 0; i < gamesize; i+=4)
83 {
84 REG_JOYTR = *(vu32*)(0x08000000+i);
85 while((REG_HS_CTRL&4) == 0) ;
86 REG_HS_CTRL |= 4;
87 }
88 REG_JOYTR = 0;
89 }
90 Halt();
91 }
92}
93
94
diff --git a/source/main.c b/source/main.c new file mode 100644 index 0000000..afe3423 --- /dev/null +++ b/source/main.c
@@ -0,0 +1,400 @@
1/*
2 * Copyright (C) 2016 FIX94
3 *
4 * This software may be modified and distributed under the terms
5 * of the MIT license. See the LICENSE file for details.
6 */
7#include <gccore.h>
8#include <stdio.h>
9#include <malloc.h>
10#include <unistd.h>
11#include <string.h>
12#include <stdlib.h>
13#include <sys/types.h>
14#include <sys/stat.h>
15#include <fcntl.h>
16#include <dirent.h>
17#include <fat.h>
18
19extern u8 gba_mb_gba[];
20extern u32 gba_mb_gba_size;
21
22void printmain()
23{
24 printf("\x1b[2J");
25 printf("\x1b[37m");
26 printf("GBA Link Cable Dumper v1.0 by FIX94\n");
27}
28
29u8 *resbuf,*cmdbuf;
30volatile u16 pads = 0;
31volatile bool ctrlerr = false;
32void ctrlcb(s32 chan, u32 ret)
33{
34 if(ret)
35 {
36 ctrlerr = true;
37 return;
38 }
39 //just call us again
40 pads = (~((resbuf[1]<<8)|resbuf[0]))&0x3FF;
41 SI_Transfer(1,cmdbuf,1,resbuf,5,ctrlcb,350);
42}
43
44volatile u32 transval = 0;
45void transcb(s32 chan, u32 ret)
46{
47 transval = 1;
48}
49
50volatile u32 resval = 0;
51void acb(s32 res, u32 val)
52{
53 resval = val;
54}
55
56unsigned int docrc(u32 crc, u32 val)
57{
58 int i;
59 for(i = 0; i < 0x20; i++)
60 {
61 if((crc^val)&1)
62 {
63 crc>>=1;
64 crc^=0xa1c1;
65 }
66 else
67 crc>>=1;
68 val>>=1;
69 }
70 return crc;
71}
72
73static inline void wait_for_transfer()
74{
75 //350 is REALLY pushing it already, cant go further
76 do{ usleep(350); }while(transval == 0);
77}
78
79void endproc()
80{
81 printf("Start pressed, exit\n");
82 VIDEO_WaitVSync();
83 VIDEO_WaitVSync();
84 exit(0);
85}
86unsigned int calckey(unsigned int size)
87{
88 unsigned int ret = 0;
89 size=(size-0x200) >> 3;
90 int res1 = (size&0x3F80) << 1;
91 res1 |= (size&0x4000) << 2;
92 res1 |= (size&0x7F);
93 res1 |= 0x380000;
94 int res2 = res1;
95 res1 = res2 >> 0x10;
96 int res3 = res2 >> 8;
97 res3 += res1;
98 res3 += res2;
99 res3 <<= 24;
100 res3 |= res2;
101 res3 |= 0x80808080;
102
103 if((res3&0x200) == 0)
104 {
105 ret |= (((res3)&0xFF)^0x4B)<<24;
106 ret |= (((res3>>8)&0xFF)^0x61)<<16;
107 ret |= (((res3>>16)&0xFF)^0x77)<<8;
108 ret |= (((res3>>24)&0xFF)^0x61);
109 }
110 else
111 {
112 ret |= (((res3)&0xFF)^0x73)<<24;
113 ret |= (((res3>>8)&0xFF)^0x65)<<16;
114 ret |= (((res3>>16)&0xFF)^0x64)<<8;
115 ret |= (((res3>>24)&0xFF)^0x6F);
116 }
117 return ret;
118}
119void doreset()
120{
121 cmdbuf[0] = 0xFF; //reset
122 transval = 0;
123 SI_Transfer(1,cmdbuf,1,resbuf,3,transcb,0);
124 wait_for_transfer();
125}
126void getstatus()
127{
128 cmdbuf[0] = 0; //status
129 transval = 0;
130 SI_Transfer(1,cmdbuf,1,resbuf,3,transcb,0);
131 wait_for_transfer();
132}
133u32 recvsafe()
134{
135 memset(resbuf,0,32);
136 cmdbuf[0]=0x14; //read
137 transval = 0;
138 SI_Transfer(1,cmdbuf,1,resbuf,5,transcb,0);
139 wait_for_transfer();
140 return *(vu32*)resbuf;
141}
142void sendsafe(u32 msg)
143{
144 cmdbuf[0]=0x15;cmdbuf[1]=(msg>>0)&0xFF;cmdbuf[2]=(msg>>8)&0xFF;
145 cmdbuf[3]=(msg>>16)&0xFF;cmdbuf[4]=(msg>>24)&0xFF;
146 transval = 0;
147 resbuf[0] = 0;
148 SI_Transfer(1,cmdbuf,5,resbuf,1,transcb,0);
149 wait_for_transfer();
150}
151u32 recvfast()
152{
153 cmdbuf[0]=0x14; //read
154 transval = 0;
155 SI_Transfer(1,cmdbuf,1,resbuf,5,transcb,0);
156 usleep(275);
157 while(transval == 0) ;
158 return *(vu32*)resbuf;
159}
160bool dirExists(const char *path)
161{
162 DIR *dir;
163 dir = opendir(path);
164 if(dir)
165 {
166 closedir(dir);
167 return true;
168 }
169 return false;
170}
171int main(int argc, char *argv[])
172{
173 void *xfb = NULL;
174 GXRModeObj *rmode = NULL;
175 VIDEO_Init();
176 rmode = VIDEO_GetPreferredMode(NULL);
177 xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
178 VIDEO_Configure(rmode);
179 VIDEO_SetNextFramebuffer(xfb);
180 VIDEO_SetBlack(FALSE);
181 VIDEO_Flush();
182 VIDEO_WaitVSync();
183 if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
184 int x = 24, y = 32, w, h;
185 w = rmode->fbWidth - (32);
186 h = rmode->xfbHeight - (48);
187 CON_InitEx(rmode, x, y, w, h);
188 VIDEO_ClearFrameBuffer(rmode, xfb, COLOR_BLACK);
189 PAD_Init();
190 cmdbuf = memalign(32,32);
191 resbuf = memalign(32,32);
192 u8 *testdump = memalign(32,0x400000);
193 if(!testdump) return 0;
194 if(!fatInitDefault())
195 {
196 printmain();
197 printf("ERROR: No usable device found to write dumped files to!\n");
198 VIDEO_WaitVSync();
199 VIDEO_WaitVSync();
200 sleep(5);
201 exit(0);
202 }
203 mkdir("/dumps", S_IREAD | S_IWRITE);
204 if(!dirExists("/dumps"))
205 {
206 printmain();
207 printf("ERROR: Could not create dumps folder, make sure you have a supported device connected!\n");
208 VIDEO_WaitVSync();
209 VIDEO_WaitVSync();
210 sleep(5);
211 exit(0);
212 }
213 int i;
214 while(1)
215 {
216 printmain();
217 printf("Waiting for a GBA in port 2...\n");
218 resval = 0;
219 ctrlerr = false;
220
221 SI_GetTypeAsync(1,acb);
222 while(1)
223 {
224 if(resval)
225 {
226 if(resval == 0x80 || resval & 8)
227 {
228 resval = 0;
229 SI_GetTypeAsync(1,acb);
230 }
231 else if(resval)
232 break;
233 }
234 PAD_ScanPads();
235 VIDEO_WaitVSync();
236 if(PAD_ButtonsHeld(0))
237 endproc();
238 }
239 if(resval & SI_GBA)
240 {
241 printf("GBA Found! Waiting on BIOS\n");
242 resbuf[2]=0;
243 while(!(resbuf[2]&0x10))
244 {
245 doreset();
246 getstatus();
247 }
248 printf("Ready, sending dumper\n");
249 unsigned int sendsize = ((gba_mb_gba_size+7)&~7);
250 unsigned int ourkey = calckey(sendsize);
251 //printf("Our Key: %08x\n", ourkey);
252 //get current sessionkey
253 u32 sessionkeyraw = recvsafe();
254 u32 sessionkey = __builtin_bswap32(sessionkeyraw^0x7365646F);
255 //send over our own key
256 sendsafe(__builtin_bswap32(ourkey));
257 unsigned int fcrc = 0x15a0;
258 //send over gba header
259 for(i = 0; i < 0xC0; i+=4)
260 {
261 sendsafe(__builtin_bswap32(*(vu32*)(gba_mb_gba+i)));
262 if(!(resbuf[0]&0x2)) printf("Possible error %02x\n",resbuf[0]);
263 }
264 //printf("Header done! Sending ROM...\n");
265 for(i = 0xC0; i < sendsize; i+=4)
266 {
267 u32 enc = ((gba_mb_gba[i+3]<<24)|(gba_mb_gba[i+2]<<16)|(gba_mb_gba[i+1]<<8)|(gba_mb_gba[i]));
268 fcrc=docrc(fcrc,enc);
269 sessionkey = (sessionkey*0x6177614B)+1;
270 enc^=sessionkey;
271 enc^=((~(i+(0x20<<20)))+1);
272 enc^=0x20796220;
273 sendsafe(enc);
274 if(!(resbuf[0]&0x2)) printf("Possible error %02x\n",resbuf[0]);
275 }
276 fcrc |= (sendsize<<16);
277 //printf("ROM done! CRC: %08x\n", fcrc);
278 //send over CRC
279 sessionkey = (sessionkey*0x6177614B)+1;
280 fcrc^=sessionkey;
281 fcrc^=((~(i+(0x20<<20)))+1);
282 fcrc^=0x20796220;
283 sendsafe(fcrc);
284 //get crc back (unused)
285 recvsafe();
286 printf("Done!\n");
287 sleep(2);
288 //hm
289 while(1)
290 {
291 printmain();
292 printf("Press A once you have a GBA Game inserted.\n \n");
293 PAD_ScanPads();
294 VIDEO_WaitVSync();
295 u32 btns = PAD_ButtonsDown(0);
296 if(btns&PAD_BUTTON_START)
297 endproc();
298 else if(btns&PAD_BUTTON_A)
299 {
300 if(recvsafe() == 0) //ready
301 {
302 sleep(1); //gba rom prepare
303 u32 gbasize = __builtin_bswap32(recvsafe());
304 if(gbasize == 0)
305 {
306 printf("ERROR: No (Valid) GBA Card inserted!\n");
307 VIDEO_WaitVSync();
308 VIDEO_WaitVSync();
309 sleep(2);
310 continue;
311 }
312 for(i = 0; i < 0xC0; i+=4)
313 *(vu32*)(testdump+i) = recvfast();
314 printf("Game Name: %.12s\n",(char*)(testdump+0xA0));
315 printf("Game ID: %.4s\n",(char*)(testdump+0xAC));
316 printf("Company ID: %.2s\n",(char*)(testdump+0xB0));
317 printf("ROM Size: %02.02f MB\n \n",((float)(gbasize/1024))/1024.f);
318 char gamename[64];
319 sprintf(gamename,"/dumps/%.12s [%.4s%.2s].gba",
320 (char*)(testdump+0xA0),(char*)(testdump+0xAC),(char*)(testdump+0xB0));
321 FILE *f = fopen(gamename,"rb");
322 if(f)
323 {
324 fclose(f);
325 sendsafe(0);
326 printf("ERROR: Game already dumped! Please insert another game.\n");
327 VIDEO_WaitVSync();
328 VIDEO_WaitVSync();
329 sleep(2);
330 continue;
331 }
332 printf("Press A to dump this game, it will take about %i minutes.\n",gbasize/1024/1024*3/2);
333 printf("Press B if you want to cancel dumping this game.\n\n");
334 int dumping = 0;
335 while(1)
336 {
337 PAD_ScanPads();
338 VIDEO_WaitVSync();
339 u32 btns = PAD_ButtonsDown(0);
340 if(btns&PAD_BUTTON_START)
341 endproc();
342 else if(btns&PAD_BUTTON_A)
343 {
344 dumping = 1;
345 break;
346 }
347 else if(btns&PAD_BUTTON_B)
348 break;
349 }
350 sendsafe(dumping);
351 if(dumping == 0)
352 continue;
353 //create base file with size
354 printf("Creating file...\n");
355 int fd = open(gamename, O_WRONLY|O_CREAT);
356 if(fd >= 0)
357 {
358 ftruncate(fd, gbasize);
359 close(fd);
360 }
361 f = fopen(gamename,"wb");
362 if(!f)
363 {
364 printf("ERROR: Could not create file! Exit...\n");
365 VIDEO_WaitVSync();
366 VIDEO_WaitVSync();
367 sleep(5);
368 exit(0);
369 }
370 printf("Dumping...\n");
371 u32 bytes_read = 0;
372 while(gbasize > 0)
373 {
374 int toread = (gbasize > 0x400000 ? 0x400000 : gbasize);
375 int j;
376 for(j = 0; j < toread; j+=4)
377 {
378 *(vu32*)(testdump+j) = recvfast();
379 bytes_read+=4;
380 if((bytes_read&0xFFFF) == 0)
381 {
382 printf("\r%02.02f MB done",(float)(bytes_read/1024)/1024.f);
383 VIDEO_WaitVSync();
384 }
385 //printf("%02x%02x%02x%02x",resbuf[0],resbuf[1],resbuf[2],resbuf[3]);
386 }
387 fwrite(testdump,toread,1,f);
388 gbasize -= toread;
389 }
390 printf("\nClosing file\n");
391 fclose(f);
392 printf("Game dumped!\n");
393 sleep(5);
394 }
395 }
396 }
397 }
398 }
399 return 0;
400}