flat assembler
Message board for the users of flat assembler.

Index > Main > combining a nibble and 3 bits

Author
Thread Post new topic Reply to topic
fpga



Joined: 22 Sep 2009
Posts: 36
fpga 25 Sep 2009, 14:10
In a program I got from here there's a line
Code:
message: db ESC,  "[1;31m"  
    

This appears to be an escape sequence for a bright red foreground that fits into the first nibble of an attribute byte.

I'd like to be able to specify a background colour too
Code:
eg ; ESC,  "[0;44m"   ;dull blue background
    

and it appears that this should occupy the next 3 bits of the byte that contains the foreground colour (as the first nibble).
I don't know the format "[x;ym" and can find no reference to it.

What does it mean?
and
How do you combine these two escape sequences so that the bits go in the right places?

I tried to specify it manually but got some surprising results
i.e. sometimes it wasn't just the characters' backgrounds that changed,
the whole console background changed which is not what I want.

I'm trying to make an asm fn callable from c++
Code:
ie Print_ch(char ch, int x, int y, int fg, int bg)
    

Any help much appreciated.


Last edited by fpga on 25 Sep 2009, 20:00; edited 1 time in total
Post 25 Sep 2009, 14:10
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20303
Location: In your JS exploiting you and your system
revolution 25 Sep 2009, 14:16
What terminal emulation is your console set to?
Post 25 Sep 2009, 14:16
View user's profile Send private message Visit poster's website Reply with quote
fpga



Joined: 22 Sep 2009
Posts: 36
fpga 25 Sep 2009, 14:30
I'm running terminator under #! linux a minimalist debian derivative
terminator is set to emulate xterm according to it's profile
Is that what you want?
Post 25 Sep 2009, 14:30
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20303
Location: In your JS exploiting you and your system
revolution 25 Sep 2009, 14:36
It was supposed to be a hint so that once you know what terminal emulation you are using then you can look up the spec of terminal escape codes to see if what you want to do is possible/easy.

Here, I googled it for you: http://invisible-island.net/xterm/ctlseqs/ctlseqs.html
Post 25 Sep 2009, 14:36
View user's profile Send private message Visit poster's website Reply with quote
fpga



Joined: 22 Sep 2009
Posts: 36
fpga 25 Sep 2009, 15:06
On the link you provided there is "P s = 44 → Set background color to Blue"
ie "[44m"

It was a bit too subtle for me because I've already printed with a blue background and a red foreground ("[31m") so I know they both work.

I haven't managed to print the two at the same time cos I don't know how to put them both in the same byte
ie
"[31m" in the low nibble
"[44m" in the next 3 bytes
and
0 in the highest highest byte (blinking off)

This is assuming that eg "[31m" represents a single byte.
I have no idea whether these symbols have some special meaning
eg you can specify
"[1;31m" to make it brighter
What sort of syntax is this?

If I could get the stuff into a single byte as I have read you should do
I'd try
db ESC, the_byte_with_both_sequences_in
db "some text", 0xa

in the program
Hope this clarifies where I've got to.
Post 25 Sep 2009, 15:06
View user's profile Send private message Reply with quote
fpga



Joined: 22 Sep 2009
Posts: 36
fpga 25 Sep 2009, 19:32
The asm program that I've been struggling with sends to stdout so I've been playing around with c++ which I'm more familiar with.

Code:
#include "iostream"
using namespace std;
int main(){
   cout << "\x1b[31m\x1b[41mTesting\n"; //red on red
   cout << "\x1b[31m\x1b[42mTesting\n"; //red on green
   cout << "\x1b[0m";                   //go back to default
   return 0;
}
    


The above works fine other than allowing me to specify x & y which the asm code does.


Last edited by fpga on 25 Sep 2009, 19:57; edited 1 time in total
Post 25 Sep 2009, 19:32
View user's profile Send private message Reply with quote
fpga



Joined: 22 Sep 2009
Posts: 36
fpga 25 Sep 2009, 19:45
Translating this to asm we get

Code:
message:  
   db ESC, "[31m", ESC, "[42m"      
   db "Programming linux is easy", 0xa  ;0xa null termination char?
   db ESC, "[0m" 
    


which works.

Thanks for the prompt revolution. The above c++ code was a mod of some other code I saw whilst googling xterm.h and .c following your question.
Post 25 Sep 2009, 19:45
View user's profile Send private message Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2465
Location: Bucharest, Romania
Borsuc 26 Sep 2009, 18:28
0x0A is newline. 0x0D is carriage return. Under Windows (not linux) you would have 0x0D, 0x0A for each newline. Linux uses only 0x0A per newline.
Post 26 Sep 2009, 18:28
View user's profile Send private message Reply with quote
fpga



Joined: 22 Sep 2009
Posts: 36
fpga 28 Sep 2009, 18:49
Thx for that!
Post 28 Sep 2009, 18:49
View user's profile Send private message 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.