linux - FreePascal 控制台视频行和列

标签 linux windows console screen freepascal

我正在寻找一种方法来获取 FPC 下控制台视频的行数和列数。我正在寻找最便携的方式,但至少可以在 Windows 下(最好也在 Linux 下)工作。

从旧的 Turbo Pascal 时代开始,我写了下面的函数,但它们不能在 FPC 下编译,而且在汇编器中它们不是很可移植。

//Return the number of video rows
function GetVideoY: Byte; assembler;
asm
  mov     ax,$40
  mov     es,ax
  mov     al,es:$84
  inc     al
end; { GetVideoY }

//Return the number of video columns
function GetVideoX: Byte; assembler;
asm
  mov     ax,$40
  mov     es,ax
  mov     al,es:$4A
end; { GetVideoX }

更新: 根据正确答案的建议,上述例程变为:

//Return the number of video rows
function GetVideoY: Byte;
begin
  GetVideoY := WindMaxY - WindMinY + 1;
end;

//Return the number of video columns
function GetVideoX: Byte;
begin
  GetVideoX := WindMaxX - WindMinX + 1;
end;

我在 Windows 和 Linux 上都试过了,它们似乎工作正常。谢谢。

最佳答案

从旧的 Turbo Pascal 时代开始,发生了很大变化的是从 ROM-BIOS 数据区域读取文本屏幕分辨率几乎只在准操作系统中才有意义,其中 Dan Rollins's TECH Help!绝对地址仍然存在,您的代码的 Free Pascal 转换看起来像

function GetVideoY: Byte;
begin
  GetVideoY := mem[$40:$84] + 1;
end;

function GetVideoX: Byte;
begin
  GetVideoX := mem[$40:$4a];
end;

在具有图形用户界面的操作系统下运行的控制台应用程序通常不直接与其他应用程序共享屏幕,也不使用 BIOS 视频调用在屏幕上绘图。相反,它们通常在虚拟化 API 后面运行。

Free Pascal 以 Crt 单元的形式为控制台应用程序提供了一个兼容性 API

Source: http://www.freepascal.org/docs-html/rtl/crt/index.html

..the CRT unit for Free Pascal, both under dos linux and Windows. The unit was first written for dos by Florian klaempfl. The unit was ported to linux by Mark May and enhanced by Michael Van Canneyt and Peter Vreman. It works on the linux console, and in xterm and rxvt windows under X-Windows. The functionality for both is the same..

您可以在

查看它的表面(可移植 API)

你可以看到里面有什么

当前屏幕分辨率的等效表达式应该是

WindMaxY - WindMinY + 1

WindMaxX - WindMinX + 1

并阅读有关 GotoXY 的文档可能是开始的好地方,在源代码文件中搜索文本 ScreenWidthScreenHeight 可以告诉您您可能想知道的任何其他信息

关于linux - FreePascal 控制台视频行和列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26776980/

相关文章:

c# - 捕捉事件窗口开关(也在同一个应用程序中,例如 Chrome 标签)

linux - Bash 多变量赋值

linux - 如何简化 bash 中的比较?

windows - 嵌套 for 循环,带有嵌套循环窗口批处理中使用的变量

c - 在有或没有 ncurses 的情况下,如何修改 linux 控制台中的键盘重复延迟

javascript - 将 javascript 表导出到 Excel 或控制台表

swift - 如何使用 Swift 在控制台应用程序上进行非阻塞键盘输入?

sql - 使用 MySQL 的 'KEY' 的重复条目 'PRIMARY'

C++ Shell 多管道不工作?

c# - C#中的文件大小监控