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

📄 slider.lst

📁 汽车通讯控制程序 电子屏字符显示器
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.06   SLIDER                                                                07/27/2005 18:45:50 PAGE 1   


C51 COMPILER V7.06, COMPILATION OF MODULE SLIDER
OBJECT MODULE PLACED IN .\slider.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE ..\..\..\基于arm的嵌入式系统开发与应用\ch09\slider\slider.c DEBUG OBJECTEXT
                    -END PRINT(.\slider.lst) OBJECT(.\slider.obj)

stmt level    source

   1          
   2          #include <stdio.h>
   3          #include <stdlib.h>
   4          #include <string.h>
   5          #include <unistd.h>
*** WARNING C318 IN LINE 5 OF ..\..\..\基于arm的嵌入式系统开发与应用\ch09\slider\slider.c: can't open file 'unistd.h'
   6          
   7          #define MWINCLUDECOLORS
   8          #include "nano-X.h"
*** WARNING C318 IN LINE 8 OF ..\..\..\基于arm的嵌入式系统开发与应用\ch09\slider\slider.c: can't open file 'nano-X.h'
   9          
  10          /* 拼图的尺寸设定 */
  11          #define WIDTH_IN_TILES  4
  12          #define HEIGHT_IN_TILES 4
  13          #define MAX_TILES       (WIDTH_IN_TILES * HEIGHT_IN_TILES)
  14          
  15          static  int     value[WIDTH_IN_TILES][HEIGHT_IN_TILES];
  16          static  int     calc_width, calc_height;
  17          static  int     tile_width = 40;
  18          static  int     tile_height = 40;
  19          
  20          
  21          static  void *  image_addr;
  22          static  int     using_image = 1;
  23          static  GR_WINDOW_ID    image;          /* 位图的存储区 */
