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-08-29 10:12:00 +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-08-29 10:12:00 +02:00
|
|
|
|
i++;
|
2018-08-17 16:46:56 +02:00
|
|
|
|
}
|
2018-08-29 10:12:00 +02:00
|
|
|
|
return i;
|
2007-04-02 15:21:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
|
|
2018-08-29 10:12:00 +02:00
|
|
|
|
# define buffersize 1024
|
|
|
|
|
|
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-29 10:12:00 +02:00
|
|
|
|
u32 printf(const u8 *string, ...)
|
2007-04-02 15:21:28 +02:00
|
|
|
|
{
|
2018-08-29 10:12:00 +02:00
|
|
|
|
va_list args;
|
|
|
|
|
u32 sizes[]={0xFF,0xFFFF,0xFFFFFFFF};
|
2018-08-30 01:07:28 +02:00
|
|
|
|
u8 strbase2[] = "b\000";
|
|
|
|
|
u8 strbase8[] = "o\000";
|
|
|
|
|
u8 strbase16[] = "h\000";
|
2018-08-29 10:12:00 +02:00
|
|
|
|
u8 hexadecimal[]="*0x\000";
|
2018-08-30 01:07:28 +02:00
|
|
|
|
u8 achar,temp;
|
|
|
|
|
u8 asize,charadd;
|
2018-08-29 10:12:00 +02:00
|
|
|
|
u8 buffer[buffersize];
|
|
|
|
|
u8 *str = string;
|
|
|
|
|
u8 *strtemp;
|
|
|
|
|
u32 i = 0, counter = 0;
|
|
|
|
|
u32 num;
|
|
|
|
|
bool flag=false;
|
2018-08-17 16:46:56 +02:00
|
|
|
|
|
2018-08-29 10:12:00 +02:00
|
|
|
|
va_start(args, string);
|
|
|
|
|
for (achar = *str; achar != '\000'; i++, achar = *(str + i))
|
|
|
|
|
{
|
|
|
|
|
if (achar != '%' && !flag)
|
|
|
|
|
{
|
|
|
|
|
putchar(achar);
|
|
|
|
|
counter++;
|
|
|
|
|
asize=2;
|
2018-08-30 01:07:28 +02:00
|
|
|
|
charadd=0xFF;
|
2018-08-29 10:12:00 +02:00
|
|
|
|
}
|
|
|
|
|
else if (achar == '%' || flag)
|
|
|
|
|
{
|
2018-08-30 01:07:28 +02:00
|
|
|
|
if (!flag) ++i;
|
2018-08-29 10:12:00 +02:00
|
|
|
|
achar = *(str + i);
|
|
|
|
|
switch(achar)
|
|
|
|
|
{
|
|
|
|
|
case '0':
|
|
|
|
|
charadd='0';
|
|
|
|
|
flag=true;
|
2018-08-30 01:07:28 +02:00
|
|
|
|
break;
|
2018-08-29 10:12:00 +02:00
|
|
|
|
case ' ':
|
|
|
|
|
charadd=' ';
|
|
|
|
|
flag=true;
|
2018-08-30 01:07:28 +02:00
|
|
|
|
break;
|
2018-08-29 10:12:00 +02:00
|
|
|
|
case 'h':
|
|
|
|
|
asize--;
|
|
|
|
|
flag=true;
|
2018-08-30 01:07:28 +02:00
|
|
|
|
break;
|
2018-08-29 10:12:00 +02:00
|
|
|
|
case 'l':
|
|
|
|
|
asize++;
|
|
|
|
|
flag=true;
|
2018-08-30 01:07:28 +02:00
|
|
|
|
break;
|
2018-08-29 10:12:00 +02:00
|
|
|
|
case 'u':
|
|
|
|
|
num = (u32)va_arg(args, int);
|
2018-08-30 01:07:28 +02:00
|
|
|
|
if (charadd==0xFF)
|
|
|
|
|
charadd='0';
|
|
|
|
|
itoa(num, &buffer, 10, sizes[asize], charadd);
|
|
|
|
|
counter += print(&buffer);
|
2018-08-29 10:12:00 +02:00
|
|
|
|
flag=false;
|
2018-08-30 01:07:28 +02:00
|
|
|
|
break;
|
2018-08-29 10:12:00 +02:00
|
|
|
|
case 'o':
|
|
|
|
|
num = (u32)va_arg(args, int);
|
2018-08-30 01:07:28 +02:00
|
|
|
|
if (charadd==0xFF)
|
|
|
|
|
charadd='0';
|
|
|
|
|
itoa(num, &buffer, 8, sizes[asize], charadd);
|
|
|
|
|
counter += print(&buffer)+1;
|
|
|
|
|
print(&strbase8);
|
2018-08-29 10:12:00 +02:00
|
|
|
|
flag=false;
|
2018-08-17 16:46:56 +02:00
|
|
|
|
break;
|
2018-08-29 10:12:00 +02:00
|
|
|
|
case 'c':
|
|
|
|
|
temp = (u8)va_arg(args, int);
|
|
|
|
|
putchar(temp);
|
|
|
|
|
counter++;
|
|
|
|
|
flag=false;
|
2018-08-17 16:46:56 +02:00
|
|
|
|
break;
|
|
|
|
|
case 'd':
|
2018-08-29 10:12:00 +02:00
|
|
|
|
case 'i':
|
|
|
|
|
num = (int)va_arg(args, int);
|
2018-08-30 01:07:28 +02:00
|
|
|
|
if (charadd==0xFF)
|
|
|
|
|
charadd=' ';
|
|
|
|
|
sitoa(num, &buffer, sizes[asize]);
|
|
|
|
|
counter += print(&buffer);
|
2018-08-29 10:12:00 +02:00
|
|
|
|
flag=false;
|
|
|
|
|
break;
|
2018-08-17 16:46:56 +02:00
|
|
|
|
case 's':
|
2018-08-29 10:12:00 +02:00
|
|
|
|
strtemp = (u8 *)va_arg(args, u8 *);
|
|
|
|
|
counter += print(strtemp);
|
|
|
|
|
flag=false;
|
2018-08-17 16:46:56 +02:00
|
|
|
|
break;
|
2018-08-29 10:12:00 +02:00
|
|
|
|
case 'p':
|
|
|
|
|
num = (u32)va_arg(args, int);
|
2018-08-30 01:07:28 +02:00
|
|
|
|
if (charadd==0xFF)
|
|
|
|
|
charadd='0';
|
|
|
|
|
print(&hexadecimal);
|
|
|
|
|
itoa(num, buffer, 16, sizes[asize], '0');
|
|
|
|
|
counter += print(&buffer)+2;
|
2018-08-29 10:12:00 +02:00
|
|
|
|
flag=false;
|
|
|
|
|
break;
|
|
|
|
|
case 'x':
|
|
|
|
|
case 'X':
|
|
|
|
|
num = (u32)va_arg(args, int);
|
2018-08-30 01:07:28 +02:00
|
|
|
|
if (charadd==0xFF)
|
|
|
|
|
charadd='0';
|
|
|
|
|
itoa(num, &buffer, 16, sizes[asize], charadd);
|
2018-08-29 10:12:00 +02:00
|
|
|
|
if (achar=='X')
|
2018-08-30 01:07:28 +02:00
|
|
|
|
strtoupper(&buffer);
|
|
|
|
|
counter += print(&buffer)+1;
|
|
|
|
|
print(&strbase16);
|
2018-08-29 10:12:00 +02:00
|
|
|
|
flag=false;
|
2018-08-17 16:46:56 +02:00
|
|
|
|
break;
|
2018-08-29 10:12:00 +02:00
|
|
|
|
case 'b':
|
|
|
|
|
num = (u32)va_arg(args, int);
|
2018-08-30 01:07:28 +02:00
|
|
|
|
if (charadd==0xFF)
|
|
|
|
|
charadd='0';
|
|
|
|
|
itoa(num, &buffer, 2, sizes[asize], charadd);
|
|
|
|
|
counter += print(&buffer)+1;
|
|
|
|
|
print(&strbase2);
|
2018-08-29 10:12:00 +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-08-29 10:12:00 +02:00
|
|
|
|
|
|
|
|
|
/* converti un entier non sign<67> en chaine de caract<63>re */
|
|
|
|
|
|
2018-08-30 01:07:28 +02:00
|
|
|
|
u8* itoa(u32 orignum, u8* str, u8 base, u32 dim, u8 achar)
|
2018-08-29 10:12:00 +02:00
|
|
|
|
{
|
2018-08-30 01:07:28 +02:00
|
|
|
|
u32 sizes[]={0xFF,0xFFFF,0xFFFFFFFF};
|
|
|
|
|
u8 *pointer = str, i, size=0;
|
|
|
|
|
u32 num=orignum;
|
|
|
|
|
num&=dim;
|
|
|
|
|
if (num == 0 && (achar==0))
|
2018-08-29 10:12:00 +02:00
|
|
|
|
{
|
2018-08-30 01:07:28 +02:00
|
|
|
|
*(pointer++) = '0';
|
|
|
|
|
*pointer = '\000';
|
2018-08-29 10:12:00 +02:00
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
switch (base)
|
|
|
|
|
{
|
|
|
|
|
case 2:
|
2018-08-30 01:07:28 +02:00
|
|
|
|
size=log2(dim);
|
2018-08-29 10:12:00 +02:00
|
|
|
|
break;
|
|
|
|
|
case 8:
|
2018-08-30 01:07:28 +02:00
|
|
|
|
size=log2(dim)/2;
|
2018-08-29 10:12:00 +02:00
|
|
|
|
break;
|
|
|
|
|
case 10:
|
2018-08-30 01:07:28 +02:00
|
|
|
|
size=log10(dim);
|
2018-08-29 10:12:00 +02:00
|
|
|
|
break;
|
|
|
|
|
case 16:
|
2018-08-30 01:07:28 +02:00
|
|
|
|
size=log2(dim)/4;
|
2018-08-29 10:12:00 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
2018-08-30 01:07:28 +02:00
|
|
|
|
for(i=0;i<size;i++)
|
2018-08-29 10:12:00 +02:00
|
|
|
|
{
|
|
|
|
|
u32 result = num % (u32)base;
|
2018-08-30 01:07:28 +02:00
|
|
|
|
*(pointer++) = (result > 9)? (result-10) + 'a' : result + '0';
|
2018-08-29 10:12:00 +02:00
|
|
|
|
num = num / (u32)base;
|
|
|
|
|
if ((num==0) && (achar==0))
|
|
|
|
|
break;
|
|
|
|
|
}
|
2018-08-30 01:07:28 +02:00
|
|
|
|
*pointer = '\000';
|
2018-08-29 10:12:00 +02:00
|
|
|
|
strinvert(str);
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
|
|
|
|
|
|
/* converti un entier en chaine de caract<63>re */
|
|
|
|
|
|
2018-08-30 01:07:28 +02:00
|
|
|
|
u8* sitoa(int num, u8* str, u32 dim)
|
2018-08-29 10:12:00 +02:00
|
|
|
|
{
|
2018-08-30 01:07:28 +02:00
|
|
|
|
u8 *pointer = str;
|
2018-08-29 10:12:00 +02:00
|
|
|
|
bool isNegative = false;
|
2018-08-30 01:07:28 +02:00
|
|
|
|
num&=dim;
|
2018-08-29 10:12:00 +02:00
|
|
|
|
if (num == 0)
|
|
|
|
|
{
|
2018-08-30 01:07:28 +02:00
|
|
|
|
*pointer++ = '0';
|
|
|
|
|
*pointer = '\000';
|
2018-08-29 10:12:00 +02:00
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
if (num < 0)
|
|
|
|
|
{
|
|
|
|
|
isNegative = true;
|
|
|
|
|
num = -num;
|
|
|
|
|
}
|
|
|
|
|
while (num != 0)
|
|
|
|
|
{
|
|
|
|
|
u32 result = num % 10;
|
2018-08-30 01:07:28 +02:00
|
|
|
|
*(pointer++) = (result > 9)? (result-10) + 'a' : result + '0';
|
2018-08-29 10:12:00 +02:00
|
|
|
|
num = num/ 10;
|
|
|
|
|
}
|
|
|
|
|
if (isNegative)
|
2018-08-30 01:07:28 +02:00
|
|
|
|
*(pointer++) = '-';
|
|
|
|
|
*pointer = '\000';
|
2018-08-29 10:12:00 +02:00
|
|
|
|
strinvert(str);
|
|
|
|
|
return str;
|
|
|
|
|
}
|