亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? render.c

?? DC的SEGA_GG模擬器源代碼
?? C
字號:

#include "shared.h"

/* Background drawing function */
void (*render_bg)(int line);

/* Pointer to output buffer */
byte *linebuf;

/* Internal buffer for drawing non 8-bit displays */
byte internal_buffer[0x100];

/* Precalculated pixel table */
word pixel[PALETTE_SIZE];

/* Pattern cache */
byte cache[0x20000];

/* Dirty pattern info */
byte vram_dirty[0x200];
byte is_vram_dirty;

/* Pixel look-up table */
byte lut[0x10000];

/* Attribute expansion table */
dword atex[4] =
{
    0x00000000,
    0x10101010,
    0x20202020,
    0x30303030,
};

/* Display sizes */
int vp_vstart;
int vp_vend;
int vp_hstart;
int vp_hend;


/* Macros to access memory 32-bits at a time (from MAME's drawgfx.c) */

#ifdef ALIGN_DWORD

static __inline__ dword read_dword(void *address)
{
    if ((dword)address & 3)
	{
#ifdef LSB_FIRST  /* little endian version */
        return ( *((byte *)address) +
                (*((byte *)address+1) << 8)  +
                (*((byte *)address+2) << 16) +
                (*((byte *)address+3) << 24) );
#else             /* big endian version */
        return ( *((byte *)address+3) +
                (*((byte *)address+2) << 8)  +
                (*((byte *)address+1) << 16) +
                (*((byte *)address)   << 24) );
#endif
	}
	else
        return *(dword *)address;
}


static __inline__ void write_dword(void *address, dword data)
{
    if ((dword)address & 3)
	{
#ifdef LSB_FIRST
            *((byte *)address) =    data;
            *((byte *)address+1) = (data >> 8);
            *((byte *)address+2) = (data >> 16);
            *((byte *)address+3) = (data >> 24);
#else
            *((byte *)address+3) =  data;
            *((byte *)address+2) = (data >> 8);
            *((byte *)address+1) = (data >> 16);
            *((byte *)address)   = (data >> 24);
#endif
		return;
  	}
  	else
        *(dword *)address = data;
}
#else
#define read_dword(address) *(dword *)address
#define write_dword(address,data) *(dword *)address=data
#endif


/****************************************************************************/


/* Initialize the rendering data */
void render_init(void)
{
    int bx, sx, b, s, bp, bf, sf, c;

    /* Generate 64k of data for the look up table */
    for(bx = 0; bx < 0x100; bx += 1)
    {
        for(sx = 0; sx < 0x100; sx += 1)
        {
            /* Background pixel */
            b  = (bx & 0x0F);

            /* Background priority */
            bp = (bx & 0x20) ? 1 : 0;

            /* Full background pixel + priority + sprite marker */
            bf = (bx & 0x7F);

            /* Sprite pixel */
            s  = (sx & 0x0F);

            /* Full sprite pixel, w/ palette and marker bits added */
            sf = (sx & 0x0F) | 0x10 | 0x40;

            /* Overwriting a sprite pixel ? */
            if(bx & 0x40)
            {
                /* Return the input */
                c = bf;
            }
            else
            {
                /* Work out priority and transparency for both pixels */
                c = bp ? b ? bf : s ? sf : bf : s ? sf : bf;
            }

            /* Store result */
            lut[(bx << 8) | (sx)] = c;
        }
    }

    render_reset();
}


/* Reset the rendering data */
void render_reset(void)
{
    int i;

    /* Clear display bitmap */
    memset(bitmap.data, 0, bitmap.pitch * bitmap.height);

    /* Clear palette */
    for(i = 0; i < PALETTE_SIZE; i += 1)
    {
        palette_sync(i);
    }

    /* Invalidate pattern cache */
    is_vram_dirty = 1;
    memset(vram_dirty, 1, 0x200);
    memset(cache, 0, sizeof(cache));

    /* Set up viewport size */
    if(IS_GG)
    {
        vp_vstart = 24;
        vp_vend   = 168;
        vp_hstart = 6;
        vp_hend   = 26;
    }
    else
    {
        vp_vstart = 0;
        vp_vend   = 192;
        vp_hstart = 0;
        vp_hend   = 32;
    }

    /* Pick render routine */
    render_bg = IS_GG ? render_bg_gg : render_bg_sms;
}


