cw32.asm

来自「开放源码的编译器open watcom 1.6.0版的源代码」· 汇编 代码 · 共 2,222 行 · 第 1/5 页

ASM
2,222
字号
;
;CauseWay v2 main file.
;
;
;Things to note:
;
;The IDT has a page to itself even though it only needs 2k. For RAW/VCPI systems
;the top 2k could be used for something else.
;
;Things to do:
;
;Put in some sort of system stack overflow checking and terminate the program
;if it happens.
;
;       option oldstructs

;       include general.inc
        include strucs.inc
        include cw.inc
;       include cw-undoc.inc

; MED 02/03/2003, make sure some language is in there
        IFNDEF  ENGLISH
                IFNDEF  SPANISH
ENGLISH EQU     1
                ENDIF
        ENDIF

        ifndef ENGLISH
ENGLISH equ     0
        endif
        ifndef SPANISH
SPANISH equ     0
        endif

b       equ     byte ptr
w       equ     word ptr
d       equ     dword ptr
f       equ     fword ptr

;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Main code segment. This takes care of calling the right initialisation routines
;and generaly getting everything rolling.
;
_cwMain segment para public 'Main thread' use16
        assume cs:_cwMain, ds:_cwMain, ss:_cwStack
;
;Want a copyright message embedded first.
;
Copyright       label byte
        db 'CauseWay DOS Extender v'
VersionMajor    db '4.'
VersionMinor    db '02'
        db " No copyright. Public domain software.",13,10,"No rights retained. ",13,10,0

;-------------------------------------------------------------------------------
;
;Some global data.
;
RealPSPSegment  dw ?            ;Real mode PSP segment.
RealENVSegment  dw ?            ;Real mode environment segment.
ProtectedFlags  dw 0            ;Bit significant, 0-DPMI,1-VCPI,2-RAW.
ProtectedType   dw 0            ;0-RAW,1-VCPI,2-DPMI.
ProtectedForce  db 0
DOSVersion      dw 0
SystemFlags     dd 0
apiCodeSeg      dw 0
apiDataSeg      dw 0
;
CodeSegment     dw MainCS       ;Setup CS selector.
CodeSegmenti    dw InitCS
DataSegment     dw MainDS       ;Setup DS selector.
DataSegmenti    dw InitDS
StackSegment    dw MainSS
RealSegment     dw KernalZero
PSPSegment      dw MainPSP
ENVSegment      dw MainENV
BasePSP dw 0
BasePSPAddress  dd 0
;
TSRSize dw 0
;
ErrorNumber     dw 0
ErrorLevel      dw 0
ErrorList       dw ErrorM00,ErrorM01,ErrorM02,ErrorM03,ErrorM04,ErrorM05,ErrorM06,ErrorM07
        dw ErrorM08,ErrorM09,ErrorM10,ErrorM11,ErrorM12,ErrorM13,ErrorM14,ErrorM15
        dw ErrorM16
ErrorM00        db 'CauseWay error '
ErrorM00n       db '00 : $'
ErrorM01        label byte
        if ENGLISH
        db 'Unable to re-size program memory block.',13,10,'$'
        elseif SPANISH
        db "Incapaz de redimensionar el bloque de memoria del programa.",13,10,"$"
        endif
ErrorM02        db "$"
ErrorM03        db "$"
ErrorM04        db "$"
ErrorM05        label byte
        if ENGLISH
        db 'Not enough memory for CauseWay.',13,10,'$'
        elseif SPANISH
        db "Memoria insuficiente para CauseWay.",13,10,"$"
        endif
ErrorM06        db "$"
ErrorM07        db "$"
ErrorM08        db "$"
ErrorM09        label byte
        if ENGLISH
        db 'Unrecoverable exception. Program terminated.',13,10,'$'
        elseif SPANISH
        db "Excepcion irrecuperable. Programa terminado.",13,10,"$"
        endif
ErrorM10        label byte
        if ENGLISH
        db 'Unable to find '
ErrorM10_T      db 'application to load.',13,10,'$',32 dup (0)
        elseif SPANISH
        db "Incapaz de encontrar '
ErrorM10_T      db 'aplicacion a cargar.",13,10,"$",32 dup (0)
        endif
ErrorM11        label byte
        if ENGLISH
        db 'DOS reported an error or corrupt file found.'
        elseif SPANISH
        db "DOS informo de un error o de un fichero corrupto."
        endif
