Merge branch 'D'
This commit is contained in:
commit
6dbe1d6b62
7 changed files with 114 additions and 68 deletions
|
@ -5,6 +5,7 @@
|
|||
#include "delay.h"
|
||||
#include "eeprom.h"
|
||||
|
||||
extern unsigned int bestScore[];
|
||||
char base[MAX_X][MAX_Y] = {0}; //x*y //0为空 1为下落完成 2为正在下落
|
||||
extern unsigned int score;
|
||||
extern enum OPR opr;
|
||||
|
@ -258,7 +259,31 @@ void blockGameOver()
|
|||
//结束则填满
|
||||
if(blockGameStatus == over)
|
||||
{
|
||||
addBest(score);
|
||||
//дÈëÅÅÐаñ
|
||||
if(addBest(score))
|
||||
{
|
||||
IapEraseSector(IAP_ADDRESS);
|
||||
IapProgramByte(IAP_ADDRESS + 0, bestScore[0] >> 8);
|
||||
IapProgramByte(IAP_ADDRESS + 1, bestScore[0] % 256);
|
||||
IapProgramByte(IAP_ADDRESS + 2, bestScore[1] >> 8);
|
||||
IapProgramByte(IAP_ADDRESS + 3, bestScore[1] % 256);
|
||||
IapProgramByte(IAP_ADDRESS + 4, bestScore[2] >> 8);
|
||||
IapProgramByte(IAP_ADDRESS + 5, bestScore[2] % 256);
|
||||
IapProgramByte(IAP_ADDRESS + 6, bestScore[3] >> 8);
|
||||
IapProgramByte(IAP_ADDRESS + 7, bestScore[3] % 256);
|
||||
IapProgramByte(IAP_ADDRESS + 8, bestScore[4] >> 8);
|
||||
IapProgramByte(IAP_ADDRESS + 9, bestScore[4] % 256);
|
||||
IapProgramByte(IAP_ADDRESS + 10, bestScore[5] >> 8);
|
||||
IapProgramByte(IAP_ADDRESS + 11, bestScore[5] % 256);
|
||||
IapProgramByte(IAP_ADDRESS + 12, bestScore[6] >> 8);
|
||||
IapProgramByte(IAP_ADDRESS + 13, bestScore[6] % 256);
|
||||
IapProgramByte(IAP_ADDRESS + 14, bestScore[7] >> 8);
|
||||
IapProgramByte(IAP_ADDRESS + 15, bestScore[7] % 256);
|
||||
IapProgramByte(IAP_ADDRESS + 16, bestScore[8] >> 8);
|
||||
IapProgramByte(IAP_ADDRESS + 17, bestScore[8] % 256);
|
||||
IapProgramByte(IAP_ADDRESS + 18, bestScore[9] >> 8);
|
||||
IapProgramByte(IAP_ADDRESS + 19, bestScore[9] % 256);
|
||||
}
|
||||
for(j = 0; j < MAX_Y; j++)
|
||||
for(i = 0; i < MAX_X; i++)
|
||||
{
|
||||
|
@ -269,3 +294,39 @@ void blockGameOver()
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int addBest(unsigned int s)
|
||||
{
|
||||
int i, j;
|
||||
for(i = 0; i < 10; i++)
|
||||
if(bestScore[i] < s)
|
||||
{
|
||||
for(j = 9; j > i; j--)
|
||||
bestScore[j] = bestScore[j - 1];
|
||||
|
||||
bestScore[i] = s;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void saveBest()
|
||||
{
|
||||
unsigned int i;
|
||||
IapEraseSector(IAP_ADDRESS);
|
||||
delayms(20);
|
||||
for(i = 0; i++; i < 10)
|
||||
{
|
||||
IapProgramByte(IAP_ADDRESS + 2 * i, bestScore[i] >> 8);
|
||||
IapProgramByte(IAP_ADDRESS + 2 * i + 1, bestScore[i] - (bestScore[i] >> 4) << 8);
|
||||
}
|
||||
}
|
||||
|
||||
void readBest()
|
||||
{
|
||||
unsigned int i;
|
||||
for(i = 0; i++; i < 10)
|
||||
{
|
||||
bestScore[i] = (unsigned int)IapReadByte(IAP_ADDRESS + 2 * i) << 8 + (unsigned int)IapReadByte(IAP_ADDRESS + 2 * i + 1);
|
||||
}
|
||||
}
|
|
@ -19,4 +19,8 @@ void moveLeftPiece();
|
|||
void moveRightPiece();
|
||||
void judgeBlock();
|
||||
void blockGameOver();
|
||||
|
||||
void saveBest();
|
||||
void readBest();
|
||||
unsigned int addBest(unsigned int s);
|
||||
#endif
|
|
@ -15,7 +15,6 @@
|
|||
#include "eeprom.h"
|
||||
#include "delay.h"
|
||||
|
||||
unsigned int bestScore[10]={0};
|
||||
|
||||
/*----------------------------
|
||||
Disable ISP/IAP/EEPROM function
|
||||
|
@ -48,7 +47,6 @@ BYTE IapReadByte(WORD addr)
|
|||
_nop_(); //MCU will hold here until ISP/IAP/EEPROM operation complete
|
||||
dat = IAP_DATA; //Read ISP/IAP/EEPROM data
|
||||
IapIdle(); //Close ISP/IAP/EEPROM function
|
||||
|
||||
return dat; //Return Flash data
|
||||
}
|
||||
|
||||
|
@ -69,6 +67,7 @@ void IapProgramByte(WORD addr, BYTE dat)
|
|||
IAP_TRIG = 0xb9; //Send trigger command2 (0xb9)
|
||||
_nop_(); //MCU will hold here until ISP/IAP/EEPROM operation complete
|
||||
IapIdle();
|
||||
delayms(10);
|
||||
}
|
||||
|
||||
/*----------------------------
|
||||
|
@ -86,43 +85,5 @@ void IapEraseSector(WORD addr)
|
|||
IAP_TRIG = 0xb9; //Send trigger command2 (0xb9)
|
||||
_nop_(); //MCU will hold here until ISP/IAP/EEPROM operation complete
|
||||
IapIdle();
|
||||
}
|
||||
|
||||
void addBest(unsigned int s)
|
||||
{
|
||||
int i,j;
|
||||
for(i=0;i<10;i++)
|
||||
if(bestScore[i]<s)
|
||||
{
|
||||
for(j=9;j>i;j--)
|
||||
bestScore[j]=bestScore[j-1];
|
||||
|
||||
bestScore[i]=s;
|
||||
saveBest();
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void saveBest()
|
||||
{
|
||||
char i;
|
||||
IapEraseSector(IAP_ADDRESS);
|
||||
delayms(20);
|
||||
for(i=0;i++;i<10)
|
||||
{
|
||||
IapProgramByte(IAP_ADDRESS+2*i, bestScore[i]/256);
|
||||
delayms(15);
|
||||
IapProgramByte(IAP_ADDRESS+2*i+1, bestScore[i]%256);
|
||||
delayms(15);
|
||||
}
|
||||
}
|
||||
|
||||
void readBest()
|
||||
{
|
||||
char i;
|
||||
for(i=0;i++;i<10)
|
||||
{
|
||||
bestScore[i]=(unsigned int)IapReadByte(IAP_ADDRESS+2*i)*256 +(unsigned int)IapReadByte(IAP_ADDRESS+2*i+1);
|
||||
}
|
||||
delayms(10);
|
||||
}
|
|
@ -33,8 +33,4 @@ BYTE IapReadByte(WORD addr);
|
|||
void IapProgramByte(WORD addr, BYTE dat);
|
||||
void IapEraseSector(WORD addr);
|
||||
|
||||
void saveBest();
|
||||
void readBest();
|
||||
void addBest(unsigned int s);
|
||||
|
||||
#endif
|
|
@ -164,12 +164,13 @@ code unsigned char FONT_OVER1[]={
|
|||
0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,
|
||||
};
|
||||
//=================== ¼Ç¼×Ö¿â ==================
|
||||
//ナナミミ
|
||||
code unsigned char FONT_BEST0[]={
|
||||
0x40,0x40,0xC0,0x5F,0x55,0x55,0xD5,0x55,0x55,0x55,0x55,0x5F,0x40,0x40,0x40,0x00,
|
||||
0x04,0x04,0x04,0x04,0xF4,0x94,0x95,0x96,0x94,0x94,0xF4,0x04,0x04,0x04,0x04,0x00,
|
||||
0x10,0x10,0x10,0xFF,0x90,0x08,0x88,0x88,0xFF,0x00,0x00,0xFF,0x88,0x88,0x08,0x00,
|
||||
0x00,0x10,0x88,0xC4,0x33,0x00,0x40,0x42,0x42,0x42,0xC2,0x42,0x42,0x42,0x40,0x00,
|
||||
};
|
||||
code unsigned char FONT_BEST1[]={
|
||||
0x20,0x60,0x3F,0x25,0x15,0x15,0xFF,0x90,0x47,0x29,0x11,0x2D,0x43,0x80,0x80,0x00,
|
||||
0x00,0xFE,0x02,0x02,0x7A,0x4A,0x4A,0x4A,0x4A,0x4A,0x7A,0x02,0x82,0xFE,0x00,0x00,
|
||||
0x02,0x42,0x81,0x7F,0x00,0x08,0x08,0x08,0xFF,0x00,0x00,0xFF,0x08,0x08,0x08,0x00,
|
||||
0x02,0x01,0x00,0xFF,0x00,0x00,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x00,
|
||||
};
|
||||
#endif
|
|
@ -6,7 +6,7 @@ unsigned char TH, TL;
|
|||
|
||||
extern Menu *NOW; //菜单指针
|
||||
extern enum OPR opr; //按键状态
|
||||
|
||||
extern unsigned int bestScore[];
|
||||
|
||||
void int0() interrupt 0 //外部中断:检测左右旋钮
|
||||
{
|
||||
|
@ -46,6 +46,7 @@ void time() interrupt 1 //
|
|||
|
||||
int main()
|
||||
{
|
||||
|
||||
TH = RELOAD / 256; //填充值预计算
|
||||
TL = RELOAD - (RELOAD / 256) * 256;
|
||||
TH0 = TH;
|
||||
|
@ -66,7 +67,29 @@ int main()
|
|||
displayInit(); //屏幕初始化
|
||||
clear();
|
||||
menuInit(); //菜单初始化
|
||||
readBest();
|
||||
|
||||
//¶ÁÈ¡ÅÅÐаñ
|
||||
bestScore[0] = ((unsigned int)IapReadByte(IAP_ADDRESS + 0)) * 256
|
||||
+ (unsigned int)IapReadByte(IAP_ADDRESS + 1);
|
||||
bestScore[1] = ((unsigned int)IapReadByte(IAP_ADDRESS + 2)) * 256
|
||||
+ (unsigned int)IapReadByte(IAP_ADDRESS + 3);
|
||||
bestScore[2] = ((unsigned int)IapReadByte(IAP_ADDRESS + 4)) * 256
|
||||
+ (unsigned int)IapReadByte(IAP_ADDRESS + 5);
|
||||
bestScore[3] = ((unsigned int)IapReadByte(IAP_ADDRESS + 6)) * 256
|
||||
+ (unsigned int)IapReadByte(IAP_ADDRESS + 7);
|
||||
bestScore[4] = ((unsigned int)IapReadByte(IAP_ADDRESS + 8)) * 256
|
||||
+ (unsigned int)IapReadByte(IAP_ADDRESS + 9);
|
||||
bestScore[5] = ((unsigned int)IapReadByte(IAP_ADDRESS + 10)) * 256
|
||||
+ (unsigned int)IapReadByte(IAP_ADDRESS + 11);
|
||||
bestScore[6] = ((unsigned int)IapReadByte(IAP_ADDRESS + 12)) * 256
|
||||
+ (unsigned int)IapReadByte(IAP_ADDRESS + 13);
|
||||
bestScore[7] = ((unsigned int)IapReadByte(IAP_ADDRESS + 14)) * 256
|
||||
+ (unsigned int)IapReadByte(IAP_ADDRESS + 15);
|
||||
bestScore[8] = ((unsigned int)IapReadByte(IAP_ADDRESS + 16)) * 256
|
||||
+ (unsigned int)IapReadByte(IAP_ADDRESS + 17);
|
||||
bestScore[9] = ((unsigned int)IapReadByte(IAP_ADDRESS + 18)) * 256
|
||||
+ (unsigned int)IapReadByte(IAP_ADDRESS + 19);
|
||||
|
||||
while(1)
|
||||
{
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ Menu* LAST = NULL; //
|
|||
enum OPR opr = idle;
|
||||
static unsigned char local[2] = {0};
|
||||
unsigned int score;
|
||||
extern unsigned int bestScore[10];
|
||||
unsigned int bestScore[10];
|
||||
extern enum GS blockGameStatus;
|
||||
|
||||
|
||||
|
@ -170,7 +170,7 @@ void m_best(struct _menu* this)
|
|||
if(LAST != &M_BEST)
|
||||
{
|
||||
LAST = &M_BEST;
|
||||
drawBEST(2, 0);
|
||||
drawBEST(2, 0); //»æÖÆ×Ö
|
||||
drawSUPNUM(2, 2, bestScore[0] / 10000); //绘制分数
|
||||
drawSUPNUM(11, 2, (bestScore[0] % 10000) / 1000);
|
||||
drawSUPNUM(20, 2, (bestScore[0] % 1000) / 100);
|
||||
|
|
Reference in a new issue