*** ERROR C129 IN LINE 23 OF ..\..\..\基于ARM的嵌入式系统开发与应用\CH09\SLIDER\SLIDER.C: missing ';' before 'image'
  24          
  25          
  26          static  GR_WINDOW_ID    master;         /* 整个窗口的ID */
  27          static  GR_WINDOW_ID    buttons;        /* 按钮的ID */
  28          static  GR_WINDOW_ID    tiles;          /* 拼图区域的ID */
  29          static  GR_GC_ID        gc1;            /* 文字显示的图形上下文 */
  30          
  31          static  void    HandleEvents();
  32          static  void    RefreshWindow();
  33          static  void    RandomiseTiles();
  34          static  void    MoveTile();
  35          static  void    DrawTile();
  36          char bmpname[16]="slidebmp.bmp";
  37          int
  38          main(int argc,char **argv)
  39          {
  40                  if (GrOpen() < 0) {
  41                          fprintf(stderr, "cannot open graphics\n");
  42                          exit(1);
  43                  }
  44                          
  45                  gc1 = GrNewGC();
  46                  
  47                  
  48                  /* 计算位图需要的内存大小.... */
  49                  image_addr = malloc(4 * (WIDTH_IN_TILES * tile_width) *
  50                          (HEIGHT_IN_TILES * tile_height) );
  51          
C51 COMPILER V7.06   SLIDER                                                                07/27/2005 18:45:50 PAGE 2   

  52                  image = GrNewPixmap((WIDTH_IN_TILES * tile_width),
  53                          (HEIGHT_IN_TILES * tile_height), image_addr);
  54           
  55                  GrDrawImageFromFile(image, gc1, 0, 0,
  56                          GR_IMAGE_MAX_SIZE, GR_IMAGE_MAX_SIZE, bmpname, 0);
  57                  
  58                  
  59                  /* calculate size of tile area */
  60                  calc_width = 10 + (WIDTH_IN_TILES * tile_width);
  61                  calc_height = 15 + 35 + (HEIGHT_IN_TILES * tile_height);
  62          
  63                  master = GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, calc_width, calc_height, 1, RED, WHITE);
  64                  buttons = GrNewWindow((GR_WINDOW_ID) master, 5, 5, (calc_width - 5), 35, 1, RED, RED);
  65          
  66                  tiles = GrNewWindow((GR_WINDOW_ID) master, (calc_width/2) - (WIDTH_IN_TILES * tile_width /2),
  67                          45 + ((calc_height - 50)/2) - (HEIGHT_IN_TILES * tile_height /2),
  68                          (WIDTH_IN_TILES * tile_width), (HEIGHT_IN_TILES * tile_height), 1, RED, RED);
  69          
  70                  GrMapWindow(master);
  71                  GrMapWindow(buttons);
  72                  GrMapWindow(tiles);
  73          
  74                  
  75                  
  76                  GrSelectEvents(master, GR_EVENT_MASK_EXPOSURE|GR_EVENT_MASK_CLOSE_REQ|
  77                          GR_EVENT_MASK_KEY_DOWN);
  78                  GrSelectEvents(buttons, GR_EVENT_MASK_BUTTON_DOWN); 
  79                  GrSelectEvents(tiles, GR_EVENT_MASK_BUTTON_DOWN);
  80                  
  81                  srandom((int) getpid());
  82                  RandomiseTiles();
  83                  RefreshWindow();
  84                  
  85                  while (GR_TRUE) {
  86                          GR_EVENT event;
  87          
  88                          GrGetNextEvent(&event);
  89                          HandleEvents(&event);
  90                  }
  91          }
  92          
  93          
  94          /*
  95           * 消息处理函数
  96           */
  97          void
  98          HandleEvents(GR_EVENT *ep)
  99          {
 100                  int hole_x_pos, hole_y_pos;
 101                  int tempx, tempy;
 102          
 103                  switch (ep->type) {
 104                          case GR_EVENT_TYPE_BUTTON_DOWN:
 105                                  if (ep->button.wid == buttons) {
 106                                          if (ep->button.x < (calc_width/2)) {
 107                                                  /* 按下了Again按钮 */
 108                                                  RandomiseTiles();
 109                                                  RefreshWindow();
 110                                          } else {
 111                                                  /* 按下了Quit按钮 */
 112                                                  GrClose();
 113          
C51 COMPILER V7.06   SLIDER                                                                07/27/2005 18:45:50 PAGE 3   

 114                                                  if (using_image)
 115                                                          free(image_addr);
 116          
 117                                                  exit(0);
 118                                          }
 119                                  }
 120          
 121                                  if (ep->button.wid == tiles) {
 122                                          /* 想要移动鼠标点击的按钮 */
 123                                          MoveTile( (int)(ep->button.x / tile_width),
 124                                                  (int)(ep->button.y / tile_height) );
 125                                  }
 126                                  break;
 127          
 128                          case GR_EVENT_TYPE_KEY_DOWN:
 129                                  if (ep->keystroke.wid == master) {
 130                                          hole_x_pos = 0;
 131                                          hole_y_pos = 0;
 132          
 133                                          /* 查找空区 */
 134                                          for (tempx = 0; tempx < WIDTH_IN_TILES; tempx++)
 135                                                  for (tempy = 0; tempy < HEIGHT_IN_TILES; tempy++)
 136                                                          if (value[tempx][tempy] == MAX_TILES) {
 137                                                                  hole_x_pos = tempx;
 138                                                                  hole_y_pos = tempy;
 139                                                          }
 140                  
 141                                          switch (ep->keystroke.ch) {
 142                                                  case 'q':
 143                                                  case 'Q':
 144                                                  case MWKEY_CANCEL:
 145                                                          GrClose();
 146          
 147                                                          if (using_image)
 148                                                                  free(image_addr);
 149          
 150                                                          exit(0);
 151          
 152                                                  case 'r':
 153                                                  case 'R':
 154                                                          RandomiseTiles();
 155                                                          RefreshWindow();
 156                                                          break;
 157          
 158                                                  case MWKEY_DOWN:
 159                                                          if (hole_y_pos != 0) {
 160                                                                  MoveTile(hole_x_pos, hole_y_pos - 1);
 161                                                          }
 162                                                          break;
 163                                                                  
 164                                                  case MWKEY_UP:
 165                                                          if (hole_y_pos != (HEIGHT_IN_TILES-1) ) {
 166                                                                  MoveTile(hole_x_pos, hole_y_pos + 1);
 167                                                          }
 168                                                          break;
 169          
 170                                                  case MWKEY_RIGHT:
 171                                                          if (hole_x_pos != 0) {
 172                                                                  MoveTile(hole_x_pos - 1, hole_y_pos);
 173                                                          }
 174                                                          break;
 175          
C51 COMPILER V7.06   SLIDER                                                                07/27/2005 18:45:50 PAGE 4   

 176                                                  case MWKEY_LEFT:

⌨️ 快捷键说明

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