1 // license:BSD-3-Clause
2 // copyright-holders:Miodrag Milanovic, Robbbert
3 /***************************************************************************
4 
5     Chaos2
6 
7     2010-04-08 Skeleton driver.
8     2012-05-19 Connected to a terminal, system is usable [Robbbert]
9 
10     This is a homebrew system: http://koo.corpus.cam.ac.uk/chaos/
11 
12     There are no schematics or manuals, so the results might not be
13     totally accurate.
14 
15     With the DOS config switch turned off, the only accepted input
16     is a line starting with '&'. The actual commands are unknown.
17 
18     With DOS enabled, a large number of commands become available.
19     These are:
20     access, ask, ascdis, bpclr, bpset, close, control, copy, devfive, dir,
21     end, exec, execute, fill, find, goto, if, input, let, list, load, lowercase,
22     memdis, memset, open, port, read, reboot, runhex, run, save, type, typesl,
23     verify.
24     An example is: memdis 0 8 (memory dump starting at 0, show 8 lines)
25     Don't try 'fill' - it fills all memory with zeroes, crashing the system.
26 
27     ToDo:
28     - Connect up floppy disk (WD1771 fdc, 5.25", single density,
29       no other info available)
30 
31 ****************************************************************************/
32 
33 #include "emu.h"
34 #include "cpu/s2650/s2650.h"
35 #include "machine/terminal.h"
36 
37 
38 class chaos_state : public driver_device
39 {
40 public:
chaos_state(const machine_config & mconfig,device_type type,const char * tag)41 	chaos_state(const machine_config &mconfig, device_type type, const char *tag)
42 		: driver_device(mconfig, type, tag)
43 		, m_terminal(*this, "terminal")
44 		, m_p_ram(*this, "ram")
45 		, m_maincpu(*this, "maincpu")
46 	{ }
47 
48 	void chaos(machine_config &config);
49 
50 private:
51 	u8 port1e_r();
52 	void port1f_w(u8 data);
53 	u8 port90_r();
54 	u8 port91_r();
55 	void kbd_put(u8 data);
56 	void data_map(address_map &map);
57 	void io_map(address_map &map);
58 	void mem_map(address_map &map);
59 	u8 m_term_data;
60 	void machine_reset() override;
61 	void machine_start() override;
62 	required_device<generic_terminal_device> m_terminal;
63 	required_shared_ptr<u8> m_p_ram;
64 	required_device<cpu_device> m_maincpu;
65 };
66 
67 
mem_map(address_map & map)68 void chaos_state::mem_map(address_map &map)
69 {
70 	map.unmap_value_high();
71 	map(0x0000, 0x7fff).ram().share("ram");
72 }
73 
io_map(address_map & map)74 void chaos_state::io_map(address_map &map)
75 {
76 	map.unmap_value_high();
77 	map(0x1e, 0x1e).r(FUNC(chaos_state::port1e_r));
78 	map(0x1f, 0x1f).rw(FUNC(chaos_state::port90_r), FUNC(chaos_state::port1f_w));
79 	map(0x90, 0x90).r(FUNC(chaos_state::port90_r));
80 	map(0x91, 0x91).r(FUNC(chaos_state::port91_r));
81 	map(0x92, 0x92).w(m_terminal, FUNC(generic_terminal_device::write));
82 }
83 
data_map(address_map & map)84 void chaos_state::data_map(address_map &map)
85 {
86 	map(S2650_DATA_PORT, S2650_DATA_PORT).noprw(); // stops error log filling up while using debug
87 }
88 
89 /* Input ports */
90 static INPUT_PORTS_START( chaos )
91 	PORT_START("CONFIG")
92 	PORT_CONFNAME( 0x01, 0x00, "Enable DOS")
DEF_STR(No)93 	PORT_CONFSETTING(    0x01, DEF_STR(No))
94 	PORT_CONFSETTING(    0x00, DEF_STR(Yes))
95 INPUT_PORTS_END
96 
97 
98 // Port 1E - Bit 0 indicates key pressed, Bit 1 indicates ok to output
99 
100 u8 chaos_state::port1e_r()
101 {
102 	return (m_term_data) ? 1 : 0;
103 }
104 
port1f_w(u8 data)105 void chaos_state::port1f_w(u8 data)
106 {
107 	// make the output readable on our terminal
108 	if (data == 0x09)
109 		return;
110 	else
111 	if (!data)
112 		data = 0x24;
113 
114 	m_terminal->write(data);
115 
116 	if (data == 0x0d)
117 		m_terminal->write(0x0a);
118 }
119 
port90_r()120 u8 chaos_state::port90_r()
121 {
122 	u8 ret = m_term_data;
123 	m_term_data = 0;
124 	return ret;
125 }
126 
127 // Status port
128 // Bit 0 = L use ports 1E & 1F; H use ports 90 & 92
129 // Bit 3 = key pressed
130 // Bit 7 = ok to output
131 
port91_r()132 u8 chaos_state::port91_r()
133 {
134 	u8 ret = 0x80 | ioport("CONFIG")->read();
135 	ret |= (m_term_data) ? 8 : 0;
136 	return ret;
137 }
138 
kbd_put(u8 data)139 void chaos_state::kbd_put(u8 data)
140 {
141 	m_term_data = data;
142 }
143 
machine_start()144 void chaos_state::machine_start()
145 {
146 	save_item(NAME(m_term_data));
147 }
148 
machine_reset()149 void chaos_state::machine_reset()
150 {
151 	// copy the roms into ram
152 	u8* ROM = memregion("roms")->base();
153 	memcpy(m_p_ram, ROM, 0x3000);
154 	memcpy(m_p_ram+0x7000, ROM+0x3000, 0x1000);
155 }
156 
chaos(machine_config & config)157 void chaos_state::chaos(machine_config &config)
158 {
159 	/* basic machine hardware */
160 	S2650(config, m_maincpu, XTAL(1'000'000));
161 	m_maincpu->set_addrmap(AS_PROGRAM, &chaos_state::mem_map);
162 	m_maincpu->set_addrmap(AS_IO, &chaos_state::io_map);
163 	m_maincpu->set_addrmap(AS_DATA, &chaos_state::data_map);
164 
165 	/* video hardware */
166 	GENERIC_TERMINAL(config, m_terminal, 0);
167 	m_terminal->set_keyboard_callback(FUNC(chaos_state::kbd_put));
168 }
169 
170 /* ROM definition */
171 ROM_START( chaos )
172 	ROM_REGION( 0x4000, "roms", 0 )
173 	ROM_LOAD( "chaos.001", 0x0000, 0x1000, CRC(3b433e72) SHA1(5b487337d71253d0e64e123f405da9eaf20e87ac))
174 	ROM_LOAD( "chaos.002", 0x1000, 0x1000, CRC(8b0b487f) SHA1(0d167cf3004a81c87446f2f1464e3debfa7284fe))
175 	ROM_LOAD( "chaos.003", 0x2000, 0x1000, CRC(5880db81) SHA1(29b8f1b03c83953f66464ad1fbbfe2e019637ce1))
176 	ROM_LOAD( "chaos.004", 0x3000, 0x1000, CRC(5d6839d6) SHA1(237f52f0780ac2e29d57bf06d0f7a982eb523084))
177 ROM_END
178 
179 /* Driver */
180 
181 //    YEAR  NAME   PARENT  COMPAT  MACHINE  INPUT  CLASS        INIT        COMPANY          FULLNAME   FLAGS
182 COMP( 1983, chaos, 0,      0,      chaos,   chaos, chaos_state, empty_init, "David Greaves", "Chaos 2", MACHINE_NO_SOUND_HW | MACHINE_SUPPORTS_SAVE )
183