Frage

While studying tsr programming i have seen the use of certain code which i cannot understand..

The example cede part is(in c): (please explain the bolded sections)

#include "dos.h"
#include"stdio.h"
void interrupt our();
void interrupt (*prev)();
char far *scr=(char far*)0xB8000000L;
int ticks;
unsigned char color;
main()
{   
    prev=getvect(8);   // <<<<<
    setvect(8,our);    // <<<<<
    keep(0,10000);     // <<<<<
}
War es hilfreich?

Lösung

You would partially understand this code if you read the answer i posted to your similar question on TSR

How to write a TSR which changes case of characters

The most important things here are

Far pointer: Since 16 bit DOS used segment offset addressing scheme, your normal near pointer could not access memory beyond 64K of it's allocated segment. You have to read details to understand it.

Video memory address: This B8000000 is the address for which you need far pointer. The special thing about this address is, that starting from this location bytes (equal to the resolution of screen * 2) are copied directly into video memory.

So if you assign a character to a pointer address after indirection it will be printed on screen

Something like

char * far p = 0xB8000000;

*p = 'a'; // this would actually print a on screen at left top

Loop forward to get to the rest of the screen.

There was a c book by yashwant kanetkar which had a good deal of reference for this. I remember using it in my undergrad many years ago.

The rest of them are just indexing api's in dos.h. Why don't you go through their description and get back here if you don't understand any?

Andere Tipps

This program installs an interrupt handler. It uses interrupt number 8, the system timer interrupt. This was a common practice to use this interrupt to "continuously" do stuff on a machine running DOS.

prev=getvect(8);

This line gets the interrupt vector, that is, a pointer to a function that the system calls 18 times per second.

setvect(8,our);

This line sets the interrupt vector, that is, tells the system to call this function, instead of the old function, 18 times per second. Note that to avoid a crash, the new function must call the old function, in addition to its main purpose (which seems to be changing the case of characters).

keep(0,10000);

This line makes the program with exit code 0 (a conventional value for success) and tells DOS to leave 10000 bytes (or maybe 16-byte units? Unlikely; I don't remember) in RAM. This is unlike normal completion of program (exit(0)), where DOS marks all RAM previously occupied by the program as free.

A common cause of a crash in a TSR program is caused by the absence of keep at the end. DOS releases the memory occupied the by the code of the function our, and in the next 1/18 of a second, a random piece of code is executed.

See Int 21/AH=31h for more information.

Please note also that the parameter to keep should be calculated by manipulating some addresses, so that you don't take too much memory, and on the other hand, take enough memory to contain the code of the function our, which performs the stuff you need. The value 10000 is just an example.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top