/* Draw a line of the display */
void render_line(int line)
{
    /* Ensure we're within the viewport range */
    if((line < vp_vstart) || (line >= vp_vend)) return;

    /* Point to current line in output buffer */
    linebuf = (bitmap.depth == 8) ? &bitmap.data[(line * bitmap.pitch)] : &internal_buffer[0];

    /* Update pattern cache */
    update_cache();

    /* Blank line */
    if( (!(vdp.reg[1] & 0x40)) || (((vdp.reg[2] & 1) == 0) && (IS_SMS)))
    {
        memset(linebuf + (vp_hstart << 3), BACKDROP_COLOR, BMP_WIDTH);
    }
    else
    {
        /* Draw background */
        render_bg(line);

        /* Draw sprites */
        render_obj(line);

        /* Blank leftmost column of display */
        if(vdp.reg[0] & 0x20)
        {
            memset(linebuf, BACKDROP_COLOR, 8);
        }
    }

    if(bitmap.depth != 8) remap_8_to_16(line);
}


/* Draw the Master System background */
void render_bg_sms(int line)
{
    int locked = 0;
    int v_line = (line + vdp.reg[9]) % 224;
    int v_row  = (v_line & 7) << 3;
    int hscroll = ((vdp.reg[0] & 0x40) && (line < 0x10)) ? 0 : (0x100 - vdp.reg[8]);
    int column = vp_hstart;
    word attr;
    word *nt = (word *)&vdp.vram[vdp.ntab + ((v_line >> 3) << 6)];
    int nt_scroll = (hscroll >> 3);
    int shift = (hscroll & 7);
    dword atex_mask;
    dword *cache_ptr;
    dword *linebuf_ptr = (dword *)&linebuf[0 - shift];

    /* Draw first column (clipped) */
    if(shift)
    {
        int x, c, a;

        attr = nt[(column + nt_scroll) & 0x1F];

#ifndef LSB_FIRST
        attr = (((attr & 0xFF) << 8) | ((attr & 0xFF00) >> 8));
#endif
        a = (attr >> 7) & 0x30;

        for(x = shift; x < 8; x += 1)
        {
            c = cache[((attr & 0x7FF) << 6) | (v_row) | (x)];
            linebuf[(0 - shift) + (x)  ] = ((c) | (a));
        }

        column += 1;
    }

    /* Draw a line of the background */
    for(; column < vp_hend; column++)
    {
        /* Stop vertical scrolling for leftmost eight columns */
        if((vdp.reg[0] & 0x80) && (!locked) && (column >= 24))
        {
            locked = 1;
            v_row = (line & 7) << 3;
            nt = (word *)&vdp.vram[((vdp.reg[2] << 10) & 0x3800) + ((line >> 3) << 6)];
        }

        /* Get name table attribute word */
        attr = nt[(column + nt_scroll) & 0x1F];

#ifndef LSB_FIRST
        attr = (((attr & 0xFF) << 8) | ((attr & 0xFF00) >> 8));
#endif
        /* Expand priority and palette bits */
        atex_mask = atex[(attr >> 11) & 3];

        /* Point to a line of pattern data in cache */
        cache_ptr = (dword *)&cache[((attr & 0x7FF) << 6) | (v_row)];
        
        /* Copy the left half, adding the attribute bits in */
        write_dword( &linebuf_ptr[(column << 1)] , read_dword( &cache_ptr[0] ) | (atex_mask));

        /* Copy the right half, adding the attribute bits in */
        write_dword( &linebuf_ptr[(column << 1) | (1)], read_dword( &cache_ptr[1] ) | (atex_mask));
    }

    /* Draw last column (clipped) */
    if(shift)
    {
        int x, c, a;

        char *p = &linebuf[(0 - shift)+(column << 3)];

        attr = nt[(column + nt_scroll) & 0x1F];

#ifndef LSB_FIRST
        attr = (((attr & 0xFF) << 8) | ((attr & 0xFF00) >> 8));
#endif
        a = (attr >> 7) & 0x30;

        for(x = 0; x < shift; x += 1)
        {
            c = cache[((attr & 0x7FF) << 6) | (v_row) | (x)];
            p[x] = ((c) | (a));
        }
    }
}


