473,796 Members | 2,619 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Clearing Console Window

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.
Nov 14 '05 #1
5 4772
phickman <ph******@tampa bay.rr.com> scribbled the following:
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.


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.program mer.win32,
comp.unix.progr ammer, or an Intel assembly newsgroup.

--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- 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
Nov 14 '05 #2
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.

--
A: Because it fouls the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

Nov 14 '05 #3
-----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/X9bR4xmappRARAi snAKCLjOPSeqkBD f+BepfTNyUwB0Wh uACfSDsK
bMgX42dzTGfOfYK 4o9QmkMs=
=pe6+
-----END PGP SIGNATURE-----
Nov 14 '05 #4

"phickman" <ph******@tampa bay.rr.com> wrote in message

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.
Nov 14 '05 #5
phickman <ph******@tampa bay.rr.com> wrote:
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.

--
Viktor Lofgren, Umea, Sweden
Mainly self-eductated UNIX programmer, running Slackware-current.
Nov 14 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
4265
by: Ishwor | last post by:
Hi i use IDLE to code Python in my machine. What i haven't been able to do is call an in-built function called clear()/cls()/clr() because it mightn't exist. so what i did is coded my own function called cls() as such >>> def cls(): for i in range(1,40): print " "; now that does the job very nicely and i get cleared screen but what i really want to achieve it everytime i start IDLE, without importing
1
2015
by: raghavendra | last post by:
Hi, i am facing problem clearing screen in console application. As, in C++ we have clrscr(); Is? their any similar type of function is avaliable.. Raghavendra...
13
13921
by: Michael Kennedy [UB] | last post by:
Hi, I have a situation where I need to clear the event sinks from an event inside a custom class. But I don't know which methods signed up for that event. Consider the following example: public class B {
4
2294
by: Brian | last post by:
Is there a easy way to clear the command screen like you could in C or C++?
2
1987
by: Slack | last post by:
I wish to write a console text editor. Can anyone tell me how to capture the screen like Vi or Pico does? Also, I wish to draw "tabs" on the screen, is there a standard way to draw so that my code is crossplatform and will compile on most platforms? Thanks, -Jason
65
8646
by: Leslie Kis-Adam | last post by:
Hi everyone! Does anyone know, if it is possible to clear the screen in ANSI C? If it is,then how? Any help would be appreciated. Laszlo Kis-Adam <dfighter_AT-NOSPAM_freemail.hu
3
1437
by: Zytan | last post by:
The Immediate Window is filled with debugging output from previous runs. Besides manually right clicking and clearing it, is there a programmatic way of doing this? Should I create and use a console window instead and put my debugging output there? What's the best way to show debugging information? Zytan
10
6350
by: Stephany Young | last post by:
When one uses the System.Diagnostics.Process.Start method to launch a common or garden Console application, one can set the WindowStyle property of the StartInfo object to ProcessWindowStyle.Hidden so that the window for the Console application is not visible. However, when using some of the 'advanced' properties of the StartInfo object, like Username, Password and Domain, the WindowsStyle property of the StartInfo object is ignored....
5
2351
by: Stephen_B | last post by:
This doesn't seem to work in a dos terminal at the start of a script: from os import popen print popen('clear').read() Any idea why not? Thanks. Stephen
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9533
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10461
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10190
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9057
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5447
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5579
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2928
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.