2011-03-30 00:47:18 +04:00
|
|
|
/*
|
|
|
|
* vim:tabstop=4
|
|
|
|
* vim:noexpandtab
|
|
|
|
*/
|
2011-01-16 04:01:19 +03:00
|
|
|
#include <system.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Text pointer, background, foreground
|
|
|
|
*/
|
|
|
|
unsigned short * textmemptr;
|
|
|
|
int attrib = 0x0F;
|
2011-03-25 08:13:44 +03:00
|
|
|
int csr_x = 0, csr_y = 0, use_serial = 1, use_csr = 1;
|
|
|
|
int old_x = 0, old_y = 0, old_s = 1, old_csr = 1;
|
2011-01-16 04:01:19 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* scroll
|
|
|
|
* Scroll the screen
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
scroll() {
|
|
|
|
unsigned blank, temp;
|
|
|
|
blank = 0x20 | (attrib << 8);
|
|
|
|
if (csr_y >= 25) {
|
|
|
|
/*
|
|
|
|
* Move the current text chunk that makes up the screen
|
|
|
|
* back in the buffer by one line.
|
|
|
|
*/
|
|
|
|
temp = csr_y - 25 + 1;
|
|
|
|
memcpy(textmemptr, textmemptr + temp * 80, (25 - temp) * 80 * 2);
|
|
|
|
/*
|
|
|
|
* Set the chunk of memory that occupies
|
|
|
|
* the last line of text to the blank character
|
|
|
|
*/
|
|
|
|
memsetw(textmemptr + (25 - temp) * 80, blank, 80);
|
|
|
|
csr_y = 25 - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-25 04:18:14 +03:00
|
|
|
void
|
|
|
|
set_serial(int on) {
|
|
|
|
use_serial = on;
|
|
|
|
}
|
|
|
|
|
2011-03-25 08:13:44 +03:00
|
|
|
void
|
|
|
|
set_csr(int on) {
|
|
|
|
use_csr = on;
|
|
|
|
}
|
|
|
|
|
2011-03-25 04:18:14 +03:00
|
|
|
void
|
|
|
|
store_csr() {
|
|
|
|
old_x = csr_x;
|
|
|
|
old_y = csr_y;
|
|
|
|
old_s = use_serial;
|
2011-03-25 08:13:44 +03:00
|
|
|
old_csr = use_csr;
|
2011-03-25 04:18:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
restore_csr() {
|
|
|
|
csr_x = old_x;
|
|
|
|
csr_y = old_y;
|
|
|
|
use_serial = old_s;
|
2011-03-25 08:13:44 +03:00
|
|
|
use_csr = old_csr;
|
2011-03-25 04:18:14 +03:00
|
|
|
}
|
|
|
|
|
2011-01-16 04:01:19 +03:00
|
|
|
/*
|
|
|
|
* move_csr
|
|
|
|
* Update the hardware cursor
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
move_csr() {
|
2011-03-25 08:13:44 +03:00
|
|
|
if (!use_csr) return;
|
2011-01-16 04:01:19 +03:00
|
|
|
unsigned temp;
|
|
|
|
temp = csr_y * 80 + csr_x;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write stuff out.
|
|
|
|
*/
|
|
|
|
outportb(0x3D4, 14);
|
|
|
|
outportb(0x3D5, temp >> 8);
|
|
|
|
outportb(0x3D4, 15);
|
|
|
|
outportb(0x3D5, temp);
|
|
|
|
}
|
|
|
|
|
2011-03-25 04:03:52 +03:00
|
|
|
/*
|
|
|
|
* place_csr(x, y)
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
place_csr(
|
|
|
|
uint32_t x,
|
|
|
|
uint32_t y
|
|
|
|
) {
|
|
|
|
csr_x = x;
|
|
|
|
csr_y = y;
|
|
|
|
move_csr();
|
|
|
|
}
|
|
|
|
|
2011-01-16 04:01:19 +03:00
|
|
|
/*
|
|
|
|
* cls
|
|
|
|
* Clear the screen
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
cls() {
|
|
|
|
unsigned blank;
|
|
|
|
int i;
|
|
|
|
blank = 0x20 | (attrib << 8);
|
|
|
|
for (i = 0; i < 25; ++i) {
|
|
|
|
memsetw(textmemptr + i * 80, blank, 80);
|
|
|
|
}
|
|
|
|
csr_x = 0;
|
|
|
|
csr_y = 0;
|
|
|
|
move_csr();
|
2011-03-29 04:34:44 +04:00
|
|
|
if (bochs_resolution_x) {
|
|
|
|
bochs_term_clear();
|
|
|
|
}
|
2011-01-16 04:01:19 +03:00
|
|
|
}
|
|
|
|
|
2011-02-11 00:13:33 +03:00
|
|
|
/*
|
|
|
|
* placech
|
|
|
|
* Put a character in a particular cell with the given attributes.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
placech(
|
|
|
|
unsigned char c,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int attr
|
|
|
|
) {
|
|
|
|
unsigned short *where;
|
|
|
|
unsigned att = attr << 8;
|
|
|
|
where = textmemptr + (y * 80 + x);
|
|
|
|
*where = c | att;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* writechf
|
|
|
|
* Force write the given character.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
writechf(
|
|
|
|
unsigned char c
|
|
|
|
) {
|
|
|
|
placech(c, csr_x, csr_y, attrib);
|
|
|
|
csr_x++;
|
|
|
|
if (csr_x >= 80) {
|
|
|
|
csr_x = 0;
|
|
|
|
++csr_y;
|
|
|
|
}
|
|
|
|
scroll();
|
|
|
|
move_csr();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-01-16 04:01:19 +03:00
|
|
|
/*
|
2011-02-07 23:30:17 +03:00
|
|
|
* writech
|
|
|
|
* Write a character to the screen.
|
2011-01-16 04:01:19 +03:00
|
|
|
*/
|
|
|
|
void
|
2011-02-07 23:30:17 +03:00
|
|
|
writech(
|
2011-01-16 04:01:19 +03:00
|
|
|
unsigned char c
|
2011-02-07 23:30:17 +03:00
|
|
|
) {
|
2011-01-16 04:01:19 +03:00
|
|
|
unsigned short *where;
|
|
|
|
unsigned att = attrib << 8;
|
|
|
|
if (c == 0x08) {
|
|
|
|
/* Backspace */
|
|
|
|
if (csr_x != 0) csr_x--;
|
|
|
|
} else if (c == 0x09) {
|
|
|
|
/* Tab */
|
|
|
|
csr_x = (csr_x + 8) & ~(8 - 1);
|
|
|
|
} else if (c == '\r') {
|
|
|
|
/* Carriage return */
|
|
|
|
csr_x = 0;
|
|
|
|
} else if (c == '\n') {
|
|
|
|
/* New line */
|
|
|
|
csr_x = 0;
|
|
|
|
csr_y++;
|
|
|
|
} else if (c >= ' ') {
|
|
|
|
where = textmemptr + (csr_y * 80 + csr_x);
|
|
|
|
*where = c | att;
|
|
|
|
csr_x++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (csr_x >= 80) {
|
|
|
|
csr_x = 0;
|
|
|
|
csr_y++;
|
|
|
|
}
|
|
|
|
scroll();
|
|
|
|
move_csr();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* puts
|
|
|
|
* Put string to screen
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
puts(
|
2011-01-16 19:56:44 +03:00
|
|
|
char * text
|
2011-01-16 04:01:19 +03:00
|
|
|
){
|
|
|
|
int i;
|
|
|
|
int len = strlen(text);
|
|
|
|
for (i = 0; i < len; ++i) {
|
2011-02-20 00:27:41 +03:00
|
|
|
writech(text[i]);
|
2011-01-16 04:01:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-30 00:02:20 +04:00
|
|
|
char vga_to_ansi[] = {
|
|
|
|
0, 4, 2, 6, 1, 5, 3, 7,
|
|
|
|
8,12,10,14, 9,13,11,15
|
|
|
|
};
|
|
|
|
|
2011-01-16 04:01:19 +03:00
|
|
|
/*
|
|
|
|
* settextcolor
|
|
|
|
* Sets the foreground and background color
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
settextcolor(
|
|
|
|
unsigned char forecolor,
|
|
|
|
unsigned char backcolor
|
|
|
|
) {
|
|
|
|
attrib = (backcolor << 4) | (forecolor & 0x0F);
|
2011-03-30 00:02:20 +04:00
|
|
|
forecolor = vga_to_ansi[forecolor];
|
|
|
|
backcolor = vga_to_ansi[backcolor];
|
2011-03-29 04:34:44 +04:00
|
|
|
if (use_serial) {
|
|
|
|
serial_send('\033');
|
|
|
|
serial_send('[');
|
|
|
|
serial_send('3');
|
|
|
|
serial_send(forecolor % 8 + '0');
|
2011-03-30 00:47:18 +04:00
|
|
|
serial_send(';');
|
|
|
|
serial_send('4');
|
|
|
|
serial_send(backcolor % 8 + '0');
|
|
|
|
if (forecolor > 7) {
|
|
|
|
serial_send(';');
|
|
|
|
serial_send('1');
|
|
|
|
}
|
2011-03-29 04:34:44 +04:00
|
|
|
serial_send('m');
|
|
|
|
}
|
|
|
|
bochs_set_colors(forecolor, backcolor);
|
2011-01-16 04:01:19 +03:00
|
|
|
}
|
|
|
|
|
2011-01-19 09:04:27 +03:00
|
|
|
/*
|
|
|
|
* resettextcolor
|
|
|
|
* Reset the text color to white on black
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
resettextcolor() {
|
2011-03-25 04:24:59 +03:00
|
|
|
settextcolor(7,0);
|
2011-03-29 04:34:44 +04:00
|
|
|
if (use_serial) {
|
|
|
|
serial_send('\033');
|
|
|
|
serial_send('[');
|
|
|
|
serial_send('0');
|
|
|
|
serial_send('m');
|
|
|
|
}
|
|
|
|
bochs_reset_colors();
|
2011-03-25 04:24:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
brighttextcolor() {
|
2011-01-19 09:04:27 +03:00
|
|
|
settextcolor(15,0);
|
|
|
|
}
|
|
|
|
|
2011-01-16 04:01:19 +03:00
|
|
|
/*
|
|
|
|
* init_video
|
|
|
|
* Initialize the VGA driver.
|
|
|
|
*/
|
|
|
|
void init_video() {
|
|
|
|
textmemptr = (unsigned short *)0xB8000;
|
2011-01-21 08:21:32 +03:00
|
|
|
csr_y = 10;
|
|
|
|
move_csr();
|
2011-01-16 04:01:19 +03:00
|
|
|
}
|