14 memset(mLcd, 0x00, NXT_LCD_DEPTH*NXT_LCD_WIDTH);
\r
15 for(int i = 0; i < NUM_SPRITES; ++i)
\r
17 mSpriteList[i] = NULL;
\r
21 void Screen::update()
\r
23 memset(mLcd, 0x00, NXT_LCD_DEPTH*NXT_LCD_WIDTH);
\r
24 for(int i = 0; i < NUM_SPRITES; ++i)
\r
28 if(mSpriteList[i]->frameIsRenderable())
\r
30 renderBitmap( mLcd,
\r
31 mSpriteList[i]->getCurrentFramePtr(),
\r
32 mSpriteList[i]->getWidth(),
\r
33 mSpriteList[i]->getHeight(),
\r
34 mSpriteList[i]->getPosition().mX,
\r
35 mSpriteList[i]->getPosition().mY,
\r
36 mSpriteList[i]->getInvert(),
\r
37 mSpriteList[i]->getHFlip(),
\r
38 mSpriteList[i]->getVFlip());
\r
41 mSpriteList[i]->update();
\r
45 // Display update of NXT LCD takes 16msec according LEGO HW development kit.
\r
46 // Thus faster refresh rate(update) than 16msec does not work.
\r
47 // Actually it makes the system busy by frequest ISR requests and
\r
48 // it may cause a system crash. Then it needs to insert 20msec (> 16msec) wait.
\r
49 systick_wait_ms(20);
\r
51 display_bitmap_copy(mLcd, NXT_LCD_WIDTH, NXT_LCD_DEPTH, 0, 0);
\r
55 Sprite* Screen::newSprite(Sprite *sprite)
\r
57 for(int i = 0; i < NUM_SPRITES; ++i)
\r
59 if(mSpriteList[i] == NULL)
\r
61 mSpriteList[i] = sprite;
\r
69 void Screen::deleteSprite(Sprite *sprite)
\r
71 for(int i = 0; i < NUM_SPRITES; ++i)
\r
73 if(mSpriteList[i] == sprite)
\r
75 mSpriteList[i] = NULL;
\r
81 void Screen::renderBitmap(U8 *lcd, const CHAR *sprite, S32 width, S32 height, S32 xPos, S32 yPos, bool invert, bool hflip, bool vflip)
\r
83 int spriteByteWidth = width/8;
\r
84 int currentSpriteByte = 0;
\r
87 for (int y = 0; y < height; ++y)
\r
91 spriteRow = height - 1 - y;
\r
98 if (spriteRow + yPos < 0 || spriteRow + yPos > 63)
\r
100 currentSpriteByte += spriteByteWidth;
\r
105 for (int x = 0; x < spriteByteWidth; x++)
\r
109 spriteCol = spriteByteWidth - 1 - x;
\r
116 unsigned char workByte = sprite[currentSpriteByte++];
\r
123 int spritePixelOffset = (spriteCol * 8) + xPos;
\r
125 int lcdPixelOffset = ((spriteRow + yPos) * 100) + spritePixelOffset;
\r
126 int pixelShift = 0;
\r
127 for (int px = 0; px < 8; ++px)
\r
135 pixelShift = 7 - px;
\r
138 if (spritePixelOffset + px < 0 || spritePixelOffset + px > 99)
\r
145 int lcdBytePos = (lcdPixelOffset + px) / 8;
\r
146 int lcdBitPos = (lcdPixelOffset + px) % 8;
\r
148 if ((workByte & (1 << pixelShift)) == (1 << pixelShift))
\r
150 lcd[lcdBytePos] |= (char)(1 << lcdBitPos);
\r
158 void Screen::renderBitmap(U8 *lcd, const CHAR *file, S32 width, S32 height, S32 xPos, S32 yPos, bool invert, bool hflip, bool vflip)
\r
160 SINT bmp_line = width / 8;
\r
166 //iterate through each row of the bitmap
\r
167 for (SINT bmp_row = 0; bmp_row < height; bmp_row++)
\r
169 //if the position of any row puts it off screen, the don' render it
\r
170 if(bmp_row + yPos < 0 || bmp_row + yPos > 63)
\r
175 //setup the pixel position on the lcd to render
\r
176 SINT lcd_row = (bmp_row + yPos) / 8;
\r
177 SINT lcd_bit_pos = 7 - ((bmp_row + yPos) % 8);
\r
179 //iterate through each column
\r
180 for(SINT bmp_col = 0; bmp_col < bmp_line ; bmp_col++)
\r
182 //vflip if nevessary
\r
187 row = (height - bmp_row);
\r
190 //hflp if necessary
\r
191 SINT renderColumn = bmp_col;
\r
195 renderColumn = bmp_line - bmp_col;
\r
198 //get the byte to render
\r
199 U8 bmp_data = file[(row * bmp_line) + bmp_col];
\r
201 //invert the bits if necessary
\r
207 //get the position on the lcd to render
\r
208 SINT lcd_pos = (lcd_row * NXT_LCD_WIDTH) + ((renderColumn * 8) + xPos);
\r
210 //now iterate through each bit in the render byte
\r
211 for (SINT bmp_bit_pos = 0; bmp_bit_pos < 8; bmp_bit_pos++)
\r
214 //hflip the renderbytes bits if necessary
\r
215 U8 bitToDraw = (7 - bmp_bit_pos);
\r
219 bitToDraw = bmp_bit_pos;
\r
222 //if ever a bit is off screen, don't render it
\r
223 if((renderColumn * 8) + xPos + bitToDraw < 0 ||
\r
224 (renderColumn * 8) + xPos + bitToDraw > 99)
\r
229 //finally, render the pixel
\r
230 if (bmp_data & (0x01 << bitToDraw))
\r
232 SINT lcd_index = lcd_pos + bmp_bit_pos;
\r
233 // checks the size of render data to be stored into LCD
\r
234 if (lcd_index < NXT_LCD_DEPTH*NXT_LCD_WIDTH)
\r
236 lcd[lcd_index] |= (0x80 >> lcd_bit_pos);
\r
241 //if the bitmap pixel is clear and we're not rendering transparently,
\r
242 //clear this pixel location on the lcd
\r
245 lcd[lcd_pos + bmp_bit_pos] &= (~0x80 >> lcd_bit_pos);
\r