微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

reactos操作系统实现(144)

当操作系统引导过程中,需要输出一些信息给用户来查看,那么就需要这个简单的VGA驱动程序,可以输出字符串显示,实现这个功能函数就是ViddisplayString函数,具体实现的代码如下:

#001 VOID

#002 NTAPI

#003 ViddisplayString(PUCHAR String)

#004 {

#005 ULONG TopDelta = 14;

#006

开始循环显示所有字符。

#007 /* Start looping the string */

#008 while (*String)

#009 {

如果遇到换行字符,就进入下面处理。

#010 /* Treat new-line separately */

#011 if (*String == '/n')

#012 {

修改显示向下移动一行。

#013 /* Modify Y position */

#014 curr_y += TopDelta;

判断是否需要滚动显示

#015 if (curr_y >= ScrollRegion[3])

#016 {

#017 /* Scroll the view */

#018 VgaScroll(TopDelta);

#019 curr_y -= TopDelta;

#020

#021 /* Preserve row */

#022 PreserveRow(curr_y,TopDelta,TRUE);

#023 }

#024

向下移动一行后,需要把X轴坐标清空为起始坐标,以便显示字符。

#025 /* Update current X */

#026 curr_x = ScrollRegion[0];

#027

#028 /* Preseve the current row */

#029 PreserveRow(curr_y,FALSE);

#030 }

如果遇到回车字符处理。

#031 else if (*String == '/r')

#032 {

回车的意思,就是把行坐标清空为0,从起点开始显示

#033 /* Update current X */

#034 curr_x = ScrollRegion[0];

#035

如果下一个字符没有换行符,也认为换行了。

#036 /* Check if we're being followed by a new line */

#037 if (String[1] != '/n') NextLine = TRUE;

#038 }

#039 else

#040 {

检查是否要换到下一行输出

#041 /* Check if we had a /n/r last time */

#042 if (NextLine)

#043 {

#044 /* We did,preserve the current row */

#045 PreserveRow(curr_y,TRUE);

#046 NextLine = FALSE;

#047 }

#048

在当前的位置显示一个字符。

#049 /* display this character */

#050 displayCharacter(*String,curr_x,curr_y,TextColor,16);

每个字符的宽度是8个像素。

#051 curr_x += 8;

#052

检查是否到了一行结尾,如果到了就需要换到下一行显示

#053 /* Check if we should scroll */

#054 if (curr_x > ScrollRegion[2])

#055 {

#056 /* Update Y position and check if we should scroll it */

#057 curr_y += TopDelta;

#058 if (curr_y > ScrollRegion[3])

#059 {

#060 /* Do the scroll */

#061 VgaScroll(TopDelta);

#062 curr_y -= TopDelta;

#063

#064 /* Save the row */

#065 PreserveRow(curr_y,TRUE);

#066 }

#067

#068 /* Update X */

#069 curr_x = ScrollRegion[0];

#070 }

#071 }

#072

处理下一个字符。

#073 /* Get the next character */

#074 String++;

#075 }

#076}

原文地址:https://www.jb51.cc/react/308379.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