1. ## Clearing r.x.flags?

Trying to work on a polled waiting loop, but I can't seem to figure out how to reset the r.x.flags or r.h.al (Can't figure out which one is the problem.) Here is my code:

Code:
```// Mike Varrieur
// Poll Loop Assignment

#include "dos.h"
union REGS r;
char far *ptr1, far *ptr2, far *ptr3, far *ptr4, far *ptr5, far *ptr6; // set up pointers to access information
int i, x;

void main(void)
{
r.h.ah = 0x00; // Set mode use function call
r.h.al = 0x03; // Mode 80x25 Color
int86(0x10, &r, &r);

x = 1; // "Dummy" incrementer to keep the loop going.
ptr1 = 0xB8000000;  // Set starting pointers
ptr2 = (ptr1 + 1992);
ptr3 = (ptr1 + 1994);
ptr4 = (ptr1 + 1996);
ptr5 = (ptr1 + 1998);
ptr6 = (ptr1 + 1000);
ptr1 = (ptr1 + 1990);

*ptr1 = 'W';
*ptr2 = 'a';
*ptr3 = 'c';
*ptr4 = 'k';
*ptr5 = 'y';

while(1)
{
do
{
*(ptr1 + 1) = ((rand() % 14) + 1);
*(ptr2 + 1) = ((rand() % 14) + 1);
*(ptr3 + 1) = ((rand() % 14) + 1);
*(ptr4 + 1) = ((rand() % 14) + 1);
*(ptr5 + 1) = ((rand() % 14) + 1);

r.h.ah = 0x01;
int86(0x16, &r, &r);

if(!(r.x.flags & (1<<6)))
{
if((r.h.al == 'Q') || (r.h.al == 'q'))
{
i = 4;
}
*ptr6 = r.h.al;

}
r.x.flags = 1;
}while(i<3);
}
}```
I'm assuming the problem is within the if statements, and I've tried r.x.flags = 0, r.x.flags != r.x.flags, etc. Oh and I know the way I used pointers was messy, but the professor seems to like using multiple pointers instead of just one and incrementing it.

2. A better question is why are you still being taught with a stone age compiler?

It is a history course?

3. Embedded software class, he's just teaching us how to use hardware interrupts and such.

4. Originally Posted by Mikey7047
Embedded software class
Still... it is not an explanation... Look at the Salem's avatar

5. > if(!(r.x.flags & (1<<6)))
Why 1<<6 ?
Aren't there constants already set up to denote each flag.

So you can do things like
( r.x.flags & carry ) == 0

set the flag would be r.x.flags |= carry;
clear the flag would be r.x.flags &= ~carry;

6. I'm not sure about constants already set up, haven't heard anything about them in class. He suggested we would have to use bitwise operations to get to the significant bit, so that's what I did. On my way home I was assuming that this maybe be my problem also, but i figured

Code:
`r.x.flags = ~(r.x.flags);`
would work to clear it if that were the case, and it wasn't working for me.

7. Using limited debugging tools, I'm seeing that r.h.al might be the problem here, it doesn't seem to change after the first key is input, does anyone see why?

8. > int86(0x16, &r, &r);
Because this only checks for key presses, you also need to read them as well.

9. Isn't that what I'm doing by reading r.h.al into a pointer? Unless there is another interrupt to read into a variable? I'm looking at his interrupt list now (Thanks for the suggestion) but it's kind of hard to understand. I'm going to try to look for a different version of it.

10. Like I said, it "tests" for a key press.
If you don't remove the key press and test it again, it will still be there.

11. Thank you guys so much, that interrupt list helped a lot, I found the correct interrupt (and was using it incorrectly for a while.) Finally realized a couple stupid mistakes I had made last night and here is my working code in case anyone else ends up with the same problem:

Code:
```// Mike Varrieur
// Poll Loop Assignment

#include "dos.h"
union REGS r;
char far *ptr1, far *ptr2, far *ptr3, far *ptr4, far *ptr5, far *ptr6; // set up pointers to access information
char key;

void main(void)
{
r.h.ah = 0x00; // Set mode use function call
r.h.al = 0x03; // Mode 80x25 Color
int86(0x10, &r, &r);

ptr1 = 0xB8000000;  // Set starting pointers
ptr2 = (ptr1 + 1992);
ptr3 = (ptr1 + 1994);
ptr4 = (ptr1 + 1996);
ptr5 = (ptr1 + 1998);
ptr6 = (ptr1 + 1000);
ptr1 = (ptr1 + 1990);

*ptr1 = 'W';
*ptr2 = 'a';
*ptr3 = 'c';
*ptr4 = 'k';
*ptr5 = 'y';

i = 1;

do
{
*(ptr1 + 1) = ((rand() % 14) + 1);
*(ptr2 + 1) = ((rand() % 14) + 1);
*(ptr3 + 1) = ((rand() % 14) + 1);
*(ptr4 + 1) = ((rand() % 14) + 1);
*(ptr5 + 1) = ((rand() % 14) + 1);
*(ptr6 + 1) = 0x0F;

{
{
key = get_ch();
*ptr6 = key;
if((key == 'Q') || (key == 'q'))
{
i = 4;
r.h.ah = 0x00; // Set mode use function call
r.h.al = 0x03; // Mode 80x25 Color
int86(0x10, &r, &r);
}
}
}
}while(i<3);
}

{
long int x;
r.h.ah=0x01; 				//service number 0x00
int86(0x16, &r, &r);  		//interrupt 0x16
x = r.x.flags;				//get flag register
if ((x & (0x40)) == 0)
{
return 1;				// A key is ready
}
else return 0;				// Else no key
}

char get_ch(void)
{
r.h.ah=0x00; 				//service number 0x00
int86(0x16, &r, &r);  		//interrupt 0x16
return r.h.al;
}```