/* vim: set filetype=c:
 *
 * time.h86  -  Timer interface definitions for runtime library
 *
 * Copyright (C) 2003-2007 Gero Kuhlmann   <gero@gkminix.han.de>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * $Id: time.h86,v 1.7 2007/01/06 18:30:54 gkminix Exp $
 */


#ifndef I386_TIME_H86
#define I386_TIME_H86



/*
 **************************************************************************
 *
 * This file can not be included into assembler source
 */
#ifndef _ASSEMBLY_

#include <common.h86>



/*
 **************************************************************************
 *
 * Timer routines
 */

/* Define the number of timer ticks per second */
#define TICKS_PER_SECOND	18


/* Get current tick count from BIOS */
__nb_inline__ unsigned long get_ticks(void)
{
  register __u32 ret;

  __asm__ __volatile__(
	"call get_ticks"
	: "=&a" (ret)
	: /* no input */
	: "cc");
  return((unsigned long)ret);
}


/* Set timeout value in seconds */
__nb_inline__ void set_timeout(unsigned short secs)
{
  __asm__ __volatile__(
	"call set_timeout"
	: /* no output */
	: "a" ((__u16)secs)
	: "cc");
}


/* Check if timeout reached */
__nb_inline__ short chk_timeout(void)
{
  register __u16 ret;

  __asm__ __volatile__(
	"call chk_timeout\n\t"
	"setc %b0\n\t"
	"cbtw"
	: "=&a" (ret)
	: /* no input */
	: "cc");
  return((short)ret);
}



/* Wait a specified number of seconds */
#define wait_seconds(t)	set_timeout(t); while (!chk_timeout())


#endif /* _ASSEMBLY_ */

#endif

