As a preface, I really do not want the exact solution to my problem, just guidance. I don’t want you to give me the code. This isn’t homework, it’s just an exercise I’m trying to solve.
I just want you to tell me how to access VDU and directly change character on same screen.
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.
My task:
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).
Really I don’t have any idea to build this code. I’m stuck at even getting started.
You are referring to what was once called the video refresh buffer. It’s important to state that Dancing Dolls was a virus for DOS.
Basically, you are expecting video memory to be at address
0xB8000000on your program’s memory. However, modern Operating Systems (like Linux/Windows/Mac OS X) provide a virtual memory mechanism that prevents applications from manipulating devices directly. So the0xB8000000address your application sees is not the physical address0xb8000000that corresponds to the video refresh buffer. The last post of this thread also has some interesting info on this subject.Nevertheless, the technique you are interested in is still valid for 16-bit DOS and is covered on the book Assembly Language Step-by-step: Programming with DOS and Linux. This book has a great section on chapter 6 that explains how this work exactly. The section is named
Inspecting the Video Refresh Buffer with DEBUG, and has an interesting example that shows how to use debug.exe to access the video memory and modify it. I tested it successfully on cmd.exe of my Win 7 box.But if you want to manipulate the screen of a Linux terminal, check ncurses: