getl.asm
上传用户:xiaoan1112
上传日期:2013-04-11
资源大小:19621k
文件大小:4k
源码类别:

操作系统开发

开发平台:

Visual C++

  1. ;
  2. ; blindingly fast assembly help for Z
  3. ;
  4. .xlist
  5. include ..hcmacros.inc
  6. ifdef OS2
  7. include ..hdoscalls.inc
  8. if1
  9. %out  ! OS2 module
  10. endif
  11. endif
  12. .list
  13. sBegin  data
  14. assumes ds,data
  15. bufstart    dd     ?
  16. staticW bufsrc,?
  17. staticW buflen,?
  18. staticW buflength,?
  19. staticW buffh,?
  20. globalB fGetlCR,?
  21. bufpos      dd      ?
  22. sEnd
  23. sBegin code
  24. assumes cs,code
  25. ;
  26. ; getlpos returns current seek position in file
  27. ;
  28. cProc   getlpos,<PUBLIC>
  29. cBegin
  30.         mov     dx,word ptr bufpos+2
  31.         mov     ax,word ptr bufpos
  32. cEnd
  33. ;
  34. ; getlinit (buf, len, fh) initializes the getl routine for buffer buf and fh fh
  35. ;
  36. cProc   getlinit,<PUBLIC>
  37. parmD   buf
  38. parmW   len
  39. parmW   fh
  40. cBegin
  41.         mov     ax,off_buf
  42.         mov     word ptr bufstart,ax
  43.         mov     ax,seg_buf
  44.         mov     word ptr bufstart+2,ax
  45.         mov     ax,fh
  46.         mov     buffh,ax
  47.         mov     ax,len
  48.         mov     buflength,ax
  49.         mov     buflen,0
  50.         mov     word ptr bufpos,0
  51.         mov     word ptr bufpos+2,0
  52.         mov     fGetlCR,0
  53. cEnd
  54. ;
  55. ; getl (dst, len) returns TRUE if a line was read.
  56. ;
  57. cProc   getl,<PUBLIC>,<DS,SI,DI>
  58. parmW   dst
  59. parmW   dstlen
  60. ifdef OS2
  61. localW BytesRead
  62. endif
  63. cBegin
  64.         assumes ss,data
  65.         cld
  66.         push    ds
  67.         pop     es
  68.         mov     ds,word ptr bufstart+2
  69.         assumes ds,nothing
  70.         mov     si,bufsrc
  71.         mov     di,dst
  72.         mov     cx,buflen
  73.         mov     dx,dstlen
  74.         dec     dx                  ; room for NUL at end
  75.         jcxz    fill
  76. movc:   lodsb                       ; get a byte
  77.         cmp     al,13               ; is it special?
  78.         jbe     spec                ; yes, go handle special case
  79. stoc:   stosb                       ; put character in buffer
  80.         dec     dx                  ; one less space in buffer
  81. endl:   loopnz  movc                ; go back for more characters
  82.         jnz     fill                ; no more characters => go fill buffer
  83.                                     ; cx = 0, buflen = length moved
  84. fin:    dec     cx
  85. fin1:   xor     ax,ax
  86.         stosb
  87.         mov     bufsrc,si           ; length moved = buflen - cx
  88.         xchg    buflen,cx
  89.         sub     cx,buflen
  90.         add     word ptr bufpos,cx
  91.         adc     word ptr bufpos+2,0
  92.         not     ax
  93.         jmp     short getldone
  94. fill:
  95.         mov     cx, buflen          ; add length moved to bufpos
  96.         add     word ptr bufpos,cx
  97.         adc     word ptr bufpos+2,0
  98. ifdef OS2
  99. push buffh
  100. push word ptr bufstart + 2
  101. push word ptr bufstart
  102. push buflength
  103. push ss
  104. lea ax, BytesRead
  105. push ax
  106. call DOSREAD
  107. mov cx, BytesRead
  108. mov buflen, cx
  109. mov si, word ptr bufstart
  110. or cx, cx
  111. jnz movc
  112. else
  113.         push    dx
  114.         mov     dx,word ptr bufstart
  115.         mov     cx,buflength
  116.         mov     bx,buffh
  117.         mov     ah,3Fh
  118.         int     21h
  119.         mov     cx,ax
  120.         mov     buflen,ax
  121.         mov     si,dx
  122.         pop     dx
  123.         or      ax,ax
  124.         jnz     movc
  125. endif
  126. ; if we've stored chars then terminate line else return with 0
  127.         cmp     di,dst
  128.         jnz     fin1
  129.         jmp     short getldone
  130. spec:   jz      setnz
  131.         cmp     al,10
  132.         jz      fin
  133.         cmp     al,9
  134.         jnz     stoc
  135.         push    cx
  136.         mov     ax,di
  137.         sub     ax,dst
  138.         and     ax,7
  139.         mov     cx,8
  140.         sub     cx,ax
  141.         cmp     cx,dx
  142.         jbe     ok
  143.         mov     cx,dx
  144. ok:     sub     dx,cx
  145.         mov     al," "
  146.         rep     stosb
  147.         pop     cx
  148.         jmp     endl
  149. setnz: or al,1
  150. mov fGetlCR,-1 ; indicate we've seen a CR
  151. jmp endl
  152. getldone:
  153. cEnd
  154. sEnd
  155. end