summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/bus/iq151/grafik.c
blob: b74caba9c945625dec28f5760855c1c410fd6ecd (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
// license:BSD-3-Clause
// copyright-holders:Sandro Ronco
/***************************************************************************

    IQ151 grafik emulation

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

#include "emu.h"
#include "grafik.h"

#define LOG 0

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

static I8255_INTERFACE( grafik_ppi8255_intf )
{
	DEVCB_NULL,
	DEVCB_DEVICE_MEMBER(DEVICE_SELF_OWNER, iq151_grafik_device, x_write),
	DEVCB_NULL,
	DEVCB_DEVICE_MEMBER(DEVICE_SELF_OWNER, iq151_grafik_device, y_write),
	DEVCB_NULL,
	DEVCB_DEVICE_MEMBER(DEVICE_SELF_OWNER, iq151_grafik_device, control_w),
};

static MACHINE_CONFIG_FRAGMENT( iq151_grafik )
	MCFG_I8255_ADD("ppi8255", grafik_ppi8255_intf)
MACHINE_CONFIG_END


//**************************************************************************
//  GLOBAL VARIABLES
//**************************************************************************

const device_type IQ151_GRAFIK = &device_creator<iq151_grafik_device>;

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

//-------------------------------------------------
//  iq151_grafik_device - constructor
//-------------------------------------------------

iq151_grafik_device::iq151_grafik_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
		: device_t(mconfig, IQ151_GRAFIK, "IQ151 grafik", tag, owner, clock, "iq151_grafik", __FILE__),
		device_iq151cart_interface( mconfig, *this ),
		m_ppi8255(*this, "ppi8255")
{
}

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

void iq151_grafik_device::device_start()
{
}

//-------------------------------------------------
//  device_reset - device-specific reset
//-------------------------------------------------

void iq151_grafik_device::device_reset()
{
	screen_device *screen = machine().first_screen();

	// if required adjust screen size
	if (screen->visible_area().max_x < 64*8-1)
		screen->set_visible_area(0, 64*8-1, 0, 32*8-1);

	memset(m_videoram, 0x00, sizeof(m_videoram));
}

//-------------------------------------------------
//  device_mconfig_additions
//-------------------------------------------------

machine_config_constructor iq151_grafik_device::device_mconfig_additions() const
{
	return MACHINE_CONFIG_NAME( iq151_grafik );
}

//-------------------------------------------------
//  I8255 port a
//-------------------------------------------------

WRITE8_MEMBER(iq151_grafik_device::x_write)
{
	if (LOG) logerror("Grafik: set posx 0x%02x\n", data);

	m_posx = data & 0x3f;
}

//-------------------------------------------------
//  I8255 port b
//-------------------------------------------------

WRITE8_MEMBER(iq151_grafik_device::y_write)
{
	if (LOG) logerror("Grafik: set posy 0x%02x\n", data);

	m_posy = data;
}

//-------------------------------------------------
//  I8255 port c
//-------------------------------------------------

WRITE8_MEMBER(iq151_grafik_device::control_w)
{
	if (LOG) logerror("Grafik: control write 0x%02x\n", data);

	m_all  = BIT(data, 0);
	m_pen  = BIT(data, 1);
	m_fast = BIT(data, 2);
	m_ev   = BIT(data, 3);
	m_ex   = (data>>4) & 0x03;
	m_sel  = BIT(data, 7);
}


//-------------------------------------------------
//  IO read
//-------------------------------------------------

void iq151_grafik_device::io_read(offs_t offset, UINT8 &data)
{
	if (offset >= 0xd0 && offset < 0xd4)
	{
		address_space& space = machine().device("maincpu")->memory().space(AS_IO);
		data = m_ppi8255->read(space, offset & 3);
	}
	else if (offset == 0xd4)
	{
		if (LOG) logerror("Grafik: vram read 0x%04x\n", m_posx + 0x40 * m_posy);

		if (m_sel)
			data = m_videoram[m_posx + 0x40 * m_posy];
	}
}

//-------------------------------------------------
//  IO write
//-------------------------------------------------

void iq151_grafik_device::io_write(offs_t offset, UINT8 data)
{
	if (offset >= 0xd0 && offset < 0xd4)
	{
		address_space& space = machine().device("maincpu")->memory().space(AS_IO);
		m_ppi8255->write(space, offset & 3, data);
	}
	else if (offset == 0xd4)
	{
		if (m_sel)
		{
			if (LOG) logerror("Grafik: vram write 0x%04x 0x%02x\n", m_posx + 0x40 * m_posy, data);

			if (m_all)
			{
				m_videoram[m_posx + 0x40 * m_posy] = data;
			}
			else
			{
				if (m_pen)
					m_videoram[m_posx + 0x40 * m_posy] &= ~(1 << (data >> 5));
				else
					m_videoram[m_posx + 0x40 * m_posy] |= (1 << (data >> 5));
			}
		}
	}
}


//-------------------------------------------------
//  video update
//-------------------------------------------------

void iq151_grafik_device::video_update(bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	if (m_ev)
	{
		for (int y = 0; y < 32*8; y++)
		{
			for (int x = 0; x < 64; x++)
			{
				for (int ra = 0; ra < 8; ra++)
				{
					bitmap.pix16(y, x*8 + ra) |= BIT(m_videoram[(32*8 -1 - y)*64 + x], ra);
				}
			}
		}
	}
}