MemCard problem?

BIOS, Controllers, Memory Cards, Serial I/O, Parallel I/O, etc.
Post Reply
NaughtyCow
Curious PSXDEV User
Curious PSXDEV User
Posts: 15
Joined: Jun 07, 2016
I am a: Student
Location: Croatia

MemCard problem?

Post by NaughtyCow » June 20th, 2016, 1:50 am

I'm trying to write some data onto the memory card, and I've followed the etc\makecard example in the PSYQ, lib, properly initializing the memory card, as well as properly opening it with open(...), etc.. Everything according to that example. For writing, I'm just using the Crash Bandicoot PAL file that I ripped from a Save File I downloaded from GameFaqs (I used Shendo's tool, and saved as Raw)... Anyway, the save file gets written, but there is no icon and no title, and the save is not recognized internally by the bios memcard manager, only by MemCardRex.. I used NO$PSX, and it doesn't proceed with the code after it fails (it freezes somehow), and when I used ePSXe emulutaor, it proceeds, but the error is caught and the error screen I created is shown.

Some code:
[C]int isAnyDataOnMC(char* fname) {
long fd;
if ((fd = open(fname, O_RDONLY )) == -1)
return 0;
close(fd);
return 1;
}

int writeDataOnMC(char* fname, Data* data, unsigned char creat, char blocks) {
long fd;
if (creat) {
if ((fd = open( fname, O_CREAT | blocks << 16 )) == -1)
return 1;
close(fd);
}
if (fd = open( fname, O_WRONLY ) == -1)
return 1;
if (write( fd, (unsigned char*)data->ptr, 8192 * blocks) != 8192 * blocks)
return 1;

close(fd);
return 0;
}

void showOverwrite(Data* data) {
// supposed to show "Do you wish to overwrite" screen? For now, just writes without creating the file.
if (writeDataOnMC("bu10:BESCES-00344972726", data, 0, 1))
exitError();
}[/C]

[C]// This triggers the save
Data d_Tempx;
if (!readfile("\\DATA\\CPSX.DAT;1", &d_Tempx, 0)) exitError();
if (isAnyDataOnMC("bu10:BESCES-00344972726")) showOverwrite(&d_Tempx);
else if (writeDataOnMC("bu10:BESCES-00344972726", &d_Tempx, 1, 1)) exitError();
freedata(&d_Tempx);[/C]

ADDENDUM: The file that gets written is completely null (all zeros).

NaughtyCow
Curious PSXDEV User
Curious PSXDEV User
Posts: 15
Joined: Jun 07, 2016
I am a: Student
Location: Croatia

Post by NaughtyCow » June 20th, 2016, 11:02 pm

anyone?

NaughtyCow
Curious PSXDEV User
Curious PSXDEV User
Posts: 15
Joined: Jun 07, 2016
I am a: Student
Location: Croatia

Post by NaughtyCow » June 21st, 2016, 12:01 am

Nevermind, I solved it. Turns out I forgot the brackets, which was setting the file descriptor to -1...

