Google Search

Custom Search

Sunday, February 14, 2010

Working with Video Memory Using far Pointers VERY INTESTING THING:

Video Memory

Segment number 0XA and 0XB is known as video memory. There are two types of video memory.

(a) Text video memory
(b) Graphics video memory

(a) Text video memory:
Segment number 0XB is known as text video memory. This segment is divided into 25 rows and 80 columns which creates 80*25=2000 cells.
Size of each cell is two byte. Each cell is divided into two parts each of size one byte.

(a) Text byte: First byte stores character information. It stores character as ASCII code.

(b) Color byte: Second byte stores color information of text byte character.

In other word we can say each even byte stores character and each odd byte stores color.
Simple example:

(q)What will be output of following c program?

void main(){
int i;
char far *ptr=(char *)0XB8000000;
*ptr='A';
*(ptr+1)=4;

}
Output: It will display character A in the red color as shown following screen dump:





Color scheme:




Color byte of size 8 bit stores the color information in the following manner.




First four bits stores color information of character.


0000 0001: Blue color (1)

0000 0010: Green color (2)

0000 0100: Red color (4)

0000 1000: To increase the intensity of color. (8)


Note: Any other number will generate mixture of above four basic colors.


Next four bits stores color information of background of character.


0001 0000: Blue color (16)

0010 0000: Green color (32)

0100 0000: Red color (64)

1000 0000: To increase the intensity of color. (128)


Note: Any other number will generate after mixing of above four basic colors.


Examples:


(1)What will be output of following c program?


void main(){

int i;

char far *ptr=(char *)0XB8000000;

*ptr='A';

*(ptr+1)=1;

*(ptr+2)='B';

*(ptr+3)=2;

*(ptr+4)='C';

*(ptr+5)=4;


}


Output:






(2)What will be output of following c program?



void main(){

int i;

char far *ptr=(char *)0XB8000000;

*ptr='W';

*(ptr+1)=1;

*(ptr+2)='O';

*(ptr+3)=2;

*(ptr+4)='R';

*(ptr+5)=4;

*(ptr+6)='L';

*(ptr+7)=1;

*(ptr+8)='D';

*(ptr+9)=2;


}


Output:





(3)What will be output of following c program?

//Mixture of basic color


void main(){

int i;

char far *ptr=(char *)0XB8000000;

clrscr();

*ptr='W';

*(ptr+1)=3;

*(ptr+2)='O';

*(ptr+3)=5;

*(ptr+4)='R';

*(ptr+5)=6;

*(ptr+6)='L';

*(ptr+7)=7;

*(ptr+8)='D';

*(ptr+9)=3;


}


Output:





(4)What will be output of following c program?

//To increase the intensity of color.


void main(){

int i;

char far *ptr=(char *)0XB8000000;

*ptr='P';

*(ptr+1)=1+8;

*(ptr+2)='O';

*(ptr+3)=2+8;

*(ptr+4)='I';

*(ptr+5)=3+8;

*(ptr+6)='N';

*(ptr+7)=4+8;

*(ptr+8)='T';

*(ptr+9)=5+8;

*(ptr+10)='E';

*(ptr+11)=6+8;

*(ptr+12)='R';

*(ptr+13)=7+8;


}


Output:





(5)What will be output of following c program?

// for background color


void main(){

int i;

char far *ptr=(char *)0XB8000000;

*ptr='M';

*(ptr+1)=4+32;

*(ptr+2)='A';

*(ptr+3)=4+32;

*(ptr+4)='N';

*(ptr+5)=4+32;

*(ptr+6)='I';

*(ptr+7)=4+16;

*(ptr+8)='S';

*(ptr+9)=4+16;

*(ptr+10)='H';

*(ptr+11)=4+16;


}


Output:



No comments: