2018-09-28 20:35:51 +02:00
|
|
|
|
/*******************************************************************************/
|
|
|
|
|
/* COS2000 - Compatible Operating System - LGPL v3 - Hord<72> Nicolas */
|
|
|
|
|
/* */
|
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-29 10:12:00 +02:00
|
|
|
|
u32 print(u8 * string)
|
2007-04-02 15:21:28 +02:00
|
|
|
|
{
|
2018-08-17 16:46:56 +02:00
|
|
|
|
u8 *source;
|
2018-09-27 17:47:27 +02:00
|
|
|
|
u32 i = 0;
|
2007-04-02 15:21:28 +02:00
|
|
|
|
source = string;
|
2018-08-17 16:46:56 +02:00
|
|
|
|
while (*source != 0) {
|
|
|
|
|
putchar(*source++);
|
2018-09-27 17:47:27 +02:00
|
|
|
|
i++;
|
2018-08-17 16:46:56 +02:00
|
|
|
|
}
|
2018-09-27 17:47:27 +02:00
|
|
|
|
return i;
|
2007-04-02 15:21:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************/
|
2018-09-28 20:35:51 +02:00
|
|
|
|
/* affiche une chaine de caract<63>re format<61> a l'ecran */
|
2007-04-02 15:21:28 +02:00
|
|
|
|
|
2018-09-27 17:47:27 +02:00
|
|
|
|
#define buffersize 1024
|
2018-08-29 10:12:00 +02:00
|
|
|
|
|
2018-09-27 17:47:27 +02:00
|
|
|
|
u32 printf(const u8 * string, ...)
|
2007-04-02 15:21:28 +02:00
|
|
|
|
{
|
2018-09-28 00:03:45 +02:00
|
|
|
|
va_list args,argstemp;
|
2018-09-27 21:01:02 +02:00
|
|
|
|
u64 sizes[] = { 0xFF, 0xFFFF, 0xFFFFFFFF, 0xFFFFFFFFFFFFFFFF };
|
2018-09-28 00:03:45 +02:00
|
|
|
|
u8 units[][4] = { "o\000\000", "kio", "mio", "gio", "tio", "pio" };
|
2018-09-27 21:01:02 +02:00
|
|
|
|
u8 strbase2[] = "0xb\000";
|
|
|
|
|
u8 strbase8[] = "0xo\000";
|
|
|
|
|
u8 strbase16[] = "0x\000";
|
2018-09-27 17:47:27 +02:00
|
|
|
|
u8 hexadecimal[] = "*0x\000";
|
|
|
|
|
u8 achar, temp;
|
2018-09-28 00:03:45 +02:00
|
|
|
|
u8 asize, charadd, unit;
|
2018-09-27 17:47:27 +02:00
|
|
|
|
u8 buffer[buffersize];
|
2018-08-29 10:12:00 +02:00
|
|
|
|
u8 *str = string;
|
2018-09-27 17:47:27 +02:00
|
|
|
|
u8 *strtemp;
|
2018-08-29 10:12:00 +02:00
|
|
|
|
u32 i = 0, counter = 0;
|
2018-09-27 21:01:02 +02:00
|
|
|
|
u64 num;
|
2018-09-27 17:47:27 +02:00
|
|
|
|
bool flag = false;
|
2018-08-17 16:46:56 +02:00
|
|
|
|
|
2018-08-29 10:12:00 +02:00
|
|
|
|
va_start(args, string);
|
2018-09-27 17:47:27 +02:00
|
|
|
|
for (achar = *str; achar != '\000'; i++, achar = *(str + i)) {
|
|
|
|
|
if (achar != '%' && !flag) {
|
2018-08-29 10:12:00 +02:00
|
|
|
|
putchar(achar);
|
|
|
|
|
counter++;
|
2018-09-27 17:47:27 +02:00
|
|
|
|
asize = 2;
|
|
|
|
|
charadd = 0xFF;
|
|
|
|
|
} else if (achar == '%' || flag) {
|
|
|
|
|
if (!flag)
|
|
|
|
|
++i;
|
2018-08-29 10:12:00 +02:00
|
|
|
|
achar = *(str + i);
|
2018-09-27 17:47:27 +02:00
|
|
|
|
switch (achar) {
|
|
|
|
|
case '0':
|
|
|
|
|
charadd = '0';
|
|
|
|
|
flag = true;
|
|
|
|
|
break;
|
|
|
|
|
case ' ':
|
|
|
|
|
charadd = ' ';
|
|
|
|
|
flag = true;
|
|
|
|
|
break;
|
|
|
|
|
case 'h':
|
|
|
|
|
asize--;
|
2018-09-27 21:01:02 +02:00
|
|
|
|
if (asize<0) asize=0;
|
2018-09-27 17:47:27 +02:00
|
|
|
|
flag = true;
|
|
|
|
|
break;
|
|
|
|
|
case 'l':
|
|
|
|
|
asize++;
|
2018-09-27 21:01:02 +02:00
|
|
|
|
if (asize>3) asize=3;
|
2018-09-27 17:47:27 +02:00
|
|
|
|
flag = true;
|
|
|
|
|
break;
|
2018-09-28 00:03:45 +02:00
|
|
|
|
case '1':
|
|
|
|
|
case '2':
|
|
|
|
|
case '3':
|
|
|
|
|
asize=0;
|
|
|
|
|
flag = true;
|
|
|
|
|
break;
|
|
|
|
|
case '4':
|
|
|
|
|
case '5':
|
|
|
|
|
case '6':
|
|
|
|
|
case '7':
|
|
|
|
|
asize=1;
|
|
|
|
|
flag = true;
|
|
|
|
|
break;
|
|
|
|
|
case '8':
|
|
|
|
|
asize=2;
|
|
|
|
|
flag = true;
|
|
|
|
|
break;
|
|
|
|
|
case '9':
|
|
|
|
|
asize=3;
|
|
|
|
|
flag = true;
|
|
|
|
|
break;
|
2018-10-04 21:49:06 +02:00
|
|
|
|
case 'f':
|
|
|
|
|
if (asize==0) {
|
|
|
|
|
num = (u64) va_arg(args, u8);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else if (asize==1) {
|
|
|
|
|
num = (u64) va_arg(args, u16);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else if (asize==2)
|
|
|
|
|
rtoasingle((float)va_arg(args, double), &buffer, 5);
|
|
|
|
|
else
|
|
|
|
|
rtoadouble((double)va_arg(args, double), &buffer, 5);
|
|
|
|
|
counter += print(&buffer);
|
|
|
|
|
flag = false;
|
|
|
|
|
break;
|
2018-09-27 17:47:27 +02:00
|
|
|
|
case 'u':
|
2018-09-27 21:01:02 +02:00
|
|
|
|
if (asize==0)
|
|
|
|
|
num = (u64) va_arg(args, u8);
|
|
|
|
|
else if (asize==1)
|
|
|
|
|
num = (u64) va_arg(args, u16);
|
|
|
|
|
else if (asize==2)
|
|
|
|
|
num = (u64) va_arg(args, u32);
|
|
|
|
|
else
|
|
|
|
|
num = (u64) va_arg(args, u64);
|
2018-09-27 17:47:27 +02:00
|
|
|
|
if (charadd == 0xFF)
|
|
|
|
|
charadd = '0';
|
2018-08-30 01:07:28 +02:00
|
|
|
|
itoa(num, &buffer, 10, sizes[asize], charadd);
|
|
|
|
|
counter += print(&buffer);
|
2018-09-27 17:47:27 +02:00
|
|
|
|
flag = false;
|
|
|
|
|
break;
|
|
|
|
|
case 'o':
|
2018-09-27 21:01:02 +02:00
|
|
|
|
if (asize==0)
|
|
|
|
|
num = (u64) va_arg(args, u8);
|
|
|
|
|
else if (asize==1)
|
|
|
|
|
num = (u64) va_arg(args, u16);
|
|
|
|
|
else if (asize==2)
|
|
|
|
|
num = (u64) va_arg(args, u32);
|
|
|
|
|
else
|
|
|
|
|
num = (u64) va_arg(args, u64);
|
2018-09-27 17:47:27 +02:00
|
|
|
|
if (charadd == 0xFF)
|
|
|
|
|
charadd = '0';
|
2018-08-30 01:07:28 +02:00
|
|
|
|
itoa(num, &buffer, 8, sizes[asize], charadd);
|
2018-09-27 17:47:27 +02:00
|
|
|
|
print(&strbase8);
|
2018-09-27 21:01:02 +02:00
|
|
|
|
counter += print(&buffer) + 1;
|
2018-09-27 17:47:27 +02:00
|
|
|
|
flag = false;
|
2018-08-17 16:46:56 +02:00
|
|
|
|
break;
|
2018-08-29 10:12:00 +02:00
|
|
|
|
case 'c':
|
2018-09-27 17:47:27 +02:00
|
|
|
|
temp = (u8) va_arg(args, int);
|
2018-08-29 10:12:00 +02:00
|
|
|
|
putchar(temp);
|
|
|
|
|
counter++;
|
2018-09-27 17:47:27 +02:00
|
|
|
|
flag = false;
|
2018-08-17 16:46:56 +02:00
|
|
|
|
break;
|
2018-09-28 00:03:45 +02:00
|
|
|
|
case 'H':
|
|
|
|
|
if (asize==0)
|
|
|
|
|
num = (u64) va_arg(args, u8);
|
|
|
|
|
else if (asize==1)
|
|
|
|
|
num = (u64) va_arg(args, u16);
|
|
|
|
|
else if (asize==2)
|
|
|
|
|
num = (u64) va_arg(args, u32);
|
|
|
|
|
else
|
|
|
|
|
num = (u64) va_arg(args, u64);
|
|
|
|
|
if (charadd == 0xFF)
|
|
|
|
|
charadd = ' ';
|
|
|
|
|
unit=0;
|
|
|
|
|
while(num>1024*10)
|
|
|
|
|
{
|
|
|
|
|
num=num>>10;
|
|
|
|
|
unit++;
|
|
|
|
|
}
|
|
|
|
|
sitoa(num, &buffer, sizes[asize]);
|
|
|
|
|
counter += print(&buffer);
|
|
|
|
|
print(units[unit]);
|
|
|
|
|
flag = false;
|
|
|
|
|
break;
|
2018-08-17 16:46:56 +02:00
|
|
|
|
case 'd':
|
2018-09-27 17:47:27 +02:00
|
|
|
|
case 'i':
|
2018-09-27 21:01:02 +02:00
|
|
|
|
if (asize==0)
|
|
|
|
|
num = (u64) va_arg(args, u8);
|
|
|
|
|
else if (asize==1)
|
|
|
|
|
num = (u64) va_arg(args, u16);
|
|
|
|
|
else if (asize==2)
|
|
|
|
|
num = (u64) va_arg(args, u32);
|
|
|
|
|
else
|
|
|
|
|
num = (u64) va_arg(args, u64);
|
2018-09-27 17:47:27 +02:00
|
|
|
|
if (charadd == 0xFF)
|
|
|
|
|
charadd = ' ';
|
2018-08-30 01:07:28 +02:00
|
|
|
|
sitoa(num, &buffer, sizes[asize]);
|
|
|
|
|
counter += print(&buffer);
|
2018-09-27 17:47:27 +02:00
|
|
|
|
flag = false;
|
2018-08-29 10:12:00 +02:00
|
|
|
|
break;
|
2018-08-17 16:46:56 +02:00
|
|
|
|
case 's':
|
2018-09-27 17:47:27 +02:00
|
|
|
|
strtemp = (u8 *) va_arg(args, u8 *);
|
2018-08-29 10:12:00 +02:00
|
|
|
|
counter += print(strtemp);
|
2018-09-27 17:47:27 +02:00
|
|
|
|
flag = false;
|
2018-08-17 16:46:56 +02:00
|
|
|
|
break;
|
2018-08-29 10:12:00 +02:00
|
|
|
|
case 'p':
|
2018-09-27 17:47:27 +02:00
|
|
|
|
num = (u32) va_arg(args, int);
|
|
|
|
|
if (charadd == 0xFF)
|
|
|
|
|
charadd = '0';
|
2018-08-30 01:07:28 +02:00
|
|
|
|
print(&hexadecimal);
|
2018-09-27 17:47:27 +02:00
|
|
|
|
itoa(num, buffer, 16, sizes[asize], '0');
|
|
|
|
|
counter += print(&buffer) + 2;
|
|
|
|
|
flag = false;
|
2018-08-29 10:12:00 +02:00
|
|
|
|
break;
|
|
|
|
|
case 'x':
|
|
|
|
|
case 'X':
|
2018-10-03 22:50:54 +02:00
|
|
|
|
case 'y':
|
|
|
|
|
case 'Y':
|
2018-09-27 21:01:02 +02:00
|
|
|
|
if (asize==0)
|
|
|
|
|
num = (u64) va_arg(args, u8);
|
|
|
|
|
else if (asize==1)
|
|
|
|
|
num = (u64) va_arg(args, u16);
|
|
|
|
|
else if (asize==2)
|
|
|
|
|
num = (u64) va_arg(args, u32);
|
|
|
|
|
else
|
|
|
|
|
num = (u64) va_arg(args, u64);
|
2018-09-27 17:47:27 +02:00
|
|
|
|
if (charadd == 0xFF)
|
|
|
|
|
charadd = '0';
|
2018-08-30 01:07:28 +02:00
|
|
|
|
itoa(num, &buffer, 16, sizes[asize], charadd);
|
2018-10-03 22:50:54 +02:00
|
|
|
|
if (achar == 'X'||achar == 'Y')
|
2018-09-27 17:47:27 +02:00
|
|
|
|
strtoupper(&buffer);
|
2018-10-03 22:50:54 +02:00
|
|
|
|
if (achar == 'X') print(&strbase16);
|
2018-09-27 21:01:02 +02:00
|
|
|
|
counter += print(&buffer) + 1;
|
2018-09-27 17:47:27 +02:00
|
|
|
|
flag = false;
|
2018-08-17 16:46:56 +02:00
|
|
|
|
break;
|
2018-08-29 10:12:00 +02:00
|
|
|
|
case 'b':
|
2018-09-27 21:01:02 +02:00
|
|
|
|
if (asize==0)
|
|
|
|
|
num = (u64) va_arg(args, u8);
|
|
|
|
|
else if (asize==1)
|
|
|
|
|
num = (u64) va_arg(args, u16);
|
|
|
|
|
else if (asize==2)
|
|
|
|
|
num = (u64) va_arg(args, u32);
|
|
|
|
|
else
|
|
|
|
|
num = (u64) va_arg(args, u64);
|
2018-09-27 17:47:27 +02:00
|
|
|
|
if (charadd == 0xFF)
|
|
|
|
|
charadd = '0';
|
2018-08-30 01:07:28 +02:00
|
|
|
|
itoa(num, &buffer, 2, sizes[asize], charadd);
|
2018-09-27 17:47:27 +02:00
|
|
|
|
print(&strbase2);
|
2018-09-27 21:01:02 +02:00
|
|
|
|
counter += print(&buffer) + 1;
|
2018-09-27 17:47:27 +02:00
|
|
|
|
flag = false;
|
|
|
|
|
break;
|
2018-08-17 16:46:56 +02:00
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-08-29 10:12:00 +02:00
|
|
|
|
va_end(args);
|
|
|
|
|
return counter;
|
2007-04-02 15:21:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-04 21:49:06 +02:00
|
|
|
|
/*******************************************************************************/
|
|
|
|
|
/* converti un r<>el sign<67> en chaine de caract<63>re */
|
|
|
|
|
u8 *rtoadouble(double num, u8 * str, u8 precision) {
|
|
|
|
|
u8 *pointer=str;
|
|
|
|
|
u32 integerpart = (int)num;
|
|
|
|
|
double fracpart = num - (double)integerpart;
|
|
|
|
|
pointer = sitoa(integerpart, str, 0xFFFFFFFF);
|
|
|
|
|
if (precision != 0)
|
|
|
|
|
{
|
|
|
|
|
*pointer = '.';
|
|
|
|
|
fracpart = fracpart * pow(10, precision);
|
|
|
|
|
sitoa((u32)fracpart, pointer+1, 0xFFFFFFFF);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
|
/* converti un r<>el sign<67> en chaine de caract<63>re */
|
|
|
|
|
u8 *rtoasingle(float num, u8 * str, u8 precision) {
|
|
|
|
|
u8 *pointer=str;
|
|
|
|
|
u32 integerpart = (int)num;
|
|
|
|
|
float fracpart = num - (float)integerpart;
|
|
|
|
|
pointer = sitoa(integerpart, str, 0xFFFFFFFF);
|
|
|
|
|
if (precision != 0)
|
|
|
|
|
{
|
|
|
|
|
*pointer = '.';
|
|
|
|
|
fracpart = fracpart * pow(10, precision);
|
|
|
|
|
sitoa((u32)fracpart, pointer+1, 0xFFFFFFFF);
|
|
|
|
|
}
|
|
|
|
|
return pointer;
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-02 15:21:28 +02:00
|
|
|
|
/*******************************************************************************/
|
2018-08-29 10:12:00 +02:00
|
|
|
|
/* converti un entier non sign<67> en chaine de caract<63>re */
|
|
|
|
|
|
2018-09-27 21:01:02 +02:00
|
|
|
|
u8 *itoa(u64 orignum, u8 * str, u8 base, u64 dim, u8 achar)
|
2018-08-29 10:12:00 +02:00
|
|
|
|
{
|
2018-09-27 17:47:27 +02:00
|
|
|
|
u8 *pointer = str, i, size = 0;
|
2018-09-27 21:01:02 +02:00
|
|
|
|
u64 num = orignum;
|
2018-09-27 17:47:27 +02:00
|
|
|
|
num &= dim;
|
|
|
|
|
if (num == 0 && (achar == 0)) {
|
|
|
|
|
*(pointer++) = '0';
|
|
|
|
|
*pointer = '\000';
|
2018-10-04 21:49:06 +02:00
|
|
|
|
return pointer;
|
2018-09-27 17:47:27 +02:00
|
|
|
|
}
|
|
|
|
|
switch (base) {
|
|
|
|
|
case 2:
|
|
|
|
|
size = log2(dim);
|
|
|
|
|
break;
|
|
|
|
|
case 8:
|
|
|
|
|
size = log2(dim) / 2;
|
|
|
|
|
break;
|
|
|
|
|
case 10:
|
|
|
|
|
size = log10(dim);
|
|
|
|
|
break;
|
|
|
|
|
case 16:
|
|
|
|
|
size = log2(dim) / 4;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
for (i = 0; i < size; i++) {
|
2018-09-28 00:03:45 +02:00
|
|
|
|
if (num == 0) {
|
|
|
|
|
if (achar == 0) break;
|
|
|
|
|
*(pointer++) = achar;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-09-27 21:01:02 +02:00
|
|
|
|
u64 result = num % (u32) base;
|
2018-09-28 00:03:45 +02:00
|
|
|
|
*(pointer++) = (result > 9) ? (result - 10) + 'a' : result + '0';
|
2018-09-27 17:47:27 +02:00
|
|
|
|
num = num / (u32) base;
|
2018-09-28 00:03:45 +02:00
|
|
|
|
}
|
2018-09-27 17:47:27 +02:00
|
|
|
|
}
|
|
|
|
|
*pointer = '\000';
|
|
|
|
|
strinvert(str);
|
2018-10-04 21:49:06 +02:00
|
|
|
|
return pointer;
|
2018-08-29 10:12:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
|
/* converti un entier en chaine de caract<63>re */
|
|
|
|
|
|
2018-09-28 00:03:45 +02:00
|
|
|
|
u8 *sitoa(u64 num, u8 * str, u64 dim)
|
2018-08-29 10:12:00 +02:00
|
|
|
|
{
|
2018-09-27 17:47:27 +02:00
|
|
|
|
u8 *pointer = str;
|
|
|
|
|
bool isNegative = false;
|
|
|
|
|
num &= dim;
|
|
|
|
|
if (num == 0) {
|
2018-10-04 21:49:06 +02:00
|
|
|
|
*(pointer++) = '0';
|
2018-09-27 17:47:27 +02:00
|
|
|
|
*pointer = '\000';
|
2018-10-04 21:49:06 +02:00
|
|
|
|
return pointer;
|
2018-09-27 17:47:27 +02:00
|
|
|
|
}
|
2018-09-28 00:03:45 +02:00
|
|
|
|
if ((((dim+1)>>1)&num)>0) {
|
2018-09-27 17:47:27 +02:00
|
|
|
|
isNegative = true;
|
2018-09-28 00:03:45 +02:00
|
|
|
|
num = (~num&dim)+1;
|
2018-09-27 17:47:27 +02:00
|
|
|
|
}
|
|
|
|
|
while (num != 0) {
|
2018-09-28 00:03:45 +02:00
|
|
|
|
u64 result = num % 10;
|
2018-09-27 17:47:27 +02:00
|
|
|
|
*(pointer++) =
|
|
|
|
|
(result > 9) ? (result - 10) + 'a' : result + '0';
|
|
|
|
|
num = num / 10;
|
|
|
|
|
}
|
|
|
|
|
if (isNegative)
|
|
|
|
|
*(pointer++) = '-';
|
|
|
|
|
*pointer = '\000';
|
|
|
|
|
strinvert(str);
|
2018-10-04 21:49:06 +02:00
|
|
|
|
return pointer;
|
2018-08-29 10:12:00 +02:00
|
|
|
|
}
|
2018-09-28 20:35:51 +02:00
|
|
|
|
/*******************************************************************************/
|