about summary refs log tree commit diff stats
path: root/gba
diff options
context:
space:
mode:
Diffstat (limited to 'gba')
-rw-r--r--gba/Makefile168
-rw-r--r--gba/source/main.c94
2 files changed, 262 insertions, 0 deletions
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