Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build option to disable 64 Disk Drive support #649

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Type 'make' by itself to view all available build options:
NO_ASM=1 == build without assembly (no dynamic recompiler or MMX/SSE code)
USE_GLES=1 == build against GLESv2 instead of OpenGL
VC=1 == build against Broadcom Videocore GLESv2
NO_64DD=1 == build without 64 Disk Drive support
NEON=1 == (ARM only) build for hard floating point environments
VFP_HARD=1 == (ARM only) full hardware floating point ABI
SHAREDIR=path == extra path to search for shared data files
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Type `make` by itself to view all available build options:
NO_ASM=1 == build without assembly (no dynamic recompiler or MMX/SSE code)
USE_GLES=1 == build against GLESv2 instead of OpenGL
VC=1 == build against Broadcom Videocore GLESv2
NO_64DD=1 == build without 64 Disk Drive support
NEON=1 == (ARM only) build for hard floating point environments
VFP_HARD=1 == (ARM only) full hardware floating point ABI
SHAREDIR=path == extra path to search for shared data files
Expand Down
9 changes: 8 additions & 1 deletion projects/unix/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,6 @@ SOURCE = \
$(SRCDIR)/device/controllers/paks/mempak.c \
$(SRCDIR)/device/controllers/paks/rumblepak.c \
$(SRCDIR)/device/controllers/paks/transferpak.c \
$(SRCDIR)/device/dd/dd_controller.c \
$(SRCDIR)/device/device.c \
$(SRCDIR)/device/gb/gb_cart.c \
$(SRCDIR)/device/gb/mbc3_rtc.c \
Expand Down Expand Up @@ -548,6 +547,14 @@ SOURCE = \
$(SRCDIR)/plugin/dummy_rsp.c \
$(MINIZIP_SOURCE)

# Include 64 Disk Drive support
NO_64DD ?= 0
ifeq ($(NO_64DD), 0)
SOURCE += $(SRCDIR)/device/dd/dd_controller.c
else
CFLAGS += -DNO64DD
endif

# MD5 lib
SOURCE += \
$(SUBDIR)/md5/md5.c
Expand Down
2 changes: 2 additions & 0 deletions src/api/m64p_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ typedef struct {
*/
char* (*get_gb_cart_ram)(void* cb_data, int controller_num);

#if !defined(NO64DD) /* build option to disable 64 Disk Drive support */
/* Allow the frontend to specify the DD IPL ROM file to load
* cb_data: points to frontend-defined callback data.
* Returns a NULL-terminated string owned by the core specifying the DD IPL ROM filename to load
Expand All @@ -203,6 +204,7 @@ typedef struct {
* Empty or NULL string results in no DD disk being loaded (eg. empty disk drive).
*/
char* (*get_dd_disk)(void* cb_data);
#endif /* build option to disable 64 Disk Drive support */
} m64p_media_loader;

/* ----------------------------------------- */
Expand Down
7 changes: 6 additions & 1 deletion src/backends/file_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
#include "api/callbacks.h"
#include "api/m64p_types.h"
#include "backends/api/storage_backend.h"
#if !defined(NO64DD) /* build option to disable 64 Disk Drive support */
#include "device/dd/dd_controller.h"
#endif /* build option to disable 64 Disk Drive support */
#include "main/util.h"

int open_file_storage(struct file_storage* fstorage, size_t size, const char* filename)
Expand Down Expand Up @@ -103,6 +105,7 @@ static void file_storage_parent_save(void* storage)
file_storage_save(fstorage);
}

#if !defined(NO64DD) /* build option to disable 64 Disk Drive support */
static void file_storage_dd_sdk_dump_save(void* storage)
{
static uint8_t sdk_buffer[SDK_FORMAT_DUMP_SIZE];
Expand Down Expand Up @@ -131,7 +134,7 @@ static void file_storage_dd_sdk_dump_save(void* storage)

free(filename);
}

#endif /* build option to disable 64 Disk Drive support */


const struct storage_backend_interface g_ifile_storage =
Expand All @@ -156,9 +159,11 @@ const struct storage_backend_interface g_isubfile_storage =
file_storage_parent_save
};

