Working with video memory using far pointers

VERY INTERESTING 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?

#include<stdio.h>

int main(){

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

*ptr='A';
*(ptr+1)=4;

return 0;
}

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?

#include<stdio.h>

int 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;

return 0;
}

Output:



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

#include<stdio.h>

int 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;

return 0;
}

Output:



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

#include<stdio.h>

//Mixture of basic color
int main(){

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

*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;

return 0;
}

Output:



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

#include<stdio.h>

//To increase the intensity of color.
int 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;

return 0;
}

Output:



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

#include<stdio.h>

// for background color
int 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;

return 0;
}

Output:



Generic pointer
Null pointer
Wild pointer
Dangling pointer
Near pointer
Far pointer
Graphics video memory
Text video memory
Huge pointer
Memory model in C
C tutorial

6 comments:

ROHIT said...

wow.! thanks

ROHIT said...

superb.....

VishwasJain said...

excellent.................keep it up

Harsha said...

Awesome ! Thanks

Neeru RS said...

fantastic

Sheela Gavi said...

what is smart pointer ..can you explain plz