summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/machine/b2m.cpp
blob: 74334bdada6f1fbb09282de68399ad2132b94566 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
// license:BSD-3-Clause
// copyright-holders:Miodrag Milanovic
/***************************************************************************

        Bashkiria-2M machine driver by Miodrag Milanovic

        28/03/2008 Preliminary driver.

****************************************************************************/


#include "emu.h"
#include "cpu/i8085/i8085.h"
#include "includes/b2m.h"

uint8_t b2m_state::keyboard_r(offs_t offset)
{
	uint8_t key = 0x00;
	if (offset < 0x100) {
		if ((offset & 0x01)!=0) { key |= ioport("LINE0")->read(); }
		if ((offset & 0x02)!=0) { key |= ioport("LINE1")->read(); }
		if ((offset & 0x04)!=0) { key |= ioport("LINE2")->read(); }
		if ((offset & 0x08)!=0) { key |= ioport("LINE3")->read(); }
		if ((offset & 0x10)!=0) { key |= ioport("LINE4")->read(); }
		if ((offset & 0x20)!=0) { key |= ioport("LINE5")->read(); }
		if ((offset & 0x40)!=0) { key |= ioport("LINE6")->read(); }
		if ((offset & 0x80)!=0) { key |= ioport("LINE7")->read(); }
	} else {
		if ((offset & 0x01)!=0) { key |= ioport("LINE8")->read(); }
		if ((offset & 0x02)!=0) { key |= ioport("LINE9")->read(); }
		if ((offset & 0x04)!=0) { key |= ioport("LINE10")->read(); }
	}
	return key;
}


void b2m_state::set_bank(int bank)
{
	uint8_t *rom;
	address_space &space = m_maincpu->space(AS_PROGRAM);
	uint8_t *ram = m_ram->pointer();

	space.install_ram(0x0000, 0xffff, ram);

	rom = memregion("maincpu")->base();
	switch(bank) {
	case 0 :
	case 1 :
		space.unmap_write(0xe000, 0xffff);
		space.install_rom(0xe000, 0xffff, rom);
		break;
	case 2 :
		space.unmap_write(0x2800, 0x2fff);
		space.install_read_handler(0x2800, 0x2fff, read8sm_delegate(*this, FUNC(b2m_state::keyboard_r)));
		space.install_ram(0x3000, 0x6fff, ram + 0x10000);
		space.unmap_write(0xe000, 0xffff);
		space.install_rom(0xe000, 0xffff, rom);
		break;
	case 3 :
		space.unmap_write(0x2800, 0x2fff);
		space.install_read_handler(0x2800, 0x2fff, read8sm_delegate(*this, FUNC(b2m_state::keyboard_r)));
		space.install_ram(0x3000, 0x6fff, ram + 0x14000);
		space.unmap_write(0xe000, 0xffff);
		space.install_rom(0xe000, 0xffff, rom);
		break;
	case 4 :
		space.install_read_handler(0x2800, 0x2fff, read8sm_delegate(*this, FUNC(b2m_state::keyboard_r)));
		space.install_ram(0x3000, 0x6fff, ram + 0x18000);
		space.unmap_write(0xe000, 0xffff);
		space.install_rom(0xe000, 0xffff, rom);
		break;
	case 5 :
		space.unmap_write(0x2800, 0x2fff);
		space.install_read_handler(0x2800, 0x2fff, read8sm_delegate(*this, FUNC(b2m_state::keyboard_r)));
		space.install_ram(0x3000, 0x6fff, ram + 0x1c000);
		space.unmap_write(0xe000, 0xffff);
		space.install_rom(0xe000, 0xffff, rom);
		break;
	case 6 :
		break;
	case 7 :
		space.unmap_write(0x0000, 0xffff);
		space.unmap_read(0x0000, 0xffff);

		space.install_rom(0x0000, 0x1fff, rom);
		space.install_rom(0x2800, 0x2fff, rom);
		space.install_rom(0x3000, 0x4fff, rom);
		space.install_rom(0x7000, 0x8fff, rom);
		space.install_rom(0xe000, 0xffff, rom);
		break;
	}
}


WRITE_LINE_MEMBER(b2m_state::pit_out1)
{
	m_speaker->level_w(state);
}

void b2m_state::ppi1_porta_w(uint8_t data)
{
	m_porta = data;
}

void b2m_state::ppi1_portb_w(uint8_t data)
{
	m_video_scroll = data;
}

void b2m_state::ppi1_portc_w(uint8_t data)
{
	m_portc = data;
	set_bank(m_portc & 7);
	m_video_page = BIT(m_portc, 7);
}

