mirror of
https://github.com/n64dev/cen64.git
synced 2024-06-23 14:33:13 -04:00
transfer pak: parse command line and load tpak ROM/saves
This commit is contained in:
parent
cdd3c44aea
commit
799b2af628
23
cen64.c
23
cen64.c
|
@ -200,6 +200,29 @@ cen64_cold int load_paks(struct controller *controller) {
|
|||
if (created)
|
||||
controller_pak_format(controller[i].mempak_save.ptr);
|
||||
}
|
||||
|
||||
else if (controller[i].pak == PAK_TRANSFER) {
|
||||
if (controller[i].tpak_rom_path != NULL) {
|
||||
if (open_rom_file(controller[i].tpak_rom_path,
|
||||
&controller[i].tpak_rom)) {
|
||||
printf("Can't open transfer pak ROM\n");
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
printf("No ROM supplied for transfer pak.\n");
|
||||
printf("The game will run but probably won't do anything interest\n");
|
||||
}
|
||||
if (controller[i].tpak_save_path != NULL) {
|
||||
if (open_gb_save(controller[i].tpak_save_path,
|
||||
&controller[i].tpak_save)) {
|
||||
printf("Can't open transfer pak save\n");
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
printf("No save supplied for transfer pak. Just FYI.\n");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -151,6 +151,8 @@ int parse_options(struct cen64_options *options, int argc, const char *argv[]) {
|
|||
int parse_controller_options(const char *str, int *num, struct controller *opt) {
|
||||
char *token;
|
||||
char mempak_path[4096];
|
||||
char tpak_rom_path[4096] = { 0, };
|
||||
char tpak_save_path[4096] = { 0, };
|
||||
char *opt_string = strdup(str);
|
||||
|
||||
if (opt_string == NULL) {
|
||||
|
@ -165,8 +167,14 @@ int parse_controller_options(const char *str, int *num, struct controller *opt)
|
|||
;
|
||||
else if (strcmp(token, "pak=rumble") == 0)
|
||||
opt->pak = PAK_RUMBLE;
|
||||
else if (strcmp(token, "pak=transfer") == 0)
|
||||
opt->pak = PAK_TRANSFER;
|
||||
else if (sscanf(token, "mempak=%4095s", mempak_path) == 1)
|
||||
opt->pak = PAK_MEM;
|
||||
else if (sscanf(token, "tpak_rom=%4095s", tpak_rom_path) == 1)
|
||||
opt->pak = PAK_TRANSFER;
|
||||
else if (sscanf(token, "tpak_save=%4095s", tpak_save_path) == 1)
|
||||
opt->pak = PAK_TRANSFER;
|
||||
else {
|
||||
printf("Unrecognized controller option: %s\n", token);
|
||||
goto err;
|
||||
|
@ -182,7 +190,14 @@ int parse_controller_options(const char *str, int *num, struct controller *opt)
|
|||
|
||||
--*num; // internally it's used as an index into an array
|
||||
mempak_path[4095] = '\0';
|
||||
opt->mempak_path = strdup(mempak_path);
|
||||
if (strlen(mempak_path) > 0)
|
||||
opt->mempak_path = strdup(mempak_path);
|
||||
tpak_rom_path[4095] = '\0';
|
||||
if (strlen(tpak_rom_path) > 0)
|
||||
opt->tpak_rom_path = strdup(tpak_rom_path);
|
||||
tpak_save_path[4095] = '\0';
|
||||
if (strlen(tpak_save_path) > 0)
|
||||
opt->tpak_save_path = strdup(tpak_save_path);
|
||||
opt->present = 1;
|
||||
|
||||
free(opt_string);
|
||||
|
|
|
@ -32,6 +32,7 @@ struct save_file {
|
|||
|
||||
cen64_cold int close_save_file(const struct save_file *file);
|
||||
cen64_cold int open_save_file(const char *path, size_t size, struct save_file *file, int *created);
|
||||
cen64_cold int open_gb_save(const char *path, struct save_file *file);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ int open_save_file(const char *path, size_t size, struct save_file *file, int *c
|
|||
// Get the file's size, map it into the address space.
|
||||
if (fstat(fd, &sb) == -1)
|
||||
return -1;
|
||||
|
||||
|
||||
if ((size_t)sb.st_size != size)
|
||||
if (ftruncate(fd, size) == -1) {
|
||||
close(fd);
|
||||
|
@ -62,3 +62,30 @@ int open_save_file(const char *path, size_t size, struct save_file *file, int *c
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Opening a game boy save: don't set a specific size and don't create
|
||||
// the file if it doesn't exist
|
||||
int open_gb_save(const char *path, struct save_file *file) {
|
||||
struct stat sb;
|
||||
void *ptr;
|
||||
int fd;
|
||||
|
||||
// try to open the file
|
||||
if ((fd = open(path, O_RDWR, 0666)) == -1)
|
||||
return -1;
|
||||
|
||||
// Get the file's size, map it into the address space.
|
||||
if (fstat(fd, &sb) == -1)
|
||||
return -1;
|
||||
|
||||
if ((ptr = mmap(NULL, sb.st_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0)) == MAP_FAILED) {
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
file->ptr = ptr;
|
||||
file->size = sb.st_size;
|
||||
file->fd = fd;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
9
si/pak.h
9
si/pak.h
|
@ -11,6 +11,7 @@
|
|||
#ifndef __si_pak_h__
|
||||
#define __si_pak_h__
|
||||
#include "common.h"
|
||||
#include "os/common/rom_file.h"
|
||||
#include "os/common/save_file.h"
|
||||
|
||||
#define MEMPAK_SIZE 0x8000
|
||||
|
@ -25,9 +26,17 @@ enum pak_type {
|
|||
struct controller {
|
||||
const char *mempak_path;
|
||||
struct save_file mempak_save;
|
||||
|
||||
const char *tpak_rom_path;
|
||||
struct rom_file tpak_rom;
|
||||
const char *tpak_save_path;
|
||||
struct save_file tpak_save;
|
||||
int tpak_mode;
|
||||
int tpak_mode_changed;
|
||||
int tpak_bank;
|
||||
|
||||
enum pak_type pak;
|
||||
int pak_enabled;
|
||||
int present;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue