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

📄 api.asm

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 ASM
📖 第 1 页 / 共 5 页
字号:
        popm    eax,edx
;
@@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      @@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
;
@@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      @@9
;
        mov     [ebp+Int_EDX],eax
        mov     [ebp+Int_ECX],ebx
;
@@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      @@2
        sys     GetSel
        jc      @@0
        mov     edx,esi
        jecxz   @@3
        dec     ecx             ;limit=length-1
@@3:    sys     SetSelDet32
        mov     [ebp+Int_BX],bx
        clc
        jmp     @@1
@@0:    call    mcbRelMemLinear32
        stc
        jmp     @@1
        ;
@@2:    mov     dx,cx
        shr     ecx,16
        mov     ax,[ebp+Int_CX]
        shl     eax,16
        mov     ax,[ebp+Int_DX]
        cmp     eax,-2
        jz      @@5
        cmp     eax,-1
        jnz     @@4
@@5:    mov     [ebp+Int_CX],cx
        mov     [ebp+Int_DX],dx
@@4:    stc
        ;
@@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      @@9
        assume ds:nothing
        cmp     cs:mcbLastChunk,0       ;DPMI memory?
        assume ds:_apiCode
        jnz     @@1
;
;Allocate a selector for this memory.
;
        sys     GetSel
        jc      @@8
        mov     edx,esi
        jecxz   @@0
        dec     ecx             ;limit=length-1
@@0:    sys     SetSelDet32
        xor     dx,dx
        jmp     @@7
;
;Get chunk's selector.
;
@@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.
;
@@7:    mov     [ebp+Int_SI],bx
        mov     [ebp+Int_DI],dx
        clc
        jmp     @@9
;
@@8:    call    mcbRelMemLinear32
        stc
;
@@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      @@2
        sys     GetSel
        jc      @@0
        mov     edx,esi
        jecxz   @@3
        dec     ecx             ;limit=length-1
        sys     SetSelDet32
@@3:    mov     [ebp+Int_BX],bx
        clc
        jmp     @@1
@@0:    call    mcbRelMemLinear32
        stc
        jmp     @@1
        ;
@@2:    cmp     d[ebp+Int_ECX],-1
        jz      @@5
        cmp     d[ebp+Int_ECX],-2
        jnz     @@4
@@5:    mov     [ebp+Int_ECX],ecx
@@4:    stc
        ;
@@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      @@9
        call    mcbResMemLinear32       ;re-size the memory.
        jc      @@9
        mov     edx,esi
        dec     ecx
        sys     SetSelDet32
@@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      @@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      @@9
;
;Check new block type.
;
        assume ds:nothing
        cmp     cs:mcbLastChunk,0       ;DPMI memory?
        assume ds:_apiCode
        jnz     @@1
;
;Update selectors details.
;
        mov     edx,esi
        dec     ecx
        sys     SetSelDet32
        xor     dx,dx
        jmp     @@7
;
;Get chunk's selector.
;
@@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     @@7
        push    bx
        mov     bx,w[ebp+Int_SI]
        sys     RelSel          ;release the selector.
        pop     bx
;
@@7:    mov     [ebp+Int_SI],bx
        mov     [ebp+Int_DI],dx
        clc
;
@@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.
;
;On Entry:
;
;BX     - Selector for block.
;ECX    - New size of block required in bytes.
;
;On Exit:
;
;Carry clear if OK.
;
cwAPI_ResMem32  proc    near
        mov     bx,[ebp+Int_BX]
        mov     ecx,[ebp+Int_ECX]
        push    ecx
        sys     GetSelDet32             ;Get selector base address.
        mov     esi,edx
        pop     ecx
        jc      @@9
        call    mcbResMemLinear32       ;re-size the memory.
        jc      @@9
        mov     edx,esi
        dec     ecx
        sys     SetSelDet32
@@9:    cwAPI_C2C
        ret
cwAPI_ResMem32  endp


;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Release previously allocated block of memory. Is be used for memory allocated
;by either GetMem or GetMem32.
;
;
;On Entry:
;
;BX     - Selector for block to release.
;
cwAPI_RelMem    proc    near
        mov     bx,[ebp+Int_BX]
        sys     GetSelDet32             ;Get selector base address.
        jc      @@9
        mov     esi,edx
        mov     ds,[ebp+Int_DS]
        mov     es,[ebp+Int_ES]
        mov     fs,[ebp+Int_FS]
        mov     gs,[ebp+Int_GS]
        sys     RelSel          ;release the selector.
        mov     [ebp+Int_DS],ds
        mov     [ebp+Int_ES],es
        mov     [ebp+Int_FS],fs
        mov     [ebp+Int_GS],gs
        call    mcbRelMemLinear32       ;release the memory.
@@9:    cwAPI_C2C
        ret
cwAPI_RelMem    endp


;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Release block of memory allocated via GetMemSO.
;
;On Entry:
;
;SI:DI  - Selector:offset for block to release.
;
cwAPI_RelMemSO  proc    near
;
;Zero any segment registers using this selector.
;
        mov     bx,w[ebp+Int_SI]
        and     bx,0ffffh-3
        jz      @@bad           ; MED 11/18/96, screen out null pointer releases
        xor     cx,cx
        mov     ax,w[ebp+Int_DS]
        and     ax,0ffffh-3
        cmp     ax,bx
        jnz     @@0
        mov     w[ebp+Int_DS],cx
        mov     ds,cx
@@0:    mov     ax,w[ebp+Int_ES]
        and     ax,0ffffh-3
        cmp     ax,bx
        jnz     @@1
        mov     w[ebp+Int_ES],cx
        mov     es,cx
@@1:    mov     ax,w[ebp+Int_FS]
        and     ax,0ffffh-3
        cmp     ax,bx
        jnz     @@2
        mov     w[ebp+Int_FS],cx
        mov     fs,cx
@@2:    mov     ax,w[ebp+Int_GS]
        and     ax,0ffffh-3
        cmp     ax,bx
        jnz     @@3
        mov     w[ebp+Int_GS],cx
        mov     gs,cx

⌨️ 快捷键说明

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