Go back to C and adapt code
This commit is contained in:
parent
aac010a9e3
commit
e0c565f7ff
18 changed files with 242 additions and 308 deletions
|
@ -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 $@ $<
|
||||
#-------------------
|
||||
|
||||
|
||||
|
|
|
@ -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
|
|
@ -1,5 +1,5 @@
|
|||
#include "./memory.hpp"
|
||||
#include "./types.hpp"
|
||||
#include "./memory.h"
|
||||
#include "./types.h"
|
||||
|
||||
//Fonction to copy data into memory
|
||||
int memcpy(u32 source, u32 dest, u32 size){
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef __memory__
|
||||
#define __memory__
|
||||
|
||||
#include "./types.hpp"
|
||||
#include "./types.h"
|
||||
|
||||
//Fonction to copy data into memory
|
||||
int memcpy(u32 source, u32 dest, u32 size);
|
|
@ -1,50 +1,36 @@
|
|||
#include "./memPrint.hpp"
|
||||
#include "./memprint.h"
|
||||
|
||||
//Define global vars
|
||||
u8 MEMPRINT_CURSORX=0;
|
||||
u8 MEMPRINT_CURSORY=0;
|
||||
u8 MEMPRINT_COLORS=0x0F;
|
||||
|
||||
|
||||
//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(){
|
||||
void memprint_updateCursor(){
|
||||
|
||||
|
||||
//Update X axis
|
||||
this->m_cursorX++;
|
||||
MEMPRINT_CURSORX++;
|
||||
|
||||
//Check X value
|
||||
if(this->m_cursorX >= MAXCURSORX){
|
||||
if(MEMPRINT_CURSORX >= MAXCURSORX){
|
||||
|
||||
//If X is out of the screen
|
||||
this->m_cursorX=0;
|
||||
MEMPRINT_CURSORX=0;
|
||||
|
||||
//Update Y
|
||||
this->m_cursorY++;
|
||||
MEMPRINT_CURSORY++;
|
||||
|
||||
//Check Y value
|
||||
if(this->m_cursorY >= MAXCURSORY){
|
||||
if(MEMPRINT_CURSORY > MAXCURSORY){
|
||||
|
||||
//If Y is out of the screen
|
||||
this->scrollUp(1);
|
||||
memprint_scrollUp(1);
|
||||
|
||||
//Decrease Y value
|
||||
this->m_cursorY--;
|
||||
MEMPRINT_CURSORY--;
|
||||
}
|
||||
|
||||
|
||||
|
@ -54,58 +40,58 @@ void memPrint::updateCursor(){
|
|||
}
|
||||
|
||||
//Change character background color
|
||||
void memPrint::setBackground(colorBios color){
|
||||
void memprint_setBackground(colorBios color){
|
||||
u8 newColor= (color << 4);
|
||||
this->m_colors= newColor | ((this->m_colors << 4) >> 4);
|
||||
MEMPRINT_COLORS= newColor | ((MEMPRINT_COLORS << 4) >> 4);
|
||||
}
|
||||
|
||||
//Change character color
|
||||
void memPrint::setForeground(colorBios color){
|
||||
void memprint_setForeground(colorBios color){
|
||||
u8 newColor= color;
|
||||
this->m_colors= newColor | ((this->m_colors >> 4) << 4);
|
||||
MEMPRINT_COLORS= newColor | ((MEMPRINT_COLORS >> 4) << 4);
|
||||
}
|
||||
|
||||
//Print a char
|
||||
void memPrint::putChar(u8 character){
|
||||
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);
|
||||
char *adress= ((char *) MEMPRINTSTARTADR) + (MEMPRINT_CURSORX * 2) + (MEMPRINT_CURSORY * MAXCURSORX * 2);
|
||||
|
||||
//Copy the character
|
||||
*adress=character;
|
||||
|
||||
//Copy his attribute
|
||||
adress++;
|
||||
*adress=this->m_colors;
|
||||
*adress=MEMPRINT_COLORS;
|
||||
|
||||
//Update cursor position
|
||||
this->updateCursor();
|
||||
memprint_updateCursor();
|
||||
|
||||
}
|
||||
|
||||
|
||||
//Print a char*
|
||||
void memPrint::print(char *str){
|
||||
void memprint_print(char *str){
|
||||
while(*str!=0x0){
|
||||
this->putChar(*str);
|
||||
memprint_putChar(*str);
|
||||
str++;
|
||||
}
|
||||
}
|
||||
|
||||
//Clear the screen
|
||||
void memPrint::clear(){
|
||||
this->scrollUp(MAXCURSORY);
|
||||
void memprint_clear(){
|
||||
memprint_scrollUp(MAXCURSORY);
|
||||
}
|
||||
|
||||
//Scroll up "number" times
|
||||
void memPrint::scrollUp(u8 number){
|
||||
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(int i=0;i!=MAXCURSORX*2*MAXCURSORY;i++){
|
||||
for(i;i!=MAXCURSORX*2*MAXCURSORY;i++){
|
||||
|
||||
//Get source character or attribute
|
||||
char* source=(((char *)MEMPRINTSTARTADR) + i);
|
59
kernel/Helpers/memprint.h
Normal file
59
kernel/Helpers/memprint.h
Normal file
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue