Te Whakahoahoa i nga Toroa Linus: Hangaia to punaha whakahaere mai i te wahanga (II)

Nau mai ki tetahi atu pou peera me pehea te hanga i ta taatau punaha whakahaere, i tenei waa NextDivel.

Ki te hoki tatou ki te waehere o te pou tuatahi i te mutunga o nga mea katoa me penei te korero:

PanukuTira-1

Mena he tika tenei ka taea e taatau te haere tonu. Ka whakamahia e au te punaha me te hanganga kei a au i runga i GitHub (http://github.com/AdrianArroyoCalle/next-divel) na te mea he pai ake mo au me koe. Ka kite koe he tuhinga noa te tuhinga, ehara i te mea ataahua. Akene he ahua ke atu i etahi noa atu. Engari e kii ana te pepeha, kia reka nga tae, a ki ta taatau punaha whakahaere ka tae nga tae. Ko nga tae tuatahi ka taea e taatau te tohu ko nga kaari VGA kei te 0:

  1. Pango
  2. Azul
  3. matomato
  4. Kawariki
  5. Rojo
  6. Kurauri
  7. Marrón
  8. Hina hina
  9. Kariki oscuro
  10. Kikorangi kikorangi
  11. He kowhatu matomato
  12. Cyan mārama
  13. Whero marama
  14. Magenta marama
  15. Parauri marama
  16. White

Ka tautuhia e matou enei tae ki te pane kia pai ake ai te mahi, akene pea kei te heke mai ka uru ki te punaha API. Na ka hangaia e matou te konae ND_Colors.hpp i te Panui Panuku whakauru.

#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

I te wa ano ka tautuhia e maatau nga mahi hou ki te tuhi ki runga i te mata kia pai ake te ahua (kaore, kaore ano matou kia whakatinana i te printf, kei te mohio ahau kei te hiahia koe). Ka hangaia e maatau he konae me tana pane mo nga mahi e pa ana ki te mata (ND_Screen.cpp me ND_Screen.hpp). I roto i a raatau ka hangaia he mahi hei: whakarereke i te tae o nga reta me te papamuri, tuhia nga rerenga me nga reta, horoia te mata ka neke huri noa i te mata. Kei te whakamahi tonu i nga mata VGA engari inaianei ka whakamahia e maatau etahi paita e hoatu ana te tae. Pēnei te ND_Screen.cpp:

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

He tino putake te pane na kaore au e whakauru atu ki konei, engari whakamaramahia te whakamaarama o te momo ND_SIDE

typedef enum ND_SIDE{
ND_SIDE_BACKGROUND,
ND_SIDE_FOREGROUND
} ND_SIDE;

Ano hoki te whakamahi i te pane ND_Types.hpp, ko tenei pane he tautuhi i etahi momo tuuturu mo uint8_t, uint16_t, me etahi atu i runga i te char me te int. Ae ko tenei pane ko te mea i roto i te paerewa C99 me te mea ko taku ND_Types.hpp he kape / whakapiri o te konae mai i Linux, kia taea ai e koe te whakawhiti me te kore e tupu (he whakamaarama anake, kaore he mahi).

Hei whakamatautau mena ka mahi tenei waehere ka whakarereketia e maatau te urunga C o te pata:

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

Ana mena ka whai tatou i enei huarahi ka ea tenei i a tatou

PanukuTira-3

Mauruuru ki enei mahi i hangaia e maatau, ka tiimata taatau ki te hanga GUI iti, penei i te awangawanga o te pata ka whakaatuhia e maatau i nga wa katoa ka hapa mai te hapa. He penei:

PanukuTira-4

Na tenei iti GUI i hangaia e maatau ma enei mahi anake:

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

Ana tae atu ki konei te pou. Ka whakamahara ahau ki a koe mo nga tohutohu ki te whakahiato i te punaha mai i te 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

Ana ka whai waahi ahau ki te whakawhetai atu ki a koe mo te manaaki pai i puta i te pou tuatahi.


Ko nga korero o te tuhinga e piri ana ki o maatau kaupapa o matatika whakatika. Ki te ripoata i tetahi paatene paato Here.

5 korero, waiho maau

Waiho to korero

Ka kore e whakaputaina tō wāhitau īmēra. Kua tohua ngā āpure e hiahiatia ana ki *

*

*

  1. He kawenga mo nga raraunga: Miguel Ángel Gatón
  2. Te kaupapa o te raraunga: Whakahaerehia te SPAM, te whakahaere korero.
  3. Ture: To whakaae
  4. Whakawhitinga korero: Kaore nga korero e tukuna ki nga taha tuatoru engari ma te ture herenga.
  5. Rokiroki raraunga: Paetukutuku e whakahaerehia ana e Occentus Networks (EU)
  6. Tika: I nga wa katoa ka taea e koe te whakaiti, te whakaora me te muku i o korero.

  1.   F3niX ka mea

    E hoa pai, ahakoa ra kei te patu ahau i taku potae ki te maarama ki te waehere o te c ++.

    Mauruuru.

  2.   panuku ka mea

    he rawe enei taonga. Kua poipoihia e au taku hiahia ki te mahi taumata-iti o nga tukatuka.
    akene mena ka whai waahi au ka tiimata taku taakaro me nga korero o muri.
    Kua roa ahau e kore e tuku tuhinga. kua hiahiatia

  3.   Puta ana a Jon ka mea

    Ka pai, koina te huarahi.

  4.   Miguel ka mea

    Kua roa ahau e hiahia ana ki te mohio me pehea te hanga punaha whakahaere.

    Kei te tatari mo to pou muri. Kia ora

  5.   Giuliano ka mea

    E hoa pai!
    Kotahi noa taku raru, ka taea e tetahi te tuku i tetahi konae C mo tenei tauira?
    Ka tukuna mai he hapa ki ahau i te tauranga