/* Draw the Game Gear background */
void render_bg_gg(int line)
{
    int v_line = (line + vdp.reg[9]) % 224;
    int v_row  = (v_line & 7) << 3;
    int hscroll = (0x100 - vdp.reg[8]);
    int column;
    word attr;
    word *nt = (word *)&vdp.vram[vdp.ntab + ((v_line >> 3) << 6)];
    int nt_scroll = (hscroll >> 3);
    dword atex_mask;
    dword *cache_ptr;
    dword *linebuf_ptr = (dword *)&linebuf[0 - (hscroll & 7)];

    /* Draw a line of the background */
    for(column = vp_hstart; column <= vp_hend; column++)
    {
        /* Get name table attribute word */
        attr = nt[(column + nt_scroll) & 0x1F];

#ifndef LSB_FIRST
        attr = (((attr & 0xFF) << 8) | ((attr & 0xFF00) >> 8));
#endif
        /* Expand priority and palette bits */
        atex_mask = atex[(attr >> 11) & 3];

        /* Point to a line of pattern data in cache */
        cache_ptr = (dword *)&cache[((attr & 0x7FF) << 6) | (v_row)];

        /* Copy the left half, adding the attribute bits in */
        write_dword( &linebuf_ptr[(column << 1)] , read_dword( &cache_ptr[0] ) | (atex_mask));

        /* Copy the right half, adding the attribute bits in */
        write_dword( &linebuf_ptr[(column << 1) | (1)], read_dword( &cache_ptr[1] ) | (atex_mask));
    }
}


