Skip to content

Commit

Permalink
Merge pull request EasyRPG#1415 from BSzili/master
Browse files Browse the repository at this point in the history
MorphOS and AmigaOS4 port
  • Loading branch information
carstene1ns authored Oct 4, 2018
2 parents 4e39bd4 + 6d6db16 commit 50fc262
Show file tree
Hide file tree
Showing 13 changed files with 196 additions and 8 deletions.
Binary file added builds/amiga/EasyRPG-Player.info
Binary file not shown.
70 changes: 70 additions & 0 deletions builds/amiga/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
TARGET := EasyRPG
BUILD := build
SOURCES := ../../src
OSTYPE := $(shell uname -s)

CFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.c))
CPPFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.cpp))
OBJS := $(CFILES:.c=.o) $(CPPFILES:.cpp=.o)

ifeq ($(OSTYPE), MorphOS)
PREFIX = ppc-morphos
CC = $(PREFIX)-gcc -noixemul
CXX = $(PREFIX)-g++ -noixemul
TOOLCHAIN_DIR := /gg/usr
SDL_LIBS = -L$(TOOLCHAIN_DIR)/local/lib -lSDL_mixer -lSDL
SDL_CFLAGS = -I$(TOOLCHAIN_DIR)/local/include/SDL -I$(TOOLCHAIN_DIR)/local/include
PIXMAN_LIBS = -lpixman
PNG_LIBS = -lpng_shared
endif
ifeq ($(OSTYPE), AmigaOS)
PREFIX = ppc-amigaos
CC = $(PREFIX)-gcc -D_GLIBCXX_USE_C99_STDINT_TR1
CXX = $(PREFIX)-g++ -D_GLIBCXX_USE_C99_STDINT_TR1
TOOLCHAIN_DIR := /usr/local/amiga/ppc-amigaos/SDK/local/newlib
SDL_LIBS = -lSDL_mixer -lmikmod -lFLAC -lmodplug -lsmpeg -lSDL
SDL_CFLAGS = -I$(TOOLCHAIN_DIR)/include/SDL
PIXMAN_LIBS = -lpixman-1
PNG_LIBS = -lpng -lz
endif

ICU_LIBS = -licuuc -licui18n -licudata

LIBS = -llcf -lexpat \
$(PIXMAN_LIBS) $(PNG_LIBS) \
-lfreetype -lmpg123 \
-lvorbisfile -lvorbis -logg -lWildMidi \
$(ICU_LIBS) \
$(SDL_LIBS)

ifeq ($(strip $(LIBLCF_DIR)),)
LIBLCF_DIR := $(TOOLCHAIN_DIR)
endif

CFLAGS = -g -O2
CXXFLAGS = $(CFLAGS) -std=gnu++11 -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
CPPFLAGS = -DUSE_SDL -DHAVE_SDL_MIXER -DHAVE_FREETYPE -DSUPPORT_AUDIO \
-DHAVE_MPG123 -DHAVE_OGGVORBIS -DHAVE_WILDMIDI -DWANT_FASTWAV \
-I$(TOOLCHAIN_DIR)/include \
$(SDL_CFLAGS) \
-I$(LIBLCF_DIR)/include/liblcf \
-I$(TOOLCHAIN_DIR)/include/pixman-1 \
-I$(TOOLCHAIN_DIR)/include/freetype2 \
-I$(TOOLCHAIN_DIR)/include/libxmp-lite \
-I$(TOOLCHAIN_DIR)/include/opus

LDFLAGS = -L$(TOOLCHAIN_DIR)/lib \
-L$(LIBLCF_DIR)/lib

all: $(TARGET).elf

%.o: %.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@

$(TARGET).elf: $(OBJS)
$(CXX) $(CXXFLAGS) $^ $(LDFLAGS) $(LIBS) -o $@
$(PREFIX)-strip -g -o $(basename $@)-stripped.elf $@

clean:
rm -rf $(TARGET).elf $(TARGET)-stripped.elf $(OBJS)
4 changes: 4 additions & 0 deletions src/async_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
#include <string>
#include <vector>

#ifdef __MORPHOS__
#undef bind
#endif

