#include #include "screen.h" #include "charmap.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 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