Skip to content

Commit

Permalink
- Support reboot on FlippyDrive with passthrough active.
Browse files Browse the repository at this point in the history
  • Loading branch information
Extrems committed Dec 18, 2024
1 parent eaae0e2 commit a00e7b5
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cube/patches/base/emulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,7 @@ static void pi_write(unsigned index, uint32_t value)
PI[index] = ((value << 2) & 0b100) | (value & ~0b100);
break;
#else
if (*VAR_DRIVE_PATCHED) {
if (*VAR_DRIVE_FLAGS & 0b01) {
PI[index] = ((value << 2) & 0b100) | (value & ~0b100);

if (!di.reset && !(value & 0b100))
Expand Down
30 changes: 30 additions & 0 deletions cube/patches/dvd/dvd.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,31 @@ static void gcode_set_disc_number(uint32_t disc)
DI[7] = 0b001;
while (DI[7] & 0b001);
}
#else
static void flippy_reset(void)
{
DI[1] = 0b100;

DI[2] = DI_CMD_FLIPPY_IPC << 24 | 0x05;
DI[3] = 0xAA55F641;
DI[7] = 0b001;
while (DI[7] & 0b001);

while (!(DI[1] & 0b100));
}

static void flippy_bypass(bool bypass)
{
DI[1] = 0b100;

DI[2] = 0xDC000000;
DI[3] = bypass ? 0 : 0xE3F72BAB;
DI[4] = bypass ? 0 : 0x72648977;
DI[7] = 0b001;
while (DI[7] & 0b001);

while (!(DI[1] & 0b100));
}
#endif

bool do_read_disc(void *buffer, uint32_t length, uint32_t offset, const frag_t *frag, frag_callback callback)
Expand Down Expand Up @@ -225,6 +250,11 @@ void reset_devices(void)
int fragnum = frag_get_list(FRAGS_BOOT_GCM, &frag);
gcode_set_disc_frags(0, frag, fragnum);
gcode_set_disc_number(0);
#else
if (*VAR_DRIVE_FLAGS & 0b10) {
flippy_bypass(false);
flippy_reset();
}
#endif

while (EXI[EXI_CHANNEL_0][3] & 0b000001);
Expand Down
6 changes: 3 additions & 3 deletions cube/reservedarea.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@

.set VAR_CURRENT_DISC, 0x09B0 # current disc number
.set VAR_SECOND_DISC, 0x09B1 # second disc present
.set VAR_DRIVE_PATCHED, 0x09B2 # disc drive patched
.set VAR_DRIVE_FLAGS, 0x09B2 # disc drive patched
.set VAR_EMU_READ_SPEED, 0x09B3 # emulate read speed
.set VAR_EXI_REGS, 0x09B4 # pointer to EXI registers
.set VAR_EXI_SLOT, 0x09B8 # is the EXI slot (0 = slot a, 1 = slot b)
.set VAR_EXI_CPR, 0x09B9 # is the EXI frequency (4 = 16mhz, 5 = 32mhz)
.set VAR_SD_SHIFT, 0x09BA # is the SD Card shift amount when issueing read cmds
.set VAR_ATA_LBA48, 0x09BA # Is the HDD in use a 48 bit LBA supported HDD?
.set VAR_IGR_EXIT_TYPE, 0x09BB # IGR exit type
.set VAR_IGR_TYPE, 0x09BB # IGR exit type
.set VAR_FRAG_LIST, 0x09BC # pointer to fragments (u32 offset, u32 size, u32 rawsector)

.set VAR_DISC_1_ID, 0x09CC # disc 1 header
Expand Down Expand Up @@ -79,7 +79,7 @@ extern char VAR_TVMODE[4]; // TV format

extern char VAR_CURRENT_DISC[1]; // current disc number
extern char VAR_SECOND_DISC[1]; // second disc present
extern char VAR_DRIVE_PATCHED[1]; // disc drive patched
extern char VAR_DRIVE_FLAGS[1]; // disc drive patched
extern char VAR_EMU_READ_SPEED[1]; // emulate read speed
extern char VAR_EXI_REGS[4]; // pointer to EXI registers
extern char VAR_EXI_SLOT[1]; // is the EXI slot (0 = slot a, 1 = slot b)
Expand Down
2 changes: 1 addition & 1 deletion cube/reservedarea.ld
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ VAR_TVMODE = VAR_AREA + 0x00CC; /* TV format */

VAR_CURRENT_DISC = VAR_AREA + 0x09B0; /* current disc number */
VAR_SECOND_DISC = VAR_AREA + 0x09B1; /* second disc present */
VAR_DRIVE_PATCHED = VAR_AREA + 0x09B2; /* disc drive patched */
VAR_DRIVE_FLAGS = VAR_AREA + 0x09B2; /* disc drive patched */
VAR_EMU_READ_SPEED = VAR_AREA + 0x09B3; /* emulate read speed */
VAR_EXI_REGS = VAR_AREA + 0x09B4; /* pointer to EXI registers */
VAR_EXI_SLOT = VAR_AREA + 0x09B8; /* is the EXI slot (0 = slot a, 1 = slot b) */
Expand Down
2 changes: 1 addition & 1 deletion cube/swiss/source/swiss.c
Original file line number Diff line number Diff line change
Expand Up @@ -2149,7 +2149,7 @@ void load_game() {

*(vu8*)VAR_CURRENT_DISC = disc2File && disc2File == fileToPatch->file;
*(vu8*)VAR_SECOND_DISC = !!disc2File;
*(vu8*)VAR_DRIVE_PATCHED = drive_status == DEBUG_MODE;
*(vu8*)VAR_DRIVE_FLAGS = (swissSettings.hasFlippyDrive << 1) | (drive_status == DEBUG_MODE);
*(vu8*)VAR_EMU_READ_SPEED = swissSettings.emulateReadSpeed;
*(vu32**)VAR_EXI_REGS = NULL;
*(vu8*)VAR_EXI_SLOT = (exi_device << 6) | (exi_channel << 4) | (exi_device << 2) | exi_channel;
Expand Down

0 comments on commit a00e7b5

Please sign in to comment.