summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/svi3x8/slot/sv806.cpp
blob: 5a7d858d38b5c7730f2a4105b3a24f9f497a9301 (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
// license:GPL-2.0+
// copyright-holders:Dirk Best
/***************************************************************************

    SV-806 80 Column Cartridge for SVI-318/328

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

#include "emu.h"
#include "sv806.h"

#include "screen.h"


//**************************************************************************
//  DEVICE DEFINITIONS
//**************************************************************************

DEFINE_DEVICE_TYPE(SV806, sv806_device, "sv806", "SV-806 80 Column Cartridge")

//-------------------------------------------------
//  rom_region - device-specific ROM region
//-------------------------------------------------

ROM_START( sv806 )
	ROM_REGION(0x1000, "gfx", 0)
	ROM_SYSTEM_BIOS(0, "en", "English Character Set")
	ROMX_LOAD("sv806.ic27",   0x0000, 0x1000, CRC(850bc232) SHA1(ed45cb0e9bd18a9d7bd74f87e620f016a7ae840f), ROM_BIOS(0))
	ROM_SYSTEM_BIOS(1, "se", "Swedish Character Set")
	ROMX_LOAD("sv806se.ic27", 0x0000, 0x1000, CRC(daea8956) SHA1(3f16d5513ad35692488ae7d864f660e76c6e8ed3), ROM_BIOS(1))
ROM_END

const tiny_rom_entry *sv806_device::device_rom_region() const
{
	return ROM_NAME( sv806 );
}

//-------------------------------------------------
//  device_add_mconfig - add device configuration
//-------------------------------------------------

void sv806_device::device_add_mconfig(machine_config &config)
{
	screen_device &screen(SCREEN(config, "80col", SCREEN_TYPE_RASTER));
	screen.set_color(rgb_t::green());
	screen.set_raw((XTAL(12'000'000) / 6) * 8, 864, 0, 640, 317, 0, 192);
	screen.set_screen_update("crtc", FUNC(hd6845s_device::screen_update));

	PALETTE(config, m_palette, palette_device::MONOCHROME);

	HD6845S(config, m_crtc, XTAL(12'000'000) / 6); // HD6845 (variant not verified)
	m_crtc->set_screen("80col");
	m_crtc->set_show_border_area(false);
	m_crtc->set_char_width(8);
	m_crtc->set_update_row_callback(FUNC(sv806_device::crtc_update_row));
}


//**************************************************************************
//  LIVE DEVICE
//**************************************************************************

//-------------------------------------------------
//  sv806_device - constructor
//-------------------------------------------------

sv806_device::sv806_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
	device_t(mconfig, SV806, tag, owner, clock),
	device_svi_slot_interface(mconfig, *this),
	m_crtc(*this, "crtc"),
	m_palette(*this, "palette"),
	m_gfx(*this, "gfx"),
	m_ram_enabled(0)
{
	m_ram = std::make_unique<uint8_t[]>(0x800);
	memset(m_ram.get(), 0xff, 0x800);
}

//-------------------------------------------------
//  device_start - device-specific startup
//-------------------------------------------------

void sv806_device::device_start()
{
	// register for savestates
	save_item(NAME(m_ram_enabled));
	save_pointer(NAME(m_ram), 0x800);
}


//**************************************************************************
//  IMPLEMENTATION
//**************************************************************************

MC6845_UPDATE_ROW( sv806_device::crtc_update_row )
{
	pen_t const *const pen = m_palette->pens();

	for (int i = 0; i < x_count; i++)
	{
		uint8_t data = m_gfx->as_u8((m_ram[(ma + i) & 0x7ff] << 4) | ra);

		if (i == cursor_x)
			data = 0xff;

		bitmap.pix(y, i * 8 + 0) = pen[BIT(data, 7)];
		bitmap.pix(y, i * 8 + 1) = pen[BIT(data, 6)];
		bitmap.pix(y, i * 8 + 2) = pen[BIT(data, 5)];
		bitmap.pix(y, i * 8 + 3) = pen[BIT(data, 4)];
		bitmap.pix(y, i * 8 + 4) = pen[BIT(data, 3)];
		bitmap.pix(y, i * 8 + 5) = pen[BIT(data, 2)];
		bitmap.pix(y, i * 8 + 6) = pen[BIT(data, 1)];
		bitmap.pix(y, i * 8 + 7) = pen[BIT(data, 0)];
	}
}

uint8_t sv806_device::mreq_r(offs_t offset)
{
	if (offset >= 0xf000 && m_ram_enabled)
	{
		m_bus->ramdis_w(0);
		return m_ram[offset & 0x7ff];
	}

	return 0xff;
}

void sv806_device::mreq_w(offs_t offset, uint8_t data)
{
	if (offset >= 0xf000 && m_ram_enabled)
	{
		m_bus->ramdis_w(0);
		m_ram[offset & 0x7ff] = data;
	}
}

uint8_t sv806_device::iorq_r(offs_t offset)
{
	if (offset == 0x51)
		return m_crtc->register_r();

	return 0xff;
}

void sv806_device::iorq_w(offs_t offset, uint8_t data)
{
	switch (offset)
	{
	case 0x50: m_crtc->address_w(data); break;
	case 0x51: m_crtc->register_w(data); break;
	case 0x58: m_ram_enabled = data; break;
	}
}