⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 snake.lst

📁 这是我大学4年来做过的竞赛以及老师的科研项目所积累下来的c51源代码
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V8.01   SNAKE                                                                 07/30/2008 23:29:10 PAGE 1   


C51 COMPILER V8.01, COMPILATION OF MODULE SNAKE
OBJECT MODULE PLACED IN SNAKE.OBJ
COMPILER INVOKED BY: D:\Keil\C51\BIN\C51.EXE SNAKE.C BROWSE DEBUG OBJECTEXTEND

line level    source

   1          #include "w77e58.h"
   2          #include "vt100.h"
   3          #include "init.h"
   4          #include "stdio.h"
   5          #include "stdlib.h"
   6          
   7          typedef struct kk{
   8                  unsigned char x;
   9                  unsigned char y;
  10          }SnakeType;
  11          
  12          xdata struct kk snake[400];
  13          
  14          
  15          #define UP      0xf0
  16          #define DOWN    0x0f
  17          //-----------------------------------------------------------------------------------
  18          #define LEFT    0x00
  19          #define RIGHT   0xff
  20          
  21          #define L_SHEET (2*2 +1)
  22          #define R_SHEET (13*2+1)
  23          
  24          #define T_SHEET 5
  25          #define B_SHEET 16
  26          //-----------------------------------------------------------------------------------
  27          void    init(void);
  28          void    delay(unsigned int);
  29          void    put_block(char,char);
  30          void    hide_block(char,char);
  31          bit     flash_snake(unsigned char);
  32          void    putch(char);
  33          bit     kbhit(void);
  34          char    getch(void);
  35          void    clr_wchdog(void){}
  36          void    put_bug(void);
  37          void    init_snake(void);
  38          void    putstr(char xdata *);
  39          void    flash_data(void);
  40          void    type_kbd(char code*);
  41          //-----------------------------------------------------------------------------------
  42          data    char GameScore;
  43          data    char HighScore;
  44          data    char direct;
  45          data    char SnakeLen;
  46          
  47          xdata   char print_buf[20];
  48          
  49          xdata   int Level;
  50          xdata   int     bug_x,bug_y;
  51          
  52          bit     TimerEnd;
  53          bit     GameOver;
  54          bit     GameStart;
  55          bit     blink_flag0;
