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

📄 api.asm

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 ASM
📖 第 1 页 / 共 5 页
字号:
        mov     [ebp+Int_BX],ax
        movzx   edx,ax
        movzx   ecx,cx
        mov     ax,Res_SEL
api18_0:        call    RegisterResource
        add     edx,8
        dec     ecx
        jnz     api18_0
;
api18_9:        ret
cwAPI_GetSels   endp


;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Release a selector.
;
;On Entry:
;
;BX     - Selector to release.
;
cwAPI_RelSel    proc    near
        mov     bx,[ebp+Int_BX]
        mov     ds,[ebp+Int_DS]
        mov     es,[ebp+Int_ES]
        mov     fs,[ebp+Int_FS]
        mov     gs,[ebp+Int_GS]
        call    _RelSelector
        cwAPI_C2C
        jc      api19_9
        mov     [ebp+Int_DS],ds
        mov     [ebp+Int_ES],es
        mov     [ebp+Int_FS],fs
        mov     [ebp+Int_GS],gs
api19_9:        ret
cwAPI_RelSel    endp


;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Force a selector to be type CODE.
;
;On Entry:
;
;BX     - Selector.
;
cwAPI_CodeSel   proc    near
        mov     bx,[ebp+Int_BX]
        call    _CodeSelector
        cwAPI_C2C
        ret
cwAPI_CodeSel   endp


;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Allocate a selector with type DATA that maps same memory as another selector.
;
;On Entry:
;
;BX     - selector.
;
;Returns:
;
;AX     - New selector.
;
cwAPI_AliasSel  proc    near
        mov     ax,000ah
        mov     bx,[ebp+Int_BX]
        cwAPI_CallOld
        cwAPI_C2C
        jc      api21_9
;
        mov     [ebp+Int_AX],ax
        push    eax
        push    edx
        movzx   edx,ax
        mov     ax,Res_SEL
        call    RegisterResource
        pop     edx
        pop     eax
;
api21_9:        ret
cwAPI_AliasSel  endp


;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Get selector base & limit.
;
;On Entry:
;
;BX     - selector.
;
;Returns:
;
;CX:DX  - Linear base.
;SI:DI  - Byte granular limit.
;
cwAPI_GetSelDet proc near
        mov     bx,[ebp+Int_BX]
        call    _DetSelector
        cwAPI_C2C
        jc      api22_9
;
        mov     ecx,eax         ;get base.
        mov     dx,cx
        shr     ecx,16
        mov     esi,ebx         ;get limit.
        mov     di,si
        shr     esi,16
        mov     [ebp+Int_CX],cx
        mov     [ebp+Int_DX],dx
        mov     [ebp+Int_SI],si
        mov     [ebp+Int_DI],di
;
api22_9:        ret
cwAPI_GetSelDet endp


;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Get selector base & limit.
;
;On Entry:
;
;BX     - selector.
;
;Returns:
;
;EDX    - base
;ECX    - limit
;
cwAPI_GetSelDet32 proc near
        mov     bx,[ebp+Int_BX]
        call    _DetSelector
        cwAPI_C2C
        jc      api23_9
;
        mov     [ebp+Int_EDX],eax
        mov     [ebp+Int_ECX],ebx
;
api23_9:        ret
cwAPI_GetSelDet32 endp


;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Set selectors base & limit.
;
;On Entry:
;
;BX     - selector
;CX:DX  - Linear base.
;SI:DI  - Byte granular limit.
;
cwAPI_SetSelDet proc near
        mov     cx,[ebp+Int_CX]
        mov     dx,[ebp+Int_DX]
        mov     si,[ebp+Int_SI]
        mov     di,[ebp+Int_DI]
        shl     ecx,16          ;Get base to somewhere useful.
        mov     cx,dx
        mov     eax,ecx
        shl     esi,16          ;get limit to somewhere useful.
        mov     si,di
        mov     ebx,esi
        mov     cx,[ebp+Int_BX]
        call    _SizeSelector
        cwAPI_C2C
        ret
cwAPI_SetSelDet endp


