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 #define md_maprgb15(R,G,B) RGB_COLOR(((R) << 3), ((G) << 3), ((B) << 3))
60 #define md_video_pixbytes(n) (n*32/8)
61 #define md_refresh_sync() (TRUE)
62 #define md_video_defaultopt() (0)
63 int md_video_pitch(void); // the length of a row of pixels in bytes
64 uint8_t *md_video_lockline(int x, int y, int w, int h);
65 void md_video_unlockline(void) {}
66 void md_video_update(int n, /*md_video_rect_t*/void *rp);
67 void md_video_fill(int x, int y, int w, int h, uint32_t c);
68 typedef uint32_t md_pixel_t;
70 // from "md_depend.h" of Zodiac
77 //typedef SDL_Rect md_video_rect_t;
78 //typedef SDL_Surface md_video_surface_t;
81 //md_video_surface_t *screen;
82 int w, h; /*
\97v
\8b\81\82µ
\82½
\83T
\83C
\83Y */
94 extern void v99x8_command(int m); /* v99x8_internal.h ?? */
95 extern void v99x8_cputovdp(int m);
98 #define XXX_V99X8_ID 0
133 static void v99x8_interleave(void)
136 static uint8_t *vram = NULL;
140 size = v99x8.pages * 0x4000;
143 vram = (uint8_t *)malloc(size);
149 if (v99x8.mode.f_interleave)
157 while (c < (int)size)
159 v99x8.vram[c] = vram[a++];
160 v99x8.vram[c + 1] = vram[b++];
171 while (c < (int)size)
173 v99x8.vram[a++] = vram[c];
174 v99x8.vram[b++] = vram[c + 1];
181 static void v99x8_mode_set(int n)
183 v99x8_screen_mode_t mode[] =
185 {TRUE, FALSE, 0, 0}, /* V99X8_SCREEN_0 */
186 {TRUE, FALSE, 0, 0}, /* V99X8_SCREEN_1 */
187 {TRUE, FALSE, 0, 0}, /* V99X8_SCREEN_2 */
188 {TRUE, FALSE, 0, 0}, /* V99X8_SCREEN_3 */
190 {FALSE, FALSE, 0, 0}, /* V99X8_SCREEN_4 */
191 {FALSE, FALSE, 256, 1}, /* V99X8_SCREEN_5 */
192 {FALSE, FALSE, 512, 2}, /* V99X8_SCREEN_6 */
193 {FALSE, TRUE, 512, 1}, /* V99X8_SCREEN_7 */
195 {FALSE, TRUE, 256, 0}, /* V99X8_SCREEN_8 */
196 {FALSE, FALSE, 0, 0}, /* V99X8_SCREEN_X */
197 {FALSE, TRUE, 256, 0}, /* V99X8_SCREEN_A */
198 {FALSE, TRUE, 256, 0} /* V99X8_SCREEN_C */
201 if (n != V99X8_SCREEN_8 || (v99x8.ctrl[25] & 0x08) != 0x08)
205 if ((v99x8.ctrl[25] & 0x10) == 0x10)
206 v99x8.scr = V99X8_SCREEN_A;
208 v99x8.scr = V99X8_SCREEN_C;
211 memcpy(&v99x8.mode, &mode[v99x8.scr], sizeof(v99x8_screen_mode_t));
214 static void v99x8_update(void)
218 V99X8_SCREEN_1, V99X8_SCREEN_2, V99X8_SCREEN_4, V99X8_SCREEN_5,
219 V99X8_SCREEN_6, V99X8_SCREEN_7, V99X8_SCREEN_IGN, V99X8_SCREEN_8,
220 V99X8_SCREEN_3, V99X8_SCREEN_IGN, V99X8_SCREEN_IGN, V99X8_SCREEN_IGN,
221 V99X8_SCREEN_IGN, V99X8_SCREEN_IGN, V99X8_SCREEN_IGN, V99X8_SCREEN_IGN,
222 V99X8_SCREEN_0, V99X8_SCREEN_IGN, V99X8_SCREEN_X
231 f = v99x8.mode.f_interleave;
233 a = ((v99x8.ctrl[0] & 0x0e) >> 1) | (v99x8.ctrl[1] & 0x18);
234 if (a >= sizeof(mapping) / sizeof(*mapping) ||
235 mapping[a] == V99X8_SCREEN_IGN)
240 v99x8_mode_set(mapping[a]);
242 if (f != v99x8.mode.f_interleave)
249 static void v99x8_ctrl_init(void)
251 memset(v99x8.ctrl, 0, sizeof(v99x8.ctrl));
254 void v99x8_ctrl(int n, uint8_t m)
256 /* printf ("v99x8_ctrl %2d <= %02x\n", n, m); */
266 if (((m ^ v99x8.ctrl[0]) & 0x0e) != 0)
274 if (((m ^ v99x8.ctrl[1]) & 0x18) != 0)
289 v99x8.col_fg = m >> 4;
290 v99x8.col_bg = m & 0x0f;
294 m &= v99x8.pages - 1;
295 vram_page = (int)m << 14;
299 if (m >= V99X8_NSTAT)
308 f_out3 = !(m & 0x80);
337 static void vram_incaddr(void)
339 vram_addr = (vram_addr + 1) & 0x3fff;
340 if (vram_addr == 0 && !v99x8.mode.f_tms)
341 v99x8_ctrl(14, v99x8.ctrl[14] + 1);
344 uint8_t vram_read(int addr)
346 return v99x8.vram[addr];
349 void vram_write(int addr, uint8_t n)
351 v99x8.vram[addr] = n;
355 uint8_t v99x8_in_0(void) /* VRAM read */
361 n = vram_read(vram_addr + vram_page);
366 void v99x8_out_0(uint8_t n) /* VRAM write */
370 vram_write(vram_addr + vram_page, n);
374 uint8_t v99x8_in_1(void) /* status in */
383 n = v99x8.status[v99x8.ctrl[15]];
386 if (z80.ivec!=Z80_NOINT)
388 printf("* IFF:%d H:%d V:%d\n", z80.IFF&1, (v99x8.ctrl[0]&0x10), (v99x8.ctrl[1]&0x20));
390 z80_intreq(Z80_NOINT);
394 switch(v99x8.ctrl[15])
397 v99x8.status[0] &= ~0xa0;
400 v99x8.status[1] &= ~0x01;
403 /* v99x8.status[7] = v99x8.ctrl[44] = v99x8_vdptocpu(); */
409 a = context.hz / 60 / 262;
410 b = (context.time_cycle % a) * 100 / a;
411 context_timeunlock();
424 void v99x8_out_1(uint8_t n) /* ctrl out */
426 //static int latch = -1;
436 v99x8_ctrl(n & 0x3f, latch1);
439 /* ??? read/write
\82Ì
\8bæ
\95Ê */
440 vram_addr = ((int)(n & 0x3f) << 8) + latch1;
446 void v99x8_out_2(uint8_t n) /* palette out */
448 //static int latch = -1;
458 v99x8_pallete_set(a, (latch2 & 0x70) >> 4, n & 0x07, latch2 & 0x07);
459 v99x8_ctrl(16, a + 1);
465 void v99x8_out_3(uint8_t n) /* ctrl out */
467 if (v99x8.ctrl[17] != 17)
468 v99x8_ctrl(v99x8.ctrl[17], n);
471 v99x8_ctrl(17, v99x8.ctrl[17] + 1);
475 static void v99x8_status_init(void)
477 memset(v99x8.status, 0, sizeof(v99x8.status));
478 v99x8.status[0] = 0x9f;
479 v99x8.status[1] = XXX_V99X8_ID << 1;
480 v99x8.status[2] = 0xac;
483 static void v99x8_vram_init(void)
485 //v99x8.vram = (uint8_t *)malloc(v99x8.pages * 0x4000);
486 memset(v99x8.vram, 0xff, v99x8.pages * 0x4000);
489 void v99x8_init(void)
503 v99x8.n_scanlines = 262;
509 /* v99x8.f_zoom = FALSE; */
513 v99x8_mode_set(V99X8_SCREEN_1);
518 v99x8_refresh_init();
521 static bool flag_frame = FALSE;
523 int V99X8::hsync(int v/*void*/)
527 v99x8.scanline = v; // is this OK???
528 v99x8.status[2] ^= 0x20;
530 if (v99x8.scanline < 226)
534 if (0 == v99x8.scanline) v99x8_refresh_clear(); // added by umaiboux
535 line = v99x8.scanline + (((v99x8.ctrl[18] >> 4) + 8) & 0x0f) - 8 - 7;
536 if (v99x8.ctrl[9] & 0x80)
541 if (v99x8.ctrl[1] & 0x40 && line >= 0 && line < a)
547 case V99X8_SCREEN_0: v99x8_refresh_sc0(line, 1); break;
548 case V99X8_SCREEN_1: v99x8_refresh_sc1(line, 1); break;
549 case V99X8_SCREEN_2: v99x8_refresh_sc4(line, 1); break;
550 case V99X8_SCREEN_3: v99x8_refresh_sc3(line, 1); break;
551 case V99X8_SCREEN_4: v99x8_refresh_sc4(line, 1); break;
552 case V99X8_SCREEN_5: v99x8_refresh_sc5(line, 1); break;
553 case V99X8_SCREEN_6: v99x8_refresh_sc6(line, 1); break;
554 case V99X8_SCREEN_7: v99x8_refresh_sc7(line, 1); break;
555 case V99X8_SCREEN_8: v99x8_refresh_sc8(line, 1); break;
556 case V99X8_SCREEN_A: v99x8_refresh_scc(line, 1); break;
557 case V99X8_SCREEN_C: v99x8_refresh_scc(line, 1); break;
558 case V99X8_SCREEN_X: v99x8_refresh_scx(line, 1); break;
563 if (((v99x8.scanline + v99x8.ctrl[23]
564 - ((v99x8.ctrl[9] & 0x80) ? 8 : 18)) & 0xff) == v99x8.ctrl[19])
566 if (v99x8.ctrl[0] & 0x10)
568 v99x8.status[1] |= 0x01; /* H-sync */
573 if (!(v99x8.ctrl[0] & 0x10))
574 v99x8.status[1] &= ~0x01; /* ?? H-sync off*/
578 switch(v99x8.scanline)
582 v99x8_refresh_screen();
584 flag_frame = md_refresh_sync();
586 v99x8.status[2] |= 0x40; /* VBlank on */
588 v99x8.status[1] &= ~0x01; /* ?? H-sync off*/
589 z80_intreq(Z80_NOINT); /* ?? H-sync
\82ð clear */
591 /* XXX sprite check */
595 /* v99x8.status[1] &= ~0x01; */ /* ?? H-sync off*/
596 if (v99x8.ctrl[1] & 0x20)
598 v99x8.status[0] |= 0x80; /* V-sync int */
604 v99x8.status[2] &= ~0x40; /* VBlank off */
605 v99x8.status[0] &= ~0x40; /* 5sprit off */
606 v99x8.status[0] &= ~0x80; /* Vsync off */
607 z80_intreq(Z80_NOINT); /* ?? V-sync
\82ð clear */
610 v99x8_refresh_clear();*/ // deleted by umaiboux
620 25/ 15: bottom border
626 return v99x8.scanline = (v99x8.scanline + 1) % v99x8.n_scanlines;
631 // from "v99x8_command.c" of Zodiac
634 * Copyright (c) 2000-2002 SASAKI Shunsuke (eruchan@users.sourceforge.net).
635 * Copyright (c) 2001-2002 The Zodiac project.
636 * All rights reserved.
638 * This program is free software; you can redistribute it and/or modify
639 * it under the terms of the GNU General Public License as published by
640 * the Free Software Foundation; either version 2 of the License, or
641 * (at your option) any later version.
643 * This program is distributed in the hope that it will be useful,
644 * but WITHOUT ANY WARRANTY; without even the implied warranty of
645 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
646 * GNU General Public License for more details.
648 * You should have received a copy of the GNU General Public License
649 * along with this program; if not, write to the Free Software
650 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
653 //#include "../../config.h"
655 //#include <string.h>
658 //#include "../zodiac.h"
661 /* #define YAN_V99X8_TEST 1 */ /* XXX */
669 int sx, sy, dx, dy, nx, ny;
697 static pixmask_t pixmasks[4] = {
698 {2, 0x01, 0x0f, {0x0f, 0xf0, 0x0f, 0xf0}, {4, 0, 4, 0}, {4, 0, 4, 0}},
699 {4, 0x03, 0x03, {0x3f, 0xcf, 0xf3, 0xfc}, {6, 4, 2, 0}, {6, 4, 2, 0}},
700 {2, 0x01, 0x0f, {0x0f, 0xf0, 0x0f, 0xf0}, {4, 0, 4, 0}, {4, 0, 4, 0}},
701 {1, 0x00, 0xff, {0x00, 0x00, 0x00, 0x00}, {0, 0, 0, 0}, {0, 0, 0, 0}}
704 static pixmask_t pixmask;
707 static int getshift(int n)
711 for (i = 0; n & (1 << i); i++)
716 #define vcom_getsx() vcom.sx = (v99x8.ctrl[32] + (v99x8.ctrl[33] << 8)) & vcom.xmask
717 #define vcom_getsy() vcom.sy = (v99x8.ctrl[34] + (v99x8.ctrl[35] << 8)) & vcom.ymask
718 #define vcom_getdx() vcom.dx = (v99x8.ctrl[36] + (v99x8.ctrl[37] << 8)) & vcom.xmask
719 #define vcom_getdy() vcom.dy = (v99x8.ctrl[38] + (v99x8.ctrl[39] << 8)) & vcom.ymask
720 #define vcom_getnx() vcom.nx = ((v99x8.ctrl[40] + (v99x8.ctrl[41] << 8) - 1) & 511) + 1
721 #define vcom_getny() vcom.ny = ((v99x8.ctrl[42] + (v99x8.ctrl[43] << 8) - 1) & 1023) + 1
723 static void vcom_lpset(int x, int y, int clr);
724 static uint8_t vcom_point(int x, int y);
726 static void vcom_set(int base, int n)
728 v99x8.ctrl[base] = n & 0xff;
729 v99x8.ctrl[base + 1] = n >> 8;
732 #define vcom_setsy(n) vcom_set(34, n)
733 #define vcom_setdy(n) vcom_set(38, n)
734 #define vcom_setny(n) vcom_set(42, n)
736 #define vcom_vram(x, y) (&v99x8.vram[((x) >> vcom.xshift) + ((y) << vcom.yshift)])
738 static int vcom_chksum(uint8_t *d, int n)
751 #define vcom_dtcopy(d, s, nbytes) { \
761 static int vcom_canonaddr(void)
765 if (v99x8.ctrl[45] & 0x04) /* Direction to left */
770 vcom.sx = max(vcom.sx, 0);
771 vcom.nx = min(vcom.nx, vcom.xmask + 1 - vcom.sx);
772 vcom.dx = max(vcom.dx, 0);
773 vcom.nx = min(vcom.nx, vcom.xmask + 1 - vcom.dx);
776 if ((v99x8.ctrl[45] & 0x08) == 0) /* Direction to down */
778 ny = min(ny, vcom.ymask + 1 - vcom.sy);
779 ny = min(ny, vcom.ymask + 1 - vcom.dy);
782 ny = min(ny, vcom.sy + 1);
783 ny = min(ny, vcom.dy + 1);
787 /* printf("can %d->%d *(%d,%d)\n", vcom.sx, vcom.dx, vcom.nx, ny); */
789 vcom.src = vcom_vram(vcom.sx, vcom.sy);
790 vcom.dst = vcom_vram(vcom.dx, vcom.dy);
791 vcom.nx >>= vcom.xshift;
796 static void vcom_hcopy(uint8_t *dst, uint8_t *src, int nx, int ny)
802 /* printf("sum1: %d\n", vcom_chksum(src, nx)); */
803 /* memmove(dst, src, nx); */
804 vcom_dtcopy(dst, src, nx);
805 /* printf("sum2: %d\n", vcom_chksum(dst, nx)); */
813 /* printf("sum1: %d\n", vcom_chksum(src, nx)); */
814 /* memmove(dst, src, nx); */
815 vcom_dtcopy(dst, src, nx);
816 /* printf("sum2: %d\n", vcom_chksum(dst, nx)); */
823 static void ymmm(void)
834 /* printf("ymmm: (%d,%d) %d*%d\n", vcom.sx, vcom.sy, vcom.dy, vcom.ny); */
835 n = vcom_canonaddr();
836 vcom_hcopy(vcom.dst, vcom.src, vcom.nx, n);
838 vcom_setsy(vcom.sy + n);
839 vcom_setdy(vcom.dy + n);
841 if (vcom.ny != abs(n))
842 vcom_setny(vcom.ny - abs(n));
845 static void hmmm(void)
856 /* printf("hmmm: (%d,%d)->(%d,%d) *(%d,%d)\n", vcom.sx, vcom.sy, vcom.dx, vcom.dy, vcom.nx, vcom.ny); */
857 n = vcom_canonaddr();
858 vcom_hcopy(vcom.dst, vcom.src, vcom.nx, n);
860 vcom_setsy(vcom.sy + n);
861 vcom_setdy(vcom.dy + n);
863 if (vcom.ny != abs(n))
864 vcom_setny(vcom.ny - abs(n));
867 static void hmmv(void)
877 clr = v99x8.ctrl[44];
879 ny = n = vcom_canonaddr();
884 memset(vcom.dst, clr, vcom.nx);
885 vcom.dst -= vcom.xbytes;
891 memset(vcom.dst, clr, vcom.nx);
892 vcom.dst += vcom.xbytes;
896 vcom_setsy(vcom.sy + n);
897 vcom_setdy(vcom.dy + n);
899 if (vcom.ny != abs(n))
900 vcom_setny(vcom.ny - abs(n));
903 #define vcom_lset(dc, sc) \
906 case 0x0: (dc) = (sc); break; \
907 case 0x1: (dc) &= (sc); break; \
908 case 0x2: (dc) |= (sc); break; \
909 case 0x3: (dc) ^= (sc); break; \
910 case 0x4: (dc) =~ (sc); break; \
911 case 0x8: if ((sc) != 0) (dc) = (sc); break; \
912 case 0x9: if ((sc) != 0) (dc) &= (sc); break; \
913 case 0xa: if ((sc) != 0) (dc) |= (sc); break; \
914 case 0xb: if ((sc) != 0) (dc) ^= (sc); break; \
915 case 0xc: if ((sc) != 0) (dc) =~ (sc); break; \
926 static void vcom_lmove(uint8_t *dst, uint8_t *src, int n)
929 if (v99x8.ctrl[45] & 0x04) /* Direction to left */
934 vcom_lset(*dst, *src);
940 static void vcom_lcopy(uint8_t *dst, uint8_t *src, int nx, int ny)
946 vcom_lmove(dst, src, nx);
954 vcom_lmove(dst, src, nx);
963 \82±
\82ê
\82Í
\82 \82
\82Ü
\82Å
\82»
\82Ì
\8fê
\82µ
\82Ì
\82¬
\82È
\82à
\82Ì
\81B
965 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
966 \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
967 \81[
\82·
\82ê
\82Î
\82¢
\82¢
\82Ì
\82©
\81H
969 \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¤
970 \82É
\82·
\82é
\81A
\82Æ
\81B
972 \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
974 \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
975 \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
977 \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
979 #ifdef YAN_V99X8_TEST
980 static void vcom_lbcopy(int sx, int sy, int dx, int dy, int nx, int ny)
995 vcom_lpset(dx, dy, (int)vcom_point(sx, sy));
1011 vcom_lpset(dx, dy, (int)vcom_point(sx, sy));
1023 #endif /* YAN_V99X8_TEST */
1026 void vcom_lputc(int m) /* XXX
\8d¶
\95û
\8cü
\81A
\8fã
\95û
\8cü
\82Ì
\83e
\83X
\83g
\82Í
\82µ
\82Ä
\82Ü
\82¹
\82ñ */
1031 dst = vcom_vram(r44.x, r44.y);
1038 pixn = r44.x & pixmask.xmask;
1039 dot = (*dst >> ((1 - pixn) * pixmask.npix)) & pixmask.mask;
1041 *dst = (*dst & pixmask.pmask[pixn]) | (dot << pixmask.lshift[pixn]);
1046 case V99X8_SCREEN_5:
1047 case V99X8_SCREEN_7:
1049 dot = (*dst >> ((1 - (r44.x & 1)) * 4)) & 0x0f;
1051 if ((r44.x & 1) == 0)
1052 *dst = (*dst & 0x0f) | (dot << 4);
1054 *dst = (*dst & 0xf0) | dot;
1057 case V99X8_SCREEN_6:
1059 dot = (*dst >> ((1 - (r44.x & 3)) * 2)) & 0x03;
1061 switch (r44.x & 0x03)
1064 *dst = (*dst & 0x3f) | (dot << 6);
1067 *dst = (*dst & 0xcf) | (dot << 4);
1070 *dst = (*dst & 0xf3) | (dot << 2);
1073 *dst = (*dst & 0xfc) | dot;
1077 case V99X8_SCREEN_8:
1078 vcom_lset(*dst, m & 0xff);
1084 if (r44.sx <= r44.ex)
1086 if (++r44.x >= r44.ex)
1089 if (r44.sy < r44.ey)
1091 if (++r44.y >= r44.ey)
1092 v99x8.status[2] &= ~0x01;
1095 if (--r44.y < r44.ey)
1096 v99x8.status[2] &= ~0x01;
1101 if (--r44.x < r44.ex)
1104 if (r44.sy <= r44.ey)
1106 if (++r44.y > r44.ey)
1107 v99x8.status[2] &= ~0x01;
1110 if (--r44.y < r44.ey)
1111 v99x8.status[2] &= ~0x01;
1118 void vcom_hputc(int m) /* XXX
\8d¶
\95û
\8cü
\81A
\8fã
\95û
\8cü
\82Ì
\83e
\83X
\83g
\82Í
\82µ
\82Ä
\82Ü
\82¹
\82ñ */
1120 *vcom_vram(r44.x, r44.y) = m;
1122 if (r44.sx <= r44.ex)
1124 r44.x += 1 << vcom.xshift;
1126 if (r44.x >= r44.ex)
1129 if (r44.sy <= r44.ey)
1131 if ((++r44.y) >= r44.ey)
1132 v99x8.status[2] &= ~0x01;
1135 if ((--r44.y) <= r44.ey)
1136 v99x8.status[2] &= ~0x01;
1141 r44.x -= 1 << vcom.xshift;
1143 if (r44.x <= r44.ex)
1146 if (r44.sy <= r44.ey)
1148 if ((++r44.y) >= r44.ey)
1149 v99x8.status[2] &= ~0x01;
1152 if ((--r44.y) <= r44.ey)
1153 v99x8.status[2] &= ~0x01;
1160 void v99x8_cputovdp(int m)
1162 if ((v99x8.status[2] & 0x01) == 0)
1165 switch(v99x8.ctrl[46] >> 4)
1176 static void lmmc(void)
1184 r44.sx = r44.x = vcom.dx;
1185 r44.sy = r44.y = vcom.dy;
1186 r44.ex = vcom.dx + vcom.nx;
1187 r44.ey = vcom.dy + vcom.ny;
1189 vcom_lputc(v99x8.ctrl[44]);
1193 static void lmcm(void);
1195 static void stop(void);
1198 static void vcom_lpset(int x,int y, int clr)
1201 int src_dot, dst_dot;
1203 dst = vcom_vram(x, y);
1209 pixn = x & pixmask.xmask;
1210 src_dot = clr & pixmask.mask;
1211 dst_dot = (*dst >> pixmask.rshift[pixn]) & pixmask.mask;
1212 vcom_lset(dst_dot, src_dot);
1213 *dst = (*dst & pixmask.pmask[pixn]) | (dst_dot << pixmask.lshift[pixn]);
1218 case V99X8_SCREEN_5:
1219 case V99X8_SCREEN_7:
1220 src_dot = clr & 0x0f;
1221 dst_dot = (*dst >> ((1 - (x & 1)) * 4)) & 0x0f;
1222 vcom_lset(dst_dot, src_dot);
1224 *dst = (*dst & 0x0f) | (dst_dot << 4);
1226 *dst = (*dst & 0xf0) | dst_dot;
1229 case V99X8_SCREEN_6:
1230 src_dot = clr & 0x03;
1231 dst_dot = (*dst >> ((1 - (r44.x & 3)) * 2)) & 0x03;
1232 vcom_lset(dst_dot, src_dot);
1236 *dst = (*dst & 0x3f) | (src_dot << 6);
1239 *dst = (*dst & 0xcf) | (src_dot << 4);
1242 *dst = (*dst & 0xf3) | (src_dot << 2);
1245 *dst = (*dst & 0xfc) | src_dot;
1249 case V99X8_SCREEN_8:
1250 vcom_lset(*dst, clr & 0xff);
1257 static void line(void)
1264 maj = (v99x8.ctrl[40] + (v99x8.ctrl[41] << 8)) & 1023;
1265 min = (v99x8.ctrl[42] + (v99x8.ctrl[43] << 8)) & 511;
1268 maj = (maj == 0) ? (1) : (maj);
1270 for (i = 0; i <= maj; i++)
1272 j = (i * min) / maj;
1273 if (v99x8.ctrl[45] & 0x01)
1275 y = vcom.dy + ((v99x8.ctrl[45] & 0x08) ? -i : i);
1276 x = vcom.dx + ((v99x8.ctrl[45] & 0x04) ? -j : j);
1279 x = vcom.dx + ((v99x8.ctrl[45] & 0x04) ? -i : i);
1280 y = vcom.dy + ((v99x8.ctrl[45] & 0x08) ? -j : j);
1282 vcom_lpset(x, y, v99x8.ctrl[44]);
1286 static uint8_t vcom_point(int x, int y)
1288 uint8_t clr = *vcom_vram(x, y);
1294 pixn = x & pixmask.xmask;
1295 clr = (clr >> pixmask.rshift[pixn]) & pixmask.mask;
1300 case V99X8_SCREEN_5:
1301 case V99X8_SCREEN_7:
1302 clr = (clr >> (4 * (x & 1))) & 0x0F;
1304 case V99X8_SCREEN_6:
1305 clr = (clr >> (2 * (x & 3))) & 0x03;
1313 static void srch(void)
1321 v99x8.status[2] &= ~0x10;
1322 while ((0 <= (vcom.sx + i)) && ((vcom.sx + i) <= vcom.xmask))
1324 uint8_t clr = vcom_point(vcom.sx + i, vcom.sy);
1325 if (v99x8.ctrl[45] & 0x02)
1327 if (clr != v99x8.ctrl[44])
1329 v99x8.status[2] |= 0x10;
1334 if (clr == v99x8.ctrl[44])
1336 v99x8.status[2] |= 0x10;
1340 i = (v99x8.ctrl[45] & 0x04) ? (i - 1) : (i + 1);
1343 if (v99x8.status[2] & 0x10)
1345 v99x8.status[8] = (vcom.sx + i) & 0xff;
1346 v99x8.status[9] = (((vcom.sx + i) >> 8) & 0x03) | 0xfc;
1351 static void pset(void)
1355 vcom_lpset(vcom.dx, vcom.dy, v99x8.ctrl[44]);
1359 static void point(void)
1363 v99x8.status[7] = vcom_point(vcom.sx, vcom.sy);
1366 static void hmmc(void)
1374 r44.sx = r44.x = vcom.dx & ~1;
1375 r44.sy = r44.y = vcom.dy;
1376 r44.ex = (vcom.dx + vcom.nx) & ~1;
1377 r44.ey = vcom.dy + vcom.ny;
1378 r44.xsize = vcom.nx & ~1;
1380 vcom_hputc(v99x8.ctrl[44]);
1383 static void lmmm(void)
1394 /* printf("hmmm: (%d,%d)->(%d,%d) *(%d,%d)\n", vcom.sx, vcom.sy, vcom.dx, vcom.dy, vcom.nx, vcom.ny); */
1395 n = vcom_canonaddr();
1396 #if YAN_V99X8_TEST /* XXX */
1397 vcom_lbcopy(vcom.sx, vcom.sy, vcom.dx, vcom.dy, vcom.nx, n);
1399 vcom_lcopy(vcom.dst, vcom.src, vcom.nx, n);
1401 vcom_setsy(vcom.sy + n);
1402 vcom_setdy(vcom.dy + n);
1404 if (vcom.ny != abs(n))
1405 vcom_setny(vcom.ny - abs(n));
1409 static void lmmm_(void);
1412 static void vcom_lfill(uint8_t *p, int clr, int n)
1414 if (n == 0) /*
\83o
\83C
\83g
\90\94\92P
\88Ê
\82Å
\8f\88\97\9d\82ð
\82¨
\82±
\82È
\82¤
\82½
\82ß */
1415 n = 1; /* 1dot
\82ª
\96³
\8e\8b\82³
\82ê
\82Ä
\82µ
\82Ü
\82¤
\91Î
\89\9e */
1462 static void lmmv(void) /* XXX byte
\92P
\88Ê
\82Å
\8f\88\97\9d\82µ
\82Ä
\82é
\82Ì
\82Í
\8eè
\94²
\82«(^^; */
1472 clr = v99x8.ctrl[44];
1473 switch (vcom.xshift)
1481 ny = n = vcom_canonaddr();
1486 vcom_lfill(vcom.dst, clr, vcom.nx);
1487 vcom.dst -= vcom.xbytes;
1493 vcom_lfill(vcom.dst, clr, vcom.nx);
1494 vcom.dst += vcom.xbytes;
1498 vcom_setsy(vcom.sy + n);
1499 vcom_setdy(vcom.dy + n);
1501 if (vcom.ny != abs(n))
1502 vcom_setny(vcom.ny - abs(n));
1506 static void lmmv_(void);
1509 void v99x8_command(int m)
1511 if (v99x8.mode.xsize == 0) /* XXX */
1514 vcom.xbytes = v99x8.mode.xsize >> v99x8.mode.xshift;
1515 vcom.xmask = v99x8.mode.xsize - 1;
1516 vcom.xshift = v99x8.mode.xshift;
1518 vcom.ymask = v99x8.pages * 0x4000 / vcom.xbytes - 1;
1519 vcom.yshift = getshift(vcom.xbytes - 1);
1522 pixmask = pixmasks[(v99x8.scr - V99X8_SCREEN_5) & 0x03];
1525 v99x8.status[2] |= 0x01;
1535 case 0xf: hmmc(); break;
1536 case 0xe: ymmm(); break;
1537 case 0xd: hmmm(); break;
1538 case 0xc: hmmv(); break;
1539 case 0xb: lmmc(); break;
1540 case 0xa: lmcm(); break;
1541 case 0x9: lmmm_(); break;
1542 case 0x8: lmmv_(); break;
1543 case 0x7: line(); break;
1544 case 0x6: srch(); break;
1545 case 0x5: pset(); break;
1546 case 0x4: point(); break;
1547 case 0x0: stop(); break;
1550 v99x8.ctrl[46] &= 0x0f;
1552 if (((m >> 4) != 0xb) && ((m >> 4) != 0xf) && (0 == cmdtime_t)) v99x8.status[2] &= ~0x01;
1555 if ((m >> 4) != 0xb && (m >> 4) != 0xf)
1556 v99x8.status[2] &= ~0x01;
1560 // from "v99x8_refresh.c" of Zodiac
1563 * Copyright (c) 2000-2002 SASAKI Shunsuke (eruchan@users.sourceforge.net).
1564 * Copyright (c) 2001-2002 The Zodiac project.
1565 * All rights reserved.
1567 * This program is free software; you can redistribute it and/or modify
1568 * it under the terms of the GNU General Public License as published by
1569 * the Free Software Foundation; either version 2 of the License, or
1570 * (at your option) any later version.
1572 * This program is distributed in the hope that it will be useful,
1573 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1574 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1575 * GNU General Public License for more details.
1577 * You should have received a copy of the GNU General Public License
1578 * along with this program; if not, write to the Free Software
1579 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1582 //#include "../../config.h"
1585 //#include <string.h>
1587 //#include "../zodiac.h"
1594 # define UINT32_FROM16(n1, n2) ((n2) << 16 | (n1))
1595 # define UINT8_FROM4(n1, n2) ((n1) << 4 | (n2))
1597 # define UINT32_FROM16(n1, n2) ((n1) << 16 | (n2))
1598 # define UINT8_FROM4(n1, n2) ((n2) << 4 | (n1))
1609 static v99x8_refresh_t v99x8_refresh;
1621 static v99x8_pallete_t pal[16 + 1];
1622 static uint32_t pal_8[256];
1623 static uint32_t pal_m[256];
1628 void v99x8_pallete_set(uint8_t n, uint8_t r, uint8_t g, uint8_t b)
1633 pal[n].r = r * 31 / 7;
1634 pal[n].g = g * 31 / 7;
1635 pal[n].b = b * 31 / 7;
1641 static int col_bg = 0;
1643 static void v99x8_pallete_update(void)
1649 for (i = 1; i < 17; ++i)
1651 pal[i].color = md_maprgb15(pal[i].r, pal[i].g, pal[i].b);
1653 a = (v99x8.col_bg == 0 || (v99x8.ctrl[8] & 0x20)) ? 16 : v99x8.col_bg;
1654 if (col_bg != a || pal[a].flag)
1658 memcpy(&pal[0], &pal[a], sizeof(v99x8_pallete_t));
1667 for (i = 0; i < 16; ++i)
1669 for (j = 0; j < 16; ++j)
1671 if (!pal[i].flag && !pal[j].flag)
1674 a = UINT8_FROM4(i, j);
1678 pal_m[a] = pal[i].color;
1681 pal_m[a] = md_maprgb15((pal[i].r >> 1) + (pal[j].r >> 1),
1682 (pal[i].g >> 1) + (pal[j].g >> 1),
1683 (pal[i].b >> 1) + (pal[j].b >> 1));
1689 for (i = 0; i < 17; ++i)
1690 pal[i].flag = FALSE;
1693 static void v99x8_pallete_init(void)
1695 static const uint8_t inipal[16][3] =
1697 {0, 0, 0}, {0, 0, 0}, {1, 6, 1}, {3, 7, 3},
1698 {1, 1, 7}, {2, 3, 7}, {5, 1, 1}, {2, 6, 7},
1699 {7, 1, 1}, {7, 3, 3}, {6, 6, 1}, {6, 6, 4},
1700 {1, 4, 1}, {6, 2, 5}, {5, 5, 5}, {7, 7, 7}
1706 memset(pal, 0, sizeof(pal));
1708 pal_black = md_maprgb15(0, 0, 0);
1709 for (i = 0; i < 256; ++i)
1712 /* i & 0x1c, (i >> 3) & 0x1c, (i & 3) << 3); */
1713 pal_8[i] = md_maprgb15((i & 0x1c) * 31 / (7 << 2),
1714 (i & 0xe0) * 31 / (7 << 5),
1716 pal_m[i] = pal_black;
1719 for(i = 0; i < 16; i++)
1720 v99x8_pallete_set(i, inipal[i][0], inipal[i][1], inipal[i][2]);
1726 #define V99X8_WIDTH (256 + 15)
1727 #define V99X8_HEIGHT (212 + 15)
1730 static uint8_t tbl_yjk_b[32 * 64 * 64], tbl_yjk_rg[62 + 32];
1731 static uint8_t blackbuf[256]; /* sprite
\94ñ
\95\
\8e¦
\97p
\83o
\83b
\83t
\83@ */
1734 void v99x8_refresh_init(void)
1737 md_video_mode_t mode;
1739 v99x8_refresh.width = V99X8_WIDTH;
1740 v99x8_refresh.height = V99X8_HEIGHT;
1744 v99x8_refresh.width *= 2;
1745 v99x8_refresh.height *= 2;
1748 mode.width = v99x8_refresh.width;
1749 mode.height = v99x8_refresh.height;
1752 mode.bpp = v99x8_refresh.bpp = MD_BPP;
1754 mode.bpp = v99x8_refresh.bpp = 16;
1757 mode.option = md_video_defaultopt();
1760 md_video_fixmode(&mode);
1761 if (!md_video_setmode(v99x8_refresh.width, v99x8_refresh.height, &mode, NULL))
1764 v99x8_refresh.bpp = md_video_bpp();
1767 v99x8_pallete_init();
1769 for (i = 0; i < 32; ++i)
1774 for (j = 0; j < 64; ++j)
1777 for (k = 0; k < 64; ++k)
1779 n = (i * 5 - ((j & 0x20) ? j - 64 : j) * 2
1780 - ((k & 0x20) ? k - 64 : k)) >> 2;
1786 tbl_yjk_b[(((j + 32) & 63) << 11)
1787 + (((k + 32) & 63) << 5) + i] = n;
1792 tbl_yjk_rg[i + 32] = i;
1793 tbl_yjk_rg[i + 64] = 31;
1804 b: (5Y + 2J + K) >> 2
1806 memset(blackbuf, 0, sizeof(blackbuf));
1809 void V99X8::v99x8_refresh_screen(void)
1811 md_video_update(0, NULL);
1814 void V99X8::v99x8_refresh_clear(void)
1816 md_video_fill(0, 0, v99x8_refresh.width, v99x8_refresh.height, pal[v99x8.col_bg].color);
1819 uint8_t *V99X8::v99x8_refresh_start(int x, int w, int h)
1823 v99x8_pallete_update();
1825 a = v99x8.f_zoom ? 2 : 1;
1827 return md_video_lockline((((7 - v99x8.ctrl[18]) & 0x0f) + x) * a
1828 , v99x8.scanline * a
1832 static __inline__ void v99x8_refresh_stop(void)
1834 md_video_unlockline();
1842 # define pixel_put(pb, n, px) *((md_pixel_t *)(pb) + (n)) = (px)
1849 # define pixel_put(pb, n, px) *((uint8_t *)(pb) + (n) / 4) \
1850 |= (px) << ((3 - (n)) * 2)
1852 # define pixel_put(pb, n, px) *((uint8_t *)(pb) + (n) / 4) \
1853 |= (px) << ((n) * 2)
1861 static __inline__ void pixel_put(void *pb, int n, uint32_t p1)
1866 switch (v99x8_refresh.bpp)
1869 *((uint16_t *)pb + n) = p1;
1872 *((uint8_t *)pb + n) = p1;
1875 *((uint32_t *)pb + n) = p1;
1878 p = (uint8_t *)pb + (n >> 2);
1880 mask = 0xc0 >> ((n & 3) * 2);
1881 pix2bpp = p1 << (6 - ((n & 3) * 2));
1883 mask = 0x03 << ((n & 3) * 2);
1884 pix2bpp = p1 << ((n & 3) * 2);
1887 *p = (*p & ~mask) | (pix2bpp & mask);
1890 /* XXX 2bpp
\91Î
\89\9e\95û
\96@
1892 * 1.
\82Ü
\82¸
\91Î
\89\9e\82·
\82é 2bit
\82ð &
\82Å 0
\83N
\83\8a\83A
\82·
\82é
1893 * 2.
\8e\9f\82É
\81A2bit
\82ð |
\82Å
\89Á
\82¦
\82é
1895 *
\82Æ
\82¢
\82¤
\8eè
\8f\87\82ª
\95K
\97v
\81B
\91Î
\89\9e\82Í
\8cã
\93ú
\82É
\82Ä.... --
\82k
1905 static uint8_t sbuf[32 + 256 + 16];
1917 static uint8_t *v99x8_refresh_sprite1(uint8_t y)
1919 v99x8_sprite_t *ptr_a;
1922 uint8_t a, c, *ptr_g, *ptr_s, *tbl_sp;
1925 /* if (v99x8.ctrl[8] & 0x02)
1928 /* tbl_sp = &v99x8.vram[(int)v99x8.ctrl[6] << 11]; */
1929 tbl_sp = v99x8.vram + ((int)v99x8.ctrl[6] << 11);
1931 memset(sbuf + 32, 0, 256);
1933 size = (v99x8.ctrl[1] & 0x02) ? 16 : 8;
1939 ptr_a = (v99x8_sprite_t *)(v99x8.vram + ((int)v99x8.ctrl[11] << 15)
1940 + ((int)v99x8.ctrl[5] << 7));
1942 for (i = 0 ;; ++i, ++ptr_a)
1944 if (i >= 32 || n >= 4 || ptr_a->y == 208)
1947 a = (uint8_t)(ptr_a->y - v99x8.ctrl[23]); /* a>256-h? a-=256 */
1948 if (a >=y || a + size < y)
1955 ptr_s = sbuf + ptr_a->x + ((c & 0x80) ? 0 : 32);
1957 + (((v99x8.ctrl[1] & 0x02) ? ptr_a->n & 0xfc : ptr_a->n) << 3);
1962 if (ptr_s[0] == 0 && (*ptr_g & 0x80)) ptr_s[0] = c;
1963 if (ptr_s[1] == 0 && (*ptr_g & 0x40)) ptr_s[1] = c;
1964 if (ptr_s[2] == 0 && (*ptr_g & 0x20)) ptr_s[2] = c;
1965 if (ptr_s[3] == 0 && (*ptr_g & 0x10)) ptr_s[3] = c;
1966 if (ptr_s[4] == 0 && (*ptr_g & 0x08)) ptr_s[4] = c;
1967 if (ptr_s[5] == 0 && (*ptr_g & 0x04)) ptr_s[5] = c;
1968 if (ptr_s[6] == 0 && (*ptr_g & 0x02)) ptr_s[6] = c;
1969 if (ptr_s[7] == 0 && (*ptr_g & 0x01)) ptr_s[7] = c;
1971 if (!(v99x8.ctrl[1] & 0x02))
1977 if (ptr_s[0] == 0 && (*ptr_g & 0x80)) ptr_s[0] = c;
1978 if (ptr_s[1] == 0 && (*ptr_g & 0x40)) ptr_s[1] = c;
1979 if (ptr_s[2] == 0 && (*ptr_g & 0x20)) ptr_s[2] = c;
1980 if (ptr_s[3] == 0 && (*ptr_g & 0x10)) ptr_s[3] = c;
1981 if (ptr_s[4] == 0 && (*ptr_g & 0x08)) ptr_s[4] = c;
1982 if (ptr_s[5] == 0 && (*ptr_g & 0x04)) ptr_s[5] = c;
1983 if (ptr_s[6] == 0 && (*ptr_g & 0x02)) ptr_s[6] = c;
1984 if (ptr_s[7] == 0 && (*ptr_g & 0x01)) ptr_s[7] = c;
1990 static uint8_t *v99x8_refresh_sprite2(uint8_t y)
1992 v99x8_sprite_t *ptr_a;
1995 uint8_t a, c, *ptr_g, *ptr_c, *ptr_s, *tbl_sp;
1998 if (v99x8.ctrl[8] & 0x02)
2001 tbl_sp = v99x8.vram + ((int)v99x8.ctrl[6] << 11);
2003 memset(sbuf + 32, 0, 256);
2005 size = (v99x8.ctrl[1] & 0x02) ? 16 : 8;
2012 ptr_c = v99x8.vram + ((int)v99x8.ctrl[11] << 15)
2013 + ((int)(v99x8.ctrl[5] & 0xf8) << 7);
2014 ptr_a = (v99x8_sprite_t *)(ptr_c + 0x200);
2016 for (i = 0 ;; ++i, ++ptr_a, ptr_c += 16)
2018 if (i >= 32 || n >= 8 || ptr_a->y == 216)
2021 a = (uint8_t)(ptr_a->y - v99x8.ctrl[23]); /* a>256-h? a-=256 */
2022 if (a >= y || a + size < y)
2029 ptr_s = sbuf + ptr_a->x + ((c & 0x80) ? 0 : 32);
2031 + (((v99x8.ctrl[1] & 0x02) ? ptr_a->n & 0xfc : ptr_a->n) << 3);
2033 if ((c & 0x40) == 0)
2038 if (ptr_s[0] == 0 && (*ptr_g & 0x80)) ptr_s[0] = c;
2039 if (ptr_s[1] == 0 && (*ptr_g & 0x40)) ptr_s[1] = c;
2040 if (ptr_s[2] == 0 && (*ptr_g & 0x20)) ptr_s[2] = c;
2041 if (ptr_s[3] == 0 && (*ptr_g & 0x10)) ptr_s[3] = c;
2042 if (ptr_s[4] == 0 && (*ptr_g & 0x08)) ptr_s[4] = c;
2043 if (ptr_s[5] == 0 && (*ptr_g & 0x04)) ptr_s[5] = c;
2044 if (ptr_s[6] == 0 && (*ptr_g & 0x02)) ptr_s[6] = c;
2045 if (ptr_s[7] == 0 && (*ptr_g & 0x01)) ptr_s[7] = c;
2047 if (!(v99x8.ctrl[1] & 0x02))
2050 ptr_s += 8; ptr_g += 16;
2051 if (ptr_s[0] == 0 && (*ptr_g & 0x80)) ptr_s[0] = c;
2052 if (ptr_s[1] == 0 && (*ptr_g & 0x40)) ptr_s[1] = c;
2053 if (ptr_s[2] == 0 && (*ptr_g & 0x20)) ptr_s[2] = c;
2054 if (ptr_s[3] == 0 && (*ptr_g & 0x10)) ptr_s[3] = c;
2055 if (ptr_s[4] == 0 && (*ptr_g & 0x08)) ptr_s[4] = c;
2056 if (ptr_s[5] == 0 && (*ptr_g & 0x04)) ptr_s[5] = c;
2057 if (ptr_s[6] == 0 && (*ptr_g & 0x02)) ptr_s[6] = c;
2058 if (ptr_s[7] == 0 && (*ptr_g & 0x01)) ptr_s[7] = c;
2065 if (*ptr_g & 0x80) ptr_s[0] |= c;
2066 if (*ptr_g & 0x40) ptr_s[1] |= c;
2067 if (*ptr_g & 0x20) ptr_s[2] |= c;
2068 if (*ptr_g & 0x10) ptr_s[3] |= c;
2069 if (*ptr_g & 0x08) ptr_s[4] |= c;
2070 if (*ptr_g & 0x04) ptr_s[5] |= c;
2071 if (*ptr_g & 0x02) ptr_s[6] |= c;
2072 if (*ptr_g & 0x01) ptr_s[7] |= c;
2074 if (!(v99x8.ctrl[1] & 0x02))
2077 ptr_s += 8; ptr_g += 16;
2078 if (*ptr_g & 0x80) ptr_s[0] |= c;
2079 if (*ptr_g & 0x40) ptr_s[1] |= c;
2080 if (*ptr_g & 0x20) ptr_s[2] |= c;
2081 if (*ptr_g & 0x10) ptr_s[3] |= c;
2082 if (*ptr_g & 0x08) ptr_s[4] |= c;
2083 if (*ptr_g & 0x04) ptr_s[5] |= c;
2084 if (*ptr_g & 0x02) ptr_s[6] |= c;
2085 if (*ptr_g & 0x01) ptr_s[7] |= c;
2093 void V99X8::v99x8_refresh_sc0(int y, int h)
2102 v99x8.tbl_pg = v99x8.vram + (((int)v99x8.ctrl[4] & 0x3f) << 11);
2103 v99x8.tbl_pn = v99x8.vram + (((int)v99x8.ctrl[2] & 0x7f) << 10);
2107 pbuf = v99x8_refresh_start(8, 240, h);
2108 pp = md_video_pitch() - md_video_pixbytes(240);
2110 fg = pal[v99x8.col_fg].color;
2111 bg = pal[v99x8.col_bg].color;
2118 T = v99x8.tbl_pn + (y >> 3) * 40;
2119 G = v99x8.tbl_pg + (y & 0x07);
2122 for (i = 0; i < 40; ++i)
2126 a = G[(int)*T++ << 3];
2129 pixel_put(pbuf, 0, (a & 0x80)? fg : bg);
2130 pixel_put(pbuf, 1, (a & 0x80)? fg : bg);
2131 pixel_put(pbuf, 2, (a & 0x40)? fg : bg);
2132 pixel_put(pbuf, 3, (a & 0x40)? fg : bg);
2133 pixel_put(pbuf, 4, (a & 0x20)? fg : bg);
2134 pixel_put(pbuf, 5, (a & 0x20)? fg : bg);
2135 pixel_put(pbuf, 6, (a & 0x10)? fg : bg);
2136 pixel_put(pbuf, 7, (a & 0x10)? fg : bg);
2137 pixel_put(pbuf, 8, (a & 0x08)? fg : bg);
2138 pixel_put(pbuf, 9, (a & 0x08)? fg : bg);
2139 pixel_put(pbuf, 10, (a & 0x04)? fg : bg);
2140 pixel_put(pbuf, 11, (a & 0x04)? fg : bg);
2141 pbuf += md_video_pixbytes(12);
2144 pixel_put(pbuf, 0, (a & 0x80)? fg : bg);
2145 pixel_put(pbuf, 1, (a & 0x40)? fg : bg);
2146 pixel_put(pbuf, 2, (a & 0x20)? fg : bg);
2147 pixel_put(pbuf, 3, (a & 0x10)? fg : bg);
2148 pixel_put(pbuf, 4, (a & 0x08)? fg : bg);
2149 pixel_put(pbuf, 5, (a & 0x04)? fg : bg);
2150 pbuf += md_video_pixbytes(6);
2156 v99x8_refresh_stop();
2159 void V99X8::v99x8_refresh_sc1(int y, int h)
2168 v99x8.tbl_pg = v99x8.vram + (((int)v99x8.ctrl[4] & 0x3f) << 11);
2169 v99x8.tbl_pn = v99x8.vram + (((int)v99x8.ctrl[2] & 0x7f) << 10);
2170 v99x8.tbl_cl = v99x8.vram + (((int)v99x8.ctrl[10] & 0x07) << 14)
2171 + ((int)v99x8.ctrl[3] << 6);
2175 pbuf = v99x8_refresh_start(0, 256, h);
2176 pp = md_video_pitch() - md_video_pixbytes(256);
2180 n = v99x8.ctrl[23] + y;
2181 G = v99x8.tbl_pg + (n & 0x07);
2182 T = v99x8.tbl_pn + ((n & 0xF8) << 2);
2183 sp = v99x8_refresh_sprite1(y++);
2185 for(i = 0; i < 32; ++i)
2191 n = v99x8.tbl_cl[*T >> 3];
2192 fg = pal[n >> 4].color;
2193 bg = pal[n & 0x0f].color;
2195 a = G[(int)*T++ << 3];
2198 pixel_put(pbuf, 0, sp[0] ? pal[sp[0]].color : (a & 0x80) ? fg : bg);
2199 pixel_put(pbuf, 1, sp[0] ? pal[sp[0]].color : (a & 0x80) ? fg : bg);
2200 pixel_put(pbuf, 2, sp[1] ? pal[sp[1]].color : (a & 0x40) ? fg : bg);
2201 pixel_put(pbuf, 3, sp[1] ? pal[sp[1]].color : (a & 0x40) ? fg : bg);
2202 pixel_put(pbuf, 4, sp[2] ? pal[sp[2]].color : (a & 0x20) ? fg : bg);
2203 pixel_put(pbuf, 5, sp[2] ? pal[sp[2]].color : (a & 0x20) ? fg : bg);
2204 pixel_put(pbuf, 6, sp[3] ? pal[sp[3]].color : (a & 0x10) ? fg : bg);
2205 pixel_put(pbuf, 7, sp[3] ? pal[sp[3]].color : (a & 0x10) ? fg : bg);
2206 pixel_put(pbuf, 8, sp[4] ? pal[sp[4]].color : (a & 0x08) ? fg : bg);
2207 pixel_put(pbuf, 9, sp[4] ? pal[sp[4]].color : (a & 0x08) ? fg : bg);
2208 pixel_put(pbuf, 10, sp[5] ? pal[sp[5]].color : (a & 0x04) ? fg : bg);
2209 pixel_put(pbuf, 11, sp[5] ? pal[sp[5]].color : (a & 0x04) ? fg : bg);
2210 pixel_put(pbuf, 12, sp[6] ? pal[sp[6]].color : (a & 0x02) ? fg : bg);
2211 pixel_put(pbuf, 13, sp[6] ? pal[sp[6]].color : (a & 0x02) ? fg : bg);
2212 pixel_put(pbuf, 14, sp[7] ? pal[sp[7]].color : (a & 0x01) ? fg : bg);
2213 pixel_put(pbuf, 15, sp[7] ? pal[sp[7]].color : (a & 0x01) ? fg : bg);
2214 pbuf += md_video_pixbytes(16);
2218 pixel_put(pbuf, 0, sp[0] ? pal[sp[0]].color : (a & 0x80) ? fg : bg);
2219 pixel_put(pbuf, 1, sp[1] ? pal[sp[1]].color : (a & 0x40) ? fg : bg);
2220 pixel_put(pbuf, 2, sp[2] ? pal[sp[2]].color : (a & 0x20) ? fg : bg);
2221 pixel_put(pbuf, 3, sp[3] ? pal[sp[3]].color : (a & 0x10) ? fg : bg);
2222 pixel_put(pbuf, 4, sp[4] ? pal[sp[4]].color : (a & 0x08) ? fg : bg);
2223 pixel_put(pbuf, 5, sp[5] ? pal[sp[5]].color : (a & 0x04) ? fg : bg);
2224 pixel_put(pbuf, 6, sp[6] ? pal[sp[6]].color : (a & 0x02) ? fg : bg);
2225 pixel_put(pbuf, 7, sp[7] ? pal[sp[7]].color : (a & 0x01) ? fg : bg);
2227 pbuf += md_video_pixbytes(8);
2234 v99x8_refresh_stop();
2237 void V99X8::v99x8_refresh_sc4(int y, int h)
2241 uint8_t *T, *PGT, *CLT;
2247 v99x8.tbl_pg = v99x8.vram + (((int)v99x8.ctrl[4] & 0x3c) << 11);
2248 v99x8.tbl_pn = v99x8.vram + (((int)v99x8.ctrl[2] & 0x7f) << 10);
2249 v99x8.tbl_cl = v99x8.vram + (((int)v99x8.ctrl[10] & 0x07) << 14)
2250 + (((int)v99x8.ctrl[3] & 0x80) << 6);
2255 pbuf = v99x8_refresh_start(0, 256, h);
2256 pp = md_video_pitch() - md_video_pixbytes(256);
2260 n = v99x8.ctrl[23] + y;
2261 T = v99x8.tbl_pn + ((n & 0xf8) << 2);
2263 n = ((n & 0xc0) << 5) + (n & 0x07);
2264 PGT = v99x8.tbl_pg + n;
2265 CLT = v99x8.tbl_cl + n;
2267 if (v99x8.scr == V99X8_SCREEN_2)
2268 sp = v99x8_refresh_sprite1(y++);
2270 sp = v99x8_refresh_sprite2(y++);
2272 for (i = 0; i < 32; ++i)
2279 fg = pal[n >> 4].color;
2280 bg = pal[n & 0x0f].color;
2282 a = PGT[(int)*T++ << 3];
2286 pixel_put(pbuf, 0, sp[0] ? pal[sp[0]].color : (a & 0x80) ? fg : bg);
2287 pixel_put(pbuf, 1, sp[0] ? pal[sp[0]].color : (a & 0x80) ? fg : bg);
2288 pixel_put(pbuf, 2, sp[1] ? pal[sp[1]].color : (a & 0x40) ? fg : bg);
2289 pixel_put(pbuf, 3, sp[1] ? pal[sp[1]].color : (a & 0x40) ? fg : bg);
2290 pixel_put(pbuf, 4, sp[2] ? pal[sp[2]].color : (a & 0x20) ? fg : bg);
2291 pixel_put(pbuf, 5, sp[2] ? pal[sp[2]].color : (a & 0x20) ? fg : bg);
2292 pixel_put(pbuf, 6, sp[3] ? pal[sp[3]].color : (a & 0x10) ? fg : bg);
2293 pixel_put(pbuf, 7, sp[3] ? pal[sp[3]].color : (a & 0x10) ? fg : bg);
2294 pixel_put(pbuf, 8, sp[4] ? pal[sp[4]].color : (a & 0x08) ? fg : bg);
2295 pixel_put(pbuf, 9, sp[4] ? pal[sp[4]].color : (a & 0x08) ? fg : bg);
2296 pixel_put(pbuf, 10, sp[5] ? pal[sp[5]].color : (a & 0x04) ? fg : bg);
2297 pixel_put(pbuf, 11, sp[5] ? pal[sp[5]].color : (a & 0x04) ? fg : bg);
2298 pixel_put(pbuf, 12, sp[6] ? pal[sp[6]].color : (a & 0x02) ? fg : bg);
2299 pixel_put(pbuf, 13, sp[6] ? pal[sp[6]].color : (a & 0x02) ? fg : bg);
2300 pixel_put(pbuf, 14, sp[7] ? pal[sp[7]].color : (a & 0x01) ? fg : bg);
2301 pixel_put(pbuf, 15, sp[7] ? pal[sp[7]].color : (a & 0x01) ? fg : bg);
2302 pbuf += md_video_pixbytes(16); sp += 8;
2305 pixel_put(pbuf, 0, sp[0] ? pal[sp[0]].color : (a & 0x80)? fg : bg);
2306 pixel_put(pbuf, 1, sp[1] ? pal[sp[1]].color : (a & 0x40)? fg : bg);
2307 pixel_put(pbuf, 2, sp[2] ? pal[sp[2]].color : (a & 0x20)? fg : bg);
2308 pixel_put(pbuf, 3, sp[3] ? pal[sp[3]].color : (a & 0x10)? fg : bg);
2309 pixel_put(pbuf, 4, sp[4] ? pal[sp[4]].color : (a & 0x08)? fg : bg);
2310 pixel_put(pbuf, 5, sp[5] ? pal[sp[5]].color : (a & 0x04)? fg : bg);
2311 pixel_put(pbuf, 6, sp[6] ? pal[sp[6]].color : (a & 0x02)? fg : bg);
2312 pixel_put(pbuf, 7, sp[7] ? pal[sp[7]].color : (a & 0x01)? fg : bg);
2314 pbuf += md_video_pixbytes(8); sp += 8;
2320 v99x8_refresh_stop();
2323 void V99X8::v99x8_refresh_sc5(int y, int h)
2332 v99x8.tbl_pn = v99x8.vram + (((int)v99x8.ctrl[2] & 0x60) << 10);
2336 pbuf = v99x8_refresh_start(0, 256, h);
2337 pp = md_video_pitch() - md_video_pixbytes(256);
2339 T = v99x8.tbl_pn + (((y + v99x8.ctrl[23]) & 0xff) << 7);
2343 sp = v99x8_refresh_sprite2(y++);
2344 for (i = 0; i < 32; ++i)
2348 pixel_put(pbuf, 0, pal[sp[0] ? sp[0] : T[0] >> 4].color);
2349 pixel_put(pbuf, 1, pal[sp[0] ? sp[0] : T[0] >> 4].color);
2350 pixel_put(pbuf, 2, pal[sp[1] ? sp[1] : T[0] & 0x0f].color);
2351 pixel_put(pbuf, 3, pal[sp[1] ? sp[1] : T[0] & 0x0f].color);
2352 pixel_put(pbuf, 4, pal[sp[2] ? sp[2] : T[1] >> 4].color);
2353 pixel_put(pbuf, 5, pal[sp[2] ? sp[2] : T[1] >> 4].color);
2354 pixel_put(pbuf, 6, pal[sp[3] ? sp[3] : T[1] & 0x0f].color);
2355 pixel_put(pbuf, 7, pal[sp[3] ? sp[3] : T[1] & 0x0f].color);
2356 pixel_put(pbuf, 8, pal[sp[4] ? sp[4] : T[2] >> 4].color);
2357 pixel_put(pbuf, 9, pal[sp[4] ? sp[4] : T[2] >> 4].color);
2358 pixel_put(pbuf, 10, pal[sp[5] ? sp[5] : T[2] & 0x0f].color);
2359 pixel_put(pbuf, 11, pal[sp[5] ? sp[5] : T[2] & 0x0f].color);
2360 pixel_put(pbuf, 12, pal[sp[6] ? sp[6] : T[3] >> 4].color);
2361 pixel_put(pbuf, 13, pal[sp[6] ? sp[6] : T[3] >> 4].color);
2362 pixel_put(pbuf, 14, pal[sp[7] ? sp[7] : T[3] & 0x0f].color);
2363 pixel_put(pbuf, 15, pal[sp[7] ? sp[7] : T[3] & 0x0f].color);
2365 pbuf += md_video_pixbytes(16); T += 4; sp += 8;
2367 pixel_put(pbuf, 0, pal[sp[0] ? sp[0] : T[0] >> 4].color);
2368 pixel_put(pbuf, 1, pal[sp[1] ? sp[1] : T[0] & 0x0f].color);
2369 pixel_put(pbuf, 2, pal[sp[2] ? sp[2] : T[1] >> 4].color);
2370 pixel_put(pbuf, 3, pal[sp[3] ? sp[3] : T[1] & 0x0f].color);
2371 pixel_put(pbuf, 4, pal[sp[4] ? sp[4] : T[2] >> 4].color);
2372 pixel_put(pbuf, 5, pal[sp[5] ? sp[5] : T[2] & 0x0f].color);
2373 pixel_put(pbuf, 6, pal[sp[6] ? sp[6] : T[3] >> 4].color);
2374 pixel_put(pbuf, 7, pal[sp[7] ? sp[7] : T[3] & 0x0f].color);
2376 pbuf += md_video_pixbytes(8); T += 4; sp += 8;
2382 v99x8_refresh_stop();
2385 void V99X8::v99x8_refresh_sc6(int y, int h)
2394 v99x8.tbl_pn = v99x8.vram + (((int)v99x8.ctrl[2] & 0x60) << 10);
2399 pbuf = v99x8_refresh_start(0, 256, h);
2400 pp = md_video_pitch() - md_video_pixbytes(256);
2402 T = v99x8.tbl_pn + (((y + v99x8.ctrl[23]) & 0xff) << 7);
2406 sp = v99x8_refresh_sprite2(y++);
2407 for(i = 0; i < 32; ++i)
2411 pixel_put(pbuf, 0, pal[sp[0] ? sp[0] : T[0] >> 6].color);
2412 pixel_put(pbuf, 1, pal[sp[0] ? sp[0] : (T[0] >> 4) & 3].color);
2413 pixel_put(pbuf, 2, pal[sp[1] ? sp[1] : (T[0] >> 2) & 3].color);
2414 pixel_put(pbuf, 3, pal[sp[1] ? sp[1] : T[0] & 3].color);
2415 pixel_put(pbuf, 4, pal[sp[2] ? sp[2] : T[1] >> 6].color);
2416 pixel_put(pbuf, 5, pal[sp[2] ? sp[2] : (T[1] >> 4) & 3].color);
2417 pixel_put(pbuf, 6, pal[sp[3] ? sp[3] : (T[1] >> 2) & 3].color);
2418 pixel_put(pbuf, 7, pal[sp[3] ? sp[3] : T[1] & 3].color);
2419 pixel_put(pbuf, 8, pal[sp[4] ? sp[4] : T[2] >> 6].color);
2420 pixel_put(pbuf, 9, pal[sp[4] ? sp[4] : (T[2] >> 4) & 3].color);
2421 pixel_put(pbuf, 10, pal[sp[5] ? sp[5] : (T[2] >> 2) & 3].color);
2422 pixel_put(pbuf, 11, pal[sp[5] ? sp[5] : T[2] & 3].color);
2423 pixel_put(pbuf, 12, pal[sp[6] ? sp[6] : T[3] >> 6].color);
2424 pixel_put(pbuf, 13, pal[sp[6] ? sp[6] : (T[3] >> 4) & 3].color);
2425 pixel_put(pbuf, 14, pal[sp[7] ? sp[7] : (T[3] >> 2) & 3].color);
2426 pixel_put(pbuf, 15, pal[sp[7] ? sp[7] : T[3] & 3].color);
2427 pbuf += md_video_pixbytes(16); T += 4; sp += 8;
2430 pixel_put(pbuf, 0, sp[0] ? pal[sp[0]].color : pal_m[(T[0] >> 6) | (T[0] & 0x30)]);
2431 pixel_put(pbuf, 1, sp[1] ? pal[sp[1]].color : pal_m[((T[0] & 0x0c) << 2) | (T[0] & 0x03)]);
2432 pixel_put(pbuf, 2, sp[2] ? pal[sp[2]].color : pal_m[(T[1] >> 6) | (T[1] & 0x30)]);
2433 pixel_put(pbuf, 3, sp[3] ? pal[sp[3]].color : pal_m[((T[1] & 0x0c) << 2) | (T[1] & 0x03)]);
2434 pixel_put(pbuf, 4, sp[4] ? pal[sp[4]].color : pal_m[(T[2] >> 6) | (T[2] & 0x30)]);
2435 pixel_put(pbuf, 5, sp[5] ? pal[sp[5]].color : pal_m[((T[2] & 0x0c) << 2) | (T[2] & 0x03)]);
2436 pixel_put(pbuf, 6, sp[6] ? pal[sp[6]].color : pal_m[(T[3] >> 6) | (T[3] & 0x30)]);
2437 pixel_put(pbuf, 7, sp[7] ? pal[sp[7]].color : pal_m[((T[3] & 0x0c) << 2) | (T[3] & 0x03)]);
2438 pbuf += md_video_pixbytes(8); T += 4; sp += 8;
2444 v99x8_refresh_stop();
2447 void V99X8::v99x8_refresh_sc7(int y, int h)
2456 v99x8.tbl_pn = v99x8.vram + (((int)v99x8.ctrl[2] & 0x20) << 11);
2460 pbuf = v99x8_refresh_start(0, 256, h);
2461 pp = md_video_pitch() - md_video_pixbytes(256);
2463 /* printf("%d/%d %d %d\n", y, v99x8.ctrl[23], (y+v99x8.ctrl[23])&0xff, v99x8.ctrl[19]+1); */
2464 T = v99x8.tbl_pn + (((y + v99x8.ctrl[23]) & 0xff) << 8);
2468 sp = v99x8_refresh_sprite2(y);
2470 for (i = 0; i < 32; ++i)
2474 pixel_put(pbuf, 0, pal[sp[0] ? sp[0] : T[0] >> 4].color);
2475 pixel_put(pbuf, 1, pal[sp[0] ? sp[0] : T[0] & 0x0f].color);
2476 pixel_put(pbuf, 2, pal[sp[1] ? sp[1] : T[1] >> 4].color);
2477 pixel_put(pbuf, 3, pal[sp[1] ? sp[1] : T[1] & 0x0f].color);
2478 pixel_put(pbuf, 4, pal[sp[2] ? sp[2] : T[2] >> 4].color);
2479 pixel_put(pbuf, 5, pal[sp[2] ? sp[2] : T[2] & 0x0f].color);
2480 pixel_put(pbuf, 6, pal[sp[3] ? sp[3] : T[3] >> 4].color);
2481 pixel_put(pbuf, 7, pal[sp[3] ? sp[3] : T[3] & 0x0f].color);
2482 pixel_put(pbuf, 8, pal[sp[4] ? sp[4] : T[4] >> 4].color);
2483 pixel_put(pbuf, 9, pal[sp[4] ? sp[4] : T[4] & 0x0f].color);
2484 pixel_put(pbuf, 10, pal[sp[5] ? sp[5] : T[5] >> 4].color);
2485 pixel_put(pbuf, 11, pal[sp[5] ? sp[5] : T[5] & 0x0f].color);
2486 pixel_put(pbuf, 12, pal[sp[6] ? sp[6] : T[6] >> 4].color);
2487 pixel_put(pbuf, 13, pal[sp[6] ? sp[6] : T[6] & 0x0f].color);
2488 pixel_put(pbuf, 14, pal[sp[7] ? sp[7] : T[7] >> 4].color);
2489 pixel_put(pbuf, 15, pal[sp[7] ? sp[7] : T[7] & 0x0f].color);
2490 pbuf += md_video_pixbytes(16); T += 8; sp += 8;
2493 pixel_put(pbuf,0, sp[0]? pal[sp[0]].color : pal_m[T[0]]);
2494 pixel_put(pbuf,1, sp[1]? pal[sp[1]].color : pal_m[T[1]]);
2495 pixel_put(pbuf,2, sp[2]? pal[sp[2]].color : pal_m[T[2]]);
2496 pixel_put(pbuf,3, sp[3]? pal[sp[3]].color : pal_m[T[3]]);
2497 pixel_put(pbuf,4, sp[4]? pal[sp[4]].color : pal_m[T[4]]);
2498 pixel_put(pbuf,5, sp[5]? pal[sp[5]].color : pal_m[T[5]]);
2499 pixel_put(pbuf,6, sp[6]? pal[sp[6]].color : pal_m[T[6]]);
2500 pixel_put(pbuf,7, sp[7]? pal[sp[7]].color : pal_m[T[7]]);
2502 pbuf += md_video_pixbytes(8); T += 8; sp += 8;
2510 v99x8_refresh_stop();
2513 void V99X8::v99x8_refresh_sc8(int y, int h)
2519 uint8_t sc8spr[16] =
2521 0x00,0x02,0x10,0x12,0x80,0x82,0x90,0x92,
2522 0x49,0x4B,0x59,0x5B,0xC9,0xCB,0xD9,0xDB
2527 v99x8.tbl_pn = v99x8.vram + (((int)v99x8.ctrl[2] & 0x20) << 11);
2531 pbuf = v99x8_refresh_start(0, 256, h);
2532 pp = md_video_pitch() - md_video_pixbytes(256);
2534 T = v99x8.tbl_pn + (((y + v99x8.ctrl[23]) & 0xff) << 8);
2538 sp = v99x8_refresh_sprite2(y);
2540 for (i = 0; i < 32; ++i)
2544 pixel_put(pbuf, 0, pal_8[sp[0] ? sc8spr[sp[0]] : T[0]]);
2545 pixel_put(pbuf, 1, pal_8[sp[0] ? sc8spr[sp[0]] : T[0]]);
2546 pixel_put(pbuf, 2, pal_8[sp[1] ? sc8spr[sp[1]] : T[1]]);
2547 pixel_put(pbuf, 3, pal_8[sp[1] ? sc8spr[sp[1]] : T[1]]);
2548 pixel_put(pbuf, 4, pal_8[sp[2] ? sc8spr[sp[2]] : T[2]]);
2549 pixel_put(pbuf, 5, pal_8[sp[2] ? sc8spr[sp[2]] : T[2]]);
2550 pixel_put(pbuf, 6, pal_8[sp[3] ? sc8spr[sp[3]] : T[3]]);
2551 pixel_put(pbuf, 7, pal_8[sp[3] ? sc8spr[sp[3]] : T[3]]);
2552 pixel_put(pbuf, 8, pal_8[sp[4] ? sc8spr[sp[4]] : T[4]]);
2553 pixel_put(pbuf, 9, pal_8[sp[4] ? sc8spr[sp[4]] : T[4]]);
2554 pixel_put(pbuf, 10, pal_8[sp[5] ? sc8spr[sp[5]] : T[5]]);
2555 pixel_put(pbuf, 11, pal_8[sp[5] ? sc8spr[sp[5]] : T[5]]);
2556 pixel_put(pbuf, 12, pal_8[sp[6] ? sc8spr[sp[6]] : T[6]]);
2557 pixel_put(pbuf, 13, pal_8[sp[6] ? sc8spr[sp[6]] : T[6]]);
2558 pixel_put(pbuf, 14, pal_8[sp[7] ? sc8spr[sp[7]] : T[7]]);
2559 pixel_put(pbuf, 15, pal_8[sp[7] ? sc8spr[sp[7]] : T[7]]);
2560 pbuf += md_video_pixbytes(16); T += 8; sp += 8;
2563 pixel_put(pbuf,0, pal_8[sp[0] ? sc8spr[sp[0]] : T[0]]);
2564 pixel_put(pbuf,1, pal_8[sp[1] ? sc8spr[sp[1]] : T[1]]);
2565 pixel_put(pbuf,2, pal_8[sp[2] ? sc8spr[sp[2]] : T[2]]);
2566 pixel_put(pbuf,3, pal_8[sp[3] ? sc8spr[sp[3]] : T[3]]);
2567 pixel_put(pbuf,4, pal_8[sp[4] ? sc8spr[sp[4]] : T[4]]);
2568 pixel_put(pbuf,5, pal_8[sp[5] ? sc8spr[sp[5]] : T[5]]);
2569 pixel_put(pbuf,6, pal_8[sp[6] ? sc8spr[sp[6]] : T[6]]);
2570 pixel_put(pbuf,7, pal_8[sp[7] ? sc8spr[sp[7]] : T[7]]);
2571 pbuf += md_video_pixbytes(8); T += 8; sp += 8;
2579 v99x8_refresh_stop();
2582 static __inline__ uint32_t v99x8_refresh_MapYJK(int n, int j, int k, int jk)
2584 return md_maprgb15(tbl_yjk_rg[n + j], tbl_yjk_rg[n + k], tbl_yjk_b [n + jk]);
2588 void V99X8::v99x8_refresh_scc(int y, int h)
2594 uint8_t sc8spr[16] =
2596 0x00, 0x02, 0x10, 0x12, 0x80, 0x82, 0x90, 0x92,
2597 0x49, 0x4B, 0x59, 0x5B, 0xC9, 0xCB, 0xD9, 0xDB
2602 v99x8.tbl_pn = v99x8.vram + (((int)v99x8.ctrl[2] & 0x20) << 11);
2606 pbuf = v99x8_refresh_start(0, 256, h);
2607 pp = md_video_pitch() - md_video_pixbytes(256);
2609 T = v99x8.tbl_pn + (((y + v99x8.ctrl[23]) & 0xff) << 8);
2613 sp = v99x8_refresh_sprite2(y);
2614 for (i = 0; i < 64; ++i)
2616 int yjk_k, yjk_j, yjk_jk;
2618 yjk_k = (((T[0] & 7) | ((T[1] & 7) << 3)) + 32) & 0x3f;
2619 yjk_j = (((T[2] & 7) | ((T[3] & 7) << 3)) + 32) & 0x3f;
2621 yjk_jk = (yjk_j << 11) + (yjk_k << 5);
2623 pixel_put(pbuf, 0, sp[0] ? pal_8[sc8spr[sp[0]]] : v99x8_refresh_MapYJK(T[0] >> 3, yjk_j, yjk_k, yjk_jk));
2624 pixel_put(pbuf, 1, sp[1] ? pal_8[sc8spr[sp[1]]] : v99x8_refresh_MapYJK(T[1] >> 3, yjk_j, yjk_k, yjk_jk));
2625 pixel_put(pbuf, 2, sp[2] ? pal_8[sc8spr[sp[2]]] : v99x8_refresh_MapYJK(T[2] >> 3, yjk_j, yjk_k, yjk_jk));
2626 pixel_put(pbuf, 3, sp[3] ? pal_8[sc8spr[sp[3]]] : v99x8_refresh_MapYJK(T[3] >> 3, yjk_j, yjk_k, yjk_jk));
2628 pbuf += md_video_pixbytes(4); T += 4; sp += 4;
2634 v99x8_refresh_stop();
2637 void V99X8::v99x8_refresh_sc2(int y, int h) {;}
2638 void V99X8::v99x8_refresh_sc3(int y, int h) {;}
2639 void V99X8::v99x8_refresh_sca(int y, int h) {;} /* sc10/sc11 */
2640 void V99X8::v99x8_refresh_scx(int y, int h)
2644 uint32_t fg, bg, m[4];
2648 v99x8.tbl_pg = v99x8.vram + (((int)v99x8.ctrl[4] & 0x3f) << 11);
2649 v99x8.tbl_pn = v99x8.vram + (((int)v99x8.ctrl[2] & 0x7c) << 10);
2650 v99x8.tbl_cl = v99x8.vram + (((int)v99x8.ctrl[10] & 0x07) << 14)
2651 + (((int)v99x8.ctrl[3] & 0xf8) << 6);
2655 pbuf = v99x8_refresh_start(8, 240, h);
2656 pp = md_video_pitch() - md_video_pixbytes(240);
2658 fg = pal[v99x8.col_fg].color;
2659 bg = pal[v99x8.col_bg].color;
2660 m[0] = pal_m[(v99x8.col_bg << 4) | v99x8.col_bg];
2661 m[1] = pal_m[(v99x8.col_bg << 4) | v99x8.col_fg];
2662 m[2] = pal_m[(v99x8.col_fg << 4) | v99x8.col_bg];
2663 m[3] = pal_m[(v99x8.col_fg << 4) | v99x8.col_fg];
2670 T = v99x8.tbl_pn + (y >> 3) * 80;
2671 G = v99x8.tbl_pg + (y & 0x07);
2674 for (i = 0; i < 80; ++i)
2678 a = G[(int)*T++ << 3];
2681 pixel_put(pbuf, 0, (a & 0x80) ? fg : bg);
2682 pixel_put(pbuf, 1, (a & 0x40) ? fg : bg);
2683 pixel_put(pbuf, 2, (a & 0x20) ? fg : bg);
2684 pixel_put(pbuf, 3, (a & 0x10) ? fg : bg);
2685 pixel_put(pbuf, 4, (a & 0x08) ? fg : bg);
2686 pixel_put(pbuf, 5, (a & 0x04) ? fg : bg);
2687 pbuf += md_video_pixbytes(6);
2690 pixel_put(pbuf, 0, m[a >> 6]);
2691 pixel_put(pbuf, 1, m[(a >> 4)& 0x03]);
2692 pixel_put(pbuf, 2, m[(a >> 2)& 0x03]);
2694 pbuf += md_video_pixbytes(3);
2700 v99x8_refresh_stop();
2708 Skelton for retropc emulator
2717 void V99X8::initialize()
2719 DEVICE::initialize();
2720 _SCREEN_WIDTH = osd->get_feature_int_value(_T("SCREEN_WIDTH"));
2721 _SCREEN_HEIGHT = osd->get_feature_int_value(_T("SCREEN_HEIGHT"));
2722 //_use_cmdtime = osd->check_feature(_T("USE_CMDTIME"));
2724 screen = (scrntype_t *)malloc(_SCREEN_WIDTH * _SCREEN_HEIGHT * sizeof(scrntype_t));
2726 register_vline_event(this);
2728 v99x8.vram = this->vram;
2729 v99x8.f_zoom = TRUE;
2733 void V99X8::release()
2735 if(screen != NULL) free(screen);
2750 void V99X8::write_io8(uint32_t addr, uint32_t data)
2769 uint32_t V99X8::read_io8(uint32_t addr)
2774 data = v99x8_in_0();
2777 data = v99x8_in_1();
2783 void V99X8::draw_screen()
2785 if(emu->now_waiting_in_debugger) {
2787 v99x8_t tmp_v99x8 = v99x8;
2788 bool tmp_intstat = intstat;
2791 for(int v = /*get_cur_vline() + 1*/0; v < get_lines_per_frame(); v++) {
2797 intstat = tmp_intstat;
2799 md_video_update(0, NULL);
2802 void V99X8::event_vline(int v, int clock)
2810 void V99X8::set_intstat(bool val)
2812 if(val != intstat) {
2813 if(!emu->now_waiting_in_debugger) {
2814 write_signals(&outputs_irq, val ? 0xffffffff : 0);
2820 void V99X8::z80_intreq(int a)
2822 set_intstat(a != Z80_NOINT);
2825 int V99X8::md_video_pitch(void)
2827 return _SCREEN_WIDTH*4;
2830 uint8_t *V99X8::md_video_lockline(int x, int y, int w, int h)
2832 return (uint8_t*)(screen+y*_SCREEN_WIDTH+x);
2834 if (SDL_MUSTLOCK(video.screen))
2835 SDL_LockSurface(video.screen); /*
\96ß
\82è
\92l
\83`
\83F
\83b
\83N
\81H */
2837 return (Uint8_t *)video.screen->pixels
2838 + video.screen->format->BytesPerPixel * (video.w + x)
2839 + video.screen->pitch * (y + video.h);
2843 void V99X8::md_video_update(int n, /*md_video_rect_t*/void *rp)
2848 int h = _SCREEN_HEIGHT;
2850 if((dst = emu->get_screen_buffer(y)) != NULL) {
2851 memcpy(dst, screen+y*_SCREEN_WIDTH, _SCREEN_WIDTH*4);
2853 if((dst = emu->get_screen_buffer(y + 1)) != NULL) {
2854 memcpy(dst, screen+y*_SCREEN_WIDTH, _SCREEN_WIDTH*4);
2864 void V99X8::md_video_fill(int x, int y, int w, int h, uint32_t c)
2868 scrntype_t *p = screen+y*_SCREEN_WIDTH+x;
2869 for(w2=w;w2>0; w2--) {
2876 static void lmcm(void)
2882 static void stop(void)
2886 v99x8.status[2] &= ~0x01;
2891 static void vcom_lfill_(int dx, int dy, int nx, int clr)
2893 if (v99x8.ctrl[45] & 0x04) { /* Direction to left */
2894 // Todo?: if (dx-nx<MIN_OF_X) xxx;
2895 for (;nx>0;nx--,dx--) vcom_lpset(dx, dy, clr);
2898 // Todo?: if (dx+nx>MAX_OF_X) xxx;
2899 for (;nx>0;nx--,dx++) vcom_lpset(dx, dy, clr);
2903 static void lmmv_(void)
2913 clr = v99x8.ctrl[44];
2915 if ((v99x8.ctrl[45] & 0x08) == 0) { /* Direction to down */
2916 int ny = vcom.ny, dy = vcom.dy;
2917 // Todo?: if (dy+ny>MAX_OF_Y) xxx;
2918 for (;ny>0;ny--,dy++) vcom_lfill_(vcom.dx, dy, vcom.nx, clr);
2919 vcom_setdy(vcom.dy + vcom.ny);
2922 int ny = vcom.ny, dy = vcom.dy;
2923 // Todo?: if (dy-ny<MIN_OF_Y) xxx;
2924 for (;ny>0;ny--,dy--) vcom_lfill_(vcom.dx, dy, vcom.nx, clr);
2925 vcom_setdy(vcom.dy - vcom.ny);
2928 //vcom_setdy(vcom.dy + n);
2930 //if (vcom.ny != abs(n))
2931 // vcom_setny(vcom.ny - abs(n));
2936 static void vcom_lcopy_(int sx, int sy, int dx, int dy, int nx)
2938 if (v99x8.ctrl[45] & 0x04) { /* Direction to left */
2939 // Todo?: if (dx-nx<MIN_OF_X) xxx;
2940 // Todo?: if (sx-nx<MIN_OF_X) xxx;
2941 for (;nx>0;nx--,dx--, sx--) vcom_lpset(dx, dy, vcom_point(sx, sy));
2944 // Todo?: if (dx+nx>MAX_OF_X) xxx;
2945 // Todo?: if (sx+nx>MAX_OF_X) xxx;
2946 if (dx+nx>vcom.xmask+1) {
2949 if (sx+nx>vcom.xmask+1) {
2952 for (;nx>0;nx--,dx++, sx++) vcom_lpset(dx, dy, vcom_point(sx, sy));
2957 static void lmmm_(void)
2966 if ((v99x8.ctrl[45] & 0x08) == 0) { /* Direction to down */
2967 int ny = vcom.ny, dy = vcom.dy, sy = vcom.sy;
2968 // Todo?: if (dy+ny>MAX_OF_Y) xxx;
2969 // Todo?: if (sy+ny>MAX_OF_Y) xxx;
2970 for (;ny>0;ny--,dy++,sy++) vcom_lcopy_(vcom.sx, sy, vcom.dx, dy, vcom.nx);
2971 vcom_setsy(vcom.sy + vcom.ny);
2972 vcom_setdy(vcom.dy + vcom.ny);
2975 int ny = vcom.ny, dy = vcom.dy, sy = vcom.sy;
2976 // Todo?: if (dy-ny<MIN_OF_Y) xxx;
2977 // Todo?: if (sy-ny<MIN_OF_Y) xxx;
2978 for (;ny>0;ny--,dy--,sy--) vcom_lcopy_(vcom.sx, sy, vcom.dx, dy, vcom.nx);
2979 vcom_setsy(vcom.sy - vcom.ny);
2980 vcom_setdy(vcom.dy - vcom.ny);
2983 //vcom_setsy(vcom.sy + n);
2984 //vcom_setdy(vcom.dy + n);
2986 //if (vcom.ny != abs(n))
2987 // vcom_setny(vcom.ny - abs(n));
2992 void cmdtime_set(int m)
2998 /* provisional data */
3000 if ((v99x8.ctrl[8] & 0x02) == 0) && ((v99x8.ctrl[1] & 0x40) != 0)
3001 YMMM 4.83 microseconds/byte
3002 HMMM 5.85 microseconds/byte
3003 HMMV 3.05 microseconds/byte
3004 LMMM 6.87 microseconds/dot
3005 LMMV 5.91 microseconds/dot
3009 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;
3010 case 0xd: /* hmmm */ vcom_getnx();vcom_getny();cmdtime_t=585*vcom.nx*vcom.ny/pixmask.npix; break;
3011 case 0xc: /* hmmv */ vcom_getnx();vcom_getny();cmdtime_t=305*vcom.nx*vcom.ny/pixmask.npix; break;
3012 case 0x9: /* lmmm */ vcom_getnx();vcom_getny();cmdtime_t=687*vcom.nx*vcom.ny; break;
3013 case 0x8: /* lmmv */ vcom_getnx();vcom_getny();cmdtime_t=591*vcom.nx*vcom.ny; break;
3015 //cmdtime_t = cmdtime_t*60*262/1000000/100;
3016 cmdtime_t = cmdtime_t/6361;
3017 if (cmdtime_t<0) cmdtime_t=0;
3021 void cmdtime_chk(void)
3026 if (0 == cmdtime_t) v99x8.status[2] &= ~0x01;
3032 #define STATE_VERSION 1
3034 bool V99X8::process_state(FILEIO* state_fio, bool loading)
3036 if(!state_fio->StateCheckUint32(STATE_VERSION)) {
3039 if(!state_fio->StateCheckInt32(this_device_id)) {
3043 state_fio->StateValue(cmdtime_t);
3044 state_fio->StateValue(cmdtime_m);
3046 state_fio->StateValue(latch1);
3047 state_fio->StateValue(latch2);
3048 state_fio->StateValue(vram_addr);
3049 state_fio->StateValue(vram_page);
3050 state_fio->StateValue(f_out3);
3051 state_fio->StateValue(f_mode);
3052 state_fio->StateValue(flag_frame);
3053 //state_fio->StateArray(&vcom, sizeof(vcom), 1); // vcom contains uint8_t*.Pointer of 64bit is sizeof(uint64_t).
3055 state_fio->StateValue(vcom.xbytes);
3056 state_fio->StateValue(vcom.xmask);
3057 state_fio->StateValue(vcom.ymask);
3058 state_fio->StateValue(vcom.xshift);
3059 state_fio->StateValue(vcom.yshift);
3061 state_fio->StateValue(vcom.sx);
3062 state_fio->StateValue(vcom.sy);
3063 state_fio->StateValue(vcom.dx);
3064 state_fio->StateValue(vcom.dy);
3065 state_fio->StateValue(vcom.nx);
3066 state_fio->StateValue(vcom.ny);
3069 uintptr_t p = (uintptr_t)vram;
3070 vcom.src = (uint8_t*)(p + state_fio->FgetInt32_LE());
3071 vcom.dst = (uint8_t*)(p + state_fio->FgetInt32_LE());
3073 uintptr_t _v, _s, _d;
3074 _v = (uintptr_t)vram;
3075 _s = (uintptr_t)(vcom.src);
3076 _d = (uintptr_t)(vcom.dst);
3077 state_fio->FputInt32_LE((int)(_s - _v));
3078 state_fio->FputInt32_LE((int)(_d - _v));
3081 state_fio->StateArray(&r44, sizeof(r44), 1); // All of this are Int32
3082 state_fio->StateArray(&pixmask, sizeof(pixmask), 1); // All of this are Int32
3083 state_fio->StateArray(&v99x8_refresh, sizeof(v99x8_refresh), 1);// All of this are Int32
3084 //state_fio->StateArray(pal, sizeof(pal), 1);
3085 for(int i = 0; i < array_length(pal); i++) {
3086 state_fio->StateValue(pai[i].flag);
3087 state_fio->StateValue(pai[i].r);
3088 state_fio->StateValue(pai[i].g);
3089 state_fio->StateValue(pai[i].b);
3090 state_fio->StateValue(pai[i].color);
3093 state_fio->StateArray(pal_8, sizeof(pal_8), 1);
3094 state_fio->StateArray(pal_m, sizeof(pal_m), 1);
3095 state_fio->StateValue(col_bg);
3096 state_fio->StateArray(tbl_yjk_b, sizeof(tbl_yjk_b), 1);
3097 state_fio->StateArray(tbl_yjk_rg, sizeof(tbl_yjk_rg), 1);
3098 state_fio->StateArray(blackbuf, sizeof(blackbuf), 1);
3099 state_fio->StateArray(sbuf, sizeof(sbuf), 1);
3100 state_fio->StateArray(vram, sizeof(vram), 1);
3101 state_fio->StateValue(intstat);
3102 // Q: Do not save "v99x8_t v99x8"? 20181014 K.O