2007-04-02 15:21:28 +02:00
|
|
|
|
#include "vga.h"
|
|
|
|
|
#include "video.h"
|
2007-04-02 16:14:21 +02:00
|
|
|
|
#include "stdarg.h"
|
2007-04-02 15:21:28 +02:00
|
|
|
|
|
2018-08-17 16:46:56 +02:00
|
|
|
|
console vc[8] = {
|
|
|
|
|
{0x07, 0, 0, 0, 0, 0, 0, 0}
|
|
|
|
|
,
|
|
|
|
|
{0x07, 0, 0, 0, 0, 0, 0, 0}
|
|
|
|
|
,
|
|
|
|
|
{0x07, 0, 0, 0, 0, 0, 0, 0}
|
|
|
|
|
,
|
|
|
|
|
{0x07, 0, 0, 0, 0, 0, 0, 0}
|
|
|
|
|
,
|
|
|
|
|
{0x07, 0, 0, 0, 0, 0, 0, 0}
|
|
|
|
|
,
|
|
|
|
|
{0x07, 0, 0, 0, 0, 0, 0, 0}
|
|
|
|
|
,
|
|
|
|
|
{0x07, 0, 0, 0, 0, 0, 0, 0}
|
|
|
|
|
,
|
|
|
|
|
{0x07, 0, 0, 0, 0, 0, 0, 0}
|
|
|
|
|
};
|
2007-04-02 16:14:21 +02:00
|
|
|
|
|
2018-08-17 16:46:56 +02:00
|
|
|
|
u8 usedvc = 0;
|
2007-04-02 15:44:12 +02:00
|
|
|
|
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
|
|
|
|
|
|
/* Fixe l'attribut courant */
|
|
|
|
|
|
|
|
|
|
void setattrib(u8 att)
|
|
|
|
|
{
|
2018-08-17 16:46:56 +02:00
|
|
|
|
static const u8 ansitovga[] = {
|
2007-04-02 15:44:12 +02:00
|
|
|
|
0, 4, 2, 6, 1, 5, 3, 7
|
|
|
|
|
};
|
|
|
|
|
u8 tempattr;
|
|
|
|
|
|
2007-04-02 16:14:21 +02:00
|
|
|
|
tempattr = vc[usedvc].attrib;
|
2018-08-17 16:46:56 +02:00
|
|
|
|
if (att == 0)
|
|
|
|
|
tempattr = 0x07; /* Couleur Grise sur fond noir */
|
2007-04-02 16:14:21 +02:00
|
|
|
|
else if (att == 5)
|
2018-08-17 16:46:56 +02:00
|
|
|
|
tempattr |= 0x80;
|
2007-04-02 16:14:21 +02:00
|
|
|
|
else if (att == 7)
|
2018-08-17 16:46:56 +02:00
|
|
|
|
tempattr = ((tempattr & 0x0F) << 4) + ((tempattr & 0xF0) >> 4);
|
2007-04-02 16:14:21 +02:00
|
|
|
|
else if (att == 8)
|
2018-08-17 16:46:56 +02:00
|
|
|
|
tempattr = 0;
|
2007-04-02 16:14:21 +02:00
|
|
|
|
else if (att == 1)
|
2018-08-17 16:46:56 +02:00
|
|
|
|
tempattr |= 0x08; /* Forte intensit<69> */
|
|
|
|
|
else if (att >= 30 && att <= 37) {
|
2007-04-02 15:44:12 +02:00
|
|
|
|
att = ansitovga[att - 30];
|
2018-08-17 16:46:56 +02:00
|
|
|
|
tempattr = (tempattr & ~0x07) | att; /* couleur de premier plan */
|
|
|
|
|
} else if (att >= 40 && att <= 47) {
|
2007-04-02 15:44:12 +02:00
|
|
|
|
att = ansitovga[att - 40] << 4;
|
2018-08-17 16:46:56 +02:00
|
|
|
|
tempattr = (tempattr & ~0x70) | att; /* couleur de fond */
|
2007-04-02 15:44:12 +02:00
|
|
|
|
}
|
2007-04-02 16:14:21 +02:00
|
|
|
|
vc[usedvc].attrib = tempattr;
|
2007-04-02 15:44:12 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
|
|
|
|
|
|
/* gere l'ansi */
|
|
|
|
|
|
|
|
|
|
bool makeansi(u8 c)
|
|
|
|
|
{
|
|
|
|
|
/* state machine to handle the escape sequences */
|
2018-08-17 16:46:56 +02:00
|
|
|
|
switch (vc[usedvc].ansi) {
|
2007-04-02 15:44:12 +02:00
|
|
|
|
case 0:
|
|
|
|
|
/* ESC -- next state */
|
2018-08-17 16:46:56 +02:00
|
|
|
|
if (c == 0x1B) {
|
2007-04-02 16:14:21 +02:00
|
|
|
|
vc[usedvc].ansi++;
|
2018-08-17 16:46:56 +02:00
|
|
|
|
return 1; /* "I handled it" */
|
2007-04-02 15:44:12 +02:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
/* ESC */
|
|
|
|
|
case 1:
|
2018-08-17 16:46:56 +02:00
|
|
|
|
if (c == '[') {
|
2007-04-02 16:14:21 +02:00
|
|
|
|
vc[usedvc].ansi++;
|
|
|
|
|
vc[usedvc].param1 = 0;
|
2007-04-02 15:44:12 +02:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
/* ESC[ */
|
|
|
|
|
case 2:
|
2018-08-17 16:46:56 +02:00
|
|
|
|
if (isdigit(c)) {
|
2007-04-02 16:14:21 +02:00
|
|
|
|
vc[usedvc].param1 = vc[usedvc].param1 * 10 + c - '0';
|
2007-04-02 15:44:12 +02:00
|
|
|
|
return 1;
|
2018-08-17 16:46:56 +02:00
|
|
|
|
} else if (c == ';') {
|
2007-04-02 16:14:21 +02:00
|
|
|
|
vc[usedvc].ansi++;
|
|
|
|
|
vc[usedvc].param2 = 0;
|
2007-04-02 15:44:12 +02:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
/* ESC[2J -- efface l'ecran */
|
2018-08-17 16:46:56 +02:00
|
|
|
|
else if (c == 'J') {
|
|
|
|
|
if (vc[usedvc].param1 == 2) {
|
2007-04-02 16:14:21 +02:00
|
|
|
|
fill(vc[usedvc].attrib);
|
2018-08-17 16:46:56 +02:00
|
|
|
|
vc[usedvc].cursX = 0;
|
|
|
|
|
vc[usedvc].cursY = 0;
|
|
|
|
|
gotoscr(0, 0);
|
2007-04-02 16:14:21 +02:00
|
|
|
|
vc[usedvc].ansi = 0;
|
2007-04-02 15:44:12 +02:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* ESC[num1m -- met l'attribut num1 */
|
2018-08-17 16:46:56 +02:00
|
|
|
|
else if (c == 'm') {
|
2007-04-02 16:14:21 +02:00
|
|
|
|
setattrib(vc[usedvc].param1);
|
|
|
|
|
vc[usedvc].ansi = 0;
|
2007-04-02 15:44:12 +02:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
/* ESC[num1A -- bouge le curseur de num1 vers le haut */
|
2018-08-17 16:46:56 +02:00
|
|
|
|
else if (c == 'A') {
|
|
|
|
|
vc[usedvc].cursY -= vc[usedvc].param1;
|
|
|
|
|
if (vc[usedvc].cursY < 0)
|
|
|
|
|
vc[usedvc].cursY = 0;
|
2007-04-02 16:14:21 +02:00
|
|
|
|
vc[usedvc].ansi = 0;
|
2018-08-17 16:46:56 +02:00
|
|
|
|
gotoscr(vc[usedvc].cursX, vc[usedvc].cursY);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2007-04-02 15:44:12 +02:00
|
|
|
|
/* ESC[num1B -- bouge le curseur de num1 vers le bas */
|
2018-08-17 16:46:56 +02:00
|
|
|
|
else if (c == 'B') {
|
|
|
|
|
vc[usedvc].cursY += vc[usedvc].param1;
|
|
|
|
|
if (vc[usedvc].cursY >= getyres() - 1)
|
|
|
|
|
vc[usedvc].cursY = getyres();
|
2007-04-02 16:14:21 +02:00
|
|
|
|
vc[usedvc].ansi = 0;
|
2018-08-17 16:46:56 +02:00
|
|
|
|
gotoscr(vc[usedvc].cursX, vc[usedvc].cursY);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2007-04-02 16:14:21 +02:00
|
|
|
|
/* ESC[num1D -- bouge le curseur de num1 vers la gauche */
|
2018-08-17 16:46:56 +02:00
|
|
|
|
else if (c == 'D') {
|
|
|
|
|
vc[usedvc].cursX -= vc[usedvc].param1;
|
|
|
|
|
if (vc[usedvc].cursX < 0)
|
|
|
|
|
vc[usedvc].cursX = 0;
|
2007-04-02 16:14:21 +02:00
|
|
|
|
vc[usedvc].ansi = 0;
|
2018-08-17 16:46:56 +02:00
|
|
|
|
gotoscr(vc[usedvc].cursX, vc[usedvc].cursY);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2007-04-02 16:14:21 +02:00
|
|
|
|
/* ESC[num1C -- bouge le curseur de num1 vers la droite */
|
2018-08-17 16:46:56 +02:00
|
|
|
|
else if (c == 'C') {
|
|
|
|
|
vc[usedvc].cursX += vc[usedvc].param1;
|
|
|
|
|
if (vc[usedvc].cursX >= getxres() - 1)
|
|
|
|
|
vc[usedvc].cursX = getxres();
|
2007-04-02 16:14:21 +02:00
|
|
|
|
vc[usedvc].ansi = 0;
|
2018-08-17 16:46:56 +02:00
|
|
|
|
gotoscr(vc[usedvc].cursX, vc[usedvc].cursY);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2007-04-02 15:44:12 +02:00
|
|
|
|
break;
|
|
|
|
|
/* ESC[num1; */
|
|
|
|
|
case 3:
|
2018-08-17 16:46:56 +02:00
|
|
|
|
if (isdigit(c)) {
|
2007-04-02 16:14:21 +02:00
|
|
|
|
vc[usedvc].param2 = vc[usedvc].param2 * 10 + c - '0';
|
2007-04-02 15:44:12 +02:00
|
|
|
|
return 1;
|
2018-08-17 16:46:56 +02:00
|
|
|
|
} else if (c == ';') {
|
2007-04-02 16:14:21 +02:00
|
|
|
|
vc[usedvc].ansi++;
|
|
|
|
|
vc[usedvc].param3 = 0;
|
2007-04-02 15:44:12 +02:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
/* ESC[num1;num2H ou ESC[num1;num2f-- bouge le curseur en num1,num2 */
|
2018-08-17 16:46:56 +02:00
|
|
|
|
else if ((c == 'H') || (c == 'f')) {
|
|
|
|
|
/* Remet la position du curseur mat<61>riel a num1,num2 */
|
|
|
|
|
gotoscr(vc[usedvc].param2, vc[usedvc].param1);
|
|
|
|
|
/* Remet la position du curseur logiciel a num1,num2 */
|
|
|
|
|
vc[usedvc].cursX = vc[usedvc].param2;
|
|
|
|
|
vc[usedvc].cursY = vc[usedvc].param1;
|
2007-04-02 16:14:21 +02:00
|
|
|
|
vc[usedvc].ansi = 0;
|
2007-04-02 15:44:12 +02:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
/* ESC[num1;num2m -- met les attributs num1,num2 */
|
2018-08-17 16:46:56 +02:00
|
|
|
|
else if (c == 'm') {
|
2007-04-02 16:14:21 +02:00
|
|
|
|
setattrib(vc[usedvc].param1);
|
|
|
|
|
setattrib(vc[usedvc].param2);
|
|
|
|
|
vc[usedvc].ansi = 0;
|
2007-04-02 15:44:12 +02:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
/* ESC[num1;num2;num3 */
|
|
|
|
|
case 4:
|
2018-08-17 16:46:56 +02:00
|
|
|
|
if (isdigit(c)) {
|
2007-04-02 16:14:21 +02:00
|
|
|
|
vc[usedvc].param3 = vc[usedvc].param3 * 10 + c - '0';
|
2007-04-02 15:44:12 +02:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
/* ESC[num1;num2;num3m -- met les attributs num1,num2,num3 */
|
2018-08-17 16:46:56 +02:00
|
|
|
|
else if (c == 'm') {
|
2007-04-02 16:14:21 +02:00
|
|
|
|
setattrib(vc[usedvc].param1);
|
|
|
|
|
setattrib(vc[usedvc].param2);
|
|
|
|
|
setattrib(vc[usedvc].param3);
|
|
|
|
|
vc[usedvc].ansi = 0;
|
2007-04-02 15:44:12 +02:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
/* Mauvais etat >> reset */
|
|
|
|
|
default:
|
2007-04-02 16:14:21 +02:00
|
|
|
|
vc[usedvc].ansi = 0;
|
2007-04-02 15:44:12 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
2007-04-02 16:14:21 +02:00
|
|
|
|
vc[usedvc].ansi = 0;
|
2018-08-17 16:46:56 +02:00
|
|
|
|
return 0; /* Ansi fini ;) */
|
2007-04-02 15:44:12 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
|
|
2007-04-02 16:14:21 +02:00
|
|
|
|
/* Change la console en cours d'utilisation */
|
|
|
|
|
|
|
|
|
|
void changevc(u8 avc)
|
|
|
|
|
{
|
2018-08-17 16:46:56 +02:00
|
|
|
|
usedvc = avc;
|
|
|
|
|
showpage(usedvc);
|
|
|
|
|
setpage(usedvc);
|
|
|
|
|
gotoscr(vc[usedvc].cursX, vc[usedvc].cursY);
|
2007-04-02 16:14:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
|
|
2007-04-02 15:44:12 +02:00
|
|
|
|
/* affiche un caract<63>re a l'<27>cran */
|
|
|
|
|
|
|
|
|
|
void putchar(u8 thechar)
|
|
|
|
|
{
|
2018-08-17 16:46:56 +02:00
|
|
|
|
showpage(usedvc);
|
|
|
|
|
setpage(usedvc);
|
|
|
|
|
if (makeansi(thechar))
|
|
|
|
|
return;
|
|
|
|
|
switch (thechar) {
|
|
|
|
|
case 0x11:
|
|
|
|
|
if (vc[usedvc].cursY > 0)
|
|
|
|
|
vc[usedvc].cursY--;
|
|
|
|
|
break;
|
|
|
|
|
case 0x12:
|
|
|
|
|
if (vc[usedvc].cursY < getyres() - 1)
|
|
|
|
|
vc[usedvc].cursY++;
|
|
|
|
|
break;
|
|
|
|
|
case 0x13:
|
|
|
|
|
if (vc[usedvc].cursX > 0)
|
|
|
|
|
vc[usedvc].cursX--;
|
|
|
|
|
break;
|
|
|
|
|
case 0x14:
|
|
|
|
|
if (vc[usedvc].cursX < getxres() - 1)
|
|
|
|
|
vc[usedvc].cursX++;
|
|
|
|
|
break;
|
|
|
|
|
case 0x2:
|
|
|
|
|
vc[usedvc].cursX = 0;
|
|
|
|
|
vc[usedvc].cursY = 0;
|
|
|
|
|
break;
|
|
|
|
|
case 0x3:
|
|
|
|
|
vc[usedvc].cursX = 0;
|
|
|
|
|
vc[usedvc].cursY = getyres() - 1;
|
|
|
|
|
break;
|
|
|
|
|
case 0x19:
|
|
|
|
|
vc[usedvc].cursX = getxres() - 1;
|
|
|
|
|
break;
|
|
|
|
|
case '\b':
|
|
|
|
|
if (vc[usedvc].cursX == 0) {
|
|
|
|
|
if (vc[usedvc].cursY > 0) {
|
|
|
|
|
vc[usedvc].cursX = getxres() - 1;
|
|
|
|
|
vc[usedvc].cursY--;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
vc[usedvc].cursX--;
|
|
|
|
|
}
|
|
|
|
|
showchar(vc[usedvc].cursX, vc[usedvc].cursY, ' ',
|
|
|
|
|
vc[usedvc].attrib);
|
|
|
|
|
break;
|
|
|
|
|
case '\t':
|
|
|
|
|
vc[usedvc].cursX = (vc[usedvc].cursX + 8) & ~(8 - 1);
|
|
|
|
|
break;
|
|
|
|
|
case '\n':
|
|
|
|
|
vc[usedvc].cursX = 0;
|
|
|
|
|
break;
|
|
|
|
|
case '\r':
|
|
|
|
|
vc[usedvc].cursX = 0;
|
2007-04-02 16:14:21 +02:00
|
|
|
|
vc[usedvc].cursY++;
|
2018-08-17 16:46:56 +02:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
if (thechar >= ' ') {
|
|
|
|
|
showchar(vc[usedvc].cursX, vc[usedvc].cursY, thechar,
|
|
|
|
|
vc[usedvc].attrib);
|
|
|
|
|
vc[usedvc].cursX++;
|
2007-04-02 15:44:12 +02:00
|
|
|
|
}
|
2018-08-17 16:46:56 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (vc[usedvc].cursX >= getxres()) {
|
|
|
|
|
vc[usedvc].cursX = 0;
|
|
|
|
|
vc[usedvc].cursY++;
|
|
|
|
|
}
|
|
|
|
|
if (vc[usedvc].cursY >= getyres()) {
|
|
|
|
|
scroll(1, vc[usedvc].attrib);
|
|
|
|
|
vc[usedvc].cursY = getyres() - 1;
|
|
|
|
|
}
|
|
|
|
|
gotoscr(vc[usedvc].cursX, vc[usedvc].cursY);
|
2007-04-02 15:44:12 +02:00
|
|
|
|
}
|
|
|
|
|
|
2007-04-02 15:21:28 +02:00
|
|
|
|
/*******************************************************************************/
|
|
|
|
|
|
|
|
|
|
/* affiche une chaine de caract<63>re a l'<27>cran */
|
|
|
|
|
|
2018-08-17 16:46:56 +02:00
|
|
|
|
void print(u8 * string)
|
2007-04-02 15:21:28 +02:00
|
|
|
|
{
|
2018-08-17 16:46:56 +02:00
|
|
|
|
u8 *source;
|
2007-04-02 15:21:28 +02:00
|
|
|
|
source = string;
|
2018-08-17 16:46:56 +02:00
|
|
|
|
while (*source != 0) {
|
|
|
|
|
putchar(*source++);
|
|
|
|
|
}
|
2007-04-02 15:21:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
|
|
2007-04-02 16:14:21 +02:00
|
|
|
|
/* affiche une chaine de caract<63>re format<61> a l'ecran */
|
2007-04-02 15:21:28 +02:00
|
|
|
|
|
2018-08-17 16:46:56 +02:00
|
|
|
|
void printf(const u8 * string, ...)
|
2007-04-02 15:21:28 +02:00
|
|
|
|
{
|
2018-08-17 16:46:56 +02:00
|
|
|
|
va_list ap;
|
|
|
|
|
u8 buffer[50];
|
|
|
|
|
u8 *pointer;
|
|
|
|
|
|
|
|
|
|
u8 radix;
|
|
|
|
|
bool signe;
|
|
|
|
|
long num;
|
|
|
|
|
|
|
|
|
|
va_start(ap, string);
|
|
|
|
|
while (*string != 0) {
|
|
|
|
|
if (*string != '%')
|
|
|
|
|
putchar(*string);
|
|
|
|
|
else {
|
|
|
|
|
switch (*++string) {
|
|
|
|
|
case 'c':
|
|
|
|
|
putchar(va_arg(ap, int));
|
|
|
|
|
break;
|
|
|
|
|
case 'u':
|
|
|
|
|
radix = 10;
|
|
|
|
|
signe = 0;
|
|
|
|
|
showstring:
|
|
|
|
|
num = va_arg(ap, int);
|
|
|
|
|
pointer = buffer + 50 - 1;
|
|
|
|
|
*pointer = '\0';
|
|
|
|
|
if ((signe == 1) && (num < 0)) {
|
|
|
|
|
num = -num;
|
|
|
|
|
signe++;
|
|
|
|
|
}
|
|
|
|
|
do {
|
2007-04-02 16:14:21 +02:00
|
|
|
|
unsigned long temp;
|
|
|
|
|
temp = (unsigned long)num % radix;
|
|
|
|
|
pointer--;
|
2018-08-17 16:46:56 +02:00
|
|
|
|
if (temp < 10)
|
2007-04-02 16:14:21 +02:00
|
|
|
|
*pointer = temp + '0';
|
|
|
|
|
else
|
|
|
|
|
*pointer = temp - 10 + 'a';
|
|
|
|
|
num = (unsigned long)num / radix;
|
|
|
|
|
}
|
2018-08-17 16:46:56 +02:00
|
|
|
|
while (num != 0);
|
|
|
|
|
if (signe > 1)
|
|
|
|
|
*(--pointer) = '-';
|
|
|
|
|
while (*pointer != 0)
|
|
|
|
|
putchar(*pointer++);
|
|
|
|
|
break;
|
|
|
|
|
case 'o':
|
|
|
|
|
radix = 8;
|
|
|
|
|
signe = 0;
|
|
|
|
|
goto showstring;
|
|
|
|
|
case 'd':
|
|
|
|
|
case 'i':
|
|
|
|
|
radix = 10;
|
|
|
|
|
signe = 1;
|
|
|
|
|
goto showstring;
|
|
|
|
|
case 'x':
|
|
|
|
|
radix = 16;
|
|
|
|
|
signe = 0;
|
|
|
|
|
goto showstring;
|
|
|
|
|
case 's':
|
|
|
|
|
pointer = va_arg(ap, u8 *);
|
|
|
|
|
if (!pointer)
|
|
|
|
|
pointer = "(null)";
|
|
|
|
|
while (*pointer != 0)
|
|
|
|
|
putchar(*pointer++);
|
|
|
|
|
break;
|
|
|
|
|
case '%':
|
|
|
|
|
putchar('%');
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
putchar(va_arg(ap, int));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
string++;
|
|
|
|
|
}
|
|
|
|
|
va_end(ap);
|
2007-04-02 15:21:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************/
|