#include #include "screen.h" #include "charmaps.h" #include "tools.h" #include "nand.h" #define SCREEN_CONTRAST_ADDR 0x900F0020 #define SCREEN_BASE_PTR 0xC0000010 #define SCREEN_MODE_ADDR 0xC000001C #define SCREEN_INT_ADDR 0xC0000020 uint16_t* SCREEN_BASE_ADDR = 0; uint16_t* orig_screen=0; uint16_t* malloc_screen=0; int contrast=0; uint8_t screen_type = SCR_320x240_565; uint16_t curcolor=0; uint16_t* getScreen() { return SCREEN_BASE_ADDR; } void setScreen(uint16_t* buf) { SCREEN_BASE_ADDR=buf; *(volatile unsigned*) SCREEN_BASE_PTR = buf; } uint8_t 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; bc_read_nand(&f, 1, 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 =*(uint16_t**)SCREEN_BASE_PTR; orig_screen = SCREEN_BASE_ADDR; contrast=*(volatile unsigned*) SCREEN_CONTRAST_ADDR; } uint8_t 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(uint16_t* buffer) { uint16_t i,j; uint16_t* ptr=buffer; uint16_t* tmpbuffer=malloc(SCREEN_SIZE); uint16_t val; for(j=0;j= SCREEN_WIDTH-CHAR_WIDTH) { if(ret) { x = 0; y += CHAR_HEIGHT; } else stop=1; } } } void dispBufImgRGB(uint16_t* buf, int16_t xoff, int16_t yoff, uint8_t* img, uint16_t width, uint16_t height,uint8_t border) { uint16_t dwidth=width, dheight=height; uint16_t data_x=0, data_y=0; uint16_t 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; } uint8_t 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) setBufPixelRGB(buf, xoff + x, yoff + dheight-1-y, r, g, b); } } void clrBuf(uint16_t* buf) { if(has_colors || malloc_screen) clrBufBox(buf,0,0,SCREEN_WIDTH,SCREEN_HEIGHT); else memset(SCREEN_BASE_ADDR,0,SCREEN_PIXELS/2); } void clrBufBox(uint16_t* buf, uint16_t x, uint16_t y, uint16_t w, uint16_t h) { uint16_t color=~curcolor; uint16_t i,j; for(j=0;j