From d5c82e8a7d02eee326863b946c6c54fbca42daff Mon Sep 17 00:00:00 2001 From: LuigiBlood Date: Sat, 29 Jul 2023 22:33:18 +0200 Subject: [PATCH] Decompiled leoRead_system_area() --- src/libleo/leocmdex.c | 90 +++++++++++++++++++++++++++++++++++++++++- tools/symbol_addrs.txt | 3 ++ 2 files changed, 91 insertions(+), 2 deletions(-) diff --git a/src/libleo/leocmdex.c b/src/libleo/leocmdex.c index 8b74dac..7d7bd42 100644 --- a/src/libleo/leocmdex.c +++ b/src/libleo/leocmdex.c @@ -1,5 +1,91 @@ -#include "common.h" +#include +#include +#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; +} diff --git a/tools/symbol_addrs.txt b/tools/symbol_addrs.txt index 72e1635..21905f0 100644 --- a/tools/symbol_addrs.txt +++ b/tools/symbol_addrs.txt @@ -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;