Annotation of hatari/src/vdi.c, revision 1.1.1.12

1.1       root        1: /*
1.1.1.5   root        2:   Hatari - vdi.c
                      3: 
                      4:   This file is distributed under the GNU Public License, version 2 or at
                      5:   your option any later version. Read the file gpl.txt for details.
1.1       root        6: 
                      7:   VDI (Virtual Device Interface) (Trap #2)
                      8: 
1.1.1.5   root        9:   To get higher resolutions on the Desktop, we intercept the VDI/Line-A calls
                     10:   and set elements in their structures to the higher width/height/cel/planes.
                     11:   We need to intercept the initial Line-A call (which we force into the TOS on
                     12:   boot-up) and also the init calls to the VDI.
1.1       root       13: */
1.1.1.12! root       14: const char VDI_fileid[] = "Hatari vdi.c : " __DATE__ " " __TIME__;
1.1       root       15: 
                     16: #include "main.h"
                     17: #include "file.h"
                     18: #include "gemdos.h"
                     19: #include "m68000.h"
                     20: #include "screen.h"
                     21: #include "stMemory.h"
                     22: #include "vdi.h"
                     23: #include "video.h"
1.1.1.9   root       24: #include "configuration.h"
1.1       root       25: 
                     26: 
1.1.1.7   root       27: Uint32 VDI_OldPC;                  /* When call Trap#2, store off PC */
1.1.1.2   root       28: 
1.1.1.12! root       29: bool bUseVDIRes = false;           /* Set to true (if want VDI), or false (ie for games) */
1.1.1.9   root       30: /* defaults */
                     31: int VDIRes = 0;                    /* 0,1 or 2 (low, medium, high) */
                     32: int VDIWidth = 640;                /* 640x480, 800x600 or 1024x768 */
                     33: int VDIHeight = 480;
                     34: int VDIPlanes = 4;
                     35: static int VDIColors = 16;
                     36: static int VDICharHeight = 8;
                     37: 
                     38: static Uint32 LineABase;           /* Line-A structure */
                     39: static Uint32 FontBase;            /* Font base, used for 16-pixel high font */
1.1       root       40: 
1.1.1.8   root       41: static Uint32 Control;
                     42: static Uint32 Intin;
                     43: static Uint32 Ptsin;
                     44: static Uint32 Intout;
                     45: static Uint32 Ptsout;
1.1       root       46: 
1.1.1.2   root       47: 
                     48: /*-----------------------------------------------------------------------*/
                     49: /* Desktop TOS 1.04 and TOS 2.06 desktop configuration files */