/* Draw sprites */
void render_obj(int line)
{
    int i;

    /* Sprite count for current line (8 max.) */
    int count = 0;

    /* Sprite dimensions */
    int width = 8;
    int height = (vdp.reg[1] & 0x02) ? 16 : 8;

    /* Pointer to sprite attribute table */
    byte *st = (byte *)&vdp.vram[vdp.satb];

    /* Adjust dimensions for double size sprites */
    if(vdp.reg[1] & 0x01)
    {
        width *= 2;
        height *= 2;
    }

    /* Draw sprites in front-to-back order */
    for(i = 0; i < 64; i++)
    {
        /* Sprite Y position */
        int yp = st[i];

        /* End of sprite list marker? */
        if(yp == 208) return;

        /* Actual Y position is +1 */
        yp += 1;

        /* Wrap Y coordinate for sprites > 240 */
        if(yp > 240) yp -= 256;

        /* Check if sprite falls on current line */
        if((line >= yp) && (line < (yp + height)))
        {
            byte *linebuf_ptr;

            /* Width of sprite */
            int start = 0;
            int end = width;

            /* Sprite X position */
            int xp = st[0x80 + (i << 1)];

            /* Pattern name */
            int n = st[0x81 + (i << 1)];

            /* Bump sprite count */
            count += 1;

            /* Too many sprites on this line ? */
            if((vdp.limit) && (count == 9)) return;

            /* X position shift */
            if(vdp.reg[0] & 0x08) xp -= 8;

            /* Add MSB of pattern name */
            if(vdp.reg[6] & 0x04) n |= 0x0100;

            /* Mask LSB for 8x16 sprites */
            if(vdp.reg[1] & 0x02) n &= 0x01FE;

            /* Point to offset in line buffer */
            linebuf_ptr = (byte *)&linebuf[xp];

            /* Clip sprites on left edge */
            if(xp < 0)
            {
                start = (0 - xp);
            }

            /* Clip sprites on right edge */
            if((xp + width) > 256)        
            {
                end = (256 - xp);
            }

            /* Draw double size sprite */
            if(vdp.reg[1] & 0x01)
            {
                int x;
                byte *cache_ptr = (byte *)&cache[(n << 6) | (((line - yp) >> 1) << 3)];

                /* Draw sprite line */
                for(x = start; x < end; x += 1)
                {
                    /* Source pixel from cache */
                    byte sp = cache_ptr[(x >> 1)];
    
                    /* Only draw opaque sprite pixels */
                    if(sp)
                    {
                        /* Background pixel from line buffer */
                        byte bg = linebuf_ptr[x];
    
                        /* Look up result */
                        linebuf_ptr[x] = lut[(bg << 8) | (sp)];
    
                        /* Set sprite collision flag */
                        if(bg & 0x40) vdp.status |= 0x20;
                    }
                }
            }
            else /* Regular size sprite (8x8 / 8x16) */
            {
                int x;
                byte *cache_ptr = (byte *)&cache[(n << 6) | ((line - yp) << 3)];

                /* Draw sprite line */
                for(x = start; x < end; x += 1)
                {
                    /* Source pixel from cache */
                    byte sp = cache_ptr[x];
    
                    /* Only draw opaque sprite pixels */
                    if(sp)
                    {
                        /* Background pixel from line buffer */
                        byte bg = linebuf_ptr[x];
    
                        /* Look up result */
                        linebuf_ptr[x] = lut[(bg << 8) | (sp)];
    
                        /* Set sprite collision flag */
                        if(bg & 0x40) vdp.status |= 0x20;
                    }
                }
            }
        }
    }
}


/* Update pattern cache with modified tiles */
void update_cache(void)
{
    int i, x, y, c;
    int b0, b1, b2, b3;
    int i0, i1, i2, i3;

    if(!is_vram_dirty) return;
    is_vram_dirty = 0;

    for(i = 0; i < 0x200; i += 1)
    {
        if(vram_dirty[i])
        {
            vram_dirty[i] = 0;

            for(y = 0; y < 8; y += 1)
            {
                b0 = vdp.vram[(i << 5) | (y << 2) | (0)];
                b1 = vdp.vram[(i << 5) | (y << 2) | (1)];
                b2 = vdp.vram[(i << 5) | (y << 2) | (2)];
                b3 = vdp.vram[(i << 5) | (y << 2) | (3)];

                for(x = 0; x < 8; x += 1)
                {
                    i0 = (b0 >> (7 - x)) & 1;
                    i1 = (b1 >> (7 - x)) & 1;
                    i2 = (b2 >> (7 - x)) & 1;
                    i3 = (b3 >> (7 - x)) & 1;

                    c = (i3 << 3 | i2 << 2 | i1 << 1 | i0);

                    cache[0x00000 | (i << 6) | ((y  ) << 3) | (x  )] = c;
                    cache[0x08000 | (i << 6) | ((y  ) << 3) | (7-x)] = c;
                    cache[0x10000 | (i << 6) | ((7-y) << 3) | (x  )] = c;
                    cache[0x18000 | (i << 6) | ((7-y) << 3) | (7-x)] = c;
                }
            }
        }
    }
}


