Annotation of frontvm/hardware/screenConvert.c, revision 1.1.1.2

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.