uibios.c

来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 515 行 · 第 1/2 页

C
515
字号
    for( p = Pairs; p->start_range != 0; ++p ) {
        if( ch >= p->start_range && ch <= p->end_range ) return( 2 );
    }
    return( 1 );
}

#define ALPHA_SMALL_BW  0
#define ALPHA_SMALL_COL 1
#define ALPHA_LARGE_BW  2
#define ALPHA_LARGE_COL 3
#define GR_MED_4COL     4           // 16K memory (40 characters wide)
#define GR_MED_BW       5           // 16K memory (40 characters wide)
#define GR_HIGH_BW      6           // 16K memory (80 characters wide)
#define MONOCHROME      7
#define GR_LOW_16COL    8           // 16K memory (20 characters wide)
#define GR_MED_16COL    9           // 32K memory
#define GR_HIGH_4COL   10           // 32K memory
#define EGA_LOW_16COL  13           // 64K memory
#define EGA_HIGH_16COL 14           // 64K memory
#define EGA_HIGH_MONO  15           // 64K memory
#define EGA_HIGH_4COL  16           // 64K memory
#define VGA_2COL       17
#define VGA_16COL      18
#define VGA_256COL     19
#define TSENG_44x132   34           // Text Mode
#define TSENG_25x132   35           // Text Mode
#define TSENG_28x132   36           // Text Mode
#define TSENG_60x80    38           // Text Mode
#define TSENG_40x100   42           // Text Mode
#define ACER_25X132    35           // Text Mode
#define ACER_44X132    51           // Text Mode
#define TRIDENT_start  80           // Text Modes 80-90
#define TRIDENT_end    90           // Text Mode
#define DELL_43X132    84           // Text Mode
#define DELL_25X132    85           // Text Mode

int IsTextMode( void )
{
    unsigned char       mode;
    unsigned char       page;
    struct cursor_pos   cursor_position;
    unsigned short __FAR *video_mem;
    unsigned short      char_attr_bios;
    unsigned short      char_attr_vmem;
    unsigned char       text_mode = 0;

    /* get current video mode */
    mode = BIOSGetMode();
    /* get current video page */
    page = BIOSGetPage();
    /* get cursor position for current page */
    cursor_position = BIOSGetCurPos( page );
    if( mode < GR_MED_4COL || mode == MONOCHROME || mode > VGA_256COL ) {
        video_mem = (unsigned short __FAR *) UIData->screen.origin;
        /* set cursor position to top left corner of screen */
        BIOSSetCurPos( 0, 0, page );
        /* get character/attribute at that location */
        char_attr_bios = BIOSGetCharAttr( page );
        /* get character/attribute from screen memory */
        char_attr_vmem = *video_mem;
        if( char_attr_bios == char_attr_vmem ) {
            /* change the character we read through BIOS call */
            char_attr_bios ^= 1;
            /* write out character using BIOS */
            BIOSSetCharAttr( char_attr_bios, page );
            /* get character/attribute from screen memory */
            char_attr_vmem = *video_mem;
            if( char_attr_bios == char_attr_vmem ) {
                /* restore character that was there */
                *video_mem = char_attr_bios ^ 1;
                text_mode = 1;
            }
        }
    }
    /* restore cursor position for current page */
    BIOSSetCurPos( cursor_position.row, cursor_position.col, page );
    return( text_mode );
}

bool intern initmonitor( void )
/*****************************/
{
    register    bool                    ega;
    register    unsigned char           mode;
    struct      ega_info                info;

    if( UIData == NULL ) {
        UIData = &ui_data;
    }

    BIOSVidPage = BIOSGetPage();
    mode = BIOSGetMode();
    UIData->width = BIOSGetColumns();
    UIData->height = 25;
    info = BIOSEGAInfo();
    if( info.switches < 0x0C && info.mono <= 0x01 && info.mem <= 0x03 ) {
        UIData->height = BIOSGetRows();
        ega = TRUE;
    } else {
        ega = FALSE;
    }
    if( ( mode == MONOCHROME ) || ( mode == EGA_HIGH_MONO ) ) {
        UIData->colour = M_MONO;
    } else if( ( mode == ALPHA_SMALL_COL ) || ( mode == ALPHA_LARGE_COL ) ) {
        if( ega ) {
            UIData->colour = M_EGA;
        } else {
            UIData->colour = M_CGA;
        }
    } else if( ( mode == ALPHA_SMALL_BW ) || ( mode == ALPHA_LARGE_BW ) ) {
        UIData->colour = M_BW;
    } else if( mode > VGA_256COL ) {
        /*
            if mode is out of known range then assume it's a VGA/SVGA mode
        */
        UIData->colour = M_VGA;
    } else {
        return( FALSE );
    }

    return( TRUE );
}


