home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / m / memres41.zip / TABLEV.ASM < prev    next >
Assembly Source File  |  1988-05-20  |  6KB  |  132 lines

  1. ; Ed Jordan 201 Smallacombe Drive, Scranton, Pa. 18508
  2. ; Version 1 - December 1986
  3. ; Version 1a - May 1988 - write table to disk from buffer instead of 0:0
  4.  
  5. cr                equ             13                ; carriage return
  6. lf                equ             10                ; line feed
  7. el                equ             '$'               ; end of string sign
  8. eof               equ             1ah               ; end of file mark
  9. esc               equ             1bh               ; escape character
  10. stdin             equ             0                 ; standard input
  11. stdout            equ             1                 ; standard output
  12. stderr            equ             2                 ; standard error handle
  13. stdaux            equ             3                 ; standard aux
  14. stdprn            equ             4                 ; standard printer handle
  15.  
  16. stackseg          segment stack para 'stack'
  17.                   db              40 dup('stack')
  18. stackseg          ends
  19.  
  20. dataseg           segment         public para    'data'
  21. error1            db              'Vector table found in current directory.',cr,lf
  22.                   db              'Press any key to revise this table or <ESC>',cr,lf
  23.                   db              'to exit.',cr,lf,el
  24. error2            db        cr,lf,'Error creating file <VECTOR.TBL>.',cr,lf,el
  25. mesg1             db              cr,lf,'Copying vector table... ',el
  26. mesg2             db              'done.',cr,lf,el
  27. mesg3             db              'VECTOR.TBL',0
  28. handle            dw              ?
  29. mesg4             db              eof
  30. mesg5             db              'TABLEV.EXE version 1a - May 1988'
  31.                   db              cr,lf,'Author: Ed Jordan',cr,lf,el
  32. buffer            db              400h dup (0)
  33. dataseg           ends
  34.  
  35. codeseg           segment public para 'code'
  36.                   assume cs:codeseg,ds:dataseg,es:nothing,ss:stackseg
  37.  
  38. tablev            proc            far
  39.                   mov             ax,dataseg
  40.                   mov             ds,ax
  41.                   mov             es,ax
  42.                   lea             dx,mesg5
  43.                   call            printerr
  44.                   lea             dx,mesg3          ; point to asciiz
  45.                   call            open_file         ; open file
  46.                   jnb             tbl1              ; if error file not found
  47. tbl3:             lea             dx,mesg3
  48.                   call            create_file       ; make file if not found
  49.                   jnb             tbl4
  50. tbl5:             lea             dx,error2         ; signal if error encountered
  51.                   call            printerr
  52.                   jmp short       tbl2
  53. tbl1:             lea             dx,error1
  54.                   call            printerr
  55.                   call            wait_response     ; wait for keyboard resp
  56.                   cmp             al,esc            ; test for escape key
  57.                   jz              tbl2              ; exit if pressed
  58.                   jmp             tbl3
  59. tbl4:             mov             handle,ax         ; store file handle
  60.                   lea             dx,mesg1
  61.                   call            printerr
  62.                   push            ds
  63.                   lea             di,buffer         ; point to buffer
  64.                   xor             ax,ax
  65.                   mov             ds,ax
  66.                   xor             si,si
  67.                   mov             cx,0400h
  68.                   rep movsb                         ; copy bytes to buffer
  69.                   pop             ds
  70.                   mov             bx,handle
  71.                   lea             dx,buffer         ; ds:dx = data to write
  72.                   mov             cx,0400h          ; size of vector table
  73.                   mov             ah,40h            ; write file
  74.                   int             21h
  75.                   jb              tbl5
  76.                   mov             ax,dataseg        ; reset the data segment
  77.                   mov             ds,ax
  78.                   call            close_file        ; close the file
  79.                   jb              tbl5
  80.                   lea             dx,mesg2
  81.                   call            printerr
  82. tbl2:             mov             ah,4ch
  83.                   int             21h               ; exit
  84. tablev            endp
  85.  
  86. open_file         proc            near
  87.                   mov             ah,3dh            ; open file
  88.                   mov             al,2              ; read/write access code
  89.                   int             21h
  90.                   ret
  91. open_file         endp
  92.  
  93. wait_response     proc            near
  94.                   mov             ax,0c08h          ; no need to make
  95.                   int             21h               ; keyboard response capital
  96.                   ret                               ; letters only
  97. wait_response     endp
  98.  
  99. close_file        proc            near
  100.                   mov             ah,3eh            ; bx= handle
  101.                   int             21h
  102.                   ret
  103. close_file        endp
  104.  
  105. create_file       proc            near
  106.                   mov             ah,3ch            ; ds:dx= asciiz
  107.                   xor             cx,cx             ; attribute of file
  108.                   int             21h
  109.                   ret
  110. create_file       endp
  111.  
  112. printerr          proc            near
  113.                   push            es                ; ds:dx = message
  114.                   push            ds
  115.                   pop             es
  116.                   mov             cx,250            ; max number of char per
  117.                   mov             al,el             ; message
  118.                   mov             di,dx             ; look for end of string
  119.                   repne scasb
  120.                   mov             cx,di             ; get string size
  121.                   sub             cx,dx             ; number of bytes to write
  122.                   dec             cx                ; don't print the last byte
  123.                   mov             bx,stderr
  124.                   mov             ah,40h            ; write to file function
  125.                   int             21h
  126.                   pop             es
  127.                   ret
  128. printerr          endp
  129.  
  130. codeseg           ends
  131.                   end
  132.