我有一个包含一些内容的文本文件,我必须将光标从相对于 BOF 的位置移入,并使用 int 21h/42h 在屏幕上显示其内容。
这是我正在处理的代码。我在VM中使用Windows 98(16位DOS),它是我系统编程任务的一部分,所以我必须在带有DOSBox的Turbo c ++中尝试使用它,但它有一些问题。
在打印buff它显示随机值
代码
#include <stdio.h>
#include <conio.h>
#include <fcntl.h>
#include <bios.h>
#include <dos.h>
unsigned int handle;
char buff[50];
void main(){
union REGS regs; // set pointer
union REGS regs_r; // read file
handle = open("text.txt", O_RDONLY);
// set pointer to BOF (Begenning of File)
regs.x.bx = handle;
regs.h.ah = 0x42; // LSEEK
regs.h.al = 0x00 // Mode (0) BOF
regs.x.cx = 0;
regs.x.dx = 0;
int86(0x21, ®s, ®s);
// read the file
regs_r.x.bx = handle;
regs_r.x.cx = 0x07; Bytes to read ?
regs_r.h.ah = 0x3fh;
regs_r.x.dx = (unsigned int) buff; // buffer for data
int86(0x21, ®s_r, ®s_r);
printf("DATA : %c", buff);
getch();
clrscr();
}
这里有一些参考链接
任何帮助将不胜感激。