-
Notifications
You must be signed in to change notification settings - Fork 2
/
OBJECTS.PAS
3207 lines (2897 loc) · 75.4 KB
/
OBJECTS.PAS
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{/////////////////////////////////////////////////////////////////////////
//
// Dos Navigator Version 1.51 Copyright (C) 1991-99 RIT Research Labs
//
// This programs is free for commercial and non-commercial use as long as
// the following conditions are aheared to.
//
// Copyright remains RIT Research Labs, and as such any Copyright notices
// in the code are not to be removed. If this package is used in a
// product, RIT Research Labs should be given attribution as the RIT Research
// Labs of the parts of the library used. This can be in the form of a textual
// message at program startup or in documentation (online or textual)
// provided with the package.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// 3. All advertising materials mentioning features or use of this software
// must display the following acknowledgement:
// "Based on Dos Navigator by RIT Research Labs."
//
// THIS SOFTWARE IS PROVIDED BY RIT RESEARCH LABS "AS IS" AND ANY EXPRESS
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// The licence and distribution terms for any publically available
// version or derivative of this code cannot be changed. i.e. this code
// cannot simply be copied and put under another distribution licence
// (including the GNU Public Licence).
//
//////////////////////////////////////////////////////////////////////////}
unit Objects;
{-----------------------------------------------------}
{ This module is based on Turbo Vision Objects Unit }
{ Copyright (c) 1990 by Borland International }
{-----------------------------------------------------}
interface uses ObjType;
const
{ TStream access modes }
stCreate = $3C40; { Create new file }
stOpenRead = $3D40; { Read access only }
stOpenWrite = $3D41; { Write access only }
stOpen = $3D42; { Read and write access }
{ TStream error codes }
stOk = 0; { No error }
stError = -1; { Access error }
stInitError = -2; { Cannot initialize stream }
stReadError = -3; { Read beyond end of stream }
stWriteError = -4; { Cannot expand stream }
stGetError = -5; { Get of unregistered object type }
stPutError = -6; { Put of unregistered object type }
{ Maximum TCollection size }
MaxCollectionSize = 65520 div SizeOf(Pointer);
{ TCollection error codes }
coIndexError = -1; { Index out of range }
coOverflow = -2; { Overflow }
{ VMT header size }
vmtHeaderSize = 8;
type
{ Type conversion records }
WordRec = record
Lo, Hi: Byte;
end;
LongRec = record
Lo, Hi: Word;
end;
PtrRec = record
Ofs, Seg: Word;
end;
{ String pointers }
PString = ^String;
{ Character set type }
PCharSet = ^TCharSet;
TCharSet = set of Char;
{ General arrays }
PByteArray = ^TByteArray;
TByteArray = array[0..32767] of Byte;
PWordArray = ^TWordArray;
TWordArray = array[0..16383] of Word;
{ TObject base object }
PObject = ^TObject;
TObject = object
constructor Init;
procedure Free;
destructor Done; virtual;
end;
{ TStreamRec }
PStreamRec = ^TStreamRec;
TStreamRec = record
ObjType: Word;
VmtLink: Word;
Load: Pointer;
Store: Pointer;
Next: Word;
end;
{ TStream }
PStream = ^TStream;
TStream = object(TObject)
Status: Integer;
ErrorInfo: Integer;
constructor Init;
procedure CopyFrom(var S: TStream; Count: Longint);
procedure Error(Code, Info: Integer); virtual;
procedure Flush; virtual;
function Get: PObject;
function GetPos: Longint; virtual;
function GetSize: Longint; virtual;
procedure Put(P: PObject);
procedure Read(var Buf; Count: Word); virtual;
function ReadStr: PString;
procedure Reset;
procedure Seek(Pos: Longint); virtual;
function StrRead: PChar;
procedure StrWrite(P: PChar);
procedure Truncate; virtual;
procedure Write(var Buf; Count: Word); virtual;
procedure WriteStr(P: PString);
end;
{ DOS file name string }
{$IFDEF Windows}
FNameStr = PChar;
{$ELSE}
FNameStr = string[79];
{$ENDIF}
{ TDosStream }
PDosStream = ^TDosStream;
TDosStream = object(TStream)
Handle: Word;
constructor Init(FileName: FNameStr; Mode: Word);
destructor Done; virtual;
function GetPos: Longint; virtual;
function GetSize: Longint; virtual;
procedure Read(var Buf; Count: Word); virtual;
procedure Seek(Pos: Longint); virtual;
procedure Truncate; virtual;
procedure Write(var Buf; Count: Word); virtual;
end;
{ TBufStream }
PBufStream = ^TBufStream;
TBufStream = object(TDosStream)
Buffer: Pointer;
BufSize: Word;
BufPtr: Word;
BufEnd: Word;
constructor Init(FileName: FNameStr; Mode, Size: Word);
destructor Done; virtual;
procedure Flush; virtual;
function GetPos: Longint; virtual;
function GetSize: Longint; virtual;
procedure Read(var Buf; Count: Word); virtual;
procedure Seek(Pos: Longint); virtual;
procedure Truncate; virtual;
procedure Write(var Buf; Count: Word); virtual;
end;
{ TEmsStream }
PEmsStream = ^TEmsStream;
TEmsStream = object(TStream)
Handle: Word;
PageCount: Word;
Size: Longint;
Position: Longint;
constructor Init(MinSize, MaxSize: Longint);
destructor Done; virtual;
function GetPos: Longint; virtual;
function GetSize: Longint; virtual;
procedure Read(var Buf; Count: Word); virtual;
procedure Seek(Pos: Longint); virtual;
procedure Truncate; virtual;
procedure Write(var Buf; Count: Word); virtual;
end;
{ TMemoryStream }
PMemoryStream = ^TMemoryStream;
TMemoryStream = object(TStream)
SegCount: Integer;
SegList: PWordArray;
CurSeg: Integer;
BlockSize: Integer;
Size: Longint;
Position: Longint;
constructor Init(ALimit: Longint; ABlockSize: Word);
destructor Done; virtual;
function GetPos: Longint; virtual;
function GetSize: Longint; virtual;
procedure Read(var Buf; Count: Word); virtual;
procedure Seek(Pos: Longint); virtual;
procedure Truncate; virtual;
procedure Write(var Buf; Count: Word); virtual;
private
function ChangeListSize(ALimit: Word): Boolean;
end;
{ TCollection types }
PItemList = ^TItemList;
TItemList = array[0..MaxCollectionSize - 1] of Pointer;
{ TCollection object }
PCollection = ^TCollection;
TCollection = object(TObject)
Items: PItemList;
Count: Integer;
Limit: Integer;
Delta: Integer;
constructor Init(ALimit, ADelta: Integer);
constructor Load(var S: TStream);
destructor Done; virtual;
function At(Index: Integer): Pointer;
procedure AtDelete(Index: Integer);
procedure AtFree(Index: Integer);
procedure AtInsert(Index: Integer; Item: Pointer);
procedure AtPut(Index: Integer; Item: Pointer);
procedure AtReplace(Index: Integer; Item: Pointer);
procedure Delete(Item: Pointer);
procedure DeleteAll;
procedure Error(Code, Info: Integer); virtual;
function FirstThat(Test: Pointer): Pointer;
procedure ForEach(Action: Pointer);
procedure Free(Item: Pointer);
procedure FreeAll;
procedure FreeItem(Item: Pointer); virtual;
function GetItem(var S: TStream): Pointer; virtual;
function IndexOf(Item: Pointer): Integer; virtual;
procedure Insert(Item: Pointer); virtual;
function LastThat(Test: Pointer): Pointer;
procedure Pack;
procedure PutItem(var S: TStream; Item: Pointer); virtual;
procedure SetLimit(ALimit: Integer); virtual;
procedure Store(var S: TStream);
end;
{ TSortedCollection object }
PSortedCollection = ^TSortedCollection;
TSortedCollection = object(TCollection)
Duplicates: Boolean;
constructor Init(ALimit, ADelta: Integer);
constructor Load(var S: TStream);
function Compare(Key1, Key2: Pointer): Integer; virtual;
function IndexOf(Item: Pointer): Integer; virtual;
procedure Insert(Item: Pointer); virtual;
function KeyOf(Item: Pointer): Pointer; virtual;
function Search(Key: Pointer; var Index: Integer): Boolean; virtual;
procedure Store(var S: TStream);
procedure QSort;
procedure QuickSort(L, R: Integer);
end;
{ TLineCollection }
PLineCollection = ^TLineCollection;
TLineCollection = object(TCollection)
procedure FreeItem(P: Pointer); virtual;
procedure PutItem(var S: TStream; Item: Pointer); virtual;
function GetItem(var S: TStream): Pointer; virtual;
end;
{ TStringCollection object }
PStringCollection = ^TStringCollection;
TStringCollection = object(TSortedCollection)
function Compare(Key1, Key2: Pointer): Integer; virtual;
procedure FreeItem(Item: Pointer); virtual;
function GetItem(var S: TStream): Pointer; virtual;
procedure PutItem(var S: TStream; Item: Pointer); virtual;
end;
{ TStrCollection object }
PStrCollection = ^TStrCollection;
TStrCollection = object(TSortedCollection)
function Compare(Key1, Key2: Pointer): Integer; virtual;
procedure FreeItem(Item: Pointer); virtual;
function GetItem(var S: TStream): Pointer; virtual;
procedure PutItem(var S: TStream; Item: Pointer); virtual;
end;
{$IFNDEF Windows}
{ TResourceCollection object }
PResourceCollection = ^TResourceCollection;
TResourceCollection = object(TStringCollection)
procedure FreeItem(Item: Pointer); virtual;
function GetItem(var S: TStream): Pointer; virtual;
function KeyOf(Item: Pointer): Pointer; virtual;
procedure PutItem(var S: TStream; Item: Pointer); virtual;
end;
{ TResourceFile object }
PResourceFile = ^TResourceFile;
TResourceFile = object(TObject)
Stream: PStream;
Modified: Boolean;
constructor Init(AStream: PStream);
destructor Done; virtual;
function Count: Integer;
procedure Delete(Key: String);
procedure Flush;
function Get(Key: String): PObject;
function KeyAt(I: Integer): String;
procedure Put(Item: PObject; Key: String);
function SwitchTo(AStream: PStream; Pack: Boolean): PStream;
private
BasePos: Longint;
IndexPos: Longint;
Index: TResourceCollection;
end;
{ TStringList object }
TStrIndexRec = record
Key, Count, Offset: Word;
end;
PStrIndex = ^TStrIndex;
TStrIndex = array[0..9999] of TStrIndexRec;
PStringList = ^TStringList;
TStringList = object(TObject)
constructor Load(var S: TStream);
destructor Done; virtual;
function Get(Key: Word): String;
private
Stream: PStream;
BasePos: Longint;
IndexSize: Integer;
Index: PStrIndex;
procedure ReadStr(var S: String; Offset, Skip: Word);
end;
{ TStrListMaker object }
PStrListMaker = ^TStrListMaker;
TStrListMaker = object(TObject)
constructor Init(AStrSize, AIndexSize: Word);
destructor Done; virtual;
procedure Put(Key: Word; S: String);
procedure Store(var S: TStream);
private
StrPos: Word;
StrSize: Word;
Strings: PByteArray;
IndexPos: Word;
IndexSize: Word;
Index: PStrIndex;
Cur: TStrIndexRec;
procedure CloseCurrent;
end;
{ TPoint object }
PPoint = ^TPoint;
TPoint = object
X, Y: Integer;
end;
{ Rectangle object }
TRect = object
A, B: TPoint;
procedure Assign(XA, YA, XB, YB: Integer);
procedure Copy(R: TRect);
procedure Move(ADX, ADY: Integer);
procedure Grow(ADX, ADY: Integer);
procedure Intersect(R: TRect);
procedure Union(R: TRect);
function Contains(P: TPoint): Boolean;
function Equals(R: TRect): Boolean;
function Empty: Boolean;
end;
{$ENDIF}
procedure FreeObject(var O);
function CnvString(P: PString): String;
procedure ReplaceP(var P: PString; S: String);
{ Dynamic string handling routines }
function NewStr(const S: String): PString;
procedure DisposeStr(P: PString);
{ Longint routines }
function LongMul(X, Y: Integer): Longint;
inline($5A/$58/$F7/$EA);
function LongDiv(X: Longint; Y: Integer): Integer;
inline($59/$58/$5A/$F7/$F9);
{ Stream routines }
procedure RegisterType( var S: TStreamRec );
procedure ReRegisterType( var S: TStreamRec );
{ Abstract notification procedure }
procedure Abstract;
{ Objects registration procedure }
const
{ Stream error procedure }
StreamError: Pointer = nil;
{ EMS stream state variables }
EmsCurHandle: Word = $FFFF;
EmsCurPage: Word = $FFFF;
{ Stream registration records }
const
RCollection: TStreamRec = (
ObjType: otCollection;
VmtLink: Ofs(TypeOf(TCollection)^);
Load: @TCollection.Load;
Store: @TCollection.Store);
const
RStringCollection: TStreamRec = (
ObjType: otStringCollection;
VmtLink: Ofs(TypeOf(TStringCollection)^);
Load: @TStringCollection.Load;
Store: @TStringCollection.Store);
const
RStrCollection: TStreamRec = (
ObjType: otStrCollection;
VmtLink: Ofs(TypeOf(TStrCollection)^);
Load: @TStrCollection.Load;
Store: @TStrCollection.Store);
{$IFNDEF Windows }
const
RStringList: TStreamRec = (
ObjType: otStringList;
VmtLink: Ofs(TypeOf(TStringList)^);
Load: @TStringList.Load;
Store: nil);
const
RStrListMaker: TStreamRec = (
ObjType: otStrListMaker;
VmtLink: Ofs(TypeOf(TStrListMaker)^);
Load: nil;
Store: @TStrListMaker.Store);
{$ENDIF}
implementation
{$IFDEF Windows}
uses WinProcs, Strings, OMemory;
{$ELSE}
uses Memory, Strings;
{$ENDIF}
{$IFDEF Windows}
{$DEFINE NewExeFormat}
{$ENDIF}
{$IFDEF DPMI}
{$DEFINE NewExeFormat}
{$ENDIF}
procedure Abstract;
begin
{RunError(211);}
end;
{ TObject }
function CnvString(P: PString): String;
begin
if P = nil then CnvString := '' else CnvString := P^;
end;
constructor TObject.Init;
type
Image = record
Link: Word;
Data: record end;
end;
begin
{$IFNDEF Windows}
FillChar(Image(Self).Data, SizeOf(Self) - SizeOf(TObject), 0);
{$ENDIF}
end;
{ Shorthand procedure for a done/dispose }
procedure TObject.Free;
begin
Dispose(PObject(@Self), Done);
end;
destructor TObject.Done;
begin
end;
{ TStream type registration routines }
const
StreamTypes: Word = 0;
procedure RegisterError;
begin
RunError(212);
end;
PROCEDURE RegisterType; assembler;
asm
MOV AX,DS
CMP AX,S.Word[2]
JNE @@1
MOV SI,S.Word[0]
MOV AX,[SI].TStreamRec.ObjType
OR AX,AX
JE @@1
MOV DI,StreamTypes
JMP @@3
@@1: JMP RegisterError
@@2: CMP AX,[DI].TStreamRec.ObjType
JE @@4
MOV DI,[DI].TStreamRec.Next
@@3: OR DI,DI
JNE @@2
MOV DI,StreamTypes
MOV [SI].TStreamRec.Next,DI
MOV StreamTypes,SI
@@4:
end;
PROCEDURE ReRegisterType; assembler;
asm
MOV AX,DS
CMP AX,S.Word[2]
JNE @Error
MOV SI,S.Word[0]
MOV DI,StreamTypes
MOV [SI].TStreamRec.Next,DI
MOV StreamTypes,SI
MOV AX,[SI].TStreamRec.ObjType
{ This moment:
SI: StreamTypes
DI: StreamTypes^.Next
AX: Current ObjType
GOAL: To find the same ObjType and
to remove it from list.
}
@Loop:
OR DI,DI
JE @End
CMP AX,[DI].TStreamRec.ObjType
JE @Found
MOV SI,DI
MOV DI,[DI].TStreamRec.Next
JMP @Loop
@Error: JMP RegisterError
@Found: MOV AX,[DI].TStreamRec.Next
MOV [SI].TStreamRec.Next,AX
XOR AX,AX
MOV [DI].TStreamRec.Next,AX
@End:
end;
{
PROCEDURE ReRegisterType; assembler;
asm
MOV AX,DS
CMP AX,S.Word[2]
JNE @@1
MOV SI,S.Word[0]
MOV AX,[SI].TStreamRec.ObjType
OR AX,AX
JE @@1
MOV DI,StreamTypes
JMP @@3
@@1: JMP RegisterError
@@2: MOV DI,[DI].TStreamRec.Next
@@3: OR DI,DI
JNE @@2
MOV DI,StreamTypes
MOV [SI].TStreamRec.Next,DI
MOV StreamTypes,SI
@@4:
end;
}
{ TStream support routines }
const
TStream_Error = vmtHeaderSize + $04;
TStream_Flush = vmtHeaderSize + $08;
TStream_Read = vmtHeaderSize + $14;
TStream_Write = vmtHeaderSize + $20;
{ Stream error handler }
{ In AX = Error info }
{ DX = Error code }
{ ES:DI = Stream object pointer }
{ Uses AX,BX,CX,DX,SI }
procedure DoStreamError; near; assembler;
asm
PUSH ES
PUSH DI
PUSH DX
PUSH AX
PUSH ES
PUSH DI
MOV DI,ES:[DI]
CALL DWORD PTR [DI].TStream_Error
POP DI
POP ES
end;
{ TStream }
constructor TStream.Init;
begin
TObject.Init;
Status := 0;
ErrorInfo := 0;
end;
procedure TStream.CopyFrom(var S: TStream; Count: Longint);
var
N: Word;
Buffer: PByteArray;
BufSize: Word;
begin
BufSize := 16384;
if BufSize > Count then BufSize := Count;
if BufSize > MaxAvail then BufSize := MaxAvail;
GetMem(Buffer, BufSize);
if Buffer = nil then Exit;
while Count > 0 do
begin
if Count > BufSize then N := BufSize else N := Count;
S.Read(Buffer^, N);
Write(Buffer^, N);
Dec(Count, N);
end;
FreeMem(Buffer, BufSize);
end;
procedure TStream.Error(Code, Info: Integer);
type
TErrorProc = procedure(var S: TStream);
begin
Status := Code;
ErrorInfo := Info;
if StreamError <> nil then TErrorProc(StreamError)(Self);
end;
procedure TStream.Flush;
begin
end;
function TStream.Get: PObject; assembler;
asm
PUSH AX
MOV AX,SP
PUSH SS
PUSH AX
MOV AX,2
PUSH AX
LES DI,Self
PUSH ES
PUSH DI
MOV DI,ES:[DI]
CALL DWORD PTR [DI].TStream_Read
POP AX
OR AX,AX
JE @@3
MOV BX,StreamTypes
JMP @@2
@@1: CMP AX,[BX].TStreamRec.ObjType
JE @@4
MOV BX,[BX].TStreamRec.Next
@@2: OR BX,BX
JNE @@1
LES DI,Self
MOV DX,stGetError
CALL DoStreamError
@@3: XOR AX,AX
MOV DX,AX
JMP @@5
@@4: LES DI,Self
PUSH ES
PUSH DI
PUSH [BX].TStreamRec.VmtLink
XOR AX,AX
PUSH AX
PUSH AX
CALL [BX].TStreamRec.Load
@@5:
end;
function TStream.GetPos: Longint;
begin
Abstract;
end;
function TStream.GetSize: Longint;
begin
Abstract;
end;
procedure TStream.Put(P: PObject); assembler;
asm
LES DI,P
MOV CX,ES
OR CX,DI
JE @@4
MOV AX,ES:[DI]
MOV BX,StreamTypes
JMP @@2
@@1: CMP AX,[BX].TStreamRec.VmtLink
JE @@3
MOV BX,[BX].TStreamRec.Next
@@2: OR BX,BX
JNE @@1
LES DI,Self
MOV DX,stPutError
CALL DoStreamError
JMP @@5
@@3: MOV CX,[BX].TStreamRec.ObjType
@@4: PUSH BX
PUSH CX
MOV AX,SP
PUSH SS
PUSH AX
MOV AX,2
PUSH AX
LES DI,Self
PUSH ES
PUSH DI
MOV DI,ES:[DI]
CALL DWORD PTR [DI].TStream_Write
POP CX
POP BX
JCXZ @@5
LES DI,Self
PUSH ES
PUSH DI
PUSH P.Word[2]
PUSH P.Word[0]
CALL [BX].TStreamRec.Store
@@5:
end;
procedure TStream.Read(var Buf; Count: Word);
begin
Abstract;
end;
function TStream.ReadStr: PString;
var
L: Byte;
P: PString;
begin
Read(L, 1);
if L > 0 then
begin
GetMem(P, L + 1);
P^[0] := Char(L);
Read(P^[1], L);
ReadStr := P;
end else ReadStr := nil;
end;
procedure TStream.Reset;
begin
Status := 0;
ErrorInfo := 0;
end;
procedure TStream.Seek(Pos: Longint);
begin
Abstract;
end;
function TStream.StrRead: PChar;
var
L: Word;
P: PChar;
begin
Read(L, SizeOf(Word));
if L = 0 then StrRead := nil else
begin
GetMem(P, L + 1);
Read(P[0], L);
P[L] := #0;
StrRead := P;
end;
end;
procedure TStream.StrWrite(P: PChar);
var
L: Word;
begin
if P = nil then L := 0 else L := StrLen(P);
Write(L, SizeOf(Word));
if P <> nil then Write(P[0], L);
end;
procedure TStream.Truncate;
begin
Abstract;
end;
procedure TStream.Write(var Buf; Count: Word);
begin
Abstract;
end;
procedure TStream.WriteStr(P: PString);
const
Empty: String[1] = '';
begin
if P <> nil then Write(P^, Length(P^) + 1) else Write(Empty, 1);
end;
{ TDosStream }
constructor TDosStream.Init(FileName: FNameStr; Mode: Word); assembler;
var
NameBuf: array[0..79] of Char;
asm
XOR AX,AX
PUSH AX
LES DI,Self
PUSH ES
PUSH DI
CALL TStream.Init
{$IFDEF Windows}
LEA DI,NameBuf
PUSH SS
PUSH DI
LES DI,FileName
PUSH ES
PUSH DI
MOV AX,79
PUSH AX
CALL StrLCopy
PUSH DX
PUSH AX
PUSH DX
PUSH AX
CALL AnsiToOem
PUSH DS
LEA DX,NameBuf
{$ELSE}
PUSH DS
LDS SI,FileName
LEA DI,NameBuf
MOV DX,DI
PUSH SS
POP ES
CLD
LODSB
CMP AL,79
JB @@1
MOV AL,79
@@1: CBW
XCHG AX,CX
REP MOVSB
XCHG AX,CX
STOSB
{$ENDIF}
PUSH SS
POP DS
XOR CX,CX
MOV AX,Mode
INT 21H
POP DS
JNC @@2
LES DI,Self
MOV DX,stInitError
CALL DoStreamError
MOV AX,-1
@@2: LES DI,Self
MOV ES:[DI].TDosStream.Handle,AX
end;
destructor TDosStream.Done; assembler;
asm
LES DI,Self
MOV BX,ES:[DI].TDosStream.Handle
CMP BX,-1
JE @@1
MOV AH,3EH
INT 21H
@@1: XOR AX,AX
PUSH AX
PUSH ES
PUSH DI
CALL TStream.Done
end;
function TDosStream.GetPos: Longint; assembler;
asm
LES DI,Self
XOR DX,DX
CMP DX,ES:[DI].TDosStream.Status
JNE @@1
MOV CX,DX
MOV BX,ES:[DI].TDosStream.Handle
MOV AX,4201H
INT 21H
JNC @@2
MOV DX,stError
CALL DoStreamError
@@1: MOV AX,-1
CWD
@@2:
end;
function TDosStream.GetSize: Longint; assembler;
asm
LES DI,Self
XOR DX,DX
CMP DX,ES:[DI].TDosStream.Status
JNE @@1
MOV CX,DX
MOV BX,ES:[DI].TDosStream.Handle
MOV AX,4201H
INT 21H
PUSH DX
PUSH AX
XOR DX,DX
MOV CX,DX
MOV AX,4202H