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

  1. ;**************************** MEMORY.ASM ********************************
  2. PAGE  70,132
  3. comment 
  4.                              MEMORY.ASM
  5.                              ----------
  6.  
  7.      Purpose:
  8.      --------
  9.  
  10.      MEMORY.ASM display the memory information available from
  11.      ALIB.  Include are the MCB chain, and the size of DOS,
  12.      XMS, and EMS memory.
  13.  
  14.      Compiling
  15.      ---------
  16.  
  17.      MEMORY.ASM was compiled using MASM and then linked with LINK.
  18.      
  19.      The following commands can be used:
  20.  
  21.         masm MEMORY;
  22.         link MEMORY,MEMORY,,alib.lib;
  23.  
  24.  
  25. 
  26.  
  27. ;----------------------------------------------------------------------------
  28. .xlist
  29.     include  mac.inc
  30.     include  common.inc
  31.     extrn    library_setup:far
  32.     extrn    library_terminate:far
  33.     extrn    stdout_string:far
  34.     extrn    stdout_char:far
  35.     extrn    word_to_hex_stdout:far
  36.     extrn    stdout_crlf:far
  37.     extrn    stdout_spaces:far
  38.     extrn    word_to_dec_stdout:far
  39.     extrn    dword_to_dec_stdout:far
  40.     extrn    a20_check:far
  41.     extrn    xms_check:far
  42.     extrn    mcb_find_first:far
  43.     extrn    mcb_find_next:far
  44.     extrn    mcb_find_name:far
  45.     extrn    mcb_display_name:far
  46.     extrn    check_dos_memory:far
  47.     extrn    xms_umb_check:far
  48.     extrn    ems_check:far
  49.     extrn    ext_check:far    
  50. .list
  51.     
  52. ;------------------------------------------------------------------------------
  53. code        segment para public 'CODE'
  54.         assume    cs:code, ds:code
  55. ;-----------------------------------------------------------------------------
  56.  
  57. stacksize    equ    1024
  58.     db    stacksize dup (0)
  59. stack_    label    word
  60. ;
  61. pspseg        dw    0        ;program segment prefix
  62. ;-----------------------------------------------------------------------------
  63. start:    cli
  64.     mov    cs:pspseg,es    ;save PSP segment
  65.     mov    ax,cs        ;get CODE segment
  66.     mov    ss,ax
  67.     mov    ds,ax
  68.     mov    es,ax
  69.     mov    sp,offset stack_
  70.     sti
  71.     
  72. ; next, release memory beyond the end of the program
  73. ; The  definition for ZSEG marks the
  74. ; end of the program's code, data and stack area.
  75. ; When linking be sure ZSEG is at the end of the program.
  76.  
  77.     mov    ax,zseg
  78.  
  79.     mov    bx,cs:pspseg        ;
  80.     mov    es,bx
  81.     sub    bx,ax
  82.     neg    bx            ; size of program in paragraphs
  83.     mov    ah,4Ah            ; resize memory block
  84.     int    21h
  85.  
  86.     mov    ax,cs
  87.     mov    es,ax
  88. ;
  89. ; setup the library information
  90. ;
  91.     mov    ax,pspseg        ;pass psp segment to setup
  92.     mov    bx,0            ;number of floating point variables
  93.     call    library_setup
  94. ;
  95. ; now remove the memory manager so we can check available memory.
  96. ; The memory manager grabs all available memory, and we will always
  97. ; get zero available if it is active.
  98. ;
  99.     mov    ax,1
  100.     call    library_terminate
  101.  
  102.     call    a20_status
  103.     call    mcb_status
  104.     call    conventional_status
  105.     call    xms_status
  106.     call    ems_status
  107.     call    ext_status
  108.     
  109. exit2:
  110.           mov    ax,4C00h
  111.     int    21h
  112. ;--------------------------------------------------------------------------
  113. wrap_msg    db    'A20 line is wrapping',0
  114. no_wrap_msg    db    'A20 line is not wrapping',0
  115. xwrap_msg    db    ', XMS driver reports A20 is wrapping',0
  116. xno_wrap_msg    db    ', XMS driver reports A20 is not wrapping',0
  117. break        label    byte
  118.  db '------------------------------------------------------------------------'
  119. crlf        db    0dh,0ah,0
  120.  
  121. a20_status:
  122.     mov    si,offset break
  123.     call    stdout_string
  124.     call    a20_check
  125.     mov    si,offset wrap_msg
  126.     cmp    al,0
  127.     je    a20_1            ;jmp if wrapping
  128.     mov    si,offset no_wrap_msg
  129. a20_1:    call    stdout_string
  130.     call    xms_check
  131.     mov    si,offset crlf
  132.     cmp    bx,0
  133.     je    a20_2            ;jmp if no xms driver
  134.     mov    si,offset xwrap_msg
  135.     cmp    cx,0
  136.     je    a20_2
  137.     mov    si,offset xno_wrap_msg
  138. a20_2:    call    stdout_string
  139.     call    stdout_crlf
  140.     ret
  141. ;--------------------------------------------------------------------------
  142.  
  143. MCB    STRUC
  144.   mcb_code1    db    0        ;4d=start 5a=end
  145.   prog_seg1    dw    0        ;program segment
  146.   mcb_len1    dw    0        ;length of memory ctrl    block
  147. MCB    ENDS
  148. ;
  149. mcb_status:
  150.     mov    si,offset break
  151.     call    stdout_string
  152.     mov    si,offset header
  153.     call    stdout_string
  154. ;
  155. ; chain high mcb's in
  156. ;
  157.     mov    ax,5803h
  158.     mov    bx,1
  159.     int    21h
  160.     
  161.     call    mcb_find_first
  162.     jmp    show_mcb
  163. mcb_loop:
  164.     call    mcb_find_next
  165. show_mcb:
  166.     pushf
  167.     mov    ah,2
  168.     call    stdout_spaces
  169.     mov    ax,es
  170.     call    word_to_hex_stdout
  171.     mov    ah,4
  172.     call    stdout_spaces
  173.     mov    ax,es:[prog_seg1]
  174.     call    word_to_hex_stdout
  175.     mov    ah,4
  176.     call    stdout_spaces
  177.     mov    ax,es:[mcb_len1]
  178.     call    word_to_hex_stdout
  179.     mov    ah,4
  180.     call    stdout_spaces
  181.     call    mcb_find_name
  182.     jnc    skip
  183.     call    mcb_display_name
  184. skip:    call    stdout_crlf
  185.     popf
  186.     jnc    mcb_loop
  187. ;
  188. ; unchain high mcb's
  189. ;
  190.      mov    ax,5803h
  191.     mov    bx,0
  192.     int    21h
  193.        ret
  194.  
  195. header    db    0dh,0ah,0dh,0ah
  196.     db    '  MCB     Block   Block   Process',0dh,0ah
  197.     db    '  Seg     Owner   Size    Name   ',0dh,0ah
  198.          db    '  -----------------------------------------------',0dh,0ah
  199.     db    0
  200. ;---------------------------------------------------------------------------
  201.  
  202. c_msg1    db    'Available DOS memory = ',0
  203. c_msg2    db    '  Total memory size (bytes) = ',0
  204. ;
  205. ; display conventional memory status
  206. ;
  207. conventional_status:
  208.     mov    si,offset break
  209.     call    stdout_string
  210.     mov    ax,zseg
  211.     call    check_dos_memory
  212.     mov    si,offset c_msg1
  213.     call    stdout_string
  214.     mov    cx,16
  215.     mul    cx
  216.     call    dword_to_dec_stdout
  217.     mov    ah,4
  218.     call    stdout_spaces
  219.     mov    si,offset c_msg2
  220.     call    stdout_string
  221.     mov    ax,bx
  222.     mov    cx,16
  223.     mul    cx
  224.     call    dword_to_dec_stdout
  225.     call    stdout_crlf
  226.     ret
  227. ;---------------------------------------------------------------------------
  228. no_xms    db    'The XMS driver was not found',0
  229. found_xms db    'The total avaliable XMS memory (bytes) = ',0
  230. no_umb    db    'XMS reports the UMB area is not available',0
  231. found_umb db    'XMS reports available UMB area (bytes) = ',0
  232.  
  233. ;
  234. ; display xms status
  235. ;
  236. xms_status:
  237.     mov    si,offset break
  238.     call    stdout_string
  239.     call    xms_check
  240.     mov    si,offset no_xms
  241.     cmp    bx,0
  242.     je    xms1            ;jmp if no xms
  243.     mov    si,offset found_xms
  244. xms1:    call    stdout_string
  245.     cmp    bx,0
  246.     je    xms9            ;jmp if no xms
  247.     mov    ax,dx
  248.     mov    cx,1024
  249.     mul    cx
  250.     call    dword_to_dec_stdout
  251.     call    stdout_crlf
  252.  
  253.     call    xms_umb_check
  254.     mov    si,offset no_umb
  255.     cmp    bx,0
  256.     je    xms2            ;jmp if no xms
  257.     mov    si,offset found_umb
  258. xms2:    call    stdout_string
  259.     cmp    bx,0
  260.     je    xms9            ;jmp if no xms
  261.     mov    ax,dx
  262.     mov    cx,1024
  263.     mul    cx
  264.     call    dword_to_dec_stdout
  265. xms9:    call    stdout_crlf
  266.     ret
  267. ;---------------------------------------------------------------------------
  268. no_ems_msg db 'EMS memory was not found',0dh,0ah,0
  269. ems_size_msg db 'EMS free memory was found, size (bytes) = ',0
  270. ems_tsize_msg db 'Total EMS size is (bytes) = ',0
  271.  
  272. ems_status:
  273.     mov    si,offset break
  274.     call    stdout_string
  275.     call    ems_check
  276.     mov    si,offset no_ems_msg
  277.     jc    ems9
  278.     push    dx
  279.     mov    si,offset ems_size_msg
  280.     call    stdout_string
  281.     mov    ax,bx
  282.     mov    cx,16384
  283.     mul    cx
  284.     call    dword_to_dec_stdout
  285.     call    stdout_crlf
  286.     mov    si,offset ems_tsize_msg
  287.     call    stdout_string
  288.     pop    ax
  289.     mul    cx
  290.     call    dword_to_dec_stdout
  291.     mov    si,offset crlf
  292. ems9:    call    stdout_string
  293.     ret
  294. ;---------------------------------------------------------------------------
  295. ext_msg1 db 'Available EXT memory reported by BIOS (bytes) = ',0
  296. ext_msg2 db 'Total EXT reported by CMOS (bytes) = ',0
  297.  
  298. ext_status:
  299.     mov    si,offset break
  300.     call    stdout_string
  301.     mov    si,offset ext_msg1
  302.     call    stdout_string
  303.     call    ext_check
  304.     mov    cx,1024
  305.     mul    cx
  306.     call    dword_to_dec_stdout
  307.     call    stdout_crlf
  308.  
  309.     mov    si,offset ext_msg2
  310.     call    stdout_string
  311.     mov    ax,bx
  312.     mov    cx,1024
  313.     mul    cx
  314.     call    dword_to_dec_stdout
  315.     call    stdout_crlf
  316.     
  317.     ret
  318. ;---------------------------------------------------------------------------
  319.  
  320. code        ends
  321.  
  322. ;-------------------------------------------------------------------------
  323. ;
  324. ; This segment definition is needed so linker will put the LIBSEG here
  325. ; before the ZSEG.  We want ZSEG to be last so memory allocation will
  326. ; work correctly.
  327. ;
  328. LIBSEG           segment byte public 'LIB'
  329. LIBSEG    ENDS
  330. ;-------------------------------------------------------------------------
  331. ; zseg must be at the end of the program for memory allocation from
  332. ; DOS.
  333. ;
  334. zseg    segment    para public 'ZZ'
  335. zseg    ends
  336.         end    start
  337.