1. scroll in dos

Hello everyone,

This is my code, which works, however I have seen a simpler way of doing this.

But I can't find it.

Does anybody know a simpler way?

 
 
 
 
 
include graphics.e 
include get.e 
--with trace------------------------ 
-----------------------------------------------------------set up------------------------------------ 
constant data={"one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen", 
               "fifteen","sixteen","seventeen","eighteen","nineteen","twenty"} 
 
sequence line 
integer i,pos,dp,start 
constant scrLen=10 
constant dbLen=20 
 
  line=repeat(0,dbLen) 
  start=1 
for x=1 to dbLen do 
    line[x]=sprintf("%2d %s\n",{x,data[x]}) 
end for 
 
for x=1 to scrLen do--lines 
    puts(1,line[x]  ) 
end for  
 
procedure color_rev() 
  text_color(0) 
  bk_color(7) 
end procedure 
 
procedure color_norm()  
  text_color(7) 
  bk_color(0) 
end procedure 
 
procedure color_red() 
  text_color(12) 
  bk_color(8) 
end procedure 
 
procedure color_test() 
  text_color(11) 
  bk_color(6) 
end procedure 
 
position(start,1) 
  color_rev() 
    puts(1,line[start] ) 
  color_norm()   
--pause() 
dp=start 
pos=start 
----------------------------------------------------------------- 
 
procedure print_move_all_down_one_info()    
 position(20,40) 
 printf(1,"pos=%d dp=%d n",{pos,dp}) 
end procedure 
 
procedure print_info(integer pos,integer dp)       
   position(10,20)  
   puts(1,    "                                    \n") 
   position(10,20) 
   printf(1,"pos=%d dp=%d   \n",{pos,dp})   
end procedure 
 
procedure print_dp()     
   position(20,60) 
printf(1,"dp=%d \n",{dp}) 
end procedure 
 
procedure print_line(integer p,integer dp) 
print_info(p,dp) 
  position(p,1) 
puts(1,    "                  \n") 
position(p,1) 
puts(1,line[dp]    &"\n") 
end procedure 
 
procedure move_all_up_one()   
  color_norm() 
   for x=1 to 9 do 
    position(x,1) 
    puts(1,    "                     ") 
    position(x,1) 
    puts(1,line[dp+x-scrLen] &"\n") 
   end for 
end procedure 
 
procedure move_all_down_one() 
color_norm() 
   for x=2 to scrLen do 
      print_line(x,dp+x-1) 
   end for 
end procedure 
 
procedure move_up_one()   
 if pos=1 and dp=1 then 
    return 
 end if 
  color_norm() 
 print_line(pos,dp) 
  color_rev() 
  pos-=1 
  dp-=1   
   if dp<=scrLen and dp!=pos then 
      pos=1 
    move_all_down_one() 
      pos=1 
   end if    
    if pos<1 then 
       pos=1 
       dp=1 
    end if 
    if dp<1 then 
       return 
    end if 
  color_rev() 
 print_line(pos,dp) 
end procedure 
 
procedure move_down_one() 
  color_norm() 
   print_line(pos,dp) 
  color_rev() 
   pos+=1 
   dp+=1 
     if pos>scrLen and dp<dbLen+1 then 
          pos=scrLen 
          move_all_up_one() 
          color_rev() 
          print_line(pos,dp) 
     elsif pos>scrLen and dp>dbLen then         
        pos=scrLen 
        dp=dbLen 
     end if 
    print_line(pos,dp) 
end procedure 
 
 
cursor(NO_CURSOR) 
 
while 1  do 
    i=wait_key() 
      if i=27 then 
        exit 
      elsif i=328 then   
          move_up_one() 
      elsif i=336 then 
          move_down_one() 
      end if 
end while 
 

Thanks Don Cole

new topic     » topic index » view message » categorize

2. Re: scroll in dos

Don: 
 
How about using interrupt 10H in DOS. 
 
http://en.wikipedia.org/wiki/INT_10H 
 
Bernie 

new topic     » goto parent     » topic index » view message » categorize

3. Re: scroll in dos

BRyan said...

Don: 
 
How about using interrupt 10H in DOS. 
 
http://en.wikipedia.org/wiki/INT_10H 
 
Bernie 

Why wouldn't you point Don to the scroll() procedure, BRyan?

This was around in 2.3 (if not earlier) and exists for the DOS versions. You implemented it for EU_ENGIN.E

http://openeuphoria.org/docs/std_graphics.html#_5997_scroll

new topic     » goto parent     » topic index » view message » categorize

4. Re: scroll in dos

Thank you Jim and BRyan,

Could someone show me a small example written in Euphoria version 3. I really don't have version 4 working now.

Thank you,

Don Cole

new topic     » goto parent     » topic index » view message » categorize

5. Re: scroll in dos

DonCole said...

Thank you Jim and BRyan,

Could someone show me a small example written in Euphoria version 3. I really don't have version 4 working now.

Thank you,

Don Cole

I'd recommend looking at the version of ed.ex which comes with version 3.

new topic     » goto parent     » topic index » view message » categorize

6. Re: scroll in dos

jimcbrown said...
DonCole said...

Thank you Jim and BRyan,

Could someone show me a small example written in Euphoria version 3. I really don't have version 4 working now.

Thank you,

Don Cole

I'd recommend looking at the version of ed.ex which comes with version 3.

Thank you Jim,

The problem with ed.ex is that there is too much stuff in there that I don't need.

I'm having trouble picking out the parts that I do need.

All I want is the vertical scroll.

