?? doublebuffering.c
字號:
#include <math.h>#include "VGSDK.h"#include "vgsndmem.h"#include "vgsnd.h"#include "mypic.h"#include "memdef.h"//global varU8 Error_Num;//9-29:snd error, 30-100:graph error//every wav stands for a music_DGSNDWAV wav, wav1, wav2;void error_trap(U8 error_num);extern My_Pic Gnd, girl, mouse, _pic_[_KEYNUMBER];extern My_Key Key[_KEYNUMBER];extern ALL_PIC_address _All_pic_add[_PIC_NUMBER];extern unsigned int _TIMER_VAR;//0.1sextern short key_left_press;extern short key_right_press;extern short x_position;extern short y_position;extern short Mouse_change;extern short Key_pressed;extern short Key_released;extern UartConfig1();extern timer_int_enable();extern void init_struct(void);extern void init_all_pic_address(void);extern void Copy_all_pic_to_Tmem(void);extern void Draw_all_small_pic(void);extern void Draw_my_pic(unsigned short dispmode, My_Pic *p_mypic, unsigned int Trans_color);extern void Recover_gnd(My_Pic *p_front, My_Pic *p_back_g);extern void Exchange_oldXY(char bank_switch, My_Pic *p_mypic);extern int change_pic(My_Pic *Des_pic, char *string);extern int Which_key_is_pressed(void);extern void init_key_range(void);extern void recover_all_key(void);float rotate_angle=0.0;//#define _LATCH_ADDR *(volatile unsigned short int*)(0x01280000) //VG2#define _LATCH_ADDR *(volatile U16*)(0x01580000) //amazon//U32 _dgADK_HW_BASEADDRESS = 0x05000000;char *fm_easy = (char *)( _FLASH_ADD + 1838992); //*.wavchar *chat = (char *)( _FLASH_ADD + 2433030);char *ding = (char *)( _FLASH_ADD + 2457228);//word *file_heaven = (word *)( 0x02200000 ); //24198 //*.b16 0x02200000 0x05000000//word *girl_address =(word*) (0x02200000 + 614400); //girl pic//word *mouse_address =(word*) (0x02200000 + 644400); // mouse picword *temp_buf = (word *)( 0x02300000 + 0); //temp buf for read pictureword *temp_buf1 = (word *)( 0x02400000 + 0); //temp buf for read picture///////pictures///////////////////void PutPixel(int x,int y,int color){ fmemw[2048*y+x*2]=color;}//2^Width_t,6:64,7:128,8:256,9:512,10:1024void PutPixel_t(int start_position, int Width_t, int x,int y,int color){ //0x40000 tmemw[ start_position + (y << (Width_t +1)) + (x << 1) ]=color; // 16bit color,so 2*width for faster speed, use "<<"}//copy bmp 16 from flash to texturemem//void Copyb16_from_flash_to_texture(word *begin_flash, word *begin_texture, // int columns, int lines, int columns_apply(2^n), int lines_apply(2^n))void Copyb16_from_flash_to_texture(word *begin_flash, int begin_texture, int columns, int lines, int columns_apply, int lines_apply){ int i,j; int color; for(j= lines-1; j>=0 ; j--) { for(i=0; i<columns; i++) { color = *begin_flash; PutPixel_t(begin_texture, columns_apply, i, j, color); begin_flash ++; } }}void Copyb16_from_mem_to_frame(char bank_number, word *begin_mem, int begin_frame_x, int begin_frame_y, int columns, int lines){ int j; char *src; char *dest; unsigned long fram_add; src = (char*)begin_mem; if( ( bank_number & 0x01) == 0) //判斷BANK0/1 { fram_add = 0x04000000; } else fram_add = 0x04400000; for(j= lines-1; j>=0 ; j--) { dest =(char *)(fram_add + (begin_frame_x<<1) + (j + begin_frame_y)*2048 );// vgmemcpy16( void* dest, void* src, long bytesize ); while((*(short*)0x1803400)& 0x2000); // wait vgmemcpy16( dest, src, columns<<1 ); src = src + (columns<<1); }}//read a block of fmem and save in main mem for recovervoid Read_from_frame_to_mem( char bank_number, word *begin_mem, int begin_frame_x, int begin_frame_y, int columns, int lines){ int j; char *src; char *dest; unsigned long fram_add; dest = (char*)begin_mem; if( ( bank_number & 0x01) == 0) //判斷BANK0/1 { fram_add = 0x04000000; } else fram_add = 0x04400000; for(j= lines-1; j>=0 ; j--) { src =(char *)(fram_add + (begin_frame_x<<1) + (j + begin_frame_y)*2048 );// vgmemcpy16( void* dest, void* src, long bytesize ); vgmemcpy16( dest, src, columns<<1 ); dest = dest + (columns<<1); }}void Copyb16_from_flash_to_texture_new(word *begin_flash, int begin_texture, int columns, int lines, int columns_apply, int lines_apply){ int j; char *src; char *dest; src = (char*)begin_flash ; for(j= lines-1; j>=0 ; j--) { dest =(char *)(0x03800000+begin_texture + (j<< (columns_apply +1)));// vgmemcpy16( void* dest, void* src, long bytesize ); vgmemcpy16( dest, src, columns<<1 ); src = src + (columns<<1); }}void delay(int i){ int j; while(i) { i--; for(j=0;j<10000;j++); }}void Make_BMP_1(void){ int index=0; int x,y,X,Y; int i; int color; byte R,G,B,r,pel; Y = 128; X = 128; for( y = Y-1; y >= 0; y--) { for( x = 0; x < X; x++) { if((x <= 64)&&(y <= 64)) { R = 0x0ff; G = 0x0; B = 0x0; } else if(( x > 64 )&&( y <= 64)) { R = 0x0; G = 0x0ff; B = 0x0; } else if((x <= 64)&&(y > 64)) { R = 0x0; G = 0x0; B = 0x0ff; } else if((x > 64)&&(y > 64)) { R = 0xbb; G = 0xbb; B = 0xbb; } color=((R&0xf8)<<8) | ((G&0xfc)<<3) | (B>>3); PutPixel_t(0x40000,7, x, y, color); } }}void Make_New_BMP1(void){ int x,y,color,X,Y; byte R,G,B; Y = 128; X = 128; for( y = Y-1; y >= 0; y--) { for( x = 0; x < X; x++) { if((x <= 64)&&(y <= 64)) { R = 0x0ff; G = 0x0; B = 0x0; } else if(( x > 64 )&&( y <= 64)) { R = 0x0; G = 0x0ff; B = 0x0; } else if((x <= 64)&&(y > 64)) { R = 0x0; G = 0x0; B = 0x0ff; } else if((x > 64)&&(y > 64)) { R = 0xbb; G = 0xbb; B = 0xbb; } color=((R&0xf8)<<8) | ((G&0xfc)<<3) | (B>>3); PutPixel_t(0x48000,7, x,y,color); } }}/////////////////////////////////////////////////////// Synchronous flipping/////////////////////////////////////////////////////void WritePacket_Flip( unsigned short* packet_addr ){ packet_addr[0] = 0x0001;}/////////////////////////////////////////////////////// Asynchronous flipping/////////////////////////////////////////////////////void WritePacket_AsyncFlip( unsigned short* packet_addr ){ packet_addr[0] = 0x0080;}/////////////////////////////////////////////////////// push flipping command & wait done../////////////////////////////////////////////////////void PushCommand( void(*WritePacket)(unsigned short *packet_addr) );void Flip_zy(){ // flip counter reset *(volatile unsigned short*)0x030000a6 = 0; // increment flip count *(volatile unsigned short*)0x030000a6 = 1; // push flipping command // refer to 7.4 page flipping //PushFlipCommand() PushCommand( WritePacket_Flip ); // wait for flipping while( *(volatile unsigned short*)0x030000a6 != 0 );}/////////////////////////////////////////////////////// clear screen/////////////////////////////////////////////////////void WritePacket_Clear( unsigned short* packet_addr ){ packet_addr[0] = 0x1110; // PH packet_addr[1] = 0; // PD[1] : left-top x packet_addr[2] = 0; // PD[2] : left-top y packet_addr[3] =820; // PD[3] : right-bottom x packet_addr[4] =511; // PD[4] : right-bottom y packet_addr[21] = (0x00<<8) | 0x00; // PD[21] : G<<8 | B black color 0 0 0 packet_addr[22] = 0x00; // PD[22] : R}/////////////////////////////////////////////////////// draw box/////////////////////////////////////////////////////long x,y;void WritePacket_Box( unsigned short* packet_addr ){ packet_addr[0] = 0x1110; // PH packet_addr[1] = x; // PD[1] : left-top x packet_addr[2] = y; // PD[2] : left-top y packet_addr[3] = x+63; // PD[3] : right-bottom x packet_addr[4] = y+63; // PD[4] : right-bottom y packet_addr[21] = (0x00<<8) | 0x00; // PD[21] : G<<8 | B packet_addr[22] = 0xff; // PD[22] : R}/////////////////////////////////////////////////////// Graphics functions/////////////////////////////////////////////////////void InitRenderingEngine();void PushCommand( void(*WritePacket)(unsigned short *packet_addr) );/////////////////////////////////////////////////////// system initialize functions.../////////////////////////////////////////////////////void VR0_memory_controller_reset();void CRT_320x240_noninterlace();////////////////////////////////////////////////////void Write_Packet_blend(int mode, int ScrX1, int ScrY1, int ScrX2, int ScrY2, int Tx1, int Ty1, int A, int B, int C, int D, int SrcAlphaColor, int SrcBlendFunc,int DestAlphaColor,int DestBlendFunc,
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -