home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / PROGRAM / ASM / ALIB30B / MEMORY3.ASM < prev    next >
Assembly Source File  |  1994-12-01  |  8KB  |  312 lines

  1.     PAGE    66,132
  2. ;****************************** MEMORY3.ASM *********************************
  3. ;
  4. ;----------------------------------------------------------------------------
  5. LIBSEG           segment byte public "LIB"
  6.         assume cs:LIBSEG , ds:nothing
  7.  
  8. ;----------------------------------------------------------------------------
  9. .xlist
  10.     include  mac.inc
  11.     include  common.inc
  12.     extrn    stdout_string:far
  13. .list
  14. ;----------------------------------------------------------------------------
  15.  
  16. MCB    STRUC
  17.   mcb_code1    db    0        ;4d=start 5a=end
  18.   prog_seg1    dw    0        ;program segment
  19.   mcb_len1    dw    0        ;length of memory ctrl    block
  20. MCB    ENDS
  21.  
  22. comment 
  23. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(  MEMORY )
  24. MCB_FIND_FIRST - scan for start of MCB chain
  25. ;  inputs: none
  26. ;  outputs: if no carry, then   es:0 points at MCB chain
  27. ;           if carry then mcb chain is bad
  28. ;
  29. ;  note:  This routine scan for the MCB chain, rather than look in
  30. ;         the DOS database.  For some implementations of brain
  31. ;         damaged DOS, the scan works better.
  32. ;* * * * * * * * * * * * * *
  33. 
  34. current_mcb_seg    dw    0
  35.  
  36.     public    MCB_FIND_FIRST
  37. MCB_FIND_FIRST    proc    far
  38.     apush    ax,bx,di
  39.     mov    current_mcb_seg,50h            ;start search at 50:0
  40.     mov    es,current_mcb_seg
  41.     sub    di,di
  42. d_find1:
  43.     cmp    es:[di.mcb_code1],4dh
  44.     je    d_find3            ;jump if possible start
  45. d_find2:
  46.     mov    ax,es
  47.     inc    ax
  48.     mov    es,ax            ;move to next paragraph
  49.     cmp    ax,0A000h
  50.     jae    mcb_chain_bad
  51.     jmp    d_find1            ;loop till trial start found
  52. d_find3:
  53.     mov    current_mcb_seg,es    ;save trial start
  54. d_find4:
  55.     mov    bx,es
  56.     add    bx,es:[di.mcb_len1]    ;conpute next mcb position
  57.     cmp    ax,bx            ;check if segment changed
  58.     jae    d_find2            ;try again if new segment is wrong
  59.     inc    bx            ;move    forward    one paragraph
  60.     mov    es,bx
  61.     cmp    es:[di.mcb_code1],4dh    ;check if next mcb is ok
  62.     je    d_find4            ;jump if mcb ok
  63.     cmp    es:[di.mcb_code1],5ah    ;check if last mcb
  64.     je    d_find5            ;jump if end of chain found
  65. ;
  66. ; bad code found, this must not    be the real mcb    chain
  67. ;
  68. d_find4a:
  69.     mov    es,current_mcb_seg
  70.     jmp    d_find2
  71. ;
  72. ; we could not find the MCB chain by searching, ask DOS
  73. ;
  74. mcb_chain_bad:
  75.     mov    ah,52h            ;get ptr to DOS lists
  76.     int    21h            ;  in es:bx
  77.     mov    es,es:[bx-2]        ;get mcb pointer from list
  78.     stc
  79.     jmp    mff_exit
  80. ;
  81. ; end of chain found ok
  82. ;
  83. d_find5:
  84.     mov    es,current_mcb_seg    ;restore ptr to start of mcb chain
  85.     clc
  86. mff_exit:
  87.     apop    di,bx,ax
  88.     retf
  89. MCB_FIND_FIRST    endp
  90.  
  91.  
  92. comment 
  93. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(  MEMORY )
  94. MCB_FIND_NEXT - scan for next MCB entry
  95. ;  inputs: ES:0 points at current MCB
  96. ;           if no carry then, es:0 point at next mcb
  97. ;           if carry then this is last mcb
  98. ;
  99. ;* * * * * * * * * * * * * *
  100. 
  101.  
  102.     public    MCB_FIND_NEXT
  103. MCB_FIND_NEXT    proc    far
  104.     push    bx
  105.     mov    bx,es
  106.     add    bx,es:[mcb_len1]    ;conpute next mcb position
  107.     inc    bx            ;move    forward    one paragraph
  108.     mov    es,bx
  109.     cmp    byte ptr es:[0],4dh    ;signature ok
  110.     je    good_mcb
  111.     stc
  112.     jmp    mfn_exit        ;jmp if bad mcb or end of chain
  113. good_mcb:
  114.     clc
  115. mfn_exit:
  116.     pop    bx
  117.     retf
  118. MCB_FIND_NEXT    endp
  119.  
  120. comment 
  121. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(  MEMORY )
  122. MCB_CHECK_NAME - compare current MCB name against list of names
  123. ;  inputs: ES:0 points at current MCB
  124. ;          DS:SI points at compare list, asciiz strings each terminated
  125. ;                with zero, the list is terminated with zero also.  Thus
  126. ;                end of list is two zeros in a row.
  127. ;  output: carry set if match, and ds:si point at match name
  128. ;
  129. ;* * * * * * * * * * * * * *
  130. 
  131. cmp_list    dd    0
  132.  
  133.     public    MCB_CHECK_NAME
  134. MCB_CHECK_NAME    proc    far
  135.     mov    word ptr cmp_list,si
  136.     mov    word ptr cmp_list+2,ds
  137.     
  138.     call    mcb_find_name            ;look in mcb for program name
  139.     jnc    mcb_srch_cont            ;jmp if name not found
  140.     call    compare_name
  141. mcb_srch_cont:
  142.     retf
  143. MCB_CHECK_NAME    endp
  144.  
  145. comment 
  146. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(  MEMORY )
  147. MCB_FIND_NAME - scan current mcb to see if name is present
  148. ;  inputs:  es:0 is mcb
  149. ;  output:  carry set if name found and es:di points at name
  150. ;
  151. ;* * * * * * * * * * * * * *
  152. 
  153. ;
  154.     public    MCB_FIND_NAME
  155. MCB_FIND_NAME    proc    far
  156.     mov    ax,es:[mcb_len1]        ;get paragraph size of mcb
  157.     cmp    ax,4096/16            ;check if mcb too big for envior
  158.     jae    fn_no_name            ;jmp if no name found
  159.     mov    cl,4
  160.     shl    ax,cl                ;convert to byte size
  161.     mov    cx,ax                ;set loop count
  162.     mov    di,16                ;start scan from loc. 16
  163. fn_scan_lp:
  164.     cmp    word ptr es:[di],0
  165.     jne    fn_nxt_loc
  166.     cmp    word ptr es:[di+2],0001
  167.     je    fn_name_ck            ;jmp if possible name start
  168. fn_nxt_loc:
  169.     inc    di
  170.     loop    fn_scan_lp            ;loop till name start fnd
  171.     jmp    fn_no_name            ;jmp if name not found
  172. ;
  173. ; we have found 00,00,01,00 now verify a name is present
  174. ;
  175. fn_name_ck:
  176.     add    di,4                ;move past 00,00,01,00
  177.     cmp    byte ptr es:[di],20h
  178.     jb    fn_no_name            ;jmp if name is illegal
  179.     cmp    byte ptr es:[di],80h
  180.     jae    fn_no_name            ;jmp if name is illegal
  181.     
  182. ;
  183. ; verify a zero is at end of name
  184. ;
  185.     mov    cx,45                ;max path size
  186.     dec    di                ;adjust for pre increment
  187. fn_zero_scan:
  188.     inc    di
  189.     cmp    byte ptr es:[di],0
  190.     je    fn_fnd_zero            ;jmp if expected zero found
  191.     cmp    byte ptr es:[di],20h
  192.     jb    fn_no_zero            ;jmp if name is illegal
  193.     cmp    byte ptr es:[di],80h
  194.     jae    fn_no_zero            ;jmp if name is illegal
  195.     loop    fn_zero_scan
  196. fn_no_zero:
  197.     jmp    fn_no_name            ;jmp if no zero at end of name
  198. ;
  199. ; we have found 00,00,01,00 followed by what appears to be a valid name
  200. ; scan back till start of name found
  201. ;
  202. fn_fnd_zero:
  203.     dec    di
  204.     cmp    byte ptr es:[di],0
  205.     je    fn_name_strt
  206.     cmp    byte ptr es:[di],'\'
  207.     je    fn_name_strt
  208.     cmp    byte ptr es:[di],':'
  209.     jne    fn_fnd_zero
  210. ;
  211. ; es:di now points at start of name -1
  212. ;
  213. fn_name_strt:
  214.     inc    di                ;move to name start
  215.     stc
  216.     jmp    fn_exit
  217. fn_no_name:
  218.     clc
  219. fn_exit:
  220.     retf
  221. MCB_FIND_NAME    endp
  222. ;---------------------------------------------------------------------------
  223. ; compare name in mcb to list at cmp_list
  224. ;  inputs: es:di points at mcb name
  225. ;  output: carry set if match, and ds:si point at match name
  226. ;
  227. mcb_name_ptr    dw    0
  228.  
  229. compare_name:
  230.     push    ds
  231.     mov    mcb_name_ptr,di
  232.     lds    si,cmp_list
  233.     cld
  234. cn_loop:
  235.     mov    al,byte ptr es:[di]        ;get mcb char.
  236.     cmp    al,'Z'
  237.     jb    cn_upper
  238.     sub    al,20h                ;convert to upper case
  239. cn_upper:
  240.     cmp    al,byte ptr ds:[si]
  241.     jne    cn_miscompare            ;jmp if different
  242.     cmp    al,0
  243.     je    cn_match            ;jmp if name matches
  244.     inc    si
  245.     inc    di
  246.     jmp    cn_loop                ;loop till all of name compared
  247. ;
  248. ; we have a miscompare, check if more entries on list
  249. ;    ds:si points at compare table
  250. ;    es:di points at mcb name
  251. ;
  252. cn_miscompare:
  253.     mov    di,mcb_name_ptr            ;restore di
  254.     cmp    byte ptr ds:[si],0        ;check if end of name
  255.     je    cn_name_end
  256.     inc    si
  257.     jmp    cn_miscompare            ;loop till end of name
  258. cn_name_end:
  259. ;
  260. ; scan past second name of matched pair
  261. ;
  262. cn_miscompare2:
  263.     mov    di,mcb_name_ptr            ;restore di
  264.     cmp    byte ptr ds:[si],0        ;check if end of name
  265.     je    cn_name_end2
  266.     inc    si
  267.     jmp    cn_miscompare2            ;loop till end of name
  268. cn_name_end2:
  269. ;
  270. ; check if end of compare list
  271. ;
  272.     inc    si                ;move to start of next name
  273.     cmp    byte ptr ds:[si],0
  274.     jne    cn_loop                ;loop if another name on list
  275.     clc
  276.     jmp    cn_exit                ;jmp if no matches
  277. cn_match:
  278.     inc    si                ;move to start of match name
  279.     stc
  280. cn_exit:
  281.     mov    di,mcb_name_ptr            ;restore -di-
  282.     pop    ds
  283.     ret
  284.  
  285. comment 
  286. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(  MEMORY )
  287. MCB_DISPLAY_NAME - display program name if associated with current mcb
  288. ;  inputs: ES:DI - points at name in MCB
  289. ;  outputs: none
  290. ;
  291. ; note: name is display at the cursor position.
  292. ;* * * * * * * * * * * * * *
  293. 
  294.  
  295.     public    MCB_DISPLAY_NAME
  296. MCB_DISPLAY_NAME    proc    far
  297.     apush    si,ds
  298.     mov    si,di
  299.     push    es
  300.     pop    ds
  301. ;
  302. ; display match name
  303. ;
  304.     call    stdout_string
  305.     apop    ds,si
  306.     retf
  307. MCB_DISPLAY_NAME    endp
  308.  
  309.  
  310. LIBSEG    ENDS
  311. ;;    end
  312.