Skip to content

Commit

Permalink
Implementing Text Mode Driver
Browse files Browse the repository at this point in the history
  • Loading branch information
maxtyson123 committed Sep 27, 2023
1 parent 5fd64ff commit e015a14
Show file tree
Hide file tree
Showing 24 changed files with 494 additions and 489 deletions.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ kernel = obj/kernel/loader.o \
obj/kernel/drivers/ethernet/intel_i217.o \
obj/kernel/drivers/ethernet/ethernet.o \
obj/kernel/drivers/clock/clock.o \
obj/kernel/drivers/console/console.o \
obj/kernel/drivers/console/textmodeconsole.o \
obj/kernel/filesystem/filesystem.o \
obj/kernel/filesystem/fat32.o \
obj/kernel/filesystem/msdospart.o \
Expand All @@ -55,6 +57,7 @@ kernel = obj/kernel/loader.o \
obj/kernel/common/graphicsContext.o \
obj/kernel/common/colour.o \
obj/kernel/common/inputStream.o \
obj/kernel/common/outputStream.o \
obj/kernel/net/etherframe.o \
obj/kernel/net/arp.o \
obj/kernel/net/ipv4.o \
Expand Down Expand Up @@ -148,6 +151,9 @@ filesystem:
toolchain/copy_filesystem.sh
sync

incrementVersion:
toolchain/increment_version.sh

build: maxOS.bin
@echo Made Max OS Kernel

Expand All @@ -165,6 +171,7 @@ build: maxOS.bin
make filesystem

@echo === Made Max OS ===
make incrementVersion



Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ MaxOS now has support for hardrives (Fat32 filesytem) and can be booted from an


## Screenshots
Booting
![Screenshot](docs/Screenshots/New_Console.png)

GUI Window System
![Screenshot](docs/Screenshots/GUI_windows.png)


Expand All @@ -44,7 +48,7 @@ Kernel Cleanup
- [x] GUI Draw Rewrite
- [ ] Usable Desktop - Windows Resizing is working but mouse is weird
- [x] Timer rewrite
- [ ] Console rewrite
- [x] Console rewrite
- [ ] Better Doxygen Documentation
- [ ] Use better c++ coding conventions
- [ ] Codebase cleanup / rewrite
Expand Down
Binary file added docs/Screenshots/New_Console.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 1 addition & 2 deletions kernel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ set(
${common_h}/types.h
${common_h}/types.h
${common_h}/graphicsContext.h ${common_c}/graphicsContext.cpp
${common_h}/printf.h ${common_c}/printf.cpp
${common_h}/vector.h
${common_h}/colour.h ${common_c}/colour.cpp

Expand All @@ -84,7 +83,7 @@ set(
${fs_h}/fat32.h ${fs_c}/fat32.cpp
${fs_h}/filesystem.h ${fs_c}/filesystem.cpp

include/common/rectangle.h include/common/coordinates.h include/common/pair.h include/common/constants.h include/common/time.h include/drivers/clock/clock.h src/drivers/clock/clock.cpp src/common/inputStream.cpp include/common/inputStream.h src/common/outputStream.cpp include/common/outputStream.h include/gui/font.h src/gui/font.cpp include/system/multiboot.h include/drivers/video/vesa.h src/drivers/video/vesa.cpp include/drivers/console/console.h src/drivers/console/console.cpp)
include/common/rectangle.h include/common/coordinates.h include/common/pair.h include/common/constants.h include/common/time.h include/drivers/clock/clock.h src/drivers/clock/clock.cpp src/common/inputStream.cpp include/common/inputStream.h src/common/outputStream.cpp include/common/outputStream.h include/gui/font.h src/gui/font.cpp include/system/multiboot.h include/drivers/video/vesa.h src/drivers/video/vesa.cpp include/drivers/console/console.h src/drivers/console/console.cpp include/drivers/console/textmodeconsole.h src/drivers/console/textmodeconsole.cpp)
#Ignore standard library
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -v -Wl,nostdlib -Wl,nodefaultlibs")

