summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/bbc/userport/lcd.cpp
blob: b693b28957ec0af12e3fe6c7b418971ea54059d8 (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
// license:BSD-3-Clause
// copyright-holders:Nigel Barnes
/**********************************************************************

    Sprow LCD Display

    http://www.sprow.co.uk/bbc/buildit.htm#Lcddisplay

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


#include "emu.h"
#include "lcd.h"
#include "screen.h"


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

DEFINE_DEVICE_TYPE(BBC_LCD, bbc_lcd_device, "bbc_lcd", "Sprow LCD Display")


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

void bbc_lcd_device::device_add_mconfig(machine_config &config)
{
	auto &screen = SCREEN(config, "screen", SCREEN_TYPE_LCD);
	screen.set_refresh_hz(50);
	screen.set_vblank_time(ATTOSECONDS_IN_USEC(2500));
	screen.set_size(120, 36);
	screen.set_visarea_full();
	screen.set_screen_update(m_lcdc, FUNC(hd44780_device::screen_update));
	screen.set_palette("palette");

	PALETTE(config, "palette", FUNC(bbc_lcd_device::lcd_palette), 3);

	HD44780(config, m_lcdc);
	m_lcdc->set_lcd_size(4, 20);
	m_lcdc->set_pixel_update_cb(FUNC(bbc_lcd_device::lcd_pixel_update));
}


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

//-------------------------------------------------
//  bbc_lcd_device - constructor
//-------------------------------------------------

bbc_lcd_device::bbc_lcd_device(const machine_config &mconfig, const char *tag, device_t *owner, const XTAL &clock)
	: device_t(mconfig, BBC_LCD, tag, owner, clock)
	, device_bbc_userport_interface(mconfig, *this)
	, m_lcdc(*this, "lcdc")
{
}


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

void bbc_lcd_device::device_start()
{
}


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

HD44780_PIXEL_UPDATE(bbc_lcd_device::lcd_pixel_update)
{
	// char size is 5x8
	if (x > 4 || y > 7)
		return;

	if (pos < 40)
	{
		if (pos >= 20)
		{
			line += 2;
			pos -= 20;
		}

		if (line < 4)
			bitmap.pix(line * (8 + 1) + y, pos * 6 + x) = state ? 1 : 2;
	}
}

void bbc_lcd_device::lcd_palette(palette_device &palette) const
{
	palette.set_pen_color(0, rgb_t(138, 146, 148)); // background
	palette.set_pen_color(1, rgb_t( 92,  83,  88)); // lcd pixel on
	palette.set_pen_color(2, rgb_t(131, 136, 139)); // lcd pixel off
}

uint8_t bbc_lcd_device::pb_r()
{
	return m_lcdc->db_r() >> 1;
}

void bbc_lcd_device::pb_w(uint8_t data)
{
	m_lcdc->rs_w(BIT(data, 0));
	m_lcdc->rw_w(BIT(data, 1));
	m_lcdc->e_w(BIT(data, 2));
	m_lcdc->db_w(data << 1);
}