|
|
1.1 root 1:
2: #include <SDL.h>
3: #include <SDL_endian.h>
4:
5: #include "main.h"
6: #include "screen.h"
7: #include "screenConvert.h"
8: #include "video.h"
9: #include "scalebit.h"
10:
11:
12: int ScrX,ScrY; /* Locals */
13: int ScrUpdateFlag; /* Bit mask of how to update screen */
14: BOOL bScrDoubleY; /* TRUE if double on Y */
15: unsigned long *RGBPalette;
16:
17: void BuildRGBPalette (unsigned long *rgb, unsigned short *st, int len)
18: {
19: int i;
20: int st_col, r, g, b;
21:
22: for (i=0; i<len; i++, st++) {
23: st_col = *st;
24: b = (st_col & 0xf)<<4;
25: g = (st_col & 0xf0);
26: r = (st_col & 0xf00)>>4;
27: //printf ("%x: %x, %x, %x\n", st_col, r,g,b);
28: rgb[i] = SDL_MapRGB(sdlscrn->format, r, g, b);
29: }
30: }
31:
32: static inline void AdjustLinePaletteRemap(int y)
33: {
34: /* Copy palette and convert to RGB in display format */
35: if (y >= 168) {
36: RGBPalette = CtrlRGBPalette;
37: } else {
38: RGBPalette = MainRGBPalette;
39: }
40: }
41:
42:
43: /*-----------------------------------------------------------------------*/
44: /*
45: Run updates to palette(STRGBPalette[]) until get to screen line we are to convert from
46: */
47: void Convert_StartFrame(void)
48: {
49: int ecx;
50: ecx=STScreenStartHorizLine; /* Get #lines before conversion starts */
51: if( ecx==0 ) return;
52: ScrY=0;
53: do
54: {
55: AdjustLinePaletteRemap(ScrY); /* Update palette */
56: ++ScrY;
57: --ecx;
58: }
59: while( ecx );
60: }
61:
62: void Draw_320x16Bit(void)
63: {
64: Uint8 *st_pix;
65: Uint16 *pc_pix;
66: int x;
67: Convert_StartFrame ();
68:
69: ScrY = STScreenStartHorizLine;
70:
71: do {
72: st_pix = (Uint8 *)VideoRaster + STScreenLineOffset[ScrY];
73: pc_pix = (Uint16 *)pPCScreenDest;
74:
75: AdjustLinePaletteRemap(ScrY);
76:
77: for (x=STScreenWidthBytes; x>0; x--) {
78: *pc_pix = RGBPalette [*st_pix];
79: pc_pix++;
80: st_pix++;
81: }
82:
83: pPCScreenDest += 320*2;
84: ScrY++;
85: } while (ScrY < STScreenEndHorizLine);
86: }
87:
88:
89: void Draw_320x24Bit(void)
90: {
91: Uint8 *st_pix;
92: Uint8 *pc_pix;
93: int x, col;
94: Convert_StartFrame ();
95:
96: ScrY = STScreenStartHorizLine;
97: pc_pix = (Uint8 *)pPCScreenDest;
98:
99: do {
100: st_pix = (Uint8 *)VideoRaster + STScreenLineOffset[ScrY];
101:
102: AdjustLinePaletteRemap(ScrY);
103:
104: for (x=STScreenWidthBytes; x>0; x--) {
105: col = RGBPalette [*st_pix];
106: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
107: *pc_pix++ = (col >> 16) & 0xff;
108: *pc_pix++ = (col >> 8) & 0xff;
109: *pc_pix++ = col & 0xff;
110: } else {
111: *pc_pix++ = col & 0xff;
112: *pc_pix++ = (col >> 8) & 0xff;
113: *pc_pix++ = (col >> 16) & 0xff;
114: }
115: st_pix++;
116: }
117: ScrY++;
118: } while (ScrY < STScreenEndHorizLine);
119: }
120:
121:
122: void Draw_320x32Bit(void)
123: {
124: Uint8 *st_pix;
125: Uint32 *pc_pix;
126: int x;
127: Convert_StartFrame ();
128:
129: ScrY = STScreenStartHorizLine;
130:
131: do {
132: st_pix = (Uint8 *)VideoRaster + STScreenLineOffset[ScrY];
133: pc_pix = (Uint32 *)pPCScreenDest;
134:
135: AdjustLinePaletteRemap(ScrY);
136:
137: for (x=STScreenWidthBytes; x>0; x--) {
138: *pc_pix = RGBPalette [*st_pix];
139: pc_pix++;
140: st_pix++;
141: }
142:
143: pPCScreenDest += 320*4;
144: ScrY++;
145: } while (ScrY < STScreenEndHorizLine);
146: }
147:
148: void Draw_640x16Bit(void)
149: {
150: Uint8 *st_pix;
151: Uint16 *pc_pix;
152: int x, col;
153: Convert_StartFrame ();
154:
155: ScrY = STScreenStartHorizLine;
156:
157: do {
158: st_pix = (Uint8 *)VideoRaster + STScreenLineOffset[ScrY];
159: pc_pix = (Uint16 *)pPCScreenDest;
160:
161: AdjustLinePaletteRemap(ScrY);
162:
163: for (x=STScreenWidthBytes; x>0; x--) {
164: col = RGBPalette [*st_pix];
165: *pc_pix = col;
166: *(pc_pix + 320*2) = col;
167: pc_pix++;
168: *pc_pix = col;
169: *(pc_pix + 320*2) = col;
170: pc_pix++;
171: st_pix++;
172: }
173:
174: pPCScreenDest += 640*4;
175: ScrY++;
176: } while (ScrY < STScreenEndHorizLine);
177: }
178:
179:
180: void Draw_640x24Bit(void)
181: {
182: Uint8 *st_pix;
183: Uint8 *pc_pix;
184: int x, col;
185: Convert_StartFrame ();
186:
187: ScrY = STScreenStartHorizLine;
188: pc_pix = (Uint8 *)pPCScreenDest;
189:
190: do {
191: st_pix = (Uint8 *)VideoRaster + STScreenLineOffset[ScrY];
192:
193: AdjustLinePaletteRemap(ScrY);
194:
195: for (x=STScreenWidthBytes; x>0; x--) {
196: col = RGBPalette [*st_pix];
197: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
198: *pc_pix = *(pc_pix+640*3) = (col >> 16) & 0xff;
199: pc_pix++;
200: *pc_pix = *(pc_pix+640*3) = (col >> 8) & 0xff;
201: pc_pix++;
202: *pc_pix = *(pc_pix+640*3) = col & 0xff;
203: pc_pix++;
204: *pc_pix = *(pc_pix+640*3) = (col >> 16) & 0xff;
205: pc_pix++;
206: *pc_pix = *(pc_pix+640*3) = (col >> 8) & 0xff;
207: pc_pix++;
208: *pc_pix = *(pc_pix+640*3) = col & 0xff;
209: pc_pix++;
210: } else {
211: *pc_pix = *(pc_pix+640*3) = col & 0xff;
212: pc_pix++;
213: *pc_pix = *(pc_pix+640*3) = (col >> 8) & 0xff;
214: pc_pix++;
215: *pc_pix = *(pc_pix+640*3) = (col >> 16) & 0xff;
216: pc_pix++;
217: *pc_pix = *(pc_pix+640*3) = col & 0xff;
218: pc_pix++;
219: *pc_pix = *(pc_pix+640*3) = (col >> 8) & 0xff;
220: pc_pix++;
221: *pc_pix = *(pc_pix+640*3) = (col >> 16) & 0xff;
222: pc_pix++;
223: }
224: st_pix++;
225: }
226: pc_pix += 640*3;
227: ScrY++;
228: } while (ScrY < STScreenEndHorizLine);
229: }
230:
231: void Draw_640x32Bit(void)
232: {
233: Uint8 *st_pix;
234: Uint32 *pc_pix;
235: int x, col;
236: Convert_StartFrame ();
237:
238: ScrY = STScreenStartHorizLine;
239:
240: do {
241: st_pix = (Uint8 *)VideoRaster + STScreenLineOffset[ScrY];
242: pc_pix = (Uint32 *)pPCScreenDest;
243:
244: AdjustLinePaletteRemap(ScrY);
245:
246: for (x=STScreenWidthBytes; x>0; x--) {
247: col = RGBPalette [*st_pix];
248: *pc_pix = col;
249: *(pc_pix + 320*2) = col;
250: pc_pix++;
251: *pc_pix = col;
252: *(pc_pix + 320*2) = col;
253: pc_pix++;
254: st_pix++;
255: }
256:
257: pPCScreenDest += 640*8;
258: ScrY++;
259: } while (ScrY < STScreenEndHorizLine);
260: }
261:
262: #define SCALE_OPT 2
263: #define SRC_PIX 1 /* 8bpp */
264: #define DEST_SLICE (320 * SRC_PIX * SCALE_OPT)
265:
266: char scale2x_buf[DEST_SLICE * 200 * SCALE_OPT];
267:
268: void Draw_Scale2x16Bit ()
269: {
270: Uint8 *st_pix;
271: Uint16 *pc_pix;
272: int x;
273:
274: scale (SCALE_OPT, scale2x_buf, DEST_SLICE, VideoRaster, 320*SRC_PIX, SRC_PIX, 320, 200);
275:
276: Convert_StartFrame ();
277:
278: ScrY = 0;
279:
280: do {
281: st_pix = (Uint8 *)scale2x_buf + 640*ScrY;
282: pc_pix = (Uint16 *)pPCScreenDest;
283:
284: AdjustLinePaletteRemap(ScrY>>1);
285:
286: for (x=640; x>0; x--) {
287: *pc_pix = RGBPalette [*st_pix];
288: pc_pix++;
289: st_pix++;
290: }
291:
292: pPCScreenDest += 640*2;
293: ScrY++;
294: } while (ScrY < SCREEN_HEIGHT_HBL*2);
295: }
296:
297:
298: void Draw_Scale2x24Bit ()
299: {
300: Uint8 *st_pix;
301: Uint8 *pc_pix;
302: int x, col;
303:
304: scale (SCALE_OPT, scale2x_buf, DEST_SLICE, VideoRaster, 320*SRC_PIX, SRC_PIX, 320, 200);
305:
306: Convert_StartFrame ();
307:
308: ScrY = 0;
309: pc_pix = (Uint8 *)pPCScreenDest;
310:
311: do {
312: st_pix = (Uint8 *)scale2x_buf + 640*ScrY;
313:
314: AdjustLinePaletteRemap(ScrY>>1);
315:
316: for (x=640; x>0; x--) {
317: col = RGBPalette [*st_pix];
318: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
319: *pc_pix++ = (col >> 16) & 0xff;
320: *pc_pix++ = (col >> 8) & 0xff;
321: *pc_pix++ = col & 0xff;
322: } else {
323: *pc_pix++ = col & 0xff;
324: *pc_pix++ = (col >> 8) & 0xff;
325: *pc_pix++ = (col >> 16) & 0xff;
326: }
327: st_pix++;
328: }
329:
330: ScrY++;
331: } while (ScrY < SCREEN_HEIGHT_HBL*2);
332: }
333:
334:
335: void Draw_Scale2x32Bit ()
336: {
337: Uint8 *st_pix;
338: Uint32 *pc_pix;
339: int x;
340:
341: scale (SCALE_OPT, scale2x_buf, DEST_SLICE, VideoRaster, 320*SRC_PIX, SRC_PIX, 320, 200);
342:
343: Convert_StartFrame ();
344:
345: ScrY = 0;
346:
347: do {
348: st_pix = (Uint8 *)scale2x_buf + 640*ScrY;
349: pc_pix = (Uint32 *)pPCScreenDest;
350:
351: AdjustLinePaletteRemap(ScrY>>1);
352:
353: for (x=640; x>0; x--) {
354: *pc_pix = RGBPalette [*st_pix];
355: pc_pix++;
356: st_pix++;
357: }
358:
359: pPCScreenDest += 640*4;
360: ScrY++;
361: } while (ScrY < SCREEN_HEIGHT_HBL*2);
362: }
363:
364:
365: /* [bytes per pixel][mode] */
366: SCREENDRAWFUNC screendrawfuncs [5][3] = {
367: { NULL, NULL, NULL },
368: { NULL, NULL, NULL },
369: { &Draw_320x16Bit, &Draw_640x16Bit, &Draw_Scale2x16Bit },
370: { &Draw_320x24Bit, &Draw_640x24Bit, &Draw_Scale2x24Bit },
371: { &Draw_320x32Bit, &Draw_640x32Bit, &Draw_Scale2x32Bit }
372: };
373:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.