🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

2 total messages Started by slamdunk Sat, 27 Mar 1999 00:00
Help- c programming
#166
Author: slamdunk
Date: Sat, 27 Mar 1999 00:00
38 lines
1704 bytes
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
}
Re: Help- c programming
#169
Author: 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
>}
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads