home *** CD-ROM | disk | FTP | other *** search
- Unit InitOvly;
- { This unit will initialize the Overlay Manager. It can be }
- { used in the situation where some of the units that a }
- { program uses have initialization code. It is especially }
- { useful when no source code is available to a unit, or you }
- { cannot remove a unit's initialization code. }
- {$O-,F+}
- Interface
-
- Uses OverLay;
-
- Const
- FileModeforOverlay = 0; { Change this value for other mode }
- OverlayFileName : String = ''; { Change to correct name }
-
- Implementation
-
- Uses
- Crt, Dos;
-
- Var
- OvrBufSize : LongInt;
- {$IFDEF VER55}
- OldOvrReadFunc : OvrReadFunc;
- {$ENDIF VER55}
-
- Function Exists( FName : String ) : Boolean;
- { This function returns either True or False, depending upon }
- { whether the file FName was in the current directory. It }
- { uses a new way of determining the existance of the file. }
- { It is no longer necessary to turn off I/O checking and then }
- { attempt to reset the file in order to determine if the file }
- { exists. }
-
- Var
- Result : String; { Result of calling the FSearch Func }
-
- Begin
- Result := FSearch( FName, '' );
- Exists := Result <> '';
- End;
-
- {$IFDEF VER55}
-
- Procedure WriteMessageAt( X, Y : Byte; Message : String );
- { Output the message parameter at screen locations X and Y }
-
- Begin
- GotoXY( X, Y );
- Write( Message );
- End;
-
-
- Procedure HandleOvrErr( Error : Integer );
- { This procedure will handle any error that happens when the }
- { program attempts to read from the .OVR file. This way, we }
- { have the capability to recover from the error. }
- Var
- ErrorString : String;
-
- Begin
- Str( Error, ErrorString );
- WriteMessageAt( 10,10, ErrorString );
- End;
-
- Function MyOvrRead( OvrSeg : Word ) : Integer;
- { This function will be called by the Overlay Manager before }
- { any attempt is made to read from the file. We must call }
- { the original read function, which will return an error code }
- { to this function if it is not successful in reading the }
- { required overlay from the .OVR file. }
- Var
- Err : Integer;
-
- Begin
- Repeat
- Err := OldOvrReadFunc( OvrSeg );
- If( Err <> 0 ) Then
- HandleOvrErr( Err );
- Until Err = 0;
- MyOvrRead := 0;
- End;
-
- {$ENDIF}
-
- Begin
- {$IFDEF VER55}
-
- OvrFileMode := FileModeforOverlay;
-
- {$ENDIF}
-
- OvrInit( OverlayFileName );
-
- {$IFDEF VER55}
-
- OldOvrReadFunc := OvrReadBuf;
- OvrReadBuf := MyOvrRead;
-
- {$ENDIF}
-
- While( OvrResult = OvrNotFound ) Do
- Begin
- Writeln( 'File not found: ', OverlayFileName, '.' );
- Write( 'Enter new name: ' );
- Readln( OverlayFileName );
- OvrInit( OverlayFileName );
- End;
- If( OvrResult <> OvrOK ) Then
- Begin
- ClrScr;
- Writeln( 'Unrecoverable Overlay Manager error. Program Terminated.' );
- Halt;
- End;
- OvrInitEMS; { Will load the .OVR file into EMS }
-
- {$IFDEF VER55}
-
- If( OvrResult = OvrOk ) Then
- Begin
- OldOvrReadFunc := OvrReadBuf;
- OvrReadBuf := MyOvrRead;
- End;
- OvrSetRetry( OvrGetBuf Div 3 );
-
- {$ENDIF}
-
- End.