reactos操作系统实现(142)

 VidInitialize函数主要进行VGA简单视频显示模式初始化。具体实现代码如下:

#001  BOOLEAN

#002  NTAPI

#003  VidInitialize(IN BOOLEAN SetMode)

#004  {

#005      ULONG Context = 0;

#006      PHYSICAL_ADDRESS TranslatedAddress;

#007      PHYSICAL_ADDRESS NullAddress = {{0, 0}};

#008      ULONG AddressSpace = 1;

#009      BOOLEAN Result;

#010      ULONG_PTR Base;

#011 

#012      /* Make sure that we have a bus translation function */

 

确保已经初始化地址总线转换回调函数。

#013      if (!HalFindBusAddressTranslation) return FALSE;

#014 

#015      /* Get the VGA Register address */

 

获取VGA的寄存器地址。

#016      Result = HalFindBusAddressTranslation(NullAddress,

#017                                            &AddressSpace,

#018                                            &TranslatedAddress,

#019                                            &Context,

#020                                            TRUE);

#021      if (!Result) return FALSE;

#022 

 

检查是否需要映射I/O地址空间。

#023      /* See if this is I/O Space, which we need to map */

#024  TryAgain:

#025      if (!AddressSpace)

#026      {

#027          /* Map it */

#028          Base = (ULONG_PTR)MmMapIoSpace(TranslatedAddress, 0x400, MmNonCached);

#029      }

#030      else

#031      {

#032          /* The base is the translated address, no need to map I/O space */

#033          Base = TranslatedAddress.LowPart;

#034      }

#035 

#036      /* Set the VGA Register base and now check if we have a VGA device */

 

保存VGA的寄存器地址。

#037      VgaRegisterBase = Base;

 

调用函数VgaIsPresent来判断VGA显示卡是否安装。

#038      if (VgaIsPresent())

#039      {

 

转换VGA显示内存地址。

#040          /* Translate the VGA Memory Address */

#041          NullAddress.LowPart = 0xA0000;

#042          AddressSpace = 0;

#043          Result = HalFindBusAddressTranslation(NullAddress,

#044                                                &AddressSpace,

#045                                                &TranslatedAddress,

#046                                                &Context,

#047                                                FALSE);

#048          if (Result)

#049          {

#050              /* Success! See if this is I/O Space, which we need to map */

 

如果是I/O地址空间,就进行映射转换。

#051              if (!AddressSpace)

#052              {

#053                  /* Map it */

#054                  Base = (ULONG_PTR)MmMapIoSpace(TranslatedAddress,

#055                                                 0x20000,

#056                                                 MmNonCached);

#057              }

#058              else

#059              {

#060                  /* The base is the translated address, no need to map I/O space */

#061                  Base = TranslatedAddress.LowPart;

#062              }

#063 

 

设置VGA的内存基地址。

#064              /* Set the VGA Memory Base */

#065              VgaBase = Base;

#066 

 

是否需要显示图片模式。

#067              /* Now check if we have to set the mode */

#068              if (SetMode)

#069              {

 

复位显示。

#070                  /* Reset the display */

#071                  HalResetDisplay();

#072                  curr_x = 0;

#073                  curr_y = 0;

#074 

#075                  /* Initialize it */

 

初始化VGA显示。

#076                  VgaInterpretCmdStream(AT_Initialization);

#077                  return TRUE;

#078              }

#079          }

#080      }

#081      else

#082      {

#083          /* It's not, so unmap the I/O space if we mapped it */

#084          if (!AddressSpace) MmUnmapIoSpace((PVOID)VgaRegisterBase, 0x400);

#085      }

#086 

 

如果初始化失败,重新开始初始化。

#087      /* If we got here, then we failed...let's try again */

#088      Result = HalFindBusAddressTranslation(NullAddress,

#089                                            &AddressSpace,

#090                                            &TranslatedAddress,

#091                                            &Context,

#092                                            TRUE);

#093      if (Result) goto TryAgain;

#094 

 

运行到这里就表示初始化VGA显示卡失败。

#095      /* If we got here, then we failed even past our re-try... */

#096      return FALSE;

#097  }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

caimouse

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值