1.1.1.8   root       50: static const Uint8 DesktopScript[504] =
1.1.1.3   root       51: {
1.1.1.9   root       52:        0x23,0x61,0x30,0x30,0x30,0x30,0x30,0x30,0x0D,0x0A,0x23,0x62,0x30,0x30,0x30,0x30,
                     53:        0x30,0x30,0x0D,0x0A,0x23,0x63,0x37,0x37,0x37,0x30,0x30,0x30,0x37,0x30,0x30,0x30,
                     54:        0x36,0x30,0x30,0x30,0x37,0x30,0x30,0x35,0x35,0x32,0x30,0x30,0x35,0x30,0x35,0x35,
                     55:        0x35,0x32,0x32,0x32,0x30,0x37,0x37,0x30,0x35,0x35,0x37,0x30,0x37,0x35,0x30,0x35,
                     56:        0x35,0x35,0x30,0x37,0x37,0x30,0x33,0x31,0x31,0x31,0x31,0x30,0x33,0x0D,0x0A,0x23,
                     57:        0x64,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
                     58:        0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
                     59:        0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x0D,0x0A,
                     60:        0x23,0x45,0x20,0x31,0x38,0x20,0x31,0x31,0x20,0x0D,0x0A,0x23,0x57,0x20,0x30,0x30,
                     61:        0x20,0x30,0x30,0x20,0x30,0x30,0x20,0x30,0x37,0x20,0x32,0x36,0x20,0x30,0x43,0x20,
                     62:        0x30,0x30,0x20,0x40,0x0D,0x0A,0x23,0x57,0x20,0x30,0x30,0x20,0x30,0x30,0x20,0x30,
                     63:        0x32,0x20,0x30,0x42,0x20,0x32,0x36,0x20,0x30,0x39,0x20,0x30,0x30,0x20,0x40,0x0D,
                     64:        0x0A,0x23,0x57,0x20,0x30,0x30,0x20,0x30,0x30,0x20,0x30,0x41,0x20,0x30,0x46,0x20,
                     65:        0x31,0x41,0x20,0x30,0x39,0x20,0x30,0x30,0x20,0x40,0x0D,0x0A,0x23,0x57,0x20,0x30,
                     66:        0x30,0x20,0x30,0x30,0x20,0x30,0x45,0x20,0x30,0x31,0x20,0x31,0x41,0x20,0x30,0x39,
                     67:        0x20,0x30,0x30,0x20,0x40,0x0D,0x0A,0x23,0x4D,0x20,0x30,0x31,0x20,0x30,0x30,0x20,
                     68:        0x30,0x30,0x20,0x46,0x46,0x20,0x43,0x20,0x48,0x41,0x52,0x44,0x20,0x44,0x49,0x53,
                     69:        0x4B,0x40,0x20,0x40,0x20,0x0D,0x0A,0x23,0x4D,0x20,0x30,0x30,0x20,0x30,0x30,0x20,
                     70:        0x30,0x30,0x20,0x46,0x46,0x20,0x41,0x20,0x46,0x4C,0x4F,0x50,0x50,0x59,0x20,0x44,
                     71:        0x49,0x53,0x4B,0x40,0x20,0x40,0x20,0x0D,0x0A,0x23,0x4D,0x20,0x30,0x30,0x20,0x30,
                     72:        0x31,0x20,0x30,0x30,0x20,0x46,0x46,0x20,0x42,0x20,0x46,0x4C,0x4F,0x50,0x50,0x59,
                     73:        0x20,0x44,0x49,0x53,0x4B,0x40,0x20,0x40,0x20,0x0D,0x0A,0x23,0x54,0x20,0x30,0x30,
                     74:        0x20,0x30,0x33,0x20,0x30,0x32,0x20,0x46,0x46,0x20,0x20,0x20,0x54,0x52,0x41,0x53,
                     75:        0x48,0x40,0x20,0x40,0x20,0x0D,0x0A,0x23,0x46,0x20,0x46,0x46,0x20,0x30,0x34,0x20,
                     76:        0x20,0x20,0x40,0x20,0x2A,0x2E,0x2A,0x40,0x20,0x0D,0x0A,0x23,0x44,0x20,0x46,0x46,
                     77:        0x20,0x30,0x31,0x20,0x20,0x20,0x40,0x20,0x2A,0x2E,0x2A,0x40,0x20,0x0D,0x0A,0x23,
                     78:        0x47,0x20,0x30,0x33,0x20,0x46,0x46,0x20,0x20,0x20,0x2A,0x2E,0x41,0x50,0x50,0x40,
                     79:        0x20,0x40,0x20,0x0D,0x0A,0x23,0x47,0x20,0x30,0x33,0x20,0x46,0x46,0x20,0x20,0x20,
                     80:        0x2A,0x2E,0x50,0x52,0x47,0x40,0x20,0x40,0x20,0x0D,0x0A,0x23,0x50,0x20,0x30,0x33,
                     81:        0x20,0x46,0x46,0x20,0x20,0x20,0x2A,0x2E,0x54,0x54,0x50,0x40,0x20,0x40,0x20,0x0D,
                     82:        0x0A,0x23,0x46,0x20,0x30,0x33,0x20,0x30,0x34,0x20,0x20,0x20,0x2A,0x2E,0x54,0x4F,
                     83:        0x53,0x40,0x20,0x40,0x20,0x0D,0x0A,0x1A
1.1       root       84: };
                     85: 
