OSDN Git Service

e20cd38a5c68e24ab525d5060dd20e61c638e83e
[csp-qt/common_source_project-fm7.git] / source / src / vm / fm7 / vram.cpp
1 /*
2  * Common source code project -> FM-7 -> Display -> Vram access
3  * (C) 2015 K.Ohta <whatisthis.sowhat _at_ gmail.com>
4  * History:
5  *  Sep 27, 2015 : Split from display.cpp .
6  */
7
8 #include "vm.h"
9 #include "emu.h"
10 #include "fm7_display.h"
11 #if defined(_FM77L4)
12 #include "hd46505.h"
13 #endif
14
15
16 void DISPLAY::draw_screen()
17 {
18 //#if !defined(_FM77AV_VARIANTS)
19         this->draw_screen2();
20 //#endif        
21 }
22
23 extern config_t config;
24 void DISPLAY::draw_screen2()
25 {
26         int y;
27         int x;
28         scrntype_t *p, *pp, *p2;
29         int yoff;
30         int yy;
31         int k;
32         //uint32_t rgbmask;
33         uint32_t yoff_d1, yoff_d2;
34         uint16_t wx_begin, wx_end, wy_low, wy_high;
35         bool scan_line = config.scan_line;
36         bool ff = force_update;
37
38 #if defined(_FM77AV40EX) || defined(_FM77AV40SX)
39         {
40                 wx_begin = window_xbegin;
41                 wx_end   = window_xend;
42                 wy_low   = window_low;
43                 wy_high  = window_high;
44                 bool _flag = window_opened; 
45                 if((wx_begin < wx_end) && (wy_low < wy_high)) {
46                         window_opened = true;
47                 } else {
48                         window_opened = false;
49                 }
50                 if(_flag != window_opened) {
51                         vram_wrote_shadow = true;
52                 }
53         }
54 #endif
55 //      frame_skip_count_draw++;
56 #if defined(_FM77AV_VARIANTS)
57         yoff_d2 = 0;
58         yoff_d1 = 0;
59 #else
60         //if(!(vram_wrote_shadow)) return;
61         yoff_d1 = yoff_d2 = offset_point;
62 #endif
63         // Set blank
64         int ylines;
65         int xpixels;
66         switch(display_mode) {
67         case DISPLAY_MODE_8_200L:
68                 xpixels = 640;
69                 ylines = 200;
70                 break;
71         case DISPLAY_MODE_8_400L:
72                 xpixels = 640;
73                 ylines = 400;
74                 break;
75         default:
76                 xpixels = 320;
77                 ylines = 200;
78                 break;
79         }
80 # if !defined(FIXED_FRAMEBUFFER_SIZE)
81         emu->set_vm_screen_size(xpixels, ylines, WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_WIDTH_ASPECT, WINDOW_HEIGHT_ASPECT);
82 # endif
83         emu->set_vm_screen_lines(ylines);
84         if(!crt_flag) {
85                 if(crt_flag_bak) {
86                         scrntype_t *ppp;
87 #if !defined(FIXED_FRAMEBUFFER_SIZE)
88                         for(y = 0; y < ylines; y += 8) {
89                                 for(yy = 0; yy < 8; yy++) {
90                                         vram_draw_table[y + yy] = false;
91                                         ppp = emu->get_screen_buffer(y + yy);
92                                         if(ppp != NULL) memset(ppp, 0x00, xpixels * sizeof(scrntype_t));
93                                 }
94                         }
95 #else
96                         for(y = 0; y < 400; y += 8) {
97                                 for(yy = 0; yy < 8; yy++) {
98                                         vram_draw_table[y + yy] = false;
99                                         ppp = emu->get_screen_buffer(y + yy);
100                                         if(ppp != NULL) memset(ppp, 0x00, 640 * sizeof(scrntype_t));
101                                 }
102                         }
103 #endif
104                         
105                 }
106                 crt_flag_bak = crt_flag;
107                 return;
108         }
109         crt_flag_bak = crt_flag;
110         if(!(vram_wrote_shadow | ff)) return;
111         vram_wrote_shadow = false;
112         if(display_mode == DISPLAY_MODE_8_200L) {
113                 int ii;
114                 yoff = 0;
115 #ifdef USE_GREEN_DISPLAY
116                 if(use_green_monitor) {
117                         // Green display had only connected to FM-8, FM-7/NEW7 and FM-77.
118                         for(y = 0; y < 200; y += 8) {
119                                 for(yy = 0; yy < 8; yy++) {
120                                         if(!(vram_draw_table[y + yy] | ff)) continue;
121                                         vram_draw_table[y + yy] = false;
122 #if !defined(FIXED_FRAMEBUFFER_SIZE)
123                                         p = emu->get_screen_buffer(y + yy);
124                                         p2 = NULL;
125 #else
126                                         p = emu->get_screen_buffer((y + yy) * 2);
127                                         p2 = emu->get_screen_buffer((y + yy) * 2 + 1);
128 #endif
129                                         if(p == NULL) continue;
130                                         yoff = (y + yy) * 80;
131                                         {
132                                                 for(x = 0; x < 10; x++) {
133                                                         for(ii = 0; ii < 8; ii++) {
134                                                                 GETVRAM_8_200L_GREEN(yoff + ii, p, p2, false, scan_line);
135 #if defined(FIXED_FRAMEBUFFER_SIZE)
136                                                                 p2 += 8;
137 #endif
138                                                                 p += 8;
139                                                         }
140                                                         yoff += 8;
141                                                 }
142                                         }
143                                 }
144                         }
145                         if(ff) force_update = false;
146                         return;
147                 }
148 #endif
149                 for(y = 0; y < 200; y += 8) {
150                         for(yy = 0; yy < 8; yy++) {
151                         
152                                 if(!(vram_draw_table[y + yy] | ff)) continue;
153                                 vram_draw_table[y + yy] = false;
154 #if !defined(FIXED_FRAMEBUFFER_SIZE)
155                                 p = emu->get_screen_buffer(y + yy);
156                                 p2 = NULL;
157 #else
158                                 p = emu->get_screen_buffer((y + yy) * 2);
159                                 p2 = emu->get_screen_buffer((y + yy) * 2 + 1);
160 #endif
161                                 if(p == NULL) continue;
162                                 yoff = (y + yy) * 80;
163 # if defined(_FM77AV40EX) || defined(_FM77AV40SX)
164                                 if(window_opened && (wy_low <= (y + yy)) && (wy_high > (y + yy))) {
165                                         for(x = 0; x < 80; x++) {
166                                                 if((x >= wx_begin) && (x < wx_end)) {
167                                                         GETVRAM_8_200L(yoff, p, p2, true, scan_line);
168                                                 } else {
169                                                         GETVRAM_8_200L(yoff, p, p2, false, scan_line);
170                                                 }
171 #if defined(FIXED_FRAMEBUFFER_SIZE)
172                                                 p2 += 8;
173 #endif
174                                                 p += 8;
175                                                 yoff++;
176                                         }
177                                 } else
178 # endif
179                                 {
180                                         for(x = 0; x < 10; x++) {
181                                                 for(ii = 0; ii < 8; ii++) {
182                                                         GETVRAM_8_200L(yoff + ii, p, p2, false, scan_line);
183 #if defined(FIXED_FRAMEBUFFER_SIZE)
184                                                         p2 += 8;
185 #endif
186                                                         p += 8;
187                                                 }
188                                                 yoff += 8;
189                                         }
190                                 }
191                         }
192                    
193                 }
194                 if(ff) force_update = false;
195                 return;
196         }
197 #if defined(_FM77L4)
198         if(display_mode == DISPLAY_MODE_1_400L) {
199                 int ii;
200                 uint8_t *regs = l4crtc->get_regs();
201                 cursor_start = (int)(regs[10] & 0x1f);
202                 cursor_end = (int)(regs[11] & 0x1f);
203                 cursor_type = (int)((regs[10] & 0x60) >> 5);
204                 text_xmax = (int)((uint16_t)regs[1] << 1);
205                 text_lines = (int)((regs[9] & 0x1f) + 1);
206                 text_ymax = (int)(regs[6] & 0x7f);
207                 yoff = 0;
208                 // Green display had only connected to FM-8, FM-7/NEW7 and FM-77.
209                 for(y = 0; y < 400; y += 8) {
210                         bool renderf = false;
211                         uint32_t naddr;
212                         uint8_t bitcode;
213                         uint8_t charcode;
214                         uint8_t attr_code;
215                         scrntype_t on_color;
216                         int xlim, ylim;
217                         bool do_green;
218                         if((y & 0x0f) == 0) {
219                                 for(yy = 0; yy < 16; yy++) renderf |= vram_draw_table[y + yy];
220                                 renderf = renderf | ff;
221                                 if(renderf) {
222                                         for(yy = 0; yy < 16; yy++) vram_draw_table[y + yy] = true;
223                                 }
224                         }
225                         if(use_green_monitor) {
226                                 for(yy = 0; yy < 8; yy++) {
227                                         if(!(vram_draw_table[y + yy] | ff)) continue;
228                                         vram_draw_table[y + yy] = false;
229                                         p = emu->get_screen_buffer(y + yy);
230                                         if(p == NULL) continue;
231                                         yoff = (y + yy) * 80;
232                                         for(x = 0; x < 10; x++) {
233                                                 for(ii = 0; ii < 8; ii++) {
234                                                         GETVRAM_1_400L_GREEN(yoff + ii, p);
235                                                         p += 8;
236                                                 }
237                                                 yoff += 8;
238                                         }
239                                 }
240                                 do_green = true;
241                         } else {
242                                 for(yy = 0; yy < 8; yy++) {
243                                         if(!(vram_draw_table[y + yy] | ff)) continue;
244                                         vram_draw_table[y + yy] = false;
245                                         p = emu->get_screen_buffer(y + yy);
246                                         if(p == NULL) continue;
247                                         yoff = (y + yy) * 80;
248                                         for(x = 0; x < 10; x++) {
249                                                 for(ii = 0; ii < 8; ii++) {
250                                                         GETVRAM_1_400L(yoff + ii, p);
251                                                         p += 8;
252                                                 }
253                                                 yoff += 8;
254                                         }
255                                 }
256                                 do_green = false;
257                         }
258                         // Draw Text
259                         if(renderf) {
260                                 bool reverse;
261                                 bool display_char;
262                                 int raster;
263                                 bool cursor_rev;
264                                 uint8_t bitdata;
265                                 if(text_width40) {
266                                         xlim = 40;
267                                 } else {
268                                         ylim = 80;
269                                 }
270                                 
271                                 for(x = 0; x < xlim; x++) {
272                                         naddr = (text_start_addr.w.l + ((y / text_lines) * text_xmax + x) * 2) & 0x0ffe;
273                                         charcode = text_vram[naddr];
274                                         attr_code = text_vram[naddr + 1];
275                                                 
276                                         on_color = GETVRAM_TEXTCOLOR(attr_code, do_green);
277                                         
278                                         display_char = ((attr_code & 0x10) == 0);
279                                         reverse = ((attr_code & 0x08) != 0);
280                                         
281                                         for(yy = 0; yy < 16; yy++) {
282                                                 raster = y % text_lines;
283                                                 bitdata = 0x00;
284                                                 p = emu->get_screen_buffer(y + yy);
285                                                 if(p == NULL) continue;
286                                                 if((raster < 16) && (display_char || text_blink)) {
287                                                         bitdata = subsys_cg_l4[(uint32_t)charcode * 16 + (uint32_t)raster];
288                                                 }
289                                                 cursor_rev = false;
290                                                 if((naddr == (uint32_t)(cursor_addr.w.l)) && (cursor_type != 1) &&
291                                                    (text_blink || (cursor_type == 0))) {
292                                                         if((raster >= cursor_start) && (raster <= cursor_end)) {
293                                                                 cursor_rev = true;
294                                                         }
295                                                 }
296                                                 bitdata = GETVRAM_TEXTPIX(bitdata, reverse, cursor_rev);
297                                                 if(bitdata != 0) {
298                                                         if(text_width40) {
299                                                                         scrntype_t *pp = &(p[x * 2]); 
300                                                                         for(ii = 0; ii < 8; ii++) {
301                                                                                 if((bitdata & 0x80) != 0) {
302                                                                                         p[0] = on_color;
303                                                                                         p[1] = on_color;
304                                                                                 }
305                                                                                 bitdata <<= 1;
306                                                                                 p += 2;
307                                                                         }                                                                               
308                                                         } else {
309                                                                 scrntype_t *pp = &(p[x * 2]); 
310                                                                 for(ii = 0; ii < 8; ii++) {
311                                                                         if((bitdata & 0x80) != 0) {
312                                                                                 p[0] = on_color;
313                                                                         }
314                                                                         bitdata <<= 1;
315                                                                         p += 1;
316                                                                 }                                                                               
317                                                         }
318                                                 }
319                                         }
320                                 }
321                         }
322                 }
323                 if(ff) force_update = false;
324                 return;
325         }
326 #endif
327 # if defined(_FM77AV_VARIANTS)
328         if(display_mode == DISPLAY_MODE_4096) {
329                 uint32_t mask = 0;
330                 int ii;
331                 yoff = 0;
332                 if(!multimode_dispflags[0]) mask = 0x00f;
333                 if(!multimode_dispflags[1]) mask = mask | 0x0f0;
334                 if(!multimode_dispflags[2]) mask = mask | 0xf00;
335                 for(y = 0; y < 200; y += 4) {
336                         for(yy = 0; yy < 4; yy++) {
337                                 if(!(vram_draw_table[y + yy] | ff)) continue;
338                                 vram_draw_table[y + yy] = false;
339
340 #if !defined(FIXED_FRAMEBUFFER_SIZE)
341                                 p = emu->get_screen_buffer(y + yy);
342                                 p2 = NULL;
343 #else
344                                 p = emu->get_screen_buffer((y + yy) * 2 );
345                                 p2 = emu->get_screen_buffer((y + yy) * 2 + 1);
346 #endif
347                                 if(p == NULL) continue;
348                                 yoff = (y + yy) * 40;
349 #  if defined(_FM77AV40EX) || defined(_FM77AV40SX)
350                                 if(window_opened && (wy_low <= (y + yy)) && (wy_high > (y + yy))) {
351                                         for(x = 0; x < 40; x++) {
352                                                 if((x >= wx_begin) && (x < wx_end)) {
353                                                         GETVRAM_4096(yoff, p, p2, mask, true, scan_line);
354                                                 } else {
355                                                         GETVRAM_4096(yoff, p, p2, mask, false, scan_line);
356                                                 }
357 #if defined(FIXED_FRAMEBUFFER_SIZE)
358                                                 p2 += 16;
359                                                 p += 16;
360 #else
361                                                 p += 8;
362 #endif
363                                                 yoff++;
364                                         }
365                                 } else
366 #  endif
367                                 {
368                                         for(x = 0; x < 5; x++) {
369                                                 for(ii = 0; ii < 8; ii++) {
370                                                         GETVRAM_4096(yoff + ii, p, p2, mask, false, scan_line);
371 #if defined(FIXED_FRAMEBUFFER_SIZE)
372                                                         p2 += 16;
373                                                         p += 16;
374 #else
375                                                         p += 8;
376 #endif
377                                                 }
378                                                 yoff += 8;
379                                         }
380                                 }
381                         }
382                    
383                 }
384                 if(ff) force_update = false;
385                 return;
386         }
387 #  if defined(_FM77AV40) || defined(_FM77AV40EX) || defined(_FM77AV40SX)
388         else if(display_mode == DISPLAY_MODE_8_400L) {
389                 int ii;
390                 yoff = 0;
391                 //rgbmask = ~multimode_dispmask;
392                 for(y = 0; y < 400; y += 8) {
393                         for(yy = 0; yy < 8; yy++) {
394                                 if(!(vram_draw_table[y + yy] | ff)) continue;
395                                 vram_draw_table[y + yy] = false;
396
397                                 p = emu->get_screen_buffer(y + yy);
398                                 if(p == NULL) continue;
399                                 pp = p;
400                                 yoff = (y + yy) * 80;
401 #    if defined(_FM77AV40EX) || defined(_FM77AV40SX)
402                                 if(window_opened && (wy_low <= (y + yy)) && (wy_high  > (y + yy))) {
403                                         for(x = 0; x < 80; x++) {
404                                                 if((x >= wx_begin) && (x < wx_end)) {
405                                                         GETVRAM_8_400L(yoff, p, true);
406                                                 } else {
407                                                         GETVRAM_8_400L(yoff, p, false);
408                                                 }
409                                                 p += 8;
410                                                 yoff++;
411                                         }
412                                 } else
413 #    endif
414                                         for(x = 0; x < 10; x++) {
415
416                                                 for(ii = 0; ii < 8; ii++) {
417                                                         GETVRAM_8_400L(yoff + ii, p);
418                                                         p += 8;
419                                                 }
420                                                 yoff += 8;
421                                         }
422                         }
423                 }
424                 if(ff) force_update = false;
425                 return;
426         } else if(display_mode == DISPLAY_MODE_256k) {
427                 int ii;
428                 //rgbmask = ~multimode_dispmask;
429                 //
430                 for(y = 0; y < 200; y += 4) {
431                         for(yy = 0; yy < 4; yy++) {
432                                 if(!(vram_draw_table[y + yy] | ff)) continue;
433                                 vram_draw_table[y + yy] = false;
434 #if !defined(FIXED_FRAMEBUFFER_SIZE)
435                                 p = emu->get_screen_buffer(y + yy);
436                                 p2 = NULL;
437 #else
438                                 p = emu->get_screen_buffer((y + yy) * 2 );
439                                 p2 = emu->get_screen_buffer((y + yy) * 2 + 1);
440 #endif
441                                 if(p == NULL) continue;
442                                 pp = p;
443                                 yoff = (y + yy) * 40;
444                                 {
445                                         for(x = 0; x < 5; x++) {
446                                                 for(ii = 0; ii < 8; ii++) {
447                                                         GETVRAM_256k(yoff + ii, p, p2, scan_line);
448 #if !defined(FIXED_FRAMEBUFFER_SIZE)
449                                                         p += 8;
450 #else
451                                                         p += 16;
452                                                         p2 += 16;
453 #endif
454                                                 }
455                                                 yoff += 8;
456                                         }
457                                 }
458                         }
459                 }
460                 if(ff) force_update = false;
461                 return;
462         }
463 #  endif // _FM77AV40
464 # endif //_FM77AV_VARIANTS
465 }
466
467 bool DISPLAY::screen_update(void)
468 {
469         if(crt_flag) {
470                 bool f = screen_update_flag;
471                 screen_update_flag = false;
472                 return f;
473         } else {
474                 if(crt_flag_bak) return true;
475         }
476         return false;
477 }
478
479 void DISPLAY::reset_screen_update(void)
480 {
481         screen_update_flag = false;
482 }
483
484 void DISPLAY::GETVRAM_8_200L(int yoff, scrntype_t *p,
485                                                          scrntype_t *px,
486                                                          bool window_inv,
487                                                          bool scan_line)
488 {
489         uint8_t b, r, g;
490         uint32_t yoff_d;
491 #if defined(_FM77AV40EX) || defined(_FM77AV40SX)
492         int dpage = vram_display_block;
493 #endif
494         if(p == NULL) return;
495         yoff_d = 0;
496         yoff_d = (yoff + yoff_d) & 0x3fff;
497
498 #if defined(_FM77AV40EX) || defined(_FM77AV40SX)
499         if(window_inv) {
500                 if(dpage == 0) {
501                         dpage = 1;
502                 } else {
503                         dpage = 0;
504                 }
505         }
506         if(dpage != 0) yoff_d += 0x18000;
507 #endif
508         b = r = g = 0;
509 #if defined(_FM77AV_VARIANTS)
510         if(display_page_bak == 1) yoff_d += 0xc000;
511 #endif
512         if(!multimode_dispflags[0]) b = gvram_shadow[yoff_d + 0x00000];
513         if(!multimode_dispflags[1]) r = gvram_shadow[yoff_d + 0x04000];
514         if(!multimode_dispflags[2]) g = gvram_shadow[yoff_d + 0x08000];
515
516         uint16_t *pg = &(bit_trans_table_0[g][0]);
517         uint16_t *pr = &(bit_trans_table_1[r][0]);
518         uint16_t *pb = &(bit_trans_table_2[b][0]);
519         uint16_t tmp_d[8];
520         scrntype_t tmp_dd[8];
521
522 __DECL_VECTORIZED_LOOP
523         for(int i = 0; i < 8; i++) {
524                 tmp_d[i] = pr[i];
525                 tmp_d[i]  = tmp_d[i] | pg[i];
526                 tmp_d[i]  = tmp_d[i] | pb[i];
527                 tmp_d[i] = tmp_d[i] >> 5;
528         }
529
530 __DECL_VECTORIZED_LOOP
531         for(int i = 0; i < 8; i++) {
532                 tmp_dd[i] = dpalette_pixel[tmp_d[i]];
533         }
534 #if defined(FIXED_FRAMEBUFFER_SIZE)
535         if(scan_line) {
536 /* Fancy scanline */
537         #if defined(_RGB555) || defined(_RGBA565)
538                 static const int shift_factor = 2;
539         #else // 24bit
540                 static const int shift_factor = 3;
541         #endif
542 __DECL_VECTORIZED_LOOP
543                 for(int i = 0; i < 8; i++) {
544                         p[i] = tmp_dd[i];
545                         tmp_dd[i] = (tmp_dd[i] >> shift_factor) & (const scrntype_t)RGBA_COLOR(31, 31, 31, 255);;
546                         px[i] = tmp_dd[i];
547                 }
548         } else {
549 __DECL_VECTORIZED_LOOP
550                 for(int i = 0; i < 8; i++) {
551                         p[i] = tmp_dd[i];
552                         px[i] = tmp_dd[i];
553                 }
554         }
555 #else
556 __DECL_VECTORIZED_LOOP
557         for(int i = 0; i < 8; i++) {
558                 p[i] = tmp_dd[i];
559         }
560 #endif  
561 }
562
563 #if defined(_FM77L4)
564 scrntype_t DISPLAY::GETVRAM_TEXTCOLOR(uint8_t attr, bool do_green)
565 {
566         int color = attr & 0x07;
567         int r, g, b;
568
569         static const int green_g_table[16] = {0, 24, 48, 64, 80, 96, 112, 128,
570                                                                                   140, 155, 175, 186, 210, 220, 240, 255};
571         if(do_green) {
572                 if((attr & 0x20) != 0) color += 8;
573                 r = b = 0;
574                 g = green_g_table[color];
575                 if(color >= 10) {
576                         r = (color - 9) * 16;
577                         b = (color - 9) * 16;
578                 }
579         } else {
580                 if((attr & 0x20) != 0) {
581                         g = ((color & 4) != 0) ? 255 : 0;
582                         r = ((color & 2) != 0) ? 255 : 0;
583                         b = ((color & 1) != 0) ? 255 : 0;
584                 } else {
585                         g = ((color & 4) != 0) ? 128 : 0;
586                         r = ((color & 2) != 0) ? 128 : 0;
587                         b = ((color & 1) != 0) ? 128 : 0;
588                 }
589         }
590         return RGBA_COLOR(r, g, b, 255);
591 }
592
593 uint8_t DISPLAY::GETVRAM_TEXTPIX(uint8_t bitdata, bool reverse, bool cursor_rev)
594 {
595         uint8_t ret = bitdata;
596         if(reverse) {
597                 ret = (uint8_t)(~ret);
598         }
599         if(cursor_rev) {
600             ret = (uint8_t)(~ret);
601         }
602         return ret;
603 }
604
605 void DISPLAY::GETVRAM_1_400L(int yoff, scrntype_t *p)
606 {
607         uint8_t pixel;
608         uint32_t yoff_d;
609         if(p == NULL) return;
610         yoff_d = yoff & 0x7fff;
611         pixel = gvram_shadow[yoff_d];
612         uint16_t *ppx = &(bit_trans_table_0[pixel][0]);
613         uint16_t tmp_d[8];
614         scrntype_t tmp_dd[8];
615         
616 __DECL_VECTORIZED_LOOP
617         for(int i = 0; i < 8; i++) {
618                 tmp_d[i] = ppx[i];
619                 tmp_d[i] = tmp_d[i] >> 5;
620         }
621
622 __DECL_VECTORIZED_LOOP
623         for(int i = 0; i < 8; i++) {
624                 tmp_dd[i] = dpalette_pixel[tmp_d[i]];
625                 p[i] = tmp_dd[i];
626         }
627         
628 }
629
630 void DISPLAY::GETVRAM_1_400L_GREEN(int yoff, scrntype_t *p)
631 {
632         uint8_t pixel;
633         uint32_t yoff_d;
634         if(p == NULL) return;
635         yoff_d = yoff & 0x7fff;
636         pixel = gvram_shadow[yoff_d];
637         uint16_t *ppx = &(bit_trans_table_0[pixel][0]);
638         uint16_t tmp_d[8];
639         scrntype_t tmp_dd[8];
640         
641 __DECL_VECTORIZED_LOOP
642         for(int i = 0; i < 8; i++) {
643                 tmp_d[i] = ppx[i];
644                 tmp_d[i] = tmp_d[i] >> 5;
645         }
646
647 __DECL_VECTORIZED_LOOP
648         for(int i = 0; i < 8; i++) {
649                 tmp_dd[i] = dpalette_pixel_green[tmp_d[i]];
650                 p[i] = tmp_dd[i];
651         }
652         
653 }
654 #endif
655
656 #if defined(USE_GREEN_DISPLAY)
657 void DISPLAY::GETVRAM_8_200L_GREEN(int yoff, scrntype_t *p,
658                                                          scrntype_t *px,
659                                                          bool window_inv,
660                                                          bool scan_line)
661 {
662         uint8_t b, r, g;
663         uint32_t yoff_d;
664 #if defined(_FM77AV40EX) || defined(_FM77AV40SX)
665         int dpage = vram_display_block;
666 #endif
667         if(p == NULL) return;
668         yoff_d = 0;
669         yoff_d = (yoff + yoff_d) & 0x3fff;
670
671         b = r = g = 0;
672         if(!multimode_dispflags[0]) b = gvram_shadow[yoff_d + 0x00000];
673         if(!multimode_dispflags[1]) r = gvram_shadow[yoff_d + 0x04000];
674         if(!multimode_dispflags[2]) g = gvram_shadow[yoff_d + 0x08000];
675
676         uint16_t *pg = &(bit_trans_table_0[g][0]);
677         uint16_t *pr = &(bit_trans_table_1[r][0]);
678         uint16_t *pb = &(bit_trans_table_2[b][0]);
679         uint16_t tmp_d[8];
680         scrntype_t tmp_dd[8];
681
682 __DECL_VECTORIZED_LOOP
683         for(int i = 0; i < 8; i++) {
684                 tmp_d[i] = pr[i];
685                 tmp_d[i]  = tmp_d[i] | pg[i];
686                 tmp_d[i]  = tmp_d[i] | pb[i];
687                 tmp_d[i] = tmp_d[i] >> 5;
688         }
689
690 __DECL_VECTORIZED_LOOP
691         for(int i = 0; i < 8; i++) {
692                 tmp_dd[i] = dpalette_pixel_green[tmp_d[i]];
693         }
694 #if defined(FIXED_FRAMEBUFFER_SIZE)
695         if(scan_line) {
696 /* Fancy scanline */
697         #if defined(_RGB555) || defined(_RGBA565)
698                 static const int shift_factor = 2;
699         #else // 24bit
700                 static const int shift_factor = 3;
701         #endif
702 __DECL_VECTORIZED_LOOP
703                 for(int i = 0; i < 8; i++) {
704                         p[i] = tmp_dd[i];
705                         tmp_dd[i] = (tmp_dd[i] >> shift_factor) & (const scrntype_t)RGBA_COLOR(31, 31, 31, 255);;
706                         px[i] = tmp_dd[i];
707                 }
708         } else {
709 __DECL_VECTORIZED_LOOP
710                 for(int i = 0; i < 8; i++) {
711                         p[i] = tmp_dd[i];
712                         px[i] = tmp_dd[i];
713                 }
714         }
715 #else
716 __DECL_VECTORIZED_LOOP
717         for(int i = 0; i < 8; i++) {
718                 p[i] = tmp_dd[i];
719         }
720 #endif  
721 }
722 #endif
723
724 #if defined(_FM77AV_VARIANTS)
725 void DISPLAY::GETVRAM_4096(int yoff, scrntype_t *p, scrntype_t *px,
726                                                    uint32_t mask,
727                                                    bool window_inv,
728                                                    bool scan_line)
729 {
730         uint32_t b3, r3, g3;
731         uint8_t  bb[4], rr[4], gg[4];
732         uint16_t pixels[8];
733         const uint16_t __masks[8] = {(uint16_t)mask, (uint16_t)mask, (uint16_t)mask, (uint16_t)mask, (uint16_t)mask, (uint16_t)mask, (uint16_t)mask, (uint16_t)mask};
734         scrntype_t b, r, g;
735         uint32_t idx;;
736         scrntype_t pixel;
737         uint32_t yoff_d1;
738         uint32_t yoff_d2;
739 # if defined(_FM77AV40EX) || defined(_FM77AV40SX)
740         int dpage = vram_display_block;
741 # endif
742         if(p == NULL) return;
743         
744         yoff_d1 = yoff;
745         yoff_d2 = yoff;
746 # if defined(_FM77AV40EX) || defined(_FM77AV40SX)
747         if(window_inv) {
748                 if(dpage == 0) {
749                         dpage = 1;
750                 } else {
751                         dpage = 0;
752                 }
753         }
754         if(dpage != 0) {
755                 yoff_d1 += 0x18000;
756                 yoff_d2 += 0x18000;
757         }
758 # endif
759         bb[0] = gvram_shadow[yoff_d1];
760         bb[1] = gvram_shadow[yoff_d1 + 0x02000];
761         rr[0] = gvram_shadow[yoff_d1 + 0x04000];
762         rr[1] = gvram_shadow[yoff_d1 + 0x06000];
763                 
764         gg[0] = gvram_shadow[yoff_d1 + 0x08000];
765         gg[1] = gvram_shadow[yoff_d1 + 0x0a000];
766                 
767         bb[2] = gvram_shadow[yoff_d2 + 0x0c000];
768         bb[3] = gvram_shadow[yoff_d2 + 0x0e000];
769                 
770         rr[2] = gvram_shadow[yoff_d2 + 0x10000];
771         rr[3] = gvram_shadow[yoff_d2 + 0x12000];
772         gg[2] = gvram_shadow[yoff_d2 + 0x14000];
773         gg[3] = gvram_shadow[yoff_d2 + 0x16000];
774
775         uint16_t tmp_g[8], tmp_r[8], tmp_b[8];
776         uint16_t *p0, *p1, *p2, *p3;
777 #if !defined(FIXED_FRAMEBUFFER_SIZE)
778         scrntype_t tmp_dd[8];
779 #else
780         scrntype_t tmp_dd[16];
781 #endif
782         // G
783         p0 = &(bit_trans_table_0[gg[0]][0]);
784         p1 = &(bit_trans_table_1[gg[1]][0]);
785         p2 = &(bit_trans_table_2[gg[2]][0]);
786         p3 = &(bit_trans_table_3[gg[3]][0]);
787 __DECL_VECTORIZED_LOOP
788         for(int i = 0; i < 8; i++) {
789                 tmp_g[i]  = p0[i];
790                 tmp_g[i]  = tmp_g[i] | p1[i];
791                 tmp_g[i]  = tmp_g[i] | p2[i];
792                 tmp_g[i]  = tmp_g[i] | p3[i];
793         }
794         // R
795         p0 = &(bit_trans_table_0[rr[0]][0]);
796         p1 = &(bit_trans_table_1[rr[1]][0]);
797         p2 = &(bit_trans_table_2[rr[2]][0]);
798         p3 = &(bit_trans_table_3[rr[3]][0]);
799 __DECL_VECTORIZED_LOOP
800         for(int i = 0; i < 8; i++) {
801                 tmp_r[i]  = p0[i];
802                 tmp_r[i]  = tmp_r[i] | p1[i];
803                 tmp_r[i]  = tmp_r[i] | p2[i];
804                 tmp_r[i]  = tmp_r[i] | p3[i];
805         }
806         // B
807         p0 = &(bit_trans_table_0[bb[0]][0]);
808         p1 = &(bit_trans_table_1[bb[1]][0]);
809         p2 = &(bit_trans_table_2[bb[2]][0]);
810         p3 = &(bit_trans_table_3[bb[3]][0]);
811 __DECL_VECTORIZED_LOOP
812         for(int i = 0; i < 8; i++) {
813                 tmp_b[i]  = p0[i];
814                 tmp_b[i]  = tmp_b[i] | p1[i];
815                 tmp_b[i]  = tmp_b[i] | p2[i];
816                 tmp_b[i]  = tmp_b[i] | p3[i];
817         }
818 __DECL_VECTORIZED_LOOP
819         for(int i = 0; i < 8; i++) {
820                 tmp_g[i] <<= 4;
821                 pixels[i] = tmp_b[i] >> 4;
822                 pixels[i] = pixels[i] | tmp_r[i];
823                 pixels[i] = pixels[i] | tmp_g[i];
824                 pixels[i] = pixels[i] & __masks[i];
825         }
826         //for(int i = 0; i < 8; i++) {
827         //      pixels[i] = pixels[i] & mask;
828         //}
829 #if !defined(FIXED_FRAMEBUFFER_SIZE)
830 __DECL_VECTORIZED_LOOP
831         for(int i = 0; i < 8; i++) {
832                 tmp_dd[i] = analog_palette_pixel[pixels[i]];
833                 p[i] = tmp_dd[i];
834         }
835 #else
836 __DECL_VECTORIZED_LOOP
837         for(int i = 0; i < 8; i++) {
838                 tmp_dd[i * 2] = tmp_dd[i * 2 + 1] = analog_palette_pixel[pixels[i]];;
839         }
840 __DECL_VECTORIZED_LOOP
841         for(int i = 0; i < 16; i++) {
842                 p[i] = tmp_dd[i];
843         }
844         if(scan_line) {
845 /* Fancy scanline */
846 __DECL_VECTORIZED_LOOP
847                 for(int i = 0; i < 16; i++) {
848 #if defined(_RGB888) || defined(_RGBA888)
849                         tmp_dd[i] = tmp_dd[i] >> 3;
850 #elif defined(_RGB555)
851                         tmp_dd[i] = tmp_dd[i] >> 2;
852 #elif defined(_RGB565)
853                         tmp_dd[i] = tmp_dd[i] >> 2;
854 #endif
855                 }
856 __DECL_VECTORIZED_LOOP
857                 for(int i = 0; i < 16; i++) {
858                         tmp_dd[i] = tmp_dd[i] & (const scrntype_t)RGBA_COLOR(31, 31, 31, 255);
859                         px[i] = tmp_dd[i];
860                 }
861         } else {
862 __DECL_VECTORIZED_LOOP
863                 for(int i = 0; i < 16; i++) {
864                         px[i] = tmp_dd[i];
865                 }
866         }
867 #endif
868
869 }
870 #endif
871
872 #if defined(_FM77AV40) || defined(_FM77AV40EX) || defined(_FM77AV40SX)
873 void DISPLAY::GETVRAM_8_400L(int yoff, scrntype_t *p,
874                                                          bool window_inv)
875 {
876         uint8_t b, r, g;
877         uint32_t dot;
878         uint32_t yoff_d;
879 # if defined(_FM77AV40EX) || defined(_FM77AV40SX)
880         int dpage = vram_display_block;
881 # endif
882         if(p == NULL) return;
883         yoff_d = yoff;
884 # if defined(_FM77AV40EX) || defined(_FM77AV40SX)
885         if(window_inv) {
886                 if(dpage == 0) {
887                         dpage = 1;
888                 } else {
889                         dpage = 0;
890                 }
891         }
892         if(dpage != 0) yoff_d += 0x18000;
893 # endif
894         b = r = g = 0;
895         if(!multimode_dispflags[0]) b = gvram_shadow[yoff_d + 0x00000];
896         if(!multimode_dispflags[1]) r = gvram_shadow[yoff_d + 0x08000];
897         if(!multimode_dispflags[2]) g = gvram_shadow[yoff_d + 0x10000];
898
899         uint16_t *pg = &(bit_trans_table_0[g][0]);
900         uint16_t *pr = &(bit_trans_table_1[r][0]);
901         uint16_t *pb = &(bit_trans_table_2[b][0]);
902         uint16_t tmp_d[8];
903
904 __DECL_VECTORIZED_LOOP
905         for(int i = 0; i < 8; i++) {
906                 tmp_d[i] = pg[i] | pr[i] | pb[i];
907                 tmp_d[i] = tmp_d[i] >> 5;
908         }               
909 __DECL_VECTORIZED_LOOP
910         for(int i = 0; i < 8; i++) {
911                 p[i] = dpalette_pixel[tmp_d[i]];
912         }
913 }
914
915 void DISPLAY::GETVRAM_256k(int yoff, scrntype_t *p, scrntype_t *px, bool scan_line)
916 {
917         uint32_t b3, r3, g3;
918         uint32_t b4, r4, g4;
919         uint32_t btmp, rtmp, gtmp;
920         
921         scrntype_t b, r, g;
922         scrntype_t pixel;
923         uint32_t _bit;
924         int _shift;
925         int cp;
926         uint32_t yoff_d1;
927         uint32_t yoff_d2;
928         if(p == NULL) return;
929         
930         r3 = g3 = b3 = 0;
931         r4 = g4 = b4 = 0;
932         r = g = b = 0;
933         
934         yoff_d1 = yoff;
935         yoff_d2 = yoff;
936
937         uint8_t  bb[8], rr[8], gg[8];
938         uint16_t *p0, *p1, *p2, *p3, *p4, *p5;
939         uint32_t _btmp[8], _rtmp[8], _gtmp[8];
940 #if !defined(FIXED_FRAMEBUFFER_SIZE)
941         scrntype_t tmp_dd[8];
942 #else
943         scrntype_t tmp_dd[16];
944 #endif
945 //      if(mask & 0x01) {
946         if(!multimode_dispflags[0]) {
947                 // B
948                 bb[0] = gvram_shadow[yoff_d1];
949                 bb[1] = gvram_shadow[yoff_d1 + 0x02000];
950                 
951                 bb[2] = gvram_shadow[yoff_d2 + 0x0c000];
952                 bb[3] = gvram_shadow[yoff_d2 + 0x0e000];
953         
954                 bb[4] = gvram_shadow[yoff_d1 + 0x18000];
955                 bb[5] = gvram_shadow[yoff_d1 + 0x1a000];
956                 
957                 p0 = &(bit_trans_table_0[bb[0]][0]);
958                 p1 = &(bit_trans_table_1[bb[1]][0]);
959                 p2 = &(bit_trans_table_2[bb[2]][0]);
960                 p3 = &(bit_trans_table_3[bb[3]][0]);
961                 p4 = &(bit_trans_table_4[bb[4]][0]);
962                 p5 = &(bit_trans_table_5[bb[5]][0]);
963 __DECL_VECTORIZED_LOOP
964                 for(int i = 0; i < 8; i++) {
965                         _btmp[i] = p0[i];
966                         _btmp[i] = _btmp[i] | p1[i];
967                         _btmp[i] = _btmp[i] | p2[i];
968                         _btmp[i] = _btmp[i] | p3[i];
969                         _btmp[i] = _btmp[i] | p4[i];
970                         _btmp[i] = _btmp[i] | p5[i];
971                 }
972         } else {
973 __DECL_VECTORIZED_LOOP
974                 for(int i = 0; i < 8; i++) {
975                         _btmp[i] = 0;
976                 }
977         }
978         if(!multimode_dispflags[1]) {
979                 //if(mask & 0x02) {
980                 // R
981                 rr[0] = gvram_shadow[yoff_d1 + 0x04000];
982                 rr[1] = gvram_shadow[yoff_d1 + 0x06000];
983                 
984                 rr[2] = gvram_shadow[yoff_d2 + 0x10000];
985                 rr[3] = gvram_shadow[yoff_d2 + 0x12000];
986         
987                 rr[4] = gvram_shadow[yoff_d1 + 0x1c000];
988                 rr[5] = gvram_shadow[yoff_d1 + 0x1e000];
989                 
990                 p0 = &(bit_trans_table_0[rr[0]][0]);
991                 p1 = &(bit_trans_table_1[rr[1]][0]);
992                 p2 = &(bit_trans_table_2[rr[2]][0]);
993                 p3 = &(bit_trans_table_3[rr[3]][0]);
994                 p4 = &(bit_trans_table_4[rr[4]][0]);
995                 p5 = &(bit_trans_table_5[rr[5]][0]);
996 __DECL_VECTORIZED_LOOP
997                 for(int i = 0; i < 8; i++) {
998                         _rtmp[i] = p0[i];
999                         _rtmp[i] = _rtmp[i] | p1[i];
1000                         _rtmp[i] = _rtmp[i] | p2[i];
1001                         _rtmp[i] = _rtmp[i] | p3[i];
1002                         _rtmp[i] = _rtmp[i] | p4[i];
1003                         _rtmp[i] = _rtmp[i] | p5[i];
1004                 }
1005         } else {
1006 __DECL_VECTORIZED_LOOP
1007                 for(int i = 0; i < 8; i++) {
1008                         _rtmp[i] = 0;
1009                 }
1010         }
1011         if(!multimode_dispflags[2]) {
1012                 //if(mask & 0x04) {
1013                 // G
1014                 gg[0] = gvram_shadow[yoff_d1 + 0x08000];
1015                 gg[1] = gvram_shadow[yoff_d1 + 0x0a000];
1016                 
1017                 gg[2] = gvram_shadow[yoff_d2 + 0x14000];
1018                 gg[3] = gvram_shadow[yoff_d2 + 0x16000];
1019         
1020                 gg[4] = gvram_shadow[yoff_d1 + 0x20000];
1021                 gg[5] = gvram_shadow[yoff_d1 + 0x22000];
1022                 
1023                 p0 = &(bit_trans_table_0[gg[0]][0]);
1024                 p1 = &(bit_trans_table_1[gg[1]][0]);
1025                 p2 = &(bit_trans_table_2[gg[2]][0]);
1026                 p3 = &(bit_trans_table_3[gg[3]][0]);
1027                 p4 = &(bit_trans_table_4[gg[4]][0]);
1028                 p5 = &(bit_trans_table_5[gg[5]][0]);
1029 __DECL_VECTORIZED_LOOP
1030                 for(int i = 0; i < 8; i++) {
1031                         _gtmp[i] = p0[i];
1032                         _gtmp[i] = _gtmp[i] | p1[i];
1033                         _gtmp[i] = _gtmp[i] | p2[i];
1034                         _gtmp[i] = _gtmp[i] | p3[i];
1035                         _gtmp[i] = _gtmp[i] | p4[i];
1036                         _gtmp[i] = _gtmp[i] | p5[i];
1037                 }
1038         } else {
1039 __DECL_VECTORIZED_LOOP
1040                 for(int i = 0; i < 8; i++) {
1041                         _gtmp[i] = 0;
1042                 }
1043         }
1044 #if !defined(FIXED_FRAMEBUFFER_SIZE)
1045 __DECL_VECTORIZED_LOOP
1046         for(int i = 0; i < 8; i++) {
1047                 tmp_dd[i] = RGB_COLOR(_rtmp[i], _gtmp[i], _btmp[i]);
1048                 p[i] = tmp_dd[i];
1049         }
1050 #else
1051 __DECL_VECTORIZED_LOOP
1052         for(int i = 0; i < 8; i++) {
1053                 tmp_dd[i * 2] = tmp_dd[i * 2 + 1] = RGB_COLOR(_rtmp[i], _gtmp[i], _btmp[i]);
1054         }
1055 __DECL_VECTORIZED_LOOP
1056         for(int i = 0; i < 16; i++) {
1057                 p[i] = tmp_dd[i];
1058         }
1059         if(scan_line) {
1060 /* Fancy scanline */
1061 __DECL_VECTORIZED_LOOP
1062                 for(int i = 0; i < 16; i++) {
1063 #if defined(_RGB888) || defined(_RGBA888)
1064                         tmp_dd[i] = tmp_dd[i] >> 3;
1065 #elif defined(_RGB555)
1066                         tmp_dd[i] = tmp_dd[i] >> 2;
1067 #elif defined(_RGB565)
1068                         tmp_dd[i] = tmp_dd[i] >> 2;
1069 #endif
1070                 }
1071 __DECL_VECTORIZED_LOOP
1072                 for(int i = 0; i < 16; i++) {
1073                         tmp_dd[i] = tmp_dd[i] & RGBA_COLOR(31, 31, 31, 256);
1074                         px[i] = tmp_dd[i];
1075                 }
1076         } else {
1077 __DECL_VECTORIZED_LOOP
1078                 for(int i = 0; i < 16; i++) {
1079                         px[i] = tmp_dd[i];
1080                 }
1081         }
1082 #endif  
1083 }
1084 #endif