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} (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |