• Welcome to Final Fantasy Hacktics. Please login or sign up.
 
April 16, 2024, 11:30:26 am

News:

Don't be hasty to start your own mod; all our FFT modding projects are greatly understaffed! Find out how you can help in the Recruitment section or our Discord!


FFTPatcher question about PS1 error detection and correction?

Started by nitwit, September 01, 2015, 04:30:20 am

nitwit

I'm curious about how FFTPatcher directly patches a disc image, specifically how it updates the error detection and correction areas when data in a sector is altered.  Does anyone have any technical information on this?

https://github.com/Glain/FFTPatcher/blob/master/PatcherLib/ISOPatching/IsoPatch.cs

This seems useful.  I'm not familiar with C# though so I can't follow it that well.

Xifanie

Nope! But I'm also extremely curious about this as well, because I made a spreadsheet which can import entire folders of files, reorganize the file index and so on, but yeah; can't recalculate that. Sticking to CDMage for that right now :/

I also want to point out that at least some emulators don't seem to care about that portion at all and still run perfectly smoothly.
  • Modding version: PSX
Love what you're seeing? https://supportus.ffhacktics.com/ 💜 it's really appreciated

Anything is possible as long as it is within the hardware's limits. (ie. disc space, RAM, Video RAM, processor, etc.)
<R999> My target market is not FFT mod players
<Raijinili> remember that? it was awful

nitwit

QuoteNope! But I'm also extremely curious about this as well, because I made a spreadsheet which can import entire folders of files, reorganize the file index and so on, but yeah; can't recalculate that. Sticking to CDMage for that right now :/

It can't be that complicated.

https://en.wikipedia.org/wiki/CD-ROM#Mode_2_Form_1

Format                   -  <----------------------- 2,352 byte sector structure ----------------------------->
Format (Details)         - Sync pattern - Address - Mode - Subheader - Data - Error detection - Error correction
CD-ROM XA Mode 2, Form 1 - 12           - 3       - 1    - 8         - 2048 - 4               - 276
CD-ROM XA Mode 2, Form 2 - 12           - 3       - 1    - 8         - 2324 - 0               - 4


It takes a little thought, but even a spreadsheet could calculate addresses to write data to - given the sector that a file starts at and the offset in the file to start reading or writing.  I just haven't found anything on how to calculate EDC and ECC.  Don't know what the Sync pattern, address, or subheader is either.

Quote
I also want to point out that at least some emulators don't seem to care about that portion at all and still run perfectly smoothly.

It matters if you want to run an eboot on a PSP.

http://consolecopyworld.com/psx/psx_cd_info.shtml

Paydirt!
http://users.utcluj.ro/~baruch/media/siee/labor/Compact-Discs.pdf.

Xifanie

Well, like I said, if it's for something like that, you can use CDMage to scan all the sectors and repair that information. It works wonderfully. Of course, I'd rather code the function to avoid having to do that, since it takes a while to scan a 500mb file. And I just never can replicate code from one language to another. >>;
  • Modding version: PSX
Love what you're seeing? https://supportus.ffhacktics.com/ 💜 it's really appreciated

Anything is possible as long as it is within the hardware's limits. (ie. disc space, RAM, Video RAM, processor, etc.)
<R999> My target market is not FFT mod players
<Raijinili> remember that? it was awful

nitwit

What languages do you work in?

I don't think CD Mage is open source.

nitwit

My computer organization instructor said we're going over CRC generation on Monday or Tuesday.  If and when I have an algorithm for generating EDC and ECC I'll share it.

Xifanie

So, I'm guessing you never got anything out of this huh. Because I could really use that stuff right now.
And C++ and VBA... but at this point I'd prefer C++. :v

Error Detection Code (EDC) is 4 bytes, it's the CRC.
Error Correction Code (ECC), if present, is 276 bytes... using  Reed-Solomon error correction (which uses Galois arithmetic), probably.

Might've found something here, but it still hurts my brain: https://schifra.codeplex.com/SourceControl/latest#schifra_crc.hpp
I'm still extremely new to C++.
  • Modding version: PSX
