⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tdecfg.c

📁 C语言高级实例解析的配套光盘资料
💻 C
📖 第 1 页 / 共 2 页
字号:
   cfg.rescan = FALSE;
   in.x.ax =  0x1a00;
   int86( VIDEO_INT, &in, &out );
   temp = out.h.al;
   active_display = out.h.bl;
   if (temp == 0x1a && (active_display == 7 || active_display == 8))
      cfg.adapter = VGA;
   else {
      in.h.ah =  0x12;
      in.h.bl =  0x10;
      int86( VIDEO_INT, &in, &out );
      if (out.h.bl != 0x10) {         
         if (vid.ega_info & 0x08) {
            if (vid.addr_6845 == 0x3d4)
               cfg.adapter = CGA;
            else
               cfg.adapter = MDA;
         } else
            cfg.adapter = EGA;
      } else if (vid.addr_6845 == 0x3d4)
         cfg.adapter = CGA;
      else
         cfg.adapter = MDA;
   }

   if (cfg.adapter == CGA)
      cfg.rescan = TRUE;

   cfg.mode = vid.vidmode;
   if (vid.addr_6845 == 0x3D4) {
      cfg.color = TRUE;
      FP_SEG( cfg.videomem ) = 0xb800;
   } else {
      cfg.color = FALSE;
      FP_SEG( cfg.videomem ) = 0xb000;
   }
   FP_OFF( cfg.videomem ) = 0x0000;
   if (cfg.color == TRUE)
      cfg.attr = COLOR_ATTR;
   else
      cfg.attr = MONO_ATTR;

   cfg.overscan = vid.crt_palette;
}


int getkey( void )
{
unsigned key;
unsigned lo;

  
   key = _bios_keybrd( 0 );
   lo = key & 0X00FF;
   lo = (int)((lo == 0) ? (((key & 0XFF00) >> 8) + 256) : lo);
   return( lo );
}



void s_output( char far *s, int line, int col, int attr )
{
int far *screen_ptr;
int max_col;
int off;

   max_col = 80;
   screen_ptr = cfg.videomem;
   off = line * 160 + col * 2;

   ASSEMBLE {
        push    ds              
        push    di              
        push    si              

        mov     bx, WORD PTR attr               
        mov     cx, WORD PTR col                
        mov     dx, WORD PTR max_col            
        mov     di, WORD PTR screen_ptr         
        add     di, WORD PTR off
        mov     ax, WORD PTR screen_ptr+2       
        mov     es, ax
        mov     si, WORD PTR s  
        or      si, si          
        je      getout          
        mov     ax, WORD PTR s+2        
        or      ax, ax          
        je      getout          
        mov     ds, ax          
        mov     ah, bl          
   }
top:

   ASSEMBLE {
        cmp     cx, dx          
        jge     getout          
        lodsb                   
        or      al, al          
        je      getout          
        stosw                   
        inc     cx              
        jmp     SHORT top       
   }
getout:

   ASSEMBLE {
        pop     si              
        pop     di              
        pop     ds              
   }
}



void hlight_line( int x, int y, int lgth, int attr )
{
int off, far *pointer;

   pointer = cfg.videomem;
   off = y * 160 + 2 * x + 1;  
   ASSEMBLE {
        push    di              

        mov     cx, lgth        

        mov     di, WORD PTR pointer    
        add     di, off                 
        mov     ax, WORD PTR pointer+2
        mov     es, ax
        mov     ax, attr        
   }
lite_len:

   ASSEMBLE {
        stosb                   
        inc     di              
        loop    lite_len        
        pop     di              
   }
}



void scroll_window( int lines, int r1, int c1, int r2, int c2, int attr )
{
char rah, ral;

   ASSEMBLE {
        mov     ax, lines
        cmp     ax, 0           
        jge     a1

        neg     ax                      
        mov     BYTE PTR ral, al        
        mov     BYTE PTR rah, 7         
        dec     r2                      
        jmp     SHORT a2
   }
a1:

   ASSEMBLE {
        mov     BYTE PTR ral, al        
        mov     BYTE PTR rah, 6         
   }
a2:

   ASSEMBLE {
        mov     ax, WORD PTR r1         
        mov     ch, al                  
        mov     ax, WORD PTR c1         
        mov     cl, al                  
        mov     ax, WORD PTR r2         
        mov     dh, al                  
        mov     ax, WORD PTR c2         
        mov     dl, al                  
        mov     ax, WORD PTR attr       
        mov     bh, al                  
        mov     ah, BYTE PTR rah        
        mov     al, BYTE PTR ral        
        push    bp                      
        int     VIDEO_INT               
        pop     bp
   }
}



void cls( void )
{
   scroll_window( 0, 0, 0, 24, 79, NORMAL );
}



void show_box( int x, int y, struct screen *p, int  attr )
{

   while (p->text) {
      s_output( p->text, p->row+y, p->col+x, attr );
      p++;
   }
}



void make_window( int col, int row, int width, int height, int attr )
{
   buf_box( col++, row++, width, height, attr );
   clear_window( col, row, width-2, height-2 );
}



void buf_box( int col, int row, int width, int height, int attr )
{
int  i;
int  row_count;
char string[82];

   if (height > 0 && width > 0 && height < 25 && width < 81) {
      row_count = 1;
      string[0]= U_LEFT;
      for (i=1; i<width-1; i++)
         string[i] = HOR_LINE;
      string[i++] = U_RIGHT; string[i] = '\0';
      s_output( string, row, col, attr );
      ++row_count;
      ++row;

      if (row_count < height) {
         string[0] = VER_LINE;
         string[1] = '\0';
         for (i=1; i<height-1; i++) {
            s_output( string, row, col, attr );
            s_output( string, row, col+width-1, attr );
            ++row;
            ++row_count;
         }
      }

      if (row_count <= height) {
         string[0] = L_LEFT;
         for (i=1; i<width-1; i++)
            string[i] = HOR_LINE;
         string[i++] = L_RIGHT; string[i] = '\0';
         s_output( string, row, col, attr );
      }
   }
}



void clear_window( int col, int row, int width, int height )
{

   scroll_window( 0, row, col, row+height-1, col+width-1, NORMAL );
}



void window_control( WINDOW **window_ptr, int action, int col, int row,
                     int width, int height )
{
WINDOW  *p;
size_t  store_me;

   if (action == SAVE) {
      p = (WINDOW *)malloc( sizeof(WINDOW) );
      if (p != NULL) {
         p->n = NULL;

         
         if (*window_ptr != NULL)
            p->n = *window_ptr;
         *window_ptr = p;
         store_me = (width * height) * sizeof( int );
         p->buf = (int *)malloc( store_me );
         save_window( p->buf, col, row, width, height );
      }
   } else if (action == RESTORE) {
      if (*window_ptr != NULL) {
         p = *window_ptr;
         restore_window( p->buf, col, row, width, height );

        
         *window_ptr = p->n;
         free( p->buf );
         free( p );
}  }  }



void save_window( int *destination, int col, int row, int width, int height )
{
int i, j, offset;
int far *pointer;

   pointer = cfg.videomem;
   offset = row * 80 + col;
   pointer += offset;
   for (i=0; i < height; i++) {
      for (j=0; j < width; j++)
         *destination++ = *(pointer + j);
      pointer += 80;
   }
}



void restore_window( int *source, int col, int row, int width, int height )
{
int i, j, offset;
int far *pointer;

   pointer = cfg.videomem;
   offset = row * 80 + col;
   pointer += offset;
   for (i=0; i < height; i++) {
      for (j=0; j < width; j++)
         *(pointer + j) = *source++;
      pointer += 80;
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -