1 // license:BSD-3-Clause
2 // copyright-holders:Sergey Svishchev
3 #include "emu.h"
4 #include "ibm6580_fdc.h"
5 
6 
7 //#define LOG_GENERAL (1U <<  0) //defined in logmacro.h already
8 #define LOG_DEBUG     (1U <<  1)
9 
10 //#define VERBOSE (LOG_GENERAL | LOG_DEBUG)
11 //#define LOG_OUTPUT_FUNC printf
12 #include "logmacro.h"
13 
14 #define LOGDBG(...) LOGMASKED(LOG_DEBUG, __VA_ARGS__)
15 
16 
17 DEFINE_DEVICE_TYPE(DW_FDC, dw_fdc_device, "dw_fdc", "IBM Displaywriter Floppy")
18 
ROM_START(dw_fdc)19 ROM_START( dw_fdc )
20 	ROM_REGION(0x800, "mcu", 0)
21 	ROM_LOAD("4430030_flp_8041.bin", 0x0000, 0x400, CRC(2bb96799) SHA1(e30b0f2d790197f290858eab74ad5e151ded78c3))
22 ROM_END
23 
24 
25 const tiny_rom_entry *dw_fdc_device::device_rom_region() const
26 {
27 	return ROM_NAME( dw_fdc );
28 }
29 
device_add_mconfig(machine_config & config)30 void dw_fdc_device::device_add_mconfig(machine_config &config)
31 {
32 	I8048(config, m_mcu, 24_MHz_XTAL / 4);    // divisor is unverified
33 //  m_mcu->bus_in_cb().set(FUNC(dw_fdc_device::bus_r));
34 //  m_mcu->bus_out_cb().set(FUNC(dw_fdc_device::bus_w));
35 	m_mcu->p1_out_cb().set(FUNC(dw_fdc_device::p1_w));
36 	m_mcu->p2_out_cb().set(FUNC(dw_fdc_device::p2_w));
37 //  m_mcu->t0_in_cb().set(FUNC(dw_fdc_device::t0_r));
38 	m_mcu->t1_in_cb().set(FUNC(dw_fdc_device::t1_r));
39 
40 	I8255(config, "ppi8255", 0);
41 
42 	UPD765A(config, "upd765", 24_MHz_XTAL / 3, false, false);
43 //  m_upd_fdc->intrq_wr_callback().set("pic8259", FUNC(pic8259_device::ir4_w));
44 //  m_upd_fdc->drq_wr_callback().set("dma8257", FUNC(dma8257_device::XXX));
45 //  FLOPPY_CONNECTOR(config, UPD765_TAG ":0", wangpc_floppies, "525dd", wangpc_state::floppy_formats);
46 //  FLOPPY_CONNECTOR(config, UPD765_TAG ":1", wangpc_floppies, "525dd", wangpc_state::floppy_formats);
47 }
48 
49 
dw_fdc_device(const machine_config & mconfig,const char * tag,device_t * owner,uint32_t clock)50 dw_fdc_device::dw_fdc_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
51 	: device_t(mconfig, DW_FDC, tag, owner, clock)
52 	, m_out_data(*this)
53 	, m_out_clock(*this)
54 	, m_out_strobe(*this)
55 	, m_mcu(*this, "mcu")
56 {
57 }
58 
device_start()59 void dw_fdc_device::device_start()
60 {
61 	m_out_data.resolve_safe();
62 	m_out_clock.resolve_safe();
63 	m_out_strobe.resolve_safe();
64 	m_reset_timer = timer_alloc();
65 }
66 
device_reset()67 void dw_fdc_device::device_reset()
68 {
69 	m_p1 = m_p2 = m_t0 = m_t1 = 0;
70 }
71 
device_timer(emu_timer & timer,device_timer_id id,int param,void * ptr)72 void dw_fdc_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
73 {
74 	m_mcu->set_input_line(INPUT_LINE_RESET, ASSERT_LINE);
75 }
76 
p1_w(uint8_t data)77 void dw_fdc_device::p1_w(uint8_t data)
78 {
79 	m_p1 = data;
80 
81 	LOGDBG("p1 <- %02x\n", data, m_p1);
82 }
83 
p2_w(uint8_t data)84 void dw_fdc_device::p2_w(uint8_t data)
85 {
86 	m_p2 = data;
87 
88 	LOGDBG("p2 <- %02x\n", data);
89 }
90 
p2_r()91 uint8_t dw_fdc_device::p2_r()
92 {
93 	uint8_t data = m_p2;
94 
95 	LOGDBG("p2 == %02x\n", data);
96 
97 	return data;
98 }
99 
READ_LINE_MEMBER(dw_fdc_device::t0_r)100 READ_LINE_MEMBER( dw_fdc_device::t0_r )
101 {
102 	LOGDBG("t0 == %d\n", m_t0);
103 
104 	return m_t0;
105 }
106 
READ_LINE_MEMBER(dw_fdc_device::t1_r)107 READ_LINE_MEMBER( dw_fdc_device::t1_r )
108 {
109 	LOGDBG("t1 == %d\n", m_t1);
110 
111 	return m_t1;
112 }
113 
bus_w(uint8_t data)114 void dw_fdc_device::bus_w(uint8_t data)
115 {
116 	m_bus = data;
117 }
118 
bus_r()119 uint8_t dw_fdc_device::bus_r()
120 {
121 	return m_bus;
122 }
123 
WRITE_LINE_MEMBER(dw_fdc_device::reset_w)124 WRITE_LINE_MEMBER( dw_fdc_device::reset_w )
125 {
126 	if(!state)
127 		m_reset_timer->adjust(attotime::from_msec(50));
128 	else
129 	{
130 		m_reset_timer->adjust(attotime::never);
131 		m_mcu->set_input_line(INPUT_LINE_RESET, CLEAR_LINE);
132 	}
133 }
134 
WRITE_LINE_MEMBER(dw_fdc_device::ack_w)135 WRITE_LINE_MEMBER( dw_fdc_device::ack_w )
136 {
137 	m_t0 = state;
138 }
139