Skip to content

Commit 593983c

Browse files
authored
ef9345: Move some code paths for the ts9347 variant into virtual functions (#14423)
1 parent 62d0ebd commit 593983c

File tree

2 files changed

+89
-55
lines changed

2 files changed

+89
-55
lines changed

src/devices/video/ef9345.cpp

Lines changed: 65 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@
2020
#include <algorithm>
2121

2222

23-
#define MODE24x40 0
24-
#define MODEVAR40 1
25-
#define MODE8x80 2
26-
#define MODE12x80 3
27-
#define MODE16x40 4
28-
2923
//**************************************************************************
3024
// GLOBAL VARIABLES
3125
//**************************************************************************
@@ -239,16 +233,7 @@ void ef9345_device::draw_char_80(uint8_t *c, uint16_t x, uint16_t y)
239233
// set then ef9345 mode
240234
void ef9345_device::set_video_mode(void)
241235
{
242-
if (m_variant == EF9345_MODE::TYPE_TS9347)
243-
{
244-
// Only TGS 7 & 6 used for the char mode with the TS9347
245-
m_char_mode = ((m_tgs & 0xc0) >> 6);
246-
}
247-
else
248-
{
249-
// PAT 7, TGS 7 & 6
250-
m_char_mode = ((m_pat & 0x80) >> 5) | ((m_tgs & 0xc0) >> 6);
251-
}
236+
m_char_mode = parse_video_mode();
252237

253238
uint16_t new_width = (m_char_mode == MODE12x80 || m_char_mode == MODE8x80) ? 492 : 336;
254239

@@ -273,6 +258,27 @@ void ef9345_device::set_video_mode(void)
273258
m_block = 0x0800 * ((((m_ror & 0xf0) >> 4) | ((m_ror & 0x40) >> 5) | ((m_ror & 0x20) >> 3)) & 0x0c);
274259
}
275260

261+
ef9345_device::char_mode_t ef9345_device::parse_video_mode() const
262+
{
263+
uint8_t selector = (BIT(m_pat, 7) << 2) | bitswap<2>(m_tgs, 7, 6);
264+
switch (selector)
265+
{
266+
default:
267+
logerror("Unknown EF9345 mode: 0x%x\n", selector);
268+
[[fallthrough]];
269+
case 0b000:
270+
return MODE24x40;
271+
case 0b001:
272+
return MODEVAR40;
273+
case 0b100:
274+
return MODE16x40;
275+
case 0b011:
276+
return MODE12x80;
277+
case 0b010:
278+
return MODE8x80;
279+
}
280+
}
281+
276282
// initialize the ef9345 accented chars
277283
void ef9345_device::init_accented_chars(void)
278284
{
@@ -382,25 +388,7 @@ void ef9345_device::zoom(uint8_t *pix, uint16_t n)
382388
// calculate the address of the char x,y
383389
uint16_t ef9345_device::indexblock(uint16_t x, uint16_t y)
384390
{
385-
uint16_t i = x, j;
386-
387-
if (m_variant == EF9345_MODE::TYPE_EF9345)
388-
{
389-
// On the EF9345 the service row is always displayed at the top, and
390-
// it can be fetched from either Y=0 or Y=1.
391-
j = (y == 0) ? ((m_tgs & 0x20) >> 5) : ((m_ror & 0x1f) + y - 1);
392-
}
393-
else
394-
{
395-
// On the TS9347 the service row is displayed either at the top or at
396-
// the bottom, and it is always fetched from Y=0.
397-
if (m_tgs & 1)
398-
j = (y == 24) ? 0 : ((m_ror & 0x1f) + y);
399-
else
400-
j = (y == 0) ? 0 : ((m_ror & 0x1f) + y - 1);
401-
}
402-
403-
j = (j > 31) ? (j - 24) : j;
391+
uint16_t i = x, j = indexrow(y);
404392

405393
//right side of a double width character
406394
if ((m_tgs & 0x80) == 0 && x > 0)
@@ -413,6 +401,16 @@ uint16_t ef9345_device::indexblock(uint16_t x, uint16_t y)
413401
return 0x40 * j + i;
414402
}
415403

404+
uint16_t ef9345_device::indexrow(uint16_t y)
405+
{
406+
uint16_t j;
407+
408+
// On the EF9345 the service row can be fetched from either Y=0 or Y=1.
409+
j = (y == 0) ? BIT(m_tgs, 5) : ((m_ror & 0x1f) + y - 1);
410+
411+
return (j > 31) ? (j - 24) : j;
412+
}
413+
416414
// applies the insert, flash, conceal and negative attributes,
417415
// considering whether the cursor is on this character or not.
418416
std::tuple<uint8_t, uint8_t, bool> ef9345_device::makecolors(uint8_t c0, uint8_t c1, bool insert, bool flash, bool conceal, bool negative, bool cursor)
@@ -782,30 +780,14 @@ void ef9345_device::makechar(uint16_t x, uint16_t y)
782780
makechar_24x40(x, y);
783781
break;
784782
case MODEVAR40:
785-
if (m_variant == EF9345_MODE::TYPE_TS9347)
786-
{ // TS9347 char mode definition is different.
787-
makechar_16x40(x, y);
788-
break;
789-
}
790-
[[fallthrough]];
791783
case MODE8x80:
792784
logerror("Unemulated EF9345 mode: %02x\n", m_char_mode);
793785
break;
794786
case MODE12x80:
795787
makechar_12x80(x, y);
796788
break;
797789
case MODE16x40:
798-
if (m_variant == EF9345_MODE::TYPE_TS9347)
799-
{
800-
logerror("Unemulated EF9345 mode: %02x\n", m_char_mode);
801-
}
802-
else
803-
{
804-
makechar_16x40(x, y);
805-
}
806-
break;
807-
default:
808-
logerror("Unknown EF9345 mode: %02x\n", m_char_mode);
790+
makechar_16x40(x, y);
809791
break;
810792
}
811793
}
@@ -1185,3 +1167,34 @@ void ef9345_device::data_w(offs_t offset, uint8_t data)
11851167
if (offset & 8)
11861168
ef9345_exec(m_registers[0] & 0xff);
11871169
}
1170+
1171+
ef9345_device::char_mode_t ts9347_device::parse_video_mode() const
1172+
{
1173+
switch (bitswap<2>(m_tgs, 7, 6))
1174+
{
1175+
case 0b00:
1176+
return MODE24x40;
1177+
case 0b01:
1178+
return MODE16x40;
1179+
case 0b11:
1180+
return MODE12x80;
1181+
case 0b10:
1182+
return MODE8x80;
1183+
default: // unreachable
1184+
abort();
1185+
}
1186+
}
1187+
1188+
uint16_t ts9347_device::indexrow(uint16_t y)
1189+
{
1190+
uint16_t j;
1191+
1192+
// On the TS9347 the service row is displayed either at the top or at
1193+
// the bottom, and it is always fetched from Y=0.
1194+
if (m_tgs & 1)
1195+
j = (y == 24) ? 0 : ((m_ror & 0x1f) + y);
1196+
else
1197+
j = (y == 0) ? 0 : ((m_ror & 0x1f) + y - 1);
1198+
1199+
return (j > 31) ? (j - 24) : j;
1200+
}

