Subversion Repositories pentevo

Rev

Blame | Last modification | View Log | Download | RSS feed | ?url?

  1. #include "std.h"
  2.  
  3. #include "emul.h"
  4. #include "vars.h"
  5. #include "draw.h"
  6. #include "dxrframe.h"
  7. #include "dxr_4bpp.h"
  8.  
  9. // AlCo 4bpp mode
  10. static const int p4bpp_ofs[] =
  11. {
  12.   0x00000000 - int(PAGE), 0x00004000 - int(PAGE), 0x00002000 - int(PAGE), 0x00006000 - int(PAGE),
  13.   0x00000001 - int(PAGE), 0x00004001 - int(PAGE), 0x00002001 - int(PAGE), 0x00006001 - int(PAGE),
  14.   0x00000002 - int(PAGE), 0x00004002 - int(PAGE), 0x00002002 - int(PAGE), 0x00006002 - int(PAGE),
  15.   0x00000003 - int(PAGE), 0x00004003 - int(PAGE), 0x00002003 - int(PAGE), 0x00006003 - int(PAGE),
  16.   0x00000004 - int(PAGE), 0x00004004 - int(PAGE), 0x00002004 - int(PAGE), 0x00006004 - int(PAGE),
  17.   0x00000005 - int(PAGE), 0x00004005 - int(PAGE), 0x00002005 - int(PAGE), 0x00006005 - int(PAGE),
  18.   0x00000006 - int(PAGE), 0x00004006 - int(PAGE), 0x00002006 - int(PAGE), 0x00006006 - int(PAGE),
  19.   0x00000007 - int(PAGE), 0x00004007 - int(PAGE), 0x00002007 - int(PAGE), 0x00006007 - int(PAGE),
  20.   0x00000008 - int(PAGE), 0x00004008 - int(PAGE), 0x00002008 - int(PAGE), 0x00006008 - int(PAGE),
  21.   0x00000009 - int(PAGE), 0x00004009 - int(PAGE), 0x00002009 - int(PAGE), 0x00006009 - int(PAGE),
  22.   0x0000000A - int(PAGE), 0x0000400A - int(PAGE), 0x0000200A - int(PAGE), 0x0000600A - int(PAGE),
  23.   0x0000000B - int(PAGE), 0x0000400B - int(PAGE), 0x0000200B - int(PAGE), 0x0000600B - int(PAGE),
  24.   0x0000000C - int(PAGE), 0x0000400C - int(PAGE), 0x0000200C - int(PAGE), 0x0000600C - int(PAGE),
  25.   0x0000000D - int(PAGE), 0x0000400D - int(PAGE), 0x0000200D - int(PAGE), 0x0000600D - int(PAGE),
  26.   0x0000000E - int(PAGE), 0x0000400E - int(PAGE), 0x0000200E - int(PAGE), 0x0000600E - int(PAGE),
  27.   0x0000000F - int(PAGE), 0x0000400F - int(PAGE), 0x0000200F - int(PAGE), 0x0000600F - int(PAGE),
  28.   0x00000010 - int(PAGE), 0x00004010 - int(PAGE), 0x00002010 - int(PAGE), 0x00006010 - int(PAGE),
  29.   0x00000011 - int(PAGE), 0x00004011 - int(PAGE), 0x00002011 - int(PAGE), 0x00006011 - int(PAGE),
  30.   0x00000012 - int(PAGE), 0x00004012 - int(PAGE), 0x00002012 - int(PAGE), 0x00006012 - int(PAGE),
  31.   0x00000013 - int(PAGE), 0x00004013 - int(PAGE), 0x00002013 - int(PAGE), 0x00006013 - int(PAGE),
  32.   0x00000014 - int(PAGE), 0x00004014 - int(PAGE), 0x00002014 - int(PAGE), 0x00006014 - int(PAGE),
  33.   0x00000015 - int(PAGE), 0x00004015 - int(PAGE), 0x00002015 - int(PAGE), 0x00006015 - int(PAGE),
  34.   0x00000016 - int(PAGE), 0x00004016 - int(PAGE), 0x00002016 - int(PAGE), 0x00006016 - int(PAGE),
  35.   0x00000017 - int(PAGE), 0x00004017 - int(PAGE), 0x00002017 - int(PAGE), 0x00006017 - int(PAGE),
  36.   0x00000018 - int(PAGE), 0x00004018 - int(PAGE), 0x00002018 - int(PAGE), 0x00006018 - int(PAGE),
  37.   0x00000019 - int(PAGE), 0x00004019 - int(PAGE), 0x00002019 - int(PAGE), 0x00006019 - int(PAGE),
  38.   0x0000001A - int(PAGE), 0x0000401A - int(PAGE), 0x0000201A - int(PAGE), 0x0000601A - int(PAGE),
  39.   0x0000001B - int(PAGE), 0x0000401B - int(PAGE), 0x0000201B - int(PAGE), 0x0000601B - int(PAGE),
  40.   0x0000001C - int(PAGE), 0x0000401C - int(PAGE), 0x0000201C - int(PAGE), 0x0000601C - int(PAGE),
  41.   0x0000001D - int(PAGE), 0x0000401D - int(PAGE), 0x0000201D - int(PAGE), 0x0000601D - int(PAGE),
  42.   0x0000001E - int(PAGE), 0x0000401E - int(PAGE), 0x0000201E - int(PAGE), 0x0000601E - int(PAGE),
  43.   0x0000001F - int(PAGE), 0x0000401F - int(PAGE), 0x0000201F - int(PAGE), 0x0000601F - int(PAGE)
  44. };
  45.  
  46. #define p4bpp8_nf p4bpp8
  47.  
  48. static int buf4bpp_shift = 0;
  49.  
  50. static void line_p4bpp_8(unsigned char *dst, unsigned char *src, unsigned *tab)
  51. {
  52.    u8 *d = (u8 *)dst;
  53.    for (unsigned x = 0, i = 0; x < 256; x += 2, i++)
  54.    {
  55.        unsigned tmp = tab[src[p4bpp_ofs[(i+temp.offset_hscroll) & 0x7f]]];
  56.        d[x]   = u8(tmp);
  57.        d[x+1] = u8(tmp >> 16);
  58.    }
  59. }
  60.  
  61. static void line_p4bpp_8d(unsigned char *dst, unsigned char *src, unsigned *tab)
  62. {
  63.    for (unsigned x = 0; x < 128; x++)
  64.    {
  65.        *(unsigned*)(dst) = tab[src[p4bpp_ofs[(x+temp.offset_hscroll) & 0x7f]]];
  66.        dst+=4;
  67.    }
  68. }
  69.  
  70. static void line_p4bpp_8d_nf(unsigned char *dst, unsigned char *src1, unsigned char *src2, unsigned *tab)
  71. {
  72.    for (unsigned x = 0; x < 128; x++)
  73.    {
  74.        *(unsigned*)(dst) =
  75.         (tab[src1[p4bpp_ofs[(x+temp.offset_hscroll     ) & 0x7f]]] & 0x0F0F0F0F) +
  76.         (tab[src2[p4bpp_ofs[(x+temp.offset_hscroll_prev) & 0x7f]]] & 0xF0F0F0F0);
  77.        dst+=4;
  78.    }
  79. }
  80.  
  81. static void line_p4bpp_16(unsigned char *dst, unsigned char *src, unsigned *tab)
  82. {
  83.    u16 *d = (u16 *)dst;
  84.    for (unsigned x = 0, i = 0; x < 256; x +=2, i++)
  85.    {
  86.        unsigned tmp = 2*src[p4bpp_ofs[(i+temp.offset_hscroll) & 0x7f]];
  87.        d[x]   = u8(tab[0+tmp]);
  88.        d[x+1] = u8(tab[1+tmp]);
  89.    }
  90. }
  91.  
  92. static void line_p4bpp_16d(unsigned char *dst, unsigned char *src, unsigned *tab)
  93. {
  94.    unsigned tmp;
  95.    for (unsigned x = 0; x < 128; x++)
  96.    {
  97.        tmp = 2*src[p4bpp_ofs[(x+temp.offset_hscroll) & 0x7f]];
  98.        *(unsigned*)dst = tab[0+tmp];
  99.        dst+=4;
  100.        *(unsigned*)dst = tab[1+tmp];
  101.        dst+=4;
  102.    }
  103. }
  104.  
  105. static void line_p4bpp_16d_nf(unsigned char *dst, unsigned char *src1, unsigned char *src2, unsigned *tab)
  106. {
  107.    unsigned tmp1;
  108.    unsigned tmp2;
  109.    for (unsigned x = 0; x < 128; x++)
  110.    {
  111.        tmp1 = unsigned(p4bpp_ofs[(x+temp.offset_hscroll     ) & 0x7f]);
  112.        tmp2 = unsigned(p4bpp_ofs[(x+temp.offset_hscroll_prev) & 0x7f]);
  113.        *(unsigned*)dst = tab[0+2*src1[tmp1]] + tab[0+2*src2[tmp2]];
  114.        dst+=4;
  115.        *(unsigned*)dst = tab[1+2*src1[tmp1]] + tab[1+2*src2[tmp2]];
  116.        dst+=4;
  117.    }
  118. }
  119.  
  120. static void line_p4bpp_32(unsigned char *dst, unsigned char *src, unsigned *tab)
  121. {
  122.    u32 *d = (u32 *)dst;
  123.    for (unsigned x = 0, i = 0; x < 256; x += 2, i++)
  124.    {
  125.        unsigned tmp = 2*src[p4bpp_ofs[(i+temp.offset_hscroll) & 0x7f]];
  126.        d[x]   = tab[0+tmp];
  127.        d[x+1] = tab[1+tmp];
  128.    }
  129. }
  130.  
  131. static void line_p4bpp_32d(unsigned char *dst, unsigned char *src, unsigned *tab)
  132. {
  133.    unsigned tmp;
  134.    for (unsigned x = 0; x < 128; x++)
  135.    {
  136.        tmp = 2*src[p4bpp_ofs[(x+temp.offset_hscroll) & 0x7f]];
  137.        *(unsigned*)dst = *(unsigned*)(dst+4) = tab[0+tmp];
  138.        dst+=8;
  139.        *(unsigned*)dst = *(unsigned*)(dst+4) = tab[1+tmp];
  140.        dst+=8;
  141.    }
  142. }
  143.  
  144. static void line_p4bpp_32d_nf(unsigned char *dst, unsigned char *src1, unsigned char *src2, unsigned *tab)
  145. {
  146.    unsigned tmp1;
  147.    unsigned tmp2;
  148.    for (unsigned x = 0; x < 128; x++)
  149.    {
  150.        tmp1 = unsigned(p4bpp_ofs[(x+temp.offset_hscroll     ) & 0x7f]);
  151.        tmp2 = unsigned(p4bpp_ofs[(x+temp.offset_hscroll_prev) & 0x7f]);
  152.        *(unsigned*)dst = *(unsigned*)(dst+4) = tab[0+2*src1[tmp1]] + tab[0+2*src2[tmp2]];
  153.        dst+=8;
  154.        *(unsigned*)dst = *(unsigned*)(dst+4) = tab[1+2*src1[tmp1]] + tab[1+2*src2[tmp2]];
  155.        dst+=8;
  156.    }
  157. }
  158.  
  159. static void r_p4bpp_8(unsigned char *dst, unsigned pitch)
  160. {
  161.     for (unsigned y = 0; y < 192; y++)
  162.     {
  163.        unsigned char *src = temp.base + t.scrtab[(unsigned char)(y+temp.offset_vscroll)];
  164.        line_p4bpp_8(dst, src, t.p4bpp8[0]); dst += pitch;
  165.     }
  166. }
  167.  
  168. static void r_p4bpp_8d1(unsigned char *dst, unsigned pitch)
  169. {
  170.    if (conf.noflic)
  171.    {
  172.       for (unsigned y = 0; y < 192; y++)
  173.       {
  174.          unsigned char *src1 = temp.base                 + t.scrtab[(unsigned char)(y+temp.offset_vscroll)];
  175.          unsigned char *src2 = temp.base + buf4bpp_shift + t.scrtab[(unsigned char)(y+temp.offset_vscroll_prev)];
  176.          line_p4bpp_8d_nf(dst, src1, src2, t.p4bpp8_nf[0]); dst += pitch;
  177.       }
  178.  
  179.    }
  180.    else
  181.    {
  182.       for (unsigned y = 0; y < 192; y++)
  183.       {
  184.          unsigned char *src = temp.base + t.scrtab[(unsigned char)(y+temp.offset_vscroll)];
  185.          line_p4bpp_8d(dst, src, t.p4bpp8[0]); dst += pitch;
  186.       }
  187.    }
  188. }
  189.  
  190. static void r_p4bpp_8d(unsigned char *dst, unsigned pitch)
  191. {
  192.    if (conf.noflic)
  193.    {
  194.  
  195.       for (unsigned y = 0; y < 192; y++)
  196.       {
  197.          unsigned char *src1 = temp.base                 + t.scrtab[(unsigned char)(y+temp.offset_vscroll)];
  198.          unsigned char *src2 = temp.base + buf4bpp_shift + t.scrtab[(unsigned char)(y+temp.offset_vscroll_prev)];
  199.          line_p4bpp_8d_nf(dst, src1, src2, t.p4bpp8_nf[0]); dst += pitch;
  200.          line_p4bpp_8d_nf(dst, src1, src2, t.p4bpp8_nf[1]); dst += pitch;
  201.       }
  202.  
  203.    }
  204.    else
  205.    {
  206.  
  207.       for (unsigned y = 0; y < 192; y++)
  208.       {
  209.          unsigned char *src = temp.base + t.scrtab[(unsigned char)(y+temp.offset_vscroll)];
  210.          line_p4bpp_8d(dst, src, t.p4bpp8[0]); dst += pitch;
  211.          line_p4bpp_8d(dst, src, t.p4bpp8[1]); dst += pitch;
  212.       }
  213.  
  214.    }
  215. }
  216.  
  217. static void r_p4bpp_16(unsigned char *dst, unsigned pitch)
  218. {
  219.     for (unsigned y = 0; y < 192; y++)
  220.     {
  221.        unsigned char *src = temp.base + t.scrtab[(unsigned char)(y+temp.offset_vscroll)];
  222.        line_p4bpp_16(dst, src, t.p4bpp16[0]);
  223.        dst += pitch;
  224.     }
  225. }
  226.  
  227. static void r_p4bpp_16d1(unsigned char *dst, unsigned pitch)
  228. {
  229.    if (conf.noflic)
  230.    {
  231.       for (unsigned y = 0; y < 192; y++)
  232.       {
  233.          unsigned char *src1 = temp.base                 + t.scrtab[(unsigned char)(y+temp.offset_vscroll)];
  234.          unsigned char *src2 = temp.base + buf4bpp_shift + t.scrtab[(unsigned char)(y+temp.offset_vscroll_prev)];
  235.          line_p4bpp_16d_nf(dst, src1, src2, t.p4bpp16_nf[0]); dst += pitch;
  236.       }
  237.  
  238.    }
  239.    else
  240.    {
  241.       for (unsigned y = 0; y < 192; y++)
  242.       {
  243.          unsigned char *src = temp.base + t.scrtab[(unsigned char)(y+temp.offset_vscroll)];
  244.          line_p4bpp_16d(dst, src, t.p4bpp16[0]); dst += pitch;
  245.       }
  246.  
  247.    }
  248. }
  249.  
  250. static void r_p4bpp_16d(unsigned char *dst, unsigned pitch)
  251. {
  252.    if (conf.noflic)
  253.    {
  254.       for (unsigned y = 0; y < 192; y++)
  255.       {
  256.          unsigned char *src1 = temp.base                 + t.scrtab[(unsigned char)(y+temp.offset_vscroll)];
  257.          unsigned char *src2 = temp.base + buf4bpp_shift + t.scrtab[(unsigned char)(y+temp.offset_vscroll_prev)];
  258.          line_p4bpp_16d_nf(dst, src1, src2, t.p4bpp16_nf[0]); dst += pitch;
  259.          line_p4bpp_16d_nf(dst, src1, src2, t.p4bpp16_nf[1]); dst += pitch;
  260.       }
  261.  
  262.    }
  263.    else
  264.    {
  265.       for (unsigned y = 0; y < 192; y++)
  266.       {
  267.          unsigned char *src = temp.base + t.scrtab[(unsigned char)(y+temp.offset_vscroll)];
  268.          line_p4bpp_16d(dst, src, t.p4bpp16[0]); dst += pitch;
  269.          line_p4bpp_16d(dst, src, t.p4bpp16[1]); dst += pitch;
  270.       }
  271.    }
  272. }
  273.  
  274. static void r_p4bpp_32(unsigned char *dst, unsigned pitch)
  275. {
  276.     for (unsigned y = 0; y < 192; y++)
  277.     {
  278.        unsigned char *src = temp.base + t.scrtab[(unsigned char)(y+temp.offset_vscroll)];
  279.        line_p4bpp_32(dst, src, t.p4bpp32[0]);
  280.        dst += pitch;
  281.     }
  282. }
  283.  
  284. static void r_p4bpp_32d1(unsigned char *dst, unsigned pitch)
  285. {
  286.    if (conf.noflic)
  287.    {
  288.       for (unsigned y = 0; y < 192; y++)
  289.       {
  290.          unsigned char *src1 = temp.base                 + t.scrtab[(unsigned char)(y+temp.offset_vscroll)];
  291.          unsigned char *src2 = temp.base + buf4bpp_shift + t.scrtab[(unsigned char)(y+temp.offset_vscroll_prev)];
  292.          line_p4bpp_32d_nf(dst, src1, src2, t.p4bpp32_nf[0]); dst += pitch;
  293.       }
  294.  
  295.    }
  296.    else
  297.    {
  298.       for (unsigned y = 0; y < 192; y++)
  299.       {
  300.          unsigned char *src = temp.base + t.scrtab[(unsigned char)(y+temp.offset_vscroll)];
  301.          line_p4bpp_32d(dst, src, t.p4bpp32[0]); dst += pitch;
  302.       }
  303.    }
  304. }
  305.  
  306. static void r_p4bpp_32d(unsigned char *dst, unsigned pitch)
  307. {
  308.    if (conf.noflic)
  309.    {
  310.       for (unsigned y = 0; y < 192; y++)
  311.       {
  312.          unsigned char *src1 = temp.base                 + t.scrtab[(unsigned char)(y+temp.offset_vscroll)];
  313.          unsigned char *src2 = temp.base + buf4bpp_shift + t.scrtab[(unsigned char)(y+temp.offset_vscroll_prev)];
  314.          line_p4bpp_32d_nf(dst, src1, src2, t.p4bpp32_nf[0]); dst += pitch;
  315.          line_p4bpp_32d_nf(dst, src1, src2, t.p4bpp32_nf[1]); dst += pitch;
  316.       }
  317.    }
  318.    else
  319.    {
  320.       for (unsigned y = 0; y < 192; y++)
  321.       {
  322.          unsigned char *src = temp.base + t.scrtab[(unsigned char)(y+temp.offset_vscroll)];
  323.          line_p4bpp_32d(dst, src, t.p4bpp32[0]); dst += pitch;
  324.          line_p4bpp_32d(dst, src, t.p4bpp32[1]); dst += pitch;
  325.       }
  326.    }
  327. }
  328.  
  329. void rend_p4bpp_small(unsigned char *dst, unsigned pitch)
  330. {
  331.    unsigned char *dst2 = dst + (temp.ox-256)*temp.obpp/16;
  332.    dst2 += temp.b_top * pitch * ((temp.oy > temp.scy)?2:1);
  333.  
  334.    if (temp.oy > temp.scy && conf.fast_sl)
  335.        pitch *= 2;
  336.  
  337.    if (conf.noflic)
  338.        buf4bpp_shift = int((rbuf_s+PAGE) - temp.base);
  339.  
  340.    if (temp.obpp == 8)
  341.    {
  342.        rend_frame8(dst, pitch);
  343.        r_p4bpp_8(dst2, pitch);
  344.    }
  345.    if (temp.obpp == 16)
  346.    {
  347.        rend_frame16(dst, pitch);
  348.        r_p4bpp_16(dst2, pitch);
  349.    }
  350.    if (temp.obpp == 32)
  351.    {
  352.        rend_frame32(dst, pitch);
  353.        r_p4bpp_32(dst2, pitch);
  354.    }
  355.  
  356.    if (conf.noflic)
  357.        memcpy(rbuf_s, temp.base-PAGE, 2*PAGE);
  358.  
  359.    temp.offset_vscroll_prev = temp.offset_vscroll;
  360.    temp.offset_vscroll = 0;
  361.    temp.offset_hscroll_prev = temp.offset_hscroll;
  362.    temp.offset_hscroll = 0;
  363. }
  364.  
  365. void rend_p4bpp(unsigned char *dst, unsigned pitch)
  366. {
  367.    unsigned char *dst2 = dst + (temp.ox-512)*temp.obpp/16;
  368.    dst2 += temp.b_top * pitch * ((temp.oy > temp.scy)?2:1);
  369.  
  370.    if (temp.oy > temp.scy && conf.fast_sl) pitch *= 2;
  371.  
  372.    if (conf.noflic)
  373.        buf4bpp_shift = int((rbuf_s+PAGE) - temp.base);
  374.  
  375.    if (temp.obpp == 8)
  376.    {
  377.        if (conf.fast_sl)
  378.        {
  379.            rend_frame_8d1(dst, pitch);
  380.            r_p4bpp_8d1(dst2, pitch);
  381.        }
  382.        else
  383.        {
  384.            rend_frame_8d(dst, pitch);
  385.            r_p4bpp_8d(dst2, pitch);
  386.        }
  387.    }
  388.    if (temp.obpp == 16)
  389.    {
  390.        if (conf.fast_sl)
  391.        {
  392.            rend_frame_16d1(dst, pitch);
  393.            r_p4bpp_16d1(dst2, pitch);
  394.        }
  395.        else
  396.        {
  397.            rend_frame_16d(dst, pitch);
  398.            r_p4bpp_16d(dst2, pitch);
  399.        }
  400.    }
  401.    if (temp.obpp == 32)
  402.    {
  403.        if (conf.fast_sl)
  404.        {
  405.            rend_frame_32d1(dst, pitch);
  406.            r_p4bpp_32d1(dst2, pitch);
  407.        }
  408.        else
  409.        {
  410.            rend_frame_32d(dst, pitch);
  411.            r_p4bpp_32d(dst2, pitch);
  412.        }
  413.    }
  414.  
  415.    if (conf.noflic)
  416.        memcpy(rbuf_s, temp.base-PAGE, 2*PAGE);
  417.  
  418.    temp.offset_vscroll_prev = temp.offset_vscroll;
  419.    temp.offset_vscroll = 0;
  420.    temp.offset_hscroll_prev = temp.offset_hscroll;
  421.    temp.offset_hscroll = 0;
  422. }
  423.