![]() Let’s leave room at the bottom of the screen for a separate message or prompt to the user. To display the ASCII art to the screen, your program needs to scan the array, set the color attribute, then show the screen one character at a time. The IMAGEDATA array contains the entire ASCII art screen and the color values for each character. We can use another bit mask with 7 (binary 0111) to pick out the background color value. This puts the “upper” bits into the “lower” bit range, so any bits like 0xxx0000 become 00000xxx instead. To get the background color, the function first performs a bit shift to “push” the bits to the right. That’s where the color pair stores the values 0 to 15 for the foreground color. Note that because the color attribute included both the background color and the foreground color in a single byte value, the textattr function uses & (binary AND) to set a bit mask that isolates only the last four bits in the attribute. The _settextcolor function sets just the text color, and the _setbkcolor function sets the background color. Using the OpenWatcom C Compiler on FreeDOS, you can write this function to set the colors appropriately from the color attribute: void To convert the color pair or attribute into color values that your program can use, you’ll need to use a bit mask to specify only the bits used for the text color or background color. The leftover bit in the byte is not used here, so we can ignore it. That’s four bits for the text color (0 to 15 or 0 to F in hexadecimal) and three bits for the background color (0 to 7 or 0 to E in hexadecimal). With color pairs, you can encode both the background and foreground colors in a single byte of eight bits. So the value F in hexadecimal is the number 15, or 1111 in binary. Counting sixteen values (from 0 to 15) in binary requires only four bits:Īnd conveniently, hexadecimal can represent 0 to 15 with a single character: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F. That’s sixteen possible text colors and eight background colors. Hexadecimal turns out to be a compact way to express a color “pair” like this.Ĭharacter mode systems like ncurses on Linux or conio on DOS can display only sixteen colors. The color attribute in this ASCII art file defines both the background and foreground color in a single byte, represented by hexadecimal values like 0x08 or 0圆E. To display this ASCII art to the screen, you need to write a small program to read the array and print each character with the right colors. For an 80x25 screen, where each character is paired with an attribute, the array contains 4000 entries (that’s 80 * 25 * 2 = 4000). Each character in the ASCII art screen can be represented by two bytes of data: The character to display and a color attribute containing both the foreground and background colors for the character. In this case, it’s an 80x25 ASCII art “image.” IMAGEDATA_LENGTH defines the number of entries in the IMAGEDATA array. ![]() Note that the code snippet defines a few values: IMAGEDATA_WIDTH and IMAGEDATA_DEPTH define the number of columns and rows on the screen. Here’s part of a sample ASCII art file, saved as C source code. It doesn’t matter what tool you use as long as you know what the saved data looks like. For this example, I used an old DOS application called TheDraw, but you can find modern open source ASCII art programs on Linux, such as Moebius (Apache license) or PabloDraw (MIT license). ![]() You can use a variety of tools to draw your ASCII art. Free online course: RHEL Technical Overview.
0 Comments
Leave a Reply. |