Decompiled leoRead_system_area()

This commit is contained in:
LuigiBlood
2023-07-29 22:33:18 +02:00
parent 63b0f8bb45
commit d5c82e8a7d
2 changed files with 91 additions and 2 deletions

View File

@@ -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;
}

View File

@@ -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;