Skip to content

Commit

Permalink
md: implement subchannel processing for mcd (CD+G)
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeUsher committed Feb 19, 2024
1 parent ed0a1c8 commit 1e83da0
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
29 changes: 29 additions & 0 deletions ares/md/mcd/cdd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ auto MCD::CDD::advance() -> void {
io.track = track();
io.sector++;
io.sample = 0;
readSubcode();
return;
}

Expand Down Expand Up @@ -93,6 +94,34 @@ auto MCD::CDD::position(s32 sector) -> double {
return sqrt(sector / sectors * (outerRadius - innerRadius) + innerRadius) / radius;
}

auto MCD::CDD::readSubcode() -> void {
if(!mcd.fd) return;

mcd.fd->seek(((abs(mcd.cdd.session.leadIn.lba) + io.sector) * 2448) + 2352);
vector<u8> subchannel;
subchannel.resize(96);
mcd.fd->read({subchannel.data(), 96});

io.subcodePosition += 49;
n6 index = io.subcodePosition;

//subchannel data is stored by ares as 12x8 for each channel (PQRSTUVW)
//we need to convert this back to the raw subchannel encoding as per EMCA-130
for(int i = 0; i < 96; i+= 2) {
n16 data = 0;
for(auto channel : range(8)) {
n8 input = subchannel[(channel * 12) + (i / 8)];
n2 bits = input >> (6 - (i & 6));
data.bit( 7 - channel) = bits.bit(0);
data.bit(15 - channel) = bits.bit(1);
}

subcode[index++] = data;
}

mcd.irq.subcode.raise();
}

auto MCD::CDD::process() -> void {
//if(command[0]) print("CDD ", command[0], ":", command[3], "\n");

Expand Down
9 changes: 8 additions & 1 deletion ares/md/mcd/io-internal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,15 @@ auto MCD::readIO(n1 upper, n1 lower, n24 address, n16 data) -> n16 {
data.bit(1,15) = gpu.vector.base.bit(3,17);
}

if(address == 0xff8068) {
data.bit(0) = Unmapped;
data.bit(1,7) = cdd.io.subcodePosition.bit(0,6);
data.bit(8,15) = Unmapped;
}

if(address >= 0xff8100 && address <= 0xff81ff) {
debug(unusual, "[MCD::readIO] address=0x", hex(address, 6L));
n6 index = address - 0xff8100 >> 1;
data = cdd.subcode[index];
}

return data;
Expand Down
3 changes: 3 additions & 0 deletions ares/md/mcd/mcd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ struct MCD : M68000, Thread {
auto sample() -> void;
auto position(s32 sector) -> double;
auto process() -> void;
auto readSubcode() -> void;
auto valid() -> bool;
auto checksum() -> void;
auto insert() -> void;
Expand Down Expand Up @@ -345,12 +346,14 @@ struct MCD : M68000, Thread {
n16 sample; //current audio sample# within current frame
n7 track; //current track#
n1 tocRead;
n6 subcodePosition;
} io;

n1 hostClockEnable;
n1 statusPending;
n4 status [10];
n4 command[10];
n16 subcode[64];
} cdd;

struct Timer {
Expand Down
2 changes: 2 additions & 0 deletions ares/md/mcd/serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,13 @@ auto MCD::CDD::serialize(serializer& s) -> void {
s(io.sample);
s(io.track);
s(io.tocRead);
s(io.subcodePosition);

s(hostClockEnable);
s(statusPending);
s(status);
s(command);
s(subcode);
}

auto MCD::Timer::serialize(serializer& s) -> void {
Expand Down
2 changes: 1 addition & 1 deletion ares/md/system/serialization.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
static const string SerializerVersion = "v134";
static const string SerializerVersion = "v135";

auto System::serialize(bool synchronize) -> serializer {
if(synchronize) scheduler.enter(Scheduler::Mode::Synchronize);
Expand Down

0 comments on commit 1e83da0

Please sign in to comment.