class FileRequestAsync;
struct FileRequestResult;

Expand Down
10 changes: 10 additions & 0 deletions src/decoder_wildmidi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ WildMidiDecoder::WildMidiDecoder(const std::string file_name) {
}

// TODO: We need some installer which creates registry keys for wildmidi
# elif defined(__MORPHOS__) || defined(__amigaos4__)
if (!found) {
config_file = "timidity/timidity.cfg";
found = FileFinder::Exists(config_file);
}
# else
if (!found) {
config_file = "/etc/timidity.cfg";
Expand Down Expand Up @@ -245,6 +250,11 @@ WildMidiDecoder::WildMidiDecoder(const std::string file_name) {
return;
}

#if defined(__MORPHOS__) || defined(__amigaos4__)
// the default volume is way too quiet with the SDL_mixer patches
WildMidi_MasterVolume(127);
#endif

// setup deinitialization
atexit(WildMidiDecoder_deinit);
}
Expand Down
4 changes: 4 additions & 0 deletions src/filefinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@
# include <SDL_system.h>
#endif

#ifdef __MORPHOS__
#undef bind
#endif

#include "system.h"
#include "options.h"
#include "utils.h"
Expand Down
4 changes: 4 additions & 0 deletions src/game_character.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
#include "color.h"
#include "rpg_moveroute.h"

#ifdef __MORPHOS__
#undef Wait
#endif

/**
* Game_Character class.
*/
Expand Down
3 changes: 3 additions & 0 deletions src/image_png.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
#ifdef SUPPORT_PNG

// Headers
#ifdef __MORPHOS__
#define __MORPHOS_SHAREDLIBS
#endif
#include <png.h>
#include <cstdlib>
#include <cstring>
Expand Down
12 changes: 6 additions & 6 deletions src/main_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include <SDL_system.h>
#endif

#ifdef GEKKO
#if defined(GEKKO) || defined(__MORPHOS__) || defined(__amigaos4__)
#include <unistd.h>
#endif

