Skip to content
This repository was archived by the owner on Nov 11, 2024. It is now read-only.

Commit 69543f0

Browse files
authored
Add GP2X support to libfat (#18)
1 parent 1087f6e commit 69543f0

5 files changed

Lines changed: 205 additions & 7 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ libogc/lib
66
libogc/wii_release
77
nds/lib
88
nds/release
9+
gp2x/lib
10+
gp2x/gp2x_release
911
distribute
1012
gba/include
1113
libogc/include
1214
nds/include
15+
gp2x/include

Makefile

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ default: release
1616

1717
all: release dist
1818

19-
release: nds-release gba-release cube-release wii-release
19+
release: nds-release gba-release cube-release wii-release gp2x-release
2020

2121
ogc-release: include/libfatversion.h cube-release wii-release
2222

@@ -32,7 +32,10 @@ cube-release: include/libfatversion.h
3232
wii-release: include/libfatversion.h
3333
$(MAKE) -C libogc PLATFORM=wii BUILD=wii_release
3434

35-
debug: nds-debug gba-debug cube-debug wii-debug
35+
gp2x-release: include/libfatversion.h
36+
$(MAKE) -C gp2x PLATFORM=gp2x BUILD=gp2x_release
37+
38+
debug: nds-debug gba-debug cube-debug wii-debug gp2x-debug
3639

3740
ogc-debug: cube-debug wii-debug
3841

@@ -42,14 +45,16 @@ nds-debug: include/libfatversion.h
4245
gba-debug: include/libfatversion.h
4346
$(MAKE) -C gba BUILD=debug
4447

45-
4648
cube-debug: include/libfatversion.h
4749
$(MAKE) -C libogc PLATFORM=cube BUILD=wii_debug
4850

4951
wii-debug: include/libfatversion.h
5052
$(MAKE) -C libogc PLATFORM=wii BUILD=cube_debug
5153

52-
clean: nds-clean gba-clean ogc-clean
54+
gp2x-debug: include/libfatversion.h
55+
$(MAKE) -C gp2x BUILD=debug
56+
57+
clean: nds-clean gba-clean ogc-clean gp2x-clean
5358

5459
nds-clean:
5560
$(MAKE) -C nds clean
@@ -60,7 +65,10 @@ gba-clean:
6065
ogc-clean:
6166
$(MAKE) -C libogc clean
6267

63-
dist-bin: nds-dist-bin gba-dist-bin ogc-dist-bin
68+
gp2x-clean:
69+
$(MAKE) -C gp2x clean
70+
71+
dist-bin: nds-dist-bin gba-dist-bin ogc-dist-bin gp2x-dist-bin
6472

6573
nds-dist-bin: include/libfatversion.h nds-release distribute/$(VERSTRING)
6674
$(MAKE) -C nds dist-bin
@@ -71,12 +79,16 @@ gba-dist-bin: include/libfatversion.h gba-release distribute/$(VERSTRING)
7179
ogc-dist-bin: include/libfatversion.h ogc-release distribute/$(VERSTRING)
7280
$(MAKE) -C libogc dist-bin
7381

82+
gp2x-dist-bin: include/libfatversion.h gp2x-release distribute/$(VERSTRING)
83+
$(MAKE) -C gp2x dist-bin
84+
7485
dist-src: distribute/$(VERSTRING)
7586
@tar --exclude=.svn --exclude=*CVS* -cvjf distribute/$(VERSTRING)/libfat-src-$(VERSTRING).tar.bz2 \
7687
source include Makefile \
7788
nds/Makefile \
7889
gba/Makefile \
79-
libogc/Makefile
90+
libogc/Makefile \
91+
gp2x/Makefile
8092

8193
dist: dist-bin dist-src
8294

@@ -95,7 +107,7 @@ include/libfatversion.h : Makefile
95107
@echo >> $@
96108
@echo "#endif // __LIBFATVERSION_H__" >> $@
97109

98-
install: nds-install gba-install ogc-install
110+
install: nds-install gba-install ogc-install gp2x-install
99111

100112
nds-install: nds-release
101113
$(MAKE) -C nds install
@@ -105,3 +117,6 @@ gba-install: gba-release
105117

106118
ogc-install: cube-release wii-release
107119
$(MAKE) -C libogc install
120+
121+
gp2x-install: gp2x-release
122+
$(MAKE) -C gp2x install

gp2x/Makefile

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
#---------------------------------------------------------------------------------
2+
.SUFFIXES:
3+
#---------------------------------------------------------------------------------
4+
ifeq ($(strip $(DEVKITARM)),)
5+
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM)
6+
endif
7+
8+
include $(DEVKITARM)/gp2x_rules
9+
10+
11+
#---------------------------------------------------------------------------------
12+
# BUILD is the directory where object files & intermediate files will be placed
13+
# SOURCES is a list of directories containing source code
14+
# INCLUDES is a list of directories containing extra header files
15+
# DATA is a list of directories containing binary files
16+
# LIB is where the built library will be placed
17+
# all directories are relative to this makefile
18+
#---------------------------------------------------------------------------------
19+
BUILD ?= release
20+
SOURCES := ../source
21+
INCLUDES := ../include
22+
DATA :=
23+
LIB := $(TOPDIR)/gp2x/lib
24+
25+
#---------------------------------------------------------------------------------
26+
# options for code generation
27+
#---------------------------------------------------------------------------------
28+
ARCH := -mthumb -mthumb-interwork
29+
30+
CFLAGS := -g -Wall -O2\
31+
-mcpu=arm9tdmi -mtune=arm9tdmi\
32+
-fomit-frame-pointer\
33+
-ffast-math \
34+
$(ARCH)
35+
36+
CFLAGS += $(INCLUDE) -DGP2X
37+
CXXFLAGS := $(CFLAGS)
38+
39+
ASFLAGS := -g $(ARCH)
40+
41+
ifneq ($(BUILD),debug)
42+
export GP2XBIN := $(LIB)/libfat.a
43+
else
44+
export GP2XBIN := $(LIB)/libfatd.a
45+
CFLAGS += -DFAT_DEBUG
46+
endif
47+
48+
49+
#---------------------------------------------------------------------------------
50+
# any extra libraries we wish to link with the project
51+
#---------------------------------------------------------------------------------
52+
LIBS :=
53+
#-lnds9
54+
55+
#---------------------------------------------------------------------------------
56+
# list of directories containing libraries, this must be the top level containing
57+
# include and lib
58+
#---------------------------------------------------------------------------------
59+
LIBDIRS := $(LIBORCUS)
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 TOPDIR ?= $(CURDIR)/..
69+
70+
export DEPSDIR := $(CURDIR)/$(BUILD)
71+
72+
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
73+
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
74+
75+
export CC := $(PREFIX)gcc
76+
export CXX := $(PREFIX)g++
77+
export AR := $(PREFIX)ar
78+
export OBJCOPY := $(PREFIX)objcopy
79+
80+
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
81+
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
82+
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
83+
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
84+
85+
#---------------------------------------------------------------------------------
86+
# use CXX for linking C++ projects, CC for standard C
87+
#---------------------------------------------------------------------------------
88+
ifeq ($(strip $(CPPFILES)),)
89+
#---------------------------------------------------------------------------------
90+
export LD := $(CC)
91+
#---------------------------------------------------------------------------------
92+
else
93+
#---------------------------------------------------------------------------------
94+
export LD := $(CXX)
95+
#---------------------------------------------------------------------------------
96+
endif
97+
#---------------------------------------------------------------------------------
98+
99+
export OFILES := $(addsuffix .o,$(BINFILES)) \
100+
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
101+
102+
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
103+
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
104+
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
105+
-I$(CURDIR)/$(BUILD)
106+
107+
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
108+
109+
.PHONY: $(BUILD) clean
110+
111+
#---------------------------------------------------------------------------------
112+
$(BUILD):
113+
@[ -d $@ ] || mkdir -p $@
114+
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
115+
116+
#---------------------------------------------------------------------------------
117+
clean:
118+
@echo clean ...
119+
@rm -fr debug gp2x_release $(LIB) include
120+
121+
all: $(GP2XBIN)
122+
123+
dist-bin:
124+
@mkdir -p include
125+
@cp $(TOPDIR)/include/fat.h $(TOPDIR)/include/libfatversion.h include
126+
@tar --exclude=.svn --exclude=*CVS* -cvjf $(TOPDIR)/distribute/$(VERSTRING)/libfat-gp2x-$(VERSTRING).tar.bz2 include lib
127+
128+
install:
129+
@mkdir -p $(DESTDIR)$(DEVKITPRO)/liborcus/lib
130+
@mkdir -p $(DESTDIR)$(DEVKITPRO)/liborcus/include
131+
@cp lib/libfat.a $(DESTDIR)$(DEVKITPRO)/liborcus/lib
132+
@cp $(TOPDIR)/include/fat.h $(TOPDIR)/include/libfatversion.h $(DESTDIR)$(DEVKITPRO)/liborcus/include
133+
134+
#---------------------------------------------------------------------------------
135+
else
136+
137+
DEPENDS := $(OFILES:.o=.d)
138+
139+
#---------------------------------------------------------------------------------
140+
# main targets
141+
#---------------------------------------------------------------------------------
142+
$(GP2XBIN) : $(OFILES) $(LIB)
143+
@rm -f "$(GP2XBIN)"
144+
@$(AR) rcs "$(GP2XBIN)" $(OFILES)
145+
@echo built ... $(notdir $@)
146+
147+
$(LIB):
148+
mkdir $(LIB)
149+
150+
#---------------------------------------------------------------------------------
151+
# you need a rule like this for each extension you use as binary data
152+
#---------------------------------------------------------------------------------
153+
%.bin.o : %.bin
154+
#---------------------------------------------------------------------------------
155+
@echo $(notdir $<)
156+
@$(bin2o)
157+
158+
159+
-include $(DEPENDS)
160+
161+
#---------------------------------------------------------------------------------------
162+
endif
163+
#---------------------------------------------------------------------------------------
164+

source/common.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252
#elif defined(GBA)
5353
#include <gba_types.h>
5454
#include <disc_io.h>
55+
#elif defined(GP2X)
56+
#include <gp2xtypes.h>
57+
#include <disc_io.h>
5558
#endif
5659

5760
// Platform specific options
@@ -73,6 +76,9 @@
7376
#define DEFAULT_CACHE_PAGES 2
7477
#define DEFAULT_SECTORS_PAGE 8
7578
#define LIMIT_SECTORS 128
79+
#elif defined (GP2X)
80+
#define DEFAULT_CACHE_PAGES 16
81+
#define DEFAULT_SECTORS_PAGE 8
7682
#endif
7783

7884
#endif // _COMMON_H

source/disc.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,15 @@ const INTERFACE_ID _FAT_disc_interfaces[] = {
111111
{NULL, NULL}
112112
};
113113

114+
/* ====================== GP2X ====================== */
115+
#elif defined (GP2X)
116+
#include <disc_io.h>
117+
118+
const INTERFACE_ID _FAT_disc_interfaces[] = {
119+
{"sd", get_io_gp2xsd},
120+
{NULL, NULL}
121+
122+
};
123+
114124
#endif
115125

0 commit comments

Comments
 (0)