1.1.1.8   root       86: static const Uint8 NewDeskScript[786] =
1.1.1.3   root       87: {
1.1.1.9   root       88:        0x23,0x61,0x30,0x30,0x30,0x30,0x30,0x30,0x0D,0x0A,0x23,0x62,0x30,0x30,0x30,0x30,
                     89:        0x30,0x30,0x0D,0x0A,0x23,0x63,0x37,0x37,0x37,0x30,0x30,0x30,0x37,0x30,0x30,0x30,
                     90:        0x36,0x30,0x30,0x30,0x37,0x30,0x30,0x35,0x35,0x32,0x30,0x30,0x35,0x30,0x35,0x35,
                     91:        0x35,0x32,0x32,0x32,0x30,0x37,0x37,0x30,0x35,0x35,0x37,0x30,0x37,0x35,0x30,0x35,
                     92:        0x35,0x35,0x30,0x37,0x37,0x30,0x33,0x31,0x31,0x31,0x31,0x30,0x33,0x0D,0x0A,0x23,
                     93:        0x64,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
                     94:        0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
                     95:        0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x0D,0x0A,
                     96:        0x23,0x4B,0x20,0x34,0x46,0x20,0x35,0x33,0x20,0x34,0x43,0x20,0x30,0x30,0x20,0x34,
                     97:        0x36,0x20,0x34,0x32,0x20,0x34,0x33,0x20,0x35,0x37,0x20,0x34,0x35,0x20,0x35,0x38,
                     98:        0x20,0x30,0x30,0x20,0x30,0x30,0x20,0x30,0x30,0x20,0x30,0x30,0x20,0x30,0x30,0x20,
                     99:        0x30,0x30,0x20,0x30,0x30,0x20,0x30,0x30,0x20,0x30,0x30,0x20,0x30,0x30,0x20,0x30,
                    100:        0x30,0x20,0x30,0x30,0x20,0x30,0x30,0x20,0x35,0x32,0x20,0x30,0x30,0x20,0x30,0x30,
                    101:        0x20,0x34,0x44,0x20,0x35,0x36,0x20,0x35,0x30,0x20,0x30,0x30,0x20,0x40,0x0D,0x0A,
                    102:        0x23,0x45,0x20,0x31,0x38,0x20,0x30,0x31,0x20,0x30,0x30,0x20,0x30,0x36,0x20,0x0D,
                    103:        0x0A,0x23,0x51,0x20,0x34,0x31,0x20,0x34,0x30,0x20,0x34,0x33,0x20,0x34,0x30,0x20,
                    104:        0x34,0x33,0x20,0x34,0x30,0x20,0x0D,0x0A,0x23,0x57,0x20,0x30,0x30,0x20,0x30,0x30,
                    105:        0x20,0x30,0x30,0x20,0x30,0x37,0x20,0x32,0x36,0x20,0x30,0x43,0x20,0x30,0x30,0x20,
                    106:        0x40,0x0D,0x0A,0x23,0x57,0x20,0x30,0x30,0x20,0x30,0x30,0x20,0x30,0x32,0x20,0x30,
                    107:        0x42,0x20,0x32,0x36,0x20,0x30,0x39,0x20,0x30,0x30,0x20,0x40,0x0D,0x0A,0x23,0x57,
                    108:        0x20,0x30,0x30,0x20,0x30,0x30,0x20,0x30,0x41,0x20,0x30,0x46,0x20,0x31,0x41,0x20,
                    109:        0x30,0x39,0x20,0x30,0x30,0x20,0x40,0x0D,0x0A,0x23,0x57,0x20,0x30,0x30,0x20,0x30,
                    110:        0x30,0x20,0x30,0x45,0x20,0x30,0x31,0x20,0x31,0x41,0x20,0x30,0x39,0x20,0x30,0x30,
                    111:        0x20,0x40,0x0D,0x0A,0x23,0x57,0x20,0x30,0x30,0x20,0x30,0x30,0x20,0x30,0x34,0x20,
                    112:        0x30,0x37,0x20,0x32,0x36,0x20,0x30,0x43,0x20,0x30,0x30,0x20,0x40,0x0D,0x0A,0x23,
                    113:        0x57,0x20,0x30,0x30,0x20,0x30,0x30,0x20,0x30,0x43,0x20,0x30,0x42,0x20,0x32,0x36,
                    114:        0x20,0x30,0x39,0x20,0x30,0x30,0x20,0x40,0x0D,0x0A,0x23,0x57,0x20,0x30,0x30,0x20,
                    115:        0x30,0x30,0x20,0x30,0x38,0x20,0x30,0x46,0x20,0x31,0x41,0x20,0x30,0x39,0x20,0x30,
                    116:        0x30,0x20,0x40,0x0D,0x0A,0x23,0x57,0x20,0x30,0x30,0x20,0x30,0x30,0x20,0x30,0x36,
                    117:        0x20,0x30,0x31,0x20,0x31,0x41,0x20,0x30,0x39,0x20,0x30,0x30,0x20,0x40,0x0D,0x0A,
                    118:        0x23,0x4E,0x20,0x46,0x46,0x20,0x30,0x34,0x20,0x30,0x30,0x30,0x20,0x40,0x20,0x2A,
                    119:        0x2E,0x2A,0x40,0x20,0x40,0x20,0x0D,0x0A,0x23,0x44,0x20,0x46,0x46,0x20,0x30,0x31,
                    120:        0x20,0x30,0x30,0x30,0x20,0x40,0x20,0x2A,0x2E,0x2A,0x40,0x20,0x40,0x20,0x0D,0x0A,
                    121:        0x23,0x47,0x20,0x30,0x33,0x20,0x46,0x46,0x20,0x30,0x30,0x30,0x20,0x2A,0x2E,0x41,
                    122:        0x50,0x50,0x40,0x20,0x40,0x20,0x40,0x20,0x0D,0x0A,0x23,0x47,0x20,0x30,0x33,0x20,
                    123:        0x46,0x46,0x20,0x30,0x30,0x30,0x20,0x2A,0x2E,0x50,0x52,0x47,0x40,0x20,0x40,0x20,
                    124:        0x40,0x20,0x0D,0x0A,0x23,0x59,0x20,0x30,0x33,0x20,0x46,0x46,0x20,0x30,0x30,0x30,
                    125:        0x20,0x2A,0x2E,0x47,0x54,0x50,0x40,0x20,0x40,0x20,0x40,0x20,0x0D,0x0A,0x23,0x50,
                    126:        0x20,0x30,0x33,0x20,0x46,0x46,0x20,0x30,0x30,0x30,0x20,0x2A,0x2E,0x54,0x54,0x50,
                    127:        0x40,0x20,0x40,0x20,0x40,0x20,0x0D,0x0A,0x23,0x46,0x20,0x30,0x33,0x20,0x30,0x34,
                    128:        0x20,0x30,0x30,0x30,0x20,0x2A,0x2E,0x54,0x4F,0x53,0x40,0x20,0x40,0x20,0x40,0x20,
                    129:        0x0D,0x0A,0x23,0x4D,0x20,0x30,0x30,0x20,0x30,0x31,0x20,0x30,0x30,0x20,0x46,0x46,
                    130:        0x20,0x43,0x20,0x48,0x41,0x52,0x44,0x20,0x44,0x49,0x53,0x4B,0x40,0x20,0x40,0x20,
                    131:        0x0D,0x0A,0x23,0x4D,0x20,0x30,0x30,0x20,0x30,0x30,0x20,0x30,0x30,0x20,0x46,0x46,
                    132:        0x20,0x41,0x20,0x46,0x4C,0x4F,0x50,0x50,0x59,0x20,0x44,0x49,0x53,0x4B,0x40,0x20,
                    133:        0x40,0x20,0x0D,0x0A,0x23,0x4D,0x20,0x30,0x31,0x20,0x30,0x30,0x20,0x30,0x30,0x20,
                    134:        0x46,0x46,0x20,0x42,0x20,0x46,0x4C,0x4F,0x50,0x50,0x59,0x20,0x44,0x49,0x53,0x4B,
                    135:        0x40,0x20,0x40,0x20,0x0D,0x0A,0x23,0x54,0x20,0x30,0x30,0x20,0x30,0x33,0x20,0x30,
                    136:        0x32,0x20,0x46,0x46,0x20,0x20,0x20,0x54,0x52,0x41,0x53,0x48,0x40,0x20,0x40,0x20,
                    137:        0x0D,0x0A
1.1       root      138: };
                    139: 
