For a piece of assembly code I'm writing I want to print a blinking text in a specific colour. I have already managed to find out how to print my text in colour. However, I'm struggling with the blinking. Here's what I have:
string: .asciz "\033[38;5;94mTEXT\033[0m"
...
mov $string, %rdi
mov $0, %rax
call printf
How do I add blinking to this?
CodePudding user response:
AFAIK blinking has to be explicitly enabled in videocard hardware.
Blinking concerns characters with background-color attribute between 8..15, which can be set by ANSII code.
I used a DOS utility OPIN.com /Attr to switch blinking on/off in emulation of real mode. It employs those TASM macros:
MACRO DisableBlink ; Makes the background color bright instead of blinking.
PUSH DS
SUB BX,BX
MOV DS,BX
MOV DX,[0463h] ; CRTC port
ADD DL,4 ; mode select port
MOV AL,[0465h] ; old CRT mode
AND AL, NOT 20h; disable blink
OR AL,09h ; visible text mode
OUT DX,AL ; CGA,HGA
MOV [0465h],AL ; new CRT mode
MOV AX,1003h
INT 10h ; disable blink EGA
POP DS
ENDM
MACRO EnableBlink ; Makes the background color blink.
PUSH DS
SUB BX,BX
MOV DS,BX
MOV DX,[0463h] ; CRT mode port
ADD DL,4 ; mode select port
MOV AL,[0465h] ; old CRT mode
OR AL,29h ; enable blink
OUT DX,AL ; CGA,HGA
MOV [0465h],AL ; new CRT mode
MOV AX,1003h
INC BL
INT 10h ; enable blink EGA
POP DS
ENDM
However, I'm not sure if this is possible in protected-mode programs.
CodePudding user response:
The ANSI Escape sequence \033[38;5;94m
selects a foreground color. To enable blinking use \033[5m
If you want blinking to last, then don't immediately reset all attributes with \033[0m
! Give it some time to actually see the text blinking.
string: .asciz "\033[5m\033[38;5;94mTEXT"
https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters