21 #define IS_FLAGREAD(n) ( FlagRead[n>>3] & (1<<(n&7)) )
22 #define SET_FLAGREAD(n) { FlagRead[n>>3] |= (1<<(n&7)); }
23 #define IS_FLAGWRITTEN(n) ( FlagWritten[n>>3] & (1<<(n&7)) )
24 #define SET_FLAGWRITTEN(n) { FlagWritten[n>>3] |= (1<<(n&7)); }
25 #define DMA2D_START_TRANSFER() {DMA2D_StartTransfer(); fTransfering = TRUE;}
28 __attribute__( ( section(
".sdram" ) ) )
31 __attribute__( ( section( ".sdram" ) ) )
34 __attribute__( ( section( ".sdram" ) ) )
35 unsigned char FlagWritten [( PHYS_SCREEN_HEIGHT* PHYS_SCREEN_WIDTH ) / 8];
37 __attribute__( ( section( ".sdram" ) ) )
38 unsigned char FlagRead [( PHYS_SCREEN_HEIGHT* PHYS_SCREEN_WIDTH ) / 8];
40 unsigned char* pFreeObjectMem = ObjectSingleMemoryPool;
42 unsigned AvailableObjectMemory = OBJECT_SINGLE_MEMORY_POOL_SIZE;
47 int DisplayedScreen = 0;
48 int AddressedScreen = 0;
49 int fTransfering = FALSE;
52 t_DMALCD_ModeLCDAccess DMALCD_ModeLCDAccess = LCD_Only;
60 int fNeutralX(
int x,
int y ) {
return x; }
61 int fNeutralY(
int x,
int y ) {
return y; }
62 tTrans CurrentTransformation = { fNeutralX, fNeutralY, 0};
66 DMA2D_InitTypeDef DMA2D_InitStruct;
67 DMA2D_FG_InitTypeDef DMA2D_FG_InitStruct;
68 DMA2D_BG_InitTypeDef DMA2D_BG_InitStruct;
76 NODEBUG
int fRot270X(
int x,
int y ) {
return pCurrentSrcObj->
mWidthUsed - y - 1; }
77 NODEBUG
int fRot270Y(
int x,
int y ) {
return x; }
78 NODEBUG
int fRot180X(
int x,
int y ) {
return pCurrentSrcObj->
mWidthUsed - x - 1; }
79 NODEBUG
int fRot180Y(
int x,
int y ) {
return pCurrentSrcObj->
mHeightUsed - y - 1; }
80 NODEBUG
int fRot90X(
int x,
int y ) {
return y; }
81 NODEBUG
int fRot90Y(
int x,
int y ) {
return pCurrentSrcObj->
mHeightUsed - x - 1; }
83 NODEBUG
void DMA2D_WaitForEndOfTransfer()
88 while ( DMA2D_GetFlagStatus( DMA2D_FLAG_TC ) == RESET );
104 NODEBUG
void ResetScreenApp(
void )
108 pFreeObjectMem = ObjectSingleMemoryPool;
115 memset( (
void* ) & ( LCD_ScreenImage[i] ), 0,
sizeof( LCD_ScreenImage[i] ) );
120 memset( (
void* ) & ( ObjectSingleMemoryPool ), 0,
sizeof( ObjectSingleMemoryPool ) );
142 NODEBUG
static int RotateIndex(
int old_orientation,
int new_orientation,
int k )
144 int H = PHYS_SCREEN_HEIGHT;
145 int W = PHYS_SCREEN_WIDTH;
147 old_orientation %= 4;
148 new_orientation %= 4;
149 if ( old_orientation == new_orientation )
152 else if ( ( old_orientation & 1 ) == ( new_orientation & 1 ) )
153 return ( H * W - 1 - k );
155 if ( old_orientation & 1 )
158 W = PHYS_SCREEN_HEIGHT;
159 H = PHYS_SCREEN_WIDTH;
163 if ( ( 4 + new_orientation - old_orientation ) % 4 == 1 )
164 return ( k / W ) + H * ( W - ( k % W ) - 1 );
166 return ( H - 1 - ( k / W ) ) + H * ( k % W );
188 NODEBUG
void DMA2D_CopyBMP(
int scr,
tDMA2D_pObject obj,
int blendingmode )
190 int x = obj->
mX[scr];
191 int y = obj->
mY[scr];
199 unsigned fg_offset = 0;
232 DMA2D_InitStruct.DMA2D_OutputGreen = 0;
233 DMA2D_InitStruct.DMA2D_OutputBlue = 0;
234 DMA2D_InitStruct.DMA2D_OutputRed = 0;
235 DMA2D_InitStruct.DMA2D_OutputAlpha = 0;
238 switch ( CurrentScreenOrientation )
243 if ( ( x >= PHYS_SCREEN_WIDTH ) || ( ( x + pixelperline ) <= 0 ) )
246 if ( ( y >= PHYS_SCREEN_HEIGHT ) || ( ( y + numberofline ) <= 0 ) )
251 if ( pixelperline > ( PHYS_SCREEN_WIDTH - x ) )
253 fg_offset += pixelperline - ( PHYS_SCREEN_WIDTH - x );
254 pixelperline = ( PHYS_SCREEN_WIDTH - x );
267 if ( numberofline > ( PHYS_SCREEN_HEIGHT - y ) )
269 numberofline = ( PHYS_SCREEN_HEIGHT - y );
277 DMA2D_InitStruct.DMA2D_OutputOffset = PHYS_SCREEN_WIDTH - pixelperline;
279 DMA2D_InitStruct.DMA2D_OutputMemoryAdd = ( uint32_t ) & ( LCD_ScreenImage[DisplayedScreen].mScreenImage.mVerView[y][x] );
286 if ( ( x >= PHYS_SCREEN_HEIGHT ) || ( ( x + pixelperline ) <= 0 ) )
289 if ( ( y >= PHYS_SCREEN_WIDTH ) || ( ( y + numberofline ) <= 0 ) )
292 if ( pixelperline > ( PHYS_SCREEN_HEIGHT - x ) )
294 fg_offset += pixelperline - ( PHYS_SCREEN_HEIGHT - x );
295 pixelperline = ( PHYS_SCREEN_HEIGHT - x );
307 if ( numberofline > ( PHYS_SCREEN_WIDTH - y ) )
309 numberofline = ( PHYS_SCREEN_WIDTH - y );
319 DMA2D_InitStruct.DMA2D_OutputOffset = PHYS_SCREEN_HEIGHT - pixelperline;
321 DMA2D_InitStruct.DMA2D_OutputMemoryAdd = ( uint32_t ) & ( LCD_ScreenImage[DisplayedScreen].mScreenImage.mHorView[y][x] );
330 RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_DMA2D, ENABLE );
331 DMA2D_DeadTimeConfig( 255, 1 );
333 #if TEST_BEFORE_TRANSFER
334 DMA2D_WaitForEndOfTransfer();
337 DMA2D_ClearFlag( DMA2D_FLAG_CE | DMA2D_FLAG_CTC | DMA2D_FLAG_CAE | DMA2D_FLAG_TW | DMA2D_FLAG_TC | DMA2D_FLAG_TE );
340 DMA2D_InitStruct.DMA2D_NumberOfLine = numberofline;
343 DMA2D_InitStruct.DMA2D_PixelPerLine = pixelperline;
346 DMA2D_InitStruct.DMA2D_CMode = CM_RGB888;
351 DMA2D_InitStruct.DMA2D_Mode = DMA2D_M2M_BLEND;
354 DMA2D_BG_StructInit( &DMA2D_BG_InitStruct );
357 DMA2D_BG_InitStruct.DMA2D_BGMA = DMA2D_InitStruct.DMA2D_OutputMemoryAdd;
360 DMA2D_BG_InitStruct.DMA2D_BGCM = CM_RGB888;
361 DMA2D_BG_InitStruct.DMA2D_BGO = DMA2D_InitStruct.DMA2D_OutputOffset;
362 DMA2D_BG_InitStruct.DMA2D_BGPFC_ALPHA_VALUE = 0xFF;
365 DMA2D_BGConfig( &DMA2D_BG_InitStruct );
370 DMA2D_InitStruct.DMA2D_Mode = DMA2D_M2M_PFC;
374 DMA2D_FG_StructInit( &DMA2D_FG_InitStruct );
378 DMA2D_InitStruct.DMA2D_Mode = DMA2D_R2M;
380 DMA2D_InitStruct.DMA2D_CMode = CM_RGB888;
383 DMA2D_InitStruct.DMA2D_OutputGreen = ( obj->
mData.
mARGB_Cst >> 8 ) & 0xff;
384 DMA2D_InitStruct.DMA2D_OutputRed = ( obj->
mData.
mARGB_Cst >> 16 ) & 0xff;
389 DMA2D_FG_InitStruct.DMA2D_FGMA = ( ( u32 )pdata + pixelsize * data_offset );
391 DMA2D_FG_InitStruct.DMA2D_FGCM = format;
392 DMA2D_FG_InitStruct.DMA2D_FGO = fg_offset ;
393 DMA2D_FG_InitStruct.DMA2D_FGPFC_ALPHA_VALUE = obj->
mStatus.
mAlpha;
394 DMA2D_FG_InitStruct.DMA2D_FGPFC_ALPHA_MODE = 2;
401 DMA2D_FG_InitStruct.DMA2D_FG_CLUT_CM = CLUT_CM_ARGB8888 ;
402 DMA2D_FG_InitStruct.DMA2D_FGPFC_ALPHA_MODE = 1;
406 DMA2D_FGConfig( &DMA2D_FG_InitStruct );
410 u32* ptrdest = ( u32* )( DMA2D_BASE + 0x400 );
413 #if 0 //FL1308: Unable to make automatic load working properly???
414 DMA2D_FGStart( ENABLE );
415 while ( DMA2D_GetFlagStatus( DMA2D_FLAG_CTC ) == RESET );
416 #else //but manual loading is fine!
419 *ptrdest++ = *ptrsrc++;
426 DMA2D_Init( &DMA2D_InitStruct );
430 DMA2D_START_TRANSFER();
431 #if TEST_AFTER_TRANSFER
432 DMA2D_WaitForEndOfTransfer();
467 DMA_LCD_UpdateScreen();
599 memset( (
void* ) & ( ObjectSingleMemoryPool ), 0,
sizeof( ObjectSingleMemoryPool ) );
645 if ( ( screen >= 0 ) && ( screen < MAX_DMA2D_SCREEN ) )
729 DMA2D_CopyBMP( screen, obj, ( i != 0 ) );
736 DMA2D_CopyBMP( screen, obj, ( i != 0 ) );
743 DMA2D_CopyBMP( screen, obj, ( i != 0 ) );
754 DMA2D_CopyBMP( screen, obj, 1 );
764 DMA2D_CopyBMP( screen, obj, ( i != 0 ) );
771 Xmax = PHYS_SCREEN_WIDTH - 1;
773 Ymax = PHYS_SCREEN_HEIGHT - 1;
814 val32 = pval24[0] | ( pval24[1] << 8 ) | ( pval24[2] << 16 );
815 return val32 | 0xff000000;
819 val32 = ( ( val16 & 0x1F ) << ( 0 + 3 ) ) | ( ( ( val16 >> 5 ) & 0x3F ) << ( 8 + 2 ) ) | ( ( ( val16 >> 11 ) & 0x1F ) << ( 16 + 3 ) ) ;
820 return val32 | 0xff000000;
824 val32 = ( ( val16 & 0x1F ) << ( 0 + 3 ) ) | ( ( ( val16 >> 5 ) & 0x1F ) << ( 8 + 3 ) ) | ( ( ( val16 >> 10 ) & 0x1F ) << ( 16 + 3 ) ) ;
825 return val32 | ( ( val16 & 0x8000 ) ? 0xff000000 : 0 );
829 val32 = ( ( val16 & 0x0F ) << ( 0 + 4 ) ) | ( ( ( val16 >> 4 ) & 0x0F ) << ( 8 + 4 ) ) | ( ( ( val16 >> 8 ) & 0x0F ) << ( 16 + 4 ) ) ;
830 return val32 | ( ( val16 & 0xF000 ) << 16 );
869 int x1 = obj1->
mX[scrn];
870 int y1 = obj1->
mY[scrn];
873 int x2 = obj2->
mX[scrn];
874 int y2 = obj2->
mY[scrn];
878 int x, y, height, width;
884 if ( ( x1 + width1 ) <= x2 )
889 width = MIN( width2, ( x1 + width1 - x2 ) );
894 if ( ( x2 + width2 ) <= x1 )
899 width = MIN( width1, ( x2 + width2 - x1 ) );
904 if ( ( y1 + height1 ) <= y2 )
909 height = MIN( height2, ( y1 + height1 - y2 ) );
914 if ( ( y2 + height2 ) <= y1 )
919 height = MIN( height1, ( y2 + height2 - y1 ) );
923 #ifdef TIMING_ANALYSIS // to debug with a scope
928 for ( i = 0; i < width ; i++ )
930 for ( j = 0; ( j < height ) && ( !val32 ) ; j++ )
937 inter = MIN( ( pixel1 >> 24 ), ( pixel2 >> 24 ) );
942 #ifdef TIMING_ANALYSIS // to debug with a scope
967 if ( ( dest >= MAX_DMA2D_SCREEN ) || ( dest >= MAX_DMA2D_SCREEN ) )
1022 size = ( max_width * max_height ) * 4 +
sizeof(
tDMA2D_Object );
1024 if ( size > AvailableObjectMemory )
1033 AvailableObjectMemory -= size;
1034 pFreeObjectMem += size;
1053 TailObj->mNextObject = pObj;
1063 for ( i = 0 ; i < ( max_width * max_height ) ; i++ )
1064 ptr[i] = 0xff000000;
1112 obj->
mX[screen] = 0;
1113 obj->
mY[screen] = 0;
1139 u16* iptr = pbitmap;
1141 if ( fbitmap0constant1 == 1 )
1152 if ( *iptr == 0xffff )
1156 if ( ( iptr [0] != 0x4D42 ) || ( iptr[3] != 0 ) )
1415 int objx, objy, width, height;
1418 for ( i = 0 ; i < count ; i++ )
1425 objx = obj->
mX[screen];
1426 objy = obj->
mY[screen];
1477 return ( obj->
mY[screen] << 16 ) | (
unsigned short ) obj->
mX[screen];
1519 for ( i = 0 ; i < N; i++ )
1523 if ( i != ( N - 1 ) )
1557 for ( i = 0 ; i < N; i++ )
1595 for ( i = 0 ; i < N; i++ )
1599 for ( ; i < ( N - 1 ) ; i++ )
1631 for ( i = 0 ; i < N; i++ )
1635 for ( ; i < ( N - 1 ) ; i++ )
1667 if ( ( old_orientation & 3 ) != ( new_orientation & 3 ) )
1669 memset( FlagRead, 0,
sizeof( FlagRead ) );
1670 for ( i = 0 ; i < PHYS_SCREEN_HEIGHT * PHYS_SCREEN_WIDTH ; i++ )
1674 if ( IS_FLAGREAD( i ) )
1684 j = RotateIndex( old_orientation, new_orientation, k );
1686 if ( IS_FLAGREAD( j ) )
1697 memcpy( tmp1, tmp2, 3 );
1730 int pos_s, pos_d, pos_0;
1738 memset( FlagRead, 0,
sizeof( FlagRead ) );
1739 memset( FlagWritten, 0,
sizeof( FlagWritten ) );
1742 if ( obj_src != obj_dest )
1746 for ( dx = 0; dx < obj_dest->
mWidthUsed ; dx++ )
1757 for ( sx = 0; sx < obj_src->
mWidthUsed ; sx++ )
1762 if ( IS_FLAGREAD( pos_s ) )
1764 if ( obj_src == obj_dest )
1775 SET_FLAGREAD( pos_s );
1784 dx = trsf->
mFctX( sx_0, sy_0 );
1785 dy = trsf->
mFctY( sx_0, sy_0 );
1789 if ( ( dx < 0 ) || ( dy < 0 ) )
1794 if ( obj_src == obj_dest )
1796 if ( IS_FLAGREAD( pos_d ) )
1800 SET_FLAGWRITTEN( pos_d );
1806 SET_FLAGREAD( pos_d );
1808 SET_FLAGWRITTEN( pos_d );
1820 SET_FLAGWRITTEN( pos_d );
1828 if ( obj_dest == obj_src )
1833 for ( dx = 0; dx < obj_dest->
mWidthUsed ; dx++ )
1836 if ( !IS_FLAGWRITTEN( pos_d ) )
1863 CurrentTransformation.
mFctX = fct_X;
1864 CurrentTransformation.
mFctY = fct_Y;
1898 for ( dx = 0; dx < obj_dest->
mWidthUsed ; dx++ )