home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / utils / sysutl / probe102.lbr / PROBSERN.CZ / PROBSERN.C
Encoding:
Text File  |  1986-12-28  |  5.5 KB  |  92 lines

  1. /******************************************************************************/
  2. /*      SERNO3.C        Version 1               Revision 00    2 January 1985 */
  3. /******************************************************************************/
  4.  
  5. /******************************************************************************/
  6. /*                              cpm_ser_num                                   */
  7. /*                  Copyright (c) 1985 by Paul M. Sittler                     */
  8. /*                  No rights reserved, or all rights reversed. . .           */
  9. /******************************************************************************/
  10. cpm_ser_num()
  11. {
  12. /******************************************************************************/
  13. /* SERNO3.C was inspired by SERNO2.ASM by Charles Horn, dtd 31 January 1984.  */
  14. /*      I coded it into 'c' so that I could add this function to some of my   */
  15. /* programs.  While I was at it, I thought I would write it up as a tutorial  */
  16. /* and show how 'c' could do most anything that could be done in assembler.   */
  17. /* The finished program, of course, is somewhat larger and a trifle slower    */
  18. /* than SERNO2.COM, but it took me a LOT less time to code it in 'c' than it  */
  19. /* would have taken me in assembler.  Enjoy, <pms>. . .                       */
  20. /*                                                                            */
  21. /* Notes and tutorial on the CP/M serial number:                              */
  22. /*                                                                            */
  23. /*    The CP/M serial number is located at the beginning of the BDOS Page     */
  24. /* of memory.  This is exactly six bytes ahead of the BDOS entry address      */
  25. /* that is accessed by the BDOS jump at 0005H.  It usually consists of        */
  26. /* three decimal numbers of the form nnn-nnnn-nn, or num1-num2-num3.  Num1    */
  27. /* and num3 are one-byte numbers, and num2 is a two byte number.  As an       */
  28. /* example, a serial number of (decimal) 123-4567-8,                          */
  29. /*      would be coded as (hexadecimal) 7B-11D7-08.                           */
  30. /*                                                                            */
  31. /*    At the actual BDOS Page location, the numbers would appear as:          */
  32. /*                                                                            */
  33. /*       At  (BDOS ENTRY - 6) >>>>---->   7B  08  00  00  11  D7              */
  34. /*                                        ||  ||  ||  ||  ||  ||              */
  35. /*           Serial Number num1  ---------++  ||  ||  ||  ||  ||              */
  36. /*           Serial Number num3  -------------++  ||  ||  ||  ||              */
  37. /*           Zero filled bytes   -----------------++--++  ||  ||              */
  38. /*           Serial Number num2  -------------------------++--++              */
  39. /*                                                                            */
  40. /*     The same number string is coded into MOVCPM.COM, starting at address   */
  41. /* (usually) 1200H.  When MOVCPM runs, it checks to see that these two numbers*/
  42. /* match.  If they do NOT match, MOVCPM reports "SYNCHRONIZATION ERROR" and   */
  43. /* quits.  This will prevent one from generating a system image in memory     */
  44. /* for customization.                                                         */
  45. /*                                                                            */
  46. /*     This program reads the BDOS entry address from the BDOS jump at 005H,  */
  47. /* sets a pointer to the beginning of the serial number, reads the serial     */
  48. /* number into memory, and prints them out.                                   */
  49. /*                                                                            */
  50. /******************************************************************************/
  51.  
  52. /******************************************************************************/
  53. /*                              local variables                               */
  54. /******************************************************************************/
  55.  
  56. int Bdos,               /* address in memory of the BDOS entry */
  57.      sernum_addr;       /* address in memory of the serial number */
  58. unsigned serno2;        /* unsigned so it can be bigger than +/- 32760 */
  59. char *ptr,              /* all purpose pointer */
  60.      serno1,            /* serno1 and two are only one byte numbers */
  61.      serno3;            /* so declare them as character */
  62.  
  63. /******************************************************************************/
  64. /*                              code starts here                              */
  65. /******************************************************************************/
  66.  
  67.     ptr = 6;                            /*set pointer to BDOS entry address */
  68.     Bdos = (*ptr++) + (*ptr++ << 8);    /* Bdos entry address */
  69.     sernum_address = Bdos - 6;          /* Back up six bytes */
  70.     ptr = sernum_address;               /* point to serial number address */
  71.     serno1 = (*ptr++);                  /* store value at pointer into serno1 */
  72.     serno3 = (*ptr++);
  73.     ptr += 2;                           /* skip those zeros */
  74.     serno2 = (*ptr++ << 8) + (*ptr);    /* Most significant bit first, */
  75.                     /* Least significant bit second. */
  76.  
  77.     printf("\n\tOperating system serial number is at location %04x.",
  78.                 sernum_address);
  79.     printf("\n\tserial number is %02x-%04x-%02x hex,",
  80.                 serno1,serno2,serno3);
  81.     printf("\n\t                or %d-%u-%03d decimal.\n",
  82.                 serno1,serno2,serno3);
  83. }
  84. 
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.