1.1.1.2   root      140: 
                    141: /*-----------------------------------------------------------------------*/
1.1.1.9   root      142: /**
                    143:  * Returns given value after constraining it within "min" and "max" values
                    144:  * and making it evenly divisable by "align"
                    145:  */
                    146: int VDI_Limit(int value, int align, int min, int max)
1.1       root      147: {
1.1.1.9   root      148:        value = (value/align)*align;
                    149:        if (value > max)
                    150:        {
                    151:                /* align down */
                    152:                return (max/align)*align;
                    153:        }
                    154:        if (value < min)
                    155:        {
                    156:                /* align up */
                    157:                min += align-1;
                    158:                return (min/align)*align;
                    159:        }
                    160:        return value;
1.1       root      161: }
                    162: 
1.1.1.2   root      163: 
                    164: /*-----------------------------------------------------------------------*/
1.1.1.9   root      165: /**
                    166:  * Set Width/Height/BitDepth according to passed GEMRES_640x480,
                    167:  * GEMRES_800x600, GEMRES_OTHER. Align size when necessary.
                    168:  */
                    169: void VDI_SetResolution(int GEMColor, int WidthRequest, int HeightRequest)
                    170: {
                    171:        /* Color depth */
                    172:        switch (GEMColor)
                    173:        {
                    174:         case GEMCOLOR_2:
                    175:                VDIRes = 2;
                    176:                VDIPlanes = 1;
                    177:                VDIColors = 2;
                    178:                VDICharHeight = 16;
                    179:                break;
                    180:         case GEMCOLOR_4:
                    181:                VDIRes = 1;
                    182:                VDIPlanes = 2;
                    183:                VDIColors = 4;
                    184:                VDICharHeight = 8;
                    185:                break;
                    186:         case GEMCOLOR_16:
                    187:                VDIRes = 0;
                    188:                VDIPlanes = 4;
                    189:                VDIColors = 16;
                    190:                VDICharHeight = 8;
                    191:                break;
                    192:        }
                    193: 
                    194:        /* width needs to be aligned to 16 bytes */
                    195:        VDIWidth = VDI_Limit(WidthRequest, 128/VDIPlanes, MIN_VDI_WIDTH, MAX_VDI_WIDTH);
                    196:        /* height needs to be multiple of cell height */
                    197:        VDIHeight = VDI_Limit(HeightRequest, VDICharHeight, MIN_VDI_HEIGHT, MAX_VDI_HEIGHT);
                    198:        printf("VDI screen: request = %dx%d@%d, aligned result = %dx%d@%d\n",
                    199:               WidthRequest, HeightRequest, VDIPlanes, VDIWidth, VDIHeight, VDIPlanes);
                    200: 
                    201:        /* Write resolution to re-boot takes effect with correct bit-depth */
                    202:        VDI_FixDesktopInf();
                    203: }
                    204: 
