Skip to content

Commit 80068b5

Browse files
committed
sapphire: add lcd screen
1 parent 2c479b2 commit 80068b5

File tree

1 file changed

+83
-13
lines changed

1 file changed

+83
-13
lines changed

src/mame/novag/sapphire.cpp

+83-13
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Novag Sapphire
1515

1616
#include "bus/rs232/rs232.h"
1717
#include "cpu/h8/h8325.h"
18+
#include "machine/nvram.h"
1819
#include "sound/dac.h"
1920
#include "video/pwm.h"
2021

@@ -34,11 +35,13 @@ class sapphire_state : public driver_device
3435
driver_device(mconfig, type, tag),
3536
m_maincpu(*this, "maincpu"),
3637
m_memory(*this, "memory"),
37-
m_banked_ram(*this, "banked_ram", 0x20000, ENDIANNESS_BIG),
38+
m_nvram(*this, "nvram", 0x20000, ENDIANNESS_BIG),
3839
m_rambank(*this, "rambank"),
40+
m_lcd_pwm(*this, "lcd_pwm"),
3941
m_dac(*this, "dac"),
4042
m_rs232(*this, "rs232"),
41-
m_inputs(*this, "IN.%u", 0)
43+
m_inputs(*this, "IN.%u", 0),
44+
m_out_lcd(*this, "s%u.%u", 0U, 0U)
4245
{ }
4346

4447
void sapphire(machine_config &config);
@@ -50,17 +53,26 @@ class sapphire_state : public driver_device
5053
// devices/pointers
5154
required_device<h8325_device> m_maincpu;
5255
memory_view m_memory;
53-
memory_share_creator<u8> m_banked_ram;
56+
memory_share_creator<u8> m_nvram;
5457
required_memory_bank m_rambank;
58+
required_device<pwm_display_device> m_lcd_pwm;
5559
required_device<dac_1bit_device> m_dac;
5660
required_device<rs232_port_device> m_rs232;
5761
required_ioport_array<2> m_inputs;
62+
output_finder<4, 10> m_out_lcd;
5863

5964
u8 m_inp_mux = 0;
65+
u8 m_lcd_sclk = 0;
66+
u16 m_lcd_data = 0;
67+
u8 m_lcd_segs2 = 0;
6068

6169
void main_map(address_map &map);
6270

6371
// I/O handlers
72+
void lcd_pwm_w(offs_t offset, u8 data);
73+
void update_lcd();
74+
void lcd_data_w(u8 data);
75+
6476
u8 p1_r();
6577
void p1_w(u8 data);
6678

@@ -85,11 +97,16 @@ class sapphire_state : public driver_device
8597

8698
void sapphire_state::machine_start()
8799
{
88-
m_rambank->configure_entries(0, 4, m_banked_ram, 0x8000);
100+
m_out_lcd.resolve();
101+
102+
m_rambank->configure_entries(0, 4, m_nvram, 0x8000);
89103
m_memory.select(0);
90104

91105
// register for savestates
92106
save_item(NAME(m_inp_mux));
107+
save_item(NAME(m_lcd_sclk));
108+
save_item(NAME(m_lcd_data));
109+
save_item(NAME(m_lcd_segs2));
93110
}
94111

95112

@@ -106,8 +123,60 @@ void sapphire_state::machine_start()
106123
[:maincpu:port4] ddr_w 3f
107124
[:maincpu:port6] ddr_w 3f
108125
126+
01 01 01 00 00000000
127+
01 01 00 01 00000000
128+
01 00 01 01 00000000
129+
00 01 01 01 00000000
130+
131+
01 01 01 11 11111111
132+
01 01 11 01 11111111
133+
01 11 01 01 11111111
134+
11 01 01 01 11111111
135+
109136
*/
110137

138+
// LCD
139+
140+
void sapphire_state::lcd_pwm_w(offs_t offset, u8 data)
141+
{
142+
m_out_lcd[offset & 0x3f][offset >> 6] = data;
143+
}
144+
145+
void sapphire_state::update_lcd()
146+
{
147+
for (int i = 0; i < 4; i++)
148+
{
149+
// LCD common is analog (voltage level)
150+
const u8 com = population_count_32(m_lcd_data >> (8 + (i * 2)) & 3);
151+
u16 segs = (m_lcd_data & 0xff) | (m_lcd_segs2 << 8 & 0x300);
152+
segs = (com == 0) ? segs : (com == 2) ? ~segs : 0;
153+
154+
m_lcd_pwm->write_row(i, segs);
155+
}
156+
}
157+
158+
void sapphire_state::lcd_data_w(u8 data)
159+
{
160+
// P62: 2*14015B R
161+
if (data & 4)
162+
m_lcd_data = 0;
163+
164+
// P60: 2*14015B C (chained)
165+
else if (data & 1 && !m_lcd_sclk)
166+
{
167+
// P61: 14015B D, outputs to LCD
168+
m_lcd_data = m_lcd_data << 1 | BIT(data, 1);
169+
}
170+
m_lcd_sclk = data & 1;
171+
172+
// P64,P65: 2 more LCD segments
173+
m_lcd_segs2 = data >> 4 & 3;
174+
update_lcd();
175+
}
176+
177+
178+
// misc
179+
111180
u8 sapphire_state::p1_r()
112181
{
113182
//printf("r1 ");
@@ -122,7 +191,7 @@ void sapphire_state::p1_w(u8 data)
122191
u8 sapphire_state::p2_r()
123192
{
124193
//printf("r2 ");
125-
return 0xff;
194+
return 0xff ^ 0x80;
126195
}
127196

128197
void sapphire_state::p2_w(u8 data)
@@ -177,8 +246,6 @@ u8 sapphire_state::p6_r()
177246

178247
void sapphire_state::p6_w(u8 data)
179248
{
180-
//printf("w6_%X ",data);
181-
182249
// P63: RAM/ROM CS
183250
m_memory.select(BIT(data, 3));
184251
}
@@ -269,18 +336,21 @@ void sapphire_state::sapphire(machine_config &config)
269336

270337
m_maincpu->read_port6().set(FUNC(sapphire_state::p6_r));
271338
m_maincpu->write_port6().set(FUNC(sapphire_state::p6_w));
339+
m_maincpu->write_port6().append(FUNC(sapphire_state::lcd_data_w));
272340

273341
m_maincpu->read_port7().set(FUNC(sapphire_state::p7_r));
274342
m_maincpu->write_port7().set(FUNC(sapphire_state::p7_w));
275343

344+
NVRAM(config, "nvram", nvram_device::DEFAULT_ALL_0);
345+
276346
// video hardware
277-
//PWM_DISPLAY(config, m_lcd_pwm).set_size(4, 10);
278-
//m_lcd_pwm->output_x().set(FUNC(sapphire_state::lcd_pwm_w));
347+
PWM_DISPLAY(config, m_lcd_pwm).set_size(4, 10);
348+
m_lcd_pwm->output_x().set(FUNC(sapphire_state::lcd_pwm_w));
279349

280-
//screen_device &screen(SCREEN(config, "screen", SCREEN_TYPE_SVG));
281-
//screen.set_refresh_hz(60);
282-
//screen.set_size(1920/2.5, 606/2.5);
283-
//screen.set_visarea_full();
350+
screen_device &screen(SCREEN(config, "screen", SCREEN_TYPE_SVG));
351+
screen.set_refresh_hz(60);
352+
screen.set_size(1920/2.5, 606/2.5);
353+
screen.set_visarea_full();
284354

285355
//config.set_default_layout(layout_novag_sapphire);
286356

0 commit comments

Comments
 (0)