Clearing Console Window

P

phickman

Hi all.

After several searches using Google, I had just about given up on
finding a way to clear the console Window. After spending the past
week learning assembly language and writing a small boot loader for an
OS, I came across code to clear the console. It works. However, I post
it here to get opinions on using this. I have tested it in Windows but
not yet on Linux (I am assuming that it will work the same as it calls
the BIOS video service).

void clear_screen()
{
/* BIOS service routine to clear console window. */
asm("mov $0x00, %ah\n\t"
"mov $0x03, %al\n\t"
"int $0x10");
}

I compiled this using the DJGPP compiler, and have also added it to my
source code collection for NASM. Because of DJGPP being a DOS port of
GCC, am I right in assuming that it will also work in Linux?

The main reason I have created this routine is because I am currently
writing my kernel in C (the kernel I have written in ASM is becoming
too long and too complex too quickly). My next step is to figure out
how to write my own "printf" routine using only video memory and BIOS
calls.

Any comments/suggestions/criticisms are greatly appreciated.

TIA.
 
J

Joona I Palaste

phickman said:
After several searches using Google, I had just about given up on
finding a way to clear the console Window. After spending the past
week learning assembly language and writing a small boot loader for an
OS, I came across code to clear the console. It works. However, I post
it here to get opinions on using this. I have tested it in Windows but
not yet on Linux (I am assuming that it will work the same as it calls
the BIOS video service).
void clear_screen()
{
/* BIOS service routine to clear console window. */
asm("mov $0x00, %ah\n\t"
"mov $0x03, %al\n\t"
"int $0x10");
}
I compiled this using the DJGPP compiler, and have also added it to my
source code collection for NASM. Because of DJGPP being a DOS port of
GCC, am I right in assuming that it will also work in Linux?
The main reason I have created this routine is because I am currently
writing my kernel in C (the kernel I have written in ASM is becoming
too long and too complex too quickly). My next step is to figure out
how to write my own "printf" routine using only video memory and BIOS
calls.
Any comments/suggestions/criticisms are greatly appreciated.

This couldn't possibly have less to do with C. All you're really
asking is how to use Intel assembly code in Windows or Linux. The
code hardly becomes C by wrapping it inside a C calling mechanism.
I suggest you try comp.os.ms-windows.programmer.win32,
comp.unix.programmer, or an Intel assembly newsgroup.

--
/-- Joona Palaste ([email protected]) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"You have moved your mouse, for these changes to take effect you must shut down
and restart your computer. Do you want to restart your computer now?"
- Karri Kalpio
 
C

CBFalconer

phickman said:
.... snip ...
it here to get opinions on using this. I have tested it in Windows
but not yet on Linux (I am assuming that it will work the same as
it calls the BIOS video service).

void clear_screen()
{
/* BIOS service routine to clear console window. */
asm("mov $0x00, %ah\n\t"
"mov $0x03, %al\n\t"
"int $0x10");
}
.... snip ...

Any comments/suggestions/criticisms are greatly appreciated.

It doesn't seem to work on the MAC, the Z80, a PDP11, an HP3000, a
PIC. Some of them have neither consoles nor windows. So it just
doesn't meet the criterion of machine independant portable C
required for postings here.
 
R

Ross Kendall Axe

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

CBFalconer wrote:
| phickman wrote:
|
| .... snip ...
|
|>it here to get opinions on using this. I have tested it in Windows
|>but not yet on Linux (I am assuming that it will work the same as
|>it calls the BIOS video service).
|>
|>void clear_screen()
|>{
|> /* BIOS service routine to clear console window. */
|> asm("mov $0x00, %ah\n\t"
|> "mov $0x03, %al\n\t"
|> "int $0x10");
|>}
|>
|
| .... snip ...
|
|>Any comments/suggestions/criticisms are greatly appreciated.
|
|
| It doesn't seem to work on the MAC, the Z80, a PDP11, an HP3000, a
| PIC. Some of them have neither consoles nor windows. So it just
| doesn't meet the criterion of machine independant portable C
| required for postings here.
|

I have my doubts that it would even work on x86 Windows. It even smells
wrong for DJGPP. Serious rethink required.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFAwj/X9bR4xmappRARAisnAKCLjOPSeqkBDf+BepfTNyUwB0WhuACfSDsK
bMgX42dzTGfOfYK4o9QmkMs=
=pe6+
-----END PGP SIGNATURE-----
 
M

Malcolm

phickman said:
void clear_screen()
{
/* BIOS service routine to clear console window. */
asm("mov $0x00, %ah\n\t"
"mov $0x03, %al\n\t"
"int $0x10");
}

Because of DJGPP being a DOS port of
GCC, am I right in assuming that it will also work in Linux?
No. This is effectively a C-callable assembly function. However the "asm"
keyword isn't guaranteed to work the same way across compilers. It may well
work under Linux, but the ANSI standard does not require it to.
My next step is to figure out how to write my own "printf" routine
using only video memory and BIOS calls.
To implement printf(), your best bet is to steal an implementation of
vsnprintf(), which will do all the formatting for you. The problem then
becomes how to display a plain character string.
If your platform allows direct writes to the console's character buffer then
this is simply a case of obtaining the address and doing a few writes.
However modern platforms tend to get stroppy about this, so you have to work
out what the low-level (and platform-specific) access protocols are.
 
V

Viktor Lofgren

phickman said:
Hi all.

After several searches using Google, I had just about given up on
finding a way to clear the console Window. After spending the past
week learning assembly language and writing a small boot loader for an
OS, I came across code to clear the console. It works. However, I post
it here to get opinions on using this. I have tested it in Windows but
not yet on Linux (I am assuming that it will work the same as it calls
the BIOS video service).

void clear_screen()
{
/* BIOS service routine to clear console window. */
asm("mov $0x00, %ah\n\t"
"mov $0x03, %al\n\t"
"int $0x10");
}

I compiled this using the DJGPP compiler, and have also added it to my
source code collection for NASM. Because of DJGPP being a DOS port of
GCC, am I right in assuming that it will also work in Linux?

The main reason I have created this routine is because I am currently
writing my kernel in C (the kernel I have written in ASM is becoming
too long and too complex too quickly). My next step is to figure out
how to write my own "printf" routine using only video memory and BIOS
calls.

Any comments/suggestions/criticisms are greatly appreciated.

TIA.

This really dosent belong here, but if you are using some sort
of ANSI-compilant terminal (which you probably are in both
linux and at least partially in windows) you can just

puts("\33[H\33[2J");

Google for "ANSI escape sequences" for further information.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top