473,320 Members | 1,845 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 4726
phickman <ph******@tampabay.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.programmer.win32,
comp.unix.programmer, or an Intel assembly newsgroup.

--
/-- Joona Palaste (pa*****@cc.helsinki.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/X9bR4xmappRARAisnAKCLjOPSeqkBDf+BepfTNyUwB0WhuACfS DsK
bMgX42dzTGfOfYK4o9QmkMs=
=pe6+
-----END PGP SIGNATURE-----
Nov 14 '05 #4

"phickman" <ph******@tampabay.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******@tampabay.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
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...
1
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
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: ...
4
by: Brian | last post by:
Is there a easy way to clear the command screen like you could in C or C++?
2
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...
65
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
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...
10
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...
5
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
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.