flat assembler
Message board for the users of flat assembler.

Index > Linux > Really fast way to clear virtual console /dev/vcsa1

Author
Thread Post new topic Reply to topic
fpga



Joined: 22 Sep 2009
Posts: 36
fpga
Does anyone know a really fast way to clear the screen of /dev/vcsa1 that I can use to replace the c call to 'system("clear")' in stdlib.h.

I've looked but a sys call to clear the screen doesn't seem to exist like it does for write.

Sending 0x1b, "[2J" to stdout seems to clear /dev/vcsa1 but I'd prefer sending something directly to /dev/vcsa1 and not stdout.
Post 06 Oct 2009, 18:47
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
Why not look into the curses library?

It's not the fastest way to do stuff, but it has the advantage that it's plenty fast on local consoles (even on old hardware), yet still allows you to do TUIs on remote shells as well.
Post 21 Oct 2009, 07:36
View user's profile Send private message Visit poster's website Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
there's 2 options for you (unless you want to learn extra annoying apis that you'll probably never use because you'll be too annoyed with it), escape keys and doing it all yourself... Can't see why you'd mind sending to stdout, but if you must, you could always memory map or use seek.
Post 21 Oct 2009, 11:48
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
stdout means using ANSI escape sequences - having a proper library is nicer.

Can vcs* be mmap'ed these days?
Post 21 Oct 2009, 14:17
View user's profile Send private message Visit poster's website Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
A proper library doesn't exist. ncurses has its name for a reason.

Anyway, just about anything can be memory mapped, i haven't personally checked, but i can't see why it couldn't be.
Post 21 Oct 2009, 18:40
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
kohlrak wrote:
A proper library doesn't exist. ncurses has its name for a reason.
And you base that on what? It's portable across a wide range of systems, it offers acceptable speed on a local console even on old hardware; I haven't tried doing realtime textmode graphics (as in spinning 3D cubes or aalib video) with it, but it works quite fine for regular textmode interfaces.

kohlrak wrote:
Anyway, just about anything can be memory mapped, i haven't personally checked, but i can't see why it couldn't be.
Last time I tried (several years back), it didn't want to be mmap()'ed - probably wouldn't grant you anything but convenience anyway, and might even be slightly slower than write() calls. You're obviously not going to get direct 0xB8000 access by mmap()'ing a /dev/vcs* device Smile

_________________
Image - carpe noctem
Post 21 Oct 2009, 22:09
View user's profile Send private message Visit poster's website Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
Quote:
And you base that on what? It's portable across a wide range of systems, it offers acceptable speed on a local console even on old hardware; I haven't tried doing realtime textmode graphics (as in spinning 3D cubes or aalib video) with it, but it works quite fine for regular textmode interfaces.



For anything other than it's unstable text mode GUI, it's really quite pointless. Most of other things like clearing the screen and such minor things can easily be made on your own with less effort than that it would take just to bother learning what ncurses has and how to use it. If you're worried about aalib and making textmode guis, sure, go ahead and learn it, but personally i think ncurses is a bit much for most console programs. Especially when he seems very adamant about using a specific file instead of stdout (i'm quite curious why Razz).

Quote:
Last time I tried (several years back), it didn't want to be mmap()'ed - probably wouldn't grant you anything but convenience anyway, and might even be slightly slower than write() calls. You're obviously not going to get direct 0xB8000 access by mmap()'ing a /dev/vcs* device


Naturally. Personally, something as simple as clearing the screen i'd probably sys_write 200 spaces on the screen and go back to 0. Or, depending if you expect it to be run in an emulated terminal or not, 25 newlines. It's cheap and get the job done. Razz
Post 22 Oct 2009, 00:16
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
Quote:
Naturally. Personally, something as simple as clearing the screen i'd probably sys_write 200 spaces on the screen and go back to 0. Or, depending if you expect it to be run in an emulated terminal or not, 25 newlines. It's cheap and get the job done. Razz
That's pretty much the worst way possible to do it Smile - I doubt many people are running 25-lines-high consoles these days (even back in textmode I ran 50, today most people will be on xterm, ssh or framebuffer console), and it's going to cause a bit of flickering... even ANSI escape sequences is better than this Smile

_________________
Image - carpe noctem
Post 22 Oct 2009, 09:45
View user's profile Send private message Visit poster's website Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
That's typically what the ncurses lib does anyway (ida pro uses ncurses afaik, and i can scroll up when i control+c in a virtual console), unless it tells the video hardware to hold on while it clears it (i can't see how ncurses would get that kind of access though). It'll work faster if you first initialize a large section of memory with the character you're using to clear (rather than flickering as you say which'd come with multiple writes). Razz
Post 22 Oct 2009, 11:40
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
Endre



Joined: 29 Dec 2003
Posts: 212
Location: Budapest, Hungary
Endre
I've not been able to mmap /dev/vcsa yet. If I remember correctly then you get a "No such device" error code. By the way I think that use of /dev/vcsa is perhaps the fastest and the most comfortable method (if you're root, of course). If not then there are those cursed escape sequences, but converting integers to string is not a big fun, additionally the terminal your program will be running on may not support all of the sequences you've thought it will. For instance blinking does not work on gnome terminals (that's why LocoDelAssembly didn't find your/my example funny Smile). Escape sequences are however more portable than use of /dev/vcsa, but I guess the most other unix systems have something similar.
Post 25 Oct 2009, 18:07
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
Endre wrote:
If not then there are those cursed escape sequences, but converting integers to string is not a big fun, additionally the terminal your program will be running on may not support all of the sequences you've thought it will.
...which is why you use ncurses (emphasis mine Smile)

_________________
Image - carpe noctem
Post 25 Oct 2009, 19:50
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.