Na-eulatingomi Linus Torvalds: Mepụta sistemụ arụmọrụ gị site na ncha (II)

Nabata na post ọzọ banyere otu esi emepụta sistemụ arụmọrụ anyị, na nke a NextDivel.

Ọ bụrụ na anyị laghachi na koodu nke post mbụ na ngwụcha nke ihe niile anyị gaara enwe ụdị ihe a:

OsoteDivel-1

Ọ bụrụ na nke a bụ eziokwu anyị nwere ike ịga n'ihu. Aga m eji sistemu na usoro m nwere na GitHub (http://github.com/AdrianArroyoCalle/next-divel) ebe ọ bụ na ọ kaara mụ na gị mma. Dịka ị pụrụ ịhụ ederede bụ ederede bụ isi, ọ naghị adọrọ adọrọ. O nwere ike ịdị ka ihe karịrị otu ihe. Mana dị ka okwu a si dị, nụrụ ụtọ agba, yana sistemụ arụmọrụ anyị ga-enwe agba. Agba mbụ anyị ga - enwe ike itinye ga - abụ ndị ga - akọwa kaadị VGA ha bụ 0:

  1. Negro
  2. Azul
  3. Verde
  4. cyan
  5. Rojo
  6. magenta
  7. Agba aja aja
  8. Agba ntụ
  9. Ọchịchịrị gbara ọchịchịrị
  10. Igwe dị ọkụ
  11. Ìhè green
  12. Cyan doro anya
  13. Uhie uhie
  14. Ìhè magenta
  15. Agba aja aja
  16. White

Anyị ga-akọwapụta agba ndị a na nkụnye eji isi mee ka ọ dịkwuo mfe ma eleghị anya n'ọdịnihu bụrụ akụkụ nke usoro API. Ya mere, anyị mepụtara faịlụ ND_Colors.hpp na NextDivel gụnyere.

#ifndef ND_COLOR_HPP
#define ND_COLOR_HPP
typedef enum ND_Color{
ND_COLOR_BLACK = 0,
ND_COLOR_BLUE = 1,
ND_COLOR_GREEN = 2,
ND_COLOR_CYAN = 3,
ND_COLOR_RED = 4,
ND_COLOR_MAGENTA = 5,
ND_COLOR_BROWN = 6,
ND_COLOR_LIGHT_GREY = 7,
ND_COLOR_DARK_GREY = 8,
ND_COLOR_LIGHT_BLUE = 9,
ND_COLOR_LIGHT_GREEN = 10,
ND_COLOR_LIGHT_CYAN = 11,
ND_COLOR_LIGHT_RED = 12,
ND_COLOR_LIGHT_MAGENTA = 13,
ND_COLOR_LIGHT_BROWN = 14,
ND_COLOR_WHITE = 15
} ND_Color;
#endif

N'otu oge ahụ, anyị ga-akọwapụta ọrụ ọhụụ iji dee na ihuenyo ahụ n'ụzọ ka mma (mba, anyị agaghị emejuputa mbipụta akwụkwọ ugbu a, amaara m na ịchọrọ ya). Anyị ga-emepụta faịlụ na isi ya maka otu ọrụ metụtara ihuenyo (ND_Screen.cpp na ND_Screen.hpp). N'ime ha anyị ga-ekepụta ọrụ iji: gbanwee agba nke mkpụrụedemede na ndabere, dee ahịrịokwu na mkpụrụedemede, hichaa ihuenyo ma na-agagharị na ihuenyo ahụ. Anyị na-aga n'ihu na-eji VGA meziri ma ugbu a, anyị ga-eji ole na ole bytes ga-enye agba. ND_Screen.cpp ga-adị ka:

