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

📄 api.asm

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 ASM
📖 第 1 页 / 共 5 页
字号:
        ret
cwAPI_LockMemNear endp


;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Un-lock a region of memory using application relative address.
;
;On Entry:
;
;ESI    - Starting linear address of memory to unlock
;EBX    - Size of region to unlock in bytes
;
cwAPI_UnLockMemNear proc near
        mov     esi,[ebp+Int_ESI]
        mov     ecx,[ebp+Int_ECX]
        assume ds:nothing
        mov     ds,cs:apiDSeg
        assume ds:_cwMain
        mov     ds,PSPSegment
        add     esi,ds:d[EPSP_NearBase]
        assume ds:_apiCode
        xchg    esi,ebx
        mov     di,si
        shr     esi,16
        mov     cx,bx
        shr     ebx,16
        mov     ax,0601h
        cwAPI_CallOld
        jc      @@9
        mov     dx,bx
        shl     edx,16
        mov     dx,cx
        mov     cx,si
        shl     ecx,16
        mov     cx,di
        mov     ax,Res_LOCK
        call    ReleaseResource
        clc
@@9:    cwAPI_C2C
        ret
cwAPI_UnLockMemNear endp


;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Allocate a region of DOS (conventional) memory.
;
;On Entry:
;
;BX     - Number of paragraphs (16 byte blocks) required.
;
;On Exit:
;
;If function was successful:
;Carry flag is clear.
;
;AX     - Initial real mode segment of allocated block
;DX     - Initial selector for allocated block
;
;If function was not successful:
;Carry flag is set.
;
;AX     - DOS error code.
;BX     - Size of largest available block in paragraphs.
;
cwAPI_GetMemDOS proc near
        mov     bx,[ebp+Int_BX]
        mov     ax,0100h
        cwAPI_CallOld
        mov     [ebp+Int_AX],ax
        cwAPI_C2C
        jnc     @@0
        mov     [ebp+Int_BX],bx
        jmp     @@9
;
@@0:    mov     [ebp+Int_DX],dx
        movzx   edx,dx
        movzx   ecx,bx
        shl     ecx,4
        mov     ax,Res_DOSMEM
        call    RegisterResource
;
@@9:    ret
cwAPI_GetMemDOS endp


;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Re-size a block of DOS (conventional) memory previously allocated with
;GetMemDOS.
;
;On Entry:
;
;BX     - New block size in paragraphs
;DX     - Selector of block to modify
;
;On Exit:
;
;If function was successful:
;Carry flag is clear.
;
;If function was not successful:
;Carry flag is set.
;
;AX     - DOS error code:
;BX     - Maximum block size possible in paragraphs
;
cwAPI_ResMemDOS proc near
        mov     bx,[ebp+Int_BX]
        mov     dx,[ebp+Int_DX]
        mov     ax,0102h
        cwAPI_CallOld
        jnc     @@0
        mov     [ebp+Int_AX],ax
        mov     [ebp+Int_BX],bx
        jmp     @@9
;
@@0:    mov     ax,Res_DOSMEM
        movzx   edx,dx
        call    ReleaseResource
        movzx   ecx,bx
        shl     ecx,4
        call    RegisterResource
        clc
;
@@9:    cwAPI_C2C
        ret
cwAPI_ResMemDOS endp


;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Release a block of DOS (conventional) memory previously allocated with
;GetMemDOS.
;
;On Entry:
;
;DX     - Selector of block to free.
;
;On Exit:
;
;If function was successful:
;Carry flag is clear.
;
;If function was not successful:
;Carry flag is set.
;
;AX     - DOS error code.
;
cwAPI_RelMemDOS proc near

        mov     ds,w[ebp+INT_DS]
        mov     es,w[ebp+INT_ES]
        mov     fs,w[ebp+INT_FS]
        mov     gs,w[ebp+INT_GS]

        mov     dx,[ebp+Int_DX]
        mov     ax,0101h
        cwAPI_CallOld
        jnc     @@0
        mov     [ebp+Int_AX],ax
        jmp     @@9
;
@@0:    mov     ax,Res_DOSMEM
        movzx   edx,dx
        call    ReleaseResource
        clc