/* Update a palette entry */
void palette_sync(int index)
{
    int r, g, b;

    if(IS_GG)
    {
        r = ((vdp.cram[(index << 1) | 0] >> 1) & 7) << 5;
        g = ((vdp.cram[(index << 1) | 0] >> 5) & 7) << 5;
        b = ((vdp.cram[(index << 1) | 1] >> 1) & 7) << 5;
    }
    else
    {
        r = ((vdp.cram[index] >> 0) & 3) << 6;
        g = ((vdp.cram[index] >> 2) & 3) << 6;
        b = ((vdp.cram[index] >> 4) & 3) << 6;
    }

    bitmap.pal.color[index][0] = r;
    bitmap.pal.color[index][1] = g;
    bitmap.pal.color[index][2] = b;

    //pixel[index] = MAKE_PIXEL(r, g, b);

    //bitmap.pal.dirty[index] = bitmap.pal.update = 1;
}


void remap_8_to_16(int line)
{
    int i;
    int length = BMP_WIDTH;
    int ofs = BMP_X_OFFSET;
    word *p = (word *)&bitmap.data[(line * bitmap.pitch) + (ofs << 1)];

    for(i = 0; i < length; i += 1)
    {
        p[i] = pixel[(internal_buffer[(ofs + i)] & PIXEL_MASK)];
    }        
}







