CS-220, Sec. 50, 51
Lab # 8, 4-20-06, 4-27-06
Report Due Date: 5-4-06

In this lab you are to write a terminate-and-stay resident (TSR), COM-file
format assembly language program for a PC-compatible computer that installs
two interrupt service routines (ISRs). These ISRs will intercept the PC's
timer tick (type 8) interrupt and its keyboard (type 9) interrupt in order
to display a "digital clock" in the upper lefthand corner of the screen.
This clock should have a minutes digit, a colon, and two seconds digits.
(You may assume that the clock will never run for more than 9 minutes and
59 seconds.) The display should be something like the following:

m:ss

where m will be the number of minutes (0-9) that have gone by since the
program began execution and ss the number of seconds (00-59) that have gone
by. The <F1>, <F2>, and <F3> keys will be used to "turn on" the digital
clock display, "turn off" the digital clock display, and reset the digital
clock display, respectively.

The ISR that intercepts the timer tick interrupt should update the seconds
(and minutes when necessary) every time one second has passed (i.e., every
18 timer ticks). After the update, control should be transfered to the old
timer tick interrupt service routine. If the display is "turned on" the
current time should be displayed as red characters on a green background
in the upper left-hand corner of the screen. This should be done by
accessing the video RAM directly, as explained in class. You may assume
that the computer has been set to its default text video mode (mode 3,
which is 80 X 25 X 16 colors). You are not to use int 10h services here.

The ISR that intercepts the keyboard interrupt should determine if the key
that was pressed was an <F1>, an <F2>, or an <F3>. If it was <F1>, the
display update should be "turned on". In other words after the user presses
<F1>, subsequently the upper lefthand corner of the display will be
updated every second. If the key pressed was <F2>, the display update
should be "turned off". In other words no subsequent display updates should
occur every second. (In fact, if the upper lefthand corner of the screen is
written to by whatever program is executing, the digital clock display will
be overwritten and should disappear--until the user presses the <F1> key
again to re-enable the display update.) Notice that even though the display
update is turned off, your TSR program should continue to keep track of how
much time has gone by. If the key that was pressed was <F3>, the time
should be reset to 0:00. Any other key press should cause control to be
transfered to the old keyboard interrupt service routine. (This should also
occur after the <F1>, <F2>, and <F3> keys have been processed.)

Your program should follow the general structure of the one-second beeper
program that was discussed in class and that is on one of the CS-220
"Sample Programs" web pages. (The new INT 8 ISR will, of course, have to
do more than just beep every time 18 timer ticks have gone by--namely, it
will have to write correct values to the correct Video RAM addresses so
that the display is updated if the display update is "turned on".) In
addition, your program will have to install a new INT 9 interrupt service
routine. This will mean adding some code to the "ldnvec" section of the
program that saves the old INT 9 vector and sets up the new INT 9 vector.
It will also mean adding a new section that might be called newisr9, in
which the code responds to the keyboard interrupt as described above. The
main idea here is that every time the keyboard interrupt comes along, the
scan code for the key pressed will be in port 60h. All your newint9 code
needs to do is input from that port, determine if the scan code is that of
the <F1>, <F2>, or <F3> key (3bh, 3ch, or 3dh, respectively), and set
appropriate variables before jumping to the old INT 9 handler.

You should demonstrate your program to the lab instructor. If that is not
possible you should turn in a diskette or CD with both the source code (.asm)
and the excutable (.exe). While the program is running, the computer user
should be able to perform other tasks. In other words, the DOS prompt
should be there, and the system should respond to DOS commands as usual.

You should submit the standard documentation--i.e., a readable, well-
documented .LST file, a hierarchy chart for the program, and flow charts
for the "ldnvec" part and for each each ISR.

EXTRA CREDIT POSSIBILITIES

For extra credit you may want to try one or more of the following:

Make the display move around on the screen. In other words, every so many
seconds the display should appear at some new place on the screen.

Make the "digital clock" become an "analog clock" in which a "second hand"
and a "minute hand" are drawn. This will be much more complex as it entails
drawing different straight lines on the screen. (The number of extra points
will be more as well.)