;
@@9:    cwAPI_C2C

        mov     w[ebp+INT_DS],ds
        mov     w[ebp+INT_ES],es
        mov     w[ebp+INT_FS],fs
        mov     w[ebp+INT_GS],gs

        ret
cwAPI_RelMemDOS endp


;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Run another CauseWay program directly.
;
;On Entry:
;
;DS:EDX - File name.
;ES:ESI - Command line. First byte is length, then real data.
;CX     - Environment selector, 0 to use existing copy.
;
;On Exit:
;
;Carry set on error and AX = error code else AL=ErrorLevel
;
cwAPI_Exec      proc    near
        mov     ds,[ebp+Int_DS]
        mov     edx,[ebp+Int_EDX]
        mov     es,[ebp+Int_ES]
        mov     esi,[ebp+Int_ESI]
        mov     cx,[ebp+Int_CX]
        mov     ebx,0
        push    ebp
        call    _Exec
        pop     ebp
        jnc     @@0
        mov     [ebp+Int_AX],ax
        jmp     @@9
;
@@0:    mov     [ebp+Int_AL],al
;
@@9:    cwAPI_C2C
IFDEF DEBUG2
        push    eax
        push    ebx
        push    ecx
        push    edx
        push    ds
        push    cs
        pop     ds
        mov     edx,OFFSET debugagtext1
debugagloop2:
        cmp     BYTE PTR ds:[edx],0
        je      debugagb
        mov     ecx,1
        mov     bx,1
        mov     ah,40h
        int     21h
        inc     edx
        jmp     debugagloop2
debugagb:
        mov     edx,OFFSET debugagtext2
        push    cs
        pop     ds
        mov     ecx,2
        mov     bx,1
        mov     ah,40h
        int     21h
        pop     ds
        pop     edx
        pop     ecx
        pop     ebx
        pop     eax
        jmp     debugagout

debugagtext1    DB      'Done with cwAPI_Exec...',0
debugagtext2    DB      13,10

debugagout:
ENDIF

        ret
cwAPI_Exec      endp


;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Validate and get expanded length of a CWC'd file.
;
;On Entry:
;
;BX     - File handle.
;
;On Exit:
;
;Carry set if not a CWC'd file else,
;
;ECX    - Expanded data size.
;
cwAPI_cwcInfo   proc    near
        mov     bx,[ebp+Int_BX]
        call    GetCWCInfo
        cwAPI_C2C
        mov     [ebp+Int_ECX],ecx
        mov     [ebp+Int_EAX],eax
        ret
cwAPI_cwcInfo   endp


;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Load/Expand a CWC'd data file into memory.
;
;On Entry:
;
;BX     - Source file handle.
;ES:EDI - Destination memory.
;
;On Exit:
;
;Carry set on error and EAX is error code else,
;
;ECX    - Expanded data length.
;
cwAPI_cwcLoad proc near
        mov     bx,[ebp+Int_BX]
        mov     es,[ebp+Int_ES]
        mov     edi,[ebp+Int_EDI]
        call    DecodeCWC
        mov     [ebp+Int_EAX],eax
        jc      @@9
        mov     [ebp+Int_ECX],ecx
@@9:    cwAPI_C2C
        ret
cwAPI_cwcLoad endp


;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
cwAPI_LinearCheck proc near
        mov     esi,[ebp+Int_ESI]
        assume ds:nothing
        mov     ds,cs:apiDSeg
        assume ds:_cwMain
        ;
        mov     es,RealSegment
        xor     eax,eax
        mov     ax,es
        lsl     eax,eax
        cmp     eax,esi
        jc      @@3
        mov     LinearAddressCheck,1
        mov     al,es:[esi]
        cmp     LinearAddressCheck,0
        mov     LinearAddressCheck,0
        jnz     @@2
@@3:    stc
        jmp     @@1
@@2:    clc
@@1:    assume ds:_apiCode
        ;
        cwAPI_C2C
        ret
cwAPI_LinearCheck endp


