Let Us C (Chapter 8 : Arrays) : Program-9
(i) The screen is divided into 25 rows and 80 columns. The characters that are displayed on the screen are stored in a special memory called VDU memory (not to be confused with ordinary memory). Each character displayed on the screen occupies two bytes in VDU memory. The first of these bytes contains the ASCII value of the character being displayed, whereas, the second byte contains the colour in which the character is displayed. For example, the ASCII value of the character present on zeroth row and zeroth column on the screen is stored at location number 0xB8000000. Therefore the colour of this character would be present at location number 0xB8000000 + 1. Similarly ASCII value of character in row 0, col 1 will be at location 0xB8000000 + 2, and its colour at 0xB8000000 + 3. With this knowledge write a program which when executed would keep converting every capital letter on the screen to small case letter and every small case letter to capital letter. The procedure should stop the moment the user hits a key from the keyboard. This is an activity of a rampant Virus called Dancing Dolls. (For monochrome adapter, use 0xB0000000 instead of 0xB8000000).
// Let Us C (Chapter 8 : Arrays) : Program-9
/* The screen is divided into 25 rows and 80 columns. The characters that are displayed on the screen are stored
in a special memory called VDU memory (not to be confused with ordinary memory). Each character displayed on the
screen occupies two bytes in VDU memory. The first of these bytes contains the ASCII value of the character being
displayed, whereas, the second byte contains the colour in which the character is displayed. For example, the ASCII
value of the character present on zeroth row and zeroth column on the screen is stored at location number 0xB8000000.
Therefore the colour of this character would be present at location number 0xB8000000 + 1. Similarly ASCII value of
character in row 0, col 1 will be at location 0xB8000000 + 2, and its colour at 0xB8000000 + 3. With this knowledge
write a program which when executed would keep converting every capital letter on the screen to small case letter and
every small case letter to capital letter. The procedure should stop the moment the user hits a key from the keyboard.
This is an activity of a rampant Virus called Dancing Dolls. (For monochrome adapter, use 0xB0000000 instead of 0xB8000000) */
#include<stdio.h>
#include<conio.h>
#include<dos.h>
#define MEMORY_SIZE 3999 // 80 x 25 x 2 bytes = 4000 bytes
void main()
{
char far *vidmem = 0xB8000000; // video memory address row & column zero
int i, position = 0, Cap = 65, Small = 97; // Capitals from 65 to 90, Smalls from 97 to 122
for(i=0;i<=MEMORY_SIZE;i+=2)
{
if (position % 2 == 0) // Capital letter at Even places
{
*(vidmem + i) = Cap++;
if (Cap > 90) // reset on range exceeded
{
Cap = 65;
}
}
else // Small letter at Odd places
{
*(vidmem + i) = Small++;
if (Small > 122) // reset on range exceeded
{
Small = 97;
}
}
position++;
}
while(!kbhit()) // Check for key hit
{
for(i=0;i<=MEMORY_SIZE;i+=2)
{
if(*(vidmem + i) >= 'A' && *(vidmem + i) <= 'Z')
*(vidmem + i) += 32;
else
{
if(*(vidmem + i) >= 'a' && *(vidmem + i) <= 'z')
*(vidmem + i) -= 32;
}
}
delay(500); // wait for 200 ms
}
}
OUTPUT
Comments
Post a Comment