#define NUMPIXELS 128 #define NUMROWS 8 #define NUMCOLUMNS 8 #define RGB_BLACK 0 #define RGB_BLUE 1 #define RGB_GREEN 2 #define RGB_CYAN 3 #define RGB_RED 4 #define RGB_MAGENTA 5 #define RGB_BROWN 6 #define RGB_LIGHTGRAY 7 #define RGB_DARKGRAY 8 #define RGB_YELLOW 14 #define RGB_WHITE 15 #include "./NPLib2x64.c" #include #include #include #include #include // API // void initialise(NUMPIXELS); // void show(void); // void setPixelTypeRGB(void); // void setPixelTypeGRB(void); // void setPixel(int pixelNumber, unsigned char R, unsigned char G, unsigned char B); // void setPixelRC(int row, int column, unsigned char R, unsigned char G, unsigned char B); // void clearPixel(int pixelNumber); // void clearbuffer(NUMPIXELS); // compile for RC2014 (CPM) using Z88dk : // zcc +cpm -vn sprites2.c -create-app -o sprites2.bin unsigned char spriteSpace[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; unsigned char spriteExclamation[] = { 0x30, 0x30, 0x30, 0x30, 0x30, 0x00, 0x30, 0x30 }; unsigned char spriteQuotation[] = { 0x66, 0x66, 0x66, 0x44, 0x88, 0x00, 0x00, 0x00 }; unsigned char spriteHash[] = { 0x24, 0x24, 0xFE, 0x24, 0x48, 0xFE, 0x48, 0x48 }; unsigned char spriteDollar[] = { 0x10, 0x7C, 0xD6, 0x70, 0x18, 0xD6, 0x7C, 0x10 }; unsigned char spritePercent[] = { 0x46, 0xAC, 0x48, 0x18, 0x30, 0x24, 0x6A, 0xC4 }; unsigned char spriteAnd[] = { 0x20, 0x50, 0x20, 0x50, 0x89, 0x8A, 0x44, 0x3A }; unsigned char spriteApostroph[] = { 0x30, 0x30, 0x30, 0x20, 0x40, 0x00, 0x00, 0x00 }; unsigned char spriteLeftRoundBracket[] = { 0x18, 0x30, 0x60, 0x60, 0x60, 0x60, 0x30, 0x18 }; unsigned char spriteRightRoundBracket[] = { 0x30, 0x18, 0x0C, 0x0C, 0x0C, 0x0C, 0x18, 0x30 }; unsigned char spriteStar[] = { 0x00, 0x92, 0x54, 0x38, 0xEE, 0x38, 0x54, 0x92 }; unsigned char spritePlus[] = { 0x00, 0x00, 0x10, 0x10, 0x7C, 0x10, 0x10, 0x00 }; unsigned char spriteComma[] = { 0x00, 0x00, 0x00, 0x30, 0x30, 0x30, 0x20, 0x40 }; unsigned char spriteMinus[] = { 0x00, 0x00, 0x00, 0x00, 0x7C, 0x00, 0x00, 0x00 }; unsigned char spriteDot[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x60 }; unsigned char spriteSlash[] = { 0x06, 0x0C, 0x08, 0x18, 0x30, 0x20, 0x60, 0xC0 }; unsigned char sprite0[] = { 0x38, 0x44, 0xD6, 0xD6, 0xD6, 0xD6, 0x44, 0x38 }; unsigned char sprite1[] = { 0x18, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7E }; unsigned char sprite2[] = { 0x7C, 0xC6, 0x06, 0x0C, 0x78, 0xC0, 0xC0, 0xFE }; unsigned char sprite3[] = { 0x7C, 0xC6, 0x06, 0x1C, 0x1C, 0x06, 0xC6, 0x7C }; unsigned char sprite4[] = { 0x2C, 0x6C, 0x6C, 0xCC, 0xCC, 0xFE, 0x0C, 0x0C }; unsigned char sprite5[] = { 0x7E, 0x60, 0x60, 0x3C, 0x06, 0x06, 0xC6, 0x7C }; unsigned char sprite6[] = { 0x7C, 0xC6, 0xC0, 0x7C, 0xC6, 0xC6, 0xC6, 0x7C }; unsigned char sprite7[] = { 0xFE, 0xC6, 0x06, 0x0C, 0x18, 0x30, 0x30, 0x30 }; unsigned char sprite8[] = { 0x7C, 0xC6, 0xC6, 0x7C, 0xC6, 0xC6, 0xC6, 0x7C }; unsigned char sprite9[] = { 0x7C, 0xC6, 0xC6, 0xC6, 0x7C, 0x06, 0xC6, 0x7C }; unsigned char spriteDoubleDot[] = { 0x00, 0x00, 0x18, 0x18, 0x00, 0x18, 0x18, 0x00 }; unsigned char spriteSemicolon[] = { 0x00, 0x30, 0x30, 0x00, 0x30, 0x30, 0x20, 0x40 }; unsigned char spriteLessThan[] = { 0x08, 0x10, 0x20, 0x40, 0x40, 0x20, 0x10, 0x08 }; unsigned char spriteEuals[] = { 0x00, 0x00, 0x7C, 0x00, 0x00, 0x7C, 0x00, 0x00 }; unsigned char spriteGreaterThan[] = { 0x20, 0x10, 0x08, 0x04, 0x04, 0x08, 0x10, 0x20 }; unsigned char spriteQuestion[] = { 0x7C, 0xC6, 0x06, 0x0C, 0x30, 0x00, 0x30, 0x30 }; unsigned char spriteAtSign[] = { 0x3C, 0x42, 0x9A, 0xAA, 0xAA, 0x94, 0x80, 0x7C }; unsigned char spriteA[] = { 0x7C, 0xC6, 0xC6, 0xC6, 0xFE, 0xC6, 0xC6, 0xC6 }; unsigned char spriteB[] = { 0xF8, 0xC4, 0xC6, 0xFC, 0xC6, 0xC6, 0xC4, 0xF8 }; unsigned char spriteC[] = { 0x7C, 0xC6, 0xC0, 0xC0, 0xC0, 0xC0, 0xC6, 0x7C }; unsigned char spriteD[] = { 0xF8, 0xC4, 0xC6, 0xC6, 0xC6, 0xC6, 0xC4, 0xF8 }; unsigned char spriteE[] = { 0xFE, 0xC0, 0xC0, 0xFC, 0xC0, 0xC0, 0xC0, 0xFE }; unsigned char spriteF[] = { 0xFE, 0xC0, 0xC0, 0xF8, 0xC0, 0xC0, 0xC0, 0xC0 }; unsigned char spriteG[] = { 0x7C, 0xC6, 0xC0, 0xC0, 0xDC, 0xC6, 0xC6, 0x7C }; unsigned char spriteH[] = { 0xC6, 0xC6, 0xC6, 0xFE, 0xC6, 0xC6, 0xC6, 0xC6 }; unsigned char spriteI[] = { 0x7E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7E }; unsigned char spriteJ[] = { 0xFE, 0x06, 0x06, 0x06, 0x06, 0x86, 0xC6, 0x7C }; unsigned char spriteK[] = { 0xC6, 0xC4, 0xCC, 0xD8, 0xF8, 0xCC, 0xC6, 0xC6 }; unsigned char spriteL[] = { 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xFE }; unsigned char spriteM[] = { 0xC6, 0xEE, 0xD6, 0xD6, 0xD6, 0xC6, 0xC6, 0xC6 }; unsigned char spriteN[] = { 0xC6, 0xE6, 0xD6, 0xD6, 0xD6, 0xD6, 0xCE, 0xC6 }; unsigned char spriteO[] = { 0x38, 0x44, 0xC6, 0xC6, 0xC6, 0xC6, 0x44, 0x38 }; unsigned char spriteP[] = { 0xFC, 0xC6, 0xC6, 0xC6, 0xFC, 0xC0, 0xC0, 0xC0 }; unsigned char spriteQ[] = { 0x38, 0x44, 0xC6, 0xC6, 0xC6, 0xD6, 0x4C, 0x3A }; unsigned char spriteR[] = { 0xFC, 0xC6, 0xC6, 0xC6, 0xFC, 0xD0, 0xC8, 0xC6 }; unsigned char spriteS[] = { 0x7C, 0xC6, 0x60, 0x30, 0x08, 0x0C, 0xC6, 0x7C }; unsigned char spriteT[] = { 0x7E, 0xD8, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3C }; unsigned char spriteU[] = { 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0x44, 0x38 }; unsigned char spriteV[] = { 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0x44, 0x28, 0x10 }; unsigned char spriteW[] = { 0xC6, 0xC6, 0xC6, 0xC6, 0x82, 0x92, 0x54, 0x28 }; unsigned char spriteX[] = { 0x82, 0xC6, 0x28, 0x10, 0x28, 0x44, 0xC6, 0x82 }; unsigned char spriteY[] = { 0x82, 0xC6, 0x6C, 0x28, 0x10, 0x10, 0x10, 0x10 }; unsigned char spriteZ[] = { 0x7E, 0x8C, 0x18, 0x30, 0x30, 0x60, 0xC6, 0xFC }; unsigned char spriteLeftSquareBracket[] = { 0x3C, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x3C }; unsigned char spriteBackSlash[] = { 0xC0, 0x60, 0x20, 0x30, 0x18, 0x08, 0x0C, 0x06 }; unsigned char spriteRightSquareBracket[] = { 0x78, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x78 }; unsigned char sprite5E[] = { 0x08, 0x14, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00 }; /* 0x5E is ^ */ unsigned char spriteUnderscore[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E }; unsigned char spriteBackApostroph[] = { 0x60, 0x60, 0x60, 0x20, 0x10, 0x00, 0x00, 0x00 }; unsigned char spriteHearth[] = { 0x44, 0xEE, 0xFE, 0xFE, 0xFE, 0x7C, 0x38, 0x10 }; unsigned char spriteCreature1[] = { 0x42, 0x24, 0x7E, 0xDB, 0xFF, 0xBD, 0x24, 0x42 }; unsigned char spriteCreature2[] = { 0x99, 0xBD, 0xDB, 0x7E, 0x24, 0x3C, 0x24, 0x24 }; unsigned char spriteTest1[] = { 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55 }; unsigned char spriteTest2[] = { 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA }; // prototypes void writeSprite1(unsigned char* sprite, unsigned char R, unsigned char G, unsigned char B); void writeSprite2(unsigned char* sprite, unsigned char R, unsigned char G, unsigned char B); void smallDelay(); void delay(); void palette(int n, uint8_t *R, uint8_t *G, uint8_t *B); int main() { uint8_t R, G, B; char command; // always initialise NUMPIXELS initialise(NUMPIXELS); while (true) { printf("\nEnter command:\n"); printf("=====================================\n"); printf("[0-7] Play with pixels\n"); printf("[R] Run demo\n"); printf("=====================================\n"); do { if(kbhit()) { command = getch(); // eat it if ((command >= '0') && (command <= 'z')) { break; } } } while (true); switch (command) { case '0': palette(RGB_MAGENTA,&R,&G,&B); setPixelRC(0, 0, R, G, B); break; case '1': palette(RGB_BLUE,&R,&G,&B); setPixelRC(1, 1, R, G, B); break; case '2': palette(RGB_RED,&R,&G,&B); setPixelRC(2, 2, R, G, B); break; case '3': palette(RGB_RED,&R,&G,&B); setPixelRC(8, 8, R, G, B); break; case '4': palette(RGB_MAGENTA,&R,&G,&B); setPixelRC(9, 9, R, G, B); break; case '5': palette(RGB_BLUE,&R,&G,&B); setPixelRC(10, 10, R, G, B); break; case '6': palette(RGB_RED,&R,&G,&B); writeSprite1((unsigned char*) &spriteR, R, G, B); break; case '7': palette(RGB_RED,&R,&G,&B); writeSprite2((unsigned char*) &spriteC, R, G, B); break; case 'R': case 'r': goto x; } } x: for (int i = 0; i < 10000; i++) { palette(RGB_MAGENTA,&R,&G,&B); writeSprite1((unsigned char*) &spriteCreature1, R, G, B); palette(RGB_CYAN,&R,&G,&B); writeSprite2((unsigned char*) &spriteHash, R, G, B); show(); delay(); //================================================================== palette(RGB_BLUE,&R,&G,&B); writeSprite1((unsigned char*) &spriteR, R, G, B); writeSprite2((unsigned char*) &spriteC, R, G, B); show(); delay(); //================================================================== palette(RGB_GREEN,&R,&G,&B); writeSprite1((unsigned char*) &sprite2, R, G, B); palette(RGB_YELLOW,&R,&G,&B); writeSprite2((unsigned char*) &sprite0, R, G, B); show(); delay(); //================================================================== palette(RGB_YELLOW,&R,&G,&B); writeSprite1((unsigned char*) &sprite1, R, G, B); palette(RGB_GREEN,&R,&G,&B); writeSprite2((unsigned char*) &sprite4, R, G, B); show(); delay(); //================================================================== palette(RGB_RED,&R,&G,&B); writeSprite1((unsigned char*) &spriteHearth, R, G, B); palette(RGB_CYAN,&R,&G,&B); writeSprite2((unsigned char*) &spriteCreature2, R, G, B); show(); delay(); if(kbhit()) { char ch = getch(); // eat it break; } } return 0; } /* * Write a sprite to 1.st matrix * * Sprite is the pointer to a byte array, encoding the contains of the sprite */ void writeSprite1(unsigned char* sprite, unsigned char R, unsigned char G, unsigned char B) { for (int row = 0; row < 8; row++) { unsigned char value = sprite[row]; unsigned char mask = 128; // bin 10000000 for (int column = 0; column < 8; column++) { if (value & mask) // pixel is not 0 { setPixelRC(row, column, R, G, B); } else { setPixelRC(row, column, 0, 0, 0); } mask >>= 1; } } } /* * Write a sprite to 2.nd matrix * * Sprite is the pointer to a byte array, encoding the contains of the sprite */ void writeSprite2(unsigned char* sprite, unsigned char R, unsigned char G, unsigned char B) { for (int row = 0; row < 8; row++) { unsigned char value = sprite[row]; unsigned char mask = 128; // bin 10000000 for (int column = 8; column < 16; column++) { if (value & mask) // pixel is not 0 { setPixelRC(row, column, R, G, B); } else { setPixelRC(row, column, 0, 0, 0); } mask >>= 1; } } } void smallDelay() { for (int i = 0; i < 1000; i++) { ; } } void delay() { for (int i = 0; i < 50; i++) { smallDelay(); } } void palette(int n, uint8_t *R, uint8_t *G, uint8_t *B ) { switch(n) { case RGB_BLUE: *R = 0; *G = 0; *B = 32; break; case RGB_GREEN: *R = 0; *G = 32; *B = 0; break; case RGB_CYAN: *R = 0; *G = 32; *B = 32; break; case RGB_RED: *R = 32; *G = 0; *B = 0; break; case RGB_MAGENTA: *R = 32; *G = 0; *B = 32; break; case RGB_BROWN: *R = 32; *G = 16; *B = 0; break; case RGB_LIGHTGRAY: *R = 16; *G = 16; *B = 16; break; case RGB_DARKGRAY: *R = 8; *G = 8; *B = 8; break; case RGB_YELLOW: *R = 32; *G = 32; *B = 0; break; case RGB_WHITE: *R = 32; *G = 32; *B = 32; break; default: *R = 0; *G = 0; *B = 0; break; } }