Compare commits

...
13 changed files with 266 additions and 81 deletions

No files matched your search

+21
View File
@@ -55,6 +55,27 @@ uint32_t TimerManager::add_oneshot_timer(uint64_t timeout, timer_cb cb)
return ti->id;
}
uint32_t TimerManager::add_immediate_timer(timer_cb cb) {
TimerInfo* ti = new TimerInfo;
ti->id = ++this->id;
ti->timeout_ns = this->get_time_now() + 10;
ti->interval_ns = 0;
ti->cb = cb;
std::shared_ptr<TimerInfo> timer_desc(ti);
// add new timer to the timer queue
this->timer_queue.push(timer_desc);
// notify listeners about changes in the timer queue
if (!this->cb_active) {
this->notify_timer_changes();
}
return ti->id;
}
uint32_t TimerManager::add_cyclic_timer(uint64_t interval, uint64_t delay, timer_cb cb)
{
if (!interval || interval <= MIN_TIMEOUT_NS) {
+1
View File
@@ -103,6 +103,7 @@ public:
// creating and cancelling timers
uint32_t add_oneshot_timer(uint64_t timeout, timer_cb cb);
uint32_t add_immediate_timer(timer_cb cb);
uint32_t add_cyclic_timer(uint64_t interval, timer_cb cb);
uint32_t add_cyclic_timer(uint64_t interval, uint64_t delay, timer_cb cb);
void cancel_timer(uint32_t id);
+24 -8
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -170,7 +170,7 @@ uint16_t Sc53C94::pseudo_dma_read()
std:memmove(this->data_fifo, &this->data_fifo[2], this->data_fifo_pos);
// update DMA status
if ((this->cmd_fifo[0] & 0x80)) {
if (this->is_dma_cmd) {
this->xfer_count -= 2;
if (!this->xfer_count) {
is_done = true;
@@ -189,6 +189,21 @@ uint16_t Sc53C94::pseudo_dma_read()
return data_word;
}
void Sc53C94::pseudo_dma_write(uint16_t data) {
this->fifo_push((data >> 8) & 0xFFU);
this->fifo_push(data & 0xFFU);
// update DMA status
if (this->is_dma_cmd) {
this->xfer_count -= 2;
if (!this->xfer_count) {
this->status |= STAT_TC; // signal zero transfer count
//this->cur_state = SeqState::XFER_END;
this->sequencer();
}
}
}
void Sc53C94::update_command_reg(uint8_t cmd)
{
if (this->on_reset && (cmd & 0x7F) != CMD_NOP) {
@@ -220,9 +235,10 @@ void Sc53C94::update_command_reg(uint8_t cmd)
void Sc53C94::exec_command()
{
uint8_t cmd = this->cur_cmd = this->cmd_fifo[0] & 0x7F;
bool is_dma_cmd = !!(this->cmd_fifo[0] & 0x80);
if (is_dma_cmd) {
this->is_dma_cmd = !!(this->cmd_fifo[0] & 0x80);
if (this->is_dma_cmd) {
if (this->config2 & CFG2_ENF) { // extended mode: 24-bit
this->xfer_count = this->set_xfer_count & 0xFFFFFFUL;
} else { // standard mode: 16-bit
@@ -468,7 +484,7 @@ void Sc53C94::sequencer()
this->cur_bus_phase = this->bus_obj->current_phase();
switch (this->cur_bus_phase) {
case ScsiPhase::DATA_OUT:
if (this->cmd_fifo[0] & 0x80) {
if (this->is_dma_cmd) {
this->cur_state = SeqState::SEND_DATA;
break;
}
@@ -481,7 +497,7 @@ void Sc53C94::sequencer()
this->bus_obj->negotiate_xfer(this->data_fifo_pos, this->bytes_out);
this->cur_state = SeqState::RCV_DATA;
this->rcv_data();
if (!(this->cmd_fifo[0] & 0x80)) {
if (!(this->is_dma_cmd)) {
this->cur_state = SeqState::XFER_END;
this->sequencer();
}
@@ -537,7 +553,7 @@ void Sc53C94::update_irq()
}
}
void Sc53C94::notify(ScsiBus* bus_obj, ScsiMsg msg_type, int param)
void Sc53C94::notify(ScsiMsg msg_type, int param)
{
switch (msg_type) {
case ScsiMsg::CONFIRM_SEL:
@@ -595,7 +611,7 @@ bool Sc53C94::rcv_data()
return false;
}
if ((this->cmd_fifo[0] & 0x80) && this->cur_bus_phase == ScsiPhase::DATA_IN) {
if (this->is_dma_cmd && this->cur_bus_phase == ScsiPhase::DATA_IN) {
req_count = std::min((int)this->xfer_count, DATA_FIFO_MAX - this->data_fifo_pos);
} else {
req_count = 1;
+12 -2
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -34,6 +34,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <devices/common/hwinterrupt.h>
#include <cinttypes>
#include <functional>
#include <memory>
#define DATA_FIFO_MAX 16
@@ -144,6 +145,8 @@ typedef struct {
int status;
} SeqDesc;
typedef std::function<void(const uint8_t drq_state)> DrqCb;
class Sc53C94 : public ScsiDevice {
public:
Sc53C94(uint8_t chip_id=12, uint8_t my_id=7);
@@ -160,6 +163,7 @@ public:
uint8_t read(uint8_t reg_offset);
void write(uint8_t reg_offset, uint8_t value);
uint16_t pseudo_dma_read();
void pseudo_dma_write(uint16_t data);
// real DMA control
void real_dma_xfer(int direction);
@@ -168,8 +172,12 @@ public:
this->dma_ch = dma_ch;
};
void set_drq_callback(DrqCb cb) {
this->drq_cb = cb;
}
// ScsiDevice methods
void notify(ScsiBus* bus_obj, ScsiMsg msg_type, int param);
void notify(ScsiMsg msg_type, int param);
bool prepare_data() { return false; };
bool has_data() { return this->data_fifo_pos != 0; };
int send_data(uint8_t* dst_ptr, int count);
@@ -222,6 +230,7 @@ private:
SeqDesc* cmd_steps;
bool is_initiator;
uint8_t cur_cmd;
bool is_dma_cmd = false;
int cur_bus_phase;
// interrupt related stuff
@@ -231,6 +240,7 @@ private:
// DMA related stuff
DmaBidirChannel* dma_ch;
DrqCb drq_cb = nullptr;
};
#endif // SC_53C94_H
+8 -2
View File
@@ -109,6 +109,8 @@ enum ScsiCommand : uint8_t {
WRITE_10 = 0x2A,
VERIFY_10 = 0x2F,
READ_LONG_10 = 0x35,
WRITE_BUFFER = 0x3B,
READ_BUFFER = 0x3C,
MODE_SENSE_10 = 0x5A,
READ_12 = 0xA8,
@@ -168,8 +170,8 @@ public:
};
~ScsiDevice() = default;
virtual void notify(ScsiBus* bus_obj, ScsiMsg msg_type, int param);
virtual void next_step(ScsiBus* bus_obj);
virtual void notify(ScsiMsg msg_type, int param);
virtual void next_step();
virtual void prepare_xfer(ScsiBus* bus_obj, int& bytes_in, int& bytes_out);
virtual void switch_phase(const int new_phase);
@@ -180,6 +182,10 @@ public:
virtual bool prepare_data() = 0;
virtual void process_command() = 0;
void set_bus_object_ptr(ScsiBus *bus_obj_ptr) {
this->bus_obj = bus_obj_ptr;
}
protected:
uint8_t cmd_buf[16] = {};
uint8_t msg_buf[16] = {}; // TODO: clarify how big this one should be
+5 -3
View File
@@ -52,6 +52,8 @@ void ScsiBus::register_device(int id, ScsiDevice* dev_obj)
}
this->devices[id] = dev_obj;
dev_obj->set_bus_object_ptr(this);
}
void ScsiBus::change_bus_phase(int initiator_id)
@@ -60,7 +62,7 @@ void ScsiBus::change_bus_phase(int initiator_id)
if (i == initiator_id)
continue; // don't notify the initiator
if (this->devices[i] != nullptr) {
this->devices[i]->notify(this, ScsiMsg::BUS_PHASE_CHANGE, this->cur_phase);
this->devices[i]->notify(ScsiMsg::BUS_PHASE_CHANGE, this->cur_phase);
}
}
}
@@ -221,7 +223,7 @@ void ScsiBus::confirm_selection(int target_id)
// notify initiator about selection confirmation from target
if (this->initiator_id >= 0) {
this->devices[this->initiator_id]->notify(this, ScsiMsg::CONFIRM_SEL, target_id);
this->devices[this->initiator_id]->notify(ScsiMsg::CONFIRM_SEL, target_id);
}
}
@@ -257,7 +259,7 @@ bool ScsiBus::push_data(const int id, const uint8_t* src_ptr, const int size)
void ScsiBus::target_next_step()
{
this->devices[this->target_id]->next_step(this);
this->devices[this->target_id]->next_step();
}
bool ScsiBus::negotiate_xfer(int& bytes_in, int& bytes_out)
+11 -12
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -26,7 +26,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cinttypes>
#include <cstring>
void ScsiDevice::notify(ScsiBus* bus_obj, ScsiMsg msg_type, int param)
void ScsiDevice::notify(ScsiMsg msg_type, int param)
{
if (msg_type == ScsiMsg::BUS_PHASE_CHANGE) {
switch (param) {
@@ -35,19 +35,18 @@ void ScsiDevice::notify(ScsiBus* bus_obj, ScsiMsg msg_type, int param)
break;
case ScsiPhase::SELECTION:
// check if something tries to select us
if (bus_obj->get_data_lines() & (1 << scsi_id)) {
if (this->bus_obj->get_data_lines() & (1 << scsi_id)) {
LOG_F(9, "ScsiDevice %d selected", this->scsi_id);
TimerManager::get_instance()->add_oneshot_timer(
BUS_SETTLE_DELAY,
[this, bus_obj]() {
[this]() {
// don't confirm selection if BSY or I/O are asserted
if (bus_obj->test_ctrl_lines(SCSI_CTRL_BSY | SCSI_CTRL_IO))
if (this->bus_obj->test_ctrl_lines(SCSI_CTRL_BSY | SCSI_CTRL_IO))
return;
bus_obj->assert_ctrl_line(this->scsi_id, SCSI_CTRL_BSY);
bus_obj->confirm_selection(this->scsi_id);
this->initiator_id = bus_obj->get_initiator_id();
this->bus_obj = bus_obj;
if (bus_obj->test_ctrl_lines(SCSI_CTRL_ATN)) {
this->bus_obj->assert_ctrl_line(this->scsi_id, SCSI_CTRL_BSY);
this->bus_obj->confirm_selection(this->scsi_id);
this->initiator_id = this->bus_obj->get_initiator_id();
if (this->bus_obj->test_ctrl_lines(SCSI_CTRL_ATN)) {
this->switch_phase(ScsiPhase::MESSAGE_OUT);
if (this->msg_buf[0] != 0x80) {
LOG_F(INFO, "ScsiDevice: received message 0x%X", this->msg_buf[0]);
@@ -73,7 +72,7 @@ void ScsiDevice::switch_phase(const int new_phase)
this->bus_obj->switch_phase(this->scsi_id, this->cur_phase);
}
void ScsiDevice::next_step(ScsiBus* bus_obj)
void ScsiDevice::next_step()
{
switch (this->cur_phase) {
case ScsiPhase::COMMAND:
@@ -98,7 +97,7 @@ void ScsiDevice::next_step(ScsiBus* bus_obj)
break;
case ScsiPhase::MESSAGE_IN:
case ScsiPhase::BUS_FREE:
bus_obj->release_ctrl_lines(this->scsi_id);
this->bus_obj->release_ctrl_lines(this->scsi_id);
this->switch_phase(ScsiPhase::BUS_FREE);
break;
default:
+88 -26
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -53,7 +53,7 @@ void ScsiHardDisk::insert_image(std::string filename) {
this->img_size = stat_buf.st_size;
this->total_blocks = (this->img_size + HDD_SECTOR_SIZE - 1) / HDD_SECTOR_SIZE;
} else {
ABORT_F("ScsiHardDisk: could not determine file size using stat()");
ABORT_F("SCSI-HD: could not determine file size using stat()");
}
this->hdd_img.seekg(0, std::ios_base::beg);
}
@@ -72,14 +72,10 @@ void ScsiHardDisk::process_command() {
// assume successful command execution
this->status = ScsiStatus::GOOD;
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
uint8_t* cmd = this->cmd_buf;
if (cmd[0] != 0 && cmd[0] != 8 && cmd[0] != 0xA && cmd[0] != 0x28
&& cmd[0] != 0x2A && cmd[0] != 0x25) {
ABORT_F("SCSI-HD: untested command 0x%X", cmd[0]);
}
switch (cmd[0]) {
case ScsiCommand::TEST_UNIT_READY:
test_unit_ready();
@@ -129,8 +125,11 @@ void ScsiHardDisk::process_command() {
case ScsiCommand::READ_CAPACITY_10:
this->read_capacity_10();
break;
case ScsiCommand::READ_BUFFER:
read_buffer();
break;
default:
LOG_F(WARNING, "SCSI_HD: unrecognized command: %x", cmd[0]);
LOG_F(WARNING, "SCSI-HD: unrecognized command: %x", cmd[0]);
}
}
@@ -138,7 +137,7 @@ bool ScsiHardDisk::prepare_data() {
switch (this->cur_phase) {
case ScsiPhase::DATA_IN:
this->data_ptr = (uint8_t*)this->img_buffer;
this->data_size = this->cur_buf_cnt;
this->data_size = this->bytes_out;
break;
case ScsiPhase::DATA_OUT:
this->data_ptr = (uint8_t*)this->img_buffer;
@@ -150,14 +149,14 @@ bool ScsiHardDisk::prepare_data() {
} else {
this->img_buffer[0] = ScsiStatus::CHECK_CONDITION;
}
this->cur_buf_cnt = 1;
this->data_size = 1;
break;
case ScsiPhase::MESSAGE_IN:
this->img_buffer[0] = this->msg_code;
this->cur_buf_cnt = 1;
this->data_size = 1;
break;
default:
LOG_F(WARNING, "SCSI_HD: unexpected phase in prepare_data");
LOG_F(WARNING, "SCSI-HD: unexpected phase in prepare_data");
return false;
}
@@ -181,29 +180,28 @@ void ScsiHardDisk::inquiry() {
int alloc_len = cmd_buf[4];
if (page_num) {
ABORT_F("SCSI_CDROM: invalid page number in INQUIRY");
ABORT_F("SCSI-HD: invalid page number in INQUIRY");
}
if (alloc_len >= 36) {
this->img_buffer[0] = 0; // device type: Direct-access block device (hard drive)
this->img_buffer[1] = 0x80; // removable media
this->img_buffer[2] = 2; // ANSI version: SCSI-2
this->img_buffer[3] = 1; // response data format
this->img_buffer[4] = 0x1F; // additional length
this->img_buffer[0] = 0; // device type: Direct-access block device
this->img_buffer[1] = 0; // non-removable media
this->img_buffer[2] = 2; // ANSI version: SCSI-2
this->img_buffer[3] = 1; // response data format
this->img_buffer[4] = 0; // additional length
this->img_buffer[5] = 0;
this->img_buffer[6] = 0;
this->img_buffer[7] = 0x18; // supports synchronous xfers and linked commands
this->img_buffer[7] = 0x18; // supports synchronous xfers and linked commands
std::memcpy(img_buffer + 8, vendor_info, 8);
std::memcpy(img_buffer + 16, prod_info, 16);
std::memcpy(img_buffer + 32, rev_info, 4);
this->bytes_out = 36;
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
this->switch_phase(ScsiPhase::DATA_IN);
}
else {
LOG_F(WARNING, "Inappropriate Allocation Length: %d", alloc_len);
LOG_F(WARNING, "Allocation length too small: %d", alloc_len);
}
}
@@ -221,9 +219,57 @@ int ScsiHardDisk::mode_select_6(uint8_t param_len) {
}
}
static char Apple_Copyright_Page_Data[] = "APPLE COMPUTER, INC ";
void ScsiHardDisk::mode_sense_6() {
uint8_t page_code = this->cmd_buf[2] & 0x3F;
uint8_t page_code = this->cmd_buf[2] & 0x3F;
uint8_t page_ctrl = this->cmd_buf[2] >> 6;
uint8_t alloc_len = this->cmd_buf[4];
this->img_buffer[ 0] = 13; // initial data size
this->img_buffer[ 1] = 0; // medium type
this->img_buffer[ 2] = 0; // medium is write enabled
this->img_buffer[ 3] = 8; // block description length
this->img_buffer[ 4] = 0; // density code
this->img_buffer[ 5] = (this->total_blocks >> 16) & 0xFFU;
this->img_buffer[ 6] = (this->total_blocks >> 8) & 0xFFU;
this->img_buffer[ 7] = (this->total_blocks ) & 0xFFU;
this->img_buffer[ 8] = 0;
this->img_buffer[ 9] = 0; // sector size MSB
this->img_buffer[10] = 2; // sector size
this->img_buffer[11] = 0; // sector size LSB
this->img_buffer[12] = page_code;
switch(page_code) {
case 3: // Format device page
this->img_buffer[13] = 22; // data size - 1
std::memset(&this->img_buffer[14], 0, 22);
// default values taken from Empire 540/1080S manual
this->img_buffer[15] = 6; // tracks per defect zone
this->img_buffer[17] = 1; // alternate sectors per zone
this->img_buffer[23] = 92; // sectors per track in the outermost zone
this->img_buffer[27] = 1; // interleave factor
this->img_buffer[29] = 19; // track skew factor
this->img_buffer[31] = 25; // cylinder skew factor
this->img_buffer[32] = 0x80; // SSEC=1, HSEC=0, RMB=0, SURF=0, INS=0
WRITE_WORD_BE_U(&this->img_buffer[24], 512); // bytes per sector
break;
case 0x30: // Copyright page for Apple certified drives
this->img_buffer[13] = 22; // data size - 1
std::memcpy(&this->img_buffer[14], Apple_Copyright_Page_Data, 22);
break;
default:
ABORT_F("SCSI-HD: unsupported page %d in MODE_SENSE_6", page_code);
};
// adjust for overall mode sense data length
this->img_buffer[0] += this->img_buffer[13] + 1;
this->bytes_out = std::min(alloc_len, (uint8_t)this->img_buffer[0]);
this->switch_phase(ScsiPhase::DATA_IN);
}
void ScsiHardDisk::read_capacity_10() {
@@ -247,8 +293,7 @@ void ScsiHardDisk::read_capacity_10() {
WRITE_DWORD_BE_A(&img_buffer[0], last_lba);
WRITE_DWORD_BE_A(&img_buffer[4], blk_len);
this->cur_buf_cnt = 8;
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
this->bytes_out = 8;
this->switch_phase(ScsiPhase::DATA_IN);
}
@@ -272,8 +317,7 @@ void ScsiHardDisk::read(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len) {
this->hdd_img.seekg(device_offset, this->hdd_img.beg);
this->hdd_img.read(img_buffer, transfer_size);
this->cur_buf_cnt = transfer_size;
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
this->bytes_out = transfer_size;
this->switch_phase(ScsiPhase::DATA_IN);
}
@@ -306,6 +350,24 @@ void ScsiHardDisk::rewind() {
this->hdd_img.seekg(0, this->hdd_img.beg);
}
void ScsiHardDisk::read_buffer() {
uint8_t mode = this->cmd_buf[1];
uint32_t alloc_len = (this->cmd_buf[6] << 24) | (this->cmd_buf[7] << 16) |
this->cmd_buf[8];
switch(mode) {
case 0: // Combined header and data mode
WRITE_DWORD_BE_A(&this->img_buffer[0], 0x10000); // report buffer size of 64K
break;
default:
ABORT_F("SCSI-HD: unsupported mode %d in READ_BUFFER", mode);
}
this->bytes_out = alloc_len;
this->switch_phase(ScsiPhase::DATA_IN);
}
static const PropMap SCSI_HD_Properties = {
{"hdd_img", new StrProperty("")},
{"hdd_wr_prot", new BinProperty(0)},
+1
View File
@@ -59,6 +59,7 @@ protected:
void write(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len);
void seek(uint32_t lba);
void rewind();
void read_buffer();
private:
std::fstream hdd_img;
+66 -14
View File
@@ -47,7 +47,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
AMIC::AMIC() : MMIODevice()
{
this->name = "Apple Memory-mapped I/O Controller";
this->set_name("Apple Memory-mapped I/O Controller");
supports_types(HWCompType::MMIO_DEV | HWCompType::INT_CTRL);
@@ -55,6 +55,13 @@ AMIC::AMIC() : MMIODevice()
this->scsi = dynamic_cast<Sc53C94*>(gMachineObj->get_comp_by_name("Sc53C94"));
this->scsi_dma = std::unique_ptr<AmicScsiDma> (new AmicScsiDma());
this->scsi->set_dma_channel(this->scsi_dma.get());
this->scsi->set_drq_callback([this](const uint8_t drq_state) {
if (drq_state & 1)
via2_ifr |= VIA2_INT_SCSI_DRQ;
else
via2_ifr &= ~VIA2_INT_SCSI_DRQ;
this->update_via2_irq();
});
// connect serial HW
this->escc = dynamic_cast<EsccController*>(gMachineObj->get_comp_by_name("Escc"));
@@ -67,6 +74,7 @@ AMIC::AMIC() : MMIODevice()
// initialize sound HW
this->snd_out_dma = std::unique_ptr<AmicSndOutDma> (new AmicSndOutDma());
this->snd_out_dma->init_interrupts(this, 2 << 8);
this->awacs = std::unique_ptr<AwacDevicePdm> (new AwacDevicePdm());
this->awacs->set_dma_out(this->snd_out_dma.get());
@@ -169,6 +177,10 @@ uint32_t AMIC::read(uint32_t rgn_start, uint32_t offset, int size)
return this->mon_id;
case AMICReg::Int_Ctrl:
return (this->int_ctrl & 0xC0) | (this->dev_irq_lines & 0x3F);
case AMICReg::DMA_IFR_0:
return this->dma_ifr0;
case AMICReg::DMA_IFR_1:
return this->dma_ifr1;
case AMICReg::Diag_Reg:
return 0xFE | this->emmo_pin;
case AMICReg::DMA_Base_Addr_0:
@@ -208,7 +220,10 @@ void AMIC::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
this->mace->write((offset >> 4) & 0x1F, value);
return;
case 0x10:
this->scsi->write((offset >> 4) & 0xF, value);
if (offset & 0x100)
this->scsi->pseudo_dma_write(value);
else
this->scsi->write((offset >> 4) & 0xF, value);
return;
case 0x14: // Sound registers
switch(offset) {
@@ -235,14 +250,14 @@ void AMIC::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
LOG_F(9, "AMIC Sound Out Ctrl updated, val=%x", value);
if ((value & 1) != (this->snd_out_ctrl & 1)) {
if (value & 1) {
LOG_F(9, "AMIC Sound Out DMA enabled!");
LOG_F(INFO, "AMIC Sound Out DMA enabled!");
this->snd_out_dma->init(this->dma_base & ~0x3FFFF,
this->snd_buf_size);
this->snd_out_dma->enable();
this->awacs->set_sample_rate((this->snd_out_ctrl >> 1) & 3);
this->awacs->dma_out_start();
} else {
LOG_F(9, "AMIC Sound Out DMA disabled!");
LOG_F(INFO, "AMIC Sound Out DMA disabled!");
this->snd_out_dma->disable();
}
}
@@ -269,10 +284,13 @@ void AMIC::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
}
break;
case AMICReg::VIA2_IFR:
// for each "1" in value clear the corresponding IRQ bit
// TODO: is bit 7 read only?
this->via2_ifr &= ~(value & 0x7F);
this->update_via2_irq();
// if bit 7 is set, clear the corresponding IRQ bit for each "1" in value
if (value & 0x80) {
this->via2_ifr &= ~(value & 0x7F);
this->update_via2_irq();
} else { // writing any value to VIA2_IFR with bit 7 cleared has no effect
LOG_F(WARNING, "%s: bit 7 of VIA2_IFR is cleared!", this->name.c_str());
}
break;
case AMICReg::VIA2_Slot_IER:
if (value & 0x80)
@@ -287,6 +305,7 @@ void AMIC::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
} else {
this->via2_ier &= ~value;
}
this->update_via2_irq();
break;
case AMICReg::Ariel_Clut_Index:
this->def_vid->set_clut_index(value);
@@ -491,7 +510,24 @@ void AMIC::ack_cpu_int(uint32_t irq_id, uint8_t irq_line_state) {
}
void AMIC::ack_dma_int(uint32_t irq_id, uint8_t irq_line_state) {
ABORT_F("AMIC: ack_dma_int() not implemented");
if (irq_id >= 0x100) { // DMA Interrupt Flags 1
irq_id = (irq_id >> 8) & 0xFFU;
if (irq_line_state)
this->dma_ifr1 |= irq_id;
else
this->dma_ifr1 &= ~irq_id;
} else { // DMA Interrupt Flags 0
irq_id &= 0xFFU;
if (irq_line_state)
this->dma_ifr0 |= irq_id;
else
this->dma_ifr0 &= ~irq_id;
}
uint8_t new_irq = (this->dma_ifr0 || this->dma_ifr1) ? 1 : 0;
if (new_irq != this->dma_irq) {
this->dma_irq = new_irq;
this->ack_cpu_int(CPU_INT_ALL_DMA, new_irq);
}
}
// ============================ Sound DMA stuff ================================
@@ -510,6 +546,7 @@ void AmicSndOutDma::init(uint32_t buf_base, uint32_t buf_samples)
this->snd_buf_num = 0;
this->cur_buf_pos = 0;
this->irq_level = 0;
}
uint8_t AmicSndOutDma::read_stat()
@@ -517,12 +554,25 @@ uint8_t AmicSndOutDma::read_stat()
return this->dma_out_ctrl;
}
void AmicSndOutDma::update_irq() {
uint8_t new_level = !!((this->dma_out_ctrl >> 4) & this->dma_out_ctrl);
if (new_level != this->irq_level) {
this->irq_level = new_level;
TimerManager::get_instance()->add_immediate_timer([this] {
this->int_ctrl->ack_dma_int(this->irq_id, this->irq_level);
});
}
}
void AmicSndOutDma::write_dma_out_ctrl(uint8_t value)
{
// clear interrupt flags
value &= ~PDM_DMA_INTS_MASK;
this->dma_out_ctrl = value;
LOG_F(9, "AMIC: Sound out DMA control set to 0x%X", value);
if (value & PDM_DMA_INTS_MASK) {
this->dma_out_ctrl &= ~(value & PDM_DMA_INTS_MASK);
this->update_irq();
}
// enable sound output DMA interrupts
this->dma_out_ctrl |= value & 0x0FU;
}
DmaPullResult AmicSndOutDma::pull_data(uint32_t req_len, uint32_t *avail_len,
@@ -535,13 +585,15 @@ DmaPullResult AmicSndOutDma::pull_data(uint32_t req_len, uint32_t *avail_len,
if (!this->snd_buf_num) {
// signal buffer 0 drained
this->dma_out_ctrl |= PDM_DMA_IF0;
// TODO: generate IE0 interrupt if enabled
} else {
// signal buffer 1 drained
this->dma_out_ctrl |= PDM_DMA_IF1;
// TODO: generate IE1 interrupt if enabled
}
// generate sound out DMA interrupt if (IF0 & IE0)
// or (IF1 & IE1) or (ERR_IF & ERR_IE)
this->update_irq();
// check DMA enable flag after buffer 1 was processed
// if it's false stop delivering sound data
// this will effectively stop audio playback
+25 -10
View File
@@ -96,20 +96,30 @@ public:
void enable() { this->enabled = true; };
void disable() { this->enabled = false; };
uint8_t read_stat();
void update_irq();
void write_dma_out_ctrl(uint8_t value);
uint32_t get_cur_buf_pos() { return this->cur_buf_pos; };
DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len,
uint8_t **p_data);
private:
bool enabled;
uint8_t dma_out_ctrl;
void init_interrupts(InterruptCtrl *int_ctrl, uint32_t irq_id) {
this->int_ctrl = int_ctrl;
this->irq_id = irq_id;
};
uint32_t out_buf0;
uint32_t out_buf1;
uint32_t out_buf_len;
uint32_t snd_buf_num;
uint32_t cur_buf_pos;
private:
bool enabled = false;
uint8_t dma_out_ctrl;
uint32_t out_buf0;
uint32_t out_buf1;
uint32_t out_buf_len;
uint32_t snd_buf_num;
uint32_t cur_buf_pos;
InterruptCtrl *int_ctrl = nullptr;
uint32_t irq_id = 0;
uint8_t irq_level = 0;
};
/** AMIC-specific floppy DMA implementation. */
@@ -203,9 +213,9 @@ enum AMICReg : uint32_t {
// Interrupt registers
Int_Ctrl = 0x2A000,
DMA_Int_0 = 0x2A008,
DMA_IFR_0 = 0x2A008,
Bus_Err_Int_0 = 0x2A009,
DMA_Int_1 = 0x2A00A,
DMA_IFR_1 = 0x2A00A,
Bus_Err_Int_1 = 0x2A00B,
// Undocumented diagnostics register
@@ -293,6 +303,11 @@ private:
uint8_t int_ctrl = 0;
uint8_t dev_irq_lines = 0; // state of the IRQ lines
// DMA IRQ flag registers
uint8_t dma_ifr0 = 0;
uint8_t dma_ifr1 = 0;
uint8_t dma_irq = 0;
// pseudo VIA2 state
uint8_t via2_ier = 0;
uint8_t via2_ifr = 0;
+2 -3
View File
@@ -107,9 +107,8 @@ AwacDevicePdm::AwacDevicePdm() : AwacsBase("AWAC-PDM")
uint32_t AwacDevicePdm::read_stat()
{
LOG_F(INFO, "%s: status requested!", this->name.c_str());
// TODO: return valid status including manufacturer & device IDs
return 0;
// TODO: implement all other status bits
return (AWAC_REV_AWACS << 12) | (AWAC_MAKER_CRYSTAL << 8);
}
void AwacDevicePdm::write_ctrl(uint32_t addr, uint16_t value)
+2 -1
View File
@@ -148,8 +148,9 @@ public:
virtual void snd_ctrl_write(uint32_t offset, uint32_t value, int size) = 0;
};
/** AWACs Screamer manufacturer and revision. */
/** AWACs manufacturers and revisions. */
#define AWAC_MAKER_CRYSTAL 1
#define AWAC_REV_AWACS 2
#define AWAC_REV_SCREAMER 3
/** Screamer sound codec. */