📄 game.lst
字号:
C51 COMPILER V7.02b GAME 04/20/2004 10:37:00 PAGE 1
C51 COMPILER V7.02b, COMPILATION OF MODULE GAME
OBJECT MODULE PLACED IN game.OBJ
COMPILER INVOKED BY: C:\KEIL\C51\BIN\C51.EXE game.c DEBUG OBJECTEXTEND
stmt level source
1 #include <game.h>
2 #include <reg51.h>
3
4 //*----------------------------------------------------------------------------
5 //* Function Name : write_point
6 //* Object : write a point to LCD
7 //* Input Parameters : xcoordinate ycoordinate
8 //* Output Parameters : none
9 //* Functions called : none
10 //*----------------------------------------------------------------------------
11 byte write_point(byte x,byte y)
12 {
13 1 byte idata temp,buffer;
14 1
15 1 if(x>128)return 0x00;
16 1 if(y>64) return 0x01;
17 1 temp=*(xram+(y/8)*128+x);
18 1 buffer=0x01;
19 1 buffer<<=(y%8);
20 1 temp=temp|buffer;
21 1 *(xram+(y/8)*128+x)=temp;
22 1 }
23
24 //*----------------------------------------------------------------------------
25 //* Function Name : write_big_point
26 //* Object : write a big point to lcd (total 4 litte point)
27 //* Input Parameters : xcoordinate ycoordinate
28 //* Output Parameters : none
29 //* Functions called : none
30 //*----------------------------------------------------------------------------
31 void write_big_point(byte x,byte y)
32 {
33 1 byte x_t,y_t;
34 1 x_t=x*2;
35 1 y_t=y*2+17;
36 1 write_point(x_t,y_t);
37 1 write_point(x_t+1,y_t);
38 1 write_point(x_t,y_t+1);
39 1 write_point(x_t+1,y_t+1);
40 1 }
41 //*----------------------------------------------------------------------------
42 //* Function Name : clear_big_point
43 //* Object : clear a big point to lcd
44 //* Input Parameters : xcoordinate ycoordinate
45 //* Output Parameters : none
46 //* Functions called : none
47 //*----------------------------------------------------------------------------
48 byte clear_point(byte x,byte y)
49 {
50 1 byte idata temp,buffer;
51 1 if(x>128)return 0x00;
52 1 if(y>64) return 0x01;
53 1 temp=*(xram+(y/8)*128+x);
54 1 buffer=0x01;
55 1 buffer<<=(y%8);
C51 COMPILER V7.02b GAME 04/20/2004 10:37:00 PAGE 2
56 1 buffer=~buffer;
57 1 temp=temp&buffer;
58 1 *(xram+(y/8)*128+x)=temp;
59 1 }
60 //*----------------------------------------------------------------------------
61 //* Function Name : clear_big_point
62 //* Object : clear a big point to lcd (total 4 litte point)
63 //* Input Parameters : xcoordinate ycoordinate
64 //* Output Parameters : none
65 //* Functions called : none
66 //*----------------------------------------------------------------------------
67 void clear_big_point(byte x,byte y)
68 {
69 1 byte x_t,y_t;
70 1 x_t=x*2;
71 1 y_t=y*2+17;
72 1 clear_point(x_t,y_t);
73 1 clear_point(x_t+1,y_t);
74 1 clear_point(x_t,y_t+1);
75 1 clear_point(x_t+1,y_t+1);
76 1 }
77 //*----------------------------------------------------------------------------
78 //* Function Name : write_square
79 //* Object : write a big point to lcd (total 4 litte point)
80 //* Input Parameters : xcoordinate ycoordinate
81 //* Output Parameters : none
82 //* Functions called : none
83 //*----------------------------------------------------------------------------
84 void write_square(byte x0,byte y0,byte x1,byte y1,byte d)
85 {
86 1 byte i;
87 1 for(i=0;i<(x1-x0);i++){
88 2 write_point((x0+i),y0);
89 2 write_point((x0+i+1),y1);
90 2 }
91 1 for(i=0;i<(y1-y0);i++){
92 2 write_point(x0,(y0+i+1));
93 2 write_point(x1,(y0+i));
94 2 }
95 1 if(d){
96 2 for(i=0;i<(x1-x0);i++){
97 3 write_point((x0+i),y0+1);
98 3 write_point((x0+i+1),y1-1);
99 3 }
100 2 for(i=0;i<(y1-y0);i++){
101 3 write_point(x0+1,(y0+i+1));
102 3 write_point(x1-1,(y0+i));
103 3 }
104 2 }
105 1 }
106 //--------------------put a char at lcd --------------------------------------
107 void put_char(byte x,byte y,byte att,byte chara){ //att: 0-> 16x16; 1->8x16; 2->24x24
108 1 byte i;
109 1 switch (att){
110 2 case 0:
111 2 for(i=0;i<16;i++){
112 3 *(xram+(y/8)*128+x+i)=chinese[chara*32+i];
113 3 *(xram+(y/8)*128+x+128+i)=chinese[chara*32+16+i];
114 3 }
115 2 break;
116 2 case 1:
117 2 for(i=0;i<16;i++)
C51 COMPILER V7.02b GAME 04/20/2004 10:37:00 PAGE 3
118 2 {
119 3 *(xram+(y/8)*128+x+i)=chinese[chara*32+i];
120 3 *(xram+(y/8)*128+x+128+i)=chinese[chara*32+16+i];
121 3 }
122 2 break;
123 2 case 2:
124 2 for(i=0;i<8;i++)
125 2 {
126 3 *(xram+(y/8)*128+x)=chinese[chara*32+i];
127 3 *(xram+(y/8)*128+x)=chinese[chara*32+i];
128 3 }
129 2 break;
130 2
131 2 default:break;
132 2 }
133 1 }
134 void write_body(void){
135 1 word i;
136 1 byte j,temp,start;
137 1 EA=0;
138 1 for(i=0;i<spoint;i++){
139 2 if(point[sp_start-i].x==point[sp_start-i-1].x){ //write snake bode from snake head
140 3 if(point[sp_start-i].y > point[sp_start-i-1].y){ // "|"
141 4 start=point[sp_start-i-1].y;
142 4 temp=point[sp_start-i].y-point[sp_start-i-1].y;
143 4 }
144 3 else{
145 4 start=point[sp_start-i].y;
146 4 temp=point[sp_start-i-1].y-point[sp_start-i].y;
147 4 }
148 3 for(j=0;j<temp+1;j++){
149 4 write_big_point(point[sp_start-i].x,start+j);
150 4 }
151 3 }
152 2 else{
153 3 if(point[sp_start-i].x > point[sp_start-i-1].x)
154 3 {
155 4 start=point[sp_start-i-1].x;
156 4 temp=point[sp_start-i].x-point[sp_start-i-1].x;
157 4 }
158 3 else
159 3 {
160 4 start=point[sp_start-i].x;
161 4 temp=point[sp_start-i-1].x-point[sp_start-i].x;
162 4 }
163 3 for(j=0;j<temp+1;j++)
164 3 {
165 4 write_big_point(start+j,point[sp_start-i].y);
166 4 }
167 3
168 3
169 3 }
170 2 }
171 1 EA=1;
172 1 }
173 //----------check the snake head touch the body and square or not--------------
174 byte check_point(){
175 1 if((point[sp_start].x== 0)||(point[sp_start].x >= 62))
176 1 return 0xff;
177 1 else{
178 2 if((point[sp_start].y==0)||(point[sp_start].y >= 22))
179 2 return 0xff;
C51 COMPILER V7.02b GAME 04/20/2004 10:37:00 PAGE 4
180 2 else
181 2 return 0x00; //that's all right
182 2 }
183 1 }
184 //------------------------move snake of tail-----------------------------------
185 void walk_tail(void){ //the snake is walk front and don't creat cells
186 1 byte tempx,tempx1,tempy,tempy1;
187 1 tempx =point[sp_end].x;
188 1 tempx1=point[sp_end+1].x;
189 1 tempy =point[sp_end].y;
190 1 tempy1=point[sp_end+1].y;
191 1 if(tempx==tempx1){
192 2 clear_big_point(tempx,point[sp_end].y); // "|"
193 2 if(tempy>tempy1){ //move the snake tail
194 3 tempy--; // ^
195 3 point[sp_end].y=tempy;// |
196 3 }
197 2 else{
198 3 tempy++; // |
199 3 point[sp_end].y=tempy;// V
200 3 }
201 2 }
202 1 else{
203 2 clear_big_point(tempx,point[sp_end].y); // "--"
204 2 if(tempx >tempx1){ // move the snake tail
205 3 tempx--; // <----
206 3 point[sp_end].x=tempx;
207 3 }
208 2 else{
209 3 tempx++; // ---->
210 3 point[sp_end].x=tempx;
211 3 }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -