// display.c : sample program to display pcx, and get key input typedef unsigned short u16; // two type definitions typedef unsigned long u32; #include "keypad.h" //keypad definitions #include "ppic.h" #define REG_DISPCNT *(u32*)0x4000000 #define MODE_4 0x4 #define BG2_ENABLE 0x400 u16* paletteMem = (u16*)0x5000000; //PalMemory is 256 16 bit BGR values love an astroid is very dangerous,what if we were hit by one, OH NO" u16* videoBuffer = (u16*)0x6000000; // video memory void PlotPixel(int x,int y, unsigned short int c) { videoBuffer[(y) *120 + (x)] = (c); } #define RGB16(r,g,b) ((r)+(g<<5)+(b<<10)) int main() { char x,y; char g,c; unsigned short* Screen = (unsigned short*)0x6000000; *(unsigned long*)0x4000000 = 0x403; // mode3, bg2 on // clear screen, and draw a blue back ground for(x = 0; x<240;x++) //loop through all x { for(y = 0; y<160; y++) //loop through all y { Screen[x+y*240] = RGB16(0,0,0); } } for(x = 0; x<240;x++) //loop through all x { for(y = 0; y<160; y++) //loop through all y { Screen[x+y*240] = RGB16(1,0,0); } } for(x = 0; x<240;x++) //loop through all x { for(y = 0; y<160; y++) //loop through all y { Screen[x+y*240] = RGB16(2,0,0); } } for(x = 0; x<240;x++) //loop through all x { for(y = 0; y<160; y++) //loop through all y { Screen[x+y*240] = RGB16(3,0,0); } } for(x = 0; x<240;x++) //loop through all x { for(y = 0; y<160; y++) //loop through all y { Screen[x+y*240] = RGB16(4,0,0); } } for(x = 0; x<240;x++) //loop through all x { for(y = 0; y<160; y++) //loop through all y { Screen[x+y*240] = RGB16(5,0,0); } } for(x = 0; x<240;x++) //loop through all x { for(y = 0; y<160; y++) //loop through all y { Screen[x+y*240] = RGB16(6,0,0); } } for(x = 0; x<240;x++) //loop through all x { for(y = 0; y<160; y++) //loop through all y { Screen[x+y*240] = RGB16(7,0,0); } } for(x = 0; x<240;x++) //loop through all x { for(y = 0; y<160; y++) //loop through all y { Screen[x+y*240] = RGB16(8,0,0); } } for(x = 0; x<240;x++) //loop through all x { for(y = 0; y<160; y++) //loop through all y { Screen[x+y*240] = RGB16(9,0,0); } } for(x = 0; x<240;x++) //loop through all x { for(y = 0; y<160; y++) //loop through all y { Screen[x+y*240] = RGB16(10,0,0); } } for(x = 0; x<240;x++) //loop through all x { for(y = 0; y<160; y++) //loop through all y { Screen[x+y*240] = RGB16(11,0,0); } } for(x = 0; x<240;x++) //loop through all x { for(y = 0; y<160; y++) //loop through all y { Screen[x+y*240] = RGB16(12,0,0); } } for(x = 0; x<240;x++) //loop through all x { for(y = 0; y<160; y++) //loop through all y { Screen[x+y*240] = RGB16(16,0,0); } } while ((*KEYS) & KEY_START) { //wait } int blockX, blockY, loop; // variables REG_DISPCNT = MODE_4 | BG2_ENABLE; // switch to mode4 for(loop = 0; loop < 256; loop++) // copy palette to memory paletteMem[loop] = picPalette[loop]; blockX = 50; // give our block a start position blockY = 50; while (1) // run forever { // process input if(!((*KEYS) & KEY_UP)) // the pushed up blockY--; // subtract from y (move up) if(!((*KEYS) & KEY_DOWN)) blockY++; if(!((*KEYS) & KEY_LEFT)) blockX--; if(!((*KEYS) & KEY_RIGHT)) blockX++; // draw the picture for(y = 0; y < 160; y++) { for(x = 0; x < 120; x++) { PlotPixel(x,y,picData[y*120+x]); } } PlotPixel(blockX, blockY, (75<<8)+75); PlotPixel(blockX+1, blockY, (75<<8)+75); PlotPixel(blockX, blockY+1, (75<<8)+75); PlotPixel(blockX+1, blockY+1, (75<<8)+75); } return 0; }