home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR2 / DVPG30FS.ZIP / DVSETUP.C < prev    next >
C/C++ Source or Header  |  1993-11-30  |  38KB  |  1,299 lines

  1. /*              Written by Eric Praetzel (C)  [usenet: praetzel@sunee.waterloo.edu]
  2.  *   Feel free to change this but if you feel its a usefull addition please
  3.  *    tell me so that I can include it for general distribution.
  4.  *
  5.  *   This allows the user to pick a video card and test any supported mode.
  6.  *
  7.  *   The S/W will default to the dvpeg.cfg file or the autodetected card if
  8.  *     the file does not exist.
  9.  *   The user can set defaults for the viewing program here.  The defaults
  10.  *    can be changed in dvpeg but can not be saved.
  11.  *
  12.  *   last changed:  Feburary 14, 1993
  13.  */
  14.  
  15. /* text screen is: a title on the top line
  16.                          a video card list (columns 1 to 24)
  17.                          a video mode list in the upper right corner (rows 2 to 12)
  18.                          a selected mode list in the lower right (rows 13 to 24)
  19.         --> if the lists ever exceed the ranges scroll bars will have to be added
  20.  
  21.   THIS IS NOT UPTO DATE - ie DON'T TRUST ANY COMMENTS THAT ARE HERE
  22.  
  23.   - added custom video mode setup
  24.   - added default setting/changing thru view_defaults int in the dvpeg.cfg file
  25.  
  26.   problems
  27.   - can't detect S3 chips & others
  28.  
  29.   - a bad mode number will lock the card in some wierd mode - I don't know how to reset short of the reset key
  30.   - if print onto last line (ie mode list, user mode list) then last line is doubled
  31.   - plotting border has problems on the last char because it causes a CR/LF !!
  32.   - loading the mask string needs a \n termination but this will be added the next time its
  33.         saved (ie you have 2 then 3 then 4 ...  -> so search the string and clip them out - done during loading
  34. */
  35.  
  36. #include <conio.h>
  37. #include <stdio.h>
  38. #include <dos.h>
  39.  
  40. #include "viewdef.h"        /* defines for the viewer */
  41. #include "jvsetup.h"        /* constants and some vars */
  42. #include "view-var.c"        /* variables for dvpeg, vidsetup */
  43. #include "modes.h"
  44.  
  45.  
  46. /* light and dark text colors
  47.  * was MAGENTA, LIGHTMAGENTA
  48.  */
  49.  
  50. #define text_bright LIGHTRED
  51. #define text_dark RED
  52.  
  53. extern   unsigned char cirrus, everex, paradise, tseng, trident;
  54. extern   unsigned char t8900, ativga, aheada, aheadb;
  55. extern   unsigned char oaktech, video7, chipstech, tseng4, genoa;
  56. extern   unsigned char ncr, compaq, vesa;
  57. extern   unsigned char vga512, vga1024;
  58. extern int fifty_lines;
  59.  
  60. int modes_available[number_modes_in_list];        /* list of video modes that match the current card */
  61.  
  62. int mode_lock,
  63.     was_fifty_used;        /* flag to indicate 50 line mode was used - ie therefore use it for DVPEG */
  64.  
  65. int        color_out,
  66.             flood_fill = 0,    /* flood fill mode for testing screen */
  67.             flood_r, flood_g, flood_b,        /* flood fill colors */
  68.             be_quiet,        /* if set then don't print any output ie if this program was called by dvpeg */
  69.             avoid_test;        /* if user says so then avoid test ie paradise card */
  70.  
  71.  
  72. int load_config_vidsetup(char *forced_name);
  73. void borders(int hi_light, int title_color, char *title);
  74. void test_video(int sel_mode);
  75. void help_msg(int which_screen);
  76. void open_window(int width, int height);
  77. int config_video(void);
  78. void video_fill(int gr_row, unsigned int width, unsigned char data);
  79.  
  80.  
  81.  
  82. void insert_in_user_list(int mode, int only_one)
  83. {
  84. int    i;
  85. int    ins_loc;                /* location to insert a new item into the users list of working modes */
  86.  
  87. /*
  88.  * if it exists then return without insertion
  89.  */
  90. for (i = 0; i < number_modes_in_list; i++)
  91.     if (ok_mode[i] >= 0){
  92.         if (ok_mode[i] == mode) return;        /* exit if its in the list already */
  93.         /* if the size already exists then do not insert (if requested) */
  94.         if ((video_cards[ok_mode[i]].y_size == video_cards[mode].y_size) &&
  95.         only_one != 0) return;
  96.         }
  97.  
  98. ins_loc = 0;
  99. /* first find the position of a mode that is non 0 and smaller size than the selected */
  100. for (i = 0; i < number_modes_in_list; i++)
  101.     if (ok_mode[i] >= 0){
  102.         if (video_cards[ok_mode[i]].resolution < video_cards[mode].resolution)
  103.             continue;
  104.         if (video_cards[ok_mode[i]].resolution > video_cards[mode].resolution){
  105.             ins_loc = i;
  106.             break;
  107.             }
  108.         /* case of empty list or first item is bigger than that being inserted */
  109.         if ((video_cards[ok_mode[i]].y_size > video_cards[mode].y_size) &&
  110.                 (video_cards[mode].y_size != 0)){
  111.             ins_loc = i;
  112.             break;
  113.             }
  114.         /* keep going thru list until we hit a bigger item */
  115.         if ((video_cards[ok_mode[i]].y_size < video_cards[mode].y_size) &&
  116.                 (video_cards[mode].y_size != 0))
  117.             ins_loc = i + 1;
  118.         }
  119.  
  120. /* inserting to a full list does nothing */
  121. i = number_modes_in_list;
  122. while( --i > ins_loc)
  123.     ok_mode[i] = ok_mode[i-1];
  124.  
  125. /* now insert it - watchout for inserting at top + 1*/
  126. if (ins_loc < number_modes_in_list)
  127.     ok_mode[ins_loc] = mode;
  128. }
  129.  
  130.  
  131.  
  132. /* raw string fill of video memory but watch out for bank crossings
  133.  *
  134.  * video_mem is the address (in the 1M bank) to start at calculated by gr_col and gr_row the row and column address
  135.  * width is the amount of memory (bytes) to copy
  136.  */
  137.  
  138. void video_fill(int gr_row, unsigned int width, unsigned char data)
  139. {
  140. unsigned int difference;
  141. unsigned long video_mem;
  142. extern int maxx;
  143.  
  144.     video_mem = (unsigned long) gr_row * maxx;
  145.  
  146. /* set memory bank */
  147.     _AX = video_mem >> 16;
  148.     newbank();
  149.  
  150. /* basic size test to see if it is only one line
  151.  *  also account for offset in the drawing if the image is centered
  152.  */
  153.     if (width > maxx) width = maxx;
  154.  
  155. /* need to check memory bank crossing */
  156.     if ((unsigned long) (video_mem & 0x0ffff) + width > 0xffff){
  157.         difference = (0xffff - (unsigned int) video_mem) + 1;
  158.         _fmemset((void far *) MK_FP(0xA000, (unsigned) video_mem), data, (size_t) difference);
  159.         _AX = (video_mem >> 16) + 1;
  160.         newbank();
  161.         _fmemset((void far *) MK_FP(0xA000, 0), data, (size_t) width - difference);
  162.         }
  163.     else
  164.         _fmemset((void far *) MK_FP(0xA000, (unsigned) video_mem), data, (size_t) width);
  165. }
  166.  
  167.  
  168.  
  169.  
  170. /*
  171.  * do an autodetect and setup for video card
  172.  */
  173.  
  174. int config_video(void)
  175. {
  176. int svga, i, ins_loc, video_resolution;
  177.  
  178. svga=whichvga();
  179.  
  180. ins_loc = 0;        /* setup index into structure holding video modes */
  181.  
  182.     if (svga){
  183.         if (aheada == 1) card_id = 0;
  184.         if (aheadb == 1) card_id = 1;
  185.         if (ativga == 1) card_id = 2;
  186.         if (chipstech == 1) card_id = 3;
  187.         if (everex == 1) card_id = 4;
  188.         if (oaktech == 1) card_id = 5;
  189.         if (genoa == 1) card_id = 6;
  190.         if (ncr == 1) card_id = 7;
  191.         if (paradise == 1) card_id = 8;
  192.         if (trident == 1 || t8900 == 1) card_id = 9;
  193.         if (tseng == 1)
  194.             if (tseng4 == 1) card_id = 11;
  195.             else card_id = 10;
  196.         if (video7 == 1) card_id = 12;
  197.         if (cirrus == 1) card_id = 13;
  198.         if (compaq == 1) card_id = 14;
  199.         if (vesa == 1) card_id = 15;
  200.         if (card_id == 0 && aheada != 1) card_id = 16;        /* S3 chips how detect ??? */
  201. /* how detect Diamond Speedstar 24X ???? */
  202.  
  203. /* only add the modes if we have enough memory */
  204. /* they are still displayed and can be added by the user if the memory detection fails */
  205.         for (video_resolution = SVGA_24_bit; video_resolution >= VGA; video_resolution--){
  206.             i = -1;
  207.             while (ins_loc < number_modes_in_list && video_cards[++i].card_number >= 0){
  208.                 if ((video_cards[i].card_number == card_id) && video_cards[i].x_size > 0 && video_cards[i].resolution == video_resolution)
  209.                     if    ((vga1024 == 1 && ((long)video_cards[i].x_width * video_cards[i].y_size <= (long)1024 * 1024)) ||
  210.                         (vga512 == 1 && ((long)video_cards[i].y_size * video_cards[i].x_width <= (long)512 * 1024)) ||
  211.                         (vga1024 == vga512 == 0 && ((long)video_cards[i].y_size * video_cards[i].x_width <= (long)128 * 1024)))
  212.                             insert_in_user_list(i, video_resolution == VGA);    /* add all modes but VGA ones that are the same size as an existing mode */
  213.                 }
  214.             }
  215.         }
  216.     else{
  217.         if (be_quiet == 0){
  218.             printf("No super VGA video card detected.\n");
  219.             printf("However, this program supports several that that it can't detect.\n");
  220.             printf("Defaulting to VGA modes.\n");
  221.             printf("Hit any key.\n");
  222.             getch();
  223.             }
  224. /* don't fail, VGA modes are assumed and will be added later */
  225. /*        return 0;        return this to fail */
  226.         card_id = 19;    /* rigged for plain VGA */
  227.         }
  228.     i = -1;
  229.     while (ins_loc < number_modes_in_list && video_cards[++i].card_number >= 0){
  230.         if ((video_cards[i].card_number == 19) && video_cards[i].x_size > 0)
  231.             insert_in_user_list(i,video_cards[i].resolution == VGA);
  232.     }
  233. return 1;
  234. }
  235.  
  236.  
  237.  
  238. /* draw the dividers on the screen for the text mode video selection
  239.      hi_light is the flag to draw a bright border around (active area)
  240.   */
  241.  
  242. void test_video(int sel_mode)
  243. {
  244. int i,
  245.         range,        /* range of colors ie 5 bits for hi_color, 6 for Super VGA */
  246.         x, y,
  247.         x_size,
  248.         y_size,
  249.         video_resolution,
  250.         shift,
  251.         maximum_index;
  252. union REGS regs;
  253.  
  254. x_size = video_cards[sel_mode].x_size;
  255. y_size = video_cards[sel_mode].y_size;
  256.  
  257. forcevga(video_cards[sel_mode].card_number);
  258. svgamode(video_cards[sel_mode].set_ax, video_cards[sel_mode].set_bx, video_cards[sel_mode].x_width, video_cards[sel_mode].card_number);
  259.  
  260. video_resolution = video_cards[sel_mode].resolution;
  261.  
  262. shift = 0;
  263. switch(video_resolution){
  264.     case VGA:
  265.         range = 64;
  266.         shift = 2;
  267.         break;
  268.     case SVGA:
  269.         range = 64;
  270.         break;
  271.     case SVGA_24_bit:
  272.         range = 256;
  273.         break;
  274.     case SVGA_16_bit:
  275.     case SVGA_15_bit:
  276.         range = 32;
  277.         break;
  278.     }
  279.  
  280. maximum_index = 0xff;        /* display 256 colors */
  281.  
  282. if (flood_fill == 0){
  283.     for (i=0; i<256; i++){
  284.         palbuf[i][0] = ((i << shift) >> 0) % range;
  285.         palbuf[i][1] = ((i << shift) >> 1) % range;
  286.         palbuf[i][2] = ((i << shift) >> 2) % range;
  287.         }
  288.     }
  289. else{
  290.     maximum_index = 0;        /* only display the first color */
  291.     /* reset all other colors to the opposite for a more thorough test */
  292.     switch(video_resolution){
  293.         case VGA:
  294.             shift = 1;
  295.             break;
  296.         case SVGA:
  297.             shift = 1;
  298.             break;
  299.         case SVGA_24_bit:
  300.             shift = 3;
  301.             break;
  302.         case SVGA_16_bit:
  303.         case SVGA_15_bit:
  304.             shift = 0;
  305.             break;
  306.         }
  307.     palbuf[0][0] = flood_r << shift;
  308.     palbuf[0][1] = flood_g << shift;
  309.     palbuf[0][2] = flood_b << shift;
  310.     for (i=1; i<256; i++){
  311.         palbuf[i][0] = (31 - flood_r) << shift;
  312.         palbuf[i][1] = (31 - flood_g) << shift;
  313.         palbuf[i][2] = (31 - flood_b) << shift;
  314.         }
  315.     }
  316.  
  317. if (video_resolution <= SVGA){
  318. /* If using only VGA then set the EGA pallet to point index properly into the SVGA one */
  319.     if (video_resolution == VGA)
  320.         for (i = 0; i < 16; i++){
  321.             regs.h.bl = i;
  322.             regs.h.bh = i;
  323.             regs.x.ax = 0x1000;
  324.             int86(0x10, ®s, ®s);
  325.             }
  326.     setmany(palbuf,0,256);
  327.     }
  328.  
  329. for(y=0; y < y_size; y++){
  330.     i = y & maximum_index;        /* ie % 256;*/
  331.         switch(video_resolution){
  332.             case SVGA_24_bit:
  333.                 for (x=0; x < x_size; x++)
  334.                     point_24(x, y, (palbuf[i][2] << 16) + (palbuf[i][1] << 8) + palbuf[i][0]);
  335.                 break;
  336.             case SVGA_16_bit:
  337.                 for (x=0; x < x_size; x++)
  338.                     point_wide(x,y, palbuf[i][2]+(palbuf[i][1]<<5) + (palbuf[i][0] << 11));
  339.                 break;
  340.             case SVGA_15_bit:
  341.                 for (x=0; x < x_size; x++)
  342.                     point_wide(x,y, palbuf[i][2]+(palbuf[i][1]<<5) + (palbuf[i][0] << 10));
  343.                 break;
  344.             case SVGA:
  345.                 video_fill(y, x_size, i);
  346.                 break;
  347.             case VGA:
  348.                 for (x=0; x < x_size; x++)
  349.                     put16Pixel(x, y, i % 16);
  350.                 break;
  351.             }
  352.     if (kbhit()) break;
  353.     }
  354.     getch();
  355.  
  356. rtn_video();
  357. }
  358.  
  359.  
  360.  
  361. /*
  362.  * return 1 if the mode or card is in the user list
  363.  *  the card value must be set, the index value can be -1 so that just
  364.  *  the existance of the card in the user list is checked
  365.  *  the index is the index into the list of modes and is independant of
  366.  *   card and mode
  367.  */
  368.  
  369. int mode_inlist(int card, int index)
  370. {
  371. int i, j;
  372.  
  373. for (i = 0; i < number_modes_in_list; i++)
  374.     if ((j = ok_mode[i]) >= 0){
  375.         if (j == index) return 1;
  376.         if ((video_cards[j].card_number == card) && (index < 0)) return 1;
  377.         }
  378. return 0;
  379. }
  380.  
  381.  
  382.  
  383. /* put a window up in the center of the screen
  384.  *    - ask about panning, video mode ....
  385.  *    - don't worry what is under it because the image will be drawn
  386.  */
  387.  
  388. void open_window(int width, int height)
  389. {
  390. char char_is;
  391. struct text_info ti;
  392. int i;
  393.  
  394. window(12, 4, 12 + width, 4 + height);
  395. clrscr();
  396.  
  397.  /*  border */
  398.  
  399. gettextinfo(&ti);
  400.  
  401. textcolor(WHITE);
  402. char_is = 219;            /* solid block */
  403.  
  404. for (i=1; i <= (ti.winright-ti.winleft); i++){        /* should go 1 count more */
  405.     gotoxy(i, 1);
  406.     putch(char_is);
  407.     gotoxy(i, ti.winbottom - ti.wintop + 1);
  408.     putch(char_is);
  409.     }
  410. for (i=2; i <= (ti.winbottom-ti.wintop); i++){
  411.     gotoxy(1, i);
  412.     putch(char_is);
  413.     gotoxy(ti.winright - ti.winleft, i);        /* had to sub +1 */
  414.     putch(char_is);
  415.     }
  416. window(14, 6, 10 + width, 2 + height);
  417. }
  418.  
  419.  
  420.  
  421. void help_msg(int which_screen)
  422. {
  423. int length;
  424. char text[80];
  425.  
  426. window(5, 1, 75, 3);        /* print help stuff */
  427. switch(which_screen){
  428.     case 0:
  429.             strcpy(text, "   test (space), DELete, locK, ESC    ");
  430.             break;
  431.     case 1:
  432.             strcpy(text, "test (space), INSert, DELete, RTN, ESC");
  433.             break;
  434.     case 2:
  435.             strcpy(text, "        choose (RTN), exit (ESC)      ");
  436.             break;
  437.     }
  438. length = strlen(text);
  439. gotoxy(40 - length / 2, 1);
  440. textcolor(LIGHTRED);
  441. cprintf("%s", text);
  442. textcolor(WHITE);
  443. }
  444.  
  445.  
  446.  
  447. /*
  448.  * toss a border around the current window
  449.  */
  450.  
  451. void borders(int hi_light, int title_color, char *title)
  452. {
  453. int i, text_start, text_end, width, height;
  454. char char_is, char_line[string_len+1];
  455. struct text_info ti;
  456.  
  457. gettextinfo(&ti);
  458.  
  459. if (hi_light){
  460.     textcolor(WHITE);
  461.     char_is = 219;            /* solid block */
  462.     }
  463. else{
  464.     textcolor(LIGHTGRAY);
  465.     char_is = 177;            /* 1/2 dense block */
  466.     }
  467.  
  468. width = ti.winright - ti.winleft;
  469. height = ti.winbottom - ti.wintop;
  470. i = strlen(title);
  471. text_start = (width - i) / 2;
  472. text_end = text_start + i;
  473.  
  474. for (i=1; i <= width; i++){        /* should go 1 count more */
  475.     if (i < text_start || i > text_end){
  476.         gotoxy(i, 1);
  477.         putch(char_is);
  478.         }
  479.     gotoxy(i, height + 1);
  480.     putch(char_is);
  481.     }
  482. for (i=2; i <= height; i++){
  483.     gotoxy(1, i);
  484.     putch(char_is);
  485.     gotoxy(width, i);        /* had to sub +1 */
  486.     putch(char_is);
  487.     }
  488.  
  489. textcolor(title_color);
  490. if (text_start > 0 && title != NULL){
  491.     gotoxy(text_start, 1);
  492.     cputs(title);
  493.     }
  494. }
  495.  
  496.  
  497.  
  498. /*
  499.  * draw a list of the video modes for a particular card
  500.  */
  501.  
  502. void modes_for_a_card(int num_lines, int sel_mode)
  503. {
  504. int i, j, text_color;
  505.  
  506. cprintf("  X  , Y   ,  mode , #       X   ,  Y  ,  mode , #  \n\r");
  507.  
  508. i = -1;
  509. while (modes_available[++i] >= 0){
  510.     j = modes_available[i];
  511.  
  512.     text_color = WHITE;
  513.     if (mode_inlist(-1, j)) text_color = text_bright;
  514.  
  515.     if (modes_available[sel_mode] == j) textbackground(LIGHTGRAY);
  516.     textcolor(text_color);
  517.  
  518.     cprintf(" %4i %4i %6i  ",video_cards[j].x_size,video_cards[j].y_size,
  519.         video_cards[j].set_ax);
  520.     switch(video_cards[j].resolution){
  521.         case VGA:
  522.             cprintf(" 16");
  523.             break;
  524.         case SVGA:
  525.             cprintf("256");
  526.             break;
  527.         case SVGA_15_bit:
  528.             cprintf("32k");
  529.             break;
  530.         case SVGA_16_bit:
  531.             cprintf("64k");
  532.             break;
  533.         case SVGA_24_bit:
  534.             cprintf("16M");
  535.             break;
  536.         }
  537.     if ((i % 2) == 0) cprintf("     ");
  538.     else                    cprintf("\r\n");
  539.     textcolor(WHITE);
  540.     textbackground(BLACK);
  541.     }
  542. }
  543.  
  544.  
  545.  
  546.  
  547. /*
  548.  * print the list of video modes in the user list
  549.  */
  550.  
  551. void print_user_modes(int num_lines, int sel_mode, int sel_mode_list)
  552. {
  553. int i, j, text_color;
  554.  
  555. cprintf(" Video Card,       X,    Y,    AX,    BX,  res.\n\r");
  556. any_hi_color = 0;
  557.  
  558. /* print the list to a maximum of 9 lines or modes */
  559.  
  560.  
  561. for (i=0; i < number_modes_in_list; i++)
  562.     if (ok_mode[i] >= 0){
  563. /* check for any hi_color modes and set flag */
  564.         if ( video_cards[ok_mode[i]].resolution != SVGA)
  565.             any_hi_color = 1;
  566.     /* temp for card # */
  567.         j = ok_mode[i];
  568.         text_color = WHITE;
  569.         if (video_cards[j].y_size == mode_lock) text_color = YELLOW;
  570.         if (i == sel_mode_list)
  571.             textbackground(LIGHTGRAY);
  572.         textcolor(text_color);
  573.  
  574.             /* temp for real card / mode # if its custom */
  575.         cprintf(" %14s   %4i  %4i %5i %5i  %8s\r\n",video_card_names[video_cards[j].card_number],
  576.             video_cards[j].x_size,
  577.             video_cards[j].y_size,
  578.             video_cards[j].set_ax,
  579.             video_cards[j].set_bx,
  580.             card_type[video_cards[j].resolution]);
  581.         textcolor(WHITE);
  582.         textbackground(BLACK);
  583.         }
  584. }
  585.  
  586.  
  587.  
  588. /*
  589.  * main program
  590.  */
  591.  
  592. int main(int argc, char *argv[])
  593. {
  594. static int i,
  595.             text_color,            /* color of text being drawn */
  596.             list_line_length,    /* length in line of the mode lists, 3 if 24 line, 15 if 43 line ie show more of the lists */
  597.             temp,                    /* temp var for things */
  598.             erase_screen,        /* flag screen erase before redraw */
  599.             exit_now,            /* exit flag for main loop */
  600.             sel_card,            /* pointer into array for selected video card */
  601.             sel_mode,            /* pointer into array for selected mode */
  602.             sel_mode_list,        /* currently item in selected mode list pointed to */
  603.             some,                    /* a check to make sure that the user mode list is not empty - otherwise the prog locs! */
  604.             update_file,        /* flag that cfg info has change */
  605.             card_mode_oklist;        /* flag for oklist (0) or card (2) or mode (1) in selection*/
  606. static int cmd;
  607. static struct text_info ti;
  608. static char temp_char[80];
  609.  
  610. extern unsigned char _video;
  611. unsigned char *ptr;
  612.  
  613. FILE *config_file;
  614. unsigned int disk_tmp;
  615. char *forced_config_ptr;
  616.  
  617.  /* if there is an arguement check to see if it is a config file with path
  618.   * or a -quiet arguement meaning don't print anything
  619.   */
  620. be_quiet = 0;
  621. if (argc > 1){
  622.     if (*argv[1] == '-')
  623.         be_quiet = 1;
  624.     else
  625.         forced_config_ptr = argv[1];
  626.     }
  627. else
  628.     forced_config_ptr = NULL;
  629.  
  630. if (get_video() != 0){        /* preserve the current video mode for exit */
  631.     was_fifty_used = fifty_line_text;
  632.     }
  633. else{
  634.     was_fifty_used = 0;
  635.     }
  636.  
  637. /* get the dir that we were booted in
  638.  * if the config file is found here then it will be written back here
  639.  * this solves the problem of having the executable on a read-only media
  640.  */
  641. _dos_getdrive(&disk_tmp);
  642.  
  643. strcpy(file_path, "C:\\");
  644. file_path[0] = disk_tmp + 'A' - 1;
  645. getcurdir(disk_tmp, file_path + 3);
  646. if (strlen(file_path) > 3)   /* watch out for root because its X:/ already */
  647. strcat(file_path, "\\");
  648. strcpy(original_path, file_path);
  649.  
  650. max_file_records = init_max_file_records;        /* nice default */
  651.  
  652. /* get current text mode + info -> not Int 10 function 0xf does not work reliably */
  653. /* this comes out of the BIOS space
  654. /* --- this is not complete.  Borland C code will not recognize 132 column text
  655. /*  modes and will do very strange things with them when you setup the text mode
  656. /*  yourself without going thru the Borland code */
  657.  
  658. text_width = peek(0x40, 0x4a);
  659. text_height = peekb(0x40, 0x84) + 1;
  660. text_mode_number = peekb(0x40, 0x49);
  661.  
  662. ptr = &_video;
  663. *(ptr+3) = text_height;
  664. *(ptr+7) = text_height + 1;
  665.  
  666. if ((list_line_length = text_height - 25) < 3) list_line_length = 0;
  667.  
  668. for (i = 0; i <= number_modes_in_list; i++)
  669.     ok_mode[i] = -1;                    /* set to not filled */
  670.  
  671. /* set up name for config file (dvpeg.cfg) and assume its in the same dir as vidsetup.exe */
  672. strcpy(config_name, argv[0]);
  673. /* change vidsetup.exe to dvpeg.exe */
  674. for (i=strlen(config_name); i >= 0 && config_name[i] != '\\'; i--);
  675. config_name[i+1] = 0;                    /* knock off file and add dvpeg.cfg to path in load_config*/
  676. strcpy(code_path, config_name);        /* save path that the prog was booted in */
  677.  
  678. /* does the dvpeg.cfg file exist? if not do auto detect*/
  679. if ( !load_config_vidsetup(forced_config_ptr) ){
  680.     if (be_quiet == 0){
  681.         printf("If you have a 1M Paradise (or compatable) card then you will want to\n");
  682.         printf(" avoid the autodetection test\n");
  683.         printf("\nDo you wish to avoid the test (Y / N)\n");
  684.         if (toupper(getch()) == 'Y')
  685.             avoid_test = 1;
  686.         }
  687.  
  688.     if (avoid_test != 1)
  689.         if ( config_video() )    /* is there super VGA ?? */
  690.             update_file = 1;
  691.     }
  692. sel_card = card_id;
  693. sel_mode = sel_mode_list = 0;            /* default to lowest resolution, card detected */
  694.  
  695. /* sel_mode points into the list of modes_available[] which is made from
  696.     the list of all modes (ie the selected ones match the current card)
  697.     */
  698.  
  699. rtn_video();    /* back to text mode */
  700.  
  701. gettextinfo(&ti);
  702.  
  703. card_mode_oklist = 2;        /* start with card menu*/
  704.  
  705. erase_screen = 0;
  706. clrscr();
  707. textcolor(YELLOW);
  708. gotoxy(1,1);
  709. cprintf("Video Setup (F1 - help)                                             Dvpeg");
  710.  
  711. /* select a video card and mode then test it or update the user mode list */
  712. /* note right side has to be wider to prevent CR/LF on plotting char 1! */
  713.  
  714. exit_now = 0;
  715.  
  716. while (be_quiet == 0 && exit_now == 0){
  717.     _setcursortype(_NOCURSOR);            /* hide the cursor*/
  718.     help_msg(card_mode_oklist);
  719.     window(1, 2, 24, 25);
  720.     if (erase_screen){
  721.         clrscr();
  722.         erase_screen = 0;
  723.         }
  724. /* setup the borders on the screen with video card hi_light */
  725.     borders(card_mode_oklist == 2, YELLOW, "Video cards");
  726.     window(2, 3, 23, 24);
  727.     gotoxy(1,1);
  728.     textcolor(WHITE);
  729.     for (i=0; i < number_VGA_cards; i++){
  730.         text_color = WHITE;
  731.         if (mode_inlist(i, -1)){
  732.             text_color = text_dark;
  733.             if (card_mode_oklist == 2)    text_color = text_bright;
  734.             }
  735.         if (i == sel_card) textbackground(LIGHTGRAY);
  736.         textcolor(text_color);
  737.         cprintf(" %s\r\n", video_card_names[i]);
  738.         textcolor(WHITE);
  739.         textbackground(BLACK);
  740.         }
  741.  
  742.     i = -1;
  743.     temp = 0;
  744.     while (temp < number_modes_in_list && video_cards[++i].card_number >= 0)
  745.         if (video_cards[i].card_number == sel_card && video_cards[i].x_size > 0)
  746.             modes_available[temp++] = i;
  747.     for (; temp < number_modes_in_list; temp++)    /* clear the rest of the list */
  748.         modes_available[temp] = -1;
  749.  
  750. /*    window(25, 2, 80, 25);        /* plot video mode available THIS IS THE FULL TEXT SPACE AVAILABLE */
  751.  
  752. /* print video mode list as a short or full list */
  753.  
  754.     i = 1;
  755.     switch(card_mode_oklist){
  756.         case 2:
  757.         case 1:
  758.             window(25, 2, 80, 22);
  759.             sprintf(temp_char, "Video Modes for %14s",video_card_names[sel_card]);
  760.             borders(card_mode_oklist == 1, YELLOW, temp_char);
  761.             window(26, 3, 78, 21);    /* full menu */
  762.             break;
  763.         case 0:
  764.             window(25, 2, 80, 4 + list_line_length);
  765.             sprintf(temp_char, "Video Modes for %14s",video_card_names[sel_card]);
  766.             borders(card_mode_oklist == 1, YELLOW, temp_char);
  767.             if (list_line_length)
  768.                 window(26, 3, 78, 3 + list_line_length);
  769.             else
  770.                 i = 0;
  771.         }
  772.     if (i){
  773.         clrscr();
  774.         gotoxy(1,1);
  775.         textcolor(WHITE);
  776.         modes_for_a_card(17, sel_mode);
  777.         }
  778.  
  779.     i = 1;
  780.     switch(card_mode_oklist){
  781.         case 2:
  782.         case 1:
  783.             window(25, 23, 80, 25 + list_line_length);
  784.             borders(card_mode_oklist == 0, YELLOW," User Selected Video Modes");
  785.             if (list_line_length)
  786.                 window(26, 24, 78, 24 + list_line_length);
  787.             else
  788.                 i = 0;
  789.             break;
  790.         case 0:
  791.             window(25, 5 + list_line_length, 80, 25 + list_line_length);
  792.             borders(card_mode_oklist == 0, YELLOW," User Selected Video Modes");
  793.             window(26, 6 + list_line_length, 78, 24 + list_line_length);
  794.         }
  795.     if (i){
  796.         clrscr();
  797.         gotoxy(1,1);
  798.         textcolor(WHITE);
  799.         print_user_modes(20, sel_mode, sel_mode_list);
  800.         }
  801.  
  802.     cmd = get_key();
  803.     if (cmd == escape){
  804.         if (card_mode_oklist == 2) exit_now = 1;
  805.         else card_mode_oklist++;                    /* RTN selects mode and/or exit */
  806.         cmd = 0;
  807.         }
  808.     if (cmd == RTN){
  809.         card_mode_oklist--;        /* ESC hops to card select */
  810.         cmd = 0;                        /* only change menu, don't act on cmd */
  811.         }
  812.     if (cmd == 'T' || cmd == 't'){        /* create custom text mode */
  813.         open_window(40,10);
  814.         gotoxy(1,1);
  815.         cprintf("What is the mode number (%i)?",text_mode_number);
  816.         gotoxy(1,2);
  817.         if (get_line(temp_char, 4) <= 1) goto break_1;
  818.         sscanf(temp_char, "%i", &text_mode_number);
  819.         gotoxy(1,3);
  820.         cprintf("What is the text height (%i)?", text_height);
  821.         gotoxy(1,4);
  822.         if (get_line(temp_char, 4) <= 1) goto break_1;
  823.         sscanf(temp_char, "%i", &text_height);
  824.         gotoxy(1,5);
  825.         cprintf("What is the text width (%i)?", text_width);
  826.         if (get_line(temp_char, 4) <= 1) goto break_1;
  827.         sscanf(temp_char, "%i", &text_width);
  828.  
  829.     break_1:
  830.         update_file = 1;
  831.         erase_screen = 1;
  832.         cmd = 0;
  833.         }
  834.     if (cmd == 'C' || cmd == 'c'){        /* create a special mode using the current card */
  835.         open_window(42,11);
  836.  
  837.         /* cmd points to the next available spot or the top */
  838.         i = cmd = -1;
  839.         while (video_cards[++i].card_number >= 0)
  840.             if (video_cards[i].x_size == 0 && cmd < 0)
  841.                 cmd = i;
  842.  
  843.         if (cmd < 0) cmd = i - 1;        /* set to top if its full ie you can always overwrite the last entry */
  844.         /* insert at index "cmd" */
  845.  
  846.         video_cards[cmd].card_number = sel_card;
  847.  
  848.         gotoxy(1,1);
  849.         cprintf("What is the X size: ");
  850.         if (get_line(temp_char, 4) <= 1) goto break_out;
  851.         sscanf(temp_char, "%i", &video_cards[cmd].x_size);
  852.  
  853.         gotoxy(1,2);
  854.         cprintf("Y size: ");
  855.         if (get_line(temp_char, 4) <= 1) goto break_out;
  856.         sscanf(temp_char, "%i", &video_cards[cmd].y_size);
  857.  
  858.         gotoxy(1,3);
  859.         cprintf("0,1,2,3,4 = 4,8,15,16,24 bit): ");
  860.         if (get_line(temp_char, 4) <= 1) goto break_out;
  861.         sscanf(temp_char, "%i", &video_cards[cmd].resolution);
  862.  
  863.         gotoxy(1,4);
  864.         cprintf("mode number (ax in decimal): ");
  865.         if (get_line(temp_char, 4) <= 1) goto break_out;
  866.         sscanf(temp_char, "%i", &video_cards[cmd].set_ax);
  867.  
  868.         gotoxy(1,5);
  869.         cprintf("BX in decimal (0 if not used): ");
  870.         if (get_line(temp_char, 4) <= 1) goto break_out;
  871.         sscanf(temp_char, "%i", &video_cards[cmd].set_bx);
  872.  
  873.         gotoxy(1,6);
  874.         video_cards[cmd].x_width = video_cards[cmd].x_size * (1 + video_cards[cmd].resolution);
  875.         if (video_cards[cmd].resolution >= 2) video_cards[cmd].x_width = video_cards[cmd].x_size * video_cards[cmd].resolution;
  876.  
  877.         cprintf("Line width in bytes (est. %5i)", video_cards[cmd].x_width);
  878.         gotoxy(1,7);
  879.         if (get_line(temp_char, 4) <= 1) goto break_out;
  880.         sscanf(temp_char, "%i", &video_cards[cmd].x_width);
  881.  
  882.         insert_in_user_list(cmd, 0);
  883.  
  884.     break_out:
  885.         update_file = 1;
  886.         erase_screen = 1;
  887.         cmd = 0;
  888.         }
  889.     if (cmd == F1){        /* help screen */
  890.         open_window(55, 15);
  891.         cprintf("Enter - hop in one level\r\n");
  892.         cprintf("ESC - hop out one level\r\n");
  893.         cprintf("arrows - move around (usually up/down)\r\n");
  894.         cprintf("T - custom Text mode\r\n");
  895.         cprintf("C - Custom video using selected mfg. card\r\n");
  896.         cprintf("F - toggle/set color to fill screen with\r\n");
  897.         cprintf("F1 - help screen\r\n");
  898.         cprintf("F3 - change viewing defaults\r\n");
  899.         cprintf("F4 - change file mask\r\n");
  900.         cprintf("F5 - change sort method\r\n");
  901.         cprintf("F6 - change defalt file path\r\n");
  902.         cprintf("F7 - change other defaults\r\n");
  903.         switch (card_mode_oklist){
  904.             case 0:
  905.                 cprintf("K - lock a video resolution for viewing\n");
  906.                 break;
  907.             case 1:
  908.                 cprintf("any other key = test mode\n");
  909.                 break;
  910. /*            case 2:*/
  911.             }
  912.         erase_screen = 1;
  913.         cmd = 0;
  914.         getch();
  915.         }
  916.         if (cmd == 'f'|| cmd == 'F'){        /* setup test pattern for a flood-fill of one user defined color */
  917.             flood_fill ^= 1;
  918.             if (flood_fill != 0){
  919.                 open_window(45, 9);
  920.                 cprintf("Picks the colors for filling the screen\r\n");
  921.                 cprintf("Red[0..31] = ");
  922.                 scanf("%i", &flood_r);
  923.                 cprintf("\rGreen[0..31] = ");
  924.                 scanf("%i", &flood_g);
  925.                 cprintf("\rBlue[0..31] = ");
  926.                 scanf("%i", &flood_b);
  927.                 erase_screen = 1;
  928.                 }
  929.             cmd = 0;
  930.             }
  931.     if (cmd == F3){        /* lets change the defaults */
  932.         do{
  933.             open_window(46,15);
  934.             show_defaults(1);
  935.             }while (    change_defaults(getch()) );
  936.         cmd = 0;
  937.         update_file = 1;
  938.         erase_screen = 1;
  939.         }
  940.     if (cmd == F4){        /* F4 - change file mask */
  941.         open_window(40, 10);
  942.         if(get_file_masks())
  943.             update_file = 1;
  944.         erase_screen = 1;
  945.         cmd = 0;
  946.         }
  947.     if (cmd == F5){
  948.         open_window(40,10);
  949.         cprintf("Sort order is: ");
  950.             switch (sort_mode){
  951.                 case NONE:
  952.                                 cprintf("unsorted");
  953.                                 break;
  954.                 case FF_NAME:
  955.                                 cprintf("by name");
  956.                                 break;
  957.                 case FF_SIZE:
  958.                                 cprintf("by size");
  959.                                 break;
  960.                 case FF_DATE:
  961.                                 cprintf("by date");
  962.                                 break;
  963.                 }
  964.         cprintf("\r\nchoose: Unsorted, Name, Size, Date\r\n");
  965.         i = getch();
  966.         switch (i){
  967.             case 'N':
  968.             case 'n':   sort_mode = FF_NAME;
  969.                             break;
  970.             case 'U':
  971.             case 'u':
  972.                             sort_mode = NONE;
  973.                             break;
  974.             case 'S':
  975.             case 's':
  976.                             sort_mode = FF_SIZE;
  977.                             break;
  978.             case 'D':
  979.             case 'd':
  980.                             sort_mode = FF_DATE;
  981.                             break;
  982.             }
  983.         erase_screen = 1;
  984.         update_file = 1;
  985.         cmd = 0;
  986.         }
  987.  
  988.     if (cmd == F6){        /* F6 - change default file path */
  989.         open_window(50, 10);
  990.         cprintf("The file path is: %25s\r\n\n", default_path);
  991.         cprintf("What is the new path (rtn = clear)?\r\n");
  992.         if (get_line(&temp_char, 25)){
  993.             if (strlen(temp_char) <= 1)    /* 1 char can mean nothing so assume empty */
  994.                 strcpy(default_path, "");
  995.             else
  996.                 strcpy(default_path, temp_char);
  997.             update_file = 1;
  998.             }
  999.         erase_screen = 1;
  1000.         cmd = 0;
  1001.         }
  1002.  
  1003.     if (cmd == F7){        /* F7 - change other defaults */
  1004.         open_window(40, 21);
  1005.         do{
  1006.             show_extra_defaults();
  1007.             }while (    change_extra_defaults(getch()) );
  1008.         cmd = 0;
  1009.         update_file = 1;
  1010.         erase_screen = 1;
  1011.         }
  1012.  
  1013.     if (card_mode_oklist < 0) card_mode_oklist = 0;
  1014.     switch (card_mode_oklist){
  1015.         case 0:            /* ok mode list ie select for delete */
  1016.             for (some = 0, i=0; i< number_modes_in_list; i++)        /* check for an empty list which would hang the S/W */
  1017.                 if (ok_mode[i] >= 0)
  1018.                     some = 1;
  1019.  
  1020.             switch (cmd){
  1021.                 case arrow_up:
  1022.                     do{
  1023.                         if (sel_mode_list > 0) sel_mode_list -=1;
  1024.                         else sel_mode_list = number_modes_in_list - 1;
  1025.                         } while (ok_mode[sel_mode_list] < 0 && some);
  1026.                     break;
  1027.                 case arrow_down:
  1028.                     do{
  1029.                         if (sel_mode_list < number_modes_in_list-1) sel_mode_list += 1;
  1030.                         else sel_mode_list = 0;
  1031.                         } while (ok_mode[sel_mode_list] < 0 && some);
  1032.                     break;
  1033.                 case delete:
  1034.                     for (i=sel_mode_list; i < number_modes_in_list; i++)
  1035.                         ok_mode[i] = ok_mode[i+1];
  1036.                     update_file = 1;
  1037.                     if (ok_mode[sel_mode_list] < 0)
  1038.                         sel_mode_list = 0;        /* reset so point points to something */
  1039.                     break;
  1040.                 case 'k':
  1041.                 case 'K':        /* lock a mode for use */
  1042.                     if (mode_lock >= 0)
  1043.                         mode_lock = -1;
  1044.                     else
  1045.                         mode_lock = video_cards[ok_mode[sel_mode_list]].y_size;
  1046.                     update_file = 1;
  1047.                     break;
  1048.                 case ' ':
  1049.                     test_video(ok_mode[sel_mode_list]);
  1050.                 }
  1051.                 break;
  1052.         case 2:            /* select a video card move up/down */
  1053.             switch (cmd){
  1054.                 case arrow_up:
  1055.                     if (sel_card > 0) sel_card -=1;
  1056.                     else sel_card = number_VGA_cards - 1;
  1057.                     sel_mode = 0;        /* old mode number may be high so reset */
  1058.                     break;
  1059.                 case arrow_down:
  1060.                     if (sel_card < number_VGA_cards - 1) sel_card += 1;
  1061.                     else sel_card = 0;
  1062.                     sel_mode = 0;
  1063.                 }
  1064.                 break;
  1065.         case 1:            /* select a video mode -> test/add/del */
  1066.             switch (cmd){
  1067.                 case arrow_up:
  1068.                 case arrow_left:
  1069.                     do{                /* make sure that we get an existing mode */
  1070.                         if (sel_mode > 0) sel_mode -=1;
  1071.                         else sel_mode = number_modes_in_list - 1;
  1072.                         } while (modes_available[sel_mode] < 0);
  1073.                     break;
  1074.                 case arrow_down:
  1075.                 case arrow_right:
  1076.                     do{
  1077.                         if (++sel_mode >= number_modes_in_list) sel_mode = 0;
  1078.                         } while (modes_available[sel_mode] < 0);
  1079.                     break;
  1080.                 case insert:
  1081.                     insert_in_user_list(modes_available[sel_mode], 0);
  1082.                     update_file = 1;
  1083.                     break;
  1084.                 case delete:
  1085.                     /* first find the same mode in the other list */
  1086.                     for (i=0; i < number_modes_in_list; i++)
  1087.                         if (modes_available[sel_mode] == ok_mode[i]) break;
  1088.                     for (; i < number_modes_in_list; i++)
  1089.                         ok_mode[i] = ok_mode[i+1];
  1090.                     update_file = 1;
  1091.                     break;
  1092.                 case 0:
  1093.                     break;        /* make sure return, esc does nothing */
  1094.                 default:            /* default to testing the mode */
  1095.                     test_video(modes_available[sel_mode]);
  1096.             }
  1097.             break;
  1098.         }
  1099.     }
  1100.  
  1101. _AH = 0x0;        /* set current text mode */
  1102. _AL = text_mode_number;
  1103. geninterrupt(0x10);
  1104.  
  1105. gettextinfo(&ti);
  1106. window(1, 1, ti.winright, ti.winbottom);
  1107.  
  1108.  
  1109. normvideo();
  1110. clrscr();
  1111. _setcursortype(_NORMALCURSOR);
  1112.  
  1113. if (update_file){            /* file was changed - does the user want to save it? */
  1114.     if (be_quiet == 0){
  1115.         printf("The video information has changed.\n\r");
  1116.         printf("Do you want to save it (Y or N)?\n\r");
  1117.         cmd = toupper(getch());
  1118.         }
  1119.     else
  1120.         cmd = 'Y';
  1121.     if (cmd == 'Y'){
  1122.         config_file = fopen(config_name,"wb");
  1123.         if (config_file != NULL){                        /* load the file mode descriptions */
  1124.             putc(cfg_file_marker, config_file);        /* config file marker */
  1125.  
  1126.             putw(mode_lock, config_file);
  1127.             putw(sort_mode, config_file);
  1128.             putw(view_defaults, config_file);
  1129.             putw(text_mode_number, config_file);    /* text mode (custom) number for dvpeg */
  1130.             putw(text_width, config_file);         /* text width, height for custom mode */
  1131.             putw(text_height, config_file);
  1132.             putw(slideshow_pause, config_file);
  1133.             putw(max_file_records, config_file);
  1134.             putw(defaults, config_file);
  1135.             putw(lock_shrink_value, config_file);
  1136.             putw(buffer_size, config_file);
  1137.             putw(twiddle_factor, config_file);        /* for future expansion */
  1138.             putw(more_defaults, config_file);
  1139.             putw(0, config_file);
  1140.             putw(0, config_file);
  1141.  
  1142.             i = 0;            /* now the list of file masks, list is terminated by an empty mask */
  1143.             do{
  1144.                 fputs(file_masks[i++], config_file);
  1145.                 fputs("\n", config_file);
  1146.                 } while (strlen(file_masks[i]) > 0 && (i < max_file_masks));
  1147.             fputs("\n", config_file);        /* signal end of file masks */
  1148.  
  1149.             fputs(default_path, config_file);
  1150.             fputs("\n", config_file);
  1151.  
  1152. /* dump out card, mode #'s for all modes followed by -1,XX */
  1153.             for (i = 0; i < number_modes_in_list; i++)
  1154.                 if (ok_mode[i] >= 0){
  1155.                     putw(ok_mode[i], config_file);        /* save this to allow reconstruction of the list when loading */
  1156.                     putw(video_cards[ok_mode[i]].card_number, config_file);
  1157.                     putw(video_cards[ok_mode[i]].x_size, config_file);
  1158.                     putw(video_cards[ok_mode[i]].y_size, config_file);
  1159.                     putw(video_cards[ok_mode[i]].resolution, config_file);
  1160.                     putw(video_cards[ok_mode[i]].set_ax, config_file);
  1161.                     putw(video_cards[ok_mode[i]].set_bx, config_file);
  1162.                     putw(video_cards[ok_mode[i]].x_width, config_file);
  1163.                     }
  1164.             putw(-1, config_file);        /* signal end of modes / file */
  1165.             fclose(config_file);
  1166.             }
  1167.         else
  1168.             printf("Error saving the file.\r\n");
  1169.         }
  1170.     }
  1171. rtn_video(0);    /* restore the original video mode */
  1172.  
  1173. return(0);
  1174. }     /* main */
  1175.  
  1176.  
  1177.  
  1178. /*
  1179.  * load_config for vidsetup only  ie it throws away info about the table of usefull modes
  1180.  *
  1181.  * setup defaults in case this is the first time used
  1182.  */
  1183.  
  1184. int load_config_vidsetup(char *forced_name)
  1185. {
  1186. int    i, j,
  1187.         card_selected,
  1188.         return_code = 1,
  1189.         num_custom;        /* index for custom modes */
  1190.  
  1191. FILE *config_file;
  1192.  
  1193. /* defaults in-case no file exists */
  1194.  
  1195. view_defaults = dithering_bit | quantize_bit | panning_bit | ask_size_bit | beep_on | ascending_bit;
  1196. defaults = use_default_file | long_file_format | show_tree | show_drives | shrink_enable_flag | error_msg_on;
  1197. defaults |= was_fifty_used;        /* also add 50 line mode if that was used */
  1198. more_defaults = 0;
  1199.  
  1200. buffer_size = 8;                /* default to 16k, should work well with GIFs */
  1201. twiddle_factor = 20;
  1202. lock_shrink_value = shrink = 1;
  1203.  
  1204. mode_lock = -1;
  1205. strcpy(file_masks[0], "*.gif");            /* make sure there is one default file mask */
  1206. strcpy(file_masks[1], "*.jpg");
  1207. strcpy(file_masks[2], "*.p?m");
  1208. strcpy(file_masks[3], "*.tga");
  1209.  
  1210. slideshow_pause = default_slide_show_pause;
  1211.  
  1212. config_file = NULL;
  1213. if (forced_name != NULL){        /* has a name been forced? */
  1214.     strcpy(config_name, forced_name);
  1215.     config_file = fopen(config_name, "rb");
  1216.     if (config_file != NULL)
  1217.         if (getc(config_file) != cfg_file_marker){        /* if there is a bad marker don't use info */
  1218.             fclose(config_file);
  1219.             config_file = NULL;
  1220.             }
  1221.         else{
  1222.             rewind(config_file);
  1223.             return_code = 2;        /* signal forced file was good and used */
  1224.             }
  1225.     }
  1226.  
  1227. if (config_file == NULL){
  1228.     strcpy(config_name, original_path);        /* first try boot path for config file */
  1229.     strcat(config_name, config_file_name);
  1230.     config_file = fopen(config_name, "rb");
  1231.     }
  1232. if (config_file == NULL){
  1233.     strcpy(config_name, code_path);        /* now try path to the executable */
  1234.     strcat(config_name, config_file_name);
  1235.     config_file = fopen(config_name, "rb");
  1236.     }
  1237. if (config_file != NULL){                        /* load the file mode descriptions */
  1238.     if (getc(config_file) != cfg_file_marker){    /* check the marker to see if it is a good file */
  1239.         fclose(config_file);
  1240.         return 0;
  1241.         }
  1242.  
  1243.     mode_lock = getw(config_file);
  1244.     sort_mode = getw(config_file);
  1245.     view_defaults = getw(config_file);                /* various defaults ie grey ... */
  1246.     text_mode_number = getw(config_file);
  1247.     text_width = getw(config_file);
  1248.     text_height = getw(config_file);
  1249.     slideshow_pause = getw(config_file);
  1250.     max_file_records = getw(config_file);
  1251.     defaults = getw(config_file);
  1252.     shrink = lock_shrink_value = getw(config_file);
  1253.     buffer_size = getw(config_file);
  1254.     twiddle_factor = getw(config_file);
  1255.     more_defaults = getw(config_file);
  1256.     getw(config_file);        /* for future expansion */
  1257.     getw(config_file);
  1258.  
  1259.     i = -1;            /* now the list of file masks, list is terminated by an empty mask */
  1260.     do{
  1261.         fgets(file_masks[++i], 15, config_file);
  1262.         for (j=0; j < 15; j++)
  1263.             if (file_masks[i][j] == '\n') file_masks[i][j] = 0;        /* remove that \n since it is only needed for loading string in */
  1264.         } while (strlen(file_masks[i]) > 0 && i < max_file_masks);
  1265.  
  1266.     fgets(default_path, 78, config_file);            /* default path ?? */
  1267.     for (i=0; i < 78; i++)
  1268.         if (default_path[i] == '\n') default_path[i] = 0;        /* remove that \n since it is only needed for loading string in */
  1269.     i = -1;
  1270.     while((card_selected = getw(config_file)) != -1){
  1271.         ok_mode[++i] = card_selected;        /* strip off vidsetup specific info */
  1272.         if (i >= number_modes_in_list) i = number_modes_in_list - 1;
  1273.         if (video_cards[ok_mode[i]].x_size == 0){
  1274.             video_cards[ok_mode[i]].card_number = getw(config_file);
  1275.             video_cards[ok_mode[i]].x_size = getw(config_file);
  1276.             video_cards[ok_mode[i]].y_size = getw(config_file);
  1277.             video_cards[ok_mode[i]].resolution = getw(config_file);
  1278.             video_cards[ok_mode[i]].set_ax = getw(config_file);
  1279.             video_cards[ok_mode[i]].set_bx = getw(config_file);
  1280.             video_cards[ok_mode[i]].x_width = getw(config_file);
  1281.             }
  1282.         else{
  1283.             getw(config_file);
  1284.             getw(config_file);
  1285.             getw(config_file);
  1286.             getw(config_file);
  1287.             getw(config_file);
  1288.             getw(config_file);
  1289.             getw(config_file);
  1290.             }
  1291.         }
  1292.     fclose(config_file);
  1293.     card_id = video_cards[ok_mode[0]].card_number;        /* set default video card */
  1294.     return return_code;
  1295.     }
  1296. else
  1297.     return 0;
  1298. }
  1299.