home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / C / C80TCOG.ZIP / HEXDIR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-08  |  4.0 KB  |  190 lines

  1. /*    hexdir.c - dump extent 0 CP/M directory entries        */
  2. /*                    1982/08/17 19:16    */
  3. /*
  4.     Inspired by the assembly language routine HEXDIR in
  5. David E. Cortesi's INSIDE CP/M: A Guide for Users and Programmers,
  6. Holt, Rinehart and Winston, New York 1982, p. 226-227.
  7.  
  8. C version:
  9.  
  10.     Copyright 1982    William G. Hutchison, Jr.
  11.             P.O. Box 278
  12.             Exton, PA 19341-0278
  13.             U.S.A.
  14.  
  15.             CompuServe 70665,1307
  16.  
  17.  
  18.  
  19.  
  20.     This  program  may be used freely for any non-commercial
  21. purpose, provided that the user does  not  remove  or  alter
  22. this notice or the copyright statement.
  23.     Those  who  wish  to  sell  or lease this program, or to
  24. incorporate it into a product  for  sale  or  lease,  should
  25. apply to the author (above) for licensing information.
  26.     This  program  is  not  covered  by  a  warranty, either
  27. express or implied. The author shall not be responsible  for
  28. any  damages (including consequential) caused by reliance on
  29. the  materials  presented,  including  but  not  limited  to
  30. typographical errors or arithmetic errors.
  31.  
  32.     This version is for C/80 Version 2 from Software Toolworks.
  33.  
  34.  
  35.  */
  36.  
  37. #include "c80def.h"
  38.  
  39. #define DEFAULT_DRIVE 25
  40. #define SELECT_DRIVE 14
  41. #define SRCH_FIRST 17
  42. #define SRCH_NEXT 18
  43.  
  44. #include "printf.c"
  45.  
  46. /*    define the number of Bytes Per Line to be dumped:    */
  47. #define BPL 16
  48.  
  49. struct dir {            /* CP/M directory entry        */
  50.     char user;
  51.     char filename[8];
  52.     char type[3];
  53.     char extent;
  54.     char s1, s2, rec_count;
  55.     char map[16];
  56.     };
  57.  
  58. #define DIR_SIZE sizeof(struct dir)
  59.  
  60. struct fcb {            /* CP/M FCB entry        */
  61.     char drv;
  62.     char filename[8];
  63.     char type[3];
  64.     char extent;
  65.     char s1, s2, rec_count;
  66.     char map[16];
  67.     char rec, d1, d2, d3;
  68.     };
  69.  
  70. #define FCB_SIZE sizeof(struct fcb)
  71.  
  72.  
  73. static struct fcb *cpmfcb= 0x5C;
  74. static struct dir *cpmbuff=0x80;
  75.  
  76. main()
  77. {
  78. int drive, place;
  79. struct fcb *locfcb;
  80.  
  81. if    ((drive= cpmfcb->drv) == 0)
  82.     drive= bdos(DEFAULT_DRIVE, 0);
  83. else
  84.     drive--            /* 1..26 => 0..25        */;
  85.  
  86. init_fcb(locfcb= alloc(FCB_SIZE), '\0', "????????", "???", '\0');
  87.  
  88. printf("Extent-zero directory entries, drive %c.\n", 'A'+drive);
  89. bdos(SELECT_DRIVE, drive);
  90.  
  91. place= bdos(SRCH_FIRST, locfcb) & 0xFF;
  92. while    (place != 0xFF) {
  93.     printf("\n");
  94.     hex_dump(cpmbuff + place, DIR_SIZE);
  95.     place= bdos(SRCH_NEXT, locfcb) & 0xFF;
  96.     }
  97. }                /* end of main            */
  98.  
  99. hex_dump(base, len)
  100. char *base;
  101. int len;
  102. {
  103. char *p;
  104. int i;
  105.  
  106. for    (; len > 0; len-= BPL, base+= BPL) {
  107. /*
  108.     printf("%4x:", (unsigned)base);
  109.  */
  110.     for    (p= base, i= (len > BPL)? BPL : len; i > 0; i--)
  111.         printf(" %2x", peek(p++));
  112.     for    (i= BPL-len; i > 0; i--)
  113.         printf("   ");
  114.     printf("  ");
  115.     for    (p= base, i= (len > BPL)? BPL : len; i > 0; i--)
  116.         printf("%c", printable(*p++));
  117.     printf("\n");
  118.     }
  119. }                /* end of hex_dump        */
  120.  
  121. init_fcb(f, d, fn, ft, x)    /* initialize an FCB        */
  122. struct fcb *f;
  123. char d, *fn, *ft, x;
  124. {
  125. int i;
  126.  
  127. f->drv= d;
  128. strmove(fn, f->filename);
  129. strmove(ft, f->type);
  130. f->extent= x;
  131. f->s1= f->s2= f->rec_count= 0;
  132. for    (i= 16-1; i >= 0; i--)
  133.     f->map[i]= 0;
  134. }                /* end of init_fcb        */
  135.  
  136. peek(p)
  137. char *p;
  138. {return    (0xFF & *p);}
  139.  
  140. #ifdef ASCII
  141. printable(c)
  142. char c;
  143. {
  144. return    (32 <= c && c <= 127? c : '.');
  145. }
  146. #endif
  147.  
  148. strmove(from, to)        /* move string but not '\0'    */
  149. char   *from,*to;
  150. {
  151. while    (*from)
  152.     *to++= *from++;
  153. }                /* end of strmove        */
  154.  
  155. bdos(fcn, arg)            /* do BDOS function fcn with arg */
  156. unsigned fcn, arg;
  157. {
  158. arg;
  159. #asm
  160.     MOV    D,H
  161.     MOV    E,L
  162. #endasm
  163. fcn;
  164. #asm
  165.     MOV    C,L
  166.     CALL    5        ;CALL BDOS
  167.     PUSH    PSW        ;SAVE VALUE IF RETURNED IN A
  168.     PUSH    H        ;SAVE VALUE IF RETURNED IN HL
  169. #endasm
  170. switch    (fcn) {            /* is value already in HL?    */
  171.     case 12:
  172.     case 24:
  173.     case 27:
  174.     case 29:
  175.     case 31:
  176. #asm
  177.     POP    H        ;PUT VALUE BACK IN HL
  178.     POP    B        ;DISCARD VALUE FROM A
  179.     RET            ;AND SILENTLY STEAL AWAY
  180. #endasm
  181.     default:
  182. #asm
  183.     POP    H        ;DISCARD VALUE FROM HL
  184.     POP    PSW        ;RECOVER VALUE FROM A
  185.     MOV    L,A        ;PUT IT INTO HL
  186.     MVI    H,0
  187. #endasm
  188.     }
  189. }                /* end of bdos            */
  190.