[C]if ((fd = open( fname, O_WRONLY )) == -1)
if (write( fd, (unsigned char*)data->ptr, 8192 * blocks) != (8192 * blocks)[/C]

I also have an another question. Is there any way to check if the memory card is in the slot, or if it requires formatting (and also how to format it).

User avatar
Shadow
Verified
Admin / PSXDEV
Admin / PSXDEV
Posts: 2670
Joined: Dec 31, 2012
PlayStation Model: H2000/5502
Discord: Shadow^PSXDEV

Post by Shadow » June 21st, 2016, 12:27 am

NaughtyCow wrote:I also have an another question. Is there any way to check if the memory card is in the slot, or if it requires formatting (and also how to format it).
Sony has some examples for that.
Development Console: SCPH-5502 with 8MB RAM, MM3 Modchip, PAL 60 Colour Modification (for NTSC), PSIO Switch Board, DB-9 breakout headers for both RGB and Serial output and an Xplorer with CAETLA 0.34.

PlayStation Development PC: Windows 98 SE, Pentium 3 at 400MHz, 128MB SDRAM, DTL-H2000, DTL-H2010, DTL-H201A, DTL-S2020 (with 4GB SCSI-2 HDD), 21" Sony G420, CD-R burner, 3.25" and 5.25" Floppy Diskette Drives, ZIP 100 Diskette Drive and an IBM Model M keyboard.

NaughtyCow
Curious PSXDEV User
Curious PSXDEV User
Posts: 15
Joined: Jun 07, 2016
I am a: Student
Location: Croatia

Post by NaughtyCow » June 21st, 2016, 12:45 am

Shadow wrote:
NaughtyCow wrote:I also have an another question. Is there any way to check if the memory card is in the slot, or if it requires formatting (and also how to format it).
Sony has some examples for that.
Thank, I've just found some myself. Also I was wondering (unrelated to this topic) does the CD-ROM have some limitations, as of maximum number of subdirectiries and files in one folder? I remember reading something about that. Something I also read was that the file size of every file must be divisible by 2048 bytes (2 KB) or else the CD wont load on the actual machine? Is that true?

User avatar
Shadow
Verified
Admin / PSXDEV
Admin / PSXDEV
Posts: 2670
Joined: Dec 31, 2012
PlayStation Model: H2000/5502
Discord: Shadow^PSXDEV

Post by Shadow » June 21st, 2016, 12:54 am

Yes it is true. I can't remember the exact number, but it's mentioned somewhere in the Sony documents.
Development Console: SCPH-5502 with 8MB RAM, MM3 Modchip, PAL 60 Colour Modification (for NTSC), PSIO Switch Board, DB-9 breakout headers for both RGB and Serial output and an Xplorer with CAETLA 0.34.

PlayStation Development PC: Windows 98 SE, Pentium 3 at 400MHz, 128MB SDRAM, DTL-H2000, DTL-H2010, DTL-H201A, DTL-S2020 (with 4GB SCSI-2 HDD), 21" Sony G420, CD-R burner, 3.25" and 5.25" Floppy Diskette Drives, ZIP 100 Diskette Drive and an IBM Model M keyboard.

NaughtyCow
Curious PSXDEV User
Curious PSXDEV User
Posts: 15
Joined: Jun 07, 2016
I am a: Student
Location: Croatia

Post by NaughtyCow » June 21st, 2016, 1:00 am

NaughtyCow wrote: ...file size of every file must be divisible by 2048 bytes (2 KB) or else the CD wont load on the actual machine? Is that true?
Is this also true, or will this code (for length of file ceiled to the nearest factor of 2048) eliminate that issue if I use it for read length:
[C]/* num = actual length , factor = 2048 */
num + (((num % factor) > 0) ? factor : 0);[/C]

Sorry if I'm seeming arrogant. I have a limited amount of CD-R's, and I cannot afford to screw up when burning by program.

User avatar
Shadow
Verified
Admin / PSXDEV
Admin / PSXDEV
Posts: 2670
Joined: Dec 31, 2012
PlayStation Model: H2000/5502
Discord: Shadow^PSXDEV

Post by Shadow » June 21st, 2016, 2:27 am

I've never ran into problems with padding or reading files to 2048.
One of my read routines however is shown below.

[C]int _read2(long byte, void *sectbuf, int mode)
{
int nsector,cnt;
nsector=(byte+2047)/2048;

// read start
CdRead(nsector, sectbuf, mode);

while((cnt=CdReadSync(1,NULL))>0) VSync(0);
return cnt;
}[/C]
Development Console: SCPH-5502 with 8MB RAM, MM3 Modchip, PAL 60 Colour Modification (for NTSC), PSIO Switch Board, DB-9 breakout headers for both RGB and Serial output and an Xplorer with CAETLA 0.34.

PlayStation Development PC: Windows 98 SE, Pentium 3 at 400MHz, 128MB SDRAM, DTL-H2000, DTL-H2010, DTL-H201A, DTL-S2020 (with 4GB SCSI-2 HDD), 21" Sony G420, CD-R burner, 3.25" and 5.25" Floppy Diskette Drives, ZIP 100 Diskette Drive and an IBM Model M keyboard.

User avatar
nocash
Verified
PSX Aficionado
PSX Aficionado
Posts: 548
Joined: Nov 12, 2012
Contact:

Post by nocash » June 23rd, 2016, 8:56 am

NaughtyCow wrote:does the CD-ROM have some limitations, as of maximum number of subdirectiries and files in one folder? I remember reading something about that. Something I also read was that the file size of every file must be divisible by 2048 bytes (2 KB) or else the CD wont load on the actual machine? Is that true?
I don't think that the filesize must be a multiple of 2048 bytes, as far as I remember, the SYSTEM.CNF file is much smaller (just check some retail discs if you want to be sure).

But the other restrictions do exist, the PSX BIOS/Kernel is loading only one 800h-byte sector per directory, and only one 800h-byte sector for the path table - even if the directory or path table is bigger than one sector. Moreover, the PSX is extracting the info from the path table and current directory to an array with limited number of entries:
- max 40 files per directory
- max 44 directories per disc

Anyways, the filesize, and and max number of files and directories are just a software issue, nothing related to real hardware. If you are using a copy the original PSX BIOS/Kernel, then you can safely test that stuff in emulators. Or, if you don't have a copy of the original bios: the bios clone included in no$psx should be also reproducing the filesystem behaviour of the original bios quite well.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests