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

📄 api.asm

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 ASM
📖 第 1 页 / 共 5 页
字号:
;
;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      api31_9
        call    mcbResMemLinear32       ;re-size the memory.
        jc      api31_9
        mov     edx,esi
        dec     ecx
        sys     SetSelDet32
api31_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      api32_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.
api32_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      api33_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     api33_0
        mov     w[ebp+Int_DS],cx
        mov     ds,cx
api33_0:        mov     ax,w[ebp+Int_ES]
        and     ax,0ffffh-3
        cmp     ax,bx
        jnz     api33_1
        mov     w[ebp+Int_ES],cx
        mov     es,cx
api33_1:        mov     ax,w[ebp+Int_FS]
        and     ax,0ffffh-3
        cmp     ax,bx
        jnz     api33_2
        mov     w[ebp+Int_FS],cx
        mov     fs,cx
api33_2:        mov     ax,w[ebp+Int_GS]
        and     ax,0ffffh-3
        cmp     ax,bx
        jnz     api33_3
        mov     w[ebp+Int_GS],cx
        mov     gs,cx
api33_3:        ;
        mov     bx,w[ebp+Int_SI]
        sys     GetSelDet32             ;get selectors details.
        jc      api33_9
        mov     esi,edx
        movzx   eax,w[ebp+Int_DI]
        add     esi,eax         ;get memory blocks address.
        call    mcbRelMemLinear32       ;release the memory.
;
;Check if block had it's own selector.
;
        cmp     w[ebp+Int_DI],0 ;offset of zero?
        jnz     api33_4
        mov     bx,w[ebp+Int_SI]
        sys     RelSel          ;release the selector.
;
api33_4:        clc
;
api33_9:        cwAPI_C2C
        ret

; MED 11/18/96
api33_bad:
        stc
        jmp     api33_9

cwAPI_RelMemSO  endp

;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Allocate a block of memory without a selector.
;
;On Entry:
;
;CX:DX  - Size of block required in bytes.
;
;On Exit:
;
;Carry clear if OK &,
;
;SI:DI  - Linear address of block allocated.
;
cwAPI_GetMemLinear proc near
        mov     cx,[ebp+Int_CX]
        mov     dx,[ebp+Int_DX]
        shl     ecx,16
        mov     cx,dx
        call    mcbGetMemLinear32
        jc      api34_9
        mov     di,si
        shr     esi,16
        mov     [ebp+Int_SI],si
        mov     [ebp+Int_DI],di
        clc
api34_9:        cwAPI_C2C
        ret
cwAPI_GetMemLinear endp


;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Allocate a block of memory without a selector.
;
;On Entry:
;
;ECX    - Size of block required in bytes.
;
;On Exit:
;
;Carry clear if OK &,
;
;ESI    - Linear address of block allocated.
;
cwAPI_GetMemLinear32 proc near
        mov     ecx,[ebp+Int_ECX]
        call    mcbGetMemLinear32
        cwAPI_C2C
        jc      api35_9
        mov     [ebp+Int_ESI],esi
api35_9:        ret
cwAPI_GetMemLinear32 endp


;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Re-size a previously allocated block of memory without a selector.
;
;On Entry:
;
;SI:DI  - Linear address of block to re-size.
;CX:DX  - Size of block required in bytes.
;
;On Exit:
;
;Carry clear if OK &,
;
;SI:DI  - New linear address of block.
;
cwAPI_ResMemLinear proc near
        mov     si,[ebp+Int_SI]
        mov     di,[ebp+Int_DI]
        mov     cx,[ebp+Int_CX]
        mov     dx,[ebp+Int_DX]
        shl     ecx,16
        mov     cx,dx
        shl     esi,16
        mov     si,di
        call    mcbResMemLinear32
        jc      api36_9
        mov     di,si
        shr     esi,16
        mov     [ebp+Int_SI],si
        mov     [ebp+Int_DI],di
        clc
api36_9:        cwAPI_C2C
        ret
cwAPI_ResMemLinear endp


;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Re-size a previously allocated block of memory without a selector.
;
;On Entry:
;
;ESI    - Linear address of block to re-size.
;ECX    - Size of block required in bytes.
;
;On Exit:
;
;Carry clear if OK &,
;
;ESI    - New linear address of block.
;
cwAPI_ResMemLinear32 proc near
        mov     esi,[ebp+Int_ESI]
        mov     ecx,[ebp+Int_ECX]
        call    mcbResMemLinear32
        jc      api37_9
        mov     [ebp+Int_ESI],esi
api37_9:        cwAPI_C2C
        ret
cwAPI_ResMemLinear32 endp


;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Release previously allocated block of memory (linear address).
;
;On Entry:
;
;SI:DI  - Linear address of block to release.
;
;On Exit:
;
cwAPI_RelMemLinear proc near
        mov     si,[ebp+Int_SI]
        mov     di,[ebp+Int_DI]
        shl     esi,16
        mov     si,di
        call    mcbRelMemLinear32
        cwAPI_C2C
        ret
cwAPI_RelMemLinear endp


;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Release previously allocated block of memory (linear address).
;
;On Entry:
;
;ESI    - Linear address of block to release.
;
;On Exit:
;
cwAPI_RelMemLinear32 proc near
        mov     esi,[ebp+Int_ESI]
        call    mcbRelMemLinear32
        cwAPI_C2C
        ret
cwAPI_RelMemLinear32 endp


