| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500 |
- {=========================================================================}
- procedure _SwapSmall(var a, b: SmallInt);
- {$IFDEF USEDLL}export;{$ELSE}Far;{$ENDIF}
- var
- Temp: SmallInt;
- begin
- Temp := a;
- a := b;
- b := Temp;
- end;
- {=========================================================================}
- procedure _SwapInt(var a, b: integer);
- {$IFDEF USEDLL}export;{$ELSE}Far;{$ENDIF}
- var
- Temp: integer;
- begin
- Temp := a;
- a := b;
- b := Temp;
- end;
- {=========================================================================}
- procedure _SwapLong(var a, b: Longint);
- {$IFDEF USEDLL}export;{$ELSE}Far;{$ENDIF}
- var
- Temp: Longint;
- begin
- Temp := a;
- a := b;
- b := Temp;
- end;
- {=========================================================================}
- function _Min(a, b: Longint): Longint;
- {$IFDEF USEDLL}export;{$ELSE}Far;{$ENDIF}
- begin
- if a > b then Result := b
- else Result := a;
- end;
- {=========================================================================}
- function _Max(a, b: Longint): Longint;
- {$IFDEF USEDLL}export;{$ELSE}Far;{$ENDIF}
- begin
- if a > b then Result := a
- else Result := b;
- end;
- {=========================================================================}
- function _MinMax(X, Min, Max: Longint): Longint;
- {$IFDEF USEDLL}export;{$ELSE}Far;{$ENDIF}
- begin
- if (X < Min) then X := Min
- else if (X > Max) then X := Max;
- Result := X;
- end;
- {=========================================================================}
- function _Limit(X, Min, Max: Longint): Longint;
- {$IFDEF USEDLL}export;{$ELSE}Far;{$ENDIF}
- begin
- if (Max >= Min) then
- begin
- if (X < Min) then X := Min
- else if (X > Max) then X := Max;
- end
- else
- begin
- if (X < Max) then X := Max
- else if (X > Min) then X := Min;
- end;
- Result := X;
- end;
- {=========================================================================}
- function _InMinMax(X,Min,Max: Longint): Boolean;
- {$IFDEF USEDLL}export;{$ELSE}Far;{$ENDIF}
- begin
- { if Min > Max then Result is never true }
- if (X < Min) then Result := False
- else if (X > Max) then Result := False
- else Result := True;
- end;
- {=========================================================================}
- function _InRange(X, Min, Max: Longint): Boolean;
- {$IFDEF USEDLL}export;{$ELSE}Far;{$ENDIF}
- begin
- if (Max >= Min) then
- begin
- if (X < Min) then Result := False
- else if (X > Max) then Result := False
- else Result := True;
- end
- else
- begin
- if (X < Max) then Result := False
- else if (X > Min) then Result := False
- else Result := True;
- end;
- end;
- {=========================================================================}
- procedure _incHuge(var Pointer; nBytes: Longint);
- {$IFDEF USEDLL}export;{$ELSE}Far;{$ENDIF}assembler;
- asm
- {$IFDEF WIN32}
- add [eax], edx
- {$ELSE}
- mov ax, nBytes.Word[0]
- mov dx, nBytes.Word[2]
- xor bx, bx
- les di, Pointer
- add es:[di].Word[0], ax
- adc bx, dx
- shl bx, 3 { inc Selector by SelectorInc = 8 }
- add es:[di].Word[2], bx
- {$ENDIF}
- end;
- {=========================================================================}
- procedure _GlobalFillMem(var X; Cnt: Longint; Value: Byte);
- {$IFDEF USEDLL}export;{$ELSE}Far;{$ENDIF}assembler;
- asm
- {$IFDEF WIN32}
- { ->EAX Pointer to destination }
- { EDX count }
- { CL value }
- test eax, eax
- jz @@error
- test edx, edx
- jz @@error
- push edi
- mov edi, eax { Point EDI to destination }
- mov ch, cl { Fill EAX with value repeated 4 times }
- mov eax, ecx
- shl eax, 16
- mov ax, cx
- mov ecx, edx
- sar ecx, 2
- js @@exit
- cld
- rep stosd { Fill count DIV 4 dwords }
- mov ecx, edx
- and ecx, 3
- rep stosb { Fill count MOD 4 bytes }
- @@exit:
- pop edi
- @@error:
- {$ELSE}
- db 66h
- xor di, di
- les di, X { Point ES:[EDI] to destination }
- mov cl, Value
- mov ch, cl { Fill EAX with value repeated 4 times }
- mov ax, cx
- db 66h
- shl ax, 16
- mov ax, cx
- db 66h
- mov cx, word ptr Cnt
- db 66h
- sar cx, 2
- js @@exit
- db 66h
- rep
- db 67h
- stosw { Fill count DIV 4 dwords }
- db 66h
- mov cx, word ptr Cnt
- db 66h
- db 83h
- db 0E1h
- db 03h { and ecx, 3 }
- rep
- db 67h
- stosb { Fill count MOD 4 bytes }
- @@exit:
- {$ENDIF}
- end;
- {=========================================================================}
- procedure _GlobalFillLong(var X; Cnt: Longint; Value: Longint);
- {$IFDEF USEDLL}export;{$ELSE}Far;{$ENDIF}assembler;
- asm
- {$IFDEF WIN32}
- { ->EAX Pointer to destination }
- { EDX count }
- { CL value }
- push edi
- mov edi, eax { Point EDI to destination }
- mov eax, ecx
- mov ecx, edx
- sar ecx, 2
- js @@exit
- cld
- rep stosd { Fill count DIV 4 dwords }
- mov ecx, edx
- and ecx, 3
- rep stosb { Fill count MOD 4 bytes }
- @@exit:
- pop edi
- {$ELSE}
- db 66h
- xor di, di
- les di, X { Point ES:[EDI] to destination }
- db 66h
- mov ax, word ptr Value
- db 66h
- mov cx, word ptr Cnt
- db 66h
- sar cx, 2
- js @@exit
- db 66h
- rep
- db 67h
- stosw { Fill count DIV 4 dwords }
- db 66h
- mov cx, word ptr Cnt
- db 66h
- db 83h
- db 0E1h
- db 03h { and ecx, 3 }
- rep
- db 67h
- stosb { Fill count MOD 4 bytes }
- @@exit:
- {$ENDIF}
- end;
- {=========================================================================}
- procedure _GlobalMoveMem(const Source; var Dest; Cnt: Longint);
- {$IFDEF USEDLL}export;{$ELSE}Far;{$ENDIF}assembler;
- asm
- {$IFDEF WIN32}
- { ->EAX Pointer to source }
- { EDX Pointer to destination }
- { ECX Count }
- test ecx, ecx
- jz @@error
- push esi
- push edi
- mov esi, eax
- mov edi, edx
- mov eax, ecx
- cmp edi, esi
- jg @@down
- je @@exit
- sar ecx, 2 { copy count DIV 4 dwords }
- js @@exit
- cld
- rep movsd
- mov ecx, eax
- and ecx, 3
- rep movsb { copy count MOD 4 bytes }
- jmp @@exit
- @@down:
- lea esi, [esi+ecx-4] { point ESI to last dword of source }
- lea edi, [edi+ecx-4] { point EDI to last dword of dest }
- sar ecx, 2 { copy count DIV 4 dwords }
- js @@exit
- std
- rep movsd
- mov ecx, eax
- and ecx, 3 { copy count MOD 4 bytes }
- add esi, 4-1 { point to last byte of rest }
- add edi, 4-1
- rep movsb
- cld
- @@exit:
- pop edi
- pop esi
- @@error:
- {$ELSE}
- mov dx, ds { save DS in DX }
- db 66h
- xor si, si
- lds si, Source { DS:[esi] point to Source }
- db 66h
- xor di, di
- les di, Dest { ES:[EDI] point to destination }
- db 66h
- mov cx, word ptr Cnt
- db 66h
- cmp di, si
- jg @@down
- cld
- db 66h
- sar cx, 2
- js @@exit
- db 66h
- rep
- db 67h
- movsw { move count DIV 4 dwords }
- db 66h
- mov cx, word ptr Cnt
- db 66h
- db 83h
- db 0E1h
- db 03h { and ecx, 3 }
- db 66h
- rep
- db 67h
- movsb { move count MOD 4 bytes }
- jmp @@exit
- @@down:
- db 66h
- add si, cx
- db 66h
- add di, cx
- db 66h
- sub si, 4
- db 66h
- sub di, 4
- std
- db 66h
- sar cx, 2
- js @@exit
- db 66h
- rep
- db 67h
- movsw { move count DIV 4 dwords }
- db 66h
- mov cx, word ptr Cnt
- db 66h
- db 83h
- db 0E1h
- db 03h { and ecx, 3 }
- db 66h
- add si, 4-1 { point to last byte of rest }
- db 66h
- add di, 4-1
- db 66h
- rep
- db 67h
- movsb { move count MOD 4 bytes }
- @@exit:
- cld
- mov ds, dx { restore DS }
- {$ENDIF}
- end;
- {=========================================================================}
- function _GlobalCmpMem(const p1, p2; Cnt: Longint): Boolean;
- {$IFDEF USEDLL}export;{$ELSE}Far;{$ENDIF}assembler;
- asm
- {$IFDEF WIN32}
- { ->EAX Pointer to source }
- { EDX Pointer to destination }
- { ECX Count }
- push edi
- push esi
- cld
- mov edi, eax
- mov esi, edx
- xor eax, eax
- mov edx, ecx
- shr ecx, 2
- or ecx, ecx
- jz @@Rest
- repz cmpsd
- jnz @@NotEqual
- @@Rest:
- mov ecx, edx
- and ecx, 3
- or ecx, ecx
- jz @@Equal
- repz cmpsb
- jnz @@NotEqual
- @@Equal:
- mov ax, True
- @@NotEqual:
- pop esi
- pop edi
- {$ELSE}
- mov bx, ds { save DS in BX }
- cld
- xor ax, ax
- db 66h
- xor si, si
- lds si, p1 { DS:[esi] point to p1 }
- db 66h
- xor di, di
- les di, p2 { ES:[EDI] point to p2 }
- db 66h
- mov cx, word ptr Cnt
- db 66h
- mov dx, cx
- db 66h
- shr cx, 2
- db 66h
- or cx, cx
- jz @@Rest
- db 66h
- repz
- db 67h
- cmpsw { compare count DIV 4 dwords }
- jnz @@NotEqual
- @@Rest:
- db 66h
- mov cx, dx
- db 66h
- db 83h
- db 0E1h
- db 03h { and ecx, 3 }
- db 66h
- or cx, cx
- jz @@Equal
- repz
- db 67h
- cmpsb
- jnz @@NotEqual
- @@Equal:
- mov ax, True
- @@NotEqual:
- mov ds, bx { restore ds }
- {$ENDIF}
- end;
|