1.1       root      205: 
1.1.1.9   root      206: /*-----------------------------------------------------------------------*/
                    207: /**
1.1.1.12! root      208:  * Check VDI call and see if we need to re-direct to our own routines.
        !           209:  * Return true if we've handled the exception, else return false.
1.1.1.9   root      210:  *
1.1.1.12! root      211:  * We enter here with Trap #2, so D1 is pointer to VDI vectors, i.e. Control,
        !           212:  * Intin, Ptsin etc...
1.1.1.9   root      213:  */
1.1.1.10  root      214: bool VDI(void)
1.1       root      215: {
1.1.1.9   root      216:        Uint32 TablePtr = Regs[REG_D1];
                    217:        /*unsigned short int OpCode;*/
1.1       root      218: 
1.1.1.9   root      219:        /* Read off table pointers */
                    220:        Control = STMemory_ReadLong(TablePtr);
                    221:        Intin = STMemory_ReadLong(TablePtr+4);
                    222:        Ptsin = STMemory_ReadLong(TablePtr+8);
                    223:        Intout = STMemory_ReadLong(TablePtr+12);
                    224:        Ptsout = STMemory_ReadLong(TablePtr+16);
                    225: 
                    226:        /*
                    227:        OpCode = STMemory_ReadWord(Control);
                    228:        // Check OpCode
                    229:        // 8 - Text Font
                    230:        if (OpCode==9)
                    231:        {
1.1.1.12! root      232:                return true;
1.1.1.9   root      233:        }
                    234:        */
1.1       root      235: 
1.1.1.9   root      236:        /* Call as normal! */
1.1.1.12! root      237:        return false;
1.1       root      238: }
                    239: 
