c++ - 如何使用 c/c++ 获取用户的输入(适用于操作系统)
问题描述
我正在用 C++ 编写操作系统来学习(包括 C)我学习了一些功能,例如打印到屏幕,但我无法学会接收用户的输入并打印到屏幕。我查看了很多资源,但找不到我想要的。我想要的是接收用户的输入并将其打印在屏幕上并等待某个键被按下以执行操作。我该怎么做?如果您能提供示例代码,我会很高兴。
加载器.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 loader
loader:
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:
内核.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);
}
函数.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;
}
}
解决方案
推荐阅读
- c - 如何访问其他模块中的全局变量?
- android - 我的 android 应用程序在颤振中没有从 release.apk 中的 api 获取数据,但在调试模式下工作
- python - 如何更改检测到对象边界框中的矩形颜色和字体颜色
- android - 使用 ImageButton 的弹出菜单
- r - 在使用 R 的 Summarize 函数中使用 mutate
- excel - 将带有扩展名的excel列表中的文件复制到其他文件夹
- c# - 将字典参数类型转换为对象
- javascript - 在 jquery 中编辑动态创建的 li 元素
- java - 无法使用 jdk 1.5 附加到 JVM
- c# - NET CORE 在发送大型 JSON 时没有“访问控制允许来源”