Skip to content

Commit

Permalink
more fun DSP fixes
Browse files Browse the repository at this point in the history
* aac.a thinks it is funny to start DMA by writing to 8184 directly
* implement retd (gross hack!!)
* remove another unimplemented exception (wat)
  • Loading branch information
Arisotura committed Oct 17, 2022
1 parent 243a027 commit 31ba585
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 8 deletions.
5 changes: 2 additions & 3 deletions src/teakra/src/btdmp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,15 @@ void Btdmp::Tick() {
std::array<std::int16_t, 2> sample;
for (int i = 0; i < 2; ++i) {
if (transmit_queue.empty()) {
std::printf("BTDMP: transmit buffer underrun\n");
//std::printf("BTDMP: transmit buffer underrun\n");
sample[i] = 0;
} else {
sample[i] = static_cast<s16>(transmit_queue.front());
transmit_queue.pop();
transmit_empty = transmit_queue.empty();
transmit_full = false;
if (transmit_empty) {
if (transmit_empty)
interrupt_handler();
}
}
}
if (audio_callback) {
Expand Down
5 changes: 5 additions & 0 deletions src/teakra/src/btdmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ class Btdmp : public CoreTiming::Callbacks {
}
}

u16 Receive() {
printf("BTDMP RECEIVE TODO!!\n");
return 0;
}

void SetTransmitFlush(u16 value) {
transmit_queue = {};
transmit_empty = true;
Expand Down
5 changes: 5 additions & 0 deletions src/teakra/src/dma.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ class Dma {
void Reset();

void EnableChannel(u16 value) {
u16 chk = value & ~enable_channel;
for (int i = 0; i < 8; i++) {
if (chk & (1<<i))
DoDma(i);
}
enable_channel = value;
}
u16 GetChannelEnabled() const {
Expand Down
25 changes: 20 additions & 5 deletions src/teakra/src/interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace Teakra {
class UnimplementedException : public std::runtime_error {
public:
UnimplementedException() : std::runtime_error("unimplemented") {}
UnimplementedException(const char* err) : std::runtime_error(err) {}
};

class Interpreter {
Expand Down Expand Up @@ -261,7 +262,7 @@ class Interpreter {
SatAndSetAccAndFlag(d1, v); // only this one affects flags (except for fl)
}
void trap() {
throw UnimplementedException();
throw UnimplementedException("trap");
}

void DoMultiplication(u32 unit, bool x_sign, bool y_sign) {
Expand Down Expand Up @@ -448,7 +449,7 @@ class Interpreter {
AlmOp::Or, AlmOp::And, AlmOp::Xor, AlmOp::Add, AlmOp::Cmp, AlmOp::Sub,
};
if (allowed_instruction.count(op.GetName()) == 0)
throw UnimplementedException(); // weird effect. probably undefined
throw UnimplementedException("weird alm"); // weird effect. probably undefined
};
switch (a.GetName()) {
// need more test
Expand Down Expand Up @@ -600,7 +601,7 @@ class Interpreter {
if (b.GetName() == RegName::p) {
bv = (u16)(ProductToBus40(Px{0}) >> 16);
} else if (b.GetName() == RegName::a0 || b.GetName() == RegName::a1) {
throw UnimplementedException(); // weird effect;
throw UnimplementedException("weird alb"); // weird effect;
} else {
bv = RegToBus16(b.GetName());
}
Expand Down Expand Up @@ -1180,7 +1181,21 @@ class Interpreter {
}
}
void retd() {
throw UnimplementedException();
// TODO: this is grossly inaccurate
// retd is supposed to kick in after 2 cycles

for (int i = 0; i < 2; i++) {
u16 opcode = mem.ProgramRead((regs.pc++) | (regs.prpage << 18));
auto& decoder = decoders[opcode];
u16 expand_value = 0;
if (decoder.NeedExpansion()) {
expand_value = mem.ProgramRead((regs.pc++) | (regs.prpage << 18));
}

decoder.call(*this, opcode, expand_value);
}

PopPC();
}
void reti(Cond c) {
if (regs.ConditionPass(c)) {
Expand Down Expand Up @@ -3430,7 +3445,7 @@ class Interpreter {
} else { // OffsetValue::MinusOne
if (!emod)
return address - 1;
throw UnimplementedException();
//throw UnimplementedException("weird OffsetAddress");
// TODO: sometimes this would return two addresses,
// neither of which is the original Rn value.
// This only happens for memory writing, but not for memory reading.
Expand Down
2 changes: 2 additions & 0 deletions src/teakra/src/mmio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ MMIORegion::MMIORegion(MemoryInterfaceUnit& miu, ICU& icu, Apbp& apbp_from_cpu,
BitFieldSlot{4, 1, {}, std::bind(&Btdmp::GetTransmitEmpty, &btdmp[i])},
});
impl->cells[0x2C6 + i * 0x80].set = std::bind(&Btdmp::Send, &btdmp[i], _1);
impl->cells[0x2C6 + i * 0x80].get = std::bind(&Btdmp::Receive, &btdmp[i]);
impl->cells[0x2CA + i * 0x80].set = std::bind(&Btdmp::SetTransmitFlush, &btdmp[i], _1);
impl->cells[0x2CA + i * 0x80].get = std::bind(&Btdmp::GetTransmitFlush, &btdmp[i]);
}
Expand All @@ -355,6 +356,7 @@ u16 MMIORegion::Read(u16 addr) {
u16 value = impl->cells[addr].get();
return value;
}

void MMIORegion::Write(u16 addr, u16 value) {
impl->cells[addr].set(value);
}
Expand Down

0 comments on commit 31ba585

Please sign in to comment.