Platform library for RETRO

Dependents:   RETRO_RickGame

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Display.cpp Source File

Display.cpp

00001 /*
00002  * (C) Copyright 2015 Valentin Ivanov. All rights reserved.
00003  *
00004  * This file is part of the RetroPlatform Library
00005  *
00006  * The RetroPlatform Library is free software: you can redistribute it and/or modify
00007  * it under the terms of the GNU Lesser General Public License as published by
00008  * the Free Software Foundation, either version 3 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public License
00017  * along with this program.  If not, see <http://www.gnu.org/licenses/>
00018  *
00019  * This library is inspired by Gamebuino Library (http://gamebuino.com)
00020  * from Aurélien Rodot. 
00021  */
00022 #include "mbed.h"
00023 #include "Display.h"
00024 
00025 Display::Display( PinName backlightPin, PinName resetPin, PinName dsPin,
00026                   PinName mosiPin, PinName misoPin, PinName clkPin, PinName csPin, PanelColorFilter colorFilter )
00027     : LCD_ST7735(backlightPin, resetPin, dsPin, mosiPin, misoPin, clkPin, csPin, colorFilter )
00028 {
00029 }
00030 
00031 
00032 void Display::drawBitmapIndexed(uint8_t x, uint8_t y, const uint8_t *pbmp)
00033 {
00034     drawBitmapIndexed(x, y, pbmp[0], pbmp[1],  pbmp+2);
00035 }
00036 
00037 void Display::drawBitmapIndexed(uint8_t x, uint8_t y, uint8_t w, uint8_t h,  const uint8_t *pbmp)
00038 {
00039     clip(x, y, w, h);
00040     int bytes = w * h / 8;
00041     beginBatchCommand(CMD_RAMWR);
00042 
00043     while(bytes--) {
00044 //        writeBatchData(_pPalette[*pbmp>>7&0x1]);
00045 //        writeBatchData(_pPalette[*pbmp>>6&0x1]);
00046 //        writeBatchData(_pPalette[*pbmp>>5&0x1]);
00047 //        writeBatchData(_pPalette[*pbmp>>4&0x1]);
00048 //        writeBatchData(_pPalette[*pbmp>>3&0x1]);
00049 //        writeBatchData(_pPalette[*pbmp>>2&0x1]);
00050 //        writeBatchData(_pPalette[*pbmp>>1&0x1]);
00051 //        writeBatchData(_pPalette[(*pbmp++)&0x1]);
00052     }
00053     endBatchCommand();
00054 }
00055 
00056 void Display::drawBitmapIndexed(uint8_t x, uint8_t y, uint8_t w, uint8_t h,  const uint8_t *pbmp, const uint16_t *palette, bool mirrored)
00057 {
00058     clip(x, y, w, h);
00059     int pixels = w * h;
00060     beginBatchCommand(CMD_RAMWR);
00061 
00062     if( mirrored ) {
00063         for( int iy =0; iy < h; iy++ ) {
00064             const uint8_t * p  = pbmp + (w>>1)*iy + (w>>1)-1;
00065             for( int ix =0; ix < w; ) {
00066                 writeBatchData(palette[(*p)&0x0F]);
00067                 writeBatchData(palette[((*p)>>4)&0x0F]);
00068                 ix+=2;
00069                 p--;
00070             }
00071         }
00072     } else {
00073         while(pixels) {
00074             writeBatchData(palette[((*pbmp)>>4)&0x0F]);
00075             writeBatchData(palette[(*pbmp)&0x0F]);
00076             pixels-=2;
00077             pbmp++;
00078         }
00079     }
00080     endBatchCommand();
00081 }
00082 
00083 //void Display::drawBitmapTransparent(uint8_t x, uint8_t y, uint8_t w, uint8_t h,  const uint8_t *pbmp, const uint16_t *palette, uint8_t color, bool mirrored )
00084 //{
00085 //    clip(x, y, w, h);
00086 //    int pixels = w * h;
00087 //    beginBatchCommand(CMD_RAMWR);
00088 //
00089 //    if( mirrored ) {
00090 //        for( int iy =0; iy < h; iy++ ) {
00091 //            const uint8_t * p  = pbmp + w*iy + w-1;
00092 //            for( int ix =0; ix < w; ix++ ) {
00093 //            {
00094 //                writeBatchData(palette[*p--]);
00095 //             }
00096 //            }
00097 //        }
00098 //    } else {
00099 //        while(pixels--) {
00100 //            writeBatchData(palette[*pbmp++]);
00101 //        }
00102 //    }
00103 //    endBatchCommand();
00104 //}
00105 
00106 void Display::drawBitmapIndexed(uint8_t x, uint8_t y, int w, int h, int src_x, int src_y, int srcWidth, int srcHeight, const uint8_t *pbmp, const uint16_t *palette)
00107 {
00108     clip(x, y, srcWidth, srcHeight);
00109     beginBatchCommand(CMD_RAMWR);
00110     const uint8_t *p = pbmp + src_x + (src_y * w);
00111     for(int iy = 0; iy < srcHeight; ++iy) {
00112         for(int ix = 0; ix < srcWidth; ++ix) {
00113             writeBatchData(palette[*(p + ix)]);
00114         }
00115         p += w;
00116     }
00117     endBatchCommand();
00118 }
00119 
00120 void Display::eraseBitmapIndexed(uint8_t x, uint8_t y, const uint8_t *pbmp)
00121 {
00122     eraseBitmapIndexed(x, y, pbmp[0], pbmp[1],  pbmp+2);
00123 }
00124 
00125 void Display::eraseBitmapIndexed(uint8_t x, uint8_t y, uint8_t w, uint8_t h,  const uint8_t *pbmp)
00126 {
00127     clip(x, y, w, h);
00128     int bytes = w * h / 8;
00129     beginBatchCommand(CMD_RAMWR);
00130 
00131     while(bytes--) {
00132 //        writeBatchData(_pPalette[0]);
00133 //        writeBatchData(_pPalette[0]);
00134 //        writeBatchData(_pPalette[0]);
00135 //        writeBatchData(_pPalette[0]);
00136 //        writeBatchData(_pPalette[0]);
00137 //        writeBatchData(_pPalette[0]);
00138 //        writeBatchData(_pPalette[0]);
00139 //        writeBatchData(_pPalette[0]);
00140     }
00141     endBatchCommand();
00142 }