;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Set a selectors details.
;
;On Entry:
;
;BX     - selector
;EDX    - base
;ECX    - limit.
;
cwAPI_SetSelDet32 proc near
        mov     cx,[ebp+Int_BX]
        mov     eax,[ebp+Int_EDX]
        mov     ebx,[ebp+Int_ECX]
        call    _SizeSelector
        cwAPI_C2C
        ret
cwAPI_SetSelDet32 endp


;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Allocate some memory with a selector attatched.
;
;On Entry:
;
;CX:DX  - Size of block required in bytes. (-1:-1 to get maximum memory size)
;
;On Exit:
;
;Carry clear if OK &
;
;BX     - Selector to access the block with.
;
;Else if CX:DX was -1, CX:DX is size of largest block available.
;
cwAPI_GetMem    proc    near
        mov     cx,[ebp+Int_CX]
        mov     dx,[ebp+Int_DX]
        shl     ecx,16
        mov     cx,dx

; MED 06/25/97
        push    ds              ; test padding flag
        mov     ds,cs:apiDSeg
        assume ds:_cwMain
        test    Pad1Flag,-1
        pop     ds
        assume ds:nothing
        je      gm2             ; padding flag not turned on
        test    ecx,0ffff0000h
        jne     gm2             ; don't pad >64K allocation
        add     ecx,1023
        and     ecx,NOT 1023    ; pad to 1K-boundary allocation
gm2:

        call    mcbGetMemLinear32
        jc      api26_2
        sys     GetSel
        jc      api26_0
        mov     edx,esi
        jecxz   api26_3
        dec     ecx             ;limit=length-1
api26_3:        sys     SetSelDet32
        mov     [ebp+Int_BX],bx
        clc
        jmp     api26_1
api26_0:        call    mcbRelMemLinear32
        stc
        jmp     api26_1
        ;
api26_2:        mov     dx,cx
        shr     ecx,16
        mov     ax,[ebp+Int_CX]
        shl     eax,16
        mov     ax,[ebp+Int_DX]
        cmp     eax,-2
        jz      api26_5
        cmp     eax,-1
        jnz     api26_4
api26_5:        mov     [ebp+Int_CX],cx
        mov     [ebp+Int_DX],dx
api26_4:        stc
        ;
api26_1:        cwAPI_C2C
        ret
cwAPI_GetMem    endp


;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Allocate some memory and return selector:offset (16-bit).
;
;On Entry:
;
;CX:DX  - Size of block required in bytes.
;
;On Exit:
;
;Carry set on error else,
;
;SI:DI  - selector:offset of allocated memory.
;
cwAPI_GetMemSO  proc    near
        mov     cx,[ebp+Int_CX]
        mov     dx,[ebp+Int_DX]
        shl     ecx,16
        mov     cx,dx
        call    mcbGetMemLinear32       ;allocate some memory.
        jc      api27_9
        assume ds:nothing
        cmp     cs:mcbLastChunk,0       ;DPMI memory?
        assume ds:_apiCode
        jnz     api27_1
;
;Allocate a selector for this memory.
;
        sys     GetSel
        jc      api27_8
        mov     edx,esi
        jecxz   api27_0
        dec     ecx             ;limit=length-1
api27_0:        sys     SetSelDet32
        xor     dx,dx
        jmp     api27_7
;
;Get chunk's selector.
;
api27_1:        push    es
        assume ds:nothing
        mov     es,cs:apiDSeg
        assume es:_cwMain
        mov     es,RealSegment
        assume es:nothing
        mov     edi,cs:mcbLastChunk
        assume ds:_apiCode
        mov     bx,es:[edi+mcbChunkSel] ;get chunk selector.
        pop     es
        mov     edx,esi
        sub     edx,edi         ;get blocks offset.
;
api27_7:        mov     [ebp+Int_SI],bx
        mov     [ebp+Int_DI],dx
        clc
        jmp     api27_9
;
api27_8:        call    mcbRelMemLinear32
        stc
;
api27_9:        cwAPI_C2C
        ret
cwAPI_GetMemSO  endp


;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;On Entry:
;
;ECX    - Size of block required in bytes. (-1 to get maximum memory size)
;
;On Exit:
;
;Carry clear if OK &
;
;BX     - Selector to access the block with.
;
;Else if ECX was -1, ECX is size of largest block available.
;
cwAPI_GetMem32  proc near
        mov     ecx,[ebp+Int_ECX]
        call    mcbGetMemLinear32
        jc      api28_2
        sys     GetSel
        jc      api28_0
        mov     edx,esi
        jecxz   api28_3
        dec     ecx             ;limit=length-1
        sys     SetSelDet32
