Category : Pascal Source Code
Archive   : PASS_ALL.ZIP
Filename : TI303.ASC

 
Output of file : TI303.ASC contained in archive : PASS_ALL.ZIP









PRODUCT : TURBO PASCAL NUMBER : 303
VERSION : ALL
OS : PC-DOS
DATE : May 21, 1986 PAGE : 1/4
TITLE : DIRECT VIDEO ADDRESSING




Using Mem and MemW you may address any location on the screen and
change its value. A possible use might be creating a memory
mapped text editor. The following in an example of using Mem to
address the text screen one byte at a time. (Exchange $B800 for
$B000 if you have a monochrome screen.)

program RAM2;

Var
j, i : integer;
ch : char;

begin
j := 0;
for i := 1 to 2048 do
begin
Mem[$B800:j] := $80; {Accessing video RAM
Mem[$B800:j + 1] := $99 a byte at a time}
j := j + 2
end;
end.

When accessing RAM addressing a word at a time using MemW, you
must be aware of the following:

1. In text mode, when you enter a word value, it is broken down
into two bytes which are placed on the screen. Consequently,
word values must equal the sum of two bytes that you want
sent consecutively to the screen.
2. You must first assign the low byte, then the high byte of
the word.
3. You must increase the offset by two to access the next word
in memory.

MemArray
program RAM1;

Var
j, i : integer;
begin
j := 0;
for i := 1 to 2048 do
begin














PRODUCT : TURBO PASCAL NUMBER : 303
VERSION : ALL
OS : PC-DOS
DATE : May 21, 1986 PAGE : 2/4
TITLE : DIRECT VIDEO ADDRESSING




MemW[$B800:j] := $9908; { Accessing video RAM a word
at a time }
j := j + 2;
end;
end.

The following program demonstrates how to write directly to
screen memory and save and restore text screens. These routines
may cause snow on some monitors. There are routines in the Editor
Toolbox to read and write to the screen without snow, but they
are much harder to use and less intuitive than these ones.

program ScreenTest;
type { Row, Column }
ScreenType = array [1..25, 1..80] of record
Character : Char;
Attribute : Byte;
end;

AnyString = string [80]; { Generic string type }

{ The attribute byte of this data structure is formatted as
follows:

Bits 0-3 hold the foreground color, bits 4-6 hold the background
color, and bit 7 indicates whether blinking is on or off.

Bit 0 1 2 3 4 5 6 7
Color Part FG FG FG FG BG BG BG BL
Color Part Value 1 2 4 8 1 2 4 1
Bit Value (Decimal) 1 2 4 8 16 32 64 128
Bit Value (Hex) $01 $02 $04 $08 $10 $20 $40 $80 }

var
ColorScreen : ScreenType absolute $B800:0;
{ Use for color screen }
MonoScreen : ScreenType absolute $B000:0;
{ Use for monochrome screen }
SavedScreen : ScreenType;
{ Buffer to save the screen }

function MakeAttribute(Foreground, Background : Byte;
Blink : Boolean) : Byte;














PRODUCT : TURBO PASCAL NUMBER : 303
VERSION : ALL
OS : PC-DOS
DATE : May 21, 1986 PAGE : 3/4
TITLE : DIRECT VIDEO ADDRESSING




{ Creates an attribute byte from a combination of foreground,
background, and blinking attributes }

begin
MakeAttribute := Foreground + (Background shl 4) +
(Ord(Blink) shl 7);
end; { MakeAttribute }

procedure WriteString(S : AnyString; var Screen : ScreenType;
Col, Row, Attrib : Byte);

{ Writes a string into screen memory starting at a particular row and
column, using Attrib as the color attribute. }

var
Counter : Byte;

begin
for Counter := 1 to Length(S) do
begin
Screen[Row, Pred(Col + Counter)].Character := S[Counter];
Screen[Row, Pred(Col + Counter)].Attribute := Attrib;
end;
end; { WriteString }

begin
SavedScreen := ColorScreen; { Save the current screen }
Window(25, 5, 55, 15); { Create the new window }
GotoXY(1, 1); { Move inside the new window }
TextColor(Yellow); { Change the current colors }
TextBackground(Red);
ClrScr;

{ Clear the window and fill it with color }
WriteString(' Press Return to continue...', ColorScreen, 25, 5,
MakeAttribute(Yellow, Red, False));
{ Write out prompt - note that WriteString uses the
absolute row and column, not the row and column
of the current window }
Read; { Wait for return to be pressed }
ColorScreen := SavedScreen; { Restore old screen }
end.