TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: JAMES NORMAN
from: ROGER SCUDDER
date: 1997-09-24 13:46:00
subject: creating ascii screens

Hi JAMES,
JAMES NORMAN was observed on 24-Sep-97, writing to ANYONE
          Something about: creating ascii screens
 JN> hi, im trying to write a C++ function that will display a screen of a
 JN> certain ascii character, however when running the program it appears 
ery
 JN> slow :( here is the code ...
 JN>
 JN> void screen(int fc, int bc, char sym) {
 JN>
 JN>         textcolor(fc); textbackground(bc);
 JN>         int i = 0;
 JN>         int j = 0;
 JN>         for (i= 1; i <= 25; i++) {
 JN>                 for (j = 1; j <= 80; j++) {
 JN>                         cprintf("%c", sym);
 JN>                 }
 JN>         }
 JN> }
 JN> // I call the function like this .... screen(15, 1, '*');
 JN> // takes a while for the screen to come up...just wondering if there is 

 JN> better way to do this...any help would be much appreciated...thanx!!!!
 /* ---------------------[cut here]------------------------ *
 The fastest way I know is to use what is called a virtual
 screen.  It's a buffer the size of the screen that you
 make changes to and then copy to the real screen.
 Your DOS text screen is made up of character cells as you
 noted in your code 25 rows and 80 cols (never assume this!).
 Each cell uses one unsigned int a.k.a. a WORD.   The low
 byte stores the character and the high byte stores the
 attribute.
 * ------------------------------------------------------- */
 #include 
 typedef unsigned char BYTE;
 #define SCREENCOLS   80  // wrong way to get these! values
 #define SCREENROWS   25  // should be set at runtime!
 #define SCREENSIZE   SCREENCOLS * SCREENROWS * 2
 void screen(int fc, int bc, char sym) {
     // store color attributes in a variable
     BYTE scolor = (fc) | ((bc) << 4 );
     // allocate memory for a virtual screen
     BYTE *vscreen = new BYTE[SCREENSIZE];
     // set the character byte (low byte)
     for (int i = 0; i < SCREENSIZE; i += 2)
         vscreen[i] = sym;
     // set the attribute byte (high byte)
     for (i = 1; i < SCREENSIZE; i += 2)
         vscreen[i] = scolor;
     // copy buffer to screen
     puttext( 1, 1, 80, 25, vscreen );
     // release virtual screen memory
     delete []vscreen;
 }
 /* ---------------------[cut here]------------------------ *
 Run this code and you will be pleasantly surprised!
 I'm sure there are faster algorithms than this one and
 I'd like it if people posted some of them. ;-)
 Oh yeah, always compile graphics (including text mode)
 code using the large memory model to be safe.
 ie; tcc -ml filename  or if compiling in the IDE go to
 options|compiler|code generation and make sure it's set
 to large model.
 Roger Scudder
 rogers@gim.net
--- Terminate 5.00/Pro
 * TerMail/QWK * Terminate = Pointmailer+Tosser+Reader+Packer+QWK!
--- WILDMAIL!/WC v4.12 
---------------
* Origin: FIDONET * Remote Control BBS * 610-623-5273 * (1:273/420.0)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.