Skip to content

Commit

Permalink
Initial commit for D2X Switch
Browse files Browse the repository at this point in the history
  • Loading branch information
aagallag committed Aug 5, 2018
1 parent 3f8c630 commit 24e3028
Show file tree
Hide file tree
Showing 22 changed files with 356 additions and 162 deletions.
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
all: physfs d1
all: physfs d1 d2

physfs:
@$(MAKE) -C physfs

d1:
@$(MAKE) -C d1

d2:
@$(MAKE) -C d1

clean:
@$(MAKE) -C physfs clean
@$(MAKE) -C d1 clean

.PHONY: physfs d1
.PHONY: physfs d1 d2
2 changes: 0 additions & 2 deletions d2/2d/font.c
Original file line number Diff line number Diff line change
Expand Up @@ -1167,13 +1167,11 @@ void gr_remap_font( grs_font *font, char * fontname, char *font_data )
int freq[256];

PHYSFS_read(fontfile,palette,3,256); //read the palette

build_colormap_good( (ubyte *)&palette, colormap, freq );

colormap[TRANSPARENCY_COLOR] = TRANSPARENCY_COLOR; // changed from colormap[255] = 255 to this for macintosh

decode_data(font->ft_data, ptr - font->ft_data, colormap, freq );

}

PHYSFS_close(fontfile);
Expand Down
208 changes: 208 additions & 0 deletions d2/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------

ifeq ($(strip $(DEVKITPRO)),)
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro")
endif

TOPDIR ?= $(CURDIR)
include $(DEVKITPRO)/libnx/switch_rules

#---------------------------------------------------------------------------------
# TARGET is the name of the output
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# DATA is a list of directories containing data files
# INCLUDES is a list of directories containing header files
# EXEFS_SRC is the optional input directory containing data copied into exefs, if anything this normally should only contain "main.npdm".
# ROMFS is the directory containing data to be added to RomFS, relative to the Makefile (Optional)
#
# NO_ICON: if set to anything, do not use icon.
# NO_NACP: if set to anything, no .nacp file is generated.
# APP_TITLE is the name of the app stored in the .nacp file (Optional)
# APP_AUTHOR is the author of the app stored in the .nacp file (Optional)
# APP_VERSION is the version of the app stored in the .nacp file (Optional)
# APP_TITLEID is the titleID of the app stored in the .nacp file (Optional)
# ICON is the filename of the icon (.jpg), relative to the project folder.
# If not set, it attempts to use one of the following (in this order):
# - <Project name>.jpg
# - icon.jpg
# - <libnx folder>/default_icon.jpg
#---------------------------------------------------------------------------------
TARGET := d2x-switch
BUILD := build
SOURCES := arch 2d 3d maths texmap misc mem arch/sdl iff libmve main
DATA := data
INCLUDES := include arch/include main arch/sdl
EXEFS_SRC := exefs_src
APP_TITLE := D2X Switch
APP_AUTHOR := aagallag
VER_MAJOR := 0
VER_MINOR := 58
VER_MICRO := 3
APP_VERSION := $(VER_MAJOR).$(VER_MINOR).$(VER_MICRO)

#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE

CFLAGS := -g -Wall -O2 -ffunction-sections \
$(ARCH) $(DEFINES)

CFLAGS += $(INCLUDE) -D__SWITCH__ -DNDEBUG -DRELEASE -DNO_ASM -DUSE_SDLMIXER \
-DDXX_VERSION_MAJORi=$(VER_MAJOR) -DDXX_VERSION_MINORi=$(VER_MINOR) -DDXX_VERSION_MICROi=$(VER_MICRO) \
-DMAXIMUM_FPS=60 -DHAVE_STRUCT_TIMEVAL -DHAVE_STRUCT_TIMESPEC \
-Wno-deprecated-declarations

CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11

ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)

LIBS := -lSDL_mixer -lSDL -lnx -lphysfs -lm

#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(PORTLIBS) $(LIBNX) $(CURDIR)/../physfs


#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------

export REL_FNAME:= $(TARGET)_v$(VER_MAJOR).$(VER_MINOR).$(VER_MICRO).zip
export OUTPUT := $(CURDIR)/$(TARGET)
export TOPDIR := $(CURDIR)

export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
$(foreach dir,$(DATA),$(CURDIR)/$(dir))

export DEPSDIR := $(CURDIR)/$(BUILD)

CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))

#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
export LD := $(CC)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
export LD := $(CXX)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------

export OFILES_BIN := $(addsuffix .o,$(BINFILES))
export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export OFILES := $(OFILES_BIN) $(OFILES_SRC)
export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES)))

export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I$(CURDIR)/$(BUILD)

export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)

export BUILD_EXEFS_SRC := $(TOPDIR)/$(EXEFS_SRC)

