/* demonstrate graphics LCD access functions */ #include "ks0108.h" // upper limit of the stack, which grows down from here. // Note that virtual byte-address 0x1400 is shown as // word-address 0x0500 in the MipsRAM editor. // #define STACKBASE 0x00001400 // a suitable address to store heap and static data. // Shown at word-address 0x0800 in the MipsRAM editor. // #define BASE 0x00002000 /* convert an integer to a four-digit hex-format string. */ char* atox( int i ) { char* cp = (char*) (BASE+16); int tmp; tmp = (i & 0xf000) >> 12; *cp++ = (tmp > 9) ? (tmp - 10 + 'A') : (tmp + '0'); tmp = (i & 0x0f00) >> 8; *cp++ = (tmp > 9) ? (tmp - 10 + 'A') : (tmp + '0'); tmp = (i & 0x00f0) >> 4; *cp++ = (tmp > 9) ? (tmp - 10 + 'A') : (tmp + '0'); tmp = (i & 0x000f) >> 0; *cp++ = (tmp > 9) ? (tmp - 10 + 'A') : (tmp + '0'); return (char*) (BASE+16); // *cp++ = ((i & 0xf000) >> 12) + '0'; // *cp++ = ((i & 0x0f00) >> 8) + '0'; // *cp++ = ((i & 0x00f0) >> 4) + '0'; // *cp++ = ((i & 0x000f) >> 0) + '0'; // return (char*) 0x0000a000; } int main( int argc, char** argv ) { int i; int *ptr; char *cptr; // write some indication that the program started to the memory, // then activate the LC display controller. // ptr = (int*) BASE; *ptr = 0xcccc0000; enableDisplay( 1 ); // select black (active pixel) color for drawing // *(ptr-1) = 0xcccc0001; setColor( 1 ); // and activate a few pixels in the first (left) half of the LCD // *(ptr-2) = 0xcccc0002; setPixel( 0, 0 ); setPixel( 1, 1 ); setPixel( 0, 63 ); setPixel( 62, 62 ); setPixel( 63, 7 ); // a few pixels in the second (right) half of the LCD // *(ptr-3) = 0xcccc0003; setPixel( 125, 1 ); setPixel( 126, 0 ); setPixel( 127, 31 ); setPixel( 127, 63 ); // a diagonal line built from setPixel() operations // *(ptr-4) = 0xcccc0004; for( i=0; i < 64; i++ ) { setPixel( i, i ); } for( i=64; i < 128; i++ ) { setPixel( i, 128-i-1 ); } // a welcome message // *(ptr-5) = 0xcccc0005; setTextPos( 0, 0 ); text( " Welcome to the (Tiny)MIPS" ); // some more text // *(ptr-6) = 0xcccc0006; setTextPos( 0, 1 ); text( " and the KS0108 display." ); // endless loop // *(ptr-7) = 0xffff0007; for( i=0; ; i++ ) { *(ptr+1) = 0xbabe0000 + i; setTextPos( 2, 7 ); cptr = atox( i ); text( cptr ); } }