summaryrefslogtreecommitdiffstats
path: root/arch/x86/inc
diff options
context:
space:
mode:
authorAlexey Gavrilov <rebovas@yahoo.com>2023-08-20 20:12:36 +0700
committerAlexey Gavrilov <rebovas@yahoo.com>2023-08-20 20:12:36 +0700
commitb82ccebd3a0cce28177b5fac046139e2de7737fa (patch)
treeb4e048eb7bed81a726340fb98690dce62eed7475 /arch/x86/inc
parenta601dbb1dd5569243fd3006a27e914491fc3f35e (diff)
Getting started with print on display + some fixes
Diffstat (limited to 'arch/x86/inc')
-rw-r--r--arch/x86/inc/TypeConverter.cpp41
-rw-r--r--arch/x86/inc/TypeConverter.h17
-rw-r--r--arch/x86/inc/types.h5
3 files changed, 63 insertions, 0 deletions
diff --git a/arch/x86/inc/TypeConverter.cpp b/arch/x86/inc/TypeConverter.cpp
new file mode 100644
index 0000000..23119a2
--- /dev/null
+++ b/arch/x86/inc/TypeConverter.cpp
@@ -0,0 +1,41 @@
+#include "TypeConverter.h"
+
+void IntConverter::clearBuff()
+{
+ for(int i = 0; i < 21; i++) buffer[i] = '\0';
+};
+
+char *IntConverter::intToChar(int n)
+{
+ clearBuff();
+
+ int number = n >> 31; // n < 0 - n = -1, else n = 0
+ number = (n ^ number) - number; // Clear sign bit
+
+ bool isNegative = n < 0;
+ unsigned int indx = 19;
+
+ do {
+ buffer[indx--] = 48 + (number % 10);
+ number /= 10;
+ }while(number != 0);
+
+ if(isNegative) buffer[indx--] = '-';
+
+ return &buffer[++indx];
+};
+
+char *IntConverter::uintToChar(unsigned int n)
+{
+ clearBuff();
+
+ unsigned int number = n;
+ unsigned int indx = 19;
+
+ do {
+ buffer[indx--] = 48 + (number % 10);
+ number /= 10;
+ }while(number != 0);
+
+ return &buffer[++indx];
+};
diff --git a/arch/x86/inc/TypeConverter.h b/arch/x86/inc/TypeConverter.h
new file mode 100644
index 0000000..93d2c8c
--- /dev/null
+++ b/arch/x86/inc/TypeConverter.h
@@ -0,0 +1,17 @@
+#ifndef TYPECONVERTER_H
+#define TYPECONVERTER_H
+
+#include "../io/VGADisplay.h"
+
+class IntConverter
+{
+ private:
+ char buffer[21];
+ void clearBuff();
+
+ public:
+ char *intToChar(int n);
+ char *uintToChar(unsigned int n);
+};
+
+#endif
diff --git a/arch/x86/inc/types.h b/arch/x86/inc/types.h
new file mode 100644
index 0000000..d688a35
--- /dev/null
+++ b/arch/x86/inc/types.h
@@ -0,0 +1,5 @@
+
+typedef unsigned char uint8;
+typedef unsigned int uint16;
+typedef unsigned long uint32;
+typedef unsigned long long uint64;