home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / powervww / pvsystem.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-01-05  |  16.0 KB  |  790 lines

  1. //  ____________________________________________________
  2. // |                                                    |
  3. // |  Project:     POWER VIEW INTERFACE                 |
  4. // |  File:        PVSYSTEM.CPP                         |
  5. // |  Compiler:    WPP386 (10.6)                        |
  6. // |                                                    |
  7. // |  Subject:     OS interface & utils implementation  |
  8. // |                                                    |
  9. // |  Author:      Emil Dotchevski                      |
  10. // |____________________________________________________|
  11. //
  12. // E-mail: zajo@geocities.com
  13. // URL:    http://www.geocities.com/SiliconValley/Bay/3577
  14.  
  15. #define uses_conio
  16. #define uses_fcntl
  17. #define uses_malloc
  18. #define uses_string
  19. #define uses_comlin
  20. #define uses_config
  21. #define uses_ini
  22. #define uses_system
  23.  
  24. #define DECLARE_PVSYSTEM
  25. #include "PVuses.h"
  26. #undef DECLARE_PVSYSTEM
  27.  
  28. #ifdef __FLAT__
  29. static word *page_offset = (word *) BIOS_DTA( 0x4E );
  30. static char *current_char_size = (char *) BIOS_DTA( 0x85 );
  31. static char *current_mode = (char *) BIOS_DTA( 0x49 );
  32. #else
  33. static word far *page_offset = (word *) BIOS_DTA( 0x4E );
  34. static char far *current_char_size = (char *) BIOS_DTA( 0x85 );
  35. static char far *current_mode = (char *) BIOS_DTA( 0x49 );
  36. #endif
  37.  
  38. //SYSTEM & DOS INTERFACE PROCS
  39.  
  40. static int cli_counter = 0;
  41.  
  42. void _cli( void )
  43. {
  44.   if( !cli_counter++ ) _disable();
  45. }
  46.  
  47. void _sti( void )
  48. {
  49.   if( !--cli_counter ) _enable();
  50. }
  51.  
  52. #ifdef __386__
  53. int lock_region ( void *address, unsigned length )
  54. {
  55.   union REGS regs;
  56.   unsigned linear;
  57.  
  58.   /* Thanks to DOS/4GW's zero-based flat memory model, converting
  59.      a pointer of any type to a linear address is trivial.
  60.   */
  61.   linear = (unsigned) address;
  62.  
  63.   regs.w.ax = 0x600;                      /* DPMI Lock Linear Region */
  64.   regs.w.bx = (word) ( linear >> 16 );    /* Linear address in BX:CX */
  65.   regs.w.cx = (word) ( linear & 0xFFFF );
  66.   regs.w.si = (word) ( length >> 16 );    /* Length in SI:DI */
  67.   regs.w.di = (word) ( length & 0xFFFF );
  68.   int386 (0x31, ®s, ®s);
  69.   return !regs.w.cflag;                   /* Return 0 if can't lock */
  70. }
  71. #endif
  72.  
  73. static boolean critical_error_flag=0;
  74. #pragma off( unreferenced )
  75. static int _loadds critical_handler( unsigned deverror, unsigned errcode, unsigned far *devhdr )
  76. {
  77.   critical_error_flag++;
  78.   return ( _HARDERR_FAIL );
  79. }
  80. #pragma on( unreferenced )
  81.  
  82. boolean critical_error( void )
  83. {
  84.   boolean result = critical_error_flag;
  85.   critical_error_flag = 0;
  86.   return result;
  87. }
  88.  
  89. #ifdef __WATCOMC__
  90. boolean memavail( unsigned long &mem )
  91. {
  92.   struct _heapinfo h_info;
  93.   int heap_status;
  94.  
  95.   h_info._pentry = NULL;
  96.   mem = 0;
  97.   for(;;)
  98.   {
  99.     heap_status = _heapwalk( &h_info );
  100.     if( heap_status != _HEAPOK ) break;
  101.     if( h_info._useflag != _USEDENTRY ) mem += h_info._size;
  102.   }
  103.   switch( heap_status )
  104.   {
  105.     case _HEAPBADBEGIN:
  106.     case _HEAPBADPTR:
  107.     case _HEAPBADNODE:
  108.       return 0;
  109.   }
  110.   return 1;
  111. }
  112. #else
  113. boolean memavail( unsigned long &mem )
  114. {
  115.   struct heapinfo heap;
  116.  
  117.   mem = coreleft();
  118.   switch( heapcheck() )
  119.   {
  120.     case _HEAPCORRUPT:
  121.       return 0;
  122.     case _HEAPOK:
  123.       heap.ptr = NULL;
  124.       while( heapwalk( &heap ) != _HEAPEND )
  125.         if( !heap.in_use )
  126.           mem += heap.size;
  127.   }
  128.   return 1;
  129. }
  130. #endif
  131.  
  132. char *fexpand( char *filespec )
  133. {
  134.   char buf[_MAX_PATH],
  135.        _drive[_MAX_DRIVE],
  136.        _dir[_MAX_DIR],
  137.        _fname[_MAX_FNAME],
  138.        _ext[_MAX_EXT], *p, *z;
  139.   if( !*filespec ) return filespec;
  140.   _fullpath( filespec, strcpy(buf,filespec), _MAX_PATH );
  141.   //the garbage below fixes the shits of _fullpath
  142.   while( ( p = strstr( filespec, "\\.." ) ) != NULL )
  143.   {
  144.     z = p;
  145.     while( *--z != '\\' );
  146.     strcpy( z, p + 3 );
  147.   }
  148.   _splitpath( filespec, _drive, _dir, _fname, NULL );
  149.   _splitpath( buf,      NULL,   NULL, NULL,   _ext );
  150.   _makepath ( filespec, _drive, _dir, _fname, _ext );
  151.   return strupr(filespec);
  152. }
  153.  
  154. char *add_ext( char *name, char *ext )
  155. {
  156.   char _drive[_MAX_DRIVE];
  157.   char _dir[_MAX_DIR];
  158.   char _file[_MAX_FNAME];
  159.   char _ext[_MAX_EXT];
  160.  
  161.   _splitpath( name, _drive, _dir, _file, _ext );
  162.   if( *_ext==0 ) strcpy( _ext, ext );
  163.   _makepath( name, _drive, _dir, _file, _ext );
  164.   return name;
  165. }
  166.  
  167. char *min_path( char *filespec )
  168. {
  169.   char dr[_MAX_DRIVE], d[_MAX_DRIVE+_MAX_DIR], s[_MAX_DRIVE+_MAX_DIR];
  170.  
  171.   _splitpath( filespec, dr, s, NULL, NULL );
  172.   strcpy( d, dr ); strcat( d, s );
  173.   getcwd( s, sizeof( s ) ); strcat( s, "\\" );
  174.   if( ( strlen(s) <= strlen( d ) ) && ( d[strlen( s )] = 0, ( strcmp( d, s ) == 0 ) ) )
  175.     strcpy( filespec, filespec + strlen( s ) );
  176.   else
  177.     if( s[0] == d[0] ) strcpy( filespec, filespec + 2 );
  178.   return filespec;
  179. }
  180.  
  181. char *short_path( char *filespec, int n )
  182. {
  183.   boolean fl;
  184.   char s[_MAX_PATH], x[_MAX_EXT], *i;
  185.  
  186.   if( strlen( filespec ) <= n ) return filespec;
  187.   n -= 4;
  188.   fl =  0;
  189.   _splitpath( filespec, NULL, NULL, s, x );
  190.   strcat( s, x );
  191.   if( strlen( s ) >= n )
  192.     strcpy( filespec, s );
  193.   else
  194.   {
  195.     while( strlen( filespec ) > n )
  196.     {
  197.       i = filespec;
  198.       if( *i == '\\' ) i++;
  199.       while( *i != '\\' ) i++;
  200.       strcpy( filespec, i );
  201.       fl = 1;
  202.     }
  203.     if( fl )
  204.     {
  205.       strcpy( s, filespec );
  206.       strcpy( filespec, "\\..." );
  207.       strcat( filespec, s );
  208.     }
  209.   }
  210.   return filespec;
  211. }
  212.  
  213. long file_size( char *filespec )
  214. {
  215.   struct find_t d;
  216.  
  217.   if( _dos_findfirst( filespec, _A_NORMAL, &d ) ) return -1;
  218.   return d.size;
  219. }
  220.  
  221. boolean get_date_time( char *filespec, uint &date, uint &time )
  222. {
  223.   int handle;
  224.   union REGS r;
  225.  
  226.   date = time = 0;
  227.   if( _dos_open( filespec, O_RDONLY, &handle ) != 0 ) return 0;
  228.   r.w.ax = 0x5700;
  229.   r.w.bx = handle;
  230.   INTR( 0x21, &r, &r );
  231.   date = r.w.dx;
  232.   time = r.w.cx;
  233.   _dos_close( handle );
  234.   return 1;
  235. }
  236.  
  237. uint pack_time( char hours, char minutes, char seconds )
  238. {
  239.   return ( hours << 11 ) | ( minutes << 5 ) | ( seconds >> 1 );
  240. }
  241.  
  242. uint pack_date( uint year, char month, char day )
  243. {
  244.   return ( ( year - 1980 ) << 9 ) | ( month << 5 ) | day;
  245. }
  246.  
  247. void unpack_time( unsigned packed, char &hours, char &minutes, char &seconds )
  248. {
  249.   hours = (char) ( packed >> 11 );
  250.   minutes = (char) ( ( packed >> 5 ) & 63 );
  251.   seconds = (char) ( ( packed & 31 ) << 1 );
  252. }
  253.  
  254. void unpack_date( unsigned packed, uint &year, char &month, char &day )
  255. {
  256.   year  = ( ( packed & 0xF800 ) >> 9 ) + 1980;
  257.   month = ( ( packed & 0x01E0 ) >> 5 );
  258.   day   = packed & 0x1F;
  259. }
  260.  
  261. //SCREEN
  262.  
  263. void set_char_size( char size )
  264. {
  265.   union REGS r;
  266.  
  267.   if( size && ( *current_char_size != size ) )
  268.   {
  269.     r.h.ah = 0x11;
  270.     switch( size )
  271.     {
  272.       case  8: r.h.al = 0x12; break;
  273.       case 14: r.h.al = 0x11; break;
  274.       case 16: r.h.al = 0x14;
  275.     }
  276.     INTR( 0x10, &r, &r );
  277. #if !defined( NOICONS ) && !defined( HGR )
  278.     if( size==16 ) set_char_width( 9 ); else set_char_width( 8 );
  279. #endif
  280.   }
  281. }
  282.  
  283. void set_video_mode( char mode, char char_size )
  284. {
  285.   if( (char_size!=*current_char_size) || (mode!=*current_mode) )
  286.     change_video_mode( mode, char_size );
  287. }
  288.  
  289. #pragma off( unreferenced )
  290. void direct_set_video_mode( char mode, char char_size )
  291. {
  292.   union REGS r;
  293.  
  294. #ifdef HGR
  295.   r.w.ax = 0x12;
  296.   INTR( 0x10, &r, &r );
  297. #else
  298.   if( mode && (mode!=*current_mode) )
  299.   {
  300.     r.w.ax = mode;
  301.     INTR( 0x10, &r, &r );
  302.   }
  303.   if( char_size && ( char_size != *current_char_size ) )
  304.     set_char_size( char_size );
  305. #endif
  306.   update_screen_information();
  307. }
  308. #pragma on( unreferenced )
  309.  
  310. #ifdef HGR
  311. void update_screen_information( void )
  312. {
  313.   scr_bw = scr_forced_bw;
  314.   scr_page = 0;
  315.   scr_mode = 0x12;
  316.   scr_columns = 80;
  317.   scr_rows = 30;
  318.   scr_soft_fonts = 0;
  319.   scr_char_size = 16;
  320.   scr_address = (word *) MKFP( 0xA000, 0 );
  321.   scr_length = scr_rows*scr_columns;
  322. }
  323. #else
  324. void update_screen_information( void )
  325. {
  326.   union REGS r;
  327.   word ax;
  328.  
  329.   r.h.ah = 0x0F;
  330.   INTR( 0x10, &r, &r );
  331.   if( !scr_forced_bw ) scr_bw = (r.h.al==2) || (r.h.al==7);
  332.   scr_page = r.h.bh;
  333.   r.h.al &= 0x7F;
  334.   ax = r.w.ax;
  335.   r.w.ax = 0x1130;
  336.   r.h.bh = 0;
  337.   r.h.dl = -1;
  338.   INTR( 0x10, &r, &r );
  339.   r.w.ax = ax;
  340.   r.h.dl++;
  341.   r.h.dh = r.h.ah;
  342.   r.h.ah = ( r.h.dl >= ( 25 + 1 ) );
  343.   r.w.si = 0xB800;
  344.   r.h.ch = 1;
  345.   if( !r.h.dl )
  346.   {
  347.     r.w.cx = 8;
  348.     r.h.dl = 25;
  349.     if( r.h.al == 7 )
  350.     {
  351.       r.w.si = 0xB000;
  352.       r.h.cl = 13;
  353.     }
  354.   }
  355.   scr_mode = r.w.ax;
  356.   scr_columns = r.h.dh;
  357.   scr_rows = r.h.dl;
  358.   scr_soft_fonts = r.h.ch;
  359.   scr_char_size = r.h.cl;
  360.   scr_address = (word *) MKFP( r.w.si, *page_offset );
  361.   scr_length = scr_rows*scr_columns*2;
  362. }
  363. #endif
  364.  
  365. void set_page( char page_num )
  366. {
  367.   union REGS r;
  368.  
  369. #ifndef NOMOUSE
  370.   hide_mouse();
  371. #endif
  372.   scr_page = page_num;
  373.   r.h.al = page_num;
  374.   r.h.ah = 5;
  375.   INTR( 0x10, &r, &r );
  376.   if( scr_mode == 7 )
  377.     scr_address = (word *) MKFP( 0xB000, *page_offset );
  378.   else
  379.     scr_address = (word *) MKFP( 0xB800, *page_offset );
  380. #ifndef NOMOUSE
  381.   show_mouse();
  382. #endif
  383. }
  384.  
  385. char *save_screen_status( void )
  386. {
  387.   union REGS r;
  388.   char *p, *result;
  389.  
  390. #ifndef NOMOUSE
  391.   hide_mouse();
  392. #endif
  393.   update_screen_information();
  394.   p = (char *)MALLOC( 9 + scr_length );
  395.   result = p;
  396.   r.h.ah = 0x0F;
  397.   INTR( 0x10, &r, &r );
  398.   *( p++ ) = r.h.al;
  399.   *( p++ ) = scr_char_size;
  400.   *( p++ ) = r.h.bh;
  401.   r.h.ah = 3;
  402.   INTR( 0x10, &r, &r );
  403.   *( p++ ) = r.h.dl;
  404.   *( p++ ) = r.h.dh;
  405.   *( p++ ) = r.h.ch;
  406.   *( p++ ) = r.h.cl;
  407.   *((word *)p) = scr_length;
  408.   p+=2;
  409.   _fmemcpy( p, scr_address, scr_length );
  410. #ifndef NOMOUSE
  411.   show_mouse();
  412. #endif
  413.   return result;
  414. }
  415.  
  416. void restore_screen_status( char *p )
  417. {
  418.   union REGS r;
  419.   char *saved;
  420.  
  421.   if( p == NULL ) return;
  422.   saved = p;
  423. #ifndef NOMOUSE
  424.   hide_mouse();
  425. #endif
  426.   set_video_mode( *( p ), *( p + 1 ) ); p += 2;
  427.   r.h.al = *p;
  428.   r.h.ah = 5;
  429.   INTR( 0x10, &r, &r );
  430.   r.h.bh = *( p++ );
  431.   r.h.dl = *( p++ );
  432.   r.h.dh = *( p++ );
  433.   r.h.ah = 2;
  434.   INTR( 0x10, &r, &r );
  435.   r.h.ch = *( p++ );
  436.   r.h.cl = *( p++ );
  437.   r.h.ah = 1;
  438.   INTR( 0x10, &r, &r );
  439.   scr_length = *(word *)p;
  440.   p+=2;
  441.   if( scr_mode == 7 )
  442.     scr_address = (word *) MKFP( 0xB000, *page_offset );
  443.   else
  444.     scr_address = (word *) MKFP( 0xB800, *page_offset );
  445.   _fmemcpy( scr_address, p, scr_length );
  446.   FREE( saved );
  447.   update_screen_information();
  448. #ifndef NOMOUSE
  449.   show_mouse();
  450. #endif
  451. }
  452.  
  453. static char *dos_screen = NULL;
  454.  
  455. void save_dos_screen( void )
  456. {
  457.   dos_screen = save_screen_status();
  458. }
  459.  
  460. void restore_dos_screen( void )
  461. {
  462.   restore_screen_status( dos_screen );
  463.   dos_screen = NULL;
  464. }
  465.  
  466. Tscreen_mode_proc hook_mode_proc( Tscreen_mode_proc p )
  467. {
  468.   Tscreen_mode_proc x;
  469.  
  470.   x = change_video_mode;
  471.   change_video_mode = p;
  472.   return x;
  473. }
  474.  
  475.  
  476. #ifndef HGR
  477.  
  478. //EGA/VGA FONTS MANAGEMENT
  479.  
  480. char seq_read( char reg )
  481. {
  482.   outp( 0x3C4, reg );
  483.   return (char) inp( 0x3C5 );
  484. }
  485.  
  486. void seq_write( char reg, char val )
  487. {
  488.   outp( 0x3C4, reg );
  489.   outp( 0x3C5, val );
  490. }
  491.  
  492. char gpx_read( char reg )
  493. {
  494.   outp( 0x3CE, reg );
  495.   return (char) inp( 0x3CF );
  496. }
  497.  
  498. void gpx_write( char reg, char val )
  499. {
  500.   outp( 0x3CE, reg );
  501.   outp( 0x3CF, val );
  502. }
  503.  
  504. void open_font_map( void )
  505. {
  506.   seq_write( 2, 4 );
  507.   seq_write( 4, 7 );
  508.   gpx_write( 5, 0 );
  509.   gpx_write( 6, 4 );
  510.   gpx_write( 4, 2 );
  511. }
  512.  
  513. void close_font_map( void )
  514. {
  515.   seq_write( 2, 3 );
  516.   seq_write( 4, 3 );
  517.   gpx_write( 5, 0x10 );
  518.   gpx_write( 6, 0x0E );
  519.   gpx_write( 4, 0 );
  520. }
  521.  
  522. char *get_char_def( int chr, char *buf )
  523. {
  524. #ifdef __FLAT__
  525.   char *A000 = VGA_CHARS;
  526. #else
  527.   char far *A000 = VGA_CHARS;
  528. #endif
  529.   uint char_offset;
  530.  
  531.   char_offset = ( chr << 5 ) | ( scr_font_num << 14 );
  532.   _fmemcpy( buf, A000 + char_offset, scr_char_size );
  533.   return buf + scr_char_size;
  534. }
  535.  
  536. char *set_char_def( int chr, char *buf )
  537. {
  538. #ifdef __FLAT__
  539.   char *A000 = VGA_CHARS;
  540. #else
  541.   char far *A000 = VGA_CHARS;
  542. #endif
  543.   uint char_offset;
  544.  
  545.   char_offset = ( chr << 5 ) | ( scr_font_num << 14 );
  546.   _fmemcpy( A000 + char_offset, buf, scr_char_size );
  547.   return buf + scr_char_size;
  548. }
  549.  
  550. char *xchg_char_def( int chr, char *buf )
  551. {
  552.   char tmp_buffer[0x10];
  553.   char *result;
  554.  
  555.   get_char_def( chr, tmp_buffer );
  556.   result = set_char_def( chr, buf );
  557.   memmove( buf, tmp_buffer, scr_char_size );
  558.   return result;
  559. }
  560.  
  561. void set_char_width( char width )
  562. {
  563.   union REGS r;
  564.   char x;
  565.  
  566.   r.w.bx = ( width == 8 ) ? 0x0001 : 0x0800;
  567.   x = (char) ( inp( 0x3CC ) & ( 255 - 12 ) );
  568.   if( width == 9 ) x |= 4;
  569.   outp( 0x3C2, x );
  570.   _cli();
  571.   outpw( 0x3C4, 0x0100 );
  572.   outpw( 0x3C4, 0x01 + ( r.h.bl << 8 ) );
  573.   outpw( 0x3C4, 0x0300 );
  574.   _sti();
  575.   r.w.ax = 0x1000;
  576.   r.h.bl = 0x13;
  577.   INTR( 0x10, &r, &r );
  578. }
  579.  
  580. void select_fonts( char font1, char font2 )
  581. {
  582.   union REGS r;
  583.  
  584.   r.h.bl = (char) ( font1 | ( font2 << 2 ) );
  585.   r.w.ax = 0x1103;
  586.   INTR( 0x10, &r, &r );
  587. }
  588.  
  589. #endif //!HGR
  590.  
  591.  
  592. //CURSOR MANAGEMENT
  593.  
  594. #ifdef HGR
  595.  
  596. void get_cursor( Tcursor &x )
  597. {
  598.   x = *current_cursor;
  599. }
  600.  
  601. void set_cursor( Tcursor &x )
  602. {
  603.   current_cursor = &x;
  604. }
  605.  
  606. #else
  607.  
  608. void get_cursor( Tcursor &x )
  609. {
  610.   union REGS r;
  611.  
  612.   r.h.ah = 0x0F;
  613.   INTR( 0x10, &r, &r );
  614.   r.h.ah = 0x03;
  615.   INTR( 0x10, &r, &r );
  616.   x.beg_line = r.h.ch;
  617.   x.end_line = r.h.cl;
  618. }
  619.  
  620. void set_cursor( Tcursor &x )
  621. {
  622.   union REGS r;
  623.  
  624.   r.h.ah=1;
  625.   r.h.ch=x.beg_line;
  626.   r.h.cl=x.end_line;
  627.   INTR( 0x10, &r, &r );
  628. }
  629.  
  630. #endif //HGR
  631.  
  632. #ifndef HGR
  633.  
  634. //EGA/VGA PALETTE MANAGEMENT
  635.  
  636. void set_blink( boolean blink )
  637. {
  638.   union REGS r;
  639. #ifdef __FLAT__
  640.   char *p = (char *) BIOS_DTA( 0x65 );
  641. #else
  642.   char far *p = (char *) BIOS_DTA( 0x65 );
  643. #endif
  644.   char x;
  645.  
  646.   r.w.ax = 0x1003;
  647.   r.h.bl = blink;
  648.   INTR( 0x10, &r, &r );
  649.   x = *p;
  650.   if( blink ) x &= !0x20; else x |= 0x20;
  651.   outp( 0x3D8, x );
  652. }
  653.  
  654. #ifndef NOPAL
  655. void set_palette( char no, char value )
  656. {
  657.   union REGS r;
  658.  
  659.   r.w.ax = 0x1000;
  660.   r.h.bl = no;
  661.   r.h.bh = value;
  662.   INTR( 0x10, &r, &r );
  663. }
  664.  
  665. char get_palette( char no )
  666. {
  667.   union REGS r;
  668.  
  669.   r.w.ax = 0x1007;
  670.   r.h.bl = no;
  671.   INTR( 0x10, &r, &r );
  672.   return r.h.bh;
  673. }
  674.  
  675. void set_border( char color )
  676. {
  677.   union REGS r;
  678.  
  679.   r.w.ax = 0x1001;
  680.   r.h.bh = color;
  681.   INTR( 0x10, &r, &r );
  682. }
  683.  
  684. char get_border( void )
  685. {
  686.   union REGS r;
  687.  
  688.   r.w.ax = 0x1008;
  689.   INTR( 0x10, &r, &r );
  690.   return r.h.bh;
  691. }
  692.  
  693. void set_all_palette( Tpal &x )
  694. {
  695.   for( char i = 0; i <= 0x0F; i++ ) set_palette( i, x[i] );
  696. }
  697.  
  698. void get_all_palette( Tpal &x )
  699. {
  700.   for( char i = 0; i <= 0x0F; i++ ) x[i] = get_palette( i );
  701. }
  702. #endif //!NOPAL
  703.  
  704. #endif //!HGR
  705.  
  706. //SOUND
  707.  
  708. void beep( uint hz, uint ms )
  709. {
  710.   sound( hz );
  711.   delay( ms );
  712.   nosound();
  713. }
  714.  
  715. #ifndef NOTIMER
  716. void smart_beep( uint hz, uint ticks )
  717. {
  718.   static int h = -1;
  719.  
  720.   free_timer( h );
  721.   sound( hz );
  722.   call_request( (h=alloc_timer()), nosound, ticks );
  723.   if( !h ) nosound();
  724. }
  725. #endif
  726.  
  727.  
  728. //STARTUP
  729.  
  730. static long startup_mode = 0;
  731. static long startup_char_size = 0;
  732.  
  733. void __set_startup_video_mode( void )
  734. {
  735.   set_video_mode( (char) startup_mode, (char) startup_char_size );
  736. }
  737.  
  738. #ifndef NOCONFIG
  739. static void read_params( void )
  740. {
  741.   seek_section( 0, SECTION_SCREEN );
  742.   ini( VAR_VIDEO_MODE, startup_mode, 0 );
  743.   ini( VAR_CHAR_SIZE, startup_char_size, 0 );
  744.   ini_lnerr( startup_char_size!= 0 && startup_char_size!= 8 &&
  745.              startup_char_size!=14 && startup_char_size!=16, INIERR_RANGE );
  746.   if( !scr_forced_bw ) ini( VAR_BW, scr_forced_bw, 0 );
  747. }
  748. #endif
  749.  
  750. static void init_cyr( void )
  751. {
  752.   union REGS r;
  753.  
  754.   r.w.ax = 0xEB01;
  755.   INTR( 0x10, &r, &r );
  756.   if( r.h.al != 0xEB ) return;
  757. #ifdef CYR
  758.   scr_font_num = 3;
  759.   r.h.bl |= 0x30; //activate, set cyr font & cyr keymap
  760.   r.h.bl &= ~0x02; //disable graphics keymap
  761. #else
  762.   scr_font_num = 0;
  763.   r.h.bl |= 0x20; //activate, set eng font & qwerty keymap
  764.   r.h.bl &= ~0x1A; //disable graphics keymap
  765. #endif
  766.   r.w.ax = 0xEB02;
  767.   INTR( 0x10, &r, &r );
  768. }
  769.  
  770. void __init_system( void )
  771. {
  772.   _harderr( critical_handler );
  773. #ifndef HGR
  774.   set_cursor( insert_cursor );
  775. #endif
  776. #ifndef NOPARAM
  777.   if( param_opt( "/COLOR" ) ) scr_forced_bw = 0;
  778.   if( param_opt( "/BW"    ) ) scr_forced_bw = 1;
  779. #endif
  780. #ifndef NOCONFIG
  781.   read_params();
  782. #endif
  783.   scr_bw = scr_forced_bw;
  784.   update_screen_information();
  785.   init_cyr();
  786. #ifdef CYR
  787.   strcpy( frame_standard, frame_cyr );
  788. #endif
  789. }
  790.