Skip to content

Instantly share code, notes, and snippets.

View leiradel's full-sized avatar

Andre Leiradella leiradel

View GitHub Profile
@leiradel
leiradel / tap.hexpat
Last active March 14, 2024 16:30
ZX Spectrum TAP pattern for ImHex
#pragma description ZX Spectrum TAP
#pragma endian little
import std.mem;
enum Flag: u8 {
Header = 0,
Body = 255
};
#include <inttypes.h>
#include <vector>
class Resumable {
public:
void resume(unsigned const continuationToken) { (void)continuationToken; }
};
template<typename T>
class Bus {
@leiradel
leiradel / spectrum.lua
Created January 31, 2021 22:44
Lua script for the 48K Libretro core in HC
local hc = require 'hc'
hc.control:addConsole('ZX Spectrum (Chips)', {
onConsoleLoaded = function()
local path = hc.config:getCoresPath() .. 'zx48k_libretro.' .. hc.soExtension
hc.control:loadCore(path)
end,
onGameLoaded = function()
local map = hc.config:getMemoryMap()
@leiradel
leiradel / autorun.lua
Created January 31, 2021 22:42
Auto-run Lua script for HC
local hc = require 'hc'
local lfs = require 'lfs'
local logger, config = hc.logger, hc.config
local coresPath = config:getCoresPath()
logger:info('Looking for Lua scripts in "%s"', coresPath)
for file in lfs.dir(coresPath) do
if file:sub(-4, -1) == '.lua' then

Save states

Despite having an API that creates save state data into an user-provided buffer, some Libretro cores still create additional data as files. Additionally, Libretro save states don't feature a screenshot of the video frame buffer at the time the save state is created, making it impossible to preview the save state or restore the frame buffer when the save state is loaded back.

We also want to save data to completely restore the emulation state, like the core name and version, core options values, and any other data needed by the application.

To make it easier to put all this data into a single file, we'll use the RIFF format. RIFF is a chunked format, allowing us to save everything we need in an organized way.

All integers and float-point numbers are written in little-endian, and strings are null-terminated.

#ifndef LRCPP_COMPONENTS_H__
#define LRCPP_COMPONENTS_H__
#include "libretro.h"
namespace lrcpp {
/**
* A logger component for Core instances.
*/
class Logger {
header {
#include "Core.h"
#include <string>
typedef const std::string const_string;
}
fsm CoreFsm {
class lrcpp::Core as ctx;
@leiradel
leiradel / modules.c
Created February 29, 2020 19:44
Use a package searcher to static link LuaSocket into an executable.
#include <stddef.h>
#include <string.h>
#include <lua.h>
#include <lauxlib.h>
#include "luasocket/src/ftp.lua.h"
#include "luasocket/src/headers.lua.h"
#include "luasocket/src/http.lua.h"
#include "luasocket/src/ltn12.lua.h"
-- Based off https://github.com/EmmanuelOga/easing
-- For all easing functions:
-- t = elapsed time between 0 and 1
-- b = begin
-- c = end
local pow = math.pow
local sin = math.sin
local cos = math.cos
@leiradel
leiradel / main.cpp
Created August 7, 2019 21:22
Dear ImGui docking bug
#include <imgui.h>
#include <imgui_impl_sdl.h>
#include <imgui_impl_opengl2.h>
#include <SDL.h>
#include <SDL_opengl.h>
#include <string>
class Application