I am writing an operating system with C++ to learn (INCLUDING C) I learned a few functions such as printing to the screen, but I could not learn to receive input from the user and print to the screen. I looked at many sources, but I could not find what I wanted.What I want is to receive input from the user and print it on the screen and wait for a certain key to be pressed for an action. How can I do it?I will be glad if you can provide sample code.
loader.s
.set MAGIC, 0x1badb002.set FLAGS, (1<<0 | 1<<1).set CHECKSUM, -(MAGIC + FLAGS).section .multiboot .long MAGIC .long FLAGS .long CHECKSUM.section .text.extern kernelMain.extern callConstructors.global loaderloader: mov $kernel_stack, %esp call callConstructors push %eax push %ebx call kernelMain_stop: cli hlt jmp _stop.section .bss .space 2*1024*1024;kernel_stack:
kernel.cpp
#include "includes/types.h"#include "includes/functions.h"#include "includes/colors.h"#include "includes/keyboard.h"using namespace std;typedef void (*constructor)();extern "C" constructor* start_ctors;extern "C" constructor* end_ctors;extern "C" void callConstructors(){ for(constructor* i=start_ctors;i!=end_ctors;i++){ (*i)(); }}extern "C" void kernelMain(void* multiboot_structure, uint32_t magicnumber){ print(COLOR_RED, "Hello!"); while(1);}
functions.h
#include "keyboard.h"#include "colors.h"static unsigned short* VideoMemory=(unsigned short*)0xb8000;int pos_print = 0;void print_title( unsigned char colour, const char *string) { volatile unsigned char *vid = (unsigned char*) VideoMemory; while(*string != 0) { *(vid) = *string; *(vid+1) = colour;++string; vid+=2; }}void setChar(char character, short col, short row, unsigned char attr) { volatile unsigned char* vid_mem = (unsigned char *) VideoMemory; int offset = (row*80 + col)*2; vid_mem += offset; if(!attr) { attr = 0x0f; } *(unsigned short int *)vid_mem = (attr<<8)+character;}void print_line( unsigned char colour, const char *string, int pos ) { volatile unsigned char *vid = (unsigned char*) VideoMemory; vid+=pos*160; while(*string != 0) { *vid = *string; *(vid+1) = colour;++string; vid+=2; }}void print( unsigned char colour, char string ) { volatile unsigned char *vid = (unsigned char*) VideoMemory; pos_print+=1; vid+=pos_print*160; while(string != 0) { *vid = string; *(vid+1) = colour;++string; vid+=2; }}