Skip to content

Commit

Permalink
Style Corrections for drivers
Browse files Browse the repository at this point in the history
  • Loading branch information
maxtyson123 committed Jan 2, 2024
1 parent 9d77507 commit 4043319
Show file tree
Hide file tree
Showing 63 changed files with 1,395 additions and 1,330 deletions.
2 changes: 1 addition & 1 deletion docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ To keep the code understanble please make sure it is formatted and reable. Addit
## We Use [GitHub Flow](https://guides.github.com/introduction/flow/index.html), So All Code Changes Happen Through Pull Requests
Pull requests are the best way to propose changes to the codebase (we use [GitHub Flow](https://guides.github.com/introduction/flow/index.html)). We actively welcome your pull requests:

1. Fork the repo and create your branch from `master`.
1. Fork the repo and create your branch from `m_is_master`.
2. If you've added code that should be tested, add tests.
3. If you've changed APIs, update the documentation.
4. Ensure the test suite passes.
Expand Down
12 changes: 6 additions & 6 deletions docs/Notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ Here are the notes on graphics for the operating system. (May need to read hardw
- However, communicating with these ports aren't that easy as there is an index port (to tell where the data should be put) and a data port (push the data)
- And on the CRTC port there is special indexes and data that has to be set for it to unlocked before writing actual data (the reason it has to be unlocked is that if incorrect data is the hardware could be damaged)
- Similarly, the AC port has to be reset before each index & data write.
- The VGA class that was written should have a class above that call graphicsContext which would define methods such as render_pixel(...), drawRect(...), draw_line(...), draw_circle(...) and sub-classes such as color.
- The draw functions should rely on the render_pixel function therefore in different graphics modes that are derived from that graphicsContext class can be supported.
- The VGA class that was written should have a class above that call m_graphics_context which would define methods such as render_pixel(...), drawRect(...), draw_line(...), draw_circle(...) and sub-classes such as color.
- The draw functions should rely on the render_pixel function therefore in different graphics modes that are derived from that m_graphics_context class can be supported.

### VESA
- VESA is a legacy extension to VGA that allows for a higher color depth and larger screen resolutions
Expand Down Expand Up @@ -283,16 +283,16 @@ Here are the notes on graphics for the operating system. (May need to read hardw
<!-- TOC --><a name="gui-framework"></a>
### GUI - Framework
See also: Bresenham line algorithm (use for later)
- The GUI framework will have a base class called Widget, which should have a draw function. This draw function would get a graphicsContext and draw itself onto of it using the graphicContext's draw methods.
- The GUI framework will have a base class called Widget, which should have a draw function. This draw function would get a m_graphics_context and draw itself onto of it using the graphicContext's draw methods.
- Thees widgets will have parents and such, therefore their draw positions will be relative, meaning there has to be a function to get the absolute position.
- Widgets will also have a m_width and m_height, and a function to check if a co-ordinate is inside itself (used for mouse handling and such)
- To handle mouse input, the widget will use a mouse event handler and handle the events onMouseDown, onMouseMoveWidget, onMouseUpEvent. However, the mouse handler won't be on the widget itself, rather it would be on the desktop.
- To handle mouse input, the widget will use a mouse event handler and handle the events onMouseDown, onMouseMoveWidget, on_mouse_up_event. However, the mouse handler won't be on the widget itself, rather it would be on the desktop.
- This is because the mouse movement is reported in relative-ness not absolute position (desktop would store mouse position and update it based on the movement, the object can just query the x,y pos from the desktop).
- A subclass of the widget would be a composite class, which would contain an array of child widgets, and it would pass methods on to the children (e.g. the child gets drawn last so its on m_top)
- To get which widget to preform the keyEvent or mouseEvent the desktop will have a function of getting the focused widget
- The desktop will work like the composite widget, but will have to override the mouseHandler class as mouse passes movement in relative to last position (moved x pixels) so the desktop will have to translate the restiveness into absolute positions
- For better performance, instead of re-drawing the screen every time just draw it once and then when a gui object changes (e.g. moving a window) memory the object to the new state and then redraw any invalid parts (invalid is where places where there used to be the gui object)
- To draw text the "modes.c" has various 8x8 Bitmap fonts. Using these fonts a Text widget can be made that gets the characters of a string from the font and then print all the pixels in that character.
- To draw text the "modes.c" has various 8x8 Bitmap fonts. Using these fonts a Text widget can be made that gets the characters of a string from the m_font and then print all the pixels in that character.

<!-- TOC --><a name="system-stuff"></a>
# System Stuff
Expand Down Expand Up @@ -343,7 +343,7 @@ See also [Double Linked List](https://en.wikipedia.org/wiki/Linked_list#Doubly_l
- - size_t : size
- These Memory Chunks are just a linked list (double linked) and every chunk that has dropped from the RAM will be entered into the list, which is how the OS will keep track of used / free memory
- More than one free chunk in a row is bad as it means larger data that could have had fit into those two chunks if they were combined won't be able to. This can be prevented merging a chunk with another if it is deallocated next to another un allocated chunk.
- To find memory easier see [multiboot.h](https://github.com/cstack/osdev/blob/master/multiboot.h), however I will implement my own for copyright reasons which will just use the multiboot structure
- To find memory easier see [multiboot.h](https://github.com/cstack/osdev/blob/m_is_master/multiboot.h), however I will implement my own for copyright reasons which will just use the multiboot structure
- Now that there is memory management objects will be able to use the "new" and "delete" methods, allowing for virtual deconstructions
- However, if there is no free memory then the function will return 0 which would work if in user space as memory pointer 0 is out of bounds. The OS cant throw an exception like c++ normally would as currently there is no exception handler
<!-- TOC --><a name="system-calls"></a>
Expand Down
2 changes: 1 addition & 1 deletion docs/Styles/Coding Style.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- Modified from https://github.com/SerenityOS/serenity/blob/master/Documentation/CodingStyle.md -->
<!-- Modified from https://github.com/SerenityOS/serenity/blob/m_is_master/Documentation/CodingStyle.md -->
# MaxOS C++ coding style


Expand Down
2 changes: 1 addition & 1 deletion docs/Styles/Interface Style.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@ Ellipses should be used sparingly elsewhere to avoid confusion with elision.
- Browse...
- Insert Emoji...

<!-- https://github.com/SerenityOS/serenity/blob/master/Documentation/HumanInterfaceGuidelines/Text.md?plain=1 -->
<!-- https://github.com/SerenityOS/serenity/blob/m_is_master/Documentation/HumanInterfaceGuidelines/Text.md?plain=1 -->
4 changes: 2 additions & 2 deletions kernel/include/common/inputStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ namespace maxOS{
*/
template<class Type> void InputStreamBuffer<Type>::on_stream_read(Type read_element) {

// Flush the buffer if the event fire element is read
// flush the buffer if the event fire element is read
if(read_element == m_event_fire_element){
flush();
return;
Expand All @@ -333,7 +333,7 @@ namespace maxOS{
*/
template<class Type> void InputStreamBuffer<Type>::on_end_of_stream(GenericInputStream<Type> *stream) {

// Flush the buffer if there is any data in it
// flush the buffer if there is any data in it
if(m_offset > 0)
flush();

Expand Down
2 changes: 1 addition & 1 deletion kernel/include/common/outputStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace maxOS{
virtual void write(string string_to_write) override;
virtual void write_char(char char_to_write);
virtual void write_int(int int_to_write);
virtual void writeHex(uint32_t hex_to_write);
virtual void write_hex(uint32_t hex_to_write);

OutputStream& operator << (string string_to_write) override;
OutputStream& operator << (int int_to_write);
Expand Down
40 changes: 18 additions & 22 deletions kernel/include/drivers/ata.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,31 @@ namespace maxOS{
class AdvancedTechnologyAttachment{

protected:
hardwarecommunication::Port16Bit dataPort;
hardwarecommunication::Port8Bit errorPort;
hardwarecommunication::Port8Bit sectorCountPort;
hardwarecommunication::Port8Bit LBAlowPort;
hardwarecommunication::Port8Bit LBAmidPort;
hardwarecommunication::Port8Bit LBAHiPort;
hardwarecommunication::Port8Bit devicePort;
hardwarecommunication::Port8Bit commandPort;
hardwarecommunication::Port8Bit controlPort;
bool master;
uint16_t bytesPerSector;

common::OutputStream* ataMessageStream;
hardwarecommunication::Port16Bit m_data_port;
hardwarecommunication::Port8Bit m_error_port;
hardwarecommunication::Port8Bit m_sector_count_port;
hardwarecommunication::Port8Bit m_LBA_low_port;
hardwarecommunication::Port8Bit m_LBA_mid_port;
hardwarecommunication::Port8Bit m_LBA_high_Port;
hardwarecommunication::Port8Bit m_device_port;
hardwarecommunication::Port8Bit m_command_port;
hardwarecommunication::Port8Bit m_control_port;
bool m_is_master;
uint16_t m_bytes_per_sector { 512 };

common::OutputStream* ata_message_stream;
public:
AdvancedTechnologyAttachment(uint16_t portBase, bool master, common::OutputStream* ataMessageStream);
AdvancedTechnologyAttachment(uint16_t port_base, bool master, common::OutputStream* output_stream);
~AdvancedTechnologyAttachment();

void Identify();
void Read28(uint32_t sector, uint8_t* data, int count);
void Write28(uint32_t sector, uint8_t* data, int count);
void Flush(); //Flush Cache //TODO: See also vid 19 24:20
void identify();
void read_28(uint32_t sector, uint8_t* data, int count);
void write_28(uint32_t sector, uint8_t* data, int count);
void flush(); //TODO: See also vid 19 24:20

//TODO: Make into driver class


};

}

}

#endif //MAXOS_DRIVERS_ATA_H
8 changes: 4 additions & 4 deletions kernel/include/drivers/clock/clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace maxOS {
class TimeEvent : public common::Event<ClockEvents>{
public:
common::Time* time;
TimeEvent(common::Time* time);
TimeEvent(common::Time*);
~TimeEvent();
};

Expand Down Expand Up @@ -71,7 +71,7 @@ namespace maxOS {
uint16_t m_ticks_until_next_event { 1 };

// Other functions
void handle_interrupt() override;
void handle_interrupt() final;
uint8_t read_hardware_clock(uint8_t address);
uint8_t binary_representation(uint8_t number);

Expand All @@ -82,8 +82,8 @@ namespace maxOS {
void activate() override;
void delay(uint32_t milliseconds);

string get_vendor_name() override;
string get_device_name() override;
string get_vendor_name() final;
string get_device_name() final;
};

}
Expand Down
21 changes: 10 additions & 11 deletions kernel/include/drivers/console/textmode.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,23 @@ namespace maxOS{

class TextModeConsole : public Driver, public Console
{
protected:
uint16_t* m_video_memory { (uint16_t*)0xB8000 };

public:
TextModeConsole();
~TextModeConsole();

uint16_t width();
uint16_t height();

void put_character(uint16_t x, uint16_t y, char c);
void set_foreground_color(uint16_t x, uint16_t y, ConsoleColour foreground);
void set_background_color(uint16_t x, uint16_t y, ConsoleColour background);
uint16_t width() final;
uint16_t height() final;

char get_character(uint16_t x, uint16_t y);
ConsoleColour get_foreground_color(uint16_t x, uint16_t y);
ConsoleColour get_background_color(uint16_t x, uint16_t y);
void put_character(uint16_t x, uint16_t y, char c) final;
void set_foreground_color(uint16_t x, uint16_t y, ConsoleColour) final;
void set_background_color(uint16_t x, uint16_t y, ConsoleColour) final;

protected:
uint16_t* videoMemory;
char get_character(uint16_t x, uint16_t y) final;
ConsoleColour get_foreground_color(uint16_t x, uint16_t y) final;
ConsoleColour get_background_color(uint16_t x, uint16_t y) final;
};

}
Expand Down
29 changes: 13 additions & 16 deletions kernel/include/drivers/console/vesaboot.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,26 @@ namespace maxOS{
{

public:
VESABootConsole(common::GraphicsContext* graphicsContext);
VESABootConsole(common::GraphicsContext*);
~VESABootConsole();

uint16_t width();
uint16_t height();
uint16_t width() final;
uint16_t height() final;

void put_character(uint16_t x, uint16_t y, char c);
void set_foreground_color(uint16_t x, uint16_t y, ConsoleColour foreground);
void set_background_color(uint16_t x, uint16_t y, ConsoleColour background);
void put_character(uint16_t x, uint16_t y, char) final;
void set_foreground_color(uint16_t x, uint16_t y, ConsoleColour) final;
void set_background_color(uint16_t x, uint16_t y, ConsoleColour) final;

char get_character(uint16_t x, uint16_t y);
ConsoleColour get_foreground_color(uint16_t x, uint16_t y);
ConsoleColour get_background_color(uint16_t x, uint16_t y);
char get_character(uint16_t x, uint16_t y) final;
ConsoleColour get_foreground_color(uint16_t x, uint16_t y) final;
ConsoleColour get_background_color(uint16_t x, uint16_t y) final;

common::Colour consoleColourToVESA(ConsoleColour colour);

// pointer to the video memory
uint16_t* videoMemory;
common::Colour console_colour_to_vesa(ConsoleColour);

protected:

common::GraphicsContext* graphicsContext;
gui::AmigaFont font;
uint16_t* m_video_memory;
common::GraphicsContext* m_graphics_context;
gui::AmigaFont m_font;
};

}
Expand Down
25 changes: 13 additions & 12 deletions kernel/include/drivers/driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ namespace maxOS
protected:
public:

common::OutputStream* driverMessageStream;
common::OutputStream* m_driver_message_stream;

Driver(common::OutputStream* driverMessageStream = 0);
~Driver();

void errorMessage(string message);
void errorMessage(char charToWrite);
void errorMessage(int intToWrite);
void errorMessage(uint32_t hexToWrite);
void error_message(string message);
void error_message(char char_to_write);
void error_message(int int_to_write);
void error_message(uint32_t hex_to_write);

virtual void activate();
virtual void deactivate();
Expand All @@ -45,27 +46,27 @@ namespace maxOS
public:
DriverSelectorEventHandler();
~DriverSelectorEventHandler();
virtual void onDriverSelected(Driver* driver);
virtual void on_driver_selected(Driver*);
};

class DriverSelector
{
public:
DriverSelector();
~DriverSelector();
virtual void selectDrivers(DriverSelectorEventHandler* handler, hardwarecommunication::InterruptManager* interruptManager, common::OutputStream* errorMessageStream);
virtual void select_drivers(DriverSelectorEventHandler* handler, hardwarecommunication::InterruptManager* interruptManager, common::OutputStream* errorMessageStream);
};

class DriverManager : public DriverSelectorEventHandler {
public:
common::Vector<Driver*> drivers;
public:
DriverManager();
~DriverManager();

void addDriver(Driver*);
void removeDriver(Driver*);
void onDriverSelected(Driver* driver);
void add_driver(Driver*);
void remove_driver(Driver*);
void on_driver_selected(Driver*);

common::Vector<Driver*> drivers;
};
}
}
Expand Down
Loading

0 comments on commit 4043319

Please sign in to comment.