Tinted text - and a warning
Sept 30, 2013 1:56:01 GMT -5
Post by Deleted on Sept 30, 2013 1:56:01 GMT -5
Complementing the ability to read single key-strokes is the ability to write text to the screen at a position you choose and in a variety of colours. This is elementary of accomplishment once one has the information: en.wikipedia.org/wiki/ANSI_escape_code
But on any particular computer the information there stated should be tested to discover what actually works; in my experience there are in that list certain codes and combinations that invariably work and certain others that while documented never in fact do.
Sixteen different foreground colours are available with this method, and these can be combined with sixteen different background colours.
1) Here are the bits and pieces required to set the screen to a foreground colour of normal intensity:
And here is what is required to set the screen to one of the eight brighter colours:
To set background colours rather than foreground colours just change the "[3" in the first line to "[4"
It will be observed that the colours actually displayed in response to any particular code differ considerably for different screen hardware. Not only that; the nomenclature of many of the sixteen colours is unsatisfactory, and the modern forward-looking programmer is invited to change it. Far too much "cyan" and "magenta" for a start!
It is not yet at this stage possible to capture the screen as an image, and simple photo-graphy is unsatisfactory, so interested readers will have to try for themselves the methods here set out.
2) Setting a certain screen position for subsequent text output - positioning the cursor to row 20 column 10, for example:
Apologies for the haphazard formatting on this forum - needs practice!
The next thing I want to do is to find the simplest way to display a picture; a considerably more complex procedure.
Last week I was using Perl and cURL under OpenBSD - its first productive use - to retrieve some of the jpg images from the Spectator archive, and I am sorry to say that the system crashed twice. The fault is not reproducible - that is to say that after a reboot the problems did not happen again. Although a crash dump was saved, I have not yet bothered to look at it; but it is a worrying occurrence and the system will have to perform better than that if it is to be of any use. Indeed the second time something in the file system was corrupted and after rebooting a whole lot of automatic checking took place. Something to do with the TCP/IP code I suspect, and it was at the time sharing an ADSL modem/router with a Windows machine. Of course eventually I intend to rewrite the whole thing in Assembly language and at that point any difficulties of this kind will be discovered and expunged; but I regret having to inform readers that at present OpenBSD does not appear to be "ready for prime time." Which is very strange indeed because it has a reputation for reliability.
But on any particular computer the information there stated should be tested to discover what actually works; in my experience there are in that list certain codes and combinations that invariably work and certain others that while documented never in fact do.
Sixteen different foreground colours are available with this method, and these can be combined with sixteen different background colours.
1) Here are the bits and pieces required to set the screen to a foreground colour of normal intensity:
COLCYN: equ '6' ; Sickly blue / Pastel blue
section .text
sicklyblue:
mov byte [numnor],COLCYN
push 8 ; The length
push fgntes ; The text
push dword 1 ; stdout file descriptor
mov eax,4 ; sys_write function
sub esp,eax ; Push a dummy (4 bytes)
int 080h
add esp,4+12 ; The dummy plus 3 arguments * 4
section .data
fgntes: db 0x1b,'[3'
numnor: db '1' ; Changed for each colour
db ';'
db '22'
db 'm'
And here is what is required to set the screen to one of the eight brighter colours:
section .text
pastelblue: mov byte [numbri],COLCYN
push 7 ; The length
push fgtes ; The text
push dword 1 ; stdout file descriptor
mov eax,4 ; sys_write function
sub esp,eax ; Push a dummy (4 bytes)
int 080h
add esp,4+12 ; The dummy plus 3 arguments * 4
section .data
fgtes: db 0x1b,'[3'
numbri: db '1' ; Changed for each colour
db ';'
db '1'
db 'm'
To set background colours rather than foreground colours just change the "[3" in the first line to "[4"
It will be observed that the colours actually displayed in response to any particular code differ considerably for different screen hardware. Not only that; the nomenclature of many of the sixteen colours is unsatisfactory, and the modern forward-looking programmer is invited to change it. Far too much "cyan" and "magenta" for a start!
It is not yet at this stage possible to capture the screen as an image, and simple photo-graphy is unsatisfactory, so interested readers will have to try for themselves the methods here set out.
2) Setting a certain screen position for subsequent text output - positioning the cursor to row 20 column 10, for example:
section .text
push tplen ; Length of sequence
push tptext ; Positioning code sequence
push dword 1 ; The screen
mov eax,4 ; sys_write function
sub esp,eax ; Push a dummy
int 080h
add esp,16
section .data
tptext: db 0x1b,'[20;10H' ; See the 20 and the 10?
tplen: equ $ - tptext
Apologies for the haphazard formatting on this forum - needs practice!
The next thing I want to do is to find the simplest way to display a picture; a considerably more complex procedure.
Last week I was using Perl and cURL under OpenBSD - its first productive use - to retrieve some of the jpg images from the Spectator archive, and I am sorry to say that the system crashed twice. The fault is not reproducible - that is to say that after a reboot the problems did not happen again. Although a crash dump was saved, I have not yet bothered to look at it; but it is a worrying occurrence and the system will have to perform better than that if it is to be of any use. Indeed the second time something in the file system was corrupted and after rebooting a whole lot of automatic checking took place. Something to do with the TCP/IP code I suspect, and it was at the time sharing an ADSL modem/router with a Windows machine. Of course eventually I intend to rewrite the whole thing in Assembly language and at that point any difficulties of this kind will be discovered and expunged; but I regret having to inform readers that at present OpenBSD does not appear to be "ready for prime time." Which is very strange indeed because it has a reputation for reliability.