From: Amelia Coutard <eliottulio.coutard@gmail.com>
Date: Fri, 6 May 2022 22:33:12 +0000 (+0200)
Subject: Changed the code to use the definitions in <cstdint> and <cstddef> instead of the... 
X-Git-Url: https://git.ameliathe1st.gay/?a=commitdiff_plain;h=309f5f5505153741d2792595e96384bc45f04008;p=voyage-au-centre-des-fichiers.git

Changed the code to use the definitions in <cstdint> and <cstddef> instead of the c equivalents
---

diff --git a/src/fb.cpp b/src/fb.cpp
index b4d6e16..c35caf0 100644
--- a/src/fb.cpp
+++ b/src/fb.cpp
@@ -3,14 +3,14 @@
 
 os::color os::operator*(color c1, color c2) {
 	return {
-		.r = uint8_t(int(c1.r) * int(c2.r) / 256),
-		.g = uint8_t(int(c1.g) * int(c2.g) / 256),
-		.b = uint8_t(int(c1.b) * int(c2.b) / 256),
+		.r = std::uint8_t(int(c1.r) * int(c2.r) / 256),
+		.g = std::uint8_t(int(c1.g) * int(c2.g) / 256),
+		.b = std::uint8_t(int(c1.b) * int(c2.b) / 256),
 	};
 }
 
