POLLED WAITING LOOPS - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

POLLED WAITING LOOPS

athlonxlathlonxl Posts: 1Member
having trouble with a program.
The program should monitor the keyboard, waiting for a keystroke. While no keystroke is entered,it should do something else, such as display the current time, or display a counter. Something visual is good, so that we can see something is happening while we wait for a key.

When the user enters a keystroke it should be clearly displayed somewhere on the screen.

To implement the polled waiting loop use int 16H function 1(see bios handout). This function checks to see if a key has been entered and returns 0 in the ZF (zero flag) if a key was entered, 1 if not. It does NOT wait for a key to be entered and it does NOT remove the key from the buffer. Use int 16H function 0 to get the key once one has been entered.

After calling int 16H, function 1, you can access the ZF in the same way you access the intel registers. For example, if you've defined a union REGS r then access the ZF through r.x.flags. The ZF is bit number 6 in the flags register. You'll need to do some bitwise operations here.

You can use printfs or int 10H functions for your output , your choice. Continue waiting for, and displaying keystrokes until a 'q' is entered, then exit the program.

im thinking of doing a clock that displays real time but cant make so it keeps changing so that the time is constant without me interfering.

here is what i have

#include
#include
#include

int main(void)
{
time_t now;
time(&now);

printf("%s", ctime(&now));


return EXIT_SUCCESS;
}


sorry cant figure out the tags




Comments

  • AsmGuru62AsmGuru62 Posts: 6,519Member
    [color=Blue]I did not write the full code - simply do not remember the DOS days. Just look at the logic and find out how to do it in VC++ of old days, because VC++ today is no longer for DOS - only for Windows.[/color]
    : [code]
    : #include
    : #include
    : #include
    :
    : int main(void)
    : {
    : time_t now;
    : [color=Red]time_t time2;[/color]
    : time(&now);
    : [color=Red]int done=0;[/color]
    :
    : printf("%s", ctime(&now));
    :
    [color=Red]: while (!done)
    : {
    : [color=Green]// use INT 16H (FUNCTION 1) to check if key is ready[/color]
    : if (key is ready)
    : {
    : [color=Green]// use INT 16H (FUNCTION 0) to read the key
    : // and then display it at current cursor location[/color]
    :
    : if (key == 'q') done=1; [color=Green]// This will stop the loop[/color]
    : }
    :
    : time (&time2);
    : if (time2 != now)
    : {
    : [color=Green]// next second arrived - you must get the real time in
    : // HH:MM:SS and print it somewhere on screen - say, on
    : // the right top corner. Before printing - remember the
    : // current cursore location and AFTER printing restore
    : // cursor location back - otherwise characters you print
    : // from your key presses will be printed out of place.[/color]
    : }
    : }[/color]
    :
    : return EXIT_SUCCESS;
    : }
    : [/code]
    :
    : sorry cant figure out the tags
    :
    :
    :
    :
    :
Sign In or Register to comment.