diff options
Diffstat (limited to 'v4.0/src/CMD/FC/GETL.ASM')
| -rw-r--r-- | v4.0/src/CMD/FC/GETL.ASM | 146 |
1 files changed, 146 insertions, 0 deletions
diff --git a/v4.0/src/CMD/FC/GETL.ASM b/v4.0/src/CMD/FC/GETL.ASM new file mode 100644 index 0000000..508eca9 --- /dev/null +++ b/v4.0/src/CMD/FC/GETL.ASM | |||
| @@ -0,0 +1,146 @@ | |||
| 1 | ; | ||
| 2 | ; blindingly fast assembly help for Z | ||
| 3 | ; | ||
| 4 | |||
| 5 | .xlist | ||
| 6 | include version.inc | ||
| 7 | include cmacros.inc | ||
| 8 | .list | ||
| 9 | |||
| 10 | sBegin data | ||
| 11 | assumes ds,data | ||
| 12 | |||
| 13 | bufstart dd ? | ||
| 14 | staticW bufsrc,? | ||
| 15 | staticW buflen,? | ||
| 16 | staticW buflength,? | ||
| 17 | staticW buffh,? | ||
| 18 | globalB fGetlCR,? | ||
| 19 | bufpos dd ? | ||
| 20 | |||
| 21 | sEnd | ||
| 22 | sBegin code | ||
| 23 | |||
| 24 | assumes cs,code | ||
| 25 | |||
| 26 | ; | ||
| 27 | ; getlpos returns current seek position in file | ||
| 28 | ; | ||
| 29 | cProc getlpos,<PUBLIC> | ||
| 30 | cBegin | ||
| 31 | mov dx,word ptr bufpos+2 | ||
| 32 | mov ax,word ptr bufpos | ||
| 33 | cEnd | ||
| 34 | |||
| 35 | ; | ||
| 36 | ; getlinit (buf, len, fh) initializes the getl routine for buffer buf and fh fh | ||
| 37 | ; | ||
| 38 | cProc getlinit,<PUBLIC> | ||
| 39 | parmD buf | ||
| 40 | parmW len | ||
| 41 | parmW fh | ||
| 42 | cBegin | ||
| 43 | mov ax,off_buf | ||
| 44 | mov word ptr bufstart,ax | ||
| 45 | mov ax,seg_buf | ||
| 46 | mov word ptr bufstart+2,ax | ||
| 47 | mov ax,fh | ||
| 48 | mov buffh,ax | ||
| 49 | mov ax,len | ||
| 50 | mov buflength,ax | ||
| 51 | mov buflen,0 | ||
| 52 | mov word ptr bufpos,0 | ||
| 53 | mov word ptr bufpos+2,0 | ||
| 54 | mov fGetlCR,0 | ||
| 55 | cEnd | ||
| 56 | |||
| 57 | ; | ||
| 58 | ; getl (dst, len) returns TRUE if a line was read. | ||
| 59 | ; | ||
| 60 | cProc getl,<PUBLIC>,<DS,SI,DI> | ||
| 61 | parmW dst | ||
| 62 | parmW dstlen | ||
| 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 | |||
| 77 | movc: lodsb ; get a byte | ||
| 78 | cmp al,13 ; is it special? | ||
| 79 | jbe spec ; yes, go handle special case | ||
| 80 | stoc: stosb ; put character in buffer | ||
| 81 | dec dx ; one less space in buffer | ||
| 82 | endl: loopnz movc ; go back for more characters | ||
| 83 | jnz fill ; no more characters => go fill buffer | ||
| 84 | ; cx = 0, buflen = length moved | ||
| 85 | fin: dec cx | ||
| 86 | fin1: xor ax,ax | ||
| 87 | stosb | ||
| 88 | mov bufsrc,si ; length moved = buflen - cx | ||
| 89 | xchg buflen,cx | ||
| 90 | sub cx,buflen | ||
| 91 | add word ptr bufpos,cx | ||
| 92 | adc word ptr bufpos+2,0 | ||
| 93 | not ax | ||
| 94 | jmp short getldone | ||
| 95 | |||
| 96 | fill: | ||
| 97 | mov cx, buflen ; add length moved to bufpos | ||
| 98 | add word ptr bufpos,cx | ||
| 99 | adc word ptr bufpos+2,0 | ||
| 100 | push dx | ||
| 101 | mov dx,word ptr bufstart | ||
| 102 | mov cx,buflength | ||
| 103 | mov bx,buffh | ||
| 104 | mov ah,3Fh | ||
| 105 | int 21h | ||
| 106 | mov cx,ax | ||
| 107 | mov buflen,ax | ||
| 108 | mov si,dx | ||
| 109 | pop dx | ||
| 110 | or ax,ax | ||
| 111 | jnz movc | ||
| 112 | ; if we've stored chars then terminate line else return with 0 | ||
| 113 | cmp di,dst | ||
| 114 | jnz fin1 | ||
| 115 | jmp short getldone | ||
| 116 | |||
| 117 | setnz: or al,1 | ||
| 118 | mov fGetlCR,-1 ; indicate we've seen a CR | ||
| 119 | jmp endl | ||
| 120 | |||
| 121 | spec: jz setnz | ||
| 122 | cmp al,10 | ||
| 123 | jz fin | ||
| 124 | cmp al,9 | ||
| 125 | jnz stoc | ||
| 126 | push cx | ||
| 127 | mov ax,di | ||
| 128 | sub ax,dst | ||
| 129 | and ax,7 | ||
| 130 | mov cx,8 | ||
| 131 | sub cx,ax | ||
| 132 | cmp cx,dx | ||
| 133 | jbe ok | ||
| 134 | mov cx,dx | ||
| 135 | ok: sub dx,cx | ||
| 136 | mov al," " | ||
| 137 | rep stosb | ||
| 138 | pop cx | ||
| 139 | jmp endl | ||
| 140 | |||
| 141 | getldone: | ||
| 142 | cEnd | ||
| 143 | |||
| 144 | sEnd | ||
| 145 | |||
| 146 | end | ||