ifeq ($(strip $(ICON)),)
icons := $(wildcard *.jpg)
ifneq (,$(findstring $(TARGET).jpg,$(icons)))
export APP_ICON := $(TOPDIR)/$(TARGET).jpg
else
ifneq (,$(findstring icon.jpg,$(icons)))
export APP_ICON := $(TOPDIR)/icon.jpg
endif
endif
else
export APP_ICON := $(TOPDIR)/$(ICON)
endif

ifeq ($(strip $(NO_ICON)),)
export NROFLAGS += --icon=$(APP_ICON)
endif

ifeq ($(strip $(NO_NACP)),)
export NROFLAGS += --nacp=$(CURDIR)/$(TARGET).nacp
endif

ifneq ($(APP_TITLEID),)
export NACPFLAGS += --titleid=$(APP_TITLEID)
endif

ifneq ($(ROMFS),)
export NROFLAGS += --romfsdir=$(CURDIR)/$(ROMFS)
endif

.PHONY: $(BUILD) clean all

#---------------------------------------------------------------------------------
all: $(BUILD)

$(BUILD):
@[ -d $@ ] || mkdir -p $@
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile

dist-bin: all
@mkdir -p releases/
@rm -f releases/$(REL_FNAME)
@zip releases/$(REL_FNAME) $(TARGET).nro descent.cfg
@echo Dist location: releases/$(REL_FNAME)

#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr $(BUILD) $(TARGET).pfs0 $(TARGET).nso $(TARGET).nro $(TARGET).nacp $(TARGET).elf


#---------------------------------------------------------------------------------
else
.PHONY: all

DEPENDS := $(OFILES:.o=.d)

#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
all : $(OUTPUT).pfs0 $(OUTPUT).nro

$(OUTPUT).pfs0 : $(OUTPUT).nso

$(OUTPUT).nso : $(OUTPUT).elf

ifeq ($(strip $(NO_NACP)),)
$(OUTPUT).nro : $(OUTPUT).elf $(OUTPUT).nacp
else
$(OUTPUT).nro : $(OUTPUT).elf
endif

$(OUTPUT).elf : $(OFILES)

$(OFILES_SRC) : $(HFILES_BIN)

#---------------------------------------------------------------------------------
# you need a rule like this for each extension you use as binary data
#---------------------------------------------------------------------------------
%.bin.o %_bin.h : %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)

-include $(DEPENDS)

#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------
8 changes: 4 additions & 4 deletions d2/SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ class DXXCommon:
self.debug = int(ARGUMENTS.get('debug', 0))
self.DESTDIR = ARGUMENTS.get('DESTDIR')
self.profiler = int(ARGUMENTS.get('profiler', 0))
self.opengl = int(ARGUMENTS.get('opengl', 1))
self.opengl = int(ARGUMENTS.get('opengl', 0))
self.asm = int(ARGUMENTS.get('asm', 0))
self.editor = int(ARGUMENTS.get('editor', 0))
self.extra_version = ARGUMENTS.get('extra_version', None)
self.sdlmixer = int(ARGUMENTS.get('sdlmixer', 1))
self.register_install_target = int(ARGUMENTS.get('register_install_target', 1))
self.ipv6 = int(ARGUMENTS.get('ipv6', 0))
self.program_name = ARGUMENTS.get('program_name')
self.use_udp = int(ARGUMENTS.get('use_udp', 1))
self.use_tracker = int(ARGUMENTS.get('use_tracker', 1))
self.use_udp = int(ARGUMENTS.get('use_udp', 0))
self.use_tracker = int(ARGUMENTS.get('use_tracker', 0))
self.verbosebuild = int(ARGUMENTS.get('verbosebuild', 0))
self.raspberrypi = int(ARGUMENTS.get('raspberrypi', 0))
self.rpi_vc_path = str(ARGUMENTS.get('rpi_vc_path', self.RPI_DEFAULT_VC_PATH))
Expand Down Expand Up @@ -153,7 +153,7 @@ class DXXCommon:

self.env.Append(CCFLAGS = ['-Wall', '-funsigned-char', '-Werror=implicit-int', '-Werror=implicit-function-declaration', '-pthread'])
self.env.Append(CFLAGS = ['-std=gnu99'])
self.env.Append(CPPDEFINES = ['NETWORK'])
#self.env.Append(CPPDEFINES = ['NETWORK'])
# Get traditional compiler environment variables
for cc in ['CC', 'CXX']:
if os.environ.has_key(cc):
Expand Down
1 change: 1 addition & 0 deletions d2/arch/sdl/digi_mixer_music.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ int mix_play_file(char *filename, int loop, void (*hook_finished_track)())
{
con_printf(CON_CRITICAL,"Music %s could not be loaded: %s\n", filename, Mix_GetError());
mix_stop_music();
printf("Music stopped....\n");
}