C51 COMPILER V8.01   SNAKE                                                                 07/30/2008 23:29:10 PAGE 2   

  56          bit     blink_flag1;
  57          bit     flashed;
  58          bit     type_flag;
  59          
  60          //-----------------------------------------------------------------------------------
  61          void    main()
  62          {
  63   1              data int ch,ch1;
  64   1              bit     scoreadd;
  65   1      
  66   1              init();
  67   1              put_bug();
  68   1              while(1)
  69   1              {
  70   2                      REN_1=1;
  71   2                      if(kbhit())
  72   2                      {
  73   3                              ch1=ch;
  74   3                              ch=getch();
  75   3                              ch=ch&(0x20^0xff);
  76   3                              switch(ch)
  77   3                              {
  78   4                              case    'W':
  79   4                                      ch=UP;
  80   4                                      if(~ch == ch1) ch=ch1;
  81   4                                      else {TimerEnd=1;scoreadd=1;}
  82   4                                      break;
  83   4                              case    'S':
  84   4                                      ch=DOWN;
  85   4                                      if(~ch == ch1) ch=ch1;
  86   4                                      else {TimerEnd=1;scoreadd=1;}
  87   4                                      break;
  88   4                              case    'A':
  89   4                                      ch=LEFT;
  90   4                                      if(~ch == ch1) ch=ch1;
  91   4                                      else {TimerEnd=1;scoreadd=1;}
  92   4                                      break;
  93   4                              case    'D':
  94   4                                      ch=RIGHT;
  95   4                                      if(~ch == ch1) ch=ch1;
  96   4                                      else {TimerEnd=1;scoreadd=1;}
  97   4                                      break;
  98   4                              case    '\r':
  99   4                                      if(GameOver)
 100   4                                      {
 101   5                                              init_snake();
 102   5                                      GameOver=0;
 103   5                                              GameScore=0;
 104   5                                             //GameStart=0;
 105   5                                      }
 106   4                                      if(!GameStart)
 107   4                                      {
 108   5                                              del_line(4);
 109   5                                              gotoxy(L_SHEET,4);
 110   5                                              fputstr("Playing game....");
 111   5                                              del_line(24);
 112   5                                              gotoxy(L_SHEET,24);
 113   5                                              fputstr("Option| UP(&W) DOWN(&S) LEFT(&A) RIGHT(D) &PAUSE");
 114   5                                      }
 115   4                                      GameStart=1;ch=1;
 116   4                                     break;
 117   4                              case    'P':
C51 COMPILER V8.01   SNAKE                                                                 07/30/2008 23:29:10 PAGE 3   

 118   4                                      if(!GameStart) break;
 119   4                                      while(!kbhit())
 120   4                                      {
 121   5                                              gotoxy(L_SHEET,4);
 122   5                                              type_kbd("Game pause, any key to continue...");
 123   5                                              del_line(4);
 124   5                                      }
 125   4                                      gotoxy(L_SHEET,4);
 126   4                                      fputstr("Playing game....");
 127   4                                      break;
 128   4                              case    'N':
 129   4                                      if(!GameStart && Level>0)       Level--;
 130   4                                      flash_data();
 131   4                                      ch=1;
 132   4                                      break;
 133   4                              case    'U':
 134   4                                      if(!GameStart && Level<16)      Level++;
 135   4                                      flash_data();
 136   4                              default:
 137   4                                      ch=1;
 138   4                              }
 139   3                      }
 140   2                      if(!GameStart)
 141   2                      {
 142   3                              del_line(4);
 143   3                              gotoxy(L_SHEET,4);
 144   3                              if(GameOver) type_kbd("Game Over,");
 145   3                              type_kbd("Press Enter to start    ");
 146   3                      }
 147   2                      if(!GameOver && GameStart)
 148   2                      {
 149   3                              if(blink_flag0)
 150   3                              {
 151   4                                      hide_block(bug_x,bug_y);
 152   4                                      blink_flag0=0;
 153   4                              }
 154   3                              if(blink_flag1)
 155   3                              {
 156   4                                      put_block(bug_x,bug_y);
 157   4                                      blink_flag1=0;
 158   4                              }
 159   3                      }
 160   2                      
 161   2                      if( TimerEnd && GameStart && !GameOver)
 162   2                      {
 163   3                              TimerEnd=0;
 164   3                              if(scoreadd)
 165   3                              {
 166   4                                      scoreadd=0;
 167   4                                      GameScore += (20+Level*2);
 168   4                              }
 169   3                              if(!flash_snake(ch))                            
 170   3                              {
 171   4                                      if(GameScore>HighScore) HighScore=GameScore;
 172   4                                      GameScore=0;
 173   4                                      GameOver=1;
 174   4                                      GameStart=0;
 175   4                                      hide_block(bug_x,bug_y);
 176   4                                      del_line(24);
 177   4                                      gotoxy(L_SHEET,24);
 178   4                                      fputstr("Option| Level &UP/DOW&N");
 179   4                              }
C51 COMPILER V8.01   SNAKE                                                                 07/30/2008 23:29:10 PAGE 4   

 180   3                              flash_data();
 181   3                      }
 182   2              }
 183   1      }
 184          //-----------------------------------------------------------------------------------
 185          void    time_int(void) interrupt 1
 186          {
 187   1              static  int tcc;
 188   1              
 189   1              TH0=0x80;
 190   1              if((tcc&0x03)==0) blink_flag0=1;
 191   1              if((tcc&0x03)==2) blink_flag1=1;
 192   1              
 193   1              if( ++tcc >= (16-Level+4) )
 194   1              {       
 195   2                      tcc=0;
 196   2                      TimerEnd=!flashed;
 197   2                      flashed=0;
 198   2              }
 199   1              if(type_flag ) TimerEnd=1;
 200   1      }
 201          //-----------------------------------------------------------------------------------
 202          void    init(void)
 203          {
 204   1              char i;
 205   1              char xdata*xptr;
 206   1              
 207   1             EA=0;
 208   1             use_inter_SRAM;
 209   1              xptr=(char xdata*)0x400;
 210   1              while(xptr) *xptr--=0;
 211   1              timer0_16bit;
 212   1              timer0_start;
 213   1              ET0=1;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -