Skip to content

Commit

Permalink
N64DD Support via Subsystems
Browse files Browse the repository at this point in the history
  • Loading branch information
m4xw committed Feb 18, 2020
1 parent 761dde7 commit a3091c9
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 10 deletions.
5 changes: 5 additions & 0 deletions custom/GLideN64/GLideN64_libretro.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,9 @@ extern uint32_t OverscanTop;
extern uint32_t OverscanLeft;
extern uint32_t OverscanRight;
extern uint32_t OverscanBottom;

// Others
#define RETRO_MEMORY_DD 0x100 + 1
#define RETRO_GAME_TYPE_DD 1

#endif
62 changes: 60 additions & 2 deletions libretro/libretro.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ uint32_t retro_screen_width = 320;
uint32_t retro_screen_height = 240;
float retro_screen_aspect = 4.0 / 3.0;

char* retro_dd_path_img;
char* retro_dd_path_rom;

uint32_t bilinearMode = 0;
uint32_t EnableHWLighting = 0;
uint32_t CorrectTexrectCoords = 0;
Expand Down Expand Up @@ -406,11 +409,65 @@ void retro_set_audio_sample_batch(retro_audio_sample_batch_t cb) { audio_batch_c
void retro_set_input_poll(retro_input_poll_t cb) { poll_cb = cb; }
void retro_set_input_state(retro_input_state_t cb) { input_cb = cb; }

bool retro_load_game_special(unsigned game_type, const struct retro_game_info *info, size_t num_info)
{
if(retro_dd_path_img)
{
free(retro_dd_path_img);
retro_dd_path_img = NULL;
}

if(retro_dd_path_rom)
{
free(retro_dd_path_rom);
retro_dd_path_rom = NULL;
}

switch(game_type)
{
case RETRO_GAME_TYPE_DD:
if(num_info == 1)
{
retro_dd_path_img = strdup(info[0].path);
}
else if(num_info == 2)
{
retro_dd_path_img = strdup(info[0].path);
retro_dd_path_rom = strdup(info[1].path);
} else {
return false;
}

printf("Loading %s...\n", info[0].path);
load_file(info[1].path, (void**)&info[1].data, &info[1].size);
return retro_load_game(&info[1]);
default:
return false;
}

return false;
}

void retro_set_environment(retro_environment_t cb)
{
environ_cb = cb;

static const struct retro_subsystem_memory_info memory_info[] = {
{ "srm", RETRO_MEMORY_DD },
};

static const struct retro_subsystem_rom_info dd_roms[] = {
{ "Disk", "ndd", true, false, true, memory_info, 1 },
{ "Cartridge", "n64|v64|z64|bin|u1", true, false, true, NULL, 0 },
};

static const struct retro_subsystem_info subsystems[] = {
{ "N64 Disk Drive", "ndd", dd_roms, 2, RETRO_GAME_TYPE_DD },
{}
};

environ_cb(RETRO_ENVIRONMENT_SET_SUBSYSTEM_INFO, (void*)subsystems);

setup_variables();
}

Expand All @@ -427,7 +484,7 @@ void retro_get_system_info(struct retro_system_info *info)
#define GIT_VERSION " git"
#endif
info->library_version = "1.0" GIT_VERSION;
info->valid_extensions = "n64|v64|z64|bin|u1|ndd";
info->valid_extensions = "n64|v64|z64|bin|u1";
info->need_fullpath = false;
info->block_extract = false;
}
Expand Down Expand Up @@ -1132,6 +1189,7 @@ void *retro_get_memory_data(unsigned type)
switch (type)
{
case RETRO_MEMORY_SYSTEM_RAM: return g_dev.rdram.dram;
case RETRO_MEMORY_DD:
case RETRO_MEMORY_SAVE_RAM: return &saved_memory;
}
return NULL;
Expand All @@ -1142,6 +1200,7 @@ size_t retro_get_memory_size(unsigned type)
switch (type)
{
case RETRO_MEMORY_SYSTEM_RAM: return RDRAM_MAX_SIZE;
case RETRO_MEMORY_DD:
case RETRO_MEMORY_SAVE_RAM: return sizeof(saved_memory);
}
return 0;
Expand Down Expand Up @@ -1205,7 +1264,6 @@ void retro_set_controller_port_device(unsigned in_port, unsigned device) {
}

