home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 June / SIMTEL_0692.cdr / msdos / desqview / xdvee11.arc / XDVEE.ASM < prev    next >
Encoding:
Assembly Source File  |  1989-06-06  |  8.0 KB  |  342 lines

  1.     PAGE    60,132
  2.     TITLE    XDVEE: RUN DESQVIEW WITH REMM.SYS 4.2 LIMITED TO EEMS
  3.     SUBTTL    Copyright 1989 John Navas II, All Rights Reserved
  4.  
  5.     COMMENT    \
  6. This program limits DV.EXE to EEMS functions, making high-performance
  7. communications multitasking possible even with REMM.SYS 4.2.  It
  8. works by installing itself as a filter for INT 67h, pretending to be
  9. an EMS driver, and spawning XDV.COM (passing all command-line
  10. arguments).
  11.     If ALLOW1 is not defined, it converts any Get EMS Version
  12. (Function 46h) response > 3.9 to 3.9 (the version returned by AST
  13. REMM.SYS 3.5); XDV.COM and DV.EXE are thereby fooled into using EEMS
  14. (instead of EMS 4.0) functions.
  15.     If ALLOW1 is defined, it does not interfere with the first (and
  16. only the first) Get EMS Version (Function 46h) response; this lets
  17. XDV.COM allocate memory using EMS 4.0 functions, which permits larger
  18. windows in certain configurations, while still fooling DV.EXE into
  19. using EEMS functions.
  20.     Written in Microsoft MASM 5.1. \
  21.  
  22. EEMS    EQU    39h        ; Version for REMM.SYS 3.5
  23.  
  24. SSIZE    EQU    400        ; stack size during spawn
  25.  
  26. BELL    EQU    07h        ; audible bell
  27. LF    EQU    0Ah        ; line feed
  28. CR    EQU    0Dh        ; carriage return
  29.  
  30. DOSTERM    EQU    20H        ; old style DOS terminate
  31.  
  32. DOSINT    EQU    21h        ; DOS call interrupt
  33. DSPSTR    EQU    09h        ; display string function
  34. S_INT    EQU    25h        ; set interrupt vector function
  35. VERSION    EQU    30h        ; get DOS version number
  36. G_INT    EQU    35h        ; get interrupt vector function
  37. CHMOD    EQU    43h        ; get/set file attributes
  38. SETBLK    EQU    4Ah        ; modify allocated memory
  39. EXEC    EQU    4Bh        ; load and execute
  40. TERM    EQU    4Ch        ; terminate a process function
  41.  
  42. EMMINT    EQU    67h        ; EMM driver interrupt
  43. EMMVER    EQU    46h        ; get EMM spec version
  44.  
  45. PROG    GROUP    prog1,prog2,prog3
  46.  
  47. prog1    SEGMENT    PARA
  48.  
  49. ;PROGRAM HEADER
  50.     DB    44 DUP(?)
  51. env_str    DW    ?        ; environment string pointer
  52.     DB    46 DUP(?)
  53. fcb1    DB    16 DUP(?)    ; dos fcb's
  54. fcb2    DB    16 DUP(?)
  55.     DB    4 DUP(?)
  56. arg_len    DB    ?        ; length of commard line args
  57. arg_val    DB    7Fh DUP(?)    ; command line string
  58.  
  59.     ASSUME    cs:PROG
  60. begin:    jmp    init_code
  61.     ASSUME    cs:NOTHING
  62.  
  63.     EVEN
  64. parmblk    LABEL    WORD        ; parameter block for spawn
  65. env_vec    DW    ?        ; segment addr of environment string
  66. cmd_lin    DW    arg_len        ; pointer to command line
  67.     DW    ?        ; (segment)
  68. fcb1v    DW    fcb1        ; pointer to 1st fcb
  69.     DW    ?        ; (segment)
  70. fcb2v    DW    fcb2        ; pointer to 2nd fcb
  71.     DW    ?        ; (segment)
  72.  
  73. spsave    DW    ?        ; save stack pointer
  74.  
  75. pathstr    DB    'XDV.COM',0    ; build path name
  76.     ORG    pathstr+65
  77.  
  78. prog1    ENDS
  79.  
  80.     PAGE
  81.  
  82. prog2    SEGMENT    PARA
  83.  
  84. header    DD    ?        ; FAKE EMM HEADER
  85.     DW    3 DUP(?)
  86. emmnam    DB    'EMMXXXX0'    ; driver name
  87.     IFDEF    ALLOW1
  88. once    DB    0        ; switch for XDV/DV
  89.     ENDIF
  90.  
  91. prog0    SEGMENT    AT 0
  92. dummy    LABEL    FAR        ; use for FAR JMP prototype
  93. prog0    ENDS
  94.  
  95.     ASSUME    cs:prog2
  96.  
  97. emment:                ; FILTER entry
  98.     cmp    ah,EMMVER        ; get version function?
  99.     je    emmchg            ; yes
  100.     jmp    dummy            ; no, go to original driver
  101. emm_v    EQU    DWORD PTR $-4        ; (original driver vector)
  102.  
  103. emmchg:    sti                ; allow interrupts
  104.     pushf                ; simulate interrupt to orig driver
  105.     call    [emm_v]
  106.     IFDEF    ALLOW1
  107.     cmp    [once],0        ; XDV or DV?
  108.     mov    [once],0FFh        ; (flip switch from XDV to DV)
  109.     jz    emmxit            ; XDV (use EMS 4.0)
  110.     ENDIF
  111.     test    ah,ah            ; error?
  112.     jnz    emmxit            ; yes
  113.     cmp    al,EEMS            ; EEMS?
  114.     jna    emmxit            ; yes
  115.     mov    al,EEMS            ; change to REMM.SYS 3.5 EEMS
  116. emmxit:    iret                ; return to caller
  117.  
  118.     ASSUME    cs:NOTHING
  119.  
  120. prog2    ENDS
  121.  
  122.     PAGE
  123.  
  124. prog3    SEGMENT    WORD
  125.  
  126. ;TERMINATION
  127.  
  128. zerror    DB    'ERROR: EXEC FAILURE!',BELL,CR,LF
  129.     DB    '$'
  130.  
  131.     ASSUME    cs:PROG,ds:PROG        ; ds valid only before spawn
  132.  
  133. termsec:
  134.     mov    sp,OFFSET PROG:memend    ; shrink stack
  135.  
  136.     mov    ah,SETBLK        ; release excess memory in es:bx
  137.     int    DOSINT
  138.     jnc    mmok            ; success
  139.  
  140.     lea    dx,[merror]
  141.     mov    ah,DSPSTR        ; display error
  142.     int    DOSINT
  143.     mov    ax,TERM SHL 8 + 1    ; and bail
  144.     int    DOSINT
  145.  
  146. mmok:
  147.     mov    ds,di            ; vector from di:dx
  148.     ASSUME    ds:NOTHING
  149.     mov    ax,S_INT SHL 8 + EMMINT    ; set my EMM vector
  150.     int    DOSINT
  151.  
  152.     push    cs            ; setup ds & es
  153.     pop    ds
  154.     ASSUME    ds:PROG
  155.     push    cs
  156.     pop    es
  157.     lea    bx,[parmblk]        ; parameter block
  158.     lea    dx,[pathstr]        ; program path name
  159.     mov    [spsave],sp        ; save stack pointer
  160.     mov    ax,EXEC SHL 8        ; load and execute
  161.     int    DOSINT
  162.     ASSUME    ds:NOTHING
  163.     cli                ; suppress interrupts
  164.     mov    bx,cs            ; restore .com stack segment
  165.     mov    ss,bx
  166.     mov    sp,[spsave]        ; restore stack pointer
  167.     sti                ; restore interrupts
  168.     jnc    puzl            ; DOS error reported
  169.  
  170.     push    cs            ; (ensure ds set up)
  171.     pop    ds
  172.     lea    dx,[zerror]
  173.     mov    ah,DSPSTR        ; display error message
  174.     int    DOSINT
  175.  
  176. puzl:
  177.     lds    dx,[emm_v]
  178.     mov    ax,S_INT SHL 8 + EMMINT    ; restore EMM vector
  179.     int    DOSINT
  180.  
  181.     mov    ax,TERM    SHL 8        ; done at last
  182.     int    DOSINT            ; call DOS
  183.  
  184.     EVEN                ; stack area
  185. memend    EQU    $ + SSIZE        ; END OF PROTECTED PROGRAM AREA
  186.  
  187.     PAGE
  188.  
  189. ;INITIALIZATION
  190.  
  191. xdvnam    DB    'XDV.COM',0    ; DESQview loader
  192. pathnam    DB    'PATH='        ; environment path string
  193.  
  194. banner    DB    'XDVEE'
  195.     IFDEF    ALLOW1
  196.     DB    '1'
  197.     ENDIF
  198.     DB    ': DESQview(tm) loader for REMM.SYS 4.2',CR,LF
  199.     DB    '$'
  200.     
  201. verror    DB    'ERROR: MUST BE DOS VERSION 2 OR GREATER!',BELL,CR,LF
  202.     DB    '$'
  203.  
  204. perror    DB    'ERROR: CANNOT FIND XDV.COM!',BELL,CR,LF
  205.     DB    '$'
  206.  
  207. nerror    DB    'ERROR: REMM.SYS NOT INSTALLED!',BELL,CR,LF
  208.     DB    '$'
  209.  
  210. copyr    DB    'Copyright 1989 John Navas II, All Rights Reserved',CR,LF
  211.     DB    '$'
  212.  
  213.     ASSUME    ds:PROG            ; only before spawn
  214.  
  215. init_code:
  216.     lea    dx,[banner]
  217.     mov    ah,DSPSTR        ; display banner message
  218.     int    DOSINT
  219.  
  220.     mov    ax,VERSION SHL 8    ; get DOS version number
  221.     int    DOSINT
  222.     cmp    al,2            ; must be version 2+
  223.     jnb    whew            ; ok, continue
  224.  
  225.     lea    dx,[verror]
  226.     mov    ah,DSPSTR        ; display error
  227.     int    DOSINT
  228.     int    DOSTERM            ;  and bail
  229.  
  230. whew:
  231.     lea    dx,[copyr]
  232.     mov    ah,DSPSTR        ; display copyright
  233.     int    DOSINT
  234.  
  235.     mov    [cmd_lin+2],cs        ; setup parameter block
  236.     mov    [fcb1v+2],cs
  237.     mov    [fcb2v+2],cs
  238.  
  239.     mov    es,[env_str]        ; get env string segment pointer
  240.     mov    [env_vec],es        ; and put in parameter block
  241.     xor    di,di
  242.     cld                ; setup for string ops
  243.  
  244. snxt:    cmp    BYTE PTR es:[di],0    ; no more strings?
  245.     je    sgot            ; none
  246.     lea    si,[pathnam]        ; keyword
  247.     mov    cx,5            ; length of keyword
  248.     repe    cmpsb            ; test for keyword
  249.     je    sgot            ; found it!
  250.     xor    al,al
  251.     mov    cx,-1
  252.     repne    scasb            ; scan for string terminator
  253.     jmp    snxt            ; check next string
  254.  
  255. sgot:
  256.     lea    dx,[pathstr]
  257.     mov    ax,CHMOD SHL 8        ; test for file found
  258.     int    DOSINT
  259.     jnc    sdot            ; found it!
  260.  
  261.     cmp    BYTE PTR es:[di],0     ; next path string?
  262.     jne    spth
  263.  
  264.     lea    dx,[perror]
  265.     mov    ah,DSPSTR        ; display error
  266.     int    DOSINT
  267.     mov    ax,TERM SHL 8 + 2    ; error code
  268.     int    DOSINT            ;  and bail
  269.  
  270. spth:
  271.     lea    si,[pathstr - 1]    ; build path name
  272. scnt:    mov    al,es:[di]        ; path char
  273.     test    al,al            ; end?
  274.     jz    schk            ; yes
  275.     inc    di            ; to next path char
  276.     cmp    al,';'
  277.     je    schk
  278.     inc    si            ; locate for char
  279.     mov    [si],al            ; store in work area
  280.     jmp    scnt            ; continue
  281.  
  282. schk:
  283.     cmp    BYTE PTR [si],'\'    ; got delimiter?
  284.     je    sfnh            ; yes
  285.     cmp    BYTE PTR [si],'/'    ; got delimiter?
  286.     je    sfnh            ; yes
  287.     inc    si            ; next position
  288.     mov    BYTE PTR [si],'\'    ; set delimiter
  289. sfnh:
  290.  
  291.     xor    bx,bx            ; move program name
  292. sxxx:    mov    al,[xdvnam+bx]        ; next char
  293.     inc    bx            ; & increment
  294.     inc    si            ; inc for output
  295.     mov    [si],al            ; store in buffer
  296.     test    al,al            ; null terminator?
  297.     jnz    sxxx            ; no, continue
  298.  
  299.     jmp    sgot            ; try to find this file
  300.  
  301. sdot:
  302.     mov    ax,G_INT SHL 8 + EMMINT    ; get EMM vector
  303.     int    DOSINT
  304.     mov    WORD PTR [emm_v],bx    ; save it for later
  305.     mov    WORD PTR [emm_v+2],es
  306.  
  307.     mov    di,OFFSET emmnam    ; check name in driver
  308.     lea    si,[emmnam]        ; against my name
  309.     mov    cx,8
  310.     repe    cmpsb
  311.     je    namok            ; matches
  312.  
  313.     lea    dx,[nerror]
  314.     mov    ah,DSPSTR        ; display error
  315.     int    DOSINT
  316.     mov    ax,TERM SHL 8 + 3    ; error code
  317.     int    DOSINT            ;  and bail
  318.  
  319. namok:
  320.     mov    di,cs            ; compute new vector in di:dx
  321.     mov    ax,OFFSET PROG:header    ; compute effective segment
  322.     mov    cl,4
  323.     shr    ax,cl
  324.     add    di,ax
  325.     mov    dx,emment - header    ; effective offset
  326.  
  327.     mov    bx,cs            ; compute memory I need in es:bx
  328.     mov    es,bx            ; point to my segment
  329.     mov    bx,OFFSET PROG:memend    ; number of paragraphs
  330.     add    bx,15
  331.     mov    cl,4
  332.     shr    bx,cl
  333.  
  334.     jmp    termsec            ; go to termination section
  335.  
  336. merror    DB    'ERROR: MEMORY ALLOCATION FAILURE!',BELL,CR,LF
  337.     DB    '$'            ; (must be above small stack)
  338.  
  339. prog3    ENDS
  340.  
  341.     END    begin
  342.