Skip to content

Commit

Permalink
Switch: add Switch port
Browse files Browse the repository at this point in the history
  • Loading branch information
rsn8887 committed Oct 24, 2018
1 parent 9e0cdf8 commit a3628fa
Show file tree
Hide file tree
Showing 25 changed files with 239 additions and 64 deletions.
18 changes: 18 additions & 0 deletions Makefile
Expand Up @@ -66,6 +66,24 @@ sdl:
sdl2:
@$(MAKE_CMD) TARGET=sdl2

switchrocks: PREFIX = $(DEVKITPRO)/devkitA64/bin/aarch64-none-elf
switchrocks: CC = $(PREFIX)-gcc
switchrocks: PROGBASE = Rocksndiamonds
switchrocks: PROGNAME = ../$(PROGBASE)
switchrocks: RO_GAME_DIR = .
switchrocks: RW_GAME_DIR = .
switchrocks:
@$(MAKE_CMD) TARGET=switch PLATFORM=switch

switchmirror: PREFIX = $(DEVKITPRO)/devkitA64/bin/aarch64-none-elf
switchmirror: CC = $(PREFIX)-gcc
switchmirror: PROGBASE = Mirrormagic
switchmirror: PROGNAME = ../$(PROGBASE)
switchmirror: RO_GAME_DIR = .
switchmirror: RW_GAME_DIR = .
switchmirror:
@$(MAKE_CMD) TARGET=switch PLATFORM=switch

vitarocks: VITA_TITLEID := ROCKS0000
vitarocks: PREFIX = arm-vita-eabi
vitarocks: CC = $(PREFIX)-gcc
Expand Down
67 changes: 53 additions & 14 deletions README.MD
@@ -1,6 +1,6 @@
Description
======
These are my Vita ports of Rocks'n'Diamonds and Mirrormagic.
These are my Vita and Switch ports of Rocks'n'Diamonds and Mirrormagic.

**Rocks'n'Diamonds** is a Boulderdash type game by Holger Schemel with many unique features, such as the ability to play remade levels from Boulderdash, Emerald Mine and Supaplex and many more levels.

Expand Down Expand Up @@ -29,26 +29,38 @@ Thanks to Holger Schemel for making a great and portable game.

Thanks to the many devs of VitaSDK for a great development environment.

Installation
Installation (Vita)
=====

- install the vpks

- extract contents of rocksndiamonds_data.zip and mirrormagic_data.zip and copy them to your Vita's ux0:/data folder. You should have folders ux0:/data/rocksndiamonds and ux0:/data/mirrormagic on your Vita with the files in them.

Vita-Exclusive Features
Installation (Switch)
=====

- extract `rocksndiamonds_data.zip` and `mirrormagic_data.zip` to the folder `/switch/` on your sd card. You should have folders such as `/switch/rocksndiamonds/levels` and `/switch/mirrormagic/levels` and more. Make sure none of the folders has the "archive" flag set after copying.

- copy `rocksndiamonds.nro` to `/switch/rocksndiamonds/` and `mirrormagic.nro` to `/switch/mirrormagic/`

- use hblauncher or any other method of choice to start the games.

Vita/Switch-Exclusive Features
=======
- game controller mapping including analog joystick mouse controls
- front touch controls with left/right mouse click and drag and drop gestures
- text entry with Vita touch keyboard, no physical keyboard or mouse required
- support for bluetooth keyboard and mouse
- the game runs smooth at the same speed as the desktop versions
- additional level package with thousands of levels as separate download (see 'More Levels')
- auto-hide mouse cursor when using the dpad
- easily switch player focus in multiplayer games using r+triangle and r+square

Vita-Exclusive Features
========
- text entry with Vita touch keyboard, no physical keyboard or mouse required
- 60 fps mode for smooth scrolling and motion in levels where the Vita can achieve stable 60 frames per second.

