     1                                  ;*********************************************************************
     2                                  ;*   MLSETUP.ASM                                                     *
     3                                  ;*                                                                   *
     4                                  ;*   By:            Michael Devore                                   *
     5                                  ;*   Date:          01/01/92                                         *
     6                                  ;*   Model:         Small                                            *
     7                                  ;*   Version:       2.5                                              *
     8                                  ;*   Assembler:     MASM 5.0                                         *
     9                                  ;*   Environment:   MS-DOS 2.x+                                      *
    10                                  ;*                                                                   *
    11                                  ;*   initial linker setup                                            *
    12                                  ;*                                                                   *
    13                                  ;*********************************************************************
    14                                  
    15                                  ;TITLE   WARPLINK mlsetup
    16                                  ;PAGE    50,80
    17                                  
    18                                  ;.MODEL  SMALL
    19                                  
    20                                  ;*****************************
    21                                  ;* Include files             *
    22                                  ;*****************************
    23                                  
    24                                  [list -]
    28                                  
    29                                  ;*****************************
    30                                  ;* Public declarations       *
    31                                  ;*****************************
    32                                  
    33                                  PUBLIC  setup,check_ems,check_xms
    34                                  
    35                                  ;*****************************
    36                                  ;* Data begins               *
    37                                  ;*****************************
    38                                  
    39                                  .DATA?
    40                                  
    41                                  ; uninitialized local variables
    42                                  
    43                                  ; doubleword values
    44 00000000 ????????                old_ctrlc   DD  ?
    45                                  
    46                                  ;*****************************
    47                                  ;* Constant data             *
    48                                  ;*****************************
    49                                  
    50                                  .CONST
    51                                  
    52 00000000 454D4D585858583000      emmname     DB  'EMMXXXX0',0
    53                                  
    54 00000009 1A                      termtext_len    DB  termtext_stop-term_text
    55 0000000A 0D0A4C696E6B207465-     term_text       DB  CR,LF,'Link terminated by user.'
    55 00000013 726D696E6174656420-
    55 0000001C 627920757365722E   
    56                                  termtext_stop   equ   $
    57                                  
    58                                  ;*****************************
    59                                  ;* Code begins               *
    60                                  ;*****************************
    61                                  
    62                                  .CODE
    63                                  
    64                                  ;*****************************
    65                                  ;* External declarations     *
    66                                  ;*****************************
    67                                  
    68                                  EXTRN   free_ems:NEAR,delete_ilf_file:NEAR
    69                                  EXTRN	delete_temp_file:NEAR,delete_qlk_file:NEAR
    70                                  
    71                                  ;*****************************
    72                                  ;* SETUP                     *
    73                                  ;*****************************
    74                                  
    75                                  ; initial linker setup
    76                                  
    77                                  setup       PROC
    78 00000000 06                          push    es              ; save es -> PSP
    79 00000001 8CD9                        mov cx,ds               ; get PSP value from initial DS value
    80 00000003 B8[ssss]                    mov ax,DGROUP           ; point data segment at DGROUP
    81 00000006 8ED8                        mov ds,ax
    82 00000008 890E[0000]                  mov [psp],cx              ; save PSP value to memory variable
    83 0000000C 8EC0                    	mov es, ax
    84                                   extern to_zero_initialise, to_zero_initialise_length_words
    85 0000000E BF[0000]                	mov di, to_zero_initialise
    86 00000011 B9[0000]                	mov cx, to_zero_initialise_length_words
    87 00000014 31C0                    	xor ax, ax
    88 00000016 F3AB                    	rep stosw
    89                                   extern to_zero_initialise_2, to_zero_initialise_2_length_words
    90 00000018 BF[0000]                	mov di, to_zero_initialise_2
    91 0000001B B9[0000]                	mov cx, to_zero_initialise_2_length_words
    92 0000001E F3AB                    	rep stosw
    93                                  
    94 00000020 FC                          cld                     ; make all string operations increment
    95                                  
    96 00000021 B433                        mov ah,33h              ; get or set Ctrl-Break flag
    97 00000023 30C0                        xor al,al               ; get flag
    98 00000025 CD21                        int 21h                 ; status returned in dl register
    99 00000027 8816[0000]                  mov [ctrlbreak],dl        ; save status
   100                                  
   101 0000002B B430                        mov ah,30h              ; get MS-DOS version number
   102 0000002D CD21                        int 21h
   103 0000002F 3C02                        cmp al,2                ; make sure at least 2.x
   104 00000031 7302                        jae s2                  ; yes
   105 00000033 CD20                        int 20h                 ; force immediate 1.x compatible termination
   106                                  
   107                                  s2:
   108 00000035 A2[0000]                    mov [dos_version],al      ; save major dos version
   109                                  
   110 00000038 B82335                      mov ax,3523h            ; get old ctrl-c handler address
   111 0000003B CD21                        int 21h
   112 0000003D 891E[0000]                  mov WORD PTR [old_ctrlc],bx   ; save offset
   113 00000041 8C06[0200]                  mov WORD PTR [old_ctrlc+2],es ; save segment
   114                                  
   115 00000045 8CC8                        mov ax,cs
   116 00000047 8ED8                        mov ds,ax
   117 00000049 BA[5800]                    mov dx,OFFSET control_break ; ds:dx -> control-c handler
   118 0000004C B82325                      mov ax,2523h            ; set ctrl-c handler
   119 0000004F CD21                        int 21h
   120 00000051 B8[ssss]                    mov ax,DGROUP
   121 00000054 8ED8                        mov ds,ax               ; restore ds -> warplink data
   122                                  
   123 00000056 07                          pop es                  ; restore es -> PSP
   124 00000057 C3                          ret
   125                                  setup       ENDP
   126                                  
   127                                  ;*****************************
   128                                  ;* CONTROL_BREAK             *
   129                                  ;*****************************
   130                                  
   131                                  ; control break handler
   132                                  
   133                                  control_break   PROC
   134 00000058 B8[ssss]                    mov ax,DGROUP
   135 0000005B 8ED8                        mov ds,ax               ; make sure ds -> warplink data
   136                                  
   137 0000005D C516[0000]                  lds dx,[old_ctrlc]        ; ds:dx -> old cntrl-cl handler
   138 00000061 B82325                      mov ax,2523h            ; set ctrl-c handler
   139 00000064 CD21                        int 21h
   140                                  
   141 00000066 B8[ssss]                    mov ax,DGROUP
   142 00000069 8ED8                        mov ds,ax               ; make sure ds -> warplink data
   143                                  
   144 0000006B E8(0000)                    call    delete_ilf_file ; delete ilf file if it exists
   145 0000006E E8(0000)                	call	delete_temp_file	; delete temp file if it exists
   146                                   extern delete_wllist_temps
   147 00000071 31C0                    	xor ax, ax
   148 00000073 E8(0000)                	call delete_wllist_temps
   149 00000076 E8(0000)                	call	delete_qlk_file	; kill qlk file too, if exists and writing to it
   150 00000079 E8(0000)                    call    free_ems
   151                                  
   152                                  ; write terminated feedback
   153                                  cb_feed:
   154 0000007C BB[0A00]                    mov bx,OFFSET term_text wrt DGROUP
   155 0000007F 8A4FFF                      mov cl,[bx-1]           ; get length of string to print
   156 00000082 89DA                        mov dx,bx               ; ds:dx -> string
   157 00000084 30ED                        xor ch,ch               ; zap high byte of cx
   158 00000086 BB0100                      mov bx,STDOUT           ; write to standard output device
   159 00000089 B440                        mov ah,40h              ; write to device
   160 0000008B CD21                        int 21h
   161 0000008D FF2E[0000]                  jmp far [old_ctrlc]
   162                                  control_break   ENDP
   163                                  
   164                                  ;*****************************
   165                                  ;* CHECK_EMS                 *
   166                                  ;*****************************
   167                                  
   168                                  ; check if EMS and can be used
   169                                  
   170                                  check_ems   PROC
   171                                  
   172                                  ;*** COMMENT # temporary for 1.60f
   173 00000091 803E[0000]00                cmp byte [is_no_ems],0         ; see if no EMS flag set
   174 00000096 754B                        jne ce_ret              ; yes
   175                                  
   176 00000098 BA[0000]                    mov dx,OFFSET emmname wrt DGROUP    ; ds:dx -> device name
   177 0000009B B8003D                      mov ax,3d00h            ; open for reading
   178 0000009E CD21                        int 21h
   179 000000A0 723C                        jc  ce_noems            ; open failed
   180                                  
   181 000000A2 89C3                        mov bx,ax               ; bx holds handle
   182 000000A4 B80044                      mov ax,4400h            ; IOCTL get device info
   183 000000A7 CD21                        int 21h
   184 000000A9 7233                        jc  ce_noems            ; IOCTL call failed
   185                                  
   186 000000AB 80E280                      and dl,80h              ; get high bit, set if char device
   187 000000AE 742E                        je  ce_noems            ; file device
   188                                  
   189 000000B0 B80744                      mov ax,4407h            ; IOCTL get output status
   190 000000B3 CD21                        int 21h
   191 000000B5 7227                        jc  ce_noems            ; IOCTL call failed
   192                                  
   193 000000B7 B43E                        mov ah,3eh              ; close file
   194 000000B9 CD21                        int 21h
   195 000000BB 7221                        jc  ce_noems            ; close failed
   196                                  
   197 000000BD B440                        mov ah,40h              ; get EMS system status
   198 000000BF CD67                        int 67h                 ; call EMM
   199 000000C1 08E4                        or  ah,ah               ; check for EMM error
   200 000000C3 7519                        jne ce_noems            ; EMM error occurred
   201                                  
   202 000000C5 B446                        mov ah,46h              ; get EMM version
   203 000000C7 CD67                        int 67h
   204 000000C9 08E4                        or  ah,ah               ; check for error
   205 000000CB 7511                        jne ce_noems            ; error occurred
   206 000000CD 3C32                        cmp al,32h              ; must be EMS version 3.2 or greater
   207 000000CF 720D                        jb  ce_noems            ; no
   208                                  
   209 000000D1 B441                        mov ah,41h              ;  get page frame address
   210 000000D3 CD67                        int 67h
   211 000000D5 08E4                        or  ah,ah
   212 000000D7 7505                        jne ce_noems            ; error occurred
   213                                  
   214 000000D9 891E[0000]                  mov [ems_base],bx         ; save EMS base (page frame)
   215 000000DD C3                          ret
   216                                  
   217                                  ;*** END COMMENT #
   218                                  
   219                                  ; no, or can't use, EMS
   220                                  ce_noems:
   221 000000DE C606[0000]01                mov byte [is_no_ems],1         ; set no EMS flag
   222                                  
   223                                  ce_ret:
   224 000000E3 C3                          ret
   225                                  check_ems   ENDP
   226                                  
   227                                  ;*****************************
   228                                  ;* CHECK_XMS                 *
   229                                  ;*****************************
   230                                  
   231                                  ; check if XMS and can be used, get XMM entry point
   232                                  
   233                                  check_xms   PROC
   234 000000E4 803E[0000]00                cmp byte [is_xms],0            ; see if XMS flag set
   235 000000E9 740E                        je  cx_ret              ; no
   236                                  
   237 000000EB B80043                      mov ax,4300h            ; check if XMM is present
   238 000000EE CD2F                        int 2fh                 ; multiplex interrupt
   239 000000F0 3C80                        cmp al,80h              ; check if driver present
   240 000000F2 7406                        je  cx_getaddr          ; yes, get entry point address
   241                                  
   242                                  ; no, or can't use, XMS
   243                                  cx_noxms:
   244 000000F4 C606[0000]00                mov byte [is_xms],0            ; reset XMS flag
   245                                  
   246                                  cx_ret:
   247 000000F9 C3                          ret
   248                                  
   249                                  cx_getaddr:
   250 000000FA B81043                      mov ax,4310h            ; get XMS driver entry point
   251 000000FD CD2F                        int 2fh
   252 000000FF 891E[0000]                  mov WORD PTR [xms_addr],bx    ; save it
   253 00000103 8C06[0200]                  mov WORD PTR [xms_addr+2],es
   254 00000107 C3                          ret
   255                                  check_xms   ENDP
   256                                  
   257                                  END
