Demo of low res colour vga video for stm32f3 discovery board
Dependencies: STM32F3-Discovery-minimal
Fork of Space_Invaders_Demo by
gdi.c@17:833f1b69e11d, 2019-04-03 (annotated)
- Committer:
- MartinJohnson
- Date:
- Wed Apr 03 22:05:56 2019 +0000
- Revision:
- 17:833f1b69e11d
- Parent:
- 14:3035b3271395
update library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MartinJohnson | 0:404dae88af71 | 1 | /*************************************************************************** |
MartinJohnson | 0:404dae88af71 | 2 | * STM32 VGA demo |
MartinJohnson | 0:404dae88af71 | 3 | * Copyright (C) 2012 Artekit Italy |
MartinJohnson | 0:404dae88af71 | 4 | * http://www.artekit.eu |
MartinJohnson | 0:404dae88af71 | 5 | * Written by Ruben H. Meleca |
MartinJohnson | 0:404dae88af71 | 6 | |
MartinJohnson | 0:404dae88af71 | 7 | ### gdi.c |
MartinJohnson | 0:404dae88af71 | 8 | |
MartinJohnson | 0:404dae88af71 | 9 | # This program is free software; you can redistribute it and/or modify |
MartinJohnson | 0:404dae88af71 | 10 | # it under the terms of the GNU General Public License as published by |
MartinJohnson | 0:404dae88af71 | 11 | # the Free Software Foundation; either version 2 of the License, or |
MartinJohnson | 0:404dae88af71 | 12 | # (at your option) any later version. |
MartinJohnson | 0:404dae88af71 | 13 | # |
MartinJohnson | 0:404dae88af71 | 14 | # This program is distributed in the hope that it will be useful, |
MartinJohnson | 0:404dae88af71 | 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
MartinJohnson | 0:404dae88af71 | 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
MartinJohnson | 0:404dae88af71 | 17 | # GNU General Public License for more details. |
MartinJohnson | 0:404dae88af71 | 18 | # |
MartinJohnson | 0:404dae88af71 | 19 | # You should have received a copy of the GNU General Public License |
MartinJohnson | 0:404dae88af71 | 20 | # along with this program; if not, write to the Free Software |
MartinJohnson | 0:404dae88af71 | 21 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
MartinJohnson | 0:404dae88af71 | 22 | |
MartinJohnson | 0:404dae88af71 | 23 | ***************************************************************************/ |
MartinJohnson | 0:404dae88af71 | 24 | |
MartinJohnson | 0:404dae88af71 | 25 | #include "gdi.h" |
MartinJohnson | 0:404dae88af71 | 26 | #include "mth.h" |
MartinJohnson | 0:404dae88af71 | 27 | #include "video.h" |
MartinJohnson | 0:404dae88af71 | 28 | #include "stm32f30x.h" |
MartinJohnson | 0:404dae88af71 | 29 | |
MartinJohnson | 0:404dae88af71 | 30 | extern u8 *fb[VID_VSIZE];// *(VID_HSIZE+2)]; |
MartinJohnson | 0:404dae88af71 | 31 | extern const u8 gdiSystemFont[]; |
MartinJohnson | 14:3035b3271395 | 32 | extern const u8 font6x8[]; |
MartinJohnson | 14:3035b3271395 | 33 | |
MartinJohnson | 0:404dae88af71 | 34 | |
MartinJohnson | 0:404dae88af71 | 35 | #define CCM __attribute__ ((section (".ccmram"))) |
MartinJohnson | 0:404dae88af71 | 36 | const u8 gdiCloseBm[] = { 0x7f, 0xC0, |
MartinJohnson | 0:404dae88af71 | 37 | 0x7f, 0xC0, |
MartinJohnson | 0:404dae88af71 | 38 | 0x7f, 0xC0, |
MartinJohnson | 0:404dae88af71 | 39 | 0x7f, 0xC0, |
MartinJohnson | 0:404dae88af71 | 40 | 0x40, 0x40, |
MartinJohnson | 0:404dae88af71 | 41 | 0x7f, 0xC0, |
MartinJohnson | 0:404dae88af71 | 42 | 0x7f, 0xC0, |
MartinJohnson | 0:404dae88af71 | 43 | 0x7f, 0xC0, |
MartinJohnson | 0:404dae88af71 | 44 | 0x7f, 0xC0 }; |
MartinJohnson | 0:404dae88af71 | 45 | |
MartinJohnson | 3:93e488fbb8a2 | 46 | int colour=7; |
MartinJohnson | 0:404dae88af71 | 47 | |
MartinJohnson | 0:404dae88af71 | 48 | u16 strLen(pu8 str) { |
MartinJohnson | 0:404dae88af71 | 49 | |
MartinJohnson | 0:404dae88af71 | 50 | int i = 0; |
MartinJohnson | 0:404dae88af71 | 51 | |
MartinJohnson | 0:404dae88af71 | 52 | while (*str != 0) { |
MartinJohnson | 0:404dae88af71 | 53 | ++i; |
MartinJohnson | 0:404dae88af71 | 54 | ++str; |
MartinJohnson | 0:404dae88af71 | 55 | } |
MartinJohnson | 0:404dae88af71 | 56 | return(i); |
MartinJohnson | 0:404dae88af71 | 57 | } |
MartinJohnson | 0:404dae88af71 | 58 | |
MartinJohnson | 0:404dae88af71 | 59 | // ***************************************************************************** |
MartinJohnson | 0:404dae88af71 | 60 | // Function gdiCopyRect(PGDI_RECT rc1, PGDI_RECT rc2) |
MartinJohnson | 0:404dae88af71 | 61 | // |
MartinJohnson | 0:404dae88af71 | 62 | // Copy rectangle rc2 to rc1 |
MartinJohnson | 0:404dae88af71 | 63 | // |
MartinJohnson | 0:404dae88af71 | 64 | // parameters: |
MartinJohnson | 0:404dae88af71 | 65 | // rc1 Destination rectangle |
MartinJohnson | 0:404dae88af71 | 66 | // y Source rectangle |
MartinJohnson | 0:404dae88af71 | 67 | // |
MartinJohnson | 0:404dae88af71 | 68 | // return: none |
MartinJohnson | 0:404dae88af71 | 69 | // ***************************************************************************** |
MartinJohnson | 0:404dae88af71 | 70 | void gdiCopyRect(PGDI_RECT rc1, PGDI_RECT rc2) { |
MartinJohnson | 0:404dae88af71 | 71 | |
MartinJohnson | 0:404dae88af71 | 72 | rc1->x = rc2->x; |
MartinJohnson | 0:404dae88af71 | 73 | rc1->y = rc2->y; |
MartinJohnson | 0:404dae88af71 | 74 | rc1->w = rc2->w; |
MartinJohnson | 0:404dae88af71 | 75 | rc1->h = rc2->h; |
MartinJohnson | 0:404dae88af71 | 76 | } |
MartinJohnson | 0:404dae88af71 | 77 | |
MartinJohnson | 0:404dae88af71 | 78 | // ***************************************************************************** |
MartinJohnson | 0:404dae88af71 | 79 | // Function gdiBitBlt(PGDI_RECT prc, i16 x, i16 y, i16 w, i16 h, pu8 bm, u16 rop) |
MartinJohnson | 0:404dae88af71 | 80 | // |
MartinJohnson | 0:404dae88af71 | 81 | // Bit Block Transfer funcion. This function uses the STM32 Bit-Banding mode |
MartinJohnson | 0:404dae88af71 | 82 | // to simplify the complex BitBlt functionality. |
MartinJohnson | 0:404dae88af71 | 83 | // |
MartinJohnson | 0:404dae88af71 | 84 | // From Cortex STM32F10x Reference Manual (RM0008): |
MartinJohnson | 0:404dae88af71 | 85 | // A mapping formula shows how to reference each word in the alias region to a |
MartinJohnson | 0:404dae88af71 | 86 | // corresponding bit in the bit-band region. The mapping formula is: |
MartinJohnson | 3:93e488fbb8a2 | 87 | // bit_word_addr = bit_band_base + (byte_offset x 32) + (bit_number � 4) |
MartinJohnson | 0:404dae88af71 | 88 | // where: |
MartinJohnson | 0:404dae88af71 | 89 | // bit_word_addr is the address of the word in the alias memory region that |
MartinJohnson | 0:404dae88af71 | 90 | // maps to the targeted bit. |
MartinJohnson | 0:404dae88af71 | 91 | // bit_band_base is the starting address of the alias region |
MartinJohnson | 0:404dae88af71 | 92 | // byte_offset is the number of the byte in the bit-band region that contains |
MartinJohnson | 0:404dae88af71 | 93 | // the targeted bit bit_number is the bit position (0-7) of the targeted bit. |
MartinJohnson | 0:404dae88af71 | 94 | // Example: |
MartinJohnson | 0:404dae88af71 | 95 | // The following example shows how to map bit 2 of the byte located at SRAM |
MartinJohnson | 0:404dae88af71 | 96 | // address 0x20000300 in the alias region: |
MartinJohnson | 0:404dae88af71 | 97 | // 0x22006008 = 0x22000000 + (0x300*32) + (2*4). |
MartinJohnson | 0:404dae88af71 | 98 | // Writing to address 0x22006008 has the same effect as a read-modify-write |
MartinJohnson | 0:404dae88af71 | 99 | // operation on bit 2 of the byte at SRAM address 0x20000300. |
MartinJohnson | 0:404dae88af71 | 100 | // Reading address 0x22006008 returns the value (0x01 or 0x00) of bit 2 of |
MartinJohnson | 0:404dae88af71 | 101 | // the byte at SRAM address 0x20000300 (0x01: bit set; 0x00: bit reset). |
MartinJohnson | 0:404dae88af71 | 102 | // |
MartinJohnson | 0:404dae88af71 | 103 | // For further reference see the Cortex M3 Technical Reference Manual |
MartinJohnson | 0:404dae88af71 | 104 | // |
MartinJohnson | 0:404dae88af71 | 105 | // Parameters: |
MartinJohnson | 0:404dae88af71 | 106 | // |
MartinJohnson | 0:404dae88af71 | 107 | // prc Clipping rectangle. All X/Y coordinates are inside "prc" |
MartinJohnson | 0:404dae88af71 | 108 | // If "prc" is NULL, the coordinates will be the entire display |
MartinJohnson | 0:404dae88af71 | 109 | // area |
MartinJohnson | 0:404dae88af71 | 110 | // x Bitmap X start position |
MartinJohnson | 0:404dae88af71 | 111 | // y Bitmap Y start position |
MartinJohnson | 0:404dae88af71 | 112 | // w Bitmap width, in pixels |
MartinJohnson | 0:404dae88af71 | 113 | // y Bitmap height, in pixels |
MartinJohnson | 0:404dae88af71 | 114 | // bm Pointer to te bitmap start position |
MartinJohnson | 0:404dae88af71 | 115 | // rop Raster operation. See GDI_ROP_xxx defines |
MartinJohnson | 0:404dae88af71 | 116 | // |
MartinJohnson | 0:404dae88af71 | 117 | // return none |
MartinJohnson | 0:404dae88af71 | 118 | // **************************************************************************** |
MartinJohnson | 0:404dae88af71 | 119 | |
MartinJohnson | 0:404dae88af71 | 120 | u8 leftmask[]={0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe}; |
MartinJohnson | 0:404dae88af71 | 121 | u8 rightmask[]={0x0,0x1,0x3,0x7,0xf,0x1f,0x3f,0x7f}; |
MartinJohnson | 0:404dae88af71 | 122 | CCM void gdiBitBlt(PGDI_RECT prc, i16 x, i16 y, i16 w, i16 h, pu8 bm, u16 rop) { |
MartinJohnson | 0:404dae88af71 | 123 | |
MartinJohnson | 0:404dae88af71 | 124 | u16 i, xz, xb, xt; |
MartinJohnson | 0:404dae88af71 | 125 | u32 wb; // Width in bytes |
MartinJohnson | 0:404dae88af71 | 126 | u32 r,rr; // Start X position in bits (relative to x) |
MartinJohnson | 0:404dae88af71 | 127 | u32 k; |
MartinJohnson | 0:404dae88af71 | 128 | u32 d; |
MartinJohnson | 0:404dae88af71 | 129 | u32 offs; |
MartinJohnson | 0:404dae88af71 | 130 | u8 c; |
MartinJohnson | 0:404dae88af71 | 131 | pu8 fbPtr; // Pointer to the Frame Buffer Bit-Band area |
MartinJohnson | 0:404dae88af71 | 132 | pu8 fbBak; |
MartinJohnson | 0:404dae88af71 | 133 | u8 fb1; |
MartinJohnson | 0:404dae88af71 | 134 | u32 fb2; |
MartinJohnson | 0:404dae88af71 | 135 | u32 rp; |
MartinJohnson | 0:404dae88af71 | 136 | pu8 bmPtr; // Pointer to the bitmap bits |
MartinJohnson | 0:404dae88af71 | 137 | |
MartinJohnson | 0:404dae88af71 | 138 | // Calculate clipping region |
MartinJohnson | 0:404dae88af71 | 139 | if (prc != NULL) { |
MartinJohnson | 0:404dae88af71 | 140 | x = prc->x + x; |
MartinJohnson | 0:404dae88af71 | 141 | y = prc->y + y; |
MartinJohnson | 0:404dae88af71 | 142 | } |
MartinJohnson | 0:404dae88af71 | 143 | |
MartinJohnson | 0:404dae88af71 | 144 | // Get total bitmap width in bytes |
MartinJohnson | 0:404dae88af71 | 145 | |
MartinJohnson | 0:404dae88af71 | 146 | wb = (u32) (w+7) >> 3; |
MartinJohnson | 0:404dae88af71 | 147 | // if ((wb << 3) < (u32) w) ++wb; |
MartinJohnson | 0:404dae88af71 | 148 | |
MartinJohnson | 0:404dae88af71 | 149 | // Get starting bit inside the first byte |
MartinJohnson | 0:404dae88af71 | 150 | |
MartinJohnson | 0:404dae88af71 | 151 | r=x&7; |
MartinJohnson | 0:404dae88af71 | 152 | xb=x>>3; |
MartinJohnson | 0:404dae88af71 | 153 | |
MartinJohnson | 0:404dae88af71 | 154 | rr=7-((w+r)&7); // no of bits to mask at end of bitmap |
MartinJohnson | 0:404dae88af71 | 155 | |
MartinJohnson | 0:404dae88af71 | 156 | // Clip X |
MartinJohnson | 0:404dae88af71 | 157 | |
MartinJohnson | 0:404dae88af71 | 158 | if (prc == NULL) { |
MartinJohnson | 0:404dae88af71 | 159 | if ((x + w) >= VID_PIXELS_X ) { |
MartinJohnson | 0:404dae88af71 | 160 | xt = VID_PIXELS_X - x; |
MartinJohnson | 0:404dae88af71 | 161 | } else { |
MartinJohnson | 0:404dae88af71 | 162 | xt = w; |
MartinJohnson | 0:404dae88af71 | 163 | } |
MartinJohnson | 0:404dae88af71 | 164 | } else { |
MartinJohnson | 0:404dae88af71 | 165 | if ((x + w) >= (x + prc->w)) { |
MartinJohnson | 0:404dae88af71 | 166 | xt = prc->w - x; |
MartinJohnson | 0:404dae88af71 | 167 | } else { |
MartinJohnson | 0:404dae88af71 | 168 | xt = w; |
MartinJohnson | 0:404dae88af71 | 169 | } |
MartinJohnson | 0:404dae88af71 | 170 | } |
MartinJohnson | 0:404dae88af71 | 171 | |
MartinJohnson | 0:404dae88af71 | 172 | // Draw bits |
MartinJohnson | 3:93e488fbb8a2 | 173 | /* |
MartinJohnson | 0:404dae88af71 | 174 | for (i = 0; i < h; i++) { |
MartinJohnson | 0:404dae88af71 | 175 | u8 lst=0,d; |
MartinJohnson | 0:404dae88af71 | 176 | // Clip Y |
MartinJohnson | 0:404dae88af71 | 177 | bmPtr = bm + ((u32) i * wb); |
MartinJohnson | 0:404dae88af71 | 178 | if ((i + y) > (VID_VSIZE - 1)) return; |
MartinJohnson | 0:404dae88af71 | 179 | if(rop==GDI_ROP_COPY) { |
MartinJohnson | 0:404dae88af71 | 180 | c = *bmPtr++; |
MartinJohnson | 0:404dae88af71 | 181 | if((w+r)<8) |
MartinJohnson | 0:404dae88af71 | 182 | fb[i+y][xb] = (fb[i+y][xb]&(leftmask[r]|rightmask[rr]))|(c>>r); |
MartinJohnson | 0:404dae88af71 | 183 | else { |
MartinJohnson | 0:404dae88af71 | 184 | fb[i+y][xb] = (fb[i+y][xb]&leftmask[r])|(c>>r); |
MartinJohnson | 0:404dae88af71 | 185 | lst=(c<<(8-r)); |
MartinJohnson | 0:404dae88af71 | 186 | for(xz=1;xz<wb;xz++) { |
MartinJohnson | 0:404dae88af71 | 187 | c = *bmPtr++; |
MartinJohnson | 0:404dae88af71 | 188 | fb[i+y][xz+xb]=((c>>r)|lst); |
MartinJohnson | 0:404dae88af71 | 189 | lst=(c<<(8-r)); |
MartinJohnson | 0:404dae88af71 | 190 | } |
MartinJohnson | 0:404dae88af71 | 191 | fb[i+y][xb+wb] = (fb[i+y][xb+wb]&rightmask[rr])|lst; |
MartinJohnson | 0:404dae88af71 | 192 | } |
MartinJohnson | 0:404dae88af71 | 193 | } |
MartinJohnson | 0:404dae88af71 | 194 | if(rop==GDI_ROP_XOR) { |
MartinJohnson | 0:404dae88af71 | 195 | for(xz=0;xz<wb;xz++) { |
MartinJohnson | 0:404dae88af71 | 196 | c = *bmPtr++; |
MartinJohnson | 0:404dae88af71 | 197 | fb[i+y][xz+xb]^=((c>>r)|lst); |
MartinJohnson | 0:404dae88af71 | 198 | lst=(c<<(8-r)); |
MartinJohnson | 0:404dae88af71 | 199 | } |
MartinJohnson | 0:404dae88af71 | 200 | if((w+r)>8) |
MartinJohnson | 0:404dae88af71 | 201 | fb[i+y][xz+xb]^=lst; |
MartinJohnson | 0:404dae88af71 | 202 | } |
MartinJohnson | 0:404dae88af71 | 203 | if(rop==GDI_ROP_OR) { |
MartinJohnson | 0:404dae88af71 | 204 | for(xz=0;xz<wb;xz++) { |
MartinJohnson | 0:404dae88af71 | 205 | c = *bmPtr++; |
MartinJohnson | 0:404dae88af71 | 206 | fb[i+y][xz+xb]|=((c>>r)|lst); |
MartinJohnson | 0:404dae88af71 | 207 | lst=(c<<(8-r)); |
MartinJohnson | 0:404dae88af71 | 208 | } |
MartinJohnson | 0:404dae88af71 | 209 | if((w+r)>8) |
MartinJohnson | 0:404dae88af71 | 210 | fb[i+y][xz+xb]|=lst; |
MartinJohnson | 0:404dae88af71 | 211 | } |
MartinJohnson | 0:404dae88af71 | 212 | |
MartinJohnson | 3:93e488fbb8a2 | 213 | */ |
MartinJohnson | 0:404dae88af71 | 214 | |
MartinJohnson | 0:404dae88af71 | 215 | // Get offset to frame buffer in bit-banding mode |
MartinJohnson | 3:93e488fbb8a2 | 216 | for (i = 0; i < h; i++) { |
MartinJohnson | 3:93e488fbb8a2 | 217 | u8 lst=0,d; |
MartinJohnson | 3:93e488fbb8a2 | 218 | |
MartinJohnson | 0:404dae88af71 | 219 | /* |
MartinJohnson | 0:404dae88af71 | 220 | offs = (((u32) x >> 3)) + ((u32) (y + i) * VID_HSIZE_R); |
MartinJohnson | 0:404dae88af71 | 221 | k = (u32) (&fb - 0x20000000); |
MartinJohnson | 0:404dae88af71 | 222 | k += offs; |
MartinJohnson | 0:404dae88af71 | 223 | fbPtr = (pu8) (0x22000000 + (k * 32) + ((7 - r) * 4)); |
MartinJohnson | 0:404dae88af71 | 224 | fbBak = (pu8) (0x22000000 + (k * 32) + 28); |
MartinJohnson | 3:93e488fbb8a2 | 225 | */ |
MartinJohnson | 3:93e488fbb8a2 | 226 | |
MartinJohnson | 3:93e488fbb8a2 | 227 | fbPtr = fb[y+i]+x; |
MartinJohnson | 3:93e488fbb8a2 | 228 | if(fbPtr > fb[VID_VSIZE-1]) return; |
MartinJohnson | 0:404dae88af71 | 229 | |
MartinJohnson | 0:404dae88af71 | 230 | // Get offset to bitmap bits |
MartinJohnson | 0:404dae88af71 | 231 | |
MartinJohnson | 0:404dae88af71 | 232 | bmPtr = bm + ((u32) i * wb); |
MartinJohnson | 0:404dae88af71 | 233 | xz = w; |
MartinJohnson | 0:404dae88af71 | 234 | |
MartinJohnson | 0:404dae88af71 | 235 | xb = 0; |
MartinJohnson | 0:404dae88af71 | 236 | for (xz = 0; xz < xt; xz++) { |
MartinJohnson | 3:93e488fbb8a2 | 237 | //fb1 = ((u32) fbPtr) & 0x000000E0; |
MartinJohnson | 3:93e488fbb8a2 | 238 | if(x+xz > VID_HSIZE) break; |
MartinJohnson | 0:404dae88af71 | 239 | if (xb++ == 0) { |
MartinJohnson | 0:404dae88af71 | 240 | c = *bmPtr; |
MartinJohnson | 0:404dae88af71 | 241 | ++bmPtr; |
MartinJohnson | 0:404dae88af71 | 242 | } |
MartinJohnson | 0:404dae88af71 | 243 | xb &= 0x07; |
MartinJohnson | 3:93e488fbb8a2 | 244 | (c & 0x80) ? (rp = colour<<4) : (rp = 0); |
MartinJohnson | 0:404dae88af71 | 245 | switch(rop) { |
MartinJohnson | 3:93e488fbb8a2 | 246 | case GDI_ROP_COPY: *fbPtr |= rp; break; |
MartinJohnson | 0:404dae88af71 | 247 | case GDI_ROP_XOR: *fbPtr ^= rp; break; |
MartinJohnson | 0:404dae88af71 | 248 | case GDI_ROP_AND: *fbPtr &= rp; break; |
MartinJohnson | 0:404dae88af71 | 249 | case GDI_ROP_OR: *fbPtr |= rp; break; |
MartinJohnson | 0:404dae88af71 | 250 | } |
MartinJohnson | 3:93e488fbb8a2 | 251 | fbPtr += 1; |
MartinJohnson | 3:93e488fbb8a2 | 252 | |
MartinJohnson | 3:93e488fbb8a2 | 253 | /* |
MartinJohnson | 0:404dae88af71 | 254 | fb2 = ((u32) fbPtr) & 0x000000E0; |
MartinJohnson | 0:404dae88af71 | 255 | if (fb1 != fb2) { |
MartinJohnson | 0:404dae88af71 | 256 | fbPtr = fbBak + 32; |
MartinJohnson | 0:404dae88af71 | 257 | fbBak = fbPtr; |
MartinJohnson | 0:404dae88af71 | 258 | } |
MartinJohnson | 3:93e488fbb8a2 | 259 | */ |
MartinJohnson | 0:404dae88af71 | 260 | c <<= 1; |
MartinJohnson | 0:404dae88af71 | 261 | } |
MartinJohnson | 3:93e488fbb8a2 | 262 | |
MartinJohnson | 0:404dae88af71 | 263 | } |
MartinJohnson | 0:404dae88af71 | 264 | } |
MartinJohnson | 3:93e488fbb8a2 | 265 | void gdiSetColour(int c) { |
MartinJohnson | 3:93e488fbb8a2 | 266 | colour=c; |
MartinJohnson | 3:93e488fbb8a2 | 267 | } |
MartinJohnson | 0:404dae88af71 | 268 | // ***************************************************************************** |
MartinJohnson | 0:404dae88af71 | 269 | // Function gdiPoint(PGDI_RECT rc, u16 x, u16 y) |
MartinJohnson | 0:404dae88af71 | 270 | // |
MartinJohnson | 0:404dae88af71 | 271 | // Show a point in x/y position using the current graphical mode stored in |
MartinJohnson | 0:404dae88af71 | 272 | // grMode variable |
MartinJohnson | 0:404dae88af71 | 273 | // |
MartinJohnson | 0:404dae88af71 | 274 | // parameters: |
MartinJohnson | 0:404dae88af71 | 275 | // x X position |
MartinJohnson | 0:404dae88af71 | 276 | // y Y position |
MartinJohnson | 0:404dae88af71 | 277 | // rop Raster operation. See GDI_ROP_xxx defines |
MartinJohnson | 0:404dae88af71 | 278 | // |
MartinJohnson | 0:404dae88af71 | 279 | // return: none |
MartinJohnson | 0:404dae88af71 | 280 | // ***************************************************************************** |
MartinJohnson | 3:93e488fbb8a2 | 281 | __attribute__ ((section ("ccmram"))) void gdiPoint(PGDI_RECT rc, u16 x, u16 y, u16 rop) { |
MartinJohnson | 0:404dae88af71 | 282 | |
MartinJohnson | 0:404dae88af71 | 283 | u16 w, r; |
MartinJohnson | 0:404dae88af71 | 284 | u8 m; |
MartinJohnson | 0:404dae88af71 | 285 | |
MartinJohnson | 0:404dae88af71 | 286 | // Test for point outside display area |
MartinJohnson | 0:404dae88af71 | 287 | |
MartinJohnson | 0:404dae88af71 | 288 | if (x >= VID_PIXELS_X || y >= VID_PIXELS_Y) return; |
MartinJohnson | 0:404dae88af71 | 289 | |
MartinJohnson | 3:93e488fbb8a2 | 290 | w = x;// >> 3; |
MartinJohnson | 5:594c9712697c | 291 | //r = x - (w << 3); |
MartinJohnson | 0:404dae88af71 | 292 | |
MartinJohnson | 0:404dae88af71 | 293 | // Prepare mask |
MartinJohnson | 0:404dae88af71 | 294 | |
MartinJohnson | 3:93e488fbb8a2 | 295 | m = colour<<4;//(0x80 >> r); |
MartinJohnson | 0:404dae88af71 | 296 | |
MartinJohnson | 0:404dae88af71 | 297 | switch(rop) { |
MartinJohnson | 0:404dae88af71 | 298 | case GDI_ROP_COPY: fb[y][w] |= m; |
MartinJohnson | 0:404dae88af71 | 299 | break; |
MartinJohnson | 0:404dae88af71 | 300 | case GDI_ROP_XOR: fb[y][w] ^= m; |
MartinJohnson | 0:404dae88af71 | 301 | break; |
MartinJohnson | 0:404dae88af71 | 302 | case GDI_ROP_AND: fb[y][w] &= m; |
MartinJohnson | 0:404dae88af71 | 303 | break; |
MartinJohnson | 0:404dae88af71 | 304 | } |
MartinJohnson | 0:404dae88af71 | 305 | } |
MartinJohnson | 0:404dae88af71 | 306 | |
MartinJohnson | 0:404dae88af71 | 307 | //***************************************************************************** |
MartinJohnson | 0:404dae88af71 | 308 | // Function gdiLine(i16 x1, i16 y1, i16 x2, i16 y2, u16 rop) |
MartinJohnson | 0:404dae88af71 | 309 | // |
MartinJohnson | 0:404dae88af71 | 310 | // Draw line using Bresenham algorithm |
MartinJohnson | 0:404dae88af71 | 311 | // |
MartinJohnson | 0:404dae88af71 | 312 | // This function was taken from the book: |
MartinJohnson | 0:404dae88af71 | 313 | // Interactive Computer Graphics, A top-down approach with OpenGL |
MartinJohnson | 0:404dae88af71 | 314 | // written by Emeritus Edward Angel |
MartinJohnson | 0:404dae88af71 | 315 | // |
MartinJohnson | 0:404dae88af71 | 316 | // parameters: |
MartinJohnson | 0:404dae88af71 | 317 | // prc Clipping rectangle |
MartinJohnson | 0:404dae88af71 | 318 | // x1 X start position |
MartinJohnson | 0:404dae88af71 | 319 | // y1 Y start position |
MartinJohnson | 0:404dae88af71 | 320 | // x2 X end position |
MartinJohnson | 0:404dae88af71 | 321 | // y2 Y end position |
MartinJohnson | 0:404dae88af71 | 322 | // rop Raster operation. See GDI_ROP_xxx defines |
MartinJohnson | 0:404dae88af71 | 323 | // |
MartinJohnson | 0:404dae88af71 | 324 | // return none |
MartinJohnson | 0:404dae88af71 | 325 | //***************************************************************************** |
MartinJohnson | 0:404dae88af71 | 326 | void gdiLine(PGDI_RECT prc, i16 x1, i16 y1, i16 x2, i16 y2, u16 rop) { |
MartinJohnson | 0:404dae88af71 | 327 | |
MartinJohnson | 0:404dae88af71 | 328 | i16 dx, dy, i, e; |
MartinJohnson | 0:404dae88af71 | 329 | i16 incx, incy, inc1, inc2; |
MartinJohnson | 0:404dae88af71 | 330 | i16 x, y; |
MartinJohnson | 0:404dae88af71 | 331 | |
MartinJohnson | 0:404dae88af71 | 332 | dx = x2 - x1; |
MartinJohnson | 0:404dae88af71 | 333 | dy = y2 - y1; |
MartinJohnson | 0:404dae88af71 | 334 | |
MartinJohnson | 0:404dae88af71 | 335 | if(dx < 0) dx = -dx; |
MartinJohnson | 0:404dae88af71 | 336 | if(dy < 0) dy = -dy; |
MartinJohnson | 0:404dae88af71 | 337 | incx = 1; |
MartinJohnson | 0:404dae88af71 | 338 | if(x2 < x1) incx = -1; |
MartinJohnson | 0:404dae88af71 | 339 | incy = 1; |
MartinJohnson | 0:404dae88af71 | 340 | if(y2 < y1) incy = -1; |
MartinJohnson | 0:404dae88af71 | 341 | x=x1; |
MartinJohnson | 0:404dae88af71 | 342 | y=y1; |
MartinJohnson | 0:404dae88af71 | 343 | |
MartinJohnson | 0:404dae88af71 | 344 | if (dx > dy) { |
MartinJohnson | 0:404dae88af71 | 345 | gdiPoint(prc, x, y, rop); |
MartinJohnson | 0:404dae88af71 | 346 | e = 2*dy - dx; |
MartinJohnson | 0:404dae88af71 | 347 | inc1 = 2 * ( dy -dx); |
MartinJohnson | 0:404dae88af71 | 348 | inc2 = 2 * dy; |
MartinJohnson | 0:404dae88af71 | 349 | for (i = 0; i < dx; i++) { |
MartinJohnson | 0:404dae88af71 | 350 | if (e >= 0) { |
MartinJohnson | 0:404dae88af71 | 351 | y += incy; |
MartinJohnson | 0:404dae88af71 | 352 | e += inc1; |
MartinJohnson | 0:404dae88af71 | 353 | } |
MartinJohnson | 0:404dae88af71 | 354 | else { |
MartinJohnson | 0:404dae88af71 | 355 | e += inc2; |
MartinJohnson | 0:404dae88af71 | 356 | } |
MartinJohnson | 0:404dae88af71 | 357 | x += incx; |
MartinJohnson | 0:404dae88af71 | 358 | gdiPoint(prc, x, y, rop); |
MartinJohnson | 0:404dae88af71 | 359 | } |
MartinJohnson | 0:404dae88af71 | 360 | } else { |
MartinJohnson | 0:404dae88af71 | 361 | gdiPoint(prc, x, y, rop); |
MartinJohnson | 0:404dae88af71 | 362 | e = 2 * dx - dy; |
MartinJohnson | 0:404dae88af71 | 363 | inc1 = 2 * (dx - dy); |
MartinJohnson | 0:404dae88af71 | 364 | inc2 = 2 * dx; |
MartinJohnson | 0:404dae88af71 | 365 | for(i = 0; i < dy; i++) { |
MartinJohnson | 0:404dae88af71 | 366 | if (e >= 0) { |
MartinJohnson | 0:404dae88af71 | 367 | x += incx; |
MartinJohnson | 0:404dae88af71 | 368 | e += inc1; |
MartinJohnson | 0:404dae88af71 | 369 | } else { |
MartinJohnson | 0:404dae88af71 | 370 | e += inc2; |
MartinJohnson | 0:404dae88af71 | 371 | } |
MartinJohnson | 0:404dae88af71 | 372 | y += incy; |
MartinJohnson | 0:404dae88af71 | 373 | gdiPoint(prc, x, y, rop); |
MartinJohnson | 0:404dae88af71 | 374 | } |
MartinJohnson | 0:404dae88af71 | 375 | } |
MartinJohnson | 0:404dae88af71 | 376 | } |
MartinJohnson | 0:404dae88af71 | 377 | |
MartinJohnson | 0:404dae88af71 | 378 | //***************************************************************************** |
MartinJohnson | 0:404dae88af71 | 379 | // Function gdiRectangle(i16 x1, i16 y1, i16 x2, i16 y2, u16 rop) |
MartinJohnson | 0:404dae88af71 | 380 | // |
MartinJohnson | 0:404dae88af71 | 381 | // Draw rectangle |
MartinJohnson | 0:404dae88af71 | 382 | // |
MartinJohnson | 0:404dae88af71 | 383 | // parameters: |
MartinJohnson | 0:404dae88af71 | 384 | // x1 X start position |
MartinJohnson | 0:404dae88af71 | 385 | // y1 Y start position |
MartinJohnson | 0:404dae88af71 | 386 | // x2 X end position |
MartinJohnson | 0:404dae88af71 | 387 | // y2 Y end position |
MartinJohnson | 0:404dae88af71 | 388 | // rop Raster operation. See GDI_ROP_xxx defines |
MartinJohnson | 0:404dae88af71 | 389 | // |
MartinJohnson | 0:404dae88af71 | 390 | // return none |
MartinJohnson | 0:404dae88af71 | 391 | //***************************************************************************** |
MartinJohnson | 0:404dae88af71 | 392 | void gdiRectangle(i16 x0, i16 y0, i16 x1, i16 y1, u16 rop) { |
MartinJohnson | 14:3035b3271395 | 393 | |
MartinJohnson | 14:3035b3271395 | 394 | gdiHLine(x0,y0,x1,rop); |
MartinJohnson | 14:3035b3271395 | 395 | gdiHLine(x0,y1,x1,rop); |
MartinJohnson | 14:3035b3271395 | 396 | gdiVLine(x0,y0,y1,rop); |
MartinJohnson | 14:3035b3271395 | 397 | gdiVLine(x1,y0,y1,rop); |
MartinJohnson | 14:3035b3271395 | 398 | } |
MartinJohnson | 0:404dae88af71 | 399 | |
MartinJohnson | 14:3035b3271395 | 400 | void gdiFilledRectangle(i16 x0, i16 y0, i16 x1, i16 y1, u16 rop) { |
MartinJohnson | 14:3035b3271395 | 401 | |
MartinJohnson | 14:3035b3271395 | 402 | for(int y=y0;y<y1;y++) |
MartinJohnson | 14:3035b3271395 | 403 | gdiHLine(x0,y,x1,rop); |
MartinJohnson | 0:404dae88af71 | 404 | } |
MartinJohnson | 0:404dae88af71 | 405 | |
MartinJohnson | 0:404dae88af71 | 406 | //***************************************************************************** |
MartinJohnson | 0:404dae88af71 | 407 | // Function gdiRectangleEx(PGDI_RECT rc, u16 rop) |
MartinJohnson | 0:404dae88af71 | 408 | // |
MartinJohnson | 0:404dae88af71 | 409 | // Draw rectangle |
MartinJohnson | 0:404dae88af71 | 410 | // |
MartinJohnson | 0:404dae88af71 | 411 | // parameters: |
MartinJohnson | 0:404dae88af71 | 412 | // rc Struct containing the rectangle parameters |
MartinJohnson | 0:404dae88af71 | 413 | // rop Raster operation. See GDI_ROP_xxx defines |
MartinJohnson | 0:404dae88af71 | 414 | // |
MartinJohnson | 0:404dae88af71 | 415 | // return none |
MartinJohnson | 0:404dae88af71 | 416 | //***************************************************************************** |
MartinJohnson | 0:404dae88af71 | 417 | void gdiRectangleEx(PGDI_RECT rc, u16 rop) { |
MartinJohnson | 0:404dae88af71 | 418 | |
MartinJohnson | 0:404dae88af71 | 419 | gdiRectangle(rc->x, rc->y, rc->x + rc->w, rc->y + rc->h,rop); |
MartinJohnson | 0:404dae88af71 | 420 | } |
MartinJohnson | 0:404dae88af71 | 421 | |
MartinJohnson | 0:404dae88af71 | 422 | //***************************************************************************** |
MartinJohnson | 0:404dae88af71 | 423 | // Function gdiCircle(i16 x, i16 y, i16 r, u16 rop) |
MartinJohnson | 0:404dae88af71 | 424 | // |
MartinJohnson | 0:404dae88af71 | 425 | // Draw circle. This function uses the integer-precision math |
MartinJohnson | 0:404dae88af71 | 426 | // |
MartinJohnson | 0:404dae88af71 | 427 | // parameters: |
MartinJohnson | 0:404dae88af71 | 428 | // x Circle center X position |
MartinJohnson | 0:404dae88af71 | 429 | // y Circle center Y position |
MartinJohnson | 0:404dae88af71 | 430 | // r Radius |
MartinJohnson | 0:404dae88af71 | 431 | // rop Raster operation. See GDI_ROP_xxx defines |
MartinJohnson | 0:404dae88af71 | 432 | // |
MartinJohnson | 0:404dae88af71 | 433 | // return none |
MartinJohnson | 0:404dae88af71 | 434 | //***************************************************************************** |
MartinJohnson | 0:404dae88af71 | 435 | void gdiCircle(u16 x, u16 y, u16 r, u16 rop) { |
MartinJohnson | 0:404dae88af71 | 436 | |
MartinJohnson | 0:404dae88af71 | 437 | i32 x1, y1; |
MartinJohnson | 0:404dae88af71 | 438 | u16 a; |
MartinJohnson | 0:404dae88af71 | 439 | |
MartinJohnson | 3:93e488fbb8a2 | 440 | int div; |
MartinJohnson | 3:93e488fbb8a2 | 441 | div=360/(16*r); |
MartinJohnson | 3:93e488fbb8a2 | 442 | if(div==0) div=1; |
MartinJohnson | 3:93e488fbb8a2 | 443 | for (a = 0; a < 360; a+=div) { |
MartinJohnson | 0:404dae88af71 | 444 | x1 = r * mthCos(a); |
MartinJohnson | 0:404dae88af71 | 445 | y1 = r * mthSin(a); |
MartinJohnson | 0:404dae88af71 | 446 | gdiPoint(NULL, (x1 / 10000) + x,(y1 / 10000) + y,rop); |
MartinJohnson | 0:404dae88af71 | 447 | } |
MartinJohnson | 0:404dae88af71 | 448 | } |
MartinJohnson | 0:404dae88af71 | 449 | |
MartinJohnson | 5:594c9712697c | 450 | void gdiHLine(u16 x, u16 y, u16 x1, u16 rop) { |
MartinJohnson | 14:3035b3271395 | 451 | // printf("gdiHline %d %d %d\n",x,y,x1); |
MartinJohnson | 14:3035b3271395 | 452 | if(x>=VID_HSIZE) x=VID_HSIZE-1; |
MartinJohnson | 14:3035b3271395 | 453 | if(x1>=VID_HSIZE) x1=VID_HSIZE-1; |
MartinJohnson | 14:3035b3271395 | 454 | if(y>=VID_VSIZE) y=VID_VSIZE-1; |
MartinJohnson | 5:594c9712697c | 455 | if(x>x1) { |
MartinJohnson | 5:594c9712697c | 456 | int t=x1; |
MartinJohnson | 5:594c9712697c | 457 | x1=x; |
MartinJohnson | 5:594c9712697c | 458 | x=t; |
MartinJohnson | 5:594c9712697c | 459 | } |
MartinJohnson | 5:594c9712697c | 460 | char *start=fb[y]+x; |
MartinJohnson | 5:594c9712697c | 461 | int n=x1-x+1; |
MartinJohnson | 5:594c9712697c | 462 | while(n--) { |
MartinJohnson | 5:594c9712697c | 463 | *start++|=(colour<<4); |
MartinJohnson | 5:594c9712697c | 464 | } |
MartinJohnson | 5:594c9712697c | 465 | } |
MartinJohnson | 5:594c9712697c | 466 | |
MartinJohnson | 14:3035b3271395 | 467 | |
MartinJohnson | 14:3035b3271395 | 468 | void gdiVLine(u16 x, u16 y, u16 y1, u16 rop) { |
MartinJohnson | 14:3035b3271395 | 469 | // printf("gdiVline %d %d %d\n",x,y,y1); |
MartinJohnson | 14:3035b3271395 | 470 | if(x>=VID_HSIZE) x=VID_HSIZE-1; |
MartinJohnson | 14:3035b3271395 | 471 | if(y1>=VID_VSIZE) y1=VID_VSIZE-1; |
MartinJohnson | 14:3035b3271395 | 472 | if(y>=VID_VSIZE) y=VID_VSIZE-1; |
MartinJohnson | 14:3035b3271395 | 473 | if(y>y1) { |
MartinJohnson | 14:3035b3271395 | 474 | u16 t=y1; |
MartinJohnson | 14:3035b3271395 | 475 | y1=y; |
MartinJohnson | 14:3035b3271395 | 476 | y=t; |
MartinJohnson | 14:3035b3271395 | 477 | } |
MartinJohnson | 14:3035b3271395 | 478 | char *start=fb[y]+x; |
MartinJohnson | 14:3035b3271395 | 479 | int n=y1-y+1; |
MartinJohnson | 14:3035b3271395 | 480 | while(n--) { |
MartinJohnson | 14:3035b3271395 | 481 | *start|=(colour<<4); |
MartinJohnson | 14:3035b3271395 | 482 | start+=HTOTAL; |
MartinJohnson | 14:3035b3271395 | 483 | } |
MartinJohnson | 14:3035b3271395 | 484 | } |
MartinJohnson | 14:3035b3271395 | 485 | |
MartinJohnson | 3:93e488fbb8a2 | 486 | void gdiFilledCircle(u16 x, u16 y, u16 r, u16 rop) { |
MartinJohnson | 3:93e488fbb8a2 | 487 | |
MartinJohnson | 3:93e488fbb8a2 | 488 | i32 x1, y1; |
MartinJohnson | 3:93e488fbb8a2 | 489 | u16 a; |
MartinJohnson | 3:93e488fbb8a2 | 490 | |
MartinJohnson | 3:93e488fbb8a2 | 491 | int div; |
MartinJohnson | 3:93e488fbb8a2 | 492 | div=360/(16*r); |
MartinJohnson | 3:93e488fbb8a2 | 493 | if(div==0) div=1; |
MartinJohnson | 3:93e488fbb8a2 | 494 | for (a = 0; a < 100; a+=div) { |
MartinJohnson | 3:93e488fbb8a2 | 495 | x1 = r * mthCos(a); |
MartinJohnson | 3:93e488fbb8a2 | 496 | y1 = r * mthSin(a); |
MartinJohnson | 5:594c9712697c | 497 | gdiHLine( (x1 / 10000) + x,(y1 / 10000) + y,-(x1 / 10000) + x,rop); |
MartinJohnson | 5:594c9712697c | 498 | gdiHLine( (x1 / 10000) + x,-(y1 / 10000) + y,-(x1 / 10000) + x,rop); |
MartinJohnson | 5:594c9712697c | 499 | // gdiPoint(NULL, (x1 / 10000) + x,(y1 / 10000) + y,rop); |
MartinJohnson | 3:93e488fbb8a2 | 500 | } |
MartinJohnson | 3:93e488fbb8a2 | 501 | } |
MartinJohnson | 0:404dae88af71 | 502 | //***************************************************************************** |
MartinJohnson | 0:404dae88af71 | 503 | // Function gdiDrawText(PGDI_RECT prc, pu8 ptext, u16 style, u16 rop) |
MartinJohnson | 0:404dae88af71 | 504 | // |
MartinJohnson | 0:404dae88af71 | 505 | // Draw text inside rectangle |
MartinJohnson | 0:404dae88af71 | 506 | // |
MartinJohnson | 0:404dae88af71 | 507 | // parameters: |
MartinJohnson | 0:404dae88af71 | 508 | // prc Pointer to clipping rectangle |
MartinJohnson | 0:404dae88af71 | 509 | // ptext Pointer to text |
MartinJohnson | 0:404dae88af71 | 510 | // style Text style (see GDI_WINCAPTION_xx defines) |
MartinJohnson | 0:404dae88af71 | 511 | // rop Raster operation. See GDI_ROP_xxx defines |
MartinJohnson | 0:404dae88af71 | 512 | // |
MartinJohnson | 0:404dae88af71 | 513 | // return none |
MartinJohnson | 0:404dae88af71 | 514 | //***************************************************************************** |
MartinJohnson | 0:404dae88af71 | 515 | CCM void gdiDrawText(PGDI_RECT prc, pu8 ptext, u16 style, u16 rop) { |
MartinJohnson | 0:404dae88af71 | 516 | |
MartinJohnson | 0:404dae88af71 | 517 | u16 l, i, pos, xp; |
MartinJohnson | 0:404dae88af71 | 518 | u8 c; |
MartinJohnson | 0:404dae88af71 | 519 | pu8 ptx; |
MartinJohnson | 0:404dae88af71 | 520 | |
MartinJohnson | 0:404dae88af71 | 521 | l = strLen(ptext) * GDI_SYSFONT_WIDTH; |
MartinJohnson | 0:404dae88af71 | 522 | switch(style) { |
MartinJohnson | 0:404dae88af71 | 523 | case GDI_WINCAPTION_RIGHT: if (l < prc->w) { |
MartinJohnson | 0:404dae88af71 | 524 | prc->x += (prc->w - l); |
MartinJohnson | 0:404dae88af71 | 525 | } |
MartinJohnson | 0:404dae88af71 | 526 | break; |
MartinJohnson | 0:404dae88af71 | 527 | case GDI_WINCAPTION_CENTER: if (l < prc->w) { |
MartinJohnson | 0:404dae88af71 | 528 | prc->x += ((prc->w - l) / 2); |
MartinJohnson | 0:404dae88af71 | 529 | } |
MartinJohnson | 0:404dae88af71 | 530 | break; |
MartinJohnson | 0:404dae88af71 | 531 | } |
MartinJohnson | 0:404dae88af71 | 532 | l = strLen(ptext); |
MartinJohnson | 0:404dae88af71 | 533 | xp = 1;//prc->x; |
MartinJohnson | 0:404dae88af71 | 534 | for (i = 0; i < l; i++) { |
MartinJohnson | 0:404dae88af71 | 535 | c = *(ptext++); |
MartinJohnson | 0:404dae88af71 | 536 | if (c >= GDI_SYSFONT_OFFSET) { |
MartinJohnson | 0:404dae88af71 | 537 | pos = (u16) (c - GDI_SYSFONT_OFFSET) * GDI_SYSFONT_BYTEWIDTH * GDI_SYSFONT_HEIGHT; |
MartinJohnson | 0:404dae88af71 | 538 | ptx = ((pu8) gdiSystemFont) + pos; |
MartinJohnson | 0:404dae88af71 | 539 | gdiBitBlt(prc, xp, 0, GDI_SYSFONT_WIDTH, GDI_SYSFONT_HEIGHT, ptx, rop); |
MartinJohnson | 0:404dae88af71 | 540 | xp += GDI_SYSFONT_WIDTH; |
MartinJohnson | 0:404dae88af71 | 541 | if (xp >= ((prc->x + prc->w) - GDI_SYSFONT_WIDTH)) return; |
MartinJohnson | 0:404dae88af71 | 542 | } |
MartinJohnson | 0:404dae88af71 | 543 | } |
MartinJohnson | 0:404dae88af71 | 544 | } |
MartinJohnson | 0:404dae88af71 | 545 | |
MartinJohnson | 0:404dae88af71 | 546 | //***************************************************************************** |
MartinJohnson | 0:404dae88af71 | 547 | // Function gdiDrawTextEx(i16 x, i16 y, pu8 ptext, u16 rop) |
MartinJohnson | 0:404dae88af71 | 548 | // |
MartinJohnson | 0:404dae88af71 | 549 | // Draw text in X/Y position using system font. |
MartinJohnson | 0:404dae88af71 | 550 | // |
MartinJohnson | 0:404dae88af71 | 551 | // parameters: |
MartinJohnson | 0:404dae88af71 | 552 | // x X start position |
MartinJohnson | 0:404dae88af71 | 553 | // y Y start position |
MartinJohnson | 0:404dae88af71 | 554 | // ptext Pointer to text |
MartinJohnson | 0:404dae88af71 | 555 | // rop Raster operation. See GDI_ROP_xxx defines |
MartinJohnson | 0:404dae88af71 | 556 | // |
MartinJohnson | 0:404dae88af71 | 557 | // return none |
MartinJohnson | 0:404dae88af71 | 558 | //***************************************************************************** |
MartinJohnson | 0:404dae88af71 | 559 | void gdiDrawTextEx(i16 x, i16 y, pu8 ptext, u16 rop) { |
MartinJohnson | 0:404dae88af71 | 560 | |
MartinJohnson | 0:404dae88af71 | 561 | u16 l, i, pos, xp; |
MartinJohnson | 0:404dae88af71 | 562 | u8 c; |
MartinJohnson | 0:404dae88af71 | 563 | pu8 ptx; |
MartinJohnson | 0:404dae88af71 | 564 | |
MartinJohnson | 0:404dae88af71 | 565 | l = strLen(ptext); |
MartinJohnson | 0:404dae88af71 | 566 | xp = x; |
MartinJohnson | 0:404dae88af71 | 567 | for (i = 0; i < l; i++) { |
MartinJohnson | 0:404dae88af71 | 568 | c = *(ptext++); |
MartinJohnson | 0:404dae88af71 | 569 | if (c >= GDI_SYSFONT_OFFSET) { |
MartinJohnson | 0:404dae88af71 | 570 | pos = (u16) (c - GDI_SYSFONT_OFFSET) * GDI_SYSFONT_BYTEWIDTH * GDI_SYSFONT_HEIGHT; |
MartinJohnson | 0:404dae88af71 | 571 | ptx = ((pu8) gdiSystemFont) + pos; |
MartinJohnson | 0:404dae88af71 | 572 | gdiBitBlt(NULL, xp, y, GDI_SYSFONT_WIDTH, GDI_SYSFONT_HEIGHT, ptx, rop); |
MartinJohnson | 0:404dae88af71 | 573 | xp += GDI_SYSFONT_WIDTH; |
MartinJohnson | 0:404dae88af71 | 574 | if (xp >= VID_PIXELS_X) return; |
MartinJohnson | 0:404dae88af71 | 575 | } |
MartinJohnson | 0:404dae88af71 | 576 | } |
MartinJohnson | 0:404dae88af71 | 577 | } |
MartinJohnson | 0:404dae88af71 | 578 | //***************************************************************************** |
MartinJohnson | 0:404dae88af71 | 579 | // Function gdiDrawWindow(PGDI_WINDOW pwin) |
MartinJohnson | 0:404dae88af71 | 580 | // |
MartinJohnson | 0:404dae88af71 | 581 | // Draw window |
MartinJohnson | 0:404dae88af71 | 582 | // |
MartinJohnson | 0:404dae88af71 | 583 | // parameters: |
MartinJohnson | 0:404dae88af71 | 584 | // pwin Pointer to windows struct |
MartinJohnson | 0:404dae88af71 | 585 | // |
MartinJohnson | 0:404dae88af71 | 586 | // return none |
MartinJohnson | 0:404dae88af71 | 587 | //***************************************************************************** |
MartinJohnson | 0:404dae88af71 | 588 | void gdiDrawWindow(PGDI_WINDOW pwin) { |
MartinJohnson | 0:404dae88af71 | 589 | |
MartinJohnson | 0:404dae88af71 | 590 | i16 i; |
MartinJohnson | 0:404dae88af71 | 591 | GDI_RECT rc, rt; |
MartinJohnson | 0:404dae88af71 | 592 | |
MartinJohnson | 0:404dae88af71 | 593 | gdiCopyRect(&rc,&pwin->rc); |
MartinJohnson | 0:404dae88af71 | 594 | if (pwin->style & GDI_WINCAPTION) { |
MartinJohnson | 0:404dae88af71 | 595 | gdiCopyRect(&rt,&pwin->rc); |
MartinJohnson | 0:404dae88af71 | 596 | rt.h = rt.y + 11; |
MartinJohnson | 0:404dae88af71 | 597 | rt.x += 2; |
MartinJohnson | 0:404dae88af71 | 598 | rt.y += 1; |
MartinJohnson | 0:404dae88af71 | 599 | rc.h += 10; |
MartinJohnson | 0:404dae88af71 | 600 | for (i = 0; i < 11; i++) { |
MartinJohnson | 0:404dae88af71 | 601 | gdiLine(NULL,rc.x, rc.y + i, rc.x + rc.w, rc.y + i, GDI_ROP_COPY); |
MartinJohnson | 0:404dae88af71 | 602 | } |
MartinJohnson | 0:404dae88af71 | 603 | if (pwin->style & GDI_WINCLOSEICON) { |
MartinJohnson | 0:404dae88af71 | 604 | gdiBitBlt(&rc, rc.w - 9, 1, 10, 9, (pu8) gdiCloseBm, GDI_ROP_COPY); |
MartinJohnson | 0:404dae88af71 | 605 | rt.w -= 11; |
MartinJohnson | 0:404dae88af71 | 606 | } else { |
MartinJohnson | 0:404dae88af71 | 607 | rt.w -= 1; |
MartinJohnson | 0:404dae88af71 | 608 | } |
MartinJohnson | 0:404dae88af71 | 609 | gdiDrawText(&rt,pwin->caption,pwin->style & GDI_WINCAPTION_MASK, GDI_ROP_XOR); |
MartinJohnson | 0:404dae88af71 | 610 | } |
MartinJohnson | 0:404dae88af71 | 611 | gdiRectangleEx(&rc,GDI_ROP_COPY); |
MartinJohnson | 0:404dae88af71 | 612 | } |
MartinJohnson | 0:404dae88af71 | 613 | |
MartinJohnson | 14:3035b3271395 | 614 | int buttonstate=0; |
MartinJohnson | 14:3035b3271395 | 615 | int buttonPress() { |
MartinJohnson | 14:3035b3271395 | 616 | int b=GPIOA->IDR&1; |
MartinJohnson | 14:3035b3271395 | 617 | if(b!=buttonstate && b) { |
MartinJohnson | 14:3035b3271395 | 618 | buttonstate=b; |
MartinJohnson | 14:3035b3271395 | 619 | return 1; |
MartinJohnson | 14:3035b3271395 | 620 | } |
MartinJohnson | 14:3035b3271395 | 621 | buttonstate=b; |
MartinJohnson | 14:3035b3271395 | 622 | return 0; |
MartinJohnson | 14:3035b3271395 | 623 | } |