1. Fastest Print to Screen
I stumbled across "perform.doc" and read that puts ain't the way to go
for speed. I tried display_text_image() but apparently it would be a
pain to parse out the sequence I want printed with all the colors in
between, or maybe it wouldn't.
Is putsxy faster?! I should have thought of that already.
Anyway, any comments on the fastest way to get text to a text-screen
would be appreciated.
Thanks!
ck
2. Re: Fastest Print to Screen
- Posted by Ralf Nieuwenhuijsen <nieuwen at XS4ALL.NL>
Nov 23, 1998
-
Last edited Nov 24, 1998
>I stumbled across "perform.doc" and read that puts ain't the way to go
>for speed. I tried display_text_image() but apparently it would be a
>pain to parse out the sequence I want printed with all the colors in
>between, or maybe it wouldn't.
Putsxy is for graphics modes.
No, you want to poke your data to the memory.
Here's a fast, text-mode only version, it clips at 25,80
But you can easily change the constants.
The code has been tested by me.
-- Fast display_text_image and save_text_image
constant
BPC = 2, -- 2 bytes per char (one for the color)
CLIP_Y = 25, -- 25 lines down
CLIP_X = 80 * BPC, -- 80 columns right
VIDEO = #B8000 -1, -- Use #B0000 for monochrome
FALSE = 0
global procedure display_text_image (sequence pos, sequence data)
integer skip, max_width, max_height, pos_x, begin, offset
sequence row
-- Calculating offset
pos_x = pos[2] * BPC - 1
offset = pos_x + (pos[1]-1) * CLIP_X + VIDEO
-- Check if the offset is out-of-bounds
if offset <= VIDEO then
skip = VIDEO - offset + 1
offset = VIDEO - 1
else
skip = FALSE
end if
-- Set the maximum length for each row
max_width = CLIP_X - pos_x
begin = FALSE
for skip_index = 1 to length(data) do
if not skip then
if length(data)-skip_index > CLIP_Y then
max_height = skip_index + CLIP_Y
else
max_height = length(data)
end if
for index = skip_index to max_height do
row = data[index]
if length(row) > max_width then
if begin then
poke (offset, row[begin..begin+max_width])
else
poke (offset, row[1..max_width+1])
end if
else
if begin then
poke(offset,row[begin..length(row)])
else
poke (offset, row)
end if
end if
offset = offset + CLIP_X
end for
exit
end if
if skip < CLIP_X then
begin = skip
skip = FALSE
else
skip = skip - CLIP_X
end if
end for
end procedure
--- End of code
3. Re: Fastest Print to Screen
>I stumbled across "perform.doc" and read that puts ain't the way to go
>for speed. I tried display_text_image() but apparently it would be a
>pain to parse out the sequence I want printed with all the colors in
>between, or maybe it wouldn't.
Ralf already gave you code for saving and displaying text images, but I
think you are looking for is a fast(er) way to put characters and strings=
directly to the screen.
What you are searching for, is maybe this: routines to write sequences
directly to the video memory, including cls() - a fast clear screen - and=
clreol() - clear to end of line.
The procedure write() has the parameters row, column, colors (fore- and
background) and the sequence to write.
I found it somewhere, some of the routines are contributed by others.
Careful tho.. you need to check if the row and column coordinates are on
screen.
-- begin Euphoria code
include graphics.e
constant TextRows =3D text_rows(28) -- my favorite resolution
constant ScrLen =3D TextRows * 80
global sequence Screen
Screen =3D repeat(' ', ScrLen + ScrLen)
sequence vc
vc =3D video_config()
constant so =3D #B8000 -- the adress of the start of (color) video mem=
ory
procedure cls(integer BkColor, integer TxtColor)
-- clear screen *and* set atrributes
integer attrib
attrib =3D TxtColor + (16 * BkColor)
for ch =3D 1 to ScrLen do
Screen[ch + ch] =3D attrib
end for
poke(so, Screen)
end procedure -- cls()
procedure write(integer row,integer col,integer a,sequence s)
sequence sa
sa =3D repeat(a, length(s) + length(s))
for i =3D 1 to length(s) do
sa[i + i - 1] =3D s[i]
end for
poke(so+((row-1)*80+col-1)*2,sa)
end procedure -- write
procedure clreol(integer TxtColor, integer BkColor)
-- clear to end of line, with given attribute
integer attrib
sequence CurPos
attrib =3D (#10 * BkColor) + TxtColor
CurPos =3D get_position()
write(CurPos[1], CurPos[2], attrib, repeat(' ', 80-CurPos[2]))
position(CurPos[1], CurPos[2])
end procedure -- clreol()
procedure char(integer row, integer col, integer ch, integer a)
-- put a single character on the screen
-- a is text attribute: a =3D text_color + 16*background_color
-- it is easier in the hexadecimal notation: e.g. #1F is bright
-- white text (F) on blue background (1)
poke(so+((row-1)*80]+col-1)*2,{ch,a})
end procedure -- char
4. Re: Fastest Print to Screen
- Posted by C & K L <candk at TICNET.COM>
Nov 23, 1998
-
Last edited Nov 24, 1998
Thank you, Ad... I'll try the code out tonight and see what kinda
performance boost I can get.
5. Re: Fastest Print to Screen
On Mon, 23 Nov 1998 12:38:08 -0600, C & K L <candkNOSPAM2ME at TICNET.COM>
wrote:
>I stumbled across "perform.doc" and read that puts ain't the way to go
>for speed. I tried display_text_image() but apparently it would be a
>pain to parse out the sequence I want printed with all the colors in
>between, or maybe it wouldn't.
>
>Is putsxy faster?! I should have thought of that already.
>
>Anyway, any comments on the fastest way to get text to a text-screen
>would be appreciated.
>
>Thanks!
>ck
A few routines for fast screen printing/puting are
available in the Euphoria Archive. Hilley's Utilities.
It is one of the very few things that are included in the library.
Test them out and see what you think. The file is rather small.
http://members.aol.com/FilesEu/llh-e.zip
_________________________
Lucius L. Hilley III lhilley at cdc.net
http://www.cdc.net/~lhilley
http://www.americanantiques.com
http://www.dragonvet.com
_________________________