mmutils.inc
上传用户:hylc_2004
上传日期:2014-01-23
资源大小:46800k
文件大小:11k
- {=========================================================================}
- 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;