Ukulingisa i-Linus Torvalds: Dala uhlelo lwakho lokusebenza kusuka ekuqaleni (II)

Uyemukelwa kokunye okuthunyelwe kokuthi singalwenza kanjani uhlelo lwethu lokusebenza, kuleli cala i-NextDivel.

Uma sibuyela kwikhodi ye- okuthunyelwe kokuqala ekugcineni kwakho konke kufanele ngabe size nokuthile okufana nalokhu:

OlandelayoDivel-1

Uma lokhu kuyiqiniso singaqhubeka. Ngizosebenzisa uhlelo nesakhiwo enginaso kwiGitHub (http://github.com/AdrianArroyoCalle/next-divel) njengoba kukhululeke kakhulukazi kimi nakuwe. Njengoba ukwazi ukubona ukuthi umbhalo ngumbhalo oyisisekelo, awukhangi. Kungabonakala njengokuthize okungajwayelekile. Kepha njengoba isisho sihamba, ukunambitha imibala, futhi ohlelweni lwethu lokusebenza kuzoba nemibala. Imibala yokuqala esizokwazi ukuyibeka kuzoba yileyo echaza amakhadi e-VGA futhi angama-0:

  1. Negro
  2. Azul
  3. oluhlaza
  4. I-Cyan
  5. I-Rojo
  6. Magenta
  7. UBrown
  8. Mpunga okhanyayo
  9. Okumpunga okumnyama
  10. Luhlaza okwesibhakabhaka
  11. Luhlaza okhanyayo
  12. Kuyacaca
  13. Ubomvu okhanyayo
  14. I-magenta ekhanyayo
  15. Umbala onsundu ngokukhanyayo
  16. Mhlophe

Sizoyichaza le mibala kunhlokweni ukuze ibe usizo kakhulu futhi mhlawumbe ngokuzayo ibe yingxenye ye-API yohlelo. Ngakho-ke sakha ifayili i-ND_Colors.hpp ku-NextDivel ifaka phakathi.

#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

Ngasikhathi sinye sichaza imisebenzi emisha ukubhala esikrinini ngendlela ethokomele (cha, ngeke sisebenzise i-printf okwamanje, ngiyazi ukuthi uyayifuna). Sizokwakha ifayela nenhloko yalo kusethi yemisebenzi ehlobene nesikrini (ND_Screen.cpp kanye ne- ND_Screen.hpp). Kuzona sizokwakha imisebenzi yoku: shintsha umbala wezinhlamvu nesizinda, bhala imishwana nezinhlamvu, uhlanze isikrini bese uzulazula esikrinini. Siyaqhubeka nokusebenzisa izikrini ze-VGA kepha manje sizosebenzisa ama-byte ambalwa azonikeza umbala. ND_Screen.cpp ibukeka kanjena:

/**
* @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;
}

Unhlokweni uzoba eyisisekelo kakhulu ngakho angikufaki lapha, kepha ngigqamisa incazelo yohlobo ND_SIDE lohlobo

typedef enum ND_SIDE{
ND_SIDE_BACKGROUND,
ND_SIDE_FOREGROUND
} ND_SIDE;

También mencionar que hacemos uso del header ND_Types.hpp, este header nos define unos tipos básicos para uint8_t, uint16_t, etc basado en los char y los int. Realmente este header es el en el estándar C99 y de hecho mi ND_Types.hpp es un copia/pega del archivo desde Linux, así que podeis intercambiarlos y no pasaría nada (solo hay definiciones, ninguna función).

Ukuhlola ukuthi le khodi iyasebenza yini sizoguqula iphoyinti lokungena le-C 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");

Futhi uma silandela lezi zinyathelo sizothola lo mphumela

OlandelayoDivel-3

Ngenxa yale misebenzi esiyenzile, singaqala ukwenza ama-GUI amancane, njengokwethuka kernel esizokukhombisa njalo uma kunephutha elingatholakali. Okuthile okufana nalokhu:

OlandelayoDivel-4

Futhi le GUI encane siyenze kuphela ngale misebenzi:

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);
}

Futhi kuze kube lapha okuthunyelwe. Ngikukhumbuza ngemiyalo yokuhlanganisa uhlelo kusuka ku-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

Futhi ngithatha leli thuba ukunibonga ngokwamukelwa okuhle kakhulu obekuthunyelwe okokuqala.


Shiya umbono wakho

Ikheli lakho le ngeke ishicilelwe. Ezidingekayo ibhalwe nge *

*

*

  1. Ubhekele imininingwane: Miguel Ángel Gatón
  2. Inhloso yedatha: Lawula Ugaxekile, ukuphathwa kwamazwana.
  3. Ukusemthethweni: Imvume yakho
  4. Ukuxhumana kwemininingwane: Imininingwane ngeke idluliselwe kubantu besithathu ngaphandle kwesibopho esisemthethweni.
  5. Isitoreji sedatha: Idatabase ebanjwe yi-Occentus Networks (EU)
  6. Amalungelo: Nganoma yisiphi isikhathi ungakhawulela, uthole futhi ususe imininingwane yakho.

  1.   I-F3niX kusho

    Umngani omuhle kakhulu, noma kunjalo ngibulala isigqoko sami sokuqonda ikhodi ku-c ++.

    Ukubingelela

  2.   i-pandacriss kusho

    lezi zinto zinhle. Bangiphakamisile ilukuluku lami mayelana nokusebenza kwezinga eliphansi labaprosesa futhi.
    mhlawumbe uma nginesikhathi ngizoqala ukudlala nge-next-divel.
    Angizange ngithumele i-athikili isikhathi eside. esivele sidingeka

  3.   UJon uyagebha kusho

    Kulungile, kunjalo.

  4.   Miguel kusho

    Kudala ngifisa ukwazi ukuthi ngingalakha kanjani uhlelo lokusebenza.

    Ilinde okuthunyelwe kwakho okulandelayo. Jabulela

  5.   UGiuliano kusho

    Umngani omkhulu!
    Nginenkinga eyodwa nje, ngabe othile angangidlulisa ifayela le-C lalesi sibonelo?
    Ihlala ingithumelela amaphutha ku-terminal