-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathBUFSTM.ASM
218 lines (187 loc) · 4.91 KB
/
BUFSTM.ASM
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
; Turbo Pascal 5.5 object-oriented example
; Assembler code for OBJECTS.PAS unit
; Copyright (c) 1989 by Borland International, Inc.
TITLE BUFSTM
INCLUDE OBJECTS.INC
CODE SEGMENT BYTE PUBLIC
EXTRN StreamError:NEAR
EXTRN DosStream@GetPos:NEAR
ASSUME CS:CODE
PUBLIC BufStream@Flush
BufStream@Flush PROC FAR
@Self EQU (DWORD PTR [BP+6])
PUSH BP
MOV BP,SP
LES DI,@Self
CMP ES:[DI].Stream@Status,0
JNE @@1
MOV AL,2
CALL FlushBuffer
@@1: POP BP
RET 4
BufStream@Flush ENDP
PUBLIC BufStream@GetPos
BufStream@GetPos PROC FAR
@Self EQU (DWORD PTR [BP+6])
PUSH BP
MOV BP,SP
LES DI,@Self
PUSH ES
PUSH DI
PUSH CS
CALL DosStream@GetPos
OR DX,DX
JS @@1
LES DI,@Self
SUB AX,ES:[DI].BufStream@BufEnd
SBB DX,0
ADD AX,ES:[DI].BufStream@BufPtr
ADC DX,0
@@1: POP BP
RET 4
BufStream@GetPos ENDP
PUBLIC BufStream@Read
BufStream@Read PROC FAR
@Buf EQU (DWORD PTR [BP+12])
@Count EQU (WORD PTR [BP+10])
@Self EQU (DWORD PTR [BP+6])
PUSH BP
MOV BP,SP
LES DI,@Self
CMP ES:[DI].Stream@Status,0
JNE @@6
MOV AL,1
CALL FlushBuffer
JNE @@6
XOR DX,DX
@@1: MOV CX,@Count
SUB CX,DX
JE @@7
LES DI,@Self
MOV AX,ES:[DI].BufStream@BufEnd
SUB AX,ES:[DI].BufStream@BufPtr
JA @@2
PUSH CX
PUSH DX
PUSH DS
LDS DX,ES:[DI].BufStream@Buffer
MOV CX,ES:[DI].BufStream@BufSize
MOV BX,ES:[DI].DosStream@Handle
MOV AH,3FH
INT 21H
POP DS
POP DX
POP CX
JC @@5
MOV ES:[DI].BufStream@BufPtr,0
MOV ES:[DI].BufStream@BufEnd,AX
OR AX,AX
JE @@4
@@2: CMP CX,AX
JB @@3
MOV CX,AX
@@3: PUSH DS
LDS SI,ES:[DI].BufStream@Buffer
ADD SI,ES:[DI].BufStream@BufPtr
ADD ES:[DI].BufStream@BufPtr,CX
LES DI,@Buf
ADD DI,DX
ADD DX,CX
CLD
REP MOVSB
POP DS
JMP @@1
@@4: MOV AX,101
@@5: CALL StreamError
@@6: LES DI,@Buf
MOV CX,@Count
XOR AL,AL
CLD
REP STOSB
@@7: POP BP
RET 10
BufStream@Read ENDP
PUBLIC BufStream@Write
BufStream@Write PROC FAR
@Buf EQU (DWORD PTR [BP+12])
@Count EQU (WORD PTR [BP+10])
@Self EQU (DWORD PTR [BP+6])
PUSH BP
MOV BP,SP
LES DI,@Self
CMP ES:[DI].Stream@Status,0
JNE @@4
MOV AL,0
CALL FlushBuffer
JNE @@4
XOR DX,DX
@@1: MOV CX,@Count
SUB CX,DX
JE @@4
LES DI,@Self
MOV AX,ES:[DI].BufStream@BufSize
SUB AX,ES:[DI].BufStream@BufPtr
JA @@2
PUSH CX
PUSH DX
MOV AL,1
CALL FlushBuffer
POP DX
POP CX
JNE @@4
MOV AX,ES:[DI].BufStream@BufSize
@@2: CMP CX,AX
JB @@3
MOV CX,AX
@@3: PUSH DS
MOV AX,ES:[DI].BufStream@BufPtr
ADD ES:[DI].BufStream@BufPtr,CX
LES DI,ES:[DI].BufStream@Buffer
ADD DI,AX
LDS SI,@Buf
ADD SI,DX
ADD DX,CX
CLD
REP MOVSB
POP DS
JMP @@1
@@4: POP BP
RET 10
BufStream@Write ENDP
; Flush stream buffer
; In AL = Flush mode (0=Read,1=Write,2=Both)
; ES:DI = BufStream pointer
; Out ZF = Status test
FlushBuffer PROC NEAR
MOV CX,ES:[DI].BufStream@BufPtr
SUB CX,ES:[DI].BufStream@BufEnd
JE @@4
MOV BX,ES:[DI].DosStream@Handle
JA @@1
CMP AL,1
JE @@4
MOV DX,CX
MOV CX,-1
MOV AX,4201H
INT 21H
JMP SHORT @@3
@@1: CMP AL,0
JE @@4
PUSH DS
LDS DX,ES:[DI].BufStream@Buffer
MOV AH,40H
INT 21H
POP DS
JC @@2
CMP AX,CX
JE @@3
MOV AX,101
@@2: CALL StreamError
@@3: XOR AX,AX
MOV ES:[DI].BufStream@BufPtr,AX
MOV ES:[DI].BufStream@BufEnd,AX
CMP AX,ES:[DI].Stream@Status
@@4: RET
FlushBuffer ENDP
CODE ENDS
END