syslinux-3.08-2 sources from FC4
[bootcd.git] / syslinux / sample / conio.c
1 #ident "$Id: conio.c,v 1.4 2005/01/03 08:23:16 hpa Exp $"
2 /* ----------------------------------------------------------------------- *
3  *   
4  *   Copyright 2001-2003 H. Peter Anvin - All Rights Reserved
5  *
6  *   This program is free software; you can redistribute it and/or modify
7  *   it under the terms of the GNU General Public License as published by
8  *   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
9  *   Boston MA 02111-1307, USA; either version 2 of the License, or
10  *   (at your option) any later version; incorporated herein by reference.
11  *
12  * ----------------------------------------------------------------------- */
13
14 /*
15  * conio.c
16  *
17  * Output to the screen
18  */
19
20 #include <com32.h>
21 #include <stdarg.h>
22
23 #define NULL ((void *)0)
24
25 static inline void memset(void *buf, int ch, unsigned int len)
26 {
27   asm volatile("cld; rep; stosb"
28                : "+D" (buf), "+c" (len) : "a" (ch) : "memory");
29 }
30
31 int putchar(int ch)
32 {
33   com32sys_t regs;
34
35   memset(&regs, 0, sizeof regs);
36
37   if ( ch == '\n' ) {
38     /* \n -> \r\n */
39     putchar('\r');
40   }
41   
42   regs.eax.b[1] = 0x02;
43   regs.edx.b[0] = ch;
44   __com32.cs_intcall(0x21, &regs, NULL);
45
46   return ch;
47 }
48
49 /* Note: doesn't put '\n' like the stdc version does */
50 int puts(const char *s)
51 {
52   int count = 0;
53
54   while ( *s ) {
55     putchar(*s);
56     count++;
57     s++;
58   }
59
60   return count;
61 }