Platform library for RETRO

Dependents:   RETRO_RickGame

Committer:
Architect
Date:
Sun Mar 01 05:29:45 2015 +0000
Revision:
0:6f26c31d8573
RetroPlatform Library for RETRO gaming system

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Architect 0:6f26c31d8573 1 /*
Architect 0:6f26c31d8573 2 * (C) Copyright 2015 Valentin Ivanov. All rights reserved.
Architect 0:6f26c31d8573 3 *
Architect 0:6f26c31d8573 4 * This file is part of the RetroPlatform Library
Architect 0:6f26c31d8573 5 *
Architect 0:6f26c31d8573 6 * The RetroPlatform Library is free software: you can redistribute it and/or modify
Architect 0:6f26c31d8573 7 * it under the terms of the GNU Lesser General Public License as published by
Architect 0:6f26c31d8573 8 * the Free Software Foundation, either version 3 of the License, or
Architect 0:6f26c31d8573 9 * (at your option) any later version.
Architect 0:6f26c31d8573 10 *
Architect 0:6f26c31d8573 11 * This program is distributed in the hope that it will be useful,
Architect 0:6f26c31d8573 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Architect 0:6f26c31d8573 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Architect 0:6f26c31d8573 14 * GNU Lesser General Public License for more details.
Architect 0:6f26c31d8573 15 *
Architect 0:6f26c31d8573 16 * You should have received a copy of the GNU Lesser General Public License
Architect 0:6f26c31d8573 17 * along with this program. If not, see <http://www.gnu.org/licenses/>
Architect 0:6f26c31d8573 18 *
Architect 0:6f26c31d8573 19 * This library is inspired by Gamebuino Library (http://gamebuino.com)
Architect 0:6f26c31d8573 20 * from Aurélien Rodot.
Architect 0:6f26c31d8573 21 */
Architect 0:6f26c31d8573 22 #include "mbed.h"
Architect 0:6f26c31d8573 23 #include "Display.h"
Architect 0:6f26c31d8573 24
Architect 0:6f26c31d8573 25 Display::Display( PinName backlightPin, PinName resetPin, PinName dsPin,
Architect 0:6f26c31d8573 26 PinName mosiPin, PinName misoPin, PinName clkPin, PinName csPin, PanelColorFilter colorFilter )
Architect 0:6f26c31d8573 27 : LCD_ST7735(backlightPin, resetPin, dsPin, mosiPin, misoPin, clkPin, csPin, colorFilter )
Architect 0:6f26c31d8573 28 {
Architect 0:6f26c31d8573 29 }
Architect 0:6f26c31d8573 30
Architect 0:6f26c31d8573 31
Architect 0:6f26c31d8573 32 void Display::drawBitmapIndexed(uint8_t x, uint8_t y, const uint8_t *pbmp)
Architect 0:6f26c31d8573 33 {
Architect 0:6f26c31d8573 34 drawBitmapIndexed(x, y, pbmp[0], pbmp[1], pbmp+2);
Architect 0:6f26c31d8573 35 }
Architect 0:6f26c31d8573 36
Architect 0:6f26c31d8573 37 void Display::drawBitmapIndexed(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t *pbmp)
Architect 0:6f26c31d8573 38 {
Architect 0:6f26c31d8573 39 clip(x, y, w, h);
Architect 0:6f26c31d8573 40 int bytes = w * h / 8;
Architect 0:6f26c31d8573 41 beginBatchCommand(CMD_RAMWR);
Architect 0:6f26c31d8573 42
Architect 0:6f26c31d8573 43 while(bytes--) {
Architect 0:6f26c31d8573 44 // writeBatchData(_pPalette[*pbmp>>7&0x1]);
Architect 0:6f26c31d8573 45 // writeBatchData(_pPalette[*pbmp>>6&0x1]);
Architect 0:6f26c31d8573 46 // writeBatchData(_pPalette[*pbmp>>5&0x1]);
Architect 0:6f26c31d8573 47 // writeBatchData(_pPalette[*pbmp>>4&0x1]);
Architect 0:6f26c31d8573 48 // writeBatchData(_pPalette[*pbmp>>3&0x1]);
Architect 0:6f26c31d8573 49 // writeBatchData(_pPalette[*pbmp>>2&0x1]);
Architect 0:6f26c31d8573 50 // writeBatchData(_pPalette[*pbmp>>1&0x1]);
Architect 0:6f26c31d8573 51 // writeBatchData(_pPalette[(*pbmp++)&0x1]);
Architect 0:6f26c31d8573 52 }
Architect 0:6f26c31d8573 53 endBatchCommand();
Architect 0:6f26c31d8573 54 }
Architect 0:6f26c31d8573 55
Architect 0:6f26c31d8573 56 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)
Architect 0:6f26c31d8573 57 {
Architect 0:6f26c31d8573 58 clip(x, y, w, h);
Architect 0:6f26c31d8573 59 int pixels = w * h;
Architect 0:6f26c31d8573 60 beginBatchCommand(CMD_RAMWR);
Architect 0:6f26c31d8573 61
Architect 0:6f26c31d8573 62 if( mirrored ) {
Architect 0:6f26c31d8573 63 for( int iy =0; iy < h; iy++ ) {
Architect 0:6f26c31d8573 64 const uint8_t * p = pbmp + (w>>1)*iy + (w>>1)-1;
Architect 0:6f26c31d8573 65 for( int ix =0; ix < w; ) {
Architect 0:6f26c31d8573 66 writeBatchData(palette[(*p)&0x0F]);
Architect 0:6f26c31d8573 67 writeBatchData(palette[((*p)>>4)&0x0F]);
Architect 0:6f26c31d8573 68 ix+=2;
Architect 0:6f26c31d8573 69 p--;
Architect 0:6f26c31d8573 70 }
Architect 0:6f26c31d8573 71 }
Architect 0:6f26c31d8573 72 } else {
Architect 0:6f26c31d8573 73 while(pixels) {
Architect 0:6f26c31d8573 74 writeBatchData(palette[((*pbmp)>>4)&0x0F]);
Architect 0:6f26c31d8573 75 writeBatchData(palette[(*pbmp)&0x0F]);
Architect 0:6f26c31d8573 76 pixels-=2;
Architect 0:6f26c31d8573 77 pbmp++;
Architect 0:6f26c31d8573 78 }
Architect 0:6f26c31d8573 79 }
Architect 0:6f26c31d8573 80 endBatchCommand();
Architect 0:6f26c31d8573 81 }
Architect 0:6f26c31d8573 82
Architect 0:6f26c31d8573 83 //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 )
Architect 0:6f26c31d8573 84 //{
Architect 0:6f26c31d8573 85 // clip(x, y, w, h);
Architect 0:6f26c31d8573 86 // int pixels = w * h;
Architect 0:6f26c31d8573 87 // beginBatchCommand(CMD_RAMWR);
Architect 0:6f26c31d8573 88 //
Architect 0:6f26c31d8573 89 // if( mirrored ) {
Architect 0:6f26c31d8573 90 // for( int iy =0; iy < h; iy++ ) {
Architect 0:6f26c31d8573 91 // const uint8_t * p = pbmp + w*iy + w-1;
Architect 0:6f26c31d8573 92 // for( int ix =0; ix < w; ix++ ) {
Architect 0:6f26c31d8573 93 // {
Architect 0:6f26c31d8573 94 // writeBatchData(palette[*p--]);
Architect 0:6f26c31d8573 95 // }
Architect 0:6f26c31d8573 96 // }
Architect 0:6f26c31d8573 97 // }
Architect 0:6f26c31d8573 98 // } else {
Architect 0:6f26c31d8573 99 // while(pixels--) {
Architect 0:6f26c31d8573 100 // writeBatchData(palette[*pbmp++]);
Architect 0:6f26c31d8573 101 // }
Architect 0:6f26c31d8573 102 // }
Architect 0:6f26c31d8573 103 // endBatchCommand();
Architect 0:6f26c31d8573 104 //}
Architect 0:6f26c31d8573 105
Architect 0:6f26c31d8573 106 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)
Architect 0:6f26c31d8573 107 {
Architect 0:6f26c31d8573 108 clip(x, y, srcWidth, srcHeight);
Architect 0:6f26c31d8573 109 beginBatchCommand(CMD_RAMWR);
Architect 0:6f26c31d8573 110 const uint8_t *p = pbmp + src_x + (src_y * w);
Architect 0:6f26c31d8573 111 for(int iy = 0; iy < srcHeight; ++iy) {
Architect 0:6f26c31d8573 112 for(int ix = 0; ix < srcWidth; ++ix) {
Architect 0:6f26c31d8573 113 writeBatchData(palette[*(p + ix)]);
Architect 0:6f26c31d8573 114 }
Architect 0:6f26c31d8573 115 p += w;
Architect 0:6f26c31d8573 116 }
Architect 0:6f26c31d8573 117 endBatchCommand();
Architect 0:6f26c31d8573 118 }
Architect 0:6f26c31d8573 119
Architect 0:6f26c31d8573 120 void Display::eraseBitmapIndexed(uint8_t x, uint8_t y, const uint8_t *pbmp)
Architect 0:6f26c31d8573 121 {
Architect 0:6f26c31d8573 122 eraseBitmapIndexed(x, y, pbmp[0], pbmp[1], pbmp+2);
Architect 0:6f26c31d8573 123 }
Architect 0:6f26c31d8573 124
Architect 0:6f26c31d8573 125 void Display::eraseBitmapIndexed(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t *pbmp)
Architect 0:6f26c31d8573 126 {
Architect 0:6f26c31d8573 127 clip(x, y, w, h);
Architect 0:6f26c31d8573 128 int bytes = w * h / 8;
Architect 0:6f26c31d8573 129 beginBatchCommand(CMD_RAMWR);
Architect 0:6f26c31d8573 130
Architect 0:6f26c31d8573 131 while(bytes--) {
Architect 0:6f26c31d8573 132 // writeBatchData(_pPalette[0]);
Architect 0:6f26c31d8573 133 // writeBatchData(_pPalette[0]);
Architect 0:6f26c31d8573 134 // writeBatchData(_pPalette[0]);
Architect 0:6f26c31d8573 135 // writeBatchData(_pPalette[0]);
Architect 0:6f26c31d8573 136 // writeBatchData(_pPalette[0]);
Architect 0:6f26c31d8573 137 // writeBatchData(_pPalette[0]);
Architect 0:6f26c31d8573 138 // writeBatchData(_pPalette[0]);
Architect 0:6f26c31d8573 139 // writeBatchData(_pPalette[0]);
Architect 0:6f26c31d8573 140 }
Architect 0:6f26c31d8573 141 endBatchCommand();
Architect 0:6f26c31d8573 142 }