PokittoLib is the library needed for programming the Pokitto DIY game console (www.pokitto.com)
Fork of PokittoLib by
Revision 15:0bbe8f6fae32, committed 2017-10-18
- Comitter:
- spinal
- Date:
- Wed Oct 18 14:47:54 2017 +0000
- Parent:
- 14:ba6ed3637e54
- Commit message:
- direct lcd stuff used by sensitive
Changed in this revision
diff -r ba6ed3637e54 -r 0bbe8f6fae32 POKITTO_CORE/PokittoDisplay.cpp --- a/POKITTO_CORE/PokittoDisplay.cpp Wed Oct 18 14:25:12 2017 +0000 +++ b/POKITTO_CORE/PokittoDisplay.cpp Wed Oct 18 14:47:54 2017 +0000 @@ -212,6 +212,10 @@ lcdPixel(x,y,color); } +void Display::directTile(int16_t x, int16_t y, int16_t x2, int16_t y2, uint16_t* gfx) { + lcdTile(x,y,x2,y2,gfx); +} + void Display::directRectangle(int16_t x, int16_t y,int16_t x2, int16_t y2, uint16_t color) { lcdRectangle(x,y,x2,y2,color); }
diff -r ba6ed3637e54 -r 0bbe8f6fae32 POKITTO_CORE/PokittoDisplay.h --- a/POKITTO_CORE/PokittoDisplay.h Wed Oct 18 14:25:12 2017 +0000 +++ b/POKITTO_CORE/PokittoDisplay.h Wed Oct 18 14:47:54 2017 +0000 @@ -229,6 +229,8 @@ // DIRECT DRAWING (NO BUFFERING) /** Direct pixel (not through display buffer) */ static void directPixel(int16_t,int16_t,uint16_t); + /** Direct tile 16bit (not through display buffer) */ + static void directTile(int16_t x, int16_t y, int16_t x2, int16_t y2, uint16_t* gfx); /** 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 */
diff -r ba6ed3637e54 -r 0bbe8f6fae32 POKITTO_HW/HWLCD.cpp --- a/POKITTO_HW/HWLCD.cpp Wed Oct 18 14:25:12 2017 +0000 +++ b/POKITTO_HW/HWLCD.cpp Wed Oct 18 14:47:54 2017 +0000 @@ -327,44 +327,72 @@ } } +void Pokitto::setWindow(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2) { + write_command(0x37); write_data(x1); + write_command(0x36); write_data(x2); + write_command(0x39); write_data(y1); + write_command(0x38); write_data(y2); + write_command(0x20); write_data(x1); + write_command(0x21); write_data(y1); +} + +void Pokitto::lcdTile(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t* gfx){ + int width=x1-x0; + int height=y1-y0; + if (x0 > POK_LCD_W) return; + if (y0 > POK_LCD_H) return; + if (x0 < 0) x0=0; + if (y0 < 0) y0=0; + + setWindow(y0, x0, y1-1, x1-1); + write_command(0x22); + + for (int x=0; x<=width*height-1;x++) { + write_data(gfx[x]); + } + setWindow(0, 0, 175, 219); +} + 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; + write_command(0x20); write_data(y); + write_command(0x21); write_data(x); + write_command(0x22); write_data(color); + } 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; + if(x1<=x0)x1=x0+1; + if(y1<=y0)y1=y0+1; + setWindow(y0, x0, y1-1, x1-1); + write_command(0x22); + int width=x1-x0; + int height=y1-y0; + int i=width*height; + while (i--) { + write_data(color); + } +} - 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 +void Pokitto::lcdRefreshRegionMode1(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint8_t * scrbuf, uint16_t * paletteptr){ + if(x1<=x0)x1=x0+1; + if(y1<=y0)y1=y0+1; + setWindow(y0, x0, y1-1, x1-1); + write_command(0x22); + uint8_t pix; + uint8_t quartWide=(x1-x0)/4; + uint8_t pic; - CLR_CS_SET_CD_RD_WR; // go to vram write mode - + x0/=4; - 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 + for(int y=y0; y<y1; y++){ + for(int x=x0; x<x0+quartWide; x++){ + pic = scrbuf[x+55*y]; + pix = (pic >> 6)&3; write_data(paletteptr[pix]); + pix = (pic >> 4)&3; write_data(paletteptr[pix]); + pix = (pic >> 2)&3; write_data(paletteptr[pix]); + pix = pic &3; write_data(paletteptr[pix]); } } }
diff -r ba6ed3637e54 -r 0bbe8f6fae32 POKITTO_HW/HWLCD.h --- a/POKITTO_HW/HWLCD.h Wed Oct 18 14:25:12 2017 +0000 +++ b/POKITTO_HW/HWLCD.h Wed Oct 18 14:47:54 2017 +0000 @@ -51,6 +51,8 @@ extern void setBacklight(float); extern void lcdFillSurface(uint16_t); extern void lcdPixel(int16_t x, int16_t y, uint16_t c); +extern void setWindow(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2); +extern void lcdTile(int16_t x0, int16_t y0, int16_t width, int16_t height, uint16_t* gfx); extern void lcdRectangle(int16_t x, int16_t y,int16_t x2, int16_t y2, uint16_t color); extern void lcdInit(); extern void lcdSleep(); @@ -58,6 +60,7 @@ extern void lcdRefresh(uint8_t *, uint16_t*); extern void lcdRefreshAB(uint8_t *, uint16_t*); extern void lcdRefreshGB(uint8_t *, uint16_t*); +extern void lcdRefreshRegionMode1(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint8_t * scrbuf, uint16_t * paletteptr); extern void lcdRefreshMode1(uint8_t *, uint16_t*); extern void lcdRefreshMode2(uint8_t *, uint16_t*); extern void lcdRefreshMode3(uint8_t *, uint16_t*);