1.1.1.2   root      240: 
                    241: /*-----------------------------------------------------------------------*/
1.1.1.9   root      242: /**
                    243:  * Modify Line-A structure for our VDI resolutions
                    244:  */
                    245: void VDI_LineA(Uint32 linea, Uint32 fontbase)
1.1       root      246: {
1.1.1.9   root      247:        if (bUseVDIRes)
                    248:        {
                    249:                STMemory_WriteWord(linea-46, VDICharHeight);          /* v_cel_ht */
                    250:                STMemory_WriteWord(linea-44, (VDIWidth/8)-1);         /* v_cel_mx (cols-1) */
                    251:                STMemory_WriteWord(linea-42, (VDIHeight/VDICharHeight)-1);  /* v_cel_my (rows-1) */
                    252:                STMemory_WriteWord(linea-40, VDICharHeight*((VDIWidth*VDIPlanes)/8));  /* v_cel_wr */
                    253: 
                    254:                STMemory_WriteWord(linea-12, VDIWidth);               /* v_rez_hz */
                    255:                STMemory_WriteWord(linea-4, VDIHeight);               /* v_rez_vt */
                    256:                STMemory_WriteWord(linea-2, (VDIWidth*VDIPlanes)/8);  /* bytes_lin */
                    257:                STMemory_WriteWord(linea+0, VDIPlanes);               /* planes */
                    258:                STMemory_WriteWord(linea+2, (VDIWidth*VDIPlanes)/8);  /* width */
                    259:        }
                    260:        LineABase = linea;
                    261:        FontBase = fontbase;
1.1       root      262: }
                    263: 
1.1.1.2   root      264: 
                    265: /*-----------------------------------------------------------------------*/
1.1.1.9   root      266: /**
                    267:  * This is called on completion of a VDI Trap, used to modify return structure for
                    268:  */
1.1       root      269: void VDI_Complete(void)
                    270: {
1.1.1.10  root      271:        Uint16 OpCode;
1.1       root      272: 
1.1.1.9   root      273:        OpCode = STMemory_ReadWord(Control);
                    274:        /* Is 'Open Workstation', or 'Open Virtual Screen Workstation'? */
                    275:        if ( (OpCode==1) || (OpCode==100) )
                    276:        {
                    277:                STMemory_WriteWord(Intout, VDIWidth-1);               /* IntOut[0] Width-1 */
                    278:                STMemory_WriteWord(Intout+1*2, VDIHeight-1);          /* IntOut[1] Height-1 */
                    279:                STMemory_WriteWord(Intout+13*2, VDIColors);           /* IntOut[13] #colors */
                    280:                STMemory_WriteWord(Intout+39*2, 512);                 /* IntOut[39] #available colors */
1.1       root      281: 
1.1.1.9   root      282:                STMemory_WriteWord(LineABase-0x15a*2, VDIWidth-1);    /* WKXRez */
                    283:                STMemory_WriteWord(LineABase-0x159*2, VDIHeight-1);   /* WKYRez */
1.1       root      284: 
1.1.1.9   root      285:                VDI_LineA(LineABase, FontBase);  /* And modify Line-A structure accordingly */
                    286:        }
1.1.1.12! root      287: 
        !           288:        LOG_TRACE(TRACE_OS_VDI, "VDI opcode %hd completed\n", OpCode);
1.1       root      289: }
                    290: 
1.1.1.2   root      291: 
                    292: /*-----------------------------------------------------------------------*/
