minor game_def.cfg update
[picodrive.git] / platform / win32 / GenaDrive / TexScreen.cpp
CommitLineData
cc68a136 1\r
2#include "app.h"\r
3\r
4IDirect3DTexture8 *TexScreen=NULL;\r
5int TexWidth=0,TexHeight=0;\r
6\r
7// Blank the texture:\r
8static int TexBlank()\r
9{\r
10 D3DLOCKED_RECT lock={0,NULL};\r
11 unsigned char *dest=NULL;\r
12 int y=0,line=0;\r
13\r
14 TexScreen->LockRect(0,&lock,NULL,0); if (lock.pBits==NULL) return 1;\r
15\r
16 dest=(unsigned char *)lock.pBits;\r
17 for (y=0; y<TexHeight; y++,line+=lock.Pitch)\r
18 {\r
19 memset(dest+line,0,TexWidth<<1);\r
20 }\r
21\r
22 TexScreen->UnlockRect(0);\r
23 return 0;\r
24}\r
25\r
26int TexScreenInit()\r
27{\r
28 TexWidth =512;\r
29 TexHeight=512;\r
30\r
31 Device->CreateTexture(TexWidth,TexHeight,1,0,D3DFMT_R5G6B5,D3DPOOL_MANAGED,&TexScreen);\r
32 if (TexScreen==NULL) return 1;\r
33\r
34 TexBlank();\r
35 return 0;\r
36}\r
37\r
38void TexScreenExit()\r
39{\r
40 RELEASE(TexScreen)\r
41 TexWidth=TexHeight=0;\r
42}\r
43\r
44// Copy screen to a swizzled texture\r
45int TexScreenSwizzle()\r
46{\r
47 D3DLOCKED_RECT lock={0,NULL};\r
48 unsigned char *dest=NULL;\r
49 int y=0,sy=0,mask=0;\r
50 unsigned short *ps=NULL;\r
51\r
52 mask=TexWidth*TexHeight-1;\r
53\r
54 TexScreen->LockRect(0,&lock,NULL,0); if (lock.pBits==NULL) return 1;\r
55\r
56 dest=(unsigned char *)lock.pBits;\r
57 ps=EmuScreen;\r
58\r
59 // Write to swizzled locations:\r
60 for (y=0,sy=0; y<EmuHeight; y++,sy++)\r
61 {\r
62 int x=0,sx=0;\r
63 sy|=0x55555555;\r
64\r
65 for (x=0,sx=0; x<EmuWidth; x++,sx++)\r
66 {\r
67 int addr=0;\r
68\r
69 sx|=0xaaaaaaaa;\r
70 addr=sx&sy&mask; // Calculate swizzled address\r
71\r
72 ((unsigned short *)dest)[addr]=*ps++;\r
73 }\r
74 }\r
75\r
76 TexScreen->UnlockRect(0);\r
77\r
78 return 0;\r
79}\r
80\r
81// Copy screen to a linear texture:\r
82int TexScreenLinear()\r
83{\r
84 D3DLOCKED_RECT lock={0,NULL};\r
85 unsigned char *dest=NULL;\r
86 int y=0,line=0;\r
87 unsigned short *ps=NULL;\r
88\r
8831ef19 89 TexScreen->LockRect(0,&lock,NULL,0);\r
90 if (lock.pBits==NULL) return 1;\r
cc68a136 91\r
92 dest=(unsigned char *)lock.pBits;\r
93 ps=EmuScreen;\r
94\r
95 for (y=0; y<EmuHeight; y++,line+=lock.Pitch)\r
96 {\r
97 int x=0;\r
98 int addr=line;\r
99\r
100 for (x=0; x<EmuWidth; x++,addr+=2)\r
101 {\r
7c9e6899 102 *(unsigned int *)(dest+addr)=*ps++;\r
cc68a136 103 }\r
104 }\r
105\r
106 TexScreen->UnlockRect(0);\r
107 return 0;\r
108}\r