int intern initbios( void )
/*************************/
{
    int                                 initialized;
    unsigned short far                  *poffset;
    LPPIXEL                             old_origin;

    initialized = FALSE;
    if( initmonitor() ) {
        UIData->desqview = (desqview_present() != 0);
        UIData->f10menus = TRUE;

        poffset = firstmeg( BIOS_PAGE, SCREEN_OFFSET );
        if( UIData->colour == M_MONO ) {
            UIData->screen.origin = firstmeg( 0xb000, *poffset );
        } else {
            UIData->screen.origin = firstmeg( 0xb800, *poffset );
        }
        if( UIData->desqview ) {
            UIData->screen.origin =
             (PIXEL far *)video_buffer( UIData->screen.origin );
        }
        if( uiisdbcs() ) {
            old_origin = UIData->screen.origin;
            UIData->screen.origin =
             (PIXEL far *)video_buffer( UIData->screen.origin );
            if( old_origin != UIData->screen.origin ) {
                UIData->desqview = TRUE;
            }
            DBCSCharacterMap(); /* in UIMAPCH.C */
        }
        UIData->screen.increment = UIData->width;

        /* if we are in a text mode then continue the initialization */
        if( IsTextMode() ) {
            uiinitcursor();
            initkeyboard();
            UIData->mouse_acc_delay = 5;   /* ticks */
            UIData->mouse_rpt_delay = 1;   /* ticks */
            UIData->mouse_clk_delay = 5;   /* ticks */
            UIData->tick_delay = 9;        /* ticks */
            UIData->mouse_speed = 8;       /* mickeys to ticks ratio */
            initialized = TRUE;
        }
    }
    return( initialized );
}

unsigned global uiclockdelay( unsigned milli )
{
    /* this routine converts milli-seconds into platform  */
    /* dependant units - used to set mouse & timer delays */
    return( milli * 18 / 1000 );
}


void intern finibios( void )
/**************************/
{
    uifinicursor();
}


/* update the physical screen with contents of virtual copy */

void intern physupdate( SAREA *area )
/*************************************/
{
    int i;
    unsigned short offset;
    unsigned short count;

/*
    The code for desqview_update is identical for DOS/V
    (Update Video Display: int 10h, AH=FFh, CX=count, ES:DI=buffer)
*/

#ifdef __386__
            union       REGPACK                 regs;
#else
            #pragma aux desqview_update = 0xcd 0x10 parm [ah] [es] [di] [cx];
            extern void desqview_update( char, unsigned, unsigned, unsigned );
#endif

        if( UIData->desqview ) {
            count = area->width * sizeof( PIXEL );
            for( i = area->row; i < (area->row + area->height); i++ ) {
                offset = ( i * UIData->width + area->col ) * sizeof( PIXEL );

#ifdef __386__
            memset( &regs, 0, sizeof( regs ) );
            if( _IsPharLap() ) {

// This code does not work as advertised under DOS/V
//              regs.h.ah = 0xff; /* update logical screen buffer request */
//              regs.w.es = FP_SEG( UIData->screen.origin );
//              regs.x.edi = FP_OFF( UIData->screen.origin );
//              regs.x.edi += offset;
//              regs.w.cx = count;
//              intr( BIOS_VIDEO, &regs );

                PHARLAP_block pblock;

                memset( &pblock, 0, sizeof( pblock ) );
                pblock.int_num = BIOS_VIDEO;        /* VIDEO call */
                pblock.real_eax = 0xff00;           /* update from v-screen */
                pblock.real_es = FP_OFF( UIData->screen.origin ) >> 4;
                regs.x.edi = (FP_OFF( UIData->screen.origin ) & 0x0f) + offset;
                regs.w.cx = count;
                regs.x.eax = 0x2511;                /* issue real-mode interrupt */
                regs.x.edx = FP_OFF( &pblock );     /* DS:EDX -> parameter block */
                regs.w.ds = FP_SEG( &pblock );
                intr( 0x21, &regs );

            } else if( _IsRational() ) {
                rm_call_struct  dblock;

                memset( &dblock, 0, sizeof( dblock ) );
                dblock.eax = 0xff00;                /* update from v-screen */
                dblock.es = FP_OFF( UIData->screen.origin ) >> 4;
                dblock.edi = (FP_OFF( UIData->screen.origin ) & 0x0f)
                               + offset;
                dblock.ecx = count;
                DPMISimulateRealModeInterrupt( BIOS_VIDEO, 0, 0, &dblock );
            }
#else
            desqview_update( 0xff, FP_SEG( UIData->screen.origin ),
                            FP_OFF( UIData->screen.origin ) + offset, count );
#endif
            } /* for */
        } /* if */
}

⌨️ 快捷键说明

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