From 4d441c6ff8efe054ef2f216371005dc37b390a28 Mon Sep 17 00:00:00 2001 From: Blue Date: Mon, 29 Apr 2019 20:13:13 +0200 Subject: [PATCH] Basic hardcoded CD reading (.bin) --- ProjectPSX/Devices/CD.cs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 ProjectPSX/Devices/CD.cs diff --git a/ProjectPSX/Devices/CD.cs b/ProjectPSX/Devices/CD.cs new file mode 100644 index 0000000..b9c5ecd --- /dev/null +++ b/ProjectPSX/Devices/CD.cs @@ -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); + } + + } +} \ No newline at end of file