Gamepad Controls
Gamepad Controls (Vita)
======
Dpad or left stick = move player and navigate menus
right stick = move mouse pointer
Expand All @@ -61,6 +73,19 @@ Start = pause (space key)
R+Triangle = set focus to next player (ALL->1->2->3->4)
R+Square = set player focus to previous player (ALL<-1<-2<-3<-4)

Gamepad Controls (Switch)
======
Dpad or left stick = move player and navigate menus
right stick = move mouse pointer
B = primary button (+ direction for snap action or turning mirrors, also 'ok' in menu)
A = secondary button (drop dynamite)
Y or L = left mouse button
X or R = right mouse button
Minus = quit (escape key, also cancels requesters)
Plus = pause (space key)
R+X = set focus to next player (ALL->1->2->3->4)
R+Y = set player focus to previous player (ALL<-1<-2<-3<-4)

Touch Controls
=======
Note: for multi-touch gestures, the fingers have to be far enough apart from each other, so that the Vita will not erroneously recognize them as a single finger. Otherwise the pointer will jump around.
Expand All @@ -79,44 +104,58 @@ More Levels for Rocks'n'Diamonds
- I made a single easy-to-install zip [More_Levels_v2.zip](https://mega.nz/#!tdBhDRrZ!t4XrrCyXzCSGjcgFjvh-Sm1MhGErcsWg3UOjUZCKvZ4) (~80 MB). It contains selected additional levels from the above site and is available here:
https://mega.nz/#!tdBhDRrZ!t4XrrCyXzCSGjcgFjvh-Sm1MhGErcsWg3UOjUZCKvZ4

- Just download, unzip, and transfer to your Vita, so that you have a subfolder ux0:/data/rocksndiamonds/levels/More_Levels.
- Just download, unzip, and transfer to your Vita, so that you have a subfolder ux0:/data/rocksndiamonds/levels/More_Levels. Or transfer to your Switch, so that you have a subfolder switch/rocksndiamonds/levels/More_Levels.

- FTP transfer of levelsets has to be done using binary transfer mode, not Auto or ASCII . Otherwise some levels will be treated as ASCII with mangled line endings and won't work. This was verified with the Emerald_Mine_Club_original_1 levels and FileZilla FTP.

Notes
=====
- To load new level sets, go to the level number selection in the menu, and press x. A new screen should open that shows a few levels. Go to the parent dir and into the folder Classic Games. There are many more levels already included in that folder.
- To load new level sets, go to the level number selection in the menu, and press X (B on Switch). A new screen should open that shows a few levels. Go to the parent dir and into the folder Classic Games. There are many more levels already included in that folder.

- Sometimes when loading a levelset after loading other level sets one after the other, the game runs out of memory and quits. This is fixed by simply restarting the game and loading the levelset again.

- To answer the OK/Cancel dialogs in the game, press select to cancel (select is escape), or x for OK.
- To answer the OK/Cancel dialogs in the game, press select (minus on Switch) to cancel (this is escape), or X (B on Switch) for OK.

- You can install new level sets for Rocks'n'Diamonds by copying them into ux0:/data/rocksndiamonds/levels. See the official manual: https://www.artsoft.org/rocksndiamonds/manual/manual.html#
- You can install new level sets for Rocks'n'Diamonds by copying them into ux0:/data/rocksndiamonds/levels on Vita, or /switch/rocksndiamonds/levels on Switch. See the official manual: https://www.artsoft.org/rocksndiamonds/manual/manual.html#

- You can install new level sets for Mirrormagic by copying them into ux0:/data/mirrormagic/levels.
- Similarly, you can install new level sets for Mirrormagic by copying them into ux0:/data/mirrormagic/levels on Vita, and /switch/mirrormagic/levels on Switch.

- If you mess up some options and want to reset to default, you can delete the folder 'ux0:/data/rocksndiamonds/userdata' and/or 'ux0:/data/mirrormagic/userdata'
- If you mess up some options and want to reset to default, you can delete the folder 'ux0:/data/rocksndiamonds/userdata' and/or 'ux0:/data/mirrormagic/userdata'. On Switch, the folders are '/switch/rocksndiamonds/userdata' and '/switch/mirrormagic/userdata'.

- For multiplayer team mode in Rocks'n'Diamonds to work on VitaTV, enable it via Setup->Game & Menu->Team-Mode (Multiplayer)->on. You also have to find make a level that has multiple players. r+square and r+triangle can be used in-game to change focus between players, see Game Controls. All controllers have to be paired before launching the app, otherwise they will not be recognized by the game.
- For multiplayer team mode in Rocks'n'Diamonds, enable it via Setup->Game & Menu->Team-Mode (Multiplayer)->on. You also have to find make a level that has multiple players. R+Square and R+Triangle (R+Y and R+X on Switch) can be used in-game to change focus between players, see Game Controls. All controllers have to be paired before launching the app, otherwise they will not be recognized by the game.

Build Instructions
=====
- clone the repository, then
````
cd rocksndiamonds
````
Then use
````
make vitarocks
````
for Rocks'n'Diamonds, or
or
````
make switchrocks
````
for Rocks'n'Diamonds, and
````
cd rocksndiamonds
make vitamirror
````
or
````
make switchmirror
````
for Mirrormagic.

You need the latest SDL2 Vita library from 05-23-2018 or later for this to work. The latest SDL2 library can be downloaded by updating your vitasdk, or here: https://dl.vitasdk.org

CHANGELOG
=====
1.9switch

- same as release 1.9, but added Switch executables to the downloads

1.9

- add '60 fps' game speed setting for perfectly smooth motion in some levels on the Vita. It works well with the bundled Emerald Mine levelsets. This mode is 20% faster than the default setting 'normal.'
Expand Down
52 changes: 52 additions & 0 deletions src/Makefile
Expand Up @@ -30,9 +30,11 @@ WINDRES = windres
CONVERT_ICON_ARGS = -transparent black -background transparent

ifneq ($(TARGET),vita)
ifneq ($(TARGET),switch)
PROGBASE = rocksndiamonds
PROGNAME = ../$(PROGBASE)
endif
endif

EDITION ?= default

Expand Down Expand Up @@ -101,6 +103,46 @@ AR = $(PREFIX)-ar
RANLIB = $(PREFIX)-ranlib
endif

ifeq ($(TARGET),switch) # compiling for Switch target
SYS_CFLAGS = -DTARGET_SDL2 \
-D__SWITCH__ \
-I$(DEVKITPRO)/portlibs/switch/include/SDL2 \
-I$(DEVKITPRO)/portlibs/switch/include \
-Wl,-q -Wall -Wno-unused-variable -O3 \
-ffunction-sections \
-ffast-math -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE \
-fno-rtti -fno-exceptions
SYS_LDFLAGS = $(SYS_CFLAGS) \
-specs=$(DEVKITPRO)/libnx/switch.specs \
-L$(DEVKITPRO)/libnx/lib \
-L$(DEVKITPRO)/portlibs/switch/lib \
-lSDL2_image \
-lSDL2_mixer \
-lSDL2_net \
-lSDL2 \
-lEGL \
-lGLESv2 \
-lglapi \
-ldrm_nouveau \
-lnx \
-lm \
-lvorbisfile \
-lvorbis \
-logg \
-lmpg123 \
-lflac \
-lmikmod \
-lmodplug \
-ljpeg \
-lfreetype \
-lc \
-lpng16 \
-lz \
-lstdc++
AR = $(PREFIX)-ar
RANLIB = $(PREFIX)-ranlib
endif

# -----------------------------------------------------------------------------
# configuring compile-time definitions
# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -251,11 +293,21 @@ $(PROGNAME).vpk: $(PROGNAME).velf
$(PREFIX)-strip -g $<
vita-elf-create $< $@

$(PROGNAME).elf: $(RNDLIBS) $(TIMESTAMP_FILE) $(OBJS) $(ICON)
$(CC) $(PROFILING) $(OBJS) $(ICON) $(RNDLIBS) $(LDFLAGS) -o $@
else
ifeq ($(TARGET),switch)
all: $(AUTOCONF) libgame_dir game_em_dir game_sp_dir game_mm_dir $(PROGNAME).nro
$(PROGNAME).nro: $(PROGNAME).elf
$(DEVKITPRO)/tools/bin/nacptool --create "$(PROGBASE)" "rsn8887" "1.0" $(PROGNAME).nacp
$(DEVKITPRO)/tools/bin/elf2nro $(PROGNAME).elf $(PROGNAME).nro --icon=../switchdata/$(PROGBASE)/icon0.jpg --nacp=$(PROGNAME).nacp

$(PROGNAME).elf: $(RNDLIBS) $(TIMESTAMP_FILE) $(OBJS) $(ICON)
$(CC) $(PROFILING) $(OBJS) $(ICON) $(RNDLIBS) $(LDFLAGS) -o $@
else
all: $(AUTOCONF) libgame_dir game_em_dir game_sp_dir game_mm_dir $(PROGNAME) graphics_dir
endif
endif

$(PROGNAME): $(RNDLIBS) $(TIMESTAMP_FILE) $(OBJS) $(ICON)
$(CC) $(PROFILING) $(OBJS) $(ICON) $(RNDLIBS) $(LDFLAGS) -o $(PROGNAME)
Expand Down
2 changes: 1 addition & 1 deletion src/events.c
Expand Up @@ -193,7 +193,7 @@ void HandleEvents()
HandleWindowEvent((WindowEvent *) &event);
break;

#if !defined(PLATFORM_VITA)
#if !defined(PLATFORM_VITA) && !defined(PLATFORM_SWITCH)
// Vita has its own touch module
case EVENT_FINGERPRESS:
case EVENT_FINGERRELEASE:
Expand Down
2 changes: 1 addition & 1 deletion src/files.c
Expand Up @@ -8851,7 +8851,7 @@ static void setSetupInfoToDefaults(struct SetupInfo *si)

si->options.verbose = FALSE;

#if defined(PLATFORM_ANDROID) || defined(PLATFORM_VITA)
#if defined(PLATFORM_ANDROID) || defined(PLATFORM_VITA) || defined(PLATFORM_SWITCH)
si->fullscreen = TRUE;
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion src/game_em/graphics.c
Expand Up @@ -301,7 +301,7 @@ static void animscreen(void)

if (!game.use_native_emc_graphics_engine)
{
#if defined(PLATFORM_VITA)
#if defined(PLATFORM_VITA) || defined(PLATFORM_SWITCH)
// This causes significant speedup on Vita when playing the bundled Emerald Mine levels
const int x_max = MIN(lev.width + 2, EM_MAX_CAVE_WIDTH - 2);
const int y_max = MIN(lev.height + 2, EM_MAX_CAVE_HEIGHT - 2);
Expand Down
2 changes: 1 addition & 1 deletion src/init.c
Expand Up @@ -5979,7 +5979,7 @@ void OpenAll()

if (options.serveronly)
{
#if defined(PLATFORM_UNIX) && !defined(PLATFORM_VITA)
#if defined(PLATFORM_UNIX) && !defined(PLATFORM_VITA) && !defined(PLATFORM_SWITCH)
NetworkServer(options.server_port, options.serveronly);
#else
Error(ERR_WARN, "networking only supported in Unix version");
Expand Down
13 changes: 13 additions & 0 deletions src/libgame/Makefile
Expand Up @@ -49,11 +49,24 @@ OBJS_VITA = psp2-dirent.o \
psp2_input.o \
psp2_touch.o

SRCS_SWITCH = \
psp2_input.c \
psp2_touch.c

OBJS_SWITCH = \
psp2_input.o \
psp2_touch.o

ifeq ($(TARGET),vita)
SRCS += $(SRCS_VITA)
OBJS += $(OBJS_VITA)
endif

ifeq ($(TARGET),switch)
SRCS += $(SRCS_SWITCH)
OBJS += $(OBJS_SWITCH)
endif

LIBGAME = libgame.a


Expand Down
2 changes: 1 addition & 1 deletion src/libgame/libgame.h
Expand Up @@ -26,7 +26,7 @@
#include "image.h"
#include "setup.h"
#include "misc.h"
#if defined(PLATFORM_VITA)
#if defined(PLATFORM_VITA) || defined(PLATFORM_SWITCH)
#include "psp2_input.h"
#endif

Expand Down
4 changes: 2 additions & 2 deletions src/libgame/misc.c
Expand Up @@ -570,7 +570,7 @@ char *getLoginName()
if (GetUserName(login_name, &buffer_size) == 0)
strcpy(login_name, ANONYMOUS_NAME);
}
#elif defined(PLATFORM_UNIX) && !defined(PLATFORM_ANDROID) && !defined(PLATFORM_VITA)
#elif defined(PLATFORM_UNIX) && !defined(PLATFORM_ANDROID) && !defined(PLATFORM_VITA) && !defined(PLATFORM_SWITCH)
if (login_name == NULL)
{
struct passwd *pwd;
Expand Down Expand Up @@ -602,7 +602,7 @@ char *getRealName()
else
real_name = ANONYMOUS_NAME;
}
#elif defined(PLATFORM_UNIX) && !defined(PLATFORM_ANDROID) && !defined(PLATFORM_VITA)
#elif defined(PLATFORM_UNIX) && !defined(PLATFORM_ANDROID) && !defined(PLATFORM_VITA) && !defined(PLATFORM_SWITCH)
if (real_name == NULL)
{
struct passwd *pwd;
Expand Down
8 changes: 7 additions & 1 deletion src/libgame/platform.h
Expand Up @@ -153,6 +153,12 @@
#define PLATFORM_STRING "Android"
#endif

#if defined(__SWITCH__)
#define PLATFORM_SWITCH
#undef PLATFORM_STRING
#define PLATFORM_STRING "Switch"
#endif

#if defined(__vita__)
#define PLATFORM_VITA
#undef PLATFORM_STRING
Expand All @@ -174,7 +180,7 @@
/* this should better go into "system.h" or "features.h" (yet to be created) */
/* ========================================================================= */

#if (defined(PLATFORM_UNIX) || defined(TARGET_SDL)) && !defined(PLATFORM_VITA)
#if (defined(PLATFORM_UNIX) || defined(TARGET_SDL)) && !defined(PLATFORM_VITA) && !defined(PLATFORM_SWITCH)
#define NETWORK_AVALIABLE
#endif

Expand Down
6 changes: 6 additions & 0 deletions src/libgame/psp2_input.c
@@ -1,6 +1,8 @@
#include "psp2_input.h"
#include "psp2_touch.h"
#if defined(__vita__)
#include "psp2_kbdvita.h"
#endif
#include <math.h>

int lastmx = 0;
Expand Down Expand Up @@ -210,6 +212,9 @@ void rescaleAnalog(int *x, int *y, int dead) {
}

void PSP2_StartTextInput(char *initial_text, int multiline) {
#if !defined(__vita__)
return;
#else
if (!can_use_IME_keyboard)
return;

Expand Down Expand Up @@ -292,6 +297,7 @@ void PSP2_StartTextInput(char *initial_text, int multiline) {
up_event.key.keysym.mod = 0;
SDL_PushEvent(&up_event);
}
#endif
}

void PSP2_StopTextInput() {
Expand Down

0 comments on commit a3628fa

Please sign in to comment.