syslinux-3.08-2 sources from FC4
[bootcd.git] / syslinux / menu / libmenu / com32io.c
1 /* -*- c -*- ------------------------------------------------------------- *
2  *   
3  *   Copyright 2004-2005 Murali Krishnan Ganapathy - All Rights Reserved
4  *
5  *   This program is free software; you can redistribute it and/or modify
6  *   it under the terms of the GNU General Public License as published by
7  *   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
8  *   Boston MA 02111-1307, USA; either version 2 of the License, or
9  *   (at your option) any later version; incorporated herein by reference.
10  *
11  * ----------------------------------------------------------------------- */
12
13 #include <string.h>
14 #include <com32.h>
15 #include "com32io.h"
16 #include "syslnx.h"
17
18 com32sys_t inreg,outreg; // Global register sets for use
19
20 /* Print character and attribute at cursor */
21 void cprint(char chr,char attr,unsigned int times,char disppage)
22 {
23     REG_AH(inreg) = 0x09;
24     REG_AL(inreg) = chr;
25     REG_BH(inreg) = disppage;
26     REG_BL(inreg) = attr;
27     REG_CX(inreg) = times;
28     __intcall(0x10,&inreg,&outreg);
29 }
30
31 void setdisppage(char num) // Set the display page to specified number
32 {
33     REG_AH(inreg) = 0x05;
34     REG_AL(inreg) = num;
35     __intcall(0x10,&inreg,&outreg);
36 }
37
38 char getdisppage() // Get current display page 
39 {
40     REG_AH(inreg) = 0x0f;
41     __intcall(0x10,&inreg,&outreg);
42     return REG_BH(outreg);
43 }
44
45 void getpos(char * row, char * col, char page)
46 {
47    REG_AH(inreg) = 0x03;
48    REG_BH(inreg) = page;
49    __intcall(0x10,&inreg,&outreg);
50    *row = REG_DH(outreg);
51    *col = REG_DL(outreg);
52 }
53
54 void gotoxy(char row,char col, char page)
55 {
56    REG_AH(inreg) = 0x02;
57    REG_BH(inreg) = page;
58    REG_DX(inreg) = (row << 8)+col;
59    __intcall(0x10,&inreg,&outreg);
60 }
61
62 unsigned char sleep(unsigned int msec)
63 {
64    unsigned long micro = 1000*msec;
65
66    REG_AH(inreg) = 0x86;
67    REG_CX(inreg) = (micro >> 16);
68    REG_DX(inreg) = (micro % 0x10000);
69    __intcall(0x15,&inreg,&outreg);
70    return REG_AH(outreg);
71 }
72
73 void beep()
74 {
75    REG_AH(inreg) = 0x0E;
76    REG_AL(inreg) = 0x07;
77    REG_BH(inreg) = 0; 
78    __intcall(0x10,&inreg,&outreg);
79 }
80
81 void scrollup()
82 {
83   unsigned int dx = (getnumrows()<< 8) + getnumcols();
84   REG_AH(inreg) = 0x06;
85   REG_AL(inreg) = 0x01;
86   REG_BH(inreg) = 0x07; // Attribute to write blanks lines
87   REG_DX(inreg) = dx; // BOT RIGHT corner to window
88   REG_CX(inreg) = 0; // TOP LEFT of window
89 }
90
91 char inputc(char * scancode)
92 {
93   REG_AH(inreg) = 0x10;
94   __intcall(0x16,&inreg,&outreg);
95   if (scancode)
96       *scancode = REG_AH(outreg);
97   return REG_AL(outreg);
98 }
99    
100 void getcursorshape(char *start, char *end)
101 {
102    char page = getdisppage();
103    REG_AH(inreg) = 0x03;
104    REG_BH(inreg) = page;
105    __intcall(0x10,&inreg,&outreg);
106    *start = REG_CH(outreg);
107    *end = REG_CL(outreg);
108 }
109
110 void setcursorshape(char start, char end)
111 {
112    REG_AH(inreg) = 0x01;
113    REG_CH(inreg) = start;
114    REG_CL(inreg) = end;
115    __intcall(0x10,&inreg,&outreg);
116 }
117
118 char getchar(void)
119 {
120    REG_AH(inreg) = 0x08;
121    __intcall(0x21,&inreg,&outreg);
122    return REG_AL(outreg);
123 }
124
125 void setvideomode(char mode)
126 {
127    REG_AH(inreg) = 0x00;
128    REG_AL(inreg) = mode;
129    __intcall(0x10,&inreg,&outreg);
130 }
131
132 unsigned char checkkbdbuf()
133 {
134    REG_AH(inreg) = 0x11;
135    __intcall(0x16,&inreg,&outreg);
136    return (outreg.eflags.l & EFLAGS_ZF);
137 }
138
139 // Get char displayed at current position
140 unsigned char getcharat(char page)
141 {
142    REG_AH(inreg) = 0x08;
143    REG_BH(inreg) = page;
144    __intcall(0x16,&inreg,&outreg);
145    return REG_AL(outreg);
146 }
147