我在世界的巅峰吧 关注:34贴子:13,379
  • 13回复贴,共1

【考古日记第二弹】那些不为人知的过往

只看楼主收藏回复



IP属地:广东1楼2022-05-23 22:33回复
    With BIOS interrupt 13 AH = 00 we're ably to change the current screen resolution (See below). Al (hex) video mode
    0
    1
    2
    3
    4
    5
    6
    7
    ...
    F
    10
    11
    12
    text 40 x 25 16 grey
    text 40 x 25 16 color
    text 80 x 25 16 grey
    text 80 x 25 16 color
    graph (CGA) 320 x 200 color
    graph (CGA) 320 x 200 black / white
    graph (CGA) 640 x 200 black / white
    text 80 x 25 black / white (MDA, Hercules)
    ...
    graph (EGA,VGA) 640x350 grey
    graph (EGA,VGA) 640x350 16 colors
    graph (VGA) 2 colors
    graph (VGA) 16 colors
    In the next paragraphs we'll discuss meanly the standard VGA resolution (12h) These days most VGA-boards has "Super VGA" resolutions, in the next table you'll find the information to change to a "VESA Super VGA"
    然后我们来做个小实验
    第一个文件:
    .MODEL SMALL
    .CODE
    start:
    mov ax,12h ;VGA mode
    int 10h ;640 x 480 16 colors.
    mov ax,0A000h
    mov es,ax ;ES points to the video memory.
    mov dx,03C4h ;dx = indexregister
    mov ax,0F02h ;INDEX = MASK MAP,
    out dx,ax ;write all the bitplanes.
    mov di,0 ;DI pointer in the video memory.
    mov cx,38400 ;(640 * 480)/8 = 38400
    mov ax,0AAh ;write to every pixel.
    rep stosb ;fill the screen
    mov ax,4c00h ;go back
    int 21h ; to DOS.
    END start
    目的是在vga 的 16色模式下填满屏幕
    第二个小程序
    是在屏幕中写一行字
    “汇编语言(第三版)王爽著(实验十)编写子程序”
    第三个小程序很短
    .MODEL SMALL
    .CODE
    start:
    mov ax,3h ;
    int 10h ;
    mov ax,4c00h ;go back
    int 21h ; to DOS.
    END start
    切回文字模式
    那么测试结果:
    dosxbox默认可以运行2.
    当运行了1以后,屏幕切了模式,无法运行2,显示字。这时候再运行3,再运行2,就可以显示了。


    IP属地:广东4楼2022-05-24 00:25
    回复
      2025-06-07 04:32:36
      广告
      从上面可知dos默认运行在text模式下。
      那么问题来了:
      在没有dos的时候,没有BIOS的时候,机器刚通电的时候,显卡是默认在什么模式下呢?


      IP属地:广东5楼2022-05-24 00:26
      收起回复
        那么,我决定追根溯源,从底层的底层的底层,一直到底无可底,探寻显卡的秘密。
        在osdever上,我们知道了,VGA显卡,它是Miscellaneous Graphics Register这个寄存器来决定如何翻译显存段映射到内存段的数据的。基本模式就4个:
        00 -- A0000h-BFFFFh -- 128K
        01 -- A0000h-AFFFFh -- 64K
        10 -- B0000h-B7FFFh -- 32K
        11 -- B8000h-BFFFFh -- 32K
        CPU从端口3CEh(地址端口) 3CFh(数据端口)访问这个寄存器。


        IP属地:广东7楼2022-05-24 01:08
        回复
          首先我们来写一个程序
          .MODEL SMALL
          .CODE
          start:
          mov dx, 3ceh
          mov al,06h
          out dx,al
          mov dx, 3CFh
          in bl,dx
          mov ax,4c00h ;go back
          int 21h ; to DOS.
          END start

          读出寄存器的值,就知道这个映射了。
          经过我苦苦搜索,已经确认的信息有:
          B0000H这段是早期monochrome text mode
          IBM Monochrome Display Adapter 简称MDA卡的。
          然后我们再切模式,读寄存器


          IP属地:广东8楼2022-05-24 01:56
          回复

            这是刚进入DOSBOX,应该是文字模式,读出来的值是0E,对应的二进制为1110,符合;
            图像模式,读出来是00,符合。

            手动切换回文字模式,又回到了1110,符合

            最后是重头戏
            INT10的7号模式text 80 x 25 black / white (MDA, Hercules),对应的就是这个古老的IBM MDA,我们看看效果哈。

            现在这值是0A,二进制是1010!正好对应了这个古兼容模式


            IP属地:广东9楼2022-05-24 02:01
            回复
              现在修改一下之前的程序,让他往我们这个老MDA段写数据,看他能认出来吗?
              答案是可以!而且变成单色了,说明实验成功

              来我们看看原来的样子

              这段代码在我修改到07H模式后是不能用的了!


              IP属地:广东10楼2022-05-24 02:06
              回复
                被抽的2 3楼参考文献:
                3楼:
                以这三段索引,查到一篇文章,
                为什么显卡在内存中的映射是0b8000H?
                在回答中找到VGA的标准的网站,找到了这个地方
                osdever
                Accessing the VGA Display Memory -- details on the memory interface between the CPU and VGA frame buffer.
                还有一段是Hardware Level VGA and SVGA Video Programming InformationPage
                2楼是VGA的wiki


                IP属地:广东11楼2022-05-24 02:09
                回复
                  2025-06-07 04:26:36
                  广告
                  是否需要加精


                  IP属地:广东13楼2022-05-24 23:18
                  回复
                    这段话也只有我自己猜看得见


                    IP属地:广东14楼2022-05-25 17:27
                    收起回复