
1. I apologize for not writing for a long time.
2. Ready PS2 SDK.
I wanted to watch out for the CD (DVD) -ROM Library, so the links and the PS2 SDK installation guide can be found at the end of the second part of this article.
The topic is quite complicated.
I will also be grateful if someone transfers to another non-paid hosting PS2 SDK .
PS2 SDK is available
here .
Narod.ru .
Magnet (link is not normally inserted thanks to the habr parser): magnet:? Xt = urn: btih: F6114E45C5E392E6D213F2547C466FADB5DA5A13 & dn = sce.zip & tr = udp% 3a // tracker.openbittorrent.com% 3a80 / announce
Another link . Thank you
Konstantinus and
ahmpro')
CD (DVD) -ROM Library.
Both IOP and EE are used to operate the drive.
The library responsible for working with the drive is called “libcdvd” (exactly).
EE library to connect: "libcdvd.a".
Header file: “libcdvd.h”.
IOP library for connection: "cdvdman.ilb".
IOP modules: "cdvdman.irx" and "cdvdfsv.irx".
Sector
The normal sector size for reading data is 2048 bytes for a DVD.
For them, there is only one mode.
Well, and the standard size for CD disks (also 2048). However, the sector may be a different size, but, at the moment, it does not matter.
Rotation speed and data transfer
PS2 uses the CAV method, so the speed of the disk is maintained and is constant. Thus, the speed of reading data will be different on the external and internal tracks.
- CD, internal tracks - 10 speed = 1500 KB / s.
- CD, external tracks - 24 speed = 3600 KB / s.
- DVD, internal tracks - 1.6 speed = 2000 KB / s.
- DVD, external tracks - 4 speed = 5000 KB / s.
Oddly enough, the rotation speed can be controlled in the following three ways:
- Using streaming mode (SCECdSpinStm): the rotational speed is adjusted in such a way that the reading can be performed reliably at a constant data rate.
- Normal data mode (SCECdSpinNom): at the beginning, an attempt will be made to read at maximum speed and, if there is a read error, the speed will be reduced to the one at which reading will be normal.
- Dual Layer Disk Mode (SCECdSpinDvdDL0): the same as streaming mode, only for dual layer discs. The speed is read from the zero track.
File system
The file system is used in ISO-9660 format.
There is a limit on the number of files and directories, however, it can be increased by the number of letters in the names of files and folders.
Number of directories in a folder: 40.
Maximum level of nesting: 8.
Number of files in the directory: 30.
File and folder names should consist only of numbers, letters of the English alphabet and underscore. All folder and file names must be in upper case only.
The file name can include no more than 8 characters in the file name and 3 characters in the extension.
The folder name can include no more than 8 characters.
Work with a disk
To read the disc, you need to access it and specify the mode.
After the processor checks it for legality. =)
Then you need to access it again.
After initializing the program, you need to initialize the drive with the sceCdInit () function.
The sceCdInit function takes one of the following parameters:
- SCECdINIT - library initialization, blocking access and waiting for the next command.
- SCECdINoD - only initialization.
- SCECdEXIT - closing the library.
The function returns a number: 0 - initialization failed, 1 - initialization was normal, 2 - initialization has already been completed.
After that, you need to specify the mode of working with the drive using the sceCdMmode () function, which takes one of the two SCECdCD or SCECdDVD parameters for CDs and DVDs, respectively. Returns 1 or 0, which corresponds to the result or not.
Example:
int main(){
sceSifInitRpc(0);
sceCdInit(SCECdINIT); /* CD/DVD */
sceCdMmode(SCECdCD); /* = CD-ROM */
/* */
while ( !sceSifRebootIop(IOPRP) );
while ( !sceSifSyncIop() );
/* */
sceSifInitRpc(0);
sceCdInit(SCECdINIT);
sceCdMmode(SCECdCD); /* = CD-ROM */
sceFsReset();
/* … */
* This source code was highlighted with Source Code Highlighter .
Reading files
To read a file, you first need to find out in which sector it is located.
To do this, there is the sceCdSearchFile () function, which takes the following arguments:
- Pointer to the drive file structure (type sceCdIFILE). It stores the LSN (logical sector number) and the file size after the function has been run.
- The absolute path to the file with the name and extension.
Returns 0 or 1, which means the file is not found or found, respectively.
Those. something like this: ret = sceCdSearchFile (& fp, "\\ SYSTEM.CNF");
This information is cached.
To read the file, there is the sceCdRead () function, which accepts the following parameters: LSN, number of sectors to read, buffer to read, type of reading.
It is necessary to remember that the function is not blocking, so you can learn that the data transfer is completed using the sceCdSync () function.
The sceCdSync () function takes one parameter, which can be of two types:
- 0x00 - will block the stream until the command ends. In this case, the function will return 0 upon completion.
- 0x01 - checks the status and returns the result without blocking the stream. In this case, the function will return 0 or 1.
In order to indicate what type of reading you are using there is a sceCdRMode () function that takes the following parameters:
- u_char - (from 0 to 255) the number of repetitions of a read before a read error is declared.
- u_char - disk rotation speed. One of the options:
- SCECdSpinStm - recommended speed;
- SCECdSpinNom - start reading the disc from the maximum speed and go down to the one on which you can read normally.
- SCECdSpinDvdDL0 - dual-layer disc reading mode.
- u_char - sector size. There is only one type of parameter: SCECdSecS2048, i.e. the size is 2048 bits.
- u_char - filled data for alignment.
The alignment data is used to ensure that the function always occupies the same memory size.
There is also a function through which you can learn about the type of error that occurred -
sceCdGetError ().
Returns the type of error or SCECdErNO if there were no errors.
Using Callback
Instead of waiting, you can use callback functions. They are assigned using the sceCdCallback () function. The parameter takes a pointer to the function address. It is necessary to take into account that the function is called regardless of which asynchronous function has ended. However, the reason code of the function call is passed in the first parameter.
You can not assign a function during the execution of the function called Calbak (sorry for the tautology).
If you pass 0 instead of the parameter, then the cashback will be removed.
The parameter passed to the function from the kelbeck can take the following values:
- SCECdFuncRead - says that the sceCdRead () function has ended
- SCECdFuncSeek - the sceCdSeek () function has ended;
- SCECdFuncStandby - the sceCdStandby () function has been completed;
- SCECdFuncStop - the sceCdStop () function has finished;
- SCECdFuncPause - the sceCdPause () function has ended.
You can not assign a function, type sceCdRead ();
The function returns 0 or the address to the previous callback.
Stream reading
Stream reading requires the use of IOP memory. To use streaming reading, you need to connect the cdvdstm.irx module via the sceSifLoadModule () function.
The stream is loaded into the IOP memory and data can be read from there.
The following functions are used for streaming reading.
sceCdStInit () - initializes the stream and sets the buffer.
Options:
- stream capacity (determined using the number of sectors at 2048 bytes).
- the number of parts of the flow (according to the specification - rings). A buffer with 3 or more parts must have a capacity of more than 16 sectors.
- stream address in memory.
To get a location in the IOP memory, you need to use the sceSifAllocIopHeap () function from the EE Kernel.
The function returns 0 or 1, which is False or True.
sceCdStStart () - start stream filling.
Options:
- position to start reading from the disk. Used LSN.
- type of reading obtained through sceCdRMode ().
Returns the same as the previous one.
sceCdStRead () - read data from stream.
Options:
- the number of sectors to read from the buffer.
- address for reading data (must be aligned to 64 bytes).
- reading type: STMNBLK - returns the information that is in the buffer; STMBLK - returns data, thu is or error.
- variable for the error number.
Returns the number of sectors read.
Error numbers may be as follows:
- 0x00 = SCECdErNO - no error.
- 0x01 = SCECdErABRT - termination command returned.
- 0x13 = SCECdErNORDY - the block is not read.
- 0x14 = SCECdErCUD - the read method is not suitable for a disk in the drive.
- 0x20 = SCECdErIPI - abnormal sector position.
- 0x21 = SCECdErRILI - abnormal number of sectors for reading.
- 0x30 = SCECdErREAD - problems reading from disk.
- 031 = SCECdErTRMOPN - the cover was opened during reading.
sceCdStPause () - pauses streaming fill.
There are no parameters. Returns the success of the operation as 0 or 1.
sceCdStResume () - return streaming fill.
There are no parameters. Returns the success of the operation.
sceCdStSeek () - changing position to read the stream.
The parameter takes LSN. Returns the success of the operation.
sceCdStStat () - get stream read status to buffer.
There are no parameters. Returns 0 in case of an error or the number of sectors read.
sceCdStStop () - stop filling status with stream
There are no parameters. Returns the success of the operation.
After calling sceCdStInit () and performing initialization of the call to sceCdStart (), the data will be read in the background, starting from the specified sector, and store them in a buffer. After sceCdStRead () is executed, the data in the buffer can be read sequentially.
Please note that the following libcdvd functions cannot be used to access the disk during streaming (I will explain them later):
- sceCdChangeThreadPriority ()
- sceCdGetToc ()
- sceCdInit ()
- sceCdMmode ()
- sceCdPause ()
- sceCdRead ()
- sceCdReadChain ()
- sceCdReadIOPm ()
- sceCdSearchFile ()
- sceCdSeek ()
- sceCdStandby ()
- sceCdStop ()
- sceCdSync ()
- sceCdDiskReady ()
- sceCdGetError ()
- sceCdGetReadPos ()
Need to know
The bottom line is that the drive is connected to the IOP and somehow you have to use the IOP functions.
The following data differs between IOP and EE:
- the command to finish reading data from EE means that the data are received by the processor EE, and not the completion of reading data from the disk;
- errors on the EE side affect subsequent actions on the IOP side;
- when transferring data to EE, memory alignment will always occur up to 64 bytes.
- the priority of the stream in EE, which will work with the disk, will correspond to the priority in the IOP, so be careful, otherwise you can lose the normal processing of other IOP streams.
By the end of the first part
The topic is very complex. In the second part I will explain the rest of the article and how to install the PS2 SDK on Windows and Linux.
PS : I apologize for any typos.