|
|
1.1 root 1: /*
2: Hatari
3:
4: Screen conversion routines. We have a number of routines to convert ST screen to PC format.
5: We split these into Low,Medium and High each with 8/16-bit versions. To gain extra speed,
6: as almost half of the processing time can be spent in these routines, we check for any
7: changes from the previously displayed frame. AdjustLinePaletteRemap() sets a flag to
8: tell the routines if we need to totally update a line(ie full update, or palette/res change)
9: or if we just can do a difference check. To see how much of the screen updates each frame, simply
10: enable 'TEST_SCREEN_UPDATE'
11: We convert each screen 16 pixels at a time by use of a couple of look-up tables. These tables
12: convert from 2-plane format to bbp and then we can add two of these together to get 4-planes. This
13: keeps the tables small and thus improves speed. We then look these bbp values up as an RGB/Index value
14: to copy to the screen.
15: */
16:
17: #include "main.h"
18: #include "screen.h"
19: #include "screenConvert.h"
20: #include "spec512.h"
21: #include "vdi.h"
22: #include "video.h"
23:
24: //#define TEST_SCREEN_UPDATE /* Enable to see partial screen update */
25:
26: int ScrX,ScrY; /* Locals */
27: int ScrUpdateFlag; /* Bit mask of how to update screen */
28: BOOL bScrDoubleY; /* TRUE if double on Y */
29: unsigned long PixelWorkspace[4]; /* Workspace to store pixels to so can print in right order for Spec512 */
30:
31: /* Remap tables to convert from plane format to byte-per-pixel (Upper is for 4-Planes so if shifted by 2) */
32: unsigned long Remap_2_Planes[256] = {
33: 0x00000000, 0x01000000, 0x00010000, 0x01010000, 0x00000100, 0x01000100, 0x00010100, 0x01010100,
34: 0x00000001, 0x01000001, 0x00010001, 0x01010001, 0x00000101, 0x01000101, 0x00010101, 0x01010101,
35: 0x02000000, 0x03000000, 0x02010000, 0x03010000, 0x02000100, 0x03000100, 0x02010100, 0x03010100,
36: 0x02000001, 0x03000001, 0x02010001, 0x03010001, 0x02000101, 0x03000101, 0x02010101, 0x03010101,
37: 0x00020000, 0x01020000, 0x00030000, 0x01030000, 0x00020100, 0x01020100, 0x00030100, 0x01030100,
38: 0x00020001, 0x01020001, 0x00030001, 0x01030001, 0x00020101, 0x01020101, 0x00030101, 0x01030101,
39: 0x02020000, 0x03020000, 0x02030000, 0x03030000, 0x02020100, 0x03020100, 0x02030100, 0x03030100,
40: 0x02020001, 0x03020001, 0x02030001, 0x03030001, 0x02020101, 0x03020101, 0x02030101, 0x03030101,
41: 0x00000200, 0x01000200, 0x00010200, 0x01010200, 0x00000300, 0x01000300, 0x00010300, 0x01010300,
42: 0x00000201, 0x01000201, 0x00010201, 0x01010201, 0x00000301, 0x01000301, 0x00010301, 0x01010301,
43: 0x02000200, 0x03000200, 0x02010200, 0x03010200, 0x02000300, 0x03000300, 0x02010300, 0x03010300,
44: 0x02000201, 0x03000201, 0x02010201, 0x03010201, 0x02000301, 0x03000301, 0x02010301, 0x03010301,
45: 0x00020200, 0x01020200, 0x00030200, 0x01030200, 0x00020300, 0x01020300, 0x00030300, 0x01030300,
46: 0x00020201, 0x01020201, 0x00030201, 0x01030201, 0x00020301, 0x01020301, 0x00030301, 0x01030301,
47: 0x02020200, 0x03020200, 0x02030200, 0x03030200, 0x02020300, 0x03020300, 0x02030300, 0x03030300,
48: 0x02020201, 0x03020201, 0x02030201, 0x03030201, 0x02020301, 0x03020301, 0x02030301, 0x03030301,
49: 0x00000002, 0x01000002, 0x00010002, 0x01010002, 0x00000102, 0x01000102, 0x00010102, 0x01010102,
50: 0x00000003, 0x01000003, 0x00010003, 0x01010003, 0x00000103, 0x01000103, 0x00010103, 0x01010103,
51: 0x02000002, 0x03000002, 0x02010002, 0x03010002, 0x02000102, 0x03000102, 0x02010102, 0x03010102,
52: 0x02000003, 0x03000003, 0x02010003, 0x03010003, 0x02000103, 0x03000103, 0x02010103, 0x03010103,
53: 0x00020002, 0x01020002, 0x00030002, 0x01030002, 0x00020102, 0x01020102, 0x00030102, 0x01030102,
54: 0x00020003, 0x01020003, 0x00030003, 0x01030003, 0x00020103, 0x01020103, 0x00030103, 0x01030103,
55: 0x02020002, 0x03020002, 0x02030002, 0x03030002, 0x02020102, 0x03020102, 0x02030102, 0x03030102,
56: 0x02020003, 0x03020003, 0x02030003, 0x03030003, 0x02020103, 0x03020103, 0x02030103, 0x03030103,
57: 0x00000202, 0x01000202, 0x00010202, 0x01010202, 0x00000302, 0x01000302, 0x00010302, 0x01010302,
58: 0x00000203, 0x01000203, 0x00010203, 0x01010203, 0x00000303, 0x01000303, 0x00010303, 0x01010303,
59: 0x02000202, 0x03000202, 0x02010202, 0x03010202, 0x02000302, 0x03000302, 0x02010302, 0x03010302,
60: 0x02000203, 0x03000203, 0x02010203, 0x03010203, 0x02000303, 0x03000303, 0x02010303, 0x03010303,
61: 0x00020202, 0x01020202, 0x00030202, 0x01030202, 0x00020302, 0x01020302, 0x00030302, 0x01030302,
62: 0x00020203, 0x01020203, 0x00030203, 0x01030203, 0x00020303, 0x01020303, 0x00030303, 0x01030303,
63: 0x02020202, 0x03020202, 0x02030202, 0x03030202, 0x02020302, 0x03020302, 0x02030302, 0x03030302,
64: 0x02020203, 0x03020203, 0x02030203, 0x03030203, 0x02020303, 0x03020303, 0x02030303, 0x03030303,
65: };
66: unsigned long Remap_2_Planes_Upper[256] = {
67: 0x00000000, 0x04000000, 0x00040000, 0x04040000, 0x00000400, 0x04000400, 0x00040400, 0x04040400,
68: 0x00000004, 0x04000004, 0x00040004, 0x04040004, 0x00000404, 0x04000404, 0x00040404, 0x04040404,
69: 0x08000000, 0x0C000000, 0x08040000, 0x0C040000, 0x08000400, 0x0C000400, 0x08040400, 0x0C040400,
70: 0x08000004, 0x0C000004, 0x08040004, 0x0C040004, 0x08000404, 0x0C000404, 0x08040404, 0x0C040404,
71: 0x00080000, 0x04080000, 0x000C0000, 0x040C0000, 0x00080400, 0x04080400, 0x000C0400, 0x040C0400,
72: 0x00080004, 0x04080004, 0x000C0004, 0x040C0004, 0x00080404, 0x04080404, 0x000C0404, 0x040C0404,
73: 0x08080000, 0x0C080000, 0x080C0000, 0x0C0C0000, 0x08080400, 0x0C080400, 0x080C0400, 0x0C0C0400,
74: 0x08080004, 0x0C080004, 0x080C0004, 0x0C0C0004, 0x08080404, 0x0C080404, 0x080C0404, 0x0C0C0404,
75: 0x00000800, 0x04000800, 0x00040800, 0x04040800, 0x00000C00, 0x04000C00, 0x00040C00, 0x04040C00,
76: 0x00000804, 0x04000804, 0x00040804, 0x04040804, 0x00000C04, 0x04000C04, 0x00040C04, 0x04040C04,
77: 0x08000800, 0x0C000800, 0x08040800, 0x0C040800, 0x08000C00, 0x0C000C00, 0x08040C00, 0x0C040C00,
78: 0x08000804, 0x0C000804, 0x08040804, 0x0C040804, 0x08000C04, 0x0C000C04, 0x08040C04, 0x0C040C04,
79: 0x00080800, 0x04080800, 0x000C0800, 0x040C0800, 0x00080C00, 0x04080C00, 0x000C0C00, 0x040C0C00,
80: 0x00080804, 0x04080804, 0x000C0804, 0x040C0804, 0x00080C04, 0x04080C04, 0x000C0C04, 0x040C0C04,
81: 0x08080800, 0x0C080800, 0x080C0800, 0x0C0C0800, 0x08080C00, 0x0C080C00, 0x080C0C00, 0x0C0C0C00,
82: 0x08080804, 0x0C080804, 0x080C0804, 0x0C0C0804, 0x08080C04, 0x0C080C04, 0x080C0C04, 0x0C0C0C04,
83: 0x00000008, 0x04000008, 0x00040008, 0x04040008, 0x00000408, 0x04000408, 0x00040408, 0x04040408,
84: 0x0000000C, 0x0400000C, 0x0004000C, 0x0404000C, 0x0000040C, 0x0400040C, 0x0004040C, 0x0404040C,
85: 0x08000008, 0x0C000008, 0x08040008, 0x0C040008, 0x08000408, 0x0C000408, 0x08040408, 0x0C040408,
86: 0x0800000C, 0x0C00000C, 0x0804000C, 0x0C04000C, 0x0800040C, 0x0C00040C, 0x0804040C, 0x0C04040C,
87: 0x00080008, 0x04080008, 0x000C0008, 0x040C0008, 0x00080408, 0x04080408, 0x000C0408, 0x040C0408,
88: 0x0008000C, 0x0408000C, 0x000C000C, 0x040C000C, 0x0008040C, 0x0408040C, 0x000C040C, 0x040C040C,
89: 0x08080008, 0x0C080008, 0x080C0008, 0x0C0C0008, 0x08080408, 0x0C080408, 0x080C0408, 0x0C0C0408,
90: 0x0808000C, 0x0C08000C, 0x080C000C, 0x0C0C000C, 0x0808040C, 0x0C08040C, 0x080C040C, 0x0C0C040C,
91: 0x00000808, 0x04000808, 0x00040808, 0x04040808, 0x00000C08, 0x04000C08, 0x00040C08, 0x04040C08,
92: 0x0000080C, 0x0400080C, 0x0004080C, 0x0404080C, 0x00000C0C, 0x04000C0C, 0x00040C0C, 0x04040C0C,
93: 0x08000808, 0x0C000808, 0x08040808, 0x0C040808, 0x08000C08, 0x0C000C08, 0x08040C08, 0x0C040C08,
94: 0x0800080C, 0x0C00080C, 0x0804080C, 0x0C04080C, 0x08000C0C, 0x0C000C0C, 0x08040C0C, 0x0C040C0C,
95: 0x00080808, 0x04080808, 0x000C0808, 0x040C0808, 0x00080C08, 0x04080C08, 0x000C0C08, 0x040C0C08,
96: 0x0008080C, 0x0408080C, 0x000C080C, 0x040C080C, 0x00080C0C, 0x04080C0C, 0x000C0C0C, 0x040C0C0C,
97: 0x08080808, 0x0C080808, 0x080C0808, 0x0C0C0808, 0x08080C08, 0x0C080C08, 0x080C0C08, 0x0C0C0C08,
98: 0x0808080C, 0x0C08080C, 0x080C080C, 0x0C0C080C, 0x08080C0C, 0x0C080C0C, 0x080C0C0C, 0x0C0C0C0C,
99: };
100: unsigned long Remap_1_Plane[16] = {
101: 0x00000000+BASECOLOUR_LONG, 0x01000000+BASECOLOUR_LONG, 0x00010000+BASECOLOUR_LONG, 0x01010000+BASECOLOUR_LONG, 0x00000100+BASECOLOUR_LONG, 0x01000100+BASECOLOUR_LONG, 0x00010100+BASECOLOUR_LONG, 0x01010100+BASECOLOUR_LONG,
102: 0x00000001+BASECOLOUR_LONG, 0x01000001+BASECOLOUR_LONG, 0x00010001+BASECOLOUR_LONG, 0x01010001+BASECOLOUR_LONG, 0x00000101+BASECOLOUR_LONG, 0x01000101+BASECOLOUR_LONG, 0x00010101+BASECOLOUR_LONG, 0x01010101+BASECOLOUR_LONG,
103: };
104:
105: //-----------------------------------------------------------------------
106: /*
107: Update the STRGBPalette[] array with current colours for this raster line.
108: Corrupt any registers, except edx,edi,esi,ebp
109:
110: Return 'ScrUpdateFlag' in 'eax', 0x80000000=Full update, 0x40000000=Update as palette changed
111: */
112: int AdjustLinePaletteRemapBIGENDIAN(void)
113: {
114: unsigned short *actHBLPal;
115: int endiantable[16] = {0,2,1,3,8,10,9,11,4,6,5,7,12,14,13,15};
116: int i;
117: int v;
118: /* Copy palette and convert to RGB in display format */
119: actHBLPal = pHBLPalettes + (ScrY<<4); /* offset in palette */
120: for(i=0; i<16; i++)
121: {
122: v=*actHBLPal;
123: actHBLPal+=1;
124: v=v&0x777;
125: STRGBPalette[endiantable[i]] = ST2RGB[v];
126: }
127: ScrUpdateFlag = *(short *)&HBLPaletteMasks[ScrY];
128: return ScrUpdateFlag;
129: }
130:
131: int AdjustLinePaletteRemap(void)
132: {
133: unsigned short *actHBLPal;
134: int i;
135: int v;
136: /* Copy palette and convert to RGB in display format */
137: actHBLPal = pHBLPalettes + (ScrY<<4); /* offset in palette */
138: for(i=0; i<16; i++)
139: {
140: v=*actHBLPal;
141: actHBLPal+=1;
142: v=v&0x777;
143: STRGBPalette[i] = ST2RGB[v];
144: }
145: ScrUpdateFlag = *(short *)&HBLPaletteMasks[ScrY];
146: return ScrUpdateFlag;
147: /*
148: __asm {
149: push ebx
150: push ecx
151: push edx
152:
153: // Copy palette and convert to RGB in display format
154: mov eax,[ScrY] // Y
155: shl eax,5 // 16 x short int's to get offset into palette
156: mov ebx,[pHBLPalettes]
157: add ebx,eax
158: mov edx,OFFSET [STRGBPalette] // Copy for use in conversion(as no registers free, need copy)
159: mov ecx,16
160: palette_loop:
161: mov ax,[ebx]
162: add ebx,2
163: and eax,0x777 // Colour&0x777
164: mov eax,ST2RGB[eax*4] // Convert to PC's RGB
165: mov [edx],eax // Store as long's for speed
166: add edx,4
167: dec ecx
168: jne palette_loop
169:
170: // Get mask, if top bit is set we need to update
171: mov eax,[ScrY]
172: mov eax,DWORD PTR HBLPaletteMasks[eax*4] // Current mask
173: mov [ScrUpdateFlag],eax // Store for pixel conversion
174:
175: pop edx
176: pop ecx
177: pop ebx
178: ret
179: }
180: */
181: }
182:
183: //-----------------------------------------------------------------------
184: /*
185: Run updates to palette(STRGBPalette[]) until get to screen line we are to convert from
186: */
187: void Convert_StartFrame(void)
188: {
189: int ecx;
190: ecx=STScreenStartHorizLine; /* Get #lines before conversion starts */
191: if( ecx==0 ) return;
192: ScrY=0;
193: do
194: {
195: AdjustLinePaletteRemap(); /* Update palette */
196: ++ScrY;
197: --ecx;
198: }
199: while( ecx );
200: }
201:
202:
203:
204:
205:
206: #define LOW_BUILD_PIXELS_0 \
207: { \
208: ebx &= 0x0f0f0f0f; \
209: ecx &= 0x0f0f0f0f; \
210: eax = ebx >> 12; \
211: eax |= ebx; \
212: edx = ecx >> 12; \
213: edx |= ecx; \
214: ebx = edx; \
215: ebx &= 0x00ff; \
216: ecx = Remap_2_Planes_Upper[ebx]; \
217: ebx = eax; \
218: ebx &= 0x00ff; \
219: ecx += Remap_2_Planes[ebx]; \
220: }
221: /*
222: __asm and ebx,0x0f0f0f0f \
223: __asm and ecx,0x0f0f0f0f \
224: __asm mov eax,ebx \
225: __asm shr eax,12 \
226: __asm or eax,ebx \
227: __asm mov edx,ecx \
228: __asm shr edx,12 \
229: __asm or edx,ecx \
230: __asm mov ebx,edx \
231: __asm and ebx,0x000000ff \
232: __asm mov ecx,Remap_2_Planes_Upper[ebx*4] \
233: __asm mov ebx,eax \
234: __asm and ebx,0x000000ff \
235: __asm add ecx,Remap_2_Planes[ebx*4]
236: */
237:
238:
239: #define LOW_BUILD_PIXELS_1 \
240: { \
241: ebx = edx; \
242: ebx = ebx >> 8; \
243: ebx &= 0x00ff; \
244: ecx = Remap_2_Planes_Upper[ebx]; \
245: ebx = eax; \
246: ebx = ebx >> 8; \
247: ebx &= 0x00ff; \
248: ecx += Remap_2_Planes[ebx]; \
249: }
250: /*
251: __asm mov ebx,edx \
252: __asm shr ebx,8 \
253: __asm and ebx,0x000000ff \
254: __asm mov ecx,Remap_2_Planes_Upper[ebx*4] \
255: __asm mov ebx,eax \
256: __asm shr ebx,8 \
257: __asm and ebx,0x000000ff \
258: __asm add ecx,Remap_2_Planes[ebx*4]
259: */
260:
261:
262: #define LOW_BUILD_PIXELS_2 \
263: { \
264: ebx = *edi; \
265: ecx = *(edi+1); \
266: ebx &= 0xf0f0f0f0; \
267: ecx &= 0xf0f0f0f0; \
268: ebx = ebx >> 4; \
269: eax = ebx; \
270: ebx = ebx >> 12; \
271: eax |= ebx; \
272: ecx = ecx >> 4; \
273: edx = ecx; \
274: ecx = ecx >> 12; \
275: edx |= ecx; \
276: ebx = edx; \
277: ebx &= 0x00ff; \
278: ecx = Remap_2_Planes_Upper[ebx]; \
279: ebx = eax; \
280: ebx &= 0x00ff; \
281: ecx += Remap_2_Planes[ebx]; \
282: }
283: /*
284: __asm mov ebx,[edi] \
285: __asm mov ecx,4[edi] \
286: __asm and ebx,0xf0f0f0f0 \
287: __asm and ecx,0xf0f0f0f0 \
288: __asm shr ebx,4 \
289: __asm mov eax,ebx \
290: __asm shr ebx,12 \
291: __asm or eax,ebx \
292: __asm shr ecx,4 \
293: __asm mov edx,ecx \
294: __asm shr ecx,12 \
295: __asm or edx,ecx \
296: __asm mov ebx,edx \
297: __asm and ebx,0x000000ff \
298: __asm mov ecx,Remap_2_Planes_Upper[ebx*4] \
299: __asm mov ebx,eax \
300: __asm and ebx,0x000000ff \
301: __asm add ecx,Remap_2_Planes[ebx*4]
302: */
303:
304:
305: #define LOW_BUILD_PIXELS_3 \
306: { \
307: ebx = edx; \
308: ebx = ebx >> 8; \
309: ebx &= 0x00ff; \
310: ecx = Remap_2_Planes_Upper[ebx]; \
311: ebx = eax; \
312: ebx = ebx >> 8; \
313: ebx &= 0x00ff; \
314: ecx += Remap_2_Planes[ebx]; \
315: }
316: /*
317: __asm mov ebx,edx \
318: __asm shr ebx,8 \
319: __asm and ebx,0x000000ff \
320: __asm mov ecx,Remap_2_Planes_Upper[ebx*4] \
321: __asm mov ebx,eax \
322: __asm shr ebx,8 \
323: __asm and ebx,0x000000ff \
324: __asm add ecx,Remap_2_Planes[ebx*4]
325: */
326:
327:
328: /* Plot Low Resolution(320xH) 16-Bit pixels */
329: #define PLOT_LOW_320_16BIT(offset) \
330: { \
331: ebx = ecx; \
332: ebx &= 0x00ff; \
333: ecx = ecx >> 8; \
334: ebx = STRGBPalette[ebx]; \
335: esi[offset] = (unsigned short) ebx; \
336: ebx = ecx; \
337: ebx &= 0x00ff; \
338: ecx = ecx >> 8; \
339: ebx = STRGBPalette[ebx]; \
340: esi[offset+1] = (unsigned short) ebx; \
341: ebx = ecx; \
342: ebx &= 0x00ff; \
343: ecx = ecx >> 8; \
344: ebx = STRGBPalette[ebx]; \
345: esi[offset+2] = (unsigned short) ebx; \
346: ebx = ecx; \
347: ebx &= 0x00ff; \
348: ebx = STRGBPalette[ebx]; \
349: esi[offset+3] = (unsigned short) ebx; \
350: }
351: /*
352: __asm mov ebx,ecx \
353: __asm and ebx,0x000000ff \
354: __asm shr ecx,8 \
355: __asm mov ebx,DWORD PTR STRGBPalette[ebx*4] \
356: __asm mov offset[esi],bx \
357: __asm mov ebx,ecx \
358: __asm and ebx,0x000000ff \
359: __asm shr ecx,8 \
360: __asm mov ebx,DWORD PTR STRGBPalette[ebx*4] \
361: __asm mov offset[esi+2],bx \
362: __asm mov ebx,ecx \
363: __asm and ebx,0x000000ff \
364: __asm shr ecx,8 \
365: __asm mov ebx,DWORD PTR STRGBPalette[ebx*4] \
366: __asm mov offset[esi+4],bx \
367: __asm mov ebx,ecx \
368: __asm and ebx,0x000000ff \
369: __asm mov ebx,DWORD PTR STRGBPalette[ebx*4] \
370: __asm mov offset[esi+6],bx
371: */
372:
373:
374:
375: /* Conversion routines */
376: #include "convert/low320x16.c" /* LowRes To 320xH x 16-bit colour */
377: #include "convert/low640x16.c" /* LowRes To 640xH x 16-bit colour */
378: #include "convert/med640x16.c" /* MediumRes To 640xH x 16-bit colour */
379: #include "convert/low320x8.c" /* LowRes To 320xH x 8-bit colour */
380: #include "convert/low640x8.c" /* LowRes To 640xH x 8-bit colour */
381: #include "convert/med640x8.c" /* MediumRes To 640xH x 8-bit colour */
382: #include "convert/high640x8.c" /* HighRes To 640xH x 8-bit colour */
383: #include "convert/high640x1.c" /* HighRes To 640xH x 1-bit colour */
384: #include "convert/spec320x16.c" /* Spectrum 512 To 320xH x 16-bit colour */
385: #include "convert/spec640x16.c" /* Spectrum 512 To 640xH x 16-bit colour */
386:
387: #include "convert/vdi16.c" /* VDI x 16 colour */
388: #include "convert/vdi4.c" /* VDI x 4 colour */
389: #include "convert/vdi2.c" /* VDI x 2 colour */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.