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

  1. ;**************************** QUOTE.ASM *********************************
  2. PAGE  70,132
  3. comment 
  4.                              QUOTE.ASM 
  5.                              ---------
  6.  
  7.      Purpose:
  8.      --------
  9.  
  10.      QUOTE.ASM is intended to demonstrate calling a random generator
  11.      and finding files located in same directory as executable.
  12.      It will display a random quote each time it is called.
  13.  
  14.      Using QUOTE.ASM
  15.      ---------------
  16.  
  17.      The files QUOTE.EXE and QUOTE.DAT must be in the same directory.
  18.      QUOTE is started by typing "QUOTE"<cr> without any parameters.
  19.      
  20.  
  21.      Compiling
  22.      ---------
  23.  
  24.      QUOTE.ASM was compiled using MASM and then linked with LINK.
  25.      
  26.      The following commands can be used:
  27.  
  28.         masm QUOTE;
  29.         link QUOTE,QUOTE,,alib.lib;
  30.  
  31.      The file QUOTE.DAT was built using EDREC.        
  32.  
  33. 
  34.  
  35. ;----------------------------------------------------------------------------
  36. .xlist
  37.     include  mac.inc
  38.     include  common.inc
  39.     extrn    library_setup:far
  40.     extrn    library_terminate:far
  41.     extrn    message:far
  42.     extrn    insert_home_path:far
  43.     extrn    last_charc:far
  44.     extrn    random_word1:far
  45. .list
  46.     
  47. ;------------------------------------------------------------------------------
  48. code        segment para public 'CODE'
  49.         assume    cs:code, ds:code
  50. ;-----------------------------------------------------------------------------
  51.  
  52. stacksize    equ    1024
  53.     db    stacksize dup (0)
  54. stack_    label    word
  55. ;
  56. pspseg        dw    0        ;program segment prefix
  57.  
  58. file_asciiz       db    'quote.dat',0
  59. file_path          db    50 dup (0)
  60. ;-----------------------------------------------------------------------------
  61. start:    cli
  62.     mov    cs:pspseg,es    ;save PSP segment
  63.     mov    ax,cs        ;get CODE segment
  64.     mov    ss,ax
  65.     mov    ds,ax
  66.     mov    es,ax
  67.     mov    sp,offset stack_
  68.     sti
  69.     
  70. ; next, release memory beyond the end of the program
  71. ; The  definition for ZSEG marks the
  72. ; end of the program's code, data and stack area.
  73. ; When linking be sure ZSEG is at the end of the program.
  74.  
  75.     mov    ax,zseg
  76.  
  77.     mov    bx,cs:pspseg        ;
  78.     mov    es,bx
  79.     sub    bx,ax
  80.     neg    bx            ; size of program in paragraphs
  81.     mov    ah,4Ah            ; resize memory block
  82.     int    21h
  83. ;
  84. ; setup the library information
  85. ;
  86.     mov    ax,pspseg        ;pass psp segment to setup
  87.     mov    bx,0            ;number of floating point variables
  88.     call    library_setup
  89.  
  90.     mov    ax,cs
  91.     mov    es,ax
  92. ;
  93. ; find where this program was loaded from, then assume the
  94. ; quote.dat file is at that location.
  95. ;
  96.     mov    si,offset file_asciiz
  97.     mov    di,offset file_path
  98.     call    insert_home_path
  99. ;
  100. ; now get our random record#
  101. ;
  102.     mov    bx,1
  103.     mov    bp,166
  104.     call    random_word1
  105.     mov    cx,ax
  106.     
  107. ;
  108. ;  inputs:    al = separator           (if flag msg_open)
  109. ;             bh = rows in box         (if flag msg_disp)
  110. ;             bl = columns in box      (if flag msg_disp)
  111. ;             cx = record #            (if flag msg_disp & not msg_rand)
  112. ;             dx = box upper left loc  (if flag msg_disp)
  113. ;          ds:si = ptr to file name    (if flag msg_open and not msg_ram)
  114. ;          ds:si = ptr to msg text     (if flag msg_ram and msg_open)
  115. ;             bp = flags, see equates
  116. ;             es = file selector       (if not flag msg_open)
  117. ; The following equates are inputs to the MESSAGE routine to contol its
  118. ; actions.  See flags in -BP-
  119. ;
  120. ; msg_save_win    equ    001h    ;save screen area before drawing box
  121. ; msg_restore_win equ    002h    ;restore screen before exit
  122. ; msg_hyper    equ    004h    ;this is a hyper msg & key processing
  123. ; msg_yesno    equ    008h    ;this message needs yes/no response
  124. ; msg_anykey    equ    010h    ;this message waits for any key
  125. ; msg_nokey    equ    020h    ;this message does not pause for key
  126. ; msg_close    equ    040h    ;close message file before exit
  127. ; msg_open    equ    080h    ;open message file before attempting read
  128. ;             equ    100h    ;                          
  129. ; msg_disp    equ    200h    ;display the message
  130. ; msg_ram        equ    400h    ;message in memory (ds:si) rather than in file
  131. ;
  132.     mov    al,0        ;message separators
  133.     mov    bh,5        ;box is 5 rows
  134.     mov    bl,75        ;box length
  135.     mov    dx,0905h    ;put box here
  136.     mov    si,offset file_path
  137.     mov    bp,msg_save_win+msg_restore_win+msg_anykey+msg_open+msg_close+msg_disp
  138.     call    message
  139.  
  140.     mov    ax,1
  141.     call    library_terminate
  142. exit2:
  143.           mov    ax,4C00h
  144.     int    21h
  145.  
  146. code        ends
  147.  
  148. ;-------------------------------------------------------------------------
  149. ;
  150. ; This segment definition is needed so linker will put the LIBSEG here
  151. ; before the ZSEG.  We want ZSEG to be last so memory allocation will
  152. ; work correctly.
  153. ;
  154. LIBSEG           segment byte public 'LIB'
  155. LIBSEG    ENDS
  156. ;-------------------------------------------------------------------------
  157. ; zseg must be at the end of the program for memory allocation from
  158. ; DOS.
  159. ;
  160. zseg    segment    para public 'ZZ'
  161. zseg    ends
  162.         end    start
  163.