OSDN Git Service

[VM][STATE] Use namespace {VMNAME} to separate per VMs.
[csp-qt/common_source_project-fm7.git] / source / src / vm / tk80bs / display.cpp
index 4856ea8..28a4d7b 100644 (file)
-/*\r
-       NEC TK-80BS (COMPO BS/80) Emulator 'eTK-80BS'\r
-\r
-       Author : Takeda.Toshiya\r
-       Date   : 2008.08.26 -\r
-\r
-       [ display ]\r
-*/\r
-\r
-#include "display.h"\r
-#include "../../fileio.h"\r
-\r
-static const int dest_x[8] = {\r
-       1, 26, 51, 76, 106, 131, 156, 181\r
-};\r
-static const int pat_led[35][24] = {\r
-       {9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9},\r
-       {9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9},\r
-       {9,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,2,0,0,9},\r
-       {9,0,0,0,6,0,1,1,1,1,1,1,1,1,1,1,1,1,0,2,2,0,0,9},\r
-       {9,0,0,0,6,6,0,1,1,1,1,1,1,1,1,1,1,0,2,2,2,0,0,9},\r
-       {9,0,0,0,6,6,6,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,0,9},\r
-       {9,0,0,0,6,6,6,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,0,9},\r
-       {9,0,0,0,6,6,6,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,0,9},\r
-       {9,0,0,0,6,6,6,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,0,9},\r
-       {9,0,0,0,6,6,6,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,0,9},\r
-       {9,0,0,0,6,6,6,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,0,9},\r
-       {9,0,0,6,6,6,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,0,0,9},\r
-       {9,0,0,6,6,6,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,0,0,9},\r
-       {9,0,0,6,6,6,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,0,0,9},\r
-       {9,0,0,6,6,6,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,0,0,9},\r
-       {9,0,0,6,6,6,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,0,0,9},\r
-       {9,0,0,0,6,0,7,7,7,7,7,7,7,7,7,7,7,0,2,0,0,0,0,9},\r
-       {9,0,0,0,0,7,7,7,7,7,7,7,7,7,7,7,7,7,0,0,0,0,0,9},\r
-       {9,0,0,0,5,0,7,7,7,7,7,7,7,7,7,7,7,0,3,0,0,0,0,9},\r
-       {9,0,0,5,5,5,0,0,0,0,0,0,0,0,0,0,0,3,3,3,0,0,0,9},\r
-       {9,0,0,5,5,5,0,0,0,0,0,0,0,0,0,0,0,3,3,3,0,0,0,9},\r
-       {9,0,0,5,5,5,0,0,0,0,0,0,0,0,0,0,0,3,3,3,0,0,0,9},\r
-       {9,0,0,5,5,5,0,0,0,0,0,0,0,0,0,0,0,3,3,3,0,0,0,9},\r
-       {9,0,0,5,5,5,0,0,0,0,0,0,0,0,0,0,0,3,3,3,0,0,0,9},\r
-       {9,0,5,5,5,0,0,0,0,0,0,0,0,0,0,0,3,3,3,0,0,0,0,9},\r
-       {9,0,5,5,5,0,0,0,0,0,0,0,0,0,0,0,3,3,3,0,0,0,0,9},\r
-       {9,0,5,5,5,0,0,0,0,0,0,0,0,0,0,0,3,3,3,0,0,0,0,9},\r
-       {9,0,5,5,5,0,0,0,0,0,0,0,0,0,0,0,3,3,3,0,0,0,0,9},\r
-       {9,0,5,5,5,0,0,0,0,0,0,0,0,0,0,0,3,3,3,0,0,0,0,9},\r
-       {9,0,5,5,5,0,0,0,0,0,0,0,0,0,0,0,3,3,3,0,0,0,0,9},\r
-       {9,0,5,5,0,4,4,4,4,4,4,4,4,4,4,0,3,3,3,0,0,0,0,9},\r
-       {9,0,5,0,4,4,4,4,4,4,4,4,4,4,4,4,0,3,3,0,8,8,0,9},\r
-       {9,0,0,4,4,4,4,4,4,4,4,4,4,4,4,4,4,0,3,0,8,8,0,9},\r
-       {9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9},\r
-       {9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9},\r
-};\r
-static const int pat_kb[31][42] = {\r
-       {1,1,1,1,1,1,1,1,1,0,0,1,1,1,0,0,0,1,1,1,0,0,1,1,1,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0},\r
-       {1,1,1,1,1,1,1,1,1,0,0,1,1,1,0,0,0,1,1,1,0,0,1,1,1,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0},\r
-       {1,1,1,0,0,0,0,0,0,0,0,1,1,1,0,0,0,1,1,1,0,0,1,1,1,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0},\r
-       {1,1,1,0,0,0,0,0,0,0,0,1,1,1,0,0,0,1,1,1,0,0,1,1,1,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0},\r
-       {1,1,1,0,0,0,0,0,0,0,0,1,1,1,0,0,0,1,1,1,0,0,1,1,1,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0},\r
-       {1,1,1,0,0,0,0,0,0,0,0,1,1,1,0,0,0,1,1,1,0,0,1,1,1,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0},\r
-       {1,1,1,1,1,1,1,0,0,0,0,1,1,1,0,0,0,1,1,1,0,0,1,1,1,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0},\r
-       {1,1,1,1,1,1,1,0,0,0,0,1,1,1,0,0,0,1,1,1,0,0,1,1,1,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0},\r
-       {1,1,1,0,0,0,0,0,0,0,0,1,1,1,0,0,0,1,1,1,0,0,1,1,1,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0},\r
-       {1,1,1,0,0,0,0,0,0,0,0,1,1,1,0,0,0,1,1,1,0,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0,2,2,2},\r
-       {0,0,0,2,2,2,0,0,0,0,0,2,2,2,0,2,2,2,0,0,0,0,2,2,2,0,0,0,2,2,2,0,0,2,2,2,0,0,0,2,2,2},\r
-       {0,0,0,2,2,2,0,0,0,0,0,2,2,2,0,2,2,2,0,0,0,0,2,2,2,0,0,0,2,2,2,0,0,2,2,2,0,0,0,2,2,2},\r
-       {0,0,0,2,2,2,0,0,0,0,0,2,2,2,2,2,0,0,0,0,0,0,0,0,2,2,2,2,2,0,0,0,0,2,2,2,0,0,0,2,2,2},\r
-       {0,0,0,2,2,2,0,0,0,0,0,2,2,2,2,2,0,0,0,0,0,0,0,0,2,2,2,2,2,0,0,0,0,2,2,2,0,0,0,2,2,2},\r
-       {0,0,0,2,2,2,0,0,0,0,0,2,2,2,0,2,2,2,0,0,0,0,2,2,2,0,0,0,2,2,2,0,0,2,2,2,0,0,0,2,2,2},\r
-       {0,0,0,2,2,2,0,0,0,0,0,2,2,2,0,2,2,2,0,0,0,0,2,2,2,0,0,0,2,2,2,0,0,2,2,2,0,0,0,2,2,2},\r
-       {0,0,0,2,2,2,0,0,0,0,0,2,2,2,0,0,0,2,2,2,0,0,2,2,2,0,0,0,2,2,2,0,0,2,2,2,0,0,0,2,2,2},\r
-       {0,0,0,2,2,2,0,0,0,0,0,2,2,2,0,0,0,2,2,2,0,0,2,2,2,0,0,0,2,2,2,0,0,2,2,2,0,0,0,2,2,2},\r
-       {0,0,0,2,2,2,0,0,0,0,0,2,2,2,0,0,0,2,2,2,0,0,0,0,2,2,2,2,2,0,0,0,0,0,0,2,2,2,2,2,0,0},\r
-       {0,0,0,2,2,2,0,0,0,0,0,2,2,2,0,0,0,2,2,2,0,0,0,0,2,2,2,2,2,0,0,0,0,0,0,2,2,2,2,2,0,0},\r
-};\r
-\r
-void DISPLAY::initialize()\r
-{\r
-       // load rom image\r
-       FILEIO* fio = new FILEIO();\r
-       if(fio->Fopen(emu->bios_path(_T("FONT.ROM")), FILEIO_READ_BINARY)) {\r
-               fio->Fread(font, sizeof(font), 1);\r
-               fio->Fclose();\r
-       }\r
-       delete fio;\r
-       \r
-       mode = 2;\r
-       dma = 0x80;\r
-}\r
-\r
-void DISPLAY::write_signal(int id, uint32 data, uint32 mask)\r
-{\r
-       if(id == SIG_DISPLAY_MODE) {\r
-               // 8255 PC on TK-80BS\r
-               mode = data & mask;\r
-       } else if(id == SIG_DISPLAY_DMA) {\r
-               // 8255 PC on TK-80\r
-               dma = data & mask;\r
-       }\r
-}\r
-\r
-void DISPLAY::draw_screen()\r
-{\r
-       // draw screen\r
-       scrntype col_w = (mode & 2) ? RGB_COLOR(255, 255, 255) : 0;\r
-       scrntype col_b = (mode & 2) ? 0 : RGB_COLOR(255, 255, 255);\r
-       int code_ofs = (mode & 1) << 8;\r
-       int ptr = 0;\r
-       \r
-       for(int y = 0; y < 128; y += 8) {\r
-               for(int x = 0; x < 256; x += 8) {\r
-                       int code = vram[ptr++] | code_ofs;\r
-                       uint8* font_base = &font[code << 3];\r
-                       \r
-                       for(int l = 0; l < 8; l++) {\r
-                               uint8 pat = font_base[l];\r
-                               scrntype* dest = &screen[l][x];\r
-                               \r
-                               dest[0] = (pat & 0x80) ? col_w : col_b;\r
-                               dest[1] = (pat & 0x40) ? col_w : col_b;\r
-                               dest[2] = (pat & 0x20) ? col_w : col_b;\r
-                               dest[3] = (pat & 0x10) ? col_w : col_b;\r
-                               dest[4] = (pat & 0x08) ? col_w : col_b;\r
-                               dest[5] = (pat & 0x04) ? col_w : col_b;\r
-                               dest[6] = (pat & 0x02) ? col_w : col_b;\r
-                               dest[7] = (pat & 0x01) ? col_w : col_b;\r
-                       }\r
-               }\r
-               for(int l = 0; l < 8; l++) {\r
-                       scrntype* dest = emu->screen_buffer(y + l);\r
-                       scrntype* src = screen[l];\r
-                       memcpy(dest, src, 256 * sizeof(scrntype));\r
-               }\r
-       }\r
-       // draw leds\r
-       scrntype col_red = RGB_COLOR(255, 0, 0);\r
-       scrntype col_on = RGB_COLOR(255, 8, 72);\r
-       scrntype col_off = RGB_COLOR(56, 0, 0);\r
-       scrntype col[10];\r
-       \r
-       memset(screen, 0, sizeof(screen));\r
-       for(int i = 0; i < 8; i++) {\r
-               for(int i = 0; i < 8; i++) {\r
-                       uint8 pat = dma ? led[i] : 0;\r
-                       col[0] = 0;\r
-                       col[1] = pat & 0x01 ? col_on : col_off;\r
-                       col[2] = pat & 0x02 ? col_on : col_off;\r
-                       col[3] = pat & 0x04 ? col_on : col_off;\r
-                       col[4] = pat & 0x08 ? col_on : col_off;\r
-                       col[5] = pat & 0x10 ? col_on : col_off;\r
-                       col[6] = pat & 0x20 ? col_on : col_off;\r
-                       col[7] = pat & 0x40 ? col_on : col_off;\r
-                       col[8] = pat & 0x80 ? col_on : col_off;\r
-                       col[9] = col_red;\r
-                       for(int y = 0; y < 35; y++) {\r
-                               scrntype *dest = &screen[y + 1][dest_x[i]];\r
-                               for(int x = 0; x < 24; x++) {\r
-                                       dest[x] = col[pat_led[y][x]];\r
-                               }\r
-                       }\r
-               }\r
-       }\r
-       // draw kb type\r
-       col[1] = d_key->read_signal(0) & 1 ? col_red : col_off;\r
-       col[2] = d_key->read_signal(0) & 2 ? col_red : col_off;\r
-       \r
-       for(int y = 0; y < 31; y++) {\r
-               scrntype *dest = &screen[y + 3][210];\r
-               for(int x = 0; x < 42; x++) {\r
-                       dest[x] = col[pat_kb[y][x]];\r
-               }\r
-       }\r
-       \r
-       // copy to screen\r
-       for(int y = 0; y < 36; y++) {\r
-               scrntype* dest = emu->screen_buffer(y + 128);\r
-               scrntype* src = screen[y];\r
-               memcpy(dest, src, 256 * sizeof(scrntype));\r
-       }\r
-}\r
-\r
+/*
+       NEC TK-80BS (COMPO BS/80) Emulator 'eTK-80BS'
+       NEC TK-80 Emulator 'eTK-80'
+       NEC TK-85 Emulator 'eTK-85'
+
+       Author : Takeda.Toshiya
+       Date   : 2008.08.26 -
+
+       [ display ]
+*/
+
+#include "display.h"
+
+namespace TK80 {
+
+static const int led_pattern[LED_SIZE_Y][LED_SIZE_X] = {
+#if defined(_TK80BS) || defined(_TK80)
+       {9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9},
+       {9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9},
+       {9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9},
+       {9,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,9},
+       {9,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,9},
+       {9,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,9},
+       {9,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,9},
+       {9,9,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,2,0,0,0,0,9,9},
+       {9,9,0,0,0,0,6,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,2,2,0,0,0,0,9,9},
+       {9,9,0,0,0,0,6,6,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,2,2,2,0,0,0,0,9,9},
+       {9,9,0,0,0,0,6,6,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,0,0,0,9,9},
+       {9,9,0,0,0,0,6,6,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,0,0,0,9,9},
+       {9,9,0,0,0,0,6,6,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,0,0,0,9,9},
+       {9,9,0,0,0,0,6,6,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,0,0,0,9,9},
+       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,0,3,3,3,0,0,0,0,0,9,9},
+       {9,9,0,0,5,5,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,3,3,0,0,0,0,0,0,9,9},
+       {9,9,0,0,5,5,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,3,3,0,0,0,0,0,0,9,9},
+       {9,9,0,0,5,5,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,3,3,0,0,0,0,0,0,9,9},
+       {9,9,0,0,5,5,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,3,3,0,0,0,0,0,0,9,9},
+       {9,9,0,0,5,5,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,3,3,0,0,0,0,0,0,9,9},
+       {9,9,0,0,5,5,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,3,3,0,0,0,0,0,0,9,9},
+       {9,9,0,0,5,5,0,4,4,4,4,4,4,4,4,4,4,4,4,4,4,0,3,3,3,0,8,8,8,0,0,9,9},
+       {9,9,0,0,5,0,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,0,3,3,0,8,8,8,0,0,9,9},
+       {9,9,0,0,0,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,0,3,0,8,8,8,0,0,9,9},
+       {9,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,9},
+       {9,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,9},
+       {9,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,9},
+       {9,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,9},
+       {9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9},
+       {9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9},
+       {9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9},
+       {9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9},
+#else
+       {9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9},
+       {9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9},
+       {9,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,9},
+       {9,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,9},
+       {9,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,9},
+       {9,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,9},
+       {9,9,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,2,0,0,0,9,9},
+       {9,9,0,0,0,0,6,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,2,2,0,0,0,9,9},
+       {9,9,0,0,0,0,6,6,0,1,1,1,1,1,1,1,1,1,1,1,0,2,2,2,0,0,0,9,9},
+       {9,9,0,0,0,0,6,6,6,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,0,0,9,9},
+       {9,9,0,0,0,0,6,6,6,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,0,0,9,9},
+       {9,9,0,0,0,0,6,6,6,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,0,0,9,9},
+       {9,9,0,0,0,0,6,6,6,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,0,0,9,9},
+       {9,9,0,0,0,0,6,6,6,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,0,0,9,9},
+       {9,9,0,0,0,6,6,6,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,0,0,0,9,9},
+       {9,9,0,0,0,6,6,6,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,0,0,0,9,9},
+       {9,9,0,0,0,6,6,6,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,0,0,0,9,9},
+       {9,9,0,0,0,6,6,6,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,0,0,0,9,9},
+       {9,9,0,0,0,0,6,0,7,7,7,7,7,7,7,7,7,7,7,7,0,2,0,0,0,0,0,9,9},
+       {9,9,0,0,0,0,0,7,7,7,7,7,7,7,7,7,7,7,7,7,7,0,0,0,0,0,0,9,9},
+       {9,9,0,0,0,0,5,0,7,7,7,7,7,7,7,7,7,7,7,7,0,3,0,0,0,0,0,9,9},
+       {9,9,0,0,0,5,5,5,0,0,0,0,0,0,0,0,0,0,0,0,3,3,3,0,0,0,0,9,9},
+       {9,9,0,0,0,5,5,5,0,0,0,0,0,0,0,0,0,0,0,0,3,3,3,0,0,0,0,9,9},
+       {9,9,0,0,0,5,5,5,0,0,0,0,0,0,0,0,0,0,0,0,3,3,3,0,0,0,0,9,9},
+       {9,9,0,0,0,5,5,5,0,0,0,0,0,0,0,0,0,0,0,0,3,3,3,0,0,0,0,9,9},
+       {9,9,0,0,5,5,5,0,0,0,0,0,0,0,0,0,0,0,0,3,3,3,0,0,0,0,0,9,9},
+       {9,9,0,0,5,5,5,0,0,0,0,0,0,0,0,0,0,0,0,3,3,3,0,0,0,0,0,9,9},
+       {9,9,0,0,5,5,5,0,0,0,0,0,0,0,0,0,0,0,0,3,3,3,0,0,0,0,0,9,9},
+       {9,9,0,0,5,5,5,0,0,0,0,0,0,0,0,0,0,0,0,3,3,3,0,0,0,0,0,9,9},
+       {9,9,0,0,5,5,5,0,0,0,0,0,0,0,0,0,0,0,0,3,3,3,0,0,0,0,0,9,9},
+       {9,9,0,0,5,5,0,4,4,4,4,4,4,4,4,4,4,4,0,3,3,3,0,8,8,8,0,9,9},
+       {9,9,0,0,5,0,4,4,4,4,4,4,4,4,4,4,4,4,4,0,3,3,0,8,8,8,0,9,9},
+       {9,9,0,0,0,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,0,3,0,8,8,8,0,9,9},
+       {9,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,9},
+       {9,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,9},
+       {9,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,9},
+       {9,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,9},
+       {9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9},
+       {9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9},
+#endif
+};
+
+void DISPLAY::initialize()
+{
+#if defined(_TK80BS)
+       // load rom image
+       FILEIO* fio = new FILEIO();
+       if(fio->Fopen(create_local_path(_T("FONT.ROM")), FILEIO_READ_BINARY)) {
+               fio->Fread(font, sizeof(font), 1);
+               fio->Fclose();
+       }
+       delete fio;
+       
+       mode = 2;
+#endif
+       dma = true;
+}
+
+void DISPLAY::write_signal(int id, uint32_t data, uint32_t mask)
+{
+#if defined(_TK80BS)
+       if(id == SIG_DISPLAY_MODE) {
+               // 8255 PC on TK-80BS
+               mode = data & mask;
+       } else
+#endif
+       if(id == SIG_DISPLAY_DMA) {
+               // 8255 PC on TK-80
+               dma = ((data & mask) != 0);
+       }
+}
+
+void DISPLAY::draw_screen()
+{
+#if defined(_TK80BS)
+       // draw screen
+       scrntype_t color_w = (mode & 2) ? RGB_COLOR(255, 255, 255) : RGB_COLOR(0, 0, 1);
+       scrntype_t color_b = (mode & 2) ? RGB_COLOR(0, 0, 1) : RGB_COLOR(255, 255, 255);
+       scrntype_t screen[36][256] = {0};
+       int code_ofs = (mode & 1) << 8;
+       int ptr = 0;
+
+       for(int y = 0; y < 128; y += 8) {
+               for(int x = 0; x < 256; x += 8) {
+                       int code = vram[ptr++];
+                       if(code != 0x20) {
+                               static_cast<VM *>(vm)->draw_ranges = 9;
+                       }
+                       code |= code_ofs;
+                       uint8_t* font_base = &font[code << 3];
+                       
+                       for(int l = 0; l < 8; l++) {
+                               uint8_t pat = font_base[l];
+                               scrntype_t* dest = &screen[l][x];
+                               
+                               dest[0] = (pat & 0x80) ? color_w : color_b;
+                               dest[1] = (pat & 0x40) ? color_w : color_b;
+                               dest[2] = (pat & 0x20) ? color_w : color_b;
+                               dest[3] = (pat & 0x10) ? color_w : color_b;
+                               dest[4] = (pat & 0x08) ? color_w : color_b;
+                               dest[5] = (pat & 0x04) ? color_w : color_b;
+                               dest[6] = (pat & 0x02) ? color_w : color_b;
+                               dest[7] = (pat & 0x01) ? color_w : color_b;
+                       }
+               }
+               for(int l = 0; l < 8; l++) {
+                       scrntype_t* dest0 = emu->get_screen_buffer(vm_ranges[8].y + (y + l) * 2 + 0) + vm_ranges[8].x;
+                       scrntype_t* dest1 = emu->get_screen_buffer(vm_ranges[8].y + (y + l) * 2 + 1) + vm_ranges[8].x;
+                       scrntype_t* src = screen[l];
+                       for(int x = 0, xx = 0; x < 256; x++, xx += 2) {
+                               dest0[xx] = dest0[xx + 1] = src[x];
+                       }
+                       memcpy(dest1, dest0, 256 * 2 * sizeof(scrntype_t));
+               }
+       }
+#endif
+       
+       // draw 7-seg LEDs
+       scrntype_t col[10];
+       scrntype_t color_on  = RGB_COLOR(255, 8, 72);
+#if defined(_TK80BS) || defined(_TK80)
+       scrntype_t color_off = RGB_COLOR(56, 0, 0);
+       col[0] = RGB_COLOR(38, 8, 0);
+#else
+       scrntype_t color_off = RGB_COLOR(111, 33, 33);
+       col[0] = RGB_COLOR(96, 53, 53);
+#endif
+       col[9] = color_off;
+       
+       for(int i = 0; i < 8; i++) {
+               uint8_t pat = dma ? led[i] : 0;
+               col[1] = pat & 0x01 ? color_on : color_off;
+               col[2] = pat & 0x02 ? color_on : color_off;
+               col[3] = pat & 0x04 ? color_on : color_off;
+               col[4] = pat & 0x08 ? color_on : color_off;
+               col[5] = pat & 0x10 ? color_on : color_off;
+               col[6] = pat & 0x20 ? color_on : color_off;
+               col[7] = pat & 0x40 ? color_on : color_off;
+               col[8] = pat & 0x80 ? color_on : color_off;
+               for(int y = 0; y < LED_SIZE_Y; y++) {
+                       scrntype_t* dest = emu->get_screen_buffer(vm_ranges[i].y + y) + vm_ranges[i].x;
+                       for(int x = 0; x < LED_SIZE_X; x++) {
+                               dest[x] = col[led_pattern[y][x]];
+                       }
+               }
+       }
+}
+
+#define STATE_VERSION  1
+
+bool DISPLAY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+#if defined(_TK80BS)
+       state_fio->StateInt32(mode);
+#endif
+       state_fio->StateBool(dma);
+       return true;
+}
+
+}