#include "buffer.h" void bufDisplay(void *buffer) { memcpy(SCREEN_BASE_ADDRESS,buffer,SCREEN_BYTES_SIZE); } void bufClear(void *buffer) { if(has_colors==0) memset(buffer,0xFF,SCREEN_BYTES_SIZE); else memset(buffer,0b1111011110111111,SCREEN_BYTES_SIZE); } void bufSetPixel(void *buffer,int x,int y,int color) { if(has_colors==0) { unsigned char *p=(unsigned char*)(buffer+((x >> 1)+(y << 7)+(y << 5))); *p=(x & 1) ? ((*p & 0xF0) | color) : ((*p & 0x0F) | (color << 4)); } else { uint16_t *p=(uint16_t*)(buffer+y*640+x*2); *p=(uint16_t)color; } } void securedBufSetPixel(void *buffer,int x,int y,int color) { if(x>=0 && x<320 && y>=0 && y<240) { bufSetPixel(buffer,x,y,color); } } void bufHorizLine(void *buffer,int x,int y,int x2, int color) { int width=0,i=0; if(x>x2) invertVars(&x,&x2); if(x2>=0 && x<320 && y>=0 && y<240) { if(x<0) x=0; if(x2>319) x2=319; if(!has_colors) { if(x%2==1) { bufSetPixel(buffer,x,y,color); x+=1; } width=x2-x+1; if(width%2==1) { bufSetPixel(buffer,x2,y,color); x2-=1; } width=x2-x+1; if(width/2>0) memset(buffer+(y*320+x)/2,(color<<4)+color,width/2); } else { for(i=x;i<=x2;i++) { *(volatile unsigned short*)(buffer+i*2+y*640)=color; } } } }