aboutsummaryrefslogtreecommitdiffstats
path: root/com32/cmenu/libmenu/com32io.h
blob: 545933284b8d21f719162a484b17c4f630ac1563 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/* -*- c -*- ------------------------------------------------------------- *
 *
 *   Copyright 2004-2005 Murali Krishnan Ganapathy - All Rights Reserved
 *
 *   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, Inc., 53 Temple Place Ste 330,
 *   Boston MA 02111-1307, USA; either version 2 of the License, or
 *   (at your option) any later version; incorporated herein by reference.
 *
 * ----------------------------------------------------------------------- */

#ifndef __COM32IO_H__
#define __COM32IO_H__

#include <com32.h>
#include <stdio.h>

#ifndef NULL
#define NULL ((void *)0)
#endif

#define CSI "\e["

/* Beep: "" are required, not '' */
static inline beep()
{
	return fputs("\007", stdout);
}

/* BIOS Assisted output routines */

// Print a C str (NUL-terminated) respecting the left edge of window
// i.e. \n in str will move cursor to column left
// Print a C str (NUL-terminated)

void csprint(const char *, const char);

//static inline void cswprint(const char *str, const char attr)
//{
//	csprint(str, attr);
//}

void cprint(const char, const char, unsigned int);

static inline void putch(const char x, char attr)
{
	cprint(x, attr, 1);
}

void clearwindow(const char, const char, const char, const char,
		 const char, const char);

/*
 * cls - clear and initialize the entire screen
 *
 * Note: when initializing xterm, one has to specify that
 * G1 points to the alternate character set (this is not true
 * by default). Without the initial printf "\033)0", line drawing
 * characters won't be displayed.
 */
static inline void cls(void)
{
	fputs("\033e\033%@\033)0\033(B\1#0\033[?25l\033[2J", stdout);
}

static inline void gotoxy(const char row, const char col)
{
	printf(CSI "%d;%dH", row + 1, col + 1);
}

void getpos(char *row, char *col, char page);

char inputc(char *scancode);	// Return ASCII char by val, and scancode by reference

void setcursorshape(char start, char end);	// Set cursor shape
void getcursorshape(char *start, char *end);	// Get shape for current page

// Get char displayed at current position in specified page
unsigned char getcharat(char page);

static inline void cursoroff(void)
{				/* Turns off cursor */
    setcursorshape(32, 33);
}

static inline void cursoron(void)
{				/* Turns on cursor */
    setcursorshape(6, 7);
}

static inline unsigned char readbiosb(unsigned int ofs)
{
    return *((unsigned char *)MK_PTR(0, ofs));
}

static inline char getnumrows()
{
    return readbiosb(0x484)+1; // Actually numrows - 1
}

static inline char getnumcols(void)
{
    return readbiosb(0x44a);	// Actually numcols
}

static inline char getshiftflags(void)
{
    return readbiosb(0x417);
}

void scrollupwindow(char top, char left, char bot, char right, char attr, char numlines);	//Scroll up given window

static inline void scrollup(void)	//Scroll up display screen by one line
{
	printf(CSI "S");
}

void setvideomode(char mode);	// Set the video mode.

static inline char getvideomode(void)	// Get the current video mode
{
    return readbiosb(0x449);
}

unsigned char sleep(unsigned int msec);	// Sleep for specified time

unsigned char checkkbdbuf();	// Check to see if there is kbd buffer is non-empty?

static inline void clearkbdbuf()	// Clear the kbd buffer (how many chars removed?)
{
    while (checkkbdbuf())
	inputc(NULL);
}

#endif