mirror of
https://github.com/n64dev/cen64.git
synced 2024-06-22 22:12:45 -04:00
eeprom: take options on command line and pass file into SI
This commit is contained in:
parent
ec739c8c94
commit
72c147255d
11
cen64.c
11
cen64.c
|
@ -15,6 +15,7 @@
|
|||
#include "device/options.h"
|
||||
#include "os/common/alloc.h"
|
||||
#include "os/common/rom_file.h"
|
||||
#include "os/common/save_file.h"
|
||||
#include "thread.h"
|
||||
#include <AL/al.h>
|
||||
#include <AL/alc.h>
|
||||
|
@ -31,6 +32,7 @@ cen64_cold static CEN64_THREAD_RETURN_TYPE run_device_thread(void *opaque);
|
|||
int cen64_main(int argc, const char **argv) {
|
||||
struct cen64_options options = default_cen64_options;
|
||||
struct rom_file ddipl, ddrom, pifrom, cart;
|
||||
struct save_file eeprom;
|
||||
struct cen64_mem cen64_device_mem;
|
||||
struct cen64_device *device;
|
||||
int status;
|
||||
|
@ -61,6 +63,7 @@ int cen64_main(int argc, const char **argv) {
|
|||
memset(&ddipl, 0, sizeof(ddipl));
|
||||
memset(&ddrom, 0, sizeof(ddrom));
|
||||
memset(&cart, 0, sizeof(cart));
|
||||
memset(&eeprom, 0, sizeof(eeprom));
|
||||
|
||||
if (load_roms(options.ddipl_path, options.ddrom_path, options.pifrom_path,
|
||||
options.cart_path, &ddipl, &ddrom, &pifrom, &cart)) {
|
||||
|
@ -68,6 +71,12 @@ int cen64_main(int argc, const char **argv) {
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (options.eeprom_path != NULL &&
|
||||
open_save_file(options.eeprom_path, options.eeprom_size, &eeprom)) {
|
||||
cen64_alloc_cleanup();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// Allocate memory for and create the device.
|
||||
if (cen64_alloc(&cen64_device_mem, sizeof(*device), false) == NULL) {
|
||||
printf("Failed to allocate enough memory for a device.\n");
|
||||
|
@ -77,7 +86,7 @@ int cen64_main(int argc, const char **argv) {
|
|||
else {
|
||||
device = (struct cen64_device *) cen64_device_mem.ptr;
|
||||
|
||||
if (device_create(device, &ddipl, &ddrom, &pifrom, &cart) == NULL) {
|
||||
if (device_create(device, &ddipl, &ddrom, &pifrom, &cart, &eeprom) == NULL) {
|
||||
printf("Failed to create a device.\n");
|
||||
status = EXIT_FAILURE;
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "fpu/fpu.h"
|
||||
#include "gl_window.h"
|
||||
#include "os/common/rom_file.h"
|
||||
#include "os/common/save_file.h"
|
||||
|
||||
#include "bus/controller.h"
|
||||
#include "ai/controller.h"
|
||||
|
@ -33,7 +34,8 @@ cen64_flatten cen64_hot static int device_spin(struct cen64_device *device);
|
|||
// Creates and initializes a device.
|
||||
struct cen64_device *device_create(struct cen64_device *device,
|
||||
const struct rom_file *ddipl, const struct rom_file *ddrom,
|
||||
const struct rom_file *pifrom, const struct rom_file *cart) {
|
||||
const struct rom_file *pifrom, const struct rom_file *cart,
|
||||
const struct save_file *eeprom) {
|
||||
|
||||
// Initialize the bus.
|
||||
device->bus.ai = &device->ai;
|
||||
|
@ -80,7 +82,7 @@ struct cen64_device *device_create(struct cen64_device *device,
|
|||
|
||||
// Initialize the SI.
|
||||
if (si_init(&device->si, &device->bus, pifrom->ptr,
|
||||
cart->ptr, ddipl->ptr != NULL)) {
|
||||
cart->ptr, ddipl->ptr != NULL, eeprom->ptr, eeprom->size)) {
|
||||
debug("create_device: Failed to initialize the SI.\n");
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "common.h"
|
||||
#include "device/options.h"
|
||||
#include "os/common/rom_file.h"
|
||||
#include "os/common/save_file.h"
|
||||
|
||||
#include "ai/controller.h"
|
||||
#include "bus/controller.h"
|
||||
|
@ -47,7 +48,8 @@ struct cen64_device {
|
|||
cen64_cold void device_destroy(struct cen64_device *device);
|
||||
cen64_cold struct cen64_device *device_create(struct cen64_device *device,
|
||||
const struct rom_file *ddipl, const struct rom_file *ddrom,
|
||||
const struct rom_file *pifrom, const struct rom_file *cart);
|
||||
const struct rom_file *pifrom, const struct rom_file *cart,
|
||||
const struct save_file *eeprom);
|
||||
|
||||
cen64_cold void device_exit(struct bus_controller *bus);
|
||||
cen64_cold void device_run(struct cen64_device *device);
|
||||
|
|
|
@ -17,6 +17,8 @@ const struct cen64_options default_cen64_options = {
|
|||
NULL, // pifrom_path
|
||||
NULL, // cart_path
|
||||
NULL, // debugger_addr
|
||||
NULL, // eeprom_path
|
||||
0, // eeprom_size
|
||||
#ifdef _WIN32
|
||||
false, // console
|
||||
#endif
|
||||
|
@ -69,6 +71,26 @@ int parse_options(struct cen64_options *options, int argc, const char *argv[]) {
|
|||
else if (!strcmp(argv[i], "-nointerface"))
|
||||
options->no_interface = true;
|
||||
|
||||
else if (!strcmp(argv[i], "-eep4k")) {
|
||||
if ((i + 1) >= (argc - 1)) {
|
||||
printf("-eep4k requires a path to the save file.\n\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
options->eeprom_path = argv[++i];
|
||||
options->eeprom_size = 4096;
|
||||
}
|
||||
|
||||
else if (!strcmp(argv[i], "-eep16k")) {
|
||||
if ((i + 1) >= (argc - 1)) {
|
||||
printf("-eep16k requires a path to the save file.\n\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
options->eeprom_path = argv[++i];
|
||||
options->eeprom_size = 16384;
|
||||
}
|
||||
|
||||
// TODO: Handle this better.
|
||||
else
|
||||
break;
|
||||
|
|
|
@ -19,6 +19,9 @@ struct cen64_options {
|
|||
const char *cart_path;
|
||||
const char *debugger_addr;
|
||||
|
||||
const char *eeprom_path;
|
||||
size_t eeprom_size;
|
||||
|
||||
#ifdef _WIN32
|
||||
bool console;
|
||||
#endif
|
||||
|
|
|
@ -37,7 +37,8 @@ static int eeprom_write(struct eeprom *eeprom, uint8_t *send_buf, uint8_t send_b
|
|||
|
||||
// Initializes the SI.
|
||||
int si_init(struct si_controller *si, struct bus_controller *bus,
|
||||
const uint8_t *pif_rom, const uint8_t *cart_rom, bool dd_present) {
|
||||
const uint8_t *pif_rom, const uint8_t *cart_rom, bool dd_present,
|
||||
const uint8_t *eeprom, size_t eeprom_size) {
|
||||
uint32_t cic_seed;
|
||||
|
||||
si->bus = bus;
|
||||
|
@ -70,8 +71,8 @@ int si_init(struct si_controller *si, struct bus_controller *bus,
|
|||
bus_write_word(si, 0x3F0, 0x800000, ~0U);
|
||||
|
||||
// initialize EEPROM
|
||||
si->eeprom.size = EEPROM_SIZE;
|
||||
// TODO zero memory?
|
||||
si->eeprom.data = eeprom;
|
||||
si->eeprom.size = eeprom_size;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -25,9 +25,8 @@ enum si_register {
|
|||
extern const char *si_register_mnemonics[NUM_SI_REGISTERS];
|
||||
#endif
|
||||
|
||||
#define EEPROM_SIZE 0x800
|
||||
struct eeprom {
|
||||
uint8_t data[EEPROM_SIZE];
|
||||
uint8_t *data;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
|
@ -44,7 +43,8 @@ struct si_controller {
|
|||
};
|
||||
|
||||
cen64_cold int si_init(struct si_controller *si, struct bus_controller *bus,
|
||||
const uint8_t *pif_rom, const uint8_t *cart_rom, bool dd_present);
|
||||
const uint8_t *pif_rom, const uint8_t *cart_rom, bool dd_present,
|
||||
const uint8_t *eeprom, size_t eeprom_size);
|
||||
|
||||
int read_pif_ram(void *opaque, uint32_t address, uint32_t *word);
|
||||
int read_pif_rom(void *opaque, uint32_t address, uint32_t *word);
|
||||
|
|
Loading…
Reference in a new issue