Board index » delphi » Scroll in text-mode

Scroll in text-mode

Hi

I want source for scrolling a text file in text-mode (Scroll up and down
with the keyboard for example).

Thanks

/Marcus Malmgren

 

Re:Scroll in text-mode


Quote
eye-q wrote in message <01bd2f2e$faa59a80$d89064c3@eye-q>...
>Hi

>I want source for scrolling a text file in text-mode (Scroll up and down
>with the keyboard for example).

>Thanks

>/Marcus Malmgren

Can I have one too?
Myles Fisher - STILL frustrated with my own scrolling in text mode...

Re:Scroll in text-mode


Quote
Myles F. wrote:
> eye-q wrote in message <01bd2f2e$faa59a80$d89064c3@eye-q>...
> >Hi

> >I want source for scrolling a text file in text-mode (Scroll up and down
> >with the keyboard for example).

> >Thanks

> >/Marcus Malmgren

> Can I have one too?
> Myles Fisher - STILL frustrated with my own scrolling in text mode...

How about an algorithm?

read file into memory
firstline = 1
maxline = (number of lines - number of screen lines) + 1
repeat
  get keypress
  case
    up arrow :
      if firstline > 1 then
        dec(firstline)
        redraw
    down arrow:
      if firstline > maxline then
        inc(firstline)
        redraw
    page up:
      dec(firstline,# screen lines)
      if firstline < 1 then firstline = 1
      redraw
    page down:
      inc(firstline,# screen lines)
      if firstline > maxline then firstline = maxline
      redraw
    home:
      firstline = 1
      redraw
    end:
      firstline = maxline
      redraw
    escape:
      indicate done with scroll
until done with scroll

There are some other minor details to this, but that essentially covers the
core functionality of an interactive text scroller.  Considerations can be
made for displaying short files, only redrawing if the screen has moved,
adding panning (left and right to view lines longer than the screen width).

For sake of speed and typing, I just used strict indenting to indicate block
scope here instead of using all sorts of begin/end markers.

--
Scott Earnest            | SPAM protection in effect. Remove  |
setech@_ix.netcom.com    | "_" as needed for true addresses.  |
earnests@_homenet.lm.com |    UIN:1136443  EFnet:pale_blue    |
sinykal@_{*word*104}space.org  | URL: http://www.netcom.com/~setech |

Re:Scroll in text-mode


Quote
Myles F. wrote:

> [dammit! my {*word*76}y server wouldn't let me post until most of your message
> was deleted...]

I know the feeling...
Quote

>     Thanks, Scott, but I've already implemented the actual handling of it.
> My prog can take any commands ('cept the wrong ones, of course!), but the
> real problem lies in the implementation of those commands - ie, the 'redraw'
> section of your program above. I've not yet learnt just how to write
> directly to screen memory, so the result is that going up a line or using
> page-down or page-up results in a very visible 'all the lines on the screen
> being redrawn' effect. So, just what is exactly the code to write to screen
> memory - and please, if there's a way to do it without assembler, I'm all
> ears!

Actually, it's very easy.  No ASM required!  I have a unit I made that
lets you
directly access the video buffer.  It's not very fast (goes plenty fast
on my
Pentium desktop!) but it gets the job done.  I can send it to you if you
want it.

BTW - I have a scrolling program that does what you're trying to do
(scrolls
very smoothly on my other computer, a '286 notebook).  It's a simple
file viewer.
I can give you some help on this program if you DESPERATELY need it.

--
----------------------------------------------------------------------
Phil Brutsche

"Be of stout heart, Number One.  We've handled the Borg.  We can
certainly handle Admiral Jellico." - Jean-Luc Picard

----------------------------------------------------------------------

Re:Scroll in text-mode


Quote
Myles F. wrote:

> eye-q wrote in message <01bd2f2e$faa59a80$d89064c3@eye-q>...
> >Hi

> >I want source for scrolling a text file in text-mode (Scroll up and down
> >with the keyboard for example).

> >Thanks

> >/Marcus Malmgren

> Can I have one too?
> Myles Fisher - STILL frustrated with my own scrolling in text mode...

Here's how I'd do it (attached).
The source shows how to do line-by-line scrolling in a plain text
buffer.
It'd be easier and faster if you used video RAM memory dumps instead of
a text file. You'd also have color then...

Anyway, if you're actually after "pixel-by-pixel" scrolling.
(Like smooth scrolling in text mode by changing then retrace offsets
or whatever)
Then you'll have to get it off someone else.

Emil.

[ Scroll.pas 1K ]
{ Textmode scrolling }
{ by Emil Mikulic }

{ please give credit where it's due }

uses crt;

type line=array[1..80] of char;
     scrolldata=array[1..800] of line;
     { approximately 800 lines will fit into a segment. why?
       a segment is 65536 bytes, a line is 80 bytes.
       65536/80 = 819.something

       if you need more than this, you'll need multiple segments
       and some other slightly more tricky stuff, etc }

var buffer:^scrolldata;
    f:text;
    yofs:integer;
    i,j,k:integer;
    s,t:string;
    c:char;

begin
 textattr:=7;
 new(buffer); { allocate buffer }

 assign(f,'text.txt');
 reset(f);            { open file to pull data out of }

 i:=0;
 repeat
  i:=i+1;
  readln(f,s);  { get line into s }

  { crop line if longer than 80. extend with spaces if shorter }
  if length(s)<80 then begin
    t:=s;
    for j:=length(s) to 79 do t:=t+' '; { fill up }
  end else begin
    { so it must be cropped cause it's longer }
    t:='';
    for j:=1 to 80 do t:=t+s[j];
  end;

  { and put it in the buffer }
  for j:=1 to 80 do buffer^[i][j]:=t[j];
 until eof(f);   { until there's no more }

 close(f);

 { here starts the scrolly }
 clrscr;
 yofs:=1;

 { key mapping: ESC to stop, UP and DOWN on the arrow keys to move }
 repeat
  { copy data }
  for j:=yofs to yofs+25 do
    for k:=1 to 80 do
      mem[$b800: (j-yofs)*160 + (k*2)] := ord(buffer^[j,k]);

  c:=readkey;
  if c=#0 then begin
    { if special key }
    c:=readkey; { again }
    case ord(c) of
         $48: yofs:=yofs-1;
         $50: yofs:=yofs+1;
         end;

    { crop yofs }
    if yofs<1 then yofs:=1;
    if yofs>(i-25) { last page } then yofs:=(i-25);
    end;
 until c=#27;

 dispose(buffer);
end.

{ that's about it, it doesn't do colors and it's a bit slow but it's
  a decent code base for a _REAL_ scroller. }

Re:Scroll in text-mode


[dammit! my {*word*76}y server wouldn't let me post until most of your message
was deleted...]

Quote
>--
>Scott Earnest

    Thanks, Scott, but I've already implemented the actual handling of it.
My prog can take any commands ('cept the wrong ones, of course!), but the
real problem lies in the implementation of those commands - ie, the 'redraw'
section of your program above. I've not yet learnt just how to write
directly to screen memory, so the result is that going up a line or using
page-down or page-up results in a very visible 'all the lines on the screen
being redrawn' effect. So, just what is exactly the code to write to screen
memory - and please, if there's a way to do it without assembler, I'm all
ears!

Myles Fisher

Re:Scroll in text-mode


In article <6b3lvm$ri...@perki.connect.com.au>,

Quote
Myles F. <fis...@smart.net.au> wrote:

>eye-q wrote in message <01bd2f2e$faa59a80$d89064c3@eye-q>...
>>Hi

>>I want source for scrolling a text file in text-mode (Scroll up and down
>>with the keyboard for example).

>>Thanks

>>/Marcus Malmgren

>Can I have one too?
>Myles Fisher - STILL frustrated with my own scrolling in text mode...

Have you thought using insline and delline? (make sure that the cursor
is on the top line)

Osmo

Re:Scroll in text-mode


Quote
Myles F. wrote:
> [dammit! my {*word*76}y server wouldn't let me post until most of your message
> was deleted...]
> >--
> >Scott Earnest

>     Thanks, Scott, but I've already implemented the actual handling of it.
> My prog can take any commands ('cept the wrong ones, of course!), but the
> real problem lies in the implementation of those commands - ie, the 'redraw'
> section of your program above. I've not yet learnt just how to write
> directly to screen memory, so the result is that going up a line or using
> page-down or page-up results in a very visible 'all the lines on the screen
> being redrawn' effect. So, just what is exactly the code to write to screen
> memory - and please, if there's a way to do it without assembler, I'm all
> ears!

> Myles Fisher

The segment for accessing the screen in text mode is: $B800 and the
offset is within 0..80*25
depending on the coordinates.

Moraliyski

Re:Scroll in text-mode


Quote

>Have you thought using insline and delline? (make sure that the cursor
>is on the top line)

>Osmo

No, no, no! Did you read my other message in another branch? I've tried that
stuff but it is too slow. However, thanks must go to Emil Mikulic who
provided a simple example of how to accomplish what I want in Pascal. Get
his sample program, and you'll see what I'm talking about - eg: direct
writes to video memory...

Thanks, anyway.
Myles Fisher

Re:Scroll in text-mode


Quote
>Here's how I'd do it (attached).
>The source shows how to do line-by-line scrolling in a plain text
>buffer.
>It'd be easier and faster if you used video RAM memory dumps instead of
>a text file. You'd also have color then...
>Anyway, if you're actually after "pixel-by-pixel" scrolling.
>(Like smooth scrolling in text mode by changing then retrace offsets
>or whatever)
>Then you'll have to get it off someone else.

>Emil.

Memo to all interested in this thread of the message - here is the answer
we're probably all seeking. Emil Mikulic's program shows exactly how to
achieve a scroll-in-text-mode effect which is perfectly suitable for README
type files, and for my purposes.
    This is the kind of stuff which should be demonstrated more often in
giving answers in this newsgroup. And I'm not talking about freely giving
away code with abandon, ok?

Myles Fisher

Re:Scroll in text-mode


In article <6b8thb$du...@perki.connect.com.au>,

Quote
Myles F. <fis...@smart.net.au> wrote:

>>Have you thought using insline and delline? (make sure that the cursor
>>is on the top line)

>>Osmo

>No, no, no! Did you read my other message in another branch? I've tried that
>stuff but it is too slow. However, thanks must go to Emil Mikulic who
>provided a simple example of how to accomplish what I want in Pascal. Get
>his sample program, and you'll see what I'm talking about - eg: direct
>writes to video memory...

What on earth are you doing and on what machine? I have used insline
and delline for 8MHz 8088 and they were fast enough. On my 386DX-40
Delline takes under 4 ms. Remember that the fastest key repeat is 30 Hz
or at 33ms interval.

Try this:

uses crt;
var i:integer;

begin
  clrscr;
  for i:=1 to 24 do writeln('This is row nro ',i);
  gotoxy(1,1);
  for i:=1 to 25 do begin
    delay(100);
    delline;
    delay(100);
    insline;
  End;
End.

Osmo

Re:Scroll in text-mode


Quote
> No, no, no! Did you read my other message in another branch? I've tried that
> stuff but it is too slow. However, thanks must go to Emil Mikulic who
> provided a simple example of how to accomplish what I want in Pascal. Get
> his sample program, and you'll see what I'm talking about - eg: direct
> writes to video memory...

Oh yeah, if you make an array that holds 4000 bytes for each page
instead of
2000 and pad it with color values (7 if unsure) then you can speed it up
tons. Anyone wnat me to try this and post another example?

At the moment there's a stupid bit of code for the direct video write
which could be replaced with a blazing fast
        move(buffer[offset],videoram,4000);

Emil.

Other Threads