mirror of
https://github.com/BluestormDNA/ProjectPSX.git
synced 2025-04-02 10:52:34 -04:00
Basic hardcoded CD reading (.bin)
This commit is contained in:
parent
37297ce936
commit
4d441c6ff8
1 changed files with 38 additions and 0 deletions
38
ProjectPSX/Devices/CD.cs
Normal file
38
ProjectPSX/Devices/CD.cs
Normal file
|
@ -0,0 +1,38 @@
|
|||
using System.IO;
|
||||
using System;
|
||||
|
||||
namespace ProjectPSX.Devices {
|
||||
internal class CD {
|
||||
|
||||
private const int BYTES_PER_SECTOR_RAW = 2352;
|
||||
private const int BYTES_PER_SECTOR_DATA = 2048;
|
||||
private const int BYTES_PER_SECTOR_HEADER = 24;
|
||||
|
||||
private FileStream stream;
|
||||
private BinaryReader reader;
|
||||
|
||||
public CD() {
|
||||
//temporary hard coded
|
||||
stream = new FileStream("./crash.bin", FileMode.Open, FileAccess.Read);
|
||||
reader = new BinaryReader(stream);
|
||||
}
|
||||
|
||||
public byte[] read(bool isSectorSizeRAW, int loc) {
|
||||
int bytesToRead;
|
||||
int sectorHeaderOffset;
|
||||
if (isSectorSizeRAW){
|
||||
bytesToRead = BYTES_PER_SECTOR_RAW;
|
||||
sectorHeaderOffset = 0;
|
||||
} else {
|
||||
bytesToRead = BYTES_PER_SECTOR_DATA;
|
||||
sectorHeaderOffset = BYTES_PER_SECTOR_HEADER;
|
||||
}
|
||||
|
||||
stream.Seek(loc * BYTES_PER_SECTOR_RAW + sectorHeaderOffset, 0);
|
||||
//Console.WriteLine("LOC = " + loc + " " + ((loc * BYTES_PER_SECTOR_RAW) + sectorHeaderOffset).ToString("x8"));
|
||||
//Console.ReadLine();
|
||||
return reader.ReadBytes(bytesToRead);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue