Library for uVGAIII
uVGAIII_Text.cpp@4:672a6d537dce, 2014-03-24 (annotated)
- Committer:
- ivygatech
- Date:
- Mon Mar 24 19:42:30 2014 +0000
- Revision:
- 4:672a6d537dce
- Parent:
- 0:de1ab53f3480
update document
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ivygatech | 0:de1ab53f3480 | 1 | // |
ivygatech | 0:de1ab53f3480 | 2 | // uVGAIII is a class to drive 4D Systems TFT touch screens |
ivygatech | 0:de1ab53f3480 | 3 | // |
ivygatech | 0:de1ab53f3480 | 4 | // Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr> |
ivygatech | 0:de1ab53f3480 | 5 | // |
ivygatech | 0:de1ab53f3480 | 6 | // uVGAIII is free software: you can redistribute it and/or modify |
ivygatech | 0:de1ab53f3480 | 7 | // it under the terms of the GNU General Public License as published by |
ivygatech | 0:de1ab53f3480 | 8 | // the Free Software Foundation, either version 3 of the License, or |
ivygatech | 0:de1ab53f3480 | 9 | // (at your option) any later version. |
ivygatech | 0:de1ab53f3480 | 10 | // |
ivygatech | 0:de1ab53f3480 | 11 | // uVGAIII is distributed in the hope that it will be useful, |
ivygatech | 0:de1ab53f3480 | 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
ivygatech | 0:de1ab53f3480 | 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ivygatech | 0:de1ab53f3480 | 14 | // GNU General Public License for more details. |
ivygatech | 0:de1ab53f3480 | 15 | // |
ivygatech | 0:de1ab53f3480 | 16 | // You should have received a copy of the GNU General Public License |
ivygatech | 0:de1ab53f3480 | 17 | // along with uVGAIII. If not, see <http://www.gnu.org/licenses/>. |
ivygatech | 0:de1ab53f3480 | 18 | |
ivygatech | 0:de1ab53f3480 | 19 | #include "mbed.h" |
ivygatech | 0:de1ab53f3480 | 20 | #include "uVGAIII.h" |
ivygatech | 0:de1ab53f3480 | 21 | |
ivygatech | 0:de1ab53f3480 | 22 | //**************************************************************************************************** |
ivygatech | 0:de1ab53f3480 | 23 | void uVGAIII :: set_font(char mode) { // set font size |
ivygatech | 0:de1ab53f3480 | 24 | char command[4] = ""; |
ivygatech | 0:de1ab53f3480 | 25 | |
ivygatech | 0:de1ab53f3480 | 26 | command[0] = (SETFONT >> 8) & 0xFF; |
ivygatech | 0:de1ab53f3480 | 27 | command[1] = SETFONT & 0xFF; |
ivygatech | 0:de1ab53f3480 | 28 | command[2] = 0; |
ivygatech | 0:de1ab53f3480 | 29 | command[3] = mode; |
ivygatech | 0:de1ab53f3480 | 30 | |
ivygatech | 0:de1ab53f3480 | 31 | current_font = mode; |
ivygatech | 0:de1ab53f3480 | 32 | |
ivygatech | 0:de1ab53f3480 | 33 | if (current_orientation == IS_PORTRAIT) { |
ivygatech | 0:de1ab53f3480 | 34 | current_w = SIZE_X; |
ivygatech | 0:de1ab53f3480 | 35 | current_h = SIZE_Y; |
ivygatech | 0:de1ab53f3480 | 36 | } else { |
ivygatech | 0:de1ab53f3480 | 37 | current_w = SIZE_Y; |
ivygatech | 0:de1ab53f3480 | 38 | current_h = SIZE_X; |
ivygatech | 0:de1ab53f3480 | 39 | } |
ivygatech | 0:de1ab53f3480 | 40 | |
ivygatech | 0:de1ab53f3480 | 41 | switch (mode) { |
ivygatech | 0:de1ab53f3480 | 42 | case FONT1 : |
ivygatech | 0:de1ab53f3480 | 43 | current_fx = 7; |
ivygatech | 0:de1ab53f3480 | 44 | current_fy = 8; |
ivygatech | 0:de1ab53f3480 | 45 | break; |
ivygatech | 0:de1ab53f3480 | 46 | case FONT2 : |
ivygatech | 0:de1ab53f3480 | 47 | current_fx = 8; |
ivygatech | 0:de1ab53f3480 | 48 | current_fy = 8; |
ivygatech | 0:de1ab53f3480 | 49 | break; |
ivygatech | 0:de1ab53f3480 | 50 | case FONT3 : |
ivygatech | 0:de1ab53f3480 | 51 | current_fx = 8; |
ivygatech | 0:de1ab53f3480 | 52 | current_fy = 12; |
ivygatech | 0:de1ab53f3480 | 53 | break; |
ivygatech | 0:de1ab53f3480 | 54 | } |
ivygatech | 0:de1ab53f3480 | 55 | |
ivygatech | 0:de1ab53f3480 | 56 | max_col = current_w / current_fx; |
ivygatech | 0:de1ab53f3480 | 57 | max_row = current_h / current_fy; |
ivygatech | 0:de1ab53f3480 | 58 | |
ivygatech | 0:de1ab53f3480 | 59 | writeCOMMAND(command, 4, 3); |
ivygatech | 0:de1ab53f3480 | 60 | |
ivygatech | 0:de1ab53f3480 | 61 | #if DEBUGMODE |
ivygatech | 0:de1ab53f3480 | 62 | pc.printf("Set font completed.\n"); |
ivygatech | 0:de1ab53f3480 | 63 | #endif |
ivygatech | 0:de1ab53f3480 | 64 | } |
ivygatech | 0:de1ab53f3480 | 65 | |
ivygatech | 0:de1ab53f3480 | 66 | //**************************************************************************************************** |
ivygatech | 0:de1ab53f3480 | 67 | void uVGAIII :: char_width(char c) { // Get the width in pixel units for a character |
ivygatech | 0:de1ab53f3480 | 68 | char command[3] = ""; |
ivygatech | 0:de1ab53f3480 | 69 | |
ivygatech | 0:de1ab53f3480 | 70 | command[0] = (CHARWIDTH >> 8) & 0xFF; |
ivygatech | 0:de1ab53f3480 | 71 | command[1] = CHARWIDTH & 0xFF; |
ivygatech | 0:de1ab53f3480 | 72 | |
ivygatech | 0:de1ab53f3480 | 73 | command[2] = c; |
ivygatech | 0:de1ab53f3480 | 74 | |
ivygatech | 0:de1ab53f3480 | 75 | writeCOMMAND(command, 3, 3); |
ivygatech | 0:de1ab53f3480 | 76 | |
ivygatech | 0:de1ab53f3480 | 77 | #if DEBUGMODE |
ivygatech | 0:de1ab53f3480 | 78 | pc.printf("Character width completed.\n"); |
ivygatech | 0:de1ab53f3480 | 79 | #endif |
ivygatech | 0:de1ab53f3480 | 80 | } |
ivygatech | 0:de1ab53f3480 | 81 | |
ivygatech | 0:de1ab53f3480 | 82 | //**************************************************************************************************** |
ivygatech | 0:de1ab53f3480 | 83 | void uVGAIII :: char_height(char c) { // Get the height in pixel units for a character |
ivygatech | 0:de1ab53f3480 | 84 | char command[3] = ""; |
ivygatech | 0:de1ab53f3480 | 85 | |
ivygatech | 0:de1ab53f3480 | 86 | command[0] = (CHARHEIGHT >> 8) & 0xFF; |
ivygatech | 0:de1ab53f3480 | 87 | command[1] = CHARHEIGHT & 0xFF; |
ivygatech | 0:de1ab53f3480 | 88 | |
ivygatech | 0:de1ab53f3480 | 89 | command[2] = c; |
ivygatech | 0:de1ab53f3480 | 90 | |
ivygatech | 0:de1ab53f3480 | 91 | writeCOMMAND(command, 3, 3); |
ivygatech | 0:de1ab53f3480 | 92 | |
ivygatech | 0:de1ab53f3480 | 93 | #if DEBUGMODE |
ivygatech | 0:de1ab53f3480 | 94 | pc.printf("Character height completed.\n"); |
ivygatech | 0:de1ab53f3480 | 95 | #endif |
ivygatech | 0:de1ab53f3480 | 96 | } |
ivygatech | 0:de1ab53f3480 | 97 | |
ivygatech | 0:de1ab53f3480 | 98 | //**************************************************************************************************** |
ivygatech | 0:de1ab53f3480 | 99 | void uVGAIII :: text_opacity(char mode) { // set text mode |
ivygatech | 0:de1ab53f3480 | 100 | char command[4] = ""; |
ivygatech | 0:de1ab53f3480 | 101 | |
ivygatech | 0:de1ab53f3480 | 102 | command[0] = (TEXTOPACITY >> 8) & 0xFF; |
ivygatech | 0:de1ab53f3480 | 103 | command[1] = TEXTOPACITY & 0xFF; |
ivygatech | 0:de1ab53f3480 | 104 | command[2] = 0x00; |
ivygatech | 0:de1ab53f3480 | 105 | command[3] = mode; |
ivygatech | 0:de1ab53f3480 | 106 | |
ivygatech | 0:de1ab53f3480 | 107 | writeCOMMAND(command, 4, 3); |
ivygatech | 0:de1ab53f3480 | 108 | |
ivygatech | 0:de1ab53f3480 | 109 | #if DEBUGMODE |
ivygatech | 0:de1ab53f3480 | 110 | pc.printf("Text opacity completed.\n"); |
ivygatech | 0:de1ab53f3480 | 111 | #endif |
ivygatech | 0:de1ab53f3480 | 112 | } |
ivygatech | 0:de1ab53f3480 | 113 | |
ivygatech | 0:de1ab53f3480 | 114 | //**************************************************************************************************** |
ivygatech | 0:de1ab53f3480 | 115 | void uVGAIII :: text_width(int multiplier) { // Set teh text width multiplier between 1 and 16 |
ivygatech | 0:de1ab53f3480 | 116 | char command[4] = ""; |
ivygatech | 0:de1ab53f3480 | 117 | |
ivygatech | 0:de1ab53f3480 | 118 | command[0] = (TEXTWIDTH >> 8) & 0xFF; |
ivygatech | 0:de1ab53f3480 | 119 | command[1] = TEXTWIDTH & 0xFF; |
ivygatech | 0:de1ab53f3480 | 120 | |
ivygatech | 0:de1ab53f3480 | 121 | command[2] = (multiplier >> 8) & 0xFF; |
ivygatech | 0:de1ab53f3480 | 122 | command[3] = multiplier & 0xFF; |
ivygatech | 0:de1ab53f3480 | 123 | |
ivygatech | 0:de1ab53f3480 | 124 | writeCOMMAND(command, 4, 3); |
ivygatech | 0:de1ab53f3480 | 125 | |
ivygatech | 0:de1ab53f3480 | 126 | #if DEBUGMODE |
ivygatech | 0:de1ab53f3480 | 127 | pc.printf("Text width completed.\n"); |
ivygatech | 0:de1ab53f3480 | 128 | #endif |
ivygatech | 0:de1ab53f3480 | 129 | } |
ivygatech | 0:de1ab53f3480 | 130 | |
ivygatech | 0:de1ab53f3480 | 131 | //**************************************************************************************************** |
ivygatech | 0:de1ab53f3480 | 132 | void uVGAIII :: text_height(int multiplier) { // Set teh text height multiplier between 1 and 16 |
ivygatech | 0:de1ab53f3480 | 133 | char command[4] = ""; |
ivygatech | 0:de1ab53f3480 | 134 | |
ivygatech | 0:de1ab53f3480 | 135 | command[0] = (TEXTHEIGHT >> 8) & 0xFF; |
ivygatech | 0:de1ab53f3480 | 136 | command[1] = TEXTHEIGHT & 0xFF; |
ivygatech | 0:de1ab53f3480 | 137 | |
ivygatech | 0:de1ab53f3480 | 138 | command[2] = (multiplier >> 8) & 0xFF; |
ivygatech | 0:de1ab53f3480 | 139 | command[3] = multiplier & 0xFF; |
ivygatech | 0:de1ab53f3480 | 140 | |
ivygatech | 0:de1ab53f3480 | 141 | writeCOMMAND(command, 4, 3); |
ivygatech | 0:de1ab53f3480 | 142 | |
ivygatech | 0:de1ab53f3480 | 143 | #if DEBUGMODE |
ivygatech | 0:de1ab53f3480 | 144 | pc.printf("Text width completed.\n"); |
ivygatech | 0:de1ab53f3480 | 145 | #endif |
ivygatech | 0:de1ab53f3480 | 146 | } |
ivygatech | 0:de1ab53f3480 | 147 | |
ivygatech | 0:de1ab53f3480 | 148 | //**************************************************************************************************** |
ivygatech | 0:de1ab53f3480 | 149 | void uVGAIII :: text_y_gap(int pixelcount) { // set the pixel gap between characters(y-axis), and the gap is in pixel units |
ivygatech | 0:de1ab53f3480 | 150 | char command[4] = ""; |
ivygatech | 0:de1ab53f3480 | 151 | |
ivygatech | 0:de1ab53f3480 | 152 | command[0] = (TEXTYGAP >> 8) & 0xFF; |
ivygatech | 0:de1ab53f3480 | 153 | command[1] = TEXTYGAP & 0xFF; |
ivygatech | 0:de1ab53f3480 | 154 | |
ivygatech | 0:de1ab53f3480 | 155 | command[2] = (pixelcount >> 8) & 0xFF; |
ivygatech | 0:de1ab53f3480 | 156 | command[3] = pixelcount & 0xFF; |
ivygatech | 0:de1ab53f3480 | 157 | |
ivygatech | 0:de1ab53f3480 | 158 | writeCOMMAND(command, 4, 3); |
ivygatech | 0:de1ab53f3480 | 159 | |
ivygatech | 0:de1ab53f3480 | 160 | #if DEBUGMODE |
ivygatech | 0:de1ab53f3480 | 161 | pc.printf("Text Y-gap completed.\n"); |
ivygatech | 0:de1ab53f3480 | 162 | #endif |
ivygatech | 0:de1ab53f3480 | 163 | } |
ivygatech | 0:de1ab53f3480 | 164 | |
ivygatech | 0:de1ab53f3480 | 165 | //**************************************************************************************************** |
ivygatech | 0:de1ab53f3480 | 166 | void uVGAIII :: text_x_gap(int pixelcount) { // set the pixel gap between characters(x-axis), and the gap is in pixel units |
ivygatech | 0:de1ab53f3480 | 167 | char command[4] = ""; |
ivygatech | 0:de1ab53f3480 | 168 | |
ivygatech | 0:de1ab53f3480 | 169 | command[0] = (TEXTXGAP >> 8) & 0xFF; |
ivygatech | 0:de1ab53f3480 | 170 | command[1] = TEXTXGAP & 0xFF; |
ivygatech | 0:de1ab53f3480 | 171 | |
ivygatech | 0:de1ab53f3480 | 172 | command[2] = (pixelcount >> 8) & 0xFF; |
ivygatech | 0:de1ab53f3480 | 173 | command[3] = pixelcount & 0xFF; |
ivygatech | 0:de1ab53f3480 | 174 | |
ivygatech | 0:de1ab53f3480 | 175 | writeCOMMAND(command, 4, 3); |
ivygatech | 0:de1ab53f3480 | 176 | |
ivygatech | 0:de1ab53f3480 | 177 | #if DEBUGMODE |
ivygatech | 0:de1ab53f3480 | 178 | pc.printf("Text X-gap completed.\n"); |
ivygatech | 0:de1ab53f3480 | 179 | #endif |
ivygatech | 0:de1ab53f3480 | 180 | } |
ivygatech | 0:de1ab53f3480 | 181 | |
ivygatech | 0:de1ab53f3480 | 182 | //**************************************************************************************************** |
ivygatech | 0:de1ab53f3480 | 183 | void uVGAIII :: text_bold(char mode) { // set the Bold attribute for the text |
ivygatech | 0:de1ab53f3480 | 184 | char command[4] = ""; |
ivygatech | 0:de1ab53f3480 | 185 | |
ivygatech | 0:de1ab53f3480 | 186 | command[0] = (TEXTBOLD >> 8) & 0xFF; |
ivygatech | 0:de1ab53f3480 | 187 | command[1] = TEXTBOLD & 0xFF; |
ivygatech | 0:de1ab53f3480 | 188 | |
ivygatech | 0:de1ab53f3480 | 189 | command[2] = 0x00; |
ivygatech | 0:de1ab53f3480 | 190 | command[3] = mode & 0xFF; |
ivygatech | 0:de1ab53f3480 | 191 | |
ivygatech | 0:de1ab53f3480 | 192 | writeCOMMAND(command, 4, 3); |
ivygatech | 0:de1ab53f3480 | 193 | |
ivygatech | 0:de1ab53f3480 | 194 | #if DEBUGMODE |
ivygatech | 0:de1ab53f3480 | 195 | pc.printf("Text bold completed.\n"); |
ivygatech | 0:de1ab53f3480 | 196 | #endif |
ivygatech | 0:de1ab53f3480 | 197 | } |
ivygatech | 0:de1ab53f3480 | 198 | |
ivygatech | 0:de1ab53f3480 | 199 | //**************************************************************************************************** |
ivygatech | 0:de1ab53f3480 | 200 | void uVGAIII :: text_inverse(char mode) { // set the text foreground and background color to be inverse |
ivygatech | 0:de1ab53f3480 | 201 | char command[4] = ""; |
ivygatech | 0:de1ab53f3480 | 202 | |
ivygatech | 0:de1ab53f3480 | 203 | command[0] = (TEXTINVERSE >> 8) & 0xFF; |
ivygatech | 0:de1ab53f3480 | 204 | command[1] = TEXTINVERSE & 0xFF; |
ivygatech | 0:de1ab53f3480 | 205 | |
ivygatech | 0:de1ab53f3480 | 206 | command[2] = 0x00; |
ivygatech | 0:de1ab53f3480 | 207 | command[3] = mode & 0xFF; |
ivygatech | 0:de1ab53f3480 | 208 | |
ivygatech | 0:de1ab53f3480 | 209 | writeCOMMAND(command, 4, 3); |
ivygatech | 0:de1ab53f3480 | 210 | |
ivygatech | 0:de1ab53f3480 | 211 | #if DEBUGMODE |
ivygatech | 0:de1ab53f3480 | 212 | pc.printf("Text inverse completed.\n"); |
ivygatech | 0:de1ab53f3480 | 213 | #endif |
ivygatech | 0:de1ab53f3480 | 214 | } |
ivygatech | 0:de1ab53f3480 | 215 | |
ivygatech | 0:de1ab53f3480 | 216 | //**************************************************************************************************** |
ivygatech | 0:de1ab53f3480 | 217 | void uVGAIII :: text_italic(char mode) { // set the text to italic |
ivygatech | 0:de1ab53f3480 | 218 | char command[4] = ""; |
ivygatech | 0:de1ab53f3480 | 219 | |
ivygatech | 0:de1ab53f3480 | 220 | command[0] = (TEXTITALIC >> 8) & 0xFF; |
ivygatech | 0:de1ab53f3480 | 221 | command[1] = TEXTITALIC & 0xFF; |
ivygatech | 0:de1ab53f3480 | 222 | |
ivygatech | 0:de1ab53f3480 | 223 | command[2] = 0x00; |
ivygatech | 0:de1ab53f3480 | 224 | command[3] = mode & 0xFF; |
ivygatech | 0:de1ab53f3480 | 225 | |
ivygatech | 0:de1ab53f3480 | 226 | writeCOMMAND(command, 4, 3); |
ivygatech | 0:de1ab53f3480 | 227 | |
ivygatech | 0:de1ab53f3480 | 228 | #if DEBUGMODE |
ivygatech | 0:de1ab53f3480 | 229 | pc.printf("Text italic completed.\n"); |
ivygatech | 0:de1ab53f3480 | 230 | #endif |
ivygatech | 0:de1ab53f3480 | 231 | } |
ivygatech | 0:de1ab53f3480 | 232 | |
ivygatech | 0:de1ab53f3480 | 233 | //**************************************************************************************************** |
ivygatech | 0:de1ab53f3480 | 234 | void uVGAIII :: text_underline(char mode) { // Set whether the text to be underlined |
ivygatech | 0:de1ab53f3480 | 235 | char command[4] = ""; // For text underline to work, text Y-gap must be set to at least 2 |
ivygatech | 0:de1ab53f3480 | 236 | |
ivygatech | 0:de1ab53f3480 | 237 | command[0] = (TEXTUNDLINE >> 8) & 0xFF; |
ivygatech | 0:de1ab53f3480 | 238 | command[1] = TEXTUNDLINE & 0xFF; |
ivygatech | 0:de1ab53f3480 | 239 | |
ivygatech | 0:de1ab53f3480 | 240 | command[2] = 0x00; |
ivygatech | 0:de1ab53f3480 | 241 | command[3] = mode & 0xFF; |
ivygatech | 0:de1ab53f3480 | 242 | |
ivygatech | 0:de1ab53f3480 | 243 | writeCOMMAND(command, 4, 3); |
ivygatech | 0:de1ab53f3480 | 244 | |
ivygatech | 0:de1ab53f3480 | 245 | #if DEBUGMODE |
ivygatech | 0:de1ab53f3480 | 246 | pc.printf("Text underline completed.\n"); |
ivygatech | 0:de1ab53f3480 | 247 | #endif |
ivygatech | 0:de1ab53f3480 | 248 | } |
ivygatech | 0:de1ab53f3480 | 249 | |
ivygatech | 0:de1ab53f3480 | 250 | //**************************************************************************************************** |
ivygatech | 0:de1ab53f3480 | 251 | void uVGAIII :: text_attributes(int value) { // Set text attributes: bold, italic, inverse, underlined |
ivygatech | 0:de1ab53f3480 | 252 | char command[4] = ""; // For text underline to work, text Y-gap must be set to at least 2 |
ivygatech | 0:de1ab53f3480 | 253 | |
ivygatech | 0:de1ab53f3480 | 254 | command[0] = (TEXTATTRIBU >> 8) & 0xFF; |
ivygatech | 0:de1ab53f3480 | 255 | command[1] = TEXTATTRIBU & 0xFF; |
ivygatech | 0:de1ab53f3480 | 256 | |
ivygatech | 0:de1ab53f3480 | 257 | command[2] = (value >> 8) & 0xFF; |
ivygatech | 0:de1ab53f3480 | 258 | command[3] = value & 0xFF; |
ivygatech | 0:de1ab53f3480 | 259 | |
ivygatech | 0:de1ab53f3480 | 260 | writeCOMMAND(command, 4, 3); |
ivygatech | 0:de1ab53f3480 | 261 | |
ivygatech | 0:de1ab53f3480 | 262 | #if DEBUGMODE |
ivygatech | 0:de1ab53f3480 | 263 | pc.printf("Text attributes completed.\n"); |
ivygatech | 0:de1ab53f3480 | 264 | #endif |
ivygatech | 0:de1ab53f3480 | 265 | } |
ivygatech | 0:de1ab53f3480 | 266 | |
ivygatech | 0:de1ab53f3480 | 267 | //**************************************************************************************************** |
ivygatech | 0:de1ab53f3480 | 268 | void uVGAIII :: move_cursor(int line, int column) { // move cursor |
ivygatech | 0:de1ab53f3480 | 269 | char command[6] = ""; |
ivygatech | 0:de1ab53f3480 | 270 | |
ivygatech | 0:de1ab53f3480 | 271 | command[0] = (MOVECURSOR >> 8) & 0xFF; |
ivygatech | 0:de1ab53f3480 | 272 | command[1] = MOVECURSOR & 0xFF; |
ivygatech | 0:de1ab53f3480 | 273 | |
ivygatech | 0:de1ab53f3480 | 274 | command[2] = (line >> 8) & 0xFF; |
ivygatech | 0:de1ab53f3480 | 275 | command[3] = line & 0xFF; |
ivygatech | 0:de1ab53f3480 | 276 | |
ivygatech | 0:de1ab53f3480 | 277 | command[4] = (column >> 8) & 0xFF; |
ivygatech | 0:de1ab53f3480 | 278 | command[5] = column & 0xFF; |
ivygatech | 0:de1ab53f3480 | 279 | |
ivygatech | 0:de1ab53f3480 | 280 | writeCOMMAND(command, 6, 1); |
ivygatech | 0:de1ab53f3480 | 281 | current_row = line; |
ivygatech | 0:de1ab53f3480 | 282 | current_col = column; |
ivygatech | 0:de1ab53f3480 | 283 | |
ivygatech | 0:de1ab53f3480 | 284 | #if DEBUGMODE |
ivygatech | 0:de1ab53f3480 | 285 | pc.printf("Move cursor completed.\n"); |
ivygatech | 0:de1ab53f3480 | 286 | #endif |
ivygatech | 0:de1ab53f3480 | 287 | } |
ivygatech | 0:de1ab53f3480 | 288 | |
ivygatech | 0:de1ab53f3480 | 289 | //**************************************************************************************************** |
ivygatech | 0:de1ab53f3480 | 290 | void uVGAIII :: put_char(char c) { // draw a text char |
ivygatech | 0:de1ab53f3480 | 291 | char command[4] = ""; |
ivygatech | 0:de1ab53f3480 | 292 | |
ivygatech | 0:de1ab53f3480 | 293 | command[0] = (PUTCHAR >> 8) & 0xFF; |
ivygatech | 0:de1ab53f3480 | 294 | command[1] = PUTCHAR & 0xFF; |
ivygatech | 0:de1ab53f3480 | 295 | |
ivygatech | 0:de1ab53f3480 | 296 | command[2] = 0x00; |
ivygatech | 0:de1ab53f3480 | 297 | command[3] = c; |
ivygatech | 0:de1ab53f3480 | 298 | |
ivygatech | 0:de1ab53f3480 | 299 | writeCOMMAND(command, 4, 1); |
ivygatech | 0:de1ab53f3480 | 300 | |
ivygatech | 0:de1ab53f3480 | 301 | #if DEBUGMODE |
ivygatech | 0:de1ab53f3480 | 302 | pc.printf("Put character completed.\n"); |
ivygatech | 0:de1ab53f3480 | 303 | #endif |
ivygatech | 0:de1ab53f3480 | 304 | } |
ivygatech | 0:de1ab53f3480 | 305 | |
ivygatech | 0:de1ab53f3480 | 306 | //**************************************************************************************************** |
ivygatech | 0:de1ab53f3480 | 307 | void uVGAIII :: put_string(char *s) { // draw a text string |
ivygatech | 0:de1ab53f3480 | 308 | |
ivygatech | 0:de1ab53f3480 | 309 | char command[1000]= ""; |
ivygatech | 0:de1ab53f3480 | 310 | int size = strlen(s); |
ivygatech | 0:de1ab53f3480 | 311 | int i = 0; |
ivygatech | 0:de1ab53f3480 | 312 | |
ivygatech | 0:de1ab53f3480 | 313 | command[0] = (PUTSTRING >> 8) & 0xFF; |
ivygatech | 0:de1ab53f3480 | 314 | command[1] = PUTSTRING & 0xFF; |
ivygatech | 0:de1ab53f3480 | 315 | |
ivygatech | 0:de1ab53f3480 | 316 | for (i=0; i<size; i++) command[2+i] = s[i]; |
ivygatech | 0:de1ab53f3480 | 317 | |
ivygatech | 0:de1ab53f3480 | 318 | command[2+size] = 0; |
ivygatech | 0:de1ab53f3480 | 319 | |
ivygatech | 0:de1ab53f3480 | 320 | writeCOMMAND(command, 3 + size, 1); |
ivygatech | 0:de1ab53f3480 | 321 | |
ivygatech | 0:de1ab53f3480 | 322 | #if DEBUGMODE |
ivygatech | 0:de1ab53f3480 | 323 | pc.printf("Put string completed.\n"); |
ivygatech | 0:de1ab53f3480 | 324 | #endif |
ivygatech | 0:de1ab53f3480 | 325 | } |
ivygatech | 0:de1ab53f3480 | 326 | |
ivygatech | 0:de1ab53f3480 | 327 | //**************************************************************************************************** |
ivygatech | 0:de1ab53f3480 | 328 | void uVGAIII :: text_fgd_color(int color) { // Set text foreground color |
ivygatech | 0:de1ab53f3480 | 329 | char command[4] = ""; |
ivygatech | 0:de1ab53f3480 | 330 | |
ivygatech | 0:de1ab53f3480 | 331 | command[0] = (TEXTFGCOLOR >> 8) & 0xFF; |
ivygatech | 0:de1ab53f3480 | 332 | command[1] = TEXTFGCOLOR & 0xFF; |
ivygatech | 0:de1ab53f3480 | 333 | |
ivygatech | 0:de1ab53f3480 | 334 | current_color = color; |
ivygatech | 0:de1ab53f3480 | 335 | |
ivygatech | 0:de1ab53f3480 | 336 | int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits |
ivygatech | 0:de1ab53f3480 | 337 | int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits |
ivygatech | 0:de1ab53f3480 | 338 | int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits |
ivygatech | 0:de1ab53f3480 | 339 | |
ivygatech | 0:de1ab53f3480 | 340 | command[2] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color |
ivygatech | 0:de1ab53f3480 | 341 | command[3] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color |
ivygatech | 0:de1ab53f3480 | 342 | |
ivygatech | 0:de1ab53f3480 | 343 | writeCOMMAND(command, 4, 3); |
ivygatech | 0:de1ab53f3480 | 344 | |
ivygatech | 0:de1ab53f3480 | 345 | #if DEBUGMODE |
ivygatech | 0:de1ab53f3480 | 346 | pc.printf("Set text foreground color completed.\n"); |
ivygatech | 0:de1ab53f3480 | 347 | #endif |
ivygatech | 0:de1ab53f3480 | 348 | } |
ivygatech | 0:de1ab53f3480 | 349 | |
ivygatech | 0:de1ab53f3480 | 350 | //**************************************************************************************************** |
ivygatech | 0:de1ab53f3480 | 351 | void uVGAIII :: text_bgd_color(int color) { // Set text background color |
ivygatech | 0:de1ab53f3480 | 352 | char command[4] = ""; |
ivygatech | 0:de1ab53f3480 | 353 | |
ivygatech | 0:de1ab53f3480 | 354 | command[0] = (TEXTBGCOLOR >> 8) & 0xFF; |
ivygatech | 0:de1ab53f3480 | 355 | command[1] = TEXTBGCOLOR & 0xFF; |
ivygatech | 0:de1ab53f3480 | 356 | |
ivygatech | 0:de1ab53f3480 | 357 | int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits |
ivygatech | 0:de1ab53f3480 | 358 | int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits |
ivygatech | 0:de1ab53f3480 | 359 | int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits |
ivygatech | 0:de1ab53f3480 | 360 | |
ivygatech | 0:de1ab53f3480 | 361 | command[2] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color |
ivygatech | 0:de1ab53f3480 | 362 | command[3] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color |
ivygatech | 0:de1ab53f3480 | 363 | |
ivygatech | 0:de1ab53f3480 | 364 | writeCOMMAND(command, 4, 3); |
ivygatech | 0:de1ab53f3480 | 365 | |
ivygatech | 0:de1ab53f3480 | 366 | #if DEBUGMODE |
ivygatech | 0:de1ab53f3480 | 367 | pc.printf("Set text foreground color completed.\n"); |
ivygatech | 0:de1ab53f3480 | 368 | #endif |
ivygatech | 0:de1ab53f3480 | 369 | } |
ivygatech | 0:de1ab53f3480 | 370 | |
ivygatech | 0:de1ab53f3480 | 371 | //**************************************************************************************************** |
ivygatech | 0:de1ab53f3480 | 372 | void uVGAIII :: putc(char c) // place char at current cursor position |
ivygatech | 0:de1ab53f3480 | 373 | //used by virtual printf function _putc |
ivygatech | 0:de1ab53f3480 | 374 | { |
ivygatech | 0:de1ab53f3480 | 375 | |
ivygatech | 0:de1ab53f3480 | 376 | pc.printf("\nCursor position: %d, %d",current_row,current_col); |
ivygatech | 0:de1ab53f3480 | 377 | if(c<0x20) { |
ivygatech | 0:de1ab53f3480 | 378 | if(c=='\n') { |
ivygatech | 0:de1ab53f3480 | 379 | current_col = 0; |
ivygatech | 0:de1ab53f3480 | 380 | current_row++; |
ivygatech | 0:de1ab53f3480 | 381 | move_cursor(current_row, current_col); |
ivygatech | 0:de1ab53f3480 | 382 | } |
ivygatech | 0:de1ab53f3480 | 383 | if(c=='\r') { |
ivygatech | 0:de1ab53f3480 | 384 | current_col = 0; |
ivygatech | 0:de1ab53f3480 | 385 | move_cursor(current_row, current_col); |
ivygatech | 0:de1ab53f3480 | 386 | } |
ivygatech | 0:de1ab53f3480 | 387 | if(c=='\f') { |
ivygatech | 0:de1ab53f3480 | 388 | cls(); //clear screen on form feed |
ivygatech | 0:de1ab53f3480 | 389 | } |
ivygatech | 0:de1ab53f3480 | 390 | } else { |
ivygatech | 0:de1ab53f3480 | 391 | put_char(c); |
ivygatech | 0:de1ab53f3480 | 392 | current_col++; |
ivygatech | 0:de1ab53f3480 | 393 | move_cursor(current_row, current_col); |
ivygatech | 0:de1ab53f3480 | 394 | } |
ivygatech | 0:de1ab53f3480 | 395 | if (current_col >= max_col) { |
ivygatech | 0:de1ab53f3480 | 396 | current_col = 0; |
ivygatech | 0:de1ab53f3480 | 397 | current_row++; |
ivygatech | 0:de1ab53f3480 | 398 | move_cursor(current_row, current_col); |
ivygatech | 0:de1ab53f3480 | 399 | } |
ivygatech | 0:de1ab53f3480 | 400 | if (current_row >= max_row) { |
ivygatech | 0:de1ab53f3480 | 401 | current_row = 0; |
ivygatech | 0:de1ab53f3480 | 402 | move_cursor(current_row, current_col); |
ivygatech | 0:de1ab53f3480 | 403 | } |
ivygatech | 0:de1ab53f3480 | 404 | } |
ivygatech | 0:de1ab53f3480 | 405 | |
ivygatech | 0:de1ab53f3480 | 406 | //**************************************************************************************************** |
ivygatech | 0:de1ab53f3480 | 407 | void uVGAIII :: puts(char *s) { // place string at current cursor position |
ivygatech | 0:de1ab53f3480 | 408 | |
ivygatech | 0:de1ab53f3480 | 409 | put_string(s); |
ivygatech | 0:de1ab53f3480 | 410 | |
ivygatech | 0:de1ab53f3480 | 411 | current_col += strlen(s); |
ivygatech | 0:de1ab53f3480 | 412 | |
ivygatech | 0:de1ab53f3480 | 413 | if (current_col >= max_col) { |
ivygatech | 0:de1ab53f3480 | 414 | current_row += current_col / max_col; |
ivygatech | 0:de1ab53f3480 | 415 | current_col %= max_col; |
ivygatech | 0:de1ab53f3480 | 416 | } |
ivygatech | 0:de1ab53f3480 | 417 | if (current_row >= max_row) { |
ivygatech | 0:de1ab53f3480 | 418 | current_row %= max_row; |
ivygatech | 0:de1ab53f3480 | 419 | } |
ivygatech | 0:de1ab53f3480 | 420 | } |