问题
Does an interrupt service routine exist to help me clear the screen of the terminal? Will it work on windows?
回答1:
Setting a graphics mode through BIOS (int 10h with AH=0) will clear the screen.
Scrolling the screen up or down through BIOS (int 10h with AH=6 or 7) can clear the screen as well.
This will only work where you can invoke BIOS service functions.
MSDOS is where this will always work.
In Windows this will work only in DOS applications and if Windows can actually run them. 64-bit editions of Windows don't support DOS applications at all and starting with Windows Vista even in 32-bit editions of Windows many DOS apps don't work fully.
Remember also that if a DOS application runs in a window in Windows, only that window will get cleared, not the entire screen.
回答2:
I got this to work (used qemu, NASM)
(http://www.gabrielececchetti.it/Teaching/CalcolatoriElettronici/Docs/i8086_and_DOS_interrupts.pdf)
call cls
jmp $
cls:
pusha
mov ah, 0x00
mov al, 0x03 ; text mode 80x25 16 colours
int 0x10
popa
ret
回答3:
For Windows console applications, in plain C:
#include <tchar.h>
#include <wincon.h>
VOID
ClearScreen(HANDLE hConsoleOutput)
{
CONSOLE_SCREEN_BUFFER_INFO csbi;
COORD coPos;
DWORD dwWritten;
GetConsoleScreenBufferInfo(hConsoleOutput, &csbi);
coPos.X = 0;
coPos.Y = 0;
FillConsoleOutputAttribute(hConsoleOutput, csbi.wAttributes,
csbi.dwSize.X * csbi.dwSize.Y,
coPos, &dwWritten);
FillConsoleOutputCharacter(hConsoleOutput, TEXT(' '),
csbi.dwSize.X * csbi.dwSize.Y,
coPos, &dwWritten);
SetConsoleCursorPosition(hConsoleOutput, coPos);
}
...
// In your main code:
/* Clear the full console screen */
ClearScreen(hOutput);
where the hConsoleOutput
is a HANDLE to a console screen-buffer (obtained either via GetStdHandle(STD_OUTPUT_HANDLE)
, or CreateConsoleScreenBuffer(...)
, or other means.
What this function does is to, first, retrieve the current console screen-buffer information (that contains its current size), then fill the complete screen-buffer with the default text attribute and with spaces, then finally place the cursor at (0,0).
回答4:
In assembly, try this:
mov ah, 0x06
mov al, 0
int 10h
And no, you cannot do this on windows. This code can only be used for bootloaders, and assembly kernels (16 bit only, WARNING: DO NOT TRY ON 32 BIT!!!)
If you'd like to do in Windows (Console Applications), then try this:
C++
//YOU SHOULD INCLUDE STDIO.H and CONIO.H. You should also type:
//using namespace std
system("cls");
VB.NET
//You should imports System and other Default namespaces
shell("cls")
C#
System.Diagnostics.Proccess.Start("CMD.exe /c cls");
NOTE: I don't think we can make Console apps using C# or VB. Of course, i never tried. Just saying. But these codes only work for windows.
来源:https://stackoverflow.com/questions/8239143/how-can-i-clear-the-screen-without-having-to-fill-it