?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
性感美女极品91精品| 日本伊人色综合网| 亚洲18女电影在线观看| 国产精品自拍三区| 欧美高清www午色夜在线视频| 中文av一区特黄| 麻豆中文一区二区| 欧美性受极品xxxx喷水| 亚洲国产精品成人综合色在线婷婷| 婷婷综合五月天| 成人黄色综合网站| 精品国产乱码久久久久久牛牛| 亚洲人成在线观看一区二区| 成人免费视频一区| 欧美r级在线观看| 日韩精品1区2区3区| 91在线小视频| 中文一区二区完整视频在线观看| 乱中年女人伦av一区二区| 欧日韩精品视频| 亚洲男人的天堂在线aⅴ视频| 成人做爰69片免费看网站| 精品国产免费久久| 久久精品国产澳门| 91精品国产免费久久综合| 亚洲大尺度视频在线观看| 色综合天天综合网国产成人综合天 | 国产精品无码永久免费888| 日本中文字幕一区二区视频 | 国产一区二区三区视频在线播放| 欧美精品日韩综合在线| 日韩在线一二三区| 欧美日韩精品一二三区| 一区二区不卡在线播放| 91成人在线精品| 亚洲国产日日夜夜| 欧美又粗又大又爽| 亚洲第一av色| 欧美一区二区三区啪啪| 老司机精品视频线观看86| 精品国产a毛片| 国产一区二区导航在线播放| 国产亚洲福利社区一区| 高清视频一区二区| 亚洲人成网站在线| 欧美日韩国产系列| 久久狠狠亚洲综合| 欧美激情一二三区| 91亚洲国产成人精品一区二三| 亚洲一区二区三区中文字幕| 欧美精品黑人性xxxx| 国内偷窥港台综合视频在线播放| 久久久久久亚洲综合影院红桃| 成人黄动漫网站免费app| 一区二区三区四区亚洲| 欧美一区二区在线视频| 国产一区啦啦啦在线观看| 亚洲欧洲精品一区二区三区| 欧美中文字幕一区二区三区亚洲 | 国产91精品一区二区麻豆网站| 国产精品美女久久久久久久久久久| 色婷婷综合久久久| 蜜桃精品视频在线观看| 国产视频一区在线观看| 91成人免费在线| 经典三级视频一区| 亚洲欧洲综合另类在线| 精品国免费一区二区三区| 不卡av电影在线播放| 五月婷婷激情综合| 国产欧美日韩亚州综合| 欧美日韩精品是欧美日韩精品| 国产乱码一区二区三区| 亚洲一区电影777| 久久色中文字幕| 欧美三级三级三级| 成人亚洲精品久久久久软件| 香蕉影视欧美成人| 综合自拍亚洲综合图不卡区| 欧美tk丨vk视频| 在线免费观看日本一区| 国产成人精品免费看| 婷婷中文字幕一区三区| 日韩一区在线播放| 久久久三级国产网站| 欧美日韩激情一区二区三区| www.在线欧美| 国产乱码一区二区三区| 美女网站在线免费欧美精品| 亚洲精品成人天堂一二三| 国产偷国产偷亚洲高清人白洁| 精品视频一区二区三区免费| 99久久婷婷国产精品综合| 久久99精品久久久久| 久久99精品视频| 亚洲午夜国产一区99re久久| 国产精品美女久久久久久久久 | 日精品一区二区| 亚洲欧美偷拍卡通变态| 中日韩av电影| 久久一区二区视频| 欧美大片一区二区| 91麻豆精品国产| 69精品人人人人| 欧美日韩国产美| 欧美日韩mp4| 欧美日韩激情一区| 欧美日韩高清在线播放| 欧美吻胸吃奶大尺度电影 | 欧美精品色综合| 9191成人精品久久| 欧美久久久一区| 91精品黄色片免费大全| 欧美日韩免费观看一区二区三区 | 国产精品香蕉一区二区三区| 黑人精品欧美一区二区蜜桃| 人人狠狠综合久久亚洲| 青青草国产精品亚洲专区无| 亚洲成人先锋电影| 日本不卡在线视频| 国产一区二区影院| 国产在线播放一区二区三区| 国产高清在线精品| 国产成人aaaa| av中文字幕不卡| 欧美在线不卡一区| 欧美久久久久中文字幕| 精品久久免费看| 欧美国产精品一区二区三区| 国产精品不卡一区二区三区| 亚洲免费观看在线视频| 亚洲综合色网站| 全国精品久久少妇| 国产在线精品一区在线观看麻豆| 国产精品影视网| 91麻豆精品一区二区三区| 欧美精品久久一区二区三区| 日韩欧美的一区二区| 久久日韩精品一区二区五区| 中文字幕一区av| 调教+趴+乳夹+国产+精品| 国产专区欧美精品| 一本到不卡免费一区二区| 欧美精品在线视频| 久久嫩草精品久久久精品一| 亚洲精品乱码久久久久| 日本va欧美va瓶| heyzo一本久久综合| 欧美日韩免费一区二区三区视频| 精品久久人人做人人爽| 亚洲精品高清在线观看| 美国十次综合导航| 91美女精品福利| 制服丝袜在线91| 国产精品久久一级| 三级不卡在线观看| 成人av在线一区二区| 日韩午夜三级在线| 亚洲美女在线一区| 国产精品综合在线视频| 在线观看亚洲精品| 国产偷国产偷亚洲高清人白洁| 偷拍自拍另类欧美| 91在线码无精品| 久久久久久久精| 天堂蜜桃91精品| 色婷婷久久久综合中文字幕 | 国产资源精品在线观看| 欧美亚洲图片小说| 国产精品区一区二区三区 | 一区二区三区中文在线| 国产精品一区二区你懂的| 欧美精品vⅰdeose4hd| 国产精品三级视频| 国产黄色精品视频| 日韩欧美一级片| 午夜在线电影亚洲一区| 色欧美乱欧美15图片| 国产精品毛片大码女人| 国产乱子伦一区二区三区国色天香| 欧美日韩国产系列| 日韩精品午夜视频| 色狠狠桃花综合| 亚洲欧洲日韩综合一区二区| 风间由美中文字幕在线看视频国产欧美| 欧美嫩在线观看| 亚洲成人av一区二区| 日本精品一级二级| 综合色中文字幕| 91浏览器入口在线观看| 国产精品无遮挡| 成人国产精品免费观看动漫| 久久久精品综合| 国产一区二区三区蝌蚪| 久久亚洲精华国产精华液 | 久久人人爽人人爽| 久久国内精品视频| 久久亚洲精品小早川怜子| 国产一区二区在线影院| 久久综合久久鬼色中文字|