;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Allocate an application relative block of memory.
;
;On Entry:
;
;EBX    - Size of block required in bytes.
;
;On Exit:
;
;Carry clear if OK &,
;
;ESI    - Application relative linear address of block allocated.
;
cwAPI_GetMemNear proc near
        mov     ecx,[ebp+Int_EBX]
        call    mcbGetMemLinear32
        jc      api40_9
        assume ds:nothing
        mov     ds,cs:apiDSeg
        assume ds:_cwMain
        mov     ds,PSPSegment
        sub     esi,DWORD PTR ds:[EPSP_Struc.EPSP_NearBase]
        assume ds:_apiCode
        mov     [ebp+Int_ESI],esi
        clc
api40_9:        cwAPI_C2C
        ret
cwAPI_GetMemNear endp


;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Re-size a previously allocated application relative block of memory.
;
;On Entry:
;
;EBX    - Size of block required in bytes.
;ESI    - application relative linear address of block to re-size.
;
;On Exit:
;
;Carry clear if OK &,
;
;ESI    - New application relative linear address of block.
;
cwAPI_ResMemNear proc near
        mov     ecx,[ebp+Int_EBX]
        mov     esi,[ebp+Int_ESI]
        assume ds:nothing
        mov     ds,cs:apiDSeg
        assume ds:_cwMain
        mov     ds,PSPSegment
        add     esi,DWORD PTR ds:[EPSP_Struc.EPSP_NearBase]
        assume ds:_apiCode
        call    mcbResMemLinear32
        jc      api41_9
        assume ds:nothing
        mov     ds,cs:apiDSeg
        assume ds:_cwMain
        mov     ds,PSPSegment
        sub     esi,DWORD PTR ds:[EPSP_Struc.EPSP_NearBase]
        assume ds:_apiCode
        mov     [ebp+Int_ESI],esi
        clc
api41_9:        cwAPI_C2C
        ret
cwAPI_ResMemNear endp


;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Release previously allocated application relative block of memory.
;
;On Entry:
;
;ESI    - Application relative linear address of block to release.
;
cwAPI_RelMemNear proc near
        mov     esi,[ebp+Int_ESI]
        assume ds:nothing
        mov     ds,cs:apiDSeg
        assume ds:_cwMain
        mov     ds,PSPSegment
        add     esi,DWORD PTR ds:[EPSP_Struc.EPSP_NearBase]
        assume ds:_apiCode
        call    mcbRelMemLinear32
        cwAPI_C2C
        ret
cwAPI_RelMemNear endp


;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Convert linear address to application relative address.
;
;On Entry:
;
;ESI    - Linear address to convert.
;
;On Exit:
;
;ESI    - Application relative linear address.
;
cwAPI_Linear2Near proc near
        mov     esi,[ebp+Int_ESI]
        assume ds:nothing
        mov     ds,cs:apiDSeg
        assume ds:_cwMain
        mov     ds,PSPSegment
        sub     esi,DWORD PTR ds:[EPSP_Struc.EPSP_NearBase]
        assume ds:_apiCode
        mov     [ebp+Int_ESI],esi
        ret
cwAPI_Linear2Near endp


;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Convert application relative address to linear address.
;
;On Entry:
;
;ESI    - Application relative linear address.
;
;On Exit:
;
;ESI    - Linear address to convert.
;
cwAPI_Near2Linear proc near
        mov     esi,[ebp+Int_ESI]
        assume ds:nothing
        mov     ds,cs:apiDSeg
        assume ds:_cwMain
        mov     ds,PSPSegment
        add     esi,DWORD PTR ds:[EPSP_Struc.EPSP_NearBase]
        assume ds:_apiCode
        mov     [ebp+Int_ESI],esi
        ret
cwAPI_Near2Linear endp


;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Lock a region of memory.
;
;On Entry:
;
;BX:CX  - Starting linear address of memory to lock.
;SI:DI  - Size of region to lock in bytes.
;
;On Exit:
;
;Carry set on error, none of the memory locked, else memory is locked.
;
cwAPI_LockMem   proc    near
        mov     bx,[ebp+Int_BX]
        mov     cx,[ebp+Int_CX]
        mov     si,[ebp+Int_SI]
        mov     di,[ebp+Int_DI]
        mov     ax,0600h
        cwAPI_CallOld
        jc      api45_9
;
        mov     dx,bx
        shl     edx,16
        mov     dx,cx
        mov     cx,si
        shl     ecx,16
        mov     cx,di
        mov     ax,Res_LOCK
        call    RegisterResource
        clc
;
api45_9:        cwAPI_C2C
        ret
cwAPI_LockMem   endp


;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Lock a region of memory.
;
;On Entry:
;
;ESI    - Starting linear address of memory to lock.
;ECX    - Size of region to lock in bytes.
;
;On Exit:
;
;Carry set on error, none of the memory locked, else memory is locked.
;
cwAPI_LockMem32 proc near
        mov     esi,[ebp+Int_ESI]
        mov     ecx,[ebp+Int_ECX]
        xchg    esi,ecx
        mov     ebx,ecx
        shr     ebx,16
        mov     di,si
        shr     esi,16
        mov     ax,0600h
        cwAPI_CallOld
        jc      api46_9
        mov     dx,bx
        shl     edx,16
        mov     dx,cx
        mov     cx,si
        shl     ecx,16
        mov     cx,di
        mov     ax,Res_LOCK
        call    RegisterResource
        clc

⌨️ 快捷键说明

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