Removed palettised blitting code.

This commit is contained in:
SarahW 2017-05-28 17:45:42 +01:00
commit 3c514a445f
18 changed files with 572 additions and 1079 deletions

View file

@ -15,7 +15,6 @@ extern "C" void video_blit_complete();
void d3d_init_objects();
void d3d_close_objects();
void d3d_blit_memtoscreen(int x, int y, int y1, int y2, int w, int h);
void d3d_blit_memtoscreen_8(int x, int y, int w, int h);
static LPDIRECT3D9 d3d = NULL;
static LPDIRECT3DDEVICE9 d3ddev = NULL;
@ -32,31 +31,6 @@ struct CUSTOMVERTEX
FLOAT tu, tv;
};
static PALETTE cgapal=
{
{0,0,0},{0,42,0},{42,0,0},{42,21,0},
{0,0,0},{0,42,42},{42,0,42},{42,42,42},
{0,0,0},{21,63,21},{63,21,21},{63,63,21},
{0,0,0},{21,63,63},{63,21,63},{63,63,63},
{0,0,0},{0,0,42},{0,42,0},{0,42,42},
{42,0,0},{42,0,42},{42,21,00},{42,42,42},
{21,21,21},{21,21,63},{21,63,21},{21,63,63},
{63,21,21},{63,21,63},{63,63,21},{63,63,63},
{0,0,0},{0,21,0},{0,0,42},{0,42,42},
{42,0,21},{21,10,21},{42,0,42},{42,0,63},
{21,21,21},{21,63,21},{42,21,42},{21,63,63},
{63,0,0},{42,42,0},{63,21,42},{41,41,41},
{0,0,0},{0,42,42},{42,0,0},{42,42,42},
{0,0,0},{0,42,42},{42,0,0},{42,42,42},
{0,0,0},{0,63,63},{63,0,0},{63,63,63},
{0,0,0},{0,63,63},{63,0,0},{63,63,63},
};
static uint32_t pal_lookup[256];
static CUSTOMVERTEX d3d_verts[] =
{
{ 0.0f, 0.0f, 1.0f, 1.0f, 0xffffff, 0.0f, 0.0f},
@ -78,11 +52,6 @@ static CUSTOMVERTEX d3d_verts[] =
void d3d_init(HWND h)
{
int c;
for (c = 0; c < 256; c++)
pal_lookup[c] = makecol(cgapal[c].r << 2, cgapal[c].g << 2, cgapal[c].b << 2);
d3d_hwnd = h;
d3d = Direct3DCreate9(D3D_SDK_VERSION);
@ -108,7 +77,6 @@ void d3d_init(HWND h)
d3d_init_objects();
video_blit_memtoscreen_func = d3d_blit_memtoscreen;
video_blit_memtoscreen_8_func = d3d_blit_memtoscreen_8;
}
void d3d_close_objects()
@ -239,7 +207,7 @@ void d3d_blit_memtoscreen(int x, int y, int y1, int y2, int w, int h)
RECT r;
int yy;
if (y1 == y2)
if (y1 == y2 || h <= 0)
{
video_blit_complete();
return; /*Nothing to do*/
@ -256,7 +224,10 @@ void d3d_blit_memtoscreen(int x, int y, int y1, int y2, int w, int h)
fatal("LockRect failed\n");
for (yy = y1; yy < y2; yy++)
memcpy((void *)((uintptr_t)dr.pBits + ((yy - y1) * dr.Pitch)), &(((uint32_t *)buffer32->line[yy + y])[x]), w * 4);
{
if ((y + yy) >= 0 && (y + yy) < buffer32->h)
memcpy((void *)((uintptr_t)dr.pBits + ((yy - y1) * dr.Pitch)), &(((uint32_t *)buffer32->line[yy + y])[x]), w * 4);
}
video_blit_complete();
d3dTexture->UnlockRect(0);
@ -326,106 +297,3 @@ void d3d_blit_memtoscreen(int x, int y, int y1, int y2, int w, int h)
if (hr == D3DERR_DEVICELOST || hr == D3DERR_INVALIDCALL)
PostMessage(d3d_hwnd, WM_RESETD3D, 0, 0);
}
void d3d_blit_memtoscreen_8(int x, int y, int w, int h)
{
VOID* pVoid;
D3DLOCKED_RECT dr;
RECT r;
int yy, xx;
HRESULT hr = D3D_OK;
if (h == 0)
{
video_blit_complete();
return; /*Nothing to do*/
}
r.top = 0;
r.left = 0;
r.bottom = h;
r.right = 2047;
if (hr == D3D_OK)
{
if (FAILED(d3dTexture->LockRect(0, &dr, &r, 0)))
fatal("LockRect failed\n");
for (yy = 0; yy < h; yy++)
{
uint32_t *p = (uint32_t *)((uintptr_t)dr.pBits + (yy * dr.Pitch));
if ((y + yy) >= 0 && (y + yy) < buffer->h)
{
for (xx = 0; xx < w; xx++)
p[xx] = pal_lookup[buffer->line[y + yy][x + xx]];
}
}
video_blit_complete();
d3dTexture->UnlockRect(0);
}
else
video_blit_complete();
d3d_verts[0].tu = d3d_verts[2].tu = d3d_verts[3].tu = 0;//0.5 / 2048.0;
d3d_verts[0].tv = d3d_verts[3].tv = d3d_verts[4].tv = 0;//0.5 / 2048.0;
d3d_verts[1].tu = d3d_verts[4].tu = d3d_verts[5].tu = (float)w / 2048.0;
d3d_verts[1].tv = d3d_verts[2].tv = d3d_verts[5].tv = (float)h / 2048.0;
d3d_verts[0].color = d3d_verts[1].color = d3d_verts[2].color =
d3d_verts[3].color = d3d_verts[4].color = d3d_verts[5].color =
d3d_verts[6].color = d3d_verts[7].color = d3d_verts[8].color =
d3d_verts[9].color = d3d_verts[10].color = d3d_verts[11].color = 0xffffff;
GetClientRect(d3d_hwnd, &r);
d3d_verts[0].x = d3d_verts[2].x = d3d_verts[3].x = -0.5;
d3d_verts[0].y = d3d_verts[3].y = d3d_verts[4].y = -0.5;
d3d_verts[1].x = d3d_verts[4].x = d3d_verts[5].x = (r.right - r.left) - 0.5;
d3d_verts[1].y = d3d_verts[2].y = d3d_verts[5].y = (r.bottom - r.top) - 0.5;
d3d_verts[6].x = d3d_verts[8].x = d3d_verts[9].x = (r.right - r.left) - 40.5;
d3d_verts[6].y = d3d_verts[9].y = d3d_verts[10].y = 8.5;
d3d_verts[7].x = d3d_verts[10].x = d3d_verts[11].x = (r.right - r.left) - 8.5;
d3d_verts[7].y = d3d_verts[8].y = d3d_verts[11].y = 14.5;
if (hr == D3D_OK)
hr = v_buffer->Lock(0, 0, (void**)&pVoid, 0); // lock the vertex buffer
if (hr == D3D_OK)
memcpy(pVoid, d3d_verts, sizeof(d3d_verts)); // copy the vertices to the locked buffer
if (hr == D3D_OK)
hr = v_buffer->Unlock(); // unlock the vertex buffer
if (hr == D3D_OK)
hr = d3ddev->BeginScene();
if (hr == D3D_OK)
{
if (hr == D3D_OK)
hr = d3ddev->SetTexture(0, d3dTexture);
if (hr == D3D_OK)
hr = d3ddev->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1);
if (hr == D3D_OK)
hr = d3ddev->SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEX));
if (hr == D3D_OK)
hr = d3ddev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2);
if (hr == D3D_OK)
hr = d3ddev->SetTexture(0, NULL);
if (hr == D3D_OK && readflash && vid_disc_indicator)
{
hr = d3ddev->DrawPrimitive(D3DPT_TRIANGLELIST, 6, 2);
readflash = 0;
}
if (hr == D3D_OK)
hr = d3ddev->EndScene();
}
if (hr == D3D_OK)
hr = d3ddev->Present(NULL, NULL, d3d_hwnd, NULL);
if (hr == D3DERR_DEVICELOST || hr == D3DERR_INVALIDCALL)
PostMessage(d3d_hwnd, WM_RESETD3D, 0, 0);
}