sinclair/tsconf.cpp: Added NeoGS sound card and Kempston mouse. (#11016)

This commit is contained in:
holub 2023-03-24 13:57:02 -04:00 committed by GitHub
parent 753a80ea19
commit fbb67a2764
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 321 additions and 21 deletions

195
src/mame/sinclair/neogs.cpp Normal file
View File

@ -0,0 +1,195 @@
// license:BSD-3-Clause
// copyright-holders:Andrei I. Holub
/*******************************************************************************************
Sound card NeoGS appropriate for playing trackers (MOD) and compressed (MP3) music on
Spectrum-compatible computers with ZXBUS slot.
Hardware:
- Compatible with General Sound (GS);
- Flexible scheme, based on fpga (Altera EP1K30);
- 4Mb RAM, 512Kb flash-ROM;
- Extended techniques of memory addressing: 2 memory windows in visible area, exclude ROM
from visible area;
- Z80 frequency modes (10, 12, 20 and 24 Mhz);
- Support up to 8 sound channels (for MOD);
- SPI mp3-decoder (like VS1011);
- SD-card SPI interface;
- DMA to NeoGS memory (transfer data from ZX to NeoGS by instructions LDI, LDIR and similar);
- Parallel working (NeoGS play music independently from ZX).
Refs:
http://nedopc.com/gs/ngs_eng.php
https://github.com/psbhlw/gs-firmware
https://8bit.yarek.pl/interface/zx.generalsound/index.html
TODO:
- ZXBUS
- SPI
- DMA
- MP3
*******************************************************************************************/
#include "emu.h"
#include "neogs.h"
#include "speaker.h"
DEFINE_DEVICE_TYPE(NEOGS, neogs_device, "neogs", "NeoGS / General Sound")
ROM_START( neogs )
ROM_REGION(0x80000, "maincpu", 0)
ROM_DEFAULT_BIOS("v1.08")
ROM_SYSTEM_BIOS(0, "v1.08", "v1.08")
ROMX_LOAD( "neogs108.rom", 0x0000, 0x80000, CRC(8e261323) SHA1(b500b4aa8dea7506d26ad9e50593d9d3bee11ae1), ROM_BIOS(0))
ROM_SYSTEM_BIOS(1, "test_muchkin", "Test ROM (Muchkin)")
ROMX_LOAD( "testrom_muchkin.rom", 0x0000, 0x80000, CRC(8ab10a88) SHA1(cff3ca96489e517568146a00412107259360d01e), ROM_BIOS(1))
ROM_END
void neogs_device::update_config()
{
if (m_gscfg0 & 4) // EXPAG
;
if (m_gscfg0 & 1) // NOROM
{
m_bank_ram->set_entry(m_mpag % (m_ram->size() / 0x8000));
m_view.select(BIT(m_gscfg0, 1)); // RAMRO
}
else
{
m_bank_rom->set_entry(m_mpag % (memregion("maincpu")->bytes() / 0x8000));
m_view.disable();
}
const double cpu_scale = (BIT(m_gscfg0, 5) ? 1 : 1.2) * (1 << BIT(~m_gscfg0, 4));
m_maincpu->set_clock_scale(cpu_scale);
}
void neogs_device::ctrl_w(u8 data)
{
if (data & 0x80)
reset();
if (data & 0x40)
m_maincpu->pulse_input_line(INPUT_LINE_NMI, attotime::zero);
if (data & 0x20)
; // LED data:0 - 1-on, 0-off
}
template <u8 Bank> u8 neogs_device::ram_bank_r(offs_t offset)
{
return m_ram->read((0xc000 * Bank) + offset);
}
template <u8 Bank> void neogs_device::ram_bank_w(offs_t offset, u8 data)
{
m_ram->write((0xc000 * Bank) + offset, data);
}
INTERRUPT_GEN_MEMBER(neogs_device::irq0_line_assert)
{
m_maincpu->pulse_input_line(INPUT_LINE_IRQ0, attotime::from_ticks(32, m_maincpu->clock()));
}
void neogs_device::map_memory(address_map &map)
{
map(0x0000, 0x3fff).rom().region("maincpu", 0x0000);
map(0x4000, 0x7fff).rw(FUNC(neogs_device::ram_bank_r<1>), FUNC(neogs_device::ram_bank_w<1>));
map(0x8000, 0xffff).bankr(m_bank_rom);
map(0x0000, 0xffff).view(m_view);
m_view[0](0x0000, 0x3fff).rw(FUNC(neogs_device::ram_bank_r<0>), FUNC(neogs_device::ram_bank_w<0>));
m_view[0](0x8000, 0xffff).bankrw(m_bank_ram);
m_view[1](0x0000, 0x3fff).r(FUNC(neogs_device::ram_bank_r<0>));
m_view[1](0x8000, 0xffff).bankrw(m_bank_ram);
}
void neogs_device::map_io(address_map &map)
{
map(0x0000, 0x0000).mirror(0xff00).lw8(
NAME([this](offs_t offset, u8 data) { m_mpag = data; update_config(); }));
map(0x0001, 0x0001).mirror(0xff00).lr8(
NAME([this](offs_t offset) { return m_command_in; }));
map(0x0002, 0x0002).mirror(0xff00).lr8(
NAME([this](offs_t offset) { m_status &= ~0x80; return m_data_in; }));
map(0x0003, 0x0003).mirror(0xff00).lw8(
NAME([this](offs_t offset, u8 data) { m_status |= 0x80; m_data_out = data; }));
map(0x0004, 0x0004).mirror(0xff00).lr8(
NAME([this](offs_t offset) { return m_status; }));
map(0x0005, 0x0005).mirror(0xff00).lrw8(
NAME([this](offs_t offset) { m_status &= ~0x01; return ~0; }),
NAME([this](offs_t offset, u8 data) { m_status &= ~0x01; }));
map(0x0006, 0x0009).mirror(0xff00).lw8(
NAME([this](offs_t offset, u8 data) { m_vol[offset] = data & 0x3f; }));
map(0x0016, 0x0019).mirror(0xff00).lw8(
NAME([this](offs_t offset, u8 data) { m_vol[4 + offset] = data & 0x3f; }));
map(0x0010, 0x0010).mirror(0xff00).lw8(
NAME([this](offs_t offset, u8 data) { m_mpagx = data; update_config(); }));
//map(0x000a, 0x000a).mirror(0xff00).noprw();
//map(0x000b, 0x000b).mirror(0xff00).noprw();
map(0x000f, 0x000f).mirror(0xff00).lrw8(
NAME([this](offs_t offset) { return m_gscfg0; }),
NAME([this](offs_t offset, u8 data) { m_gscfg0 = data; update_config(); }));
map(0x0011, 0x0011).mirror(0xff00).nopw();
map(0x0013, 0x0013).mirror(0xff00).noprw();
map(0x0014, 0x0014).mirror(0xff00).nopr();
}
void neogs_device::device_add_mconfig(machine_config &config)
{
RAM(config, m_ram).set_default_size("4M").set_default_value(0xff);
Z80(config, m_maincpu, 10_MHz_XTAL);
m_maincpu->set_memory_map(&neogs_device::map_memory);
m_maincpu->set_io_map(&neogs_device::map_io);
m_maincpu->set_periodic_int(FUNC(neogs_device::irq0_line_assert), attotime::from_hz(37.5_kHz_XTAL));
SPEAKER(config, "lspeaker").front_left();
SPEAKER(config, "rspeaker").front_right();
for (auto i = 0; i < 8; i++)
DAC_16BIT_R2R_TWOS_COMPLEMENT(config, m_dac[i], 0).add_route(ALL_OUTPUTS, (i & 2) ? "rspeaker" : "lspeaker", 0.5); // TDA1543
}
const tiny_rom_entry *neogs_device::device_rom_region() const
{
return ROM_NAME( neogs );
}
void neogs_device::device_start()
{
if (!m_ram->started())
throw device_missing_dependencies();
memory_region *rom = memregion("maincpu");
m_bank_rom->configure_entries(0, rom->bytes() / 0x8000, rom->base(), 0x8000);
m_bank_ram->configure_entries(0, m_ram->size() / 0x8000, m_ram->pointer(), 0x8000);
m_maincpu->space(AS_PROGRAM).install_read_tap(0x6000, 0x7fff, "dac_w", [this](offs_t offset, u8 &data, u8 mem_mask)
{
if (!machine().side_effects_disabled())
{
const u8 chanel = BIT(offset, 8, BIT(m_gscfg0, 2) ? 3 : 2); // 8CHANS
const u8 sample = data ^ (m_gscfg0 & 0x80); // INV7B
const s16 out = (sample - 0x80) * (m_vol[chanel] << 2);
m_dac[chanel]->data_w(out);
if (BIT(m_gscfg0, 2) && BIT(m_gscfg0, 6)) // PAN4CH
;
}
});
}
void neogs_device::device_reset()
{
m_status = 0;
m_gscfg0 = 0;
m_mpag = 0;
update_config();
}

70
src/mame/sinclair/neogs.h Normal file
View File

@ -0,0 +1,70 @@
// license:BSD-3-Clause
// copyright-holders:Andrei I. Holub
#ifndef MAME_SINCLAIR_NEOGS_H
#define MAME_SINCLAIR_NEOGS_H
#pragma once
#include "cpu/z80/z80.h"
#include "machine/ram.h"
#include "sound/dac.h"
DECLARE_DEVICE_TYPE(NEOGS, neogs_device)
class neogs_device : public device_t
{
public:
neogs_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock = 0)
: device_t(mconfig, NEOGS, tag, owner, clock)
, m_maincpu(*this, "maincpu")
, m_ram(*this, RAM_TAG)
, m_bank_rom(*this, "bank_rom")
, m_bank_ram(*this, "bank_ram")
, m_view(*this, "view")
, m_dac(*this, "dac%u", 0U)
{ }
u8 status_r() { return m_status; };
void command_w(u8 data) { m_status |= 0x01; m_command_in = data; };
u8 data_r() { m_status &= ~0x80; return m_data_out; };
void data_w(u8 data) { m_status |= 0x80; m_data_in = data; };
void ctrl_w(u8 data);
protected:
// device-level overrides
void device_start() override;
void device_reset() override;
const tiny_rom_entry *device_rom_region() const override;
void device_add_mconfig(machine_config &config) override;
INTERRUPT_GEN_MEMBER(irq0_line_assert);
void map_memory(address_map &map);
void map_io(address_map &map);
void update_config();
required_device<z80_device> m_maincpu;
required_device<ram_device> m_ram;
memory_bank_creator m_bank_rom;
memory_bank_creator m_bank_ram;
memory_view m_view;
required_device_array<dac_word_interface, 8> m_dac;
private:
template <u8 Bank> u8 ram_bank_r(offs_t offset);
template <u8 Bank> void ram_bank_w(offs_t offset, u8 data);
u8 m_data_in;
u8 m_data_out;
u8 m_command_in;
u8 m_status;
u8 m_mpag;
u8 m_mpagx;
u8 m_gscfg0;
u8 m_vol[8];
};
#endif // MAME_SINCLAIR_NEOGS_H

