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
240234void 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
277283void 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
383389uint16_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.
418416std::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+ }
0 commit comments