1 // license:LGPL-2.1+
2 // copyright-holders:Michael Zapf
3 /****************************************************************************
4 
5     SNUG BwG Disk Controller
6     Based on WD1770
7     Double Density, Double-sided
8 
9     Michael Zapf, September 2010
10     February 2012: Rewritten as class
11 
12 *****************************************************************************/
13 
14 #ifndef MAME_BUS_TI99_PED_BWG_H
15 #define MAME_BUS_TI99_PED_BWG_H
16 
17 #pragma once
18 
19 #include "peribox.h"
20 #include "imagedev/floppy.h"
21 #include "machine/mm58274c.h"
22 #include "machine/wd_fdc.h"
23 #include "machine/ram.h"
24 #include "machine/74259.h"
25 #include "machine/74123.h"
26 
27 namespace bus { namespace ti99 { namespace peb {
28 
29 class snug_bwg_device : public device_t, public device_ti99_peribox_card_interface
30 {
31 public:
32 	snug_bwg_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
33 
34 	void readz(offs_t offset, uint8_t *value) override;
35 	void write(offs_t offset, uint8_t data) override;
36 	void setaddress_dbin(offs_t offset, int state) override;
37 
38 	void crureadz(offs_t offset, uint8_t *value) override;
39 	void cruwrite(offs_t offset, uint8_t data) override;
40 
41 protected:
42 	void device_start() override;
43 	void device_reset() override;
44 	void device_config_complete() override;
45 
46 	const tiny_rom_entry *device_rom_region() const override;
47 	virtual void device_add_mconfig(machine_config &config) override;
48 	ioport_constructor device_input_ports() const override;
49 
50 private:
51 	DECLARE_FLOPPY_FORMATS( floppy_formats );
52 
53 	DECLARE_WRITE_LINE_MEMBER( fdc_irq_w );
54 	DECLARE_WRITE_LINE_MEMBER( fdc_drq_w );
55 
56 	// Latch callbacks
57 	DECLARE_WRITE_LINE_MEMBER( den_w );
58 	DECLARE_WRITE_LINE_MEMBER( mop_w );
59 	DECLARE_WRITE_LINE_MEMBER( waiten_w );
60 	DECLARE_WRITE_LINE_MEMBER( hlt_w );
61 	DECLARE_WRITE_LINE_MEMBER( dsel1_w );
62 	DECLARE_WRITE_LINE_MEMBER( dsel2_w );
63 	DECLARE_WRITE_LINE_MEMBER( dsel3_w );
64 	DECLARE_WRITE_LINE_MEMBER( dsel4_w );
65 	DECLARE_WRITE_LINE_MEMBER( sidsel_w );
66 	DECLARE_WRITE_LINE_MEMBER( dden_w );
67 
68 	DECLARE_WRITE_LINE_MEMBER( motorona_w );
69 
70 	void select_drive(int n, int state);
71 
72 	// Debugger accessors
73 	void debug_read(offs_t offset, uint8_t* value);
74 	void debug_write(offs_t offset, uint8_t data);
75 
76 	// Wait state logic
77 	void operate_ready_line();
78 
79 	// Set the current floppy
80 	void set_drive();
81 
82 	// Holds the status of the DRQ and IRQ lines.
83 	int m_DRQ, m_IRQ;
84 
85 	// DIP switch state
86 	int m_dip1, m_dip2, m_dip34;
87 
88 	// Address in card area
89 	bool m_inDsrArea;
90 
91 	// WD selected
92 	bool m_WDsel, m_WDsel0;
93 
94 	// RTC selected
95 	bool m_RTCsel;
96 
97 	// last 1K area selected
98 	bool m_lastK;
99 
100 	// Data register +1 selected
101 	bool m_dataregLB;
102 
103 	// Signal motor_on. When true, makes all drives turning.
104 	int m_MOTOR_ON;
105 
106 	// Recent address
107 	int m_address;
108 
109 	// DSR ROM
110 	uint8_t*          m_dsrrom;
111 
112 	// Buffer RAM
113 	required_device<ram_device> m_buffer_ram;
114 
115 	// Link to the attached floppy drives
116 	floppy_image_device*    m_floppy[4];
117 
118 	// Currently selected floppy drive (1-4, 0=none)
119 	int m_sel_floppy;
120 
121 	// Link to the WD1773 controller on the board.
122 	required_device<wd1773_device>   m_wd1773;
123 
124 	// Link to the real-time clock on the board.
125 	required_device<mm58274c_device> m_clock;
126 
127 	// Latched CRU outputs
128 	required_device<hc259_device> m_crulatch0_7;
129 	required_device<hc259_device> m_crulatch8_15;
130 
131 	// Motor monoflop
132 	required_device<ttl74123_device> m_motormf;
133 };
134 
135 } } } // end namespace bus::ti99::peb
136 
137 DECLARE_DEVICE_TYPE_NS(TI99_BWG, bus::ti99::peb, snug_bwg_device)
138 
139 #endif // MAME_BUS_TI99_PED_BWG_H
140