src/devices/video/ef9345.h

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,18 @@ class ef9345_device : public device_t,
3939
void update_scanline(uint16_t scanline);
4040
uint32_t screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
4141

42-
protected:
42+
enum char_mode_t : uint8_t {
43+
// 40 column modes:
44+
MODE24x40, // long codes
45+
MODEVAR40, // variable codes
46+
MODE16x40, // short codes
47+
48+
// 80 column modes:
49+
MODE8x80, // long codes
50+
MODE12x80, // variable codes
51+
};
4352

53+
protected:
4454
enum class EF9345_MODE {
4555
TYPE_EF9345 = 0x001,
4656
TYPE_TS9347 = 0x002
@@ -67,7 +77,6 @@ class ef9345_device : public device_t,
6777
TIMER_CALLBACK_MEMBER(clear_busy_flag);
6878
TIMER_CALLBACK_MEMBER(blink_tick);
6979

70-
private:
7180
void set_busy_flag(int period);
7281
void set_video_mode(void);
7382
void init_accented_chars(void);
@@ -77,6 +86,12 @@ class ef9345_device : public device_t,
7786
uint16_t indexblock(uint16_t x, uint16_t y);
7887
std::tuple<uint8_t, uint8_t, bool> makecolors(uint8_t c0, uint8_t c1, bool insert, bool flash, bool conceal, bool negative, bool cursor);
7988

89+
virtual char_mode_t parse_video_mode() const;
90+
91+
// Computes the index of the memory row containing data for the y-th
92+
// screen row.
93+
virtual uint16_t indexrow(uint16_t y);
94+
8095
// Dispatch rendering of character (x, y) to one of the specialized
8196
// drawing functions (bichrome40/quadrichrome40/bichrome80).
8297
void makechar(uint16_t x, uint16_t y);
@@ -105,7 +120,7 @@ class ef9345_device : public device_t,
105120
address_space *m_videoram;
106121

107122
uint8_t m_bf; //busy flag
108-
uint8_t m_char_mode; //40 or 80 chars for line
123+
char_mode_t m_char_mode; //40 or 80 chars for line
109124
uint8_t m_acc_char[0x2000]; //accented chars
110125
uint8_t m_registers[8]; //registers R0-R7
111126
uint8_t m_state; //status register
@@ -135,8 +150,14 @@ class ts9347_device : public ef9345_device
135150
{
136151
public:
137152
ts9347_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
153+
154+
protected:
155+
virtual char_mode_t parse_video_mode() const override;
156+
virtual uint16_t indexrow(uint16_t y) override;
138157
};
139158

159+
ALLOW_SAVE_TYPE(ef9345_device::char_mode_t)
160+
140161
// device type definition
141162
DECLARE_DEVICE_TYPE(EF9345, ef9345_device)
142163
DECLARE_DEVICE_TYPE(TS9347, ts9347_device)

0 commit comments

Comments
 (0)