Author Topic: Screen programming in Linux  (Read 16000 times)

nobody

  • Guest
Screen programming in Linux
« on: December 05, 2004, 11:09:20 AM »
I want to write a program that needs to find the cursor position
and move it etc (Linux NASM).  I only know pure assembly and want to make the system calls but I can't find anything related to the screen in the docs I have, this is from:
http://www.lxhp.in-berlin.de/lhpsysc0.html.
Could anyone suggest how to find doc about system calls for
the screen?

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Screen programming in Linux
« Reply #1 on: December 08, 2004, 09:13:07 AM »
You can send "escape sequences" to stdout - IIRC you can read the cursor position from stdin, after sending the "get position" escape sequence. Unfortunately, I don't know what that is! :( Possibly that "c" that the comment below refers to?

global _start

section .data
;    msg db 27, '[37;40m Hello, World!',10,0
; c - garbage back d - row?, r - home, f - row;col

msg db 27,'[2j'         ; cls?
        db 27, '[18;48f'    ; row 18, column 48
        db 27, '[37;44m'    ; white foreground, blue background
        db ' Hello, World! ',10
   db 27, '[37;40m'    ; "normal" white on black
   db 27, '[25;0f'     ; row 25
    msg_len equ $ - msg

section .text

_start

mov   eax, 4   ;system call number (sys_write)
   mov   ebx, 1   ;file descriptor (stdout)
   mov   ecx, msg   ;message to write
   mov     edx, msg_len
   int   0x80   ;call kernel

exit:
   mov   eax,1   ;system call number (sys_exit)
   int   0x80
;-------------------------------------------

... or so. I don't recall where I found the info for the values... pretty much the same as ANSI.SYS, I think, if you're familiar with that. Part of "VT-100" specs, maybe(?) I *think* this is the way "ncurses" does it - calling "ncurses" would be a way, but I take it you don't want to do that.

Another way to do it is to open /dev/vcsa0 for RW... There's a few bytes of "header" in the file, then char/attribute/char/attribute... just like writing direct to the screen in DOS. You move the cursor by sys_seeking around in the file. Kinda weird. There may be issues with "permissions" to that file. Konstantin's "window" example in the asmutils - http://www.linuxassembly.org - does it this way. Whether you can open this file and determine the cursor position by finding the file-pointer (seek to "current position")??? - I doubt that would work - I think the file pointer would be at zero when you first open the file.

So sending escape sequences might be your best bet. I'll see if I can figure out what the command is...

Best,
Frank