1.1.1.9   root      293: /**
                    294:  * Save desktop configuration file for VDI, eg desktop.inf(TOS 1.04) or newdesk.inf(TOS 2.06)
                    295:  */
1.1.1.8   root      296: static void VDI_SaveDesktopInf(char *pszFileName, const Uint8 *Script, long ScriptSize)
1.1       root      297: {
1.1.1.9   root      298:        /* Just save file */
1.1.1.12! root      299:        File_Save(pszFileName, Script, ScriptSize, false);
1.1       root      300: }
                    301: 
1.1.1.2   root      302: 
                    303: /*-----------------------------------------------------------------------*/
1.1.1.9   root      304: /**
                    305:  * Modify exisiting ST desktop configuration files to set resolution(keep user settings)
                    306:  */
1.1.1.5   root      307: static void VDI_ModifyDesktopInf(char *pszFileName)
1.1       root      308: {
1.1.1.9   root      309:        long InfSize;
                    310:        Uint8 *pInfData;
                    311:        int i;
                    312: 
                    313:        /* Load our '.inf' file */
                    314:        pInfData = File_Read(pszFileName, &InfSize, NULL);
                    315:        if (pInfData)
                    316:        {
                    317:                /* Scan file for '#E' */
                    318:                i = 0;
                    319:                while (i < (InfSize-8))
                    320:                {
                    321:                        if ((pInfData[i]=='#') && (pInfData[i+1]=='E'))
                    322:                        {
                    323:                                /* Modify resolution */
                    324:                                pInfData[i+7] = '1'+VDIRes;
                    325:                                break;
                    326:                        }
                    327: 
                    328:                        i++;
                    329:                }
                    330: 
                    331:                /* And save */
1.1.1.12! root      332:                File_Save(pszFileName, pInfData, InfSize, false);
1.1.1.9   root      333:                /* Free */
                    334:                free(pInfData);
                    335:        }
1.1       root      336: }
                    337: 
1.1.1.2   root      338: 
                    339: /*-----------------------------------------------------------------------*/
1.1.1.9   root      340: /**
                    341:  * Modify (or create) ST desktop configuration files so VDI boots up in
                    342:  * correct color depth
                    343:  */
1.1       root      344: void VDI_FixDesktopInf(void)
                    345: {
1.1.1.9   root      346:        char *szDesktopFileName, *szNewDeskFileName;
1.1       root      347: 
1.1.1.9   root      348:        if (!GEMDOS_EMU_ON)
                    349:        {
                    350:                /* Can't modify DESKTOP.INF when not using GEMDOS hard disk emulation */
                    351:                return;
                    352:        }
                    353: 
                    354:        szDesktopFileName = malloc(2 * FILENAME_MAX);
                    355:        if (!szDesktopFileName)
                    356:        {
                    357:                perror("VDI_FixDesktopInf");
                    358:                return;
                    359:        }
                    360:        szNewDeskFileName = szDesktopFileName + FILENAME_MAX;
                    361: 
                    362:        /* Create filenames for hard-drive */
                    363:        GemDOS_CreateHardDriveFileName(2, "\\DESKTOP.INF", szDesktopFileName, FILENAME_MAX);
                    364:        GemDOS_CreateHardDriveFileName(2, "\\NEWDESK.INF", szNewDeskFileName, FILENAME_MAX);
                    365: 
                    366:        /* First, check if files exist(ie modify or replace) */
                    367:        if (!File_Exists(szDesktopFileName))
                    368:                VDI_SaveDesktopInf(szDesktopFileName,DesktopScript,sizeof(DesktopScript));
                    369:        VDI_ModifyDesktopInf(szDesktopFileName);
                    370: 
                    371:        if (!File_Exists(szNewDeskFileName))
                    372:                VDI_SaveDesktopInf(szNewDeskFileName,NewDeskScript,sizeof(NewDeskScript));
                    373:        VDI_ModifyDesktopInf(szNewDeskFileName);
1.1.1.5   root      374: 
1.1.1.9   root      375:        free(szDesktopFileName);
1.1       root      376: }

unix.superglobalmegacorp.com

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