🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: att.lang.c++
Article #169

Re: Help- c programming

#169
From: Robert Byrne
Date: Thu, 01 Apr 1999 00:00
90 lines
3314 bytes
You making life a bit hard for yourself using printf. Just write directly to
memory and remember that in text mode each character is a word, the first 4
bits is the background colour the next 4 bits are the foreground colour and
the next 8 bits is the ascii value for the character, so writing 0x0020 to
each cell with totally clear it.


void CLRSCR ( int UX,  // upper left X-coord
                       int UY,  // upper left Y-coord
                       int LX,  // lower right X-coord
                       int LY)  // lower right Y-cord
 {
  // check that short is a 16bit type
   unsigned short far *txtMem = ( unsigned short * ) 0xb8000000 ;
  // your UY and LY values are probably between 1-25 so translate them to 0
based
  UY -- ;
  LY -- ;
  // and same idea for UX and LX
  UX -- ;
  LX -- ;
  short i ;

  // add your upper Y times the screenwidth to the top corner
  txtMem += UY * 80 ;

  while( UY < LY ) {
     for( i = UX ; i < LX ; i++ ) {
         txtMem[i] = 0x0020 ;
     }
     // move to the next line
     txtMem += 80 ;
     UY ++ ;
  }
}

you could speed up the inner for loop by having a long pointer and writing
0x00200020 to each cell and cut the loop in half.

if your have trouble gis a shout
bobby@tinet.ie



----- Original Message -----
From: slamdunk <slamdunk@usa.com>
Newsgroups: att.lang.c++
Sent: Saturday, March 27, 1999 10:49 PM
Subject: Help- c programming


>The problem is in the "for" loop of the CLRSCR function.  Why doesn't
>it work?  Hints?
>
>#include <stdio.h>
>#include <stdlib.h>
>/***********Beginning memory location of color videomemory**********/
>#define VIDEOMEMORY (char far *) 0xb8000000L
>#define BLACK       (char) 0
>
>void FILLSCREEN(char c) {      // fills screen with character 'C'
> int x,y;
> for (y=1; y<=24; y++)       // for each Y-coord 1..24
> for (x=1; x<=80; x++)    // for each X-coord 1..80
> printf("%c", c);
>}
>
>void CLRSCR ( int UX,  // upper left X-coord
>             int UY,  // upper left Y-coord
>             int LX,  // lower right X-coord
>             int LY)  // lower right Y-coord
> {
>             char far *c;  // pointer into videomemory
>   int y,        // outer loop counter
>       x;        // inner loop couter
>
>
> for (y=UY; *(c + y) < *(c + LY); y+=2)
> { for (x=UX; *(c + x) < *(c + LX); x+=2)
>   { printf("%c",0); }
>   }
>   }
>
>void main (void) {
> FILLSCREEN ('X');      // fills screen with 'X'
> CLRSCR (10,10,70,20);   // cut a hole in the middle of the
>
>                                                       //  screen
>}
Technical Details
Message-ID: <7e0fig$9nd$1@scotty.tinet.ie>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <36fd5254.150669080@news.erols.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10d4ba,da90caff31ed307e
X-Google-Attributes: gid10d4ba,public
From: "Robert Byrne" <bobby@tinet.ie>
Subject: Re: Help- c programming
Date: 1999/04/01
Message-ID: <7e0fig$9nd$1@scotty.tinet.ie>
X-Deja-AN: 461666917
References: <36fd5254.150669080@news.erols.com>
X-Priority: 3
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.0810.800
X-Complaints-To: newsmaster@tinet.ie
X-Trace: scotty.tinet.ie 922993040 9965 159.134.227.21 (1 Apr 1999 18:57:20 GMT)
Organization: Telecom Internet (http://www.tinet.ie/)
X-MSMail-Priority: Normal
NNTP-Posting-Date: 1 Apr 1999 18:57:20 GMT
Newsgroups: att.lang.c++