;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
cwAPI_ExecDebug proc near
        mov     ds,[ebp+Int_DS]
        mov     edx,[ebp+Int_EDX]
        mov     es,[ebp+Int_ES]
        mov     esi,[ebp+Int_ESI]
        mov     cx,[ebp+Int_CX]
        mov     ebx,1
        push    ebp
        call    _Exec
        jnc     @@0
        pop     ebp
        mov     [ebp+Int_AX],ax
        jmp     @@9
;
@@0:    shl     esi,16
        mov     si,di
        mov     edi,ebp
        pop     ebp
        mov     [ebp+Int_EAX],eax
        mov     [ebp+Int_BX],bx
        mov     [ebp+Int_CX],cx
        mov     [ebp+Int_EDX],edx
        mov     [ebp+Int_DI],si
        shr     esi,16
        mov     [ebp+Int_SI],si
        mov     [ebp+Int_EBP],edi
        clc
;
@@9:    cwAPI_C2C
IFDEF DEBUG2
        push    eax
        push    ebx
        push    ecx
        push    edx
        push    ds
        push    cs
        pop     ds
        mov     edx,OFFSET debugaitext1
debugailoop2:
        cmp     BYTE PTR ds:[edx],0
        je      debugaib
        mov     ecx,1
        mov     bx,1
        mov     ah,40h
        int     21h
        inc     edx
        jmp     debugailoop2
debugaib:
        mov     edx,OFFSET debugaitext2
        push    cs
        pop     ds
        mov     ecx,2
        mov     bx,1
        mov     ah,40h
        int     21h
        pop     ds
        pop     edx
        pop     ecx
        pop     ebx
        pop     eax
        jmp     debugaiout

debugaitext1    DB      'Done with cwAPI_ExecDebug...',0
debugaitext2    DB      13,10

debugaiout:
ENDIF

        ret
cwAPI_ExecDebug endp


;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Load another CauseWay program as an overlay, ie, do relocations etc but don't
;actually execute it.
;
;On Entry:
;
;DS:EDX - File name.
;
;On Exit:
;
;Carry set on error and AX = error code else,
;
;CX:EDX - Entry CS:EIP
;BX:EAX - Entry SS:ESP
;SI     - PSP.
;
cwAPI_cwLoad    proc near
        mov     ds,[ebp+Int_DS]
        mov     edx,[ebp+Int_EDX]
        mov     ebx,2
        xor     ax,ax
        mov     es,ax
        mov     fs,ax
        push    ebp
        call    _Exec
        pop     ebp
        jnc     @@0
        mov     [ebp+Int_AX],ax
        jmp     @@9
;
@@0:    mov     [ebp+Int_CX],cx
        mov     [ebp+Int_EDX],edx
        mov     [ebp+Int_BX],bx
        mov     [ebp+Int_EAX],eax
        mov     [ebp+Int_SI],si
;
@@9:    cwAPI_C2C
IFDEF DEBUG2
        push    eax
        push    ebx
        push    ecx
        push    edx
        push    ds
        push    cs
        pop     ds
        mov     edx,OFFSET debugahtext1
debugahloop2:
        cmp     BYTE PTR ds:[edx],0
        je      debugahb
        mov     ecx,1
        mov     bx,1
        mov     ah,40h
        int     21h
        inc     edx
        jmp     debugahloop2
debugahb:
        mov     edx,OFFSET debugahtext2
        push    cs
        pop     ds
        mov     ecx,2
        mov     bx,1
        mov     ah,40h
        int     21h
        pop     ds
        pop     edx
        pop     ecx
        pop     ebx
        pop     eax
        jmp     debugahout

debugahtext1    DB      'Done with cwAPI_cwLoad...',0
debugahtext2    DB      13,10

debugahout:
ENDIF

        ret
cwAPI_cwLoad    endp


;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
cwAPI_Cleanup   proc    near
        assume ds:nothing
        mov     ds,cs:apiDSeg
        assume ds:_cwMain
        call    LoseFileHandles
        clc
        assume ds:_apiCode
        cwAPI_C2C
        ret
cwAPI_Cleanup   endp


;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Use DPMI services to allocate a single selector and initialise base & limit
;as specified with type=data/read/write.
;
;On Entry:-
;
;EAX    - Linear base.
;EBX    - li

⌨️ 快捷键说明

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