api28_3:        mov     [ebp+Int_BX],bx
        clc
        jmp     api28_1
api28_0:        call    mcbRelMemLinear32
        stc
        jmp     api28_1
        ;
api28_2:        cmp     d[ebp+Int_ECX],-1
        jz      api28_5
        cmp     d[ebp+Int_ECX],-2
        jnz     api28_4
api28_5:        mov     [ebp+Int_ECX],ecx
api28_4:        stc
        ;
api28_1:        cwAPI_C2C
        ret
cwAPI_GetMem32  endp


;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Re-size a previously allocated block of memory.
;
;On Entry:
;
;BX     - Selector for block.
;CX:DX  - New size of block required in bytes.
;
;On Exit:
;
;Carry clear if OK.
;
cwAPI_ResMem    proc    near
        mov     bx,[ebp+Int_BX]
        mov     cx,[ebp+Int_CX]
        mov     dx,[ebp+Int_DX]
        shl     ecx,16          ;convert new size to 32-bit.
        mov     cx,dx
        push    ecx
        sys     GetSelDet32             ;Get selector base address.
        mov     esi,edx
        pop     ecx
        jc      api29_9
        call    mcbResMemLinear32       ;re-size the memory.
        jc      api29_9
        mov     edx,esi
        dec     ecx
        sys     SetSelDet32
api29_9:        cwAPI_C2C
        ret
cwAPI_ResMem    endp


;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Re-size a previously allocated block of memory.
;
;On Entry:
;
;SI:DI  - Selector:offset for block.
;CX:DX  - New size of block required in bytes.
;
;On Exit:
;
;Carry set on error else,
;
;SI:DI  - selector:offset new block address.
;
cwAPI_ResMemSO  proc    near
        mov     ds,[ebp+Int_DS]
        mov     es,[ebp+Int_ES]
        mov     fs,[ebp+Int_FS]
        mov     gs,[ebp+Int_GS]
;
        mov     bx,w[ebp+Int_SI]
        sys     GetSelDet32             ;get selectors details.
        jc      api30_9
        mov     esi,edx
        movzx   eax,w[ebp+Int_DI]
        add     esi,eax         ;get memory blocks address.
        mov     cx,[ebp+Int_CX]
        mov     dx,[ebp+Int_DX]
        shl     ecx,16          ;convert new size to 32-bit.
        mov     cx,dx
        call    mcbResMemLinear32       ;re-size the memory.
        jc      api30_9
;
;Check new block type.
;
        assume ds:nothing
        cmp     cs:mcbLastChunk,0       ;DPMI memory?
        assume ds:_apiCode
        jnz     api30_1
;
;Update selectors details.
;
        mov     edx,esi
        dec     ecx
        sys     SetSelDet32
        xor     dx,dx
        jmp     api30_7
;
;Get chunk's selector.
;
api30_1:        push    es
        assume ds:nothing
        mov     es,cs:apiDSeg
        assume es:_cwMain
        mov     es,RealSegment
        assume es:nothing
        mov     edi,cs:mcbLastChunk
        assume ds:_apiCode
        mov     bx,es:[edi+mcbChunkSel] ;get chunk selector.
        pop     es
        mov     edx,esi
        sub     edx,edi         ;get blocks offset.
;
;Check if the old block had it's own selector.
;
        cmp     w[ebp+Int_DI],0 ;offset of zero?
        jnz     api30_7
        push    bx
        mov     bx,w[ebp+Int_SI]
        sys     RelSel          ;release the selector.
        pop     bx
;
api30_7:        mov     [ebp+Int_SI],bx
        mov     [ebp+Int_DI],dx
        clc
;
api30_9:        cwAPI_C2C
        mov     [ebp+Int_DS],ds
        mov     [ebp+Int_ES],es
        mov     [ebp+Int_FS],fs
        mov     [ebp+Int_GS],gs
        ret
cwAPI_ResMemSO  endp


;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Re-size a previously allocated block of memory.

⌨️ 快捷键说明

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