View File

@ -103,8 +103,14 @@ void tsconf_state::tsconf_io(address_map &map)
map(0x00af, 0x00af).select(0xff00).rw(FUNC(tsconf_state::tsconf_port_xxaf_r), FUNC(tsconf_state::tsconf_port_xxaf_w));
map(0x8ff7, 0x8ff7).select(0x7000).w(FUNC(tsconf_state::tsconf_port_f7_w)); // 3:bff7 5:dff7 6:eff7
map(0xbff7, 0xbff7).r(FUNC(tsconf_state::tsconf_port_f7_r));
map(0xfadf, 0xfadf).lr8(NAME([this]() { return 0x80 | (m_io_mouse[2]->read() & 0x07); }));
map(0xfbdf, 0xfbdf).lr8(NAME([this]() { return m_io_mouse[0]->read(); }));
map(0xffdf, 0xffdf).lr8(NAME([this]() { return ~m_io_mouse[1]->read(); }));
map(0x8000, 0x8000).mirror(0x3ffd).w("ay8912", FUNC(ay8910_device::data_w));
map(0xc000, 0xc000).mirror(0x3ffd).rw("ay8912", FUNC(ay8910_device::data_r), FUNC(ay8910_device::address_w));
map(0x00bb, 0x00bb).mirror(0xff00).rw(m_gs, FUNC(neogs_device::status_r), FUNC(neogs_device::command_w));
map(0x00b3, 0x00b3).mirror(0xff00).rw(m_gs, FUNC(neogs_device::data_r), FUNC(neogs_device::data_w));
map(0x0033, 0x0033).mirror(0xff00).w(m_gs, FUNC(neogs_device::ctrl_w));
}
void tsconf_state::tsconf_switch(address_map &map)
@ -240,6 +246,22 @@ void tsconf_state::machine_reset()
while (m_keyboard->read() != 0) { /* invalidate buffer */ }
}
INPUT_PORTS_START( tsconf )
PORT_INCLUDE( spec_plus )
PORT_START("mouse_input1")
PORT_BIT(0xff, 0, IPT_MOUSE_X) PORT_SENSITIVITY(30)
PORT_START("mouse_input2")
PORT_BIT(0xff, 0, IPT_MOUSE_Y) PORT_SENSITIVITY(30)
PORT_START("mouse_input3")
PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_BUTTON4) PORT_NAME("Left mouse button") PORT_CODE(MOUSECODE_BUTTON1)
PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_BUTTON5) PORT_NAME("Right mouse button") PORT_CODE(MOUSECODE_BUTTON2)
PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_BUTTON6) PORT_NAME("Middle mouse button") PORT_CODE(MOUSECODE_BUTTON3)
INPUT_PORTS_END
void tsconf_state::tsconf(machine_config &config)
{
spectrum_128(config);
@ -280,6 +302,8 @@ void tsconf_state::tsconf(machine_config &config)
.add_route(1, "rspeaker", 0.25)
.add_route(2, "rspeaker", 0.50);
NEOGS(config, m_gs);
PALETTE(config, "palette", FUNC(tsconf_state::tsconf_palette), 256);
m_screen->set_raw(14_MHz_XTAL / 2, 448, with_hblank(0), 448, 320, with_vblank(0), 320);
subdevice<gfxdecode_device>("gfxdecode")->set_info(gfx_tsconf);
@ -298,4 +322,4 @@ ROM_START(tsconf)
ROM_END
// YEAR NAME PARENT COMPAT MACHINE INPUT CLASS INIT COMPANY FULLNAME FLAGS
COMP( 2011, tsconf, spec128, 0, tsconf, spec_plus, tsconf_state, empty_init, "NedoPC, TS-Labs", "ZX Evolution: TS-Configuration", 0)
COMP( 2011, tsconf, spec128, 0, tsconf, tsconf, tsconf_state, empty_init, "NedoPC, TS-Labs", "ZX Evolution: TS-Configuration", 0)

View File

@ -17,6 +17,7 @@
#include "glukrs.h"
#include "machine/pckeybrd.h"
#include "machine/spi_sdcard.h"
#include "neogs.h"
#include "tsconfdma.h"
#include "tilemap.h"
@ -29,6 +30,7 @@ public:
: spectrum_128_state(mconfig, type, tag),
m_bank0_rom(*this, "bank0_rom"),
m_keyboard(*this, "pc_keyboard"),
m_io_mouse(*this, "mouse_input%u", 1U),
m_beta(*this, BETA_DISK_TAG),
m_dma(*this, "dma"),
m_sdcard(*this, "sdcard"),
@ -36,7 +38,8 @@ public:
m_palette(*this, "palette"),
m_gfxdecode(*this, "gfxdecode"),
m_cram(*this, "cram"),
m_sfile(*this, "sfile")
m_sfile(*this, "sfile"),
m_gs(*this, "gs")
{
}
@ -50,7 +53,6 @@ protected:
void machine_start() override;
void machine_reset() override;
TIMER_CALLBACK_MEMBER(irq_on) override;
TIMER_CALLBACK_MEMBER(irq_off) override;
TIMER_CALLBACK_MEMBER(irq_frame);
TIMER_CALLBACK_MEMBER(irq_scanline);
@ -196,6 +198,7 @@ private:
memory_view m_bank0_rom;
required_device<at_keyboard_device> m_keyboard;
required_ioport_array<3> m_io_mouse;
required_device<beta_disk_device> m_beta;
required_device<tsconfdma_device> m_dma;
@ -212,6 +215,7 @@ private:
tilemap_t *m_ts_tilemap[3]{};
required_device<ram_device> m_cram;
required_device<ram_device> m_sfile;
required_device<neogs_device> m_gs;
};
/*----------- defined in drivers/tsconf.c -----------*/

