home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / C-ASM_VI.ARJ / PROGC.ZIP / PROGC092.C < prev    next >
Text File  |  1988-05-26  |  3KB  |  78 lines

  1.  
  2. /************************************************************************/
  3. /* Display black and white sprite and move it using arrow keys          */
  4. /************************************************************************/
  5.  
  6. demo_cursor()
  7.         {
  8.         #define MAX_X           (640 - 16)
  9.         #define MAX_Y           (350 - 16)
  10.  
  11.         #define KEY_ESC         0x011B
  12.         #define KEY_UP          0x4800
  13.         #define KEY_DOWN        0x5000
  14.         #define KEY_LEFT        0x4B00
  15.         #define KEY_RIGHT       0x4D00
  16.         #define KEY_ENTER       0x1C0D
  17.  
  18.         static  char    and_mask[] = {
  19.                 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x1F,0xF8,
  20.                 0x1F,0xF8, 0x1F,0xF8, 0x1F,0xF8, 0x1F,0xF8,
  21.                 0x1F,0xF8, 0x1F,0xF8, 0x1F,0xF8, 0x1F,0xF8,
  22.                 0x1F,0xF8, 0x00,0x00, 0x00,0x00, 0x00,0x00};
  23.         static  char    xor_mask[] = {
  24.                 0xFF,0xFF, 0x80,0x01, 0xBF,0xFD, 0xA0,0x05,
  25.                 0xA0,0x05, 0xA0,0x05, 0xA0,0x05, 0xA0,0x05,
  26.                 0xA0,0x05, 0xA0,0x05, 0xA0,0x05, 0xA0,0x05,
  27.                 0xA0,0x05, 0xBF,0xFD, 0x80,0x01, 0xFF,0xFF};
  28.         int     key, x, y, i;
  29.  
  30.         /* Draw a background pattern  and a solid white box             */
  31.  
  32.         clear_screen();
  33.         for (i = 0; i < 640; i += 20) line(320,100,i,  0,i/20);
  34.         for (i = 0; i < 640; i += 20) line(320,100,i,199,i/20);
  35.         for (i = 0; i < 200; i += 10) line(320,100,0,  i,i/10);
  36.         for (i = 0; i < 200; i += 10) line(320,100,639,i,i/10);
  37.         solid_box(320,100,150,150,15);
  38.  
  39.         /* Set cursor shape and color, and display the first cursor     */
  40.  
  41.         set_cursor(and_mask, xor_mask, 0, 15);
  42.         x = 320;                        /* initial position of cursor   */
  43.         y = 100;
  44.         move_cursor(x,y);               /* show cursor at initial pos   */
  45.  
  46.         /* Loop while keys are pressed                                          */
  47.  
  48.         do
  49.                 {
  50.                 switch (key = get_key())/* Move cursor according to key */
  51.                         {
  52.                         case KEY_ESC:
  53.                         case KEY_ENTER:
  54.                                 remove_cursor();
  55.                                 break;
  56.                         case KEY_UP:
  57.                                 y = (y -1) > 0 ? --y : 0;
  58.                                 move_cursor(x, y);
  59.                                 break;
  60.                         case KEY_DOWN:
  61.                                 y = (y + 1) < MAX_Y ? ++y : MAX_Y;
  62.                                 move_cursor(x, y);
  63.                                 break;
  64.                         case KEY_RIGHT:
  65.                                 x = (x + 1) < MAX_X ? ++x : MAX_X;
  66.                                 move_cursor(x, y);
  67.                                 break;
  68.                         case KEY_LEFT:
  69.                                 x = (x - 1) > 0 ? --x : 0;
  70.                                 move_cursor(x, y);
  71.                                 break;
  72.                         default:
  73.                                 break;
  74.                         }
  75.                 } while (key != KEY_ENTER);
  76.         }
  77.  
  78.