window3.c

来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 346 行

C
346
字号
/****************************************************************************
*
*                            Open Watcom Project
*
*    Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
*  ========================================================================
*
*    This file contains Original Code and/or Modifications of Original
*    Code as defined in and that are subject to the Sybase Open Watcom
*    Public License version 1.0 (the 'License'). You may not use this file
*    except in compliance with the License. BY USING THIS FILE YOU AGREE TO
*    ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
*    provided with the Original Code and Modifications, and is also
*    available at www.sybase.com/developer/opensource.
*
*    The Original Code and all software distributed under the License are
*    distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
*    EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
*    ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
*    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
*    NON-INFRINGEMENT. Please see the License for the specific language
*    governing rights and limitations under the License.
*
*  ========================================================================
*
* Description:  WHEN YOU FIGURE OUT WHAT THIS MODULE DOES, PLEASE
*               DESCRIBE IT HERE!
*
****************************************************************************/



#include "app.h"

extern WNDNUMROWS W3NumRows;

static gui_menu_struct W3PopUp[] = {
    { "Default Popup", MENU_W3_POPUP, GUI_ENABLED },
    { "Show Lisa The Bug", MENU_W3_BUG, GUI_ENABLED },
};

static char *Stuff[] =
{
#if 0
"With a Pentium compiler writer's guide in one hand, and a simulator",
"listing in the other, we set out to make WATCOM C/C++ 32 into a Pentium",
"aware compiler.  It looked easy at first glance, but as we got into it,",
"some interesting challenges emerged.  These are a few of things that we",
"learned.",
"",
"Instruction Scheduling",
"======================",
"",
"Because of the Pentium's multiple execution pipes, instruction",
"scheduling, or reordering, is by far the most important optimization",
"performed by the compiler.  A three phase approach to scheduling emerged",
"as the strategy of choice given the framework of the code genererator.",
"",
"First, 'RISC-ification'.  That is, reduction of integer instructions to",
"use the RISC subset of the instruction set.  For example, we turn an add",
"from memory into a load followed by an add from register.  The two",
"instructions are a bit larger, but no slower, and they give you more",
"freedom to choose an optimal instruction ordering.",
"",
"Second, 'scheduling'.  Move data dependant instructions so that they are",
"not adjacent.  Ideally, a result shouldn't be used until the instruction",
"has had enough time to complete all pipeline stages.  This allows your",
"code to take full advantage of the superscalar architecture, and leads",
"to considerable 486 execution speed improvement.",
"",
"Finally, 're-CISC-ification'.  Build instructions back up to take",
"advantage of complex instructions.  Often, data dependencies do not",
"allow scheduling in certain portions of the code.  You might turn  the",
"load/add sequence created in first phase back into an add from memory,",
"if there was no scheduling benefit.",
"",
"Quirks",
"=======",
"",
"There are some interesting architectural anomalies which can materially affect Pentium",
"performance."
"In order to reference 16 bit items, an operand size prefix has to",
"be used.  We do our best to eliminate these prefix bytes if",
"possible, but it's still a good idea to stay away from short integers.",
"",
"Floating-point instructions must also be scheduled to take full",
"advantage of the float pipe.  The FXCH instruction was designed to make",
"this easier.  It can execute simultaneously with other floating-point",
"instructions.  Since one operand of a floating-point instruction must be",
"ST(0), a free FXCH instruction allows floating-point sequences to be",
"scheduled for better throughput.  Two data independant sequences are",
"interleaved, and FXCH is inserted when an intermediate result needs to",
"be brought to the top of the stack.",
"",
"It sounds great, but before you re-write your floating point library to",
"take full advantage of the free FXCH instruction, you need to read the",
"fine print.  There are conditions that must be met before instruction",
"pairing occurs.",
"",
"First, the FXCH must be followed by another floating-point instruction.",
"Secondly, it must be preceded by a floating-point instruction which does",
"not pop the stack."
"If these",
"conditions are not met, your code may actually run slower, since the",
"FXCH instructions each take one clock cycle.",
"",
"Finally, here's something you might run across in the processor",
"documentation.  'Performing a floating-point operation on a memory",
"operand instead of on a stack register adds no cycles'.  True, assuming",
"a cache hit.  However, there is a clock penalty for cache misses."
"Don't be fooled by the clock cycles.  Keep integer and",
"floating-point values in registers wherever possible.",
"",
"386/486 considerations",
"==================",
"",
"The 486 only has one integer pipe, and one float pipe, but it is still a",
"pipelined architecture.  An optimal Pentium ordering is usually optimal,",
"or nearly so, on the 486 as well.  The scheduling avoids pipeline",
"stalls, greatly increasing 486 performance.",
"",
"There is one major compromise which must be made if code is to be",
"optimized for both the Pentium and the 386/486.  In this case, you don't",
"use the FXCH instruction to achieve parallelism.  It may speed up",
"Pentium code considerably, but will not be free on a 386/486.",
"",
"16 bit code",
"===========",
"",
"Remember to optimize your 16-bit code for the Pentium as well.  All the",
"same rules apply, except that 32-bit operands now require a prefix byte.",
"Since WATCOM C uses a common code generator to produce both 16 and",
"32-bit code, WATCOM C/C++ 16 became Pentium aware for 'free'.  We",
"re-compiled a suite of small benchmarks programs, and were amazed when",
"we saw a 40% average speed increase, with improvements ranging up to a",
"factor of two in execution speed.",
"",
"Conclusion",
"==========",
"",
"The superscalar Pentium aware compiler described here is available",
"today.  With it you can create a singled .EXE (16 or 32-bit) that",
"delivers significant performance benefits on the 486, and is ready to",
"really fly on the Pentium processor.",
#else
"        title = 僐儅儞僪丒僾儘儞僾僩",
"        help = DOS 僐儅儞僪丒僾儘儞僾僩傪婲摦偟, 僐儅儞僪擖椡忬懺偵偟傑偡丅^m^m僐儅儞僪丒儔僀儞偐傜DOS 僔僃儖偵栠傞偨傔偵偼:^m^m1. exit 偲擖椡偟, ^m2. Enter(夵峴)僉乕傪墴偟偰偔偩偝偄丅^m^m娭楢崁栚"
"        pause = disabled",
"    }",
"    special = default",
"    program = ",
"    {",
"        command = SWITCH",
"        title = 塸岅儌乕僪傊愗傝懼偊",
"        help = 擔杮岅儌乕僪偐傜塸岅儌乕僪傊愗傝懼偊傑偡丅僞僗僋愗傝懼偊傪巊梡拞偵偼幚峴偟側偄偱偔偩偝偄丅",
"        pause = disabled",
"    }",
"    program = ",
"    {",
"        command = E %1",
"        title = PC DOS E 僄僨傿僞乕",
"        help = 僥僉僗僩丒僼傽僀儖傪曇廤偡傞 PC DOS E 僄僨傿僞乕傪婲摦偟傑偡丅偙偺僄僨傿僞乕傪慖傇偲曇廤偡傞僼傽僀儖柤傪擖椡偡傞僷僱儖偑昞帵偝傟傑偡丅^m^m娭楢崁栚^m   "
"        pause = disabled",
"        dialog = ",
"        {",
"            title = 曇廤僼傽僀儖柤偺擖椡",
"            info = 僼傽僀儖柤傪擖椡偟偰壓偝偄丅僼傽僀儖傪僆乕僾儞偣偢偵僄僨傿僞乕傪婲摦偡傞応崌偼丄Enter僉乕傪墴偟偰壓偝偄丅",
"            prompt = 曇廤僼傽僀儖柤?",
"            parameter = %1",
"        }",
"    }",
"    program = ",
"    {",
"        help = 僗働僕儏乕儔乕傪巊梡偡傟偽巜掕偟偨擔帪偵巜掕偟偨僾儘僌儔儉傪幚峴偡傞偙偲偑偱偒傑偡丅DOS僾儘儞僾僩偐傜婲摦偱偒傞僾儘僌儔儉偱偁傟偽偳傫側僾儘僌儔儉偱傕巜掕偡傞偙偲偑偱偒傑偡丅偨偩偟丄DOSSHELL 傪婲摦偡傞慜偵 CPSCHED.EXE(TSR) 傪忢挀偝偣偰偍偔昁梫偑偁傝傑偡丅",
"        screenmode = text",
"        alttab = enabled",
"        altesc = enabled",
"        ctrlesc = enabled",
"        prevent = disabled",
"        command = SCHEDULE",
"        title = Central Point僗働僕儏乕儔乕",
"        pause = disabled",
"    }",
"    program = ",
"    {",
"        help = 僼儖丒僗僋儕乕儞偺 UNDELETE 僾儘僌儔儉傪婲摦偟丄埲慜偵嶍彍偟偨僼傽僀儖偍傛傃僨傿儗僋僩儕乕傪暅尦偟傑偡丅"
"        screenmode = text",
"        alttab = enabled",
"        altesc = enabled",
"        ctrlesc = enabled",
"        prevent = disabled",
"        command = UNDELETE",
"        title = Central Point傾儞僨儕乕僩",
"        pause = disabled",
"    }",
"    group = ",
"    {",
"        title = 僨傿僗僋丒儐乕僥傿儕僥傿乕",
"        help = 僨傿僗僋娗棟偺偨傔偺儐乕僥傿儕僥傿乕偺僾儘僌儔儉丒傾僀僥儉傪昞帵偟傑偡丅傑偨, 儊僀儞丒僌儖乕僾傗捛壛偟偨僌儖乕僾傪僆乕僾儞偡傞偙偲傕偱偒傑偡丅",
"        program = ",
"        {",
"            command = diskcopy %1",
"            title = 僨傿僗働僢僩偺暋幨",
"            pause = enabled",
"            dialog = ",
"            {",
"                title = 僨傿僗働僢僩偺暋幨",
"                info = 暋幨尦偍傛傃暋幨愭僪儔僀僽傪擖椡偟偰偔偩偝偄丅",
"                prompt = 僷儔儊乕僞乕 . . .",
"                default = a: b:",
"                parameter = %1",
"            }",
"        }",
"        program = ",
"        {",
"            command = format %1 /q",
"            title = 僋僀僢僋丒僼僅乕儅僢僩",
"            pause = enabled",
"            dialog = ",
"            {",
"                title = 僋僀僢僋丒僼僅乕儅僢僩",
"                info = 僋僀僢僋丒僼僅乕儅僢僩偡傞僪儔僀僽傪擖椡偟偰偔偩偝偄丅",
"                prompt = 僷儔儊乕僞乕 . . .",
"                default = a:",
"                parameter = %1",
"            }",
"            screenmode = text",
"            alttab = enabled",
"            altesc = enabled",
"            ctrlesc = enabled",
"            prevent = enabled",
"        }",
"        program = ",
"        {",
"            command = format %1",
"            title = 僼僅乕儅僢僩",
"            pause = enabled",
"            dialog = ",
"            {",
"                title = 僼僅乕儅僢僩",
"                info = 僼僅乕儅僢僩偡傞僪儔僀僽傪擖椡偟偰偔偩偝偄丅",
"                prompt = 僷儔儊乕僞乕 . . .",
"                default = a:",
"                parameter = %1",
"            }",
"        }",
"        program = ",
"        {",
"            command = undelete %1",
"            title = 僼傽僀儖偺暅尦",
"            pause = enabled",
"            dialog = ",
"            {",
"                title = 僼傽僀儖偺暅尦",
"                info = 拲堄両偙偺僐儅儞僪偼嶍彍偟偨僼傽僀儖傪暅尦偱偒側偄偙偲偑偁傝傑偡丅徻偟偔偼, F1僉乕傪墴偟偰偔偩偝偄丅",
"                prompt = 僷儔儊乕僞乕 . . .",
"                default = /LIST",
"                parameter = %1",
"            }",
"            screenmode = text",
#endif
};

