Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: YATTT sd_map_test cPong SnowDemo ... more
PokittoLib
Library for programming Pokitto hardware
How to Use
- Import this library to online compiler (see button "import" on the right hand side
- DO NOT import mbed-src anymore, a better version is now included inside PokittoLib
- Change My_settings.h according to your project
- Start coding!
Revision 21:f8dc968e5739, committed 2017-12-29
- Comitter:
- Pokitto
- Date:
- Fri Dec 29 02:54:52 2017 +0000
- Parent:
- 20:fa6899411a24
- Child:
- 22:e826f80d8582
- Commit message:
- PokittoLib with Spinal's direct to screen improvements
Changed in this revision
--- a/POKITTO_CORE/PokittoDisplay.cpp Sun Oct 22 19:02:56 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,2147 +0,0 @@
-/**************************************************************************/
-/*!
- @file PokittoDisplay.cpp
- @author Jonne Valola
-
- @section LICENSE
-
- Software License Agreement (BSD License)
-
- Copyright (c) 2016, Jonne Valola
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holders nor the
- names of its contributors may be used to endorse or promote products
- derived from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-/**************************************************************************/
-
-
-/* THE SEGMENT BELOW PERTAINS TO CIRCLE DRAWING FUNCTIONS ONLY
-*
-This is the core graphics library for all our displays, providing a common
-set of graphics primitives (points, lines, circles, etc.). It needs to be
-paired with a hardware-specific library for each display device we carry
-(to handle the lower-level functions).
-Adafruit invests time and resources providing this open source code, please
-support Adafruit & open-source hardware by purchasing products from Adafruit!
-Copyright (c) 2013 Adafruit Industries. All rights reserved.
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-- Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
-- Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
-LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#include "PokittoDisplay.h"
-#include "Pokitto_settings.h"
-#include "GBcompatibility.h"
-#include "PokittoCore.h"
-#include "PokittoSound.h"
-#include <stdio.h>
-#include <string.h>
-
-#ifndef POK_SIM
-#include "HWLCD.h"
-#else
-#include "SimLCD.h"
-#endif
-
-Pokitto::Core core;
-Pokitto::Sound sound;
-
-using namespace Pokitto;
-
-
-
-uint8_t* Display::m_scrbuf;
-uint8_t* Display::m_tileset;
-uint8_t* Display::m_tilebuf;
-uint8_t* Display::m_tilecolorbuf;
-uint8_t Display::m_mode, Display::m_colordepth;
-uint8_t Display::fontSize=1;
-int16_t Display::cursorX,Display::cursorY;
-uint16_t Display::m_w,Display::m_h;
-uint8_t Display::fontWidth, Display::fontHeight;
-bool Display::textWrap=true;
-
-uint8_t Display::persistence = 0;
-uint16_t Display::color = 1;
-uint16_t Display::bgcolor = 0;
-uint16_t Display::invisiblecolor = 17;
-uint16_t Display::directcolor=0xFFFF;
-uint16_t Display::directbgcolor=0x0;
-
-uint16_t* Display::paletteptr;
-uint16_t Display::palette[PALETTE_SIZE];
-const unsigned char* Display::font;
-int8_t Display::adjustCharStep = 1;
-int8_t Display::adjustLineStep = 1;
-bool Display::fixedWidthFont = false;
-
-/** drawing canvas **/
-//uint8_t* Display::canvas; // points to the active buffer. if null, draw direct to screen
-
-/** screenbuffer **/
-uint8_t Display::bpp = POK_COLORDEPTH;
-#ifndef POK_TILEDMODE
-#if (POK_SCREENMODE == MODE_HI_MONOCHROME)
- uint8_t Display::width = POK_LCD_W;
- uint8_t Display::height = POK_LCD_H;
- uint8_t Display::screenbuffer[((POK_LCD_H+1)*POK_LCD_W)*POK_COLORDEPTH/8]; // maximum resolution
-#elif (POK_SCREENMODE == MODE_HI_4COLOR)
- uint8_t Display::width = POK_LCD_W;
- uint8_t Display::height = POK_LCD_H;
- uint8_t __attribute__((section (".bss"))) Display::screenbuffer[((POK_LCD_H)*POK_LCD_W)/4]; // maximum resolution
-#elif (POK_SCREENMODE == MODE_FAST_16COLOR)
- uint8_t Display::width = POK_LCD_W/2;
- uint8_t Display::height = POK_LCD_H/2;
- uint8_t Display::screenbuffer[(((POK_LCD_H/2)+1)*POK_LCD_W/2)*POK_COLORDEPTH/8]; // half resolution
-#elif (POK_SCREENMODE == MODE_HI_16COLOR)
- uint8_t Display::width = POK_LCD_W;
- uint8_t Display::height = POK_LCD_H;
- uint8_t Display::screenbuffer[POK_LCD_H*POK_LCD_W/2]; // 4 bits per pixel
-#elif (POK_SCREENMODE == MODE_LAMENES)
- uint8_t Display::width = 128;
- uint8_t Display::height = 120;
- uint8_t Display::screenbuffer[((121)*128)*POK_COLORDEPTH/8]; // half resolution
-#elif (POK_SCREENMODE == MODE_GAMEBOY)
- uint8_t Display::width = 160;
- uint8_t Display::height = 144;
- uint8_t Display::screenbuffer[160*144/4];
-#else
- uint8_t Display::width = 84;
- uint8_t Display::height = 48;
- uint8_t Display::screenbuffer[128*64]; // not needed because Gamebuino and Arduboy have their own buffer
-#endif
-#else //Tiledmode
-#if (POK_SCREENMODE == MODE_TILED_1BIT)
- uint8_t Display::width = POK_LCD_W;
- uint8_t Display::height = POK_LCD_H;
- uint8_t Display::screenbuffer[0];
-#else
- uint8_t Display::width = POK_LCD_W;
- uint8_t Display::height = POK_LCD_H;
- uint8_t Display::screenbuffer[0];
-#endif
-#endif //tiledmode
-
-// RLE decoding
-#define RLE_ESC_EOL 0
-#define RLE_ESC_EOB 1
-#define RLE_ESC_OFFSET 2
-
-Display::Display() {
- m_scrbuf = screenbuffer;
- setDefaultPalette();
- m_mode = 1; // direct printing on by default
- m_w = POK_LCD_W;
- m_h = POK_LCD_H;
- setFont(DEFAULT_FONT);
- invisiblecolor=17;
- bgcolor=0;
- if (POK_COLORDEPTH) m_colordepth = POK_COLORDEPTH;
- else m_colordepth = 4;
- #if POK_GAMEBUINO_SUPPORT
- setColorDepth(1);
- #endif // POK_GAMEBUINO_SUPPORT
-}
-
-uint16_t Display::getWidth() {
- return width;
-}
-
-uint8_t Display::getNumberOfColors() {
- return 1<<POK_COLORDEPTH;
-}
-
-uint16_t Display::getHeight() {
- return height;
-}
-
-uint8_t Display::getColorDepth() {
- return m_colordepth;
-}
-
-void Display::setColorDepth(uint8_t v) {
- if (v > POK_COLORDEPTH) v=POK_COLORDEPTH;
- m_colordepth = v;
-}
-
-void Display::clearLCD() {
- lcdFillSurface(0);
- setCursor(0,0); // old basic computer style
-}
-
-void Display::fillLCD(uint16_t c) {
- lcdFillSurface(c);
-}
-
-void Display::directPixel(int16_t x, int16_t y, uint16_t color) {
- lcdPixel(x,y,color);
-}
-
-void Display::directRectangle(int16_t x, int16_t y,int16_t x2, int16_t y2, uint16_t color) {
- lcdRectangle(x,y,x2,y2,color);
-}
-
-void Display::begin() {
- lcdInit();
-}
-
-void Display::setCursor(int16_t x,int16_t y) {
- cursorX = x;
- cursorY = y;
-}
-
-void Display::update() {
-
-#if POK_SCREENMODE == MODE_GAMEBOY
- lcdRefreshModeGBC(m_scrbuf, paletteptr);
-#endif
-
-#if POK_SCREENMODE == MODE_HI_4COLOR
- lcdRefreshMode1(m_scrbuf, paletteptr);
-#endif
-
-#if POK_SCREENMODE == MODE_HI_16COLOR
- lcdRefreshMode3(m_scrbuf, paletteptr);
-#endif
-
-#if POK_SCREENMODE == MODE_FAST_16COLOR
- lcdRefreshMode2(m_scrbuf, paletteptr);
-#endif
-
-#if POK_SCREENMODE == MODE_GAMEBUINO_16COLOR
- lcdRefreshGB(m_scrbuf, paletteptr);
-#endif
-
-#if POK_SCREENMODE == MODE_ARDUBOY_16COLOR
- lcdRefreshAB(m_scrbuf, paletteptr);
-#endif
-
-#if POK_SCREENMODE == MODE_TILED_1BIT
- lcdRefreshT1(m_tilebuf, m_tilecolorbuf, m_tileset, paletteptr);
-#endif
-
-if (!persistence) clear();
-
-/** draw volume bar if visible **/
-#if POK_SHOW_VOLUME > 0
-if (core.volbar_visible) {
- core.drawvolbar(4,20,sound.getVolume(),true);
- core.volbar_visible--;
-}
-#endif // POK_SHOW_VOLUME
-
-}
-
-void Display::directBitmap(int16_t x, int16_t y, const uint8_t *bitmap, uint8_t depth, uint8_t scale) {
- uint8_t w = *bitmap;
- uint8_t h = *(bitmap + 1);
- bitmap = bitmap + 2; //add an offset to the pointer to start after the width and height
- int16_t i, j;
- int8_t byteNum, bitNum, byteWidth = (w + 7) >> 3;
-
- if (depth == 1) {
- for (i = 0; i < w; i++) {
- byteNum = i / 8;
- bitNum = i % 8;
- for (j = 0; j < h; j++) {
- if (*(bitmap + j * byteWidth + byteNum) & (0x80 >> bitNum)) { //0x80 = B10000000
- if (scale==1) directPixel(x + i, y + j,directcolor);
- else {
- directPixel(x + i + i, y + j + j,directcolor);
- directPixel(x + 1 + i + i, y + j + j,directcolor);
- directPixel(x + i + i, y + j + j + 1,directcolor);
- directPixel(x + i + i + 1 , y + j + j + 1,directcolor);
- }
- }
- }
- }
- } else if (depth == 4) {
- for (j = 0; j < h; j+=1) {
- for (i = 0; i < w; i+=2) {
- uint16_t col = paletteptr[*bitmap>>4]; //higher nibble
- if (scale==2) {
- directPixel(x + (i<<1), y + (j<<1),col);
- directPixel(x + (i<<1) + 1, y + (j<<1),col);
- directPixel(x + (i<<1) + 1, y + (j<<1) + 1,col);
- directPixel(x + (i<<1), y + (j<<1) + 1,col);
- } else directPixel(x + i, y + j,col);
- col = paletteptr[*bitmap&0xF]; // lower nibble
- if (scale==2) {
- directPixel(x + (i<<1) + 2, y + (j<<1),col);
- directPixel(x + (i<<1) + 1 + 2, y + (j<<1),col);
- directPixel(x + (i<<1) + 1 + 2, y + (j<<1) + 1,col);
- directPixel(x + (i<<1) + 2 , y + (j<<1) + 1,col);
- } else directPixel(x + i + 1, y + j,col);
- bitmap++;
- }
- }
- }
-
-}
-
-int Display::directChar(int16_t x, int16_t y, uint16_t index){
- const uint8_t* bitmap = font;
- uint8_t w = *bitmap;
- uint8_t h = *(bitmap + 1);
- uint8_t hbytes=0, xtra=1;
- if (h==8 || h==16) xtra=0; //don't add if exactly on byte limit
- hbytes=(h>>3)+xtra; //GLCD fonts are arranged w+1 times h/8 bytes
- //bitmap = bitmap + 3 + index * h * ((w>>3)+xtra); //add an offset to the pointer (fonts !)
- bitmap = bitmap + 4 + index * (w * hbytes + 1); //add an offset to the pointer (fonts !)
- //int8_t i, j, byteNum, bitNum, byteWidth = (w + 7) >> 3;
- int8_t i, j, numBytes;
- numBytes = *bitmap++; //first byte of char is the width in bytes
- // GLCD fonts are arranged LSB = topmost pixel of char, so its easy to just shift through the column
- uint16_t bitcolumn; //16 bits for 2x8 bit high characters
-
- for (i = 0; i < numBytes; i++) {
- bitcolumn = *bitmap++;
- if (hbytes == 2) bitcolumn |= (*bitmap++)<<8; // add second byte for 16 bit high fonts
- for (j = 0; j < h; j++) {
- if (bitcolumn&0x1) {
- if (fontSize==2) {
- directPixel(x + (i<<1) , y + (j<<1),directcolor);
- directPixel(x + (i<<1)+1, y + (j<<1),directcolor);
- directPixel(x + (i<<1) , y + (j<<1)+1,directcolor);
- directPixel(x + (i<<1)+1, y + (j<<1)+1,directcolor);
- } else directPixel(x + i, y + j,directcolor);
- } else if (directbgcolor != invisiblecolor) {
- if (fontSize==2) {
- directPixel(x + (i<<1) , y + (j<<1),directbgcolor);
- directPixel(x + (i<<1)+1, y + (j<<1),directbgcolor);
- directPixel(x + (i<<1) , y + (j<<1)+1,directbgcolor);
- directPixel(x + (i<<1)+1, y + (j<<1)+1,directbgcolor);
- } else directPixel(x + i, y + j,directbgcolor);
- }
- bitcolumn>>=1;
- }
- }
- return (numBytes+adjustCharStep)*fontSize; // for character stepping
-}
-
-int Display::bufferChar(int16_t x, int16_t y, uint16_t index){
- const uint8_t* bitmap = font;
- uint8_t w = *bitmap;
- uint8_t h = *(bitmap + 1);
- uint8_t hbytes=0, xtra=1;
- if (h==8 || h==16) xtra=0; //don't add if exactly on byte limit
- hbytes=(h>>3)+xtra; //GLCD fonts are arranged w+1 times h/8 bytes
- //bitmap = bitmap + 3 + index * h * ((w>>3)+xtra); //add an offset to the pointer (fonts !)
- bitmap = bitmap + 4 + index * (w * hbytes + 1); //add an offset to the pointer (fonts !)
- //int8_t i, j, byteNum, bitNum, byteWidth = (w + 7) >> 3;
- int8_t i, j, numBytes;
- numBytes = *bitmap++; //first byte of char is the width in bytes
- // GLCD fonts are arranged LSB = topmost pixel of char, so its easy to just shift through the column
- uint16_t bitcolumn; //16 bits for 2x8 bit high characters
-
- for (i = 0; i < numBytes; i++) {
- bitcolumn = *bitmap++;
- if (hbytes == 2) bitcolumn |= (*bitmap++)<<8; // add second byte for 16 bit high fonts
- for (j = 0; j <= h; j++) { // was j<=h
- #if PROJ_ARDUBOY > 0
- if (bitcolumn&0x1) {
- drawPixel(x + i, y + 7 - j,color);
- } else drawPixel(x + i, y + 7 - j,bgcolor);
- bitcolumn>>=1;
- #else
- if (bitcolumn&0x1) {
- drawPixel(x + i, y + j,color);
- } else drawPixel(x + i, y + j,bgcolor);
- bitcolumn>>=1;
- #endif // PROJ_ARDUBOY
-
- }
- }
-
- return numBytes+adjustCharStep; // for character stepping
-}
-
-void Display::clear() {
-
- uint8_t c=0;
- c = bgcolor & (PALETTE_SIZE-1) ; //don't let palette go out of bounds
- if (bpp==1 && bgcolor) c=0xFF; // bgcolor !=0, set all pixels
- else if (bpp==2) {
- c = bgcolor & 0x3;
- c = c | (c << 2);
- c = c | (c << 4);
- } else {
- c = (c & 0x0F) | (c << 4);
- }
- uint16_t j = sizeof(screenbuffer);
- memset((void*)m_scrbuf,c,j);
-
- setCursor(0,0);
-
-}
-
-void Display::scroll(int16_t pixelrows) {
- uint16_t index = 0, index2,oc;
- if (pixelrows==0) return;
- if (pixelrows >= height) pixelrows=height-1;
- if (bpp == 4) index2 = pixelrows*width/2;
- else if (bpp == 2) index2 = pixelrows*width/4;
- else return;
- oc = color;
- color = bgcolor;
- if (pixelrows>0) {
- for (uint16_t y=0;y<height-pixelrows;y++) {
- for (uint16_t x=0;x<(width/8)*bpp;x++) screenbuffer[index++]=screenbuffer[index2++];
- }
- fillRect(0,cursorY,width,height);
- } else {
- for (uint16_t y=pixelrows;y<height;y++) {
- for (uint16_t x=0;x<(width*bpp)/8;x++) screenbuffer[index2++]=screenbuffer[index2];
- }
- fillRect(0,0,width,pixelrows);
- }
- color=oc;
-}
-
-void Display::fillScreen(uint16_t c) {
- c = c & (PALETTE_SIZE-1) ; //don't let palette go out of bounds
- if (bpp==1 && c) c=0xFF; // set all pixels
- else if (bpp==2) {
- c = bgcolor & 0x3;
- c = c | (c << 2);
- c = c | (c << 4);
- } else {
- c = (c & 0x0F) | (c << 4);
- }
- memset((void*)m_scrbuf,c,sizeof(screenbuffer));
-}
-
-void Display::setDefaultPalette() {
- #if PICOPALETTE
- loadRGBPalette(palettePico);
- #else
- loadRGBPalette(POK_DEFAULT_PALETTE);
- #endif //PICOPALETTE
-}
-
-void Display::setColor(uint8_t c) {
- color = c & ((1<<POK_COLORDEPTH)-1); // cut out colors that go above palette limit
-}
-
-void Display::setColor(uint8_t c,uint8_t bgc){
- color = c & ((1<<POK_COLORDEPTH)-1); // cut out colors that go above palette limit
- bgcolor = bgc & ((1<<POK_COLORDEPTH)-1); // cut out colors that go above palette limit
-}
-
-void Display::setInvisibleColor(uint16_t c){
- invisiblecolor = c; // invisible color can have values beyond 255 for identification purposes
-}
-
-uint8_t Display::getColor() {
- return color;
-}
-
-uint8_t Display::getBgColor() {
- return bgcolor;
-}
-
-uint16_t Display::getInvisibleColor() {
- return invisiblecolor;
-}
-
-void Display::drawPixel(int16_t x,int16_t y, uint8_t col) {
- if (col==invisiblecolor) return; // do not draw transparent pixels
- if ((uint16_t)x >= width || (uint16_t)y >= height) return;
- col &= (PALETTE_SIZE-1);
- #if POK_GAMEBUINO_SUPPORT >0
-
- uint8_t c = col;
- uint8_t ct = col;
-
- uint16_t bitptr=0;
- for (uint8_t cbit=0;cbit<POK_COLORDEPTH;cbit++) {
- c = ct & 1; // take the lowest bit of the color index number
- if(c == 0){ //white - or actually "Clear bit"
- m_scrbuf[x + (y / 8) * LCDWIDTH + bitptr] &= ~_BV(y % 8);
- } else { //black - or actually "Set bit"
- m_scrbuf[x + (y / 8) * LCDWIDTH + bitptr] |= _BV(y % 8);
- }
- ct >>=1; // shift to get next bit
- bitptr += POK_BITFRAME; // move one screen worth of buffer forward to get to the next color bit
- } // POK_COLOURDEPTH
-
- #else
- #if POK_COLORDEPTH == 1
- if (col) {m_scrbuf[(y >> 3) * width + x] |= (0x80 >> (y & 7)); return;}
- m_scrbuf[(y >> 3) * width + x] &= ~(0x80 >> (y & 7));
- #elif POK_COLORDEPTH == 2
- if (col) {
- col &= 3;
- }
- uint16_t i = y*(width>>2) + (x>>2);
- uint8_t pixel = m_scrbuf[i];
- uint8_t column = x&0x03;
- if (column==3) pixel = (pixel&0xFC)|(col); // bits 0-1
- else if (column==2) pixel = (pixel&0xF3)|(col<<2); // bits 2-3
- else if (column==1) pixel = (pixel&0xCF)|(col<<4); // bits 4-5
- else pixel = (pixel&0x3F)|(col<<6); // bits 6-7
- m_scrbuf[i] = pixel;
- #elif POK_COLORDEPTH == 3
- #elif POK_COLORDEPTH == 4
- uint16_t i = y*(width>>1) + (x>>1);
- uint8_t pixel = m_scrbuf[i];
- if (x&1) pixel = (pixel&0xF0)|(col);
- else pixel = (pixel&0x0F) | (col<<4);
- m_scrbuf[i] = pixel;
- #endif // POK_COLORDEPTH
- #endif // POK_GAMEBUINO_SUPPORT
-}
-
-void Display::drawPixel(int16_t x,int16_t y) {
- if ((uint16_t)x >= width || (uint16_t)y >= height) return;
-
- #if POK_GAMEBUINO_SUPPORT > 0
-
- uint8_t c = color;
- uint8_t ct = color;
- if(ct == INVERT){
- ct = !getPixel(x, y); //jonne - was c = !getP...
- }
-
- uint16_t bitptr=0;
- for (uint8_t cbit=0;cbit<POK_COLORDEPTH;cbit++) {
- c = ct & 1; // take the lowest bit of the color index number
- if(c == 0){ //white - or actually "Clear bit"
- #if DISPLAY_ROT == NOROT
- m_scrbuf[x + (y / 8) * LCDWIDTH + bitptr] &= ~_BV(y % 8);
- #elif DISPLAY_ROT == ROTCCW
- m_scrbuf[LCDHEIGHT - y - 1 + (x / 8) * LCDWIDTH_NOROT + bitptr] &= ~_BV(x % 8);
- #elif DISPLAY_ROT == ROT180
- m_scrbuf[LCDWIDTH - x - 1 + ((LCDHEIGHT - y - 1) / 8) * LCDWIDTH_NOROT + bitptr] &= ~_BV((LCDHEIGHT - y - 1) % 8);
- #elif DISPLAY_ROT == ROTCW
- m_scrbuf[y + ((LCDWIDTH - x - 1) / 8) * LCDWIDTH_NOROT + bitbtr] &= ~_BV((LCDWIDTH - x - 1) % 8);
- #endif
- //return; //jonne
- } else { //black - or actually "Set bit"
- #if DISPLAY_ROT == NOROT
- m_scrbuf[x + (y / 8) * LCDWIDTH + bitptr] |= _BV(y % 8);
- #elif DISPLAY_ROT == ROTCCW
- m_scrbuf[LCDHEIGHT - y - 1 + (x / 8) * LCDWIDTH_NOROT + bitptr] |= _BV(x % 8);
- #elif DISPLAY_ROT == ROT180
- m_scrbuf[LCDWIDTH - x - 1 + ((LCDHEIGHT - y - 1) / 8) * LCDWIDTH_NOROT + bitptr] |= _BV((LCDHEIGHT - y - 1) % 8);
- #elif DISPLAY_ROT == ROTCW
- m_scrbuf[y + ((LCDWIDTH - x - 1) / 8) * LCDWIDTH_NOROT + bitptr] |= _BV((LCDWIDTH - x -1) % 8);
- #endif
- //return; //jonne
- }
- ct >>=1; // shift to get next bit
- bitptr += POK_BITFRAME; // move one screen worth of buffer forward to get to the next color bit
- } // POK_COLOURDEPTH
-
- #else
-
- /** NOT Gamebuino */
- #if POK_COLORDEPTH == 1
- if (color) {m_scrbuf[(y >> 3) * width + x] |= (0x80 >> (y & 7)); return;}
- m_scrbuf[(y >> 3) * width + x] &= ~(0x80 >> (y & 7));
- #elif POK_COLORDEPTH == 2
- uint16_t i = y*(width>>2) + (x>>2);
- uint8_t pixel = m_scrbuf[i];
- uint8_t column = x&0x03;
- if (column==3) pixel = (pixel&0xFC)|(color); // bits 0-1
- else if (column==2) pixel = (pixel&0xF3)|(color<<2); // bits 2-3
- else if (column==1) pixel = (pixel&0xCF)|(color<<4); // bits 4-5
- else pixel = (pixel&0x3F)|(color<<6); // bits 6-7
- m_scrbuf[i] = pixel;
- #elif POK_COLORDEPTH == 3
- #elif POK_COLORDEPTH == 4
- uint16_t i = y*(width>>1) + (x>>1);
- uint8_t pixel = m_scrbuf[i];
- if (x&1) pixel = (pixel&0xF0)|(color);
- else pixel = (pixel&0x0F) | (color<<4);
- m_scrbuf[i] = pixel;
- #endif // POK_COLORDEPTH
- #endif // POK_GAMEBUINO_SUPPORT
-}
-
-uint8_t Display::getPixel(int16_t x,int16_t y) {
- if ((uint16_t)x >= width || (uint16_t)y >= height) return 0;
- #if POK_GAMEBUINO_SUPPORT
- uint8_t color=0; //jonne
- for (uint8_t cbit=0; cbit<POK_COLORDEPTH;cbit++) {
- color |= (m_scrbuf[x + (y / 8) * LCDWIDTH+POK_BITFRAME*cbit] >> (y % 8)) & 0x1 ; //jonne - added +504*cbit
- }
- return color;
- #else
- /** not gamebuino */
- #if POK_COLORDEPTH == 1
- return (m_scrbuf[(y >> 3) * width + x] & (0x80 >> (y & 7))) ? 1:0;
- #elif POK_COLORDEPTH == 2
- uint16_t i = y*(width>>2) + (x>>2);
- uint8_t pixel = m_scrbuf[i];
- uint8_t column = x&0x03;
- if (column==0) return pixel & 0x03; // bits 0-1
- else if (column==1) return (pixel & 0x0C)>>2; // bits 2-3
- else if (column==2) return (pixel & 0x30)>>4; // bits 4-5
- else return pixel>>6;; // bits 6-7
- #elif POK_COLORDEPTH == 3
- #elif POK_COLORDEPTH == 4
- uint16_t i = y*(width>>1) + (x>>1);
- uint8_t pixel = m_scrbuf[i];
- if (x&1) return pixel & 0x0F;
- else return pixel>>4;
- #endif // POK_COLORDEPTH
- #endif // POK_GAMEBUINO_SUPPORT
-}
-
-void Display::drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1) {
- if ((uint16_t)x0 >= width || (uint16_t)y0 >= height || (uint16_t)x1 >= width || (uint16_t)y1 >= height ) {
- if (clipLine (&x0,&y0,&x1,&y1)==0) return; // line out of bounds
- }
- if (x0 == x1)
- drawColumn(x0,y0,y1);
- else if (y0 == y1)
- drawRow(x0,x1,y0);
- else {
- int e;
- signed int dx,dy,j, temp;
- signed char s1,s2, xchange;
- signed int x,y;
-
- x = x0;
- y = y0;
-
- //take absolute value
- if (x1 < x0) {
- dx = x0 - x1;
- s1 = -1;
- }
- else if (x1 == x0) {
- dx = 0;
- s1 = 0;
- }
- else {
- dx = x1 - x0;
- s1 = 1;
- }
-
- if (y1 < y0) {
- dy = y0 - y1;
- s2 = -1;
- }
- else if (y1 == y0) {
- dy = 0;
- s2 = 0;
- }
- else {
- dy = y1 - y0;
- s2 = 1;
- }
-
- xchange = 0;
-
- if (dy>dx) {
- temp = dx;
- dx = dy;
- dy = temp;
- xchange = 1;
- }
-
- e = ((int)dy<<1) - dx;
-
- for (j=0; j<=dx; j++) {
- drawPixel(x,y);
-
- if (e>=0) {
- if (xchange==1) x = x + s1;
- else y = y + s2;
- e = e - ((int)dx<<1);
- }
- if (xchange==1)
- y = y + s2;
- else
- x = x + s1;
- e = e + ((int)dy<<1);
- }
- }
-}
-
-uint8_t Display::clipLine(int16_t *x0, int16_t *y0, int16_t *x1, int16_t *y1){
- // Check X bounds
- if (*x1<*x0) {
- //std::swap (*x1,*x0); // swap so that we dont have to check x1 also
- swapWT(int16_t*,x1,x0);
- //std::swap (*y1,*y0); // y needs to be swaaped also
- swapWT(int16_t*,y1,y0);
- }
-
- if (*x0>=width) return 0; // whole line is out of bounds
-
- // Clip against X0 = 0
- if (*x0 < 0) {
- if ( *x1 < 0) return 0; // nothing visible
- int16_t dx = (*x1 - *x0);
- int16_t dy = ((*y1 - *y0) << 8); // 8.8 fixed point calculation trick
- int16_t m = dy/dx;
- *y0 = *y0 + ((m*-*x0)>>8); // get y0 at boundary
- *x0 = 0;
- }
-
- // Clip against x1 = 83
- if (*x1 >= width) {
- int16_t dx = (*x1 - *x0);
- int16_t dy = ((*y1 - *y0) << 8); // 8.8 fixed point calculation trick
- int16_t m = dy/dx;
- //*y1 = *y1 + ((m*(*x1-XMAX))>>8); // get y0 at boundary
- *y1 = *y1 + ((m*(width-1-*x1))>>8); // get y0 at boundary
- *x1 = width-1;
- }
-
- // Check Y bounds
- if (*y1<*y0) {
- //std::swap (*x1,*x0); // swap so that we dont have to check x1 also
- swapWT(int16_t*,x1,x0);
- //std::swap (*y1,*y0); // y needs to be swaaped also
- swapWT(int16_t*,y1,y0);
- }
-
- if (*y0>=height) return 0; // whole line is out of bounds
-
- if (*y0 < 0) {
- if ( *y1 < 0) return 0; // nothing visible
- int16_t dx = (*x1 - *x0) << 8;
- int16_t dy = (*y1 - *y0); // 8.8 fixed point calculation trick
- int16_t m = dx/dy;
- *x0 = *x0 + ((m*-*y0)>>8); // get x0 at boundary
- *y0 = 0;
- }
-
- // Clip against y1 = 47
- if (*y1 >= height) {
- int16_t dx = (*x1 - *x0) << 8;
- int16_t dy = (*y1 - *y0); // 8.8 fixed point calculation trick
- int16_t m = dx/dy;
- *x1 = *x1 + ((m*(height-1-*y1))>>8); // get y0 at boundary
- //*x1 = *x1 + ((m*(*y1-YMAX))>>8); // get y0 at boundary
- *y1 = height-1;
- }
- return 1; // clipped succesfully
-}
-
-void Display::map1BitColumn(int16_t x, int16_t sy, int16_t ey, const uint8_t* bitmap, uint16_t column){
- if ((uint16_t)sy>=height && (uint16_t)ey>=height) return; //completely out of bounds
- if ((uint16_t)x>=width) return; //completely out of bounds
- if (sy>ey) {
- int y=sy;
- sy=ey;
- ey=y; // swap around so that x0 is less than x1
- }
- uint16_t bmw,bmh;
- float texelstep, texelindex;
- bmw = *(bitmap);
- bmh = *(bitmap+1);
- if (column>bmw-1) column=bmw-1;
- bitmap += 2;
- bitmap += column;
- texelstep = (float)bmh/((float)ey-(float)sy);
- texelindex = 0;
- for (int y=sy; y <= ey; y++, texelindex += texelstep) {
- uint8_t texel;
- uint8_t currbyte, bit;
- currbyte = texelindex / 8;
- bit = 7-((uint16_t) texelindex & 0x7);
- texel=*(bitmap+currbyte*bmw);
- if (texel & (1<<bit)) drawPixel(x,y);
- else if (bgcolor != invisiblecolor) drawPixel(x,y,bgcolor);
- }
-};
-
-void Display::drawColumn(int16_t x, int16_t sy, int16_t ey){
- if ((uint16_t)sy>=height && (uint16_t)ey>=height) return; //completely out of bounds
- if ((uint16_t)x>=width) return; //completely out of bounds
- if (sy>ey) {
- int y=sy;
- sy=ey;
- ey=y; // swap around so that x0 is less than x1
- }
- for (int y=sy; y <= ey; y++) {
- drawPixel(x,y);
- }
-}
-
-void Display::drawRow(int16_t x0, int16_t x1, int16_t y){
- if ((uint16_t)x0>=width && (uint16_t)x1>=width) return; //completely out of bounds
- if ((uint16_t)y>=height) return; //completely out of bounds
-
- if (x0>x1) {
- int x=x0;
- x0=x1;
- x1=x; // swap around so that x0 is less than x1
- }
- for (int x=x0; x <= x1; x++) {
- drawPixel(x,y);
- }
-}
-
-void Display::drawFastVLine(int16_t x, int16_t y, int16_t h){
- if (h<0) {y += h; h = -h;}
- drawColumn(x,y,y+h);
-}
-
-void Display::drawFastHLine(int16_t x, int16_t y, int16_t w){
- if (w<0) {x += w; w = -w;}
- drawRow(x,x+w-1,y);
-}
-
-void Display::drawRectangle(int16_t x0, int16_t y0, int16_t w, int16_t h) {
- drawColumn(x0,y0,y0+h);
- drawColumn(x0+w,y0,y0+h);
- drawRow(x0,x0+w,y0);
- drawRow(x0,x0+w,y0+h);
-}
-
-void Display::fillRectangle(int16_t x0,int16_t y0, int16_t w, int16_t h){
- int16_t x,y,x1,y1;
- x1=x0+w;y1=y0+h;
- if ((x0<0 && x1<0) || (x0>=width && x1 >=width)) return; //completely out of bounds
- if ((y0<0 && y1<0) || (y0>=height && y1 >=height)) return; //completely out of bounds
- if (x0>x1) {x=x1;x1=x0;}
- else x=x0;
- if (y0>y1) {y=y1;y1=y0;}
- else y=y0;
- if (x<0) x=0;
- if (y<0) y=0;
- for (;x<x1;x++) drawColumn(x,y,y1);
-}
-
-void Display::fillRect(int16_t x, int16_t y, int16_t w, int16_t h) {
- fillRectangle(x,y,w,h);
-}
-
-void Display::drawRect(int16_t x, int16_t y, int16_t w, int16_t h) {
- drawRectangle(x,y,w,h);
-}
-
-void Display::drawCircle(int16_t x0, int16_t y0, int16_t r) {
- int16_t f = 1 - r;
- int16_t ddF_x = 1;
- int16_t ddF_y = -2 * r;
- int16_t x = 0;
- int16_t y = r;
-
- drawPixel(x0, y0 + r);
- drawPixel(x0, y0 - r);
- drawPixel(x0 + r, y0);
- drawPixel(x0 - r, y0);
-
- while (x < y) {
- if (f >= 0) {
-
- y--;
- ddF_y += 2;
- f += ddF_y;
- }
- x++;
- ddF_x += 2;
- f += ddF_x;
-
- drawPixel(x0 + x, y0 + y);
- drawPixel(x0 - x, y0 + y);
- drawPixel(x0 + x, y0 - y);
- drawPixel(x0 - x, y0 - y);
- drawPixel(x0 + y, y0 + x);
- drawPixel(x0 - y, y0 + x);
- drawPixel(x0 + y, y0 - x);
- drawPixel(x0 - y, y0 - x);
-
- }
-}
-
-void Display::drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint16_t cornername) {
- int16_t f = 1 - r;
- int16_t ddF_x = 1;
- int16_t ddF_y = -2 * r;
- int16_t x = 0;
- int16_t y = r;
-
- while (x < y) {
- if (f >= 0) {
- y--;
- ddF_y += 2;
- f += ddF_y;
- }
- x++;
- ddF_x += 2;
- f += ddF_x;
- if (cornername & 0x4) {
- drawPixel(x0 + x, y0 + y);
- drawPixel(x0 + y, y0 + x);
- }
- if (cornername & 0x2) {
- drawPixel(x0 + x, y0 - y);
- drawPixel(x0 + y, y0 - x);
- }
- if (cornername & 0x8) {
- drawPixel(x0 - y, y0 + x);
- drawPixel(x0 - x, y0 + y);
- }
- if (cornername & 0x1) {
-
- drawPixel(x0 - y, y0 - x);
- drawPixel(x0 - x, y0 - y);
- }
- }
-}
-
-void Display::fillCircle(int16_t x0, int16_t y0, int16_t r) {
- drawFastVLine(x0, y0 - r, 2 * r );
- fillCircleHelper(x0, y0, r, 3, 0);
-}
-
-void Display::fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint16_t cornername, int16_t delta) {
- int16_t f = 1 - r;
- int16_t ddF_x = 1;
- int16_t ddF_y = -2 * r;
- int16_t x = 0;
- int16_t y = r;
-
- while (x < y) {
- if (f >= 0) {
- y--;
- ddF_y += 2;
- f += ddF_y;
- }
- x++;
- ddF_x += 2;
- f += ddF_x;
-
- if (cornername & 0x1) {
- drawFastVLine(x0 + x, y0 - y, 2 * y + 1 + delta-1); //added -1 here, jonne
- drawFastVLine(x0 + y, y0 - x, 2 * x + 1 + delta-1); //added -1 here, jonne
- }
- if (cornername & 0x2) {
-
- drawFastVLine(x0 - x, y0 - y, 2 * y + 1 + delta-1); //added -1 here, jonne
- drawFastVLine(x0 - y, y0 - x, 2 * x + 1 + delta-1); //added -1 here, jonne
- }
- }
-}
-
-void Display::drawRoundRect(int16_t x, int16_t y, int16_t w,int16_t h, int16_t r) {
- if (r<2) {drawRectangle(x,y,w,h);return;}
- // smarter version
- drawFastHLine(x + r, y, w - 2 * r); // Top
- drawFastHLine(x + r, y + h - 1, w - 2 * r); // Bottom
- drawFastVLine(x, y + r, h - 2 * r); // Left
- drawFastVLine(x + w - 1, y + r, h - 2 * r); // Right
- // draw four corners
- drawCircleHelper(x + r, y + r, r, 1);
- drawCircleHelper(x + w - r - 1, y + r, r, 2);
- drawCircleHelper(x + w - r - 1, y + h - r - 1, r, 4);
- drawCircleHelper(x + r, y + h - r - 1, r, 8);
-}
-
-void Display::fillRoundRect(int16_t x, int16_t y, int16_t w,int16_t h, int16_t r) {
- if (r<2) {fillRectangle(x,y,w,h);return;}
- fillRectangle(x + r, y, w - 2 * r, h-1);
- // draw four corners
- fillCircleHelper(x + w - r - 1, y + r, r, 1, h - 2 * r - 1);
- fillCircleHelper(x + r, y + r, r, 2, h - 2 * r - 1);
-}
-
-void Display::drawTriangle(int16_t x0, int16_t y0,
- int16_t x1, int16_t y1,
- int16_t x2, int16_t y2) {
- drawLine(x0, y0, x1, y1);
- drawLine(x1, y1, x2, y2);
- drawLine(x2, y2, x0, y0);
-}
-
-void Display::fillTriangle(int16_t x0, int16_t y0,
- int16_t x1, int16_t y1,
- int16_t x2, int16_t y2) {
- int16_t a, b, y, last;
-
- // Sort coordinates by Y order (y2 >= y1 >= y0)
- if (y0 > y1) {
- swapWT(int16_t,y0, y1);
- swapWT(int16_t,x0, x1);
- }
- if (y1 > y2) {
- swapWT(int16_t,y2, y1);
- swapWT(int16_t,x2, x1);
- }
- if (y0 > y1) {
- swapWT(int16_t,y0, y1);
- swapWT(int16_t,x0, x1);
- }
-
- if (y0 == y2) { // Handle awkward all-on-same-line case as its own thing
- a = b = x0;
- if (x1 < a) a = x1;
- else if (x1 > b) b = x1;
- if (x2 < a) a = x2;
- else if (x2 > b) b = x2;
- drawFastHLine(a, y0, b - a + 1);
- return;
- }
-
- int16_t
- dx01 = x1 - x0,
- dy01 = y1 - y0,
- dx02 = x2 - x0,
- dy02 = y2 - y0,
- dx12 = x2 - x1,
- dy12 = y2 - y1,
- sa = 0,
- sb = 0;
-
- // For upper part of triangle, find scanline crossings for segments
- // 0-1 and 0-2. If y1=y2 (flat-bottomed triangle), the scanline y1
- // is included here (and second loop will be skipped, avoiding a /0
- // error there), otherwise scanline y1 is skipped here and handled
- // in the second loop...which also avoids a /0 error here if y0=y1
- // (flat-topped triangle).
- if (y1 == y2) last = y1; // Include y1 scanline
- else last = y1 - 1; // Skip it
-
- for (y = y0; y <= last; y++) {
- a = x0 + sa / dy01;
- b = x0 + sb / dy02;
- sa += dx01;
- sb += dx02;
- /* longhand:
- a = x0 + (x1 - x0) * (y - y0) / (y1 - y0);
- b = x0 + (x2 - x0) * (y - y0) / (y2 - y0);
- */
- if (a > b) swapWT(int16_t,a, b);
- drawFastHLine(a, y, b - a + 1);
- }
-
- // For lower part of triangle, find scanline crossings for segments
- // 0-2 and 1-2. This loop is skipped if y1=y2.
- sa = dx12 * (y - y1);
- sb = dx02 * (y - y0);
- for (; y <= y2; y++) {
- a = x1 + sa / dy12;
- b = x0 + sb / dy02;
- sa += dx12;
- sb += dx02;
-
- if (a > b) swapWT(int16_t,a, b);
- drawFastHLine(a, y, b - a + 1);
- }
-}
-
-void Display::setFont(const unsigned char * f) {
- font = f;
- fontWidth = *(font)+1;
- fontHeight = *(font + 1)+1;
-}
-
-void Display::drawMonoBitmap(int16_t x, int16_t y, const uint8_t* bitmap, uint8_t index) {
- uint8_t w = *bitmap;
- uint8_t h = *(bitmap + 1);
- uint8_t xtra=0;
- if (w&0x7) xtra=1;
- bitmap = bitmap + 3 + index * h * ((w>>3)+xtra); //add an offset to the pointer (fonts !)
- #if POK_GAMEBUINO_SUPPORT > 0
- int8_t i, j, byteNum, bitNum, byteWidth = (w + 7) >> 3;
- for (i = 0; i < w; i++) {
- byteNum = i / 8;
- bitNum = i % 8;
- for (j = 0; j < h; j++) {
- uint8_t source = *(bitmap + j * byteWidth + byteNum);
- if (source & (0x80 >> bitNum)) {
- drawPixel(x + i, y + j);
- }
- }
- }
- #else
- /** not gamebuino */
- int8_t scrx,scry;
- uint8_t* scrptr = m_scrbuf + (y*(width>>1) + (x>>1));
- int8_t bitptr;
- for (scry = y; scry < y+h; scry+=1) {
- if ((x&1)==0) { /** EVEN pixel starting line**/
- for (scrx = x, bitptr=7; scrx < w+x; scrx+=2) {
- uint8_t targetpixel = *scrptr;
- if (*bitmap & (1<<bitptr)) targetpixel = (targetpixel & 0xF) | color<<4; // upper nibble
- else if (bgcolor != invisiblecolor) targetpixel = (targetpixel & 0xF) | bgcolor<<4; // upper nibble
- bitptr--;
- if (*bitmap & (1<<bitptr)) targetpixel = (targetpixel & 0xF0) | color; // lower nibble
- else if (bgcolor != invisiblecolor) targetpixel = (targetpixel & 0xF0) | bgcolor; // lower nibble
- bitptr--;
- if (bitptr<0) { bitptr = 7; bitmap++; }
- *scrptr = targetpixel;
- scrptr++;
- }
- } else { /** ODD pixel starting line **/
- for (scrx = x, bitptr=7; scrx < w+x; scrx+=2) {
- uint8_t targetpixel = *scrptr;
- // store higher nibble of source pixel in lower nibble of target
- if (*bitmap & (1<<bitptr)) targetpixel = (targetpixel & 0xF0) | color; // lower nibble
- else if (bgcolor != invisiblecolor) targetpixel = (targetpixel & 0xF0) | bgcolor; // lower nibble
- *scrptr = targetpixel; // store
- bitptr--;scrptr++;targetpixel = *scrptr;
- // store lower nibble of source pixel in higher nibble of target
- if (*bitmap & (1<<bitptr)) targetpixel = (targetpixel & 0xF) | color<<4; // higher nibble
- else if (bgcolor != invisiblecolor) targetpixel = (targetpixel & 0xF) | bgcolor<<4; // higher nibble
- *scrptr = targetpixel; // store
- bitptr--; // do not increment scrptr here !
- }
- }
- if (bitptr!=7) bitmap++; // force skip to next line
- // increment the y jump in the scrptr
- scrptr = scrptr + ((width - w)>>1);
- }
- #endif // POK_GAMEBUINO_SUPPORT
-}
-
-
-void Display::drawBitmap(int16_t x, int16_t y, const uint8_t* bitmap, uint8_t frame)
-{
- int16_t w = *bitmap;
- int16_t h = *(bitmap + 1);
- uint8_t framew = *(bitmap+2);
- bitmap = bitmap + 3; //add an offset to the pointer to start after the width and height
- /** visibility check */
- if (y<-h || y>height) return; //invisible
- if (x<-framew || x>width) return; //invisible
- /** 1 bpp mode */
- if (m_colordepth<2) {
- int16_t i, j, byteNum, bitNum, byteWidth = (w + 7) >> 3;
- for (i = 0; i < w; i++) {
- byteNum = i / 8;
- bitNum = i % 8;
- for (j = 0; j < h; j++) {
- uint8_t source = *(bitmap + j * byteWidth + byteNum);
- if (source & (0x80 >> bitNum)) {
- drawPixel(x + i, y + j);
- }
- }
- }
-
- return;
- }
- /** 2 bpp mode */
- if (m_colordepth<4) {
- int16_t i, j, byteNum, bitNum, byteWidth = w >> 2;
- for (i = 0; i < w; i++) {
- byteNum = i / 4;
- bitNum = (i % 4)<<1;
- for (j = 0; j < h; j++) {
- uint8_t source = *(bitmap + j * byteWidth + byteNum);
- uint8_t output = (source & (0xC0 >> bitNum));
- output >>= (6-bitNum);
- if (output != invisiblecolor) {
- setColor(output);
- drawPixel(x + i, y + j);
- }
- }
- }
-
- return;
- }
- /** 4bpp fast version */
- int16_t scrx,scry,xclip,xjump,scrxjump;
- xclip=xjump=scrxjump=0;
- bitmap += (framew*frame)>>1;
- /** y clipping */
- if (y<0) { h+=y; bitmap -= y*(w>>1); y=0;}
- else if (y+h>height) { h -=(y-height);}
- /** x clipping */
- xjump = (w-framew)>>1;
- if (x<0) { xclip=(x&1)<<1; framew+=x; xjump = ((-x)>>1); bitmap += xjump; x=0;}
- else if (x+framew>width) {
- xclip = (x&1)<<1;
- scrxjump = x&1;
- xjump=((x+framew-width)>>1)+scrxjump;
- framew = width-x;}
-
- uint8_t* scrptr = m_scrbuf + (y*(width>>1) + (x>>1));
- /** ONLY 4-bit mode for time being **/
- for (scry = y; scry < y+h; scry+=1) {
- if (scry>=height) return;
- if ((x&1)==0) { /** EVEN pixel starting line, very simple, just copypaste **/
- for (scrx = x; scrx < framew+x-xclip; scrx+=2) {
- uint8_t sourcepixel = *bitmap;
- if (xclip) {
- sourcepixel <<=4;
- sourcepixel |= ((*(bitmap+1))>>4);
- }
- uint8_t targetpixel = *scrptr;
- if ((sourcepixel>>4) != invisiblecolor ) targetpixel = (targetpixel&0x0F) | (sourcepixel & 0xF0);
- if ((sourcepixel&0x0F) != invisiblecolor) targetpixel = (targetpixel & 0xF0) | (sourcepixel & 0x0F);
- *scrptr = targetpixel;
- bitmap++;
- scrptr++;
- }
- if (xclip){
- if (framew&1) {
- /**last pixel is odd pixel due to clipping & odd width*/
- uint8_t sourcepixel = *bitmap;
- if ((sourcepixel&0x0F) != invisiblecolor) {
- sourcepixel <<=4;
- uint8_t targetpixel = *scrptr;// & 0x0F;
- targetpixel |= sourcepixel;
- *scrptr = targetpixel;
- }
- //scrptr++;
- }
- bitmap++;
- scrptr++;
- }
- bitmap += xjump; // needed if x<0 clipping occurs
- } else { /** ODD pixel starting line **/
- for (scrx = x; scrx < framew+x-xclip; scrx+=2) {
- uint8_t sourcepixel = *bitmap;
- uint8_t targetpixel = *scrptr;
- // store higher nibble of source pixel in lower nibble of target
- if((sourcepixel>>4)!=invisiblecolor) targetpixel = (targetpixel & 0xF0) | (sourcepixel >> 4 );
- *scrptr = targetpixel;
- scrptr++;
- targetpixel = *scrptr;
- // store lower nibble of source pixel in higher nibble of target
- if((sourcepixel&0x0F)!=invisiblecolor) targetpixel = (targetpixel & 0x0F) | (sourcepixel << 4);
- *scrptr = targetpixel;
- bitmap++;
- }
- bitmap+=xjump;
- }
- // increment the y jump in the scrptr
- scrptr = scrptr + ((width - framew)>>1)+scrxjump;
- }
-}
-
-
-void Display::drawBitmap(int16_t x, int16_t y, const uint8_t* bitmap)
-{
- int16_t w = *bitmap;
- int16_t h = *(bitmap + 1);
- bitmap = bitmap + 2; //add an offset to the pointer to start after the width and height
- /** visibility check */
- if (y<-h || y>height) return; //invisible
- if (x<-w || x>width) return; //invisible
- /** 1 bpp mode */
- if (m_colordepth<2) {
- int16_t i, j, byteNum, bitNum, byteWidth = (w + 7) >> 3;
- for (i = 0; i < w; i++) {
- byteNum = i / 8;
- bitNum = i % 8;
- for (j = 0; j < h; j++) {
- uint8_t source = *(bitmap + j * byteWidth + byteNum);
- if (source & (0x80 >> bitNum)) {
- drawPixel(x + i, y + j);
- }
- }
- }
-
- return;
- }
- /** 2 bpp mode */
- if (m_colordepth<4) {
- int16_t i, j, byteNum, bitNum, byteWidth = w >> 2;
- for (i = 0; i < w; i++) {
- byteNum = i / 4;
- bitNum = (i % 4)<<1;
- for (j = 0; j < h; j++) {
- uint8_t source = *(bitmap + j * byteWidth + byteNum);
- uint8_t output = (source & (0xC0 >> bitNum));
- output >>= (6-bitNum);
- if (output != invisiblecolor) {
- setColor(output);
- drawPixel(x + i, y + j);
- }
- }
- }
-
- return;
- }
- /** 4bpp fast version */
- int16_t scrx,scry,xclip,xjump,scrxjump;
- xclip=xjump=scrxjump=0;
- /** y clipping */
- if (y<0) { h+=y; bitmap -= y*(w>>1); y=0;}
- else if (y+h>height) { h -=(y-height);}
- /** x clipping */
- if (x<0) { xclip=(x&1)<<1; w+=x; xjump = ((-x)>>1); bitmap += xjump; x=0;}
- else if (x+w>width) {
- xclip = (x&1)<<1;
- scrxjump = x&1;
- xjump=((x+w-width)>>1)+scrxjump;
- w = width-x;}
-
- uint8_t* scrptr = m_scrbuf + (y*(width>>1) + (x>>1));
- /** ONLY 4-bit mode for time being **/
- for (scry = y; scry < y+h; scry+=1) {
- if (scry>=height) return;
- if ((x&1)==0) { /** EVEN pixel starting line, very simple, just copypaste **/
- for (scrx = x; scrx < w+x-xclip; scrx+=2) {
- uint8_t sourcepixel = *bitmap;
- if (xclip) {
- sourcepixel <<=4;
- sourcepixel |= ((*(bitmap+1))>>4);
- }
- uint8_t targetpixel = *scrptr;
- if ((sourcepixel>>4) != invisiblecolor ) targetpixel = (targetpixel&0x0F) | (sourcepixel & 0xF0);
- if ((sourcepixel&0x0F) != invisiblecolor) targetpixel = (targetpixel & 0xF0) | (sourcepixel & 0x0F);
- *scrptr = targetpixel;
- bitmap++;
- scrptr++;
- }
- if (xclip){
- if (w&1) {
- /**last pixel is odd pixel due to clipping & odd width*/
- uint8_t sourcepixel = *bitmap;
- if ((sourcepixel&0x0F) != invisiblecolor) {
- sourcepixel <<=4;
- uint8_t targetpixel = *scrptr;// & 0x0F;
- targetpixel |= sourcepixel;
- *scrptr = targetpixel;
- }
- //scrptr++;
- }
- bitmap++;
- scrptr++;
- }
- bitmap += xjump; // needed if x<0 clipping occurs
- } else { /** ODD pixel starting line **/
- for (scrx = x; scrx < w+x-xclip; scrx+=2) {
- uint8_t sourcepixel = *bitmap;
- uint8_t targetpixel = *scrptr;
- // store higher nibble of source pixel in lower nibble of target
- if((sourcepixel>>4)!=invisiblecolor) targetpixel = (targetpixel & 0xF0) | (sourcepixel >> 4 );
- *scrptr = targetpixel;
- scrptr++;
- targetpixel = *scrptr;
- // store lower nibble of source pixel in higher nibble of target
- if((sourcepixel&0x0F)!=invisiblecolor) targetpixel = (targetpixel & 0x0F) | (sourcepixel << 4);
- *scrptr = targetpixel;
- bitmap++;
- }
- bitmap+=xjump;
- }
- // increment the y jump in the scrptr
- scrptr = scrptr + ((width - w)>>1)+scrxjump;
- }
-}
-
-void Display::drawRleBitmap(int16_t x, int16_t y, const uint8_t* rlebitmap)
-{
- // ONLY can copy 4-bit bitmap to 4-bit screen mode for time being
- #if (POK_SCREENMODE != MODE_FAST_16COLOR)
- return;
- #endif
-
- int16_t w = *rlebitmap;
- int16_t h = *(rlebitmap + 1);
- rlebitmap = rlebitmap + 2; //add an offset to the pointer to start after the width and height
-
- // visibility check
- if (y<-h || y>height) return; //invisible
- if (x<-w || x>width) return; //invisible
-
- // Clipping is not supported
- if ((x < 0) || (x+w > width) || (y < 0) || (y+h > height)) return;
-
- // Currently only support RLE bitmaps in 16 color mode.
- if (m_colordepth != 4) //
- return;
-
- // Go through each line.
- uint8_t* scrptr = m_scrbuf + (y*(width>>1) + (x>>1));
- bool is_endofbitmap = false;
- for (int16_t scry = y; scry < y+h && !is_endofbitmap;) {
-
- // Process one line. Go through each pixel run and escape command in RLE data.
- for (int16_t scrx = x;;) {
- uint8_t rle_count = *rlebitmap++;
-
- if (rle_count == 0) {
-
- /** Escape or absolute mode */
-
- uint8_t rle_escape_or_runsize = *rlebitmap++;
- if ( rle_escape_or_runsize == RLE_ESC_EOL) {
- // End of line.
- break;
- }
- else if ( rle_escape_or_runsize == RLE_ESC_EOB) {
- // End of bitmap.
- is_endofbitmap = true;
- break;
- }
- else if ( rle_escape_or_runsize == RLE_ESC_OFFSET) {
- // Move position in target.
- // TODO: not tested yet.
- uint8_t xoffset = *rlebitmap++;
- uint8_t yoffset = *rlebitmap++;
- scrptr += (xoffset>1);
- scrx += xoffset;
- scrptr += yoffset*width;
- scry += yoffset;
- }
- else {
-
- /** Absolute mode. Copy pixels from the source bitmap to the target screen. */
-
- int16_t runsize = rle_escape_or_runsize;
- uint8_t targetpixel = *scrptr; // initial value
- uint8_t sourcepixel = *rlebitmap; // initial value
- for( int16_t runx = 0; runx < runsize; ) {
- if (scrx&0x1) { // screen pixel is in the low nibble
- if (runx&0x1) { // bitmap pixel is in the low nibble
- if ((sourcepixel&0x0F) != invisiblecolor)
- targetpixel = (targetpixel&0xF0) | (sourcepixel&0x0F); // Copy low to low nibble.
- rlebitmap++;
- }
- else // bitmap pixel is in the high nibble
- if ((sourcepixel>>4) != invisiblecolor)
- targetpixel = (targetpixel&0xF0) | (sourcepixel>>4); // Copy high to low nibble.
-
- // Copy the byte to the target.
- *scrptr = targetpixel;
- scrptr++;
- }
- else { // screen pixel is in the high nibble
- targetpixel = *scrptr;
- sourcepixel = *rlebitmap;
- if (runx&0x1) { // bitmap pixel is sourcepixel = *rlebitmapin the low nibble
- if ((sourcepixel&0x0F) != invisiblecolor )
- targetpixel = (targetpixel&0x0F) | ((sourcepixel<<4)&0xF0); // Copy low to high nibble.
- rlebitmap++; // read the new source byte
- }
- else // bitmap pixel is in the high nibble
- if ((sourcepixel>>4) != invisiblecolor )
- targetpixel = (targetpixel&0x0F) | (sourcepixel&0xF0); // Copy high to high nibble.
- }
- runx++;
- scrx++;
- } // end for
-
- // If this is odd target index, copy the byte to the target.
- if (scrx&0x1) {
- *scrptr = targetpixel;
- scrptr++;
- }
-
- // In absolute mode the source size is always padded to the word boundary.
- if (runsize%4) {
- int16_t padpixcount = 4 - (runsize%4);
- rlebitmap += padpixcount>>1; // skip n padding bytes
- }
- }
- }
- else {
-
- /** Encoded mode. Duplicate one pixel pair to the all required pixels on the target screen */
-
- int16_t runsize = rle_count;
- uint8_t clonepixelpair = *rlebitmap++;
- uint8_t targetpixel = *scrptr; // initial value
- for( int16_t runx = 0; runx < runsize; ) {
- if (scrx&0x1) { // screen pixel is in the low nibble
- if (runx&0x1) { // bitmap pixel is in the low nibble
- if ((clonepixelpair&0x0F) != invisiblecolor)
- targetpixel = (targetpixel&0xF0) | (clonepixelpair&0x0F); // Copy low to low nibble.
- }
- else // bitmap pixel is in the high nibble
- if ((clonepixelpair>>4) != invisiblecolor)
- targetpixel = (targetpixel&0xF0) | (clonepixelpair>>4); // Copy high to low nibble.
-
- // Copy the byte to the target.
- *scrptr = targetpixel;
- scrptr++;
- }
- else { // screen pixel is in the high nibble
- targetpixel = *scrptr;
- if (runx&0x1) {// bitmap pixel is in the low nibble
- if ((clonepixelpair&0x0F) != invisiblecolor )
- targetpixel = (targetpixel&0x0F) | ((clonepixelpair<<4)&0xF0); // Copy low to high nibble.
- }
- else // bitmap pixel is in the high nibble
- if ((clonepixelpair>>4) != invisiblecolor )
- targetpixel = (targetpixel&0x0F) | (clonepixelpair&0xF0); // Copy high to high nibble.
- }
- runx++;
- scrx++;
-
- } // end for
-
- // If this is odd target index, copy the byte to the target.
- if (scrx&0x1) {
- *scrptr = targetpixel;
- scrptr++;
- }
- } // end if
- } // end while
-
- // Increment the target screen pointer and index.
- scrptr = scrptr + ((width - w)>>1);
- scry++;
- } // end for scry
-}
-
-void Display::drawBitmapXFlipped(int16_t x, int16_t y, const uint8_t* bitmap)
-{
- int16_t w = *bitmap;
- int16_t h = *(bitmap + 1);
- bitmap = bitmap + 2; //add an offset to the pointer to start after the width and height
- /** visibility check */
- if (y<-h || y>height) return; //invisible
- if (x<-w || x>width) return; //invisible
- /** 1 bpp mode */
- if (m_colordepth<2) {
- int16_t i, j, byteNum, bitNum, byteWidth = (w + 7) >> 3;
- for (i = 0; i < w; i++) {
- byteNum = i / 8;
- bitNum = i % 8;
- for (j = 0; j < h; j++) {
- uint8_t source = *(bitmap + j * byteWidth + byteNum);
- if (source & (0x80 >> bitNum)) {
- drawPixel(x + w - i, y + j);
- }
- }
- }
-
- return;
- }
- /** 2 bpp mode */
- if (m_colordepth<4) {
- int16_t i, j, byteNum, bitNum, byteWidth = w >> 2;
- for (i = 0; i < w; i++) {
- byteNum = i / 4;
- bitNum = (i % 4)<<1;
- for (j = 0; j < h; j++) {
- uint8_t source = *(bitmap + j * byteWidth + byteNum);
- uint8_t output = (source & (0xC0 >> bitNum));
- output >>= (6-bitNum);
- if (output != invisiblecolor) {
- setColor(output);
- drawPixel(x + i, y + j);
- }
- }
- }
-
- return;
- }
- /** 4bpp fast version */
- int16_t scrx,scry,xclip,xjump,scrxjump;
- xclip=xjump=scrxjump=0;
- /** y clipping */
- if (y<0) { h+=y; bitmap -= y*(w>>1); y=0;}
- else if (y+h>height) { h -=(y-height);}
- /** x clipping */
- bitmap += ((w>>1)-1); //inverted!
- if (x<0) {
- xclip=(x&1)<<1;
- w+=x;
- xjump = ((-x)>>1);
- //bitmap += xjump; // do not clip left edge of source, as bitmap is inverted !
- x=0;
- }
- else if (x+w>width) {
- xclip = (x&1)<<1;
- scrxjump = x&1;
- xjump=((x+w-width)>>1)+scrxjump;
- w = width-x;}
-
- //uint8_t* scrptr = m_scrbuf + (y*(width>>1) + ((x+width)>>1));
- uint8_t* scrptr = m_scrbuf + (y*(width>>1) + (x>>1));
- /** ONLY 4-bit mode for time being **/
- for (scry = y; scry < y+h; scry+=1) {
- // for (scry = y; scry < y+2; scry+=1) {
- if (scry>=height) return;
- if ((x&1)==0) { /** EVEN pixel starting line, very simple, just copypaste **/
- //for (scrx = w+x-xclip-1; scrx >= x; scrx-=2) {
- for (scrx = x; scrx < w+x-xclip; scrx+=2) {
- uint8_t sourcepixel = *(bitmap);
- if (xclip) {
- sourcepixel <<=4;
- sourcepixel |= ((*(bitmap-1))>>4);//inverted!
- }
- uint8_t targetpixel = *scrptr;
- // NIBBLES ARE INVERTED BECAUSE PICTURE IS FLIPPED !!!
- if ((sourcepixel>>4) != invisiblecolor ) targetpixel = (targetpixel&0xF0) | (sourcepixel>>4);
- if ((sourcepixel&0x0F) != invisiblecolor) targetpixel = (targetpixel & 0x0F) | (sourcepixel<<4);
- *scrptr = targetpixel;
- bitmap--;
- scrptr++;
- }
- bitmap += w; // w*2 >> 1 because inverted and because 2 pixels per byte!!
- if (xclip){
- if (w&1) {
- /**last pixel is odd pixel due to clipping & odd width*/
- uint8_t sourcepixel = *bitmap;
- if ((sourcepixel&0x0F) != invisiblecolor) {
- sourcepixel <<=4;
- uint8_t targetpixel = *scrptr;// & 0x0F;
- targetpixel |= sourcepixel;
- *scrptr = targetpixel;
- }
- //scrptr++;
- }
- bitmap++;
- scrptr++;
- }
- bitmap += xjump; // needed if x<0 clipping occurs
- } else { /** ODD pixel starting line **/
- for (scrx = x; scrx < w+x-xclip; scrx+=2 ) {
- uint8_t sourcepixel = *bitmap;
- uint8_t targetpixel = *scrptr;
- // inverted !!! store lower nibble of source pixel in lower nibble of target
- if((sourcepixel&0x0F)!=invisiblecolor) targetpixel = (targetpixel & 0xF0) | (sourcepixel & 0x0F );
- *scrptr = targetpixel;
- scrptr++;
- targetpixel = *scrptr;
- // inverted ! store higher nibble of source pixel in higher nibble of target
- if((sourcepixel>>4)!=invisiblecolor) targetpixel = (targetpixel & 0x0F) | (sourcepixel & 0xF0);
- *scrptr = targetpixel;
- bitmap--;
- }
- bitmap += w; // w*2 >> 1 because inverted and because 2 pixels per byte!!
- bitmap+=xjump;
- }
- // increment the y jump in the scrptr
- scrptr = scrptr + ((width - w)>>1)+scrxjump;
- }
-}
-
-void Display::drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, uint8_t rotation, uint8_t flip) {
-#if PROJ_GAMEBUINO == 0
- if (!flip) drawBitmap(x,y,bitmap);
- else drawBitmapXFlipped(x,y,bitmap);
-#else
- if((rotation == NOROT) && (flip == NOFLIP)){
- drawBitmap(x,y,bitmap); //use the faster algorithm
- return;
- }
- uint8_t w = bitmap[0];
- uint8_t h = bitmap[1];
- bitmap = bitmap + 2; //add an offset to the pointer to start after the width and height
- int8_t i, j, //coordinates in the raw bitmap
- k, l, //coordinates in the rotated/flipped bitmap
- byteNum, bitNum, byteWidth = (w + 7) >> 3;
-
- rotation %= 4;
-
- for (i = 0; i < w; i++) {
- byteNum = i / 8;
- bitNum = i % 8;
- for (j = 0; j < h; j++) {
- if (bitmap[j * byteWidth + byteNum] & (B10000000 >> bitNum)) {
- switch (rotation) {
- case NOROT: //no rotation
- k = i;
- l = j;
- break;
- case ROTCCW: //90� counter-clockwise
- k = j;
- l = w - i - 1;
- break;
- case ROT180: //180�
- k = w - i - 1;
- l = h - j - 1;
- break;
- case ROTCW: //90� clockwise
- k = h - j - 1;
- l = i;
- break;
- }
- if (flip) {
- flip %= 4;
- if (flip & B00000001) { //horizontal flip
- k = w - k;
- }
- if (flip & B00000010) { //vertical flip
- l = h - l;
- }
- }
- k += x; //place the bitmap on the screen
- l += y;
- drawPixel(k, l);
- }
- }
- }
-#endif //PROJ_GAMEBUINO
-
-}
-
-uint8_t* Display::getBuffer() {
- return m_scrbuf;
-}
-
-uint8_t Display::getBitmapPixel(const uint8_t* bitmap, uint16_t x, uint16_t y) {
- uint16_t w = *bitmap;
- uint8_t sourcebyte = bitmap[2+(y * ((w+7)>>3))+ (x>>3)];
- return sourcebyte & (0x80>>(x&7));
-}
-
-int Display::print_char(uint8_t x, uint8_t y, unsigned char c) {
- c -= font[2];
- if (m_mode) return directChar(x,y,c);
- return bufferChar(x,y,c);
-}
-
-void Display::drawChar(int8_t x, int8_t y, unsigned char c, uint8_t size) {
- print_char(x,y,c);
- return;
-}
-
-
-bool Display::isDirectPrintingEnabled() {
- return m_mode;
-}
-
-void Display::enableDirectPrinting(uint8_t m) {
- if (m) {
- m_mode=true;
- m_w = POK_LCD_W;
- m_h = POK_LCD_H;
- } else {
- m_mode=false;
- m_w = getWidth();
- m_h = getHeight();
- }
-}
-
-void Display::write(uint8_t c) {
- int charstep=0;
- if(font[3]) {
- // only caps in this font
- if (c>=97) c-=32;
- }
- switch(c) {
- case '\0': //null
- break;
- case '\n': //line feed
- cursorX = 0;
- inc_txtline();
- break;
- case 8: //backspace
- cursorX -= font[0];
- charstep=print_char(cursorX,cursorY,' ');
- break;
- case 13: //carriage return
- cursorX = 0;
- break;
- case 14: //form feed new page(clear screen)
- //clear_screen();
- break;
- default:
- if (cursorX >= (m_w - font[0])) {
- cursorX = 0;
- if (textWrap) inc_txtline();
- else return; // stop outputting text
- charstep=print_char(cursorX,cursorY,c);
- }
- else
- charstep=print_char(cursorX,cursorY,c);
- if (c==' ' && adjustCharStep) charstep=(charstep>>1)+1;
- cursorX += charstep;
- }
-}
-
-void Display::inc_txtline() {
- if (cursorY > m_h - 2*font[1]) //= (height - (font[1]+1)))
- #if SCROLL_TEXT > 0
- scroll(font[1] + adjustLineStep);
- #else
- cursorY = 0;
- #endif
- else
- cursorY += font[1] + adjustLineStep;
-}
-
-/* default implementation: may be overridden */
-void Display::write(const char *str)
-{
- while (*str)
- write(*str++);
-}
-
-/* default implementation: may be overridden */
-void Display::write(const uint8_t *buffer, uint8_t size)
-{
- while (size--)
- write(*buffer++);
-}
-
-void Display::print(const char str[])
-{
- write(str);
-}
-
-void Display::print(char c, int base)
-{
- print((long) c, base);
-}
-
-void Display::print(unsigned char b, int base)
-{
- print((unsigned long) b, base);
-}
-
-void Display::print(int n, int base)
-{
- print((long) n, base);
-}
-
-void Display::print(unsigned int n, int base)
-{
- print((unsigned long) n, base);
-}
-
-void Display::print(long n, int base)
-{
- if (base == 0) {
- write(n);
- } else if (base == 10) {
- if (n < 0) {
- print('-');
- n = -n;
- }
- printNumber(n, 10);
- } else {
- printNumber(n, base);
- }
-}
-
-void Display::print(unsigned long n, int base)
-{
- if (base == 0) write(n);
- else printNumber(n, base);
-}
-
-void Display::print(double n, int digits)
-{
- printFloat(n, digits);
-}
-
-void Display::println(void)
-{
- print('\r');
- print('\n');
-}
-
-void Display::println(const char c[])
-{
- print(c);
- println();
-}
-
-void Display::println(char c, int base)
-{
- print(c, base);
- println();
-}
-
-void Display::println(unsigned char b, int base)
-{
- print(b, base);
- println();
-}
-
-void Display::println(int n, int base)
-{
- print(n, base);
- println();
-}
-
-void Display::println(unsigned int n, int base)
-{
- print(n, base);
- println();
-}
-
-void Display::println(long n, int base)
-{
- print(n, base);
- println();
-}
-
-void Display::println(unsigned long n, int base)
-{
- print(n, base);
- println();
-}
-
-void Display::println(double n, int digits)
-{
- print(n, digits);
- println();
-}
-
-void Display::set_cursor(uint8_t x, uint8_t y) {
- cursorX = x;
- cursorY = y;
-}
-
-void Display::print(uint8_t x, uint8_t y, const char str[]) {
- cursorX = x;
- cursorY = y;
- write(str);
-
-}
-void Display::print(uint8_t x, uint8_t y, char c, int base) {
- cursorX = x;
- cursorY = y;
- print((long) c, base);
-}
-void Display::print(uint8_t x, uint8_t y, unsigned char b, int base) {
- cursorX = x;
- cursorY = y;
- print((unsigned long) b, base);
-}
-void Display::print(uint8_t x, uint8_t y, int n, int base) {
- cursorX = x;
- cursorY = y;
- print((long) n, base);
-}
-void Display::print(uint8_t x, uint8_t y, unsigned int n, int base) {
- cursorX = x;
- cursorY = y;
- print((unsigned long) n, base);
-}
-void Display::print(uint8_t x, uint8_t y, long n, int base) {
- cursorX = x;
- cursorY = y;
- print(n,base);
-}
-void Display::print(uint8_t x, uint8_t y, unsigned long n, int base) {
- cursorX = x;
- cursorY = y;
- print(n,base);
-}
-void Display::print(uint8_t x, uint8_t y, double n, int digits) {
- cursorX = x;
- cursorY = y;
- print(n,digits);
-}
-
-void Display::println(uint8_t x, uint8_t y, const char c[])
-{
- cursorX = x;
- cursorY = y;
- print(c);
- println();
-}
-
-void Display::println(uint8_t x, uint8_t y, char c, int base)
-{
- cursorX = x;
- cursorY = y;
- print(c, base);
- println();
-}
-
-void Display::println(uint8_t x, uint8_t y, unsigned char b, int base)
-{
- cursorX = x;
- cursorY = y;
- print(b, base);
- println();
-}
-
-void Display::println(uint8_t x, uint8_t y, int n, int base)
-{
- cursorX = x;
- cursorY = y;
- print(n, base);
- println();
-}
-
-void Display::println(uint8_t x, uint8_t y, unsigned int n, int base)
-{
- cursorX = x;
- cursorY = y;
- print(n, base);
- println();
-}
-
-void Display::println(uint8_t x, uint8_t y, long n, int base)
-{
- cursorX = x;
- cursorY = y;
- print(n, base);
- println();
-}
-
-void Display::println(uint8_t x, uint8_t y, unsigned long n, int base)
-{
- cursorX = x;
- cursorY = y;
- print(n, base);
- println();
-}
-
-void Display::println(uint8_t x, uint8_t y, double n, int digits)
-{
- cursorX = x;
- cursorY = y;
- print(n, digits);
- println();
-}
-
-void Display::printNumber(unsigned long n, uint8_t base)
-{
- unsigned char buf[8 * sizeof(long)]; // Assumes 8-bit chars.
- unsigned long i = 0;
-
- if (n == 0) {
- print('0');
- return;
- }
-
- while (n > 0) {
- buf[i++] = n % base;
- n /= base;
- }
-
- for (; i > 0; i--)
- print((char) (buf[i - 1] < 10 ?
- '0' + buf[i - 1] :
- 'A' + buf[i - 1] - 10));
-}
-
-void Display::printFloat(double number, uint8_t digits)
-{
- // Handle negative numbers
- if (number < 0.0)
- {
- print('-');
- number = -number;
- }
-
- // Round correctly so that print(1.999, 2) prints as "2.00"
- double rounding = 0.5;
- for (uint8_t i=0; i<digits; ++i)
- rounding /= 10.0;
-
- number += rounding;
-
- // Extract the integer part of the number and print it
- unsigned long int_part = (unsigned long)number;
- double remainder = number - (double)int_part;
- print(int_part);
-
- // Print the decimal point, but only if there are digits beyond
- if (digits > 0)
- print(".");
-
- // Extract digits from the remainder one at a time
- while (digits-- > 0)
- {
- remainder *= 10.0;
- int toPrint = int(remainder);
- print(toPrint);
- remainder -= toPrint;
- }
-}
-
-void Display::draw4BitColumn(int16_t x, int16_t y, uint8_t h, uint8_t* bitmap)
-{
- int8_t scry;
- uint8_t* scrptr = m_scrbuf + (y*(width>>1) + (x>>1));
-
- /** ONLY 4-bit mode for time being **/
-
- if ((x&1)==0) { /** EVEN pixel starting line, very simple, just copypaste **/
- for (scry = y; scry < h+y; scry++) {
- uint8_t sourcepixel = *bitmap;
- uint8_t targetpixel = *scrptr;
- targetpixel = (targetpixel&0x0F) | (sourcepixel << 4);
- *scrptr = targetpixel;
- bitmap++;
- scrptr+=55;
- }
- } else { /** ODD pixel starting line **/
- for (scry = y; scry < h+y; scry++) {
- uint8_t sourcepixel = *bitmap;
- uint8_t targetpixel = *scrptr;
- // store source pixel in lower nibble of target
- targetpixel = (targetpixel & 0xF0) | (sourcepixel);
- *scrptr = targetpixel;
- scrptr+=55;
- bitmap++;
- }
- }
-}
-
-void Display::lcdRefresh(unsigned char* scr) {
-
-#if POK_SCREENMODE == MODE_GAMEBOY
- lcdRefreshModeGBC(scr, paletteptr);
-#endif
-
-#if POK_SCREENMODE == MODE_HI_4COLOR
- lcdRefreshMode1(scr, paletteptr);
-#endif
-
-#if POK_SCREENMODE == MODE_FAST_16COLOR
- lcdRefreshMode2(scr, paletteptr);
-#endif
-
-#if POK_SCREENMODE == MODE_GAMEBUINO_16COLOR
- lcdRefreshGB(scr, paletteptr);
-#endif
-
-#if POK_SCREENMODE == MODE_ARDUBOY_16COLOR
- lcdRefreshAB(scr, paletteptr);
-#endif
-
-}
-
-void Display::setFrameBufferTo(uint8_t* sb) {
- m_scrbuf = sb;
-};
-
-void Display::setTileBufferTo(uint8_t* tb) {
- m_tilebuf = tb;
-};
-
-void Display::loadTileset(const uint8_t* ts) {
- m_tileset = (uint8_t*) ts;
-};
-
-void Display::setTile(uint16_t i, uint8_t t) {
- if (!m_tilebuf) return;
- m_tilebuf[i]=t;
-};
-
-
-/** Eof */
-
-
-
--- a/POKITTO_CORE/PokittoDisplay.h Sun Oct 22 19:02:56 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,407 +0,0 @@
-/**************************************************************************/
-/*!
- @file PokittoDisplay.h
- @author Jonne Valola
-
- @section LICENSE
-
- Software License Agreement (BSD License)
-
- Copyright (c) 2016, Jonne Valola
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holders nor the
- names of its contributors may be used to endorse or promote products
- derived from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-/**************************************************************************/
-
-
-
-/* THE SEGMENT BELOW PERTAINS TO CIRCLE DRAWING FUNCTIONS ONLY
-*
-This is the core graphics library for all our displays, providing a common
-set of graphics primitives (points, lines, circles, etc.). It needs to be
-paired with a hardware-specific library for each display device we carry
-(to handle the lower-level functions).
-Adafruit invests time and resources providing this open source code, please
-support Adafruit & open-source hardware by purchasing products from Adafruit!
-Copyright (c) 2013 Adafruit Industries. All rights reserved.
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-- Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
-- Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
-LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#ifndef POKITTODISPLAY_H
-#define POKITTODISPLAY_H
-
-#include <stdint.h>
-#include "Pokitto_settings.h"
-#include "PokittoGlobs.h"
-#include "PokittoFonts.h"
-#include "PokittoPalettes.h"
-
-// Basic Color definitions
-#define COLOR_BLACK (uint16_t)(0x0000)
-#define COLOR_BLUE (uint16_t)(0x001F)
-#define COLOR_RED (uint16_t)(0xF800)
-#define COLOR_GREEN (uint16_t)(0x07E0)
-#define COLOR_CYAN (uint16_t)(0x07FF)
-#define COLOR_MAGENTA (uint16_t)(0xF81F)
-#define COLOR_YELLOW (uint16_t)(0xFFE0)
-#define COLOR_WHITE (uint16_t)(0xFFFF)
-
-// Grayscale Values
-#define COLOR_GRAY_15 (uint16_t)(0x0861) // 15 15 15
-#define COLOR_GRAY_30 (uint16_t)(0x18E3) // 30 30 30
-#define COLOR_GRAY_50 (uint16_t)(0x3186) // 50 50 50
-#define COLOR_GRAY_80 (uint16_t)(0x528A) // 80 80 80
-#define COLOR_GRAY_128 (uint16_t)(0x8410) // 128 128 128
-#define COLOR_GRAY_200 (uint16_t)(0xCE59) // 200 200 200
-#define COLOR_GRAY_225 (uint16_t)(0xE71C) // 225 225 225
-
-/** The tables below are palettes, that resemble the Pico 8 palette*/
-
-enum defcolors {
- C_BLACK,
- C_DARKBLUE,
- C_PURPLE,
- C_DARKGREEN,
-
- C_BROWN,
- C_DARKBROWN,
- C_LIGHTGRAY,
- C_WHITE,
-
- C_RED,
- C_ORANGE,
- C_YELLOW,
- C_GREEN,
-
- C_BLUE,
- C_DARKGRAY,
- C_PINK,
- C_PEACH
-};
-
-const uint16_t def565palette[16] = {
- //kind of like pico8 palette
- 0,0x194a,0x792a,0x42a,
- 0xaa86,0x5aa9,0xc618,0xff9d,
- 0xf809,0xfd00,0xff84,0x72a,
- 0x2d7f,0x83b3,0xfbb5,0xfe75
-};
-
-#define PALETTE_SIZE 16
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-
-
-namespace Pokitto {
-
-class Display {
-public:
- Display();
-
- // PROPERTIES
-private:
- static uint8_t* canvas;
- static uint8_t bpp;
- static uint8_t m_colordepth;
-public:
- static uint8_t width;
- static uint8_t height;
- static uint8_t screenbuffer[];
-
- // PROPERTIES
- static void setColorDepth(uint8_t);
- static uint8_t getColorDepth();
- static uint8_t getBitsPerPixel();
- static uint16_t getWidth();
- static uint16_t getHeight();
- static uint8_t getNumberOfColors();
-
- // IMPORTANT PUBLIC STATE MEMBERS
- /** Selected font */
- static const unsigned char * font;
- /** Set if screen is cleared between updates or not*/
- static uint8_t persistence;
- /** Selected drawing color */
- static uint16_t color;
- /** Selected background color */
- static uint16_t bgcolor;
- /** Selected invisible color */
- static uint16_t invisiblecolor;
- /** Direct unbuffered color */
- static uint16_t directcolor;
- /** Direct unbuffered background color */
- static uint16_t directbgcolor;
- /** set color with a command */
- static void setColor(uint8_t);
- /** set color and bgcolor with a command */
- static void setColor(uint8_t,uint8_t);
- /** set invisiblecolor with a command */
- static void setInvisibleColor(uint16_t);
- /** get color */
- static uint8_t getColor();
- /** get background color */
- static uint8_t getBgColor();
- /** get invisible color */
- static uint16_t getInvisibleColor();
-
-
- /** Initialize display */
- static void begin();
- /** Clear display buffer */
- static void clear();
- /** Scroll by x lines */
- static void scroll(int16_t);
- /** Fill display buffer */
- static void fillScreen(uint16_t);
- /** Send display buffer to display hardware */
- static void update();
- /** Forced update of LCD display memory with a given pixel buffer */
- static void lcdRefresh(unsigned char*);
- /** Clear LCD hardware memory */
- static void clearLCD();
- /** Fill LCD hardware memory */
- static void fillLCD(uint16_t);
- /** Show Pokitto logo at startup*/
- static void showLogo();
- /** Point to another screenbuffer instead of the default one */
- static void setFrameBufferTo(uint8_t*);
-
- // COLORS AND PALETTE
-public:
- /** set default palette */
- static void setDefaultPalette();
- /** master palette */
- static uint16_t palette[PALETTE_SIZE];
- /** runtime palette pointer */
- static uint16_t *paletteptr;
- /** convert RGB to 565 color value */
- static uint16_t RGBto565(uint8_t,uint8_t,uint8_t);
- /** linear interpolation between colors */
- static uint16_t interpolateColor(uint16_t, uint16_t, uint8_t);
- /** load an R,G,B triplet palette */
- static void loadRGBPalette(const unsigned char*);
- /** load a ready-made 565 palette */
- static void load565Palette(const uint16_t*);
- /** rotate palette by step */
- static void rotatePalette(int8_t);
- /** tween between two palettes **/
- static void tweenPalette(uint16_t*, const uint16_t*, const uint16_t*, uint8_t);
-
- // DIRECT DRAWING (NO BUFFERING)
- /** Direct pixel (not through display buffer) */
- static void directPixel(int16_t,int16_t,uint16_t);
- /** Direct rectangle (not through display buffer) */
- static void directRectangle(int16_t, int16_t,int16_t, int16_t, uint16_t);
- /** Set the cursor for printing to a certain screen position */
- static void setCursor(int16_t,int16_t);
- /** direct bitmap to screen (no buffering) */
- static void directBitmap(int16_t,int16_t,const uint8_t*, uint8_t,uint8_t);
-
-
- // DRAWING METHODS
- /** Draw pixel at various bit depths */
- static void drawPixel(int16_t,int16_t);
- /** Draw pixel with specific color index at various bit depths */
- static void drawPixel(int16_t x,int16_t y, uint8_t col);
- /** Get pixel at various bit depths */
- static uint8_t getPixel(int16_t,int16_t);
- /** Draw line **/
- static void drawLine(int16_t,int16_t,int16_t,int16_t);
- /** Clip line with screen boundaries, returns 0 if whole line is out of bounds */
- static uint8_t clipLine(int16_t*, int16_t*, int16_t*, int16_t*);
- /** Draw a column real fast */
- static void drawColumn(int16_t, int16_t, int16_t);
- /** Map a 1-bit column real fast */
- static void map1BitColumn(int16_t, int16_t, int16_t, const uint8_t*, uint16_t);
- /** Draw a row real fast */
- static void drawRow(int16_t, int16_t, int16_t);
- /** Legacy drawColumn name, for compatibility - macros are not OK because of scope problems */
- static void drawFastVLine(int16_t, int16_t, int16_t);
- /** Legacy drawRow name, for compatibility - macros are not OK because of scope problems */
- static void drawFastHLine(int16_t, int16_t, int16_t);
- /** Draw rectangle (edges only) */
- static void drawRectangle(int16_t,int16_t,int16_t,int16_t);
- /** Fill rectangle */
- static void fillRectangle(int16_t,int16_t,int16_t,int16_t);
- /** GB compatibility fillRect */
- static void fillRect(int16_t x, int16_t y, int16_t w, int16_t h);
- /** GB compatibility drawRect */
- static void drawRect(int16_t x, int16_t y, int16_t w, int16_t h);
-
- // Functions lifted from Adafruit GFX library (see PokittoDisplay.h for license //
- /** Draw circle */
- static void drawCircle(int16_t x0, int16_t y0, int16_t r);
- /** Draw circle helper */
- static void drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint16_t cornername);
- /** Fill circle */
- static void fillCircle(int16_t x0, int16_t y0, int16_t r);
- /** Fill circle helper*/
- static void fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint16_t cornername, int16_t delta);
- /** draw triangle */
- static void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2);
- /** Fill triangle*/
- static void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2);
- /** Draw rounded rectangle */
- static void drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius);
- /** Fill rounded rectangle */
- static void fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius);
-
- // BITMAPS !
- /** Draw monochromatic bitmap. Used in font rendering */
- static void drawMonoBitmap(int16_t x, int16_t y, const uint8_t* bitmap, uint8_t index);
- /** Draw bitmap */
- static void drawBitmap(int16_t x, int16_t y, const uint8_t* bitmap);
- /** Draw RLE bitmap */
- static void drawRleBitmap(int16_t x, int16_t y, const uint8_t* bitmap);
- /** Draw animated bitmap frame */
- static void drawBitmap(int16_t x, int16_t y, const uint8_t* bitmap, uint8_t frame);
- /** Draw bitmap flipped on x-axis*/
- static void drawBitmapXFlipped(int16_t x, int16_t y, const uint8_t* bitmap);
- /** Draw bitmap with options */
- static void drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, uint8_t rotation, uint8_t flip);
- /** Get pointer to the screen buffer - GB compatibility */
- static uint8_t* getBuffer();
- /** Get pixel in a monochromatic bitmap - GB compatibility */
- static uint8_t getBitmapPixel(const uint8_t*, uint16_t, uint16_t);
- /** Optimized functions for drawing bit columns - used in raytracing */
- static void draw4BitColumn(int16_t x, int16_t y, uint8_t h, uint8_t* bitmap);
-
- // PRINTING
- /** direct character to screen (no buffering) */
- static int directChar(int16_t, int16_t, uint16_t);
- /** character to screenbuffer */
- static int bufferChar(int16_t, int16_t, uint16_t);
- /** set the active font */
- static void setFont(const unsigned char * f);
- /** font dimensions */
- static uint8_t fontWidth, fontHeight;
- /** text wrapping */
- static bool textWrap;
- /** GB compatibility drawChar */
- static void drawChar(int8_t x, int8_t y, unsigned char c, uint8_t size);
-
- static void enableDirectPrinting(uint8_t m);
- static bool isDirectPrintingEnabled();
- static int print_char(uint8_t x, uint8_t y, unsigned char c);
- static void set_cursor(uint8_t, uint8_t);
- static void write(uint8_t);
- static void write(const char *str);
- static void write(const uint8_t *buffer, uint8_t size);
- static void print(const char[]);
- static void print(char, int base = 0);
- static void print(unsigned char, int base = 0);
- static void print(int, int base = 10);
- static void print(unsigned int, int base = 10);
- static void print(long, int base = 10);
- static void print(unsigned long, int base = 10);
- static void print(double, int base = 2);
- static void print(uint8_t, uint8_t, const char[]);
- static void print(uint8_t, uint8_t, char, int = 0);
- static void print(uint8_t, uint8_t, unsigned char, int = 0);
- static void print(uint8_t, uint8_t, int, int = 10);
- static void print(uint8_t, uint8_t, unsigned int, int = 10);
- static void print(uint8_t, uint8_t, long, int = 10);
- static void print(uint8_t, uint8_t, unsigned long, int = 10);
- static void print(uint8_t, uint8_t, double, int = 2);
- static void println(uint8_t, uint8_t, const char[]);
- static void println(uint8_t, uint8_t, char, int = 0);
- static void println(uint8_t, uint8_t, unsigned char, int = 0);
- static void println(uint8_t, uint8_t, int, int = 10);
- static void println(uint8_t, uint8_t, unsigned int, int = 10);
- static void println(uint8_t, uint8_t, long, int = 10);
- static void println(uint8_t, uint8_t, unsigned long, int = 10);
- static void println(uint8_t, uint8_t, double, int = 2);
- static void println(uint8_t, uint8_t);
- static void println(const char[]);
- static void println(char, int = 0);
- static void println(unsigned char, int = 0);
- static void println(int, int = 10);
- static void println(unsigned int, int = 10);
- static void println(long, int = 10 );
- static void println(unsigned long, int = 10);
- static void println(double, int = 2);
- static void println(void);
-
- static int16_t cursorX,cursorY;
- static uint8_t fontSize;
- static int8_t adjustCharStep, adjustLineStep;
- static bool fixedWidthFont;
-
- static void inc_txtline();
- static void printNumber(unsigned long, uint8_t);
- static void printFloat(double, uint8_t);
-
- /** Tiled mode functions **/
-
- static void loadTileset(const uint8_t*);
-
- static void setTileBufferTo(uint8_t*);
- static void clearTileBuffer();
- static void shiftTileBuffer(int8_t,int8_t);
-
- static void setTile(uint16_t,uint8_t);
- static uint8_t getTile(uint16_t);
- static uint8_t getTile(uint8_t,uint8_t);
-
-
-
-private:
- static uint8_t m_mode;
- static uint16_t m_w,m_h; // store these for faster access when switching printing modes
- /** Pointer to screen buffer */
- static uint8_t* m_scrbuf;
- /** Pointer to tileset */
- static uint8_t* m_tileset;
- /** Pointer to tilebuffer */
- static uint8_t* m_tilebuf;
- /** Pointer to tilecolorbuffer */
- static uint8_t* m_tilecolorbuf;
-
-};
-
-}
-
-#endif // POKITTODISPLAY_H
-
-
-
-
--- a/POKITTO_HW/HWLCD.cpp Sun Oct 22 19:02:56 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,1137 +0,0 @@
-/**************************************************************************/
-/*!
- @file HWLCD.cpp
- @author Jonne Valola
-
- @section LICENSE
-
- Software License Agreement (BSD License)
-
- Copyright (c) 2016, Jonne Valola
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holders nor the
- names of its contributors may be used to endorse or promote products
- derived from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-/**************************************************************************/
-
-#include "HWLCD.h" //HWLCD.h" #include "HWLCD.h"
-#include "Pokitto_settings.h"
-
-#define AB_JUMP 1024 // jump one 1-bit Arduboy screen forward to get next color bit
-#define GB_JUMP 504 // jump one 1-bit Gamebuino screen forward to get next color bit
-
-using namespace Pokitto;
-
-uint16_t prevdata=0; // if data does not change, do not adjust LCD bus lines
-
-#if POK_BOARDREV == 2
- pwmout_t backlightpwm;
-#endif
-
-
-/**************************************************************************/
-/*!
- @brief set up the 16-bit bus
-*/
-/**************************************************************************/
-
-static inline void setup_data_16(uint16_t data)
-{
- uint32_t p2=0;
-
- if (data != prevdata) {
-
- prevdata=data;
-
- /** D0...D16 = P2_3 ... P2_18 **/
- p2 = data << 3;
-
- //__disable_irq(); // Disable Interrupts
- SET_MASK_P2;
- LPC_GPIO_PORT->MPIN[2] = p2; // write bits to port
- CLR_MASK_P2;
- //__enable_irq(); // Enable Interrupts
- }
-}
-
-
-/**************************************************************************/
-/*!
- @brief Write a command to the lcd, 16-bit bus
-*/
-/**************************************************************************/
-inline void write_command_16(uint16_t data)
-{
- CLR_CS; // select lcd
- CLR_CD; // clear CD = command
- SET_RD; // RD high, do not read
- setup_data_16(data); // function that inputs the data into the relevant bus lines
- CLR_WR; // WR low
- SET_WR; // WR low, then high = write strobe
- SET_CS; // de-select lcd
-}
-
-/**************************************************************************/
-/*!
- @brief Write data to the lcd, 16-bit bus
-*/
-/**************************************************************************/
-inline void write_data_16(uint16_t data)
-{
- CLR_CS;
- SET_CD;
- SET_RD;
- setup_data_16(data);
- CLR_WR;
- SET_WR;
- SET_CS;
-}
-
-/**************************************************************************/
-/*!
- @brief Point to a (x,y) location in the LCD DRAM
-*/
-/**************************************************************************/
-static inline void setDRAMptr(uint8_t xptr, uint8_t yoffset)
-{
- write_command(0x20); // Vertical DRAM Address
- write_data(yoffset);
- write_command(0x21); // Horizontal DRAM Address
- write_data(xptr); //
- write_command(0x22); // write data to DRAM
- CLR_CS_SET_CD_RD_WR;
-}
-
-void Pokitto::initBacklight() {
- #if POK_BOARDREV == 2
- pwmout_init(&backlightpwm,POK_BACKLIGHT_PIN);
- pwmout_period_us(&backlightpwm,5);
- pwmout_write(&backlightpwm,POK_BACKLIGHT_INITIALVALUE);
- #endif
-}
-
-void Pokitto::setBacklight(float value) {
- if (value>0.999f) value = 0.999f;
- pwmout_write(&backlightpwm,value);
-}
-
-void Pokitto::lcdInit() {
- initBacklight();
-
- SET_RESET;
- wait_ms(10);
- CLR_RESET;
- wait_ms(10);
- SET_RESET;
- wait_ms(10);
- //************* Start Initial Sequence **********//
- write_command(0x01); // driver output control, this also affects direction
- write_data(0x11C); // originally: 0x11C 100011100 SS,NL4,NL3,NL2
- // NL4...0 is the number of scan lines to drive the screen !!!
- // so 11100 is 1c = 220 lines, correct
- // test 1: 0x1C 11100 SS=0,NL4,NL3,NL2 -> no effect
- // test 2: 0x31C 1100011100 GS=1,SS=1,NL4,NL3,NL2 -> no effect
- // test 3: 0x51C 10100011100 SM=1,GS=0,SS=1,NL4,NL3,NL2 -> no effect
- // test 4: 0x71C SM=1,GS=1,SS=1,NL4,NL3,NL2
- // test 5: 0x
- // seems to have no effect... is this perhaps only for RGB mode ?
-
- write_command(0x02); // LCD driving control
- write_data(0x0100); // INV = 1
-
- write_command(0x03); // Entry mode... lets try if this affects the direction
- write_data(0x1030); // originally 0x1030 1000000110000 BGR,ID1,ID0
- // test 1: 0x1038 1000000111000 BGR,ID1,ID0,AM=1 ->drawing DRAM horizontally
- // test 4: am=1, id0=0, id1=0, 1000000001000,0x1008 -> same as above, but flipped on long
- // test 2: am=0, id0=0, 1000000100000, 0x1020 -> flipped on long axis
- // test 3: am=0, id1=0, 1000000010000, 0x1010 -> picture flowed over back to screen
-
-
- write_command(0x08); // Display control 2
- write_data(0x0808); // 100000001000 FP2,BP2
-
- write_command(0x0C); // RGB display interface
- write_data(0x0000); // all off
-
- write_command(0x0F); // Frame marker position
- write_data(0x0001); // OSC_EN
-
- write_command(0x20); // Horizontal DRAM Address
- write_data(0x0000); // 0
-
- write_command(0x21); // Vertical DRAM Address
- write_data(0x0000); // 0
-
- //*************Power On sequence ****************//
- write_command(0x10);
- write_data(0x0000);
-
- write_command(0x11);
- write_data(0x1000);
- wait_ms(10);
-//------------------------ Set GRAM area --------------------------------//
- write_command(0x30); // Gate scan position
- write_data(0x0000); // if GS=0, 00h=G1, else 00h=G220
-
- write_command(0x31); // Vertical scroll control
- write_data(0x00DB); // scroll start line 11011011 = 219
-
- write_command(0x32); // Vertical scroll control
- write_data(0x0000); // scroll end line 0
-
- write_command(0x33); // Vertical scroll control
- write_data(0x0000); // 0=vertical scroll disabled
-
- write_command(0x34); // Partial screen driving control
- write_data(0x00DB); // db = full screen (end)
-
- write_command(0x35); // partial screen
- write_data(0x0000); // 0 = start
-
- write_command(0x36); // Horizontal and vertical RAM position
- write_data(0x00AF); //end address 175
-
- write_command(0x37);
- write_data(0x0000); // start address 0
-
- write_command(0x38);
- write_data(0x00DB); //end address 219
-
- write_command(0x39); // start address 0
- write_data(0x0000);
- wait_ms(10);
- write_command(0xff); // start gamma register control
- write_data(0x0003);
-
-// ----------- Adjust the Gamma Curve ----------//
- write_command(0x50);
- write_data(0x0203);
-
- write_command(0x051);
- write_data(0x0A09);
-
- write_command(0x52);
- write_data(0x0005);
-
- write_command(0x53);
- write_data(0x1021);
-
- write_command(0x54);
- write_data(0x0602);
-
- write_command(0x55);
- write_data(0x0003);
-
- write_command(0x56);
- write_data(0x0703);
-
- write_command(0x57);
- write_data(0x0507);
-
- write_command(0x58);
- write_data(0x1021);
-
- write_command(0x59);
- write_data(0x0703);
-
- write_command(0xB0);
- write_data(0x2501);
-
- write_command(0xFF);
- write_data(0x0000);
-
- write_command(0x07);
- write_data(0x1017);
- wait_ms(200);
- write_command(0x22);
-
- lcdClear();
-}
-
-void Pokitto::lcdSleep(void){
- write_command(0xFF);
- write_data(0x0000);
-
- write_command(0x07);
- write_data(0x0000);
- wait_ms(50);
- write_command(0x10);// Enter Standby mode
- write_data(0x0003);
- wait_ms(200);
-
-}
-
-void Pokitto::lcdWakeUp (void){
-
- wait_ms(200);
- write_command(0xFF);
- write_data(0x0000);
-
- write_command(0x10);// Exit Sleep/ Standby mode
- write_data(0x0000);
- wait_ms(50);
- write_command(0x07);
- write_data(0x0117);
- wait_ms(200);
- }
-
-void Pokitto::lcdFillSurface(uint16_t c) {
- uint32_t i;
- write_command(0x20); // Horizontal DRAM Address
- write_data(0x0000); // 0
- write_command(0x21); // Vertical DRAM Address
- write_data(0);
- write_command(0x22); // write data to DRAM
- setup_data_16(c);
- CLR_CS_SET_CD_RD_WR;
- for(i=0;i<220*176;i++)
- {
- CLR_WR;
- SET_WR;
- }
-}
-
-void Pokitto::lcdClear() {
- uint32_t i;
- write_command(0x20); // Horizontal DRAM Address
- write_data(0x0000); // 0
- write_command(0x21); // Vertical DRAM Address
- write_data(0);
- write_command(0x22); // write data to DRAM
- setup_data_16(0x0000);
- CLR_CS_SET_CD_RD_WR;
- for(i=0;i<220*176;i++)
- {
- CLR_WR;
- SET_WR;
- }
-}
-
-void Pokitto::lcdPixel(int16_t x, int16_t y, uint16_t color) {
- if ((x < 0) || (x >= POK_LCD_W) || (y < 0) || (y >= POK_LCD_H))
- return;
- write_command(0x20); // Horizontal DRAM Address
- write_data(y); // 0
- write_command(0x21); // Vertical DRAM Address
- write_data(x);
- write_command(0x22); // write data to DRAM
- CLR_CS_SET_CD_RD_WR;
- setup_data_16(color);
- CLR_WR;SET_WR;
-}
-
-void Pokitto::lcdRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color) {
- int16_t temp;
- if (x0>x1) {temp=x0;x0=x1;x1=temp;}
- if (y0>y1) {temp=y0;y0=y1;y1=temp;}
- if (x0 > POK_LCD_W) return;
- if (y0 > POK_LCD_H) return;
- if (x1 > POK_LCD_W) x1=POK_LCD_W;
- if (y1 > POK_LCD_H) y1=POK_LCD_W;
- if (x0 < 0) x0=0;
- if (y0 < 0) y0=0;
-
- int16_t x,y;
- for (x=x0; x<=x1;x++) {
- write_command(0x20); // Horizontal DRAM Address (=y on pokitto screen)
- write_data(y0);
- write_command(0x21); // Vertical DRAM Address (=x on pokitto screen)
- write_data(x);
- write_command(0x22); // write data to DRAM
-
- CLR_CS_SET_CD_RD_WR; // go to vram write mode
-
-
- for (y=y0; y<y1;y++) {
- setup_data_16(color); // setup the data (flat color = no change between pixels)
- CLR_WR;SET_WR; //CLR_WR;SET_WR;//toggle writeline, pokitto screen writes a column up to down
- }
- }
-}
-
-void Pokitto::lcdRefreshMode1(uint8_t * scrbuf, uint16_t* paletteptr) {
-uint16_t x,y,xptr;
-uint16_t scanline[4][176]; // read 4 half-nibbles = 4 pixels at a time
-uint8_t *d, yoffset=0;
-
-xptr = 0;
-setDRAMptr(xptr,yoffset);
-
-
-for(x=0;x<220;x+=4)
- {
- d = scrbuf+(x>>2);// point to beginning of line in data
- /** find colours in one scanline **/
- uint8_t s=0;
- for(y=0;y<176;y++)
- {
- uint8_t tdata = *d;
- uint8_t t4 = tdata & 0x03; tdata >>= 2;// lowest half-nibble
- uint8_t t3 = tdata & 0x03; tdata >>= 2;// second lowest half-nibble
- uint8_t t2 = tdata & 0x03; tdata >>= 2;// second highest half-nibble
- uint8_t t = tdata & 0x03;// highest half-nibble
-
- /** put nibble values in the scanlines **/
- scanline[0][s] = paletteptr[t];
- scanline[1][s] = paletteptr[t2];
- scanline[2][s] = paletteptr[t3];
- scanline[3][s++] = paletteptr[t4];
-
- d+=220/4; // jump to read byte directly below in screenbuffer
- }
- s=0;
- /** draw scanlines **/
- for (s=0;s<176;) {
- setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
- }
- for (s=0;s<176;) {
- setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
- }
- for (s=0;s<176;) {
- setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
- }
- for (s=0;s<176;) {
- setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
- }
- }
-}
-
-void Pokitto::lcdRefreshMode2(uint8_t * scrbuf, uint16_t* paletteptr) {
-uint16_t x,y;
-uint16_t scanline[2][88]; // read two nibbles = pixels at a time
-uint8_t *d;
-
-write_command(0x20); // Horizontal DRAM Address
-write_data(0); // 0
-write_command(0x21); // Vertical DRAM Address
-write_data(0);
-write_command(0x22); // write data to DRAM
-CLR_CS_SET_CD_RD_WR;
-
-for(x=0;x<110;x+=2)
- {
- d = scrbuf+(x>>1);// point to beginning of line in data
- /** find colours in one scanline **/
- uint8_t s=0;
- for(y=0;y<88;y++)
- {
- uint8_t t = *d >> 4; // higher nibble
- uint8_t t2 = *d & 0xF; // lower nibble
- /** higher nibble = left pixel in pixel pair **/
- scanline[0][s] = paletteptr[t];
- scanline[1][s++] = paletteptr[t2];
- /** testing only **/
- //scanline[0][s] = 0xFFFF*(s&1);
- //scanline[1][s] = 0xFFFF*(!(s&1));
- //s++;
- /** until here **/
- d+=110/2; // jump to read byte directly below in screenbuffer
- }
- s=0;
- /** draw scanlines **/
- /** leftmost scanline twice**/
-
- for (s=0;s<88;) {
- setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
- }
-
- for (s=0;s<88;) {
- setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
- }
- /** rightmost scanline twice**/
- //setDRAMptr(xptr++,yoffset);
- for (s=0;s<88;) {
- setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
- }
-
- for (s=0;s<88;) {
- setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
- }
- }
-}
-
-void Pokitto::lcdRefreshMode3(uint8_t * scrbuf, uint16_t* paletteptr) {
-uint16_t x,y;
-uint16_t scanline[2][176]; // read two nibbles = pixels at a time
-uint8_t *d;
-
-write_command(0x20); // Horizontal DRAM Address
-write_data(0); // 0
-write_command(0x21); // Vertical DRAM Address
-write_data(0);
-write_command(0x22); // write data to DRAM
-CLR_CS_SET_CD_RD_WR;
-
-for(x=0;x<220;x+=2)
- {
- d = scrbuf+(x>>1);// point to beginning of line in data
- /** find colours in one scanline **/
- uint8_t s=0;
- for(y=0;y<176;y++)
- {
- uint8_t t = *d >> 4; // higher nibble
- uint8_t t2 = *d & 0xF; // lower nibble
- /** higher nibble = left pixel in pixel pair **/
- scanline[0][s] = paletteptr[t];
- scanline[1][s++] = paletteptr[t2];
- /** testing only **/
- //scanline[0][s] = 0xFFFF*(s&1);
- //scanline[1][s] = 0xFFFF*(!(s&1));
- //s++;
- /** until here **/
- d+=220/2; // jump to read byte directly below in screenbuffer
- }
- s=0;
- /** draw scanlines **/
- /** leftmost scanline**/
-
- for (s=0;s<176;) {
- setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
- }
-
- /** rightmost scanline**/
- //setDRAMptr(xptr++,yoffset);
- for (s=0;s<176;) {
- setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
- }
- }
-}
-
-void Pokitto::lcdRefreshGB(uint8_t * scrbuf, uint16_t* paletteptr) {
-uint16_t x,y;
-uint16_t scanline[48];
-uint8_t * d;
-
-#if POK_STRETCH
-//uint16_t xptr = 8;
-#else
-//xptr = 26;
-#endif
-
-write_command(0x20); // Horizontal DRAM Address
-write_data(0); // 0
-write_command(0x21); // Vertical DRAM Address
-write_data(0);
-write_command(0x22); // write data to DRAM
-CLR_CS_SET_CD_RD_WR;
-
-/** draw border **/
- for (int s=0;s<5*176;) {
- setup_data_16(COLOR_BLACK);CLR_WR;SET_WR;s++;
- }
-
-for(x=0;x<84;x++)
- {
-
- d = scrbuf + x;// point to beginning of line in data
-
- /** find colours in one scanline **/
- uint8_t s=0;
- for(y=0;y<6;y++)
- {
- uint8_t t = *d;
- #if POK_COLORDEPTH > 1
- uint8_t t2 = *(d+504);
- #endif
- #if POK_COLORDEPTH > 2
- uint8_t t3 = *(d+504+504);
- #endif
- #if POK_COLORDEPTH > 3
- uint8_t t4 = *(d+504+504+504);
- #endif
- uint8_t paletteindex = 0;
-
- /** bit 1 **/
- #if POK_COLORDEPTH == 1
- paletteindex = (t & 0x1);
- #elif POK_COLORDEPTH == 2
- paletteindex = ((t & 0x1)) | ((t2 & 0x01)<<1);
- #elif POK_COLORDEPTH == 3
- paletteindex = (t & 0x1) | ((t2 & 0x1)<<1) | ((t3 & 0x1)<<2);
- #elif POK_COLORDEPTH == 4
- paletteindex = (t & 0x1) | ((t2 & 0x1)<<1) | ((t3 & 0x1)<<2) | ((t4 & 0x1)<<3);
- #endif
- scanline[s++] = paletteptr[paletteindex];
-
- /** bit 2 **/
- #if POK_COLORDEPTH == 1
- paletteindex = (t & 0x2)>>1;
- #elif POK_COLORDEPTH == 2
- paletteindex = ((t & 0x2)>>1) | ((t2 & 0x02));
- #elif POK_COLORDEPTH == 3
- paletteindex = ((t & 0x2)>>1) | ((t2 & 0x2)) | ((t3 & 0x2)<<1);
- #elif POK_COLORDEPTH == 4
- paletteindex = ((t & 0x2)>>1) | ((t2 & 0x2)) | ((t3 & 0x2)<<1) | ((t4 & 0x2)<<2);
- #endif
- scanline[s++] = paletteptr[paletteindex];
-
- /** bit 3 **/
- #if POK_COLORDEPTH == 1
- paletteindex = (t & 0x4)>>2;
- #elif POK_COLORDEPTH == 2
- paletteindex = ((t & 4)>>2) | ((t2 & 0x04)>>1);
- #elif POK_COLORDEPTH == 3
- paletteindex = ((t & 0x4)>>2) | ((t2 & 0x4)>>1) | (t3 & 0x4);
- #elif POK_COLORDEPTH == 4
- paletteindex = ((t & 0x4)>>2) | ((t2 & 0x4)>>1) | (t3 & 0x4) | ((t4 & 0x4)<<1);
- #endif
- scanline[s++] = paletteptr[paletteindex];
-
- /** bit 4 **/
- #if POK_COLORDEPTH == 1
- paletteindex = (t & 0x8)>>3;
- #elif POK_COLORDEPTH == 2
- paletteindex = ((t & 0x8)>>3) | ((t2 & 0x08)>>2);
- #elif POK_COLORDEPTH == 3
- paletteindex = ((t & 0x8)>>3) | ((t2 & 0x8)>>2) | ((t3 & 0x8)>>1);
- #elif POK_COLORDEPTH == 4
- paletteindex = ((t & 0x8)>>3) | ((t2 & 0x8)>>2) | ((t3 & 0x8)>>1) | (t4 & 0x8);
- #endif
- scanline[s++] = paletteptr[paletteindex];
-
- /** bit 5 **/
- #if POK_COLORDEPTH == 1
- paletteindex = (t & 0x10)>>4;
- #elif POK_COLORDEPTH == 2
- paletteindex = ((t & 0x10)>>4) | ((t2 & 0x10)>>3);
- #elif POK_COLORDEPTH == 3
- paletteindex = ((t & 0x10)>>4) | ((t2 & 0x10)>>3) | ((t3 & 0x10)>>2);
- #elif POK_COLORDEPTH == 4
- paletteindex = ((t & 0x10)>>4) | ((t2 & 0x10)>>3) | ((t3 & 0x10)>>2) | ((t4 & 0x10)>>1);
- #endif
- scanline[s++] = paletteptr[paletteindex];
-
- /** bit 6 **/
- #if POK_COLORDEPTH == 1
- paletteindex = (t & 0x20)>>5;
- #elif POK_COLORDEPTH == 2
- paletteindex = ((t & 0x20)>>5) | ((t2 & 0x20)>>4);
- #elif POK_COLORDEPTH == 3
- paletteindex = ((t & 0x20)>>5) | ((t2 & 0x20)>>4) | ((t3 & 0x20)>>3);
- #elif POK_COLORDEPTH == 4
- paletteindex = ((t & 0x20)>>5) | ((t2 & 0x20)>>4) | ((t3 & 0x20)>>3) | ((t4 & 0x20)>>2);
- #endif
- scanline[s++] = paletteptr[paletteindex];
-
- /** bit 7 **/
- #if POK_COLORDEPTH == 1
- paletteindex = (t & 0x40)>>6;
- #elif POK_COLORDEPTH == 2
- paletteindex = ((t & 0x40)>>6) | ((t2 & 0x40)>>5);
- #elif POK_COLORDEPTH == 3
- paletteindex = ((t & 0x40)>>6) | ((t2 & 0x40)>>5) | ((t3 & 0x40)>>4) ;
- #elif POK_COLORDEPTH == 4
- paletteindex = ((t & 0x40)>>6) | ((t2 & 0x40)>>5) | ((t3 & 0x40)>>4) | ((t4 & 0x40)>>3);
- #endif
- scanline[s++] = paletteptr[paletteindex];
-
- /** bit 8 **/
- #if POK_COLORDEPTH == 1
- paletteindex = (t & 0x80)>>7;
- #elif POK_COLORDEPTH == 2
- paletteindex = ((t & 0x80)>>7) | ((t2 & 0x80)>>6);
- #elif POK_COLORDEPTH == 3
- paletteindex = ((t & 0x80)>>7) | ((t2 & 0x80)>>6) | ((t3 & 0x80)>>5);
- #elif POK_COLORDEPTH == 4
- paletteindex = ((t & 0x80)>>7) | ((t2 & 0x80)>>6) | ((t3 & 0x80)>>5) | ((t4 & 0x80)>>4);
- #endif
- scanline[s++] = paletteptr[paletteindex];
-
- d+=84; // jump to byte directly below
- }
-
-
- /*write_command(0x20); // Horizontal DRAM Address
- write_data(0x10); // 0
- write_command(0x21); // Vertical DRAM Address
- write_data(xptr++);
- write_command(0x22); // write data to DRAM
- CLR_CS_SET_CD_RD_WR;*/
- /** draw border **/
- setup_data_16(COLOR_BLACK);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR; CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
-
- s=0;
-
- /** draw scanlines **/
- for (s=0;s<48;) {
- setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
- }
- /** draw border **/
- setup_data_16(COLOR_BLACK);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR; CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
-
-
- /*write_command(0x20); // Horizontal DRAM Address
- write_data(0x10); // 0
- write_command(0x21); // Vertical DRAM Address
- write_data(xptr++);
- write_command(0x22); // write data to DRAM
- CLR_CS_SET_CD_RD_WR;*/
- /** draw border **/
- setup_data_16(COLOR_BLACK);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR; CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
-
- for (s=0;s<48;) {
- setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
- }
-
- /** draw border **/
- setup_data_16(COLOR_BLACK);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR; CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
-
-
- #if POK_STRETCH
- //if (x>16 && x<68)
- if (x&2)// && x&2)
- {
- /*write_command(0x20); // Horizontal DRAM Address
- write_data(0x10); // 0
- write_command(0x21); // Vertical DRAM Address
- write_data(xptr++);
- write_command(0x22); // write data to DRAM
- CLR_CS_SET_CD_RD_WR;*/
- /** draw border **/
- setup_data_16(COLOR_BLACK);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR; CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
-
-
- for (s=0;s<48;) {
- setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
- }
-
- /** draw border **/
- setup_data_16(COLOR_BLACK);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR; CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
-
- }
- #endif
- }
- /** draw border **/
- for (int s=0;s<5*176;) {
- setup_data_16(COLOR_BLACK);CLR_WR;SET_WR;s++;
- }
-}
-
-
-void Pokitto::lcdRefreshAB(uint8_t * scrbuf, uint16_t* paletteptr) {
-uint16_t x,y;
-uint16_t scanline[64];
-uint8_t *d;
-//lcdClear();
-#if POK_STRETCH
-uint16_t xptr = 14;
-uint8_t yoffset = 24;
-#else
-xptr = 0; //was 26
-#endif
-
-for(x=0;x<128;x++)
- {
- write_command(0x20); // Horizontal DRAM Address
- write_data(yoffset); // 0
- write_command(0x21); // Vertical DRAM Address
- write_data(xptr++);
- write_command(0x22); // write data to DRAM
- CLR_CS_SET_CD_RD_WR;
- //setDRAMptr(xptr++,yoffset);
-
- d = scrbuf + x;// point to beginning of line in data
-
- /** find colours in one scanline **/
- uint8_t s=0;
- for(y=0;y<8;y++)
- {
- uint8_t t = *d;
- #if POK_COLORDEPTH > 1
- uint8_t t2 = *(d+AB_JUMP);
- #endif // POK_COLORDEPTH
- #if POK_COLORDEPTH > 2
- uint8_t t3 = *(d+AB_JUMP+AB_JUMP);
- #endif // POK_COLORDEPTH
- #if POK_COLORDEPTH > 3
- uint8_t t4 = *(d+AB_JUMP+AB_JUMP+AB_JUMP);
- #endif // POK_COLORDEPTH
- uint8_t paletteindex = 0;
-
- /** bit 1 **/
- #if POK_COLORDEPTH == 1
- paletteindex = (t & 0x1);
- #elif POK_COLORDEPTH == 2
- paletteindex = ((t & 0x1)) | ((t2 & 0x01)<<1);
- #elif POK_COLORDEPTH == 3
- paletteindex = (t & 0x1) | ((t2 & 0x1)<<1) | ((t3 & 0x1)<<2);
- #elif POK_COLORDEPTH == 4
- paletteindex = (t & 0x1) | ((t2 & 0x1)<<1) | ((t3 & 0x1)<<2) | ((t4 & 0x1)<<3);
- #endif
- scanline[s++] = paletteptr[paletteindex];
-
- /** bit 2 **/
- #if POK_COLORDEPTH == 1
- paletteindex = (t & 0x2)>>1;
- #elif POK_COLORDEPTH == 2
- paletteindex = ((t & 0x2)>>1) | ((t2 & 0x02));
- #elif POK_COLORDEPTH == 3
- paletteindex = ((t & 0x2)>>1) | ((t2 & 0x2)) | ((t3 & 0x2)<<1);
- #elif POK_COLORDEPTH == 4
- paletteindex = ((t & 0x2)>>1) | ((t2 & 0x2)) | ((t3 & 0x2)<<1) | ((t4 & 0x2)<<2);
- #endif
- scanline[s++] = paletteptr[paletteindex];
-
- /** bit 3 **/
- #if POK_COLORDEPTH == 1
- paletteindex = (t & 0x4)>>2;
- #elif POK_COLORDEPTH == 2
- paletteindex = ((t & 4)>>2) | ((t2 & 0x04)>>1);
- #elif POK_COLORDEPTH == 3
- paletteindex = ((t & 0x4)>>2) | ((t2 & 0x4)>>1) | (t3 & 0x4);
- #elif POK_COLORDEPTH == 4
- paletteindex = ((t & 0x4)>>2) | ((t2 & 0x4)>>1) | (t3 & 0x4) | ((t4 & 0x4)<<1);
- #endif
- scanline[s++] = paletteptr[paletteindex];
-
- /** bit 4 **/
- #if POK_COLORDEPTH == 1
- paletteindex = (t & 0x8)>>3;
- #elif POK_COLORDEPTH == 2
- paletteindex = ((t & 0x8)>>3) | ((t2 & 0x08)>>2);
- #elif POK_COLORDEPTH == 3
- paletteindex = ((t & 0x8)>>3) | ((t2 & 0x8)>>2) | ((t3 & 0x8)>>1);
- #elif POK_COLORDEPTH == 4
- paletteindex = ((t & 0x8)>>3) | ((t2 & 0x8)>>2) | ((t3 & 0x8)>>1) | (t4 & 0x8);
- #endif
- scanline[s++] = paletteptr[paletteindex];
-
- /** bit 5 **/
- #if POK_COLORDEPTH == 1
- paletteindex = (t & 0x10)>>4;
- #elif POK_COLORDEPTH == 2
- paletteindex = ((t & 0x10)>>4) | ((t2 & 0x10)>>3);
- #elif POK_COLORDEPTH == 3
- paletteindex = ((t & 0x10)>>4) | ((t2 & 0x10)>>3) | ((t3 & 0x10)>>2);
- #elif POK_COLORDEPTH == 4
- paletteindex = ((t & 0x10)>>4) | ((t2 & 0x10)>>3) | ((t3 & 0x10)>>2) | ((t4 & 0x10)>>1);
- #endif
- scanline[s++] = paletteptr[paletteindex];
-
- /** bit 6 **/
- #if POK_COLORDEPTH == 1
- paletteindex = (t & 0x20)>>5;
- #elif POK_COLORDEPTH == 2
- paletteindex = ((t & 0x20)>>5) | ((t2 & 0x20)>>4);
- #elif POK_COLORDEPTH == 3
- paletteindex = ((t & 0x20)>>5) | ((t2 & 0x20)>>4) | ((t3 & 0x20)>>3);
- #elif POK_COLORDEPTH == 4
- paletteindex = ((t & 0x20)>>5) | ((t2 & 0x20)>>4) | ((t3 & 0x20)>>3) | ((t4 & 0x20)>>2);
- #endif
- scanline[s++] = paletteptr[paletteindex];
-
- /** bit 7 **/
- #if POK_COLORDEPTH == 1
- paletteindex = (t & 0x40)>>6;
- #elif POK_COLORDEPTH == 2
- paletteindex = ((t & 0x40)>>6) | ((t2 & 0x40)>>5);
- #elif POK_COLORDEPTH == 3
- paletteindex = ((t & 0x40)>>6) | ((t2 & 0x40)>>5) | ((t3 & 0x40)>>4) ;
- #elif POK_COLORDEPTH == 4
- paletteindex = ((t & 0x40)>>6) | ((t2 & 0x40)>>5) | ((t3 & 0x40)>>4) | ((t4 & 0x40)>>3);
- #endif
- scanline[s++] = paletteptr[paletteindex];
-
- /** bit 8 **/
- #if POK_COLORDEPTH == 1
- paletteindex = (t & 0x80)>>7;
- #elif POK_COLORDEPTH == 2
- paletteindex = ((t & 0x80)>>7) | ((t2 & 0x80)>>6);
- #elif POK_COLORDEPTH == 3
- paletteindex = ((t & 0x80)>>7) | ((t2 & 0x80)>>6) | ((t3 & 0x80)>>5);
- #elif POK_COLORDEPTH == 4
- paletteindex = ((t & 0x80)>>7) | ((t2 & 0x80)>>6) | ((t3 & 0x80)>>5) | ((t4 & 0x80)>>4);
- #endif
- scanline[s++] = paletteptr[paletteindex];
-
- d+=128; // jump to byte directly below
- }
-
- s=0;
-
- /** draw scanlines **/
- for (s=0;s<64;) {
- setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
- }
-
- #if POK_STRETCH
- if (x&1) {
- write_command(0x20); // Horizontal DRAM Address
- write_data(yoffset); // 0
- write_command(0x21); // Vertical DRAM Address
- write_data(xptr++);
- write_command(0x22); // write data to DRAM
- CLR_CS_SET_CD_RD_WR;
- //setDRAMptr(xptr++,yoffset);
-
- for (s=0;s<64;) {
- setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
- setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
- }
- }
- #endif
- }
-}
-
-void Pokitto::lcdRefreshModeGBC(uint8_t * scrbuf, uint16_t* paletteptr) {
-uint16_t x,y,xptr;
-uint16_t scanline[4][144]; // read 4 half-nibbles = 4 pixels at a time
-uint8_t *d, yoffset=0;
-
-xptr = 0;
-setDRAMptr(xptr,yoffset);
-
-
-for(x=0;x<160;x+=4)
- {
- d = scrbuf+(x>>2);// point to beginning of line in data
- /** find colours in one scanline **/
- uint8_t s=0;
- for(y=0;y<144;y++)
- {
- uint8_t tdata = *d;
- uint8_t t4 = tdata & 0x03; tdata >>= 2;// lowest half-nibble
- uint8_t t3 = tdata & 0x03; tdata >>= 2;// second lowest half-nibble
- uint8_t t2 = tdata & 0x03; tdata >>= 2;// second highest half-nibble
- uint8_t t = tdata & 0x03;// highest half-nibble
-
- /** put nibble values in the scanlines **/
-
- scanline[0][s] = paletteptr[t];
- scanline[1][s] = paletteptr[t2];
- scanline[2][s] = paletteptr[t3];
- scanline[3][s++] = paletteptr[t4];
-
- d+=160/4; // jump to read byte directly below in screenbuffer
- }
-
- s=0;
- /** draw scanlines **/
- for (s=0;s<144;) {
- setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
- }
- setDRAMptr(++xptr,yoffset);
- for (s=0;s<144;) {
- setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
- }
- setDRAMptr(++xptr,yoffset);
- for (s=0;s<144;) {
- setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
- }
- setDRAMptr(++xptr,yoffset);
- for (s=0;s<144;) {
- setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
- setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
- }
- setDRAMptr(++xptr,yoffset);
- }
-}
-
-
-void Pokitto::lcdRefreshT1(uint8_t* tilebuf, uint8_t* tilecolorbuf, uint8_t* tileset, uint16_t* paletteptr) {
-#ifdef POK_TILEMODE
-uint16_t x,y,data,xptr;
-uint16_t scanline[176];
-uint8_t yoffset=0, tilebyte, tileindex, tilex=0, tiley=0,xcount;
-
-
-if (!tileset) return;
-
-#if LCDWIDTH < POK_LCD_W
-xptr = (POK_LCD_W-LCDWIDTH)/2;
-#else
-xptr = 0;
-#endif
-#if LCDHEIGHT < POK_LCD_H
-yoffset = (POK_LCD_H-LCDHEIGHT)/2;
-#else
-yoffset = 0;
-#endif
-
-for(x=0, xcount=0 ;x<LCDWIDTH;x++,xcount++) // loop through vertical columns
- {
- setDRAMptr(xptr++,yoffset); //point to VRAM
-
- /** find colours in one scanline **/
- uint8_t s=0, tiley=0;
- //tileindex = tilebuf[tilex*POK_TILES_Y];
- if (xcount==POK_TILE_W) {
- tilex++;
- xcount=0;
- }
-
- for(y=0;y<LCDHEIGHT;)
- {
- uint8_t tileval = tilebuf[tilex+tiley*POK_TILES_X]; //get tile number
- uint16_t index = tileval*POK_TILE_W+xcount;
- uint8_t tilebyte = tileset[index]; //get bitmap data
- for (uint8_t ycount=0, bitcount=0; ycount<POK_TILE_H; ycount++, y++, bitcount++) {
- if (bitcount==8) {
- bitcount=0;
- index += 176; //jump to byte below in the tileset bitmap
- tilebyte = tileset[index]; //get bitmap data
- }
- //tilebyte = tile[(tileindex>>4)+*POK_TILE_W]; //tilemaps are 16x16
- //uint8_t paletteindex = ((tilebyte>>(bitcount&0x7)) & 0x1);
- if (!tileval) scanline[s++] = COLOR_MAGENTA*((tilebyte>>bitcount)&0x1);//paletteptr[paletteindex];
- else scanline[s++] = paletteptr[((tilebyte>>bitcount)&0x1)*tileval];//paletteptr[paletteindex];
- }
- tiley++; //move to next tile
- }
- s=0;
-
- /** draw scanlines **/
- for (s=0;s<LCDHEIGHT;) {
- setup_data_16(scanline[s++]);CLR_WR;SET_WR;
- }
- }
- #endif
-}
-
-void Pokitto::blitWord(uint16_t c) {
- setup_data_16(c);CLR_WR;SET_WR;
-}
-
--- a/POKITTO_HW/HWLCD.h Sun Oct 22 19:02:56 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,195 +0,0 @@
-/**************************************************************************/
-/*!
- @file HWLCD.h
- @author Jonne Valola
-
- @section LICENSE
-
- Software License Agreement (BSD License)
-
- Copyright (c) 2016, Jonne Valola
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holders nor the
- names of its contributors may be used to endorse or promote products
- derived from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-/**************************************************************************/
-
-#ifndef __HWLCD_H__
-#define __HWLCD_H__
-
-#include "mbed.h"
-#include "gpio_api.h"
-#include "pinmap.h"
-
-#define write_command write_command_16
-#define write_data write_data_16
-
-namespace Pokitto {
-
-
-extern void initBacklight();
-extern void setBacklight(float);
-extern void lcdFillSurface(uint16_t);
-extern void lcdPixel(int16_t x, int16_t y, uint16_t c);
-extern void lcdRectangle(int16_t x, int16_t y,int16_t x2, int16_t y2, uint16_t color);
-extern void lcdInit();
-extern void lcdSleep();
-extern void lcdWakeUp();
-extern void lcdRefresh(uint8_t *, uint16_t*);
-extern void lcdRefreshAB(uint8_t *, uint16_t*);
-extern void lcdRefreshGB(uint8_t *, uint16_t*);
-extern void lcdRefreshMode1(uint8_t *, uint16_t*);
-extern void lcdRefreshMode2(uint8_t *, uint16_t*);
-extern void lcdRefreshMode3(uint8_t *, uint16_t*);
-extern void lcdRefreshModeGBC(uint8_t *, uint16_t*);
-/** Update LCD from 1-bit tile mode */
-extern void lcdRefreshT1(uint8_t*, uint8_t*, uint8_t*, uint16_t*);
-extern void lcdClear();
-extern void lcdFill(uint16_t);
-/** Blit one word of data*/
-extern void blitWord(uint16_t);
-
-/**************************************************************************/
-/** PINS AND PORTS **/
-/**************************************************************************/
-
-#if POK_BOARDREV == 1
-/** 2-layer board version 1.3 **/
- #define LCD_CD_PORT 0
- #define LCD_CD_PIN 2
- #define LCD_WR_PORT 1
- #define LCD_WR_PIN 23
- #define LCD_RD_PORT 1
- #define LCD_RD_PIN 24
- #define LCD_RES_PORT 1
- #define LCD_RES_PIN 28
-#else
-/** 4-layer board version 2.1 **/
- #define LCD_CD_PORT 0
- #define LCD_CD_PIN 2
- #define LCD_WR_PORT 1
- #define LCD_WR_PIN 12
- #define LCD_RD_PORT 1
- #define LCD_RD_PIN 24
- #define LCD_RES_PORT 1
- #define LCD_RES_PIN 0
-#endif
-
-/**************************************************************************/
-/** LCD CONTROL MACROS **/
-/**************************************************************************/
-
-#define CLR_RESET LPC_GPIO_PORT->CLR[LCD_RES_PORT] = 1 << LCD_RES_PIN; //RST = (0); // Clear pin
-#define SET_RESET LPC_GPIO_PORT->SET[LCD_RES_PORT] = 1 << LCD_RES_PIN; // RST = (1); // Set pin
-
-#define CLR_CD { LPC_GPIO_PORT->CLR[LCD_CD_PORT] = 1 << LCD_CD_PIN; } // RS = (0); // Clear pin
-#define SET_CD { LPC_GPIO_PORT->SET[LCD_CD_PORT] = 1 << LCD_CD_PIN; }// RS = (1); // Set pin
-
-#define CLR_WR { LPC_GPIO_PORT->CLR[LCD_WR_PORT] = 1 << LCD_WR_PIN; __asm("nop");__asm("nop");}//WR = (0); // Clear pin
-#define SET_WR LPC_GPIO_PORT->SET[LCD_WR_PORT] = 1 << LCD_WR_PIN; //WR = (1); // Set pin
-
-#define CLR_RD LPC_GPIO_PORT->CLR[LCD_RD_PORT] = 1 << LCD_RD_PIN; //RD = (0); // Clear pin
-#define SET_RD LPC_GPIO_PORT->SET[LCD_RD_PORT] = 1 << LCD_RD_PIN; //RD = (1); // Set pin
-
-#define SET_CS //CS tied to ground
-#define CLR_CS
-
-#define CLR_CS_CD_SET_RD_WR {CLR_CD; SET_RD; SET_WR;}
-#define CLR_CS_SET_CD_RD_WR {SET_CD; SET_RD; SET_WR;}
-#define SET_CD_RD_WR {SET_CD; SET_RD; SET_WR;}
-#define SET_WR_CS SET_WR;
-
-#define SET_MASK_P2 LPC_GPIO_PORT->MASK[2] = ~(0x7FFF8); //mask P2_3 ...P2_18
-#define CLR_MASK_P2 LPC_GPIO_PORT->MASK[2] = 0; // all on
-
-
-
-/**************************************************************************/
-/** SETUP GPIO & DATA **/
-/**************************************************************************/
-
-static void setup_gpio()
-{
- /** control lines **/
- LPC_GPIO_PORT->DIR[LCD_CD_PORT] |= (1 << LCD_CD_PIN );
- LPC_GPIO_PORT->DIR[LCD_WR_PORT] |= (1 << LCD_WR_PIN );
- LPC_GPIO_PORT->DIR[LCD_RD_PORT] |= (1 << LCD_RD_PIN );
- LPC_GPIO_PORT->DIR[LCD_RES_PORT] |= (1 << LCD_RES_PIN );
- /** data lines **/
- LPC_GPIO_PORT->DIR[2] |= (0xFFFF << 3); // P2_3...P2_18 as output
-
- pin_mode(P2_3,PullNone); // turn off pull-up
- pin_mode(P2_4,PullNone); // turn off pull-up
- pin_mode(P2_5,PullNone); // turn off pull-up
- pin_mode(P2_6,PullNone); // turn off pull-up
-
- pin_mode(P2_7,PullNone); // turn off pull-up
- pin_mode(P2_8,PullNone); // turn off pull-up
- pin_mode(P2_9,PullNone); // turn off pull-up
- pin_mode(P2_10,PullNone); // turn off pull-up
-
- pin_mode(P2_11,PullNone); // turn off pull-up
- pin_mode(P2_12,PullNone); // turn off pull-up
- pin_mode(P2_13,PullNone); // turn off pull-up
- pin_mode(P2_14,PullNone); // turn off pull-up
-
- pin_mode(P2_15,PullNone); // turn off pull-up
- pin_mode(P2_16,PullNone); // turn off pull-up
- pin_mode(P2_17,PullNone); // turn off pull-up
- pin_mode(P2_18,PullNone); // turn off pull-up
-}
-
-
-
-
-#define HI_BYTE(d) (LPC_GPIO->MPIN[1]= (d<<13)) //((d>>8)<<21))
-#define LO_BYTE(d) (LPC_GPIO->MPIN[1]= (d<<21)) //because of mask makes no difference
-
-// Macros to set data bus direction to input/output
-#define LCD_GPIO2DATA_SETINPUT GPIO_GPIO2DIR &= ~LCD_DATA_MASK
-#define LCD_GPIO2DATA_SETOUTPUT GPIO_GPIO2DIR |= LCD_DATA_MASK
-
-
-// Basic Color definitions
-#define COLOR_BLACK (uint16_t)(0x0000)
-#define COLOR_BLUE (uint16_t)(0x001F)
-#define COLOR_RED (uint16_t)(0xF800)
-#define COLOR_GREEN (uint16_t)(0x07E0)
-#define COLOR_CYAN (uint16_t)(0x07FF)
-#define COLOR_MAGENTA (uint16_t)(0xF81F)
-#define COLOR_YELLOW (uint16_t)(0xFFE0)
-#define COLOR_WHITE (uint16_t)(0xFFFF)
-
-// Grayscale Values
-#define COLOR_GRAY_15 (uint16_t)(0x0861) // 15 15 15
-#define COLOR_GRAY_30 (uint16_t)(0x18E3) // 30 30 30
-#define COLOR_GRAY_50 (uint16_t)(0x3186) // 50 50 50
-#define COLOR_GRAY_80 (uint16_t)(0x528A) // 80 80 80
-#define COLOR_GRAY_128 (uint16_t)(0x8410) // 128 128 128
-#define COLOR_GRAY_200 (uint16_t)(0xCE59) // 200 200 200
-#define COLOR_GRAY_225 (uint16_t)(0xE71C) // 225 225 225
-
-
-} // namespace pokitto
-#endif // __HWLCD_H_
-