Expand Down Expand Up @@ -83,11 +83,11 @@ void Main_Data::Init() {
// first set to current directory for all platforms
project_path = ".";

#ifdef GEKKO
// Working directory not correctly handled under Wii
char gekko_dir[256];
getcwd(gekko_dir, 255);
project_path = std::string(gekko_dir);
#if defined(GEKKO) || defined(__MORPHOS__) || defined(__amigaos4__)
// Working directory not correctly handled
char working_dir[256];
getcwd(working_dir, 255);
project_path = std::string(working_dir);
#elif defined(PSP2)
// Check if app0 filesystem contains the title id reference file
FILE* f = fopen("app0:/titleid.txt","r");
Expand Down
4 changes: 4 additions & 0 deletions src/output.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
#include <string>
#include <iosfwd>

#ifdef __MORPHOS__
#undef Debug
#endif

/**
* Output Namespace.
*/
Expand Down
87 changes: 86 additions & 1 deletion src/sdl_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ SdlUi::SdlUi(long width, long height, bool fs_flag) :

// Set some SDL environment variables before starting. These are platform
// dependent, so every port needs to set them manually
#ifndef GEKKO
#if !defined(GEKKO) && !defined(__MORPHOS__)
// Set window position to the middle of the screen
putenv(const_cast<char *>("SDL_VIDEO_WINDOW_POS=center"));
#endif
Expand Down Expand Up @@ -423,6 +423,90 @@ bool SdlUi::ShowCursor(bool flag) {
void SdlUi::Blit2X(Bitmap const& src, SDL_Surface* dst_surf) {
if (SDL_MUSTLOCK(dst_surf)) SDL_LockSurface(dst_surf);

#if defined(__MORPHOS__) || defined(__amigaos4__)
// Quick & dirty big endian 2x zoom blitter
int blit_height = src.height() * 2;
int blit_width = src.width();
int src_pitch = src.pitch();
int dst_pitch = dst_surf->pitch;
int dst_bpp = sdl_surface->format->BitsPerPixel;

uint8_t* src_pixels = (uint8_t*)src.pixels();
uint8_t* dst_pixels = (uint8_t*)dst_surf->pixels;

switch (dst_bpp) {
case 32:
for (int i = 0; i < blit_height; i++) {
uint32_t* src = (uint32_t*)src_pixels;
uint32_t* dst = (uint32_t*)dst_pixels;
for (int j = 0; j < blit_width; j++) {
uint32_t pixel = *src;
*dst++ = pixel;
*dst++ = pixel;
src++;
}
dst_pixels += dst_pitch;
if (i & 1) {
src_pixels += src_pitch;
}
}
break;
case 24:
for (int i = 0; i < blit_height; i++) {
uint32_t* src = (uint32_t*)src_pixels;
uint8_t* dst = (uint8_t*)dst_pixels;
for (int j = 0; j < blit_width; j++) {
uint8_t* pixels = (uint8_t*)src + 1;
*dst++ = *pixels++;
*dst++ = *pixels++;
*dst++ = *pixels;
pixels = (uint8_t*)src + 1;
*dst++ = *pixels++;
*dst++ = *pixels++;
*dst++ = *pixels;
src++;
}
dst_pixels += dst_pitch;
if (i & 1) {
src_pixels += src_pitch;
}
}
break;
case 16:
for (int i = 0; i < blit_height; i++) {
uint16_t* src = (uint16_t*)src_pixels;
uint16_t* dst = (uint16_t*)dst_pixels;
for (int j = 0; j < blit_width; j++) {
// 5:5:5:1 RGBA to 6:5:5 RGB
uint16_t pixel = (*src & 0x7FE0) << 1 | (*src & 0x001F);
*dst++ = pixel;
*dst++ = pixel;
src++;
}
dst_pixels += dst_pitch;
if (i & 1) {
src_pixels += src_pitch;
}
}
break;
case 15:
for (int i = 0; i < blit_height; i++) {
uint16_t* src = (uint16_t*)src_pixels;
uint16_t* dst = (uint16_t*)dst_pixels;
for (int j = 0; j < blit_width; j++) {
uint16_t pixel = *src;
*dst++ = pixel;
*dst++ = pixel;
src++;
}
dst_pixels += dst_pitch;
if (i & 1) {
src_pixels += src_pitch;
}
}
break;
}
#else
BitmapRef dst = Bitmap::Create(
dst_surf->pixels,
dst_surf->w,
Expand All @@ -437,6 +521,7 @@ void SdlUi::Blit2X(Bitmap const& src, SDL_Surface* dst_surf) {
PF::NoAlpha));

dst->Blit2x(dst->GetRect(), src, src.GetRect());
#endif

if (SDL_MUSTLOCK(dst_surf)) SDL_UnlockSurface(dst_surf);
}
Expand Down
2 changes: 1 addition & 1 deletion src/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
# define SUPPORT_JOYSTICK_AXIS
#endif

#ifdef GEKKO
#if defined(GEKKO) || defined(__MORPHOS__) || defined(__amigaos4__)
# include "stdint.h"

# define WORDS_BIGENDIAN
Expand Down
2 changes: 2 additions & 0 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ std::string Utils::EncodeUTF(const std::u32string& str) {
return result;
}

#ifndef __amigaos4__
template<size_t WideSize>
static std::wstring ToWideStringImpl(const std::string&);
#if __SIZEOF_WCHAR_T__ == 4 || __WCHAR_MAX__ > 0x10000
Expand Down Expand Up @@ -301,6 +302,7 @@ std::string FromWideStringImpl<2>(const std::wstring& str) {
std::string Utils::FromWideString(const std::wstring& str) {
return FromWideStringImpl<sizeof(wchar_t)>(str);
}
#endif

int Utils::PositiveModulo(int i, int m) {
return (i % m + m) % m;
Expand Down
2 changes: 2 additions & 0 deletions src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ namespace Utils {
*/
std::string EncodeUTF(const std::u32string& str);

#ifndef __amigaos4__
/**
* Converts UTF-8 string to std::wstring.
*
Expand All @@ -107,6 +108,7 @@ namespace Utils {
* @return the converted string.
*/
std::string FromWideString(const std::wstring& str);
#endif

/**
* Converts arithmetic types to a string.
Expand Down

0 comments on commit 50fc262

Please sign in to comment.