ErrorM11_0      db 13,10,'$'
        db "No:"
ErrorM11_1      db "00000000",13,10,"$"
ErrorM12        label byte
        if ENGLISH
        db 'Not enough memory to load application.',13,10,'$'
        elseif SPANISH
        db "Memoria insuficiente para cargar la aplicacion.",13,10,"$"
        endif
ErrorM13        db "$"
ErrorM14        label byte
        if ENGLISH
        db 'Memory structures destroyed. Program terminated.',13,10,'$'
        elseif SPANISH
        db "Estructuras de memoria destruidas. Programa terminado.",13,10,"$"
        endif
ErrorM15        label byte
        if ENGLISH
        db 'DOS reported an error while accessing swap file. Program terminated.',13,10,'$'
        elseif SPANISH
        db "DOS informa de un error mientras se accede al fichero de swap. Programa terminado.",13,10,"$"
        endif
ErrorM16        label byte
        if ENGLISH
        db "Unsupported DOS function call, program terminated.",13,10,"$"
        elseif SPANISH
        db "Llamada a funcion no soportada del DOS, programa terminado.",13,10,"$"
        endif
;
ALIGN 4
MainExec        db 128 dup (0)
;
DtaBuffer       db 128 dup (0)
;
TransferSize    dd 8192
TransferReal    dw ?
;
MouseETarget    dd 0,0
ResourceTracking dw 0
ForcedFind      dd 0,0
mcbAllocations  dw 0
LinearAddressCheck db 0
;
TerminationHandler dd offset InitError,InitCS
UserTermRoutine DF      0
UserTermDump    DF      0       ; dump location for register info
;
DPMIStateAddr   df 0
DPMIStateSize   dd 0
DPMIStackOff    dw ?
DPMIStackSeg    dw ?
;
DebugDump       db 0
EnableDebugDump DB      1
UserTermFlag    DB      0
Pad1Flag        DB      0

IFDEF PERMNOEX
NoEXECPatchFlag DB      1
ELSE
NoEXECPatchFlag DB      0
ENDIF

; MED, 11/11/99
; used to flag checking XMS total memory because EMM386 lies and acts as VCPI
;  host when NOVCPI set, but provides no memory
VCPIHasNoMem    DB      0

NewCWErrName    DB      81 DUP (0)
DOS4GFlag       db 0
;
Int21Buffer     db size RealRegsStruc dup (?)
Int10Buffer     db size RealRegsStruc dup (?)
Int33Buffer     db size RealRegsStruc dup (?)
;
apiExcepPatched db 0
;
ExtensionList   label word
        dw ExceptionExtension
        dw Int21hExtension,Int10hExtension,Int33hExtension
        dw -1
;
ExceptionExtension dw _Excep,0
        dd offset ExcepEnd-ExcepStart
        dd offset ExcepOpen,?
        dd offset ExcepClose,?
        dd 0
        dd 0
        dd 0
;
Int21hExtension dw _Int21h,1            ;segment start.
        dd offset Int21hEnd-Int21hStart ;segment length.
        dd offset Int21hOpen,?  ;init code.
        dd offset Int21hClose,? ;remove code.
        dd 0                    ;code selector.
        dd 0                    ;data selector.
        dd 0                    ;installed flag.
;
Int10hExtension dw _Int10h,1            ;segment start.
        dd offset Int10hEnd-Int10hStart ;segment length.
        dd offset Int10hOpen,?  ;init code.
        dd offset Int10hClose,? ;remove code.
        dd 0                    ;code selector.
        dd 0                    ;data selector.
        dd 0                    ;installed flag.
;
Int33hExtension dw _Int33h,1            ;segment start.
        dd offset Int33hEnd-Int33hStart ;segment length.
        dd offset Int33hOpen,?  ;init code.
        dd offset Int33hClose,? ;remove code.
        dd 0                    ;code selector.
        dd 0                    ;data selector.
        dd 0                    ;installed flag.
;
Temp0_  dd ?
Temp1_  dd ?
;
DebugUserOff    DD      ?
DebugUserSel    DW      ?
DebugUserCount  DW      0       ; must be initialized, nonzero value flags operation
DebugAsciiFlag  DB      ?

        .386
