#include #include "types.h" #include "tools.h" #include "screen.h" #include "charmaps.h" #include "nand.h" #include "ndlessext.h" #define SCREEN_CONTRAST_ADDR 0x900F0020 #define SCREEN_BASE_PTR 0xC0000010 #define SCREEN_MODE_ADDR 0xC000001C #define SCREEN_INT_ADDR 0xC0000020 u16* SCREEN_BASE_ADDR = 0; u16* orig_screen=0; u16* malloc_screen=0; u16 offscreen[SCREEN_WIDTH*SCREEN_HEIGHT]; //u8 offscreen[SCREEN_SIZE]; int contrast=0; u8 screen_type = SCR_320x240_565; u16 curcolor=0; u16* getScreen() { return SCREEN_BASE_ADDR; } u16* getOffScreen() { return offscreen; } void setScreen(u16* buf) { SCREEN_BASE_ADDR=buf; *(volatile unsigned*) SCREEN_BASE_PTR = buf; } u8 getScreenType() { if(has_colors) { if(nl_ndless_rev() >= 2004) { // Ndless 4.2+ if(lcd_type()==SCR_240x320_565) return SCR_240x320_565; } else { // Ndless < 4.2 char f=0; ext_read_nand(&f, 1, MANUF_CR4_OFFSET, 0, 0, 0); if(f==1) return SCR_240x320_565; } } return SCR_320x240_565; } void initScreen() { screen_type=getScreenType(); setCurColorRGB(0,0,0); SCREEN_BASE_ADDR =*(u16**)SCREEN_BASE_PTR; orig_screen = SCREEN_BASE_ADDR; contrast=*(volatile unsigned*) SCREEN_CONTRAST_ADDR; } u8 off_mode=0; unsigned int setContrast(unsigned int level) { unsigned int lowlevel = level &0b11111111; if(lowlevel>CONTRAST_MAX) lowlevel=CONTRAST_MAX; if(lowlevel>3; r=(val&0b1111100000000000)>>8; *ptr=rgb2gs(r,g,b); ptr++; } } void convertRGB565320to240(u16* buffer) { u16 i,j; u16* ptr=buffer; u16* tmpbuffer=malloc(SCREEN_SIZE); u16 val; for(j=0;j0) { for (i=0;i= SCREEN_WIDTH-CHAR_WIDTH) { if(ret) { x = 0; y += CHAR_HEIGHT; } else stop=1; } } } void dispBufImgRGB(u16* buf, int16_t xoff, int16_t yoff, u8* img, u16 width, u16 height,u8 border) { u16 dwidth=width, dheight=height; u16 data_x=0, data_y=0; u16 x = 0, y = 0; float i, j; if(xoff < 0){ dwidth = dwidth + xoff; data_x = (int)(-xoff); xoff = 0; } if(yoff < 0){ dheight = dheight + yoff; data_y = (int)(-yoff); yoff = 0; } u8 r,g,b; for(i=0, x=0; (int)i < dwidth && x < SCREEN_WIDTH; i+= 1, x++) for(j=0, y=0; (int)j < dheight && y < SCREEN_HEIGHT; j+= 1, y++) { b=img[(((int)j+data_y)*width+(int)i+data_x)*3]; g=img[(((int)j+data_y)*width+(int)i+data_x)*3+1]; r=img[(((int)j+data_y)*width+(int)i+data_x)*3+2]; if(!border || b!=0 || g!=0 || r!=0) setPixelRGB(xoff + x, yoff + dheight-1-y, r, g, b); } } void clrBuf(u16* buf) { if(has_colors || malloc_screen) clrBufBox(offscreen,0,0,SCREEN_WIDTH,SCREEN_HEIGHT); else memset(SCREEN_BASE_ADDR,0,SCREEN_PIXELS/2); } void clrBufBox(u16* buf, u16 x, u16 y, u16 w, u16 h) { u16 color=~curcolor; u16 i,j; for(j=0;j