From 394107b576959f48311e07e73e92cb3e0f5cbe1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miodrag=20Milanovi=C4=87?= Date: Sun, 1 May 2022 20:45:47 +0200 Subject: -tim011.cpp: Hooked up floppy drives properly. (#9649) * Hooked up floppy drives and controller properly, and implemented video display. * formats/tim011_dsk.cpp: Added TIM 011 floppy image format. -machine/upd765.cpp: If waiting for additional command bytes, treat a data register read as an open bus write (tested on real hardware) and always trigger the DRQ line even if in nodma mode. [Carl -cpu/z180: Added callbacks for tend; decrement bcr1 when DMA channel 1 is active. [Carl] --- scripts/src/formats.lua | 12 ++++++ scripts/target/mame/mess.lua | 1 + src/devices/cpu/z180/z180.cpp | 16 +++++++ src/devices/cpu/z180/z180.h | 5 +++ src/devices/machine/upd765.cpp | 20 +++++---- src/lib/formats/all.cpp | 9 ++++ src/lib/formats/tim011_dsk.cpp | 45 ++++++++++++++++++++ src/lib/formats/tim011_dsk.h | 32 ++++++++++++++ src/mame/drivers/tim011.cpp | 97 +++++++++++++++++++++++++----------------- 9 files changed, 189 insertions(+), 48 deletions(-) create mode 100644 src/lib/formats/tim011_dsk.cpp create mode 100644 src/lib/formats/tim011_dsk.h diff --git a/scripts/src/formats.lua b/scripts/src/formats.lua index 10b27e06ec3..1798880b0e0 100644 --- a/scripts/src/formats.lua +++ b/scripts/src/formats.lua @@ -1872,6 +1872,18 @@ if opt_tool(FORMATS, "TIKI100_DSK") then } end +-------------------------------------------------- +-- +--@src/lib/formats/tim011_dsk.h,FORMATS["TIM011_DSK"] = true +-------------------------------------------------- + +if opt_tool(FORMATS, "TIM011_DSK") then + files { + MAME_DIR.. "src/lib/formats/tim011_dsk.cpp", + MAME_DIR.. "src/lib/formats/tim011_dsk.h", + } +end + -------------------------------------------------- -- --@src/lib/formats/trd_dsk.h,FORMATS["TRD_DSK"] = true diff --git a/scripts/target/mame/mess.lua b/scripts/target/mame/mess.lua index 64c1d4124dd..2f49b9994dc 100644 --- a/scripts/target/mame/mess.lua +++ b/scripts/target/mame/mess.lua @@ -1170,6 +1170,7 @@ FORMATS["THOM_CAS"] = true FORMATS["THOM_DSK"] = true FORMATS["TI99_DSK"] = true FORMATS["TIKI100_DSK"] = true +FORMATS["TIM011_DSK"] = true FORMATS["TRD_DSK"] = true FORMATS["TRS80_DSK"] = true FORMATS["TRS_CAS"] = true diff --git a/src/devices/cpu/z180/z180.cpp b/src/devices/cpu/z180/z180.cpp index dc7fe875b7e..6c68b877bca 100644 --- a/src/devices/cpu/z180/z180.cpp +++ b/src/devices/cpu/z180/z180.cpp @@ -94,6 +94,8 @@ z180_device::z180_device(const machine_config &mconfig, device_type type, const , m_io_config("io", ENDIANNESS_LITTLE, 8, 16, 0) , m_decrypted_opcodes_config("opcodes", ENDIANNESS_LITTLE, 8, 20, 0, 16, 12, internal_map) , m_extended_io(extended_io) + , m_tend0_cb(*this) + , m_tend1_cb(*this) { // some arbitrary initial values m_asci_cntla[0] = m_asci_cntla[1] = 0; @@ -145,6 +147,12 @@ z80182_device::z80182_device(const machine_config &mconfig, const char *tag, dev { } +void z180_device::device_resolve_objects() +{ + m_tend0_cb.resolve_safe(); + m_tend1_cb.resolve_safe(); +} + #define CF 0x01 #define NF 0x02 #define PF 0x04 @@ -1269,6 +1277,7 @@ int z180_device::z180_dma0(int max_cycles) if (bcr0 == 1) { m_iol |= Z180_TEND0; + m_tend0_cb(ASSERT_LINE); } switch( m_dmode & (Z180_DMODE_SM | Z180_DMODE_DM) ) { @@ -1391,6 +1400,7 @@ int z180_device::z180_dma0(int max_cycles) if (bcr0 == 0) { m_iol &= ~Z180_TEND0; + m_tend0_cb(CLEAR_LINE); m_dstat &= ~Z180_DSTAT_DE0; /* terminal count interrupt enabled? */ if (m_dstat & Z180_DSTAT_DIE0 && m_IFF1) @@ -1424,6 +1434,7 @@ int z180_device::z180_dma1() if (bcr1 == 1) { m_iol |= Z180_TEND1; + m_tend1_cb(ASSERT_LINE); } m_extra_cycles = 0; @@ -1432,15 +1443,19 @@ int z180_device::z180_dma1() { case 0x00: /* memory MAR1+1 to I/O IAR1 fixed */ m_io.write_byte(iar1, z180_read_memory(mar1++)); + bcr1--; break; case 0x01: /* memory MAR1-1 to I/O IAR1 fixed */ m_io.write_byte(iar1, z180_read_memory(mar1--)); + bcr1--; break; case 0x02: /* I/O IAR1 fixed to memory MAR1+1 */ z180_write_memory(mar1++, m_io.read_byte(iar1)); + bcr1--; break; case 0x03: /* I/O IAR1 fixed to memory MAR1-1 */ z180_write_memory(mar1--, m_io.read_byte(iar1)); + bcr1--; break; } @@ -1458,6 +1473,7 @@ int z180_device::z180_dma1() if (bcr1 == 0) { m_iol &= ~Z180_TEND1; + m_tend1_cb(CLEAR_LINE); m_dstat &= ~Z180_DSTAT_DE1; if (m_dstat & Z180_DSTAT_DIE1 && m_IFF1) m_int_pending[Z180_INT_DMA1] = 1; diff --git a/src/devices/cpu/z180/z180.h b/src/devices/cpu/z180/z180.h index 7ce993cb7dc..94b95d1488e 100644 --- a/src/devices/cpu/z180/z180.h +++ b/src/devices/cpu/z180/z180.h @@ -105,6 +105,9 @@ enum { class z180_device : public cpu_device, public z80_daisy_chain_interface { public: + auto tend0_wr_callback() { return m_tend0_cb.bind(); } + auto tend1_wr_callback() { return m_tend1_cb.bind(); } + bool get_tend0(); bool get_tend1(); @@ -115,6 +118,7 @@ protected: // device-level overrides virtual void device_start() override; virtual void device_reset() override; + virtual void device_resolve_objects() override; // device_execute_interface overrides virtual uint32_t execute_min_cycles() const noexcept override { return 1; } @@ -210,6 +214,7 @@ private: int m_icount; int m_extra_cycles; /* extra cpu cycles */ uint8_t *m_cc[6]; + devcb_write_line m_tend0_cb, m_tend1_cb; typedef void (z180_device::*opcode_func)(); static const opcode_func s_z180ops[6][0x100]; diff --git a/src/devices/machine/upd765.cpp b/src/devices/machine/upd765.cpp index 3c8f3add09e..0db88c35c6e 100644 --- a/src/devices/machine/upd765.cpp +++ b/src/devices/machine/upd765.cpp @@ -533,12 +533,17 @@ uint8_t upd765_family_device::fifo_r() { uint8_t r = 0xff; switch(main_phase) { + case PHASE_CMD: + if(command_pos) + fifo_w(0xff); + LOGFIFO("fifo_r in command phase\n"); + break; case PHASE_EXEC: if(machine().side_effects_disabled()) return fifo[0]; if(internal_drq) return fifo_pop(false); - LOGFIFO("fifo_r in phase %d\n", main_phase); + LOGFIFO("fifo_r in execution phase\n"); break; case PHASE_RESULT: @@ -594,7 +599,7 @@ void upd765_family_device::fifo_w(uint8_t data) fifo_push(data, false); return; } - LOGFIFO("fifo_w in phase %d\n", main_phase); + LOGFIFO("fifo_w in execution phase\n"); break; default: @@ -639,11 +644,10 @@ void upd765_family_device::enable_transfer() check_irq(); } - } else { - // DMA - if(!drq) - set_drq(true); } + // DMA + if(!drq) + set_drq(true); } void upd765_family_device::disable_transfer() @@ -651,8 +655,8 @@ void upd765_family_device::disable_transfer() if(spec & SPEC_ND) { internal_drq = false; check_irq(); - } else - set_drq(false); + } + set_drq(false); } void upd765_family_device::fifo_push(uint8_t data, bool internal) diff --git a/src/lib/formats/all.cpp b/src/lib/formats/all.cpp index a084c87afea..5dedacc1b3b 100644 --- a/src/lib/formats/all.cpp +++ b/src/lib/formats/all.cpp @@ -616,6 +616,10 @@ #include "tiki100_dsk.h" #endif +#ifdef HAS_FORMATS_TIM011_DSK +#include "tim011_dsk.h" +#endif + #ifdef HAS_FORMATS_TRD_DSK #include "trd_dsk.h" #endif @@ -1259,6 +1263,11 @@ void mame_formats_full_list(mame_formats_enumerator &en) en.add(FLOPPY_TIKI100_FORMAT); // tiki100_dsk.h #endif + en.category("TIM 011"); +#ifdef HAS_FORMATS_TIM011_DSK + en.add(FLOPPY_TIM011_FORMAT); // tim011_dsk.h +#endif + en.category("Videoton"); #ifdef HAS_FORMATS_TVC_CAS en.add(tvc64_cassette_formats); // tvc_cas.h diff --git a/src/lib/formats/tim011_dsk.cpp b/src/lib/formats/tim011_dsk.cpp new file mode 100644 index 00000000000..acf5ac17055 --- /dev/null +++ b/src/lib/formats/tim011_dsk.cpp @@ -0,0 +1,45 @@ +// license:BSD-3-Clause +// copyright-holders:Miodrag Milanovic +/********************************************************************* + + formats/tim011_dsk.cpp + + TIM 011 format + +*********************************************************************/ + +#include "formats/tim011_dsk.h" + +tim011_format::tim011_format() : upd765_format(formats) +{ +} + +const char *tim011_format::name() const +{ + return "tim011"; +} + +const char *tim011_format::description() const +{ + return "TIM 011 disk image"; +} + +const char *tim011_format::extensions() const +{ + return "img"; +} + +// Unverified gap sizes. +const tim011_format::format tim011_format::formats[] = { + { + floppy_image::FF_35, floppy_image::DSDD, floppy_image::MFM, + 2000, + 5, 80, 2, + 1024, {}, + 17, {}, + 80, 50, 22, 80 + }, + {} +}; + +const tim011_format FLOPPY_TIM011_FORMAT; diff --git a/src/lib/formats/tim011_dsk.h b/src/lib/formats/tim011_dsk.h new file mode 100644 index 00000000000..b15278baf9c --- /dev/null +++ b/src/lib/formats/tim011_dsk.h @@ -0,0 +1,32 @@ +// license:BSD-3-Clause +// copyright-holders:Miodrag Milanovic +/********************************************************************* + + formats/tim011_dsk.h + + TIM 011 format + +*********************************************************************/ +#ifndef MAME_FORMATS_TIM011_DSK_H +#define MAME_FORMATS_TIM011_DSK_H + +#pragma once + +#include "upd765_dsk.h" + +class tim011_format : public upd765_format +{ +public: + tim011_format(); + + virtual const char *name() const override; + virtual const char *description() const override; + virtual const char *extensions() const override; + +private: + static const format formats[]; +}; + +extern const tim011_format FLOPPY_TIM011_FORMAT; + +#endif // MAME_FORMATS_TIM011_DSK_H diff --git a/src/mame/drivers/tim011.cpp b/src/mame/drivers/tim011.cpp index ea1fe53d65a..66234dbea39 100644 --- a/src/mame/drivers/tim011.cpp +++ b/src/mame/drivers/tim011.cpp @@ -12,6 +12,7 @@ #include "cpu/z180/z180.h" #include "imagedev/floppy.h" #include "formats/imd_dsk.h" +#include "formats/tim011_dsk.h" #include "machine/upd765.h" #include "emupal.h" #include "screen.h" @@ -25,33 +26,30 @@ public: : driver_device(mconfig, type, tag) , m_maincpu(*this, "maincpu") , m_fdc(*this, FDC9266_TAG) - , m_floppy0(*this, FDC9266_TAG ":0:35dd") - , m_floppy1(*this, FDC9266_TAG ":1:35dd") - , m_floppy2(*this, FDC9266_TAG ":2:35dd") - , m_floppy3(*this, FDC9266_TAG ":3:35dd") + , m_floppy(*this, FDC9266_TAG ":%u", 0) + , m_vram(*this, "videoram") + , m_palette(*this, "palette") { } void tim011(machine_config &config); private: virtual void machine_reset() override; - virtual void video_start() override; uint32_t screen_update_tim011(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); void print_w(uint8_t data); void scroll_w(uint8_t data); - void fdc_dma_w(uint8_t data); uint8_t print_r(); uint8_t scroll_r(); - uint8_t m_scroll = 0; + uint8_t m_scroll; - required_device m_maincpu; + required_device m_maincpu; required_device m_fdc; - required_device m_floppy0; - required_device m_floppy1; - required_device m_floppy2; - required_device m_floppy3; + required_device_array m_floppy; + required_shared_ptr m_vram; + required_device m_palette; void tim011_io(address_map &map); void tim011_mem(address_map &map); + void tim011_palette(palette_device &palette) const; }; @@ -66,11 +64,11 @@ void tim011_state::tim011_io(address_map &map) { map.unmap_value_high(); map(0x0000, 0x007f).ram(); /* Z180 internal registers */ - map(0x0080, 0x009f).m(m_fdc, FUNC(upd765a_device::map)); - //map(0x00a0, 0x00a0).mirror(0x001f).w(FUNC(tim011_state::fdc_dma_w)); - //map(0x00c0, 0x00c1).mirror(0x000e).rw(FUNC(tim011_state::print_r), FUNC(tim011_state::print_w)); - //map(0x00d0, 0x00d0).mirror(0x000f).rw(FUNC(tim011_state::scroll_r), FUNC(tim011_state::scroll_w)); - map(0x8000, 0xffff).ram(); // Video RAM 43256 SRAM (32KB) + map(0x0080, 0x0081).mirror(0xff0e).m(m_fdc, FUNC(upd765a_device::map)); + map(0x00a0, 0x00a0).mirror(0xff0f).rw(m_fdc, FUNC(upd765a_device::dma_r), FUNC(upd765a_device::dma_w)); + map(0x00c0, 0x00c1).mirror(0xff0e).rw(FUNC(tim011_state::print_r), FUNC(tim011_state::print_w)); + map(0x00d0, 0x00d0).mirror(0xff0f).rw(FUNC(tim011_state::scroll_r), FUNC(tim011_state::scroll_w)); + map(0x8000, 0xffff).ram().share(m_vram); // Video RAM 43256 SRAM (32KB) } /* Input ports */ @@ -79,27 +77,32 @@ INPUT_PORTS_END void tim011_state::machine_reset() { + m_scroll = 0; // motor is actually connected on TXS pin of CPU - m_floppy0->mon_w(0); - m_floppy1->mon_w(0); - m_floppy2->mon_w(0); - m_floppy3->mon_w(0); -} - -void tim011_state::video_start() -{ + for (auto &drive : m_floppy) + { + if (drive->get_device()) + drive->get_device()->mon_w(0); + } } uint32_t tim011_state::screen_update_tim011(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect) { + for (int x = 0; x < 512/4; x++) + { + for (int y = cliprect.top(); y <= cliprect.bottom(); y++) + { + int horpos = x << 2; + u8 code = m_vram[(x << 8) + ((y + m_scroll) & 0xff)]; + bitmap.pix(y, horpos++) = (code >> 0) & 0x03; + bitmap.pix(y, horpos++) = (code >> 2) & 0x03; + bitmap.pix(y, horpos++) = (code >> 4) & 0x03; + bitmap.pix(y, horpos++) = (code >> 6) & 0x03; + } + } return 0; } -void tim011_state::fdc_dma_w(uint8_t data) -{ - printf("fdc_dma_w :%02x\n",data); -} - void tim011_state::print_w(uint8_t data) { //printf("print_w :%02x\n",data); @@ -130,6 +133,19 @@ static void tim011_floppy_formats(format_registration &fr) { fr.add_mfm_containers(); fr.add(FLOPPY_IMD_FORMAT); + fr.add(FLOPPY_TIM011_FORMAT); +} + +void tim011_state::tim011_palette(palette_device &palette) const +{ + static constexpr rgb_t tim011_pens[4] = { + { 0x00, 0x00, 0x00 }, // 0 + { 0x00, 0x55, 0x00 }, // 1 + { 0x00, 0xaa, 0x00 }, // 2 + { 0x00, 0xff, 0x00 }, // 3 + }; + + palette.set_pen_colors(0, tim011_pens); } void tim011_state::tim011(machine_config &config) @@ -138,37 +154,38 @@ void tim011_state::tim011(machine_config &config) HD64180RP(config, m_maincpu, XTAL(12'288'000)); // location U17 HD64180 m_maincpu->set_addrmap(AS_PROGRAM, &tim011_state::tim011_mem); m_maincpu->set_addrmap(AS_IO, &tim011_state::tim011_io); - m_maincpu->set_vblank_int("screen", FUNC(tim011_state::irq0_line_hold)); + m_maincpu->tend1_wr_callback().set(m_fdc, FUNC(upd765a_device::tc_line_w)); // CDP1802(config, "keyboard", XTAL(1'750'000)); // CDP1802, unknown clock // FDC9266 location U43 UPD765A(config, m_fdc, XTAL(8'000'000), true, true); m_fdc->intrq_wr_callback().set_inputline(m_maincpu, INPUT_LINE_IRQ2); + m_fdc->drq_wr_callback().set_inputline(m_maincpu, Z180_INPUT_LINE_DREQ1); /* floppy drives */ - FLOPPY_CONNECTOR(config, FDC9266_TAG ":0", tim011_floppies, "35dd", tim011_floppy_formats); - FLOPPY_CONNECTOR(config, FDC9266_TAG ":1", tim011_floppies, "35dd", tim011_floppy_formats); - FLOPPY_CONNECTOR(config, FDC9266_TAG ":2", tim011_floppies, "35dd", tim011_floppy_formats); - FLOPPY_CONNECTOR(config, FDC9266_TAG ":3", tim011_floppies, "35dd", tim011_floppy_formats); + FLOPPY_CONNECTOR(config, m_floppy[0], tim011_floppies, "35dd", tim011_floppy_formats); + FLOPPY_CONNECTOR(config, m_floppy[1], tim011_floppies, nullptr, tim011_floppy_formats); + FLOPPY_CONNECTOR(config, m_floppy[2], tim011_floppies, nullptr, tim011_floppy_formats); + FLOPPY_CONNECTOR(config, m_floppy[3], tim011_floppies, nullptr, tim011_floppy_formats); /* video hardware */ + PALETTE(config, m_palette, FUNC(tim011_state::tim011_palette), 4); + screen_device &screen(SCREEN(config, "screen", SCREEN_TYPE_RASTER)); screen.set_refresh_hz(50); screen.set_vblank_time(ATTOSECONDS_IN_USEC(2500)); /* not accurate */ screen.set_size(512, 256); screen.set_visarea(0, 512-1, 0, 256-1); screen.set_screen_update(FUNC(tim011_state::screen_update_tim011)); - screen.set_palette("palette"); - - PALETTE(config, "palette", palette_device::MONOCHROME); + screen.set_palette(m_palette); } /* ROM definition */ ROM_START( tim011 ) - ROM_REGION( 0x10000, "maincpu", ROMREGION_ERASEFF ) + ROM_REGION( 0x2000, "maincpu", ROMREGION_ERASEFF ) ROM_LOAD( "sys_tim011.u16", 0x0000, 0x2000, CRC(5b4f1300) SHA1(d324991c4292d7dcde8b8d183a57458be8a2be7b)) - ROM_REGION( 0x10000, "keyboard", ROMREGION_ERASEFF ) + ROM_REGION( 0x1000, "keyboard", ROMREGION_ERASEFF ) ROM_LOAD( "keyb_tim011.bin", 0x0000, 0x1000, CRC(a99c40a6) SHA1(d6d505271d91df4e079ec3c0a4abbe75ae9d649b)) ROM_END -- cgit v1.2.3