#if !defined(NO64DD) /* build option to disable 64 Disk Drive support */
const struct storage_backend_interface g_ifile_storage_dd_sdk_dump =
{
file_storage_data,
file_storage_size,
file_storage_dd_sdk_dump_save
};
#endif /* build option to disable 64 Disk Drive support */
2 changes: 2 additions & 0 deletions src/backends/file_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ void close_file_storage(struct file_storage* storage);
extern const struct storage_backend_interface g_ifile_storage;
extern const struct storage_backend_interface g_ifile_storage_ro;
extern const struct storage_backend_interface g_isubfile_storage;
#if !defined(NO64DD) /* build option to disable 64 Disk Drive support */
extern const struct storage_backend_interface g_ifile_storage_dd_sdk_dump;
#endif /* build option to disable 64 Disk Drive support */

#endif
55 changes: 54 additions & 1 deletion src/device/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,24 @@ static void write_open_bus(void* opaque, uint32_t address, uint32_t value, uint3
{
}


#if defined(NO64DD) /* build option to disable 64 Disk Drive support */
static unsigned int dd_dom_dma_read(void* opaque, const uint8_t* dram, uint32_t dram_addr, uint32_t cart_addr, uint32_t length)
{
return /* length / 8 */0x1000;
}


static unsigned int dd_dom_dma_write(void* opaque, uint8_t* dram, uint32_t dram_addr, uint32_t cart_addr, uint32_t length)
{
return /* length / 8 */0x1000;
}


static void get_pi_dma_handler(struct device* dev, uint32_t address, void** opaque, const struct pi_dma_handler** handler)
#else
static void get_pi_dma_handler(struct cart* cart, struct dd_controller* dd, uint32_t address, void** opaque, const struct pi_dma_handler** handler)
#endif /* build option to disable 64 Disk Drive support */
{
#define RW(o, x) \
do { \
Expand All @@ -58,21 +75,37 @@ static void get_pi_dma_handler(struct cart* cart, struct dd_controller* dd, uint
if (address >= MM_CART_ROM) {
if (address >= MM_CART_DOM3) {
/* 0x1fd00000 - 0x7fffffff : dom3 addr2, cart rom (Paper Mario (U)) ??? */
#if defined(NO64DD) /* build option to disable 64 Disk Drive support */
RW(&dev->cart, cart_dom3);
#else
RW(cart, cart_dom3);
#endif /* build option to disable 64 Disk Drive support */
}
else {
/* 0x10000000 - 0x1fbfffff : dom1 addr2, cart rom */
#if defined(NO64DD) /* build option to disable 64 Disk Drive support */
RW(&dev->cart.cart_rom, cart_rom);
#else
RW(&cart->cart_rom, cart_rom);
#endif /* build option to disable 64 Disk Drive support */
}
}
else if (address >= MM_DOM2_ADDR2) {
/* 0x08000000 - 0x0fffffff : dom2 addr2, cart save */
#if defined(NO64DD) /* build option to disable 64 Disk Drive support */
RW(&dev->cart, cart_dom2);
#else
RW(cart, cart_dom2);
#endif /* build option to disable 64 Disk Drive support */
}
else if (address >= MM_DOM2_ADDR1) {
/* 0x05000000 - 0x05ffffff : dom2 addr1, dd buffers */
/* 0x06000000 - 0x07ffffff : dom1 addr1, dd rom */
#if defined(NO64DD) /* build option to disable 64 Disk Drive support */
RW(NULL, dd_dom);
#else
RW(dd, dd_dom);
#endif /* build option to disable 64 Disk Drive support */
}
#undef RW
}
Expand Down Expand Up @@ -103,11 +136,15 @@ void init_device(struct device* dev,
void* eeprom_storage, const struct storage_backend_interface* ieeprom_storage,
uint32_t flashram_type,
void* flashram_storage, const struct storage_backend_interface* iflashram_storage,
#if defined(NO64DD) /* build option to disable 64 Disk Drive support */
void* sram_storage, const struct storage_backend_interface* isram_storage)
#else
void* sram_storage, const struct storage_backend_interface* isram_storage,
/* dd */
void* dd_rtc_clock, const struct clock_backend_interface* dd_rtc_iclock,
size_t dd_rom_size,
void* dd_disk, const struct storage_backend_interface* dd_idisk)
#endif /* build option to disable 64 Disk Drive support */
{
struct interrupt_handler interrupt_handlers[] = {
{ &dev->vi, vi_vertical_interrupt_event }, /* VI */
Expand Down Expand Up @@ -145,13 +182,16 @@ void init_device(struct device* dev,
{ A(MM_PI_REGS, 0xffff), M64P_MEM_PI, { &dev->pi, RW(pi_regs) } },
{ A(MM_RI_REGS, 0xffff), M64P_MEM_RI, { &dev->ri, RW(ri_regs) } },
{ A(MM_SI_REGS, 0xffff), M64P_MEM_SI, { &dev->si, RW(si_regs) } },
#if !defined(NO64DD) /* build option to disable 64 Disk Drive support */
{ A(MM_DOM2_ADDR1, 0xffffff), M64P_MEM_NOTHING, { NULL, RW(open_bus) } },
{ A(MM_DD_ROM, 0x1ffffff), M64P_MEM_NOTHING, { NULL, RW(open_bus) } },
#endif /* build option to disable 64 Disk Drive support */
{ A(MM_DOM2_ADDR2, 0x1ffff), M64P_MEM_FLASHRAMSTAT, { &dev->cart, RW(cart_dom2) } },
{ A(MM_CART_ROM, rom_size-1), M64P_MEM_ROM, { &dev->cart.cart_rom, RW(cart_rom) } },
{ A(MM_PIF_MEM, 0xffff), M64P_MEM_PIF, { &dev->pif, RW(pif_ram) } }
};

#if !defined(NO64DD) /* build option to disable 64 Disk Drive support */
/* init and map DD if present */
if (dd_rom_size > 0) {
mappings[14] = (struct mem_mapping){ A(MM_DOM2_ADDR1, 0xffffff), M64P_MEM_NOTHING, { &dev->dd, RW(dd_regs) } };
Expand All @@ -163,6 +203,7 @@ void init_device(struct device* dev,
dd_disk, dd_idisk,
&dev->r4300);
}
#endif /* build option to disable 64 Disk Drive support */

struct mem_handler dbg_handler = { &dev->r4300, RW(with_bp_checks) };
#undef A
Expand All @@ -181,13 +222,18 @@ void init_device(struct device* dev,
init_ai(&dev->ai, &dev->mi, &dev->ri, &dev->vi, aout, iaout);
init_mi(&dev->mi, &dev->r4300);
init_pi(&dev->pi,
#if defined(NO64DD) /* build option to disable 64 Disk Drive support */
dev, get_pi_dma_handler,
#else
get_pi_dma_handler,
&dev->cart, &dev->dd,
#endif /* build option to disable 64 Disk Drive support */
&dev->mi, &dev->ri, &dev->dp);
init_ri(&dev->ri, &dev->rdram);
init_si(&dev->si, si_dma_duration, &dev->mi, &dev->pif, &dev->ri);
init_vi(&dev->vi, vi_clock, expected_refresh_rate, &dev->mi, &dev->dp);

#if !defined(NO64DD) /* build option to disable 64 Disk Drive support */
/* FIXME: should boot on cart, unless only a disk is present, but having no cart is not yet supported by ui/core,
* so use another way of selecting boot device:
* use CART unless DD is plugged and the plugged CART is not a combo media (cart+disk).
Expand All @@ -196,11 +242,16 @@ void init_device(struct device* dev,
uint32_t rom_base = (dd_rom_size > 0 && media != 'C')
? MM_DD_ROM
: MM_CART_ROM;
#endif /* build option to disable 64 Disk Drive support */

init_pif(&dev->pif,
(uint8_t*)mem_base_u32(base, MM_PIF_MEM),
jbds, ijbds,
#if defined(NO64DD) /* build option to disable 64 Disk Drive support */
(uint8_t*)mem_base_u32(base, MM_CART_ROM + 0x40),
#else
(uint8_t*)mem_base_u32(base, rom_base) + 0x40,
#endif /* build option to disable 64 Disk Drive support */
&dev->r4300);

init_cart(&dev->cart,
Expand Down Expand Up @@ -240,10 +291,12 @@ void poweron_device(struct device* dev)
channel->ijbd->poweron(channel->jbd);
}
}


#if !defined(NO64DD) /* build option to disable 64 Disk Drive support */
if (dev->dd.rom != NULL) {
poweron_dd(&dev->dd);
}
#endif /* build option to disable 64 Disk Drive support */
}

void run_device(struct device* dev)
Expand Down
11 changes: 10 additions & 1 deletion src/device/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
#include "controllers/paks/mempak.h"
#include "controllers/paks/rumblepak.h"
#include "controllers/paks/transferpak.h"
#if !defined(NO64DD) /* build option to disable 64 Disk Drive support */
#include "dd/dd_controller.h"
#endif /* build option to disable 64 Disk Drive support */
#include "gb/gb_cart.h"
#include "memory/memory.h"
#include "pif/pif.h"
Expand Down Expand Up @@ -70,10 +72,12 @@ enum { GAME_CONTROLLERS_COUNT = 4 };
#define MM_SI_REGS UINT32_C(0x04800000)

#define MM_DOM2_ADDR1 UINT32_C(0x05000000)
#if !defined(NO64DD) /* build option to disable 64 Disk Drive support */
#define MM_DD_C2S_BUFFER UINT32_C(0x05000000)
#define MM_DD_DS_BUFFER UINT32_C(0x05000400)
#define MM_DD_REGS UINT32_C(0x05000500)
#define MM_DD_MS_RAM UINT32_C(0x05000580)
#endif /* build option to disable 64 Disk Drive support */
#define MM_DD_ROM UINT32_C(0x06000000)

#define MM_DOM2_ADDR2 UINT32_C(0x08000000)
Expand Down Expand Up @@ -107,8 +111,9 @@ struct device
struct gb_cart gb_carts[GAME_CONTROLLERS_COUNT];

struct cart cart;

#if !defined(NO64DD) /* build option to disable 64 Disk Drive support */
struct dd_controller dd;
#endif /* build option to disable 64 Disk Drive support */
};

/* Setup device "static" properties. */
Expand Down Expand Up @@ -138,11 +143,15 @@ void init_device(struct device* dev,
void* eeprom_storage, const struct storage_backend_interface* ieeprom_storage,
uint32_t flashram_type,
void* flashram_storage, const struct storage_backend_interface* iflashram_storage,
#if defined(NO64DD) /* build option to disable 64 Disk Drive support */
void* sram_storage, const struct storage_backend_interface* isram_storage);
#else
void* sram_storage, const struct storage_backend_interface* isram_storage,
/* dd */
void* dd_rtc_clock, const struct clock_backend_interface* dd_rtc_iclock,
size_t dd_rom_size,
void* dd_disk, const struct storage_backend_interface* dd_idisk);
#endif /* build option to disable 64 Disk Drive support */

/* Setup device such that it's state is
* what it should be after power on.
Expand Down
6 changes: 6 additions & 0 deletions src/device/pif/cic.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,12 @@ void init_cic_using_ipl3(struct cic* cic, const void* ipl3)
{ "X103", CIC_X103, 0x78 },
{ "X105", CIC_X105, 0x91 },
{ "X106", CIC_X106, 0x85 },
#if defined(NO64DD) /* build option to disable 64 Disk Drive support */
{ "5167", CIC_5167, 0xdd }
#else
{ "5167", CIC_5167, 0xdd },
{ "8303", CIC_8303, 0xdd }
#endif /* build option to disable 64 Disk Drive support */
};

