Previous 15994 Revisions Next

r12788 Sunday 4th September, 2011 at 08:44:23 UTC by Sandro Ronco
[KC] Added emulation of D004 Floppy Disk Interface. [Sandro Ronco]
[src/mess]mess.mak mess_dev.lst
[src/mess/drivers]kc.c
[src/mess/includes]kc.h
[src/mess/machine]kc_d002.c kc_d002.h kc_d004.c* kc_d004.h*

src/mess/machine/kc_d002.c
r12787r12788
5252
5353static SLOT_INTERFACE_START(kc_d002_exp)
5454   SLOT_INTERFACE("d002", KC_D002)         // D002 Bus Driver
55   SLOT_INTERFACE("d004", KC_D004)         // D004 Floppy Disk Interface
5556SLOT_INTERFACE_END
5657
5758WRITE_LINE_MEMBER(kc_d002_device::out_irq_w)
src/mess/machine/kc_d002.h
r12787r12788
77#include "machine/kcexp.h"
88#include "machine/kc_ram.h"
99#include "machine/kc_rom.h"
10#include "machine/kc_d002.h"
10#include "machine/kc_d004.h"
1111
1212//**************************************************************************
1313//  TYPE DEFINITIONS
src/mess/machine/kc_d004.c
r0r12788
1/***************************************************************************
2
3    kc_d004.c
4
5    KC85 D004 Floppy Disk Interface
6
7***************************************************************************/
8#define ADDRESS_MAP_MODERN
9
10#include "emu.h"
11#include "kc_d004.h"
12
13#define Z80_TAG         "disk"
14#define Z80CTC_TAG      "z80ctc"
15#define UPD765_TAG      "upd765"
16
17/***************************************************************************
18    IMPLEMENTATION
19***************************************************************************/
20
21static ADDRESS_MAP_START(kc_d004_mem, AS_PROGRAM, 8, kc_d004_device)
22   AM_RANGE(0x0000, 0xffff) AM_RAM      // 64kb RAM
23ADDRESS_MAP_END
24
25static ADDRESS_MAP_START(kc_d004_io, AS_IO, 8, kc_d004_device)
26   ADDRESS_MAP_UNMAP_HIGH
27   ADDRESS_MAP_GLOBAL_MASK(0xff)
28   AM_RANGE(0xf0, 0xf0) AM_DEVREAD_LEGACY(UPD765_TAG, upd765_status_r)
29   AM_RANGE(0xf1, 0xf1) AM_DEVREADWRITE_LEGACY(UPD765_TAG, upd765_data_r, upd765_data_w)
30   AM_RANGE(0xf2, 0xf3) AM_DEVREADWRITE_LEGACY(UPD765_TAG, upd765_dack_r, upd765_dack_w)
31   AM_RANGE(0xf4, 0xf4) AM_READ(hw_input_gate_r)
32   AM_RANGE(0xf6, 0xf7) AM_WRITE(fdd_select_w)
33   AM_RANGE(0xf8, 0xf9) AM_WRITE(hw_terminal_count_w)
34   AM_RANGE(0xfc, 0xff) AM_DEVREADWRITE_LEGACY(Z80CTC_TAG, z80ctc_r, z80ctc_w)
35ADDRESS_MAP_END
36
37static LEGACY_FLOPPY_OPTIONS_START(kc_d004)
38   LEGACY_FLOPPY_OPTION(kc85, "img", "KC85 disk image 800KB", basicdsk_identify_default, basicdsk_construct_default, NULL,
39      HEADS([2])
40      TRACKS([80])
41      SECTORS([5])
42      SECTOR_LENGTH([1024])
43      FIRST_SECTOR_ID([1]))
44   LEGACY_FLOPPY_OPTION(kc85, "img", "KC85 disk image 720KB", basicdsk_identify_default, basicdsk_construct_default, NULL,
45      HEADS([2])
46      TRACKS([80])
47      SECTORS([9])
48      SECTOR_LENGTH([512])
49      FIRST_SECTOR_ID([1]))
50   LEGACY_FLOPPY_OPTION(kc85, "img", "KC85 disk image 640KB", basicdsk_identify_default, basicdsk_construct_default, NULL,
51      HEADS([2])
52      TRACKS([80])
53      SECTORS([16])
54      SECTOR_LENGTH([256])
55      FIRST_SECTOR_ID([1]))
56LEGACY_FLOPPY_OPTIONS_END
57
58static const floppy_interface kc_d004_floppy_interface =
59{
60   DEVCB_NULL,
61   DEVCB_NULL,
62   DEVCB_NULL,
63   DEVCB_NULL,
64   DEVCB_NULL,
65   FLOPPY_STANDARD_5_25_DSHD,
66   LEGACY_FLOPPY_OPTIONS_NAME(kc_d004),
67   NULL,
68   NULL
69};
70
71static device_t *kc_d004_get_fdd(device_t *device, int floppy_index)
72{
73   kc_d004_device* owner = dynamic_cast<kc_d004_device *>(device->owner());
74   return owner->get_active_fdd();
75}
76
77static const upd765_interface kc_d004_interface =
78{
79   DEVCB_DEVICE_LINE_MEMBER(DEVICE_SELF_OWNER, kc_d004_device, fdc_interrupt),
80   DEVCB_DEVICE_LINE_MEMBER(DEVICE_SELF_OWNER, kc_d004_device, fdc_dma_request),
81   kc_d004_get_fdd,
82   UPD765_RDY_PIN_NOT_CONNECTED,
83   {FLOPPY_0, FLOPPY_1, FLOPPY_2, FLOPPY_3}
84};
85
86static const z80_daisy_config kc_d004_daisy_chain[] =
87{
88   { Z80CTC_TAG },
89   { NULL }
90};
91
92static Z80CTC_INTERFACE( kc_d004_ctc_intf )
93{
94   0,                                    /* timer disablers */
95   DEVCB_CPU_INPUT_LINE(Z80_TAG, 0),            /* interrupt callback */
96   DEVCB_DEVICE_LINE(Z80CTC_TAG, z80ctc_trg1_w),   /* ZC/TO0 callback */
97   DEVCB_DEVICE_LINE(Z80CTC_TAG, z80ctc_trg2_w),   /* ZC/TO1 callback */
98   DEVCB_DEVICE_LINE(Z80CTC_TAG, z80ctc_trg3_w)   /* ZC/TO2 callback */
99};
100
101static MACHINE_CONFIG_FRAGMENT(kc_d004)
102   MCFG_CPU_ADD(Z80_TAG, Z80, XTAL_8MHz/2)
103   MCFG_CPU_PROGRAM_MAP(kc_d004_mem)
104   MCFG_CPU_IO_MAP(kc_d004_io)
105   MCFG_CPU_CONFIG(kc_d004_daisy_chain)
106
107   MCFG_Z80CTC_ADD( Z80CTC_TAG, XTAL_8MHz/2, kc_d004_ctc_intf )
108
109   MCFG_UPD765A_ADD(UPD765_TAG, kc_d004_interface)
110   MCFG_LEGACY_FLOPPY_4_DRIVES_ADD(kc_d004_floppy_interface)
111MACHINE_CONFIG_END
112
113ROM_START( kc_d004 )
114   ROM_REGION(0x2000, Z80_TAG, 0)
115   ROM_LOAD_OPTIONAL(   "d004v20.bin",   0x0000, 0x2000, CRC(4f3494f1) SHA1(66f476de78fb474d9ac61c6eaffce3354fd66776))
116ROM_END
117
118//**************************************************************************
119//  GLOBAL VARIABLES
120//**************************************************************************
121
122const device_type KC_D004 = &device_creator<kc_d004_device>;
123
124//**************************************************************************
125//  LIVE DEVICE
126//**************************************************************************
127
128//-------------------------------------------------
129//  kc_d004_device - constructor
130//-------------------------------------------------
131
132kc_d004_device::kc_d004_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
133      : device_t(mconfig, KC_D004, "D004", tag, owner, clock),
134      device_kcexp_interface( mconfig, *this ),
135      device_slot_card_interface(mconfig, *this),
136      m_cpu(*this, Z80_TAG),
137      m_fdc(*this, UPD765_TAG)
138{
139}
140
141//-------------------------------------------------
142//  device_start - device-specific startup
143//-------------------------------------------------
144
145void kc_d004_device::device_start()
146{
147   m_rom  = subregion(Z80_TAG)->base();
148
149   m_reset_timer = timer_alloc(TIMER_RESET);
150   m_tc_clear_timer = timer_alloc(TIMER_TC_CLEAR);
151}
152
153//-------------------------------------------------
154//  device_reset - device-specific reset
155//-------------------------------------------------
156
157void kc_d004_device::device_reset()
158{
159   m_rom_base = 0xc000;
160   m_enabled = m_connected = 0;
161   m_floppy = downcast<device_t *>(subdevice(FLOPPY_0));
162
163   // hold cpu at reset
164   m_reset_timer->adjust(attotime::zero);
165}
166
167//-------------------------------------------------
168//  device_mconfig_additions
169//-------------------------------------------------
170
171machine_config_constructor kc_d004_device::device_mconfig_additions() const
172{
173   return MACHINE_CONFIG_NAME( kc_d004 );
174}
175
176//-------------------------------------------------
177//  device_rom_region
178//-------------------------------------------------
179
180const rom_entry *kc_d004_device::device_rom_region() const
181{
182   return ROM_NAME( kc_d004 );
183}
184
185//-------------------------------------------------
186//  device_timer - handler timer events
187//-------------------------------------------------
188
189void kc_d004_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
190{
191   switch(id)
192   {
193      case TIMER_RESET:
194         device_set_input_line(m_cpu, INPUT_LINE_RESET, ASSERT_LINE);
195         break;
196      case TIMER_TC_CLEAR:
197         upd765_tc_w(m_fdc, 0x00);
198         break;
199   }
200}
201
202/*-------------------------------------------------
203    set module status
204-------------------------------------------------*/
205
206void kc_d004_device::control_w(UINT8 data)
207{
208   m_enabled = BIT(data, 0);
209   m_connected = BIT(data, 2);
210   m_rom_base = (data & 0x20) ? 0xe000 : 0xc000;
211}
212
213/*-------------------------------------------------
214    read
215-------------------------------------------------*/
216
217void kc_d004_device::read(offs_t offset, UINT8 &data)
218{
219   if (offset >= m_rom_base && offset < (m_rom_base + 0x2000) && m_enabled)
220      data = m_rom[offset & 0x1fff];
221}
222
223//-------------------------------------------------
224//  IO read
225//-------------------------------------------------
226
227void kc_d004_device::io_read(offs_t offset, UINT8 &data)
228{
229   if ((offset & 0xff) == 0x80)
230   {
231      UINT8 slot_id = (offset>>8) & 0xff;
232
233      if (slot_id == 0xfc)
234         data = module_id_r();
235   }
236   else
237   {
238      if (m_connected)
239      {
240         switch(offset & 0xff)
241         {
242         case 0xf0:
243         case 0xf1:
244         case 0xf2:
245         case 0xf3:
246            data = m_cpu->memory().space(AS_PROGRAM)->read_byte(0xfc00 | ((offset & 0x03)<<8) | ((offset>>8) & 0xff));
247            break;
248         }
249      }
250   }
251}
252
253//-------------------------------------------------
254//  IO write
255//-------------------------------------------------
256
257void kc_d004_device::io_write(offs_t offset, UINT8 data)
258{
259   if ((offset & 0xff) == 0x80)
260   {
261      UINT8 slot_id = (offset>>8) & 0xff;
262
263      if (slot_id == 0xfc)
264         control_w(data);
265   }
266   else
267   {
268      if (m_connected)
269      {
270         switch(offset & 0xff)
271         {
272         case 0xf0:
273         case 0xf1:
274         case 0xf2:
275         case 0xf3:
276            m_cpu->memory().space(AS_PROGRAM)->write_byte(0xfc00 | ((offset & 0x03)<<8) | ((offset>>8) & 0xff), data);
277            break;
278         case 0xf4:
279            if (data & 0x01)
280               device_set_input_line(m_cpu, INPUT_LINE_RESET, CLEAR_LINE);
281
282            if (data & 0x02)
283            {
284               for (int i=0; i<0xfc00; i++)
285                  m_cpu->memory().space(AS_PROGRAM)->write_byte(i, 0);
286
287               device_set_input_line(m_cpu, INPUT_LINE_RESET, ASSERT_LINE);
288            }
289
290            if (data & 0x04)
291               device_set_input_line(m_cpu, INPUT_LINE_RESET, HOLD_LINE);
292
293            if (data & 0x08)
294               device_set_input_line(m_cpu, INPUT_LINE_NMI, HOLD_LINE);
295
296            //printf("D004 CPU state: %x\n", data & 0x0f);
297            break;
298         }
299      }
300   }
301}
302
303//**************************************************************************
304//  FDC emulation
305//**************************************************************************
306
307READ8_MEMBER(kc_d004_device::hw_input_gate_r)
308{
309   if (floppy_ready_r(m_floppy))
310      m_hw_input_gate |= 0x20;
311   else
312      m_hw_input_gate &= ~0x20;
313
314   if (floppy_index_r(m_floppy))
315      m_hw_input_gate &= ~0x10;
316   else
317      m_hw_input_gate |= 0x10;
318
319   return m_hw_input_gate | 0x0f;
320}
321
322WRITE8_MEMBER(kc_d004_device::fdd_select_w)
323{
324   if (data & 0x01)
325      m_floppy = downcast<device_t *>(subdevice(FLOPPY_0));
326   else if (data & 0x02)
327      m_floppy = downcast<device_t *>(subdevice(FLOPPY_1));
328   else if (data & 0x04)
329      m_floppy = downcast<device_t *>(subdevice(FLOPPY_2));
330   else if (data & 0x08)
331      m_floppy = downcast<device_t *>(subdevice(FLOPPY_3));
332}
333
334WRITE8_MEMBER(kc_d004_device::hw_terminal_count_w)
335{
336   upd765_tc_w(m_fdc, 1);
337
338   m_tc_clear_timer->adjust(attotime::from_nsec(200));
339}
340
341WRITE_LINE_MEMBER( kc_d004_device::fdc_interrupt )
342{
343   if (state)
344      m_hw_input_gate &= ~0x40;
345   else
346      m_hw_input_gate |= 0x40;
347}
348
349WRITE_LINE_MEMBER( kc_d004_device::fdc_dma_request )
350{
351   if (state)
352      m_hw_input_gate &= ~0x80;
353   else
354      m_hw_input_gate |= 0x80;
355}
src/mess/machine/kc_d004.h
r0r12788
1#pragma once
2
3#ifndef __KC_D004_H__
4#define __KC_D004_H__
5
6#include "emu.h"
7#include "machine/kcexp.h"
8#include "machine/z80ctc.h"
9#include "cpu/z80/z80.h"
10#include "machine/upd765.h"
11#include "formats/basicdsk.h"
12#include "imagedev/flopdrv.h"
13
14
15//**************************************************************************
16//  TYPE DEFINITIONS
17//**************************************************************************
18
19// ======================> kc_d004_device
20
21class kc_d004_device :
22      public device_t,
23      public device_kcexp_interface,
24      public device_slot_card_interface
25{
26public:
27   // construction/destruction
28   kc_d004_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
29
30   // optional information overrides
31   virtual machine_config_constructor device_mconfig_additions() const;
32   virtual const rom_entry *device_rom_region() const;
33
34protected:
35   // device-level overrides
36   virtual void device_start();
37   virtual void device_reset();
38   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
39   virtual void device_config_complete() { m_shortname = "kc_d004"; }
40
41   // kcexp_interface overrides
42   virtual UINT8 module_id_r() { return 0xa7; }
43   virtual void control_w(UINT8 data);
44   virtual void read(offs_t offset, UINT8 &data);
45   virtual void io_read(offs_t offset, UINT8 &data);
46   virtual void io_write(offs_t offset, UINT8 data);
47
48public:
49   device_t* get_active_fdd() { return m_floppy; }
50   DECLARE_READ8_MEMBER(hw_input_gate_r);
51   DECLARE_WRITE8_MEMBER(fdd_select_w);
52   DECLARE_WRITE8_MEMBER(hw_terminal_count_w);
53   DECLARE_WRITE_LINE_MEMBER(fdc_interrupt);
54   DECLARE_WRITE_LINE_MEMBER(fdc_dma_request);
55
56private:
57   static const device_timer_id TIMER_RESET = 0;
58   static const device_timer_id TIMER_TC_CLEAR = 1;
59
60   required_device<cpu_device> m_cpu;
61   required_device<device_t>   m_fdc;
62
63   // internal state
64   emu_timer *         m_reset_timer;
65   emu_timer *         m_tc_clear_timer;
66
67   UINT8 *            m_rom;
68   UINT8            m_hw_input_gate;
69   UINT16            m_rom_base;
70   UINT8            m_enabled;
71   UINT8            m_connected;
72   UINT8            m_active_fdd;
73   device_t *         m_floppy;
74};
75
76
77// device type definition
78extern const device_type KC_D004;
79
80#endif  /* __KC_D004_H__ */
src/mess/includes/kc.h
r12787r12788
1616#include "machine/kc_ram.h"
1717#include "machine/kc_rom.h"
1818#include "machine/kc_d002.h"
19#include "machine/kc_d004.h"
1920
2021#define KC85_4_CLOCK 1750000
2122#define KC85_3_CLOCK 1750000
src/mess/mess_dev.lst
r12787r12788
116116CPC_DKSPEECH  // uses internal SP0256 ROM
117117CPC_MFACE2
118118C64_XL80
119KC_D004
119120
src/mess/mess.mak
r12787r12788
16741674   $(MESS_MACHINE)/kc_ram.o   \
16751675   $(MESS_MACHINE)/kc_rom.o   \
16761676   $(MESS_MACHINE)/kc_d002.o   \
1677   $(MESS_MACHINE)/kc_d004.o   \
16771678   $(MESS_DRIVERS)/lc80.o      \
16781679   $(MESS_DRIVERS)/mc80.o      \
16791680   $(MESS_VIDEO)/mc80.o      \
src/mess/drivers/kc.c
r12787r12788
265265
266266static SLOT_INTERFACE_START(kc85_exp)
267267   SLOT_INTERFACE("d002", KC_D002)         // D002 Bus Driver
268   SLOT_INTERFACE("d004", KC_D004)         // D004 Floppy Disk Interface
268269SLOT_INTERFACE_END
269270
270271

Previous 15994 Revisions Next


© 1998-2018 The MESS Team