Skip to content

Commit

Permalink
webMAN MOD 1.47.45
Browse files Browse the repository at this point in the history
- Reverting changes in commit 6c608e6 due issue #981
  • Loading branch information
aldostools committed Nov 16, 2023
1 parent 6c608e6 commit 51bf6da
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 72 deletions.
217 changes: 145 additions & 72 deletions _Projects_/rawseciso/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ enum EMU_TYPE
#define OK 0
#define FAILED -1

#define ERR_EBUSY 0x8001000A
#define NO_SECTOR 0xFFFFFFFF
#define LAST_SECTOR 1
#define READ_SECTOR 0xFFFFFFFF

#define NONE -1
#define SYS_PPU_THREAD_NONE (sys_ppu_thread_t)NONE
#define SYS_EVENT_QUEUE_NONE (sys_event_queue_t)NONE
#define SYS_DEVICE_HANDLE_NONE (sys_device_handle_t)NONE
#define SYS_EVENT_QUEUE_NONE (sys_event_queue_t)NONE
#define SYS_DEVICE_HANDLE_NONE (sys_device_handle_t)NONE

enum STORAGE_COMMAND
{
Expand Down Expand Up @@ -350,68 +350,13 @@ static void get_next_read(u64 discoffset, u64 bufsize, u64 *offset, u64 *readsiz
DPRINTF("Offset or size out of range %lx%08lx %lx!!!!!!!!\n", discoffset>>32, discoffset, bufsize);
}

u8 prev_sect_buf[4096] __attribute__((aligned(16)));
u32 prev_sect = NO_SECTOR;

static int read_storage(u32 sector, u32 n, u8 *buf)
{
if(prev_sect == sector)
{
return OK;
}

u32 r;
int ret;

for(int x = 0; x < 16; x++)
{
r = 0;
ret = sys_storage_read(handle, 0, sector, n, buf, &r, 0);

if((ret == OK) && (r == n))
{
prev_sect = sector;
return OK;
}

prev_sect = NO_SECTOR;

if(emu_mode == EMU_PSX_MULTI) return (int) ERR_EBUSY;

if((ret == (int) 0x80010002) || (ret == (int) 0x8001002D))
{
if(handle != SYS_DEVICE_HANDLE_NONE) sys_storage_close(handle); handle = SYS_DEVICE_HANDLE_NONE;

while(ntfs_running)
{
if(sys_storage_get_device_info(usb_device, &disc_info) == OK)
{
ret = sys_storage_open(usb_device, 0, &handle, 0);
if(ret == OK) break;

handle = SYS_DEVICE_HANDLE_NONE; sysUsleep(500000);
}
else sysUsleep(7000000);
}

x = -1; continue; // retry
}

if(x >= 15 || !ntfs_running)
{
DPRINTF("sys_storage_read failed: %x 1 -> %x\n", sector, ret);
return FAILED;
}

sysUsleep(100000);
}

return ret;
}
u8 last_sect_buf[4096] __attribute__((aligned(16)));
u32 last_sect = READ_SECTOR;

static int process_read_iso_cmd(u8 *buf, u64 offset, u64 size)
{
u64 remaining;
int x;

//DPRINTF("read iso: %p %lx %lx\n", buf, offset, size);
remaining = size;
Expand All @@ -422,6 +367,7 @@ static int process_read_iso_cmd(u8 *buf, u64 offset, u64 size)
int idx;
int ret;
u32 sector;
u32 r;

if(!ntfs_running) return FAILED;

Expand All @@ -439,15 +385,59 @@ static int process_read_iso_cmd(u8 *buf, u64 offset, u64 size)
if(pos % sec_size)
{
sector = sections[idx] + (pos / sec_size);
for(x = 0; x < 16; x++)
{
r = 0;
if(last_sect == sector)
{
ret = OK; r = LAST_SECTOR;
}
else
ret = sys_storage_read(handle, 0, sector, 1, last_sect_buf, &r, 0);

if((ret == OK) && (r == LAST_SECTOR))
last_sect = sector;
else
last_sect = READ_SECTOR;

if((ret != OK) || (r != LAST_SECTOR))
{
if(emu_mode == EMU_PSX_MULTI) return (int) 0x8001000A; // EBUSY

if((ret == (int) 0x80010002) || (ret == (int) 0x8001002D))
{
if(handle != SYS_DEVICE_HANDLE_NONE) sys_storage_close(handle); handle = SYS_DEVICE_HANDLE_NONE;

while(ntfs_running)
{
if(sys_storage_get_device_info(usb_device, &disc_info) == OK)
{
ret = sys_storage_open(usb_device, 0, &handle, 0);
if(ret == OK) break;

handle = SYS_DEVICE_HANDLE_NONE; sysUsleep(500000);
}
else sysUsleep(7000000);
}
x= -1; continue;
}


ret = read_storage(sector, 1, prev_sect_buf);
if(ret == (int) ERR_EBUSY || ret == FAILED) return (int) ret;
if(x == 15 || !ntfs_running)
{
DPRINTF("sys_storage_read failed: %x 1 -> %x\n", sector, ret);
return FAILED;
}
else sysUsleep(100000);
}
else break;
}

u64 csize = sec_size - (pos % sec_size);

if(csize > readsize) csize = readsize;

memcpy64(buf, prev_sect_buf + (pos % sec_size), csize);
memcpy64(buf, last_sect_buf + (pos % sec_size), csize);
buf += csize;
offset += csize;
pos += csize;
Expand All @@ -462,9 +452,47 @@ static int process_read_iso_cmd(u8 *buf, u64 offset, u64 size)
if(n)
{
sector = sections[idx] + (pos / sec_size);
for(x = 0; x < 16; x++)
{
r = 0;
ret = sys_storage_read(handle, 0, sector, n, buf, &r, 0);

ret = read_storage(sector, n, buf);
if(ret == (int) ERR_EBUSY || ret == FAILED) return (int) ret;
if((ret == OK) && (r == n))
last_sect = sector + n - 1;
else
last_sect = READ_SECTOR;

if((ret != OK) || (r != n))
{
if(emu_mode == EMU_PSX_MULTI) return (int) 0x8001000A; // EBUSY

if((ret == (int) 0x80010002) || (ret == (int) 0x8001002D))
{
if(handle != SYS_DEVICE_HANDLE_NONE) sys_storage_close(handle); handle = SYS_DEVICE_HANDLE_NONE;

while(ntfs_running)
{
if(sys_storage_get_device_info(usb_device, &disc_info) == OK)
{
ret = sys_storage_open(usb_device, 0, &handle, 0);
if(ret == OK) break;

handle = SYS_DEVICE_HANDLE_NONE; sysUsleep(500000);
}
else sysUsleep(7000000);
}
x= -1; continue;
}

if(x == 15 || !ntfs_running)
{
DPRINTF("sys_storage_read failed: %x %x -> %x\n", sector, n, ret);
return FAILED;
}
else sysUsleep(100000);
}
else break;
}

u64 s = n * sec_size;

Expand All @@ -478,11 +506,54 @@ static int process_read_iso_cmd(u8 *buf, u64 offset, u64 size)
if(readsize)
{
sector = sections[idx] + pos / sec_size;
for(x = 0; x < 16; x++)
{
r = 0;
if(last_sect == sector)
{
ret = OK; r = LAST_SECTOR;
}
else
ret = sys_storage_read(handle, 0, sector, 1, last_sect_buf, &r, 0);

if((ret == OK) && (r == LAST_SECTOR))
last_sect = sector;
else
last_sect = READ_SECTOR;

if((ret != OK) || (r != LAST_SECTOR))
{
if(emu_mode == EMU_PSX_MULTI) return (int) 0x8001000A; // EBUSY

if((ret == (int) 0x80010002) || (ret == (int) 0x8001002D))
{
if(handle != SYS_DEVICE_HANDLE_NONE) sys_storage_close(handle); handle = SYS_DEVICE_HANDLE_NONE;

ret = read_storage(sector, 1, prev_sect_buf);
if(ret == (int) ERR_EBUSY || ret == FAILED) return (int) ret;
while(ntfs_running)
{
if(sys_storage_get_device_info(usb_device, &disc_info) == OK)
{
ret = sys_storage_open(usb_device, 0, &handle, 0);
if(ret == OK) break;

handle = SYS_DEVICE_HANDLE_NONE; sysUsleep(500000);
}
else sysUsleep(3000000);
}
x= -1; continue;
}

memcpy64(buf, prev_sect_buf, readsize);
if(x == 15 || !ntfs_running)
{
DPRINTF("sys_storage_read failed: %x 1 -> %x\n", sector, ret);
return FAILED;
}
else sysUsleep(100000);
}
else break;
}

memcpy64(buf, last_sect_buf, readsize);
buf += readsize;
offset += readsize;
remaining -= readsize;
Expand Down Expand Up @@ -643,7 +714,7 @@ static int process_read_psx_cmd(u8 *buf, u64 offset, u64 size, u32 ssector)
ret = cellFsReadWithOffset(discfd, pos, buf + rel, readsize, &p);
if(ret)
{
if(ret == (int) 0x8001002B) return (int) ERR_EBUSY;
if(ret == (int) 0x8001002B) return (int) 0x8001000A; // EBUSY

return OK;
}
Expand Down Expand Up @@ -949,6 +1020,8 @@ static void eject_thread(u64 arg)
}
}



while(do_run) sysUsleep(100000);

psx_indx = (psx_indx + 1) & 7;
Expand Down Expand Up @@ -1282,7 +1355,7 @@ static void rawseciso_thread(u64 arg)
ret = sys_event_port_send(result_port, ret, 0, 0);
if(ret == OK) break;

if(ret == (int) ERR_EBUSY)
if(ret == (int) 0x8001000A)
{ // EBUSY
sysUsleep(100000);
continue;
Expand Down
Binary file modified _Projects_/updater/pkgfiles/USRDIR/res/raw_iso.sprx
Binary file not shown.
Binary file modified _Projects_/updater/update/dev_hdd0/tmp/wm_res/raw_iso.sprx
Binary file not shown.

0 comments on commit 51bf6da

Please sign in to comment.