added clang format
This commit is contained in:
parent
ba8f73277c
commit
dfd6e90200
13 changed files with 366 additions and 390 deletions
22
.clang-format
Normal file
22
.clang-format
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
---
|
||||||
|
BasedOnStyle: LLVM
|
||||||
|
IndentWidth: 4
|
||||||
|
---
|
||||||
|
Language: Cpp
|
||||||
|
DerivePointerAlignment: false
|
||||||
|
PointerAlignment: Right
|
||||||
|
AccessModifierOffset: 0
|
||||||
|
AlignAfterOpenBracket: true
|
||||||
|
AlignEscapedNewlinesLeft: false
|
||||||
|
AlignOperands: true
|
||||||
|
AlignTrailingComments: true
|
||||||
|
AllowShortBlocksOnASingleLine: true
|
||||||
|
AllowShortCaseLabelsOnASingleLine: true
|
||||||
|
AllowShortFunctionsOnASingleLine: true
|
||||||
|
AllowShortIfStatementsOnASingleLine: true
|
||||||
|
AllowShortLoopsOnASingleLine: true
|
||||||
|
AlwaysBreakTemplateDeclarations: true
|
||||||
|
ColumnLimit: 120
|
||||||
|
NamespaceIndentation: Inner
|
||||||
|
Standard: Cpp11
|
||||||
|
UseTab: Never
|
|
@ -14,259 +14,249 @@
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ANY
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ANY
|
||||||
* DEVELOPER OR DISTRIBUTOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
* DEVELOPER OR DISTRIBUTOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY,
|
||||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
||||||
* IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MULTIBOOT_HEADER
|
#ifndef MULTIBOOT_HEADER
|
||||||
#define MULTIBOOT_HEADER 1
|
#define MULTIBOOT_HEADER 1
|
||||||
|
|
||||||
/* How many bytes from the start of the file we search for the header. */
|
/* How many bytes from the start of the file we search for the header. */
|
||||||
#define MULTIBOOT_SEARCH 8192
|
#define MULTIBOOT_SEARCH 8192
|
||||||
#define MULTIBOOT_HEADER_ALIGN 4
|
#define MULTIBOOT_HEADER_ALIGN 4
|
||||||
|
|
||||||
/* The magic field should contain this. */
|
/* The magic field should contain this. */
|
||||||
#define MULTIBOOT_HEADER_MAGIC 0x1BADB002
|
#define MULTIBOOT_HEADER_MAGIC 0x1BADB002
|
||||||
|
|
||||||
/* This should be in %eax. */
|
/* This should be in %eax. */
|
||||||
#define MULTIBOOT_BOOTLOADER_MAGIC 0x2BADB002
|
#define MULTIBOOT_BOOTLOADER_MAGIC 0x2BADB002
|
||||||
|
|
||||||
/* Alignment of multiboot modules. */
|
/* Alignment of multiboot modules. */
|
||||||
#define MULTIBOOT_MOD_ALIGN 0x00001000
|
#define MULTIBOOT_MOD_ALIGN 0x00001000
|
||||||
|
|
||||||
/* Alignment of the multiboot info structure. */
|
/* Alignment of the multiboot info structure. */
|
||||||
#define MULTIBOOT_INFO_ALIGN 0x00000004
|
#define MULTIBOOT_INFO_ALIGN 0x00000004
|
||||||
|
|
||||||
/* Flags set in the 'flags' member of the multiboot header. */
|
/* Flags set in the 'flags' member of the multiboot header. */
|
||||||
|
|
||||||
/* Align all boot modules on i386 page (4KB) boundaries. */
|
/* Align all boot modules on i386 page (4KB) boundaries. */
|
||||||
#define MULTIBOOT_PAGE_ALIGN 0x00000001
|
#define MULTIBOOT_PAGE_ALIGN 0x00000001
|
||||||
|
|
||||||
/* Must pass memory information to OS. */
|
/* Must pass memory information to OS. */
|
||||||
#define MULTIBOOT_MEMORY_INFO 0x00000002
|
#define MULTIBOOT_MEMORY_INFO 0x00000002
|
||||||
|
|
||||||
/* Must pass video information to OS. */
|
/* Must pass video information to OS. */
|
||||||
#define MULTIBOOT_VIDEO_MODE 0x00000004
|
#define MULTIBOOT_VIDEO_MODE 0x00000004
|
||||||
|
|
||||||
/* This flag indicates the use of the address fields in the header. */
|
/* This flag indicates the use of the address fields in the header. */
|
||||||
#define MULTIBOOT_AOUT_KLUDGE 0x00010000
|
#define MULTIBOOT_AOUT_KLUDGE 0x00010000
|
||||||
|
|
||||||
/* Flags to be set in the 'flags' member of the multiboot info structure. */
|
/* Flags to be set in the 'flags' member of the multiboot info structure. */
|
||||||
|
|
||||||
/* is there basic lower/upper memory information? */
|
/* is there basic lower/upper memory information? */
|
||||||
#define MULTIBOOT_INFO_MEMORY 0x00000001
|
#define MULTIBOOT_INFO_MEMORY 0x00000001
|
||||||
/* is there a boot device set? */
|
/* is there a boot device set? */
|
||||||
#define MULTIBOOT_INFO_BOOTDEV 0x00000002
|
#define MULTIBOOT_INFO_BOOTDEV 0x00000002
|
||||||
/* is the command-line defined? */
|
/* is the command-line defined? */
|
||||||
#define MULTIBOOT_INFO_CMDLINE 0x00000004
|
#define MULTIBOOT_INFO_CMDLINE 0x00000004
|
||||||
/* are there modules to do something with? */
|
/* are there modules to do something with? */
|
||||||
#define MULTIBOOT_INFO_MODS 0x00000008
|
#define MULTIBOOT_INFO_MODS 0x00000008
|
||||||
|
|
||||||
/* These next two are mutually exclusive */
|
/* These next two are mutually exclusive */
|
||||||
|
|
||||||
/* is there a symbol table loaded? */
|
/* is there a symbol table loaded? */
|
||||||
#define MULTIBOOT_INFO_AOUT_SYMS 0x00000010
|
#define MULTIBOOT_INFO_AOUT_SYMS 0x00000010
|
||||||
/* is there an ELF section header table? */
|
/* is there an ELF section header table? */
|
||||||
#define MULTIBOOT_INFO_ELF_SHDR 0X00000020
|
#define MULTIBOOT_INFO_ELF_SHDR 0X00000020
|
||||||
|
|
||||||
/* is there a full memory map? */
|
/* is there a full memory map? */
|
||||||
#define MULTIBOOT_INFO_MEM_MAP 0x00000040
|
#define MULTIBOOT_INFO_MEM_MAP 0x00000040
|
||||||
|
|
||||||
/* Is there drive info? */
|
/* Is there drive info? */
|
||||||
#define MULTIBOOT_INFO_DRIVE_INFO 0x00000080
|
#define MULTIBOOT_INFO_DRIVE_INFO 0x00000080
|
||||||
|
|
||||||
/* Is there a config table? */
|
/* Is there a config table? */
|
||||||
#define MULTIBOOT_INFO_CONFIG_TABLE 0x00000100
|
#define MULTIBOOT_INFO_CONFIG_TABLE 0x00000100
|
||||||
|
|
||||||
/* Is there a boot loader name? */
|
/* Is there a boot loader name? */
|
||||||
#define MULTIBOOT_INFO_BOOT_LOADER_NAME 0x00000200
|
#define MULTIBOOT_INFO_BOOT_LOADER_NAME 0x00000200
|
||||||
|
|
||||||
/* Is there a APM table? */
|
/* Is there a APM table? */
|
||||||
#define MULTIBOOT_INFO_APM_TABLE 0x00000400
|
#define MULTIBOOT_INFO_APM_TABLE 0x00000400
|
||||||
|
|
||||||
/* Is there video information? */
|
/* Is there video information? */
|
||||||
#define MULTIBOOT_INFO_VBE_INFO 0x00000800
|
#define MULTIBOOT_INFO_VBE_INFO 0x00000800
|
||||||
#define MULTIBOOT_INFO_FRAMEBUFFER_INFO 0x00001000
|
#define MULTIBOOT_INFO_FRAMEBUFFER_INFO 0x00001000
|
||||||
|
|
||||||
#ifndef ASM_FILE
|
#ifndef ASM_FILE
|
||||||
|
|
||||||
typedef unsigned char multiboot_uint8_t;
|
typedef unsigned char multiboot_uint8_t;
|
||||||
typedef unsigned short multiboot_uint16_t;
|
typedef unsigned short multiboot_uint16_t;
|
||||||
typedef unsigned int multiboot_uint32_t;
|
typedef unsigned int multiboot_uint32_t;
|
||||||
typedef unsigned long long multiboot_uint64_t;
|
typedef unsigned long long multiboot_uint64_t;
|
||||||
|
|
||||||
struct multiboot_header
|
struct multiboot_header {
|
||||||
{
|
/* Must be MULTIBOOT_MAGIC - see above. */
|
||||||
/* Must be MULTIBOOT_MAGIC - see above. */
|
multiboot_uint32_t magic;
|
||||||
multiboot_uint32_t magic;
|
|
||||||
|
|
||||||
/* Feature flags. */
|
/* Feature flags. */
|
||||||
multiboot_uint32_t flags;
|
multiboot_uint32_t flags;
|
||||||
|
|
||||||
/* The above fields plus this one must equal 0 mod 2^32. */
|
/* The above fields plus this one must equal 0 mod 2^32. */
|
||||||
multiboot_uint32_t checksum;
|
multiboot_uint32_t checksum;
|
||||||
|
|
||||||
/* These are only valid if MULTIBOOT_AOUT_KLUDGE is set. */
|
/* These are only valid if MULTIBOOT_AOUT_KLUDGE is set. */
|
||||||
multiboot_uint32_t header_addr;
|
multiboot_uint32_t header_addr;
|
||||||
multiboot_uint32_t load_addr;
|
multiboot_uint32_t load_addr;
|
||||||
multiboot_uint32_t load_end_addr;
|
multiboot_uint32_t load_end_addr;
|
||||||
multiboot_uint32_t bss_end_addr;
|
multiboot_uint32_t bss_end_addr;
|
||||||
multiboot_uint32_t entry_addr;
|
multiboot_uint32_t entry_addr;
|
||||||
|
|
||||||
/* These are only valid if MULTIBOOT_VIDEO_MODE is set. */
|
/* These are only valid if MULTIBOOT_VIDEO_MODE is set. */
|
||||||
multiboot_uint32_t mode_type;
|
multiboot_uint32_t mode_type;
|
||||||
multiboot_uint32_t width;
|
multiboot_uint32_t width;
|
||||||
multiboot_uint32_t height;
|
multiboot_uint32_t height;
|
||||||
multiboot_uint32_t depth;
|
multiboot_uint32_t depth;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* The symbol table for a.out. */
|
/* The symbol table for a.out. */
|
||||||
struct multiboot_aout_symbol_table
|
struct multiboot_aout_symbol_table {
|
||||||
{
|
multiboot_uint32_t tabsize;
|
||||||
multiboot_uint32_t tabsize;
|
multiboot_uint32_t strsize;
|
||||||
multiboot_uint32_t strsize;
|
multiboot_uint32_t addr;
|
||||||
multiboot_uint32_t addr;
|
multiboot_uint32_t reserved;
|
||||||
multiboot_uint32_t reserved;
|
|
||||||
};
|
};
|
||||||
typedef struct multiboot_aout_symbol_table multiboot_aout_symbol_table_t;
|
typedef struct multiboot_aout_symbol_table multiboot_aout_symbol_table_t;
|
||||||
|
|
||||||
/* The section header table for ELF. */
|
/* The section header table for ELF. */
|
||||||
struct multiboot_elf_section_header_table
|
struct multiboot_elf_section_header_table {
|
||||||
{
|
multiboot_uint32_t num;
|
||||||
multiboot_uint32_t num;
|
multiboot_uint32_t size;
|
||||||
multiboot_uint32_t size;
|
multiboot_uint32_t addr;
|
||||||
multiboot_uint32_t addr;
|
multiboot_uint32_t shndx;
|
||||||
multiboot_uint32_t shndx;
|
|
||||||
};
|
};
|
||||||
typedef struct multiboot_elf_section_header_table multiboot_elf_section_header_table_t;
|
typedef struct multiboot_elf_section_header_table multiboot_elf_section_header_table_t;
|
||||||
|
|
||||||
struct multiboot_info
|
struct multiboot_info {
|
||||||
{
|
/* Multiboot info version number */
|
||||||
/* Multiboot info version number */
|
multiboot_uint32_t flags;
|
||||||
multiboot_uint32_t flags;
|
|
||||||
|
|
||||||
/* Available memory from BIOS */
|
/* Available memory from BIOS */
|
||||||
multiboot_uint32_t mem_lower;
|
multiboot_uint32_t mem_lower;
|
||||||
multiboot_uint32_t mem_upper;
|
multiboot_uint32_t mem_upper;
|
||||||
|
|
||||||
/* "root" partition */
|
/* "root" partition */
|
||||||
multiboot_uint32_t boot_device;
|
multiboot_uint32_t boot_device;
|
||||||
|
|
||||||
/* Kernel command line */
|
/* Kernel command line */
|
||||||
multiboot_uint32_t cmdline;
|
multiboot_uint32_t cmdline;
|
||||||
|
|
||||||
/* Boot-Module list */
|
/* Boot-Module list */
|
||||||
multiboot_uint32_t mods_count;
|
multiboot_uint32_t mods_count;
|
||||||
multiboot_uint32_t mods_addr;
|
multiboot_uint32_t mods_addr;
|
||||||
|
|
||||||
union
|
union {
|
||||||
{
|
multiboot_aout_symbol_table_t aout_sym;
|
||||||
multiboot_aout_symbol_table_t aout_sym;
|
multiboot_elf_section_header_table_t elf_sec;
|
||||||
multiboot_elf_section_header_table_t elf_sec;
|
} u;
|
||||||
} u;
|
|
||||||
|
|
||||||
/* Memory Mapping buffer */
|
/* Memory Mapping buffer */
|
||||||
multiboot_uint32_t mmap_length;
|
multiboot_uint32_t mmap_length;
|
||||||
multiboot_uint32_t mmap_addr;
|
multiboot_uint32_t mmap_addr;
|
||||||
|
|
||||||
/* Drive Info buffer */
|
/* Drive Info buffer */
|
||||||
multiboot_uint32_t drives_length;
|
multiboot_uint32_t drives_length;
|
||||||
multiboot_uint32_t drives_addr;
|
multiboot_uint32_t drives_addr;
|
||||||
|
|
||||||
/* ROM configuration table */
|
/* ROM configuration table */
|
||||||
multiboot_uint32_t config_table;
|
multiboot_uint32_t config_table;
|
||||||
|
|
||||||
/* Boot Loader Name */
|
/* Boot Loader Name */
|
||||||
multiboot_uint32_t boot_loader_name;
|
multiboot_uint32_t boot_loader_name;
|
||||||
|
|
||||||
/* APM table */
|
/* APM table */
|
||||||
multiboot_uint32_t apm_table;
|
multiboot_uint32_t apm_table;
|
||||||
|
|
||||||
/* Video */
|
/* Video */
|
||||||
multiboot_uint32_t vbe_control_info;
|
multiboot_uint32_t vbe_control_info;
|
||||||
multiboot_uint32_t vbe_mode_info;
|
multiboot_uint32_t vbe_mode_info;
|
||||||
multiboot_uint16_t vbe_mode;
|
multiboot_uint16_t vbe_mode;
|
||||||
multiboot_uint16_t vbe_interface_seg;
|
multiboot_uint16_t vbe_interface_seg;
|
||||||
multiboot_uint16_t vbe_interface_off;
|
multiboot_uint16_t vbe_interface_off;
|
||||||
multiboot_uint16_t vbe_interface_len;
|
multiboot_uint16_t vbe_interface_len;
|
||||||
|
|
||||||
multiboot_uint64_t framebuffer_addr;
|
multiboot_uint64_t framebuffer_addr;
|
||||||
multiboot_uint32_t framebuffer_pitch;
|
multiboot_uint32_t framebuffer_pitch;
|
||||||
multiboot_uint32_t framebuffer_width;
|
multiboot_uint32_t framebuffer_width;
|
||||||
multiboot_uint32_t framebuffer_height;
|
multiboot_uint32_t framebuffer_height;
|
||||||
multiboot_uint8_t framebuffer_bpp;
|
multiboot_uint8_t framebuffer_bpp;
|
||||||
#define MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED 0
|
#define MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED 0
|
||||||
#define MULTIBOOT_FRAMEBUFFER_TYPE_RGB 1
|
#define MULTIBOOT_FRAMEBUFFER_TYPE_RGB 1
|
||||||
#define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT 2
|
#define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT 2
|
||||||
multiboot_uint8_t framebuffer_type;
|
multiboot_uint8_t framebuffer_type;
|
||||||
union
|
union {
|
||||||
{
|
struct {
|
||||||
struct
|
multiboot_uint32_t framebuffer_palette_addr;
|
||||||
{
|
multiboot_uint16_t framebuffer_palette_num_colors;
|
||||||
multiboot_uint32_t framebuffer_palette_addr;
|
};
|
||||||
multiboot_uint16_t framebuffer_palette_num_colors;
|
struct {
|
||||||
|
multiboot_uint8_t framebuffer_red_field_position;
|
||||||
|
multiboot_uint8_t framebuffer_red_mask_size;
|
||||||
|
multiboot_uint8_t framebuffer_green_field_position;
|
||||||
|
multiboot_uint8_t framebuffer_green_mask_size;
|
||||||
|
multiboot_uint8_t framebuffer_blue_field_position;
|
||||||
|
multiboot_uint8_t framebuffer_blue_mask_size;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
struct
|
|
||||||
{
|
|
||||||
multiboot_uint8_t framebuffer_red_field_position;
|
|
||||||
multiboot_uint8_t framebuffer_red_mask_size;
|
|
||||||
multiboot_uint8_t framebuffer_green_field_position;
|
|
||||||
multiboot_uint8_t framebuffer_green_mask_size;
|
|
||||||
multiboot_uint8_t framebuffer_blue_field_position;
|
|
||||||
multiboot_uint8_t framebuffer_blue_mask_size;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
typedef struct multiboot_info multiboot_info_t;
|
typedef struct multiboot_info multiboot_info_t;
|
||||||
|
|
||||||
struct multiboot_color
|
struct multiboot_color {
|
||||||
{
|
multiboot_uint8_t red;
|
||||||
multiboot_uint8_t red;
|
multiboot_uint8_t green;
|
||||||
multiboot_uint8_t green;
|
multiboot_uint8_t blue;
|
||||||
multiboot_uint8_t blue;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct multiboot_mmap_entry
|
struct multiboot_mmap_entry {
|
||||||
{
|
multiboot_uint32_t size;
|
||||||
multiboot_uint32_t size;
|
multiboot_uint64_t addr;
|
||||||
multiboot_uint64_t addr;
|
multiboot_uint64_t len;
|
||||||
multiboot_uint64_t len;
|
#define MULTIBOOT_MEMORY_AVAILABLE 1
|
||||||
#define MULTIBOOT_MEMORY_AVAILABLE 1
|
#define MULTIBOOT_MEMORY_RESERVED 2
|
||||||
#define MULTIBOOT_MEMORY_RESERVED 2
|
#define MULTIBOOT_MEMORY_ACPI_RECLAIMABLE 3
|
||||||
#define MULTIBOOT_MEMORY_ACPI_RECLAIMABLE 3
|
#define MULTIBOOT_MEMORY_NVS 4
|
||||||
#define MULTIBOOT_MEMORY_NVS 4
|
#define MULTIBOOT_MEMORY_BADRAM 5
|
||||||
#define MULTIBOOT_MEMORY_BADRAM 5
|
multiboot_uint32_t type;
|
||||||
multiboot_uint32_t type;
|
|
||||||
} GRUB_PACKED;
|
} GRUB_PACKED;
|
||||||
typedef struct multiboot_mmap_entry multiboot_memory_map_t;
|
typedef struct multiboot_mmap_entry multiboot_memory_map_t;
|
||||||
|
|
||||||
struct multiboot_mod_list
|
struct multiboot_mod_list {
|
||||||
{
|
/* the memory used goes from bytes 'mod_start' to 'mod_end-1' inclusive */
|
||||||
/* the memory used goes from bytes 'mod_start' to 'mod_end-1' inclusive */
|
multiboot_uint32_t mod_start;
|
||||||
multiboot_uint32_t mod_start;
|
multiboot_uint32_t mod_end;
|
||||||
multiboot_uint32_t mod_end;
|
|
||||||
|
|
||||||
/* Module command line */
|
/* Module command line */
|
||||||
multiboot_uint32_t cmdline;
|
multiboot_uint32_t cmdline;
|
||||||
|
|
||||||
/* padding to take it to 16 bytes (must be zero) */
|
/* padding to take it to 16 bytes (must be zero) */
|
||||||
multiboot_uint32_t pad;
|
multiboot_uint32_t pad;
|
||||||
};
|
};
|
||||||
typedef struct multiboot_mod_list multiboot_module_t;
|
typedef struct multiboot_mod_list multiboot_module_t;
|
||||||
|
|
||||||
/* APM BIOS info. */
|
/* APM BIOS info. */
|
||||||
struct multiboot_apm_info
|
struct multiboot_apm_info {
|
||||||
{
|
grub_uint16_t version;
|
||||||
grub_uint16_t version;
|
grub_uint16_t cseg;
|
||||||
grub_uint16_t cseg;
|
grub_uint32_t offset;
|
||||||
grub_uint32_t offset;
|
grub_uint16_t cseg_16;
|
||||||
grub_uint16_t cseg_16;
|
grub_uint16_t dseg;
|
||||||
grub_uint16_t dseg;
|
grub_uint16_t flags;
|
||||||
grub_uint16_t flags;
|
grub_uint16_t cseg_len;
|
||||||
grub_uint16_t cseg_len;
|
grub_uint16_t cseg_16_len;
|
||||||
grub_uint16_t cseg_16_len;
|
grub_uint16_t dseg_len;
|
||||||
grub_uint16_t dseg_len;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* ! ASM_FILE */
|
#endif /* ! ASM_FILE */
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
#include <base.hpp>
|
|
||||||
#include "../../../hw/pc/cgaterm/cgaterm.hpp"
|
#include "../../../hw/pc/cgaterm/cgaterm.hpp"
|
||||||
|
#include <base.hpp>
|
||||||
CGATerm term;
|
CGATerm term;
|
||||||
void main();
|
void main();
|
||||||
extern "C" void start() {
|
extern "C" void start() { main(); }
|
||||||
main();
|
|
||||||
}
|
|
||||||
void drivers_init() {
|
void drivers_init() {
|
||||||
setMainTTY(&term);
|
setMainTTY(&term);
|
||||||
--term;
|
--term;
|
||||||
|
|
|
@ -1,69 +1,36 @@
|
||||||
#include "cgaterm.hpp"
|
#include "cgaterm.hpp"
|
||||||
#include "cp437.hpp"
|
#include "cp437.hpp"
|
||||||
CGATerm::CGATerm(): TTY(80, 25) {}
|
CGATerm::CGATerm() : TTY(80, 25) {}
|
||||||
CGATerm::~CGATerm() {}
|
CGATerm::~CGATerm() {}
|
||||||
auto CGATerm::rgbSupport() -> bool {return false;}
|
auto CGATerm::rgbSupport() -> bool { return false; }
|
||||||
struct ScreenChar {
|
struct ScreenChar {
|
||||||
unsigned char ch;
|
unsigned char ch;
|
||||||
char fgcolor:4;
|
char fgcolor : 4;
|
||||||
char bgcolor:4;
|
char bgcolor : 4;
|
||||||
}__attribute__((packed));
|
} __attribute__((packed));
|
||||||
ScreenChar *scr = (ScreenChar*)0xB8000;
|
ScreenChar *scr = (ScreenChar *)0xB8000;
|
||||||
auto CGATerm::plotChar(int x, int y, int c) -> void {
|
auto CGATerm::plotChar(int x, int y, int c) -> void {
|
||||||
char ch = unicodeToCP437(c);
|
char ch = unicodeToCP437(c);
|
||||||
scr[y*80+x].ch = ch;
|
scr[y * 80 + x].ch = ch;
|
||||||
scr[y*80+x].bgcolor = 0;
|
scr[y * 80 + x].bgcolor = 0;
|
||||||
char col = 0;
|
char col = 0;
|
||||||
switch(curColor) {
|
switch (curColor) {
|
||||||
case Color::BLACK:
|
case Color::BLACK: col = 0; break;
|
||||||
col = 0;
|
case Color::BLUE: col = 1; break;
|
||||||
break;
|
case Color::GREEN: col = 2; break;
|
||||||
case Color::BLUE:
|
case Color::CYAN: col = 3; break;
|
||||||
col = 1;
|
case Color::RED: col = 4; break;
|
||||||
break;
|
case Color::MAGENTA: col = 5; break;
|
||||||
case Color::GREEN:
|
case Color::BROWN: col = 6; break;
|
||||||
col = 2;
|
case Color::LIGHT_GRAY: col = 7; break;
|
||||||
break;
|
case Color::GRAY: col = 8; break;
|
||||||
case Color::CYAN:
|
case Color::LIGHT_BLUE: col = 9; break;
|
||||||
col = 3;
|
case Color::LIGHT_GREEN: col = 10; break;
|
||||||
break;
|
case Color::LIGHT_CYAN: col = 11; break;
|
||||||
case Color::RED:
|
case Color::LIGHT_RED: col = 12; break;
|
||||||
col = 4;
|
case Color::LIGHT_MAGENTA: col = 13; break;
|
||||||
break;
|
case Color::YELLOW: col = 14; break;
|
||||||
case Color::MAGENTA:
|
case Color::WHITE: col = 15; break;
|
||||||
col = 5;
|
|
||||||
break;
|
|
||||||
case Color::BROWN:
|
|
||||||
col = 6;
|
|
||||||
break;
|
|
||||||
case Color::LIGHT_GRAY:
|
|
||||||
col = 7;
|
|
||||||
break;
|
|
||||||
case Color::GRAY:
|
|
||||||
col = 8;
|
|
||||||
break;
|
|
||||||
case Color::LIGHT_BLUE:
|
|
||||||
col = 9;
|
|
||||||
break;
|
|
||||||
case Color::LIGHT_GREEN:
|
|
||||||
col = 10;
|
|
||||||
break;
|
|
||||||
case Color::LIGHT_CYAN:
|
|
||||||
col = 11;
|
|
||||||
break;
|
|
||||||
case Color::LIGHT_RED:
|
|
||||||
col = 12;
|
|
||||||
break;
|
|
||||||
case Color::LIGHT_MAGENTA:
|
|
||||||
col = 13;
|
|
||||||
break;
|
|
||||||
case Color::YELLOW:
|
|
||||||
col = 14;
|
|
||||||
break;
|
|
||||||
case Color::WHITE:
|
|
||||||
col = 15;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
scr[y*80+x].fgcolor = col;
|
scr[y * 80 + x].fgcolor = col;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <tty.hpp>
|
#include <tty.hpp>
|
||||||
class CGATerm: public TTY {
|
class CGATerm : public TTY {
|
||||||
protected:
|
protected:
|
||||||
virtual auto plotChar(int x, int y, int c) -> void;
|
virtual auto plotChar(int x, int y, int c) -> void;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CGATerm();
|
CGATerm();
|
||||||
virtual ~CGATerm();
|
virtual ~CGATerm();
|
||||||
virtual auto rgbSupport() -> bool;
|
virtual auto rgbSupport() -> bool;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,10 +1,21 @@
|
||||||
int tbl[] = {0, 9786, 9787, 9829, 9830, 9827, 9824, 8226, 9688, 9675, 9689, 9794, 9792, 9834, 9835, 9788, 9658, 9668, 8597, 8252, 182, 167, 9644, 8616, 8593, 8595, 8594, 8592, 8735, 8596, 9652, 9660, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 8962, 199, 252, 233, 226, 228, 224, 229, 231, 234, 235, 232, 239, 238, 236, 196, 197, 201, 230, 198, 244, 246, 242, 251, 249, 255, 214, 220, 162, 163, 165, 8359, 402, 225, 237, 243, 250, 241, 209, 170, 186, 191, 8976, 172, 189, 188, 161, 171, 187, 9617, 9618, 9619, 9474, 9508, 9569, 9570, 9558, 9557, 9571, 9553, 9559, 9565, 9564, 9563, 9488, 9492, 9524, 9516, 9500, 9472, 9532, 9566, 9567, 9562, 9556, 9577, 9574, 9568, 9552, 9580, 9575, 9576, 9572, 9573, 9561, 9560, 9554, 9555, 9579, 9578, 9496, 9484, 9608, 9604, 9612, 9616, 9600, 945, 223, 915, 960, 931, 963, 181, 964, 934, 920, 937, 948, 8734, 966, 949, 8745, 8801, 177, 8805, 8804, 8992, 8993, 247, 8776, 176, 8729, 183, 8730, 8319, 178, 9632, 160};
|
int tbl[] = {0, 9786, 9787, 9829, 9830, 9827, 9824, 8226, 9688, 9675, 9689, 9794, 9792, 9834, 9835, 9788, 9658, 9668,
|
||||||
|
8597, 8252, 182, 167, 9644, 8616, 8593, 8595, 8594, 8592, 8735, 8596, 9652, 9660, 32, 33, 34, 35,
|
||||||
|
36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
|
||||||
|
54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
|
||||||
|
72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
|
||||||
|
90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107,
|
||||||
|
108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125,
|
||||||
|
126, 8962, 199, 252, 233, 226, 228, 224, 229, 231, 234, 235, 232, 239, 238, 236, 196, 197,
|
||||||
|
201, 230, 198, 244, 246, 242, 251, 249, 255, 214, 220, 162, 163, 165, 8359, 402, 225, 237,
|
||||||
|
243, 250, 241, 209, 170, 186, 191, 8976, 172, 189, 188, 161, 171, 187, 9617, 9618, 9619, 9474,
|
||||||
|
9508, 9569, 9570, 9558, 9557, 9571, 9553, 9559, 9565, 9564, 9563, 9488, 9492, 9524, 9516, 9500, 9472, 9532,
|
||||||
|
9566, 9567, 9562, 9556, 9577, 9574, 9568, 9552, 9580, 9575, 9576, 9572, 9573, 9561, 9560, 9554, 9555, 9579,
|
||||||
|
9578, 9496, 9484, 9608, 9604, 9612, 9616, 9600, 945, 223, 915, 960, 931, 963, 181, 964, 934, 920,
|
||||||
|
937, 948, 8734, 966, 949, 8745, 8801, 177, 8805, 8804, 8992, 8993, 247, 8776, 176, 8729, 183, 8730,
|
||||||
|
8319, 178, 9632, 160};
|
||||||
char unicodeToCP437(int c) {
|
char unicodeToCP437(int c) {
|
||||||
for(int i=0; i<256; i++)
|
for (int i = 0; i < 256; i++)
|
||||||
if(tbl[i]==c)
|
if (tbl[i] == c) return (char)i;
|
||||||
return (char)i;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int CP437ToUnicode(char c) {
|
int CP437ToUnicode(char c) { return tbl[(unsigned char)c]; }
|
||||||
return tbl[(unsigned char)c];
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,20 +1,15 @@
|
||||||
#include <stdint.h>
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
extern "C" void __cxa_pure_virtual() {
|
extern "C" void __cxa_pure_virtual() {
|
||||||
//panic("Pure virtual function called.");
|
// panic("Pure virtual function called.");
|
||||||
}
|
}
|
||||||
void * operator new(size_t s) {
|
void *operator new(size_t s) { return (void *)1; }
|
||||||
return (void*)1;
|
void *operator new[](size_t s) { return (void *)1; }
|
||||||
}
|
void operator delete(void *p) {}
|
||||||
void * operator new[](size_t s) {
|
void operator delete[](void *p) {}
|
||||||
return (void*)1;
|
void operator delete(void *p, size_t s) {}
|
||||||
}
|
void operator delete[](void *p, size_t s) {}
|
||||||
void operator delete(void* p) {}
|
void *operator new(size_t s, void *p) { return p; }
|
||||||
void operator delete[](void* p) {}
|
void *operator new[](size_t s, void *p) { return p; }
|
||||||
void operator delete(void* p, size_t s) {}
|
|
||||||
void operator delete[](void* p, size_t s) {}
|
|
||||||
void * operator new(size_t s, void* p) {return p;}
|
|
||||||
void * operator new[](size_t s, void* p) {return p;}
|
|
||||||
void operator delete(void *, void *p) {}
|
void operator delete(void *, void *p) {}
|
||||||
void operator delete[](void *, void *p) {}
|
void operator delete[](void *, void *p) {}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <tty.hpp>
|
|
||||||
#include <kobject.hpp>
|
#include <kobject.hpp>
|
||||||
|
#include <tty.hpp>
|
||||||
extern TTY *out;
|
extern TTY *out;
|
||||||
void setMainTTY(Kobject *obj);
|
void setMainTTY(Kobject *obj);
|
||||||
|
|
|
@ -1,75 +1,75 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
enum class kobjectType {
|
enum class kobjectType {
|
||||||
POINTER, //Pointer to non-object
|
POINTER, // Pointer to non-object
|
||||||
KOBJECT, //garbage collected kobject
|
KOBJECT, // garbage collected kobject
|
||||||
TTY,
|
TTY,
|
||||||
};
|
};
|
||||||
class Kref {
|
class Kref {
|
||||||
public:
|
public:
|
||||||
kobjectType type;
|
kobjectType type;
|
||||||
void *ptr;
|
void *ptr;
|
||||||
unsigned int refctr;
|
unsigned int refctr;
|
||||||
bool mset;
|
bool mset;
|
||||||
Kref(kobjectType type) {
|
Kref(kobjectType type) {
|
||||||
this->type = type;
|
this->type = type;
|
||||||
refctr = 1;
|
refctr = 1;
|
||||||
|
mset = false;
|
||||||
|
}
|
||||||
|
template <typename T>
|
||||||
|
auto set(T *data) -> Kref & {
|
||||||
|
if (mset) return *this;
|
||||||
|
ptr = (void *)data;
|
||||||
|
mset = true;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
template <typename T>
|
||||||
|
T *get() {
|
||||||
|
return (T *)ptr;
|
||||||
|
}
|
||||||
|
auto operator++(int) -> Kref & {
|
||||||
|
unsigned int old = refctr;
|
||||||
|
refctr++;
|
||||||
|
if (old > refctr) {
|
||||||
|
// uh-oh this shouldn't happen
|
||||||
|
// Put panic() here, because this object could lead to kernel execution
|
||||||
|
// when the refctr overflows.
|
||||||
|
for (;;)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
auto operator--(int) -> Kref & {
|
||||||
|
refctr--;
|
||||||
|
if (!refctr) {
|
||||||
|
// delete ptr;
|
||||||
mset = false;
|
mset = false;
|
||||||
|
ptr = nullptr;
|
||||||
}
|
}
|
||||||
template<typename T>
|
return *this;
|
||||||
auto set(T *data) -> Kref & {
|
}
|
||||||
if(mset)
|
|
||||||
return *this;
|
|
||||||
ptr = (void*)data;
|
|
||||||
mset=true;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
template<typename T>
|
|
||||||
T *get() {
|
|
||||||
return (T*)ptr;
|
|
||||||
}
|
|
||||||
auto operator++(int) -> Kref & {
|
|
||||||
unsigned int old = refctr;
|
|
||||||
refctr++;
|
|
||||||
if(old > refctr) {
|
|
||||||
//uh-oh this shouldn't happen
|
|
||||||
//Put panic() here, because this object could lead to kernel execution when the refctr overflows.
|
|
||||||
for(;;);
|
|
||||||
}
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
auto operator--(int) -> Kref & {
|
|
||||||
refctr--;
|
|
||||||
if(!refctr) {
|
|
||||||
//delete ptr;
|
|
||||||
mset = false;
|
|
||||||
ptr = nullptr;
|
|
||||||
}
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
class Kobject {
|
class Kobject {
|
||||||
public:
|
public:
|
||||||
kobjectType type;
|
kobjectType type;
|
||||||
unsigned int refctr;
|
unsigned int refctr;
|
||||||
Kobject(kobjectType type):type(type),refctr(1) {}
|
Kobject(kobjectType type) : type(type), refctr(1) {}
|
||||||
virtual ~Kobject() {
|
virtual ~Kobject() { refctr = 0; }
|
||||||
refctr=0;
|
virtual auto operator++() -> Kobject & {
|
||||||
|
unsigned int tmp = refctr;
|
||||||
|
refctr++;
|
||||||
|
if (refctr < tmp) {
|
||||||
|
// TODO panic("Refcounter overflow");
|
||||||
|
for (;;)
|
||||||
|
;
|
||||||
}
|
}
|
||||||
virtual auto operator++() -> Kobject & {
|
return *this;
|
||||||
unsigned int tmp=refctr;
|
}
|
||||||
refctr++;
|
virtual auto operator--() -> Kobject & {
|
||||||
if(refctr < tmp) {
|
refctr--;
|
||||||
//TODO panic("Refcounter overflow");
|
if (refctr == 0) {
|
||||||
for(;;);
|
// TODO delete this;
|
||||||
}
|
return *((Kobject *)nullptr);
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
virtual auto operator--() -> Kobject & {
|
|
||||||
refctr--;
|
|
||||||
if(refctr == 0) {
|
|
||||||
//TODO delete this;
|
|
||||||
return *((Kobject*)nullptr);
|
|
||||||
}
|
|
||||||
return *this;
|
|
||||||
}
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -18,8 +18,8 @@ enum class Color {
|
||||||
YELLOW,
|
YELLOW,
|
||||||
WHITE
|
WHITE
|
||||||
};
|
};
|
||||||
class TTY: public Kobject {
|
class TTY : public Kobject {
|
||||||
protected:
|
protected:
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
int width;
|
int width;
|
||||||
|
@ -28,7 +28,8 @@ protected:
|
||||||
unsigned int rgbColor;
|
unsigned int rgbColor;
|
||||||
bool useRGB;
|
bool useRGB;
|
||||||
virtual auto plotChar(int x, int y, int c) -> void;
|
virtual auto plotChar(int x, int y, int c) -> void;
|
||||||
public:
|
|
||||||
|
public:
|
||||||
TTY(int width, int height);
|
TTY(int width, int height);
|
||||||
virtual ~TTY();
|
virtual ~TTY();
|
||||||
virtual auto rgbSupport() -> bool;
|
virtual auto rgbSupport() -> bool;
|
||||||
|
@ -36,26 +37,25 @@ public:
|
||||||
virtual auto setColor(unsigned int c) -> void;
|
virtual auto setColor(unsigned int c) -> void;
|
||||||
virtual auto putChar(int c) -> void;
|
virtual auto putChar(int c) -> void;
|
||||||
virtual auto puts(const char *s) -> void;
|
virtual auto puts(const char *s) -> void;
|
||||||
template<typename T>
|
template <typename T>
|
||||||
auto puti(T x) -> TTY & {
|
auto puti(T x) -> TTY & {
|
||||||
T output = x;
|
T output = x;
|
||||||
const char* chars="0123456789ABCDEF";
|
const char *chars = "0123456789ABCDEF";
|
||||||
char buf[sizeof(T)*8+1];
|
char buf[sizeof(T) * 8 + 1];
|
||||||
buf[sizeof(T)*8]='\0';
|
buf[sizeof(T) * 8] = '\0';
|
||||||
char* ptr=buf+sizeof(T)*8-1;
|
char *ptr = buf + sizeof(T) * 8 - 1;
|
||||||
do {
|
do {
|
||||||
*(ptr--)=chars[output&0xF];
|
*(ptr--) = chars[output & 0xF];
|
||||||
output>>=4;
|
output >>= 4;
|
||||||
} while(output && (ptr != buf));
|
} while (output && (ptr != buf));
|
||||||
puts(ptr+1);
|
puts(ptr + 1);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
template<typename T>
|
template <typename T>
|
||||||
auto operator<<(T x) -> TTY & {
|
auto operator<<(T x) -> TTY & {
|
||||||
puts(x);
|
puts(x);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
template <>
|
template <>
|
||||||
auto TTY::operator<<<int>(int) -> TTY &;
|
auto TTY::operator<<<int>(int) -> TTY &;
|
||||||
|
@ -63,4 +63,3 @@ template <>
|
||||||
auto TTY::operator<<<unsigned int>(unsigned int) -> TTY &;
|
auto TTY::operator<<<unsigned int>(unsigned int) -> TTY &;
|
||||||
template <>
|
template <>
|
||||||
auto TTY::operator<<<long long>(long long) -> TTY &;
|
auto TTY::operator<<<long long>(long long) -> TTY &;
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,12 @@
|
||||||
#include <base.hpp>
|
#include <base.hpp>
|
||||||
void drivers_init();
|
void drivers_init();
|
||||||
extern "C" void(*start_ctors)();
|
extern "C" void (*start_ctors)();
|
||||||
extern "C" void(*end_ctors)();
|
extern "C" void (*end_ctors)();
|
||||||
extern "C" void(*start_dtors)();
|
extern "C" void (*start_dtors)();
|
||||||
extern "C" void(*end_dtors)();
|
extern "C" void (*end_dtors)();
|
||||||
void main() {
|
void main() {
|
||||||
for(auto ctor=&start_ctors;ctor<&end_ctors;ctor++)
|
for (auto ctor = &start_ctors; ctor < &end_ctors; ctor++) (**ctor)();
|
||||||
(**ctor)();
|
|
||||||
drivers_init();
|
drivers_init();
|
||||||
*out << "Hallo!\n";
|
*out << "Hallo!\n";
|
||||||
for(auto dtor=&start_dtors;dtor!=&end_dtors;dtor++)
|
for (auto dtor = &start_dtors; dtor != &end_dtors; dtor++) (**dtor)();
|
||||||
(**dtor)();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,11 @@
|
||||||
TTY *out;
|
TTY *out;
|
||||||
bool tty_set = false;
|
bool tty_set = false;
|
||||||
void setMainTTY(Kobject *obj) {
|
void setMainTTY(Kobject *obj) {
|
||||||
if(obj->type == kobjectType::TTY) {
|
if (obj->type == kobjectType::TTY) {
|
||||||
++*obj;
|
++*obj;
|
||||||
// if(tty_set)
|
// if(tty_set)
|
||||||
// --*out;
|
// --*out;
|
||||||
out=(TTY*)obj;
|
out = (TTY *)obj;
|
||||||
tty_set=true;
|
tty_set = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,78 +1,73 @@
|
||||||
#include <tty.hpp>
|
#include <tty.hpp>
|
||||||
TTY::TTY(int width, int height): x(0), y(0), width(width), height(height), curColor(Color::WHITE), rgbColor(0xFFFFFF), useRGB(false), Kobject(kobjectType::TTY) {}
|
TTY::TTY(int width, int height)
|
||||||
|
: x(0), y(0), width(width), height(height), curColor(Color::WHITE), rgbColor(0xFFFFFF), useRGB(false),
|
||||||
|
Kobject(kobjectType::TTY) {}
|
||||||
TTY::~TTY() {}
|
TTY::~TTY() {}
|
||||||
auto TTY::plotChar(int x, int y, int c) -> void {}
|
auto TTY::plotChar(int x, int y, int c) -> void {}
|
||||||
auto TTY::rgbSupport() -> bool {return true;}
|
auto TTY::rgbSupport() -> bool { return true; }
|
||||||
auto TTY::setColor(Color c) -> void {
|
auto TTY::setColor(Color c) -> void {
|
||||||
curColor = c;
|
curColor = c;
|
||||||
useRGB=false;
|
useRGB = false;
|
||||||
}
|
}
|
||||||
auto TTY::setColor(unsigned int c) -> void {
|
auto TTY::setColor(unsigned int c) -> void {
|
||||||
rgbColor = c;
|
rgbColor = c;
|
||||||
useRGB=true;
|
useRGB = true;
|
||||||
}
|
}
|
||||||
auto TTY::putChar(int c) -> void {
|
auto TTY::putChar(int c) -> void {
|
||||||
auto scroll = [this]()->void {
|
auto scroll = [this]() -> void {
|
||||||
for(int x=0;x<this->width;x++)
|
for (int x = 0; x < this->width; x++)
|
||||||
for(int y=0;y<this->height;y++)
|
for (int y = 0; y < this->height; y++) this->plotChar(x, y, 0);
|
||||||
this->plotChar(x,y,0);
|
this->x = this->y = 0;
|
||||||
this->x=this->y=0;
|
|
||||||
};
|
};
|
||||||
switch(c) {
|
switch (c) {
|
||||||
case '\n':
|
case '\n':
|
||||||
x=0;
|
x = 0;
|
||||||
y++;
|
y++;
|
||||||
if(y>=height)
|
if (y >= height) scroll();
|
||||||
scroll();
|
break;
|
||||||
break;
|
default:
|
||||||
default:
|
plotChar(x, y, c);
|
||||||
plotChar(x,y,c);
|
x++;
|
||||||
x++;
|
if (x > width) y++;
|
||||||
if(x>width)
|
if (y >= height) scroll();
|
||||||
y++;
|
|
||||||
if(y>=height)
|
|
||||||
scroll();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
auto TTY::puts(const char *str) -> void {
|
auto TTY::puts(const char *str) -> void {
|
||||||
for(int i=0;str[i];i++) {
|
for (int i = 0; str[i]; i++) {
|
||||||
//Decode UTF-8
|
// Decode UTF-8
|
||||||
int character=0;
|
int character = 0;
|
||||||
if(str[i]<0x80) {
|
if (str[i] < 0x80) { character = str[i]; }
|
||||||
character=str[i];
|
// UTF-8 character
|
||||||
|
if ((str[i] & 0b11000000) == 0b10000000) {
|
||||||
|
character = 0xFFFD; // ILLEGAL SEQUENCE
|
||||||
}
|
}
|
||||||
//UTF-8 character
|
// Now count how many bytes follow
|
||||||
if((str[i]&0b11000000)==0b10000000) {
|
int bytesToFollow = 0;
|
||||||
character=0xFFFD; //ILLEGAL SEQUENCE
|
if ((str[i] & 0b11100000) == 0b11000000) {
|
||||||
}
|
bytesToFollow = 1;
|
||||||
//Now count how many bytes follow
|
character = str[i] & 0b11111;
|
||||||
int bytesToFollow=0;
|
} else if ((str[i] & 0b11110000) == 0b11100000) {
|
||||||
if((str[i]&0b11100000)==0b11000000) {
|
bytesToFollow = 2;
|
||||||
bytesToFollow=1;
|
character = str[i] & 0b1111;
|
||||||
character=str[i]&0b11111;
|
} else if ((str[i] & 0b11111000) == 0b11110000) {
|
||||||
} else if((str[i]&0b11110000)==0b11100000) {
|
bytesToFollow = 3;
|
||||||
bytesToFollow=2;
|
character = str[i] & 0b111;
|
||||||
character=str[i]&0b1111;
|
} else if (!character)
|
||||||
} else if((str[i]&0b11111000)==0b11110000) {
|
character = 0xFFFD; // ILLEGAL SEQUENCE
|
||||||
bytesToFollow=3;
|
while (bytesToFollow) {
|
||||||
character=str[i]&0b111;
|
|
||||||
} else if(!character)
|
|
||||||
character=0xFFFD; //ILLEGAL SEQUENCE
|
|
||||||
while(bytesToFollow) {
|
|
||||||
i++;
|
i++;
|
||||||
if(!str[i]) {
|
if (!str[i]) {
|
||||||
putChar(0xFFFD); //Incomplete
|
putChar(0xFFFD); // Incomplete
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if((str[i]&0b11000000)!=0b10000000) {
|
if ((str[i] & 0b11000000) != 0b10000000) {
|
||||||
putChar(0xFFFD); //ILLEGAL SEQUENCE
|
putChar(0xFFFD); // ILLEGAL SEQUENCE
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
character <<= 6;
|
character <<= 6;
|
||||||
character |= str[i] & 0b111111;
|
character |= str[i] & 0b111111;
|
||||||
bytesToFollow--;
|
bytesToFollow--;
|
||||||
}
|
}
|
||||||
if(!bytesToFollow)
|
if (!bytesToFollow) putChar(character);
|
||||||
putChar(character);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue