OSDN Git Service

[UI][VM][EMU][Qt][WIP] Apply upstream's OSD class.I don't test to build yet X-)
[csp-qt/common_source_project-fm7.git] / source / src / vm / tk80bs / display.cpp
1 /*
2         NEC TK-80BS (COMPO BS/80) Emulator 'eTK-80BS'
3
4         Author : Takeda.Toshiya
5         Date   : 2008.08.26 -
6
7         [ display ]
8 */
9
10 #include "display.h"
11
12 static const int dest_x[8] = {
13         1, 26, 51, 76, 106, 131, 156, 181
14 };
15 static const int pat_led[35][24] = {
16         {9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9},
17         {9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9},
18         {9,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,2,0,0,9},
19         {9,0,0,0,6,0,1,1,1,1,1,1,1,1,1,1,1,1,0,2,2,0,0,9},
20         {9,0,0,0,6,6,0,1,1,1,1,1,1,1,1,1,1,0,2,2,2,0,0,9},
21         {9,0,0,0,6,6,6,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,0,9},
22         {9,0,0,0,6,6,6,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,0,9},
23         {9,0,0,0,6,6,6,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,0,9},
24         {9,0,0,0,6,6,6,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,0,9},
25         {9,0,0,0,6,6,6,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,0,9},
26         {9,0,0,0,6,6,6,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,0,9},
27         {9,0,0,6,6,6,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,0,0,9},
28         {9,0,0,6,6,6,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,0,0,9},
29         {9,0,0,6,6,6,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,0,0,9},
30         {9,0,0,6,6,6,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,0,0,9},
31         {9,0,0,6,6,6,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,0,0,9},
32         {9,0,0,0,6,0,7,7,7,7,7,7,7,7,7,7,7,0,2,0,0,0,0,9},
33         {9,0,0,0,0,7,7,7,7,7,7,7,7,7,7,7,7,7,0,0,0,0,0,9},
34         {9,0,0,0,5,0,7,7,7,7,7,7,7,7,7,7,7,0,3,0,0,0,0,9},
35         {9,0,0,5,5,5,0,0,0,0,0,0,0,0,0,0,0,3,3,3,0,0,0,9},
36         {9,0,0,5,5,5,0,0,0,0,0,0,0,0,0,0,0,3,3,3,0,0,0,9},
37         {9,0,0,5,5,5,0,0,0,0,0,0,0,0,0,0,0,3,3,3,0,0,0,9},
38         {9,0,0,5,5,5,0,0,0,0,0,0,0,0,0,0,0,3,3,3,0,0,0,9},
39         {9,0,0,5,5,5,0,0,0,0,0,0,0,0,0,0,0,3,3,3,0,0,0,9},
40         {9,0,5,5,5,0,0,0,0,0,0,0,0,0,0,0,3,3,3,0,0,0,0,9},
41         {9,0,5,5,5,0,0,0,0,0,0,0,0,0,0,0,3,3,3,0,0,0,0,9},
42         {9,0,5,5,5,0,0,0,0,0,0,0,0,0,0,0,3,3,3,0,0,0,0,9},
43         {9,0,5,5,5,0,0,0,0,0,0,0,0,0,0,0,3,3,3,0,0,0,0,9},
44         {9,0,5,5,5,0,0,0,0,0,0,0,0,0,0,0,3,3,3,0,0,0,0,9},
45         {9,0,5,5,5,0,0,0,0,0,0,0,0,0,0,0,3,3,3,0,0,0,0,9},
46         {9,0,5,5,0,4,4,4,4,4,4,4,4,4,4,0,3,3,3,0,0,0,0,9},
47         {9,0,5,0,4,4,4,4,4,4,4,4,4,4,4,4,0,3,3,0,8,8,0,9},
48         {9,0,0,4,4,4,4,4,4,4,4,4,4,4,4,4,4,0,3,0,8,8,0,9},
49         {9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9},
50         {9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9},
51 };
52 static const int pat_kb[31][42] = {
53         {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},
54         {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},
55         {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},
56         {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},
57         {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},
58         {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},
59         {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},
60         {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},
61         {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},
62         {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},
63         {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},
64         {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},
65         {1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1},
66         {1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1},
67         {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,0,0,0,0,0,0,0,0,0,0,0,0,0},
68         {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,0,0,0,0,0,0,0,0,0,0,0,0,0},
69         {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,0,0,0,0,0,0,0,0,0,0,0,0,0},
70         {2,2,2,2,2,2,2,2,2,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},
71         {2,2,2,2,2,2,2,2,2,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},
72         {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},
73         {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},
74         {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},
75         {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},
76         {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},
77         {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},
78         {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},
79         {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},
80         {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},
81         {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},
82         {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},
83         {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},
84 };
85
86 void DISPLAY::initialize()
87 {
88         // load rom image
89         FILEIO* fio = new FILEIO();
90         if(fio->Fopen(emu->bios_path(_T("FONT.ROM")), FILEIO_READ_BINARY)) {
91                 fio->Fread(font, sizeof(font), 1);
92                 fio->Fclose();
93         }
94         delete fio;
95         
96         mode = 2;
97         dma = 0x80;
98 }
99
100 void DISPLAY::write_signal(int id, uint32 data, uint32 mask)
101 {
102         if(id == SIG_DISPLAY_MODE) {
103                 // 8255 PC on TK-80BS
104                 mode = data & mask;
105         } else if(id == SIG_DISPLAY_DMA) {
106                 // 8255 PC on TK-80
107                 dma = data & mask;
108         }
109 }
110
111 void DISPLAY::draw_screen()
112 {
113         // draw screen
114         scrntype col_w = (mode & 2) ? RGB_COLOR(255, 255, 255) : 0;
115         scrntype col_b = (mode & 2) ? 0 : RGB_COLOR(255, 255, 255);
116         int code_ofs = (mode & 1) << 8;
117         int ptr = 0;
118         
119         for(int y = 0; y < 128; y += 8) {
120                 for(int x = 0; x < 256; x += 8) {
121                         int code = vram[ptr++] | code_ofs;
122                         uint8* font_base = &font[code << 3];
123                         
124                         for(int l = 0; l < 8; l++) {
125                                 uint8 pat = font_base[l];
126                                 scrntype* dest = &screen[l][x];
127                                 
128                                 dest[0] = (pat & 0x80) ? col_w : col_b;
129                                 dest[1] = (pat & 0x40) ? col_w : col_b;
130                                 dest[2] = (pat & 0x20) ? col_w : col_b;
131                                 dest[3] = (pat & 0x10) ? col_w : col_b;
132                                 dest[4] = (pat & 0x08) ? col_w : col_b;
133                                 dest[5] = (pat & 0x04) ? col_w : col_b;
134                                 dest[6] = (pat & 0x02) ? col_w : col_b;
135                                 dest[7] = (pat & 0x01) ? col_w : col_b;
136                         }
137                 }
138                 for(int l = 0; l < 8; l++) {
139                         scrntype* dest = emu->screen_buffer(y + l);
140                         scrntype* src = screen[l];
141                         memcpy(dest, src, 256 * sizeof(scrntype));
142                 }
143         }
144         // draw 7-seg LEDs
145         scrntype col_red = RGB_COLOR(255, 0, 0);
146         scrntype col_on = RGB_COLOR(255, 8, 72);
147         scrntype col_off = RGB_COLOR(56, 0, 0);
148         scrntype col[10];
149         
150         memset(screen, 0, sizeof(screen));
151         for(int i = 0; i < 8; i++) {
152                 for(int i = 0; i < 8; i++) {
153                         uint8 pat = dma ? led[i] : 0;
154                         col[0] = 0;
155                         col[1] = pat & 0x01 ? col_on : col_off;
156                         col[2] = pat & 0x02 ? col_on : col_off;
157                         col[3] = pat & 0x04 ? col_on : col_off;
158                         col[4] = pat & 0x08 ? col_on : col_off;
159                         col[5] = pat & 0x10 ? col_on : col_off;
160                         col[6] = pat & 0x20 ? col_on : col_off;
161                         col[7] = pat & 0x40 ? col_on : col_off;
162                         col[8] = pat & 0x80 ? col_on : col_off;
163                         col[9] = col_red;
164                         for(int y = 0; y < 35; y++) {
165                                 scrntype *dest = &screen[y + 1][dest_x[i]];
166                                 for(int x = 0; x < 24; x++) {
167                                         dest[x] = col[pat_led[y][x]];
168                                 }
169                         }
170                 }
171         }
172         // draw kb type
173         col[1] = d_key->read_signal(0) & 1 ? col_red : col_off;
174         col[2] = d_key->read_signal(0) & 2 ? col_red : col_off;
175         
176         for(int y = 0; y < 31; y++) {
177                 scrntype *dest = &screen[y + 3][210];
178                 for(int x = 0; x < 42; x++) {
179                         dest[x] = col[pat_kb[y][x]];
180                 }
181         }
182         
183         // copy to screen
184         for(int y = 0; y < 36; y++) {
185                 scrntype* dest = emu->screen_buffer(y + 128);
186                 scrntype* src = screen[y];
187                 memcpy(dest, src, 256 * sizeof(scrntype));
188         }
189 }
190