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

📄 api1.asm

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 ASM
📖 第 1 页 / 共 5 页
字号:
;*****************************************************************************
;*
;*                            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 FILE DOES, PLEASE
;*               DESCRIBE IT HERE!
;*
;*****************************************************************************



        NAME    APILIB
        TITLE   DESQview API Interface Library

; To change compilers simply change the definition of "compiler"
; to one of the following and reassemble:

        microsoft       equ     0
        turboc          equ     1
        lattice         equ     2
        metaware        equ     3
        watcom          equ     4

        compiler        equ     watcom

; To change memory models simply change the definition of "_model"
; to one of the following and reassemble:

        _small          equ     0
        _compact        equ     1
        _medium         equ     2
        _large          equ     3
        _huge           equ     4

        _model          equ     _compact

; The remaining control variables are computed based on the COMPILER
; and MODEL variables.  They may be set manually if the default values
; are inappropriate.  The meanings of these variables are:
;
;       farcode         - use FAR procedures
;       fardata         - use FAR data pointers
;       shortnames      - use 8-character names
;       underscore      - precede external names with an underscore

farcode     equ (_model eq _medium) or (_model eq _large) or (_model eq _huge)
fardata     equ (_model eq _compact) or (_model eq _large) or (_model eq _huge)
shortnames  equ (compiler eq lattice)
underscore  equ (compiler eq microsoft) or (compiler eq turboc) or (compiler eq watcom)


; The following macros replace the PROC, ENDP, PUBLIC, and EXTRN
; pseudo-ops with versions that take the control variables into account.

emit_proc macro name,x          ; emit a PROC pseudo-op
    public name
  if farcode
    name proc far
  else
    name proc near
  endif
  endm

emit_endp macro name,x          ; emit an ENDP pseudo-op
    name endp
  endm

emit_extrn macro name,distance  ; emit an EXTRN pseudo-op
    extrn &name:&distance
  endm

emit_public macro name,x        ; emit a PUBLIC pseudo-op
    public name
  endm

add_under macro name,x,mac      ; conditionally add an underscore to the name
  if underscore
    mac _&name,x
  else
    mac name,x
  endif
  endm

make_name macro short,rest,x,mac ; pass either the short or long name
  if shortnames
    add_under short,x,mac
  else
    add_under short&rest,x,mac
  endif
  endm

function macro short,rest       ; used instead of PROC
  make_name short,rest,,emit_proc
  endm

endfunc macro short,rest        ; used instead of ENDP
  make_name short,rest,,emit_endp
  endm

ext macro short,rest            ; used instead of EXTRN
  if farcode
    make_name short,rest,FAR,emit_extrn
  else
    make_name short,rest,NEAR,emit_extrn
  endif
  endm

pub macro short,rest            ; used instead of PUBLIC
  make_name short,rest,,emit_public
  endm


; The following macros are used to define the stack frame on entry to
; an API function.  The "frame" macro accounts for the return address
; and any registers that have been pushed since the call.  The "arg"
; macro assigns offset values for each argument name according to the
; COMPILER and MODEL being used.

frame macro pushed
    if farcode
        _off = 6
    else
        _off = 4
    endif
    ifnb <pushed>
        _off = _off + pushed * 2
    endif
    endm

arg macro aname,atype
        aname = _off
    ifidn <atype>,<word>
        _off = _off + 2
    else
    ifidn <atype>,<dword>
        _off = _off + 4
    else
    ifidn <atype>,<fptr>
        _off = _off + 4
    else
    ifidn <atype>,<ptr>
      if fardata
        _off = _off + 4
      else
        _off = _off + 2
      endif
    else
    ifidn <atype>,<cptr>
      if (compiler eq lattice)
        if fardata
          _off = _off + 4
        else
          _off = _off + 2
        endif
      else
      if farcode
        _off = _off + 4
      else
        _off = _off + 2
      endif
      endif
    endif
    endif
    endif
    endif
    endif
    endm


; The "fix_long" macro is a hook to support different conventions
; for how DWORD values are returned to C.  The API functions always
; setup such values in DX:AX (Microsoft convention).  The "fix_long"
; macro is called just before a function returns to allow these
; registers to be changed.

fix_long macro
    if (compiler eq lattice)
        mov     bx,ax
        mov     ax,dx
    endif
    endm


; The following macros are used to access code and data pointers.
; They take into account the COMPILER and MODEL being used.

push_dptr macro  addr           ; push data pointer
    if fardata
        push     addr+2
    else
        push     ds
    endif
        push     addr
    endm

push_fptr macro  addr           ; push data pointer
    push         addr+2
    push         addr
    endm

push_cptr macro  addr           ; push code pointer
    if (compiler eq lattice) and (farcode) and (not fardata)
        push    di
        mov     di,addr
        push    [di+2]
        push    [di]
        pop     di
    else
    if farcode
        push    addr+2
        push    addr
    else
        push    cs
        push    addr
    endif
    endif
    endm

load_dptr macro seg,off, addr   ; load data pointer into registers
    if fardata
        mov     seg, addr+2
    else
        push    ds
        pop     seg
    endif
        mov     off, addr
    endm

load_fptr macro seg,off, addr   ; load data pointer into registers
    mov seg, addr+2
    mov off, addr
    endm

load_cptr macro seg,off, addr   ; load code pointer into registers
    if (compiler eq lattice) and (farcode) and (not fardata)
      ifdif <off>,<di>
          push  di
      endif
          mov   di,addr
          mov   seg,[di+2]
          mov   off,[di]
      ifdif <off>,<di>
          pop   di
      endif
    else
    if farcode
        mov     seg,addr+2
        mov     off,addr
    else
        push    cs
        pop     seg
        mov     off,addr
    endif
    endif
    endm

