home *** CD-ROM | disk | FTP | other *** search
- {-----------------------------------------------------------------------------}
- { Name: DMA.INC }
- { Author: Peter Thomas }
- { Purpose: This set of procedures and functions can be used to replace the }
- { standard TURBO Pascal output routines with direct "pokes" into }
- { the hardware buffer on an IBM-PC (or truely compatible machine). }
- { }
- { If used on an IBM Color adaptor board, these routines are }
- { (unfortunately) slower than standard DOS calls if a flicker }
- { free screen is wanted. If however screen flicker can be tolerated }
- { the routines can be considerably quicker. Programs may also make }
- { use of special calls to "turn off" the screen during periods }
- { of heavy screen I/O. This will enable faster running, albeit }
- { with a blank screen at certain times. }
- { }
- { All data structures, variables, constants, functions and }
- { procedures which are intended to be used soley within this }
- { file begin with the character "_". Any other variables etc. }
- { may be freely used by the main program. }
- { }
- { Usage: (*$I DMA.INC *) Include the code }
- { DMA_Out (BW_Screen); Activate the DMA procedures for monochrome }
- { or DMA_Out (Color_Screen); for color }
- { DMA_In ; Optionally activate read back from screen }
- { DMA_Color_Type ( Color_IBM ) using an IBM color adaptor }
- { DMA_Color_Type ( Color_Other) using a compatible adaptor }
- { which is flicker free }
- { DMA_Screen_Disable Turn off the screen (usable on IBM adaptor }
- { to speed up screen handling, with no }
- { flicker) }
- { DMA_Screen_Enable Turn on the screen }
- { DMA_Out_Reset Reset's output to use non DMA functions }
- { DMA_In_Reset Reset's input to use standard keyboard }
- { functions }
- { }
- { From here on: }
- { 1 - any WRITE or WRITELN's that would go to }
- { the TRM, or CON will go to via DMA }
- { to the screen. }
- { 2 - To utilize the standard files, WRITEs }
- { will have to utilize the device AUX }
- { (i.e. WRITELN ( Aux , Junk ) ). }
- { 3 - Any calls to ClrEol, ClrScr, DelLine, InsLine, }
- { GotoXY, LowVideo, NormVideo, WhereX, WhereY will be }
- { TextColor, TextBackGround, }
- { replaced by their DMA equivalent. }
- { 4 - The TURBO calls will be replaced by performed by }
- { prefixing the function or procedure with T_ }
- { (i.e. T_ClrEol ). }
- { 5 - The system may be reset to standard usage of WRITE }
- { by calling DMA_Out_Reset. However, all calls }
- { to TURBO screen handling will have to be performed }
- { by the T_ prefixed functions. }
- { }
- { Optional Input Handling: ONLY IF DMA_In has been called }
- { 1 - Any READ or READLN's that would go to }
- { TRM, KBD, CON will read the data from }
- { the present cursor postion. }
- { 2 - To perform a READ ( KBD, Char) the function Get_Kbd }
- { will have to be used. }
- { 3 - On a READ ( Aux ) there is no echoing performed }
- { to the screen. }
- { 4 - The system may be reset to standard usage of READ by }
- { calling DMA_In_Reset. }
- { }
- { How It Works: DMA.INC makes use of the ability of a user to define his }
- { own Input/Output handles. The standard TURBO screen drivers }
- { are referenced thru the variables ConInPtr and ConOutPtr. }
- { These are modified to point to two TURBO routines to return }
- { one character from the screen and place one on the screen. }
- { All standard screen handling functions are made available }
- { by defining the replacemnts AFTER the prefixed versions }
- { have been created, thus in the scope of T_ClrEol the meaning }
- { of ClrEol is the TURBO standard, whereas in the user code }
- { the meaning of ClrEol is the modified ClrEol. }
- {-----------------------------------------------------------------------------}
-
-
- {-----------------------------------------------------------------------------}
- { Functions and Procedures to provide access to standard TURBO screen }
- { handling, while the DMA.INC file has been included. }
- {-----------------------------------------------------------------------------}
-
- PROCEDURE T_ClrEol ;
- BEGIN
- ClrEol ;
- END;
-
- PROCEDURE T_ClrScr ;
- BEGIN
- ClrScr ;
- END;
-
- PROCEDURE T_DelLine ;
- BEGIN
- DelLine ;
- END ;
-
- PROCEDURE T_InsLine ;
- BEGIN
- InsLine ;
- END ;
-
- PROCEDURE T_GotoXY ( X , Y : INTEGER ) ;
- BEGIN
- GotoXY ( X , Y ) ;
- END ;
-
- PROCEDURE T_LowVideo ;
- BEGIN
- LowVideo ;
- END ;
-
- PROCEDURE T_NormVideo ;
- BEGIN
- NormVideo ;
- END ;
-
- PROCEDURE T_TextBackground ( Color : Byte ) ;
- BEGIN
- TextBackground ( Color ) ;
- END ;
-
- PROCEDURE T_TextColor ( Color : Byte ) ;
- BEGIN
- TextColor ( Color ) ;
- END ;
-
- FUNCTION T_WhereX : INTEGER ;
- BEGIN
- T_WhereX := WhereX ;
- END ;
-
- FUNCTION T_WhereY : INTEGER ;
- BEGIN
- T_WhereY := WhereY ;
- END ;
-
- {-----------------------------------------------------------------------------}
- { End of TURBO Replacement Functions }
- {-----------------------------------------------------------------------------}
-
- {-----------------------------------------------------------------------------}
- { Internal Data Types }
- {-----------------------------------------------------------------------------}
-
- TYPE
- _Screen_Position = ( _Char_Byte, _Attr_Byte) ;
- _Rows = 1..25;
- _Cols = 1..80;
- _Screen = ARRAY [1..25, 1..80, _Char_Byte.._Attr_Byte] OF CHAR;
- _Screen_Ptr = ^ _Screen;
- _Location = RECORD
- Y : _Rows;
- X : _Cols;
- END;
-
-
- {-----------------------------------------------------------------------------}
- { Public Constants }
- {-----------------------------------------------------------------------------}
-
- CONST
- BW_Screen = $B000 ; { Offset of B+W Screen }
- Color_Screen = $B800 ; { Offset of color screen }
-
- TYPE
- _DMA_Screen_Make = ( BW , Color_IBM , Color_Other ) ;
-
- {-----------------------------------------------------------------------------}
- { Internal Variables }
- {-----------------------------------------------------------------------------}
-
- VAR
- _DMA_Screen : _Screen_Ptr; { Offset to start of screen memory }
- _Global_Loc : _Location; { Present location on screen }
- _Default_Attr : Byte ; { Display data with this attribute }
- _Old_Aux_InPtr, { Save the old Auxilary Device }
- _Old_Aux_OutPtr : Integer ; { Input and Output handlers }
- _DMA_Action : BOOLEAN ; { Used to "force" changes to output ports }
- _DMA_Color : _DMA_Screen_Make ; { What type screen : BW, IBM color or other color }
- _DMA_Enable : BOOLEAN ; { Allow total turn-off of screen }
-
- {-----------------------------------------------------------------------------}
- { Internal Functions and Procedures }
- {-----------------------------------------------------------------------------}
-
- PROCEDURE _DMA_New_Pos (VAR Where : _Location; D_Row : INTEGER; D_Col : INTEGER);
- { Given a Location and a "Delta" location return the next postion. }
- BEGIN
- WITH Where DO
- BEGIN
- X := X + D_Col;
- Y := Y + D_Row;
- IF X < 1 THEN
- X := 1
- ELSE IF X > 80 THEN
- BEGIN
- Y := Y + 1;
- X := 1;
- END;
- IF Y < 1 THEN
- Y := 1
- ELSE IF Y > 25 THEN
- Y := 25;
- END;
- END;
-
- PROCEDURE _DMA_Color_Off ;
- { Disables the screen , or waits for vertical retrace on an IBM color card }
- BEGIN
- IF _DMA_Action OR
- ( _DMA_Enable AND ( _DMA_Color = Color_IBM ) ) THEN
- BEGIN
- WHILE ( PORT[$3DA] AND $08) = 0 DO ;
- PORT[$3D8] := $21 ;
- _DMA_Action := FALSE ;
- END ;
- END ;
-
- PROCEDURE _DMA_Color_On ;
- { Re-enables the screen disabled by _DMA_Color_Off }
- BEGIN
- IF _DMA_Action OR
- ( _DMA_Enable AND ( _DMA_Color = Color_IBM ) ) THEN
- BEGIN
- PORT[$3D8] := $29 ;
- _DMA_Action := FALSE ;
- END ;
- END ;
-
- PROCEDURE _DMA_Display ( What : CHAR ; X , Y : INTEGER ) ;
- { Displays the character What at a given location on the screen. }
- { No attempt to provide "flicker free" display }
- BEGIN
- _DMA_Screen^[Y,X,_Attr_Byte] := CHR(_Default_Attr);
- _DMA_Screen^[Y,X,_Char_Byte] := What;
- END ;
-
- PROCEDURE _DMA_CopyLine ( FromLine, ToLine : _Rows ) ;
- { Copies one line of the screen to a second }
- BEGIN
- MOVE ( _DMA_Screen^[FromLine] , _DMA_Screen^[ToLine], SIZEOF (_DMA_Screen^[1] ) ) ;
- END ;
-
- PROCEDURE _DMA_WriteCh (What : CHAR);
- { Places a character on the screen with the presently active display attribute}
- { Called by TURBO as Console device Output Handler }
- BEGIN
- _DMA_Color_Off ;
- _DMA_Display ( What , _Global_Loc.X, _Global_Loc.Y ) ;
- _DMA_Color_On ;
- _DMA_New_Pos (_Global_Loc, 0, 1);
- END;
-
- FUNCTION _DMA_GetCh : CHAR;
- { Returns a character from the screen }
- { Called by TURBO as Console Device Input Handler }
- BEGIN
- WITH _Global_Loc DO
- _DMA_GetCh := _DMA_Screen^[Y, X, _Char_Byte];
- _DMA_New_Pos (_Global_Loc, 0, 1);
- END;
-
- { TURBO Replacement Functions and Procedures }
-
- PROCEDURE ClrEol ;
- VAR
- Temp_X : _Cols ;
- BEGIN
- _DMA_Color_Off ;
- WITH _Global_Loc DO
- FOR Temp_X := X TO 80 DO
- _DMA_Display ( ' ' , Temp_X , Y ) ;
- _DMA_Color_On ;
- END ;
-
- PROCEDURE ClrScr;
- VAR
- Temp_X : _Cols;
- Temp_Y : _Rows;
- BEGIN
- _DMA_Color_Off ;
- FOR Temp_X := 1 TO 80 DO
- _DMA_Display ( ' ' , Temp_X , 1 ) ;
- FOR Temp_Y := 2 TO 25 DO
- _DMA_CopyLine ( 1, Temp_Y ) ;
- _DMA_Color_On ;
- END;
-
- PROCEDURE DelLine ;
- VAR
- Temp_Y : _Rows ;
- Temp_X : _Cols ;
- BEGIN
- _DMA_Color_Off ;
- WITH _Global_Loc DO
- FOR Temp_Y := Y TO 24 DO
- _DMA_CopyLine ( Temp_Y+1, Temp_Y ) ;
- FOR Temp_X := 1 TO 80 DO
- _DMA_Display ( ' ' , Temp_X , 25 ) ;
- _DMA_Color_On ;
- END ;
-
- PROCEDURE InsLine ;
- VAR
- Temp_X : _Rows ;
- Temp_Y : _COls ;
- BEGIN
- _DMA_Color_Off ;
- WITH _Global_Loc DO
- BEGIN
- FOR Temp_Y := 25 DOWNTO Y+1 DO
- _DMA_CopyLine ( Temp_Y - 1, Temp_Y ) ;
- FOR Temp_X := 1 TO 80 DO
- _DMA_Display ( ' ' , Temp_X , Y ) ;
- END ;
- _DMA_Color_On ;
- END ;
-
- PROCEDURE GotoXY (X_Pos : _Cols; Y_Pos : _Rows) ;
- BEGIN
- WITH _Global_Loc DO
- BEGIN
- X := X_Pos;
- Y := Y_Pos;
- END;
- END;
-
- PROCEDURE LowVideo ;
- BEGIN
- _Default_Attr := $07 ;
- END ;
-
- PROCEDURE NormVideo ;
- BEGIN
- _Default_Attr := $0F ;
- END ;
-
- PROCEDURE HighVideo ;
- BEGIN
- NormVideo ;
- END;
-
- PROCEDURE TextBackground ( Color : Byte ) ;
- BEGIN
- _Default_Attr := ( _Default_Attr AND $0F ) OR ( ( Color AND $0F ) shl 4 ) ;
- END ;
-
- PROCEDURE TextColor ( Color : Byte ) ;
- BEGIN
- _Default_Attr := ( _Default_Attr AND $F0 ) OR ( Color AND $0F ) ;
- END ;
-
-
- FUNCTION WhereX : INTEGER;
- BEGIN
- WhereX := _Global_Loc.X;
- END;
-
- FUNCTION WhereY : INTEGER;
- BEGIN
- WhereY := _Global_Loc.Y;
- END;
-
- FUNCTION GetKbd : Char ;
- VAR
- Temp_Char : Char ;
- BEGIN
- ConInPtr := AuxInPtr ;
- READ ( Kbd , Temp_Char ) ;
- ConInPtr := OFS ( _DMA_GetCh ) ;
- GetKbd := Temp_Char ;
- END ;
-
- {-----------------------------------------------------------------------------}
- { User Initialization Routines }
- {-----------------------------------------------------------------------------}
-
- PROCEDURE DMA_Out (Which : Integer ) ;
- { Called to initialize the interface. Which is the segment address of the }
- { screen buffer }
- BEGIN
- _DMA_Enable := TRUE ;
- _DMA_Action := FALSE ;
- IF Which = Color_Screen THEN
- _DMA_Color := Color_IBM
- ELSE
- _DMA_Color := BW ;
- _DMA_Screen := PTR(Which,0);
- WITH _Global_Loc DO
- BEGIN
- X := T_WhereX;
- Y := T_WhereY;
- END;
- _Old_Aux_OutPtr := AuxOutPtr ;
- AuxOutPtr := ConOutPtr;
- ConOutPtr := OFS(_DMA_WriteCh);
- _Default_Attr := $0F ;
- END;
-
- PROCEDURE DMA_Color_Type ( Screen_Type : _DMA_Screen_Make ) ;
- { Allows specification of a "flicker free" color screen }
- BEGIN
- IF SEG(_DMA_Screen^) = Color_Screen THEN
- _DMA_Color := Screen_Type ;
- END ;
-
- PROCEDURE DMA_Screen_Disable ;
- { Disable all screen updates }
- BEGIN
- _DMA_Action := TRUE ;
- _DMA_Color_Off ;
- _DMA_Enable := FALSE ;
- END ;
-
- PROCEDURE DMA_Screen_Enable ;
- { Re-enables screen updates }
- BEGIN
- _DMA_Action := TRUE ;
- _DMA_Color_On ;
- _DMA_Enable := TRUE ;
- END ;
-
- PROCEDURE DMA_In ;
- { Activates input reading from the screen (bypasses KBD) }
- BEGIN
- _Old_Aux_InPtr := AuxInPtr ;
- ConOutPtr := OFS(_DMA_WriteCh);
- AuxInPtr := ConInPtr ;
- END;
-
- PROCEDURE DMA_Out_Reset ;
- { Rsstores "standard" output handling }
- BEGIN
- ConOutPtr := AuxOutPtr ;
- AuxOutPtr := _Old_Aux_OutPtr ;
- END;
-
- PROCEDURE DMA_In_Reset ;
- { Restores "standard" input handling }
- BEGIN
- ConInPtr := AuxInPtr ;
- AuxInPtr := _Old_Aux_InPtr ;
- END;
- {on
- OWsC rhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhsssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss