From 31ba585d392c9745917a141c72b3349d029586f0 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Mon, 17 Oct 2022 20:16:19 +0200 Subject: [PATCH] more fun DSP fixes * aac.a thinks it is funny to start DMA by writing to 8184 directly * implement retd (gross hack!!) * remove another unimplemented exception (wat) --- src/teakra/src/btdmp.cpp | 5 ++--- src/teakra/src/btdmp.h | 5 +++++ src/teakra/src/dma.h | 5 +++++ src/teakra/src/interpreter.h | 25 ++++++++++++++++++++----- src/teakra/src/mmio.cpp | 2 ++ 5 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/teakra/src/btdmp.cpp b/src/teakra/src/btdmp.cpp index 20a1f094..abdaf527 100644 --- a/src/teakra/src/btdmp.cpp +++ b/src/teakra/src/btdmp.cpp @@ -28,16 +28,15 @@ void Btdmp::Tick() { std::array 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(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) { diff --git a/src/teakra/src/btdmp.h b/src/teakra/src/btdmp.h index 63cbb9b2..da0a9321 100644 --- a/src/teakra/src/btdmp.h +++ b/src/teakra/src/btdmp.h @@ -58,6 +58,11 @@ public: } } + u16 Receive() { + printf("BTDMP RECEIVE TODO!!\n"); + return 0; + } + void SetTransmitFlush(u16 value) { transmit_queue = {}; transmit_empty = true; diff --git a/src/teakra/src/dma.h b/src/teakra/src/dma.h index f5a81125..6aa05c23 100644 --- a/src/teakra/src/dma.h +++ b/src/teakra/src/dma.h @@ -16,6 +16,11 @@ public: void Reset(); void EnableChannel(u16 value) { + u16 chk = value & ~enable_channel; + for (int i = 0; i < 8; i++) { + if (chk & (1<> 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()); } @@ -1180,7 +1181,21 @@ public: } } 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)) { @@ -3430,7 +3445,7 @@ private: } 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. diff --git a/src/teakra/src/mmio.cpp b/src/teakra/src/mmio.cpp index 0a8e3bc2..9834758c 100644 --- a/src/teakra/src/mmio.cpp +++ b/src/teakra/src/mmio.cpp @@ -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]); } @@ -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); }