From 12f395461e4f3b41bdfb50cc983b46364a97616e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Hord=C3=A9?= Date: Sun, 7 Oct 2018 12:57:38 +0200 Subject: [PATCH] fix: ajout d'une fonction sprintf, corrections diverses fonction utilisant printf --- include/video.h | 4 ++ lib/multiboot.c | 6 +-- lib/shell.c | 23 +++++----- lib/video.c | 117 +++++++++++++++++++++++++++++++++++------------- system/system.c | 8 ++-- 5 files changed, 109 insertions(+), 49 deletions(-) diff --git a/include/video.h b/include/video.h index 34e79a2..0877148 100755 --- a/include/video.h +++ b/include/video.h @@ -1,6 +1,9 @@ /*******************************************************************************/ /* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */ /* */ + +#include "stdarg.h" + typedef struct console { u8 attrib; s16 cursX; @@ -22,3 +25,4 @@ u8* itoa(u64 num, u8* str, u8 base, u64 dim, u8 achar); u8* sitoa(u64 num, u8 * str, u64 dim); u8* rtoadouble(double num, u8 * str, u8 precisioni , u8 precisionf); u8* rtoasingle(float num, u8 * str, u8 precisioni , u8 precisionf); +u32 format(const u8 * string, va_list args, u32 (*fonction)(u8* src, u8** dest, u32 len), u8* dest); diff --git a/lib/multiboot.c b/lib/multiboot.c index 019c9fc..0a78df2 100644 --- a/lib/multiboot.c +++ b/lib/multiboot.c @@ -28,7 +28,7 @@ for (tag = (struct multiboot_tag *) (addr + 8); tag->type != MULTIBOOT_TAG_TYPE_END; tag = (struct multiboot_tag *) ((u8 *) tag + ((tag->size + 7) & ~7))) { - printf ("--- Tag % 4u, Taille % 4u\r\n", tag->type, tag->size); + printf ("--- Tag % hu, Taille % hu\r\n", tag->type, tag->size); switch (tag->type) { case MULTIBOOT_TAG_TYPE_CMDLINE: @@ -51,7 +51,7 @@ for (tag = (struct multiboot_tag *) (addr + 8); ((u64)((struct multiboot_tag_basic_meminfo *) tag)->mem_upper)<<10); break; case MULTIBOOT_TAG_TYPE_BOOTDEV: - printf ("Peripherique de demarrage : %x,%u,%u\r\n\r\n", + printf ("Peripherique de demarrage : %X,%u,%u\r\n\r\n", ((struct multiboot_tag_bootdev *) tag)->biosdev, ((struct multiboot_tag_bootdev *) tag)->slice, ((struct multiboot_tag_bootdev *) tag)->part); @@ -62,7 +62,7 @@ for (tag = (struct multiboot_tag *) (addr + 8); printf ("*** Plan de memoire ***\r\n"); for (mmap = ((struct multiboot_tag_mmap *) tag)->entries;(u8 *) mmap < (u8 *) tag + tag->size; mmap = (multiboot_memory_map_t *) ((unsigned long) mmap + ((struct multiboot_tag_mmap *) tag)->entry_size)) - printf (" adresse: %lx,"" taille:%lx, type:%x\r\n", + printf (" adresse: %lX,"" taille:%lX, type:%X\r\n", (u64) (mmap->addr), (u64) (mmap->len), (u32) (mmap->type)); diff --git a/lib/shell.c b/lib/shell.c index 0747ce2..205efde 100644 --- a/lib/shell.c +++ b/lib/shell.c @@ -224,28 +224,29 @@ int readidt() u32 offset = desc[index].offset0_15 + (desc[index].offset16_31 << 16); u32 type = desc[index].type & 0x0F00; - u8 *type2; + u8 *typestr1, *typestr2; if (i>=32 & i<=39) - type2="IRQ master"; + typestr1="IRQ master"; else if (i>=96 & i<=103) - type2="IRQ slave "; + typestr1="IRQ slave "; else if (i<19) - type2="EXCEPTION "; + typestr1="EXCEPTION "; else - type2="INTERRUPT "; - printf("\r\%s % hu %hY:%Y - ", type2,i++, select, offset, type); + typestr1="INTERRUPT "; if (type == INTGATE) - print("INTGATE"); + typestr2="INTGATE"; else if (type == TRAPGATE) - print("TRAPGATE"); + typestr2="TRAPGATE"; else if (type == TASKGATE) - print("TASKGATE"); + typestr2="TASKGATE"; else if (type == CALLGATE) - print("CALLGATE"); + typestr2="CALLGATE"; else if (type == LDTDES) - print("LDTDES"); + typestr2="LDTDES"; else print("inconnu"); + printf("%s % hu %hY:%Y - %s\r\n", typestr1, i++, select, offset, typestr2); + if (i % 32 == 0) { print("\r\n\r\n"); waitascii(); diff --git a/lib/video.c b/lib/video.c index 230da08..8af9d69 100755 --- a/lib/video.c +++ b/lib/video.c @@ -299,13 +299,54 @@ u32 print(u8 * string) } /*******************************************************************************/ -/* affiche une chaine de caractère formaté a l'ecran */ +/* Fonction d'affichage (pour printf) */ -#define buffersize 1024 +u32 printstr(u8* src, u8** dest, u32 len) { + for(u32 i=0;i>10; unit++; } - sitoa(num, &buffer, sizes[asize]); - counter += print(&buffer); - print(units[unit]); + bufferend=sitoa(num, &buffer, sizes[asize]); + buffersize=bufferend-&buffer[0]; + counter += fonction(&buffer,&dest,buffersize); + counter += fonction(units[unit],&dest,3); flag = false; break; case 'd': @@ -489,22 +535,24 @@ u32 printf(const u8 * string, ...) num = (u64) va_arg(args, u64); if (charadd == 0xFF) charadd = ' '; - sitoa(num, &buffer, sizes[asize]); - counter += print(&buffer); + bufferend=sitoa(num, &buffer, sizes[asize]); + buffersize=bufferend-&buffer[0]; + counter += fonction(&buffer,&dest,buffersize); flag = false; break; case 's': strtemp = (u8 *) va_arg(args, u8 *); - counter += print(strtemp); + counter += fonction(strtemp,&dest,strlen(strtemp)); flag = false; break; case 'p': num = (u32) va_arg(args, int); if (charadd == 0xFF) charadd = '0'; - print(&hexadecimal); - itoa(num, buffer, 16, sizes[asize], '0'); - counter += print(&buffer) + 2; + counter += fonction(&hexadecimal,&dest,3); + bufferend=itoa(num, &buffer, 16, sizes[asize], '0'); + buffersize=bufferend-&buffer[0]; + counter += fonction(&buffer,&dest,buffersize); flag = false; break; case 'x': @@ -521,11 +569,12 @@ u32 printf(const u8 * string, ...) num = (u64) va_arg(args, u64); if (charadd == 0xFF) charadd = '0'; - itoa(num, &buffer, 16, sizes[asize], charadd); + if (achar == 'X') counter += fonction(&strbase16,&dest,2); + bufferend=itoa(num, &buffer, 16, sizes[asize], charadd); + buffersize=bufferend-&buffer[0]; if (achar == 'X'||achar == 'Y') strtoupper(&buffer); - if (achar == 'X') print(&strbase16); - counter += print(&buffer) + 1; + counter += fonction(&buffer,&dest,buffersize); flag = false; break; case 'b': @@ -539,9 +588,10 @@ u32 printf(const u8 * string, ...) num = (u64) va_arg(args, u64); if (charadd == 0xFF) charadd = '0'; - itoa(num, &buffer, 2, sizes[asize], charadd); - print(&strbase2); - counter += print(&buffer) + 1; + counter += fonction(&strbase2,&dest,2); + bufferend=itoa(num, &buffer, 2, sizes[asize], charadd); + buffersize=bufferend-&buffer[0]; + counter += fonction(&buffer,&dest,buffersize); flag = false; break; default: @@ -549,7 +599,7 @@ u32 printf(const u8 * string, ...) } } } - va_end(args); + return counter; } @@ -562,6 +612,9 @@ u8 *rtoadouble(double num, u8 * str, u8 precisioni , u8 precisionf) { u8 i,j,integerpart,fracpart; if (precisioni==0) precisioni=12; if (precisionf==0) precisionf=8; + double round=0.5; + for (i=0;i