Expand Down
9 changes: 5 additions & 4 deletions kernel/include/drivers/console/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace maxOS {
Magenta = 0x05,
Brown = 0x06,
LightGrey = 0x07,
DarkGray = 0x08,
DarkGrey = 0x08,
LightBlue = 0x09,
LightGreen = 0x0A,
LightCyan = 0x0B,
Expand Down Expand Up @@ -53,11 +53,11 @@ namespace maxOS {


virtual void putChar(common::uint16_t x, common::uint16_t y, char c, ConsoleColor foreground, ConsoleColor background);
virtual void putString(common::uint16_t x, common::uint16_t y, common::string s, ConsoleColor foreground = LightGray, ConsoleColor background = Black);
virtual void putString(common::uint16_t x, common::uint16_t y, common::string s, ConsoleColor foreground = LightGrey, ConsoleColor background = Black);
virtual void scrollUp();
virtual void scrollUp(common::uint16_t left, common::uint16_t top, common::uint16_t width, common::uint16_t height, ConsoleColor foreground = LightGray, ConsoleColor background = Black, char fill=' ');
virtual void scrollUp(common::uint16_t left, common::uint16_t top, common::uint16_t width, common::uint16_t height, ConsoleColor foreground = LightGrey, ConsoleColor background = Black, char fill=' ');
virtual void clear();
virtual void clear(common::uint16_t left, common::uint16_t top, common::uint16_t width, common::uint16_t height, ConsoleColor foreground = LightGray, ConsoleColor background = Black, char fill=' ');
virtual void clear(common::uint16_t left, common::uint16_t top, common::uint16_t width, common::uint16_t height, ConsoleColor foreground = LightGrey, ConsoleColor background = Black, char fill=' ');
virtual void invertColors(common::uint16_t x, common::uint16_t y);
};

Expand All @@ -71,6 +71,7 @@ namespace maxOS {
common::uint16_t height;
public:
ConsoleArea(Console* console, common::uint16_t left, common::uint16_t top, common::uint16_t width, common::uint16_t height);
ConsoleArea(Console* console, common::uint16_t left, common::uint16_t top, common::uint16_t width, common::uint16_t height, ConsoleColor foreground, ConsoleColor background);
~ConsoleArea();

common::uint16_t getWidth();
Expand Down
44 changes: 44 additions & 0 deletions kernel/include/drivers/console/textmodeconsole.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// Created by 98max on 27/09/2023.
//

#ifndef MAXOS_DRIVERS_CONSOLE_TEXTMODECONSOLE_H
#define MAXOS_DRIVERS_CONSOLE_TEXTMODECONSOLE_H

#include <common/types.h>
#include <drivers/driver.h>
#include <drivers/console/console.h>

namespace maxOS{

namespace drivers {

namespace console {

class TextModeConsole : public Driver, public Console
{

public:
TextModeConsole();
~TextModeConsole();

common::uint16_t getWidth();
common::uint16_t getHeight();

void putChar(common::uint16_t x, common::uint16_t y, char c);
void setForegroundColor(common::uint16_t x, common::uint16_t y, ConsoleColor foreground);
void setBackgroundColor(common::uint16_t x, common::uint16_t y, ConsoleColor background);

char getChar(common::uint16_t x, common::uint16_t y);
ConsoleColor getForegroundColor(common::uint16_t x, common::uint16_t y);
ConsoleColor getBackgroundColor(common::uint16_t x, common::uint16_t y);

protected:
common::uint16_t* videoMemory;
};

}
}
}

#endif //MAXOS_DRIVERS_CONSOLE_TEXTMODECONSOLE_H
1 change: 0 additions & 1 deletion kernel/include/filesystem/fat32.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <common/vector.h>
#include <memory/memorymanagement.h>
#include <common/outputStream.h>
#include <common/printf.h>

namespace maxOS{

Expand Down
7 changes: 5 additions & 2 deletions kernel/include/hardwarecommunication/interrupts.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <hardwarecommunication/port.h>
#include <system/gdt.h>
#include <system/multithreading.h>
#include <common/inputStream.h>
#include <common/outputStream.h>


namespace maxOS {
Expand All @@ -30,7 +32,7 @@ namespace maxOS {

};

class InterruptManager {
class InterruptManager : public common::InputStream {
friend class InterruptHandler;

protected:
Expand All @@ -55,6 +57,7 @@ namespace maxOS {
} __attribute__((packed));

common::uint16_t hardwareInterruptOffset;
common::OutputStream* errorMessages;

static void SetInterruptDescriptorTableEntry(common::uint8_t interrupt,
common::uint16_t codeSegmentSelectorOffset,
Expand Down Expand Up @@ -130,7 +133,7 @@ namespace maxOS {


public:
InterruptManager(common::uint16_t hardwareInterruptOffset, system::GlobalDescriptorTable *globalDescriptorTable, ThreadManager* threadManager);
InterruptManager(common::uint16_t hardwareInterruptOffset, system::GlobalDescriptorTable *globalDescriptorTable, ThreadManager* threadManage, common::OutputStream* handler);

~InterruptManager();

Expand Down
5 changes: 4 additions & 1 deletion kernel/include/hardwarecommunication/pci.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,11 @@ namespace maxOS
{
Port32Bit dataPort;
Port32Bit commandPort;

common::OutputStream* debugMessagesStream;

public:
PeripheralComponentInterconnectController();
PeripheralComponentInterconnectController(common::OutputStream* debugMessagesStream);
~PeripheralComponentInterconnectController();

common::uint32_t Read(common::uint16_t bus, common::uint16_t device, common::uint16_t function, common::uint32_t registeroffset);
Expand Down
22 changes: 22 additions & 0 deletions kernel/src/drivers/console/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ void Console::putChar(common::uint16_t x, common::uint16_t y, char c, ConsoleCol
*/
void Console::putString(common::uint16_t x, common::uint16_t y, common::string s, ConsoleColor foreground, ConsoleColor background) {

// For each character in the string
for(const char* si = s; x < getWidth() && *si != '\0'; si++, x++) {

// Put the character on the console
putChar(x,y,*si,foreground,background);

}

}

/**
Expand Down Expand Up @@ -226,6 +234,20 @@ ConsoleArea::ConsoleArea(Console *console, common::uint16_t left, common::uint16

}

ConsoleArea::ConsoleArea(Console *console, common::uint16_t left, common::uint16_t top, common::uint16_t width, common::uint16_t height, ConsoleColor foreground, ConsoleColor background)
: console(console), left(left), top(top), width(width), height(height)
{

// Loop through the area setting the colors
for(uint16_t y = top; y < top+height; y++)
for(uint16_t x = left; x < left+width; x++){
console->setForegroundColor(x,y,foreground);
console->setBackgroundColor(x,y,background);
}

}


ConsoleArea::~ConsoleArea() {

}
Expand Down
152 changes: 152 additions & 0 deletions kernel/src/drivers/console/textmodeconsole.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
//
// Created by 98max on 27/09/2023.
//

#include <drivers/console/textmodeconsole.h>

using namespace maxOS;
using namespace maxOS::common;
using namespace maxOS::drivers;
using namespace maxOS::drivers::console;

TextModeConsole::TextModeConsole()
: Driver(),
Console(),
videoMemory((uint16_t*) 0xb8000)
{

}

TextModeConsole::~TextModeConsole()
{

}

uint16_t TextModeConsole::getWidth()
{
return 80;
}

uint16_t TextModeConsole::getHeight()
{
return 25;
}

/**
* Places a character at the specified location
* @param x The x coordinate
* @param y The y coordinate
* @param c The character to place
*/
void TextModeConsole::putChar(common::uint16_t x, common::uint16_t y, char c) {

// If the coordinates are out of bounds, return
if(x >= 80 || y >= 25)
return;

// Calculate the offset (*80 because there are 80 characters per line)
int offset = (y*80 + x);

// Set the character at the offset, by masking the character with the current character (last 8 bits)
videoMemory[offset] = (videoMemory[offset] & 0xFF00) | (uint16_t)c;

}

/**
* Sets the foreground color at the specified location
* @param x The x coordinate
* @param y The y coordinate
* @param foreground The foreground color
*/
void TextModeConsole::setForegroundColor(common::uint16_t x, common::uint16_t y, ConsoleColor foreground) {

// If the coordinates are out of bounds, return
if(x >= 80 || y >= 25)
return;

// Calculate the offset (*80 because there are 80 characters per line)
int offset = (y*80 + x);

// Set the foreground color at the offset, by masking the foreground color with the current foreground color (bits 8-11)
videoMemory[offset] = (videoMemory[offset] & 0xF0FF) | ((uint16_t)foreground << 8);
}

/**
* Sets the background color at the specified location
* @param x The x coordinate
* @param y The y coordinate
* @param background The background color
*/
void TextModeConsole::setBackgroundColor(common::uint16_t x, common::uint16_t y, ConsoleColor background) {

// If the coordinates are out of bounds, return
if(x >= 80 || y >= 25)
return;

// Calculate the offset (*80 because there are 80 characters per line)
int offset = (y*80 + x);

// Set the background color at the offset, by masking the background color with the current background color (bits 12-15)
videoMemory[offset] = (videoMemory[offset] & 0x0FFF) | ((uint16_t)background << 12);

}

/**
* Gets the character at the specified location
* @param x The x coordinate
* @param y The y coordinate
* @return The character at the specified location
*/
char TextModeConsole::getChar(common::uint16_t x, common::uint16_t y) {

// If the coordinates are out of bounds, return
if(x >= 80 || y >= 25)
return ' ';

// Calculate the offset (*80 because there are 80 characters per line)
int offset = (y*80 + x);

// Return the character at the offset, by masking the character with the current character (last 8 bits)
return (char)(videoMemory[offset] & 0x00FF);
}

/**
* Gets the foreground color at the specified location
* @param x The x coordinate
* @param y The y coordinate
* @return The foreground color at the specified location
*/
ConsoleColor TextModeConsole::getForegroundColor(common::uint16_t x, common::uint16_t y) {

// If the coordinates are out of bounds, return
if(x >= 80 || y >= 25)
return ConsoleColor::Black;

// Calculate the offset (*80 because there are 80 characters per line)
int offset = (y*80 + x);

// Return the foreground color at the offset, by masking the foreground color with the current foreground color (bits 8-11)
return (ConsoleColor)((videoMemory[offset] & 0x0F00) >> 8);
}

/**
* Gets the background color at the specified location
* @param x The x coordinate
* @param y The y coordinate
* @return The background color at the specified location
*/
ConsoleColor TextModeConsole::getBackgroundColor(common::uint16_t x, common::uint16_t y) {

// If the coordinates are out of bounds, return
if(x >= 80 || y >= 25)
return ConsoleColor::Black;

// Calculate the offset (*80 because there are 80 characters per line)
int offset = (y*80 + x);

// Return the background color at the offset, by masking the background color with the current background color (bits 12-15)
return (ConsoleColor)((videoMemory[offset] & 0xF000) >> 12);
}



Loading

0 comments on commit e015a14

Please sign in to comment.