Start filling in lots of 64DD implementation.

Also, fix a few bugs in the past two commits.
This commit is contained in:
Tyler Stachecki 2015-01-06 15:32:25 -05:00
parent c6729b8dcc
commit 10fc81d7a3
17 changed files with 155 additions and 36 deletions

View file

@ -16,15 +16,19 @@
#define AI_REGS_ADDRESS_LEN 0x00000018
// DD C2 sector buffer.
#define DD_C2S_BUFFER_ADDRESS 0x50000000
#define DD_C2S_BUFFER_ADDRESS 0x05000000
#define DD_C2S_BUFFER_LEN 0x00000400
// DD data sector buffer.
#define DD_DS_BUFFER_ADDRESS 0x50000400
#define DD_DS_BUFFER_ADDRESS 0x05000400
#define DD_DS_BUFFER_LEN 0x00000100
// DD IPL ROM.
#define DD_IPL_ROM_ADDRESS 0x06000000
#define DD_IPL_ROM_LEN 0x00400000
// DD microsequencer RAM.
#define DD_MS_RAM_ADDRESS 0x50000580
#define DD_MS_RAM_ADDRESS 0x05000580
#define DD_MS_RAM_LEN 0x00000040
// DD interface registers.

View file

@ -25,7 +25,7 @@
#include "vr4300/cpu.h"
#include "vr4300/interface.h"
#define NUM_MAPPINGS 18
#define NUM_MAPPINGS 19
struct bus_controller_mapping {
memory_rd_function read;
@ -53,6 +53,7 @@ int bus_init(struct bus_controller *bus) {
{read_dd_c2s_buffer, write_dd_c2s_buffer, DD_C2S_BUFFER_ADDRESS, DD_C2S_BUFFER_LEN},
{read_dd_ds_buffer, write_dd_ds_buffer, DD_DS_BUFFER_ADDRESS, DD_DS_BUFFER_LEN},
{read_dd_ms_ram, write_dd_ms_ram, DD_MS_RAM_ADDRESS, DD_MS_RAM_LEN},
{read_dd_ipl_rom, write_dd_ipl_rom, DD_IPL_ROM_ADDRESS, DD_IPL_ROM_LEN},
{read_pif_ram, write_pif_ram, PIF_RAM_BASE_ADDRESS, PIF_RAM_ADDRESS_LEN},
{read_pif_rom, write_pif_rom, PIF_ROM_BASE_ADDRESS, PIF_ROM_ADDRESS_LEN},
{read_rdram_regs, write_rdram_regs, RDRAM_REGS_BASE_ADDRESS, RDRAM_REGS_ADDRESS_LEN},
@ -75,6 +76,7 @@ int bus_init(struct bus_controller *bus) {
bus->dd,
bus->dd,
bus->dd,
bus->dd,
bus->si,
bus->si,
bus->ri,

View file

@ -42,7 +42,7 @@ struct memory_map_node {
};
struct memory_map {
struct memory_map_node mappings[20];
struct memory_map_node mappings[21];
struct memory_map_node *nil;
struct memory_map_node *root;

30
cen64.c
View file

@ -15,13 +15,14 @@
#include "os/rom_file.h"
#include <stdlib.h>
static int load_roms(const char *pifrom_path, const char *cart_path,
static int load_roms(const char *ddipl_path, const char *pifrom_path,
const char *cart_path, struct rom_file *ddipl,
struct rom_file *pifrom, struct rom_file *cart);
// Called when another simulation instance is desired.
int cen64_cmdline_main(int argc, const char *argv[]) {
struct cen64_options options = default_cen64_options;
struct rom_file pifrom, cart;
struct rom_file ddipl, pifrom, cart;
int status;
if (argc < 3) {
@ -36,10 +37,14 @@ int cen64_cmdline_main(int argc, const char *argv[]) {
return EXIT_FAILURE;
}
if (load_roms(options.pifrom_path, options.cart_path, &pifrom, &cart))
if (load_roms(options.ddipl_path, options.pifrom_path,
options.cart_path, &ddipl, &pifrom, &cart))
return EXIT_FAILURE;
status = os_main(&options, &pifrom, &cart);
status = os_main(&options, &ddipl, &pifrom, &cart);
if (options.ddipl_path)
close_rom_file(&ddipl);
close_rom_file(&cart);
close_rom_file(&pifrom);
@ -47,17 +52,32 @@ int cen64_cmdline_main(int argc, const char *argv[]) {
}
// Load any ROM images required for simulation.
int load_roms(const char *pifrom_path, const char *cart_path,
int load_roms(const char *ddipl_path, const char *pifrom_path,
const char *cart_path, struct rom_file *ddipl,
struct rom_file *pifrom, struct rom_file *cart) {
memset(ddipl, 0, sizeof(*ddipl));
if (ddipl_path && open_rom_file(ddipl_path, ddipl)) {
printf("Failed to load DD IPL ROM: %s.\n", ddipl_path);
return 1;
}
if (open_rom_file(pifrom_path, pifrom)) {
printf("Failed to load PIF ROM: %s.\n", pifrom_path);
if (ddipl_path)
close_rom_file(ddipl);
return 1;
}
if (open_rom_file(cart_path, cart)) {
printf("Failed to load cart: %s.\n", cart_path);
if (ddipl_path)
close_rom_file(ddipl);
close_rom_file(pifrom);
return 2;
}

View file

@ -22,8 +22,10 @@ const char *dd_register_mnemonics[NUM_DD_REGISTERS] = {
#endif
// Initializes the DD.
int dd_init(struct dd_controller *dd, struct bus_controller *bus) {
int dd_init(struct dd_controller *dd, struct bus_controller *bus,
const uint8_t *rom) {
dd->bus = bus;
dd->rom = rom;
return 0;
}
@ -53,6 +55,29 @@ int write_dd_regs(void *opaque, uint32_t address, uint32_t word, uint32_t dqm) {
return 0;
}
// Reads a word from the DD IPL ROM.
int read_dd_ipl_rom(void *opaque, uint32_t address, uint32_t *word) {
uint32_t offset = address - DD_IPL_ROM_ADDRESS;
struct dd_controller *dd = (struct dd_controller*) opaque;
if (!dd->rom)
memset(word, 0, sizeof(word));
else {
memcpy(word, dd->rom + offset, sizeof(*word));
*word = byteswap_32(*word);
}
//debug_mmio_read(dd, "DD_IPL_ROM", *word);
return 0;
}
// Writes a word to the DD IPL ROM.
int write_dd_ipl_rom(void *opaque, uint32_t address, uint32_t word, uint32_t dqm) {
assert(0 && "Attempt to write to DD IPL ROM.");
return 0;
}
// Reads a word from the DD C2S buffer.
int read_dd_c2s_buffer(void *opaque, uint32_t address, uint32_t *word) {
struct dd_controller *dd = (struct dd_controller *) opaque;
@ -89,7 +114,7 @@ int write_dd_ds_buffer(void *opaque, uint32_t address, uint32_t word, uint32_t d
return 0;
}
// Reads a word from the DD DS buffer.
// Reads a word from the DD MS RAM.
int read_dd_ms_ram(void *opaque, uint32_t address, uint32_t *word) {
struct dd_controller *dd = (struct dd_controller *) opaque;
unsigned offset = address - DD_MS_RAM_ADDRESS;
@ -98,7 +123,7 @@ int read_dd_ms_ram(void *opaque, uint32_t address, uint32_t *word) {
return 0;
}
// Writes a word to the DD DS BUFFER.
// Writes a word to the DD MS RAM.
int write_dd_ms_ram(void *opaque, uint32_t address, uint32_t word, uint32_t dqm) {
struct dd_controller *dd = (struct dd_controller *) opaque;
unsigned offset = address - DD_MS_RAM_ADDRESS;

View file

@ -11,6 +11,7 @@
#ifndef __dd_controller_h__
#define __dd_controller_h__
#include "common.h"
#include "bus/address.h"
struct bus_controller *bus;
@ -27,6 +28,7 @@ extern const char *dd_register_mnemonics[NUM_DD_REGISTERS];
struct dd_controller {
struct bus_controller *bus;
const uint8_t *rom;
uint32_t regs[NUM_DD_REGISTERS];
uint8_t c2s_buffer[DD_C2S_BUFFER_LEN];
@ -34,11 +36,15 @@ struct dd_controller {
uint8_t ms_ram[DD_MS_RAM_LEN];
};
cen64_cold int dd_init(struct dd_controller *dd, struct bus_controller *bus);
cen64_cold int dd_init(struct dd_controller *dd, struct bus_controller *bus,
const uint8_t *ddipl);
int read_dd_regs(void *opaque, uint32_t address, uint32_t *word);
int write_dd_regs(void *opaque, uint32_t address, uint32_t word, uint32_t dqm);
int read_dd_ipl_rom(void *opaque, uint32_t address, uint32_t *word);
int write_dd_ipl_rom(void *opaque, uint32_t address, uint32_t word, uint32_t dqm);
int read_dd_c2s_buffer(void *opaque, uint32_t address, uint32_t *word);
int write_dd_c2s_buffer(void *opaque, uint32_t address, uint32_t word, uint32_t dqm);
int read_dd_ds_buffer(void *opaque, uint32_t address, uint32_t *word);

View file

@ -9,7 +9,7 @@
//
#ifndef DD_REGISTER_LIST
#define DD_REGISTER_LIST
#define DD_REGISTER_LIST \
X(DD_ASIC_DATA) \
X(DD_ASIC_MISC_REG) \
X(DD_ASIC_CMD) \

View file

@ -19,6 +19,7 @@
#include "bus/controller.h"
#include "ai/controller.h"
#include "dd/controller.h"
#include "pi/controller.h"
#include "ri/controller.h"
#include "si/controller.h"
@ -36,10 +37,12 @@ cen64_hot static int device_spin(struct cen64_device *device);
// Creates and initializes a device.
struct cen64_device *device_create(struct cen64_device *device,
uint8_t *ram, const struct rom_file *pifrom, const struct rom_file *cart) {
uint8_t *ram, const struct rom_file *ddipl, const struct rom_file *pifrom,
const struct rom_file *cart) {
// Initialize the bus.
device->bus.ai = &device->ai;
device->bus.dd = &device->dd;
device->bus.pi = &device->pi;
device->bus.ri = &device->ri;
device->bus.si = &device->si;
@ -61,6 +64,12 @@ struct cen64_device *device_create(struct cen64_device *device,
return NULL;
}
// Initialize the DD.
if (dd_init(&device->dd, &device->bus, ddipl->ptr)) {
debug("create_device: Failed to initialize the AI.\n");
return NULL;
}
// Initialize the PI.
if (pi_init(&device->pi, &device->bus, cart->ptr, cart->size)) {
debug("create_device: Failed to initialize the PI.\n");
@ -74,7 +83,8 @@ struct cen64_device *device_create(struct cen64_device *device,
}
// Initialize the SI.
if (si_init(&device->si, &device->bus, pifrom->ptr, cart->ptr)) {
if (si_init(&device->si, &device->bus, pifrom->ptr,
cart->ptr, ddipl->ptr != NULL)) {
debug("create_device: Failed to initialize the SI.\n");
return NULL;
}

View file

@ -16,6 +16,7 @@
#include "ai/controller.h"
#include "bus/controller.h"
#include "dd/controller.h"
#include "pi/controller.h"
#include "ri/controller.h"
#include "si/controller.h"
@ -34,6 +35,7 @@ struct cen64_device {
struct vr4300 vr4300;
struct ai_controller ai;
struct dd_controller dd;
struct pi_controller pi;
struct ri_controller ri;
struct si_controller si;
@ -45,7 +47,8 @@ struct cen64_device {
cen64_cold void device_destroy(struct cen64_device *device);
cen64_cold struct cen64_device *device_create(struct cen64_device *device,
uint8_t *ram, const struct rom_file *pifrom, const struct rom_file *cart);
uint8_t *ram, const struct rom_file *ddipl, const struct rom_file *pifrom,
const struct rom_file *cart);
cen64_cold void device_exit(struct bus_controller *bus);
cen64_cold void device_run(struct cen64_device *device);

View file

@ -12,6 +12,7 @@
#include "options.h"
const struct cen64_options default_cen64_options = {
NULL, // ddipl_path
NULL, // pifrom_path
NULL, // cart_path
#ifdef _WIN32
@ -33,8 +34,16 @@ int parse_options(struct cen64_options *options, int argc, const char *argv[]) {
else
#endif
if (!strcmp(argv[i], "-ddipl")) {
if ((i + 1) >= (argc - 2)) {
printf("-ddipl requires a path to the ROM file.\n\n");
return 1;
}
if (!strcmp(argv[i], "-nointerface"))
options->ddipl_path = argv[++i];
}
else if (!strcmp(argv[i], "-nointerface"))
options->no_interface = true;
#ifdef CEN64_DEVFEATURES
@ -53,12 +62,13 @@ int parse_options(struct cen64_options *options, int argc, const char *argv[]) {
// Prints the command-line usage string.
void print_command_line_usage(const char *invokation_string) {
printf("%s [Options] <PIFROM Path> <ROM Path>\n\n"
printf("%s [Options] <PIF IPL ROM Path> <ROM Path>\n\n"
"Options:\n"
#ifdef _WIN32
" -console : Creates/shows the system console.\n"
#endif
" -ddipl <path> : Path to the 64DD IPL ROM (enables 64DD mode).\n"
" -nointerface : Run simulator without a user interface.\n"
#ifdef CEN64_DEVFEATURES
" -printsimstats : Print simulation statistics at exit.\n"

View file

@ -13,6 +13,7 @@
#include "common.h"
struct cen64_options {
const char *ddipl_path;
const char *pifrom_path;
const char *cart_path;

View file

@ -14,7 +14,7 @@
#include "rom_file.h"
cen64_cold int os_main(struct cen64_options *options,
struct rom_file *pifrom, struct rom_file *cart);
struct rom_file *ddipl, struct rom_file *pifrom, struct rom_file *cart);
cen64_cold bool os_exit_requested(struct gl_window *gl_window);
cen64_cold void os_render_frame(struct gl_window *gl_window, const void *data,

View file

@ -101,7 +101,7 @@ bool os_exit_requested(struct gl_window *gl_window) {
}
// Allocates memory for a new device, runs it.
int os_main(struct cen64_options *options,
int os_main(struct cen64_options *options, struct rom_file *ddipl,
struct rom_file *pifrom, struct rom_file *cart) {
struct gl_window_hints hints;
struct glx_window window;
@ -121,7 +121,7 @@ int os_main(struct cen64_options *options,
// about uninitialized memory being read, etc.
memset(&device, 0, sizeof(device));
if (device_create(&device, ram, pifrom, cart) == NULL) {
if (device_create(&device, ram, ddipl, pifrom, cart) == NULL) {
printf("Failed to create a device.\n");
deallocate_ram(&hunk);

View file

@ -19,7 +19,8 @@
#include <windows.h>
static int cen64_win32_main(int argc, const char *argv[]);
static int load_roms(const char *pifrom_path, const char *cart_path,
static int load_roms(const char *ddipl_path, const char *pifrom_path,
const char *cart_path, struct rom_file *ddipl,
struct rom_file *pifrom, struct rom_file *cart);
static void hide_console(void);
@ -67,7 +68,7 @@ int WINAPI WinMain(HINSTANCE hInstance,
// Called when another simulation instance is desired.
int cen64_win32_main(int argc, const char *argv[]) {
struct cen64_options options = default_cen64_options;
struct rom_file pifrom, cart;
struct rom_file ddipl, pifrom, cart;
int status;
if (argc < 3) {
@ -88,10 +89,14 @@ int cen64_win32_main(int argc, const char *argv[]) {
return EXIT_FAILURE;
}
if (load_roms(options.pifrom_path, options.cart_path, &pifrom, &cart))
if (load_roms(options.ddipl_path, options.pifrom_path,
options.cart_path, &ddipl, &pifrom, &cart))
return EXIT_FAILURE;
status = os_main(&options, &pifrom, &cart);
status = os_main(&options, &ddipl, &pifrom, &cart);
if (options.ddipl_path)
close_rom_file(&ddipl);
close_rom_file(&cart);
close_rom_file(&pifrom);
@ -107,21 +112,37 @@ void hide_console(void) {
}
// Load any ROM images required for simulation.
int load_roms(const char *pifrom_path, const char *cart_path,
int load_roms(const char *ddipl_path, const char *pifrom_path,
const char *cart_path, struct rom_file *ddipl,
struct rom_file *pifrom, struct rom_file *cart) {
memset(ddipl, 0, sizeof(*ddipl));
if (ddipl_path && open_rom_file(ddipl_path, ddipl)) {
MessageBox(NULL, "Failed to load DD IPL ROM.", "CEN64",
MB_OK | MB_ICONEXCLAMATION);
return 1;
}
if (open_rom_file(pifrom_path, pifrom)) {
MessageBox(NULL, "Failed to load PIF ROM.", "CEN64",
MB_OK | MB_ICONEXCLAMATION);
return 1;
if (ddipl_path)
close_rom_file(ddipl);
return 2;
}
if (open_rom_file(cart_path, cart)) {
MessageBox(NULL, "Failed to load cart.", "CEN64",
MB_OK | MB_ICONEXCLAMATION);
if (ddipl_path)
close_rom_file(ddipl);
close_rom_file(pifrom);
return 2;
return 3;
}
return 0;
@ -144,7 +165,7 @@ void os_release_input(struct gl_window *gl_window) {
}
// Allocates memory for a new device, runs it.
int os_main(struct cen64_options *options,
int os_main(struct cen64_options *options, struct rom_file *ddipl,
struct rom_file *pifrom, struct rom_file *cart) {
struct gl_window_hints hints;
struct winapi_window window;
@ -160,7 +181,8 @@ int os_main(struct cen64_options *options,
// about uninitialized memory being read, etc.
memset(&device, 0, sizeof(device));
if (device_create(&device, malloc(DEVICE_RAMSIZE), pifrom, cart) == NULL) {
if (device_create(&device, malloc(DEVICE_RAMSIZE),
ddipl, pifrom, cart) == NULL) {
printf("Failed to create a device.\n");
//deallocate_ram(&hunk);

View file

@ -11,6 +11,7 @@
#include "common.h"
#include "bus/address.h"
#include "bus/controller.h"
#include "dd/controller.h"
#include "pi/controller.h"
#include "ri/controller.h"
#include "vr4300/interface.h"
@ -70,7 +71,14 @@ static int pi_dma_write(struct pi_controller *pi) {
if (length & 7)
length = (length + 7) & ~7;
if (source & 0x08000000) {
if (pi->bus->dd->rom && source & 0x03000000) {
source &= 0x003FFFFF;
memcpy(pi->bus->ri->ram + dest, pi->bus->dd->rom + source, length);
}
else if (source & 0x08000000) {
}
else if (!(source & 0x06000000)) {
@ -79,7 +87,7 @@ static int pi_dma_write(struct pi_controller *pi) {
//assert(0);
}
memcpy(pi->bus->ri->ram + dest, pi->rom + source, length);
memcpy(pi->bus->ri->ram + dest, pi->rom + source, length);
}
pi->regs[PI_DRAM_ADDR_REG] += length;

View file

@ -33,7 +33,7 @@ static int pif_perform_command(struct si_controller *si, unsigned channel,
// Initializes the SI.
int si_init(struct si_controller *si, struct bus_controller *bus,
const uint8_t *pif_rom, const uint8_t *cart_rom) {
const uint8_t *pif_rom, const uint8_t *cart_rom, bool dd_present) {
uint32_t cic_seed;
si->bus = bus;
@ -49,6 +49,14 @@ int si_init(struct si_controller *si, struct bus_controller *bus,
si->ram[0x26] = cic_seed >> 8;
si->ram[0x27] = cic_seed >> 0;
// 64DD present? Use that.
if (dd_present) {
si->ram[0x24] = 0x00;
si->ram[0x25] = 0x0A;
si->ram[0x26] = 0xDD;
si->ram[0x27] = 0x3F;
}
// Specify 8MiB RDRAM for 6102/6105 carts.
if (si->ram[0x26] == 0x3F && si->ram[0x27] == 0x3F)
bus_write_word(si->bus, 0x318, 0x800000, ~0U);

View file

@ -37,7 +37,7 @@ 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);
const uint8_t *pif_rom, const uint8_t *cart_rom, bool dd_present);
int read_pif_ram(void *opaque, uint32_t address, uint32_t *word);
int read_pif_rom(void *opaque, uint32_t address, uint32_t *word);