Split up source and added basic support for different targets.

This commit is contained in:
2024-01-12 17:19:27 +01:00
parent 219a48c616
commit 408e06b2e0
29 changed files with 559 additions and 36 deletions

View File

@@ -0,0 +1,27 @@
#pragma once
#if !defined(BAD_APPLE_OS_ASSERT_H_INCLUDED)
#define BAD_APPLE_OS_ASSERT_H_INCLUDED
#include "./detail/common.h"
BA_EXTERN_C_BEGIN
#if defined(NDEBUG)
#define assert(condition) ((void) 0)
#else
#define assert(condition) \
if (!(condition)) \
{ \
__ba__assert_fail(__FILE__, __LINE__, #condition); \
}
#endif
#if !defined(NDEBUG)
BA_CXX_NORETURN void __ba__assert_fail(const char* filename, int line, const char* condition) BA_CXX_NOEXCEPT;
#endif
BA_EXTERN_C_END
#endif // !defined(BAD_APPLE_OS_ASSERT_H_INCLUDED)

View File

@@ -0,0 +1,21 @@
#pragma once
#if !defined(BAD_APPLE_OS_DETAIL_ATTRIBUTES_H_INCLUDED)
#define BAD_APPLE_OS_DETAIL_ATTRIBUTES_H_INCLUDED
#if defined(__cplusplus)
#define BA_CXX_NODISCARD [[nodiscard]]
#define BA_CXX_NORETURN [[noreturn]]
#define BA_CXX_NOEXCEPT noexcept
#define BA_EXTERN_C_BEGIN extern "C" {
#define BA_EXTERN_C_END }
#else
#define BA_CXX_NODISCARD
#define BA_CXX_NORETURN
#define BA_CXX_NOEXCEPT
#define BA_EXTERN_C_BEGIN
#define BA_EXTERN_C_END
#endif
#endif // !defined(BAD_APPLE_OS_DETAIL_ATTRIBUTES_H_INCLUDED)

View File

@@ -0,0 +1,10 @@
#pragma once
#if !defined(BAD_APPLE_OS_PANIC_HPP_INCLUDED)
#define BAD_APPLE_OS_PANIC_HPP_INCLUDED
[[noreturn]] void panic(const char* message) noexcept;
[[noreturn]] void panicf(const char* format, ...) noexcept;
#endif // !defined(BAD_APPLE_OS_PANIC_HPP_INCLUDED)

View File

@@ -0,0 +1,46 @@
#pragma once
#if !defined(OS_TTY_HPP_INCLUDED)
#define OS_TTY_HPP_INCLUDED 1
#include <stddef.h>
#include <stdint.h>
namespace tty
{
enum class VgaColor : uint8_t
{
BLACK = 0,
BLUE = 1,
GREEN = 2,
CYAN = 3,
RED = 4,
MAGENTA = 5,
BROWN = 6,
LIGHT_GREY = 7,
DARK_GREY = 8,
LIGHT_BLUE = 9,
LIGHT_GREEN = 10,
LIGHT_CYAN = 11,
LIGHT_RED = 12,
LIGHT_MAGENTA = 13,
LIGHT_BROWN = 14,
WHITE = 15
};
struct VgaDoubleColor
{
VgaColor foreground : 4 = VgaColor::LIGHT_GREY;
VgaColor background : 4 = VgaColor::BLACK;
};
void initialize();
void setColor(VgaDoubleColor color);
void putEntryAt(char chr, VgaDoubleColor color, size_t posX, size_t posY);
void putChar(char chr);
void write(const char* data, size_t size);
void write(const char* data);
} // namespace tty
#endif // OS_TTY_HPP_INCLUDED

View File

@@ -0,0 +1,19 @@
#pragma once
#if !defined(BAD_APPLE_OS_STDIO_H_INCLUDED)
#define BAD_APPLE_OS_STDIO_H_INCLUDED
#include <stdarg.h>
#include "./detail/common.h"
BA_EXTERN_C_BEGIN
int putchar(int chr) BA_CXX_NOEXCEPT;
int puts(const char* str) BA_CXX_NOEXCEPT;
int printf(const char* format, ...) BA_CXX_NOEXCEPT;
int vprintf(const char* format, va_list vlist) BA_CXX_NOEXCEPT;
BA_EXTERN_C_END
#endif // !defined(BAD_APPLE_OS_STDIO_H_INCLUDED)

View File

@@ -0,0 +1,18 @@
#pragma once
#if !defined(BAD_APPLE_OS_STDLIB_H_INCLUDED)
#define BAD_APPLE_OS_STDLIB_H_INCLUDED
#include <stddef.h>
#include "./detail/common.h"
BA_EXTERN_C_BEGIN
BA_CXX_NORETURN void abort();
BA_CXX_NODISCARD void* malloc(size_t size) BA_CXX_NOEXCEPT;
void free(void* ptr) BA_CXX_NOEXCEPT;
BA_EXTERN_C_END
#endif // !defined(BAD_APPLE_OS_STDLIB_H_INCLUDED)

View File

@@ -0,0 +1,21 @@
#pragma once
#if !defined(BAD_APPLE_OS_STRING_H_INCLUDED)
#define BAD_APPLE_OS_STRING_H_INCLUDED
#include <stddef.h>
#include "./detail/common.h"
BA_EXTERN_C_BEGIN
BA_CXX_NODISCARD int memcmp(const void* lhs, const void* rhs, size_t count) BA_CXX_NOEXCEPT;
void memcpy(void* dest, const void* src, size_t count) BA_CXX_NOEXCEPT;
void memmove(void* dest, const void* src, size_t count) BA_CXX_NOEXCEPT;
void* memset(void* dest, int value, size_t count) BA_CXX_NOEXCEPT;
BA_CXX_NODISCARD size_t strlen(const char* str) BA_CXX_NOEXCEPT;
BA_EXTERN_C_END
#endif // !defined(BAD_APPLE_OS_STRING_H_INCLUDED)