Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2001-08

Reading the color attributes from the screen

6 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Unknown author

The following bit of code is something I use in my go32v2 (DOS) programs to save/restore the contents of the screen to/from memory. It works great except that it takes the colors as they appear on the screen (which is okay most of the time). But is there a way I can store/reset the color attributes either directly on the screen or in the array after I've saved the screen? Or perhaps there's another mem[] region I can grab and modify the colors their instead?

TIA...

Jim

//  for screens up to 132x60
const
  BUF_SIZE = 7920;
// array to hold screen contents
var
  ScreenBuffer : array [1..BUF_SIZE] of byte;
// save the entire screen to memory
  move (mem [$B8000],ScreenBuffer,BUF_SIZE);
// restore the screen from memory
  move (ScreenBuffer,mem [$B8000],BUF_SIZE);
Thomas Schatzl
to Unknown author

From:
Subject: [fpc-pascal]Reading the color attributes from the screen

Hi,

Show quoted text 9 lines
The following bit of code is something I use in my go32v2 (DOS) programs to save/restore the contents of the screen to/from memory. [...] the array after I've saved the screen? Or perhaps there's another mem[] region I can grab and modify the colors their instead? // for screens up to 132x60 const BUF_SIZE = 7920;

Note that this value for the buffer size only covers half of the textmode screen memory, see below why.

// array to hold screen contents var ScreenBuffer : array [1..BUF_SIZE] of byte; [...]

(VGA-)Textmode has the following memory layout:
Each cell of the screen is represented by two bytes, the first is the color attribute the second is the ascii character value. The cells are stored one after another in a linear fashion from left to right, line by line from top to bottom.
E.g. a procedure which sets the attribute and ascii character value of a cell could look like the following:

procedure PutChar(x, y : DWord; attr : Byte; character : Char);
begin
    ScreenBuffer[(y * WIDTH + x ) * 2] := attr;
    ScreenBuffer[(y * WIDTH + x ) * 2 + 1] := Ord(character);
end;

where WIDTH is the screen's physical number of cells per line. (Note that the x/y coords are interpreted as zero based).

Use the mem[] operator with the same offsets into the screen buffer area as used in the previous example to change cell character and ascii value directly on the screen.
E.g.

procedure PutChar(x, y : DWord; attr : Byte; character : Char);
begin
    mem[$B8000 + (y * WIDTH + x ) * 2] := attr;
    mem[$B8000 + (y * WIDTH + x ) * 2 + 1] := Ord(character);
end;

Should do the trick (everything untested).

Regards,
Thomas

Unknown author
Show quoted text 8 lines
(VGA-)Textmode has the following memory layout: Each cell of the screen is represented by two bytes, the first is the color attribute the second is the ascii character value. The cells are stored one after another in a linear fashion from left to right, line by line from top to bottom. [snip] Should do the trick (everything untested).

Untested, perhaps, but certainly enough for me to see what I was missing. Thanks for the help...

Jim

Stefan Becker
to Unknown author

Hi,
is there a way to read this information from
a linux console?

Like a "Get Charater and attribute under Cursor" command.

cheers,
Stefan

LUFA Speyer (EDV)
email:
tel : +49 (0)6232-629542
fax : +49 (0)6232-629544
http://www.lufa-speyer.de/

Earlier message 21 lines
-----Original Message----- From: Behalf Of Sent: Monday, August 20, 2001 5:33 PM To: Subject: Re: [fpc-pascal]Reading the color attributes from the screen > (VGA-)Textmode has the following memory layout: > Each cell of the screen is represented by two bytes, the first > is the color attribute the second is the ascii character value. > The cells are stored one after another in a linear fashion from > left to right, line by line from top to bottom. > [snip] > Should do the trick (everything untested). Untested, perhaps, but certainly enough for me to see what I was missing. Thanks for the help... Jim
Ken J. Wright
to Stefan Becker
you wrote 5 lines
Hi, is there a way to read this information from a linux console? Like a "Get Charater and attribute under Cursor" command.

The oCrt unit contains nReadScr, nReadScrStr, nReadScrColor, etc. functions for this.

Ken

Show quoted text 37 lines
cheers, Stefan LUFA Speyer (EDV) email: tel : +49 (0)6232-629542 fax : +49 (0)6232-629544 http://www.lufa-speyer.de/ -----Original Message----- From: Behalf Of Sent: Monday, August 20, 2001 5:33 PM To: Subject: Re: [fpc-pascal]Reading the color attributes from the screen > (VGA-)Textmode has the following memory layout: > Each cell of the screen is represented by two bytes, the first > is the color attribute the second is the ascii character value. > The cells are stored one after another in a linear fashion from > left to right, line by line from top to bottom. > [snip] > > Should do the trick (everything untested). Untested, perhaps, but certainly enough for me to see what I was missing. Thanks for the help... Jim _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
AITOR.SM

Every character is stored into a word, 2 bytes, one for the attributes (hi), and one for the code in the current codepage (lo). So the current size is actually double. You can either modify the screen buffer or your saved copy. For the attributes byte, there is one nibble for background, another for foreground colours (I can't remember which is which, so check it out! ;-))

Aitor

Earlier message 42 lines
----- Mensaje Original ----- De: Fecha: Viernes, Agosto 17, 2001 10:28 pm Asunto: [fpc-pascal]Reading the color attributes from the screen > The following bit of code is something I use in my go32v2 (DOS) > programs > to save/restore the contents of the screen to/from memory. It > works great > except that it takes the colors as they appear on the screen > (which is > okay most of the time). But is there a way I can store/reset the > color > attributes either directly on the screen or in the array after > I've saved > the screen? Or perhaps there's another mem[] region I can grab and > modify > the colors their instead? > > TIA... > > Jim > > > // for screens up to 132x60 > const > BUF_SIZE = 7920; > > // array to hold screen contents > var > ScreenBuffer : array [1..BUF_SIZE] of byte; > > // save the entire screen to memory > move (mem [$B8000],ScreenBuffer,BUF_SIZE); > > // restore the screen from memory > move (ScreenBuffer,mem [$B8000],BUF_SIZE); > ___________________________________________________________________ Consigue tu e-mail gratuito TERRA.ES Haz clic en http://www.terra.es/correo/