Browse Source

nbzwt: Port to Nintendo 3DS; Fix SDL 1.2 support (#2)

Wenting Zhang 7 years ago
parent
commit
3f6284967f
17 changed files with 486 additions and 8 deletions
  1. 212 0
      3ds/Makefile
  2. BIN
      3ds/banner.bin
  3. BIN
      3ds/banner.png
  4. BIN
      3ds/icon.bin
  5. BIN
      3ds/icon.png
  6. BIN
      3ds/icon_24x24.png
  7. BIN
      3ds/music.wav
  8. 199 0
      3ds/sdlpal.rsf
  9. 12 0
      README.txt
  10. 24 1
      common.h
  11. 18 0
      input.c
  12. 1 1
      main.c
  13. 4 0
      sound.c
  14. 6 2
      uigame.c
  15. 4 0
      unix/unix.cpp
  16. 1 1
      util.c
  17. 5 3
      video.c

+ 212 - 0
3ds/Makefile

@@ -0,0 +1,212 @@
+export DEVKITPRO=/opt/devkitpro
+export DEVKITARM=/opt/devkitpro/devkitARM
+#---------------------------------------------------------------------------------
+.SUFFIXES:
+#---------------------------------------------------------------------------------
+
+ifeq ($(strip $(DEVKITARM)),)
+$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
+endif
+
+TOPDIR ?= $(CURDIR)
+include $(DEVKITARM)/3ds_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
+#
+# NO_SMDH: if set to anything, no SMDH file is generated.
+# ROMFS is the directory which contains the RomFS, relative to the Makefile (Optional)
+# APP_TITLE is the name of the app stored in the SMDH file (Optional)
+# APP_DESCRIPTION is the description of the app stored in the SMDH file (Optional)
+# APP_AUTHOR is the author of the app stored in the SMDH file (Optional)
+# ICON is the filename of the icon (.png), relative to the project folder.
+#   If not set, it attempts to use one of the following (in this order):
+#     - <Project name>.png
+#     - icon.png
+#     - <libctru folder>/default_icon.png
+#---------------------------------------------------------------------------------
+TARGET		:=	sdlpal
+BUILD		:=	build
+SOURCES		:=	.. ../adplug ../libmad
+
+APP_TITLE	:=	SDLPAL
+APP_DESCRIPTION :=	Pal DOS for 3DS
+APP_AUTHOR	:=	Ported by ZephRay
+
+ICON		:=	icon.png
+
+#---------------------------------------------------------------------------------
+# options for code generation
+#---------------------------------------------------------------------------------
+ARCH	:=	-march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft
+
+CFLAGS	:=	-g -Wall -O2 -mword-relocations \
+			-fomit-frame-pointer -ffunction-sections \
+			$(ARCH)
+
+CFLAGS	+=	$(INCLUDE) -DARM11 -D_3DS -D__3DS__ -D__N3DS__
+
+CXXFLAGS	:= $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++14
+
+ASFLAGS	:=	-g $(ARCH)
+LDFLAGS	=	-specs=3dsx.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
+
+LIBS	:= -lSDL -lcitro3d -lctru -lm
+
+#---------------------------------------------------------------------------------
+# list of directories containing libraries, this must be the top level containing
+# include and lib
+#---------------------------------------------------------------------------------
+LIBDIRS	:= $(CTRULIB) $(PORTLIBS)
+
+
+#---------------------------------------------------------------------------------
+# 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 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)))
+PICAFILES	:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.v.pica)))
+SHLISTFILES	:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.shlist)))
+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	:=	$(addsuffix .o,$(BINFILES)) \
+			$(PICAFILES:.v.pica=.shbin.o) $(SHLISTFILES:.shlist=.shbin.o) \
+			$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
+
+export INCLUDE	:=	$(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
+			$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
+			$(foreach dir,$(LIBDIRS),-I$(dir)/include/SDL) \
+			-I$(CURDIR)/$(BUILD)
+
+export LIBPATHS	:=	$(foreach dir,$(LIBDIRS),-L$(dir)/lib)
+
+ifeq ($(strip $(ICON)),)
+	icons := $(wildcard *.png)
+	ifneq (,$(findstring $(TARGET).png,$(icons)))
+		export APP_ICON := $(TOPDIR)/$(TARGET).png
+	else
+		ifneq (,$(findstring icon.png,$(icons)))
+			export APP_ICON := $(TOPDIR)/icon.png
+		endif
+	endif
+else
+	export APP_ICON := $(TOPDIR)/$(ICON)
+endif
+
+ifeq ($(strip $(NO_SMDH)),)
+	export _3DSXFLAGS += --smdh=$(CURDIR)/$(TARGET).smdh
+endif
+
+ifneq ($(ROMFS),)
+	export _3DSXFLAGS += --romfs=$(CURDIR)/$(ROMFS)
+endif
+
+.PHONY: $(BUILD) clean all
+
+#---------------------------------------------------------------------------------
+all: $(BUILD)
+
+$(BUILD):
+	@[ -d $@ ] || mkdir -p $@
+	@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
+
+#---------------------------------------------------------------------------------
+clean:
+	@echo clean ...
+	@rm -fr $(BUILD) $(TARGET).3dsx $(OUTPUT).smdh $(TARGET).elf $(TARGET).cia $(TARGET)-strip.elf
+
+#---------------------------------------------------------------------------------
+$(TARGET)-strip.elf: $(BUILD)
+	@$(STRIP) $(TARGET).elf -o $(TARGET)-strip.elf
+#---------------------------------------------------------------------------------
+cci: $(TARGET)-strip.elf
+	@makerom -f cci -rsf resources/$(TARGET).rsf -target d -exefslogo -elf $(TARGET)-strip.elf -o $(TARGET).3ds
+	@echo "built ... 3ds"
+#---------------------------------------------------------------------------------
+cia: $(TARGET)-strip.elf
+	@makerom -f cia -o $(TARGET).cia -elf $(TARGET)-strip.elf -rsf $(TARGET).rsf -icon icon.bin -banner banner.bin -exefslogo -target t
+	@echo "built ... cia"
+#---------------------------------------------------------------------------------
+else
+
+DEPENDS	:=	$(OFILES:.o=.d)
+
+#---------------------------------------------------------------------------------
+# main targets
+#---------------------------------------------------------------------------------
+ifeq ($(strip $(NO_SMDH)),)
+$(OUTPUT).3dsx	:	$(OUTPUT).elf $(OUTPUT).smdh
+else
+$(OUTPUT).3dsx	:	$(OUTPUT).elf
+endif
+
+$(OUTPUT).elf	:	$(OFILES)
+
+#---------------------------------------------------------------------------------
+# you need a rule like this for each extension you use as binary data
+#---------------------------------------------------------------------------------
+%.bin.o	:	%.bin
+#---------------------------------------------------------------------------------
+	@echo $(notdir $<)
+	@$(bin2o)
+
+#---------------------------------------------------------------------------------
+# rules for assembling GPU shaders
+#---------------------------------------------------------------------------------
+define shader-as
+	$(eval CURBIN := $(patsubst %.shbin.o,%.shbin,$(notdir $@)))
+	picasso -o $(CURBIN) $1
+	bin2s $(CURBIN) | $(AS) -o $@
+	echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo $(CURBIN) | tr . _)`.h
+	echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo $(CURBIN) | tr . _)`.h
+	echo "extern const u32" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo $(CURBIN) | tr . _)`.h
+endef
+
+%.shbin.o : %.v.pica %.g.pica
+	@echo $(notdir $^)
+	@$(call shader-as,$^)
+
+%.shbin.o : %.v.pica
+	@echo $(notdir $<)
+	@$(call shader-as,$<)
+
+%.shbin.o : %.shlist
+	@echo $(notdir $<)
+	@$(call shader-as,$(foreach file,$(shell cat $<),$(dir $<)/$(file)))
+
+-include $(DEPENDS)
+
+#---------------------------------------------------------------------------------------
+endif
+#---------------------------------------------------------------------------------------

BIN
3ds/banner.bin


BIN
3ds/banner.png


BIN
3ds/icon.bin


BIN
3ds/icon.png


BIN
3ds/icon_24x24.png


BIN
3ds/music.wav


+ 199 - 0
3ds/sdlpal.rsf

@@ -0,0 +1,199 @@
+BasicInfo:
+  Title                   : "SDLPAL"
+  CompanyCode             : "00"
+  ProductCode             : "CTR-P-PALD"
+  ContentType             : Application
+  Logo                    : Nintendo # Nintendo / Licensed / Distributed / iQue / iQueForSystem
+
+RomFs:
+  # Specifies the root path of the read only file system to include in the ROM.
+  RootPath                : ""
+  
+TitleInfo:
+  UniqueId                : 0x8848
+  Category                : Application
+  
+CardInfo:
+  MediaSize               : 128MB # 128MB / 256MB / 512MB / 1GB / 2GB / 4GB
+  MediaType               : Card1 # Card1 / Card2
+  CardDevice              : None # NorFlash(Pick this if you use savedata) / None
+  
+
+Option:
+  UseOnSD                 : true # true if App is to be installed to SD
+  FreeProductCode         : true # Removes limitations on ProductCode
+  MediaFootPadding        : false # If true CCI files are created with padding
+  EnableCrypt             : false # Enables encryption for NCCH and CIA
+  EnableCompress          : true # Compresses exefs code
+  
+AccessControlInfo:
+  #UseExtSaveData : true
+  #ExtSaveDataId: 0xff3ff
+  #UseExtendedSaveDataAccessControl: true
+  #AccessibleSaveDataIds: [0x101, 0x202, 0x303, 0x404, 0x505, 0x606]
+
+SystemControlInfo:
+  SaveDataSize: 128KB
+  RemasterVersion: 0
+  StackSize: 0x40000
+  
+# DO NOT EDIT BELOW HERE OR PROGRAMS WILL NOT LAUNCH (most likely)
+
+AccessControlInfo:
+  FileSystemAccess:
+   - Debug
+   - DirectSdmc
+   - DirectSdmcWrite
+   
+  IdealProcessor                : 0
+  AffinityMask                  : 1
+  
+  Priority                      : 16
+   
+  MaxCpu                        : 0x9E # Default
+  DisableDebug                  : false
+  EnableForceDebug              : false
+  CanWriteSharedPage            : false
+  CanUsePrivilegedPriority      : false
+  CanUseNonAlphabetAndNumber    : false
+  PermitMainFunctionArgument    : false
+  CanShareDeviceMemory          : false
+  RunnableOnSleep               : false
+  SpecialMemoryArrange          : false
+  CoreVersion                   : 2
+  DescVersion                   : 2
+  
+  ReleaseKernelMajor            : "02"
+  ReleaseKernelMinor            : "33" 
+  MemoryType                    : Application
+  HandleTableSize: 512
+  
+  SystemModeExt                 : Legacy # Legacy(Default)/124MB/178MB  Legacy:Use Old3DS SystemMode
+  CpuSpeed                      : 268MHz # 268MHz(Default)/804MHz
+  EnableL2Cache                 : false # false(default)/true
+  CanAccessCore2                : false 
+  
+  IORegisterMapping: 
+   - 1ff50000-1ff57fff
+   - 1ff70000-1ff77fff
+  MemoryMapping: 
+   - 1f000000-1f5fffff:r
+  SystemCallAccess: 
+    ArbitrateAddress: 34
+    Break: 60
+    CancelTimer: 28
+    ClearEvent: 25
+    ClearTimer: 29
+    CloseHandle: 35
+    ConnectToPort: 45
+    ControlMemory: 1
+    CreateAddressArbiter: 33
+    CreateEvent: 23
+    CreateMemoryBlock: 30
+    CreateMutex: 19
+    CreateSemaphore: 21
+    CreateThread: 8
+    CreateTimer: 26
+    DuplicateHandle: 39
+    ExitProcess: 3
+    ExitThread: 9
+    GetCurrentProcessorNumber: 17
+    GetHandleInfo: 41
+    GetProcessId: 53
+    GetProcessIdOfThread: 54
+    GetProcessIdealProcessor: 6
+    GetProcessInfo: 43
+    GetResourceLimit: 56
+    GetResourceLimitCurrentValues: 58
+    GetResourceLimitLimitValues: 57
+    GetSystemInfo: 42
+    GetSystemTick: 40
+    GetThreadContext: 59
+    GetThreadId: 55
+    GetThreadIdealProcessor: 15
+    GetThreadInfo: 44
+    GetThreadPriority: 11
+    MapMemoryBlock: 31
+    OutputDebugString: 61
+    QueryMemory: 2
+    ReleaseMutex: 20
+    ReleaseSemaphore: 22
+    SendSyncRequest1: 46
+    SendSyncRequest2: 47
+    SendSyncRequest3: 48
+    SendSyncRequest4: 49
+    SendSyncRequest: 50
+    SetThreadPriority: 12
+    SetTimer: 27
+    SignalEvent: 24
+    SleepThread: 10
+    UnmapMemoryBlock: 32
+    WaitSynchronization1: 36
+    WaitSynchronizationN: 37
+  InterruptNumbers:
+  ServiceAccessControl: 
+   - APT:U
+   - $hioFIO
+   - $hostio0
+   - $hostio1
+   - ac:u
+   - boss:U
+   - cam:u
+   - ir:rst
+   - cfg:u
+   - dlp:FKCL
+   - dlp:SRVR
+   - dsp::DSP
+   - frd:u
+   - fs:USER
+   - gsp::Gpu
+   - hid:USER
+   - http:C
+   - mic:u
+   - ndm:u
+   - news:s
+   - nwm::UDS
+   - ptm:u
+   - pxi:dev
+   - soc:U
+   - gsp::Lcd
+   - y2r:u
+   - ldr:ro
+   - ir:USER
+   - ir:u
+   - csnd:SND
+   - am:u
+   - ns:s
+   
+SystemControlInfo:
+  Dependency: 
+    ac: 0x0004013000002402L
+    am: 0x0004013000001502L
+    boss: 0x0004013000003402L
+    camera: 0x0004013000001602L
+    cecd: 0x0004013000002602L
+    cfg: 0x0004013000001702L
+    codec: 0x0004013000001802L
+    csnd: 0x0004013000002702L
+    dlp: 0x0004013000002802L
+    dsp: 0x0004013000001a02L
+    friends: 0x0004013000003202L
+    gpio: 0x0004013000001b02L
+    gsp: 0x0004013000001c02L
+    hid: 0x0004013000001d02L
+    http: 0x0004013000002902L
+    i2c: 0x0004013000001e02L
+    ir: 0x0004013000003302L
+    mcu: 0x0004013000001f02L
+    mic: 0x0004013000002002L
+    ndm: 0x0004013000002b02L
+    news: 0x0004013000003502L
+    nim: 0x0004013000002c02L
+    nwm: 0x0004013000002d02L
+    pdn: 0x0004013000002102L
+    ps: 0x0004013000003102L
+    ptm: 0x0004013000002202L
+    ro: 0x0004013000003702L
+    socket: 0x0004013000002e02L
+    spi: 0x0004013000002302L
+    ssl: 0x0004013000002f02L

+ 12 - 0
README.txt

@@ -100,6 +100,18 @@ ndk-build
 cd ..
 ant debug
 
+COMPILE FOR NINTENDO 3DS
+========================
+
+To compile, type:
+
+cd 3ds
+make
+make cia
+
+You need to have DevkitPro ARM and SDL 1.2 for 3DS portlib installed. The 
+compiled executable should be generated with the filename 'sdlpal' at the
+current directory.
 
 COMPILE FOR OTHER PLATFORMS
 ===========================

+ 24 - 1
common.h

@@ -193,6 +193,29 @@ extern "C"
 # define PAL_CREDIT           "(Unknown)"
 # define PAL_PORTYEAR         "2012"
 
+#elif defined (__N3DS__)
+
+#define PAL_PREFIX            "sdmc:/3ds/sdlpal/"
+#define PAL_SAVE_PREFIX       "sdmc:/3ds/sdlpal/"
+#define PAL_CONFIG_PREFIX     "sdmc:/3ds/sdlpal/"
+#define PAL_SCREENSHOT_PREFIX "sdmc:/3ds/sdlpal/"
+
+#define PAL_AUDIO_DEFAULT_BUFFER_SIZE   2048
+
+#define PAL_HAS_JOYSTICKS     0
+#define PAL_HAS_MP3           0
+#define PAL_HAS_OGG           0
+#define PAL_HAS_TOUCH         0
+
+#define PAL_DEFAULT_WINDOW_WIDTH   320
+#define PAL_DEFAULT_WINDOW_HEIGHT  240
+
+#define PAL_VIDEO_INIT_FLAGS  (SDL_SWSURFACE | SDL_TOPSCR | SDL_CONSOLEBOTTOM | SDL_FULLSCREEN)
+
+# define PAL_PLATFORM         "Nintendo 3DS"
+# define PAL_CREDIT           "ZephRay"
+# define PAL_PORTYEAR         "2017"
+
 #elif defined (__IOS__)
 
 #define PAL_PREFIX            UTIL_BasePath()
@@ -404,7 +427,7 @@ typedef const WCHAR        *LPCWSTR;
 #define PAL_HAS_NATIVEMIDI  0
 #endif
 
-#if defined (__SYMBIAN32__)
+#if defined (__SYMBIAN32__) || defined (__N3DS__)
 #define PAL_LARGE           static
 #else
 #define PAL_LARGE           /* */

+ 18 - 0
input.c

@@ -24,6 +24,10 @@
 #include "main.h"
 #include <math.h>
 
+#ifdef __N3DS__
+#include <3ds.h>
+#endif
+
 volatile PALINPUTSTATE   g_InputState;
 #if PAL_HAS_JOYSTICKS
 static SDL_Joystick     *g_pJoy = NULL;
@@ -676,6 +680,7 @@ PAL_JoystickEventFilter(
 #endif
 }
 
+#if PAL_HAS_TOUCH
 
 #define  TOUCH_NONE     0
 #define    TOUCH_UP      1
@@ -842,6 +847,8 @@ PAL_UnsetTouchAction(
    }
 }
 
+#endif
+
 static VOID
 PAL_TouchEventFilter(
    const SDL_Event *lpEvent
@@ -861,6 +868,7 @@ PAL_TouchEventFilter(
 
 --*/
 {
+#if PAL_HAS_TOUCH
    static SDL_TouchID finger1 = -1, finger2 = -1;
    static int prev_touch1 = TOUCH_NONE;
    static int prev_touch2 = TOUCH_NONE;
@@ -924,6 +932,7 @@ PAL_TouchEventFilter(
       }
       break;
    }
+#endif
 }
 
 static int SDLCALL
@@ -1073,6 +1082,15 @@ PAL_InitInput(
 #ifdef PAL_ALLOW_KEYREPEAT
    SDL_EnableKeyRepeat(0, 0);
 #endif
+
+#ifdef __N3DS__
+   SDL_N3DSKeyBind(KEY_A, SDLK_RETURN);
+   SDL_N3DSKeyBind(KEY_B, SDLK_ESCAPE);
+   SDL_N3DSKeyBind(KEY_CPAD_UP, SDLK_UP);
+   SDL_N3DSKeyBind(KEY_CPAD_DOWN, SDLK_DOWN);
+   SDL_N3DSKeyBind(KEY_CPAD_LEFT, SDLK_LEFT);
+   SDL_N3DSKeyBind(KEY_CPAD_RIGHT, SDLK_RIGHT);
+#endif
 }
 
 VOID

+ 1 - 1
main.c

@@ -73,7 +73,7 @@ PAL_Init(
    //
 #if defined(DINGOO)
    if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) == -1)
-#elif defined (__WINRT__)
+#elif defined (__WINRT__) || defined (__N3DS__)
    if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) == -1)
 #else
    if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_CDROM | SDL_INIT_NOPARACHUTE | SDL_INIT_JOYSTICK) == -1)

+ 4 - 0
sound.c

@@ -39,7 +39,11 @@ typedef struct tagWAVESPEC
 {
 	int                 size;
 	int                 freq;
+#if SDL_VERSION_ATLEAST(2,0,0)
 	SDL_AudioFormat     format;
+#else
+	uint16_t            format;
+#endif
 	uint8_t             channels;
 	uint8_t             align;
 } WAVESPEC;

+ 6 - 2
uigame.c

@@ -677,7 +677,7 @@ PAL_InGameMagicMenu(
    int              i, y;
    static WORD      w;
    WORD             wMagic;
-   const SDL_Rect   rect = {35, 62, 320, 90};
+   const SDL_Rect   rect = {35, 62, 285, 90};
 
    //
    // Draw the player info boxes
@@ -887,7 +887,7 @@ PAL_InventoryMenu(
 --*/
 {
    static WORD      w = 0;
-   const SDL_Rect   rect = {30, 60, 320, 60};
+   const SDL_Rect   rect = {30, 60, 290, 60};
 
    MENUITEM        rgMenuItem[2] =
    {
@@ -2005,7 +2005,11 @@ PAL_QuitGame(
    VOID
 )
 {
+#ifndef __N3DS__
 	WORD wReturnValue = PAL_TripleMenu(SYSMENU_LABEL_LAUNCHSETTING);
+#else
+	WORD wReturnValue = PAL_ConfirmMenu(); // No config menu available
+#endif
 	if (wReturnValue == 1 || wReturnValue == 2)
 	{
 		if (wReturnValue == 2) gConfig.fLaunchSetting = TRUE;

+ 4 - 0
unix/unix.cpp

@@ -95,7 +95,9 @@ void InitControls()
    gWidgets.msgfile->value(gConfig.pszMsgFile);
    gWidgets.font->value(gConfig.fUseEmbeddedFonts ? 1 : 0);
    gWidgets.touch->value(gConfig.fUseTouchOverlay ? 1 : 0);
+#if SDL_VERSION_ATLEAST(2,0,0)
    gWidgets.aspect->value(gConfig.fKeepAspectRatio ? 1 : 0);
+#endif
    gWidgets.fullscreen->value(gConfig.fFullScreen ? 1 : 0);
    gWidgets.cd->value(gConfig.eCDType - MUSIC_MP3);
    gWidgets.bgm->value(gConfig.eMusicType - MUSIC_RIX);
@@ -119,7 +121,9 @@ void SaveControls()
    gConfig.uCodePage = (gWidgets.cht->value() ? CP_BIG5 : CP_GBK);
    gConfig.fUseEmbeddedFonts = gWidgets.font->value();
    gConfig.fUseTouchOverlay = gWidgets.touch->value();
+#if SDL_VERSION_ATLEAST(2,0,0)
    gConfig.fKeepAspectRatio = gWidgets.aspect->value();
+#endif
    gConfig.fFullScreen = gWidgets.fullscreen->value();
    gConfig.eCDType = (MUSICTYPE)(gWidgets.cd->value() + MUSIC_MP3);
    gConfig.eMusicType = (MUSICTYPE)(gWidgets.bgm->value() + MUSIC_RIX);

+ 1 - 1
util.c

@@ -497,7 +497,7 @@ UTIL_OpenFileForMode(
 	else
 		fp = fopen(va("%s%s", gConfig.pszGamePath, lpszFileName), szMode);
 
-#ifndef _WIN32
+#if !(defined(_WIN32) || defined(__N3DS__))
 	if (fp == NULL)
 	{
 		//

+ 5 - 3
video.c

@@ -44,7 +44,7 @@ static SDL_Surface       *gpScreenReal       = NULL;
 
 volatile BOOL g_bRenderPaused = FALSE;
 
-#if (defined (__SYMBIAN32__) && !defined (__S60_5X__)) || defined (PSP) || defined (GEKKO)
+#if (defined (__SYMBIAN32__) && !defined (__S60_5X__)) || defined (PSP) || defined (GEKKO) || defined(__N3DS__)
    static BOOL bScaleScreen = FALSE;
 #else
    static BOOL bScaleScreen = TRUE;
@@ -56,7 +56,6 @@ static WORD               g_wShakeLevel      = 0;
 
 #if SDL_VERSION_ATLEAST(2, 0, 0)
 #define SDL_SoftStretch SDL_UpperBlit
-#endif
 
 static SDL_Texture *VIDEO_CreateTexture(int width, int height)
 {
@@ -89,7 +88,9 @@ static SDL_Texture *VIDEO_CreateTexture(int width, int height)
 		gTextureRect.x = (texture_width - 320) / 2;
 		gTextureRect.y = (texture_height - 200) / 2;
 		gTextureRect.w = 320; gTextureRect.h = 200;
+#if PAL_HAS_TOUCH
 		PAL_SetTouchBounds(width, height, gOverlayRect);
+#endif
 	}
 	else
 	{
@@ -107,6 +108,7 @@ static SDL_Texture *VIDEO_CreateTexture(int width, int height)
 	//
 	return SDL_CreateTexture(gpRenderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, texture_width, texture_height);
 }
+#endif
 
 INT
 VIDEO_Startup(
@@ -569,7 +571,7 @@ VIDEO_SetPalette(
    SDL_SetPalette(gpScreen, SDL_LOGPAL | SDL_PHYSPAL, rgPalette, 0, 256);
    SDL_SetPalette(gpScreenBak, SDL_LOGPAL | SDL_PHYSPAL, rgPalette, 0, 256);
    SDL_SetPalette(gpScreenReal, SDL_LOGPAL | SDL_PHYSPAL, rgPalette, 0, 256);
-#if (defined (__SYMBIAN32__))
+#if (defined (__SYMBIAN32__)) || (defined (__N3DS__))
    {
       static UINT32 time = 0;
       if (SDL_GetTicks() - time > 50)