Demo of low res colour vga video for stm32f3 discovery board

Dependencies:   STM32F3-Discovery-minimal

Fork of Space_Invaders_Demo by Martin Johnson

Committer:
MartinJohnson
Date:
Tue Mar 01 02:40:19 2016 +0000
Revision:
0:404dae88af71
Child:
3:93e488fbb8a2
space invaders game

Who changed what in which revision?

UserRevisionLine numberNew 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 0:404dae88af71 32
MartinJohnson 0:404dae88af71 33 #define CCM __attribute__ ((section (".ccmram")))
MartinJohnson 0:404dae88af71 34 const u8 gdiCloseBm[] = { 0x7f, 0xC0,
MartinJohnson 0:404dae88af71 35 0x7f, 0xC0,
MartinJohnson 0:404dae88af71 36 0x7f, 0xC0,
MartinJohnson 0:404dae88af71 37 0x7f, 0xC0,
MartinJohnson 0:404dae88af71 38 0x40, 0x40,
MartinJohnson 0:404dae88af71 39 0x7f, 0xC0,
MartinJohnson 0:404dae88af71 40 0x7f, 0xC0,
MartinJohnson 0:404dae88af71 41 0x7f, 0xC0,
MartinJohnson 0:404dae88af71 42 0x7f, 0xC0 };
MartinJohnson 0:404dae88af71 43
MartinJohnson 0:404dae88af71 44
MartinJohnson 0:404dae88af71 45 u16 strLen(pu8 str) {
MartinJohnson 0:404dae88af71 46
MartinJohnson 0:404dae88af71 47 int i = 0;
MartinJohnson 0:404dae88af71 48
MartinJohnson 0:404dae88af71 49 while (*str != 0) {
MartinJohnson 0:404dae88af71 50 ++i;
MartinJohnson 0:404dae88af71 51 ++str;
MartinJohnson 0:404dae88af71 52 }
MartinJohnson 0:404dae88af71 53 return(i);
MartinJohnson 0:404dae88af71 54 }
MartinJohnson 0:404dae88af71 55
MartinJohnson 0:404dae88af71 56 // *****************************************************************************
MartinJohnson 0:404dae88af71 57 // Function gdiCopyRect(PGDI_RECT rc1, PGDI_RECT rc2)
MartinJohnson 0:404dae88af71 58 //
MartinJohnson 0:404dae88af71 59 // Copy rectangle rc2 to rc1
MartinJohnson 0:404dae88af71 60 //
MartinJohnson 0:404dae88af71 61 // parameters:
MartinJohnson 0:404dae88af71 62 // rc1 Destination rectangle
MartinJohnson 0:404dae88af71 63 // y Source rectangle
MartinJohnson 0:404dae88af71 64 //
MartinJohnson 0:404dae88af71 65 // return: none
MartinJohnson 0:404dae88af71 66 // *****************************************************************************
MartinJohnson 0:404dae88af71 67 void gdiCopyRect(PGDI_RECT rc1, PGDI_RECT rc2) {
MartinJohnson 0:404dae88af71 68
MartinJohnson 0:404dae88af71 69 rc1->x = rc2->x;
MartinJohnson 0:404dae88af71 70 rc1->y = rc2->y;
MartinJohnson 0:404dae88af71 71 rc1->w = rc2->w;
MartinJohnson 0:404dae88af71 72 rc1->h = rc2->h;
MartinJohnson 0:404dae88af71 73 }
MartinJohnson 0:404dae88af71 74
MartinJohnson 0:404dae88af71 75 // *****************************************************************************
MartinJohnson 0:404dae88af71 76 // Function gdiBitBlt(PGDI_RECT prc, i16 x, i16 y, i16 w, i16 h, pu8 bm, u16 rop)
MartinJohnson 0:404dae88af71 77 //
MartinJohnson 0:404dae88af71 78 // Bit Block Transfer funcion. This function uses the STM32 Bit-Banding mode
MartinJohnson 0:404dae88af71 79 // to simplify the complex BitBlt functionality.
MartinJohnson 0:404dae88af71 80 //
MartinJohnson 0:404dae88af71 81 // From Cortex STM32F10x Reference Manual (RM0008):
MartinJohnson 0:404dae88af71 82 // A mapping formula shows how to reference each word in the alias region to a
MartinJohnson 0:404dae88af71 83 // corresponding bit in the bit-band region. The mapping formula is:
MartinJohnson 0:404dae88af71 84 // bit_word_addr = bit_band_base + (byte_offset x 32) + (bit_number × 4)
MartinJohnson 0:404dae88af71 85 // where:
MartinJohnson 0:404dae88af71 86 // bit_word_addr is the address of the word in the alias memory region that
MartinJohnson 0:404dae88af71 87 // maps to the targeted bit.
MartinJohnson 0:404dae88af71 88 // bit_band_base is the starting address of the alias region
MartinJohnson 0:404dae88af71 89 // byte_offset is the number of the byte in the bit-band region that contains
MartinJohnson 0:404dae88af71 90 // the targeted bit bit_number is the bit position (0-7) of the targeted bit.
MartinJohnson 0:404dae88af71 91 // Example:
MartinJohnson 0:404dae88af71 92 // The following example shows how to map bit 2 of the byte located at SRAM
MartinJohnson 0:404dae88af71 93 // address 0x20000300 in the alias region:
MartinJohnson 0:404dae88af71 94 // 0x22006008 = 0x22000000 + (0x300*32) + (2*4).
MartinJohnson 0:404dae88af71 95 // Writing to address 0x22006008 has the same effect as a read-modify-write
MartinJohnson 0:404dae88af71 96 // operation on bit 2 of the byte at SRAM address 0x20000300.
MartinJohnson 0:404dae88af71 97 // Reading address 0x22006008 returns the value (0x01 or 0x00) of bit 2 of
MartinJohnson 0:404dae88af71 98 // the byte at SRAM address 0x20000300 (0x01: bit set; 0x00: bit reset).
MartinJohnson 0:404dae88af71 99 //
MartinJohnson 0:404dae88af71 100 // For further reference see the Cortex M3 Technical Reference Manual
MartinJohnson 0:404dae88af71 101 //
MartinJohnson 0:404dae88af71 102 // Parameters:
MartinJohnson 0:404dae88af71 103 //
MartinJohnson 0:404dae88af71 104 // prc Clipping rectangle. All X/Y coordinates are inside "prc"
MartinJohnson 0:404dae88af71 105 // If "prc" is NULL, the coordinates will be the entire display
MartinJohnson 0:404dae88af71 106 // area
MartinJohnson 0:404dae88af71 107 // x Bitmap X start position
MartinJohnson 0:404dae88af71 108 // y Bitmap Y start position
MartinJohnson 0:404dae88af71 109 // w Bitmap width, in pixels
MartinJohnson 0:404dae88af71 110 // y Bitmap height, in pixels
MartinJohnson 0:404dae88af71 111 // bm Pointer to te bitmap start position
MartinJohnson 0:404dae88af71 112 // rop Raster operation. See GDI_ROP_xxx defines
MartinJohnson 0:404dae88af71 113 //
MartinJohnson 0:404dae88af71 114 // return none
MartinJohnson 0:404dae88af71 115 // ****************************************************************************
MartinJohnson 0:404dae88af71 116
MartinJohnson 0:404dae88af71 117 u8 leftmask[]={0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe};
MartinJohnson 0:404dae88af71 118 u8 rightmask[]={0x0,0x1,0x3,0x7,0xf,0x1f,0x3f,0x7f};
MartinJohnson 0:404dae88af71 119 CCM void gdiBitBlt(PGDI_RECT prc, i16 x, i16 y, i16 w, i16 h, pu8 bm, u16 rop) {
MartinJohnson 0:404dae88af71 120
MartinJohnson 0:404dae88af71 121 u16 i, xz, xb, xt;
MartinJohnson 0:404dae88af71 122 u32 wb; // Width in bytes
MartinJohnson 0:404dae88af71 123 u32 r,rr; // Start X position in bits (relative to x)
MartinJohnson 0:404dae88af71 124 u32 k;
MartinJohnson 0:404dae88af71 125 u32 d;
MartinJohnson 0:404dae88af71 126 u32 offs;
MartinJohnson 0:404dae88af71 127 u8 c;
MartinJohnson 0:404dae88af71 128 pu8 fbPtr; // Pointer to the Frame Buffer Bit-Band area
MartinJohnson 0:404dae88af71 129 pu8 fbBak;
MartinJohnson 0:404dae88af71 130 u8 fb1;
MartinJohnson 0:404dae88af71 131 u32 fb2;
MartinJohnson 0:404dae88af71 132 u32 rp;
MartinJohnson 0:404dae88af71 133 pu8 bmPtr; // Pointer to the bitmap bits
MartinJohnson 0:404dae88af71 134
MartinJohnson 0:404dae88af71 135 // Calculate clipping region
MartinJohnson 0:404dae88af71 136
MartinJohnson 0:404dae88af71 137 if (prc != NULL) {
MartinJohnson 0:404dae88af71 138 x = prc->x + x;
MartinJohnson 0:404dae88af71 139 y = prc->y + y;
MartinJohnson 0:404dae88af71 140 }
MartinJohnson 0:404dae88af71 141
MartinJohnson 0:404dae88af71 142 // Get total bitmap width in bytes
MartinJohnson 0:404dae88af71 143
MartinJohnson 0:404dae88af71 144 wb = (u32) (w+7) >> 3;
MartinJohnson 0:404dae88af71 145 // if ((wb << 3) < (u32) w) ++wb;
MartinJohnson 0:404dae88af71 146
MartinJohnson 0:404dae88af71 147 // Get starting bit inside the first byte
MartinJohnson 0:404dae88af71 148
MartinJohnson 0:404dae88af71 149 r=x&7;
MartinJohnson 0:404dae88af71 150 xb=x>>3;
MartinJohnson 0:404dae88af71 151
MartinJohnson 0:404dae88af71 152 rr=7-((w+r)&7); // no of bits to mask at end of bitmap
MartinJohnson 0:404dae88af71 153
MartinJohnson 0:404dae88af71 154 // Clip X
MartinJohnson 0:404dae88af71 155
MartinJohnson 0:404dae88af71 156 if (prc == NULL) {
MartinJohnson 0:404dae88af71 157 if ((x + w) >= VID_PIXELS_X ) {
MartinJohnson 0:404dae88af71 158 xt = VID_PIXELS_X - x;
MartinJohnson 0:404dae88af71 159 } else {
MartinJohnson 0:404dae88af71 160 xt = w;
MartinJohnson 0:404dae88af71 161 }
MartinJohnson 0:404dae88af71 162 } else {
MartinJohnson 0:404dae88af71 163 if ((x + w) >= (x + prc->w)) {
MartinJohnson 0:404dae88af71 164 xt = prc->w - x;
MartinJohnson 0:404dae88af71 165 } else {
MartinJohnson 0:404dae88af71 166 xt = w;
MartinJohnson 0:404dae88af71 167 }
MartinJohnson 0:404dae88af71 168 }
MartinJohnson 0:404dae88af71 169
MartinJohnson 0:404dae88af71 170 // Draw bits
MartinJohnson 0:404dae88af71 171
MartinJohnson 0:404dae88af71 172 for (i = 0; i < h; i++) {
MartinJohnson 0:404dae88af71 173 u8 lst=0,d;
MartinJohnson 0:404dae88af71 174 // Clip Y
MartinJohnson 0:404dae88af71 175 bmPtr = bm + ((u32) i * wb);
MartinJohnson 0:404dae88af71 176 if ((i + y) > (VID_VSIZE - 1)) return;
MartinJohnson 0:404dae88af71 177 if(rop==GDI_ROP_COPY) {
MartinJohnson 0:404dae88af71 178 c = *bmPtr++;
MartinJohnson 0:404dae88af71 179 if((w+r)<8)
MartinJohnson 0:404dae88af71 180 fb[i+y][xb] = (fb[i+y][xb]&(leftmask[r]|rightmask[rr]))|(c>>r);
MartinJohnson 0:404dae88af71 181 else {
MartinJohnson 0:404dae88af71 182 fb[i+y][xb] = (fb[i+y][xb]&leftmask[r])|(c>>r);
MartinJohnson 0:404dae88af71 183 lst=(c<<(8-r));
MartinJohnson 0:404dae88af71 184 for(xz=1;xz<wb;xz++) {
MartinJohnson 0:404dae88af71 185 c = *bmPtr++;
MartinJohnson 0:404dae88af71 186 fb[i+y][xz+xb]=((c>>r)|lst);
MartinJohnson 0:404dae88af71 187 lst=(c<<(8-r));
MartinJohnson 0:404dae88af71 188 }
MartinJohnson 0:404dae88af71 189 fb[i+y][xb+wb] = (fb[i+y][xb+wb]&rightmask[rr])|lst;
MartinJohnson 0:404dae88af71 190 }
MartinJohnson 0:404dae88af71 191 }
MartinJohnson 0:404dae88af71 192 if(rop==GDI_ROP_XOR) {
MartinJohnson 0:404dae88af71 193 for(xz=0;xz<wb;xz++) {
MartinJohnson 0:404dae88af71 194 c = *bmPtr++;
MartinJohnson 0:404dae88af71 195 fb[i+y][xz+xb]^=((c>>r)|lst);
MartinJohnson 0:404dae88af71 196 lst=(c<<(8-r));
MartinJohnson 0:404dae88af71 197 }
MartinJohnson 0:404dae88af71 198 if((w+r)>8)
MartinJohnson 0:404dae88af71 199 fb[i+y][xz+xb]^=lst;
MartinJohnson 0:404dae88af71 200 }
MartinJohnson 0:404dae88af71 201 if(rop==GDI_ROP_OR) {
MartinJohnson 0:404dae88af71 202 for(xz=0;xz<wb;xz++) {
MartinJohnson 0:404dae88af71 203 c = *bmPtr++;
MartinJohnson 0:404dae88af71 204 fb[i+y][xz+xb]|=((c>>r)|lst);
MartinJohnson 0:404dae88af71 205 lst=(c<<(8-r));
MartinJohnson 0:404dae88af71 206 }
MartinJohnson 0:404dae88af71 207 if((w+r)>8)
MartinJohnson 0:404dae88af71 208 fb[i+y][xz+xb]|=lst;
MartinJohnson 0:404dae88af71 209 }
MartinJohnson 0:404dae88af71 210
MartinJohnson 0:404dae88af71 211
MartinJohnson 0:404dae88af71 212
MartinJohnson 0:404dae88af71 213 // Get offset to frame buffer in bit-banding mode
MartinJohnson 0:404dae88af71 214 /*
MartinJohnson 0:404dae88af71 215
MartinJohnson 0:404dae88af71 216 offs = (((u32) x >> 3)) + ((u32) (y + i) * VID_HSIZE_R);
MartinJohnson 0:404dae88af71 217 k = (u32) (&fb - 0x20000000);
MartinJohnson 0:404dae88af71 218 k += offs;
MartinJohnson 0:404dae88af71 219 fbPtr = (pu8) (0x22000000 + (k * 32) + ((7 - r) * 4));
MartinJohnson 0:404dae88af71 220 fbBak = (pu8) (0x22000000 + (k * 32) + 28);
MartinJohnson 0:404dae88af71 221
MartinJohnson 0:404dae88af71 222 // Get offset to bitmap bits
MartinJohnson 0:404dae88af71 223
MartinJohnson 0:404dae88af71 224 bmPtr = bm + ((u32) i * wb);
MartinJohnson 0:404dae88af71 225 xz = w;
MartinJohnson 0:404dae88af71 226
MartinJohnson 0:404dae88af71 227 xb = 0;
MartinJohnson 0:404dae88af71 228 for (xz = 0; xz < xt; xz++) {
MartinJohnson 0:404dae88af71 229 fb1 = ((u32) fbPtr) & 0x000000E0;
MartinJohnson 0:404dae88af71 230 if (xb++ == 0) {
MartinJohnson 0:404dae88af71 231 c = *bmPtr;
MartinJohnson 0:404dae88af71 232 ++bmPtr;
MartinJohnson 0:404dae88af71 233 }
MartinJohnson 0:404dae88af71 234 xb &= 0x07;
MartinJohnson 0:404dae88af71 235 (c & 0x80) ? (rp = 1) : (rp = 0);
MartinJohnson 0:404dae88af71 236 switch(rop) {
MartinJohnson 0:404dae88af71 237 case GDI_ROP_COPY: *fbPtr = rp; break;
MartinJohnson 0:404dae88af71 238 case GDI_ROP_XOR: *fbPtr ^= rp; break;
MartinJohnson 0:404dae88af71 239 case GDI_ROP_AND: *fbPtr &= rp; break;
MartinJohnson 0:404dae88af71 240 case GDI_ROP_OR: *fbPtr |= rp; break;
MartinJohnson 0:404dae88af71 241 }
MartinJohnson 0:404dae88af71 242 fbPtr -= 4;
MartinJohnson 0:404dae88af71 243 fb2 = ((u32) fbPtr) & 0x000000E0;
MartinJohnson 0:404dae88af71 244 if (fb1 != fb2) {
MartinJohnson 0:404dae88af71 245 fbPtr = fbBak + 32;
MartinJohnson 0:404dae88af71 246 fbBak = fbPtr;
MartinJohnson 0:404dae88af71 247 }
MartinJohnson 0:404dae88af71 248 c <<= 1;
MartinJohnson 0:404dae88af71 249 }
MartinJohnson 0:404dae88af71 250 */
MartinJohnson 0:404dae88af71 251 }
MartinJohnson 0:404dae88af71 252 }
MartinJohnson 0:404dae88af71 253
MartinJohnson 0:404dae88af71 254 // *****************************************************************************
MartinJohnson 0:404dae88af71 255 // Function gdiPoint(PGDI_RECT rc, u16 x, u16 y)
MartinJohnson 0:404dae88af71 256 //
MartinJohnson 0:404dae88af71 257 // Show a point in x/y position using the current graphical mode stored in
MartinJohnson 0:404dae88af71 258 // grMode variable
MartinJohnson 0:404dae88af71 259 //
MartinJohnson 0:404dae88af71 260 // parameters:
MartinJohnson 0:404dae88af71 261 // x X position
MartinJohnson 0:404dae88af71 262 // y Y position
MartinJohnson 0:404dae88af71 263 // rop Raster operation. See GDI_ROP_xxx defines
MartinJohnson 0:404dae88af71 264 //
MartinJohnson 0:404dae88af71 265 // return: none
MartinJohnson 0:404dae88af71 266 // *****************************************************************************
MartinJohnson 0:404dae88af71 267 void gdiPoint(PGDI_RECT rc, u16 x, u16 y, u16 rop) {
MartinJohnson 0:404dae88af71 268
MartinJohnson 0:404dae88af71 269 u16 w, r;
MartinJohnson 0:404dae88af71 270 u8 m;
MartinJohnson 0:404dae88af71 271
MartinJohnson 0:404dae88af71 272 // Test for point outside display area
MartinJohnson 0:404dae88af71 273
MartinJohnson 0:404dae88af71 274 if (x >= VID_PIXELS_X || y >= VID_PIXELS_Y) return;
MartinJohnson 0:404dae88af71 275
MartinJohnson 0:404dae88af71 276 w = x >> 3;
MartinJohnson 0:404dae88af71 277 r = x - (w << 3);
MartinJohnson 0:404dae88af71 278
MartinJohnson 0:404dae88af71 279 // Prepare mask
MartinJohnson 0:404dae88af71 280
MartinJohnson 0:404dae88af71 281 m = (0x80 >> r);
MartinJohnson 0:404dae88af71 282
MartinJohnson 0:404dae88af71 283 switch(rop) {
MartinJohnson 0:404dae88af71 284 case GDI_ROP_COPY: fb[y][w] |= m;
MartinJohnson 0:404dae88af71 285 break;
MartinJohnson 0:404dae88af71 286 case GDI_ROP_XOR: fb[y][w] ^= m;
MartinJohnson 0:404dae88af71 287 break;
MartinJohnson 0:404dae88af71 288 case GDI_ROP_AND: fb[y][w] &= m;
MartinJohnson 0:404dae88af71 289 break;
MartinJohnson 0:404dae88af71 290 }
MartinJohnson 0:404dae88af71 291 }
MartinJohnson 0:404dae88af71 292
MartinJohnson 0:404dae88af71 293 //*****************************************************************************
MartinJohnson 0:404dae88af71 294 // Function gdiLine(i16 x1, i16 y1, i16 x2, i16 y2, u16 rop)
MartinJohnson 0:404dae88af71 295 //
MartinJohnson 0:404dae88af71 296 // Draw line using Bresenham algorithm
MartinJohnson 0:404dae88af71 297 //
MartinJohnson 0:404dae88af71 298 // This function was taken from the book:
MartinJohnson 0:404dae88af71 299 // Interactive Computer Graphics, A top-down approach with OpenGL
MartinJohnson 0:404dae88af71 300 // written by Emeritus Edward Angel
MartinJohnson 0:404dae88af71 301 //
MartinJohnson 0:404dae88af71 302 // parameters:
MartinJohnson 0:404dae88af71 303 // prc Clipping rectangle
MartinJohnson 0:404dae88af71 304 // x1 X start position
MartinJohnson 0:404dae88af71 305 // y1 Y start position
MartinJohnson 0:404dae88af71 306 // x2 X end position
MartinJohnson 0:404dae88af71 307 // y2 Y end position
MartinJohnson 0:404dae88af71 308 // rop Raster operation. See GDI_ROP_xxx defines
MartinJohnson 0:404dae88af71 309 //
MartinJohnson 0:404dae88af71 310 // return none
MartinJohnson 0:404dae88af71 311 //*****************************************************************************
MartinJohnson 0:404dae88af71 312 void gdiLine(PGDI_RECT prc, i16 x1, i16 y1, i16 x2, i16 y2, u16 rop) {
MartinJohnson 0:404dae88af71 313
MartinJohnson 0:404dae88af71 314 i16 dx, dy, i, e;
MartinJohnson 0:404dae88af71 315 i16 incx, incy, inc1, inc2;
MartinJohnson 0:404dae88af71 316 i16 x, y;
MartinJohnson 0:404dae88af71 317
MartinJohnson 0:404dae88af71 318 dx = x2 - x1;
MartinJohnson 0:404dae88af71 319 dy = y2 - y1;
MartinJohnson 0:404dae88af71 320
MartinJohnson 0:404dae88af71 321 if(dx < 0) dx = -dx;
MartinJohnson 0:404dae88af71 322 if(dy < 0) dy = -dy;
MartinJohnson 0:404dae88af71 323 incx = 1;
MartinJohnson 0:404dae88af71 324 if(x2 < x1) incx = -1;
MartinJohnson 0:404dae88af71 325 incy = 1;
MartinJohnson 0:404dae88af71 326 if(y2 < y1) incy = -1;
MartinJohnson 0:404dae88af71 327 x=x1;
MartinJohnson 0:404dae88af71 328 y=y1;
MartinJohnson 0:404dae88af71 329
MartinJohnson 0:404dae88af71 330 if (dx > dy) {
MartinJohnson 0:404dae88af71 331 gdiPoint(prc, x, y, rop);
MartinJohnson 0:404dae88af71 332 e = 2*dy - dx;
MartinJohnson 0:404dae88af71 333 inc1 = 2 * ( dy -dx);
MartinJohnson 0:404dae88af71 334 inc2 = 2 * dy;
MartinJohnson 0:404dae88af71 335 for (i = 0; i < dx; i++) {
MartinJohnson 0:404dae88af71 336 if (e >= 0) {
MartinJohnson 0:404dae88af71 337 y += incy;
MartinJohnson 0:404dae88af71 338 e += inc1;
MartinJohnson 0:404dae88af71 339 }
MartinJohnson 0:404dae88af71 340 else {
MartinJohnson 0:404dae88af71 341 e += inc2;
MartinJohnson 0:404dae88af71 342 }
MartinJohnson 0:404dae88af71 343 x += incx;
MartinJohnson 0:404dae88af71 344 gdiPoint(prc, x, y, rop);
MartinJohnson 0:404dae88af71 345 }
MartinJohnson 0:404dae88af71 346 } else {
MartinJohnson 0:404dae88af71 347 gdiPoint(prc, x, y, rop);
MartinJohnson 0:404dae88af71 348 e = 2 * dx - dy;
MartinJohnson 0:404dae88af71 349 inc1 = 2 * (dx - dy);
MartinJohnson 0:404dae88af71 350 inc2 = 2 * dx;
MartinJohnson 0:404dae88af71 351 for(i = 0; i < dy; i++) {
MartinJohnson 0:404dae88af71 352 if (e >= 0) {
MartinJohnson 0:404dae88af71 353 x += incx;
MartinJohnson 0:404dae88af71 354 e += inc1;
MartinJohnson 0:404dae88af71 355 } else {
MartinJohnson 0:404dae88af71 356 e += inc2;
MartinJohnson 0:404dae88af71 357 }
MartinJohnson 0:404dae88af71 358 y += incy;
MartinJohnson 0:404dae88af71 359 gdiPoint(prc, x, y, rop);
MartinJohnson 0:404dae88af71 360 }
MartinJohnson 0:404dae88af71 361 }
MartinJohnson 0:404dae88af71 362 }
MartinJohnson 0:404dae88af71 363
MartinJohnson 0:404dae88af71 364 //*****************************************************************************
MartinJohnson 0:404dae88af71 365 // Function gdiRectangle(i16 x1, i16 y1, i16 x2, i16 y2, u16 rop)
MartinJohnson 0:404dae88af71 366 //
MartinJohnson 0:404dae88af71 367 // Draw rectangle
MartinJohnson 0:404dae88af71 368 //
MartinJohnson 0:404dae88af71 369 // parameters:
MartinJohnson 0:404dae88af71 370 // x1 X start position
MartinJohnson 0:404dae88af71 371 // y1 Y start position
MartinJohnson 0:404dae88af71 372 // x2 X end position
MartinJohnson 0:404dae88af71 373 // y2 Y end position
MartinJohnson 0:404dae88af71 374 // rop Raster operation. See GDI_ROP_xxx defines
MartinJohnson 0:404dae88af71 375 //
MartinJohnson 0:404dae88af71 376 // return none
MartinJohnson 0:404dae88af71 377 //*****************************************************************************
MartinJohnson 0:404dae88af71 378 void gdiRectangle(i16 x0, i16 y0, i16 x1, i16 y1, u16 rop) {
MartinJohnson 0:404dae88af71 379
MartinJohnson 0:404dae88af71 380 gdiLine(NULL,x0,y0,x1,y0,rop);
MartinJohnson 0:404dae88af71 381 gdiLine(NULL,x0,y1,x1,y1,rop);
MartinJohnson 0:404dae88af71 382 gdiLine(NULL,x0,y0,x0,y1,rop);
MartinJohnson 0:404dae88af71 383 gdiLine(NULL,x1,y0,x1,y1,rop);
MartinJohnson 0:404dae88af71 384 }
MartinJohnson 0:404dae88af71 385
MartinJohnson 0:404dae88af71 386 //*****************************************************************************
MartinJohnson 0:404dae88af71 387 // Function gdiRectangleEx(PGDI_RECT rc, u16 rop)
MartinJohnson 0:404dae88af71 388 //
MartinJohnson 0:404dae88af71 389 // Draw rectangle
MartinJohnson 0:404dae88af71 390 //
MartinJohnson 0:404dae88af71 391 // parameters:
MartinJohnson 0:404dae88af71 392 // rc Struct containing the rectangle parameters
MartinJohnson 0:404dae88af71 393 // rop Raster operation. See GDI_ROP_xxx defines
MartinJohnson 0:404dae88af71 394 //
MartinJohnson 0:404dae88af71 395 // return none
MartinJohnson 0:404dae88af71 396 //*****************************************************************************
MartinJohnson 0:404dae88af71 397 void gdiRectangleEx(PGDI_RECT rc, u16 rop) {
MartinJohnson 0:404dae88af71 398
MartinJohnson 0:404dae88af71 399 gdiRectangle(rc->x, rc->y, rc->x + rc->w, rc->y + rc->h,rop);
MartinJohnson 0:404dae88af71 400 }
MartinJohnson 0:404dae88af71 401
MartinJohnson 0:404dae88af71 402 //*****************************************************************************
MartinJohnson 0:404dae88af71 403 // Function gdiCircle(i16 x, i16 y, i16 r, u16 rop)
MartinJohnson 0:404dae88af71 404 //
MartinJohnson 0:404dae88af71 405 // Draw circle. This function uses the integer-precision math
MartinJohnson 0:404dae88af71 406 //
MartinJohnson 0:404dae88af71 407 // parameters:
MartinJohnson 0:404dae88af71 408 // x Circle center X position
MartinJohnson 0:404dae88af71 409 // y Circle center Y position
MartinJohnson 0:404dae88af71 410 // r Radius
MartinJohnson 0:404dae88af71 411 // rop Raster operation. See GDI_ROP_xxx defines
MartinJohnson 0:404dae88af71 412 //
MartinJohnson 0:404dae88af71 413 // return none
MartinJohnson 0:404dae88af71 414 //*****************************************************************************
MartinJohnson 0:404dae88af71 415 void gdiCircle(u16 x, u16 y, u16 r, u16 rop) {
MartinJohnson 0:404dae88af71 416
MartinJohnson 0:404dae88af71 417 i32 x1, y1;
MartinJohnson 0:404dae88af71 418 u16 a;
MartinJohnson 0:404dae88af71 419
MartinJohnson 0:404dae88af71 420 for (a = 0; a < 360; a++) {
MartinJohnson 0:404dae88af71 421 x1 = r * mthCos(a);
MartinJohnson 0:404dae88af71 422 y1 = r * mthSin(a);
MartinJohnson 0:404dae88af71 423 gdiPoint(NULL, (x1 / 10000) + x,(y1 / 10000) + y,rop);
MartinJohnson 0:404dae88af71 424 }
MartinJohnson 0:404dae88af71 425 }
MartinJohnson 0:404dae88af71 426
MartinJohnson 0:404dae88af71 427 //*****************************************************************************
MartinJohnson 0:404dae88af71 428 // Function gdiDrawText(PGDI_RECT prc, pu8 ptext, u16 style, u16 rop)
MartinJohnson 0:404dae88af71 429 //
MartinJohnson 0:404dae88af71 430 // Draw text inside rectangle
MartinJohnson 0:404dae88af71 431 //
MartinJohnson 0:404dae88af71 432 // parameters:
MartinJohnson 0:404dae88af71 433 // prc Pointer to clipping rectangle
MartinJohnson 0:404dae88af71 434 // ptext Pointer to text
MartinJohnson 0:404dae88af71 435 // style Text style (see GDI_WINCAPTION_xx defines)
MartinJohnson 0:404dae88af71 436 // rop Raster operation. See GDI_ROP_xxx defines
MartinJohnson 0:404dae88af71 437 //
MartinJohnson 0:404dae88af71 438 // return none
MartinJohnson 0:404dae88af71 439 //*****************************************************************************
MartinJohnson 0:404dae88af71 440 CCM void gdiDrawText(PGDI_RECT prc, pu8 ptext, u16 style, u16 rop) {
MartinJohnson 0:404dae88af71 441
MartinJohnson 0:404dae88af71 442 u16 l, i, pos, xp;
MartinJohnson 0:404dae88af71 443 u8 c;
MartinJohnson 0:404dae88af71 444 pu8 ptx;
MartinJohnson 0:404dae88af71 445
MartinJohnson 0:404dae88af71 446 l = strLen(ptext) * GDI_SYSFONT_WIDTH;
MartinJohnson 0:404dae88af71 447 switch(style) {
MartinJohnson 0:404dae88af71 448 case GDI_WINCAPTION_RIGHT: if (l < prc->w) {
MartinJohnson 0:404dae88af71 449 prc->x += (prc->w - l);
MartinJohnson 0:404dae88af71 450 }
MartinJohnson 0:404dae88af71 451 break;
MartinJohnson 0:404dae88af71 452 case GDI_WINCAPTION_CENTER: if (l < prc->w) {
MartinJohnson 0:404dae88af71 453 prc->x += ((prc->w - l) / 2);
MartinJohnson 0:404dae88af71 454 }
MartinJohnson 0:404dae88af71 455 break;
MartinJohnson 0:404dae88af71 456 }
MartinJohnson 0:404dae88af71 457 l = strLen(ptext);
MartinJohnson 0:404dae88af71 458 xp = 1;//prc->x;
MartinJohnson 0:404dae88af71 459 for (i = 0; i < l; i++) {
MartinJohnson 0:404dae88af71 460 c = *(ptext++);
MartinJohnson 0:404dae88af71 461 if (c >= GDI_SYSFONT_OFFSET) {
MartinJohnson 0:404dae88af71 462 pos = (u16) (c - GDI_SYSFONT_OFFSET) * GDI_SYSFONT_BYTEWIDTH * GDI_SYSFONT_HEIGHT;
MartinJohnson 0:404dae88af71 463 ptx = ((pu8) gdiSystemFont) + pos;
MartinJohnson 0:404dae88af71 464 gdiBitBlt(prc, xp, 0, GDI_SYSFONT_WIDTH, GDI_SYSFONT_HEIGHT, ptx, rop);
MartinJohnson 0:404dae88af71 465 xp += GDI_SYSFONT_WIDTH;
MartinJohnson 0:404dae88af71 466 if (xp >= ((prc->x + prc->w) - GDI_SYSFONT_WIDTH)) return;
MartinJohnson 0:404dae88af71 467 }
MartinJohnson 0:404dae88af71 468 }
MartinJohnson 0:404dae88af71 469 }
MartinJohnson 0:404dae88af71 470
MartinJohnson 0:404dae88af71 471 //*****************************************************************************
MartinJohnson 0:404dae88af71 472 // Function gdiDrawTextEx(i16 x, i16 y, pu8 ptext, u16 rop)
MartinJohnson 0:404dae88af71 473 //
MartinJohnson 0:404dae88af71 474 // Draw text in X/Y position using system font.
MartinJohnson 0:404dae88af71 475 //
MartinJohnson 0:404dae88af71 476 // parameters:
MartinJohnson 0:404dae88af71 477 // x X start position
MartinJohnson 0:404dae88af71 478 // y Y start position
MartinJohnson 0:404dae88af71 479 // ptext Pointer to text
MartinJohnson 0:404dae88af71 480 // rop Raster operation. See GDI_ROP_xxx defines
MartinJohnson 0:404dae88af71 481 //
MartinJohnson 0:404dae88af71 482 // return none
MartinJohnson 0:404dae88af71 483 //*****************************************************************************
MartinJohnson 0:404dae88af71 484 void gdiDrawTextEx(i16 x, i16 y, pu8 ptext, u16 rop) {
MartinJohnson 0:404dae88af71 485
MartinJohnson 0:404dae88af71 486 u16 l, i, pos, xp;
MartinJohnson 0:404dae88af71 487 u8 c;
MartinJohnson 0:404dae88af71 488 pu8 ptx;
MartinJohnson 0:404dae88af71 489
MartinJohnson 0:404dae88af71 490 l = strLen(ptext);
MartinJohnson 0:404dae88af71 491 xp = x;
MartinJohnson 0:404dae88af71 492 for (i = 0; i < l; i++) {
MartinJohnson 0:404dae88af71 493 c = *(ptext++);
MartinJohnson 0:404dae88af71 494 if (c >= GDI_SYSFONT_OFFSET) {
MartinJohnson 0:404dae88af71 495 pos = (u16) (c - GDI_SYSFONT_OFFSET) * GDI_SYSFONT_BYTEWIDTH * GDI_SYSFONT_HEIGHT;
MartinJohnson 0:404dae88af71 496 ptx = ((pu8) gdiSystemFont) + pos;
MartinJohnson 0:404dae88af71 497 gdiBitBlt(NULL, xp, y, GDI_SYSFONT_WIDTH, GDI_SYSFONT_HEIGHT, ptx, rop);
MartinJohnson 0:404dae88af71 498 xp += GDI_SYSFONT_WIDTH;
MartinJohnson 0:404dae88af71 499 if (xp >= VID_PIXELS_X) return;
MartinJohnson 0:404dae88af71 500 }
MartinJohnson 0:404dae88af71 501 }
MartinJohnson 0:404dae88af71 502 }
MartinJohnson 0:404dae88af71 503 //*****************************************************************************
MartinJohnson 0:404dae88af71 504 // Function gdiDrawWindow(PGDI_WINDOW pwin)
MartinJohnson 0:404dae88af71 505 //
MartinJohnson 0:404dae88af71 506 // Draw window
MartinJohnson 0:404dae88af71 507 //
MartinJohnson 0:404dae88af71 508 // parameters:
MartinJohnson 0:404dae88af71 509 // pwin Pointer to windows struct
MartinJohnson 0:404dae88af71 510 //
MartinJohnson 0:404dae88af71 511 // return none
MartinJohnson 0:404dae88af71 512 //*****************************************************************************
MartinJohnson 0:404dae88af71 513 void gdiDrawWindow(PGDI_WINDOW pwin) {
MartinJohnson 0:404dae88af71 514
MartinJohnson 0:404dae88af71 515 i16 i;
MartinJohnson 0:404dae88af71 516 GDI_RECT rc, rt;
MartinJohnson 0:404dae88af71 517
MartinJohnson 0:404dae88af71 518 gdiCopyRect(&rc,&pwin->rc);
MartinJohnson 0:404dae88af71 519 if (pwin->style & GDI_WINCAPTION) {
MartinJohnson 0:404dae88af71 520 gdiCopyRect(&rt,&pwin->rc);
MartinJohnson 0:404dae88af71 521 rt.h = rt.y + 11;
MartinJohnson 0:404dae88af71 522 rt.x += 2;
MartinJohnson 0:404dae88af71 523 rt.y += 1;
MartinJohnson 0:404dae88af71 524 rc.h += 10;
MartinJohnson 0:404dae88af71 525 for (i = 0; i < 11; i++) {
MartinJohnson 0:404dae88af71 526 gdiLine(NULL,rc.x, rc.y + i, rc.x + rc.w, rc.y + i, GDI_ROP_COPY);
MartinJohnson 0:404dae88af71 527 }
MartinJohnson 0:404dae88af71 528 if (pwin->style & GDI_WINCLOSEICON) {
MartinJohnson 0:404dae88af71 529 gdiBitBlt(&rc, rc.w - 9, 1, 10, 9, (pu8) gdiCloseBm, GDI_ROP_COPY);
MartinJohnson 0:404dae88af71 530 rt.w -= 11;
MartinJohnson 0:404dae88af71 531 } else {
MartinJohnson 0:404dae88af71 532 rt.w -= 1;
MartinJohnson 0:404dae88af71 533 }
MartinJohnson 0:404dae88af71 534 gdiDrawText(&rt,pwin->caption,pwin->style & GDI_WINCAPTION_MASK, GDI_ROP_XOR);
MartinJohnson 0:404dae88af71 535 }
MartinJohnson 0:404dae88af71 536 gdiRectangleEx(&rc,GDI_ROP_COPY);
MartinJohnson 0:404dae88af71 537 }
MartinJohnson 0:404dae88af71 538
MartinJohnson 0:404dae88af71 539