-os::framebuffer::framebuffer(uint64_t addr, uint32_t pitch, uint32_t width, uint32_t height, uint8_t bpp, uint8_t type, const uint8_t* color_info) {
-	address = phys_ptr<volatile uint8_t>(addr);
+os::framebuffer::framebuffer(std::uint64_t addr, std::uint32_t pitch, std::uint32_t width, std::uint32_t height, std::uint8_t bpp, std::uint8_t type, const std::uint8_t* color_info) {
+	address = phys_ptr<volatile std::uint8_t>(addr);
 	this->pitch = pitch;
 	this->width = width;
 	this->height = height;
@@ -31,23 +31,23 @@ os::framebuffer::framebuffer(uint64_t addr, uint32_t pitch, uint32_t width, uint
 	b_pos =  color_info[4];
 	b_mask = (1 << color_info[5]) - 1;
 }
-void os::framebuffer::putpixel(size_t x, size_t y, color c) {
-	*reinterpret_cast<volatile uint32_t*>(&address[pitch * y + x * bpp / 8]) = color_to_data(c);
+void os::framebuffer::putpixel(std::size_t x, std::size_t y, color c) {
+	*reinterpret_cast<volatile std::uint32_t*>(&address[pitch * y + x * bpp / 8]) = color_to_data(c);
 }
 void os::framebuffer::clear(color c) {
-	for (size_t x = 0; x < width; x++) {
-		for (size_t y = 0; y < height; y++) {
+	for (std::size_t x = 0; x < width; x++) {
+		for (std::size_t y = 0; y < height; y++) {
 			putpixel(x, y, c);
 		}
 	}
 }
-size_t os::framebuffer::get_width() const {
+std::size_t os::framebuffer::get_width() const {
 	return width;
 }
-size_t os::framebuffer::get_height() const {
+std::size_t os::framebuffer::get_height() const {
 	return height;
 }
 
-uint32_t os::framebuffer::color_to_data(color c) const {
-return ((uint32_t(c.r) & r_mask) << r_pos) | ((uint32_t(c.g) & g_mask) << g_pos) | ((uint32_t(c.b) & b_mask) << b_pos);
+std::uint32_t os::framebuffer::color_to_data(color c) const {
+return ((std::uint32_t(c.r) & r_mask) << r_pos) | ((std::uint32_t(c.g) & g_mask) << g_pos) | ((std::uint32_t(c.b) & b_mask) << b_pos);
 }
diff --git a/src/fb.hpp b/src/fb.hpp
index 15f6e9a..7c512d9 100644
--- a/src/fb.hpp
+++ b/src/fb.hpp
@@ -1,40 +1,40 @@
 #pragma once
 
-#include <stdint.h>
+#include <cstdint>
 #include "utils.hpp"
 
 namespace os {
 
 struct color {
-	uint8_t r;
-	uint8_t g;
-	uint8_t b;
+	std::uint8_t r;
+	std::uint8_t g;
+	std::uint8_t b;
 };
 color operator*(color c1, color c2);
 
 class framebuffer {
 public:
 	framebuffer() = default;
-	framebuffer(uint64_t addr, uint32_t pitch, uint32_t width, uint32_t height, uint8_t bpp, uint8_t type, const uint8_t* color_info);
-	void putpixel(size_t x, size_t y, color c);
+	framebuffer(std::uint64_t addr, std::uint32_t pitch, std::uint32_t width, std::uint32_t height, std::uint8_t bpp, std::uint8_t type, const std::uint8_t* color_info);
+	void putpixel(std::size_t x, std::size_t y, color c);
 	void clear(color c);
-	size_t get_width() const;
-	size_t get_height() const;
+	std::size_t get_width() const;
+	std::size_t get_height() const;
 
 private:
-	uint32_t color_to_data(color c) const;
+	std::uint32_t color_to_data(color c) const;
 
-	phys_ptr<volatile uint8_t> address = nullptr;
-	size_t pitch;
-	size_t width;
-	size_t height;
-	uint8_t bpp;
-	uint8_t r_pos;
-	uint8_t r_mask;
-	uint8_t g_pos;
-	uint8_t g_mask;
-	uint8_t b_pos;
-	uint8_t b_mask;
+	phys_ptr<volatile std::uint8_t> address = nullptr;
+	std::size_t pitch;
+	std::size_t width;
+	std::size_t height;
+	std::uint8_t bpp;
+	std::uint8_t r_pos;
+	std::uint8_t r_mask;
+	std::uint8_t g_pos;
+	std::uint8_t g_mask;
+	std::uint8_t b_pos;
+	std::uint8_t b_mask;
 };
 
 }
diff --git a/src/multiboot2.hpp b/src/multiboot2.hpp
index 41091ac..adaa1e0 100644
--- a/src/multiboot2.hpp
+++ b/src/multiboot2.hpp
@@ -1,38 +1,38 @@
 #pragma once
 
 #ifdef __cplusplus
-#	include <stdint.h>
+#	include <cstdint>
 #	include "utils.hpp"
 	namespace multiboot2 {
 #endif // __cplusplus
 
 #ifdef __cplusplus
-	constexpr uint32_t magic = 0xE85250D6;
+	constexpr std::uint32_t magic = 0xE85250D6;
 #else
 #	define multiboot2_magic 0xE85250D6
 #endif // __cplusplus
 
 #ifdef __cplusplus
-	constexpr uint32_t arch_i386_32bit = 0;
-	constexpr uint32_t arch_mips_32bit = 4;
+	constexpr std::uint32_t arch_i386_32bit = 0;
+	constexpr std::uint32_t arch_mips_32bit = 4;
 #else
 #	define multiboot2_arch_i386_32bit 0
 #	define multiboot2_arch_mips_32bit 4
 #endif // __cplusplus
 
 #ifdef __cplusplus
-	constexpr uint32_t checksum(uint32_t arch, uint32_t length) { return -(magic + arch + length); }
+	constexpr std::uint32_t checksum(std::uint32_t arch, std::uint32_t length) { return -(magic + arch + length); }
 #else
 #	define multiboot2_checksum(arch, length) -(multiboot2_magic + (arch) + (length))
 #endif // __cplusplus
 
 #ifdef __cplusplus
 	struct __attribute__((packed)) info_start {
-		uint32_t total_size;
-		uint32_t reserved;
+		std::uint32_t total_size;
+		std::uint32_t reserved;
 	};
 	struct __attribute__((packed)) info {
-		enum class type_t : uint32_t {
+		enum class type_t : std::uint32_t {
 			end = 0,
 			basic_memory_info = 4,
 			bios_boot_device = 5,
@@ -57,8 +57,8 @@
 			image_load_base_physical_address = 21,
 		};
 		type_t type;
-		uint32_t size;
-		uint8_t rest[];
+		std::uint32_t size;
+		std::uint8_t rest[];
 	};
 
 	inline os::phys_ptr<const info> next(os::phys_ptr<const info_start> ptr) {
@@ -68,26 +68,26 @@
 		return os::phys_ptr<const info>((ptr.get_phys_addr() + ptr->size + 7) / 8 * 8); // + 7) / 8 * 8 is required for alignment.
 	}
 
-	uint64_t framebuffer_addr(os::phys_ptr<const info> ptr) {
-		return *reinterpret_cast<const uint64_t*>(&ptr->rest[0]);
+	std::uint64_t framebuffer_addr(os::phys_ptr<const info> ptr) {
+		return *reinterpret_cast<const std::uint64_t*>(&ptr->rest[0]);
 	}
-	uint32_t framebuffer_pitch(os::phys_ptr<const info> ptr) {
-		return *reinterpret_cast<const uint32_t*>(&ptr->rest[8]);
+	std::uint32_t framebuffer_pitch(os::phys_ptr<const info> ptr) {
+		return *reinterpret_cast<const std::uint32_t*>(&ptr->rest[8]);
 	}
-	uint32_t framebuffer_width(os::phys_ptr<const info> ptr) {
-		return *reinterpret_cast<const uint32_t*>(&ptr->rest[12]);
+	std::uint32_t framebuffer_width(os::phys_ptr<const info> ptr) {
+		return *reinterpret_cast<const std::uint32_t*>(&ptr->rest[12]);
 	}
-	uint32_t framebuffer_height(os::phys_ptr<const info> ptr) {
-		return *reinterpret_cast<const uint32_t*>(&ptr->rest[16]);
+	std::uint32_t framebuffer_height(os::phys_ptr<const info> ptr) {
+		return *reinterpret_cast<const std::uint32_t*>(&ptr->rest[16]);
 	}
-	uint8_t framebuffer_bpp(os::phys_ptr<const info> ptr) {
-		return *reinterpret_cast<const uint8_t*>(&ptr->rest[20]);
+	std::uint8_t framebuffer_bpp(os::phys_ptr<const info> ptr) {
+		return *reinterpret_cast<const std::uint8_t*>(&ptr->rest[20]);
 	}
-	uint8_t framebuffer_type(os::phys_ptr<const info> ptr) {
-		return *reinterpret_cast<const uint8_t*>(&ptr->rest[21]);
+	std::uint8_t framebuffer_type(os::phys_ptr<const info> ptr) {
+		return *reinterpret_cast<const std::uint8_t*>(&ptr->rest[21]);
 	}
-	const uint8_t* color_info(os::phys_ptr<const info> ptr) {
-		return reinterpret_cast<const uint8_t*>(&ptr->rest[24]);
+	const std::uint8_t* color_info(os::phys_ptr<const info> ptr) {
+		return reinterpret_cast<const std::uint8_t*>(&ptr->rest[24]);
 	}
 #endif // __cplusplus
 
diff --git a/src/serial.cpp b/src/serial.cpp
index 8cf52b7..a8ae1a7 100644
--- a/src/serial.cpp
+++ b/src/serial.cpp
@@ -1,12 +1,12 @@
-#include <stddef.h>
+#include <cstddef>
 #include "serial.hpp"
 
 namespace {
-	void outb(uint16_t port, uint8_t data) {
+	void outb(std::uint16_t port, std::uint8_t data) {
 		asm volatile ("outb %1,%0" : : "dN"(port), "a"(data));
 	}
-	uint8_t inb(uint16_t port) {
-		uint8_t data;
+	std::uint8_t inb(std::uint16_t port) {
+		std::uint8_t data;
 		asm volatile ("inb %1,%0" : "=a"(data) : "dN"(port));
 		return data;
 	}
@@ -33,14 +33,14 @@ bool os::init_serial_port() {
 bool os::serial_received() {
 	return (inb(serial_port + 5) & 0x01) != 0;
 }
-uint8_t os::read_serial() {
+std::uint8_t os::read_serial() {
 	while (!serial_received()) {}
 	return inb(serial_port + 0);
 }
 bool os::serial_transmit_empty() {
 	return (inb(serial_port + 5) & 0x20) != 0;
 }
-void os::write_serial(uint8_t v) {
+void os::write_serial(std::uint8_t v) {
 	while (!serial_transmit_empty()) {}
 	outb(serial_port + 0, v);
 }
@@ -49,68 +49,68 @@ void os::printc(char c) {
 	write_serial(c);
 }
 void os::print(const char* str) {
-	for (size_t i = 0; str[i] != '\0'; i++) {
+	for (std::size_t i = 0; str[i] != '\0'; i++) {
 		os::printc(str[i]);
 	}
 }
-void os::print(uint64_t v) {
+void os::print(std::uint64_t v) {
 	for (int i = 60; i >= 0; i -= 4) {
 		const int c = (v >> i) & 0xF;
 		os::printc(c < 10 ? c + '0' : c + 'A' - 10);
 	}
 }
-void os::print(uint32_t v) {
+void os::print(std::uint32_t v) {
 	for (int i = 28; i >= 0; i -= 4) {
 		const int c = (v >> i) & 0xF;
 		os::printc(c < 10 ? c + '0' : c + 'A' - 10);
 	}
 }
-void os::print(uint16_t v) {
+void os::print(std::uint16_t v) {
 	for (int i = 12; i >= 0; i -= 4) {
 		const int c = (v >> i) & 0xF;
 		os::printc(c < 10 ? c + '0' : c + 'A' - 10);
 	}
 }
-void os::print(uint8_t v) {
+void os::print(std::uint8_t v) {
 	for (int i = 4; i >= 0; i -= 4) {
 		const int c = (v >> i) & 0xF;
 		os::printc(c < 10 ? c + '0' : c + 'A' - 10);
 	}
 }
-void os::print(int64_t v) {
+void os::print(std::int64_t v) {
 	if (v < 0) {
 		os::printc('-');
-		os::print(uint64_t(-v));
+		os::print(std::uint64_t(-v));
 	} else {
 		os::printc(' ');
-		os::print(uint64_t(v));
+		os::print(std::uint64_t(v));
 	}
 }
-void os::print(int32_t v) {
+void os::print(std::int32_t v) {
 	if (v < 0) {
 		os::printc('-');
-		os::print(uint32_t(-v));
+		os::print(std::uint32_t(-v));
 	} else {
 		os::printc(' ');
-		os::print(uint32_t(v));
+		os::print(std::uint32_t(v));
 	}
 }
-void os::print(int16_t v) {
+void os::print(std::int16_t v) {
 	if (v < 0) {
 		os::printc('-');
-		os::print(uint16_t(-v));
+		os::print(std::uint16_t(-v));
 	} else {
 		os::printc(' ');
-		os::print(uint16_t(v));
+		os::print(std::uint16_t(v));
 	}
 }
-void os::print(int8_t v) {
+void os::print(std::int8_t v) {
 	if (v < 0) {
 		os::printc('-');
-		os::print(uint8_t(-v));
+		os::print(std::uint8_t(-v));
 	} else {
 		os::printc(' ');
-		os::print(uint8_t(v));
+		os::print(std::uint8_t(v));
 	}
 }
 void os::println(const char* str) {
diff --git a/src/serial.hpp b/src/serial.hpp
index a62a59a..39bb4b4 100644
--- a/src/serial.hpp
+++ b/src/serial.hpp
@@ -1,28 +1,28 @@
 #pragma once
 
-#include <stdint.h>
+#include <cstdint>
 
 namespace os {
 
-constexpr uint16_t serial_port{0x3F8};
+constexpr std::uint16_t serial_port{0x3F8};
 
 bool init_serial_port();
 
 bool serial_received();
-uint8_t read_serial();
+std::uint8_t read_serial();
 bool serial_transmit_empty();
-void write_serial(uint8_t v);
+void write_serial(std::uint8_t v);
 
 void printc(char c);
 void print(const char* str);
-void print(uint64_t v);
-void print(uint32_t v);
-void print(uint16_t v);
-void print(uint8_t v);
-void print(int64_t v);
-void print(int32_t v);
-void print(int16_t v);
-void print(int8_t v);
+void print(std::uint64_t v);
+void print(std::uint32_t v);
+void print(std::uint16_t v);
+void print(std::uint8_t v);
+void print(std::int64_t v);
+void print(std::int32_t v);
+void print(std::int16_t v);
+void print(std::int8_t v);
 void println(const char* str);
 void assert(bool cond, const char* diagnostic);
 
diff --git a/src/utils.hpp b/src/utils.hpp
index 773056f..2f1ae15 100644
--- a/src/utils.hpp
+++ b/src/utils.hpp
@@ -1,7 +1,7 @@
 #pragma once
 
-#include <stddef.h>
-#include <stdint.h>
+#include <cstddef>
+#include <cstdint>
 #include <compare>
 
 namespace os {
@@ -9,10 +9,10 @@ namespace os {
 	template <typename T>
 	class phys_ptr {
 	public:
-		constexpr explicit phys_ptr(uintptr_t phys_addr): phys_addr(phys_addr) {}
-		constexpr phys_ptr(nullptr_t): phys_addr(0) {}
+		constexpr explicit phys_ptr(std::uintptr_t phys_addr): phys_addr(phys_addr) {}
+		constexpr phys_ptr(std::nullptr_t): phys_addr(0) {}
 
-		constexpr T& operator[](size_t i) const {
+		constexpr T& operator[](std::size_t i) const {
 			return get_virt_addr()[i];
 		}
 		constexpr T& operator*() const {
@@ -38,11 +38,11 @@ namespace os {
 			operator--();
 			return old;
 		}
-		constexpr phys_ptr<T>& operator+=(ptrdiff_t offset) {
+		constexpr phys_ptr<T>& operator+=(std::ptrdiff_t offset) {
 			phys_addr += offset * sizeof(T);
 			return *this;
 		}
-		constexpr phys_ptr<T>& operator-=(ptrdiff_t offset) {
+		constexpr phys_ptr<T>& operator-=(std::ptrdiff_t offset) {
 			phys_addr -= offset * sizeof(T);
 			return *this;
 		}
@@ -50,17 +50,17 @@ namespace os {
 		friend constexpr auto operator<=>(phys_ptr<T> a, phys_ptr<T> b) { return    a.phys_addr <=> b.phys_addr;    }
 		friend constexpr auto operator== (phys_ptr<T> a, phys_ptr<T> b) { return    a.phys_addr ==  b.phys_addr;    }
 
-		friend constexpr phys_ptr<T> operator+(phys_ptr<T> ptr, ptrdiff_t offset) {
+		friend constexpr phys_ptr<T> operator+(phys_ptr<T> ptr, std::ptrdiff_t offset) {
 			return phys_ptr<T>{ptr.phys_addr + offset * sizeof(T)};
 		}
-		friend constexpr phys_ptr<T> operator+(ptrdiff_t offset, phys_ptr<T> ptr) {
+		friend constexpr phys_ptr<T> operator+(std::ptrdiff_t offset, phys_ptr<T> ptr) {
 			return ptr + offset;
 		}
-		friend constexpr phys_ptr<T> operator-(phys_ptr<T> ptr, ptrdiff_t offset) {
+		friend constexpr phys_ptr<T> operator-(phys_ptr<T> ptr, std::ptrdiff_t offset) {
 			return phys_ptr<T>{ptr.phys_addr - offset * sizeof(T)};
 		}
 
-		constexpr uintptr_t get_phys_addr() const {
+		constexpr std::uintptr_t get_phys_addr() const {
 			return phys_addr;
 		}
 
@@ -69,7 +69,7 @@ namespace os {
 			return reinterpret_cast<T*>(phys_addr + 0xFFFF800000000000);
 		}
 
-		uintptr_t phys_addr;
+		std::uintptr_t phys_addr;
 	};
 
 	void halt();