Start to code memPrint
This commit is contained in:
parent
c10137539f
commit
81d1351c73
3 changed files with 113 additions and 4 deletions
|
@ -3,9 +3,69 @@
|
||||||
//Constructor
|
//Constructor
|
||||||
memPrint::memPrint(){
|
memPrint::memPrint(){
|
||||||
|
|
||||||
|
//Initialise position
|
||||||
|
this->m_cursorX=0;
|
||||||
|
this->m_cursorY=0;
|
||||||
|
|
||||||
|
//Initialise color
|
||||||
|
this->setBackground(BLACK);
|
||||||
|
this->setForeground(WHITE);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Destructor
|
//Destructor
|
||||||
memPrint::~memPrint(){
|
memPrint::~memPrint(){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Move cursor
|
||||||
|
void memPrint::updateCursor(){
|
||||||
|
this->m_cursorX++;
|
||||||
|
|
||||||
|
if(this->m_cursorX > MAXCURSORX){
|
||||||
|
this->m_cursorX=0;
|
||||||
|
this->m_cursorY++;
|
||||||
|
|
||||||
|
if(this->m_cursorY > MAXCURSORY){
|
||||||
|
//Scroll screen
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void memPrint::setBackground(colorBios color){
|
||||||
|
u8 newColor= (color << 4);
|
||||||
|
this->m_colors= newColor | ((this->m_colors << 4) >> 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
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){
|
||||||
|
|
||||||
|
char *adress= ((char *) MEMPRINTSTARTADR) + (this->m_cursorX * 2) + (this->m_cursorY * 80 * 2);
|
||||||
|
|
||||||
|
*adress=character;
|
||||||
|
|
||||||
|
adress++;
|
||||||
|
|
||||||
|
*adress=this->m_colors;
|
||||||
|
|
||||||
|
this->updateCursor();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void memPrint::print(char *str){
|
||||||
|
while(*str!=0x0){
|
||||||
|
this->putChar(*str);
|
||||||
|
str++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,13 @@
|
||||||
#ifndef __memPrint__
|
#ifndef __memPrint__
|
||||||
#define __memPrint__
|
#define __memPrint__
|
||||||
|
|
||||||
|
#include "./types.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
#define MEMPRINTSTARTADR 0xB8000
|
||||||
|
#define MAXCURSORX 80
|
||||||
|
#define MAXCURSORY 25
|
||||||
|
|
||||||
//Define the bios color
|
//Define the bios color
|
||||||
enum colorBios{
|
enum colorBios{
|
||||||
|
|
||||||
|
@ -32,6 +39,15 @@ class memPrint{
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
//Cursor position
|
||||||
|
u8 m_cursorX;
|
||||||
|
u8 m_cursorY;
|
||||||
|
|
||||||
|
//Current colors (background and foreground):
|
||||||
|
u8 m_colors;
|
||||||
|
|
||||||
|
//Methods
|
||||||
|
void updateCursor();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -40,6 +56,17 @@ class memPrint{
|
||||||
|
|
||||||
//Destructor
|
//Destructor
|
||||||
~memPrint();
|
~memPrint();
|
||||||
|
|
||||||
|
//Set color
|
||||||
|
void setBackground(colorBios color);
|
||||||
|
void setForeground(colorBios color);
|
||||||
|
|
||||||
|
//Putchar
|
||||||
|
void putChar(u8 character);
|
||||||
|
|
||||||
|
//Print
|
||||||
|
void print(char *str);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -7,10 +7,20 @@
|
||||||
int main(){
|
int main(){
|
||||||
|
|
||||||
//Test print a char
|
//Test print a char
|
||||||
char* letter=(char*)0xB8A00;
|
/*char* letter=(char*)0xB8A00;
|
||||||
*letter='H';
|
*letter='H';
|
||||||
letter++;
|
letter++;
|
||||||
*letter=(GREEN << 4) | BLUE;
|
*letter=(GREEN << 4) | BLUE;*/
|
||||||
|
|
||||||
|
memPrint VideoRam;
|
||||||
|
|
||||||
|
|
||||||
|
VideoRam.print("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
|
||||||
|
VideoRam.print("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
|
||||||
|
VideoRam.print("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
|
||||||
|
VideoRam.print("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
|
||||||
|
VideoRam.print("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
|
||||||
|
VideoRam.print("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
|
||||||
|
|
||||||
//Infinite loop
|
//Infinite loop
|
||||||
while(1);
|
while(1);
|
||||||
|
@ -29,9 +39,21 @@ extern "C" void _boot(){
|
||||||
Gdt gdt;
|
Gdt gdt;
|
||||||
|
|
||||||
//Load Gdt into memory
|
//Load Gdt into memory
|
||||||
//gdt.loadGdt();
|
gdt.loadGdt();
|
||||||
|
|
||||||
//Call main function
|
//Init all segments and stack
|
||||||
|
__asm__("\
|
||||||
|
movw $0x10, %ax; \n \
|
||||||
|
movw %ax, %ds; \n \
|
||||||
|
movw %ax, %es \n \
|
||||||
|
ljmp $0x08, $updateDS;\
|
||||||
|
updateDS: \n\
|
||||||
|
movw $0x18, %ax \n \
|
||||||
|
movw %ax, %ss \n \
|
||||||
|
movl $0x00B00000, %esp \n\
|
||||||
|
");
|
||||||
|
|
||||||
|
//Call main function after stack pointer changing (due to C++ optimisation)
|
||||||
main();
|
main();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue