summaryrefslogtreecommitdiff
path: root/v4.0/src/CMD/FC/GETL.ASM
diff options
context:
space:
mode:
Diffstat (limited to 'v4.0/src/CMD/FC/GETL.ASM')
-rw-r--r--v4.0/src/CMD/FC/GETL.ASM146
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
6include version.inc
7include cmacros.inc
8.list
9
10sBegin data
11assumes ds,data
12
13bufstart dd ?
14staticW bufsrc,?
15staticW buflen,?
16staticW buflength,?
17staticW buffh,?
18globalB fGetlCR,?
19bufpos dd ?
20
21sEnd
22sBegin code
23
24assumes cs,code
25
26;
27; getlpos returns current seek position in file
28;
29cProc getlpos,<PUBLIC>
30cBegin
31 mov dx,word ptr bufpos+2
32 mov ax,word ptr bufpos
33cEnd
34
35;
36; getlinit (buf, len, fh) initializes the getl routine for buffer buf and fh fh
37;
38cProc getlinit,<PUBLIC>
39parmD buf
40parmW len
41parmW fh
42cBegin
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
55cEnd
56
57;
58; getl (dst, len) returns TRUE if a line was read.
59;
60cProc getl,<PUBLIC>,<DS,SI,DI>
61parmW dst
62parmW dstlen
63cBegin
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
77movc: lodsb ; get a byte
78 cmp al,13 ; is it special?
79 jbe spec ; yes, go handle special case
80stoc: stosb ; put character in buffer
81 dec dx ; one less space in buffer
82endl: loopnz movc ; go back for more characters
83 jnz fill ; no more characters => go fill buffer
84 ; cx = 0, buflen = length moved
85fin: dec cx
86fin1: 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
96fill:
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
117setnz: or al,1
118 mov fGetlCR,-1 ; indicate we've seen a CR
119 jmp endl
120
121spec: 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
135ok: sub dx,cx
136 mov al," "
137 rep stosb
138 pop cx
139 jmp endl
140
141getldone:
142cEnd
143
144sEnd
145
146end