home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / EGAMOV.ZIP / FILIO.ASM < prev    next >
Encoding:
Assembly Source File  |  1986-05-04  |  3.0 KB  |  101 lines

  1. PAGE 55,96
  2. COMMENT |
  3.  
  4. Functions readfil and writfil allow read/write
  5. to/from memory buffers whose segment address is
  6. passed to the procedures.  The purpose is to
  7. eliminate the limitations of MS Pascal which does not
  8. allow to declare an object larger than some 58K.
  9.  
  10. Pascal declarations:
  11.  
  12. function
  13. readfil(var fnam:lstring;count:word;bufads:adsmem):
  14. word;extern;
  15.  
  16. function
  17. writfil(var fnam:lstring;count:word;bufads:adsmem):
  18. word;extern; |
  19.  
  20. TITLE FILIO.ASM Version 1.00
  21.  
  22. fio     segment 'code'
  23.         assume cs:fio,ds:fio,es:fio
  24.         public readfil,writfil
  25. readfil proc far
  26.         push bp
  27.         mov bp,sp
  28.         mov bx,[bp+12]  ;fname address
  29.         mov si,[bx]     ;fname length
  30.         and si,0ffh     ;mask upper 8 bits
  31.         inc si          ;loc just after fname
  32.         mov byte ptr[bx+si],0 ;create ASCIIZ string
  33.         mov dx,bx       ;call needs it
  34.         inc dx          ;skip fname length
  35.         mov ah,3dh      ;get file handle
  36.         mov al,0        ;access code read
  37.         int 21h
  38.         jc rerr_ex      ;cannot open file
  39.         mov bx,ax       ;file handle
  40.         mov cx,[bp+10]  ;byte count
  41.         mov ax,[bp+8]   ;buffer segment
  42.         mov dx,[bp+6]   ;buffer offset
  43.         push ds
  44.         mov ds,ax
  45.         mov ah,3fh
  46.         int 21h         ;read CX bytes
  47.         pop ds
  48.         jc rerr_ex      ;error occured
  49. rexit:   pop bp
  50.         mov bx,[bp+12]  ;fname address
  51.         mov si,[bx]     ;fname length
  52.         and si,0ffh     ;mask upper 8 bits
  53.         inc si          ;loc just after fname
  54.         mov byte ptr[bx+si],0 ;create ASCIIZ string
  55.         mov dx,bx       ;call needs it
  56.         ret 8           ;discard four parameter words
  57. rerr_ex:
  58.         mov ax,0ffffh   ;error rcode
  59.         jmp rexit
  60. readfil endp
  61.  
  62. writfil proc far
  63.         push bp
  64.         mov bp,sp
  65.         mov bx,[bp+12]  ;fname address
  66.         mov si,[bx]     ;fname length
  67.         and si,0ffh     ;mask upper 8 bits
  68.         inc si          ;loc just after fname
  69.         mov byte ptr[bx+si],0 ;create ASCIIZ string
  70.         mov dx,bx       ;call needs it
  71.         inc dx          ;skip fname length
  72.         xor cx,cx
  73.         mov ah,3ch
  74.         int 21h         ;create file
  75.         jc werr_ex      ;error occured
  76.         mov bx,ax       ;file handle
  77.         mov cx,[bp+10]  ;byte count
  78.         mov ax,[bp+8]   ;buffer segment
  79.         mov dx,[bp+6]   ;buffer offset
  80.         push ds         ;preserve data segment
  81.         push bx         ;preserve handle
  82.         mov ds,ax       ;buffer data segment
  83.         mov ah,40h
  84.         int 21h         ;write CX bytes
  85.         pop bx          ;restore handle
  86.         pop ds          ;restore data segment
  87.         jc werr_ex      ;write did not succeed
  88.         mov ah,3eh      ;close file code
  89.         int 21h
  90.         jc werr_ex      ;error occured
  91. wexit:
  92.         pop bp
  93.         ret 8           ;discard four parameter words
  94. werr_ex:
  95.         mov ax,0ffffh   ;error rcode
  96.         jmp wexit
  97. writfil endp
  98.  
  99. fio     ends
  100.         end
  101.