home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1996 February / PCWK0296.iso / sharewar / dos / program / tdsk22sr / kbsec.c < prev    next >
C/C++ Source or Header  |  1995-06-04  |  4KB  |  92 lines

  1.  
  2. /*********************************************************************
  3. *                                                                    *
  4. *  KBSEC 1.2 - Utility to calc with high precision the data transfer *
  5. *              rate (the read data transfer read) in a ramdisk.      *
  6. *                                                                    *
  7. *                (C) 1992-1995 Ciriaco García de Celis               *
  8. *                                                                    *
  9. *  - Do not run this program with a cache program loaded; compile    *
  10. *    it in LARGE memory model with  «Test stack overflow»  option    *
  11. *    disabled. Use Borland C. This program has english messages.     *
  12. *                                                                    *
  13. *********************************************************************/
  14.  
  15. #include <stdio.h>
  16. #include <dos.h>
  17. #include <conio.h>
  18. #include <stdlib.h>
  19.  
  20. #define MAXBUF 64512L  /* 63 Kb  (no sobrepasar 64 Kb en un acceso) */
  21. #define TIEMPO 110L    /* 6 segundos * 18,2 ≈ 110 tics (error < 1%) */
  22. #define TM 18.2      /* cadencia de interrupciones del temporizador */
  23. #define HORA_BIOS MK_FP(0x40, 0x6c)    /* variable de hora del BIOS */
  24.  
  25. unsigned long ti, vueltas, far *cbios;
  26. unsigned segmento, tamsect, far *pantalla;
  27. unsigned char far *sbuffer;
  28. static unsigned tiempo;
  29. int unidad;
  30. void interrupt (*viejaIRQ0)();
  31.  
  32.  
  33. void interrupt nuevaIRQ0 () /* rutina ejecutada cada 55 ms */
  34. {
  35.    tiempo++;                /* incrementar nuestro contador de hora */
  36.    outportb (0x20,0x20);    /* EOI al controlador de interrupciones */
  37. }
  38.  
  39. void prep_hw (void)
  40. {
  41.   viejaIRQ0=getvect(8);      /* preservar vector de int. periódica */
  42.   setvect (8, nuevaIRQ0);    /* instalar nueva rutina de control   */
  43.   outportb (0x21, 0xfe);     /* inhibir todas las int. salvo timer */
  44. }
  45.  
  46. void rest_hw (unsigned long tiempo_transcurrido_con_reloj_parado)
  47. {
  48.   outportb (0x21, 0);         /* autorizar todas las interrupciones */
  49.   setvect (8, viejaIRQ0);     /* restaurar vector de int. periódica */
  50.   cbios=HORA_BIOS; *cbios+=tiempo_transcurrido_con_reloj_parado;
  51. }
  52.  
  53.  
  54. void main(int argc, char **argv)
  55. {
  56.   if (allocmem ((unsigned) ((MAXBUF+0x1800) >> 4), &segmento)!=-1) {
  57.     printf("\nInsufficient memory.\n"); exit(255); }
  58.  
  59.   sbuffer=MK_FP((segmento+0x100) & 0xff00 | 0x80, 0); /* 2Kb+n*4Kb */
  60.  
  61.   if (argc<2) { printf("\nChoose the drive to test.\n"); exit(1); }
  62.   unidad=(argv[1][0] | 0x20) - 'a';
  63.   if ((unidad<2) || (absread (unidad, 1, 0L, sbuffer)!=0)) {
  64.     printf ("\nChoose drive C or above with less than 32 Mb.\n");
  65.     exit (2); }
  66.  
  67.   tamsect = sbuffer[11] | (sbuffer[12]<<8);
  68.   ti = (long) tamsect * ((sbuffer[0x14] << 8) | sbuffer[0x13]);
  69.   if ((ti < MAXBUF) || (ti > 33554431L)) {
  70.     printf ("\nNeeds a disk from %2.0f Kb to 32 Mb\n", MAXBUF/1024.0);
  71.     exit (3); }
  72.  
  73.   textmode (C80); clrscr();
  74.   printf ("\nComputing speed (wait %2.0f sec.)...", TIEMPO/TM);
  75.  
  76.   pantalla=MK_FP((peekb(0x40,0x49)==7 ? 0xB000:0xB800), 0x140);
  77.  
  78.   prep_hw(); ti=tiempo=vueltas=0;
  79.   while (ti==tiempo); /* esperar pulso del reloj */ ti+=TIEMPO;
  80.  
  81.   while (ti >= tiempo)
  82.     if (absread (unidad, MAXBUF / tamsect, 0L, sbuffer)!=0) {
  83.       rest_hw(ti-tiempo); printf ("\nError reading the disk.\n");
  84.       exit(254); }
  85.     else if (!(vueltas++ & 7)) *pantalla++=0xf07;  /* "imprimir" */
  86.  
  87.   rest_hw(TIEMPO); clrscr();
  88.  
  89.   printf("\nKBSEC 1.2: Effective data transfer rate on drive %c:\
  90.     %6.0f Kb/sec.\n", unidad+'A',MAXBUF/1024.0*vueltas/(TIEMPO/TM));
  91. }
  92.