Annotation of uae/src/od-dos/video/video.c, revision 1.1.1.2

1.1       root        1:  /*
                      2:   * UAE - The Un*x Amiga Emulator
                      3:   *
                      4:   * DOS video interface.
                      5:   *
                      6:   * (c) 1997 Gustavo Goedert
                      7:   *
                      8:   * Originaly based on svga.c -- (c) 1995 Bernd Schmidt
                      9:   */
                     10: 
                     11: #include "sysconfig.h"
                     12: #include "sysdeps.h"
                     13: 
                     14: #include <dos.h>
                     15: #include <go32.h>
                     16: #include <dpmi.h>
                     17: #include <sys/exceptn.h>
                     18: #include <crt0.h>
                     19: #include <signal.h>
                     20: 
                     21: #include "config.h"
                     22: #include "options.h"
                     23: #include "threaddep/penguin.h"
                     24: #include "memory.h"
                     25: #include "custom.h"
                     26: #include "xwin.h"
                     27: #include "disk.h"
                     28: #include "uae.h"
                     29: #include "debug.h"
                     30: #include "picasso96.h"
                     31: #include "misc/handlers.h"
                     32: #include "misc/misc.h"
                     33: #include "video/vbe.h"
                     34: 
                     35: int GetColor(int r, int g, int b, xcolnr *cnp);
                     36: void InitColors(void);
                     37: void SetWindowForPicasso(void);
                     38: void SetWindowForAmiga(void);
                     39: uae_u8 *lockscr (void);
                     40: void unlockscr (void);
                     41: 
                     42: extern int debugging;
                     43: 
                     44: xcolnr xcolors[4096];
                     45: struct vidbuf_description gfxvidinfo;
                     46: int NeedDither;
                     47: UBYTE DitherBuf[1000];
                     48: int ColorsAllocated;
                     49: char *LinearMem = NULL;
                     50: int ModeNumber = -1, UseLinear = 0;
                     51: int PicassoModeNumber = -1, PicassoUseLinear = 0;
                     52: int ScreenIsPicasso = 0;
                     53: char PicassoInvalidLines[1200];
                     54: 
                     55: struct bstring *video_mode_menu = NULL;
                     56: 
                     57: void setup_brkhandler(void) {
                     58: }
                     59: 
                     60: void flush_line(int y) {
                     61:     int target_y = y;
                     62:     char *addr;
                     63: 
                     64:     if (debugging)
                     65:        return;
                     66:     if (LinearMem == NULL) {
                     67:        addr = gfxvidinfo.bufmem + y*gfxvidinfo.rowbytes;
                     68:        if (target_y < CurrentMode.ModeHeight && target_y >= 0) {
                     69:            if (NeedDither) {
                     70:                DitherLine(DitherBuf, (UWORD *)addr, 0, y, gfxvidinfo.width, CurrentMode.BitsPerPixel);
                     71:                addr = DitherBuf;
                     72:            }
                     73:            CurrentMode.PutLine(addr, target_y);
                     74:        }
                     75:     } else if (NeedDither && target_y >= 0) {
                     76:        addr = gfxvidinfo.bufmem + y*gfxvidinfo.rowbytes;
                     77:        DitherLine(LinearMem + CurrentMode.LogicalLineLength * target_y, (UWORD *)addr, 0, y, gfxvidinfo.width, CurrentMode.BitsPerPixel);
                     78:     }
                     79: }
                     80: 
                     81: void flush_block(int a, int b) {
                     82:     abort();
                     83: }
                     84: 
                     85: void flush_screen(int a, int b) {
                     86: }
                     87: 
                     88: int GetColor(int r, int g, int b, xcolnr *cnp) {
                     89:     if ((CurrentMode.ModeType == T16) && (ColorsAllocated == 16))
                     90:        return -1;
                     91:     else if (ColorsAllocated == 256)
                     92:        return -1;
                     93:     *cnp = ColorsAllocated;
                     94:     DelayedSetPalette(ColorsAllocated, doMask(r, 6, 0), doMask(g, 6, 0), doMask(b, 6, 0));
                     95:     ColorsAllocated++;
                     96:     return 1;
                     97: }
                     98: 
                     99: void InitColors(void) {
                    100:     int i;
                    101: 
                    102:     gfxvidinfo.can_double = 0;
                    103:     if (NeedDither)
                    104:        setup_dither(CurrentMode.BitsPerColor, GetColor);
                    105:     else {
                    106:        ColorsAllocated = 0;
                    107:        if (gfxvidinfo.pixbytes == 1)
                    108:            alloc_colors256(GetColor);
                    109:        else
                    110:            alloc_colors64k(CurrentMode.RedSize,
                    111:                            CurrentMode.GreenSize,
                    112:                            CurrentMode.BlueSize,
                    113:                            CurrentMode.RedPosition,
                    114:                            CurrentMode.GreenPosition,
                    115:                            CurrentMode.BluePosition);
                    116:        if (gfxvidinfo.pixbytes == 1) {
                    117:            for (i = 0; i < 4096; i++)
                    118:                xcolors[i] = xcolors[i] * 0x01010101;
                    119:            gfxvidinfo.can_double = 1;
                    120:        } else if (gfxvidinfo.pixbytes == 2) {
                    121:            for (i = 0; i < 4096; i++)
                    122:                xcolors[i] = xcolors[i] * 0x00010001;
                    123:            gfxvidinfo.can_double = 1;
                    124:        }
                    125:    }
                    126: }
                    127: 
                    128: int graphics_setup(void) {
                    129:     return 1;
                    130: }
                    131: 
                    132: int graphics_init(void) {
                    133:     T_ModeType WantedType;
                    134:     int i;
                    135: 
                    136:     /* save produce_sound state */
                    137:     Original_produce_sound = currprefs.produce_sound;
                    138: 
                    139:     switch (currprefs.color_mode) {
                    140:        case 0: WantedType=T256; NeedDither=0; break;
                    141:        case 1: WantedType=T32K; NeedDither=0; break;
                    142:        case 2: WantedType=T64K; NeedDither=0; break;
                    143:        case 3: WantedType=T256; NeedDither=1; break;
                    144:        case 4: WantedType=T16;  NeedDither=1; break;
                    145:        case 5: WantedType=T16M; NeedDither=0; break;
                    146:        default:
                    147:        printf("Invalid color mode.\n");
                    148:        return 0;
                    149:     }
                    150: 
                    151:     if (!InitGfxLib()) {
                    152:        printf("Can't init GfxLib.\n");
                    153:        return 0;
                    154:     }
                    155: 
                    156:     if (!currprefs.no_xhair)
                    157:        for (i = 0; i < NumberOfModes; i++) {
                    158:            if ((ModeList[i].ModeType == WantedType) &&
                    159:                (ModeList[i].ModeWidth == currprefs.gfx_width) &&
                    160:                (ModeList[i].ModeHeight == currprefs.gfx_height) &&
                    161:                 ModeList[i].HasLinear) {
                    162:                ModeNumber = i;
                    163:                UseLinear = 1;
                    164:                break;
                    165:            }
                    166:        }
                    167:     if (ModeNumber == -1)
                    168:        for (i = 0; i < NumberOfModes; i++) {
                    169:            if ((ModeList[i].ModeType == WantedType) &&
                    170:                (ModeList[i].ModeWidth == currprefs.gfx_width) &&
                    171:                (ModeList[i].ModeHeight == currprefs.gfx_height)) {
                    172:                if (ModeList[i].HasWindow || ((!ModeList[i].HasLinear) && (!ModeList[i].HasWindow))) {
                    173:                    ModeNumber = i;
                    174:                    break;
                    175:                }
                    176:            }
                    177:        }
                    178: 
                    179:     if (ModeNumber == -1) {
                    180:        printf("Sorry, this combination of color and video mode is not supported.\n");
                    181:        return 0;
                    182:     }
                    183: 
                    184:     if (!SetMode(ModeNumber, UseLinear)) {
                    185:        printf("Can't start graphics mode.\n");
                    186:        return 0;
                    187:     }
                    188: 
                    189:     if (!NeedDither)
                    190:        gfxvidinfo.pixbytes = CurrentMode.BitsPerPixel>>3;
                    191:     else
                    192:        gfxvidinfo.pixbytes = 2;
                    193: 
                    194:     if (UseLinear) {
                    195:        printf("Using linear framebuffer.\n");
                    196:        if (CanMapBuffer) {
                    197:            LinearMem = CurrentMode.MappedAddress;
                    198:            if (LinearMem != NULL)
                    199:                printf("Mapping linear framebuffer into emulator memory.\n");
                    200:            else {
                    201:                printf("Can't map linear framebuffer.\n");
                    202:                return 0;
                    203:            }
                    204:        }
                    205:     }
                    206: 
                    207:     gfxvidinfo.maxblocklines = 0;
                    208: 
                    209:     gfxvidinfo.width = CurrentMode.ModeWidth;
                    210:     gfxvidinfo.height = CurrentMode.ModeHeight;
                    211:     gfxvidinfo.linemem = 0;
1.1.1.2 ! root      212:     gfxvidinfo.emergmem = 0;
1.1       root      213: 
                    214:     InitColors();
                    215:     if ((gfxvidinfo.pixbytes == 1) || NeedDither)
                    216:        LoadPalette();
                    217: 
                    218:     if (UseLinear && CanMapBuffer && (!NeedDither) && (LinearMem != NULL)) {
                    219:        gfxvidinfo.bufmem = LinearMem;
                    220:        gfxvidinfo.rowbytes = CurrentMode.LogicalLineLength;
                    221:     } else {
                    222:        gfxvidinfo.rowbytes = (CurrentMode.ModeWidth * gfxvidinfo.pixbytes + 3) & ~3;
                    223:        gfxvidinfo.bufmem = malloc(gfxvidinfo.rowbytes * CurrentMode.ModeHeight);
                    224:        if (gfxvidinfo.bufmem == NULL) {
                    225:            printf("Can't allocate framebuffer.\n");
                    226:            return 0;
                    227:        }
                    228:     }
                    229: 
                    230:     memset(gfxvidinfo.bufmem, 0, gfxvidinfo.rowbytes * CurrentMode.ModeHeight);
                    231:     for(i=0; i<gfxvidinfo.height; i++)
                    232:        flush_line(i);
                    233: 
                    234:     /* set up handlers */
                    235:     if (!InstallHandlers()) {
                    236:        printf("Can't install all handlers.\n");
                    237:        return(0);
                    238:     }
                    239: 
                    240:     return 1;
                    241: }
                    242: 
                    243: void graphics_leave(void) {
                    244:     UninstallHandlers();
                    245:     CloseGfxLib();
                    246:     dumpcustom();
                    247:     /* restore produce_sound state */
                    248:     currprefs.produce_sound = Original_produce_sound;
                    249: }
                    250: 
