From e0c565f7ff7620dca9dfc6c607f4798f5291c7bf Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Tue, 28 Jul 2015 14:19:00 +0400 Subject: Go back to C and adapt code --- kernel/Helpers/Makefile | 14 ++--- kernel/Helpers/globalVars.hpp | 0 kernel/Helpers/memPrint.cpp | 125 ------------------------------------------ kernel/Helpers/memPrint.hpp | 81 --------------------------- kernel/Helpers/memory.c | 31 +++++++++++ kernel/Helpers/memory.cpp | 31 ----------- kernel/Helpers/memory.h | 10 ++++ kernel/Helpers/memory.hpp | 10 ---- kernel/Helpers/memprint.c | 111 +++++++++++++++++++++++++++++++++++++ kernel/Helpers/memprint.h | 59 ++++++++++++++++++++ kernel/Helpers/types.h | 14 +++++ kernel/Helpers/types.hpp | 14 ----- 12 files changed, 232 insertions(+), 268 deletions(-) delete mode 100644 kernel/Helpers/globalVars.hpp delete mode 100644 kernel/Helpers/memPrint.cpp delete mode 100644 kernel/Helpers/memPrint.hpp create mode 100644 kernel/Helpers/memory.c delete mode 100644 kernel/Helpers/memory.cpp create mode 100644 kernel/Helpers/memory.h delete mode 100644 kernel/Helpers/memory.hpp create mode 100644 kernel/Helpers/memprint.c create mode 100644 kernel/Helpers/memprint.h create mode 100644 kernel/Helpers/types.h delete mode 100644 kernel/Helpers/types.hpp (limited to 'kernel/Helpers') diff --git a/kernel/Helpers/Makefile b/kernel/Helpers/Makefile index 76805bd..a813312 100644 --- a/kernel/Helpers/Makefile +++ b/kernel/Helpers/Makefile @@ -1,23 +1,23 @@ EXEC=helpers.o - all:$(EXEC) #----- Helpers ----- -$(EXEC): memory.o memPrint.o - ld -m elf_i386 -r -o $(EXEC) $^ +$(EXEC): memory.o memprint.o +# ld -m elf_i386 -r -o $(EXEC) $^ + ar -r -o $(EXEC) $^ #--------------- #----- Memory ----- -memory.o: memory.cpp memory.hpp - $(CXX) -c -o $@ $< +memory.o: memory.c memory.h + $(CC) $(CFLAGS) -c -o $@ $< #------------------ #----- memPrint ----- -memPrint.o: memPrint.cpp memPrint.hpp - $(CXX) -c -o $@ $< +memprint.o: memprint.c memprint.h + $(CC) $(CFLAGS) -c -o $@ $< #------------------- diff --git a/kernel/Helpers/globalVars.hpp b/kernel/Helpers/globalVars.hpp deleted file mode 100644 index e69de29..0000000 diff --git a/kernel/Helpers/memPrint.cpp b/kernel/Helpers/memPrint.cpp deleted file mode 100644 index 179b821..0000000 --- a/kernel/Helpers/memPrint.cpp +++ /dev/null @@ -1,125 +0,0 @@ -#include "./memPrint.hpp" - - - -//Constructor -memPrint::memPrint(){ - - //Initialise position - this->m_cursorX=0; - this->m_cursorY=0; - - //Initialise color - this->setBackground(BLACK); - this->setForeground(WHITE); - -} - -//Destructor -memPrint::~memPrint(){ - -} - - -//Move cursor -void memPrint::updateCursor(){ - - - //Update X axis - this->m_cursorX++; - - //Check X value - if(this->m_cursorX >= MAXCURSORX){ - - //If X is out of the screen - this->m_cursorX=0; - - //Update Y - this->m_cursorY++; - - //Check Y value - if(this->m_cursorY >= MAXCURSORY){ - - //If Y is out of the screen - this->scrollUp(1); - - //Decrease Y value - this->m_cursorY--; - } - - - } - - -} - -//Change character background color -void memPrint::setBackground(colorBios color){ - u8 newColor= (color << 4); - this->m_colors= newColor | ((this->m_colors << 4) >> 4); -} - -//Change character color -void memPrint::setForeground(colorBios color){ - u8 newColor= color; - this->m_colors= newColor | ((this->m_colors >> 4) << 4); -} - -//Print a char -void memPrint::putChar(u8 character){ - - //Get the adresse with the cursor position - char *adress= ((char *) MEMPRINTSTARTADR) + (this->m_cursorX * 2) + (this->m_cursorY * MAXCURSORX * 2); - - //Copy the character - *adress=character; - - //Copy his attribute - adress++; - *adress=this->m_colors; - - //Update cursor position - this->updateCursor(); - -} - - -//Print a char* -void memPrint::print(char *str){ - while(*str!=0x0){ - this->putChar(*str); - str++; - } -} - -//Clear the screen -void memPrint::clear(){ - this->scrollUp(MAXCURSORY); -} - -//Scroll up "number" times -void memPrint::scrollUp(u8 number){ - - //Get number of adress (char & his attribute) to scroll - int nbAdrToScroll=number*MAXCURSORX*2; - - - //Scroll all of the characters and attributes - for(int i=0;i!=MAXCURSORX*2*MAXCURSORY;i++){ - - //Get source character or attribute - char* source=(((char *)MEMPRINTSTARTADR) + i); - - //Get destination character or attribute - char* dest=source-nbAdrToScroll; - - //Check if destination is out of the screen - if(dest >= (char *)MEMPRINTSTARTADR) - *dest=*source; - - //Remove data from source - *source=0x0; - - } - -} diff --git a/kernel/Helpers/memPrint.hpp b/kernel/Helpers/memPrint.hpp deleted file mode 100644 index 19a6708..0000000 --- a/kernel/Helpers/memPrint.hpp +++ /dev/null @@ -1,81 +0,0 @@ -#ifndef __memPrint__ -#define __memPrint__ - -#include "./types.hpp" - - -#define MEMPRINTSTARTADR 0xB8000 -#define MAXCURSORX 80 -#define MAXCURSORY 25 - - - - -//Define the bios color -enum colorBios{ - - BLACK=0x0, - BLUE=0x1, - GREEN=0x2, - CYAN=0x3, - RED=0x4, - MAGENTA=0x5, - BROWN=0x6, - LIGHTGRAY=0x7, - DARKGRAY=0x8, - LIGHTBLUE=0x9, - LIGHTGREEN=0xA, - LIGHTCYAN=0xB, - LIGHTRED=0xC, - LIGHTMAGENTA=0xD, - YELLOW=0xE, - WHITE=0xF - -}; - -//Type def for biosColor -typedef enum colorBios colorBios; - - -//Class to print char on screen using Video Ram mapping -class memPrint{ - - private: - - //Cursor position - u8 m_cursorX; - u8 m_cursorY; - - //Current colors (background and foreground): - u8 m_colors; - - //Methods - void updateCursor(); - - public: - - //Constructor - memPrint(); - - //Destructor - ~memPrint(); - - //Set color - void setBackground(colorBios color); - void setForeground(colorBios color); - - //Putchar - void putChar(u8 character); - - //Print - void print(char *str); - - //Scroll up - void scrollUp(u8 number); - - //Clear screen - void clear(); - -}; - -#endif diff --git a/kernel/Helpers/memory.c b/kernel/Helpers/memory.c new file mode 100644 index 0000000..44c0e90 --- /dev/null +++ b/kernel/Helpers/memory.c @@ -0,0 +1,31 @@ +#include "./memory.h" +#include "./types.h" + +//Fonction to copy data into memory +int memcpy(u32 source, u32 dest, u32 size){ + + //Init source and destination pointer + u32 *sourceTmp=(u32 *)source; + u32 *destTmp=(u32 *)dest; + + //Init progression + u32 progress=0; + + //Start copy + while(progress != size){ + + //Copy + *destTmp=*sourceTmp; + + //Update source and destination + sourceTmp++; + destTmp++; + + //Update progression + progress++; + } + + //End and return progression + return progress; + +} diff --git a/kernel/Helpers/memory.cpp b/kernel/Helpers/memory.cpp deleted file mode 100644 index 8ace044..0000000 --- a/kernel/Helpers/memory.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include "./memory.hpp" -#include "./types.hpp" - -//Fonction to copy data into memory -int memcpy(u32 source, u32 dest, u32 size){ - - //Init source and destination pointer - u32 *sourceTmp=(u32 *)source; - u32 *destTmp=(u32 *)dest; - - //Init progression - u32 progress=0; - - //Start copy - while(progress != size){ - - //Copy - *destTmp=*sourceTmp; - - //Update source and destination - sourceTmp++; - destTmp++; - - //Update progression - progress++; - } - - //End and return progression - return progress; - -} diff --git a/kernel/Helpers/memory.h b/kernel/Helpers/memory.h new file mode 100644 index 0000000..5f399db --- /dev/null +++ b/kernel/Helpers/memory.h @@ -0,0 +1,10 @@ +#ifndef __memory__ +#define __memory__ + +#include "./types.h" + +//Fonction to copy data into memory +int memcpy(u32 source, u32 dest, u32 size); + + +#endif diff --git a/kernel/Helpers/memory.hpp b/kernel/Helpers/memory.hpp deleted file mode 100644 index ddc522c..0000000 --- a/kernel/Helpers/memory.hpp +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef __memory__ -#define __memory__ - -#include "./types.hpp" - -//Fonction to copy data into memory -int memcpy(u32 source, u32 dest, u32 size); - - -#endif diff --git a/kernel/Helpers/memprint.c b/kernel/Helpers/memprint.c new file mode 100644 index 0000000..83eb8de --- /dev/null +++ b/kernel/Helpers/memprint.c @@ -0,0 +1,111 @@ +#include "./memprint.h" + +//Define global vars +u8 MEMPRINT_CURSORX=0; +u8 MEMPRINT_CURSORY=0; +u8 MEMPRINT_COLORS=0x0F; + + + +//Move cursor +void memprint_updateCursor(){ + + + //Update X axis + MEMPRINT_CURSORX++; + + //Check X value + if(MEMPRINT_CURSORX >= MAXCURSORX){ + + //If X is out of the screen + MEMPRINT_CURSORX=0; + + //Update Y + MEMPRINT_CURSORY++; + + //Check Y value + if(MEMPRINT_CURSORY > MAXCURSORY){ + + //If Y is out of the screen + memprint_scrollUp(1); + + //Decrease Y value + MEMPRINT_CURSORY--; + } + + + } + + +} + +//Change character background color +void memprint_setBackground(colorBios color){ + u8 newColor= (color << 4); + MEMPRINT_COLORS= newColor | ((MEMPRINT_COLORS << 4) >> 4); +} + +//Change character color +void memprint_setForeground(colorBios color){ + u8 newColor= color; + MEMPRINT_COLORS= newColor | ((MEMPRINT_COLORS >> 4) << 4); +} + +//Print a char +void memprint_putChar(u8 character){ + + //Get the adresse with the cursor position + char *adress= ((char *) MEMPRINTSTARTADR) + (MEMPRINT_CURSORX * 2) + (MEMPRINT_CURSORY * MAXCURSORX * 2); + + //Copy the character + *adress=character; + + //Copy his attribute + adress++; + *adress=MEMPRINT_COLORS; + + //Update cursor position + memprint_updateCursor(); + +} + + +//Print a char* +void memprint_print(char *str){ + while(*str!=0x0){ + memprint_putChar(*str); + str++; + } +} + +//Clear the screen +void memprint_clear(){ + memprint_scrollUp(MAXCURSORY); +} + +//Scroll up "number" times +void memprint_scrollUp(u8 number){ + + //Get number of adress (char & his attribute) to scroll + int nbAdrToScroll=number*MAXCURSORX*2; + + int i=0; + //Scroll all of the characters and attributes + for(i;i!=MAXCURSORX*2*MAXCURSORY;i++){ + + //Get source character or attribute + char* source=(((char *)MEMPRINTSTARTADR) + i); + + //Get destination character or attribute + char* dest=source-nbAdrToScroll; + + //Check if destination is out of the screen + if(dest >= (char *)MEMPRINTSTARTADR) + *dest=*source; + + //Remove data from source + *source=0x0; + + } + +} diff --git a/kernel/Helpers/memprint.h b/kernel/Helpers/memprint.h new file mode 100644 index 0000000..eb41941 --- /dev/null +++ b/kernel/Helpers/memprint.h @@ -0,0 +1,59 @@ +#ifndef __memprint__ +#define __memprint__ + +#include "./types.h" + + +#define MEMPRINTSTARTADR 0xB8000 +#define MAXCURSORX 80 +#define MAXCURSORY 25 + + +//Define the bios color +enum colorBios{ + + BLACK=0x0, + BLUE=0x1, + GREEN=0x2, + CYAN=0x3, + RED=0x4, + MAGENTA=0x5, + BROWN=0x6, + LIGHTGRAY=0x7, + DARKGRAY=0x8, + LIGHTBLUE=0x9, + LIGHTGREEN=0xA, + LIGHTCYAN=0xB, + LIGHTRED=0xC, + LIGHTMAGENTA=0xD, + YELLOW=0xE, + WHITE=0xF + +}; + +//Type def for biosColor +typedef enum colorBios colorBios; + + +//Update cursor position +void memprint_updateCursor(); + +//Set color +void memprint_setBackground(colorBios color); +void memprint_setForeground(colorBios color); + +//Putchar +void memprint_putChar(u8 character); + +//Print +void memprint_print(char *str); + +//Scroll up +void memprint_scrollUp(u8 number); + +//Clear screen +void memprint_clear(); + + + +#endif diff --git a/kernel/Helpers/types.h b/kernel/Helpers/types.h new file mode 100644 index 0000000..a6f334e --- /dev/null +++ b/kernel/Helpers/types.h @@ -0,0 +1,14 @@ +#ifndef __types__ +#define __types__ + +//Byte : +typedef unsigned char u8; + +//Word : +typedef unsigned short u16; + +//Double Word : +typedef unsigned long int u32; + + +#endif diff --git a/kernel/Helpers/types.hpp b/kernel/Helpers/types.hpp deleted file mode 100644 index a6f334e..0000000 --- a/kernel/Helpers/types.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef __types__ -#define __types__ - -//Byte : -typedef unsigned char u8; - -//Word : -typedef unsigned short u16; - -//Double Word : -typedef unsigned long int u32; - - -#endif -- cgit v1.2.3