for (i = 0; i < 0xfc0/4; i++)
Expand All @@ -65,7 +69,9 @@ void init_cic_using_ipl3(struct cic* cic, const void* ipl3)
case UINT64_C(0x000000D6D5BE5580): i = 5; break; /* CIC_X106 */
case UINT64_C(0x000001053BC19870): i = 6; break; /* CIC 5167 */
case UINT64_C(0x000000A5F80BF620): i = 0; break; /* CIC 5101 */
#if !defined(NO64DD) /* build option to disable 64 Disk Drive support */
case UINT64_C(0x000000D2E53EF008): i = 7; break; /* CIC 8303 */
#endif /* build option to disable 64 Disk Drive support */
}

memcpy(cic, &cics[i], sizeof(*cic));
Expand Down
4 changes: 4 additions & 0 deletions src/device/pif/cic.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ enum cic_version
CIC_X105,
CIC_X106,
CIC_5101,
#if defined(NO64DD) /* build option to disable 64 Disk Drive support */
CIC_5167
#else
CIC_5167,
CIC_8303
#endif /* build option to disable 64 Disk Drive support */
};

struct cic
Expand Down
4 changes: 4 additions & 0 deletions src/device/pif/pif.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,11 @@ void reset_pif(struct pif* pif, unsigned int reset_type)
size_t i;

/* HACK: for allowing pifbootrom execution */
#if defined(NO64DD) /* build option to disable 64 Disk Drive support */
unsigned int rom_type = 0;
#else
unsigned int rom_type = (pif->cic.version == CIC_8303) ? 1 : 0;
#endif /* build option to disable 64 Disk Drive support */
unsigned int s7 = 0;

/* 0:ColdReset, 1:NMI */
Expand Down