/**
* @file ND_Screen.cpp
* @author Adrián Arroyo Calle
* @brief Implements four easy functions for write strings directly
*/
#include <ND_Types.hpp>
#include <ND_Color.hpp>
#include <ND_Screen.hpp>
uint16_t *vidmem= (uint16_t *)0xB8000;
ND_Color backColour = ND_COLOR_BLACK;
ND_Color foreColour = ND_COLOR_WHITE;
uint8_t cursor_x = 0;
uint8_t cursor_y = 0;
/**
* @brief Gets the current color
* @param side The side to get the color
* */
ND_Color ND::Screen::GetColor(ND_SIDE side)
{
if(side==ND_SIDE_BACKGROUND){
return backColour;
}else{
return foreColour;
}
}
/**
* @brief Sets the color to a screen side
* @param side The side to set colour
* @param colour The new colour
* @see GetColor
* */
void ND::Screen::SetColor(ND_SIDE side, ND_Color colour)
{
if(side==ND_SIDE_BACKGROUND)
{
backColour=colour;
}else{
foreColour=colour;
}
}
/**
* @brief Puts the char on screen
* @param c The character to write
* */
void ND::Screen::PutChar(char c)
{
uint8_t attributeByte = (backColour << 4) | (foreColour & 0x0F);
uint16_t attribute = attributeByte << 8; uint16_t *location; if (c == 0x08 && cursor_x) { cursor_x--; }else if(c == '\r') { cursor_x=0; }else if(c == '\n') { cursor_x=0; cursor_y=1; } if(c >= ' ') /* Printable character */
{
location = vidmem + (cursor_y*80 + cursor_x);
*location = c | attribute;
cursor_x++;
}
if(cursor_x >= 80) /* New line, please*/
{
cursor_x = 0;
cursor_y++;
}
/* Scroll if needed*/
uint8_t attributeByte2 = (0 /*black*/ << 4) | (15 /*white*/ & 0x0F);
uint16_t blank = 0x20 /* space */ | (attributeByte2 << 8); if(cursor_y >= 25)
{
int i;
for (i = 0*80; i < 24*80; i++)
{
vidmem[i] = vidmem[i+80];
}
// The last line should now be blank. Do this by writing
// 80 spaces to it.
for (i = 24*80; i < 25*80; i++)
{
vidmem[i] = blank;
}
// The cursor should now be on the last line.
cursor_y = 24;
}
}
/**
* @brief Puts a complete string to screen
* @param str The string to write
* */
void ND::Screen::PutString(const char* str)
{
int i=0;
while(str[i])
{
ND::Screen::PutChar(str[i++]);
}
}
/**
* @brief Cleans the screen with a color
* @param colour The colour to fill the screen
* */
void ND::Screen::Clear(ND_Color colour)
{
uint8_t attributeByte = (colour /*background*/ << 4) | (15 /*white - foreground*/ & 0x0F);
uint16_t blank = 0x20 /* space */ | (attributeByte << 8);
int i;
for (i = 0; i < 80*25; i++)
{
vidmem[i] = blank;
}
cursor_x = 0;
cursor_y = 0;
}
/**
* @brief Sets the cursor via software
* @param x The position of X
* @param y The position of y
* */
void ND::Screen::SetCursor(uint8_t x, uint8_t y)
{
cursor_x=x;
cursor_y=y;
}

Isi ihe ahụ ga-abụ ihe dị mkpa nke mere na anaghị m etinye ya ebe a, mana gosipụta nkọwa nke ụdị ND_SIDE

typedef enum ND_SIDE{
ND_SIDE_BACKGROUND,
ND_SIDE_FOREGROUND
} ND_SIDE;

Kwuokwa na anyị na - eji ND_Types.hpp nkụnye eji isi mee, isi a na - akọwa ụfọdụ ụdị maka uint8_t, uint16_t, wdg. Dabere na char na int. N'ezie isi okwu a bụ nke dị na ọkọlọtọ C99 yana n'eziokwu ND NDyyy.hpp m bụ oyiri / mado nke faịlụ ahụ site na Linux, yabụ ị nwere ike ịgbanwe ha ma ọ nweghị ihe ga - eme (enwere naanị nkọwa, enweghị ọrụ)