int TheSize = ArraySize( Stuff );

extern  WNDMENU W3MenuItem;
extern void     W3MenuItem( a_window *wnd, unsigned id, int row, int piece )
{
    row=row;piece=piece;
    switch( id ) {
    case MENU_W3_POPUP:
        Say2( "Default Popup", WndPopItem( wnd ) );
        break;
    case MENU_W3_BUG:
        TheSize = TheSize == ArraySize( Stuff ) ? 10 : ArraySize( Stuff );
        WndRepaint( wnd );
        break;
    }
}

extern  WNDMODIFY W3Modify;
extern  void    W3Modify( a_window *wnd, int row, int piece )
{
    W3MenuItem( wnd, 0, row, piece );
}


extern int W3NumRows( a_window *wnd )
{
    wnd=wnd;
    return( TheSize );
}

extern WNDGETLINE W3GetLine;
extern  bool    W3GetLine( a_window *wnd, wnd_row row, int piece,
                             wnd_line_piece *line )
{
    wnd=wnd;
    if( row >= TheSize ) return( FALSE );
    if( piece != 0 ) return( FALSE );
    line->text = Stuff[ row ];
    line->tabstop = TRUE;
//  line->extent = WND_MAX_EXTEND;
    return( TRUE );
}


extern WNDREFRESH W3Refresh;
void    W3Refresh( a_window *wnd )
{
    WndRepaint( wnd );
}

wnd_info W3Info = {
    NoEventProc,
    W3Refresh,
    W3GetLine,
    W3MenuItem,
    NoScroll,
    NoBegPaint,
    NoEndPaint,
    W3Modify,
    W3NumRows,
    NoNextRow,
    NoNotify,
    0,
    DefPopUp( W3PopUp )
};

extern WNDOPEN W3Open;
extern a_window *W3Open()
{
    a_window    *wnd;
    wnd_create_struct   info;

    WndInitCreateStruct( &info );
    info.info = &W3Info;
    wnd = WndCreateWithStruct( &info );
    if( wnd != NULL ) {
        WndSetSwitches( wnd, WSW_LBUTTON_SELECTS+WSW_CHAR_CURSOR );
        WndClrSwitches( wnd, WSW_HIGHLIGHT_CURRENT );
    }
    return( wnd );
}

⌨️ 快捷键说明

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