return 0;
Expand Down
9 changes: 4 additions & 5 deletions d2/arch/sdl/gr.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,14 @@ int gr_set_mode(u_int32_t mode)
{
unsigned int w, h;

if (mode<=0)
return 0;

w=SM_W(mode);
h=SM_H(mode);
w = 1280;
h = 720;
screen=NULL;

#ifndef __SWITCH__
SDL_WM_SetCaption(DESCENT_VERSION, "Descent II");
SDL_WM_SetIcon( SDL_LoadBMP( "d2x-rebirth.bmp" ), NULL );
#endif

if(SDL_VideoModeOK(w,h,GameArg.DbgBpp,sdl_video_flags))
{
Expand Down
8 changes: 4 additions & 4 deletions d2/include/physfsrwops.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ extern "C" {
* @return A valid SDL_RWops structure on success, NULL on error. Specifics
* of the error can be gleaned from PHYSFS_getLastError().
*/
__EXPORT__ SDL_RWops *PHYSFSRWOPS_openRead(const char *fname);
SDL_RWops *PHYSFSRWOPS_openRead(const char *fname);

/**
* Open a platform-independent filename for writing, and make it accessible
Expand All @@ -56,7 +56,7 @@ __EXPORT__ SDL_RWops *PHYSFSRWOPS_openRead(const char *fname);
* @return A valid SDL_RWops structure on success, NULL on error. Specifics
* of the error can be gleaned from PHYSFS_getLastError().
*/
__EXPORT__ SDL_RWops *PHYSFSRWOPS_openWrite(const char *fname);
SDL_RWops *PHYSFSRWOPS_openWrite(const char *fname);

/**
* Open a platform-independent filename for appending, and make it accessible
Expand All @@ -68,7 +68,7 @@ __EXPORT__ SDL_RWops *PHYSFSRWOPS_openWrite(const char *fname);
* @return A valid SDL_RWops structure on success, NULL on error. Specifics
* of the error can be gleaned from PHYSFS_getLastError().
*/
__EXPORT__ SDL_RWops *PHYSFSRWOPS_openAppend(const char *fname);
SDL_RWops *PHYSFSRWOPS_openAppend(const char *fname);

/**
* Make a SDL_RWops from an existing PhysicsFS file handle. You should
Expand All @@ -80,7 +80,7 @@ __EXPORT__ SDL_RWops *PHYSFSRWOPS_openAppend(const char *fname);
* @return A valid SDL_RWops structure on success, NULL on error. Specifics
* of the error can be gleaned from PHYSFS_getLastError().
*/
__EXPORT__ SDL_RWops *PHYSFSRWOPS_makeRWops(PHYSFS_file *handle);
SDL_RWops *PHYSFSRWOPS_makeRWops(PHYSFS_file *handle);

#ifdef __cplusplus
}
Expand Down
2 changes: 1 addition & 1 deletion d2/include/pstypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ typedef ubyte bool;
defined(__arm__) || defined(ARM) || \
(defined(__mips__) && defined(__MIPSEL__)) || \
defined(__SYMBIAN32__) || \
defined(__x86_64__) || \
defined(__x86_64__) || defined(__SWITCH__) || \
defined(__LITTLE_ENDIAN__) // from physfs_internal.h
//# define WORDS_BIGENDIAN 0
#else
Expand Down
4 changes: 4 additions & 0 deletions d2/libmve/mve_main.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@

// Don't compile this file on switch
#ifndef __SWITCH__

#include <stdlib.h>
#include <string.h>
#include <assert.h>
Expand Down Expand Up @@ -182,3 +185,4 @@ static int doPlay(const char *filename)

return 0;
}
#endif // __SWITCH__
3 changes: 3 additions & 0 deletions d2/main/bmread.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
*
*/

#ifdef EDITOR

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
Expand Down Expand Up @@ -2244,3 +2246,4 @@ void bm_write_extra_robots()

PHYSFS_close(fp);
}
#endif // EDITOR
1 change: 1 addition & 0 deletions d2/main/cntrlcen.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
#include "state.h"
#include "byteswap.h"
#include "args.h"
#include "multi.h"

//@@vms_vector controlcen_gun_points[MAX_CONTROLCEN_GUNS];
//@@vms_vector controlcen_gun_dirs[MAX_CONTROLCEN_GUNS];
Expand Down
4 changes: 4 additions & 0 deletions d2/main/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ void con_printf(int priority, const char *fmt, ...)

memset(buffer,'\0',CON_LINE_LENGTH);

#ifdef __SWITCH_DBG__
if (1)
#else
if (priority <= ((int)GameArg.DbgVerbose))
#endif
{
char *p1, *p2;

Expand Down
Loading

0 comments on commit 24e3028

Please sign in to comment.