first FunKey-S working version

This commit is contained in:
Jack 2021-03-12 17:13:36 +01:00
parent 6c2e1a7167
commit 01a3a59b87
9 changed files with 119 additions and 32 deletions

1
.gitignore vendored
View File

@ -1,6 +1,7 @@
*.o
projects/vs2017/libs/**
projects/opendingux/**
projects/funkey/**
**/.vs/**
**/Debug/**
**/Release/**

View File

@ -4,6 +4,7 @@ project (retro8)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/projects/cmake")
option(FUNKEY_S "Building for FunKey-S" OFF)
option(OPENDINGUX "Build on opendingux toolchain" OFF)
if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
@ -14,12 +15,21 @@ if(OPENDINGUX)
set(CMAKE_CXX_COMPILER "$ENV{CROSS}g++" CACHE PATH "" FORCE)
set(CMAKE_C_COMPILER "$ENV{CROSS}gcc" CACHE PATH "" FORCE)
set(CMAKE_SYSROOT "/opt/gcw0-toolchain/usr/mipsel-gcw0-linux-uclibc/sysroot")
elseif(FUNKEY_S)
add_definitions(-DFUNKEY_S)
endif()
find_package(SDL2 REQUIRED)
if (FUNKEY_S)
find_package(SDL REQUIRED)
include_directories(${SDL_INCLUDE_DIR})
else()
find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIR})
endif()
add_compile_options(-Wno-unused-parameter -Wno-missing-field-initializers
-Wno-sign-compare -Wno-parentheses -Wno-unused-variable
-Wno-sign-compare -Wno-parentheses -Wno-unused-variable -Wno-char-subscripts
)
add_compile_options(-g -O2 -W -Wall -Wextra)
@ -34,8 +44,6 @@ else()
endif()
include_directories(src)
include_directories(${SDL2_INCLUDE_DIR})
set(SRC_ROOT "${CMAKE_SOURCE_DIR}/src")
file(GLOB SOURCES_ROOT "${SRC_ROOT}/*.cpp")
@ -48,4 +56,8 @@ set(SOURCES ${SOURCES_ROOT} ${SOURCES_VIEWS} ${SOURCES_IO} ${SOURCES_VM} ${SOURC
add_executable(retro8 ${SOURCES})
target_link_libraries(retro8 ${SDL2_LIBRARY})
if (SDL_FOUND)
target_link_libraries(retro8 ${SDL_LIBRARY})
else()
target_link_libraries(retro8 ${SDL2_LIBRARY})
endif()

View File

@ -0,0 +1,10 @@
[Desktop Entry]
Type=Emulator
Name=retro-8
Comment=PICO-8 Emulator
Terminal=false
StartupNotify=true
Exec=retro8 %f
Icon=icon
Categories=emulators;
X-OD-Filter=.png,.p8

8
projects/build_opk_funkey.sh Executable file
View File

@ -0,0 +1,8 @@
rm -rf opk
mkdir -p opk
cp funkey/retro8 opk
cp vs2017/retro8/api.lua opk
cp ../data/default.funkey-s.desktop opk
cp ../data/icon.png opk
mksquashfs opk retro8.opk -all-root -noappend -no-exports -no-xattrs -no-progress > /dev/null
# rm -rf opk

View File

@ -15,12 +15,6 @@
#define PLATFORM PLATFORM_WIN32
#endif
#if defined(_WIN32) && !defined(__LIBRETRO__)
#define LOGD(x , ...) printf(x"\n", __VA_ARGS__)
#else
#define LOGD(...)
#endif
#define MOUSE_ENABLED false
#define TEST_MODE false
@ -32,8 +26,8 @@ static constexpr int SCREEN_HEIGHT = 240;
#if PLATFORM != PLATFORM_LIBRETRO
#include "SDL.h"
#define LOGD(x , ...) printf(x"\n", __VA_ARGS__)
#include "SDL.h"
#define LOGD(x , ...) printf(x"\n", ## __VA_ARGS__)
#if PLATFORM == PLATFORM_WIN32
@ -70,8 +64,8 @@ static constexpr int SCREEN_HEIGHT = 240;
static constexpr auto KEY_ACTION1_2 = SDLK_SPACE; // Y
static constexpr auto KEY_ACTION2_2 = SDLK_LSHIFT; // X
static constexpr auto KEY_MUTE = SDLK_UNKNOWN;
static constexpr auto KEY_PAUSE = SDLK_UNKNOWN;
static constexpr auto KEY_MUTE = 0xffff;
static constexpr auto KEY_PAUSE = 0xffff + 1;
static constexpr auto KEY_NEXT_SCALER = SDLK_TAB; // L
@ -90,13 +84,13 @@ static constexpr int SCREEN_HEIGHT = 240;
static constexpr auto KEY_ACTION1_2 = SDLK_y; // Y
static constexpr auto KEY_ACTION2_2 = SDLK_x; // X
static constexpr auto KEY_MUTE = SDLK_UNKNOWN;
static constexpr auto KEY_PAUSE = SDLK_UNKNOWN;
static constexpr auto KEY_MUTE = 0xffff;
static constexpr auto KEY_PAUSE = 0xffff + 1;
static constexpr auto KEY_NEXT_SCALER = SDLK_h; // L
static constexpr auto KEY_MENU = SDLK_s;
static constexpr auto KEY_EXIT = SDLK_UNKNOWN;
static constexpr auto KEY_EXIT = 0xffff + 2;
#endif
@ -104,4 +98,4 @@ static constexpr int SCREEN_HEIGHT = 240;
#define LOGD(x, ...)
#endif
#endif

View File

@ -1,6 +1,7 @@
#include "stegano.h"
#include <cassert>
#include <algorithm>
using namespace retro8;
using namespace io;
@ -79,7 +80,7 @@ private:
public:
PXADecoder(const uint8_t* data, size_t expected) : data(data), b(0), o(0), expected(expected)
{
{
/* initalize mapping, each value to itself */
//TODO
for (size_t i = 0; i < m.size(); ++i)
@ -104,14 +105,14 @@ public:
uint8_t index = readBits(4 + unary) + (unaryMask << 4);
code += m[index];
moveToFront(index);
moveToFront(index);
}
/* copy section */
else
{
/* read offset */
int32_t offsetBits;
if (readBit())
offsetBits = readBit() ? 5 : 10;
else
@ -119,7 +120,7 @@ public:
auto offset = readBits(offsetBits) + 1;
/* special hacky case in which bytes are directly emitted without
/* special hacky case in which bytes are directly emitted without
affecting move-to-front
*/
if (offsetBits == 10 && offset == 1)
@ -163,7 +164,7 @@ void Stegano::load20(const PngData& data, Machine& m)
{
auto* d = data.data;
size_t o = RAW_DATA_LENGTH + MAGIC_LENGTH;
size_t decompressedLength = assembleByte(d[o++]) << 8 | assembleByte(d[o++]);
size_t compressedLength = assembleByte(d[o++]) << 8 | assembleByte(d[o++]);
compressedLength -= HEADER_20_LENGTH; /* subtract header length */

View File

@ -93,12 +93,12 @@ retro8::io::PngData loadPng(const std::string& path)
size_t length = fl.tellg();
char* bdata = new char[length];
fl.seekg(0, std::ios::beg);
fl.read(bdata, length);
fl.close();
std::vector<uint8_t> out;
unsigned long width, height;
auto result = Platform::loadPNG(out, width, height, (uint8_t*)bdata, length, true);
@ -204,7 +204,7 @@ void GameView::render()
loader.loadFile(_path, machine);
manager->setPngCartridge(nullptr);
}
machine.memory().backupCartridge();
int32_t fps = machine.code().require60fps() ? 60 : 30;
@ -255,7 +255,7 @@ void GameView::render()
dest = { 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT };
manager->blitToScreen(_output, dest);
if (_showFPS)
{
char buffer[16];
@ -415,6 +415,9 @@ void GameView::handleKeyboardEvent(const SDL_Event& event)
if (event.type == SDL_KEYDOWN)
manager->exit();
break;
default:
break;
}
}
@ -449,4 +452,4 @@ GameView::~GameView()
}
uint32_t Platform::getTicks() { return SDL_GetTicks(); }
uint32_t Platform::getTicks() { return SDL_GetTicks(); }

