From 8de17f2ec3e91b70061b801cc57d97d3adca2ef6 Mon Sep 17 00:00:00 2001 From: nucho Date: Sat, 17 Mar 2012 17:09:53 +0900 Subject: Added Print class --- src/core/Print.cpp | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/core/Print.h | 40 ++++++++++++++++++++ 2 files changed, 149 insertions(+) create mode 100644 src/core/Print.cpp create mode 100644 src/core/Print.h diff --git a/src/core/Print.cpp b/src/core/Print.cpp new file mode 100644 index 0000000..ab58b9f --- /dev/null +++ b/src/core/Print.cpp @@ -0,0 +1,109 @@ +#include "Print.h" + +void Print::print(const char *s) //uart_puts +{ + int n; + for (n = 0; *s; s++, n++) { + write(*s); + } + //return n; + return; +} + +void Print::print(int val, RADIX_FORMAT format) +{ + if(format == BYTE) + { + write((char)(val & 0xff)); + return; + } + char s[32]; + int i,j; + i=j=0; // header of strings + if (val<0) + { //minus value + s[i]='-'; + val=~val+1; + i++; + j++; + } + switch(format) + { + case BIN: + while (val>0) + { // do until zero + s[i++]=radix_bin[val%format]; + val/=format; + } + break; + + case OCT: + while (val>0) + { // do until zero + s[i++]=radix_oct[val%format]; + val/=format; + } + break; + + case DEC: //RADIX = Decimal + while (val>0) + { // do until zero + s[i++]=radix_dec[val%format]; + val/=format; + } + break; + + case HEX: //RADIX = Hexadecimal + while (val>0) + { // do until zero + s[i++]=radix_hex[val%format]; + val/=format; + } + break; + default: + break; + } + s[i--]='\0'; // EOF + while (j