unsigned retro_api_version(void) { return RETRO_API_VERSION; }
bool retro_load_game_special(unsigned game_type, const struct retro_game_info *info, size_t num_info) { return false; }

void retro_cheat_reset(void)
{
Expand Down
38 changes: 30 additions & 8 deletions mupen64plus-core/src/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,12 @@
#include <sys/stat.h>
#endif

#ifdef __LIBRETRO__
#include <file/file_path.h>
#include "../../../libretro/libretro_memory.h"
#include "../../../custom/GLideN64/GLideN64_libretro.h"
extern retro_environment_t environ_cb;
#endif // __LIBRETRO__

#ifdef DBG
#include "debugger/dbg_debugger.h"
Expand Down Expand Up @@ -703,6 +707,18 @@ static void load_dd_rom(uint8_t* rom, size_t* rom_size)
? NULL
: g_media_loader.get_dd_rom(g_media_loader.cb_data);

char* sys_pathname;
environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &sys_pathname);
char* pathname = (char*)malloc(2048);
strncpy(pathname, sys_pathname, 2048 - 1);
if (pathname[(strlen(pathname)-1)] != '/' && pathname[(strlen(pathname)-1)] != '\\')
strcat(pathname, path_default_slash());
strcat(pathname, "Mupen64plus");
strcat(pathname, path_default_slash());
strcat(pathname, "IPL.n64");

dd_ipl_rom_filename = pathname;

if ((dd_ipl_rom_filename == NULL) || (strlen(dd_ipl_rom_filename) == 0)) {
goto no_dd;
}
Expand Down Expand Up @@ -757,14 +773,19 @@ static void load_dd_rom(uint8_t* rom, size_t* rom_size)
*rom_size = 0;
}

extern char* retro_dd_path_img;
extern char* retro_dd_path_rom;
static void load_dd_disk(struct file_storage* dd_disk, const struct storage_backend_interface** dd_idisk)
{
const char* format_desc;
/* ask the core loader for DD disk filename */
char* dd_disk_filename = (g_media_loader.get_dd_disk == NULL)
? NULL
? retro_dd_path_img
: g_media_loader.get_dd_disk(g_media_loader.cb_data);

printf("Load DD disk %s\n", dd_disk_filename);
fflush(stdout);

/* handle the no disk case */
if (dd_disk_filename == NULL || strlen(dd_disk_filename) == 0) {
goto no_disk;
Expand Down Expand Up @@ -805,12 +826,13 @@ static void load_dd_disk(struct file_storage* dd_disk, const struct storage_back
} break;

default:
format_desc = "ERR";
DebugMessage(M64MSG_ERROR, "Invalid DD Disk size %u.", (uint32_t) dd_disk->size);
close_file_storage(dd_disk);
goto no_disk;
}

DebugMessage(M64MSG_INFO, "DD Disk: %s - %zu - %s",
DebugMessage(M64MSG_INFO, "DD Disk: %s - %u - %s",
dd_disk->filename,
dd_disk->size,
format_desc);
Expand Down Expand Up @@ -973,6 +995,11 @@ extern audio_plugin_functions dummy_audio;
unsigned int emumode;

uint32_t rdram_size;
struct file_storage eep;
struct file_storage fla;
struct file_storage sra;
struct file_storage dd_disk;
size_t dd_rom_size;

m64p_error main_run(void)
{
Expand All @@ -982,11 +1009,6 @@ m64p_error main_run(void)
int si_dma_duration;
int no_compiled_jump;
int randomize_interrupt;
struct file_storage eep;
struct file_storage fla;
struct file_storage sra;
size_t dd_rom_size;
struct file_storage dd_disk;
struct audio_out_backend_interface audio_out_backend_libretro;

int control_ids[GAME_CONTROLLERS_COUNT];
Expand Down

0 comments on commit a3091c9

Please sign in to comment.