在命令提示符下重画字符 [英] redrawing characters in command prompt

查看:97
本文介绍了在命令提示符下重画字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

k,听起来听起来很傻,但是请耐心等待一秒钟.我在这里寻找的是某些功能或怪异的方法,可在dos提示下快速在屏幕上重新绘制字符.我打算为我的高中计算机信息科学课制作一个愚蠢的小ascii游戏,其中我们有一台使用dos 7.0格式化的计算机,但我遇到了这个小问题.我想立即重绘文本,有点像x每秒直接绘制60帧的方式,但仅仅是重绘文本.在这么低的分辨率下,我认为它应该非常简单,但是当我执行这样的操作时,它会令人讨厌!

k, this is gonna sound pretty silly, but just bear with me for a sec. what i''m looking for here is some function, or weird method, of rapidly redrawing the characters on the screen in a dos prompt. I intend to make a silly little ascii game for my high school computer information science class where we have a computer formated with dos 7.0, and i ran into this little problem. i would like to redraw the text instantly, kinda like how direct x draws 60 frames per second, but simply with redrawing text. at such a low resolution, i assume it should be very simple, but when i do something like this, it''s nasty blinky!

while(1)
{
    cout << "test string here";
    system("cls");
}



旧的软件不能使计算机成为旧的硬件,为什么图形适配器不能跟上这么简单的事情?所以我想我的问题是,有没有办法更快地重新粉刷?或绕过所说的眨眼,有一种方法可以只在屏幕上重绘单个字符,例如,如果有人按下向右箭头,并且只有屏幕中间的x会将一个字符空间移至固定位置,我不必重新绘制整个屏幕,只需重新绘制x?

顺便说一句,我还没有为dos专门编写程序,我只是为Windows中的命令提示符编写程序.



an old software doesn''t make the computer old hardware, why is the graphics adapter not able to keep up with something so simple? So i guess my question is, is there a way to repaint it more rapidly? or as a bypass to said blinkiness, is there a way to redraw only individual characters on the screen so that, say, if a person hits the right arrow, and only the x in the middle of the screen moves one character space to the rigth, i don''t have to redraw the entire screen, just redraw that x?

btw, i''m not writing the program specifically for dos yet, i''m just writing it for the command prompt in windows.

推荐答案

没有人做在DOS上这样的事情!

取而代之的是,人们将直接进入视频卡RAM,根据卡的类型找出文本屏幕缓冲区的地址,然后直接对其进行写入.甚至不要玩弄使用控制台的想法-它不是为此类事情而设计的.现在,彩色模式文本屏幕的缓冲区由一对字节组成:一个字节是要输出的字符,另一个字节是背景色和前景色,一个半字节是前景色,另一个半字节是背景,所以您有16种颜色用于前景,16用于背景.我希望我没记错.

因此,您有一个16位字的数组,可以按任意顺序编写.水平线通常为80个字符,因此您可以像排列2的数组那样对数组进行寻址.更改数组中的任何字节都会更改屏幕上任何位置的输出.

这很容易.我们甚至曾经使用伪图形字符在屏幕上绘制各种图片.您还可以修改文本模式的字体,这些字体也存储在视频卡RAM中.这样,您可以绘制非常类似于图形(像素级)模式的非常特殊的图形.

最后,还有另一个技巧:动态重新加载某些字符的字体.它以非常流畅的方式运行,因此有一个流行的程序可以在像素级别(纯文本模式!)中处理鼠标光标.通过读取鼠标位置周围的缓冲字符,动态修改这些字符的字符字节和字体的位图来完成此操作.

还有什么?是的,当监视器将电子束从按钮右像素的位置移至左上角像素的位置时,在电子束对角运动时,视频卡会触发硬件中断.人们在此IRQ上安装中断处理程序以触发视频卡缓冲区中的更改.这类似于双重缓冲":代替昂贵的双重缓冲,当图像更新暂停到电子束向后移动时,所有更改都被写入卡中.



对于基本的参考资料,请使用以下内容: http://en.wikipedia.org/wiki/VGA_compatible_text_mode [ ^ ].当您学习术语但错过了一些信息时,请使用基本术语和概念在Web上搜索更多详细信息.

这是键盘中断用法的参考: http://webpages.charter.net/danrollins/techhelp/0106. HTM [ ^ ].看整个网站,看起来很有希望.

—SA
Nobody did such things on DOS!

Instead, people would go directly to video card RAM, figure out the address of text screen buffer, depending on card type, and would write directly to it. Don''t even play with the idea of using console -- it is not designed for such things. Now, the buffer of color mode text screen consists of pair of bytes: one byte is the character to output, another one is background and foreground color, one half-byte for foreground, another half-byte for background, so you have 16 colors for foreground and 16 for background. I hope I remember this correctly.

Therefore, you have an array of 16-bit words which you can write in arbitrary order. The horizontal line is usually 80 characters, so you can address the array like an array of rank 2. Changing any byte in the array changes output in any position on screen.

This is easy enough. We even used to draw all kind of pictures on screen, using pseudo-graphics characters. You also can modify fonts for text mode which are also stored in the video card RAM. This way, you can draw a very special graphics which looks almost like graphical (pixel-level) mode.

Finally, there is one more trick: reloading font for some characters dynamically. It runs in a very smooth way, so there were a popular programs addressing a mouse cursor on a pixel level (in a pure text mode!). It was done via reading of the buffer characters around mouse location, modifying character bytes and bitmap of the font for these characters dynamically.

What else? Yes, you can get a hardware interrupt triggered by the video card at the moment of diagonal motion of the electron beam when the monitor moves the beam from the position of button right pixel to the position of top left one. People install interrupt handler on this IRQ to trigger changes in the video card buffer. This is an analog of "double buffering": instead of costly double buffering, all changes were written to the card when the image update was paused to the back move of the electron beam.



For rudimentary reference material, use this: http://en.wikipedia.org/wiki/VGA_compatible_text_mode[^]. When you learn terminology but miss some information, search fore more detail in the Web using basic terms and concepts.

And here is the reference for keyboard interrupt usage: http://webpages.charter.net/danrollins/techhelp/0106.HTM[^]. Look at the whole site, it looks promising.

—SA


这篇关于在命令提示符下重画字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