diff options
author | Devin Acker <d@revenant1.net> | 2021-10-13 03:35:00 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-13 09:35:00 +0200 |
commit | 8962638b779165a93817553a4d75cd15dcabecf6 (patch) | |
tree | beba0ea20d2e6521ed4f27cb50160e170797ca9e /src/devices/machine | |
parent | a15538b4aeffee95a0821ca8de71ca94d6fe864d (diff) |
Casio CTK-551 [Daivn Acker]
* New machine marked as NOT_WORKING
----------------------------------
Casio CTK-551 [Devin Acker]
Diffstat (limited to 'src/devices/machine')
-rw-r--r-- | src/devices/machine/gt913_io.cpp | 156 | ||||
-rw-r--r-- | src/devices/machine/gt913_io.h | 74 | ||||
-rw-r--r-- | src/devices/machine/gt913_kbd.cpp | 104 | ||||
-rw-r--r-- | src/devices/machine/gt913_kbd.h | 62 | ||||
-rw-r--r-- | src/devices/machine/gt913_snd.cpp | 167 | ||||
-rw-r--r-- | src/devices/machine/gt913_snd.h | 45 |
6 files changed, 608 insertions, 0 deletions
diff --git a/src/devices/machine/gt913_io.cpp b/src/devices/machine/gt913_io.cpp new file mode 100644 index 00000000000..e77efd91fd9 --- /dev/null +++ b/src/devices/machine/gt913_io.cpp @@ -0,0 +1,156 @@ +// license:BSD-3-Clause +// copyright-holders:Devin Acker +/*************************************************************************** + Casio GT913 I/O (HLE) + + TODO: + - timer behavior is unverified (see comment in timer_control_w and timer_adjust) + - various other unemulated registers + +***************************************************************************/ + +#include "emu.h" +#include "gt913_io.h" + + +//************************************************************************** +// DEVICE DEFINITIONS +//************************************************************************** + +DEFINE_DEVICE_TYPE(GT913_IO_HLE, gt913_io_hle_device, "gt913_io_hle", "Casio GT913F I/O (HLE)") + +gt913_io_hle_device::gt913_io_hle_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) : + device_t(mconfig, GT913_IO_HLE, tag, owner, clock), + m_cpu(*this, DEVICE_SELF_OWNER), + m_cpu_io(nullptr), m_intc(nullptr), m_intc_tag(nullptr) +{ + m_timer_irq[0] = m_timer_irq[1] = 0; +} + +void gt913_io_hle_device::device_start() +{ + m_cpu_io = &m_cpu->space(AS_IO); + m_intc = siblingdevice<h8_intc_device>(m_intc_tag); + + m_timer[0] = timer_alloc(0); + m_timer[1] = timer_alloc(1); + + save_item(NAME(m_timer_control)); + save_item(NAME(m_timer_rate)); + save_item(NAME(m_timer_irq_pending)); + save_item(NAME(m_adc_enable)); + save_item(NAME(m_adc_channel)); + save_item(NAME(m_adc_data)); +} + +void gt913_io_hle_device::device_reset() +{ + m_timer_control[0] = m_timer_control[1] = 0x00; + m_timer_rate[0] = m_timer_rate[1] = 0; + m_timer_irq_pending[0] = m_timer_irq_pending[1] = false; + + m_adc_enable = false; + m_adc_channel = false; + m_adc_data[0] = m_adc_data[1] = 0; +} + +void gt913_io_hle_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) +{ + m_timer_irq_pending[id] = true; + timer_check_irq(id); +} + +void gt913_io_hle_device::timer_control_w(offs_t offset, uint8_t data) +{ + assert(offset < 2); + // TODO: ctk551 clears and sets bit 4 during the respective timer's IRQ, what should this do? pause/restart the timer? + m_timer_control[offset] = data; + timer_check_irq(offset); +} + +uint8_t gt913_io_hle_device::timer_control_r(offs_t offset) +{ + assert(offset < 2); + return m_timer_control[offset]; +} + +void gt913_io_hle_device::timer_rate0_w(uint16_t data) +{ + m_timer_rate[0] = data; + timer_adjust(0); +} + +void gt913_io_hle_device::timer_rate1_w(uint8_t data) +{ + m_timer_rate[1] = data; + timer_adjust(1); +} + +void gt913_io_hle_device::timer_adjust(offs_t num) +{ + assert(num < 2); + + /* + On the CTK-551, this behavior provides the expected rate for timer 0, which is the MIDI PPQN timer. + For timer 1, this is less certain, but it seems to provide an auto power off delay only a little + longer than the "about six minutes" mentioned in the user manual. + */ + u64 clocks = m_timer_rate[num]; + if (!clocks) + { + m_timer[num]->adjust(attotime::never); + } + else + { + switch (m_timer_control[num] & 0x7) + { + default: + logerror("unknown timer %u prescaler %u (pc = %04x)\n", num, m_timer_control[num] & 0x7, m_cpu->pc()); + [[fallthrough]]; + case 0: + clocks <<= 1; break; + case 2: + clocks <<= 10; break; + } + + attotime period = m_cpu->clocks_to_attotime(clocks); + m_timer[num]->adjust(period, 0, period); + } +} + +void gt913_io_hle_device::timer_check_irq(offs_t num) +{ + assert(num < 2); + + if (BIT(m_timer_control[num], 3) && m_timer_irq_pending[num]) + { + m_intc->internal_interrupt(m_timer_irq[num]); + m_timer_irq_pending[num] = false; + } +} + +void gt913_io_hle_device::adc_control_w(uint8_t data) +{ + m_adc_enable = BIT(data, 2); + m_adc_channel = BIT(data, 3); + if (m_adc_enable && BIT(data, 0)) + { + if (!m_adc_channel) + m_adc_data[0] = m_cpu_io->read_word(h8_device::ADC_0); + else + m_adc_data[1] = m_cpu_io->read_word(h8_device::ADC_1); + } +} + +uint8_t gt913_io_hle_device::adc_control_r() +{ + return (m_adc_enable << 2) | (m_adc_channel << 3); +} + +uint8_t gt913_io_hle_device::adc_data_r() +{ + if (!m_adc_channel) + return m_adc_data[0]; + else + return m_adc_data[1]; +} diff --git a/src/devices/machine/gt913_io.h b/src/devices/machine/gt913_io.h new file mode 100644 index 00000000000..08fc5f9595f --- /dev/null +++ b/src/devices/machine/gt913_io.h @@ -0,0 +1,74 @@ +// license:BSD-3-Clause +// copyright-holders: Devin Acker +/*************************************************************************** + Casio GT913 I/O (HLE) +***************************************************************************/ + +#ifndef MAME_MACHINE_GT913_IO_H +#define MAME_MACHINE_GT913_IO_H + +#pragma once + +#include "cpu/h8/h8_intc.h" + +//************************************************************************** +// TYPE DEFINITIONS +//************************************************************************** + +// ======================> gt913_kbd_hle_device + +class gt913_io_hle_device : public device_t +{ +public: + // construction/destruction + gt913_io_hle_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock = 0); + gt913_io_hle_device(const machine_config &mconfig, const char *tag, device_t *owner, const char *intc, int t0irq, int t1irq) + : gt913_io_hle_device(mconfig, tag, owner, 0) + { + m_intc_tag = intc; + m_timer_irq[0] = t0irq; + m_timer_irq[1] = t1irq; + } + + void timer_control_w(offs_t offset, uint8_t data); + uint8_t timer_control_r(offs_t offset); + void timer_rate0_w(uint16_t data); + void timer_rate1_w(uint8_t data); + + void adc_control_w(uint8_t data); + uint8_t adc_control_r(); + uint8_t adc_data_r(); + +protected: + void timer_adjust(offs_t num); + void timer_check_irq(offs_t num); + + // device_t overrides + virtual void device_start() override; + virtual void device_reset() override; + + virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; + +private: + required_device<cpu_device> m_cpu; + address_space *m_cpu_io; + h8_intc_device *m_intc; + const char *m_intc_tag; + + /* timers */ + uint8_t m_timer_control[2]; + uint16_t m_timer_rate[2]; + int m_timer_irq[2]; + bool m_timer_irq_pending[2]; + emu_timer *m_timer[2]; + + /* 2x ADC */ + bool m_adc_enable, m_adc_channel; + uint8_t m_adc_data[2]; + +}; + +// device type definition +DECLARE_DEVICE_TYPE(GT913_IO_HLE, gt913_io_hle_device) + +#endif // MAME_MACHINE_GT913_IO_H diff --git a/src/devices/machine/gt913_kbd.cpp b/src/devices/machine/gt913_kbd.cpp new file mode 100644 index 00000000000..92d80512cc2 --- /dev/null +++ b/src/devices/machine/gt913_kbd.cpp @@ -0,0 +1,104 @@ +// license:BSD-3-Clause +// copyright-holders:Devin Acker +/*************************************************************************** + Casio GT913 keyboard controller (HLE) + + This is the keyboard controller portion of the GT913. + The actual keyboard keys (as opposed to console buttons) have two + contacts per key, which allows the controller to detect the velocity + of the keypress. The detected velocity is read as a 7-bit value + from the data port, along with the actual key scan code. + + Right now, velocity is just simulated using an (optional) analog + control. The keyboard FIFO size is also basically a guess based on + the CTK-551's 16-key polyphony. + +***************************************************************************/ + +#include "emu.h" +#include "gt913_kbd.h" +#include "keyboard.ipp" + + +//************************************************************************** +// DEVICE DEFINITIONS +//************************************************************************** + +DEFINE_DEVICE_TYPE(GT913_KBD_HLE, gt913_kbd_hle_device, "gt913_kbd_hle", "Casio GT913F keyboard controller (HLE)") + +gt913_kbd_hle_device::gt913_kbd_hle_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) : + device_t(mconfig, GT913_KBD_HLE, tag, owner, clock), + device_matrix_keyboard_interface(mconfig, *this, "KO0", "KO1", "KO2", "KO3", "KO4", "KO5", "KO6", "KO7", "KO8", "KO9", "KO10", "KO11", "KO12"), + m_intc(nullptr), m_intc_tag(nullptr), m_irq(0), + m_velocity(*this, "VELOCITY") +{ +} + +void gt913_kbd_hle_device::device_start() +{ + m_intc = siblingdevice<h8_intc_device>(m_intc_tag); + + save_item(NAME(m_status)); + save_item(NAME(m_fifo)); + save_item(NAME(m_fifo_read)); + save_item(NAME(m_fifo_write)); +} + +void gt913_kbd_hle_device::device_reset() +{ + m_status = 0x0000; + std::memset(m_fifo, 0xff, sizeof(m_fifo)); + m_fifo_read = m_fifo_write = 0; + + reset_key_state(); + start_processing(attotime::from_hz(1200)); +} + +void gt913_kbd_hle_device::key_add(uint8_t row, uint8_t column, int state) +{ + m_fifo[m_fifo_write] = (row << 3) | (column & 7); + if (state) + m_fifo[m_fifo_write] |= 0x80; + + if (((m_fifo_write + 1) & 15) != m_fifo_read) + { + (++m_fifo_write) &= 15; + update_status(); + } +} + +void gt913_kbd_hle_device::update_status() +{ + if (m_fifo_read == m_fifo_write) + m_status &= 0x7fff; + else + m_status |= 0x8000; + + if (BIT(m_status, 15) && BIT(m_status, 14)) + m_intc->internal_interrupt(m_irq); +} + +uint16_t gt913_kbd_hle_device::read() +{ + if (m_fifo_read == m_fifo_write) + return 0xff00; + + uint16_t data = (m_fifo[m_fifo_read] << 8) | m_velocity.read_safe(0x7f); + + if (!machine().side_effects_disabled()) + { + if (m_fifo_read != m_fifo_write) + { + (++m_fifo_read) &= 15; + update_status(); + } + } + + return data; +} + +void gt913_kbd_hle_device::status_w(uint16_t data) +{ + m_status = data; + update_status(); +} diff --git a/src/devices/machine/gt913_kbd.h b/src/devices/machine/gt913_kbd.h new file mode 100644 index 00000000000..3e44b1166cb --- /dev/null +++ b/src/devices/machine/gt913_kbd.h @@ -0,0 +1,62 @@ +// license:BSD-3-Clause +// copyright-holders: Devin Acker +/*************************************************************************** + Casio GT913 keyboard controller (HLE) +***************************************************************************/ + +#ifndef MAME_MACHINE_GT913_KBD_H +#define MAME_MACHINE_GT913_KBD_H + +#pragma once + +#include "cpu/h8/h8_intc.h" +#include "keyboard.h" + +//************************************************************************** +// TYPE DEFINITIONS +//************************************************************************** + +// ======================> gt913_kbd_hle_device + +class gt913_kbd_hle_device : public device_t, protected device_matrix_keyboard_interface<13> +{ +public: + // construction/destruction + gt913_kbd_hle_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock = 0); + gt913_kbd_hle_device(const machine_config &mconfig, const char *tag, device_t *owner, const char *intc, int irq) + : gt913_kbd_hle_device(mconfig, tag, owner, 0) + { + m_intc_tag = intc; + m_irq = irq; + } + + uint16_t read(); + void status_w(uint16_t data); + uint16_t status_r() { return m_status; } + +protected: + // device_t overrides + virtual void device_start() override; + virtual void device_reset() override; + + // device_matrix_keyboard_interface overrides + virtual void key_make(uint8_t row, uint8_t column) override { key_add(row, column, 0); } + virtual void key_break(uint8_t row, uint8_t column) override { key_add(row, column, 1); } + + void key_add(uint8_t row, uint8_t column, int state); + void update_status(); +private: + h8_intc_device *m_intc; + const char *m_intc_tag; + int m_irq; + optional_ioport m_velocity; + + uint16_t m_status; + uint8_t m_fifo[16]; + uint8_t m_fifo_read, m_fifo_write; +}; + +// device type definition +DECLARE_DEVICE_TYPE(GT913_KBD_HLE, gt913_kbd_hle_device) + +#endif // MAME_MACHINE_GT913_KBD_H diff --git a/src/devices/machine/gt913_snd.cpp b/src/devices/machine/gt913_snd.cpp new file mode 100644 index 00000000000..8ffabac7077 --- /dev/null +++ b/src/devices/machine/gt913_snd.cpp @@ -0,0 +1,167 @@ +// license:BSD-3-Clause +// copyright-holders:Devin Acker +/*************************************************************************** + Casio GT913 sound (HLE) + + This is the sound portion of the GT913. + Up to 24 voices can be mixed into a 16-bit stereo serial bitstream, + which is then input to either a serial DAC or a HG51B-based DSP, + depending on the model of keyboard. + + Currently, the actual sample format in ROM is unknown. + The serial output is twos-complement 16-bit PCM, but the data in ROM + doesn't seem to be - reading it as such produces sounds that are + somewhat recognizable, but highly distorted. + + For now, all known (and unknown) register writes are just logged + without generating any sound. + +***************************************************************************/ + +#include "emu.h" +#include "gt913_snd.h" + + +//************************************************************************** +// DEVICE DEFINITIONS +//************************************************************************** + +DEFINE_DEVICE_TYPE(GT913_SOUND_HLE, gt913_sound_hle_device, "gt913_sound_hle", "Casio GT913F sound (HLE)") + +gt913_sound_hle_device::gt913_sound_hle_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) : + device_t(mconfig, GT913_SOUND_HLE, tag, owner, clock) +{ +} + +void gt913_sound_hle_device::device_start() +{ + save_item(NAME(m_gain)); + save_item(NAME(m_data)); + + save_item(NAME(m_volume_target)); + save_item(NAME(m_volume_rate)); +} + +void gt913_sound_hle_device::device_reset() +{ + m_gain = 0; + std::memset(m_data, 0, sizeof(m_data)); + std::memset(m_volume_target, 0, sizeof(m_volume_target)); + std::memset(m_volume_rate, 0, sizeof(m_volume_rate)); +} + +void gt913_sound_hle_device::data_w(offs_t offset, uint16_t data) +{ + assert(offset < 3); + m_data[offset] = data; +} + +uint16_t gt913_sound_hle_device::data_r(offs_t offset) +{ + assert(offset < 3); + return m_data[offset]; +} + +void gt913_sound_hle_device::command_w(uint16_t data) +{ + uint8_t voicenum = (data & 0x1f00) >> 8; + uint16_t voicecmd = data & 0x60ff; + + if (data == 0x0012) + { + uint8_t gain = m_data[0] & 0x3f; + if (gain != m_gain) + logerror("gain %u\n", gain); + m_gain = gain; + } + else if (voicenum >= 24) + { + return; + } + else if (voicecmd == 0x0008) + { + /* + Set the voice's sample start point as a ROM address. + This is usually word-aligned, but not always + (e.g. ctk551's lowest piano sample is at address 0x5a801) + */ + uint32_t samplestart = (m_data[1] | (m_data[2] << 16)) & 0xfffff; + logerror("voice %u sample start 0x%06x\n", voicenum, samplestart); + } + else if (voicecmd == 0x0000) + { + /* + Set the voice's sample end point as a ROM address. + */ + uint32_t sampleend = (m_data[0] | (m_data[1] << 16)) & 0xfffff; + logerror("voice %u sample end 0x%06x\n", voicenum, sampleend); + } + else if (voicecmd == 0x2000) + { + /* + Set the voice's sample loop point as a ROM address. + */ + uint32_t sampleloop = (m_data[0] | (m_data[1] << 16)) & 0xfffff; + logerror("voice %u sample loop 0x%06x\n", voicenum, sampleloop); + } + else if (voicecmd == 0x200b) + { + /* + Turn this voice on/off. + ctk551 turns output off before assigning a new note or instrument to this voice, + then turns output back on afterward + */ + logerror("voice %u output %s\n", voicenum, BIT(m_data[2], 7) ? "on" : "off"); + } + else if (voicecmd == 0x4004) + { + /* + Set this voice's panning, in the form of left and right volume levels (3 bits each) + */ + uint8_t left = (m_data[1] & 0xe0) >> 5; + uint8_t right = (m_data[1] & 0x1c) >> 2; + logerror("voice %u left %u right %u\n", voicenum, left, right); + } + else if (voicecmd == 0x4005) + { + /* + Set the current pitch of this voice. + The actual format of the value is unknown, but presumably some kind of fixed point + */ + uint32_t pitch = (m_data[0] << 8) | (m_data[1] >> 8); + logerror("voice %u pitch 0x%06x\n", voicenum, pitch); + } + else if (voicecmd == 0x6007) + { + /* + Raise or lower the volume to a specified level at a specified rate. + The actual volume level is probably 7.8 fixed point or something like that, but this command + only sets the most significant bits. + */ + logerror("voice %u volume %u rate %u\n", voicenum, (m_data[0] >> 8) & 0x7f, m_data[0] & 0xff); + m_volume_target[voicenum] = m_data[0] & 0x7f00; + m_volume_rate[voicenum] = m_data[0] & 0xff; + } + else if (voicecmd == 0x2028) + { + /* + ctk551 issues this command and then reads the voice's current volume from data0 + to determine if it's time to start the next part of the volume envelope or not. + For now, just return the "target" volume immediately + (TODO: also figure out what it expects to be returned in data1) + */ + m_data[0] = m_volume_target[voicenum]; + m_data[1] = 0; + } + else + { + logerror("unknown sound write %04x (data: %04x %04x %04x)\n", data, m_data[0], m_data[1], m_data[2]); + } +} + +uint16_t gt913_sound_hle_device::status_r() +{ + /* ctk551 reads the current gain level out of the lower 6 bits and ignores the rest + it's unknown what, if anything, the other bits are supposed to contain */ + return m_gain & 0x3f; +} diff --git a/src/devices/machine/gt913_snd.h b/src/devices/machine/gt913_snd.h new file mode 100644 index 00000000000..cc994690d3d --- /dev/null +++ b/src/devices/machine/gt913_snd.h @@ -0,0 +1,45 @@ +// license:BSD-3-Clause +// copyright-holders: Devin Acker +/*************************************************************************** + Casio GT913 sound (HLE) +***************************************************************************/ + +#ifndef MAME_AUDIO_GT913_H +#define MAME_AUDIO_GT913_H + +#pragma once + +//************************************************************************** +// TYPE DEFINITIONS +//************************************************************************** + +// ======================> gt913_sound_hle_device + +class gt913_sound_hle_device : public device_t +{ +public: + // construction/destruction + gt913_sound_hle_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock = 0); + + void data_w(offs_t offset, uint16_t data); + uint16_t data_r(offs_t offset); + void command_w(uint16_t data); + uint16_t status_r(); + +protected: + // device_t overrides + virtual void device_start() override; + virtual void device_reset() override; + +private: + uint8_t m_gain; + uint16_t m_data[3]; + + uint16_t m_volume_target[24]; + uint8_t m_volume_rate[24]; +}; + +// device type definition +DECLARE_DEVICE_TYPE(GT913_SOUND_HLE, gt913_sound_hle_device) + +#endif // MAME_AUDIO_GT913_H |