问题
I would like to know how can we change the letters of the characters on screen using C. It is a TSR program using dos.h header file.
回答1:
I might be able to help partially from what i remember of my early undergrad.
In DOS, the address 0xB8000000 (0xB800:0 as segment:offset rightly pointed out in comments) is the starting address of text mode video memory (0xA8000000 being that for graphics). Any thing written into this area is copied directly to vga card. Now every character on the screen is made up of two bytes. First byte was the ascii character and second was the color.
So effectively you take a far pointer in 16 bit c (since a normal near pointer won't do) and assign it the above address. Then assuming your screen size (25*80) or whatever * 2 is the total number of single byte addresses filling your screen.
I remember having written the equivalent of a trivial printf function using above.
Getting back to your problem, you have to write code which loops through all even addresses starting from above address till screen size. Even address because odd one represents color. There it checks if the assigned character is valid ascii and add or subtract according to needs e.g. 'A' + 32 would get you 'a' and so on.
Question remains about when your above program does this. I believe you can have some interrupt or similar thing in dos.h which triggers every time any screen character is changed. But this part is not very clear in my memory.
See if that works for you.
来源:https://stackoverflow.com/questions/12825511/tsr-program-to-change-case-of-characters-on-screen-in-windows-dos