Skip to content

Commit

Permalink
big discsystem refactors and preliminary CCD handling. not to be cons…
Browse files Browse the repository at this point in the history
…idered stable, but ill start supporting it.
  • Loading branch information
zeromus committed Dec 4, 2014
1 parent d8a2045 commit 29b217b
Show file tree
Hide file tree
Showing 31 changed files with 1,908 additions and 623 deletions.
11 changes: 9 additions & 2 deletions BizHawk.Client.Common/RomLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,16 @@ private bool PreferredPlatformIsDefined(string extension)
try
{
var ext = file.Extension.ToLower();
if (ext == ".iso" || ext == ".cue")
if (ext == ".iso" || ext == ".cue" || ext == ".ccd")
{
var disc = ext == ".iso" ? Disc.FromIsoPath(path) : Disc.FromCuePath(path, new CueBinPrefs());
Disc disc = null;
if(ext == ".iso")
disc = Disc.FromIsoPath(path);
if(ext == ".cue")
disc = Disc.FromCuePath(path, new CueBinPrefs());
if (ext == ".ccd")
disc = Disc.FromCCDPath(path);

var hash = disc.GetHash();
game = Database.CheckDatabase(hash);
if (game == null)
Expand Down
8 changes: 4 additions & 4 deletions BizHawk.Client.DiscoHawk/AudioExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ class AudioExtractor
public static void Extract(Disc disc, string path, string filebase)
{
bool confirmed = false;
var tracks = disc.TOC.Sessions[0].Tracks;
var tracks = disc.Structure.Sessions[0].Tracks;
foreach (var track in tracks)
{
if (track.TrackType != ETrackType.Audio)
continue;

var waveData = new byte[track.length_aba * 2352];
var waveData = new byte[track.LengthInSectors * 2352];
int startLba = track.Indexes[1].LBA;
for (int sector = 0; sector < track.length_aba; sector++)
for (int sector = 0; sector < track.LengthInSectors; sector++)
disc.ReadLBA_2352(startLba + sector, waveData, sector * 2352);

string mp3Path = string.Format("{0} - Track {1:D2}.mp3", Path.Combine(path, filebase), track.num);
string mp3Path = string.Format("{0} - Track {1:D2}.mp3", Path.Combine(path, filebase), track.Number);
if (File.Exists(mp3Path))
{
if (!confirmed)
Expand Down
6 changes: 5 additions & 1 deletion BizHawk.Client.DiscoHawk/BizHawk.Client.DiscoHawk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{C4366030-6D03-424B-AE53-F4F43BB217C3}</ProjectGuid>
<OutputType>WinExe</OutputType>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>BizHawk.Client.DiscoHawk</RootNamespace>
<AssemblyName>DiscoHawk</AssemblyName>
Expand Down Expand Up @@ -153,6 +153,10 @@
<Content Include="discohawk.ico" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BizHawk.Common\BizHawk.Common.csproj">
<Project>{866F8D13-0678-4FF9-80A4-A3993FD4D8A3}</Project>
<Name>BizHawk.Common</Name>
</ProjectReference>
<ProjectReference Include="..\BizHawk.Emulation.DiscSystem\BizHawk.Emulation.DiscSystem.csproj">
<Project>{f51946ea-827f-4d82-b841-1f2f6d060312}</Project>
<Name>BizHawk.Emulation.DiscSystem</Name>
Expand Down
4 changes: 4 additions & 0 deletions BizHawk.Client.DiscoHawk/DiscoHawk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ public void Run(string[] args)
dialog.ShowDialog();
return;
}
else
{
//test stuff...
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions BizHawk.Client.DiscoHawk/DiscoHawkDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ void BindDisc(DiscRecord discRecord)
Disc disc = discRecord.Disc;
boundDiscRecord = discRecord;

DiscTOC toc = disc.ReadTOC();
DiscStructure toc = disc.ReadStructure();
boundDisc = disc;
lblSessions.Text = toc.Sessions.Count.ToString();
lblTracks.Text = toc.Sessions.Sum((ses) => ses.Tracks.Count).ToString();
lblSectors.Text = string.Format("{0} ({1})", toc.length_aba, toc.FriendlyLength.Value);
lblSectors.Text = string.Format("{0} ({1})", toc.LengthInSectors, toc.FriendlyLength.Value);
lblSize.Text = string.Format("{0:0.00} MB", toc.BinarySize / 1024.0 / 1024.0);
btnExportCue.Enabled = true;
UpdateCue();
Expand Down
9 changes: 7 additions & 2 deletions BizHawk.Client.DiscoHawk/MainDiscoForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using System.IO;
using System.Threading;

using BizHawk.Common;
using BizHawk.Common.StringExtensions;
using BizHawk.Emulation.DiscSystem;

namespace BizHawk.Client.DiscoHawk
Expand Down Expand Up @@ -60,8 +62,10 @@ private void lblMagicDragArea_DragDrop(object sender, DragEventArgs e)
Disc disc = null;
if (ext == ".ISO")
disc = Disc.FromIsoPath(file);
else if(ext == ".CUE")
else if (ext == ".CUE")
disc = Disc.FromCuePath(file, prefs);
else if (ext == ".CCD")
disc = Disc.FromCCDPath(file);
string baseName = Path.GetFileNameWithoutExtension(file);
baseName += "_hawked";
prefs.ReallyDumpBin = true;
Expand Down Expand Up @@ -116,7 +120,8 @@ List<string> validateDrop(IDataObject ido)
if (files == null) return new List<string>();
foreach (string str in files)
{
if (Path.GetExtension(str).ToUpper() != ".CUE" && Path.GetExtension(str).ToUpper() != ".ISO")
string ext = Path.GetExtension(str).ToUpper();
if(!ext.In(new string[]{".CUE",".ISO",".CCD"}))
{
return new List<string>();
}
Expand Down
16 changes: 8 additions & 8 deletions BizHawk.Client.EmuHawk/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1875,20 +1875,20 @@ private void OpenRom()
if (VersionInfo.DeveloperBuild)
{
ofd.Filter = FormatFilter(
"Rom Files", "*.nes;*.fds;*.sms;*.gg;*.sg;*.pce;*.sgx;*.bin;*.smd;*.rom;*.a26;*.a78;*.lnx;*.cue;*.exe;*.gb;*.gbc;*.gba;*.gen;*.md;*.col;.int;*.smc;*.sfc;*.prg;*.d64;*.g64;*.crt;*.sgb;*.xml;*.z64;*.v64;*.n64;*.ws;*.wsc;%ARCH%",
"Rom Files", "*.nes;*.fds;*.sms;*.gg;*.sg;*.pce;*.sgx;*.bin;*.smd;*.rom;*.a26;*.a78;*.lnx;*.cue;*.ccd;*.exe;*.gb;*.gbc;*.gba;*.gen;*.md;*.col;.int;*.smc;*.sfc;*.prg;*.d64;*.g64;*.crt;*.sgb;*.xml;*.z64;*.v64;*.n64;*.ws;*.wsc;%ARCH%",
"Music Files", "*.psf;*.sid",
"Disc Images", "*.cue",
"Disc Images", "*.cue;*.ccd",
"NES", "*.nes;*.fds;%ARCH%",
"Super NES", "*.smc;*.sfc;*.xml;%ARCH%",
"Master System", "*.sms;*.gg;*.sg;%ARCH%",
"PC Engine", "*.pce;*.sgx;*.cue;%ARCH%",
"PC Engine", "*.pce;*.sgx;*.cue;*.ccd;%ARCH%",
"TI-83", "*.rom;%ARCH%",
"Archive Files", "%ARCH%",
"Savestate", "*.state",
"Atari 2600", "*.a26;*.bin;%ARCH%",
"Atari 7800", "*.a78;*.bin;%ARCH%",
"Atari Lynx", "*.lnx;%ARCH%",
"Genesis", "*.gen;*.smd;*.bin;*.md;*.cue;%ARCH%",
"Genesis", "*.gen;*.smd;*.bin;*.md;*.cue;*.ccd;%ARCH%",
"Gameboy", "*.gb;*.gbc;*.sgb;%ARCH%",
"Gameboy Advance", "*.gba;%ARCH%",
"Colecovision", "*.col;%ARCH%",
Expand All @@ -1904,23 +1904,23 @@ private void OpenRom()
else
{
ofd.Filter = FormatFilter(
"Rom Files", "*.nes;*.fds;*.sms;*.gg;*.sg;*.gb;*.gbc;*.gba;*.pce;*.sgx;*.bin;*.smd;*.gen;*.md;*.smc;*.sfc;*.a26;*.a78;*.lnx;*.col;*.rom;*.cue;*.sgb;*.z64;*.v64;*.n64;*.ws;*.wsc;*.xml;%ARCH%",
"Disc Images", "*.cue",
"Rom Files", "*.nes;*.fds;*.sms;*.gg;*.sg;*.gb;*.gbc;*.gba;*.pce;*.sgx;*.bin;*.smd;*.gen;*.md;*.smc;*.sfc;*.a26;*.a78;*.lnx;*.col;*.rom;*.cue;*.ccd;*.sgb;*.z64;*.v64;*.n64;*.ws;*.wsc;*.xml;%ARCH%",
"Disc Images", "*.cue;*.ccd",
"NES", "*.nes;*.fds;%ARCH%",
"Super NES", "*.smc;*.sfc;*.xml;%ARCH%",
"Nintendo 64", "*.z64;*.v64;*.n64",
"Gameboy", "*.gb;*.gbc;*.sgb;%ARCH%",
"Gameboy Advance", "*.gba;%ARCH%",
"Master System", "*.sms;*.gg;*.sg;%ARCH%",
"PC Engine", "*.pce;*.sgx;*.cue;%ARCH%",
"PC Engine", "*.pce;*.sgx;*.cue;*.ccd;%ARCH%",
"Atari 2600", "*.a26;%ARCH%",
"Atari 7800", "*.a78;%ARCH%",
"Atari Lynx", "*.lnx;%ARCH%",
"Colecovision", "*.col;%ARCH%",
"TI-83", "*.rom;%ARCH%",
"Archive Files", "%ARCH%",
"Savestate", "*.state",
"Genesis", "*.gen;*.md;*.smd;*.bin;*.cue;%ARCH%",
"Genesis", "*.gen;*.md;*.smd;*.bin;*.cue;*.ccd;%ARCH%",
"WonderSwan", "*.ws;*.wsc;%ARCH%",
"All Files", "*.*");
}
Expand Down
4 changes: 4 additions & 0 deletions BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@
<Reference Include="Newtonsoft.Json">
<HintPath>..\References\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="OpenTK, Version=1.1.0.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\References\OpenTK.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
Expand Down
38 changes: 21 additions & 17 deletions BizHawk.Emulation.Cores/Consoles/PC Engine/ScsiCDBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,16 @@ public bool RST

PCEngine pce;
public Disc disc;
SubcodeReader subcodeReader;
SubchannelQ subchannelQ;
int audioStartLBA;
int audioEndLBA;

public ScsiCDBus(PCEngine pce, Disc disc)
{
this.pce = pce;
this.disc = disc;
subcodeReader = new SubcodeReader(disc);
}

public void Think()
Expand Down Expand Up @@ -418,7 +421,7 @@ void CommandAudioStartPos()

case 0x80: // Set start offset in track units
byte trackNo = CommandBuffer[2].BCDtoBin();
audioStartLBA = disc.TOC.Sessions[0].Tracks[trackNo - 1].Indexes[1].aba - 150;
audioStartLBA = disc.Structure.Sessions[0].Tracks[trackNo - 1].Indexes[1].aba - 150;
break;
}

Expand Down Expand Up @@ -453,10 +456,10 @@ void CommandAudioEndPos()

case 0x80: // Set end offset in track units
byte trackNo = CommandBuffer[2].BCDtoBin();
if (trackNo - 1 >= disc.TOC.Sessions[0].Tracks.Count)
if (trackNo - 1 >= disc.Structure.Sessions[0].Tracks.Count)
audioEndLBA = disc.LBACount;
else
audioEndLBA = disc.TOC.Sessions[0].Tracks[trackNo - 1].Indexes[1].aba - 150;
audioEndLBA = disc.Structure.Sessions[0].Tracks[trackNo - 1].Indexes[1].aba - 150;
break;
}

Expand Down Expand Up @@ -493,7 +496,7 @@ void CommandPause()
void CommandReadSubcodeQ()
{
bool playing = pce.CDAudio.Mode != CDAudio.CDAudioMode_Stopped;
var sectorEntry = disc.ReadLBA_SectorEntry(playing ? pce.CDAudio.CurrentSector : CurrentReadingSector);
int sectorNum = playing ? pce.CDAudio.CurrentSector : CurrentReadingSector;

DataIn.Clear();

Expand All @@ -504,15 +507,16 @@ void CommandReadSubcodeQ()
case CDAudio.CDAudioMode_Stopped: DataIn.Enqueue(3); break;
}

DataIn.Enqueue(sectorEntry.q_status); // I do not know what status is
DataIn.Enqueue(sectorEntry.q_tno.BCDValue); // track
DataIn.Enqueue(sectorEntry.q_index.BCDValue); // index
DataIn.Enqueue(sectorEntry.q_min.BCDValue); // M(rel)
DataIn.Enqueue(sectorEntry.q_sec.BCDValue); // S(rel)
DataIn.Enqueue(sectorEntry.q_frame.BCDValue); // F(rel)
DataIn.Enqueue(sectorEntry.q_amin.BCDValue); // M(abs)
DataIn.Enqueue(sectorEntry.q_asec.BCDValue); // S(abs)
DataIn.Enqueue(sectorEntry.q_aframe.BCDValue); // F(abs)
subcodeReader.ReadLBA_SubchannelQ(sectorNum, ref subchannelQ);
DataIn.Enqueue(subchannelQ.q_status); // I do not know what status is
DataIn.Enqueue(subchannelQ.q_tno); // track
DataIn.Enqueue(subchannelQ.q_index); // index
DataIn.Enqueue(subchannelQ.min.BCDValue); // M(rel)
DataIn.Enqueue(subchannelQ.sec.BCDValue); // S(rel)
DataIn.Enqueue(subchannelQ.frame.BCDValue); // F(rel)
DataIn.Enqueue(subchannelQ.ap_min.BCDValue); // M(abs)
DataIn.Enqueue(subchannelQ.ap_sec.BCDValue); // S(abs)
DataIn.Enqueue(subchannelQ.ap_frame.BCDValue); // F(abs)

SetPhase(BusPhase_DataIn);
}
Expand All @@ -525,7 +529,7 @@ void CommandReadTOC()
{
DataIn.Clear();
DataIn.Enqueue(0x01);
DataIn.Enqueue(((byte)disc.TOC.Sessions[0].Tracks.Count).BinToBCD());
DataIn.Enqueue(((byte)disc.Structure.Sessions[0].Tracks.Count).BinToBCD());
SetPhase(BusPhase_DataIn);
break;
}
Expand All @@ -546,7 +550,7 @@ void CommandReadTOC()
case 2: // Return starting position of specified track in MSF format
{
int track = CommandBuffer[2].BCDtoBin();
var tracks = disc.TOC.Sessions[0].Tracks;
var tracks = disc.Structure.Sessions[0].Tracks;
if (CommandBuffer[2] > 0x99)
throw new Exception("invalid track number BCD request... is something I need to handle?");
if (track == 0) track = 1;
Expand All @@ -556,7 +560,7 @@ void CommandReadTOC()
int lbaPos;

if (track > tracks.Count)
lbaPos = disc.TOC.Sessions[0].length_aba - 150;
lbaPos = disc.Structure.Sessions[0].length_aba - 150;
else
lbaPos = tracks[track].Indexes[1].aba - 150;

Expand All @@ -568,7 +572,7 @@ void CommandReadTOC()
DataIn.Enqueue(s.BinToBCD());
DataIn.Enqueue(f.BinToBCD());

if (track > tracks.Count || disc.TOC.Sessions[0].Tracks[track].TrackType == ETrackType.Audio)
if (track > tracks.Count || disc.Structure.Sessions[0].Tracks[track].TrackType == ETrackType.Audio)
DataIn.Enqueue(0);
else
DataIn.Enqueue(4);
Expand Down
2 changes: 1 addition & 1 deletion BizHawk.Emulation.Cores/Consoles/Sega/Saturn/Yabause.cs
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ int CD_ReadTOC(IntPtr dest)
{
// this stuff from yabause's cdbase.c. don't ask me to explain it

var TOC = CD.ReadTOC();
var TOC = CD.ReadStructure();
int[] rTOC = new int[102];
var ses = TOC.Sessions[0];
int ntrk = ses.Tracks.Count;
Expand Down
4 changes: 2 additions & 2 deletions BizHawk.Emulation.Cores/Consoles/Sega/gpgx/GPGX.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ unsafe byte[] GetCDData()

ret.readcallback = cd_callback_handle = new LibGPGX.cd_read_cb(CDRead);

var ses = CD.TOC.Sessions[0];
var ses = CD.Structure.Sessions[0];
int ntrack = ses.Tracks.Count;

// bet you a dollar this is all wrong
Expand All @@ -325,7 +325,7 @@ unsafe byte[] GetCDData()
if (i < ntrack)
{
ret.tracks[i].start = ses.Tracks[i].Indexes[1].aba - 150;
ret.tracks[i].end = ses.Tracks[i].length_aba + ret.tracks[i].start;
ret.tracks[i].end = ses.Tracks[i].LengthInSectors + ret.tracks[i].start;
if (i == ntrack - 1)
{
ret.end = ret.tracks[i].end;
Expand Down
13 changes: 12 additions & 1 deletion BizHawk.Emulation.DiscSystem/BizHawk.Emulation.DiscSystem.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@
<Link>VersionInfo.cs</Link>
</Compile>
<Compile Include="Blobs\Blob_ECM.cs" />
<Compile Include="Blobs\Blob_RawFile.cs" />
<Compile Include="Blobs\Blob_WaveFile.cs" />
<Compile Include="Blobs\Blob_ZeroPadAdapter.cs" />
<Compile Include="Blobs\IBlob.cs" />
<Compile Include="Blobs\RiffMaster.cs" />
<Compile Include="CCD_format.cs" />
<Compile Include="CDAudio.cs" />
Expand All @@ -62,12 +65,16 @@
<Compile Include="Disc.API.cs" />
<Compile Include="Disc.cs" />
<Compile Include="Disc.ID.cs" />
<Compile Include="DiscTOC.cs" />
<Compile Include="DiscTypes.cs" />
<Compile Include="DiscUtils.cs" />
<Compile Include="ECM.cs" />
<Compile Include="GPL_ECM.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\svnrev.cs" />
<Compile Include="SectorInterfaces.cs" />
<Compile Include="Subcode.cs" />
<Compile Include="TOC\DiscStructure.cs" />
<Compile Include="TOC\TOCRaw.cs" />
<Compile Include="TOC_format.cs" />
</ItemGroup>
<ItemGroup>
Expand All @@ -80,6 +87,10 @@
<Name>BizHawk.Emulation.Common</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="docs\notes.txt" />
<Content Include="docs\todo.txt" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>"$(SolutionDir)subwcrev.bat" "$(ProjectDir)"</PreBuildEvent>
Expand Down
Loading

0 comments on commit 29b217b

Please sign in to comment.