Skip to content

Commit

Permalink
retro: add a libretro skeleton.
Browse files Browse the repository at this point in the history
  • Loading branch information
samhocevar committed Jun 22, 2020
1 parent 5e8cf74 commit e2048a1
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,9 @@
branch = task/msvc-support
update = merge
upstream = https://github.com/horhof/quickjs

[submodule "libretro-common"]
path = src/3rdparty/libretro-common
url = https://github.com/libretro/libretro-common
branch = master
update = merge
1 change: 1 addition & 0 deletions src/3rdparty/libretro-common
Submodule libretro-common added at 44c1cd
46 changes: 43 additions & 3 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@
include $(top_srcdir)/src/3rdparty/lolengine/build/autotools/common.am

bin_PROGRAMS = ../zepto8 ../z8dev ../z8tool ../z8lua
libretro_LTLIBRARIES = libretro-zepto8.la
noinst_LIBRARIES = $(static_libs)

static_libs = libzepto8.a libz8lua.a libquickjs.a

libzepto8_adir = $(datarootdir)/zepto8
___z8devdir = $(datarootdir)/zepto8
libzepto8_adir = $(datarootdir)/zepto8
libretrodir = $(datarootdir)/libretro

#
# zepto8: the emulator
#

___zepto8_SOURCES = \
zepto8.cpp \
Expand All @@ -25,6 +31,20 @@ endif

EXTRA_DIST += zepto8.vcxproj

#
# libretro-zepto8: RetroArch core
#

libretro_zepto8_la_SOURCES = \
libretro.cpp
libretro_zepto8_la_DEPENDENCIES = $(static_libs) @LOL_DEPS@
libretro_zepto8_la_CPPFLAGS = -I3rdparty/libretro-common/include \
$(AM_CPPFLAGS)

#
# z8dev: the IDE prototype
#

# FIXME: move player.cpp / player.h into a separate library?
___z8dev_SOURCES = \
z8dev.cpp \
Expand Down Expand Up @@ -111,6 +131,10 @@ endif

EXTRA_DIST += $(___z8dev_DATA) z8dev.vcxproj

#
# z8tool: multi purpose tool
#

___z8tool_SOURCES = \
z8tool.cpp \
splore.cpp splore.h \
Expand All @@ -130,6 +154,10 @@ ___z8tool_DEPENDENCIES = $(static_libs) @LOL_DEPS@
EXTRA_DIST += zlib/deflate.c zlib/trees.c
EXTRA_DIST += z8tool.vcxproj

#
# z8lua: our modified Lua interpreter
#

___z8lua_SOURCES = \
3rdparty/z8lua/lua.c dummy.cpp \
$(NULL)
Expand All @@ -139,6 +167,10 @@ ___z8lua_DEPENDENCIES = libz8lua.a

EXTRA_DIST += z8lua.vcxproj

#
# libzepto8: core library used by all programs
#

libzepto8_a_SOURCES = \
zepto8.h \
vm.cpp \
Expand All @@ -163,6 +195,10 @@ libzepto8_a_CPPFLAGS = $(AM_CPPFLAGS)

EXTRA_DIST += $(libzepto8_a_DATA) libzepto8.vcxproj

#
# libz8lua: z8lua library used by all programs
#

libz8lua_a_SOURCES = \
3rdparty/z8lua/lapi.c 3rdparty/z8lua/lcode.c 3rdparty/z8lua/ldebug.c \
3rdparty/z8lua/ldo.c 3rdparty/z8lua/ldump.c 3rdparty/z8lua/lfunc.c \
Expand Down Expand Up @@ -193,6 +229,12 @@ lua_cflags += -DLUA_USE_READLINE
lua_ldflags += -lreadline
endif

EXTRA_DIST += libz8lua.vcxproj

#
# libquickjs: QuickJS library used by all programs
#

libquickjs_a_SOURCES = \
3rdparty/quickjs/quickjs.c 3rdparty/quickjs/quickjs.h \
3rdparty/quickjs/quickjs-atom.h 3rdparty/quickjs/quickjs-opcode.h \
Expand All @@ -210,5 +252,3 @@ libquickjs_a_CPPFLAGS = \

EXTRA_DIST += libquickjs.vcxproj

EXTRA_DIST += libz8lua.vcxproj

80 changes: 80 additions & 0 deletions src/libretro.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
//
// ZEPTO-8 — Fantasy console emulator
//
// Copyright © 2016—2020 Sam Hocevar <sam@hocevar.net>
//
// This program is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it
// and/or modify it under the terms of the Do What the Fuck You Want
// to Public License, Version 2, as published by the WTFPL Task Force.
// See http://www.wtfpl.net/ for more details.
//

#if HAVE_CONFIG_H
# include "config.h"
#endif

#include <lol/engine.h> // lol::input
#include <lol/transform> // lol::mat4
#include <lol/color> // lol::color

#include "player.h"

#include "zepto8.h"
#include "pico8/vm.h"
#include "pico8/pico8.h"
#include "raccoon/vm.h"

extern "C"
{
#include "libretro.h"
}

namespace z8
{

extern "C" void retro_get_system_info(struct retro_system_info *info)
{
memset(info, 0, sizeof(*info));
info->library_name = "zepto8";
info->library_version = "0.0.0";
info->valid_extensions = "p8|p8.png";
info->need_fullpath = true; // we load our own carts for now
}

extern "C" void retro_get_system_av_info(struct retro_system_av_info *info)
{
memset(info, 0, sizeof(*info));
info->geometry.base_width = info->geometry.max_width = 128;
info->geometry.base_height = info->geometry.max_height = 128;
info->geometry.aspect_ratio = 1.f;
info->timing.fps = 60.f;
info->timing.sample_rate = 44100.f;
}

extern "C" void retro_set_environment(retro_environment_t cb)
{
// We can run without a cartridge
bool no_rom = true;
cb(RETRO_ENVIRONMENT_SET_SUPPORT_NO_GAME, &no_rom);
}

extern "C" bool retro_load_game(const struct retro_game_info *info)
{
// TODO: load cart
(void)info;
return true;
}

extern "C" void retro_unload_game()
{
}

extern "C" void retro_run(void)
{
// TODO: vm->step(), audio_cb(), video_cb()
}


} // namespace z8

0 comments on commit e2048a1

Please sign in to comment.