OSDN Git Service

db21fe555ffb4634006925669b7d278ab9913258
[csp-qt/common_source_project-fm7.git] / source / src / vm / pc6001 / memory_draw.cpp
1 /** iP6: PC-6000/6600 series emualtor ************************/
2 /**                                                         **/
3 /**                         Refresh.c                       **/
4 /**                                                         **/
5 /** modified by Windy 2002-2004                             **/
6 /** by ISHIOKA Hiroshi 1998,1999                            **/
7 /** This code is based on fMSX written by Marat Fayzullin   **/
8 /** and Adaptions for any X-terminal by Arnold Metselaar    **/
9 /*************************************************************/
10
11 /*
12         NEC PC-6001 Emulator 'yaPC-6001'
13         NEC PC-6001mkII Emulator 'yaPC-6201'
14         NEC PC-6001mkIISR Emulator 'yaPC-6401'
15         NEC PC-6601 Emulator 'yaPC-6601'
16         NEC PC-6601SR Emulator 'yaPC-6801'
17
18         Author : tanam
19         Date   : 2013.07.15-
20
21         [ draw ]
22 */
23
24 #include "memory.h"
25
26 #define CGROM1          (MEMORY_BASE + CGROM1_BASE)
27 #define CGROM5          (MEMORY_BASE + CGROM5_BASE)
28 #define CGROM6          (MEMORY_BASE + CGROM6_BASE)
29
30 #define SETSCRVARM1(y1) dest = &screen[y1][0];W=0;
31 #define SETSCRVARM5(y1) dest = &screen[y1][0];W=0;
32 #define M1HEIGHT 192
33 #define M5HEIGHT 200
34 #define M6HEIGHT 204
35 #define SeqPix21(c) dest[X*8+W]=c;W++;
36 #define SeqPix41(c) dest[X*8+W]=c;W++;dest[X*8+W]=c;W++;
37
38 void PC6001_MEMORY::draw_screen()
39 {
40         if (CRTKILL) {
41                 for(int y = 0; y < 400; y++) {
42                         scrntype_t* dest = emu->get_screen_buffer(y);
43                         memset(dest, 0, 640 * sizeof(scrntype_t));
44                 }
45 #if defined(_PC6601SR) || defined(_PC6001MK2SR)
46         } else if (static_cast<VM *>(vm)->sr_mode) {
47                 if (CRTMode2) {
48                         if (CRTMode3) RefreshScr63();
49                         else RefreshScr62();
50                 } else RefreshScr61();
51                 // copy to screen
52                 emu->set_vm_screen_lines(200);
53                 if (bitmap) {
54                         for(int y = 0; y < 200; y++) {
55                                 scrntype_t* dest = emu->get_screen_buffer(y*2);
56                                 scrntype_t* dest1 = emu->get_screen_buffer(y*2+1);
57                                 for(int x = 0; x < 320; x++) {
58                                         dest[x*2] = dest[x*2+1] = palette_pc[screen[y][x*2]];
59                                 }
60                                 if(config.scan_line) {
61                                         memset(dest1, 0, 640 * sizeof(scrntype_t));
62                                 } else {
63                                         my_memcpy(dest1, dest, 640 * sizeof(scrntype_t));
64                                 }
65                         }
66                 } else if (cols==40) {
67                         for(int y = 0; y < 200; y++) {
68                                 scrntype_t* dest = emu->get_screen_buffer(y*2);
69                                 scrntype_t* dest1 = emu->get_screen_buffer(y*2+1);
70                                 for(int x = 0; x < 320; x++) {
71                                         dest[x*2] = dest[x*2+1] = palette_pc[screen[y][x]];
72                                 }
73                                 if(config.scan_line) {
74                                         memset(dest1, 0, 640 * sizeof(scrntype_t));
75                                 } else {
76                                         my_memcpy(dest1, dest, 640 * sizeof(scrntype_t));
77                                 }
78                         }
79                 } else {
80                         for(int y = 0; y < 200; y++) {
81                                 scrntype_t* dest = emu->get_screen_buffer(y*2);
82                                 scrntype_t* dest1 = emu->get_screen_buffer(y*2+1);
83                                 for(int x = 0; x < 640; x++) {
84                                         dest[x] = palette_pc[screen[y][x]];
85                                 }
86                                 if(config.scan_line) {
87                                         memset(dest1, 0, 640 * sizeof(scrntype_t));
88                                 } else {
89                                         my_memcpy(dest1, dest, 640 * sizeof(scrntype_t));
90                                 }
91                         }
92                 }
93 #endif
94         } else {
95                 if (CRTMode1) {
96                         if (CRTMode2)
97                                 if (CRTMode3) RefreshScr54();
98                                 else RefreshScr53();
99                         else RefreshScr51();
100                         // copy to screen
101                         emu->set_vm_screen_lines(200);
102                         for(int y = 0; y < 200; y++) {
103                                 scrntype_t* dest = emu->get_screen_buffer(y*2);
104                                 scrntype_t* dest1 = emu->get_screen_buffer(y*2+1);
105                                 for(int x = 0; x < 320; x++) {
106                                         dest[x*2] = dest[x*2+1] = palette_pc[screen[y][x]];
107                                 }
108                                 if(config.scan_line) {
109                                         memset(dest1, 0, 640 * sizeof(scrntype_t));
110                                 } else {
111                                         my_memcpy(dest1, dest, 640 * sizeof(scrntype_t));
112                                 }
113                         }
114                 } else {
115                         RefreshScr10();
116                         // copy to screen
117                         emu->set_vm_screen_lines(200);
118                         for(int y = 0; y < 200; y++) {
119                                 scrntype_t* dest = emu->get_screen_buffer(y*2);
120                                 scrntype_t* dest1 = emu->get_screen_buffer(y*2+1);
121                                 for(int x = 0; x < 320; x++) {
122                                         if (x >= 32 && x < 288 && y >=4 && y < 196) {
123                                                 dest[x*2] = dest[x*2+1] = palette_pc[screen[y-4][x-32]];
124                                         } else {
125                                                 dest[x*2] = dest[x*2+1] = palette_pc[8];
126                                         }
127                                 }
128                                 if(config.scan_line) {
129                                         memset(dest1, 0, 640 * sizeof(scrntype_t));
130                                 } else {
131                                         my_memcpy(dest1, dest, 640 * sizeof(scrntype_t));
132                                 }
133                         }
134                 }
135         }
136         emu->screen_skip_line(true);
137 }
138
139 // RefreshScr10: N60-BASIC select function
140 void PC6001_MEMORY::RefreshScr10()
141 {
142         if ((*VRAM&0x80) == 0x00)
143                 RefreshScr11();
144         else
145                 switch (*(VRAM)&0x1C) {
146                 case 0x00: case 0x10: //  64x 64 color / 128x 64
147                         RefreshScr13a(); break;
148                 case 0x08: // 128x 64 color
149                         RefreshScr13b(); break;
150                 case 0x18: // 128x 96
151                         RefreshScr13c(); break;
152                 case 0x04: // 128x 96 color
153                         RefreshScr13d(); break;
154                 case 0x14: // 128x192
155                         RefreshScr13e(); break;
156                 default: // 128x192 color / 256x192
157                         RefreshScr13(); break;
158                 }
159 }
160
161 // RefreshScr11: N60-BASIC screen 1,2
162 void PC6001_MEMORY::RefreshScr11()
163 {
164         uint8_t X,Y,K;
165         int FC,BC;
166         uint8_t *S,*T1,*T2;
167         uint8_t *G;
168
169         G = CGROM;              /* CGROM */ 
170         T1 = VRAM;              /* attribute data */
171         T2 = VRAM+0x0200;       /* ascii/semi-graphic data */
172         for(Y=0; Y<M1HEIGHT; Y++) {
173                 SETSCRVARM1(Y); /* Drawing area */
174                 for(X=0; X<32; X++, T1++, T2++) {
175                         /* get CGROM address and color */
176                         if (*T1&0x40) { /* if semi-graphic */
177                                 if (*T1&0x20) {         /* semi-graphic 6 */
178                                         S = G+((*T2&0x3f)<<4)+0x1000;
179                                         FC = BPal12[(*T1&0x02)<<1|(*T2)>>6]; BC = BPal[8];
180                                 } else {                /* semi-graphic 4 */
181                                         S = G+((*T2&0x0f)<<4)+0x2000;
182                                         FC = BPal12[(*T2&0x70)>>4]; BC = BPal[8];
183                                 }
184                         } else {                /* if normal character */
185                                 S = G+((*T2)<<4); 
186                                 FC = BPal11[(*T1&0x03)]; BC = BPal11[(*T1&0x03)^0x01];
187                         }
188                         K=*(S+Y%12);
189 W=0;
190                         SeqPix21(K&0x80? FC:BC); SeqPix21(K&0x40? FC:BC);
191                         SeqPix21(K&0x20? FC:BC); SeqPix21(K&0x10? FC:BC);
192                         SeqPix21(K&0x08? FC:BC); SeqPix21(K&0x04? FC:BC);
193                         SeqPix21(K&0x02? FC:BC); SeqPix21(K&0x01? FC:BC);
194                 }
195                 if (Y%12!=11) { T1-=32; T2-=32; }
196         }
197 }
198
199 // RefreshScr13: N60-BASIC screen 3,4
200 void PC6001_MEMORY::RefreshScr13()
201 {
202         uint8_t X,Y;
203         uint8_t *T1,*T2;
204         uint8_t attr;
205
206         T1 = VRAM;              /* attribute data */
207         T2 = VRAM+0x0200;       /* graphic data */
208         for (Y=0; Y<M1HEIGHT; Y++) {
209                 SETSCRVARM1(Y); /* Drawing area */
210                 for (X=0; X<32; X++,T1++,T2++) {
211                         if (*T1&0x10) { /* 256x192 (SCREEN 4) */
212                                 attr = *T1&0x02;
213 W=0;
214                                 SeqPix21(BPal14[attr|(*T2&0x80)>>7]);
215                                 SeqPix21(BPal14[attr|(*T2&0x40)>>6]);
216                                 SeqPix21(BPal14[attr|(*T2&0x20)>>5]);
217                                 SeqPix21(BPal14[attr|(*T2&0x10)>>4]);
218                                 SeqPix21(BPal14[attr|(*T2&0x08)>>3]);
219                                 SeqPix21(BPal14[attr|(*T2&0x04)>>2]);
220                                 SeqPix21(BPal14[attr|(*T2&0x02)>>1]);
221                                 SeqPix21(BPal14[attr|(*T2&0x01)   ]);
222                         } else { /* 128x192 color (SCREEN 3) */
223                                 attr = (*T1&0x02)<<1;
224 W=0;
225                                 SeqPix41(BPal13[attr|(*T2&0xC0)>>6]);
226                                 SeqPix41(BPal13[attr|(*T2&0x30)>>4]);
227                                 SeqPix41(BPal13[attr|(*T2&0x0C)>>2]);
228                                 SeqPix41(BPal13[attr|(*T2&0x03)   ]);
229                         }
230                 }
231                 if (T1 == VRAM+0x200) T1=VRAM;
232         }
233 }
234
235 // RefreshScr13a: N60-BASIC screen 3,4
236 void PC6001_MEMORY::RefreshScr13a() /*  64x 64 color / 128x 64 */
237 {
238         uint8_t X,Y;
239         uint8_t *T1,*T2;
240         uint8_t attr;
241         int L;
242
243         T1 = VRAM;              /* attribute data */
244         T2 = VRAM+0x0200;       /* graphic data */
245         for (Y=0; Y<M1HEIGHT; Y++) {
246                 SETSCRVARM1(Y); /* Drawing area */
247                 for (X=0; X<16; X++,T1++,T2++) {
248                         if (*T1&0x10) { /* 128x 64 */
249                                 attr = *T1&0x02;
250 W=0;
251                                 SeqPix41(BPal14[attr|(*T2&0x80)>>7]);
252                                 SeqPix41(BPal14[attr|(*T2&0x40)>>6]);
253                                 SeqPix41(BPal14[attr|(*T2&0x20)>>5]);
254                                 SeqPix41(BPal14[attr|(*T2&0x10)>>4]);
255                                 SeqPix41(BPal14[attr|(*T2&0x08)>>3]);
256                                 SeqPix41(BPal14[attr|(*T2&0x04)>>2]);
257                                 SeqPix41(BPal14[attr|(*T2&0x02)>>1]);
258                                 SeqPix41(BPal14[attr|(*T2&0x01)   ]);
259                         } else { /*  64x 64 color */
260                                 attr = (*T1&0x02)<<1;
261 W=0;
262                                 SeqPix41(L=BPal13[attr|(*T2&0xC0)>>6]);
263                                 SeqPix41(L);
264                                 SeqPix41(L=BPal13[attr|(*T2&0x30)>>4]);
265                                 SeqPix41(L);
266                                 SeqPix41(L=BPal13[attr|(*T2&0x0C)>>2]);
267                                 SeqPix41(L);
268                                 SeqPix41(L=BPal13[attr|(*T2&0x03)   ]);
269                                 SeqPix41(L);
270                         }
271                 }
272                 if (Y%3 != 2) { T1-=16; T2-=16; }
273                 else if (T1 == VRAM+0x200) T1=VRAM;
274         }
275 }
276
277 // RefreshScr13b: N60-BASIC screen 3,4
278 void PC6001_MEMORY::RefreshScr13b() /* 128x 64 color */
279 {
280         uint8_t X,Y;
281         uint8_t *T1,*T2;
282         uint8_t attr;
283
284         T1 = VRAM;              /* attribute data */
285         T2 = VRAM+0x0200;       /* graphic data */
286         for (Y=0; Y<M1HEIGHT; Y++) {
287                 SETSCRVARM1(Y); /* Drawing area */
288                 for (X=0; X<32; X++,T1++,T2++) {
289 W=0;
290                         attr = (*T1&0x02)<<1;
291                         SeqPix41(BPal13[attr|(*T2&0xC0)>>6]);
292                         SeqPix41(BPal13[attr|(*T2&0x30)>>4]);
293                         SeqPix41(BPal13[attr|(*T2&0x0C)>>2]);
294                         SeqPix41(BPal13[attr|(*T2&0x03)   ]);
295                 }
296                 if (Y%3 != 2) { T1-=32; T2-=32; }
297                 else if (T1 == VRAM+0x200) T1=VRAM;
298         }
299 }
300
301 // RefreshScr13c: N60-BASIC screen 3,4
302 void PC6001_MEMORY::RefreshScr13c() /* 128x 96 */
303 {
304         uint8_t X,Y;
305         uint8_t *T1,*T2;
306         uint8_t attr;
307
308         T1 = VRAM;              /* attribute data */
309         T2 = VRAM+0x0200;       /* graphic data */
310         for (Y=0; Y<M1HEIGHT; Y++) {
311                 SETSCRVARM1(Y); /* Drawing area */
312                 for (X=0; X<16; X++,T1++,T2++) {
313                         attr = *T1&0x02;
314 W=0;
315                         SeqPix41(BPal14[attr|(*T2&0x80)>>7]);
316                         SeqPix41(BPal14[attr|(*T2&0x40)>>6]);
317                         SeqPix41(BPal14[attr|(*T2&0x20)>>5]);
318                         SeqPix41(BPal14[attr|(*T2&0x10)>>4]);
319                         SeqPix41(BPal14[attr|(*T2&0x08)>>3]);
320                         SeqPix41(BPal14[attr|(*T2&0x04)>>2]);
321                         SeqPix41(BPal14[attr|(*T2&0x02)>>1]);
322                         SeqPix41(BPal14[attr|(*T2&0x01)   ]);
323                 }
324                 if (!(Y&1)) { T1-=16; T2-=16; }
325                 else if (T1 == VRAM+0x200) T1=VRAM;
326         }
327 }
328
329 // RefreshScr13d: N60-BASIC screen 3,4
330 void PC6001_MEMORY::RefreshScr13d() /* 128x 96 color */
331 {
332         uint8_t X,Y;
333         uint8_t *T1,*T2;
334         uint8_t attr;
335
336         T1 = VRAM;              /* attribute data */
337         T2 = VRAM+0x0200;       /* graphic data */
338         for (Y=0; Y<M1HEIGHT; Y++) {
339                 SETSCRVARM1(Y); /* Drawing area */
340                 for (X=0; X<32; X++,T1++,T2++) {
341                         attr = (*T1&0x02)<<1;
342 W=0;
343                         SeqPix41(BPal13[attr|(*T2&0xC0)>>6]);
344                         SeqPix41(BPal13[attr|(*T2&0x30)>>4]);
345                         SeqPix41(BPal13[attr|(*T2&0x0C)>>2]);
346                         SeqPix41(BPal13[attr|(*T2&0x03)   ]);
347                 }
348                 if (!(Y&1)) { T1-=32; T2-=32; }
349                 else if (T1 == VRAM+0x200) T1=VRAM;
350         }
351 }
352
353 // RefreshScr13e: N60-BASIC screen 3,4
354 void PC6001_MEMORY::RefreshScr13e() /* 128x192 */
355 {
356         uint8_t X,Y;
357         uint8_t *T1,*T2;
358         uint8_t attr;
359
360         T1 = VRAM;              /* attribute data */
361         T2 = VRAM+0x0200;       /* graphic data */
362         for (Y=0; Y<M1HEIGHT; Y++) {
363                 SETSCRVARM1(Y); /* Drawing area */
364                 for (X=0; X<16; X++,T1++,T2++) {
365                         attr = *T1&0x02;
366 W=0;
367                         SeqPix41(BPal14[attr|(*T2&0x80)>>7]);
368                         SeqPix41(BPal14[attr|(*T2&0x40)>>6]);
369                         SeqPix41(BPal14[attr|(*T2&0x20)>>5]);
370                         SeqPix41(BPal14[attr|(*T2&0x10)>>4]);
371                         SeqPix41(BPal14[attr|(*T2&0x08)>>3]);
372                         SeqPix41(BPal14[attr|(*T2&0x04)>>2]);
373                         SeqPix41(BPal14[attr|(*T2&0x02)>>1]);
374                         SeqPix41(BPal14[attr|(*T2&0x01)   ]);
375                 }
376                 if (T1 == VRAM+0x200) T1=VRAM;
377         }
378 }
379
380 // RefreshScr51: N60m/66-BASIC screen 1,2
381 void PC6001_MEMORY::RefreshScr51()
382 {
383         uint8_t X,Y,K;
384         int FC,BC;
385         uint8_t *S,*T1,*T2;
386         uint8_t *G;
387
388         G = CGROM;              /* CGROM */ 
389         T1 = VRAM;              /* attribute data */
390         T2 = VRAM+0x0400;       /* ascii/semi-graphic data */
391         for(Y=0; Y<M5HEIGHT; Y++) {
392                 SETSCRVARM5(Y); /* Drawing area */
393                 for(X=0; X<40; X++, T1++, T2++) {
394                         /* get CGROM address and color */
395                         S = G+(*T2<<4)+(*T1&0x80?0x1000:0);
396                         FC = BPal[(*T1)&0x0F]; BC = BPal[(((*T1)&0x70)>>4)|CSS2];
397                         K=*(S+Y%10);
398 W=0;
399                         SeqPix21(K&0x80? FC:BC); SeqPix21(K&0x40? FC:BC);
400                         SeqPix21(K&0x20? FC:BC); SeqPix21(K&0x10? FC:BC);
401                         SeqPix21(K&0x08? FC:BC); SeqPix21(K&0x04? FC:BC);
402                         SeqPix21(K&0x02? FC:BC); SeqPix21(K&0x01? FC:BC);
403                 }
404                 if (Y%10!=9) { T1-=40; T2-=40; }
405         }
406 }
407
408 // RefreshScr53: N60m/66-BASIC screen 3
409 void PC6001_MEMORY::RefreshScr53()
410 {
411         uint8_t X,Y;
412         uint8_t *T1,*T2;
413
414         T1 = VRAM;              /* attribute data */
415         T2 = VRAM+0x2000;       /* graphic data */
416         for(Y=0; Y<M5HEIGHT; Y++) {
417                 SETSCRVARM5(Y); /* Drawing area */
418                 for(X=0; X<40; X++) {
419 W=0;
420                         SeqPix41(BPal53[CSS3|((*T1)&0xC0)>>6|((*T2)&0xC0)>>4]);
421                         SeqPix41(BPal53[CSS3|((*T1)&0x30)>>4|((*T2)&0x30)>>2]);
422                         SeqPix41(BPal53[CSS3|((*T1)&0x0C)>>2|((*T2)&0x0C)   ]);
423                         SeqPix41(BPal53[CSS3|((*T1)&0x03)   |((*T2)&0x03)<<2]);
424                         T1++; T2++;
425                 }
426         }
427 }
428
429 // RefreshScr54: N60m/66-BASIC screen 4
430 void PC6001_MEMORY::RefreshScr54()
431 {
432         uint8_t X,Y;
433         uint8_t *T1,*T2;
434         uint8_t cssor;
435
436         T1 = VRAM;              /* attribute data */
437         T2 = VRAM+0x2000;       /* graphic data */
438         /* CSS OR */
439         cssor = CSS3|CSS2|CSS1;
440         for(Y=0; Y<M5HEIGHT; Y++) {
441                 SETSCRVARM5(Y); /* Drawing area */
442                 for(X=0; X<40; X++) {
443 W=0;
444                         SeqPix21(BPal53[cssor|((*T1)&0x80)>>7|((*T2)&0x80)>>6]);
445                         SeqPix21(BPal53[cssor|((*T1)&0x40)>>6|((*T2)&0x40)>>5]);
446                         SeqPix21(BPal53[cssor|((*T1)&0x20)>>5|((*T2)&0x20)>>4]);
447                         SeqPix21(BPal53[cssor|((*T1)&0x10)>>4|((*T2)&0x10)>>3]);
448                         SeqPix21(BPal53[cssor|((*T1)&0x08)>>3|((*T2)&0x08)>>2]);
449                         SeqPix21(BPal53[cssor|((*T1)&0x04)>>2|((*T2)&0x04)>>1]);
450                         SeqPix21(BPal53[cssor|((*T1)&0x02)>>1|((*T2)&0x02)   ]);
451                         SeqPix21(BPal53[cssor|((*T1)&0x01)   |((*T2)&0x01)<<1]);
452                         T1++;T2++;
453                 }
454         }
455 }
456
457 #if defined(_PC6601SR) || defined(_PC6001MK2SR)
458 // RefreshScr61: N66-SR BASIC screen 1
459 void PC6001_MEMORY::RefreshScr61()
460 {
461         uint8_t X,Y,K;
462         register int FC,BC;
463         uint8_t *S,*T1,*T2;
464         uint8_t *G;
465         int high;
466         int addr;
467         int semi_addr;
468
469         G = CGROM;              /* CGROM */
470         T1 = TEXTVRAM+1;                /* attribute data */
471         T2 = TEXTVRAM;                  /* ascii/semi-graphic data */
472         high= (rows==20)? 10:8;       /* charactor's high   SR BASIC 2002/2/23 */
473         addr= (rows==20)? 0x2000: 0x1000; /* CGROM address  SR BASIC 2002/2/23 */
474         semi_addr= (rows==20)? 0x3000: 0x4000; /* semi address 2003/7/8 */
475         for(Y=0; Y<M5HEIGHT; Y++) {
476                 SETSCRVARM5(Y); /* Drawing area */
477                 for(X=0; X< cols; X++, T1+=2, T2+=2) {
478 W=0;
479                         S= G+(*T2<<4)+(*T1&0x80?semi_addr:addr); /*for CGROM6 SR semi graph 2002/2/23*//* 2003/7/8 */
480                         FC = BPal[ (*T1)&0x0F];                                    /* fast Palet (2002/9/27) */
481                         BC = BPal[ (((*T1)&0x70)>>4) |CSS2];
482                         K=*(S+Y%high);                  /* character high 2002/2/23 */
483                         SeqPix21(K&0x80? FC:BC); SeqPix21(K&0x40? FC:BC);
484                         SeqPix21(K&0x20? FC:BC); SeqPix21(K&0x10? FC:BC);
485                         SeqPix21(K&0x08? FC:BC); SeqPix21(K&0x04? FC:BC);
486                         SeqPix21(K&0x02? FC:BC); SeqPix21(K&0x01? FC:BC);
487                 }
488                 if (Y% high!=high-1) { T1-=cols*2; T2-=cols*2; } /* character high  2002/2/23 */
489         }
490 }
491
492 // RefreshScr62  N66-SR BASIC screen 2
493 void PC6001_MEMORY::RefreshScr62()
494 {
495         uint8_t X,Y;
496         uint8_t *T1,*T2;
497         T1 = VRAM+ 0x1a00;
498         T2 = VRAM;
499         for(Y=0; Y<M6HEIGHT; Y++) {
500                 SETSCRVARM5(Y); /* Drawing area */
501                 for(X=0; X< 64; X++) {
502 W=0;
503                         SeqPix41(BPal53[ CSS3|((*T1)&0x0f) ]);
504                         SeqPix41(BPal53[ CSS3|((*T1)&0xf0)>>4 ]);
505                         T1++;
506                         SeqPix41(BPal53[ CSS3|((*T1)&0x0f) ]);
507                         SeqPix41(BPal53[ CSS3|((*T1)&0xf0)>>4 ]);
508                         T1+=3;
509                 }
510                 for(X=64 ;X<80 ; X++) {
511 W=0;
512                         SeqPix41(BPal53[ CSS3|((*T2)&0x0f) ]);
513                         SeqPix41(BPal53[ CSS3|((*T2)&0xf0)>>4 ]);
514                         T2++;
515                         SeqPix41(BPal53[ CSS3|((*T2)&0x0f) ]);
516                         SeqPix41(BPal53[ CSS3|((*T2)&0xf0)>>4 ]);
517                         T2+=3;
518                 }
519                 if( (Y & 1)==0)
520                         { T1-=(254);  T2-=(62);}
521                 else
522                         { T1-=2; T2-=2; }
523         }
524 }
525
526 // RefreshScr63  N66-SR BASIC screen 3
527 void PC6001_MEMORY::RefreshScr63()
528 {
529         uint8_t X,Y;
530         uint8_t *T1,*T2;
531         uint8_t cssor;
532
533         T1 = VRAM+ 0x1a00;
534         T2 = VRAM;
535         cssor = CSS3|CSS2|CSS1;
536         for(Y=0; Y<M6HEIGHT; Y++) {
537                 SETSCRVARM5(Y);         /* Drawing area */
538                 for(X=0; X< 64; X++) {
539 W=0;
540                         SeqPix41(BPal53[cssor|((*T1)&0x80)>>7|((*(T1+1))&0x80)>>6]);
541                         SeqPix41(BPal53[cssor|((*T1)&0x40)>>6|((*(T1+1))&0x40)>>5]);
542                         SeqPix41(BPal53[cssor|((*T1)&0x20)>>5|((*(T1+1))&0x20)>>4]);
543                         SeqPix41(BPal53[cssor|((*T1)&0x10)>>4|((*(T1+1))&0x10)>>3]);
544                         SeqPix41(BPal53[cssor|((*T1)&0x08)>>3|((*(T1+1))&0x08)>>2]);
545                         SeqPix41(BPal53[cssor|((*T1)&0x04)>>2|((*(T1+1))&0x04)>>1]);
546                         SeqPix41(BPal53[cssor|((*T1)&0x02)>>1|((*(T1+1))&0x02)   ]);
547                         SeqPix41(BPal53[cssor|((*T1)&0x01)   |((*(T1+1))&0x01)<<1]);
548                         T1+=4;
549                 }
550                 for(X=64 ;X<80 ; X++) {
551 W=0;
552                         SeqPix41(BPal53[cssor|((*T2)&0x80)>>7|((*(T2+1))&0x80)>>6]);
553                         SeqPix41(BPal53[cssor|((*T2)&0x40)>>6|((*(T2+1))&0x40)>>5]);
554                         SeqPix41(BPal53[cssor|((*T2)&0x20)>>5|((*(T2+1))&0x20)>>4]);
555                         SeqPix41(BPal53[cssor|((*T2)&0x10)>>4|((*(T2+1))&0x10)>>3]);
556                         SeqPix41(BPal53[cssor|((*T2)&0x08)>>3|((*(T2+1))&0x08)>>2]);
557                         SeqPix41(BPal53[cssor|((*T2)&0x04)>>2|((*(T2+1))&0x04)>>1]);
558                         SeqPix41(BPal53[cssor|((*T2)&0x02)>>1|((*(T2+1))&0x02)   ]);
559                         SeqPix41(BPal53[cssor|((*T2)&0x01)   |((*(T2+1))&0x01)<<1]);
560                         T2+=4;
561                 }
562                 if( (Y & 1)==0)
563                         { T1-=(254);  T2-=(62);}
564                 else
565                         { T1-=2; T2-=2; }
566         }
567 }
568
569 void PC6001_MEMORY::do_palet(int dest,int src)
570 {
571         int textpalet2[16]={0,4,1,5,2,6,3,7,8,12,9,13,10,14,11,15}; /*  color code-> VRAM code*/
572         // *************** for RefreshScr 53/54/62/63 ***************************
573         if ((CSS3 & 0x10) ==0 ) // CSS3 =0
574         {
575                 if(dest>=0 && dest<32 && src>=0 && src<32)
576                 {
577                         BPal53[dest]= BPal62[src];
578                 }
579         } else {                                // CSS3 =1
580                 if (dest>=0 && dest<32 && src>=0 && src<32)
581                 {
582                         int dest1,dest2;
583                         switch( dest+1)
584                         {
585                         case 16: dest1 =13; dest2 = 5; break;
586                         case 15: dest1 =10; dest2 = 2; break;
587                         case 14: dest1 =14; dest2 = 6; break;
588                         case 13: dest1 = 1; dest2 = 9; break;
589                         }
590                         BPal53[16+dest1-1]= BPal62[src];
591                         BPal53[16+dest2-1]= BPal62[src];
592                 }
593         }
594         // ************** for RefreshScr51/61 **************************
595         if(dest>=0 && dest<16 && src>=0 && src<16)
596                 BPal[textpalet2[dest]]= BPal61[ textpalet2[src]];  
597 }
598
599 void PC6001_MEMORY::make_semigraph(void)
600 {
601         uint8_t *P;
602         unsigned int i, j, m1, m2;
603         P = CGROM1+0x1000;
604         for(i=0; i<64; i++) {
605                 for(j=0; j<16; j++) {
606                         switch (j/4) {
607                         case 0: m1=0x20; m2=0x10; break;
608                         case 1: m1=0x08; m2=0x04; break;
609                         case 2: m1=0x02; m2=0x01; break;
610                         default: m1=m2=0;
611                         };
612                         *P++=(i&m1 ? 0xF0: 0) | (i&m2 ? 0x0F: 0);
613                 }
614         }
615         P = CGROM1+0x2000;
616         for(i=0; i<16; i++) {
617                 for(j=0; j<16; j++) {
618                         switch (j/6) {
619                         case 0: m1=0x08; m2=0x04; break;
620                         case 1: m1=0x02; m2=0x01; break;
621                         default: m1=m2=0;
622                         };
623                         *P++=(i&m1 ? 0xF0: 0) | (i&m2 ? 0x0F: 0);
624                 }
625         }
626         P = CGROM6+0x4000;
627         for(i=0; i<256; i++) {
628                 for(j=0; j<16; j++) {
629                         switch (j/2) {
630                         case 0: m1=0x80; m2=0x40; break;
631                         case 1: m1=0x20; m2=0x10; break;
632                         case 2: m1=0x08; m2=0x04; break;
633                         case 3: m1=0x02; m2=0x01; break;
634                         default: m1=m2=0;
635                         };
636                         *P++=(i&m1 ? 0xF0: 0) | (i&m2 ? 0x0F: 0);
637                 }
638         }
639 }
640
641 int PC6001_MEMORY::chk_gvram(uint32_t A,int flag)
642 {
643         if (port60[ (A>>13)+flag ]==0x00 && bitmap)     // VRAM \82Ì\90æ\93ª\82©\82Â\81ACRT\82ª BITMAP mode
644                 return 1;
645         return 0;
646 }
647
648 uint8_t PC6001_MEMORY::gvram_read(uint32_t A)
649 {
650         uint8_t* adr;
651         uint8_t  ret;
652         int x,y,z,w,off;
653
654         x = A & 0x1fff;
655         y = portCF*16+portCE;                 /* y\8dÀ\95W */
656         if( y >=204) y-=204;                  /* Y\8dÀ\95W 204 \88È\8fã\82¾\82Æ 204 \88ø\82­ add 2003/10/22 */
657         w = (x <256) ? 256: 64;          /* width:0..255 \82È\82ç256 / 256..319\82È\82ç 64\82É\82·\82é*/
658         off=(x <256) ? 0x1a00: 0x0000;   /* offset: Vram offset address */
659         x = (x <256) ? x: x-256;              /* x:256..319 \82È\82ç 256\82ð\88ø\82­\81@ */
660         z = ((y & 1 )==1) ? 2: 0;        /* z:Y\8dÀ\95W\82ª\8aï\90\94\82È\82ç\81A2\82ð\91«\82·  */
661         adr = (VRAM+ (off+ (y>>1)*w + (x&0xffc)+z));
662         switch(x & 3)
663         {
664         case 0: ret=  *(adr);      break;
665         case 1: ret=  *(adr)>>4;   break;
666         case 2: ret=  *(adr+1);    break;
667         case 3: ret=  *(adr+1)>>4; break;
668         }
669         return (ret);
670 }
671
672 void PC6001_MEMORY::gvram_write(uint32_t A, uint32_t V)
673 {
674         uint8_t* adr;
675         int x,y,z,w,off;
676
677         x = A & 0x1fff;
678         y = portCF*16+portCE;           /* y\8dÀ\95W */
679         if( y >=204) y-=204;                    /* Y\8dÀ\95W 204 \88È\8fã\82¾\82Æ 204 \88ø\82­ */
680         w = (x <256) ? 256: 64;         /* width:0..255 \82È\82ç256 / 256..319\82È\82ç 64\82É\82·\82é*/
681         off=(x <256) ? 0x1a00: 0x0000;  /* offset: Vram offset address */
682         x = (x <256) ? x: x-256;            /* x:256..319 \82È\82ç 256\82ð\88ø\82­\81@ */
683         z = ((y & 1 )==1) ? 2: 0;       /* z:Y\8dÀ\95W\82ª\8aï\90\94\82È\82ç\81A2\82ð\91«\82·  */
684         V&= 0x0f;
685         adr = VRAM+(off+ (y>>1)*(w) + (x&0xffc)+z);
686         switch(x & 3)
687         {
688         case 0: *(adr)=(*(adr)  &0xf0)  |V;    break;
689         case 1: *(adr)=(*(adr)  &0x0f)  |V<<4; break;
690         case 2: *(adr+1)=(*(adr+1)&0xf0)|V;    break;
691         case 3: *(adr+1)=(*(adr+1)&0x0f)|V<<4; break;
692         }
693 }
694 #endif
695