uint8_t b2m_state::ppi1_portb_r()
{
	return m_video_scroll;
}

WRITE_LINE_MEMBER( b2m_state::fdc_drq )
{
	/* Clears HALT state of CPU when data is ready to read */
	if (state)
		m_maincpu->set_input_line(INPUT_LINE_HALT, CLEAR_LINE);
}


void b2m_state::ppi2_portc_w(uint8_t data)
{
	uint8_t drive = BIT(~data, 1);
	uint8_t side  = BIT(~data, 0);

	floppy_image_device *floppy = nullptr;
	if (m_fd[drive].found())
		floppy = m_fd[drive]->get_device();

	if (floppy)
		floppy->mon_w(0);
	m_fdc->set_floppy(floppy);

	if (floppy)
		floppy->ss_w(side);

	/*
	    When bit 5 is set CPU is in HALT state and stay there until
	    DRQ is triggered from floppy side
	*/

	if ((data & 0xf0)==0x20) {
		m_maincpu->set_input_line(INPUT_LINE_HALT, ASSERT_LINE);
	}
}

uint8_t b2m_state::romdisk_porta_r()
{
	uint8_t *romdisk = memregion("maincpu")->base() + 0x2000;
	return romdisk[m_romdisk_msb*256+m_romdisk_lsb];
}

void b2m_state::romdisk_portb_w(uint8_t data)
{
	m_romdisk_lsb = data;
}

void b2m_state::romdisk_portc_w(uint8_t data)
{
	m_romdisk_msb = data & 0x7f;
}

void b2m_state::palette_w(offs_t offset, uint8_t data)
{
	uint8_t b = BIT(~data, 6, 2) * 0x55;
	uint8_t g = BIT(~data, 4, 2) * 0x55;
	uint8_t r = BIT(~data, 2, 2) * 0x55;

	uint8_t bw = BIT(~data, 0, 2) * 0x55;

	m_color[offset & 3] = data;

	if (ioport("MONITOR")->read()==1)
		m_palette->set_pen_color(offset, r, g, b);
	else
		m_palette->set_pen_color(offset, bw, bw, bw);
}

uint8_t b2m_state::palette_r(offs_t offset)
{
	return m_color[offset];
}

void b2m_state::localmachine_w(uint8_t data)
{
	m_localmachine = data;
}

uint8_t b2m_state::localmachine_r()
{
	return m_localmachine;
}

void b2m_state::postload()
{
	set_bank(m_portc & 7);
}

void b2m_state::machine_start()
{
	/* register for state saving */
	save_item(NAME(m_porta));
	save_item(NAME(m_video_scroll));
	save_item(NAME(m_portc));
	save_item(NAME(m_video_page));
	save_item(NAME(m_romdisk_lsb));
	save_item(NAME(m_romdisk_msb));
	save_pointer(NAME(m_color), 4);
	save_item(NAME(m_localmachine));
	save_item(NAME(m_vblank_state));

	machine().save().register_postload(save_prepost_delegate(FUNC(b2m_state::postload), this));
}

INTERRUPT_GEN_MEMBER(b2m_state::vblank_interrupt)
{
	m_vblank_state++;
	if (m_vblank_state>1) m_vblank_state=0;
	m_pic->ir0_w(m_vblank_state);
}

void b2m_state::machine_reset()
{
	m_vblank_state = 0;
	set_bank(7);
}

uint32_t b2m_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	u8 const *const ram = m_ram->pointer();

	for (int x = 0; x < 48; x++)
	{
		for (int y = 0; y < 256; y++)
		{
			u16 const t = x*256 + ((y + m_video_scroll) & 0xff);
			u8 code1, code2;
			if (m_video_page==0)
			{
				code1 = ram[0x11000 + t];
				code2 = ram[0x15000 + t];
			}
			else
			{
				code1 = ram[0x19000 + t];
				code2 = ram[0x1d000 + t];
			}
			for (int b = 7; b >= 0; b--)
			{
				u8 const col = (BIT(code2, b)<<1) + BIT(code1, b);
				bitmap.pix(y, x*8+b) =  col;
			}
		}
	}

	return 0;
}

void b2m_state::b2m_palette(palette_device &palette) const
{
	static constexpr rgb_t b2m_pens[4] = {
		{ 0x00, 0x00, 0x00 }, // 0
		{ 0x00, 0x00, 0x00 }, // 1
		{ 0x00, 0x00, 0x00 }, // 2
		{ 0x00, 0x00, 0x00 }, // 3
	};

	palette.set_pen_colors(0, b2m_pens);
}