cys@engin.umich.edu (CAO YUSONG ) (02/22/91)
I am writing a TP program as an exercise. The program is a TSR clock which displays the time on screen. The program captures the interrupt $1c. After the initialization. I use "Keep(3)" to terminate the program to hope it can stay resident. My problems are: 1. After I run the program, DOS gave me the following message "Memory allocation error Can not load COMMAND.COM" Then the machine freeses. I have to hard-boot it. I didn't compile it with "Force FAR calls" on, can that be a problem? 2. In the intertupt handling routine, I couldn't seem to use Readln, and Keypressed, but I could use other stuff like GetTime, Writeln, etc. .. Could someone explain? Thanks. Please use address jzeng@norway.biop.umich.edu if you want to e-mail. -- Jim Zeng
CDCKAB%EMUVM1.BITNET@cunyvm.cuny.edu ( Karl Brendel) (02/22/91)
In article <1991Feb21.170654.3759@engin.umich.edu>, cys@engin.umich.edu (CAO YUSONG) wrote: >I am writing a TP program as an exercise. The program is a TSR clock >which displays the time on screen. The program captures the >interrupt $1c. After the initialization. I use "Keep(3)" to >terminate the program to hope it can stay resident. My problems are: > 1. After I run the program, DOS gave me the following message > "Memory allocation error > Can not load COMMAND.COM" > Then the machine freeses. I have to hard-boot it. > I didn't compile it with "Force FAR calls" on, can that be a > problem? > 2. In the intertupt handling routine, I couldn't seem to use > Readln, and Keypressed, but I could use other stuff like > GetTime, Writeln, etc. .. Could someone explain? First, a general remark: Everybody interested in writing TSR programs is strongly urged to get a reliable library, such as TSRME (by TurboPower) or TeSseRact (Shareware) or some detailed example code such as StayRes (by Lane Ferris, I believe). Particularly if they are at all tempted to release their programs for distribution, I would recommend the library approach. Indeed, I would beg them to go that route, and would even buy them library for them if that were feasible--which is isn't, so don't call me on that one. :) Now to specifics: "After I run the program,..." When does the allocation error occur? Immediately after the Keep, or sometime later? If immediately, is it possible that you are allocating the default heap? Your program probably doesn't need any heap, so it should have {$M some_little_number,0,0}. I wouldn't think that FAR calls should be a problem, as long as the interrupt handler itself is FAR. I have read both that declaring a routine to be an interrupt handler automatically makes it FAR and that it needs to be explicitly declared FAR. I don't know which is true, so I would put {$F+} {$F-} around the procedure. As for the availablility of various routines from your interrupt handler (indeed, from the entire program after going resident): The availibility of DOS functions depends on DOS' state at the time. (An understanding of when you can call DOS functions is best gained from studying the recommended libraries, or commented code, or references such as the _MS-DOS Encyclopedia_.) Turbo Pascal does not track the availibilty of DOS calls. That is up to the programmer. If you call a TPas routine that calls DOS, when DOS is not available, "undefined results" are to be expected. ;) A final note: The (5.X) Keep documentation states: Use with care! Terminate Stay Resident (TSR) programs are complex and _no_ other support for them is provided. Well, they warned you. ;) +--------------------------------------------------------------------+ | Karl Brendel Centers for Disease Control | | Internet: CDCKAB@EMUVM1.BITNET Epidemiology Program Office | | Bitnet: CDCKAB@EMUVM1 Atlanta, GA, USA | | Home of Epi Info 5.0 | +--------------------------------------------------------------------+