Iji nwalee ma koodu a rụọ ọrụ, anyị ga-agbanwe ebe ntinye C nke kernel:

ND::Screen::Clear(ND_COLOR_WHITE);
ND::Screen::SetColor(ND_SIDE_BACKGROUND,ND_COLOR_WHITE);
ND::Screen::SetColor(ND_SIDE_FOREGROUND,ND_COLOR_GREEN);
ND::Screen::PutString("NextDivel\n");
ND::Screen::SetColor(ND_SIDE_FOREGROUND,ND_COLOR_BLACK);
ND::Screen::PutString("Licensed under GNU GPL v2");

Ọ bụrụ na anyị agbaso usoro ndị a, anyị ga-enweta nsonaazụ a

OsoteDivel-3

N'ihi ọrụ ndị a anyị kere anyị nwere ike ịmalite ịme obere GUI, dị ka ụjọ kernel anyị ga-egosi oge ọ bụla enwere njehie a na-apụghị ịchọpụta. Ihe dika nke a:

OsoteDivel-4

Obere GUI a ka anyị ji rụọ ọrụ ndị a:

void ND::Panic::Show(const char* error)
{
ND::Screen::Clear(ND_COLOR_RED);
ND::Screen::SetColor(ND_SIDE_BACKGROUND, ND_COLOR_WHITE);
ND::Screen::SetColor(ND_SIDE_FOREGROUND, ND_COLOR_RED);
ND::Screen::SetCursor(29,10); //(80-22)/2
ND::Screen::PutString("NextDivel Kernel Error\n");
ND::Screen::SetCursor(15,12);
ND::Screen::PutString(error);
}

Na ebe a post. M na-echetara gị nke ntuziaka ka ikpokọta usoro si 0:

git clone http://github.com/AdrianArroyoCalle/next-divel
cd next-divel
mkdir build && cd build
cmake ..
make
make DESTDIR=next install
chmod +x iso.sh
./iso.sh
qemu-system-i386 nextdivel.iso

Eji m ohere a na-ekele unu maka nnabata nnabata nke ọkwa izizi nwere.


Ọdịnaya nke isiokwu agbaso ụkpụrụ anyị nke ụkpụrụ nduzi. Kpesa mmejọ pịa ebe a.

Ihe 5 kwuru, hapụ nke gị

Hapu okwu gi

Adreesị email gị agaghị bipụtara. Chọrọ ubi na-akara na *

*

*

  1. Rụ ọrụ maka data: Miguel Ángel Gatón
  2. Nzube nke data: Nchịkwa SPAM, njikwa okwu.
  3. Ikike: Nkwenye gị
  4. Nkwurịta okwu nke data: Agaghị agwa ndị ọzọ data ahụ ma ọ bụghị site na iwu.
  5. Nchekwa data: Ebe nchekwa data nke Occentus Networks (EU) kwadoro
  6. Ikike: Oge obula inwere ike igbachi, weghachite ma hichapụ ihe omuma gi.

  1.   F3niX dijo

    Ezigbo enyi, ọbụlagodi na m na-egbu okpu agha m ịghọta koodu ahụ na c ++.

    Ekele.

  2.   oria ojoo dijo

    ihe ndị a dị mma. emeela ka m nwee ọchịchọ ịmata banyere arụmọrụ dị ala nke ndị nhazi ahụ ọzọ.
    Eleghi anya ọ bụrụ na m nwere oge m ga-amalite igwu egwu na-esote.
    Ezitebeghị m otu edemede ogologo oge. adịworị mkpa

  3.   Jon burrows dijo

    Ọ dị mma, nke ahụ bụ ụzọ.

  4.   Miguel dijo

    Achọrọ m ịmata otu esi arụ sistemụ arụmọrụ.

    Na-echere post gị ọzọ. ekele

  5.   Giuliano dijo

    Ezigbo enyi!
    Enwere m naanị otu nsogbu, mmadụ nwere ike ịgafe m faịlụ C nke ihe atụ a?
    Ọ na-ezigara m njehie na ọnụ