I don't care about editing etc...

Does anyone have some simple code that only does vertical scroll?

TIA

Don Cole

new topic     » goto parent     » topic index » view message » categorize

7. Re: scroll in dos

DonCole said...

Does anyone have some simple code that only does vertical scroll?

Boy, this sure does take me back. I had to bust out DOSBOX for this one! I sort of miss the good ol' days. smile

This little app will display itself on screen and scroll up/down with the arrow keys. Press Escape or 'q' to quit.

include file.e 
include get.e 
include graphics.e 
 
integer fn, rows, top, key 
sequence cmd, lines, vc 
object line 
 
-- get the command line parameters 
cmd = command_line() 
 
-- hold a buffer of lines 
lines = {} 
 
-- open the file 
fn = open( cmd[2], "r" ) 
if fn = -1 then 
    printf( 2, "cannot read file: %s\n", {cmd[2]} ) 
    abort( 1 ) 
end if 
 
-- read all the lines into the buffer 
line = gets( fn ) 
while sequence( line ) do 
 
    -- trim the line 
    while length(line) and find( line[$], " \r\n\t" ) do 
	line = line[1..$-1] 
    end while 
     
    -- append it to the buffer 
    lines = append( lines, line ) 
     
    -- get the next line 
    line = gets( fn ) 
end while 
 
-- close the file 
close( fn ) 
 
-- get the screen configuration 
vc = video_config() 
rows = vc[VC_LINES] 
 
-- turn off cursor and wrap 
cursor(NO_CURSOR) 
wrap(0) 
 
-- track the top row 
top = 1 
 
-- display the initial lines on the screen 
for i = top to length(lines) by 1 do 
     
    position( i, 1 ) 
    puts( 1, lines[i] ) 
     
    if i = rows then 
	-- that's enough 
	exit 
    end if 
     
end for 
 
-- begin key loop 
key = wait_key() 
while key != 27 and key != 'q' do -- escape or 'q' quits 
     
    if key = 328 then -- up 
	 
	-- are there more lines to display? 
	if top > 1 then 
	     
	    -- scroll down 
	    scroll( -1, 1, rows ) 
	    top -= 1 
	     
	    -- write the top line 
	    position( 1, 1 ) 
	    puts( 1, lines[top] ) 
	     
	end if 
	 
    elsif key = 336 then -- down 
	 
	-- are there more lines to display? 
	if (top + rows - 1) < length(lines) then 
	     
	    -- scroll up 
	    scroll( 1, 1, rows ) 
	    top += 1 
	     
	    -- write the bottom line 
	    position( rows, 1 ) 
	    puts( 1, lines[top+rows-1] ) 
	     
	end if 
	 
    end if 
     
    key = wait_key() 
end while 

Enjoy!

-Greg

new topic     » goto parent     » topic index » view message » categorize

8. Re: scroll in dos

ghaberek said...
DonCole said...

Does anyone have some simple code that only does vertical scroll?

Boy, this sure does take me back. I had to bust out DOSBOX for this one! I sort of miss the good ol' days. smile

This little app will display itself on screen and scroll up/down with the arrow keys. Press Escape or 'q' to quit.

include file.e 
include get.e 
include graphics.e 
 
integer fn, rows, top, key 
sequence cmd, lines, vc 
object line 
 
-- get the command line parameters 
cmd = command_line() 
 
-- hold a buffer of lines 
lines = {} 
 
-- open the file 
fn = open( cmd[2], "r" ) 
if fn = -1 then 
    printf( 2, "cannot read file: %s\n", {cmd[2]} ) 
    abort( 1 ) 
end if 
 
-- read all the lines into the buffer 
line = gets( fn ) 
while sequence( line ) do 
 
    -- trim the line 
    while length(line) and find( line[$], " \r\n\t" ) do 
	line = line[1..$-1] 
    end while 
     
    -- append it to the buffer 
    lines = append( lines, line ) 
     
    -- get the next line 
    line = gets( fn ) 
end while 
 
-- close the file 
close( fn ) 
 
-- get the screen configuration 
vc = video_config() 
rows = vc[VC_LINES] 
 
-- turn off cursor and wrap 
cursor(NO_CURSOR) 
wrap(0) 
 
-- track the top row 
top = 1 
 
-- display the initial lines on the screen 
for i = top to length(lines) by 1 do 
     
    position( i, 1 ) 
    puts( 1, lines[i] ) 
     
    if i = rows then 
	-- that's enough 
	exit 
    end if 
     
end for 
 
-- begin key loop 
key = wait_key() 
while key != 27 and key != 'q' do -- escape or 'q' quits 
     
    if key = 328 then -- up 
	 
	-- are there more lines to display? 
	if top > 1 then 
	     
	    -- scroll down 
	    scroll( -1, 1, rows ) 
	    top -= 1 
	     
	    -- write the top line 
	    position( 1, 1 ) 
	    puts( 1, lines[top] ) 
	     
	end if 
	 
    elsif key = 336 then -- down 
	 
	-- are there more lines to display? 
	if (top + rows - 1) < length(lines) then 
	     
	    -- scroll up 
	    scroll( 1, 1, rows ) 
	    top += 1 
	     
	    -- write the bottom line 
	    position( rows, 1 ) 
	    puts( 1, lines[top+rows-1] ) 
	     
	end if 
	 
    end if 
     
    key = wait_key() 
end while 

Enjoy!

-Greg

THANK YOU GREG,

That's exactly what I was looking for.

Sigh! (of relief)

Don Cole

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu