home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / alde_c / misc / lib / r_la4_01 / wpro1.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-12-23  |  2.1 KB  |  74 lines

  1. /* WPRO1.C - From page 355 of "Microsoft C Programming for      */
  2. /* the IBM" by Robert Lafore. This is a rudimentary one line    */
  3. /* word processor.                                              */
  4. /****************************************************************/
  5.  
  6. #include "dos.h"           /*for REGS definition*/
  7. #define TRUE 1
  8. #define COMAX 80           /*max num of cols*/
  9. #define R_ARRO 77
  10. #define L_ARRO 75
  11. #define VIDEO 0x10         /*video ROM BIOS service*/
  12. int col = 0;               /*cursor position*/
  13. int far *farptr;
  14. union REGS regs;           /*for ROM BIOS calls*/
  15.  
  16. main()
  17. {
  18. char ch;
  19.  
  20.    farptr = (int far *) 0xB0000000;    /*start of screen memory*/
  21.    clear();
  22.    cursor();                           /*position cursor*/
  23.    while(TRUE) {
  24.       if ((ch = getch()) == 0) {
  25.          ch = getch();                 /*read extended code*/
  26.          switch(ch) {
  27.             case R_ARRO:
  28.                if (col < COMAX)
  29.                   ++col;
  30.                break;
  31.             case L_ARRO:
  32.                if (col > 0)
  33.                   --col;
  34.                break;
  35.          }
  36.       }
  37.       else                             /*not extended code*/
  38.          if (col < COMAX)
  39.             insert(ch);                /*print char at col*/
  40.       cursor();                        /*reset cursor*/
  41.    }
  42. }
  43.  
  44. /* cursor */  /*move cursor to row = 0, col */
  45. cursor()
  46. {
  47.  
  48.    regs.h.ah = 2;                /* 'set cursor position service */
  49.    regs.h.dl = col;              /*column varies*/
  50.    regs.h.dh = 0;                /*always top row*/
  51.    regs.h.bh = 0;                /*page zero*/
  52.    int86(VIDEO, ®s, ®s);   /*call video int*/
  53. }
  54.  
  55. /* insert() */  /*inserts char at cursor position*/
  56. insert(ch)
  57. char ch;
  58. {
  59. int j;
  60.  
  61.    *(farptr + col) = ch | 0x700;       /*insert char*/
  62.    ++col;                              /*move cursor right*/
  63. }
  64.  
  65. /* clear */      /*clears screen using direct memory access*/
  66. clear()
  67. {
  68. int j;
  69.  
  70.    for(j = 0; j < 2000; j++)           /*fill screen mem with*/
  71.       *(farptr + j) = 0x0700;          /*zeros   (attrib=07) */
  72. }
  73.  
  74.