Visual C++

Moderators: Lundin
Number of threads: 379
Number of posts: 695

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
POLLED WAITING LOOPS Posted by athlonxl on 9 Feb 2011 at 8:19 AM
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 <stdio.h>
#include <stdlib.h>
#include <time.h>

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

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


return EXIT_SUCCESS;
}


sorry cant figure out the tags




Report
Re: POLLED WAITING LOOPS Posted by AsmGuru62 on 10 Feb 2011 at 5:44 AM
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.
:
: #include <stdio.h>
: #include <stdlib.h>
: #include <time.h>
: 
: int main(void)
: {
:   time_t now;
:   time_t time2;
:   time(&now);
:   int done=0;
: 
:   printf("%s", ctime(&now));
:
:   while (!done)
:   {
:     // use INT 16H (FUNCTION 1) to check if key is ready
:     if (key is ready)
:     {
:       // use INT 16H (FUNCTION 0) to read the key
:       // and then display it at current cursor location
:
:       if (key == 'q') done=1; // This will stop the loop
:     }
:
:     time (&time2);
:     if (time2 != now)
:     {
:       // 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.
:     }
:   }
:
:   return EXIT_SUCCESS;
: }
: 

:
: sorry cant figure out the tags
:
:
:
:
:



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.