Board index » delphi » Protected mode - text screen reading and writing

Protected mode - text screen reading and writing

How does one read (and write) to the text screen in protected mode.
 In real mode setting up an array at the absolute address $B800 works great
but in protected mode this causes a GPF.

Thanks in advance
Wayne Schou
sch...@fri.cri.nz

 

Re:Protected mode - text screen reading and writing


Quote
Wayne Schou wrote:

> How does one read (and write) to the text screen in protected mode.
>  In real mode setting up an array at the absolute address $B800 works great
> but in protected mode this causes a GPF.

> Thanks in advance
> Wayne Schou
> sch...@fri.cri.nz

In protected mode, use the provided selectors to specify a segment,
rather than using an absolute number.  In this specific case, replace
all of your references to $B800 with SegB800.  

The need to use selectors in well documented in the BP manuals, and
also to a lesser extent in the online help.  Start off looking up
SegXXXX in the on-line help.

Rob

Re:Protected mode - text screen reading and writing


Quote
Wayne Schou wrote:
> How does one read (and write) to the text screen in protected mode.
>  In real mode setting up an array at the absolute address $B800 works great
> but in protected mode this causes a GPF.

Absolute address variables aren't allowed in protected mode (though an
absolute to another variable is perfectly legal).

If you use this method in real mode:

type
  Tcell = record
    ch : char;
    at : byte;
  end;

type
  TScreen = array[1..25,1..80] of TCell;

var
  TextScreen : TScreen absolute $b800:$0000;

{...}

It only takes a little bit of modification to use in protected mode:

Add this declaration:

type
  PScreen = ^TScreen;

Then change the variable to:

var
  TextScreen : PScreen;

In your initialization code:

begin
  TextScreen := ptr(SegB800,0);
  {...}
end;

Now, all access is done much like before, but through TextScreen^ rather
than TextScreen (dereferencing the pointer).

Quote
> Thanks in advance
> Wayne Schou
> sch...@fri.cri.nz

--
Scott Earnest        | We now return you to our regularly |
set...@ix.netcom.com | scheduled chaos and mayhem. . . .  |

Re:Protected mode - text screen reading and writing


Re:Protected mode - text screen reading and writing


Quote
>How does one read (and write) to the text screen in protected mode.
> In real mode setting up an array at the absolute address $B800 works great
>but in protected mode this causes a GPF.

>Thanks in advance
>Wayne Schou
>sch...@fri.cri.nz

Look up addressing in protected mode.  You will see that for the more
commonly used address like B800 that there are predefined variables that
can be used in real mode and protected mode.  For those that are not
predefined, you will have to figure out how to set the address.  The reason
that absolute addressing does not work in protected mode is that protected
mode supports flat addressing, not segmented addressing.

Some of the predefined addresses are Seg0040, SegA000, SegB000 and SegB800.
The absolute address equivalents should be obvious.  For additional
information, consult the manuals, the help file or Brian Long's, The Borland
Pascal Problem Solver, Addison-Wesley, 1994, ISBN 0-201-59383-1.

Jose' Perez

Re:Protected mode - text screen reading and writing


Quote
Jose' M. Perez wrote:
> >How does one read (and write) to the text screen in protected mode.
> > In real mode setting up an array at the absolute address $B800 works great
> >but in protected mode this causes a GPF.

> >Thanks in advance
> >Wayne Schou
> >sch...@fri.cri.nz

> Look up addressing in protected mode.  You will see that for the more
> commonly used address like B800 that there are predefined variables that
> can be used in real mode and protected mode.  For those that are not
> predefined, you will have to figure out how to set the address.  The reason
> that absolute addressing does not work in protected mode is that protected
> mode supports flat addressing, not segmented addressing.

Well, in BP7's protected mode interface is 16-bit, and the segment limit
is 64K.  So, effectively, memory will still have the same constraints as
real mode segmented memory.

Quote
> Some of the predefined addresses are Seg0040, SegA000, SegB000 and SegB800.

Actually, those are the only predefined addresses.

Quote
> The absolute address equivalents should be obvious.

But absolute addresses aren't possible.  For an absolute address, what
you need to do is change something like:

type
  TScreenChar = record
    ch : char;
    at : byte;
  end;

type
  Tscreen = array[1..25,1..80] of TScreenChar;

var
  screen : Tscreen absolute $b800:$0000;

To use this in protected mode, add the following declaration:

type
  Pscreen = ^Tscreen;

Then change:

var
  screen : Pscreen;

In your initialization code:

begin
  screen := ptr(SegB800,$0);
  {...}
end;

The only difference is that references to video memory through screen
must be changed to screen^.  (BTW, I'm getting deja vu, didn't I just
post something like this recently?)

Quote
> For additional
> information, consult the manuals, the help file or Brian Long's, The Borland
> Pascal Problem Solver, Addison-Wesley, 1994, ISBN 0-201-59383-1.

> Jose' Perez

--
Scott Earnest        | We now return you to our regularly |
set...@ix.netcom.com | scheduled chaos and mayhem. . . .  |

Re:Protected mode - text screen reading and writing


In article <9703171300591.DLITE.jope...@delphi.com>,
Jose' M. Perez <jope...@delphi.com> wrote:

Quote
>>How does one read (and write) to the text screen in protected mode.
>> In real mode setting up an array at the absolute address $B800 works great
>>but in protected mode this causes a GPF.

>Look up addressing in protected mode.  You will see that for the more
>commonly used address like B800 that there are predefined variables that
>can be used in real mode and protected mode.  For those that are not
>predefined, you will have to figure out how to set the address.  
>The reason that absolute addressing does not work in protected mode is
>that protected mode supports flat addressing, not segmented addressing.

From our web page (http://www.monstersoft.com/tutorial1/48bit_intro.html):

The memory on the bus of the PC is called physical memory.  Each byte is
assigned a unique address, called a physical address, which ranges from
zero to a maximum of 2^32-1 bytes.  With segmentation, however, it is
possible to have multiple, independent address spaces. [...]  The PC is
limited to 16,383 segments of up to 4 gigabytes each, or a total as large
as 2^46 bytes (64 terabytes).  

_32-Bit Addressing_

32-bit addressing is commonly referred to as the "flat" memory model.  This
is a misnomer, since there isn't a mode bit or control register which
turns off the segmentation mechanism.  Instead, all of the segment registers
are mapped to the same address space (usually the base of memory), and
only the 32-bit offset is used.  This mode has the benefit of not needing
to load segment registers.

Quote
>Some of the predefined addresses are Seg0040, SegA000, SegB000 and SegB800.
>The absolute address equivalents should be obvious.  For additional
>information, consult the manuals, the help file or Brian Long's, The Borland
>Pascal Problem Solver, Addison-Wesley, 1994, ISBN 0-201-59383-1.

You can also create your own with this function:

function SegToSelector(SegAddr:word):word; assembler;
asm
        mov     ax,0002h
        mov     bx,SegAddr
        int     31h
end;

SegC000:=SegToSelector($C000);

Quote
>Jose' Perez

--Mark Iuzzolino
one of the monst...@monstersoft.com  |  "Paradise is similar to where you are
http://www.monstersoft.com           |   now, only much *much* better."

Other Threads