;-------------------------------------------------------------------------------
;
;Final init stuff.
;
cwOpen  proc    near
        assume ds:nothing               ;make our data addresable.
        mov     ds,cs:DataSegment
        assume ds:_cwMain
        ;
        mov     d[TerminationHandler],offset cwClose
        mov     w[TerminationHandler+4],cs
;
;Now we know the machines details, re-size the program
;block again to release as much memory as possible.
;
        mov     edi,offset Int21Buffer
        push    ds
        pop     es
        mov     ax,RealPSPSegment
        mov     es:RealRegsStruc.Real_ES[edi],ax
        mov     bx,_cwDPMIEMU
        cmp     ProtectedType,2
        jnz     cw1_KeepRaw
        mov     bx,_cwRaw
cw1_KeepRaw:    sub     bx,ax           ;Size program.
        inc     bx
        mov     TSRSize,bx
        mov     es:RealRegsStruc.Real_EBX[edi],ebx
        mov     es:RealRegsStruc.Real_EAX[edi],4a00h
        mov     bl,21h
        mov     ErrorNumber,1
        sys     IntXX
        test    WORD PTR es:[edi+RealRegsStruc.Real_Flags],1
        jnz     cw1_9
        mov     ErrorNumber,0   ;clear error number.
;
;Force accurate memory values.
;
        or      ecx,-1
        sys     GetMemLinear32
;
;Enable resource tracking and MCB allocations.
;
        or      ResourceTracking,-1     ;Enable resource tracking.
;
;Run the main program.
;
        mov     edx,offset MainExec     ;name to exec.
        mov     esi,80h
        mov     es,PSPSegment
        xor     cx,cx
        sys     cwExec          ;run the bugger.
        jnc     cw1_8
        add     ax,10-1         ;convert error number.
        mov     ErrorNumber,ax
        jmp     cw1_9
cw1_8:  cmp     DebugDump,0
        jnz     cw1_9
        mov     ErrorLevel,ax   ;store programs error level.
        mov     ErrorNumber,0   ;clear error number.
cw1_9:  jmp     cwClose
cwOpen  endp


;-------------------------------------------------------------------------------
;
;Shut everything down.
;
cwClose proc    near

IFDEF DEBUG4
        push    eax
        push    ebx
        push    ecx
        push    edx
        push    ds
        push    cs
        pop     ds
        mov     edx,OFFSET debugatext1
debugaloop2:
        cmp     BYTE PTR ds:[edx],0
        je      debugab
        mov     ecx,1
        mov     bx,1
        mov     ah,40h
        int     21h
        inc     edx
        jmp     debugaloop2
debugab:
        mov     edx,OFFSET debugatext2
        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     debugaout

debugatext1     DB      'Entering cwClose...',0
debugatext2     DB      13,10

debugaout:
        push    ecx
        mov     ecx,100000h
debugaloop:
;       dec     ecx
;       jne     debugaloop
        pop     ecx
ENDIF

        assume ds:nothing
        mov     ds,cs:DataSegment
        assume ds:_cwMain
        ;
        mov     ResourceTracking,0
        mov     mcbAllocations,0
        sti
        mov     w[TerminationHandler+4],0
        ;

IFDEF DEBUG4
        push    eax
        push    ebx
        push    ecx
        push    edx
        push    ds

        mov     dx,w[ExceptionExtension+12]
;       lar     ax,dx
        cmp     dx,127h
        jnz     debughout
;       and     ah,3
;       cmp     ah,3
;       jne     debughout

        push    cs
        pop     ds
        mov     edx,OFFSET debughtext1
debughloop2:
        cmp     BYTE PTR ds:[edx],0
        je      debughb
        mov     ecx,1
        mov     bx,1
        mov     ah,40h
        int     21h
        inc     edx
        jmp     debughloop2
debughb:
        mov     edx,OFFSET debughtext2
        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     debughout

debughtext1     DB      'Calling DebugDisplay...',0
debughtext2     DB      13,10

debughout:
        push    ecx
        mov     ecx,100000h
debughloop:
;       dec     ecx
;       jne     debughloop
        pop     ecx

ENDIF

        push    cs
        push    offset cw2_dd0
        push    w[ExceptionExtension+12]
        mov     eax,offset DebugDisplay
        push    ax
        retf
cw2_dd0:        ;

        cmp     ErrorNumber,0
        jz      cw2_NoError

        mov     ax,ErrorNumber  ;Get the error number.
        xor     dx,dx
        mov     cx,10

⌨️ 快捷键说明

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