diff --git a/makecom/sky/cwppsky b/makecom/sky/cwppsky new file mode 100644 index 0000000..e13f246 --- /dev/null +++ b/makecom/sky/cwppsky @@ -0,0 +1,241 @@ +########################################################################### +# +# File : makecom/cwsky +# +# Abstract : sky gcc specific compile time options. +# +# See +# o GCC homepage +# http://www.gnu.org/software/gcc +# o GCC compilations flags +# http://www.gnu.org/software/gcc/onlinedocs/gcc_2.html +# +# This file is included from a generic top level makefile when +# the Visual C compiler is selected +# +########################################################################### +# +# This file is a product of Criterion Software Ltd. +# +# This file is provided as is with no warranties of any kind and is +# provided without any obligation on Criterion Software Ltd. or Canon Inc. +# to assist in its use or modification. +# +# Criterion Software Ltd. will not, under any circumstances, be liable for +# any lost revenue or other damages arising from the use of this file. +# +# Copyright (c) 1999 Criterion Software Ltd. +# All Rights Reserved. +# +# RenderWare is a trademark of Canon Inc. +# +########################################################################### + +# Indicate that compiler options have been included +MAKECOM=1 + +ifeq ($(SMALLCODE), 1) +C_OPT = -O4,s +else +C_OPT = -O4,p +endif + +# by default, C optimisation is off when a C debug build is used. +ifndef COPTIMIZE +ifeq ($(CDEBUG), 1) +COPTIMIZE = 0 +else +COPTIMIZE = 1 +endif +endif + +ifeq ($(COPTIMIZE), 1) +CFLAGS += $(C_OPT) -DNDEBUG +else +CFLAGS += -O0 +#---------------- +# # gcc requires the generation of a dependency tree, and hence at least -O1, +# # to detect any use of uninitialized variables +# so build optimised then. Code generation options win. +endif + +ifeq ($(CDEBUG), 1) +CFLAGS += -g -prefix PREFIX_PS2_DEBUG.h +else +CFLAGS += -prefix PREFIX_PS2.h +endif + +ifeq ($(PG), 1) +CFLAGS += -pg -DPG +endif + +CFLAGS += -DRW_USE_SPF + +ifeq ($(SCE_11),1) +CFLAGS += -DSCE_11 +endif + +ifdef IOPPATH +CFLAGS += -DIOPPATH=$(IOPPATH) +endif + +# These seem to be platform specific, not compiler specific + +ifeq ($(NOASM), 1) +CFLAGS += -DNOASM +endif + +ifeq ("$(COMPILER)", "") +COMPILER=cc +endif + +ifeq ("$(LINKER)", "") +# It should be this, but we have a rather strange idea of LINKER +LINKER=link.exe +endif + +###### +# included burst from sony Makefiles +###### + +ifeq ("$(PS2_DRIVE)", "") +SCE = /usr/local/sce/ee +else +SCE = $(PS2_DRIVE):/usr/local/sce/ee +endif + +SCELIBDIR = $(SCE)/lib +SCEINCDIR = $(SCE)/include + +#PS2DIR = '$(subst \,/,$(patsubst %\license.dat,%, $(subst Program Files,Progra~1,$(LM_LICENSE_FILE))))/PS2Sup~1' +PS2DIR = '$(subst \,/,$(patsubst %\license.dat,%,$(LM_LICENSE_FILE)))/PS2 Support' +PS2LIB = '$(subst \,/,$(patsubst %\license.dat,%,$(LM_LICENSE_FILE)))/PS2 Support/Runtime/Libraries' + +# LCFILE = $(PS2DIR)/PS2LinkSegment.lcf +LCFILE = $(DEMODIR)/../../cwcommon/PS2LinkSegment.lcf + +ifeq ($(CDEBUG), 1) +MSLGCC_PS2_LIB = '$(subst \,/,$(patsubst %\license.dat,%,$(LM_LICENSE_FILE))/PS2 Support/Runtime/Libraries/MSLGCC_PS2D.LIB)' +else # ($(CDEBUG), 1) +MSLGCC_PS2_LIB = '$(subst \,/,$(patsubst %\license.dat,%,$(LM_LICENSE_FILE))/PS2 Support/Runtime/Libraries/MSLGCC_PS2.LIB)' +endif # ($(CDEBUG), 1) +ANSICPP_PS2_LIB= '$(subst \,/,$(patsubst %\license.dat,%,$(LM_LICENSE_FILE))/PS2 Support/Msl/MSL_C++/MSL_MIPS/Lib/ANSICPP_PS2.LIB)' + +# RenderWare is a trademark of Canon Inc. + +SYSLIBS = \ + $(PS2DIR)/gcc_wrapper.c \ + $(SCELIBDIR)/libgraph.a \ + $(SCELIBDIR)/libdma.a \ + $(SCELIBDIR)/libdev.a \ + $(SCELIBDIR)/libpkt.a \ + $(SCELIBDIR)/libvu0.a \ + $(SCELIBDIR)/libmpeg.a \ + $(SCELIBDIR)/libipu.a \ + $(SCELIBDIR)/libpc.a \ + $(SCELIBDIR)/libkernl.a \ + $(SCELIBDIR)/libcdvd.a \ + $(SCELIBDIR)/liblout.a \ + $(SCELIBDIR)/libpad.a \ + $(SCELIBDIR)/libsdr.a \ + $(SCELIBDIR)/libssyn.a \ + $(SCELIBDIR)/libmc.a \ + $(SCELIBDIR)/libmsin.a \ + $(SCELIBDIR)/../gcc/ee/lib/libc.a \ + $(SCELIBDIR)/../gcc/ee/lib/libm.a \ + $(SCELIBDIR)/../gcc/lib/gcc-lib/ee/2.95.2/libgcc.a \ + $(MSLGCC_PS2_LIB) \ + $(ANSICPP_PS2_LIB) + +# $(SCELIBDIR)/../gcc/lib/gcc-lib/ee/2.9-ee-990721/libgcc.a \ + +CFLAGS += \ + -D__EXCEPTION__ \ + -D__NEW__ \ + -I'$(subst \,/,$(patsubst %\license.dat,%,$(LM_LICENSE_FILE)))/PS2 Support/Msl/MSL_C++/MSL_Common/Include' \ + -I'$(subst \,/,$(patsubst %\license.dat,%,$(LM_LICENSE_FILE)))/PS2 Support/Msl/MSL_C/MSL_Common/Include' \ + -I'$(subst \,/,$(patsubst %\license.dat,%,$(LM_LICENSE_FILE)))/PS2 Support/Msl/MSL_C/MSL_MIPS/Include' \ + -I'$(subst \,/,$(patsubst %\license.dat,%,$(LM_LICENSE_FILE)))/PS2 Support/Msl/MSL_C/MSL_MIPS/Include/cname' \ + -I$(PS2_DRIVE):/usr/local/sce/ee/include + +ifndef SCE_11 +SYSLIBS += $(SCELIBDIR)/libpad.a +endif + +ifeq ($(RWDEBUG), 1) +ifeq ($(RWMEMDEBUG), 1) +SYSLIBS += -L$(RWLIBDIR) -lrtdbmalloc +endif # ($(RWMEMDEBUG), 1) +endif # ($(RWDEBUG), 1) + +CWARNINGS = \ + +# -warn all \ +# -warn notinlined \ +# -warn pedantic \ +# -warn unused \ +# -warn unusedvar \ +# -warn noimplicit \ +# -warn nounusedarg +# +# # -warn dump + +CC = mwccps2 -dialect ec++ -msgstyle gcc -strict on -gccincludes +CPP = $(CC) +COUT = -o +LOUT = -e +SOUT = -S -o $@ +CPPOPT = -EP +CFLAGS += $(CWARNINGS) +CFLAGS += -c +CFLAGS += -DSKY +LD = mwccps2 --gcc-compat +LFLAGS = -I$(SCEINCDIR) -T $(LCFILE) -warn off -main ENTRYPOINT -g -nostartfiles -L$(SCE)/lib # -lm +LOUT = -o + +AS = asm_r5900_elf.exe +AOUT = -o +ASFLAGS = -c_preprocess -gnu # -w +ASFLAGS += -list $(OBJDIR)/$(basename $(notdir $<)).lsa + +DVPASM = ee-dvp-as +DVPASFLAGS = -I$(SRCDIR) -I$(DEVDIR)/$(RWTARGET) +DVPAOUT = -o + +RUN = dsedb -r run + +ifeq ($(CDEBUG), 1) +ASFLAGS += --gstabs +DVPASMFLAGS += --gstabs +endif + +# We do want assembler + +CFLAGS += -I$(SCE)/../common/include -I$(SCE)/include + +# Add crtO.o to list of object files + +OBJ += crt0.o + +VPATH += $(SCELIBDIR) + +# Define some compiler/platform specific parameters for the naming of object +# and library files + +O = o +L = a +LP = lib +EXE = .elf + +# Directory creation +ifndef MD +MD = mkdir -p +endif + +# The following rule is required, as it is not a default +#.SUFFIXES: .c .$(O) .asm .dsm + +$(OBJDIR)/%.$(O) : %.dsm + $(DVPASM) $(DVPASFLAGS) -alhs $(DVPAOUT)$@ $^ > $(OBJDIR)/$*.lsd + +CPPFLAGS += $(CFLAGS) diff --git a/makecom/sky/cwsky b/makecom/sky/cwsky new file mode 100644 index 0000000..cdd6f13 --- /dev/null +++ b/makecom/sky/cwsky @@ -0,0 +1,262 @@ +########################################################################### +# +# File : makecom/cwsky +# +# Abstract : sky gcc specific compile time options. +# +# See +# o GCC homepage +# http://www.gnu.org/software/gcc +# o GCC compilations flags +# http://www.gnu.org/software/gcc/onlinedocs/gcc_2.html +# +# This file is included from a generic top level makefile when +# the Visual C compiler is selected +# +########################################################################### +# +# This file is a product of Criterion Software Ltd. +# +# This file is provided as is with no warranties of any kind and is +# provided without any obligation on Criterion Software Ltd. or Canon Inc. +# to assist in its use or modification. +# +# Criterion Software Ltd. will not, under any circumstances, be liable for +# any lost revenue or other damages arising from the use of this file. +# +# Copyright (c) 1999 Criterion Software Ltd. +# All Rights Reserved. +# +# RenderWare is a trademark of Canon Inc. +# +########################################################################### + +# Indicate that compiler options have been included +MAKECOM=1 + +ifeq ($(SMALLCODE), 1) +C_OPT = -O4,s # -opt dump +else +C_OPT = -O4,p # -opt dump +endif + +# by default, C optimisation is off when a C debug build is used. +ifndef COPTIMIZE +ifeq ($(CDEBUG), 1) +COPTIMIZE = 0 +else +COPTIMIZE = 1 +endif +endif + +ifeq ($(COPTIMIZE), 1) +CFLAGS += $(C_OPT) -DNDEBUG +else +CFLAGS += -O0 +#---------------- +# # gcc requires the generation of a dependency tree, and hence at least -O1, +# # to detect any use of uninitialized variables +# so build optimised then. Code generation options win. +endif + +ifeq ($(CDEBUG), 1) +CFLAGS += -g -prefix PREFIX_PS2_DEBUG.h +else +CFLAGS += -prefix PREFIX_PS2.h +endif + +ifeq ($(PG), 1) +CFLAGS += -pg -DPG +endif + +CFLAGS += -DRW_USE_SPF + +ifeq ($(SCE_11),1) +CFLAGS += -DSCE_11 +endif + +ifdef IOPPATH +CFLAGS += -DIOPPATH=$(IOPPATH) +endif + +# These seem to be platform specific, not compiler specific + +ifeq ($(NOASM), 1) +CFLAGS += -DNOASM +endif + +ifeq ("$(COMPILER)", "") +COMPILER=cc +endif + +ifeq ("$(LINKER)", "") +# It should be this, but we have a rather strange idea of LINKER +LINKER=link.exe +endif + +###### +# included burst from sony Makefiles +###### + +ifeq ("$(PS2_DRIVE)", "") +SCE = /usr/local/sce/ee +else +SCE = $(PS2_DRIVE):/usr/local/sce/ee +endif + +SCELIBDIR = $(SCE)/lib +SCEINCDIR = $(SCE)/include + +#PS2DIR = '$(subst \,/,$(patsubst %\license.dat,%, $(subst Program Files,Progra~1,$(LM_LICENSE_FILE))))/PS2Sup~1' +PS2DIR = '$(subst \,/,$(patsubst %\license.dat,%,$(LM_LICENSE_FILE)))/PS2 Support' +PS2LIB = '$(subst \,/,$(patsubst %\license.dat,%,$(LM_LICENSE_FILE)))/PS2 Support/Runtime/Libraries' + +# LCFILE = $(PS2DIR)/PS2LinkSegment.lcf +LCFILE = $(DEMODIR)/../../cwcommon/PS2LinkSegment.lcf + + +###### +# The debug version of this seems to have been removed, so always use non-debug +#ifeq ($(CDEBUG), 1) +#MSLGCC_PS2_LIB = '$(subst \,/,$(patsubst %\license.dat,%,$(LM_LICENSE_FILE))/PS2 Support/Runtime/Libraries/MSLGCC_PS2D.LIB)' +#else # ($(CDEBUG), 1) +MSLGCC_PS2_LIB = '$(subst \,/,$(patsubst %\license.dat,%,$(LM_LICENSE_FILE))/PS2 Support/Runtime/Libraries/MSLGCC_PS2.LIB)' +#endif # ($(CDEBUG), 1) +ANSICPP_PS2_LIB= '$(subst \,/,$(patsubst %\license.dat,%,$(LM_LICENSE_FILE))/PS2 Support/Msl/MSL_C++/MSL_MIPS/Lib/ANSICPP_PS2.LIB)' + +# RenderWare is a trademark of Canon Inc. + +SYSLIBS = \ + $(PS2DIR)/gcc_wrapper.c \ + $(SCELIBDIR)/libgraph.a \ + $(SCELIBDIR)/libdma.a \ + $(SCELIBDIR)/libdev.a \ + $(SCELIBDIR)/libpkt.a \ + $(SCELIBDIR)/libvu0.a \ + $(SCELIBDIR)/libmpeg.a \ + $(SCELIBDIR)/libipu.a \ + $(SCELIBDIR)/libpc.a \ + $(SCELIBDIR)/libkernl.a \ + $(SCELIBDIR)/libcdvd.a \ + $(SCELIBDIR)/liblout.a \ + $(SCELIBDIR)/libpad.a \ + $(SCELIBDIR)/libsdr.a \ + $(SCELIBDIR)/libssyn.a \ + $(SCELIBDIR)/libmc.a \ + $(SCELIBDIR)/libmsin.a \ + $(SCELIBDIR)/../gcc/ee/lib/libc.a \ + $(SCELIBDIR)/../gcc/ee/lib/libm.a \ + $(SCELIBDIR)/../gcc/lib/gcc-lib/ee/2.95.2/libgcc.a \ + $(MSLGCC_PS2_LIB) \ + $(ANSICPP_PS2_LIB) + +# $(SCELIBDIR)/../gcc/lib/gcc-lib/ee/2.9-ee-990721/libgcc.a \ + + +CFLAGS += \ + -D__EXCEPTION__ \ + -D__NEW__ \ + -I'$(subst \,/,$(patsubst %\license.dat,%,$(LM_LICENSE_FILE)))/PS2 Support/Msl/MSL_C++/MSL_Common/Include' \ + -I'$(subst \,/,$(patsubst %\license.dat,%,$(LM_LICENSE_FILE)))/PS2 Support/Msl/MSL_C/MSL_Common/Include' \ + -I'$(subst \,/,$(patsubst %\license.dat,%,$(LM_LICENSE_FILE)))/PS2 Support/Msl/MSL_C/MSL_MIPS/Include' \ + -I'$(subst \,/,$(patsubst %\license.dat,%,$(LM_LICENSE_FILE)))/PS2 Support/Msl/MSL_C/MSL_MIPS/Include/cname' \ + -I$(PS2_DRIVE):/usr/local/sce/ee/include + + +ifndef SCE_11 +SYSLIBS += $(SCELIBDIR)/libpad.a +endif + +ifeq ($(RWDEBUG), 1) +ifeq ($(RWMEMDEBUG), 1) +SYSLIBS += -L$(RWLIBDIR) -lrtdbmalloc +endif # ($(RWMEMDEBUG), 1) +endif # ($(RWDEBUG), 1) + +CWARNINGS = \ + -warn all \ + -warn notinlined \ + -warn pedantic \ + -warn unused \ + -warn unusedvar \ + -warn noimplicit \ + -warn nounusedarg + +# -warn dump + +CC = mwccps2 --gcc-compat +CPP = $(CC) +COUT = -o +LOUT = -e +SOUT = -S -o $@ +CPPOPT = -E -P +CFLAGS += $(CWARNINGS) +CFLAGS += -c +CFLAGS += -DSKY +LD = mwccps2 --gcc-compat +LFLAGS = -I$(SCEINCDIR) -T $(LCFILE) -warn off -main ENTRYPOINT -g -nostartfiles -L$(SCE)/lib # -lm +LOUT = -o + +AS = asm_r5900_elf.exe +AOUT = -o +ASFLAGS = -c_preprocess -gnu # -w +ASFLAGS += -list $(OBJDIR)/$(basename $(notdir $<)).lsa + +DVPASM = ee-dvp-as +DVPASFLAGS = -I$(SRCDIR) -I$(DEVDIR)/$(RWTARGET) +DVPAOUT = -o + +RUN = dsedb -r run + +ifeq ($(CDEBUG), 1) +DVPASMFLAGS += --gstabs +else +ASFLAGS += -nodebug +endif + +# We do want assembler + +CFLAGS += -I$(SCE)/../common/include -I$(SCE)/include + +# Add crtO.o to list of object files + +OBJ += crt0.o + +VPATH += $(SCELIBDIR) + +# Define some compiler/platform specific parameters for the naming of object +# and library files + +O = o +L = a +LP = lib +EXE = .elf + +# Directory creation +ifndef MD +MD = mkdir -p +endif + +# Patch support +ifeq ($(RWPATCH), 1) +RWLIBS += \ + $(RWLIBDIR)/$(LP)rppatch.$(L) \ + $(RWLIBDIR)/$(LP)rtbezpat.$(L) +endif # ($(RWPATCH), 1) + +# Patch support +ifeq ($(RWPATCH), 1) +RWLIBS += \ + $(RWLIBDIR)/$(LP)rppatch.$(L) \ + $(RWLIBDIR)/$(LP)rtbezpat.$(L) +endif # ($(RWPATCH), 1) + +# The following rule is required, as it is not a default +#.SUFFIXES: .c .$(O) .asm .dsm + +$(OBJDIR)/%.$(O) : %.dsm + $(DVPASM) $(DVPASFLAGS) -alhs $(DVPAOUT)$@ $^ > $(OBJDIR)/$*.lsd + + + +CPPFLAGS += $(CFLAGS) diff --git a/makecom/sky/sky295 b/makecom/sky/sky295 new file mode 100644 index 0000000..5f0dff5 --- /dev/null +++ b/makecom/sky/sky295 @@ -0,0 +1,326 @@ +########################################################################### +# +# File : makecom/skygcc +# +# Abstract : sky gcc 2.95.2 specific compile time options. +# +# See +# o ee-gcc295 binaries +# http://www.snsys.com/files/psx2/gcc-2.95.2-ee-1.1-bin.zip +# o GCC homepage +# http://www.gnu.org/software/gcc +# o GCC compilations flags +# http://www.gnu.org/software/gcc/onlinedocs/gcc_2.html +# +########################################################################### +# +# This file is a product of Criterion Software Ltd. +# +# This file is provided as is with no warranties of any kind and is +# provided without any obligation on Criterion Software Ltd. or Canon Inc. +# to assist in its use or modification. +# +# Criterion Software Ltd. will not, under any circumstances, be liable for +# any lost revenue or other damages arising from the use of this file. +# +# Copyright (c) 1999 Criterion Software Ltd. +# All Rights Reserved. +# +# RenderWare is a trademark of Canon Inc. +# +########################################################################### + +# Indicate that compiler options have been included +MAKECOM=1 + +ifeq ($(SMALLCODE), 1) +C_OPT = -Os +else +C_OPT = -O3 +endif + +C_OPT += \ + -fcaller-saves \ + -fcse-follow-jumps \ + -fcse-skip-blocks \ + -fdelayed-branch \ + -fexpensive-optimizations \ + -ffast-math \ + -fgcse \ + -fmove-all-movables \ + -freduce-all-givs \ + -fregmove \ + -frerun-cse-after-loop \ + -frerun-loop-opt \ + -fschedule-insns2 \ + -fstrength-reduce \ + -fstrict-aliasing \ + -fthread-jumps \ + -funroll-loops + +# -fdata-sections \ +# -ffunction-sections \ + +# -fdelete-null-pointer-checks \ +# -foptimize-register-moves \ +# -fsingle-precision-constant \ +# -falign-functions=n \ +# -falign-jumps=n \ +# -falign-labels=n \ +# -falign-loops=n \ +# -fbranch-probabilities \ +# -fdce \ +# -ffloat-store \ +# -fforce-addr \ +# -fforce-mem \ +# -finline-functions \ +# -finline-limit=n \ +# -fkeep-inline-functions \ +# -fno-default-inline \ +# -fno-defer-pop \ +# -fno-function-cse \ +# -fno-inline \ +# -fno-math-errno \ +# -fno-peephole \ +# -fomit-frame-pointer \ +# -foptimize-sibling-calls \ +# -fschedule-insns \ +# -fssa \ +# -funroll-all-loops \ + + +# by default, C optimisation is off when a C debug build is used. +ifndef COPTIMIZE +ifeq ($(CDEBUG), 1) +COPTIMIZE = 0 +else +COPTIMIZE = 1 +endif +endif + +ifeq ($(COPTIMIZE), 1) +CFLAGS += $(C_OPT) -DNDEBUG -Wuninitialized +else +CFLAGS += -O0 +#---------------- +# # gcc requires the generation of a dependency tree, and hence at least -O1, +# # to detect any use of uninitialized variables +# so build optimised then. Code generation options win. +endif + +ifeq ($(CDEBUG), 1) +CFLAGS += -g +endif + +ifeq ($(PG), 1) +CFLAGS += -pg -DPG +endif + +CFLAGS += -DRW_USE_SPF + +ifeq ($(SCE_11),1) +CFLAGS += -DSCE_11 +endif + +ifdef IOPPATH +CFLAGS += -DIOPPATH=$(IOPPATH) +endif + +# These seem to be platform specific, not compiler specific + +ifeq ($(NOASM), 1) +CFLAGS += -DNOASM +endif + +ifeq ("$(COMPILER)", "") +COMPILER=cc +endif + +ifeq ("$(LINKER)", "") +# It should be this, but we have a rather strange idea of LINKER +LINKER=link.exe +endif + +###### +# included burst from sony Makefiles +###### + +ifeq ("$(PS2_DRIVE)", "") +SCE = /usr/local/sce/ee +else +SCE = $(PS2_DRIVE):/usr/local/sce/ee +endif + +SCELIBDIR = $(SCE)/lib +SCEINCDIR = $(SCE)/include + +ifeq ("$(SKYLCF)", "RWCMD") +LCFILE = $(DEMODIR)/../../makecom/sky/rwapp.cmd +else # ("$(RWLCF)", "") +LCFILE = $(SCELIBDIR)/app.cmd +endif # ("$(RWLCF)", "") + +SYSLIBS = $(SCELIBDIR)/libgraph.a \ + $(SCELIBDIR)/libdma.a + +ifndef SCE_11 +SYSLIBS += $(SCELIBDIR)/libpad.a +endif + +ifeq ($(RWDEBUG), 1) +ifeq ($(RWMEMDEBUG), 1) +SYSLIBS += -L$(RWLIBDIR) -lrtdbmalloc +endif # ($(RWMEMDEBUG), 1) +endif # ($(RWDEBUG), 1) + +CWARNINGS = \ + -W \ + -Wall \ + -Wcast-qual \ + -Wchar-subscripts \ + -Wcomment \ + -Werror-implicit-function-declaration \ + -Wformat \ + -Wimplicit \ + -Wimplicit-function-declaration \ + -Wimplicit-int \ + -Wimport \ + -Winline \ + -Wlong-long \ + -Wmain \ + -Wmissing-noreturn \ + -Wmultichar \ + -Wnested-externs \ + -Wno-import \ + -Wparentheses \ + -Wpointer-arith \ + -Wreturn-type \ + -Wsign-compare \ + -Wswitch \ + -Wtrigraphs \ + -Wunknown-pragmas \ + -Wunused \ + -Wwrite-strings + +# -Wbad-function-cast +# -Wredundant-decls +# -Wshadow +# -Wtraditional +# -Wundef +# -pedantic +# -Wmissing-declarations /* sce include files fire these warnings*/ +# -Wmissing-prototypes /* sce include files fire these warnings*/ +# -Wstrict-prototypes /* sce include files fire these warnings */ +# -w +# -Wcast-align +# -Wconversion +# -Wfloat-equal +# -Wpacked +# -Wpadded +# -Wunreachable-code +# -Wunused-function +# -Wunused-label +# -Wunused-parameter +# -Wunused-value +# -Wunused-variable +# -Waggregate-return +# -Werror +# -Wid-clash-len +# -Wlarger-than-len +# -fsyntax-only +# -Wbad-function-cast +# -Wredundant-decls +# -Wshadow +# -Wtraditional +# -Wundef +# -pedantic +# -Wmissing-declarations /* sce include files fire these warnings*/ +# -Wmissing-prototypes /* sce include files fire these warnings*/ +# -Wstrict-prototypes /* sce include files fire these warnings */ +# -w +# -Wcast-align +# -Wconversion +# -Wfloat-equal +# -Wpacked +# -Wpadded +# -Wunreachable-code +# -Wunused-function +# -Wunused-label +# -Wunused-parameter +# -Wunused-value +# -Wunused-variable +# -Waggregate-return +# -Werror +# -Wid-clash-len +# -Wlarger-than-len +# -fsyntax-only + +CC = ee-gcc295 +CPP = $(CC) +COUT = -o +LOUT = -e +SOUT = -S -o $@ +CPPOPT = -E -P +CFLAGS += $(CWARNINGS) -fno-common -c +CFLAGS += -Wa,-I$(DEVDIR)/$(RWTARGET) +CFLAGS += -Wa,-al=$*.lst +CFLAGS += -DSKY +LD = ee-gcc295 -Q # -Q seems to avoid temporary file race conditions +LFLAGS = -T $(LCFILE) -g -Wl,-Map,$(TARGET).map -nostartfiles -L$(SCELIBDIR) -lm +LOUT = -o + +AS = ee-gcc295 -Q # -Q seems to avoid temporary file race conditions +AOUT = -o +ASFLAGS = -c -xassembler-with-cpp +ASFLAGS += -Wa,-al=$*.lsa + +DVPASM = ee-dvp-as +DVPASFLAGS = -I$(SRCDIR) -I$(DEVDIR)/$(RWTARGET) +DVPAOUT = -o + +RUN = dsedb -r run + +ifeq ($(CDEBUG), 1) +ASFLAGS += --gstabs +DVPASMFLAGS += --gstabs +endif + +# We do want assembler + +CFLAGS += -I/usr/local/sce/common/include -I/usr/local/sce/ee/include +CFLAGS += -fno-rtti -fno-exceptions + + +# Add crtO.o to list of object files + +OBJ += crt0.o + +VPATH += $(SCELIBDIR) + +# Define some compiler/platform specific parameters for the naming of object +# and library files + +O = o +L = a +LP = lib +EXE = .elf + +# Directory creation +ifndef MD +MD = mkdir -p +endif + +# Patch support +ifeq ($(RWPATCH), 1) +RWLIBS += \ + $(RWLIBDIR)/$(LP)rppatch.$(L) \ + $(RWLIBDIR)/$(LP)rtbezpat.$(L) +endif # ($(RWPATCH), 1) + +# The following rule is required, as it is not a default + +#.SUFFIXES: .c .$(O) .asm .dsm + +$(OBJDIR)/%.$(O) : %.dsm + $(DVPASM) $(DVPASFLAGS) -alhs $(DVPAOUT)$@ $^ > $(OBJDIR)/$*.lsd +CPPFLAGS += $(CFLAGS) diff --git a/makecom/sky/sky2953 b/makecom/sky/sky2953 new file mode 100644 index 0000000..eaca9d1 --- /dev/null +++ b/makecom/sky/sky2953 @@ -0,0 +1,323 @@ +########################################################################### +# +# File : makecom/skygcc +# +# Abstract : sky gcc 2.95.3 specific compile time options. +# +# See +# o ee-gcc2953 binaries +# http://www.snsys.com/files/psx2/Temp/ps2-ee-2.95.3-v1.01.zip +# o GCC homepage +# http://www.gnu.org/software/gcc/gcc-2.95/gcc-2.95.3.html +# +########################################################################### +# +# This file is a product of Criterion Software Ltd. +# +# This file is provided as is with no warranties of any kind and is +# provided without any obligation on Criterion Software Ltd. or Canon Inc. +# to assist in its use or modification. +# +# Criterion Software Ltd. will not, under any circumstances, be liable for +# any lost revenue or other damages arising from the use of this file. +# +# Copyright (c) 1999 Criterion Software Ltd. +# All Rights Reserved. +# +# RenderWare is a trademark of Canon Inc. +# +########################################################################### + +# Indicate that compiler options have been included +MAKECOM=1 + +ifeq ($(SMALLCODE), 1) +C_OPT = -Os +else +C_OPT = -O3 +endif + +C_OPT += \ + -fcaller-saves \ + -fcse-follow-jumps \ + -fcse-skip-blocks \ + -fdelayed-branch \ + -fexpensive-optimizations \ + -ffast-math \ + -fgcse \ + -fmove-all-movables \ + -freduce-all-givs \ + -fregmove \ + -frerun-cse-after-loop \ + -frerun-loop-opt \ + -fschedule-insns2 \ + -fstrength-reduce \ + -fstrict-aliasing \ + -fthread-jumps \ + -funroll-loops + +# -fdata-sections \ +# -ffunction-sections \ + +# -fdelete-null-pointer-checks \ +# -foptimize-register-moves \ +# -fsingle-precision-constant \ +# -falign-functions=n \ +# -falign-jumps=n \ +# -falign-labels=n \ +# -falign-loops=n \ +# -fbranch-probabilities \ +# -fdce \ +# -ffloat-store \ +# -fforce-addr \ +# -fforce-mem \ +# -finline-functions \ +# -finline-limit=n \ +# -fkeep-inline-functions \ +# -fno-default-inline \ +# -fno-defer-pop \ +# -fno-function-cse \ +# -fno-inline \ +# -fno-math-errno \ +# -fno-peephole \ +# -fomit-frame-pointer \ +# -foptimize-sibling-calls \ +# -fschedule-insns \ +# -fssa \ +# -funroll-all-loops \ + + +# by default, C optimisation is off when a C debug build is used. +ifndef COPTIMIZE +ifeq ($(CDEBUG), 1) +COPTIMIZE = 0 +else +COPTIMIZE = 1 +endif +endif + +ifeq ($(COPTIMIZE), 1) +CFLAGS += $(C_OPT) -DNDEBUG -Wuninitialized +else +CFLAGS += -O0 +#---------------- +# # gcc requires the generation of a dependency tree, and hence at least -O1, +# # to detect any use of uninitialized variables +# so build optimised then. Code generation options win. +endif + +ifeq ($(CDEBUG), 1) +CFLAGS += -g +endif + +ifeq ($(PG), 1) +CFLAGS += -pg -DPG +endif + +CFLAGS += -DRW_USE_SPF + +ifeq ($(SCE_11),1) +CFLAGS += -DSCE_11 +endif + +ifdef IOPPATH +CFLAGS += -DIOPPATH=$(IOPPATH) +endif + +# These seem to be platform specific, not compiler specific + +ifeq ($(NOASM), 1) +CFLAGS += -DNOASM +endif + +ifeq ("$(COMPILER)", "") +COMPILER=cc +endif + +ifeq ("$(LINKER)", "") +# It should be this, but we have a rather strange idea of LINKER +LINKER=link.exe +endif + +###### +# included burst from sony Makefiles +###### + +ifeq ("$(PS2_DRIVE)", "") +SCE = /usr/local/sce/ee +else +SCE = $(PS2_DRIVE):/usr/local/sce/ee +endif + +SCELIBDIR = $(SCE)/lib +SCEINCDIR = $(SCE)/include + +ifeq ("$(SKYLCF)", "RWCMD") +LCFILE = $(DEMODIR)/../../makecom/sky/rwapp.cmd +else # ("$(RWLCF)", "") +LCFILE = $(SCELIBDIR)/app.cmd +endif # ("$(RWLCF)", "") + +SYSLIBS = $(SCELIBDIR)/libgraph.a \ + $(SCELIBDIR)/libdma.a + +ifndef SCE_11 +SYSLIBS += $(SCELIBDIR)/libpad.a +endif + +ifeq ($(RWDEBUG), 1) +ifeq ($(RWMEMDEBUG), 1) +SYSLIBS += -L$(RWLIBDIR) -lrtdbmalloc +endif # ($(RWMEMDEBUG), 1) +endif # ($(RWDEBUG), 1) + +CWARNINGS = \ + -W \ + -Wall \ + -Wcast-qual \ + -Wchar-subscripts \ + -Wcomment \ + -Werror-implicit-function-declaration \ + -Wformat \ + -Wimplicit \ + -Wimplicit-function-declaration \ + -Wimplicit-int \ + -Wimport \ + -Winline \ + -Wlong-long \ + -Wmain \ + -Wmissing-noreturn \ + -Wmultichar \ + -Wnested-externs \ + -Wno-import \ + -Wparentheses \ + -Wpointer-arith \ + -Wreturn-type \ + -Wsign-compare \ + -Wswitch \ + -Wtrigraphs \ + -Wunknown-pragmas \ + -Wunused \ + -Wwrite-strings + +# -Wbad-function-cast +# -Wredundant-decls +# -Wshadow +# -Wtraditional +# -Wundef +# -pedantic +# -Wmissing-declarations /* sce include files fire these warnings*/ +# -Wmissing-prototypes /* sce include files fire these warnings*/ +# -Wstrict-prototypes /* sce include files fire these warnings */ +# -w +# -Wcast-align +# -Wconversion +# -Wfloat-equal +# -Wpacked +# -Wpadded +# -Wunreachable-code +# -Wunused-function +# -Wunused-label +# -Wunused-parameter +# -Wunused-value +# -Wunused-variable +# -Waggregate-return +# -Werror +# -Wid-clash-len +# -Wlarger-than-len +# -fsyntax-only +# -Wbad-function-cast +# -Wredundant-decls +# -Wshadow +# -Wtraditional +# -Wundef +# -pedantic +# -Wmissing-declarations /* sce include files fire these warnings*/ +# -Wmissing-prototypes /* sce include files fire these warnings*/ +# -Wstrict-prototypes /* sce include files fire these warnings */ +# -w +# -Wcast-align +# -Wconversion +# -Wfloat-equal +# -Wpacked +# -Wpadded +# -Wunreachable-code +# -Wunused-function +# -Wunused-label +# -Wunused-parameter +# -Wunused-value +# -Wunused-variable +# -Waggregate-return +# -Werror +# -Wid-clash-len +# -Wlarger-than-len +# -fsyntax-only + +CC = ee-gcc2953 # -Q seems to avoid temporary file race conditions +CPP = $(CC) +COUT = -o +LOUT = -e +SOUT = -S -o $@ +CPPOPT = -E -P +CFLAGS += $(CWARNINGS) -fno-common -c +CFLAGS += -Wa,-I$(DEVDIR)/$(RWTARGET) +CFLAGS += -Wa,-al=$*.lst +CFLAGS += -DSKY +LD = ee-gcc2953 # -Q seems to avoid temporary file race conditions +LFLAGS = -T $(LCFILE) -g -Wl,-Map,$(TARGET).map -nostartfiles -L$(SCELIBDIR) -lm +LOUT = -o + +AS = ee-gcc2953 # -Q seems to avoid temporary file race conditions +AOUT = -o +ASFLAGS = -c -xassembler-with-cpp +ASFLAGS += -Wa,-al=$*.lsa + +DVPASM = ee-dvp-as +DVPASFLAGS = -I$(SRCDIR) -I$(DEVDIR)/$(RWTARGET) +DVPAOUT = -o + +RUN = dsedb -r run + +ifeq ($(CDEBUG), 1) +ASFLAGS += --gstabs +DVPASMFLAGS += --gstabs +endif + +# We do want assembler + +CFLAGS += -I/usr/local/sce/common/include -I/usr/local/sce/ee/include +CFLAGS += -fno-rtti -fno-exceptions + +# Add crtO.o to list of object files + +OBJ += crt0.o + +VPATH += $(SCELIBDIR) + +# Define some compiler/platform specific parameters for the naming of object +# and library files + +O = o +L = a +LP = lib +EXE = .elf + +# Directory creation +ifndef MD +MD = mkdir -p +endif + +# Patch support +ifeq ($(RWPATCH), 1) +RWLIBS += \ + $(RWLIBDIR)/$(LP)rppatch.$(L) \ + $(RWLIBDIR)/$(LP)rtbezpat.$(L) +endif # ($(RWPATCH), 1) + +# The following rule is required, as it is not a default + +#.SUFFIXES: .c .$(O) .asm .dsm + +$(OBJDIR)/%.$(O) : %.dsm + $(DVPASM) $(DVPASFLAGS) -alhs $(DVPAOUT)$@ $^ > $(OBJDIR)/$*.lsd +CPPFLAGS += $(CFLAGS) diff --git a/makecom/sky/skygcc b/makecom/sky/skygcc new file mode 100644 index 0000000..7f5d2c9 --- /dev/null +++ b/makecom/sky/skygcc @@ -0,0 +1,276 @@ +########################################################################### +# +# File : makecom/skygcc +# +# Abstract : sky gcc specific compile time options. +# +# See +# o GCC homepage +# http://www.gnu.org/software/gcc +# o GCC compilations flags +# http://www.gnu.org/software/gcc/onlinedocs/gcc_2.html +# +# This file is included from a generic top level makefile when +# using the Linux hosted Sony tool chain. It may also be used +# with PC builds of the Sony tools. +# +########################################################################### +# +# This file is a product of Criterion Software Ltd. +# +# This file is provided as is with no warranties of any kind and is +# provided without any obligation on Criterion Software Ltd. or Canon Inc. +# to assist in its use or modification. +# +# Criterion Software Ltd. will not, under any circumstances, be liable for +# any lost revenue or other damages arising from the use of this file. +# +# Copyright (c) 1999 Criterion Software Ltd. +# All Rights Reserved. +# +# RenderWare is a trademark of Canon Inc. +# +########################################################################### + +# Indicate that compiler options have been included +MAKECOM=1 + +CC = ee-gcc + +# +# Sony tool chain 2.96 requires a slightly different config to the +# older ones. The following lets us sellect. +# +CC_VER := $(shell $(CC) -dumpversion) +CC_VER := $(findstring 2.96, $(CC_VER)) + +ifeq ($(SMALLCODE), 1) +C_OPT = -Os +else +C_OPT = -O3 +endif + +# by default, C optimisation is off when a C debug build is used. +ifndef COPTIMIZE +ifeq ($(CDEBUG), 1) +COPTIMIZE = 0 +else +COPTIMIZE = 1 +endif +endif + +ifeq ($(COPTIMIZE), 1) +CFLAGS += $(C_OPT) -DNDEBUG -Wuninitialized +else +CFLAGS += -O0 +#---------------- +# # gcc requires the generation of a dependency tree, and hence at least -O1, +# # to detect any use of uninitialized variables +# so build optimised then. Code generation options win. +endif + +ifeq ($(CDEBUG), 1) +CFLAGS += -g +endif + +ifeq ($(PG), 1) +CFLAGS += -pg -DPG +endif + +CFLAGS += -DRW_USE_SPF + +ifeq ($(SCE_11),1) +CFLAGS += -DSCE_11 +endif + +ifdef IOPPATH +CFLAGS += -DIOPPATH=$(IOPPATH) +endif + +# These seem to be platform specific, not compiler specific + +ifeq ($(NOASM), 1) +CFLAGS += -DNOASM +endif + +ifeq ("$(COMPILER)", "") +COMPILER=cc +endif + +ifeq ("$(LINKER)", "") +# It should be this, but we have a rather strange idea of LINKER +LINKER=link.exe +endif + +###### +# included burst from sony Makefiles +###### + +ifeq ("$(PS2_DRIVE)", "") +SCE = /usr/local/sce/ee +else +SCE = $(PS2_DRIVE):/usr/local/sce/ee +endif + +SCELIBDIR = $(SCE)/lib +SCEINCDIR = $(SCE)/include + +ifeq ("$(SKYLCF)", "RWCMD") +LCFILE = $(DEMODIR)/../../makecom/sky/rwapp.cmd +else # ("$(RWLCF)", "") +LCFILE = $(SCELIBDIR)/app.cmd +endif # ("$(RWLCF)", "") + +SYSLIBS = $(SCELIBDIR)/libgraph.a \ + $(SCELIBDIR)/libdma.a + +ifndef SCE_11 +SYSLIBS += $(SCELIBDIR)/libpad.a +endif + +ifeq ($(RWDEBUG), 1) +ifeq ($(RWMEMDEBUG), 1) +SYSLIBS += -L$(RWLIBDIR) -lrtdbmalloc +endif # ($(RWMEMDEBUG), 1) +endif # ($(RWDEBUG), 1) + +CWARNINGS = \ + -Wall \ + -W \ + -Wcast-qual \ + -Wchar-subscripts \ + -Wcomment \ + -Wformat \ + -Wimplicit \ + -Wimplicit-function-declaration \ + -Wimplicit-int \ + -Winline \ + -Wlong-long \ + -Wmain \ + -Wmissing-noreturn \ + -Wmultichar \ + -Wnested-externs \ + -Wparentheses \ + -Wpointer-arith \ + -Wreturn-type \ + -Wsign-compare \ + -Wswitch \ + -Wtrigraphs \ + -Wunknown-pragmas \ + -Wunused \ + -Wwrite-strings + +# -Wid-clash-32 \ +# -ansi +# -pedantic +# -Waggregate-return +# -Wbad-function-cast +# -Wcast-align +# -Wconversion +# -Werror +# -Wlarger-than-len +# -Wmissing-declarations /* sce include files fire these warnings*/ +# -Wmissing-prototypes /* sce include files fire these warnings*/ +# -Wredundant-decls +# -Wshadow +# -Wstrict-prototypes /* sce include files fire these warnings */ +# -Wtraditional +# -Wundef +# -Wuninitialized + +CPP = $(CC) +COUT = -o +LOUT = -e +SOUT = -S -o $@ +CPPOPT = -E -P +CFLAGS += $(CWARNINGS) -fno-common -c +CFLAGS += -Wa,-I$(DEVDIR)/$(RWTARGET) +#CFLAGS += -Wa,-al=$*.lst +CFLAGS += -DSKY +LD = ee-gcc +LFLAGS = -T $(LCFILE) -g -Wl,-Map,$(TARGET).map -L$(SCELIBDIR) -lm + +ifeq ("$(CC_VER)", "2.96") +LFLAGS += -mno-crt0 +else +LFLAGS += -nostartfiles +endif + +LOUT = -o + +AS = ee-gcc +AOUT = -o +ASFLAGS = -c -xassembler-with-cpp +#ASFLAGS += -Wa,-al=$*.lsa + +DVPASM = ee-dvp-as +DVPASFLAGS = -I$(SRCDIR) -I$(DEVDIR)/$(RWTARGET) +DVPAOUT = -o + +RUN = dsedb -r run + +ifeq ($(CDEBUG), 1) +ASFLAGS += --gstabs +DVPASMFLAGS += --gstabs +endif + +# We do want assembler + +CFLAGS += -I/usr/local/sce/common/include -I/usr/local/sce/ee/include +CFLAGS += -fno-exceptions + + +# Add crtO.o to list of object files + +OBJ += crt0.o + +VPATH += $(SCELIBDIR) + +# Define some compiler/platform specific parameters for the naming of object +# and library files + +O = o +L = a +LP = lib +EXE = .elf + +# Directory creation +ifndef MD +MD = mkdir -p +endif + +# Patch support +ifeq ($(RWPATCH), 1) +RWLIBS += \ + $(RWLIBDIR)/$(LP)rppatch.$(L) \ + $(RWLIBDIR)/$(LP)rtbezpat.$(L) +endif # ($(RWPATCH), 1) + +# The following rule is required, as it is not a default + +#.SUFFIXES: .c .$(O) .asm .dsm + +$(OBJDIR)/%.$(O) : %.dsm + $(DVPASM) $(DVPASFLAGS) -alhs $(DVPAOUT)$@ $^ > $(OBJDIR)/$*.lsd + +CPPFLAGS += $(CFLAGS) + +CPPFLAGS += \ + -Wctor-dtor-privacy \ + -Wno-non-template-friend \ + -Wno-pmf-conversions \ + -Wnon-virtual-dtor \ + -Woverloaded-virtual \ + -Wreorder \ + -Wsign-promo \ + -Wsynth + +# -Weffc++ +# -Wold-style-cast + + + + + + +CXX = ee-g++ diff --git a/makecom/sky/skygpp b/makecom/sky/skygpp new file mode 100644 index 0000000..3844942 --- /dev/null +++ b/makecom/sky/skygpp @@ -0,0 +1,8 @@ +########################################## +# These are for gcc in the sky cross env # +# running in c++ mode # +########################################## + +CFLAGS += -x c++ + +include $(RWSDK)/../app/makecom/sky/sky2953 diff --git a/makecom/sky/skyprodg b/makecom/sky/skyprodg new file mode 100644 index 0000000..c411eb2 --- /dev/null +++ b/makecom/sky/skyprodg @@ -0,0 +1,237 @@ +########################################################################### +# +# File : makecom/skygcc +# +# Abstract : sky gcc specific compile time options. +# +# See +# o GCC homepage +# http://www.gnu.org/software/gcc +# o GCC compilations flags +# http://www.gnu.org/software/gcc/onlinedocs/gcc_2.html +# +# This file is included from a generic top level makefile when +# the Visual C compiler is selected +# +########################################################################### +# +# This file is a product of Criterion Software Ltd. +# +# This file is provided as is with no warranties of any kind and is +# provided without any obligation on Criterion Software Ltd. or Canon Inc. +# to assist in its use or modification. +# +# Criterion Software Ltd. will not, under any circumstances, be liable for +# any lost revenue or other damages arising from the use of this file. +# +# Copyright (c) 1999 Criterion Software Ltd. +# All Rights Reserved. +# +# RenderWare is a trademark of Canon Inc. +# +########################################################################### + +# Indicate that compiler options have been included +MAKECOM=1 + +ifeq ($(SMALLCODE), 1) +C_OPT = -Os +else +C_OPT = -O3 +endif + +# by default, C optimisation is off when a C debug build is used. +ifndef COPTIMIZE +ifeq ($(CDEBUG), 1) +COPTIMIZE = 0 +else +COPTIMIZE = 1 +endif +endif + +ifeq ($(COPTIMIZE), 1) +CFLAGS += $(C_OPT) -DNDEBUG -Wuninitialized +else +CFLAGS += -O0 +#---------------- +# # gcc requires the generation of a dependency tree, and hence at least -O1, +# # to detect any use of uninitialized variables +# so build optimised then. Code generation options win. +endif + +ifeq ($(CDEBUG), 1) +CFLAGS += -g +endif + +ifeq ($(PG), 1) +CFLAGS += -pg -DPG +endif + +CFLAGS += -DRW_USE_SPF + +ifeq ($(SCE_11),1) +CFLAGS += -DSCE_11 +endif + +ifeq ($(RWDEBUG), 1) +ifeq ($(RWMEMDEBUG), 1) +RWLIBS += $(RWLIBDIR)/$(LP)rtmemdbg.$(L) +endif # ($(RWMEMDEBUG), 1) +endif # ($(RWDEBUG), 1) + +ifdef IOPPATH +CFLAGS += -DIOPPATH=$(IOPPATH) +endif + +# These seem to be platform specific, not compiler specific + +ifeq ($(NOASM), 1) +CFLAGS += -DNOASM +endif + +ifeq ("$(COMPILER)", "") +COMPILER=cc +endif + +ifeq ("$(LINKER)", "") +# It should be this, but we have a rather strange idea of LINKER +LINKER=link.exe +endif + +###### +# included burst from sony Makefiles +###### + +SCE = /usr/local/sce/ee +SCELIBDIR = $(SCE)/lib +SCEINCDIR = $(SCE)/include + + +LCFILE = $(PS2_DRIVE):$(SCELIBDIR)/ps2.lk + +SYSLIBS = $(PS2_DRIVE):$(SCELIBDIR)/libgraph.a \ + $(PS2_DRIVE):$(SCELIBDIR)/libdma.a \ + $(PS2_DRIVE):$(SCELIBDIR)/libdev.a \ + $(PS2_DRIVE):$(SCELIBDIR)/libpkt.a \ + $(PS2_DRIVE):$(SCELIBDIR)/libvu0.a + +ifndef SCE_11 +SYSLIBS += $(PS2_DRIVE):$(SCELIBDIR)/libpad.a +endif + +CWARNINGS = \ + -Wall \ + -W \ + -Wcast-qual \ + -Wchar-subscripts \ + -Wcomment \ + -Wformat \ + -Wid-clash-32 \ + -Wimplicit \ + -Wimplicit-function-declaration \ + -Wimplicit-int \ + -Winline \ + -Wlong-long \ + -Wmain \ + -Wmissing-noreturn \ + -Wmultichar \ + -Wnested-externs \ + -Wparentheses \ + -Wpointer-arith \ + -Wreturn-type \ + -Wsign-compare \ + -Wswitch \ + -Wtrigraphs \ + -Wunknown-pragmas \ + -Wunused \ + -Wwrite-strings + +# -ansi +# -pedantic +# -Waggregate-return +# -Wbad-function-cast +# -Wcast-align +# -Wconversion +# -Werror +# -Wlarger-than-len +# -Wmissing-declarations /* sce include files fire these warnings*/ +# -Wmissing-prototypes /* sce include files fire these warnings*/ +# -Wredundant-decls +# -Wshadow +# -Wstrict-prototypes /* sce include files fire these warnings */ +# -Wtraditional +# -Wundef +# -Wuninitialized + +CC = ee-gcc +CPP = $(CC) +COUT = -o +LOUT = -e +SOUT = -S -o $@ +CPPOPT = -E -P +CFLAGS += $(CWARNINGS) -fno-common -c +CFLAGS += -Wa,-I$(DEVDIR)/$(RWTARGET) +CFLAGS += -Wa,-al=$*.lst +CFLAGS += -DSKY +LD = ps2link +LFLAGS = \ + -verbose -c \ + -l $(PS2_DRIVE):$(SCELIBDIR) \ + -l $(PS2_DRIVE):$(SCE)/gcc/ee/lib \ + -l $(PS2_DRIVE):$(SCE)/gcc/lib/gcc-lib/ee/2.9-ee-990721 \ + @$(LCFILE),$(PROJS),$(PROJS).map +LOUT = -o + +AS = ee-gcc +AOUT = -o +ASFLAGS = -c -xassembler-with-cpp +ASFLAGS += -Wa,-al=$*.lsa + +DVPASM = ee-dvp-as +DVPASFLAGS = -I$(SRCDIR) -I$(DEVDIR)/$(RWTARGETcomp) +DVPAOUT = -o + +RUN = dsedb -r run + +ifeq ($(CDEBUG), 1) +ASFLAGS += --gstabs +DVPASMFLAGS += --gstabs +endif + +# We do want assembler + +CFLAGS += -I$(SCEINCDIR) +CFLAGS += -fno-rtti -fno-exceptions + +# Add crtO.o to list of object files + +OBJ += crt0.o + +VPATH += $(SCELIBDIR) + +# Define some compiler/platform specific parameters for the naming of object +# and library files + +O = o +L = a +LP = lib +EXE = .elf + +# Directory creation +ifndef MD +MD = mkdir -p +endif + +# Patch support +ifeq ($(RWPATCH), 1) +RWLIBS += \ + $(RWLIBDIR)/$(LP)rppatch.$(L) \ + $(RWLIBDIR)/$(LP)rtbezpat.$(L) +endif # ($(RWPATCH), 1) + +#.SUFFIXES: .c .$(O) .asm .dsm + +$(OBJDIR)/%.$(O) : %.dsm + $(DVPASM) $(DVPASFLAGS) -alhs $(DVPAOUT)$@ $^ > $(OBJDIR)/$*.lsd +CPPFLAGS += $(CFLAGS) + diff --git a/makefile b/makefile new file mode 100644 index 0000000..9e13360 --- /dev/null +++ b/makefile @@ -0,0 +1,31 @@ +# Define the projects to be built + +DEMO = rwtest + +# include common makefile options + +include makeopt + +CXXSRC = $(SRC)/main.cpp \ + $(SRC)/Pad.cpp \ + $(SRC)/FileMgr.cpp \ + +CSRC = $(SRC)/camera.c \ + $(SRC)/skyfs.c \ + +#CSRC += $(SKELSRC) + +ifeq ($(RWMETRICS), 1) +CSRC += $(SKEL)/vecfont.c \ + $(SKEL)/metrics.c +endif + +RWLIBS += $(RWLIBDIR)/$(LP)rtcharse.$(L) \ + $(RWLIBDIR)/$(LP)rpworld.$(L) \ + $(RWLIBDIR)/$(LP)rwcore.$(L) + +SYSLIBS += $(SCELIBDIR)/libcdvd.a + +include maketarg + + diff --git a/makeopt b/makeopt new file mode 100644 index 0000000..0cb6fa4 --- /dev/null +++ b/makeopt @@ -0,0 +1,170 @@ +# put a default target at the top to prevent rules from getting confused later + +all: demo + +# +# include user custom options file if it exists +# +ifndef RWOPTIONS +RWOPTIONS = options.mak +endif +include $(RWOPTIONS) + +ifndef RWSIMD +RWSIMD = 0 +endif + +ifndef RWVERBOSE +RWVERBOSE = 0 +endif + +ifndef RWSUPPRESSINLINE +RWSUPPRESSINLINE = 0 +endif + +ifndef RWSUPPRESSOPTIMIZATIONPRAGMAS +RWSUPPRESSOPTIMIZATIONPRAGMAS = 0 +endif + +ifeq ($(RWFULLPLATFORM), 1) +RWPLATFORM = $(RWOS)/$(RWCOMPILER)/$(RWTARGET) +RWPLATFORMEXE = $(RWOS)_$(RWCOMPILER)_$(RWTARGET) +else +RWPLATFORM = $(RWTARGET) +RWPLATFORMEXE = $(RWTARGET) +endif # ifeq ($(RWFULLPLATFORM), 1) + +# all directories are defined relative to DEMODIR +ifndef DEMODIR +DEMODIR = $(CURDIR) +# setting BASDEIR=$(CURDIR) enables absolute path names +# which makes a better job of debug symbols for profiling. debugging etc. +# see also http://www.fsf.org/software/make/make.html +endif + +# RWOUTPUT +ifeq ("$(RWOUTPUT)", "") +RWLIBPATH = $(RWSDK)/lib/$(RWPLATFORM) +else +RWLIBPATH = $(RWSDK)/lib/$(RWPLATFORM)/$(RWOUTPUT) +endif + +ifeq ($(RWMETRICS), 1) +RWLIBDIR = $(RWLIBPATH)/metrics +ifeq ("$(RWOUTPUT)", "") +OBJDIR = obj/$(RWPLATFORM)m +else +OBJDIR = obj/$(RWPLATFORM)m/$(RWOUTPUT) +endif +CFLAGS += -DRWMETRICS +PROJS = $(DEMO)_$(RWPLATFORMEXE)m$(EXE) +else # RWMETRICS +ifeq ($(RWDEBUG), 1) +RWLIBDIR = $(RWLIBPATH)/debug +ifeq ("$(RWOUTPUT)", "") +OBJDIR = obj/$(RWPLATFORM)d +else +OBJDIR = obj/$(RWPLATFORM)d/$(RWOUTPUT) +endif +CFLAGS += -DRWDEBUG +PROJS = $(DEMO)_$(RWPLATFORMEXE)d$(EXE) +else # RWDEBUG +ifeq ($(CPROFILE), 1) +RWLIBDIR = $(RWLIBPATH)/profile +ifeq ("$(RWOUTPUT)", "") +OBJDIR = obj/$(RWPLATFORM)p +else +OBJDIR = obj/$(RWPLATFORM)p/$(RWOUTPUT) +endif +CFLAGS += -DCPROFILE +PROJS = $(DEMO)_$(RWPLATFORMEXE)p$(EXE) +else # CPROFILE +ifeq ($(MSWST), 1) +RWLIBDIR = $(RWLIBPATH)/mswst +ifeq ("$(RWOUTPUT)", "") +OBJDIR = obj/$(RWPLATFORM)wst +else +OBJDIR = obj/$(RWPLATFORM)wst/$(RWOUTPUT) +endif +PROJS = $(DEMO)_$(RWPLATFORMEXE)wst$(EXE) +else # MSWS +RWLIBDIR = $(RWLIBPATH) +ifeq ("$(RWOUTPUT)", "") +OBJDIR = obj/$(RWPLATFORM) +else +OBJDIR = obj/$(RWPLATFORM)/$(RWOUTPUT) +endif +PROJS = $(DEMO)_$(RWPLATFORMEXE)$(EXE) +endif # MSWST +endif # CPROFILE +endif # RWDEBUG +endif # RWMETRICS + +ifeq ("$(RWTARGET)", "xbox") +XBOXPROJS = $(patsubst %$(EXE),%.xbe,$(PROJS)) +endif + +ifeq ($(RWPATCH), 1) +CFLAGS += -DRWPATCH +endif + +ifeq ($(RWMEMDEBUG), 1) +CFLAGS += -DRWMEMDEBUG +endif + +ifeq ($(RWSIMD), 1) +CFLAGS += -DRWSIMD +endif + +ifeq ($(RWVERBOSE), 1) +CFLAGS += -DRWVERBOSE +endif + +ifeq ($(RWSUPPRESSINLINE), 1) +CFLAGS += -DRWSUPPRESSINLINE +endif + +ifeq ($(RWSUPPRESSOPTIMIZATIONPRAGMAS), 1) +CFLAGS += -DRWSUPPRESSOPTIMIZATIONPRAGMAS +endif + +RWINCDIR = $(RWSDK)/include/$(RWPLATFORM) + +# Define Common Directories & Files + +SKEL = $(DEMODIR)/skel +SKELPS = $(SKEL)/$(RWOS) +COMMON = $(DEMODIR)/democom +SRC = $(DEMODIR)/src + +# FXNODES= $(DEMODIR)/../fxnodes + +ifeq ($(RWLOGO), 1) +RWLIBS += $(RWLIBDIR)/$(LP)rplogo.$(L) +CFLAGS += -DRWLOGO +endif + +ifeq ($(RWSPLASH), 1) +CFLAGS += -DRWSPLASH +endif + +CINCLUDE += \ + -I$(RWINCDIR) \ + -I$(RWSDK)/include/$(RWPLATFORM)/archive \ + -I$(COMMON) \ + -I$(SKEL) \ + -I$(SKELPS) \ + -I$(SRC) + +CFLAGS += \ + -DRWTARGET_$(RWPLATFORMEXE) \ + $(CINCLUDE) + +# -I$(FXNODES) + +include makecom/$(RWOS)/$(RWCOMPILER) + +ifeq ($(RWTEST), 1) +include ../../../tests/maketest/$(RWOS) +endif + diff --git a/maketarg b/maketarg new file mode 100644 index 0000000..1daadf9 --- /dev/null +++ b/maketarg @@ -0,0 +1,90 @@ + +OBJ += $(patsubst %.c,$(OBJDIR)/%.$(O),$(notdir $(CSRC))) +OBJ += $(patsubst %.cpp,$(OBJDIR)/%.$(O),$(notdir $(CXXSRC))) +OBJ += $(SKELOBJ) + +ifeq ("$(RWTARGET)", "xbox") +TARGET = $(XBOXPROJS) +else +TARGET = $(PROJS) +endif + +# VALIDATE will be done first, if set. +demo: $(VALIDATE) $(OBJDIR) $(TARGET) + +$(OBJDIR): + $(MD) $@ + +$(PROJS): $(OPTPROJ) $(OBJ) $(RWLIBS) + $(LD) $(SYSOBJ) $(OBJ) $(RWLIBS) $(SYSLIBS) $(LOUT)$@ $(LFLAGS) + +run: demo + $(RUN) $(PROJS) + +doscheck: + cygfind . -print | doschk + +distclean: clean $(OPTDISTCLEAN) + $(RM) *.xbe + $(RM) *.exe + $(RM) *.elf + $(RM) *.lst + $(RM) *.dsw + $(RM) *.prf + $(RM) crt0.* + $(RM) .map + $(RM) -r obj + $(RM) -r $(DEMO)_*Data + +clean: + $(RM) $(OBJ) $(OPTPROJ) + +# Rules + +$(OBJDIR)/%.$(O): $(SKEL)/%.c + $(CC) $(CFLAGS) $(COUT)$@ $< + +$(OBJDIR)/%.$(O): $(SKELPS)/%.c + $(CC) $(CFLAGS) $(COUT)$@ $< + +$(OBJDIR)/%.$(O): $(COMMON)/%.c + $(CC) $(CFLAGS) $(COUT)$@ $< + +$(OBJDIR)/%.$(O): $(SRC)/%.c + $(CC) $(CFLAGS) $(COUT)$@ $< + + +$(OBJDIR)/%.$(O): $(SRC)/$(RWOS)/%.c + $(CC) $(CFLAGS) $(COUT)$@ $< + +%.$(O) : %.c + $(CC) $(CFLAGS) $(COUT)$@ $< + +# $(OBJDIR)/%.$(O): $(FXNODES)/%.c +# $(CC) $(CFLAGS) $(COUT)$@ $< + + + + + +# c++ Rules + +$(OBJDIR)/%.$(O): $(SKEL)/%.cpp + $(CXX) $(CFLAGS) $(COUT)$@ $< + +$(OBJDIR)/%.$(O): $(SKELPS)/%.cpp + $(CXX) $(CFLAGS) $(COUT)$@ $< + +$(OBJDIR)/%.$(O): $(COMMON)/%.cpp + $(CXX) $(CFLAGS) $(COUT)$@ $< + +$(OBJDIR)/%.$(O): $(SRC)/%.cpp + $(CXX) $(CFLAGS) $(COUT)$@ $< + + +$(OBJDIR)/%.$(O): $(SRC)/$(RWOS)/%.cpp + $(CXX) $(CFLAGS) $(COUT)$@ $< + +%.$(O) : %.cpp + $(CXX) $(CFLAGS) $(COUT)$@ $< + diff --git a/models/player.dff b/models/player.dff new file mode 100755 index 0000000..36409ac Binary files /dev/null and b/models/player.dff differ diff --git a/models/player.txd b/models/player.txd new file mode 100755 index 0000000..9feb7db Binary files /dev/null and b/models/player.txd differ diff --git a/options.mak b/options.mak new file mode 100644 index 0000000..b2bab03 --- /dev/null +++ b/options.mak @@ -0,0 +1,12 @@ +RWSDK=/usr/local/RW310/rwsdk +RWTARGET=sky2 +RWOUTPUT= +RWOS=sky +RWCOMPILER=skygcc +RWDEBUG=0 +RWMETRICS=0 +RWLOGO=0 +RWSPLASH=0 +RWMOUSE=0 +CDEBUG=0 +IOPPATH=/usr/local/sce/iop diff --git a/src/FileMgr.cpp b/src/FileMgr.cpp new file mode 100644 index 0000000..f0298d6 --- /dev/null +++ b/src/FileMgr.cpp @@ -0,0 +1,158 @@ +#include +#include "rwcore.h" +#include "common.h" +#include "libcdvd.h" +#include "FileMgr.h" + +char CFileMgr::ms_rootDirName[128] = "\\"; +char CFileMgr::ms_dirName[128]; + +void SkySetDirectory(char *dir) {} // TODO: skyfs.c + +void +CFileMgr::Initialise(void) +{ + SkySetDirectory(ms_rootDirName); +} + +void +CFileMgr::ChangeDir(const char *dir) +{ + if(*dir == '\\'){ + strcpy(ms_dirName, ms_rootDirName); + dir++; + } + if(*dir != '\0'){ + strcat(ms_dirName, dir); + if(dir[strlen(dir)-1] != '\\') + strcat(ms_dirName, "\\"); + } + SkySetDirectory(ms_dirName); +} + +void +CFileMgr::SetDir(const char *dir) +{ + strcpy(ms_dirName, ms_rootDirName); + if(*dir != '\0'){ + strcat(ms_dirName, dir); + if(dir[strlen(dir)-1] != '\\') + strcat(ms_dirName, "\\"); + } + SkySetDirectory(ms_dirName); +} + +// actually no mode on PS2 +ssize_t +CFileMgr::LoadFile(const char *file, uint8 *buf, int maxlen, const char *mode) +{ + void *fp; + int len, size; + RwFileFunctions *fileFuncs; + + fileFuncs = RwOsGetFileInterface(); + fp = fileFuncs->rwfopen(file, "r"); + if(fp == nil) + return -1; + size = 0; + // actually fwread returns size_t, so always positive... + while(len = fileFuncs->rwfread(buf+size, 1, 0x4000, fp), len >= 0){ + size += len; + if(size > maxlen) + assert(0 && "read past buffer"); + if(len != 0x4000){ + fileFuncs->rwfclose(fp); + return size; + } + } + return -1; +} + +int +CFileMgr::OpenFile(const char *file) +{ + RwFileFunctions *fileFuncs; + + fileFuncs = RwOsGetFileInterface(); + return (int)fileFuncs->rwfopen(file, "r"); +} + +int +CFileMgr::OpenFileForWriting(const char *file) +{ + RwFileFunctions *fileFuncs; + + fileFuncs = RwOsGetFileInterface(); + return (int)fileFuncs->rwfopen(file, "wo"); +} + +size_t +CFileMgr::Read(int fd, char *buf, ssize_t len) +{ + RwFileFunctions *fileFuncs; + + fileFuncs = RwOsGetFileInterface(); + return (int)fileFuncs->rwfread(buf, 1, len, (void*)fd); +} + +size_t +CFileMgr::Write(int fd, const char *buf, ssize_t len) +{ + RwFileFunctions *fileFuncs; + + fileFuncs = RwOsGetFileInterface(); + return (int)fileFuncs->rwfwrite(buf, 1, len, (void*)fd); +} + +bool +CFileMgr::Seek(int fd, int offset, int whence) +{ + RwFileFunctions *fileFuncs; + + fileFuncs = RwOsGetFileInterface(); + return (int)fileFuncs->rwfseek((void*)fd, offset, whence); +} + +bool +CFileMgr::ReadLine(int fd, char *buf, int len) +{ + RwFileFunctions *fileFuncs; + + fileFuncs = RwOsGetFileInterface(); + return fileFuncs->rwfgets(buf, len, (void*)fd) > 0; +} + +int +CFileMgr::CloseFile(int fd) +{ + RwFileFunctions *fileFuncs; + + fileFuncs = RwOsGetFileInterface(); + return (int)fileFuncs->rwfclose((void*)fd); +} + +bool +CFileMgr::GetCdFile(const char *file, uint32 &pos, uint32 &size) +{ + sceCdlFILE cdfile; + if(sceCdSearchFile(&cdfile, file) == 0) + return false; + pos = cdfile.lsn; + size = cdfile.size; + return true; +} + +void +CFileMgr::InitCd(void) +{ + sceCdDiskReady(0); + sceCdStandby(); + sceCdSync(0); +} + +void +CFileMgr::InitCdSystem(void) +{ + sceCdInit(SCECdINIT); + sceCdMmode(SCECdDVD); +} diff --git a/src/FileMgr.h b/src/FileMgr.h new file mode 100644 index 0000000..276a459 --- /dev/null +++ b/src/FileMgr.h @@ -0,0 +1,31 @@ +class CFileMgr +{ + static char ms_rootDirName[128]; + static char ms_dirName[128]; +public: + static void Initialise(void); + static void ChangeDir(const char *dir); + static void SetDir(const char *dir); +// not on PS2 + static void SetDirMyDocuments(void); + static ssize_t LoadFile(const char *file, uint8 *buf, int maxlen, const char *mode); +// not on PS2 + static int OpenFile(const char *file, const char *mode); + static int OpenFile(const char *file); + static int OpenFileForWriting(const char *file); + static size_t Read(int fd, char *buf, ssize_t len); + static size_t Write(int fd, const char *buf, ssize_t len); + static bool Seek(int fd, int offset, int whence); + static bool ReadLine(int fd, char *buf, int len); + static int CloseFile(int fd); +// not on PS2 + static int GetErrorReadWrite(int fd); +// not on PS2 + static char *GetRootDirName() { return ms_rootDirName; } + +// only PS2 + static bool GetCdFile(const char *file, uint32 &xx, uint32 &yy); + static void InitCd(void); + static void InitCdSystem(void); +}; + diff --git a/src/Pad.cpp b/src/Pad.cpp new file mode 100644 index 0000000..b51cd8c --- /dev/null +++ b/src/Pad.cpp @@ -0,0 +1,153 @@ +#include "common.h" +#include "rwcore.h" + +#include "eeregs.h" +#include "sifdev.h" +#include "sifrpc.h" + +#include "libpad.h" + +#include "Pad.h" + +static unsigned char ReadData[32] __attribute__ ((aligned(64))); +static u_long128 PadDmaBuffer[scePadDmaBufferMax] __attribute__ ((aligned(64))); +static u_long128 PadDmaBuffer2[scePadDmaBufferMax] __attribute__ ((aligned(64))); + +Pad pad1; + + +RwBool +PadInit(void) +{ + scePadInit(0); + scePadPortOpen(0, 0, PadDmaBuffer); + scePadPortOpen(1, 0, PadDmaBuffer2); + + return TRUE; +} + +#define Min(x, y) ((x) < (y) ? (x) : (y)) +#define Max(x, y) ((x) > (y) ? (x) : (y)) + +void +UpdatePad(Pad *pad, int port) +{ + unsigned int PadData; + int id, ext_id; + int state; + + pad->OldState = pad->NewState; + memset(&pad->NewState, 0, sizeof(pad->NewState)); + + state = scePadGetState(port, 0); + + switch(pad->Phase){ + // Detect + case 0: + // wait for stable state + if(state != scePadStateStable && state != scePadStateFindCTP1) + break; + + id = scePadInfoMode(port, 0, InfoModeCurID, 0); + if(id==0) break; + + ext_id = scePadInfoMode(port, 0, InfoModeCurExID,0); + if(ext_id>0) id = ext_id; + + switch(id) { + /* STANDARD */ + case 4: + pad->Phase = 40; + break; + + /* ANALOG */ + case 7: + pad->Phase = 70; + break; + + default: + pad->Phase = 99; + break; + } + break; + + // Standard Controller + case 40: + // check if there are modes + if (scePadInfoMode(port, 0, InfoModeIdTable, -1)==0) { + pad->Phase = 99; + break; + } + pad->Phase++; + // fall through + case 41: + // set mode to analog but don't lock + if (scePadSetMainMode(port, 0, 1, 0)==1) + pad->Phase++; + break; + case 42: + // wait until set + if (scePadGetReqState(port, 0)==scePadReqStateFaild) + pad->Phase--; + // check info again, should now be analog + if (scePadGetReqState(port, 0)==scePadReqStateComplete) + pad->Phase = 0; + break; + + // DualShock2 + case 70: + // check if we can have pressure sensitive buttons + if (scePadInfoPressMode(port,0)==1) { + pad->Phase = 76; + break; + } + pad->Phase = 99; + break; + case 76: + // yes, enable + if (scePadEnterPressMode(port, 0)==1) + pad->Phase++; + break; + case 77: + // wait until enabled + if (scePadGetReqState(port, 0)==scePadReqStateFaild) + pad->Phase--; + if (scePadGetReqState(port, 0)==scePadReqStateComplete) + pad->Phase = 99; + break; + + default: + // wait for stable state + if(state != scePadStateStable && state != scePadStateFindCTP1) + break; + + if(scePadRead(port, 0, ReadData) > 0) + PadData = 0xffff ^ ((ReadData[2] << 8) | ReadData[3]); + else + PadData = 0; + + if(PadData & SCE_PADLup) pad->NewState.DPadUp = 255; + if(PadData & SCE_PADLdown) pad->NewState.DPadDown = 255; + if(PadData & SCE_PADLleft) pad->NewState.DPadLeft = 255; + if(PadData & SCE_PADLright) pad->NewState.DPadRight = 255; + if(PadData & SCE_PADstart) pad->NewState.Start = 255; + if(PadData & SCE_PADselect) pad->NewState.Select = 255; + if(PadData & SCE_PADRup) pad->NewState.Triangle = 255; + if(PadData & SCE_PADRdown) pad->NewState.Cross = 255; + if(PadData & SCE_PADRleft) pad->NewState.Square = 255; + if(PadData & SCE_PADRright) pad->NewState.Circle = 255; + if(PadData & SCE_PADL1) pad->NewState.LeftShoulder1 = 255; + if(PadData & SCE_PADL2) pad->NewState.LeftShoulder2 = 255; + if(PadData & SCE_PADR1) pad->NewState.RightShoulder1 = 255; + if(PadData & SCE_PADR2) pad->NewState.RightShoulder2 = 255; + if(PadData & SCE_PADi) pad->NewState.LeftShock = 255; + if(PadData & SCE_PADj) pad->NewState.RightShock = 255; +#define CLAMP_AXIS(x) (((x) < 43 && (x) >= -42) ? 0 : (((x) > 0) ? (Max((x)-42, 0)*127/85) : Min((x)+42, 0)*127/85)) +#define GET_AXIS(x) CLAMP_AXIS((x)-128) + pad->NewState.RightStickX = GET_AXIS((int16)ReadData[4]); + pad->NewState.RightStickY = GET_AXIS((int16)ReadData[5]); + pad->NewState.LeftStickX = GET_AXIS((int16)ReadData[6]); + pad->NewState.LeftStickY = GET_AXIS((int16)ReadData[7]); + } +} + diff --git a/src/Pad.h b/src/Pad.h new file mode 100644 index 0000000..b856c80 --- /dev/null +++ b/src/Pad.h @@ -0,0 +1,31 @@ + +typedef struct ControllerState ControllerState; +struct ControllerState +{ + int16 LeftStickX, LeftStickY; + int16 RightStickX, RightStickY; + int16 LeftShoulder1, LeftShoulder2; + int16 RightShoulder1, RightShoulder2; + int16 DPadUp, DPadDown, DPadLeft, DPadRight; + int16 Start, Select; + int16 Square, Triangle, Cross, Circle; + int16 LeftShock, RightShock; + int16 NetworkTalk; + +// float GetLeftStickX(void) { return LeftStickX/32767.0f; }; +// float GetLeftStickY(void) { return LeftStickY/32767.0f; }; +// float GetRightStickX(void) { return RightStickX/32767.0f; }; +// float GetRightStickY(void) { return RightStickY/32767.0f; }; +}; + +typedef struct Pad Pad; +struct Pad +{ + ControllerState OldState, NewState; + int Phase; +}; +extern Pad pad1; + +RwBool SkyPadDetect(void); +RwBool PadInit(void); +void UpdatePad(Pad *pad, int port); diff --git a/src/camera.c b/src/camera.c new file mode 100644 index 0000000..aed1545 --- /dev/null +++ b/src/camera.c @@ -0,0 +1,408 @@ +#include "rwcore.h" + +#include "camera.h" + + +/* + ***************************************************************************** + */ +void +CameraSize(RwCamera *camera, RwRect *rect, RwReal viewWindow, RwReal aspectRatio) +{ + if( camera ) + { + RwVideoMode videoMode; + static RwRect origSize = {0, 0, 0, 0}; + + if( origSize.w == 0 || origSize.h == 0 ) + { + origSize.x = origSize.y = 0; + origSize.w = RwRasterGetWidth(RwCameraGetRaster(camera)); + origSize.h = RwRasterGetHeight(RwCameraGetRaster(camera)); + } + + RwEngineGetVideoModeInfo(&videoMode, RwEngineGetCurrentVideoMode()); + + if( !rect ) + { + static RwRect r; + + rect = &r; + + /* + * Rect not specified - reuse current values... + */ + rect->w = RwRasterGetWidth(RwCameraGetRaster(camera)); + rect->h = RwRasterGetHeight(RwCameraGetRaster(camera)); + rect->x = rect->y = 0; + } + + /* + * For full screen applications, resizing the camera just doesn't + * make sense, use the video mode size... + */ + if( videoMode.flags & rwVIDEOMODEEXCLUSIVE ) + { + rect->x = rect->y = 0; + rect->w = videoMode.width; + rect->h = videoMode.height; + } + + if( (rect->w > 0) && (rect->h > 0) ) + { + RwV2d vw; + RwRaster *raster = NULL; + RwRaster *zRaster = NULL; + + /* + * In OpenGl & D3D8 you don't need to care about the rasters + * of the cameras + */ +#if (defined(D3D8_DRVMODEL_H)) || (defined(OPENGL_DRVMODEL_H)) + raster = RwCameraGetRaster(camera); + zRaster = RwCameraGetZRaster(camera); + + raster->width = rect->w; + raster->height= rect->h; + + zRaster->width = rect->w; + zRaster->height= rect->h; + +#else + /* + * Destroy rasters... + */ + raster = RwCameraGetRaster(camera); + if( raster ) + { + RwRasterDestroy(raster); + + raster = NULL; + } + + zRaster = RwCameraGetZRaster(camera); + if( zRaster ) + { + RwRasterDestroy(zRaster); + + zRaster = NULL; + } + + /* + * Create new rasters... + */ + raster = RwRasterCreate(rect->w, rect->h, 0, rwRASTERTYPECAMERA); + zRaster = RwRasterCreate(rect->w, rect->h, 0, rwRASTERTYPEZBUFFER); + + if( raster && zRaster ) + { + RwCameraSetRaster(camera, raster); + RwCameraSetZRaster(camera, zRaster); + } + else + { + if( raster ) + { + RwRasterDestroy(raster); + + raster = NULL; + } + + if( zRaster ) + { + RwRasterDestroy(zRaster); + + zRaster = NULL; + } + + rect->w = origSize.w; + rect->h = origSize.h; + + /* + * Use default values... + */ + raster = + RwRasterCreate(rect->w, rect->h, 0, rwRASTERTYPECAMERA); + + zRaster = + RwRasterCreate(rect->w, rect->h, 0, rwRASTERTYPEZBUFFER); + + RwCameraSetRaster(camera, raster); + RwCameraSetZRaster(camera, zRaster); + + return; + } +#endif + + /* + * Figure out the view window... + */ + if( videoMode.flags & rwVIDEOMODEEXCLUSIVE ) + { + /* + * Derive ratio from aspect ratio... + */ + vw.x = viewWindow; + vw.y = viewWindow / aspectRatio; + } + else + { + + /* + * In OpenGl & D3D8 you don't need to care about the rasters + * of the cameras, just change the aspect ratio + */ +#if (defined(D3D8_DRVMODEL_H)) || (defined(OPENGL_DRVMODEL_H)) +#else + rect->w = RwRasterGetWidth(RwCameraGetRaster(camera)); + rect->h = RwRasterGetHeight(RwCameraGetRaster(camera)); +#endif + /* + * Derive from pixel ratios... + */ + if( rect->w > rect->h ) + { + vw.x = viewWindow; + vw.y = (rect->h * viewWindow) / rect->w; + } + else + { + vw.x = (rect->w * viewWindow) / rect->h; + vw.y = viewWindow; + } + } + + RwCameraSetViewWindow(camera, &vw); + } + } + + return; +} + + +/* + ***************************************************************************** + */ +void +CameraDestroy(RwCamera *camera) +{ + if( camera ) + { + RwRaster *raster; + RwFrame *frame; + + frame = RwCameraGetFrame(camera); + if( frame ) + { + RwCameraSetFrame(camera, NULL); + + RwFrameDestroy(frame); + } + + raster = RwCameraGetRaster(camera); + if( raster ) + { + RwRasterDestroy(raster); + + RwCameraSetRaster(camera, NULL); + } + + raster = RwCameraGetZRaster(camera); + if( raster ) + { + RwRasterDestroy(raster); + + RwCameraSetZRaster(camera, NULL); + } + + RwCameraDestroy(camera); + } + + return; +} + + +/* + ***************************************************************************** + */ +RwCamera * +CameraCreate(RwInt32 width, RwInt32 height, RwBool zBuffer) +{ + RwCamera *camera; + + camera = RwCameraCreate(); + if( camera ) + { + RwCameraSetFrame(camera, RwFrameCreate()); + + RwCameraSetRaster(camera, + RwRasterCreate(width, height, 0, rwRASTERTYPECAMERA)); + + if( zBuffer ) + { + RwCameraSetZRaster(camera, + RwRasterCreate(width, height, 0, rwRASTERTYPEZBUFFER)); + } + + /* + * Check everything is valid... + */ + if( RwCameraGetFrame(camera) && RwCameraGetRaster(camera) && + (!zBuffer || RwCameraGetZRaster(camera)) ) + { + /* + * Everything OK... + */ + return camera; + } + } + + /* + * Error - so clean up... + */ + CameraDestroy(camera); + + return NULL; +} + + +/* + ***************************************************************************** + */ +void +CameraMove(RwCamera *camera, RwV3d *delta) +{ + RwV3d offset; + RwFrame *cameraFrame; + RwMatrix *cameraMatrix; + RwV3d *at, *up, *right; + + cameraFrame = RwCameraGetFrame(camera); + cameraMatrix = RwFrameGetMatrix(cameraFrame); + + at = RwMatrixGetAt(cameraMatrix); + up = RwMatrixGetUp(cameraMatrix); + right = RwMatrixGetRight(cameraMatrix); + + offset.x = delta->x * right->x + delta->y * up->x + delta->z * at->x; + offset.y = delta->x * right->y + delta->y * up->y + delta->z * at->y; + offset.z = delta->x * right->z + delta->y * up->z + delta->z * at->z; + + RwFrameTranslate(cameraFrame, &offset, rwCOMBINEPOSTCONCAT); + + return; +} + + +/* + ***************************************************************************** + */ +void +CameraPan(RwCamera *camera, const RwV3d *pos, RwReal angle) +{ + RwV3d invCamPos; + RwFrame *cameraFrame; + RwMatrix *cameraMatrix; + RwV3d camPos; + + cameraFrame = RwCameraGetFrame(camera); + cameraMatrix = RwFrameGetMatrix(cameraFrame); + + camPos = (pos) ? *pos : *RwMatrixGetPos(cameraMatrix); + + RwV3dScale(&invCamPos, &camPos, -1.0f); + + /* + * Translate the camera back to the rotation origin... + */ + RwFrameTranslate(cameraFrame, &invCamPos, rwCOMBINEPOSTCONCAT); + + /* + * Get the camera's UP vector and use this as the axis of rotation... + */ + RwMatrixRotate(cameraMatrix, + RwMatrixGetUp(cameraMatrix), angle, rwCOMBINEPOSTCONCAT); + + /* + * Translate the camera back to its original position... + */ + RwFrameTranslate(cameraFrame, &camPos, rwCOMBINEPOSTCONCAT); + + return; +} + + +/* + ***************************************************************************** + */ +void +CameraTilt(RwCamera *camera, const RwV3d *pos, RwReal angle) +{ + RwV3d invCamPos; + RwFrame *cameraFrame; + RwMatrix *cameraMatrix; + RwV3d camPos; + + cameraFrame = RwCameraGetFrame(camera); + cameraMatrix = RwFrameGetMatrix(cameraFrame); + + camPos = (pos) ? *pos : *RwMatrixGetPos(cameraMatrix); + + RwV3dScale(&invCamPos, &camPos, -1.0f); + + /* + * Translate the camera back to the rotation origin... + */ + RwFrameTranslate(cameraFrame, &invCamPos, rwCOMBINEPOSTCONCAT); + + /* + * Get the camera's RIGHT vector and use this as the axis of rotation... + */ + RwMatrixRotate(cameraMatrix, + RwMatrixGetRight(cameraMatrix), angle, rwCOMBINEPOSTCONCAT); + + /* + * Translate the camera back to its original position... + */ + RwFrameTranslate(cameraFrame, &camPos, rwCOMBINEPOSTCONCAT); + + return; +} + + +/* + ***************************************************************************** + */ +void +CameraRotate(RwCamera *camera, const RwV3d *pos, RwReal angle) +{ + RwV3d invCamPos; + RwFrame *cameraFrame; + RwMatrix *cameraMatrix; + RwV3d camPos; + + cameraFrame = RwCameraGetFrame(camera); + cameraMatrix = RwFrameGetMatrix(cameraFrame); + + camPos = (pos) ? *pos : *RwMatrixGetPos(cameraMatrix); + + RwV3dScale(&invCamPos, &camPos, -1.0f); + + /* + * Translate the camera back to the rotation origin... + */ + RwFrameTranslate(cameraFrame, &invCamPos, rwCOMBINEPOSTCONCAT); + + /* + * Get the camera's AT vector and use this as the axis of rotation... + */ + RwMatrixRotate(cameraMatrix, RwMatrixGetAt(cameraMatrix), + angle, rwCOMBINEPOSTCONCAT); + + /* + * Translate the camera back to its original position... + */ + RwFrameTranslate(cameraFrame, &camPos, rwCOMBINEPOSTCONCAT); + + return; +} diff --git a/src/camera.h b/src/camera.h new file mode 100644 index 0000000..787b12d --- /dev/null +++ b/src/camera.h @@ -0,0 +1,60 @@ + +/**************************************************************************** + * + * camera.h + * + * This file is a product of Criterion Software Ltd. + * + * This file is provided as is with no warranties of any kind and is + * provided without any obligation on Criterion Software Ltd. + * or Canon Inc. to assist in its use or modification. + * + * Criterion Software Ltd. and Canon Inc. will not, under any + * circumstances, be liable for any lost revenue or other damages + * arising from the use of this file. + * + * Copyright (c) 1999, 2000 Criterion Software Ltd. + * All Rights Reserved. + * + */ + +#if (!defined(_CAMERA_H)) +#define _CAMERA_H + +#include "rwcore.h" + +#ifdef __cplusplus +extern "C" +{ +#endif /* __cplusplus */ + +extern void +CameraMove(RwCamera *camera, RwV3d *offset); + +extern void +CameraTilt(RwCamera *camera, const RwV3d *pos, RwReal angle); + +extern void +CameraPan(RwCamera *camera, const RwV3d *pos, RwReal angle); + +extern void +CameraRotate(RwCamera *camera, const RwV3d *pos, RwReal angle); + +extern void +CameraSize(RwCamera *camera, RwRect *rect, RwReal viewWindow, RwReal aspectRatio); + +extern void +CameraDestroy(RwCamera *camera); + +extern RwCamera * +CameraCreate(RwInt32 width, RwInt32 height, RwBool zBuffer); + +extern RwRaster * +CameraCreateCrossHair(void); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* (!defined(_CAMERA_H)) */ + diff --git a/src/common.h b/src/common.h new file mode 100644 index 0000000..eab22d9 --- /dev/null +++ b/src/common.h @@ -0,0 +1,11 @@ + +typedef unsigned char uint8; +typedef signed char int8; +typedef unsigned short uint16; +typedef signed short int16; +typedef unsigned int uint32; +typedef signed int int32; +//typedef int32 ssize_t; +//typedef uint32 size_t; + +#define nil NULL diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..44452ab --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,884 @@ +//////////// NB: for non-devkits all these have to be defined!!! +// this disconnects dsedb if run with -r run foo.elf +// but it works if you run from within dsedb +//#define REBOOT_IOP +//#define IOP_CDROM // load IOP modules from CD +#define CDROM // enable CD support + + +#include +#include "rwcore.h" +#include "rpworld.h" + +#ifdef RWMETRICS +#include "metrics.h" +#endif + +#include "rtcharse.h" + +#if (!defined(RWDEBUG)) +#define __RWRELEASEUNUSED__ __RWUNUSED__ +#endif /* (!defined(RWDEBUG)) */ + +#if (!defined(__RWRELEASEUNUSED__)) +#define __RWRELEASEUNUSED__ /* No op */ +#endif /* (!defined(__RWRELEASEUNUSED__)) */ + +#if (!defined(__GNUC__)) +#define __FUNCTION__ "Unknown" +#endif /* (!defined(__GNUC__)) */ + + +// skeleton stuff +#include "camera.h" +#include "skyfs.h" + +// SCE stuff +#include "eeregs.h" +#include "sifdev.h" +#include "sifrpc.h" +#include "libpad.h" +#ifdef CDROM +#include "libcdvd.h" +#endif + + +#include "common.h" +#include "FileMgr.h" +#include "Pad.h" + +#ifdef WIDE_SCREEN +#define DEFAULT_ASPECTRATIO (16.0f/9.0f) +#else +#define DEFAULT_ASPECTRATIO (4.0f/3.0f) +#endif + +#define DEFAULT_VIEWWINDOW (0.5f) + +static RwInt32 FrameCounter = 0; +static RwInt32 FramesPerSecond = 0; + +static RwRGBA ForegroundColor = {200, 200, 200, 255}; +static RwRGBA BackgroundColor = { 64, 64, 64, 0}; + +static RtCharset *Charset = NULL; +static RpLight *AmbientLight = NULL; +static RpLight *MainLight = NULL; + +RpClump *Clump = NULL; +RpWorld *World = NULL; +RwCamera *Camera = NULL; +RwTexDictionary *TexDict = NULL; + + + +void RsTerminate(void); +RwBool RsInitialise(void); +void RsRwTerminate(void); +RwBool RsRwInitialise(void); + +RwUInt32 RsTimer(void); +void RsErrorMessage(const RwChar * message); + +typedef struct RsGlobalType RsGlobalType; +struct RsGlobalType +{ + const RwChar *appName; + RwInt32 maximumWidth; + RwInt32 maximumHeight; + RwInt32 maxFPS; + RwBool quit; + + void *ps; /* platform specific data */ +}; +RsGlobalType RsGlobal; + + + +struct DirEntry +{ + uint32 offset; + uint32 size; + char name[24]; +}; +DirEntry directory[4000]; +uint32 maxFileSize; +uint8 *streamBuffer; + +int cdImageFD; + +void +LoadDirectory(int fd) +{ + DirEntry de; + int i = 0; + while(CFileMgr::Read(fd, (char*)&de, 32) == 32){ +// printf("dir: %08X %08X %s\n", de.offset, de.size, de.name); + directory[i++] = de; + if(de.size > maxFileSize) + maxFileSize = de.size; + } +} +int +FindDirEntry(const char *name) +{ + int i; + for(i = 0; i < 4000; i++){ + if(directory[i].offset == 0 && + directory[i].size == 0) + return -1; + if(strcasecmp(directory[i].name, name) == 0) + return i; + } + return -1; +} + + +static RpWorld * +CreateWorld(void) +{ + RpWorld *world; + RwBBox bBox; + + bBox.sup.x = bBox.sup.y = bBox.sup.z = 100.0f; + bBox.inf.x = bBox.inf.y = bBox.inf.z = -100.0f; + + world = RpWorldCreate(&bBox); + + return world; +} + + +static RpLight * +CreateAmbientLight(RpWorld *world) +{ + RpLight *light; + + light = RpLightCreate(rpLIGHTAMBIENT); + if(light) { + RwRGBAReal color; + + color.red = color.green = color.blue = 0.3f; + color.alpha = 1.0f; + + RpLightSetColor(light, &color); + RpWorldAddLight(world, light); + + return light; + } + + return NULL; +} + + +static RpLight * +CreateMainLight(RpWorld *world) +{ + RpLight *light; + + light = RpLightCreate(rpLIGHTDIRECTIONAL); + if(light) { + RwFrame *frame; + + frame = RwFrameCreate(); + if(frame) { + RwV3d xAxis = {1.0f, 0.0f, 0.0f}; + RwV3d yAxis = {0.0f, 1.0f, 0.0f}; + + RwFrameRotate(frame, &xAxis, 30.0f, rwCOMBINEREPLACE); + RwFrameRotate(frame, &yAxis, 30.0f, rwCOMBINEPOSTCONCAT); + + RpLightSetFrame(light, frame); + + RpWorldAddLight(world, light); + + return light; + } + + RpLightDestroy(light); + } + + return NULL; +} + + +static RwCamera * +CreateCamera(RpWorld *world) +{ + RwCamera *camera; + + camera = CameraCreate(RsGlobal.maximumWidth, RsGlobal.maximumHeight, TRUE); + if(camera) { + RwFrame *frame; + RwV3d pos; + + frame = RwCameraGetFrame(camera); + + pos = *RwMatrixGetAt(RwFrameGetMatrix(frame)); + RwV3dScale(&pos, &pos, -5.0f); + + RwFrameTranslate(frame, &pos, rwCOMBINEREPLACE); + + RwCameraSetFarClipPlane(camera, 250.0f); + RwCameraSetNearClipPlane(camera, 0.5f); + + RpWorldAddCamera(world, camera); + + return camera; + } + + return NULL; +} + +RwStream* +OpenFromDirectory(const char *name) +{ + int slot; + RwMemory mem; + + slot = FindDirEntry(name); + if(slot == -1){ + printf("couldn't find <%s>\n", name); + return NULL; + } + printf("found <%s>: %d %X %X\n", name, slot, directory[slot].offset, directory[slot].size); + CFileMgr::Seek(cdImageFD, directory[slot].offset*2048, 0); + CFileMgr::Read(cdImageFD, (char*)streamBuffer, directory[slot].size*2048); + mem.start = streamBuffer; + mem.length = directory[slot].size*2048; + return RwStreamOpen(rwSTREAMMEMORY, rwSTREAMREAD, &mem); +} + +#define USE_CDIMAGE +#ifdef USE_CDIMAGE +RwStream* +OpenStream(const char *name) +{ + return OpenFromDirectory(name); +} +#else +RwStream* +OpenStream(const char *name) +{ + char path[256]; + sprintf(path, "./models/%s", name); + return RwStreamOpen(rwSTREAMFILENAME, rwSTREAMREAD, path); +} +#endif + +static RpClump * +LoadClump(const RwChar *file) +{ + RpClump *clump = NULL; + RwStream *stream; + + stream = OpenStream(file); + if(stream) { + if(RwStreamFindChunk(stream, rwID_CLUMP, NULL, NULL)) + clump = RpClumpStreamRead(stream); + + RwStreamClose(stream, NULL); + } + + return clump; +} + + +static RpClump * +CreateClump(RpWorld *world) +{ + RpClump *clump; + + clump = LoadClump("player.dff"); + if( clump == NULL ) + return NULL; + + RpWorldAddClump(world, clump); + + return clump; +} + +static RwTexDictionary* +LoadTextureDictionary(const char *file) +{ + RwTexDictionary *texDict = NULL; + RwStream *stream; + + stream = OpenStream(file); + if(stream) { + if(RwStreamFindChunk(stream, rwID_TEXDICTIONARY, NULL, NULL)) + texDict = RwTexDictionaryStreamRead(stream); + + RwStreamClose(stream, NULL); + } + + return texDict; +}; + +static RwBool +Initialise(void) +{ + if(RsInitialise()) { + RsGlobal.appName = "GTA test"; + RsGlobal.maxFPS = 120; + + return TRUE; + } + + return FALSE; +} + + +uint8 buf[24*1024]; + +void +InitDirectory(void) +{ + int fd; + + fd = CFileMgr::OpenFile("cdrom0:\\MODELS\\GTA3.DIR"); + if(fd == 0){ + printf("error opening\n"); + return; + } + LoadDirectory(fd); + CFileMgr::CloseFile(fd); + streamBuffer = (uint8*)RwMalloc(maxFileSize*2048); + + cdImageFD = CFileMgr::OpenFile("cdrom0:\\MODELS\\GTA3.IMG"); + if(cdImageFD == 0){ + printf("error opening\n"); + return; + } +} + +RwBool +Initialise3D(void) +{ + if(!RsRwInitialise()) { + RsErrorMessage("Error initializing RenderWare."); + return FALSE; + } + + InitDirectory(); + + Charset = RtCharsetCreate(&ForegroundColor, &BackgroundColor); + if(Charset == NULL) { + RsErrorMessage("Cannot create raster charset."); + return FALSE; + } + + World = CreateWorld(); + if(World == NULL) { + RsErrorMessage("Cannot create world."); + return FALSE; + } + + AmbientLight = CreateAmbientLight(World); + if(AmbientLight == NULL) { + RsErrorMessage("Cannot create ambient light."); + return FALSE; + } + + MainLight = CreateMainLight(World); + if(MainLight == NULL) { + RsErrorMessage("Cannot create main light."); + return FALSE; + } + + Camera = CreateCamera(World); + if(Camera == NULL) { + RsErrorMessage("Cannot create camera."); + return FALSE; + } + + TexDict = LoadTextureDictionary("player.txd"); + if(TexDict) + RwTexDictionarySetCurrent(TexDict); + + Clump = CreateClump(World); + if(Clump == NULL) { + RsErrorMessage("Cannot create clump."); + return FALSE; + } + +#ifdef RWMETRICS + RsMetricsOpen(Camera); +#endif + + return TRUE; +} + + +static void +Terminate3D(void) +{ +#ifdef RWMETRICS + RsMetricsClose(); +#endif + + if(Clump) { + RpWorldRemoveClump(World, Clump); + RpClumpDestroy(Clump); + } + + if(Camera) { + RpWorldRemoveCamera(World, Camera); + + CameraDestroy(Camera); + } + + if(AmbientLight) { + RpWorldRemoveLight(World, AmbientLight); + + RpLightDestroy(AmbientLight); + } + + if(MainLight) { + RwFrame *frame; + + RpWorldRemoveLight(World, MainLight); + + frame = RpLightGetFrame(MainLight); + RpLightSetFrame(MainLight, NULL); + RwFrameDestroy(frame); + + RpLightDestroy(MainLight); + } + + if(World) + RpWorldDestroy(World); + + if(Charset) + RwRasterDestroy(Charset); + + RsRwTerminate(); +} + + +static RwBool +AttachPlugins(void) +{ + if(!RpWorldPluginAttach()) + return FALSE; + return TRUE; +} + +void +FrameRotate(RwReal xAngle, RwReal yAngle) +{ + RwFrame *frame; + RwV3d *right, *up; + RwV3d pos; + + frame = RpClumpGetFrame(Clump); + + right = RwMatrixGetRight(RwFrameGetMatrix(RwCameraGetFrame(Camera))); + up = RwMatrixGetUp(RwFrameGetMatrix(RwCameraGetFrame(Camera))); + + pos = *RwMatrixGetPos(RwFrameGetMatrix(frame)); + + RwV3dScale(&pos, &pos, -1.0f); + RwFrameTranslate(frame, &pos, rwCOMBINEPOSTCONCAT); + + RwFrameRotate(frame, up, xAngle, rwCOMBINEPOSTCONCAT); + RwFrameRotate(frame, right, yAngle, rwCOMBINEPOSTCONCAT); + + RwV3dScale(&pos, &pos, -1.0f); + RwFrameTranslate(frame, &pos, rwCOMBINEPOSTCONCAT); +} + +static void +Render(void) +{ + RwCameraClear(Camera, &BackgroundColor, rwCAMERACLEARZ|rwCAMERACLEARIMAGE); + + if(RwCameraBeginUpdate(Camera)) { + RpWorldRender(World); + +#ifdef RWMETRICS + RsMetricsRender(); +#endif + + RwCameraEndUpdate(Camera); + } + + RwCameraShowRaster(Camera, NULL, 0); + + FrameCounter++; +} + + +static void +Idle(void) +{ + RwUInt32 thisTime; + + static RwBool firstCall = TRUE; + static RwUInt32 lastFrameTime; + + if(firstCall) { + lastFrameTime = RsTimer(); + firstCall = FALSE; + } + + thisTime = RsTimer(); + + if(thisTime > (lastFrameTime + 1000)) { + FramesPerSecond = FrameCounter; + FrameCounter = 0; + lastFrameTime = thisTime; + } + + + float rotx = (pad1.NewState.DPadRight - pad1.NewState.DPadLeft)/255.0f; + float roty = (pad1.NewState.DPadUp - pad1.NewState.DPadDown)/255.0f; + FrameRotate(rotx*2.0f, roty*2.0f); + + rotx = pad1.NewState.LeftStickX/128.0f; + roty = pad1.NewState.LeftStickY/128.0f; + FrameRotate(rotx*2.0f, roty*2.0f); + + Render(); +} + + + + + +volatile unsigned long sweHighCount; +int skyTimerHandlerHid; + + +static int +TimerHandler(int ca) +{ + if ((ca == INTC_TIM0) && (*T0_MODE & 0x800)) { + *T0_MODE |= 0x800; + + sweHighCount += 0x10000; + } + + ExitHandler(); + + return 0; +} + +void +RsErrorMessage(const RwChar * message __RWRELEASEUNUSED__) +{ + RwDebugSendMessage(rwDEBUGERROR, __FUNCTION__, message); +} + +void +RsWarningMessage(const RwChar * message __RWRELEASEUNUSED__) +{ + RwDebugSendMessage(rwDEBUGMESSAGE, __FUNCTION__, message); +} + +void +psDebugMessageHandler(RwDebugType type, const RwChar * str) +{ + switch (type) { +#if (defined(COLOR)) + case rwDEBUGASSERT: /* red */ + printf("\033[31m%s\033[0m\n", str); + break; + case rwDEBUGERROR: /* bold red */ + printf("\033[31;1m%s\033[0m\n", str); + break; + case rwDEBUGMESSAGE: /* blue */ + printf("\033[34m%s\033[0m\n", str); + break; +#endif + default: + printf("%s\n", str); + } +} + +RwUInt32 +RsTimer(void) +{ + unsigned long high0, low0, high1, low1; + + high0 = sweHighCount; + low0 = *T0_COUNT; + high1 = sweHighCount; + low1 = *T0_COUNT; + + if (high0 == high1) + return ((RwUInt32) ((high0 | (low0 & 0xffff)) / 9216)); + else + return ((RwUInt32) ((high1 | (low1 & 0xffff)) / 9216)); +} + +RwUInt64 +psMicroTimer(void) +{ + unsigned long high0, low0, high1, low1; + + high0 = sweHighCount; + low0 = *T0_COUNT; + high1 = sweHighCount; + low1 = *T0_COUNT; + + if (high0 == high1) + return (((RwUInt64) (high0 | (low0 & 0xffff))) * 1000) / 9216; + else + return (((RwUInt64) (high1 | (low1 & 0xffff))) * 1000) / 9216; +} + + +RwBool +RsSelectDevice(void) +{ + RwVideoMode vmodeInfo; + RwInt32 numVideoModes; + RwInt32 i; + RwVideoMode videoMode; + + numVideoModes = RwEngineGetNumVideoModes() + 1; + + for (i = 1; i < numVideoModes; i++) + if (RwEngineGetVideoModeInfo(&vmodeInfo, (i - 1))) { + if(vmodeInfo.width == 640 && vmodeInfo.height == 512 && + vmodeInfo.depth == 32 && + vmodeInfo.flags == (rwVIDEOMODEEXCLUSIVE|rwVIDEOMODEINTERLACE|rwVIDEOMODEFSAA1)) { + RwEngineSetVideoMode(i-1); + break; + } + } + RwEngineGetVideoModeInfo(&videoMode, RwEngineGetCurrentVideoMode()); + + RsGlobal.maximumWidth = videoMode.width; + RsGlobal.maximumHeight = videoMode.height; + + return TRUE; +} + +void +RsTerminate(void) +{ +} + +RwBool +RsInitialise(void) +{ + RwBool result; + + RsGlobal.appName = "RenderWare Application"; + RsGlobal.maximumWidth = 0; + RsGlobal.maximumHeight = 0; + RsGlobal.maxFPS = 0; + RsGlobal.quit = FALSE; + + return TRUE; +} + +// this is where the magic happens +char* +GetModulePath(const char *module) +{ + char tmp[64]; + static char path[256]; + char *s; + + strcpy(tmp, module); +#ifdef IOP_CDROM + strcpy(path, "cdrom0:\\SYSTEM\\"); +#else +#define TOSTRING__(arg) #arg +#define TOSTRING(arg) TOSTRING__(arg) + for(s = tmp; *s; s++) + if(isupper(*s)) *s = tolower(*s); + sprintf(path, "host0:%s/modules/", TOSTRING(IOPPATH)); +#endif + strcat(path, tmp); + return path; +} + +void +LoadModule(const char *module) +{ + static char noargs[] = ""; + char *path; + path = GetModulePath(module); + printf("Loading %s\n", path); + while(sceSifLoadModule(path, 0, noargs) < 0) + printf("Can't Load Module %s\n", path); +} + +void +TheGame(void) +{ + while (!RsGlobal.quit) { + static RwUInt32 lastpoll = 0; + RwUInt32 polltime; + + polltime = RsTimer(); + if (polltime - lastpoll > 15) { + UpdatePad(&pad1, 0); + + lastpoll = polltime; + } + + Idle(); + } +} + +void +SystemInit(void) +{ + /* by default don't look in subdirs for assets */ + skyTimerHandlerHid = -1; + + sceSifInitRpc(0); + sceSifInitIopHeap(); + +#ifdef CDROM + CFileMgr::InitCdSystem(); +#endif + +#ifdef REBOOT_IOP + printf("rebooting IOP\n"); + while(!sceSifRebootIop(GetModulePath(IOP_IMAGE_FILE))) + continue; + + while(!sceSifSyncIop()) + continue; + + sceSifInitRpc(0); + +#ifdef CDROM + CFileMgr::InitCdSystem(); +#endif + sceFsReset(); +#endif + + LoadModule("SIO2MAN.IRX"); + LoadModule("PADMAN.IRX"); + + skyTimerHandlerHid = AddIntcHandler(INTC_TIM0, TimerHandler, 0); + /* Set up time0 */ + sweHighCount = 0; + *T0_COUNT = 0; + *T0_COMP = 0; + *T0_HOLD = 0; + *T0_MODE = 0x281; + EnableIntc(INTC_TIM0); +} + +void +GameInit(void) +{ + RwRect r; + + Initialise3D(); + + r.x = 0; + r.y = 0; + r.w = RsGlobal.maximumWidth; + r.h = RsGlobal.maximumHeight; + CameraSize(Camera, &r, DEFAULT_VIEWWINDOW, DEFAULT_ASPECTRATIO); +} + +int +main(int argc, char *argv[]) +{ + SystemInit(); + + Initialise(); // not in GTA + + PadInit(); + + GameInit(); + + TheGame(); + + Terminate3D(); + RsTerminate(); + + DisableIntc(INTC_TIM0); + RemoveIntcHandler(INTC_TIM0, skyTimerHandlerHid); + + return 0; +} + + +#ifdef RWDEBUG +static RwBool +RsSetDebug(void) +{ + RwDebugSetHandler(psDebugMessageHandler); + + RwDebugSendMessage(rwDEBUGMESSAGE, RsGlobal.appName, + "Debugging Initialized"); + + return TRUE; +} +#endif + +static RwTexDictionary * +texDictDestroyCB(RwTexDictionary *dict, void *data __RWUNUSED__) +{ + RwTexDictionaryDestroy(dict); + return dict; +} + +void +RsRwTerminate(void) +{ + RtCharsetClose(); + + RwTexDictionaryForAllTexDictionaries(texDictDestroyCB, NULL); + + RwEngineStop(); + RwEngineClose(); + RwEngineTerm(); + + return; +} + +RwBool +RsRwInitialise(void) +{ + RwEngineOpenParams openParams; + + if (!RwEngineInit(NULL, 0)) + return (FALSE); + + SkyInstallFileSystem(); + +#ifdef RWDEBUG + RsSetDebug(); +#endif + + if(!AttachPlugins()) { + printf("Couldn't load the plugins for some reason\n"); + for(;;); + } + + openParams.displayID = NULL; + if (!RwEngineOpen(&openParams)) { + RwEngineTerm(); + return (FALSE); + } + + RsSelectDevice(); + + if (!RwEngineStart()) { + RwEngineClose(); + RwEngineTerm(); + return (FALSE); + } + + if (!RtCharsetOpen()) { + RwEngineStop(); + RwEngineClose(); + RwEngineTerm(); + return (FALSE); + } + + return TRUE; +} + diff --git a/src/skyfs.c b/src/skyfs.c new file mode 100644 index 0000000..802eb43 --- /dev/null +++ b/src/skyfs.c @@ -0,0 +1,738 @@ + +/**************************************************************************** + * + * skyfs.c + * + * This file is a product of Criterion Software Ltd. + * + * This file is provided as is with no warranties of any kind and is + * provided without any obligation on Criterion Software Ltd. + * or Canon Inc. to assist in its use or modification. + * + * Criterion Software Ltd. and Canon Inc. will not, under any + * circumstances, be liable for any lost revenue or other damages + * arising from the use of this file. + * + * Copyright (c) 1999, 2000 Criterion Software Ltd. + * All Rights Reserved. + * + */ + +#include "stdio.h" +#include "string.h" +#include "assert.h" + +/*#include "unistd.h"*/ +#include "sifdev.h" + +#include "rwcore.h" +#include "skyfs.h" + +/* Because CDROM is used in sky.c + * it's better to define this for a project and not here. + */ + +/* Use this define to get DEBUGSTATION behavior */ +/*#define DEBUGSTATION*/ +/* Use this define to get CDROM behavior */ +//#define CDROM + +#define READBUFFERSIZE 10240 + +#define RWGDFSGLOBAL(var) \ + (RWPLUGINOFFSET(gdfsGlobals, \ + RwEngineInstance, \ + gdfsModuleInfo.globalsOffset)->var) + +#define rwID_SKYDEVICEMODULE (MAKECHUNKID(rwVENDORID_CRITERIONINT, 0x30)) + +typedef struct skyFile skyFile; +struct skyFile +{ + int gdfs; + RwInt32 POS; + RwInt32 SOF; + RwUInt8 readBuffer[READBUFFERSIZE]; + RwUInt32 bufferPos; + RwBool bufferValid; +}; + +typedef struct gdfsGlobals gdfsGlobals; +struct gdfsGlobals +{ + RwFileFunctions oldFS; /* Old Filing system vectors */ + RwFreeList *fpFreeList; /* File pointer free list */ +}; + +/* These are all global to all RenderWare instances */ + +RwInt32 gdfsOpenFiles; +RwModuleInfo gdfsModuleInfo; + +#ifdef DEBUGSTATION +extern char debugStationFilePrefix[32]; +#endif + +/**************************************************************************** + skyTransMode + + Attempt to convert a mode string to an open mode + + On entry : access mode + On exit : integer mode + */ +static int +skyTransMode(const RwChar * access) +{ + int mode; + char *r; + char *w; + char *a; + char *plus; + char *n; + char *d; + + /* I add a couple of new characters for now: + * n non-blocking mode + * d no write back d cache */ + + r = strrchr(access, (int) 'r'); + w = strrchr(access, (int) 'w'); + a = strrchr(access, (int) 'a'); + plus = strrchr(access, (int) '+'); + n = strrchr(access, (int) 'n'); + d = strrchr(access, (int) 'd'); + + if (plus) + mode = SCE_RDWR; + else if (r) + mode = SCE_RDONLY; + else if (w) + mode = SCE_WRONLY; + else if (a) + mode = SCE_WRONLY; + else + return (0); + + /* later we will test for SCE_CREAT & !SCE_TRUNC as a seek to end of file */ + if (w) + mode |= SCE_CREAT | SCE_TRUNC; + + if (a) + mode |= SCE_CREAT; + + if (n) + mode |= SCE_NOWAIT; + + if (d) + mode |= SCE_NOWBDC; + + return (mode); +} + +/**************************************************************************** + trySkyFopen + + One attempt at opening a file + + On entry : Filename, access mode + On exit : + */ + +static void * +trySkyFopen(const RwChar * fname, const RwChar * access) +{ + skyFile *fp; + int mode; + RwChar name[256]; + RwChar *nameptr; + int cdrom = 0; + + /* First manipulate the filename into a Sky friendly name */ + if (strchr(fname, ':')) + { + strncpy(name, fname, 255); + if(strncmp(name, "cdrom", 5) == 0) + cdrom = 1; + } + else + { +#if (defined(CDROM)) + sprintf(name, "cdrom0:\\%s", fname); + cdrom = 1; + + /* append a ;1 to the end if required */ + name[253] = 0; + /* we assume that any ';' indicates a version appended */ + if (!strrchr(name, ';')) + { + strcat(name, ";1"); + } + strupr(&name[7]); +#elif (defined(DEBUGSTATION)) + strcpy(name, debugStationFilePrefix); + strcat((RwChar *)name, fname); +#else + strcpy(name, "host:"); + strcat((RwChar *)name, fname); + +#endif /* CDROM */ + } + /* force null termination */ + name[255] = 0; + + nameptr = name; + while (*nameptr) + { + if(cdrom){ + if (*nameptr == '/') + *nameptr = '\\'; + }else{ + if (*nameptr == '\\') + *nameptr = '/'; + } + nameptr++; + } + + /* Allocate structure for holding info */ + fp = (skyFile *) RwFreeListAlloc(RWGDFSGLOBAL(fpFreeList)); + if (!fp) + { + return (NULL); + } + + mode = skyTransMode(access); + if (!mode) + { + return (NULL); + } + + fp->gdfs = sceOpen(name, mode); +printf("open <%s> -> %d\n", name, fp->gdfs); + + if (fp->gdfs < 0) + { + RwFreeListFree(RWGDFSGLOBAL(fpFreeList), fp); + return (NULL); + } + + /* We seek to the end of the file to get size */ + fp->SOF = fp->POS = sceLseek(fp->gdfs, 0, SCE_SEEK_END); + if (fp->SOF < 0) + { + sceClose(fp->gdfs); + RwFreeListFree(RWGDFSGLOBAL(fpFreeList), fp); + return (NULL); + } + /* SCE_CREAT & !SCE_TRUNC mean seek to end of file */ + if (!((mode & SCE_CREAT) && !(mode & SCE_TRUNC))) + { + fp->POS = sceLseek(fp->gdfs, 0, SCE_SEEK_SET); + + if (fp->POS < 0) + { + sceClose(fp->gdfs); + RwFreeListFree(RWGDFSGLOBAL(fpFreeList), fp); + return (NULL); + } + } + + /* Initialise the buffer to show nothing buffered */ + fp->bufferPos = READBUFFERSIZE; + + gdfsOpenFiles++; + + return ((void *) fp); +} + +/**************************************************************************** + skyFopen + + On entry : Filename, access mode + On exit : + */ + +static void * +skyFopen(const RwChar * name, const RwChar * access) +{ + void *res; + + res = trySkyFopen(name, access); + + if (res) + { + return (res); + } + + return (NULL); +} + +/**************************************************************************** + skyFclose + + On entry : FILE * (data block specific to this implementation) + On exit : 0 on success + */ + +static int +skyFclose(void *fptr) +{ + skyFile *fp = (skyFile *) fptr; + + assert(fptr); + + if (fp && gdfsOpenFiles) + { + sceClose(fp->gdfs); + + RwFreeListFree(RWGDFSGLOBAL(fpFreeList), fp); + + --gdfsOpenFiles; + + return (0); + } + + return (-1); +} + +/**************************************************************************** + skyFexist + + On entry : Filename + On exit : + */ + +static RwBool +skyFexist(const RwChar * name) +{ + void *res; + + res = RwOsGetFileInterface()->rwfopen(name, "r"); + if (res) + { + RwOsGetFileInterface()->rwfclose(res); + return (TRUE); + } + + return (FALSE); +} + +/**************************************************************************** + skyFread + + On entry : Address to read to, block size, block count, file to read from + On exit : Number of bytes read + */ + +static size_t +skyFread(void *addr, size_t size, size_t count, void *fptr) +{ + skyFile *fp = (skyFile *) fptr; + size_t numBytesToRead = size * count; + int bytesRead, bytesRead2; + + bytesRead = 0; + + /* Trim number of bytes for the size of the file */ + if ((fp->POS + (RwInt32) numBytesToRead) > fp->SOF) + { + numBytesToRead = fp->SOF - fp->POS; + } + + /* First try and use the buffer */ + if ((fp->bufferPos < READBUFFERSIZE) && + (bytesRead < (RwInt32) numBytesToRead)) + { + /* Pull from the buffer */ + if (numBytesToRead < (READBUFFERSIZE - fp->bufferPos)) + { + /* Can satisfy entirely from buffer */ + bytesRead = numBytesToRead; + } + else + { + /* Pull as much as possible from the buffer */ + bytesRead = READBUFFERSIZE - fp->bufferPos; + } + + /* Copy it */ + memcpy(addr, &fp->readBuffer[fp->bufferPos], bytesRead); + + /* Update target address and source address */ + addr = (void *) ((RwUInt8 *) addr + bytesRead); + fp->bufferPos += bytesRead; + fp->POS += bytesRead; + } + + /* If next bit is bigger than a buffer, read it directly and ignore the + * buffer. + */ + if ((numBytesToRead - bytesRead) > 0) + { + if ((numBytesToRead - bytesRead) >= READBUFFERSIZE) + { + bytesRead2 = (numBytesToRead - bytesRead); + bytesRead2 = sceRead(fp->gdfs, addr, bytesRead2); + if (bytesRead2 < 0) + { + bytesRead2 = 0; + } + } + else + { + /* Go via the buffer */ + sceRead(fp->gdfs, fp->readBuffer, READBUFFERSIZE); + bytesRead2 = (numBytesToRead - bytesRead); + memcpy(addr, fp->readBuffer, bytesRead2); + fp->bufferPos = bytesRead2; + } + fp->POS += bytesRead2; + bytesRead += bytesRead2; + } + + return (bytesRead / size); +} + +/**************************************************************************** + skyFwrite + + On entry : Address to write from, block size, block count, file to write to + On exit : Number of bytes written + */ + +static size_t +skyFwrite(const void *addr, size_t size, size_t count, void *fptr) +{ + int bytesWritten; + skyFile *fp = (skyFile *) fptr; + RwInt32 numBytesToWrite = size * count; + + assert(addr); + assert(fptr); + + bytesWritten = sceWrite(fp->gdfs, (void *)addr, numBytesToWrite); + + if (-1 != bytesWritten) + { + fp->POS += bytesWritten; + if (fp->POS > fp->SOF) + fp->SOF = fp->POS; + return (size > 0 ? bytesWritten / size : 0); + } + return (0); +} + +/**************************************************************************** + skyFseek + + On entry : file to seek in, offset, how to seek + On exit : 0 on success + */ + +static int +skyFseek(void *fptr, long offset, int origin) +{ + skyFile *fp = (skyFile *) fptr; + RwInt32 oldFPos, bufStart; + RwBool noBuffer = FALSE; + + assert(fptr); + + oldFPos = fp->POS; + bufStart = oldFPos - fp->bufferPos; + if (fp->bufferPos == READBUFFERSIZE) + noBuffer = TRUE; + fp->bufferPos = READBUFFERSIZE; + + switch (origin) + { + case SEEK_CUR: + { + /* Does the seek stay in the buffer */ + if (((oldFPos + offset >= bufStart) && + (oldFPos + offset < bufStart + READBUFFERSIZE)) && + (!noBuffer)) + { + fp->bufferPos = (oldFPos + offset) - bufStart; + fp->POS += offset; + } + else + { + fp->POS = + sceLseek(fp->gdfs, oldFPos + offset, + SCE_SEEK_SET); + } + break; + } + case SEEK_END: + { + fp->POS = sceLseek(fp->gdfs, offset, SCE_SEEK_END); + break; + } + case SEEK_SET: + { + fp->POS = sceLseek(fp->gdfs, offset, SCE_SEEK_SET); + break; + } + default: + { + return (-1); + } + } + + if (noBuffer) + fp->bufferPos = READBUFFERSIZE; + + if (fp->POS == -1) + { + /* This may not be valid */ + fp->POS = oldFPos; + fp->bufferPos = READBUFFERSIZE; + return (-1); + } + + return (0); +} + +/**************************************************************************** + skyFtell + + On entry : file to tell offset in + On exit : current offset in file + */ + +static int +skyFtell(void *fptr) +{ + skyFile *fp = (skyFile *) fptr; + + assert(fptr); + + return sceLseek(fp->gdfs, 0, SCE_SEEK_CUR); +} + +/**************************************************************************** + skyFgets + + On entry : Buffer to read into, max chars to read, file to read from + On exit : Returns pointer to string on success + */ + +static RwChar * +skyFgets(RwChar * buffer, int maxLen, void *fptr) +{ + skyFile *fp = (skyFile *) fptr; + RwInt32 i; + RwInt32 numBytesRead; + + assert(buffer); + assert(fptr); + + i = 0; + + numBytesRead = skyFread(buffer, 1, maxLen - 1, fp); + + if (numBytesRead == 0) + { + return (0); + } + + while (i < numBytesRead) + { + if (buffer[i] == '\n') + { + i++; + + buffer[i] = '\0'; + + /* the file pointer needs */ + /* to be reset as skyFread */ + /* will have overshot the */ + /* first new line */ + + i -= numBytesRead; + skyFseek(fp, i, SEEK_CUR); + + return (buffer); + } + else if (buffer[i] == 0x0D) + { + if ((i < (numBytesRead - 1)) && (buffer[i + 1] == '\n')) + { + memcpy(&buffer[i], &buffer[i + 1], + (numBytesRead - i - 1)); + numBytesRead--; + } + else + i++; + } + else + i++; + } + + /* + * Don't return NULL because we could have read maxLen bytes + * without finding a \n + */ + return (buffer); +} + +/**************************************************************************** + skyFputs + + On entry : Buffer to write from, file to write to + On exit : Non negative value on success + */ + +static int +skyFputs(const RwChar * buffer, void *fptr) +{ + skyFile *fp = (skyFile *) fptr; + int i, j; + + assert(buffer); + assert(fptr); + + i = strlen(buffer); + j = sceWrite(fp->gdfs, (void *) buffer, i); + + if (j != -1) + { + fp->POS += j; + if (fp->POS > fp->SOF) + fp->SOF = fp->POS; + } + if ((j == -1) || (i != j)) + { + return (EOF); + } + return (j); +} + +/**************************************************************************** + skyFeof + + On entry : File to test for end of + On exit : Non zero if end of file reached + */ + +static int +skyFeof(void *fptr) +{ + skyFile *fp = (skyFile *) fptr; + + assert(fptr); + + return (fp->POS >= fp->SOF); +} + +/**************************************************************************** + skyFflush + + On entry : + On exit : + */ + +static int +skyFflush(void *fptr __RWUNUSED__) +{ + return (0); +} + +/**************************************************************************** + _rwSkyFSOpen + + On entry : Instance, offset, size + On exit : instance pointer on success + */ + +static void * +_rwSkyFSOpen(void *instance, RwInt32 offset, RwInt32 size __RWUNUSED__) +{ + RwFileFunctions *FS; + + /* Cache the globals offset */ + gdfsModuleInfo.globalsOffset = offset; + + /* Create a free list for file handle structures */ + RWGDFSGLOBAL(fpFreeList) = RwFreeListCreate(sizeof(skyFile), 5, 0); + if (!RWGDFSGLOBAL(fpFreeList)) + { + return (NULL); + } + + /* This is per instance of RenderWare */ + FS = RwOsGetFileInterface(); + + /* save away the old filing system */ + RWGDFSGLOBAL(oldFS) = *FS; + + /* attach the new filing system */ + FS->rwfexist = skyFexist; /* FS->rwfexist; */ + FS->rwfopen = skyFopen; + FS->rwfclose = skyFclose; + FS->rwfread = skyFread; + FS->rwfwrite = skyFwrite; + FS->rwfgets = skyFgets; + FS->rwfputs = skyFputs; + FS->rwfeof = skyFeof; + FS->rwfseek = skyFseek; + FS->rwfflush = skyFflush; + FS->rwftell = skyFtell; + + gdfsModuleInfo.numInstances++; + + return (instance); +} + +/**************************************************************************** + _rwSkyFSClose + + On entry : instance, offset, size + On exit : instance pointer on success + */ + +static void * +_rwSkyFSClose(void *instance, RwInt32 offset __RWUNUSED__, + RwInt32 size __RWUNUSED__) +{ + RwFileFunctions *FS; + + FS = RwOsGetFileInterface(); + + /* re-attach the old filing system - not strictly necessary, + * but we are feeling kind today! */ + *FS = RWGDFSGLOBAL(oldFS); + + /* Blow away our free list */ + RwFreeListDestroy(RWGDFSGLOBAL(fpFreeList)); + + gdfsModuleInfo.numInstances--; + + return (instance); +} + +/**************************************************************************** + RwSkyInstallFileSystem + + On entry : + On exit : TRUE on success + */ + +RwBool +SkyInstallFileSystem(void) +{ + +// gdfsOpenFiles = 0; + + if (RwEngineRegisterPlugin + (sizeof(gdfsGlobals), rwID_SKYDEVICEMODULE, _rwSkyFSOpen, + _rwSkyFSClose) < 0) + { + /* If it is negative, we've failed */ + return (FALSE); + } + + /* Hurrah */ + return (TRUE); +} diff --git a/src/skyfs.h b/src/skyfs.h new file mode 100644 index 0000000..f5a20ab --- /dev/null +++ b/src/skyfs.h @@ -0,0 +1,38 @@ + +/**************************************************************************** + * + * skyfs.h + * + * This file is a product of Criterion Software Ltd. + * + * This file is provided as is with no warranties of any kind and is + * provided without any obligation on Criterion Software Ltd. + * or Canon Inc. to assist in its use or modification. + * + * Criterion Software Ltd. and Canon Inc. will not, under any + * circumstances, be liable for any lost revenue or other damages + * arising from the use of this file. + * + * Copyright (c) 1999, 2000 Criterion Software Ltd. + * All Rights Reserved. + * + */ + +#if (!defined(SKYFS_H)) +#define SKYFS_H + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif /* __cplusplus */ + +RwBool SkyInstallFileSystem(void); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + + +#endif /* (!defined(SKYFS_H)) */