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

uVGA III