Back to home page

DOS ain't dead

Forum index page

Log in | Register

Back to the forum
Board view  Mix view

How to keep resident only a part of the program (Developers)

posted by tom Homepage, Germany (West), 14.08.2021, 11:28

> Hello Laaca,
>
> > I am thinking about very tiny resident utility which hooks the INT16
> > interrupt. I know that "high-level" languages like pascal or C have
> > something like function Keep (which apparently calls INT21h/AH=31h). But
>
> Actually the int 0x21, ah = 0x31 interface does allow one to specify how
> many paragraphs of memory one wants to keep resident. Turbo C and Watcom C
> also accept a paragraph count as a parameter to keep(...) and
> (respectively) _dos_keep(...).
>
> But it might be hard to use this correctly in the context of high-level
> code. You need to arrange your program binary code in such a way that the
> resident portions will come before (most of) the transient portions (and
> you must take library functions into account too...). I am not sure what
> features Free Pascal (e.g.) has that might facilitate this sort of thing.
>
> > Is possible solution to allocate a additional memory block via
> > INT21h/AH=48h, copy the code of KeyClick into this block and the program
> > end not with Keep but hith Halt?
>
> That will likely not work --- DOS will free up all memory blocks
> allocated by your program, including those from int 0x21, ah = 0x48.

while true (this wouldn't work), you can make it work by using the undocumented feature that DOS_realloc(para, size) also sets the PSP of the allocated memory, and on exit(), DOS will only free allocated memory with your PSP.

so a sequence like

needed_bytes = 1024;

resident_seg = DOS_alloc(needed_bytes);

my_PSP = DOS_GET_PSP();

DOS_SET_PSP(0x60); program 0x60 will never exit

DOS_realloc(resident_seg, needed_bytes);

DOS_SET_PSP(my_PSP);

memcpy(MK_FP(resident_seg,0), my code, needed_bytes);

point interrupt vector to the copied code
...

exit()


would work in principle (remove the large program from memory, leave needed_bytes in memory).

of course, your code would really quickly implode because you are calling the runtime library (sound(), delay()) and you have little to no control over where the runtime will be loaded.

time to change the language:-D

Pascal is just not the right language for this kind of stuff.

 

Complete thread:

Back to the forum
Board view  Mix view
22049 Postings in 2034 Threads, 396 registered users, 47 users online (0 registered, 47 guests)
DOS ain't dead | Admin contact
RSS Feed
powered by my little forum