Skip to content

Commit

Permalink
Merge pull request #50 from LuigiBlood/libleo
Browse files Browse the repository at this point in the history
libleo changes
  • Loading branch information
RevoSucks authored Jul 29, 2023
2 parents 857c200 + d5c82e8 commit 62bb0e3
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 6 deletions.
2 changes: 1 addition & 1 deletion include/libleo/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ extern u16 leoLba_to_phys(u32 lba);
extern s32 __leoActive;
extern s32 __leoResetCalled;
extern s32 __leoQueuesCreated;
extern s32 LEO_country_code;
extern u32 LEO_country_code;
extern u32 LEOasic_bm_ctl_shadow;
extern u32 LEOasic_seq_ctl_shadow;
extern u8 LEOdisk_type;
Expand Down
2 changes: 1 addition & 1 deletion src/libleo/cjcreateleomanager.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ s32 LeoCJCreateLeoManager(OSPri comPri, OSPri intPri, OSMesg *cmdBuf, s32 cmdMsg

dummy *= data;
dummy -= (u32)&cmdBlockInq;
LEO_country_code = -0x17B72CEA;
LEO_country_code = 0xE848D316;
} else {
while (1) {}
}
Expand Down
4 changes: 2 additions & 2 deletions src/libleo/driveexist.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ void __osPiRelAccess(void);
void __osPiGetAccess(void);

#define CONNECTED 0x2129FFF8
#define DDROM_STATUS_REG 0x06001010
#define DDROM_ADDRESS_CHECK 0x06001010

// https://github.com/LuigiBlood/64dd/wiki/64DD-IPL
u32 LeoDriveExist(void) {
Expand All @@ -30,7 +30,7 @@ u32 LeoDriveExist(void) {
HW_REG(PI_BSD_DOM1_RLS_REG, u32) = 3;
HW_REG(PI_BSD_DOM1_PWD_REG, u32) = 0xFF;

ddromStatus = HW_REG(DDROM_STATUS_REG, u32);
ddromStatus = HW_REG(DDROM_ADDRESS_CHECK, u32);

HW_REG(PI_BSD_DOM1_LAT_REG, u32) = lastLatency;
HW_REG(PI_BSD_DOM1_PGS_REG, u32) = lastPageSize;
Expand Down
90 changes: 88 additions & 2 deletions src/libleo/leocmdex.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,91 @@
#include "common.h"
#include <ultra64.h>
#include <leo.h>
#include "libleo/internal.h"

extern u16 LEOrw_flags;

#pragma GLOBAL_ASM("asm/nonmatchings/libleo/leocmdex/leomain.s")

#pragma GLOBAL_ASM("asm/nonmatchings/libleo/leocmdex/leoRead_system_area.s")
/*const LEOCmdRead leo_sys_read_cmd =
{
{LEO_COMMAND_READ,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00000000},
12,1,0,0
};
const u8 leo_sys_form_lbas[] = {0, 1, 8, 9};*/

extern LEOCmdRead leo_sys_read_cmd;
extern u8 leo_sys_form_lbas[];

u8 leoRead_system_area(void) {
LEOCmdRead temp_cmd;
LEOCmd* prev_cmd;
u32 retry_cntr;
s32 read_mode;

prev_cmd = LEOcur_command;
LEOcur_command = (LEOCmd*)&temp_cmd;
read_mode = 0;
retry_cntr = 0;

while (1) {
LEOdisk_type = 0;
//For lba_to_phys to avoid dealing with alternative tracks on the disk
LEO_sys_data.param.defect_num[0] = 0;
LEOrw_flags = 0x3000;
temp_cmd = leo_sys_read_cmd;
temp_cmd.buff_ptr = &LEO_sys_data;

if (read_mode == 0) {
//read System LBA 12 (+0, this is an offset value for leoRead_common)
//see leo_sys_read_cmd premade struct
leoRead_common(0);
switch (temp_cmd.header.sense) {
case LEO_SENSE_NO_ADDITIONAL_SENSE_INFOMATION:
do {
//if expecting a retail disk, LBA 12 is expected to do a read error, if not then freeze
} while (LEO_country_code != 0);
retry_cntr = 0;
read_mode--;
continue;
case LEO_SENSE_UNRECOVERED_READ_ERROR:
do {
//if expecting a development disk, LBA 12 is expected to read correctly, if not then freeze
} while (LEO_country_code == 0);
retry_cntr = 0;
read_mode--;
continue;
}
} else {
//read System LBA 0,1,8,9 (or 2,3,10,11 for dev)
temp_cmd.lba = leo_sys_form_lbas[retry_cntr & 3];
if (LEO_country_code == 0) {
temp_cmd.lba += 2;
}
leoRead_common(0);
if (temp_cmd.header.status == LEO_STATUS_GOOD) {
do {
//if disk country and set country code in libleo mismatch, then freeze
} while (LEO_sys_data.param.country != LEO_country_code);
break;
}
}
system_retry:
if (leoChk_err_retry(temp_cmd.header.sense) != LEO_SENSE_NO_ADDITIONAL_SENSE_INFOMATION) {
break;
}
if (retry_cntr++ >= 0x40U) {
break;
}
if ((retry_cntr & 7) == 0) {
//Recalibrate drive every 8th tries
if ((temp_cmd.header.sense = leoSend_asic_cmd_w(ASIC_RECAL, 0)) == LEO_SENSE_NO_ADDITIONAL_SENSE_INFOMATION) {
continue;
}
goto system_retry;
}
}
LEOcur_command = prev_cmd;
prev_cmd->header.sense = temp_cmd.header.sense;
return prev_cmd->header.sense;
}
3 changes: 3 additions & 0 deletions tools/symbol_addrs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ LEORAM_BYTE = 0x8007DD28;
LEOVZONE_TBL = 0x8007DB98;
LEOVZONE_PZONEHD_TBL = 0x8007DC98;
LEOBYTE_TBL2 = 0x8007DB84;
leo_sys_read_cmd = 0x80079560;
leo_sys_form_lbas = 0x8007DA40;
LEO_sys_data = 0x800FF9F0;
LEOdrive_flag = 0x801006D4;
LEOtgt_param = 0x801006E0;
leoDiskStack = 0x801020D0;
Expand Down

0 comments on commit 62bb0e3

Please sign in to comment.