home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / microcrn / issue_32.arc / C.FIG < prev    next >
Text File  |  1979-12-31  |  4KB  |  129 lines

  1.  
  2. ((this is C Fig. 1))
  3.  
  4. main()
  5. {
  6.   system("copy c:\budget\taxes.wk c:\lotus");
  7.   system("cd \lotus");
  8.   exec("123.exe","");
  9.   system("copy c:\lotus\taxes.wk c:\budget");
  10.   system("del c:\lotus\taxes.wk");
  11. }
  12.  
  13. ((this is C Fig. 2))
  14.  
  15. filesend(source,target)
  16.  char *source.*target;
  17. {
  18.   int fout,fin;
  19.   char buffer[BUFSIZE];  /* set BUFSIZE as big as you'd like, for speed */
  20.  
  21.   if( (fout=open(source,0)) == -1) error(); /*or however you wish to */
  22.   if( (fin=creat(target,0) == -1) error();  /* handle errors */
  23.   while( write(fin,buffer,read(fout,buffer,BUFSIZE)) == BUFSIZE);
  24. }
  25.  
  26. ((C Figure 3 - An On Screen Clock))
  27.  
  28. ; Module for masm. DeSmet fans could go in-line with this.
  29. CODE        SEGMENT PUBLIC BYTE
  30.             ASSUME      CS:CODE ,DS:DATA
  31.             PUBLIC      _ourint,_putds
  32. savds       DW          ?              ;storage for DS
  33. _puts:      MOV         CS:savds,DS    ;storing DS in code segment
  34.             RET
  35. _ourint:    PUSH        AX        ;heck--save everything in sight
  36.             PUSH        BX        ;but let's use the subprogram's stack
  37.             PUSH        CX
  38.             PUSH        DX
  39.             PUSH        DI
  40.             PUSH        SI
  41.             PUSH        ES
  42.             PUSH        DS
  43.             PUSH        BP
  44.             MOV         DS,CS:savds
  45.             MOV         ES,CS:savds
  46.             CALL        _procss    ; calling C-code
  47.             POP         BP
  48.             POP         DS     ;restore everything again
  49.             POP         ES
  50.             POP         SI
  51.             POP         DI
  52.             POP         DX
  53.             POP         CX
  54.             POP         BX
  55.             POP         AX
  56.             IRET                     ;and back to subprogram
  57. /*************************/
  58.  
  59.           /* the C module */
  60. #include <regs.h >         /* header for interrupt structures */
  61. #define clkint 0x1c       /* clock interrupt */
  62. #define timeaddr 0x46C    /* ticks past midnight */
  63. #define scrseg 0xb800     /* video ram segment--you could test for this */
  64. #define offset  3840      /* position on screen = lower left corner */
  65. extern unsigned _code,_data;    /* obvious segment addresses */
  66. unsigned us[2],them[2],hand,index,tick,hour,minute,second;
  67. char time[]=
  68.   " \160 \160 \160:\160 \160 \160:\160 \160 \160 \160"; /*reverse video */
  69. long midtick;
  70. /**************************/
  71. procss()       /* interrupt handler itself: called by assembly code*/
  72. {
  73.   if(tick++%9) return; else tick=0;  /* look every half second */
  74.   peek(0,timeaddr,&midtick,4);       /* get tick count from low memory */
  75.   hour=midtick/65543;                /* 65543 ticks/hour */
  76.   midtick %= 65543;
  77.   minute = midtick/1092;
  78.   midtick %= 1092;
  79.   second = midtick/18;
  80.   time[2]=0x30+hour/10;    /* stuffing array for poking into video ram */
  81.   time[4]=0x30+hour%10;
  82.   time[8]=0x30+minute/10;
  83.   time[10]=0x30+minute%10;
  84.   time[14]=0x30+second/10;
  85.   time[16]=0x30+second%10;
  86.   poke(scrseg,offset,time,18); /* Who needs an operating system, anyway? */
  87.  }
  88. /******************/
  89. main(argc,argv)  /* put compound command line in quotes as argument */
  90.  int argc;
  91.  char **argv;
  92. {
  93.   int ourint();  /* declaring assembly language routine */
  94.  
  95.   if(argc != 2){
  96.      puts("USE: clock \"command_line\"\n");
  97.      exit(0);
  98.      }
  99.   putds();   /*assembly language routine for storing DS in CODE  segment */
  100.   peek(0,clkint*4,them,4);      /* preserve old interrupt */
  101.   us[0]=ourint;
  102.   us[1]=_code;
  103.   poke(0,clkint*4,us,4);        /* insert our own handler */
  104.   system(argv[1]);         /* run applications program */
  105.   poke(0,clkint*4,them,4); /*nice children clean up after playing */
  106. }
  107.  
  108.  
  109. ((C Figure 4 - Going All the Way))
  110.  
  111. main(argc,argv)
  112.  int argc;
  113.  char **argv;
  114. {
  115.   int ourint();
  116.   char *malloc();
  117.   unsigned topseg  /* bottom of freeable memory */
  118.   struct regs rr;
  119.  
  120.   putds();
  121.   us[0]=ourint;
  122.   us[1]=_code;
  123.   poke(0,clkint*4,us,4);
  124.   topseg = 1 +  (unsigned)malloc(0)/0x10 ; /*get paragraph boundary*/
  125.   rr.ax=0x3100;  /* terminate but stay resident */
  126.   rr.dx=topseg + _data - _code; /*program size, in paragraphs */
  127.   interrupt(0x21,&rr);   /* bye bye */
  128. }
  129.