; The following macros test code and data pointers for NULL.

null_dptr macro  addr           ; test data pointer for NULL
    local L1
        cmp     word ptr  addr,0
    if fardata
        jne     L1
        cmp     word ptr  addr+2,0
L1:
    endif
    endm

null_cptr macro  addr           ; test code pointer for NULL
    local L1
        cmp     word ptr  addr,0
    if farcode
        jne     L1
        cmp     word ptr  addr+2,0
L1:
    endif
    endm


; The following conditionals select appropriate segment declarations
; for each COMPILER and MODEL.  The results are four macros (dseg, dend
; cseg, cend) that are invoked later to do the actual declarations.

if (compiler eq microsoft) or (compiler eq turboc) or (compiler eq watcom)

        dseg    macro
        DGROUP  GROUP   _DATA
                ASSUME  DS:DGROUP
        _DATA   SEGMENT WORD PUBLIC 'DATA'
                public  _dvapibuf
        _dvapibuf db    260 dup (?)
                endm

        dend    macro
        _DATA    ENDS
                endm

  if (farcode eq 0)

        cseg    macro
        _TEXT   SEGMENT BYTE PUBLIC 'CODE'
                ASSUME  CS:_TEXT
                endm

        cend    macro
        _TEXT  ENDS
                endm

  else

        cseg    macro
        API1_TEXT SEGMENT BYTE PUBLIC 'CODE'
                ASSUME  CS:API1_TEXT
                endm

        cend    macro
        API1_TEXT ENDS
                endm

    endif

else
if (compiler eq metaware)

        dseg    macro
        DGROUP  GROUP   _DATA
                ASSUME  DS:DGROUP
        _DATA   SEGMENT WORD PUBLIC 'DATA'
                public   dvapibuf
        dvapibuf db    260 dup (?)
                endm

        dend    macro
        _DATA    ENDS
                endm

  if (farcode eq 0)

        cseg    macro
        CODE    SEGMENT BYTE PUBLIC 'CODE'
        CGROUP  GROUP   CODE
                ASSUME  CS:CGROUP
                endm

        cend    macro
         CODE  ENDS
                endm

  else

        cseg    macro
        API1_TEXT SEGMENT BYTE PUBLIC 'CODE'
                ASSUME  CS:API1_TEXT
                endm

        cend    macro
        API1_TEXT ENDS
                endm

    endif

else
if (compiler eq lattice)

        dseg    macro
        DGROUP  GROUP   DATA
        DATA    SEGMENT WORD PUBLIC 'DATA'
                public  dvapibuf
        dvapibuf db     260 dup (?)
                endm

        dend    macro
        DATA    ENDS
                endm

    if (farcode eq 0) and (fardata eq 0)

        cseg    macro
        PGROUP  GROUP   PROG
        PROG    SEGMENT BYTE PUBLIC 'PROG'
                ASSUME  CS:PGROUP
                endm
        cend    macro
        PROG    ENDS
                endm

    else
    if farcode and (fardata eq 0)

        cseg    macro
        _CODE   SEGMENT BYTE PUBLIC 'CODE'
                ASSUME  CS:_CODE
                endm
        cend    macro
        _CODE   ENDS
                endm

    else
    if (farcode eq 0) and fardata

        cseg    macro
        CGROUP  GROUP   CODE
        CODE    SEGMENT BYTE PUBLIC 'CODE'
                ASSUME  CS:CGROUP
                endm
        cend    macro
        CODE    ENDS
                endm

    else
    if farcode and fardata

        cseg    macro
        _PROG   SEGMENT BYTE PUBLIC 'PROG'
                ASSUME  CS:_PROG
                endm
        cend    macro
        _PROG   ENDS
                endm

    endif
    endif
    endif
    endif

endif
endif
endif

; All the control variables and associated macros have been defined.
; Its time to generate some code!


include dvapi.inc  ; define API assembly language interfaces

; if (compiler eq watcom)
;       if farcode
;         emit_extrn  sprintf_,FAR
;       else
;         emit_extrn  sprintf_,NEAR
;       endif
; else
;       ext     sprintf,        ; declare sprintf to be external
; endif

        dseg                    ; data segment starts here
        dend                    ;   and ends here

        cseg                    ; code segment starts here

        pub     win_stre,am     ; make win_stream public

CrunDS     dw   0               ; C's DS value
apiversion dw   0               ; API version number
lockobj    dw   0,0             ; dvapibuf access semaphore

; The following functions are used internally by the C Library
; to control access to the dvapibuf buffer.

; dvlockb
    function dvlockb,
        @send   lock,cs:lockobj
        ret
    endfunc dvlockb,

; dvfreeb
    function dvfreeb,
        @send   close,cs:lockobj
        ret
    endfunc dvfreeb,


; The remainder of this module contains the API interface functions.
; Functions having similar interfaces are grouped together to allow
; as much sharing of code as possible.  The result is that any given
; function is hard to find unless you search for it using an editor.

; api_beginc
    function api_begi,nc
        @call   beginc
        xor     ax,ax
        ret
    endfunc api_begi,nc

; win_disperor
    function win_disp,eror
    frame
    arg winhan,dword
    arg buffer,ptr
    arg lbuffer,word
    arg rows,word
    arg cols,word
    arg beep,word
    arg buttons,word
        push    bp
        mov     bp,sp

⌨️ 快捷键说明

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