View File

@ -213,7 +213,7 @@ void tsconf_state::tsconf_UpdateGfxBitmap(bitmap_ind16 &bitmap, const rectangle
u8 pal_offset = m_regs[PAL_SEL] << 4;
for (u16 vpos = cliprect.top(); vpos <= cliprect.bottom(); vpos++)
{
u16 y_offset = (0x200 + OFFS_512(G_Y_OFFS_L) + m_gfx_y_frame_offset + vpos) & 0x1ff;
u16 y_offset = (OFFS_512(G_Y_OFFS_L) + m_gfx_y_frame_offset + vpos) & 0x1ff;
u16 x_offset = (OFFS_512(G_X_OFFS_L) + (cliprect.left() - get_screen_area().left())) & 0x1ff;
u8 *video_location = m_ram->pointer() + PAGE4K(m_regs[V_PAGE]) + ((y_offset * 512 + x_offset) >> (2 - VM));
u16 *bm = &(bitmap.pix(vpos, cliprect.left()));
@ -767,58 +767,65 @@ IRQ_CALLBACK_MEMBER(tsconf_state::irq_vector)
return vector;
}
TIMER_CALLBACK_MEMBER(tsconf_state::irq_on)
{
m_maincpu->set_input_line(INPUT_LINE_IRQ0, ASSERT_LINE);
m_irq_off_timer->adjust(attotime::from_ticks(32, m_maincpu->unscaled_clock()));
}
TIMER_CALLBACK_MEMBER(tsconf_state::irq_off)
{
m_int_mask = 0;
m_maincpu->set_input_line(0, CLEAR_LINE);
m_int_mask &= ~1;
if (!m_int_mask)
m_maincpu->set_input_line(0, CLEAR_LINE);
}
void tsconf_state::update_frame_timer()
{
u16 vpos = OFFS_512(VS_INT_L);
u16 hpos = m_regs[HS_INT];
attotime at = (BIT(m_regs[INT_MASK], 0) && vpos <= 319 && hpos <= 223) ? m_screen->time_until_pos(vpos, hpos << 1) : m_screen->time_until_pos(0, 0);
if (at >= m_screen->frame_period())
at = attotime::zero;
m_frame_irq_timer->adjust(at);
attotime next;
if (vpos <= 319 && hpos <= 223)
{
next = m_screen->time_until_pos(vpos, hpos << 1);
if (next >= m_screen->frame_period())
next = attotime::zero;
}
else
next = attotime::never;
m_gfx_y_frame_offset = -get_screen_area().top();
m_frame_irq_timer->adjust(next);
}
INTERRUPT_GEN_MEMBER(tsconf_state::tsconf_vblank_interrupt)
{
update_frame_timer();
m_gfx_y_frame_offset = -get_screen_area().top();
m_scanline_irq_timer->adjust(attotime::zero);
}
void tsconf_state::dma_ready(int line)
{
if (BIT(m_regs[INT_MASK], 4))
if (BIT(m_regs[INT_MASK], 2))
{
if (!m_int_mask)
m_maincpu->set_input_line(INPUT_LINE_IRQ0, ASSERT_LINE);
m_int_mask |= 4;
m_irq_on_timer->adjust(attotime::zero);
}
}
TIMER_CALLBACK_MEMBER(tsconf_state::irq_frame)
{
if (BIT(m_regs[INT_MASK], 0))
{
if (!m_int_mask)
m_maincpu->set_input_line(INPUT_LINE_IRQ0, ASSERT_LINE);
m_irq_off_timer->adjust(attotime::from_ticks(32, m_maincpu->unscaled_clock()));
m_int_mask |= 1;
m_irq_on_timer->adjust(attotime::zero);
}
}
TIMER_CALLBACK_MEMBER(tsconf_state::irq_scanline)
{
if (BIT(m_regs[INT_MASK], 1))
{
if (!m_int_mask)
m_maincpu->set_input_line(INPUT_LINE_IRQ0, ASSERT_LINE);
m_int_mask |= 2;
m_irq_on_timer->adjust(attotime::zero);
}
u16 screen_vpos = m_screen->vpos();