FVIEW.CPP
上传用户:xr_qian
上传日期:2007-01-05
资源大小:443k
文件大小:14k
源码类别:

通讯/手机编程

开发平台:

DOS

  1. // ******************************************************************** //
  2. //                                                                      //
  3. //      FVIEW.CPP                                                       //
  4. //      Copyright (c) 1993, Michael Holmes and Bob Flanders             //
  5. //      C++ Communication Utilities                                     //
  6. //                                                                      //
  7. //      This file contains the routines under the VIEW main menu        //
  8. //      entry.  These routines provide for the viewing of a G3 fax      //
  9. //      on a VGA screen.                                                //
  10. //                                                                      //
  11. // ******************************************************************** //
  12. #define VIDEO_GET_MODE()    r.x.ax = 0x0f00;            
  13.                             int86(0x10, &r, &r)
  14. #define VIDEO_SET_MODE(a)   r.x.ax = a;                 
  15.                             r.x.bx = 0;                 
  16.                             int86(0x10, &r, &r)
  17. #define VIDEO_DOT(a, b, c)  r.x.ax = 0x0c00 | c;        
  18.                             r.x.bx = 0;                 
  19.                             r.x.cx = a; r.x.dx = b;     
  20.                             int86(0x10, &r, &r)
  21. #define VIDEO_WRITE(a)      r.x.ax = 0x0e00 | a;        
  22.                             r.x.bx = 7;                 
  23.                             int86(0x10, &r, &r)
  24. #define VIDEO_POS(a, b)     r.x.ax = 0x0200;            
  25.                             r.h.bh = 0;                 
  26.                             r.x.dx = (b << 8) | a;      
  27.                             int86(0x10, &r, &r)
  28. #define VIDEO_STRING(a)     { for (char *s = a; *s; s++)
  29.                                 { VIDEO_WRITE(*s); } }
  30. #define VIDEO_CLR()         r.x.ax = 0x0700;            
  31.                             r.h.bh = 7;                 
  32.                             r.x.cx = 0;                 
  33.                             r.x.dx = 0x1e4f;            
  34.                             int86(0x10, &r, &r)
  35. /* ******************************************************************** *
  36.  *
  37.  *  f_bit_count() -- return total number of bits on based on zoom
  38.  *
  39.  * ******************************************************************** */
  40. int     f_bit_count(char *p,                // start of line
  41.                     int  sb,                // starting bit number
  42.                     int  z)                 // zoom (number of bits)
  43. {
  44. int     total = 0,                          // total bits on
  45.         i, j,                               // loop control
  46.         sbp;                                // start bit prime
  47. for (i = 0; i < z; i++, p += LINE)          // for each line
  48.     for (j = 0, sbp = sb; j < z; j++, sbp++)// ..and each bit in zoom
  49.         total += get_bit((UCHAR *) p, sbp); // tally the on bits
  50. return(total);                              // return with "on" bit count
  51. }
  52. /* ******************************************************************** *
  53.  *
  54.  *  f_show_part() -- draw a portion of a page on the screen
  55.  *
  56.  * ******************************************************************** */
  57. void    f_show_part(int x, int y,           // column and row base
  58.                     int z,                  // zoom level
  59.                     int pg)                 // page number
  60. {
  61. int     i, ii, j, jj,                       // loop control
  62.         imax, jmax,                         // ..and more loop control
  63.         w;                                  // work bit collector
  64. char    huge *p,                            // work pointer
  65.         buf[80];                            // string buffer
  66. union   REGS r;                             // cpu registers
  67. static
  68. char    f_colors[3][10] =                   // zoom level to video dots
  69.     {
  70.     { 0, 1, 1 },                            // 1 bit zoom (2 bits max)
  71.     { 0, 0, 1, 1, 1 },                      // 2 bit zoom (4 bits max)
  72.     { 0, 0, 0, 0, 1, 1, 1, 1, 1, 1 }        // 3 bit zoom (9 bits max)
  73.     };
  74. sprintf(buf, "%s  Page %d  Zoom %d",        // prepare bottom line
  75.             f_filename, pg, z);             // ..to keep user informed
  76. VIDEO_CLR();                                // clear screen
  77. VIDEO_POS(0, 29);                           // get to bottom line
  78. VIDEO_STRING(buf);                          // ..and give status
  79. p = &page[(long) y * LINE];                 // find bitmap start point
  80. imax = 640;                                 // use screen width
  81. jmax = 480;                                 // ..and max line count
  82. for (j = y, jj = 0;                         // for each line ..
  83.             jj < jmax && j < LINES;         // ..loop till bottom of screen
  84.             j += z, jj++, p += (LINE * z))  // ..or end of data
  85.     {
  86.     for (i = x, ii = 0;                     // and write dots until out
  87.                 ii < imax && i < PELS;      // ..of source bits in bitmap
  88.                 i += z, ii++)               // ..or screen
  89.         {
  90.         w = f_bit_count((char *) p, i, z);  // get some bits
  91.         if (f_colors[z - 1][w])             // q. enough bits on?
  92.             {
  93.             VIDEO_DOT(ii, jj, 0);           // a. yes .. display a dot
  94.             }
  95.         }
  96.     if (bioskey(1))                         // q. key available?
  97.         return;                             // a. yes .. return to caller
  98.     }
  99. VIDEO_POS(0, 29);                           // get to bottom line
  100. VIDEO_STRING(buf);                          // ..and give status
  101. }
  102. /* ******************************************************************** *
  103.  *
  104.  *  f_view() -- view a fax on the screen
  105.  *
  106.  * ******************************************************************** */
  107. #pragma argsused
  108. int     f_view(int cc, int rr)              // column and row
  109. {
  110. int     x, y,                               // page positioning
  111.         z,                                  // zoom factor
  112.         pn = 1,                             // fax page number
  113.         k = 1,                              // keystroke buffer
  114.         qf = 0;                             // quit flag
  115. char    old_mode,                           // old video mode
  116.         buf[50];                            // string buffer
  117. union   REGS r;                             // cpu registers
  118. Window  v_win(1, 1, 80, 25,                 // define temporary window
  119.             menu_cn, menu_cr);              // ..using system colors
  120. if (f_handle == -1)                         // q. file open?
  121.     return(ESC);                            // a. no .. just return
  122. v_win.Open(none);                           // open window to save screen
  123. VIDEO_GET_MODE();                           // get current video mode
  124. old_mode = r.h.al;                          // ..and save for later
  125. VIDEO_SET_MODE(0x11);                       // select video mode
  126. VIDEO_GET_MODE();                           // get current video mode
  127. if (r.h.al != 0x11)                         // q. unsupported mode?
  128.     {
  129.     VIDEO_SET_MODE(old_mode);               // a. yes .. select old mode
  130.     return(ESC);                            // ..and just return
  131.     }
  132. sprintf(buf, fmt_msg, pn);                  // format information message
  133. VIDEO_CLR();                                // clear screen
  134. VIDEO_POS(31, 15);                          // center on the screen
  135. VIDEO_STRING(buf);                          // ..and give status
  136. if (f_read_g3(pn))                          // q. 1st page available?
  137.     qf = 1;                                 // a. no .. set quit flag
  138. x = y = 0;                                  // start at top left of page
  139. z = 1;                                      // set zoom to max level
  140. while (NOT qf)                              // loop until quit requested
  141.     {
  142.     if (k)                                  // q. need to show something?
  143.         f_show_part(x, y, z, pn);           // a. yes .. part of a page
  144.     while (NOT (k = get_key(NO_ALT)))       // wait for a key
  145.         ;                                   // ..before continuing
  146.     switch (k)                              // handle user's input
  147.         {
  148.         case LEFT:                          // left key
  149.             if ((x - 576) >= 0)             // q. can show more on left?
  150.                 x -= 576;                   // a. yes .. set up coordinate
  151.              else
  152.                 {
  153.                 k = 0;                      // else .. don't re-draw screen
  154.                 printf(BELL);               // ..but beep a little
  155.                 }
  156.             break;                          // ..then get next key
  157.         case RIGHT:                         // right key
  158.             if ((x + 576) < PELS)           // q. more to show on right?
  159.                 x += 576;                   // a. yes .. set up coordinate
  160.              else
  161.                 {
  162.                 k = 0;                      // else .. don't re-draw screen
  163.                 printf(BELL);               // ..but beep a little
  164.                 }
  165.             break;                          // ..then get next key
  166.         case HOME:                          // home key
  167.             x = y = 0;                      // reset pointers to top left
  168.             break;                          // ..and wait for next key
  169.         case END:                           // end key
  170.             x = 0;                          // get to left margin
  171.             y = LINES - 200;                // ..and bottom of page
  172.             break;                          // ..and wait for next key
  173.         case INSERT:                        // insert key
  174.         case '+':                           // ..or plus key
  175.             if (z > 1)                      // q. room to increase detail?
  176.                 z--;                        // a. yes .. change zoom
  177.              else
  178.                 {
  179.                 k = 0;                      // else .. don't re-draw screen
  180.                 printf(BELL);               // ..but beep a little
  181.                 }
  182.             break;                          // ..and wait for next key
  183.         case DELETE:                        // delete key
  184.         case '-':                           // ..or minus key
  185.             if (z < 3)                      // q. room to decrease detail?
  186.                 z++;                        // a. yes .. change zoom
  187.              else
  188.                 {
  189.                 k = 0;                      // else .. don't re-draw screen
  190.                 printf(BELL);               // ..but beep a little
  191.                 }
  192.             break;                          // ..and wait for next key
  193.         case UP:                            // up arrow key
  194.             if ((y - 200) >= 0)             // q. room to move up?
  195.                 y -= 200;                   // a. yes .. adjust coordinate
  196.              else
  197.                 {
  198.                 k = 0;                      // else .. don't re-draw screen
  199.                 printf(BELL);               // ..but beep instead
  200.                 }
  201.             break;                          // ..and get next key
  202.         case DOWN:                          // down arrow key
  203.         case CR:                            // carriage return
  204.             if ((y + 200) < LINES)          // q. room to move down?
  205.                 y += 200;                   // a. yes .. adjust coordinate
  206.              else
  207.                 {
  208.                 k = 0;                      // else .. don't re-draw screen
  209.                 printf(BELL);               // ..but beep instead
  210.                 }
  211.             break;                          // ..and get next key
  212.         case PAGE_UP:                       // page up
  213.             if (pn > 1)                     // q. previous page available?
  214.                 {                           // a. yes .. format prev page
  215.                 sprintf(buf, fmt_msg, --pn);// format information message
  216.                 VIDEO_CLR();                // clear screen
  217.                 VIDEO_POS(31, 15);          // center on the screen
  218.                 VIDEO_STRING(buf);          // ..and give status
  219.                 f_read_g3(pn);              // format previous page
  220.                 x = y = 0;                  // ..and set up indices
  221.                 }
  222.              else
  223.                 {
  224.                 k = 0;                      // else .. don't re-draw screen
  225.                 printf(BELL);               // ..but beep instead
  226.                 }
  227.             break;                          // ..and get next key
  228.         case PAGE_DOWN:                     // page down
  229.             if (pn < f_pgcnt)               // q. next page available?
  230.                 {                           // a. yes .. format prev page
  231.                 sprintf(buf, fmt_msg, ++pn);// format information message
  232.                 VIDEO_CLR();                // clear screen
  233.                 VIDEO_POS(31, 15);          // center on the screen
  234.                 VIDEO_STRING(buf);          // ..and give status
  235.                 f_read_g3(pn);              // format the page
  236.                 x = y = 0;                  // ..and set up indices
  237.                 }
  238.              else
  239.                 {
  240.                 k = 0;                      // else .. don't re-draw screen
  241.                 printf(BELL);               // ..but beep instead
  242.                 }
  243.             break;                          // ..and get next key
  244.         case ESC:                           // escape key
  245.             qf = 1;                         // set quit flag
  246.             break;                          // ..and exit loop
  247.         default:                            // error case
  248.             printf(BELL);                   // ring the bell
  249.             k = 0;                          // don't re-draw the screen
  250.             break;                          // ..and wait for next key
  251.         }
  252.     }
  253. VIDEO_SET_MODE(old_mode);                   // select old video mode
  254. return(ESC);                                // finally, rtn to caller
  255. }