3 // from "v99x8.c" of Zodiac
6 * Copyright (c) 2000-2002 SASAKI Shunsuke (eruchan@users.sourceforge.net).
7 * Copyright (c) 2001-2002 The Zodiac project.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 //#include "../../config.h"
29 //#include "../zodiac.h"
34 void cmdtime_set(int m);
35 void cmdtime_chk(void);
42 // from "md.h.in" of Zodiac
44 # define __inline__ __forceinline
45 #elif defined(_MWERKS_)
46 # define __inline__ inline
47 #elif !defined(__GNUC__)
53 //#include "z80.h" /* XXX interrupt */
54 #define Z80_NOINT 0xffff
55 #define Z80_INT 0x0038
56 //#define Z80_NMI 0x0066
59 #if defined(USE_QT) || defined(_USE_QT) // Using Shader
60 # define md_maprgb15(R,G,B) RGB_COLOR((R << 3), (G << 3), (B << 3))
62 # define md_maprgb15(R,G,B) (((R)<<19)|((G)<<11)|((B)<<3))
64 #define md_video_pixbytes(n) (n*32/8)
65 #define md_refresh_sync() (TRUE)
66 #define md_video_defaultopt() (0)
67 int md_video_pitch(void); // the length of a row of pixels in bytes
68 uint8 *md_video_lockline(int x, int y, int w, int h);
69 void md_video_unlockline(void) {}
70 void md_video_update(int n, /*md_video_rect_t*/void *rp);
71 void md_video_fill(int x, int y, int w, int h, uint32 c);
72 typedef uint32 md_pixel_t;
74 // from "md_depend.h" of Zodiac
81 //typedef SDL_Rect md_video_rect_t;
82 //typedef SDL_Surface md_video_surface_t;
85 //md_video_surface_t *screen;
86 int w, h; /*
\97v
\8b\81\82µ
\82½
\83T
\83C
\83Y */
98 extern void v99x8_command(int m); /* v99x8_internal.h ?? */
99 extern void v99x8_cputovdp(int m);
102 #define XXX_V99X8_ID 0
137 static void v99x8_interleave(void)
140 static uint8 *vram = NULL;
144 size = v99x8.pages * 0x4000;
147 vram = (uint8 *)malloc(size);
153 if (v99x8.mode.f_interleave)
161 while (c < (int)size)
163 v99x8.vram[c] = vram[a++];
164 v99x8.vram[c + 1] = vram[b++];
175 while (c < (int)size)
177 v99x8.vram[a++] = vram[c];
178 v99x8.vram[b++] = vram[c + 1];
185 static void v99x8_mode_set(int n)
187 v99x8_screen_mode_t mode[] =
189 {TRUE, FALSE, 0, 0}, /* V99X8_SCREEN_0 */
190 {TRUE, FALSE, 0, 0}, /* V99X8_SCREEN_1 */
191 {TRUE, FALSE, 0, 0}, /* V99X8_SCREEN_2 */
192 {TRUE, FALSE, 0, 0}, /* V99X8_SCREEN_3 */
194 {FALSE, FALSE, 0, 0}, /* V99X8_SCREEN_4 */
195 {FALSE, FALSE, 256, 1}, /* V99X8_SCREEN_5 */
196 {FALSE, FALSE, 512, 2}, /* V99X8_SCREEN_6 */
197 {FALSE, TRUE, 512, 1}, /* V99X8_SCREEN_7 */
199 {FALSE, TRUE, 256, 0}, /* V99X8_SCREEN_8 */
200 {FALSE, FALSE, 0, 0}, /* V99X8_SCREEN_X */
201 {FALSE, TRUE, 256, 0}, /* V99X8_SCREEN_A */
202 {FALSE, TRUE, 256, 0} /* V99X8_SCREEN_C */
205 if (n != V99X8_SCREEN_8 || (v99x8.ctrl[25] & 0x08) != 0x08)
209 if ((v99x8.ctrl[25] & 0x10) == 0x10)
210 v99x8.scr = V99X8_SCREEN_A;
212 v99x8.scr = V99X8_SCREEN_C;
215 memcpy(&v99x8.mode, &mode[v99x8.scr], sizeof(v99x8_screen_mode_t));
218 static void v99x8_update(void)
222 V99X8_SCREEN_1, V99X8_SCREEN_2, V99X8_SCREEN_4, V99X8_SCREEN_5,
223 V99X8_SCREEN_6, V99X8_SCREEN_7, V99X8_SCREEN_IGN, V99X8_SCREEN_8,
224 V99X8_SCREEN_3, V99X8_SCREEN_IGN, V99X8_SCREEN_IGN, V99X8_SCREEN_IGN,
225 V99X8_SCREEN_IGN, V99X8_SCREEN_IGN, V99X8_SCREEN_IGN, V99X8_SCREEN_IGN,
226 V99X8_SCREEN_0, V99X8_SCREEN_IGN, V99X8_SCREEN_X
235 f = v99x8.mode.f_interleave;
237 a = ((v99x8.ctrl[0] & 0x0e) >> 1) | (v99x8.ctrl[1] & 0x18);
238 if (a >= sizeof(mapping) / sizeof(*mapping) ||
239 mapping[a] == V99X8_SCREEN_IGN)
244 v99x8_mode_set(mapping[a]);
246 if (f != v99x8.mode.f_interleave)
253 static void v99x8_ctrl_init(void)
255 memset(v99x8.ctrl, 0, sizeof(v99x8.ctrl));
258 void v99x8_ctrl(int n, uint8 m)
260 /* printf ("v99x8_ctrl %2d <= %02x\n", n, m); */
270 if (((m ^ v99x8.ctrl[0]) & 0x0e) != 0)
278 if (((m ^ v99x8.ctrl[1]) & 0x18) != 0)
293 v99x8.col_fg = m >> 4;
294 v99x8.col_bg = m & 0x0f;
298 m &= v99x8.pages - 1;
299 vram_page = (int)m << 14;
303 if (m >= V99X8_NSTAT)
312 f_out3 = !(m & 0x80);
341 static void vram_incaddr(void)
343 vram_addr = (vram_addr + 1) & 0x3fff;
344 if (vram_addr == 0 && !v99x8.mode.f_tms)
345 v99x8_ctrl(14, v99x8.ctrl[14] + 1);
348 uint8 vram_read(int addr)
350 return v99x8.vram[addr];
353 void vram_write(int addr, uint8 n)
355 v99x8.vram[addr] = n;
359 uint8 v99x8_in_0(void) /* VRAM read */
365 n = vram_read(vram_addr + vram_page);
370 void v99x8_out_0(uint8 n) /* VRAM write */
374 vram_write(vram_addr + vram_page, n);
378 uint8 v99x8_in_1(void) /* status in */
387 n = v99x8.status[v99x8.ctrl[15]];
390 if (z80.ivec!=Z80_NOINT)
392 printf("* IFF:%d H:%d V:%d\n", z80.IFF&1, (v99x8.ctrl[0]&0x10), (v99x8.ctrl[1]&0x20));
394 z80_intreq(Z80_NOINT);
398 switch(v99x8.ctrl[15])
401 v99x8.status[0] &= ~0xa0;
404 v99x8.status[1] &= ~0x01;
407 /* v99x8.status[7] = v99x8.ctrl[44] = v99x8_vdptocpu(); */
413 a = context.hz / 60 / 262;
414 b = (context.time_cycle % a) * 100 / a;
415 context_timeunlock();
428 void v99x8_out_1(uint8 n) /* ctrl out */
430 //static int latch = -1;
440 v99x8_ctrl(n & 0x3f, latch1);
443 /* ??? read/write
\82Ì
\8bæ
\95Ê */
444 vram_addr = ((int)(n & 0x3f) << 8) + latch1;
450 void v99x8_out_2(uint8 n) /* palette out */
452 //static int latch = -1;
462 v99x8_pallete_set(a, (latch2 & 0x70) >> 4, n & 0x07, latch2 & 0x07);
463 v99x8_ctrl(16, a + 1);
469 void v99x8_out_3(uint8 n) /* ctrl out */
471 if (v99x8.ctrl[17] != 17)
472 v99x8_ctrl(v99x8.ctrl[17], n);
475 v99x8_ctrl(17, v99x8.ctrl[17] + 1);
479 static void v99x8_status_init(void)
481 memset(v99x8.status, 0, sizeof(v99x8.status));
482 v99x8.status[0] = 0x9f;
483 v99x8.status[1] = XXX_V99X8_ID << 1;
484 v99x8.status[2] = 0xac;
487 static void v99x8_vram_init(void)
489 //v99x8.vram = (uint8 *)malloc(v99x8.pages * 0x4000);
490 memset(v99x8.vram, 0xff, v99x8.pages * 0x4000);
493 void v99x8_init(void)
507 v99x8.n_scanlines = 262;
513 /* v99x8.f_zoom = FALSE; */
517 v99x8_mode_set(V99X8_SCREEN_1);
522 v99x8_refresh_init();
525 static bool flag_frame = FALSE;
527 int V99X8::hsync(int v/*void*/)
531 v99x8.scanline = v; // is this OK???
532 v99x8.status[2] ^= 0x20;
534 if (v99x8.scanline < 226)
538 if (0 == v99x8.scanline) v99x8_refresh_clear(); // added by umaiboux
539 line = v99x8.scanline + (((v99x8.ctrl[18] >> 4) + 8) & 0x0f) - 8 - 7;
540 if (v99x8.ctrl[9] & 0x80)
545 if (v99x8.ctrl[1] & 0x40 && line >= 0 && line < a)
551 case V99X8_SCREEN_0: v99x8_refresh_sc0(line, 1); break;
552 case V99X8_SCREEN_1: v99x8_refresh_sc1(line, 1); break;
553 case V99X8_SCREEN_2: v99x8_refresh_sc4(line, 1); break;
554 case V99X8_SCREEN_3: v99x8_refresh_sc3(line, 1); break;
555 case V99X8_SCREEN_4: v99x8_refresh_sc4(line, 1); break;
556 case V99X8_SCREEN_5: v99x8_refresh_sc5(line, 1); break;
557 case V99X8_SCREEN_6: v99x8_refresh_sc6(line, 1); break;
558 case V99X8_SCREEN_7: v99x8_refresh_sc7(line, 1); break;
559 case V99X8_SCREEN_8: v99x8_refresh_sc8(line, 1); break;
560 case V99X8_SCREEN_A: v99x8_refresh_scc(line, 1); break;
561 case V99X8_SCREEN_C: v99x8_refresh_scc(line, 1); break;
562 case V99X8_SCREEN_X: v99x8_refresh_scx(line, 1); break;
567 if (((v99x8.scanline + v99x8.ctrl[23]
568 - ((v99x8.ctrl[9] & 0x80) ? 8 : 18)) & 0xff) == v99x8.ctrl[19])
570 if (v99x8.ctrl[0] & 0x10)
572 v99x8.status[1] |= 0x01; /* H-sync */
577 if (!(v99x8.ctrl[0] & 0x10))
578 v99x8.status[1] &= ~0x01; /* ?? H-sync off*/
582 switch(v99x8.scanline)
586 v99x8_refresh_screen();
588 flag_frame = md_refresh_sync();
590 v99x8.status[2] |= 0x40; /* VBlank on */
592 v99x8.status[1] &= ~0x01; /* ?? H-sync off*/
593 z80_intreq(Z80_NOINT); /* ?? H-sync
\82ð clear */
595 /* XXX sprite check */
599 /* v99x8.status[1] &= ~0x01; */ /* ?? H-sync off*/
600 if (v99x8.ctrl[1] & 0x20)
602 v99x8.status[0] |= 0x80; /* V-sync int */
608 v99x8.status[2] &= ~0x40; /* VBlank off */
609 v99x8.status[0] &= ~0x40; /* 5sprit off */
610 v99x8.status[0] &= ~0x80; /* Vsync off */
611 z80_intreq(Z80_NOINT); /* ?? V-sync
\82ð clear */
614 v99x8_refresh_clear();*/ // deleted by umaiboux
624 25/ 15: bottom border
630 return v99x8.scanline = (v99x8.scanline + 1) % v99x8.n_scanlines;
635 // from "v99x8_command.c" of Zodiac
638 * Copyright (c) 2000-2002 SASAKI Shunsuke (eruchan@users.sourceforge.net).
639 * Copyright (c) 2001-2002 The Zodiac project.
640 * All rights reserved.
642 * This program is free software; you can redistribute it and/or modify
643 * it under the terms of the GNU General Public License as published by
644 * the Free Software Foundation; either version 2 of the License, or
645 * (at your option) any later version.
647 * This program is distributed in the hope that it will be useful,
648 * but WITHOUT ANY WARRANTY; without even the implied warranty of
649 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
650 * GNU General Public License for more details.
652 * You should have received a copy of the GNU General Public License
653 * along with this program; if not, write to the Free Software
654 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
657 //#include "../../config.h"
659 //#include <string.h>
662 //#include "../zodiac.h"
665 /* #define YAN_V99X8_TEST 1 */ /* XXX */
673 int sx, sy, dx, dy, nx, ny;
701 static pixmask_t pixmasks[4] = {
702 {2, 0x01, 0x0f, {0x0f, 0xf0, 0x0f, 0xf0}, {4, 0, 4, 0}, {4, 0, 4, 0}},
703 {4, 0x03, 0x03, {0x3f, 0xcf, 0xf3, 0xfc}, {6, 4, 2, 0}, {6, 4, 2, 0}},
704 {2, 0x01, 0x0f, {0x0f, 0xf0, 0x0f, 0xf0}, {4, 0, 4, 0}, {4, 0, 4, 0}},
705 {1, 0x00, 0xff, {0x00, 0x00, 0x00, 0x00}, {0, 0, 0, 0}, {0, 0, 0, 0}}
708 static pixmask_t pixmask;
711 static int getshift(int n)
715 for (i = 0; n & (1 << i); i++)
720 #define vcom_getsx() vcom.sx = (v99x8.ctrl[32] + (v99x8.ctrl[33] << 8)) & vcom.xmask
721 #define vcom_getsy() vcom.sy = (v99x8.ctrl[34] + (v99x8.ctrl[35] << 8)) & vcom.ymask
722 #define vcom_getdx() vcom.dx = (v99x8.ctrl[36] + (v99x8.ctrl[37] << 8)) & vcom.xmask
723 #define vcom_getdy() vcom.dy = (v99x8.ctrl[38] + (v99x8.ctrl[39] << 8)) & vcom.ymask
724 #define vcom_getnx() vcom.nx = ((v99x8.ctrl[40] + (v99x8.ctrl[41] << 8) - 1) & 511) + 1
725 #define vcom_getny() vcom.ny = ((v99x8.ctrl[42] + (v99x8.ctrl[43] << 8) - 1) & 1023) + 1
727 static void vcom_lpset(int x, int y, int clr);
728 static uint8 vcom_point(int x, int y);
730 static void vcom_set(int base, int n)
732 v99x8.ctrl[base] = n & 0xff;
733 v99x8.ctrl[base + 1] = n >> 8;
736 #define vcom_setsy(n) vcom_set(34, n)
737 #define vcom_setdy(n) vcom_set(38, n)
738 #define vcom_setny(n) vcom_set(42, n)
740 #define vcom_vram(x, y) (&v99x8.vram[((x) >> vcom.xshift) + ((y) << vcom.yshift)])
742 static int vcom_chksum(uint8 *d, int n)
755 #define vcom_dtcopy(d, s, nbytes) { \
765 static int vcom_canonaddr(void)
769 if (v99x8.ctrl[45] & 0x04) /* Direction to left */
774 vcom.sx = max(vcom.sx, 0);
775 vcom.nx = min(vcom.nx, vcom.xmask + 1 - vcom.sx);
776 vcom.dx = max(vcom.dx, 0);
777 vcom.nx = min(vcom.nx, vcom.xmask + 1 - vcom.dx);
780 if ((v99x8.ctrl[45] & 0x08) == 0) /* Direction to down */
782 ny = min(ny, vcom.ymask + 1 - vcom.sy);
783 ny = min(ny, vcom.ymask + 1 - vcom.dy);
786 ny = min(ny, vcom.sy + 1);
787 ny = min(ny, vcom.dy + 1);
791 /* printf("can %d->%d *(%d,%d)\n", vcom.sx, vcom.dx, vcom.nx, ny); */
793 vcom.src = vcom_vram(vcom.sx, vcom.sy);
794 vcom.dst = vcom_vram(vcom.dx, vcom.dy);
795 vcom.nx >>= vcom.xshift;
800 static void vcom_hcopy(uint8 *dst, uint8 *src, int nx, int ny)
806 /* printf("sum1: %d\n", vcom_chksum(src, nx)); */
807 /* memmove(dst, src, nx); */
808 vcom_dtcopy(dst, src, nx);
809 /* printf("sum2: %d\n", vcom_chksum(dst, nx)); */
817 /* printf("sum1: %d\n", vcom_chksum(src, nx)); */
818 /* memmove(dst, src, nx); */
819 vcom_dtcopy(dst, src, nx);
820 /* printf("sum2: %d\n", vcom_chksum(dst, nx)); */
827 static void ymmm(void)
838 /* printf("ymmm: (%d,%d) %d*%d\n", vcom.sx, vcom.sy, vcom.dy, vcom.ny); */
839 n = vcom_canonaddr();
840 vcom_hcopy(vcom.dst, vcom.src, vcom.nx, n);
842 vcom_setsy(vcom.sy + n);
843 vcom_setdy(vcom.dy + n);
845 if (vcom.ny != abs(n))
846 vcom_setny(vcom.ny - abs(n));
849 static void hmmm(void)
860 /* printf("hmmm: (%d,%d)->(%d,%d) *(%d,%d)\n", vcom.sx, vcom.sy, vcom.dx, vcom.dy, vcom.nx, vcom.ny); */
861 n = vcom_canonaddr();
862 vcom_hcopy(vcom.dst, vcom.src, vcom.nx, n);
864 vcom_setsy(vcom.sy + n);
865 vcom_setdy(vcom.dy + n);
867 if (vcom.ny != abs(n))
868 vcom_setny(vcom.ny - abs(n));
871 static void hmmv(void)
881 clr = v99x8.ctrl[44];
883 ny = n = vcom_canonaddr();
888 memset(vcom.dst, clr, vcom.nx);
889 vcom.dst -= vcom.xbytes;
895 memset(vcom.dst, clr, vcom.nx);
896 vcom.dst += vcom.xbytes;
900 vcom_setsy(vcom.sy + n);
901 vcom_setdy(vcom.dy + n);
903 if (vcom.ny != abs(n))
904 vcom_setny(vcom.ny - abs(n));
907 #define vcom_lset(dc, sc) \
910 case 0x0: (dc) = (sc); break; \
911 case 0x1: (dc) &= (sc); break; \
912 case 0x2: (dc) |= (sc); break; \
913 case 0x3: (dc) ^= (sc); break; \
914 case 0x4: (dc) =~ (sc); break; \
915 case 0x8: if ((sc) != 0) (dc) = (sc); break; \
916 case 0x9: if ((sc) != 0) (dc) &= (sc); break; \
917 case 0xa: if ((sc) != 0) (dc) |= (sc); break; \
918 case 0xb: if ((sc) != 0) (dc) ^= (sc); break; \
919 case 0xc: if ((sc) != 0) (dc) =~ (sc); break; \
930 static void vcom_lmove(uint8 *dst, uint8 *src, int n)
933 if (v99x8.ctrl[45] & 0x04) /* Direction to left */
938 vcom_lset(*dst, *src);
944 static void vcom_lcopy(uint8 *dst, uint8 *src, int nx, int ny)
950 vcom_lmove(dst, src, nx);
958 vcom_lmove(dst, src, nx);
967 \82±
\82ê
\82Í
\82 \82
\82Ü
\82Å
\82»
\82Ì
\8fê
\82µ
\82Ì
\82¬
\82È
\82à
\82Ì
\81B
969 src
\82Ì
\83f
\81[
\83^
\82ðbuf
\82É
\83o
\83C
\83g
\83R
\83s
\81[
\82µ
\81Adst
\82Ì
\90æ
\93ª
\82\90\82\89\82\98\82\85\82\8c\88Ê
\92u
\82É
\82 \82¤
\82æ
\82¤
\82É
\83r
\83b
\83g
\83V
\83t
\83g
\82µ
\81A
970 \90æ
\92[
\82Æ
\8fI
\92[
\82Ì
\83f
\81[
\83^
\82ðdst
\82Æ
\8d\87\90¬
\82µ
\82Ä
\81A
\82»
\82ê
\82ðdst
\82Ölogop
\82ð
\8dl
\97¶
\82µ
\82Â
\82Â
\81A
\83o
\83C
\83g
\83R
\83s
971 \81[
\82·
\82ê
\82Î
\82¢
\82¢
\82Ì
\82©
\81H
973 \82Å
\81ASCREEN8
\82Ì
\8e\9e\82â
\81Asrc
\82Ædst
\82Ìpixel
\88Ê
\92u
\82ª
\93¯
\82¶
\82È
\82ç
\81A
\83V
\83t
\83g
\8f\88\97\9d\82ð
\82µ
\82È
\82¢
\82æ
\82¤
974 \82É
\82·
\82é
\81A
\82Æ
\81B
976 \83R
\83X
\83g
\82Í
\82©
\82©
\82é
\82¯
\82Ç
\81A1pix
\82¸
\82Â
\82¿
\82Ü
\82¿
\82Ü
\83R
\83s
\81[
\82·
\82é
\82æ
\82è
\82©
\82Í
\91¬
\82»
\82¤
\82È
\8bC
\82ª
\82·
\82é
\81B
978 \82»
\82Ì
\8fê
\8d\87 vcom_lset
\82É
\82à
\8eè
\92¼
\82µ
\82ª
\95K
\97v
\82É
\82È
\82é
\82Æ(T
\95t
\82«
\98_
\97\9d\89\89\8eZ
\95\94\95ª)
\81B
979 \82¾
\82¯
\82Ç memmove
\82Ì
\8c\8f\82Ì
\82æ
\82¤
\82É
\81A
\88ê
\92Ubuf
\82É
\83Z
\81[
\83u
\82·
\82é
\82Æ
\81AVRAM
\89ó
\82µ
\82¿
\82á
\82¤
\82©
\82à
\81B
981 \82Æ
\82·
\82é
\82Æ
\81c
\89º
\82Ý
\82½
\82¢
\82É
\82¿
\82Ü
\82¿
\82Ü
\83R
\83s
\81[
\82µ
\82Ä
\82
\82µ
\82©
\82È
\82¢
\82Ì
\82©
\82È
\82\9f\81c
983 #ifdef YAN_V99X8_TEST
984 static void vcom_lbcopy(int sx, int sy, int dx, int dy, int nx, int ny)
999 vcom_lpset(dx, dy, (int)vcom_point(sx, sy));
1015 vcom_lpset(dx, dy, (int)vcom_point(sx, sy));
1027 #endif /* YAN_V99X8_TEST */
1030 void vcom_lputc(int m) /* XXX
\8d¶
\95û
\8cü
\81A
\8fã
\95û
\8cü
\82Ì
\83e
\83X
\83g
\82Í
\82µ
\82Ä
\82Ü
\82¹
\82ñ */
1035 dst = vcom_vram(r44.x, r44.y);
1042 pixn = r44.x & pixmask.xmask;
1043 dot = (*dst >> ((1 - pixn) * pixmask.npix)) & pixmask.mask;
1045 *dst = (*dst & pixmask.pmask[pixn]) | (dot << pixmask.lshift[pixn]);
1050 case V99X8_SCREEN_5:
1051 case V99X8_SCREEN_7:
1053 dot = (*dst >> ((1 - (r44.x & 1)) * 4)) & 0x0f;
1055 if ((r44.x & 1) == 0)
1056 *dst = (*dst & 0x0f) | (dot << 4);
1058 *dst = (*dst & 0xf0) | dot;
1061 case V99X8_SCREEN_6:
1063 dot = (*dst >> ((1 - (r44.x & 3)) * 2)) & 0x03;
1065 switch (r44.x & 0x03)
1068 *dst = (*dst & 0x3f) | (dot << 6);
1071 *dst = (*dst & 0xcf) | (dot << 4);
1074 *dst = (*dst & 0xf3) | (dot << 2);
1077 *dst = (*dst & 0xfc) | dot;
1081 case V99X8_SCREEN_8:
1082 vcom_lset(*dst, m & 0xff);
1088 if (r44.sx <= r44.ex)
1090 if (++r44.x >= r44.ex)
1093 if (r44.sy < r44.ey)
1095 if (++r44.y >= r44.ey)
1096 v99x8.status[2] &= ~0x01;
1099 if (--r44.y < r44.ey)
1100 v99x8.status[2] &= ~0x01;
1105 if (--r44.x < r44.ex)
1108 if (r44.sy <= r44.ey)
1110 if (++r44.y > r44.ey)
1111 v99x8.status[2] &= ~0x01;
1114 if (--r44.y < r44.ey)
1115 v99x8.status[2] &= ~0x01;
1122 void vcom_hputc(int m) /* XXX
\8d¶
\95û
\8cü
\81A
\8fã
\95û
\8cü
\82Ì
\83e
\83X
\83g
\82Í
\82µ
\82Ä
\82Ü
\82¹
\82ñ */
1124 *vcom_vram(r44.x, r44.y) = m;
1126 if (r44.sx <= r44.ex)
1128 r44.x += 1 << vcom.xshift;
1130 if (r44.x >= r44.ex)
1133 if (r44.sy <= r44.ey)
1135 if ((++r44.y) >= r44.ey)
1136 v99x8.status[2] &= ~0x01;
1139 if ((--r44.y) <= r44.ey)
1140 v99x8.status[2] &= ~0x01;
1145 r44.x -= 1 << vcom.xshift;
1147 if (r44.x <= r44.ex)
1150 if (r44.sy <= r44.ey)
1152 if ((++r44.y) >= r44.ey)
1153 v99x8.status[2] &= ~0x01;
1156 if ((--r44.y) <= r44.ey)
1157 v99x8.status[2] &= ~0x01;
1164 void v99x8_cputovdp(int m)
1166 if ((v99x8.status[2] & 0x01) == 0)
1169 switch(v99x8.ctrl[46] >> 4)
1180 static void lmmc(void)
1188 r44.sx = r44.x = vcom.dx;
1189 r44.sy = r44.y = vcom.dy;
1190 r44.ex = vcom.dx + vcom.nx;
1191 r44.ey = vcom.dy + vcom.ny;
1193 vcom_lputc(v99x8.ctrl[44]);
1197 static void lmcm(void);
1199 static void stop(void);
1202 static void vcom_lpset(int x,int y, int clr)
1205 int src_dot, dst_dot;
1207 dst = vcom_vram(x, y);
1213 pixn = x & pixmask.xmask;
1214 src_dot = clr & pixmask.mask;
1215 dst_dot = (*dst >> pixmask.rshift[pixn]) & pixmask.mask;
1216 vcom_lset(dst_dot, src_dot);
1217 *dst = (*dst & pixmask.pmask[pixn]) | (dst_dot << pixmask.lshift[pixn]);
1222 case V99X8_SCREEN_5:
1223 case V99X8_SCREEN_7:
1224 src_dot = clr & 0x0f;
1225 dst_dot = (*dst >> ((1 - (x & 1)) * 4)) & 0x0f;
1226 vcom_lset(dst_dot, src_dot);
1228 *dst = (*dst & 0x0f) | (dst_dot << 4);
1230 *dst = (*dst & 0xf0) | dst_dot;
1233 case V99X8_SCREEN_6:
1234 src_dot = clr & 0x03;
1235 dst_dot = (*dst >> ((1 - (r44.x & 3)) * 2)) & 0x03;
1236 vcom_lset(dst_dot, src_dot);
1240 *dst = (*dst & 0x3f) | (src_dot << 6);
1243 *dst = (*dst & 0xcf) | (src_dot << 4);
1246 *dst = (*dst & 0xf3) | (src_dot << 2);
1249 *dst = (*dst & 0xfc) | src_dot;
1253 case V99X8_SCREEN_8:
1254 vcom_lset(*dst, clr & 0xff);
1261 static void line(void)
1268 maj = (v99x8.ctrl[40] + (v99x8.ctrl[41] << 8)) & 1023;
1269 min = (v99x8.ctrl[42] + (v99x8.ctrl[43] << 8)) & 511;
1272 maj = (maj == 0) ? (1) : (maj);
1274 for (i = 0; i <= maj; i++)
1276 j = (i * min) / maj;
1277 if (v99x8.ctrl[45] & 0x01)
1279 y = vcom.dy + ((v99x8.ctrl[45] & 0x08) ? -i : i);
1280 x = vcom.dx + ((v99x8.ctrl[45] & 0x04) ? -j : j);
1283 x = vcom.dx + ((v99x8.ctrl[45] & 0x04) ? -i : i);
1284 y = vcom.dy + ((v99x8.ctrl[45] & 0x08) ? -j : j);
1286 vcom_lpset(x, y, v99x8.ctrl[44]);
1290 static uint8 vcom_point(int x, int y)
1292 uint8 clr = *vcom_vram(x, y);
1298 pixn = x & pixmask.xmask;
1299 clr = (clr >> pixmask.rshift[pixn]) & pixmask.mask;
1304 case V99X8_SCREEN_5:
1305 case V99X8_SCREEN_7:
1306 clr = (clr >> (4 * (x & 1))) & 0x0F;
1308 case V99X8_SCREEN_6:
1309 clr = (clr >> (2 * (x & 3))) & 0x03;
1317 static void srch(void)
1325 v99x8.status[2] &= ~0x10;
1326 while ((0 <= (vcom.sx + i)) && ((vcom.sx + i) <= vcom.xmask))
1328 uint8 clr = vcom_point(vcom.sx + i, vcom.sy);
1329 if (v99x8.ctrl[45] & 0x02)
1331 if (clr != v99x8.ctrl[44])
1333 v99x8.status[2] |= 0x10;
1338 if (clr == v99x8.ctrl[44])
1340 v99x8.status[2] |= 0x10;
1344 i = (v99x8.ctrl[45] & 0x04) ? (i - 1) : (i + 1);
1347 if (v99x8.status[2] & 0x10)
1349 v99x8.status[8] = (vcom.sx + i) & 0xff;
1350 v99x8.status[9] = (((vcom.sx + i) >> 8) & 0x03) | 0xfc;
1355 static void pset(void)
1359 vcom_lpset(vcom.dx, vcom.dy, v99x8.ctrl[44]);
1363 static void point(void)
1367 v99x8.status[7] = vcom_point(vcom.sx, vcom.sy);
1370 static void hmmc(void)
1378 r44.sx = r44.x = vcom.dx & ~1;
1379 r44.sy = r44.y = vcom.dy;
1380 r44.ex = (vcom.dx + vcom.nx) & ~1;
1381 r44.ey = vcom.dy + vcom.ny;
1382 r44.xsize = vcom.nx & ~1;
1384 vcom_hputc(v99x8.ctrl[44]);
1387 static void lmmm(void)
1398 /* printf("hmmm: (%d,%d)->(%d,%d) *(%d,%d)\n", vcom.sx, vcom.sy, vcom.dx, vcom.dy, vcom.nx, vcom.ny); */
1399 n = vcom_canonaddr();
1400 #if YAN_V99X8_TEST /* XXX */
1401 vcom_lbcopy(vcom.sx, vcom.sy, vcom.dx, vcom.dy, vcom.nx, n);
1403 vcom_lcopy(vcom.dst, vcom.src, vcom.nx, n);
1405 vcom_setsy(vcom.sy + n);
1406 vcom_setdy(vcom.dy + n);
1408 if (vcom.ny != abs(n))
1409 vcom_setny(vcom.ny - abs(n));
1413 static void lmmm_(void);
1416 static void vcom_lfill(uint8 *p, int clr, int n)
1418 if (n == 0) /*
\83o
\83C
\83g
\90\94\92P
\88Ê
\82Å
\8f\88\97\9d\82ð
\82¨
\82±
\82È
\82¤
\82½
\82ß */
1419 n = 1; /* 1dot
\82ª
\96³
\8e\8b\82³
\82ê
\82Ä
\82µ
\82Ü
\82¤
\91Î
\89\9e */
1466 static void lmmv(void) /* XXX byte
\92P
\88Ê
\82Å
\8f\88\97\9d\82µ
\82Ä
\82é
\82Ì
\82Í
\8eè
\94²
\82«(^^; */
1476 clr = v99x8.ctrl[44];
1477 switch (vcom.xshift)
1485 ny = n = vcom_canonaddr();
1490 vcom_lfill(vcom.dst, clr, vcom.nx);
1491 vcom.dst -= vcom.xbytes;
1497 vcom_lfill(vcom.dst, clr, vcom.nx);
1498 vcom.dst += vcom.xbytes;
1502 vcom_setsy(vcom.sy + n);
1503 vcom_setdy(vcom.dy + n);
1505 if (vcom.ny != abs(n))
1506 vcom_setny(vcom.ny - abs(n));
1510 static void lmmv_(void);
1513 void v99x8_command(int m)
1515 if (v99x8.mode.xsize == 0) /* XXX */
1518 vcom.xbytes = v99x8.mode.xsize >> v99x8.mode.xshift;
1519 vcom.xmask = v99x8.mode.xsize - 1;
1520 vcom.xshift = v99x8.mode.xshift;
1522 vcom.ymask = v99x8.pages * 0x4000 / vcom.xbytes - 1;
1523 vcom.yshift = getshift(vcom.xbytes - 1);
1526 pixmask = pixmasks[(v99x8.scr - V99X8_SCREEN_5) & 0x03];
1529 v99x8.status[2] |= 0x01;
1539 case 0xf: hmmc(); break;
1540 case 0xe: ymmm(); break;
1541 case 0xd: hmmm(); break;
1542 case 0xc: hmmv(); break;
1543 case 0xb: lmmc(); break;
1544 case 0xa: lmcm(); break;
1545 case 0x9: lmmm_(); break;
1546 case 0x8: lmmv_(); break;
1547 case 0x7: line(); break;
1548 case 0x6: srch(); break;
1549 case 0x5: pset(); break;
1550 case 0x4: point(); break;
1551 case 0x0: stop(); break;
1554 v99x8.ctrl[46] &= 0x0f;
1556 if (((m >> 4) != 0xb) && ((m >> 4) != 0xf) && (0 == cmdtime_t)) v99x8.status[2] &= ~0x01;
1559 if ((m >> 4) != 0xb && (m >> 4) != 0xf)
1560 v99x8.status[2] &= ~0x01;
1564 // from "v99x8_refresh.c" of Zodiac
1567 * Copyright (c) 2000-2002 SASAKI Shunsuke (eruchan@users.sourceforge.net).
1568 * Copyright (c) 2001-2002 The Zodiac project.
1569 * All rights reserved.
1571 * This program is free software; you can redistribute it and/or modify
1572 * it under the terms of the GNU General Public License as published by
1573 * the Free Software Foundation; either version 2 of the License, or
1574 * (at your option) any later version.
1576 * This program is distributed in the hope that it will be useful,
1577 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1578 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1579 * GNU General Public License for more details.
1581 * You should have received a copy of the GNU General Public License
1582 * along with this program; if not, write to the Free Software
1583 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1586 //#include "../../config.h"
1589 //#include <string.h>
1591 //#include "../zodiac.h"
1598 # define UINT32_FROM16(n1, n2) ((n2) << 16 | (n1))
1599 # define UINT8_FROM4(n1, n2) ((n1) << 4 | (n2))
1601 # define UINT32_FROM16(n1, n2) ((n1) << 16 | (n2))
1602 # define UINT8_FROM4(n1, n2) ((n2) << 4 | (n1))
1613 static v99x8_refresh_t v99x8_refresh;
1625 static v99x8_pallete_t pal[16 + 1];
1626 static uint32 pal_8[256];
1627 static uint32 pal_m[256];
1632 void v99x8_pallete_set(uint8 n, uint8 r, uint8 g, uint8 b)
1637 pal[n].r = r * 31 / 7;
1638 pal[n].g = g * 31 / 7;
1639 pal[n].b = b * 31 / 7;
1645 static int col_bg = 0;
1647 static void v99x8_pallete_update(void)
1653 for (i = 1; i < 17; ++i)
1655 pal[i].color = md_maprgb15(pal[i].r, pal[i].g, pal[i].b);
1657 a = (v99x8.col_bg == 0 || (v99x8.ctrl[8] & 0x20)) ? 16 : v99x8.col_bg;
1658 if (col_bg != a || pal[a].flag)
1662 memcpy(&pal[0], &pal[a], sizeof(v99x8_pallete_t));
1671 for (i = 0; i < 16; ++i)
1673 for (j = 0; j < 16; ++j)
1675 if (!pal[i].flag && !pal[j].flag)
1678 a = UINT8_FROM4(i, j);
1682 pal_m[a] = pal[i].color;
1685 pal_m[a] = md_maprgb15((pal[i].r >> 1) + (pal[j].r >> 1),
1686 (pal[i].g >> 1) + (pal[j].g >> 1),
1687 (pal[i].b >> 1) + (pal[j].b >> 1));
1693 for (i = 0; i < 17; ++i)
1694 pal[i].flag = FALSE;
1697 static void v99x8_pallete_init(void)
1699 static const uint8 inipal[16][3] =
1701 {0, 0, 0}, {0, 0, 0}, {1, 6, 1}, {3, 7, 3},
1702 {1, 1, 7}, {2, 3, 7}, {5, 1, 1}, {2, 6, 7},
1703 {7, 1, 1}, {7, 3, 3}, {6, 6, 1}, {6, 6, 4},
1704 {1, 4, 1}, {6, 2, 5}, {5, 5, 5}, {7, 7, 7}
1710 memset(pal, 0, sizeof(pal));
1712 pal_black = md_maprgb15(0, 0, 0);
1713 for (i = 0; i < 256; ++i)
1716 /* i & 0x1c, (i >> 3) & 0x1c, (i & 3) << 3); */
1717 pal_8[i] = md_maprgb15((i & 0x1c) * 31 / (7 << 2),
1718 (i & 0xe0) * 31 / (7 << 5),
1720 pal_m[i] = pal_black;
1723 for(i = 0; i < 16; i++)
1724 v99x8_pallete_set(i, inipal[i][0], inipal[i][1], inipal[i][2]);
1730 #define V99X8_WIDTH (256 + 15)
1731 #define V99X8_HEIGHT (212 + 15)
1734 static uint8 tbl_yjk_b[32 * 64 * 64], tbl_yjk_rg[62 + 32];
1735 static uint8 blackbuf[256]; /* sprite
\94ñ
\95\
\8e¦
\97p
\83o
\83b
\83t
\83@ */
1738 void v99x8_refresh_init(void)
1741 md_video_mode_t mode;
1743 v99x8_refresh.width = V99X8_WIDTH;
1744 v99x8_refresh.height = V99X8_HEIGHT;
1748 v99x8_refresh.width *= 2;
1749 v99x8_refresh.height *= 2;
1752 mode.width = v99x8_refresh.width;
1753 mode.height = v99x8_refresh.height;
1756 mode.bpp = v99x8_refresh.bpp = MD_BPP;
1758 mode.bpp = v99x8_refresh.bpp = 16;
1761 mode.option = md_video_defaultopt();
1764 md_video_fixmode(&mode);
1765 if (!md_video_setmode(v99x8_refresh.width, v99x8_refresh.height, &mode, NULL))
1768 v99x8_refresh.bpp = md_video_bpp();
1771 v99x8_pallete_init();
1773 for (i = 0; i < 32; ++i)
1778 for (j = 0; j < 64; ++j)
1781 for (k = 0; k < 64; ++k)
1783 n = (i * 5 - ((j & 0x20) ? j - 64 : j) * 2
1784 - ((k & 0x20) ? k - 64 : k)) >> 2;
1790 tbl_yjk_b[(((j + 32) & 63) << 11)
1791 + (((k + 32) & 63) << 5) + i] = n;
1796 tbl_yjk_rg[i + 32] = i;
1797 tbl_yjk_rg[i + 64] = 31;
1808 b: (5Y + 2J + K) >> 2
1810 memset(blackbuf, 0, sizeof(blackbuf));
1813 void V99X8::v99x8_refresh_screen(void)
1815 md_video_update(0, NULL);
1818 void V99X8::v99x8_refresh_clear(void)
1820 md_video_fill(0, 0, v99x8_refresh.width, v99x8_refresh.height, pal[v99x8.col_bg].color);
1823 uint8 *V99X8::v99x8_refresh_start(int x, int w, int h)
1827 v99x8_pallete_update();
1829 a = v99x8.f_zoom ? 2 : 1;
1831 return md_video_lockline((((7 - v99x8.ctrl[18]) & 0x0f) + x) * a
1832 , v99x8.scanline * a
1836 static __inline__ void v99x8_refresh_stop(void)
1838 md_video_unlockline();
1846 # define pixel_put(pb, n, px) *((md_pixel_t *)(pb) + (n)) = (px)
1853 # define pixel_put(pb, n, px) *((uint8 *)(pb) + (n) / 4) \
1854 |= (px) << ((3 - (n)) * 2)
1856 # define pixel_put(pb, n, px) *((uint8 *)(pb) + (n) / 4) \
1857 |= (px) << ((n) * 2)
1865 static __inline__ void pixel_put(void *pb, int n, uint32 p1)
1870 switch (v99x8_refresh.bpp)
1873 *((uint16 *)pb + n) = p1;
1876 *((uint8 *)pb + n) = p1;
1879 *((uint32 *)pb + n) = p1;
1882 p = (uint8 *)pb + (n >> 2);
1884 mask = 0xc0 >> ((n & 3) * 2);
1885 pix2bpp = p1 << (6 - ((n & 3) * 2));
1887 mask = 0x03 << ((n & 3) * 2);
1888 pix2bpp = p1 << ((n & 3) * 2);
1891 *p = (*p & ~mask) | (pix2bpp & mask);
1894 /* XXX 2bpp
\91Î
\89\9e\95û
\96@
1896 * 1.
\82Ü
\82¸
\91Î
\89\9e\82·
\82é 2bit
\82ð &
\82Å 0
\83N
\83\8a\83A
\82·
\82é
1897 * 2.
\8e\9f\82É
\81A2bit
\82ð |
\82Å
\89Á
\82¦
\82é
1899 *
\82Æ
\82¢
\82¤
\8eè
\8f\87\82ª
\95K
\97v
\81B
\91Î
\89\9e\82Í
\8cã
\93ú
\82É
\82Ä.... --
\82k
1909 static uint8 sbuf[32 + 256 + 16];
1921 static uint8 *v99x8_refresh_sprite1(uint8 y)
1923 v99x8_sprite_t *ptr_a;
1926 uint8 a, c, *ptr_g, *ptr_s, *tbl_sp;
1929 /* if (v99x8.ctrl[8] & 0x02)
1932 /* tbl_sp = &v99x8.vram[(int)v99x8.ctrl[6] << 11]; */
1933 tbl_sp = v99x8.vram + ((int)v99x8.ctrl[6] << 11);
1935 memset(sbuf + 32, 0, 256);
1937 size = (v99x8.ctrl[1] & 0x02) ? 16 : 8;
1943 ptr_a = (v99x8_sprite_t *)(v99x8.vram + ((int)v99x8.ctrl[11] << 15)
1944 + ((int)v99x8.ctrl[5] << 7));
1946 for (i = 0 ;; ++i, ++ptr_a)
1948 if (i >= 32 || n >= 4 || ptr_a->y == 208)
1951 a = (uint8)(ptr_a->y - v99x8.ctrl[23]); /* a>256-h? a-=256 */
1952 if (a >=y || a + size < y)
1959 ptr_s = sbuf + ptr_a->x + ((c & 0x80) ? 0 : 32);
1961 + (((v99x8.ctrl[1] & 0x02) ? ptr_a->n & 0xfc : ptr_a->n) << 3);
1966 if (ptr_s[0] == 0 && (*ptr_g & 0x80)) ptr_s[0] = c;
1967 if (ptr_s[1] == 0 && (*ptr_g & 0x40)) ptr_s[1] = c;
1968 if (ptr_s[2] == 0 && (*ptr_g & 0x20)) ptr_s[2] = c;
1969 if (ptr_s[3] == 0 && (*ptr_g & 0x10)) ptr_s[3] = c;
1970 if (ptr_s[4] == 0 && (*ptr_g & 0x08)) ptr_s[4] = c;
1971 if (ptr_s[5] == 0 && (*ptr_g & 0x04)) ptr_s[5] = c;
1972 if (ptr_s[6] == 0 && (*ptr_g & 0x02)) ptr_s[6] = c;
1973 if (ptr_s[7] == 0 && (*ptr_g & 0x01)) ptr_s[7] = c;
1975 if (!(v99x8.ctrl[1] & 0x02))
1981 if (ptr_s[0] == 0 && (*ptr_g & 0x80)) ptr_s[0] = c;
1982 if (ptr_s[1] == 0 && (*ptr_g & 0x40)) ptr_s[1] = c;
1983 if (ptr_s[2] == 0 && (*ptr_g & 0x20)) ptr_s[2] = c;
1984 if (ptr_s[3] == 0 && (*ptr_g & 0x10)) ptr_s[3] = c;
1985 if (ptr_s[4] == 0 && (*ptr_g & 0x08)) ptr_s[4] = c;
1986 if (ptr_s[5] == 0 && (*ptr_g & 0x04)) ptr_s[5] = c;
1987 if (ptr_s[6] == 0 && (*ptr_g & 0x02)) ptr_s[6] = c;
1988 if (ptr_s[7] == 0 && (*ptr_g & 0x01)) ptr_s[7] = c;
1994 static uint8 *v99x8_refresh_sprite2(uint8 y)
1996 v99x8_sprite_t *ptr_a;
1999 uint8 a, c, *ptr_g, *ptr_c, *ptr_s, *tbl_sp;
2002 if (v99x8.ctrl[8] & 0x02)
2005 tbl_sp = v99x8.vram + ((int)v99x8.ctrl[6] << 11);
2007 memset(sbuf + 32, 0, 256);
2009 size = (v99x8.ctrl[1] & 0x02) ? 16 : 8;
2016 ptr_c = v99x8.vram + ((int)v99x8.ctrl[11] << 15)
2017 + ((int)(v99x8.ctrl[5] & 0xf8) << 7);
2018 ptr_a = (v99x8_sprite_t *)(ptr_c + 0x200);
2020 for (i = 0 ;; ++i, ++ptr_a, ptr_c += 16)
2022 if (i >= 32 || n >= 8 || ptr_a->y == 216)
2025 a = (uint8)(ptr_a->y - v99x8.ctrl[23]); /* a>256-h? a-=256 */
2026 if (a >= y || a + size < y)
2033 ptr_s = sbuf + ptr_a->x + ((c & 0x80) ? 0 : 32);
2035 + (((v99x8.ctrl[1] & 0x02) ? ptr_a->n & 0xfc : ptr_a->n) << 3);
2037 if ((c & 0x40) == 0)
2042 if (ptr_s[0] == 0 && (*ptr_g & 0x80)) ptr_s[0] = c;
2043 if (ptr_s[1] == 0 && (*ptr_g & 0x40)) ptr_s[1] = c;
2044 if (ptr_s[2] == 0 && (*ptr_g & 0x20)) ptr_s[2] = c;
2045 if (ptr_s[3] == 0 && (*ptr_g & 0x10)) ptr_s[3] = c;
2046 if (ptr_s[4] == 0 && (*ptr_g & 0x08)) ptr_s[4] = c;
2047 if (ptr_s[5] == 0 && (*ptr_g & 0x04)) ptr_s[5] = c;
2048 if (ptr_s[6] == 0 && (*ptr_g & 0x02)) ptr_s[6] = c;
2049 if (ptr_s[7] == 0 && (*ptr_g & 0x01)) ptr_s[7] = c;
2051 if (!(v99x8.ctrl[1] & 0x02))
2054 ptr_s += 8; ptr_g += 16;
2055 if (ptr_s[0] == 0 && (*ptr_g & 0x80)) ptr_s[0] = c;
2056 if (ptr_s[1] == 0 && (*ptr_g & 0x40)) ptr_s[1] = c;
2057 if (ptr_s[2] == 0 && (*ptr_g & 0x20)) ptr_s[2] = c;
2058 if (ptr_s[3] == 0 && (*ptr_g & 0x10)) ptr_s[3] = c;
2059 if (ptr_s[4] == 0 && (*ptr_g & 0x08)) ptr_s[4] = c;
2060 if (ptr_s[5] == 0 && (*ptr_g & 0x04)) ptr_s[5] = c;
2061 if (ptr_s[6] == 0 && (*ptr_g & 0x02)) ptr_s[6] = c;
2062 if (ptr_s[7] == 0 && (*ptr_g & 0x01)) ptr_s[7] = c;
2069 if (*ptr_g & 0x80) ptr_s[0] |= c;
2070 if (*ptr_g & 0x40) ptr_s[1] |= c;
2071 if (*ptr_g & 0x20) ptr_s[2] |= c;
2072 if (*ptr_g & 0x10) ptr_s[3] |= c;
2073 if (*ptr_g & 0x08) ptr_s[4] |= c;
2074 if (*ptr_g & 0x04) ptr_s[5] |= c;
2075 if (*ptr_g & 0x02) ptr_s[6] |= c;
2076 if (*ptr_g & 0x01) ptr_s[7] |= c;
2078 if (!(v99x8.ctrl[1] & 0x02))
2081 ptr_s += 8; ptr_g += 16;
2082 if (*ptr_g & 0x80) ptr_s[0] |= c;
2083 if (*ptr_g & 0x40) ptr_s[1] |= c;
2084 if (*ptr_g & 0x20) ptr_s[2] |= c;
2085 if (*ptr_g & 0x10) ptr_s[3] |= c;
2086 if (*ptr_g & 0x08) ptr_s[4] |= c;
2087 if (*ptr_g & 0x04) ptr_s[5] |= c;
2088 if (*ptr_g & 0x02) ptr_s[6] |= c;
2089 if (*ptr_g & 0x01) ptr_s[7] |= c;
2097 void V99X8::v99x8_refresh_sc0(int y, int h)
2106 v99x8.tbl_pg = v99x8.vram + (((int)v99x8.ctrl[4] & 0x3f) << 11);
2107 v99x8.tbl_pn = v99x8.vram + (((int)v99x8.ctrl[2] & 0x7f) << 10);
2111 pbuf = v99x8_refresh_start(8, 240, h);
2112 pp = md_video_pitch() - md_video_pixbytes(240);
2114 fg = pal[v99x8.col_fg].color;
2115 bg = pal[v99x8.col_bg].color;
2122 T = v99x8.tbl_pn + (y >> 3) * 40;
2123 G = v99x8.tbl_pg + (y & 0x07);
2126 for (i = 0; i < 40; ++i)
2130 a = G[(int)*T++ << 3];
2133 pixel_put(pbuf, 0, (a & 0x80)? fg : bg);
2134 pixel_put(pbuf, 1, (a & 0x80)? fg : bg);
2135 pixel_put(pbuf, 2, (a & 0x40)? fg : bg);
2136 pixel_put(pbuf, 3, (a & 0x40)? fg : bg);
2137 pixel_put(pbuf, 4, (a & 0x20)? fg : bg);
2138 pixel_put(pbuf, 5, (a & 0x20)? fg : bg);
2139 pixel_put(pbuf, 6, (a & 0x10)? fg : bg);
2140 pixel_put(pbuf, 7, (a & 0x10)? fg : bg);
2141 pixel_put(pbuf, 8, (a & 0x08)? fg : bg);
2142 pixel_put(pbuf, 9, (a & 0x08)? fg : bg);
2143 pixel_put(pbuf, 10, (a & 0x04)? fg : bg);
2144 pixel_put(pbuf, 11, (a & 0x04)? fg : bg);
2145 pbuf += md_video_pixbytes(12);
2148 pixel_put(pbuf, 0, (a & 0x80)? fg : bg);
2149 pixel_put(pbuf, 1, (a & 0x40)? fg : bg);
2150 pixel_put(pbuf, 2, (a & 0x20)? fg : bg);
2151 pixel_put(pbuf, 3, (a & 0x10)? fg : bg);
2152 pixel_put(pbuf, 4, (a & 0x08)? fg : bg);
2153 pixel_put(pbuf, 5, (a & 0x04)? fg : bg);
2154 pbuf += md_video_pixbytes(6);
2160 v99x8_refresh_stop();
2163 void V99X8::v99x8_refresh_sc1(int y, int h)
2172 v99x8.tbl_pg = v99x8.vram + (((int)v99x8.ctrl[4] & 0x3f) << 11);
2173 v99x8.tbl_pn = v99x8.vram + (((int)v99x8.ctrl[2] & 0x7f) << 10);
2174 v99x8.tbl_cl = v99x8.vram + (((int)v99x8.ctrl[10] & 0x07) << 14)
2175 + ((int)v99x8.ctrl[3] << 6);
2179 pbuf = v99x8_refresh_start(0, 256, h);
2180 pp = md_video_pitch() - md_video_pixbytes(256);
2184 n = v99x8.ctrl[23] + y;
2185 G = v99x8.tbl_pg + (n & 0x07);
2186 T = v99x8.tbl_pn + ((n & 0xF8) << 2);
2187 sp = v99x8_refresh_sprite1(y++);
2189 for(i = 0; i < 32; ++i)
2195 n = v99x8.tbl_cl[*T >> 3];
2196 fg = pal[n >> 4].color;
2197 bg = pal[n & 0x0f].color;
2199 a = G[(int)*T++ << 3];
2202 pixel_put(pbuf, 0, sp[0] ? pal[sp[0]].color : (a & 0x80) ? fg : bg);
2203 pixel_put(pbuf, 1, sp[0] ? pal[sp[0]].color : (a & 0x80) ? fg : bg);
2204 pixel_put(pbuf, 2, sp[1] ? pal[sp[1]].color : (a & 0x40) ? fg : bg);
2205 pixel_put(pbuf, 3, sp[1] ? pal[sp[1]].color : (a & 0x40) ? fg : bg);
2206 pixel_put(pbuf, 4, sp[2] ? pal[sp[2]].color : (a & 0x20) ? fg : bg);
2207 pixel_put(pbuf, 5, sp[2] ? pal[sp[2]].color : (a & 0x20) ? fg : bg);
2208 pixel_put(pbuf, 6, sp[3] ? pal[sp[3]].color : (a & 0x10) ? fg : bg);
2209 pixel_put(pbuf, 7, sp[3] ? pal[sp[3]].color : (a & 0x10) ? fg : bg);
2210 pixel_put(pbuf, 8, sp[4] ? pal[sp[4]].color : (a & 0x08) ? fg : bg);
2211 pixel_put(pbuf, 9, sp[4] ? pal[sp[4]].color : (a & 0x08) ? fg : bg);
2212 pixel_put(pbuf, 10, sp[5] ? pal[sp[5]].color : (a & 0x04) ? fg : bg);
2213 pixel_put(pbuf, 11, sp[5] ? pal[sp[5]].color : (a & 0x04) ? fg : bg);
2214 pixel_put(pbuf, 12, sp[6] ? pal[sp[6]].color : (a & 0x02) ? fg : bg);
2215 pixel_put(pbuf, 13, sp[6] ? pal[sp[6]].color : (a & 0x02) ? fg : bg);
2216 pixel_put(pbuf, 14, sp[7] ? pal[sp[7]].color : (a & 0x01) ? fg : bg);
2217 pixel_put(pbuf, 15, sp[7] ? pal[sp[7]].color : (a & 0x01) ? fg : bg);
2218 pbuf += md_video_pixbytes(16);
2222 pixel_put(pbuf, 0, sp[0] ? pal[sp[0]].color : (a & 0x80) ? fg : bg);
2223 pixel_put(pbuf, 1, sp[1] ? pal[sp[1]].color : (a & 0x40) ? fg : bg);
2224 pixel_put(pbuf, 2, sp[2] ? pal[sp[2]].color : (a & 0x20) ? fg : bg);
2225 pixel_put(pbuf, 3, sp[3] ? pal[sp[3]].color : (a & 0x10) ? fg : bg);
2226 pixel_put(pbuf, 4, sp[4] ? pal[sp[4]].color : (a & 0x08) ? fg : bg);
2227 pixel_put(pbuf, 5, sp[5] ? pal[sp[5]].color : (a & 0x04) ? fg : bg);
2228 pixel_put(pbuf, 6, sp[6] ? pal[sp[6]].color : (a & 0x02) ? fg : bg);
2229 pixel_put(pbuf, 7, sp[7] ? pal[sp[7]].color : (a & 0x01) ? fg : bg);
2231 pbuf += md_video_pixbytes(8);
2238 v99x8_refresh_stop();
2241 void V99X8::v99x8_refresh_sc4(int y, int h)
2245 uint8 *T, *PGT, *CLT;
2251 v99x8.tbl_pg = v99x8.vram + (((int)v99x8.ctrl[4] & 0x3c) << 11);
2252 v99x8.tbl_pn = v99x8.vram + (((int)v99x8.ctrl[2] & 0x7f) << 10);
2253 v99x8.tbl_cl = v99x8.vram + (((int)v99x8.ctrl[10] & 0x07) << 14)
2254 + (((int)v99x8.ctrl[3] & 0x80) << 6);
2259 pbuf = v99x8_refresh_start(0, 256, h);
2260 pp = md_video_pitch() - md_video_pixbytes(256);
2264 n = v99x8.ctrl[23] + y;
2265 T = v99x8.tbl_pn + ((n & 0xf8) << 2);
2267 n = ((n & 0xc0) << 5) + (n & 0x07);
2268 PGT = v99x8.tbl_pg + n;
2269 CLT = v99x8.tbl_cl + n;
2271 if (v99x8.scr == V99X8_SCREEN_2)
2272 sp = v99x8_refresh_sprite1(y++);
2274 sp = v99x8_refresh_sprite2(y++);
2276 for (i = 0; i < 32; ++i)
2283 fg = pal[n >> 4].color;
2284 bg = pal[n & 0x0f].color;
2286 a = PGT[(int)*T++ << 3];
2290 pixel_put(pbuf, 0, sp[0] ? pal[sp[0]].color : (a & 0x80) ? fg : bg);
2291 pixel_put(pbuf, 1, sp[0] ? pal[sp[0]].color : (a & 0x80) ? fg : bg);
2292 pixel_put(pbuf, 2, sp[1] ? pal[sp[1]].color : (a & 0x40) ? fg : bg);
2293 pixel_put(pbuf, 3, sp[1] ? pal[sp[1]].color : (a & 0x40) ? fg : bg);
2294 pixel_put(pbuf, 4, sp[2] ? pal[sp[2]].color : (a & 0x20) ? fg : bg);
2295 pixel_put(pbuf, 5, sp[2] ? pal[sp[2]].color : (a & 0x20) ? fg : bg);
2296 pixel_put(pbuf, 6, sp[3] ? pal[sp[3]].color : (a & 0x10) ? fg : bg);
2297 pixel_put(pbuf, 7, sp[3] ? pal[sp[3]].color : (a & 0x10) ? fg : bg);
2298 pixel_put(pbuf, 8, sp[4] ? pal[sp[4]].color : (a & 0x08) ? fg : bg);
2299 pixel_put(pbuf, 9, sp[4] ? pal[sp[4]].color : (a & 0x08) ? fg : bg);
2300 pixel_put(pbuf, 10, sp[5] ? pal[sp[5]].color : (a & 0x04) ? fg : bg);
2301 pixel_put(pbuf, 11, sp[5] ? pal[sp[5]].color : (a & 0x04) ? fg : bg);
2302 pixel_put(pbuf, 12, sp[6] ? pal[sp[6]].color : (a & 0x02) ? fg : bg);
2303 pixel_put(pbuf, 13, sp[6] ? pal[sp[6]].color : (a & 0x02) ? fg : bg);
2304 pixel_put(pbuf, 14, sp[7] ? pal[sp[7]].color : (a & 0x01) ? fg : bg);
2305 pixel_put(pbuf, 15, sp[7] ? pal[sp[7]].color : (a & 0x01) ? fg : bg);
2306 pbuf += md_video_pixbytes(16); sp += 8;
2309 pixel_put(pbuf, 0, sp[0] ? pal[sp[0]].color : (a & 0x80)? fg : bg);
2310 pixel_put(pbuf, 1, sp[1] ? pal[sp[1]].color : (a & 0x40)? fg : bg);
2311 pixel_put(pbuf, 2, sp[2] ? pal[sp[2]].color : (a & 0x20)? fg : bg);
2312 pixel_put(pbuf, 3, sp[3] ? pal[sp[3]].color : (a & 0x10)? fg : bg);
2313 pixel_put(pbuf, 4, sp[4] ? pal[sp[4]].color : (a & 0x08)? fg : bg);
2314 pixel_put(pbuf, 5, sp[5] ? pal[sp[5]].color : (a & 0x04)? fg : bg);
2315 pixel_put(pbuf, 6, sp[6] ? pal[sp[6]].color : (a & 0x02)? fg : bg);
2316 pixel_put(pbuf, 7, sp[7] ? pal[sp[7]].color : (a & 0x01)? fg : bg);
2318 pbuf += md_video_pixbytes(8); sp += 8;
2324 v99x8_refresh_stop();
2327 void V99X8::v99x8_refresh_sc5(int y, int h)
2336 v99x8.tbl_pn = v99x8.vram + (((int)v99x8.ctrl[2] & 0x60) << 10);
2340 pbuf = v99x8_refresh_start(0, 256, h);
2341 pp = md_video_pitch() - md_video_pixbytes(256);
2343 T = v99x8.tbl_pn + (((y + v99x8.ctrl[23]) & 0xff) << 7);
2347 sp = v99x8_refresh_sprite2(y++);
2348 for (i = 0; i < 32; ++i)
2352 pixel_put(pbuf, 0, pal[sp[0] ? sp[0] : T[0] >> 4].color);
2353 pixel_put(pbuf, 1, pal[sp[0] ? sp[0] : T[0] >> 4].color);
2354 pixel_put(pbuf, 2, pal[sp[1] ? sp[1] : T[0] & 0x0f].color);
2355 pixel_put(pbuf, 3, pal[sp[1] ? sp[1] : T[0] & 0x0f].color);
2356 pixel_put(pbuf, 4, pal[sp[2] ? sp[2] : T[1] >> 4].color);
2357 pixel_put(pbuf, 5, pal[sp[2] ? sp[2] : T[1] >> 4].color);
2358 pixel_put(pbuf, 6, pal[sp[3] ? sp[3] : T[1] & 0x0f].color);
2359 pixel_put(pbuf, 7, pal[sp[3] ? sp[3] : T[1] & 0x0f].color);
2360 pixel_put(pbuf, 8, pal[sp[4] ? sp[4] : T[2] >> 4].color);
2361 pixel_put(pbuf, 9, pal[sp[4] ? sp[4] : T[2] >> 4].color);
2362 pixel_put(pbuf, 10, pal[sp[5] ? sp[5] : T[2] & 0x0f].color);
2363 pixel_put(pbuf, 11, pal[sp[5] ? sp[5] : T[2] & 0x0f].color);
2364 pixel_put(pbuf, 12, pal[sp[6] ? sp[6] : T[3] >> 4].color);
2365 pixel_put(pbuf, 13, pal[sp[6] ? sp[6] : T[3] >> 4].color);
2366 pixel_put(pbuf, 14, pal[sp[7] ? sp[7] : T[3] & 0x0f].color);
2367 pixel_put(pbuf, 15, pal[sp[7] ? sp[7] : T[3] & 0x0f].color);
2369 pbuf += md_video_pixbytes(16); T += 4; sp += 8;
2371 pixel_put(pbuf, 0, pal[sp[0] ? sp[0] : T[0] >> 4].color);
2372 pixel_put(pbuf, 1, pal[sp[1] ? sp[1] : T[0] & 0x0f].color);
2373 pixel_put(pbuf, 2, pal[sp[2] ? sp[2] : T[1] >> 4].color);
2374 pixel_put(pbuf, 3, pal[sp[3] ? sp[3] : T[1] & 0x0f].color);
2375 pixel_put(pbuf, 4, pal[sp[4] ? sp[4] : T[2] >> 4].color);
2376 pixel_put(pbuf, 5, pal[sp[5] ? sp[5] : T[2] & 0x0f].color);
2377 pixel_put(pbuf, 6, pal[sp[6] ? sp[6] : T[3] >> 4].color);
2378 pixel_put(pbuf, 7, pal[sp[7] ? sp[7] : T[3] & 0x0f].color);
2380 pbuf += md_video_pixbytes(8); T += 4; sp += 8;
2386 v99x8_refresh_stop();
2389 void V99X8::v99x8_refresh_sc6(int y, int h)
2398 v99x8.tbl_pn = v99x8.vram + (((int)v99x8.ctrl[2] & 0x60) << 10);
2403 pbuf = v99x8_refresh_start(0, 256, h);
2404 pp = md_video_pitch() - md_video_pixbytes(256);
2406 T = v99x8.tbl_pn + (((y + v99x8.ctrl[23]) & 0xff) << 7);
2410 sp = v99x8_refresh_sprite2(y++);
2411 for(i = 0; i < 32; ++i)
2415 pixel_put(pbuf, 0, pal[sp[0] ? sp[0] : T[0] >> 6].color);
2416 pixel_put(pbuf, 1, pal[sp[0] ? sp[0] : (T[0] >> 4) & 3].color);
2417 pixel_put(pbuf, 2, pal[sp[1] ? sp[1] : (T[0] >> 2) & 3].color);
2418 pixel_put(pbuf, 3, pal[sp[1] ? sp[1] : T[0] & 3].color);
2419 pixel_put(pbuf, 4, pal[sp[2] ? sp[2] : T[1] >> 6].color);
2420 pixel_put(pbuf, 5, pal[sp[2] ? sp[2] : (T[1] >> 4) & 3].color);
2421 pixel_put(pbuf, 6, pal[sp[3] ? sp[3] : (T[1] >> 2) & 3].color);
2422 pixel_put(pbuf, 7, pal[sp[3] ? sp[3] : T[1] & 3].color);
2423 pixel_put(pbuf, 8, pal[sp[4] ? sp[4] : T[2] >> 6].color);
2424 pixel_put(pbuf, 9, pal[sp[4] ? sp[4] : (T[2] >> 4) & 3].color);
2425 pixel_put(pbuf, 10, pal[sp[5] ? sp[5] : (T[2] >> 2) & 3].color);
2426 pixel_put(pbuf, 11, pal[sp[5] ? sp[5] : T[2] & 3].color);
2427 pixel_put(pbuf, 12, pal[sp[6] ? sp[6] : T[3] >> 6].color);
2428 pixel_put(pbuf, 13, pal[sp[6] ? sp[6] : (T[3] >> 4) & 3].color);
2429 pixel_put(pbuf, 14, pal[sp[7] ? sp[7] : (T[3] >> 2) & 3].color);
2430 pixel_put(pbuf, 15, pal[sp[7] ? sp[7] : T[3] & 3].color);
2431 pbuf += md_video_pixbytes(16); T += 4; sp += 8;
2434 pixel_put(pbuf, 0, sp[0] ? pal[sp[0]].color : pal_m[(T[0] >> 6) | (T[0] & 0x30)]);
2435 pixel_put(pbuf, 1, sp[1] ? pal[sp[1]].color : pal_m[((T[0] & 0x0c) << 2) | (T[0] & 0x03)]);
2436 pixel_put(pbuf, 2, sp[2] ? pal[sp[2]].color : pal_m[(T[1] >> 6) | (T[1] & 0x30)]);
2437 pixel_put(pbuf, 3, sp[3] ? pal[sp[3]].color : pal_m[((T[1] & 0x0c) << 2) | (T[1] & 0x03)]);
2438 pixel_put(pbuf, 4, sp[4] ? pal[sp[4]].color : pal_m[(T[2] >> 6) | (T[2] & 0x30)]);
2439 pixel_put(pbuf, 5, sp[5] ? pal[sp[5]].color : pal_m[((T[2] & 0x0c) << 2) | (T[2] & 0x03)]);
2440 pixel_put(pbuf, 6, sp[6] ? pal[sp[6]].color : pal_m[(T[3] >> 6) | (T[3] & 0x30)]);
2441 pixel_put(pbuf, 7, sp[7] ? pal[sp[7]].color : pal_m[((T[3] & 0x0c) << 2) | (T[3] & 0x03)]);
2442 pbuf += md_video_pixbytes(8); T += 4; sp += 8;
2448 v99x8_refresh_stop();
2451 void V99X8::v99x8_refresh_sc7(int y, int h)
2460 v99x8.tbl_pn = v99x8.vram + (((int)v99x8.ctrl[2] & 0x20) << 11);
2464 pbuf = v99x8_refresh_start(0, 256, h);
2465 pp = md_video_pitch() - md_video_pixbytes(256);
2467 /* printf("%d/%d %d %d\n", y, v99x8.ctrl[23], (y+v99x8.ctrl[23])&0xff, v99x8.ctrl[19]+1); */
2468 T = v99x8.tbl_pn + (((y + v99x8.ctrl[23]) & 0xff) << 8);
2472 sp = v99x8_refresh_sprite2(y);
2474 for (i = 0; i < 32; ++i)
2478 pixel_put(pbuf, 0, pal[sp[0] ? sp[0] : T[0] >> 4].color);
2479 pixel_put(pbuf, 1, pal[sp[0] ? sp[0] : T[0] & 0x0f].color);
2480 pixel_put(pbuf, 2, pal[sp[1] ? sp[1] : T[1] >> 4].color);
2481 pixel_put(pbuf, 3, pal[sp[1] ? sp[1] : T[1] & 0x0f].color);
2482 pixel_put(pbuf, 4, pal[sp[2] ? sp[2] : T[2] >> 4].color);
2483 pixel_put(pbuf, 5, pal[sp[2] ? sp[2] : T[2] & 0x0f].color);
2484 pixel_put(pbuf, 6, pal[sp[3] ? sp[3] : T[3] >> 4].color);
2485 pixel_put(pbuf, 7, pal[sp[3] ? sp[3] : T[3] & 0x0f].color);
2486 pixel_put(pbuf, 8, pal[sp[4] ? sp[4] : T[4] >> 4].color);
2487 pixel_put(pbuf, 9, pal[sp[4] ? sp[4] : T[4] & 0x0f].color);
2488 pixel_put(pbuf, 10, pal[sp[5] ? sp[5] : T[5] >> 4].color);
2489 pixel_put(pbuf, 11, pal[sp[5] ? sp[5] : T[5] & 0x0f].color);
2490 pixel_put(pbuf, 12, pal[sp[6] ? sp[6] : T[6] >> 4].color);
2491 pixel_put(pbuf, 13, pal[sp[6] ? sp[6] : T[6] & 0x0f].color);
2492 pixel_put(pbuf, 14, pal[sp[7] ? sp[7] : T[7] >> 4].color);
2493 pixel_put(pbuf, 15, pal[sp[7] ? sp[7] : T[7] & 0x0f].color);
2494 pbuf += md_video_pixbytes(16); T += 8; sp += 8;
2497 pixel_put(pbuf,0, sp[0]? pal[sp[0]].color : pal_m[T[0]]);
2498 pixel_put(pbuf,1, sp[1]? pal[sp[1]].color : pal_m[T[1]]);
2499 pixel_put(pbuf,2, sp[2]? pal[sp[2]].color : pal_m[T[2]]);
2500 pixel_put(pbuf,3, sp[3]? pal[sp[3]].color : pal_m[T[3]]);
2501 pixel_put(pbuf,4, sp[4]? pal[sp[4]].color : pal_m[T[4]]);
2502 pixel_put(pbuf,5, sp[5]? pal[sp[5]].color : pal_m[T[5]]);
2503 pixel_put(pbuf,6, sp[6]? pal[sp[6]].color : pal_m[T[6]]);
2504 pixel_put(pbuf,7, sp[7]? pal[sp[7]].color : pal_m[T[7]]);
2506 pbuf += md_video_pixbytes(8); T += 8; sp += 8;
2514 v99x8_refresh_stop();
2517 void V99X8::v99x8_refresh_sc8(int y, int h)
2525 0x00,0x02,0x10,0x12,0x80,0x82,0x90,0x92,
2526 0x49,0x4B,0x59,0x5B,0xC9,0xCB,0xD9,0xDB
2531 v99x8.tbl_pn = v99x8.vram + (((int)v99x8.ctrl[2] & 0x20) << 11);
2535 pbuf = v99x8_refresh_start(0, 256, h);
2536 pp = md_video_pitch() - md_video_pixbytes(256);
2538 T = v99x8.tbl_pn + (((y + v99x8.ctrl[23]) & 0xff) << 8);
2542 sp = v99x8_refresh_sprite2(y);
2544 for (i = 0; i < 32; ++i)
2548 pixel_put(pbuf, 0, pal_8[sp[0] ? sc8spr[sp[0]] : T[0]]);
2549 pixel_put(pbuf, 1, pal_8[sp[0] ? sc8spr[sp[0]] : T[0]]);
2550 pixel_put(pbuf, 2, pal_8[sp[1] ? sc8spr[sp[1]] : T[1]]);
2551 pixel_put(pbuf, 3, pal_8[sp[1] ? sc8spr[sp[1]] : T[1]]);
2552 pixel_put(pbuf, 4, pal_8[sp[2] ? sc8spr[sp[2]] : T[2]]);
2553 pixel_put(pbuf, 5, pal_8[sp[2] ? sc8spr[sp[2]] : T[2]]);
2554 pixel_put(pbuf, 6, pal_8[sp[3] ? sc8spr[sp[3]] : T[3]]);
2555 pixel_put(pbuf, 7, pal_8[sp[3] ? sc8spr[sp[3]] : T[3]]);
2556 pixel_put(pbuf, 8, pal_8[sp[4] ? sc8spr[sp[4]] : T[4]]);
2557 pixel_put(pbuf, 9, pal_8[sp[4] ? sc8spr[sp[4]] : T[4]]);
2558 pixel_put(pbuf, 10, pal_8[sp[5] ? sc8spr[sp[5]] : T[5]]);
2559 pixel_put(pbuf, 11, pal_8[sp[5] ? sc8spr[sp[5]] : T[5]]);
2560 pixel_put(pbuf, 12, pal_8[sp[6] ? sc8spr[sp[6]] : T[6]]);
2561 pixel_put(pbuf, 13, pal_8[sp[6] ? sc8spr[sp[6]] : T[6]]);
2562 pixel_put(pbuf, 14, pal_8[sp[7] ? sc8spr[sp[7]] : T[7]]);
2563 pixel_put(pbuf, 15, pal_8[sp[7] ? sc8spr[sp[7]] : T[7]]);
2564 pbuf += md_video_pixbytes(16); T += 8; sp += 8;
2567 pixel_put(pbuf,0, pal_8[sp[0] ? sc8spr[sp[0]] : T[0]]);
2568 pixel_put(pbuf,1, pal_8[sp[1] ? sc8spr[sp[1]] : T[1]]);
2569 pixel_put(pbuf,2, pal_8[sp[2] ? sc8spr[sp[2]] : T[2]]);
2570 pixel_put(pbuf,3, pal_8[sp[3] ? sc8spr[sp[3]] : T[3]]);
2571 pixel_put(pbuf,4, pal_8[sp[4] ? sc8spr[sp[4]] : T[4]]);
2572 pixel_put(pbuf,5, pal_8[sp[5] ? sc8spr[sp[5]] : T[5]]);
2573 pixel_put(pbuf,6, pal_8[sp[6] ? sc8spr[sp[6]] : T[6]]);
2574 pixel_put(pbuf,7, pal_8[sp[7] ? sc8spr[sp[7]] : T[7]]);
2575 pbuf += md_video_pixbytes(8); T += 8; sp += 8;
2583 v99x8_refresh_stop();
2586 static __inline__ uint32 v99x8_refresh_MapYJK(int n, int j, int k, int jk)
2588 return md_maprgb15(tbl_yjk_rg[n + j], tbl_yjk_rg[n + k], tbl_yjk_b [n + jk]);
2592 void V99X8::v99x8_refresh_scc(int y, int h)
2600 0x00, 0x02, 0x10, 0x12, 0x80, 0x82, 0x90, 0x92,
2601 0x49, 0x4B, 0x59, 0x5B, 0xC9, 0xCB, 0xD9, 0xDB
2606 v99x8.tbl_pn = v99x8.vram + (((int)v99x8.ctrl[2] & 0x20) << 11);
2610 pbuf = v99x8_refresh_start(0, 256, h);
2611 pp = md_video_pitch() - md_video_pixbytes(256);
2613 T = v99x8.tbl_pn + (((y + v99x8.ctrl[23]) & 0xff) << 8);
2617 sp = v99x8_refresh_sprite2(y);
2618 for (i = 0; i < 64; ++i)
2620 int yjk_k, yjk_j, yjk_jk;
2622 yjk_k = (((T[0] & 7) | ((T[1] & 7) << 3)) + 32) & 0x3f;
2623 yjk_j = (((T[2] & 7) | ((T[3] & 7) << 3)) + 32) & 0x3f;
2625 yjk_jk = (yjk_j << 11) + (yjk_k << 5);
2627 pixel_put(pbuf, 0, sp[0] ? pal_8[sc8spr[sp[0]]] : v99x8_refresh_MapYJK(T[0] >> 3, yjk_j, yjk_k, yjk_jk));
2628 pixel_put(pbuf, 1, sp[1] ? pal_8[sc8spr[sp[1]]] : v99x8_refresh_MapYJK(T[1] >> 3, yjk_j, yjk_k, yjk_jk));
2629 pixel_put(pbuf, 2, sp[2] ? pal_8[sc8spr[sp[2]]] : v99x8_refresh_MapYJK(T[2] >> 3, yjk_j, yjk_k, yjk_jk));
2630 pixel_put(pbuf, 3, sp[3] ? pal_8[sc8spr[sp[3]]] : v99x8_refresh_MapYJK(T[3] >> 3, yjk_j, yjk_k, yjk_jk));
2632 pbuf += md_video_pixbytes(4); T += 4; sp += 4;
2638 v99x8_refresh_stop();
2641 void V99X8::v99x8_refresh_sc2(int y, int h) {;}
2642 void V99X8::v99x8_refresh_sc3(int y, int h) {;}
2643 void V99X8::v99x8_refresh_sca(int y, int h) {;} /* sc10/sc11 */
2644 void V99X8::v99x8_refresh_scx(int y, int h)
2648 uint32 fg, bg, m[4];
2652 v99x8.tbl_pg = v99x8.vram + (((int)v99x8.ctrl[4] & 0x3f) << 11);
2653 v99x8.tbl_pn = v99x8.vram + (((int)v99x8.ctrl[2] & 0x7c) << 10);
2654 v99x8.tbl_cl = v99x8.vram + (((int)v99x8.ctrl[10] & 0x07) << 14)
2655 + (((int)v99x8.ctrl[3] & 0xf8) << 6);
2659 pbuf = v99x8_refresh_start(8, 240, h);
2660 pp = md_video_pitch() - md_video_pixbytes(240);
2662 fg = pal[v99x8.col_fg].color;
2663 bg = pal[v99x8.col_bg].color;
2664 m[0] = pal_m[(v99x8.col_bg << 4) | v99x8.col_bg];
2665 m[1] = pal_m[(v99x8.col_bg << 4) | v99x8.col_fg];
2666 m[2] = pal_m[(v99x8.col_fg << 4) | v99x8.col_bg];
2667 m[3] = pal_m[(v99x8.col_fg << 4) | v99x8.col_fg];
2674 T = v99x8.tbl_pn + (y >> 3) * 80;
2675 G = v99x8.tbl_pg + (y & 0x07);
2678 for (i = 0; i < 80; ++i)
2682 a = G[(int)*T++ << 3];
2685 pixel_put(pbuf, 0, (a & 0x80) ? fg : bg);
2686 pixel_put(pbuf, 1, (a & 0x40) ? fg : bg);
2687 pixel_put(pbuf, 2, (a & 0x20) ? fg : bg);
2688 pixel_put(pbuf, 3, (a & 0x10) ? fg : bg);
2689 pixel_put(pbuf, 4, (a & 0x08) ? fg : bg);
2690 pixel_put(pbuf, 5, (a & 0x04) ? fg : bg);
2691 pbuf += md_video_pixbytes(6);
2694 pixel_put(pbuf, 0, m[a >> 6]);
2695 pixel_put(pbuf, 1, m[(a >> 4)& 0x03]);
2696 pixel_put(pbuf, 2, m[(a >> 2)& 0x03]);
2698 pbuf += md_video_pixbytes(3);
2704 v99x8_refresh_stop();
2712 Skelton for retropc emulator
2721 void V99X8::initialize()
2724 register_vline_event(this);
2726 v99x8.vram = this->vram;
2727 v99x8.f_zoom = TRUE;
2742 void V99X8::write_io8(uint32 addr, uint32 data)
2761 uint32 V99X8::read_io8(uint32 addr)
2766 data = v99x8_in_0();
2769 data = v99x8_in_1();
2775 void V99X8::draw_screen()
2777 md_video_update(0, NULL);
2780 void V99X8::event_vline(int v, int clock)
2788 void V99X8::set_intstat(bool val)
2790 if(val != intstat) {
2791 write_signals(&outputs_irq, val ? 0xffffffff : 0);
2796 void V99X8::z80_intreq(int a)
2798 set_intstat(a != Z80_NOINT);
2801 int V99X8::md_video_pitch(void)
2803 return SCREEN_WIDTH*4;
2806 uint8 *V99X8::md_video_lockline(int x, int y, int w, int h)
2808 return (uint8*)(screen+y*SCREEN_WIDTH+x);
2810 if (SDL_MUSTLOCK(video.screen))
2811 SDL_LockSurface(video.screen); /*
\96ß
\82è
\92l
\83`
\83F
\83b
\83N
\81H */
2813 return (Uint8 *)video.screen->pixels
2814 + video.screen->format->BytesPerPixel * (video.w + x)
2815 + video.screen->pitch * (y + video.h);
2819 void V99X8::md_video_update(int n, /*md_video_rect_t*/void *rp)
2824 int h = SCREEN_HEIGHT;
2826 if((dst = emu->screen_buffer(y)) != NULL) {
2827 memcpy(dst, screen+y*SCREEN_WIDTH, SCREEN_WIDTH*4);
2829 if((dst = emu->screen_buffer(y + 1)) != NULL) {
2830 memcpy(dst, screen+y*SCREEN_WIDTH, SCREEN_WIDTH*4);
2840 void V99X8::md_video_fill(int x, int y, int w, int h, uint32 c)
2844 scrntype *p = screen+y*SCREEN_WIDTH+x;
2845 for(w2=w;w2>0; w2--) {
2852 static void lmcm(void)
2858 static void stop(void)
2862 v99x8.status[2] &= ~0x01;
2867 static void vcom_lfill_(int dx, int dy, int nx, int clr)
2869 if (v99x8.ctrl[45] & 0x04) { /* Direction to left */
2870 // Todo?: if (dx-nx<MIN_OF_X) xxx;
2871 for (;nx>0;nx--,dx--) vcom_lpset(dx, dy, clr);
2874 // Todo?: if (dx+nx>MAX_OF_X) xxx;
2875 for (;nx>0;nx--,dx++) vcom_lpset(dx, dy, clr);
2879 static void lmmv_(void)
2889 clr = v99x8.ctrl[44];
2891 if ((v99x8.ctrl[45] & 0x08) == 0) { /* Direction to down */
2892 int ny = vcom.ny, dy = vcom.dy;
2893 // Todo?: if (dy+ny>MAX_OF_Y) xxx;
2894 for (;ny>0;ny--,dy++) vcom_lfill_(vcom.dx, dy, vcom.nx, clr);
2895 vcom_setdy(vcom.dy + vcom.ny);
2898 int ny = vcom.ny, dy = vcom.dy;
2899 // Todo?: if (dy-ny<MIN_OF_Y) xxx;
2900 for (;ny>0;ny--,dy--) vcom_lfill_(vcom.dx, dy, vcom.nx, clr);
2901 vcom_setdy(vcom.dy - vcom.ny);
2904 //vcom_setdy(vcom.dy + n);
2906 //if (vcom.ny != abs(n))
2907 // vcom_setny(vcom.ny - abs(n));
2912 static void vcom_lcopy_(int sx, int sy, int dx, int dy, int nx)
2914 if (v99x8.ctrl[45] & 0x04) { /* Direction to left */
2915 // Todo?: if (dx-nx<MIN_OF_X) xxx;
2916 // Todo?: if (sx-nx<MIN_OF_X) xxx;
2917 for (;nx>0;nx--,dx--, sx--) vcom_lpset(dx, dy, vcom_point(sx, sy));
2920 // Todo?: if (dx+nx>MAX_OF_X) xxx;
2921 // Todo?: if (sx+nx>MAX_OF_X) xxx;
2922 if (dx+nx>vcom.xmask+1) {
2925 if (sx+nx>vcom.xmask+1) {
2928 for (;nx>0;nx--,dx++, sx++) vcom_lpset(dx, dy, vcom_point(sx, sy));
2933 static void lmmm_(void)
2942 if ((v99x8.ctrl[45] & 0x08) == 0) { /* Direction to down */
2943 int ny = vcom.ny, dy = vcom.dy, sy = vcom.sy;
2944 // Todo?: if (dy+ny>MAX_OF_Y) xxx;
2945 // Todo?: if (sy+ny>MAX_OF_Y) xxx;
2946 for (;ny>0;ny--,dy++,sy++) vcom_lcopy_(vcom.sx, sy, vcom.dx, dy, vcom.nx);
2947 vcom_setsy(vcom.sy + vcom.ny);
2948 vcom_setdy(vcom.dy + vcom.ny);
2951 int ny = vcom.ny, dy = vcom.dy, sy = vcom.sy;
2952 // Todo?: if (dy-ny<MIN_OF_Y) xxx;
2953 // Todo?: if (sy-ny<MIN_OF_Y) xxx;
2954 for (;ny>0;ny--,dy--,sy--) vcom_lcopy_(vcom.sx, sy, vcom.dx, dy, vcom.nx);
2955 vcom_setsy(vcom.sy - vcom.ny);
2956 vcom_setdy(vcom.dy - vcom.ny);
2959 //vcom_setsy(vcom.sy + n);
2960 //vcom_setdy(vcom.dy + n);
2962 //if (vcom.ny != abs(n))
2963 // vcom_setny(vcom.ny - abs(n));
2968 void cmdtime_set(int m)
2973 /* provisional data */
2975 if ((v99x8.ctrl[8] & 0x02) == 0) && ((v99x8.ctrl[1] & 0x40) != 0)
2976 YMMM 4.83 microseconds/byte
2977 HMMM 5.85 microseconds/byte
2978 HMMV 3.05 microseconds/byte
2979 LMMM 6.87 microseconds/dot
2980 LMMV 5.91 microseconds/dot
2984 case 0xe: /* ymmm */ vcom_getdx();vcom_getny();cmdtime_t=483*(v99x8.ctrl[45] & 0x04?vcom.dx:v99x8.mode.xsize-vcom.dx)*vcom.ny/pixmask.npix; break;
2985 case 0xd: /* hmmm */ vcom_getnx();vcom_getny();cmdtime_t=585*vcom.nx*vcom.ny/pixmask.npix; break;
2986 case 0xc: /* hmmv */ vcom_getnx();vcom_getny();cmdtime_t=305*vcom.nx*vcom.ny/pixmask.npix; break;
2987 case 0x9: /* lmmm */ vcom_getnx();vcom_getny();cmdtime_t=687*vcom.nx*vcom.ny; break;
2988 case 0x8: /* lmmv */ vcom_getnx();vcom_getny();cmdtime_t=591*vcom.nx*vcom.ny; break;
2990 //cmdtime_t = cmdtime_t*60*262/1000000/100;
2991 cmdtime_t = cmdtime_t/6361;
2992 if (cmdtime_t<0) cmdtime_t=0;
2995 void cmdtime_chk(void)
2999 if (0 == cmdtime_t) v99x8.status[2] &= ~0x01;
3004 #define STATE_VERSION 1
3006 void V99X8::save_state(FILEIO* state_fio)
3008 state_fio->FputUint32(STATE_VERSION);
3009 state_fio->FputInt32(this_device_id);
3011 state_fio->Fwrite(&v99x8, sizeof(v99x8), 1);
3013 state_fio->FputInt32(cmdtime_t);
3014 state_fio->FputInt32(cmdtime_m);
3016 state_fio->FputInt32(latch1);
3017 state_fio->FputInt32(latch2);
3018 state_fio->FputInt32(vram_addr);
3019 state_fio->FputInt32(vram_page);
3020 state_fio->FputBool(f_out3);
3021 state_fio->FputBool(f_mode);
3022 state_fio->FputBool(flag_frame);
3023 state_fio->Fwrite(&vcom, sizeof(vcom), 1);
3024 state_fio->FputInt32((int)(vcom.src - vram));
3025 state_fio->FputInt32((int)(vcom.dst - vram));
3026 state_fio->Fwrite(&r44, sizeof(r44), 1);
3027 state_fio->Fwrite(&pixmask, sizeof(pixmask), 1);
3028 state_fio->Fwrite(&v99x8_refresh, sizeof(v99x8_refresh), 1);
3029 state_fio->Fwrite(pal, sizeof(pal), 1);
3030 state_fio->Fwrite(pal_8, sizeof(pal_8), 1);
3031 state_fio->Fwrite(pal_m, sizeof(pal_m), 1);
3032 state_fio->FputInt32(col_bg);
3033 state_fio->Fwrite(tbl_yjk_b, sizeof(tbl_yjk_b), 1);
3034 state_fio->Fwrite(tbl_yjk_rg, sizeof(tbl_yjk_rg), 1);
3035 state_fio->Fwrite(blackbuf, sizeof(blackbuf), 1);
3036 state_fio->Fwrite(sbuf, sizeof(sbuf), 1);
3037 state_fio->Fwrite(vram, sizeof(vram), 1);
3038 state_fio->FputBool(intstat);
3041 bool V99X8::load_state(FILEIO* state_fio)
3043 if(state_fio->FgetUint32() != STATE_VERSION) {
3046 if(state_fio->FgetInt32() != this_device_id) {
3049 state_fio->Fread(&v99x8, sizeof(v99x8), 1);
3051 cmdtime_t = state_fio->FgetInt32();
3052 cmdtime_m = state_fio->FgetInt32();
3054 latch1 = state_fio->FgetInt32();
3055 latch2 = state_fio->FgetInt32();
3056 vram_addr = state_fio->FgetInt32();
3057 vram_page = state_fio->FgetInt32();
3058 f_out3 = state_fio->FgetBool();
3059 f_mode = state_fio->FgetBool();
3060 flag_frame = state_fio->FgetBool();
3061 state_fio->Fread(&vcom, sizeof(vcom), 1);
3062 vcom.src = vram + state_fio->FgetInt32();
3063 vcom.dst = vram + state_fio->FgetInt32();
3064 state_fio->Fread(&r44, sizeof(r44), 1);
3065 state_fio->Fread(&pixmask, sizeof(pixmask), 1);
3066 state_fio->Fread(&v99x8_refresh, sizeof(v99x8_refresh), 1);
3067 state_fio->Fread(pal, sizeof(pal), 1);
3068 state_fio->Fread(pal_8, sizeof(pal_8), 1);
3069 state_fio->Fread(pal_m, sizeof(pal_m), 1);
3070 col_bg = state_fio->FgetInt32();
3071 state_fio->Fread(tbl_yjk_b, sizeof(tbl_yjk_b), 1);
3072 state_fio->Fread(tbl_yjk_rg, sizeof(tbl_yjk_rg), 1);
3073 state_fio->Fread(blackbuf, sizeof(blackbuf), 1);
3074 state_fio->Fread(sbuf, sizeof(sbuf), 1);
3075 state_fio->Fread(vram, sizeof(vram), 1);
3076 intstat = state_fio->FgetBool();