Versión de Firmware con funciones de RAM incorporadas.
Dependencies: mbed
Fork of VmRecorderV1dot1 by
Doggy/draw2D.cpp@0:3d456b8ce449, 2015-06-15 (annotated)
- Committer:
- JuanManuelAmador
- Date:
- Mon Jun 15 15:34:27 2015 +0000
- Revision:
- 0:3d456b8ce449
prueba
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JuanManuelAmador | 0:3d456b8ce449 | 1 | #include "doggy.h" |
JuanManuelAmador | 0:3d456b8ce449 | 2 | |
JuanManuelAmador | 0:3d456b8ce449 | 3 | void DogMLCD::LineH( int x0, int y, int x1, doggy_op raster ) |
JuanManuelAmador | 0:3d456b8ce449 | 4 | { |
JuanManuelAmador | 0:3d456b8ce449 | 5 | if( y & 0xFFC0 ) return; // line is out of screen |
JuanManuelAmador | 0:3d456b8ce449 | 6 | BOUND( x0, 0, 127 ) |
JuanManuelAmador | 0:3d456b8ce449 | 7 | BOUND( x1, 0, 127 ) |
JuanManuelAmador | 0:3d456b8ce449 | 8 | ORDER( x0, x1 ) |
JuanManuelAmador | 0:3d456b8ce449 | 9 | |
JuanManuelAmador | 0:3d456b8ce449 | 10 | int n = x1 - x0 + 1; |
JuanManuelAmador | 0:3d456b8ce449 | 11 | char* p = b_ + (( y & 0x38 ) << 4) + x0; |
JuanManuelAmador | 0:3d456b8ce449 | 12 | if( raster == poke ) |
JuanManuelAmador | 0:3d456b8ce449 | 13 | { |
JuanManuelAmador | 0:3d456b8ce449 | 14 | char b = DOGMLCD_on[ y & 7 ]; |
JuanManuelAmador | 0:3d456b8ce449 | 15 | while( n-- ) |
JuanManuelAmador | 0:3d456b8ce449 | 16 | *p++ |= b; |
JuanManuelAmador | 0:3d456b8ce449 | 17 | } |
JuanManuelAmador | 0:3d456b8ce449 | 18 | else if( raster == wipe ) |
JuanManuelAmador | 0:3d456b8ce449 | 19 | { |
JuanManuelAmador | 0:3d456b8ce449 | 20 | char b = DOGMLCD_off[ y & 7 ]; |
JuanManuelAmador | 0:3d456b8ce449 | 21 | while( n-- ) |
JuanManuelAmador | 0:3d456b8ce449 | 22 | *p++ &= b; |
JuanManuelAmador | 0:3d456b8ce449 | 23 | } |
JuanManuelAmador | 0:3d456b8ce449 | 24 | else |
JuanManuelAmador | 0:3d456b8ce449 | 25 | { |
JuanManuelAmador | 0:3d456b8ce449 | 26 | char b = DOGMLCD_on[ y & 7 ]; |
JuanManuelAmador | 0:3d456b8ce449 | 27 | while( n-- ) |
JuanManuelAmador | 0:3d456b8ce449 | 28 | *p++ ^= b; |
JuanManuelAmador | 0:3d456b8ce449 | 29 | } |
JuanManuelAmador | 0:3d456b8ce449 | 30 | } |
JuanManuelAmador | 0:3d456b8ce449 | 31 | void DogMLCD::LineV( int x, int y0, int y1, doggy_op raster ) |
JuanManuelAmador | 0:3d456b8ce449 | 32 | { |
JuanManuelAmador | 0:3d456b8ce449 | 33 | if( x & 0xFF80 ) return; // line is out of screen |
JuanManuelAmador | 0:3d456b8ce449 | 34 | BOUND( y0, 0, 63 ) |
JuanManuelAmador | 0:3d456b8ce449 | 35 | BOUND( y1, 0, 63 ) |
JuanManuelAmador | 0:3d456b8ce449 | 36 | ORDER( y0, y1 ) |
JuanManuelAmador | 0:3d456b8ce449 | 37 | RasterOp op = ((RasterOp[]){ &DogMLCD::Poke, &DogMLCD::Wipe, &DogMLCD::Inv })[raster]; |
JuanManuelAmador | 0:3d456b8ce449 | 38 | for( int y = y0 ; y <= y1 ; y++ ) |
JuanManuelAmador | 0:3d456b8ce449 | 39 | (this->*op)( x, y ); |
JuanManuelAmador | 0:3d456b8ce449 | 40 | } |
JuanManuelAmador | 0:3d456b8ce449 | 41 | void DogMLCD::Line( int x0, int y0, int x1, int y1, doggy_op raster ) |
JuanManuelAmador | 0:3d456b8ce449 | 42 | { |
JuanManuelAmador | 0:3d456b8ce449 | 43 | bool steep = abs( y1 - y0 ) > abs( x1 - x0 ); |
JuanManuelAmador | 0:3d456b8ce449 | 44 | if( steep ) { SWAP( x0, y0 ) SWAP( x1, y1 ) } |
JuanManuelAmador | 0:3d456b8ce449 | 45 | if( x0 > x1) { SWAP( x0, x1 ) SWAP( y0, y1 ) } |
JuanManuelAmador | 0:3d456b8ce449 | 46 | |
JuanManuelAmador | 0:3d456b8ce449 | 47 | int dx = x1 - x0; |
JuanManuelAmador | 0:3d456b8ce449 | 48 | int dy = abs( y1 - y0 ); |
JuanManuelAmador | 0:3d456b8ce449 | 49 | int e = dx / 2; |
JuanManuelAmador | 0:3d456b8ce449 | 50 | int ystep = y0 < y1 ? 1 : -1; |
JuanManuelAmador | 0:3d456b8ce449 | 51 | RasterOp op = ((RasterOp[]){ &DogMLCD::Poke, &DogMLCD::Wipe, &DogMLCD::Inv })[raster]; |
JuanManuelAmador | 0:3d456b8ce449 | 52 | |
JuanManuelAmador | 0:3d456b8ce449 | 53 | if( steep ) for( int x = x0, y = y0 ; x <= x1 ; x++ ) |
JuanManuelAmador | 0:3d456b8ce449 | 54 | { |
JuanManuelAmador | 0:3d456b8ce449 | 55 | (this->*op)( y, x ); |
JuanManuelAmador | 0:3d456b8ce449 | 56 | if( ( e -= dy ) < 0 ) |
JuanManuelAmador | 0:3d456b8ce449 | 57 | { |
JuanManuelAmador | 0:3d456b8ce449 | 58 | y += ystep; |
JuanManuelAmador | 0:3d456b8ce449 | 59 | e += dx; |
JuanManuelAmador | 0:3d456b8ce449 | 60 | } |
JuanManuelAmador | 0:3d456b8ce449 | 61 | } |
JuanManuelAmador | 0:3d456b8ce449 | 62 | else for( int x = x0, y = y0 ; x <= x1 ; x++ ) |
JuanManuelAmador | 0:3d456b8ce449 | 63 | { |
JuanManuelAmador | 0:3d456b8ce449 | 64 | (this->*op)( x, y ); |
JuanManuelAmador | 0:3d456b8ce449 | 65 | if( ( e -= dy ) < 0 ) |
JuanManuelAmador | 0:3d456b8ce449 | 66 | { |
JuanManuelAmador | 0:3d456b8ce449 | 67 | y += ystep; |
JuanManuelAmador | 0:3d456b8ce449 | 68 | e += dx; |
JuanManuelAmador | 0:3d456b8ce449 | 69 | } |
JuanManuelAmador | 0:3d456b8ce449 | 70 | } |
JuanManuelAmador | 0:3d456b8ce449 | 71 | } |
JuanManuelAmador | 0:3d456b8ce449 | 72 | void DogMLCD::Frame( int x0, int y0, int x1, int y1, doggy_op raster ) |
JuanManuelAmador | 0:3d456b8ce449 | 73 | { |
JuanManuelAmador | 0:3d456b8ce449 | 74 | ORDER( x0, x1 ) |
JuanManuelAmador | 0:3d456b8ce449 | 75 | ORDER( y0, y1 ) |
JuanManuelAmador | 0:3d456b8ce449 | 76 | |
JuanManuelAmador | 0:3d456b8ce449 | 77 | LineH( x0, y0, x1, raster ); |
JuanManuelAmador | 0:3d456b8ce449 | 78 | if( y1 > y0 ) LineH( x0, y1, x1, raster ); |
JuanManuelAmador | 0:3d456b8ce449 | 79 | |
JuanManuelAmador | 0:3d456b8ce449 | 80 | y0++; // don't overlap at angles |
JuanManuelAmador | 0:3d456b8ce449 | 81 | y1--; |
JuanManuelAmador | 0:3d456b8ce449 | 82 | if( y1 >= y0 ) // don't overlap if horizontal lines where adjacent |
JuanManuelAmador | 0:3d456b8ce449 | 83 | { |
JuanManuelAmador | 0:3d456b8ce449 | 84 | LineV( x0, y0, y1, raster ); |
JuanManuelAmador | 0:3d456b8ce449 | 85 | if( x1 > x0 ) LineV( x1, y0, y1, raster ); |
JuanManuelAmador | 0:3d456b8ce449 | 86 | } |
JuanManuelAmador | 0:3d456b8ce449 | 87 | } |
JuanManuelAmador | 0:3d456b8ce449 | 88 | void DogMLCD::Rect( int x0, int y0, int x1, int y1, const unsigned char* p, doggy_op raster ) |
JuanManuelAmador | 0:3d456b8ce449 | 89 | { |
JuanManuelAmador | 0:3d456b8ce449 | 90 | BOUND( x0, 0, 127 ) |
JuanManuelAmador | 0:3d456b8ce449 | 91 | BOUND( x1, 0, 127 ) |
JuanManuelAmador | 0:3d456b8ce449 | 92 | BOUND( y0, 0, 63 ) |
JuanManuelAmador | 0:3d456b8ce449 | 93 | BOUND( y1, 0, 63 ) |
JuanManuelAmador | 0:3d456b8ce449 | 94 | ORDER( x0, x1 ) |
JuanManuelAmador | 0:3d456b8ce449 | 95 | ORDER( y0, y1 ) |
JuanManuelAmador | 0:3d456b8ce449 | 96 | RasterOp op = ((RasterOp[]){ &DogMLCD::Poke, &DogMLCD::Wipe, &DogMLCD::Inv })[raster]; |
JuanManuelAmador | 0:3d456b8ce449 | 97 | for( int x = x0 ; x <= x1 ; x++ ) |
JuanManuelAmador | 0:3d456b8ce449 | 98 | for( int y = y0 ; y <= y1 ; y++ ) |
JuanManuelAmador | 0:3d456b8ce449 | 99 | if( p[x & 7] & ( 1 << ( y & 7 ) ) ) |
JuanManuelAmador | 0:3d456b8ce449 | 100 | (this->*op)( x, y ); |
JuanManuelAmador | 0:3d456b8ce449 | 101 | } |