View File

@ -9,6 +9,7 @@ bool SDL<EventHandler, Renderer>::init()
return false;
}
SDL_ShowCursor(0);
SDL_EnableKeyRepeat(0, 0);
#if defined(WINDOW_SCALE)
@ -37,10 +38,67 @@ void SDL<EventHandler, Renderer>::loop()
}
}
static constexpr auto RES_HW_SCREEN_VERTICAL = 240;
static constexpr auto RES_HW_SCREEN_HORIZONTAL = 240;
static void scale_NN_AllowOutOfScreen(SDL_Surface *src_surface, SDL_Surface *dst_surface, int new_w, int new_h)
{
/// Sanity check
if (src_surface->format->BytesPerPixel != dst_surface->format->BytesPerPixel) {
printf("Error in %s, src_surface bpp: %d != dst_surface bpp: %d", __func__,
src_surface->format->BytesPerPixel, dst_surface->format->BytesPerPixel);
return;
}
int BytesPerPixel = src_surface->format->BytesPerPixel;
int w1 = src_surface->w;
//int h1=src_surface->h;
int w2 = new_w;
int h2 = new_h;
int x_ratio = (int)((src_surface->w << 16) / w2);
int y_ratio = (int)((src_surface->h << 16) / h2);
int x2, y2;
/// --- Compute padding for centering when out of bounds ---
int y_padding = (RES_HW_SCREEN_VERTICAL - new_h) / 2;
int x_padding = 0;
if (w2 > RES_HW_SCREEN_HORIZONTAL) {
x_padding = (w2 - RES_HW_SCREEN_HORIZONTAL) / 2 + 1;
}
int x_padding_ratio = x_padding * w1 / w2;
//printf("src_surface->h=%d, h2=%d\n", src_surface->h, h2);
for (int i = 0; i < h2; i++)
{
if (i >= RES_HW_SCREEN_VERTICAL) {
continue;
}
uint8_t* t = (uint8_t*)(dst_surface->pixels) + ((i + y_padding) * ((w2 > RES_HW_SCREEN_HORIZONTAL) ? RES_HW_SCREEN_HORIZONTAL : w2))*BytesPerPixel;
y2 = ((i*y_ratio) >> 16);
uint8_t* p = (uint8_t*)(src_surface->pixels) + (y2*w1 + x_padding_ratio)*BytesPerPixel;
int rat = 0;
for (int j = 0; j < w2; j++)
{
if (j >= RES_HW_SCREEN_HORIZONTAL) {
continue;
}
x2 = (rat >> 16);
//*t++ = p[x2];
memcpy(t, &p[x2*BytesPerPixel], BytesPerPixel);
t += BytesPerPixel;
rat += x_ratio;
}
}
}
template<typename EventHandler, typename Renderer>
void SDL<EventHandler, Renderer>::blitToScreen(const Surface& surface, const SDL_Rect& rect)
{
SDL_BlitSurface(surface.surface, nullptr, _screen, const_cast<SDL_Rect*>(&rect));
scale_NN_AllowOutOfScreen(surface.surface, _screen, 256, 256);
//SDL_BlitSurface(surface.surface, nullptr, _screen, const_cast<SDL_Rect*>(&rect));
}
template<typename EventHandler, typename Renderer>
@ -69,7 +127,7 @@ template<typename EventHandler, typename Renderer>
inline void SDL<EventHandler, Renderer>::blit(const Surface& surface, const SDL_Rect& from, int dx, int dy)
{
SDL_Rect to = { dx, dy, from.w, from.h };
SDL_BlitSurface(surface.surface, from, _screen, &to);
SDL_BlitSurface(surface.surface, &from, _screen, &to);
}
template<typename EventHandler, typename Renderer>
@ -115,4 +173,4 @@ inline void SDL<EventHandler, Renderer>::release(const Surface& surface)
inline static SDL_Rect SDL_MakeRect(int x, int y, int w, int h) { return { (Sint16)x, (Sint16)y, (Uint16)w, (Uint16)h }; }
#endif
#endif