1.1.1.2 ! root      251: int debuggable(void)
        !           252: {
        !           253:     return 1;
1.1       root      254: }
                    255: 
1.1.1.2 ! root      256: int needmousehack(void)
        !           257: {
        !           258:     return 0;
1.1       root      259: }
                    260: 
                    261: #ifdef PICASSO96
                    262: 
                    263: void PicassoRefresh(void) {
                    264:     if (ScreenIsPicasso && !picasso_vidinfo.extra_mem) {
                    265:        int i;
                    266:        char *addr = gfxmemory + (picasso96_state.Address - gfxmem_start);
                    267:        for (i = 0; i < picasso_vidinfo.height; i++, addr += picasso96_state.BytesPerRow) {
                    268:            if (!PicassoInvalidLines[i])
                    269:                continue;
                    270:            PicassoInvalidLines[i] = 0;
                    271:            CurrentMode.PutLine(addr, i);
                    272:        }
                    273:     }
                    274: }
                    275: 
                    276: void DX_Invalidate (int first, int last) {
                    277:     if (!picasso_vidinfo.extra_mem) {
                    278:        do {
                    279:            PicassoInvalidLines[first] = 1;
                    280:            first++;
                    281:        } while (first <= last);
                    282:     }
                    283: }
                    284: 
                    285: int DX_BitsPerCannon (void) {
                    286:     return 8;
                    287: }
                    288: 
                    289: void DX_SetPalette(int start, int count) {
                    290:     if (!ScreenIsPicasso || picasso_vidinfo.pixbytes != 1)
                    291:        return;
                    292: 
                    293:     while (count-- > 0) {
                    294:        DelayedSetPalette(start, picasso96_state.CLUT[start].Red * 63 / 255,
                    295:                                 picasso96_state.CLUT[start].Green * 63 / 255,
                    296:                                 picasso96_state.CLUT[start].Blue * 63 / 255);
                    297:        start++;
                    298:     }
                    299:     LoadPalette();
                    300: }
                    301: 
                    302: int DX_FillResolutions (uae_u16 *ppixel_format) {
                    303:     int i, count = 0;
                    304:     uae_u16 format = 0;
                    305: 
                    306:     for (i = 0; i < NumberOfModes; i++) {
                    307:        if (ModeList[i].ModeType != T16) {
                    308:            DisplayModes[count].res.width = ModeList[i].ModeWidth;
                    309:            DisplayModes[count].res.height = ModeList[i].ModeHeight;
                    310:            DisplayModes[count].depth = ModeList[i].BitsPerPixel>>3;
                    311:            DisplayModes[count].refresh = 75;
                    312:            switch (DisplayModes[count].depth) {
                    313:                case 1: format |= RGBFF_CHUNKY; break;
                    314:                case 2: format |= RGBFF_R5G6B5PC; break;
                    315:                case 3: format |= RGBFF_B8G8R8; break;
                    316:                case 4: format |= RGBFF_B8G8R8A8; break;
                    317:            }
                    318:            count++;
                    319:        }
                    320:     }
                    321: 
                    322:     *ppixel_format = format;
                    323:     return count;
                    324: }
                    325: 
                    326: void SetWindowForPicasso(void) {
                    327:     if (!SetMode(PicassoModeNumber, PicassoUseLinear)) {
                    328:        printf("Can't start graphics mode.\n");
                    329:        abort();
                    330:     }
                    331:     if (PicassoUseLinear && (CurrentMode.MappedAddress != NULL)) {
                    332:        LinearMem = CurrentMode.MappedAddress;
                    333:        picasso_vidinfo.extra_mem = 1;
                    334:     } else
                    335:        picasso_vidinfo.extra_mem = 0;
                    336:     DX_SetPalette (0, 256);
                    337: }
                    338: 
                    339: void SetWindowForAmiga(void) {
                    340:     if (!SetMode(ModeNumber, UseLinear)) {
                    341:        printf("Can't start graphics mode.\n");
                    342:        abort();
                    343:     }
                    344:     if (UseLinear && (CurrentMode.MappedAddress != NULL) && (!NeedDither)) {
                    345:        LinearMem = CurrentMode.MappedAddress;
                    346:        gfxvidinfo.bufmem = LinearMem;
                    347:     }
                    348:     if ((gfxvidinfo.pixbytes == 1) || NeedDither)
                    349:        LoadPalette();
                    350: }
                    351: 
                    352: void gfx_set_picasso_state (int on) {
                    353:     if (on == ScreenIsPicasso)
                    354:        return;
                    355:     ScreenIsPicasso = on;
                    356:     if (on)
                    357:        SetWindowForPicasso();
                    358:     else
                    359:        SetWindowForAmiga();
                    360: }
                    361: 
                    362: void gfx_set_picasso_modeinfo (int w, int h, int depth) {
                    363:     T_ModeType WantedType;
                    364:     int i;
                    365: 
                    366:     PicassoModeNumber = -1;
                    367:     PicassoUseLinear = 0;
                    368:     switch (depth) {
                    369:        case 8: WantedType=T256; break;
                    370:        case 16: WantedType=T64K; break;
                    371:        case 24:
                    372:        case 32: WantedType=T16M; break;
                    373:        default:
                    374:        printf("Invalid Picasso mode.\n");
                    375:        abort();
                    376:     }
                    377: 
                    378:     if (!currprefs.no_xhair)
                    379:        for (i = 0; i < NumberOfModes; i++) {
                    380:            if ((ModeList[i].ModeType == WantedType) &&
                    381:                (ModeList[i].ModeWidth == w) &&
                    382:                (ModeList[i].ModeHeight == h) &&
                    383:                 ModeList[i].HasLinear) {
                    384:                PicassoModeNumber = i;
                    385:                PicassoUseLinear = 1;
                    386:                break;
                    387:            }
                    388:        }
                    389:     if (PicassoModeNumber == -1)
                    390:        for (i = 0; i < NumberOfModes; i++) {
                    391:            if ((ModeList[i].ModeType == WantedType) &&
                    392:                (ModeList[i].ModeWidth == w) &&
                    393:                (ModeList[i].ModeHeight == h)) {
                    394:                if (ModeList[i].HasWindow || ((!ModeList[i].HasLinear) && (!ModeList[i].HasWindow))) {
                    395:                    PicassoModeNumber = i;
                    396:                    break;
                    397:                }
                    398:            }
                    399:        }
                    400: 
                    401:     if (PicassoModeNumber == -1) {
                    402:        printf("Invalid Picasso mode.\n");
                    403:        abort ();
                    404:     }
                    405: 
                    406:     picasso_vidinfo.width = w;
                    407:     picasso_vidinfo.height = h;
                    408:     picasso_vidinfo.depth = depth;
                    409:     picasso_vidinfo.pixbytes = depth>>3;
                    410:     picasso_vidinfo.rowbytes = ModeList[PicassoModeNumber].LogicalLineLength;
                    411:     if (ScreenIsPicasso)
                    412:        SetWindowForPicasso ();
                    413: }
                    414: 
                    415: uae_u8 *lockscr (void) {
                    416:     return LinearMem;
                    417: }
                    418: 
                    419: void unlockscr (void) {
                    420: }
                    421: 
                    422: #endif

unix.superglobalmegacorp.com

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