Love what you're seeing? https://supportus.ffhacktics.com/ 💜 it's really appreciated

Anything is possible as long as it is within the hardware's limits. (ie. disc space, RAM, Video RAM, processor, etc.)
<R999> My target market is not FFT mod players
<Raijinili> remember that? it was awful

nitwit

Quote from: Xifanie on July 07, 2016, 09:29:49 am
So, I'm guessing you never got anything out of this huh. Because I could really use that stuff right now.

I bitterly regret attending this school.  It has the worst computer science program in my state.  Portland Community College has a better CS/CIS program than we do.  The only schools with worse programs are the ones that barely have programs, but even then it's debatable if it's worse since you have far fewer filler classes and no utterly malicious instructors.

But enough of my disappointment.

Quote from: Xifanie on July 07, 2016, 09:29:49 am
And C++ and VBA... but at this point I'd prefer C++. :v

Error Detection Code (EDC) is 4 bytes, it's the CRC.
Error Correction Code (ECC), if present, is 276 bytes... using  Reed-Solomon error correction (which uses Galois arithmetic), probably.

Might've found something here, but it still hurts my brain: https://schifra.codeplex.com/SourceControl/latest#schifra_crc.hpp
I'm still extremely new to C++.

Good luck with C++, and keep at it.

I'm emailing the creator of jPSXdec - a Java tool to extract and insert STR files from PS1 disc images - about how to read directory sectors in disc images, and once that's figured out how to build ECC and EDC from a given sector.  If I ever do, I'll give you pseudocode to generate it.

Java is not much like C++, but if you have experience with C# you should be able to muddle through it.  Bear in mind that both of these contain code for dealing with audio and video, neither of which are relevant to our interests (well maybe not yours).

Here is a good portion of the relevant disc image handling code:
https://kenai.com/projects/jpsxdec/sources/svn/show/trunk/jpsxdec/src/jpsxdec/cdreaders

I vaguely remember seeing some simple and easy to follow code written in D a long time ago but I think it was hosted on Google Code, which is long since dead.

nitwit

The jPSXdec guy told me - very politely - to read the spec, pleb.

So in short, I'm on my own.  Next time I'll make false statements to trigger his autism and bait him into replying to me.

Does anyone else think that programmers should be beaten a few times a year to keep them grounded?  I never understood just how worthy of hate most computer scientists are until I starting going to school with them.  They are pure autism, superiority complex, and power-tripping.  They think that because their shitty instructors academically hazed them that they have the right to do the same to everyone else.

You'd think that someone involved in modding and open source would want to make their software and the information they used to make their software as accessible as possible, but the urge to 'tism is far too overwhelming.


Quote15:31   nitwit   i'm typing a reply on the EDC/ECC thread, but do you know how the data sectors that store file and directory locations work?
15:31   nitwit   like how long each entry is?
15:33   Xifanie   only from looking at it myself... couldn't find info about the structure online
15:34   nitwit   yeah i can't find anything about it in the specs, mostly because i don't know what it is called.
15:35   Xifanie   the header + subheader is 24 bytes, then comes 2048 of data, then 4 bytes of CRC, then 276 bytes of error correction
15:35   Xifanie   that's form 1
15:35   nitwit   i know that
15:35   Xifanie   kay, then I have no info
15:35   nitwit   i mean the data for i think the 16th sector (?)
15:35   nitwit   where it has the name of the file or directory in ascii (SCUS, BATTLE.BIN, MON) and other information
15:37   nitwit   
15:37   nitwit   Really?
15:37   nitwit   x
15:37   nitwit   i.sli.mg/NRumkM.png
15:37   nitwit   that's what i'm talking about
15:37   Xifanie   I know it's something like an identifier (file or directory) then the name, sector offset, then the sector offset in big endian, then the file size, file size in big endian
15:38   nitwit   in that order?
15:38   Xifanie   I haven't touched the stuff in a while
15:38   Xifanie   nope
15:38   nitwit   what delimits each entry?
15:38   Xifanie   the string has a delimiter, probably 0x00
15:39   Xifanie   uh, and that "XA" should be the delimiter IIRC
15:40   nitwit   well that's good enough