Clearing r.x.flags?

This is a discussion on Clearing r.x.flags? within the C Programming forums, part of the General Programming Boards category; Trying to work on a polled waiting loop, but I can't seem to figure out how to reset the r.x.flags ...

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    6

    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. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,832
    A better question is why are you still being taught with a stone age compiler?

    It is a history course?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    6
    Embedded software class, he's just teaching us how to use hardware interrupts and such.

  4. #4
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Quote Originally Posted by Mikey7047
    Embedded software class
    Still... it is not an explanation... Look at the Salem's avatar
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,832
    > 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

    Which leads onto say
    set the flag would be r.x.flags |= carry;
    clear the flag would be r.x.flags &= ~carry;
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    Registered User
    Join Date
    Oct 2006
    Posts
    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.
    Last edited by Mikey7047; 10-30-2006 at 04:10 PM.

  7. #7
    Registered User
    Join Date
    Oct 2006
    Posts
    6
    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. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,832
    > int86(0x16, &r, &r);
    Because this only checks for key presses, you also need to read them as well.

    I trust you've downloaded "Ralph Brown's interrupt list".
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  9. #9
    Registered User
    Join Date
    Oct 2006
    Posts
    6
    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. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,832
    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.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  11. #11
    Registered User
    Join Date
    Oct 2006
    Posts
    6
    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
    int i, ready;
    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;
    
    		ready = key_ready();
    		{
    			if(ready == 1)
    			{
    				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);
    				}
    				ready = 0;
    			}
    		}
    	}while(i<3);
    }
    
    int key_ready(void)
    {
    	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;
    }
    Last edited by Mikey7047; 10-31-2006 at 12:17 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem Clearing Terminal
    By mrginger in forum C Programming
    Replies: 3
    Last Post: 04-15-2009, 12:58 PM
  2. Proper method of clearing buffer
    By Oldman47 in forum C++ Programming
    Replies: 14
    Last Post: 04-23-2007, 08:14 PM
  3. clearing the message queue or don't let messages get queued
    By Leeman_s in forum Windows Programming
    Replies: 6
    Last Post: 12-25-2002, 06:37 PM
  4. clearing things up
    By webturtle0 in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 11-28-2002, 03:59 PM
  5. Clearing the screen
    By Shadow in forum C Programming
    Replies: 4
    Last Post: 05-23-2002, 02:40 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21