RetroQUEST/scripts/libretro_loader.gd

60 lines
1.8 KiB
GDScript3
Raw Permalink Normal View History

2024-12-10 12:59:49 +00:00
extends Node
2024-12-13 03:19:48 +00:00
@onready var sub_viewport = $room/SubViewport
@onready var texture_rect = $room/SubViewport/TextureRect
2024-12-10 12:59:49 +00:00
func start_emulation(core_name: String, rom_path: String) -> bool:
print("[libretro_loader] Starting emulation with core: ", core_name, ", ROM: ", rom_path)
2024-12-10 12:59:49 +00:00
# Load the core
if not RetroHost.load_core(core_name):
push_error("[libretro_loader] Failed to load core: " + core_name)
2024-12-13 03:19:48 +00:00
return false
print("[libretro_loader] Core path: ", core_name)
2024-12-27 03:00:53 +00:00
print("[libretro_loader] Core loaded successfully.")
2024-12-10 12:59:49 +00:00
# Open the ROM file
2024-12-13 03:19:48 +00:00
var file = FileAccess.open(rom_path, FileAccess.READ)
if not file:
2024-12-27 03:00:53 +00:00
push_error("[libretro_loader] Failed to open ROM: " + rom_path)
2024-12-13 03:19:48 +00:00
return false
print("[libretro_loader] ROM path: ", rom_path)
2024-12-10 12:59:49 +00:00
2024-12-13 03:19:48 +00:00
var rom_data = file.get_buffer(file.get_length())
file.close()
2024-12-27 01:53:34 +00:00
print("[libretro_loader] ROM data loaded successfully.")
2024-12-10 12:59:49 +00:00
# Pass ROM data to the core using RetroHost
var game_info = {}
game_info["data"] = rom_data
game_info["size"] = rom_data.size()
2024-12-13 03:19:48 +00:00
if not RetroHost.load_game(game_info):
push_error("[libretro_loader] Failed to load ROM into the core.")
2024-12-13 03:19:48 +00:00
return false
print("[libretro_loader] Core and ROM loaded successfully.")
2024-12-13 03:19:48 +00:00
return true
2024-12-10 12:59:49 +00:00
func _process(delta):
2024-12-13 03:19:48 +00:00
"""
Run the core and update the framebuffer.
2024-12-13 03:19:48 +00:00
"""
RetroHost.run()
2024-12-13 03:19:48 +00:00
var frame_buffer = RetroHost.get_frame_buffer()
if frame_buffer:
var img_tex = ImageTexture.create_from_image(frame_buffer)
texture_rect.texture = img_tex
2024-12-13 03:19:48 +00:00
func _ready():
"""
Initialize and start emulation.
2024-12-13 03:19:48 +00:00
"""
print("[libretro_loader] _ready: Initializing...")
var success = start_emulation("genesis_plus_gx_libretro", "res://roms/megadrive/Sonic the Hedgehog.bin")
2024-12-27 03:00:53 +00:00
if success:
print("[libretro_loader] Emulation started successfully.")
else:
print("[libretro_loader] Failed to start emulation.")