home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / DOS / UTILITY / GEHEUGEN / UMBGWJ10 / UMB_GWJ.ASM < prev    next >
Assembly Source File  |  1994-11-29  |  13KB  |  553 lines

  1. ;; UMB_GWJ.ASM
  2. ;; Upper Memory Manager for MS-DOS
  3. ;; version 1.0
  4. ;; Copyright (C) 1993  Grzegorz W. Jablonski
  5. ;;
  6. ;; This program is free software; you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation; either version 2 of the License, or
  9. ;; (at your option) any later version.
  10. ;;
  11. ;; This program is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. ;; GNU General Public License for more details.
  15. ;;
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with this program; if not, write to the Free Software
  18. ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. ;;
  20. ;; To contact the author about changes, enhancements, bug reports, or
  21. ;; other comments, send electronic mail to:
  22. ;;
  23. ;;      gwj@j-23.p.lodz.pl (from Internet sites)
  24. ;;
  25. ;; If you are unable to contact the author through electronic mail,
  26. ;; try sending a letter (as a last resort, only) to the following address:
  27. ;;
  28. ;;      Grzegorz W. Jablonski
  29. ;;      ul. Lanowa 6B m 64
  30. ;;      91-103 Lodz
  31. ;;      POLAND
  32. ;;
  33. ;; Please note that mail sent to this address may not yield a response
  34. ;; for several months!
  35. ;;
  36.  
  37. .286p
  38. LOCALS
  39.  
  40. grupa           group   seg_a,seg_b,seg_c
  41.  
  42. seg_a           segment byte public
  43.         assume  cs:seg_a, ds:nothing
  44.         org     0
  45.  
  46. rh              struc      ; request header
  47. len             db      ?
  48. dev             db      ?
  49. cmd             db      ?
  50. status          dw      ?
  51. rsvd            dq      ?
  52. ct              db      ?
  53. aoff            dw      ?
  54. aseg            dw      ?
  55. dptr            dd      ?
  56. rh              ends
  57.  
  58.  
  59. umbdvr          proc    far
  60. loc_3:
  61. header          dd      0FFFFFFFFh
  62. attributes      dw      8000h
  63. pointers        dw      offset strategy
  64.         dw      offset commands
  65. char_dev        db      '$'
  66.         db      'UMBXXX0'
  67. req_addr        dw      ?,?    ;request packet address
  68. umbdvr          endp
  69.  
  70. begn            equ     0
  71. lgth            equ     2
  72.  
  73. strategy        proc    far
  74.         mov     cs:req_addr,bx
  75.         mov     word ptr cs:req_addr+2,es
  76.         retf
  77. strategy        endp
  78.  
  79. commands        proc    far
  80.         push    ds
  81.         push    es
  82.         pusha
  83.         lds     bx,dword ptr cs:req_addr
  84.         cmp     byte ptr [(rh ptr bx).cmd],0
  85.         jne     noinit
  86.         call    initproc
  87. return:
  88.         popa
  89.         pop     es
  90.         pop     ds
  91.         retf
  92. commands        endp
  93.  
  94. noinit:
  95.         mov     word ptr [(rh ptr bx).ct],0
  96.         mov     word ptr [(rh ptr bx).status],810Ch
  97.         jmp     short return
  98. seg_a           ends
  99.  
  100. seg_b           segment
  101.         assume  cs:seg_b,ds:nothing,es:nothing
  102.  
  103. move_beg:       db 32 DUP(?) ;reserve space for DOS memory block header
  104.  
  105. ;XMS services
  106. xms_entry:      pushf
  107.         cmp     ah,0
  108.         jne     noxmsver
  109. ;get XMS version
  110. ifdef DEBUG
  111.         mov     dx,offset versionreq
  112.         call    displayText
  113. endif
  114.         mov     ax,200h
  115.         mov     bx,ax
  116.         xor     dx,dx
  117.         popf
  118.         retf
  119. noxmsver:       push    di
  120.         push    si
  121.         cmp     ah,10h
  122.         je      noumbreq
  123. ;function not implemented - uninstall
  124. ;possible lack of DOS=UMB line in CONFIG.SYS
  125. ifdef DEBUG
  126.         mov     dx,offset notimpl
  127.         call    displayText
  128. endif
  129.         cmp     [cs:byte ptr uninstalled],0
  130.         jne     ret_xms ;we were uninstalled already
  131.         mov     dx,offset noumb
  132.         call    displayText
  133.         xor     ax,ax
  134.         mov     bl,80h
  135.         jmp short deinst
  136.  
  137. maxblock        equ     10 ;maksimum number of UMB blocks
  138. ;UMB request
  139. noumbreq:
  140.         mov     ax,word ptr [cs:left]
  141.         mov     si,offset data
  142.         dec     ax
  143.         shl     ax,2
  144.         add     si,ax
  145.         mov     di,cs:[si+lgth]
  146.         cmp     di,dx
  147.         jb      tooltl
  148. ifdef DEBUG
  149.         mov     dx,offset umbsuccess
  150.         call    displayText
  151. endif
  152.         mov     dx,di
  153.         mov     bx,cs:[si+begn]
  154.         mov     ax,1
  155.         dec     word ptr cs:[left]
  156.         jmp     short   ret_xms
  157. tooltl:         mov     dx,di
  158.         xor     ax,ax
  159.         cmp     byte ptr cs:[left],0
  160.         jz      lack
  161. ifdef DEBUG
  162.         push    dx
  163.         mov     dx,offset umbtosmall
  164.         call    displayText
  165.         pop     dx
  166. endif
  167.         mov     bl,0b0h
  168.         jmp     short   ret_xms
  169. lack:          mov     bl,0b1h
  170.         xor     dx,dx
  171.         jmp     short   deinst
  172.  
  173. ret_xms:        pop     si
  174.         pop     di
  175.         popf
  176.         retf
  177. ;XMS uninstallation
  178. deinst:         cmp [cs:byte ptr uninstalled],1
  179.         je      short ret_xms
  180.         inc [cs:byte ptr uninstalled]
  181.         push    ax
  182.         push    dx
  183.         push    ds
  184.         lds     dx,dword ptr [cs:old2f]
  185.         mov     ax,252Fh
  186.         int     21h   ;set 2Fh interrupt vector                    
  187.         pop     ds  
  188. ifdef DEBUG
  189.         mov     dx,offset deinstTxt
  190.         call    displayText
  191. endif
  192.         pop     dx
  193.         pop     ax
  194.         jmp     short ret_xms
  195.  
  196. int2f_entry:    pushf
  197.         push    dx
  198. ifdef DEBUG
  199.         mov     dx,offset int2fcall
  200.         call    displayText
  201. endif
  202.         pop     dx
  203.         cmp     ah,43h ;mutliplex interrupt for XMS
  204.         jne     not_for_us
  205.         cmp     al,0
  206.         jne     no_xms_install
  207. ;is XMS installed?
  208. ifdef DEBUG
  209.         push    dx
  210.         mov     dx,offset XMSinstalled
  211.         call    displayText
  212.         pop     dx
  213. endif
  214.         mov     al,80h
  215.         popf
  216.         iret
  217. no_xms_install:
  218.         cmp     al,10h
  219.         jne     not_for_us
  220. ;XMS program entry point address request
  221. ifdef DEBUG
  222.         push    dx
  223.         mov     dx,offset XMSaddrreq
  224.         call    displayText
  225.         pop     dx
  226. endif
  227.         mov     bx,cs
  228.         mov     es,bx
  229.         mov     bx,offset seg_b:xms_entry
  230.         popf
  231.         iret
  232. not_for_us:
  233.         popf
  234.         jmp     dword ptr [cs:seg_b:old2f]
  235. ;display text pointed by cs:dx
  236. displayText     proc    near
  237.         push    ds
  238.         push    cs
  239.         pop     ds
  240.         push    ax
  241.         mov     ah,9
  242.         int     21h
  243.         pop     ax
  244.         pop     ds
  245.         ret
  246. displayText     endp
  247.  
  248. old2f:          dd      ?
  249. block_num:     dw      2
  250. data:           dd      maxblock dup(?)
  251. left:    dw      0h
  252. uninstalled:    db      0h
  253. ifdef DEBUG
  254. deinstTxt:      db 13,10,'Int2F handler uninstalled.'
  255.         db 13,10,'$'
  256. versionreq:     db 13,10,'Version number requested.'
  257.         db 13,10,'$'
  258. umbsuccess:     db 13,10
  259.         db 'UMB address returned successfully.'
  260.         db 13,10,'$'
  261. umbtosmall:     db 13,10,'Smaller UMB available.',13,10,'$'
  262. XMSaddrreq:     db 13,10,'XMS entry address returned.'
  263.         db 13,10,'$'
  264. XMSinstalled:   db 13,10,'XMS installation state polling.'
  265.         db 13,10,'$'
  266. notimpl:        db 13,10,'XMS function not implemented'
  267.         db 13,10,'$'
  268. int2Fcall:      db 13,10,'int 2F called',13,10,'$'
  269. endif
  270. noumb:          db 13,10,"Don't install this program "
  271.         db 'without dos=umb line in CONFIG.SYS'
  272.         db 13,10,'$'
  273.  
  274. move_end:
  275. seg_b           ends
  276.  
  277. seg_c           segment
  278.         assume  cs:grupa,ds:grupa
  279. initproc        proc    near
  280.         mov     bp,sp
  281.         cld
  282.  
  283.         push    cs
  284.         pop     ds
  285.  
  286.         mov     ah, 9
  287.         mov     dx, offset grupa:eHello
  288.         int     21h
  289.  
  290.         mov     ax,3306h
  291.         int     21h     ; get DOS version
  292.         jc      wrongDOS
  293.         cmp     bl,5
  294.         jb      wrongDOS
  295.         cmp     bl,0Ah
  296.         jb      skip1
  297. wrongDOS:
  298.         mov     dx,offset grupa:DOSnrTxt
  299.         mov     ah,9
  300.         int 21h
  301.         jmp  finish
  302. xmsinst:
  303. ;XMS already installed
  304.         mov     dx,offset grupa:XMSinstTxt
  305.         mov     ah,9
  306.         int 21h
  307.         jmp  finish
  308. skip1:
  309.         mov     ax,4300h
  310.         int     2Fh ;is XMS server installed?
  311.         cmp     al,80h
  312.         je      xmsinst
  313.         call    lexer
  314.         jnc     @@1
  315.         jmp     errr
  316. @@1:
  317. ;check for space for resident part
  318. ;the last bytes are text - may be overwritten by DOS memory block header
  319.         mov     cx,offset move_end-move_beg
  320.         mov     ax,word ptr [grupa:data+lgth]
  321.         add     cx,15
  322.         shr     cx,4
  323.         cmp     cx,ax
  324.         jna     @@2
  325.         jmp     block2small
  326. @@2:
  327.         ;initialize left and enable SHADOW-RAM
  328.         mov     ax,word ptr [grupa:block_num]
  329.         mov     word ptr [grupa:left],ax
  330.         mov     si,offset grupa:data
  331. blocks_loop:   push     ax
  332.         mov     bx,word ptr [si+begn] 
  333.         ;in bx segment address of block
  334.         mov     dx,[si+lgth] 
  335.         ;in dx block length in paragraphs
  336.         add     dx,bx
  337.         and     dx,7fffh
  338.         ;;enable proper shadow ram
  339.         and     bx,7fffh
  340.         shr     bx,10
  341.         ; bx - first block number
  342. round:          mov     ah,42
  343.         mov     al,15
  344.         ;set block attributes - r/w + cache
  345.         call    poke
  346.         mov     ah,41
  347.         mov     al,bl    ;which blok
  348.         call    poke
  349.         mov     ah,40
  350.         mov     al,195   
  351.         ;pass parameters to chipset
  352.         call    poke
  353.         inc     bx
  354.         mov     ax,bx
  355.         shl     ax,10
  356. ;in ax - first not enabled block of SHADOW-RAM address with MSB reset
  357.         cmp     ax,dx
  358.         jb      round
  359.         ;;SHADOW-RAM enabled
  360.         pop     ax
  361.         inc     si
  362.         inc     si
  363.         inc     si
  364.         inc     si
  365.         dec     ax
  366.         jne     blocks_loop
  367.  
  368.         mov     ax,352fh
  369.         int     21h ;get 2fh vector
  370.         mov     word ptr [grupa:old2f],bx
  371.         mov     word ptr [grupa:old2f+2],es
  372.  
  373.         mov     ax,word ptr [grupa:data+begn]
  374.         mov     es,ax
  375.         xor     di,di
  376.         mov     cx,offset move_end-move_beg
  377.         mov     si,offset grupa:move_beg
  378.         ;mov XMS procedures to UMB
  379.         rep     movsb
  380.  
  381.         mov     dx,offset seg_b:int2f_entry
  382.         mov     ax,word ptr [grupa:data+begn]
  383.         mov     ds,ax
  384.         mov     ax,252Fh
  385.         int     21h  ;set 2Fh vector 
  386. finish:          lds     bx,dword ptr cs:req_addr
  387.         mov     word ptr [(rh ptr bx).aoff],0
  388.         mov     [(rh ptr bx).aseg],cs
  389.         mov     word ptr [(rh ptr bx).status],100h
  390.         ret
  391. errr:           mov     dx,offset grupa:syntax
  392.         mov     ah,9
  393.         int     21h
  394.         jmp short       finish
  395. block2small:
  396.         mov     dx,offset grupa:toosmall
  397.         mov     ah,9
  398.         int     21h
  399.         jmp     short finish
  400. initproc        endp
  401.  
  402. lexer           proc    near
  403.         push      ds
  404.         ;lexical analyser
  405.         lds     bx,dword ptr cs:req_addr 
  406.         lds     si, [(rh ptr bx).dptr] 
  407.         ; ds:si = command line arguments
  408.         cld
  409.  
  410. s0:             lodsb                           
  411.         ; stan 0, skip filename
  412.         call    eol
  413.         je      short @@badch
  414.         call    blank
  415.         jne     short s0
  416.  
  417.         mov cx,0        ;block counter
  418.         mov di,offset grupa:data
  419. blockl:
  420.  
  421. s1:             lodsb                           
  422.         ; state1, skip whitespace
  423.         call    eol
  424.         je      short done
  425.         call    blank
  426.         je      short s1
  427.  
  428.         call    getseg
  429.         jc      @@badch
  430.         mov     word ptr cs:[di+begn],bx
  431.         lodsb
  432.         cmp     al,'-'
  433.         jne     @@badch
  434.         lodsb
  435.         call    getseg
  436.         jc      @@badch
  437.         mov     ax,word ptr cs:[di+begn]
  438.         sub     bx,ax
  439.         mov     word ptr cs:[di+lgth],bx
  440.         inc cx
  441.         inc di
  442.         inc di
  443.         inc di
  444.         inc di
  445.         cmp     cx,maxblock
  446.         je      done
  447.         jmp     short blockl
  448. done:
  449.         cmp     cx,0
  450.         je      @@badch
  451.         pop     ds
  452.         mov word ptr cs:[grupa:block_num],cx
  453.         clc
  454.         ret
  455.  
  456.  
  457. @@badch:        pop     ds    ;wrong character
  458.         stc
  459.         ret
  460.  
  461. lexer           endp
  462.  
  463. ;get segment address from command line
  464. getseg          proc    near
  465.         call    hex0f
  466.         ja      short @@badch
  467.         mov     bh, al
  468.         lodsb   ; get second hexadecimal digit
  469.         call    hex0f
  470.         ja      short @@badch
  471.         shl     bh, 4
  472.         or      bh, al
  473.         xor     bl, bl
  474.         lodsb   ; get third hexadecimal digit
  475.         call    hex0f
  476.         ja      short   @@badch
  477.         mov     bl,al  
  478.         lodsb   ; get fourth hexadecimal number
  479.         call    hex0f
  480.         ja      short   @@badch
  481.         shl     bl,4
  482.         or      bl,al
  483.         clc
  484.         ret
  485. @@badch:
  486.         stc
  487.         ret
  488. getseg          endp
  489.  
  490. ;check for eol
  491. eol             proc    near
  492.         cmp     al, 13
  493.         je      short @@1
  494.         cmp     al, 26
  495. @@1:            ret
  496. endp
  497.  
  498. ;check if space or tab
  499. blank           proc    near
  500.         cmp     al, 32
  501.         je      short @@1
  502.         cmp     al, 9
  503. @@1:            ret
  504. endp
  505.  
  506. ;check, if al is hexadecimal digit
  507. hex0f           proc    near
  508.         sub     al,'0'
  509.         cmp     al,9
  510.         ja      @@1
  511.         ret
  512. @@1:            add     al,'0'
  513.         or      al, 32
  514.         sub     al, 'a'
  515.         cmp     al, 5
  516.         jna     @@2
  517.         ret
  518. @@2:            add     al,10
  519.         cmp     al,15
  520.         ret
  521. endp
  522.  
  523. poke            proc    near
  524.         push    ax
  525.         mov     al,ah
  526.         out     40,al
  527.         pop     ax
  528.         out     36,al
  529.         ret
  530. poke            endp
  531.  
  532. eHello:         db      13,10
  533.         db      '(c) 1993-11-07 Grzegorz Jablonski'
  534.         db      13,10
  535.         db      'UMB driver version 1.0 '
  536.         db      'for HT-320 chipset.',13,10
  537.         db      "If you haven't done so,",13,10
  538.         db      'enable proper shadows in SETUP or '
  539.         db      'disable remapping.',13,10
  540.         db      '$'
  541. syntax:         db      'Syntax error - '
  542.         db      'driver NOT installed.',13,10,'$'
  543. toosmall:       db      'First declared UMB is too small - '
  544.         db      'driver NOT installed.',13,10,'$'
  545. XMSinstTxt:     db      13,10,'XMM already installed - '
  546.         db      'driver NOT installed.',13,10,'$'
  547. DOSnrTxt:       db      13,10,'This program requires '
  548.         db      'DOS 5.00 or higher - driver NOT '
  549.         db      'installed.',13,10,'$'
  550. end_prog:
  551. seg_c           ends
  552. end
  553.