home *** CD-ROM | disk | FTP | other *** search
/ The Pier Shareware 6 / The_Pier_Shareware_Number_6_(The_Pier_Exchange)_(1995).iso / 035 / cenvi29.zip / BATTMEM.CMM < prev    next >
Text File  |  1994-08-22  |  7KB  |  208 lines

  1. /*********************************************************************************
  2.  *** Battmem.bat - Display status saved in battery-backed memory registers.    ***
  3.  *** ver.2         This examples programs displays how to use CEnvi to read    ***
  4.  ***               data from hardware ports, and how to manipulate bits within ***
  5.  ***               a byte.                                                     ***
  6.  *********************************************************************************/
  7.  
  8. printf("These are values read from battery-operated memory:\n");
  9.  
  10. #define  CLOCK_ADDRESS_REG    0x70  // put address to read here
  11. #define  CLOCK_READ_REG       0x71  // read value from address
  12. #define  BLANK_LINE           printf("\n")
  13.  
  14. BLANK_LINE
  15. /*****************************************************/
  16. /* SHOW ERRORS THAT MAY OCCUR IN THE DIAGNOSTIC BYTE */
  17. /*****************************************************/
  18. #define  DIAGNOSTIC_REG_ADDRESS  0x0E
  19. #define  DIAG_BYTES_UNUSED       0x03
  20. #define  DATETIME_ERROR          0x04
  21. #define  HARD_DRIVE_ERROR        0x08
  22. #define  MEMSIZE_ERROR           0x10
  23. #define  BAD_CONFIG_BYTE         0x20
  24. #define  CHECKSUM_ERROR          0x40
  25. #define  DEAD_CLOCK_BATTERY      0x80
  26.  
  27. diag = ReadByte(DIAGNOSTIC_REG_ADDRESS) & ~DIAG_BYTES_UNUSED
  28. if ( 0 == diag )
  29.    printf("No errors in the Diagnostic Byte Structure.\n")
  30. else {
  31.    if ( diag & DATETIME_ERROR )
  32.       printf("Date or time incorrect!\a\n")
  33.    if ( diag & HARD_DRIVE_ERROR )
  34.       printf("Hard drive or controler error!\a\n")
  35.    if ( diag & MEMSIZE_ERROR )
  36.       printf("Memory size incorrect!\a\n")
  37.    if ( diag & BAD_CONFIG_BYTE )
  38.       printf("Configuration byte is incorrect!\a\n")
  39.    if ( diag & CHECKSUM_ERROR )
  40.       printf("Checksum incorrect!\a\n")
  41.    if ( diag & DATETIME_ERROR )
  42.       printf("Realtime battery clock is dead!\a\n")
  43. }
  44.  
  45. BLANK_LINE
  46. /*******************************/
  47. /* STATUS AT SYSTEM POWER DOWN */
  48. /*******************************/
  49. #define  POWERDOWN_REG     0x0F
  50. printf("Status at system powerdown = %d\n",ReadByte(POWERDOWN_REG))
  51.  
  52.  
  53. BLANK_LINE
  54. /***********************************/
  55. /* STATUS OF FIRST TWO DISK DRIVES */
  56. /***********************************/
  57. #define  DRIVETYPE_REG     0x10
  58. DriveTypes = ReadByte(DRIVETYPE_REG)
  59. printf("The first floppy drive is type: %s\n", FloppyDriveDescription(Bits(DriveTypes,4,4)) )
  60. printf("The second floppy drive is type: %s\n", FloppyDriveDescription(Bits(DriveTypes,0,4)) )
  61.  
  62. FloppyDriveDescription(type)
  63. {
  64.    switch( type ) {
  65.       case 0
  66.          description = "Not Installed"
  67.          break
  68.       case 1
  69.          description = "5-1/4, 320/360K"
  70.          break
  71.       case 2
  72.          description = "5-1/4, 1.2 meg"
  73.          break
  74.       case 3
  75.          description = "3-1/2, 720K"
  76.          break
  77.       case 4
  78.          description = "3-1/2, 1.44 meg"
  79.          break
  80.       case 5
  81.          description = "3-1/2, 2.88 meg"
  82.          break
  83.       default
  84.          sprintf(description,"Unknown drive type %d",type)
  85.          break
  86.    }
  87.    return(description)
  88. }
  89.  
  90.  
  91. BLANK_LINE
  92. /***************************************/
  93. /* SHOW TYPES OF FIRST TWO HARD DRIVES */
  94. /***************************************/
  95. #define  HARD_DRIVE_REG     0x12
  96. DriveTypes = ReadByte(HARD_DRIVE_REG)
  97. printf("Hard drive 1 is type: %s\n", HardDriveDescription(Bits(DriveTypes,4,4)) )
  98. printf("Hard drive 2 is type: %s\n", HardDriveDescription(Bits(DriveTypes,0,4)) )
  99.  
  100. HardDriveDescription(type)
  101. {
  102.    switch( type ) {
  103.       case 0
  104.          description = "Not Installed"
  105.          break
  106.       case 0xF
  107.          description = "Extended drive type"
  108.          break
  109.       default
  110.          sprintf(description,"%d",type);
  111.          break
  112.    }
  113.    return(description)
  114. }
  115.  
  116.  
  117. BLANK_LINE
  118. /**********************************/
  119. /* SHOW CONFIGURATION INFORMATION */
  120. /**********************************/
  121. #define  CONFIGURATION_REG    0x14
  122. #define  NO_DRIVE_OFFSET      0
  123. #define  COPROCESSOR_OFFSET   1
  124. #define  HARDDRIVE_ERROR_OFF  3
  125. #define  VIDEO_STARTUP_OFF    4
  126. #define  VIDEO_STARTUP_COUNT  2
  127. #define  DISK_DRIVE_COUNT_OFF 6
  128. #define  DISK_DRIVE_COUNT_NUM 2
  129. config = ReadByte(CONFIGURATION_REG)
  130. printf("At lease 1 disk drive is%s installed.\n",Bits(config,NO_DRIVE_OFFSET,1) ? "" : " NOT" )
  131. printf("Math coprocessor is%s installed.\n",Bits(config,COPROCESSOR_OFFSET,1) ? "" : " NOT" )
  132. if Bits(config,HARDDRIVE_ERROR_OFF,1)
  133.    printf("Hard drive or controller error.\n")
  134. printf("Video mode at startup is: ")
  135. switch( Bits(config,VIDEO_STARTUP_OFF,VIDEO_STARTUP_COUNT) ) {
  136.    case 0      printf("unknown.\n")                   break
  137.    case 1      printf("CGA/EGA/VGA, 40 columns.\n")   break
  138.    case 2      printf("CGA,EGA,CGA, 80 columns.\n")   break
  139.    case 3      printf("MDA/Hercules, 80 columns\n")   break
  140. }
  141. printf("Number of floppy disk drives = %d.\n",Bits(config,DISK_DRIVE_COUNT_OFF,DISK_DRIVE_COUNT_NUM))
  142.  
  143.  
  144. BLANK_LINE
  145. /***********************************************/
  146. /* SHOW MAIN MEMORY AND EXPANSION MEMORY SIZES */
  147. /***********************************************/
  148. #define  MEM_SIZE_REG         0x15
  149. #define  EXPANSION_MEM_REG    0x17
  150. #define  EXPANSION2_REG       0x30
  151. printf("Main memory size = %d K-bytes\n",ReadWord(MEM_SIZE_REG))
  152. printf("Expansion board's main memory size = %d K-bytes\n",ReadWord(EXPANSION_MEM_REG))
  153. printf("Expansion memory size = %d K-bytes\n",ReadWord(EXPANSION2_REG))
  154.  
  155.  
  156. BLANK_LINE
  157. /***********************************/
  158. /* SHOW HARD DISK EXTENDED TYPES ***/
  159. /***********************************/
  160. #define  EXTEND_HD1_REG 0x19
  161. #define  EXTEND_HD2_REG 0x1A
  162. printf("Hard disk 1, extended type: %d\n",ReadByte(EXTEND_HD1_REG));
  163. printf("Hard disk 2, extended type: %d\n",ReadByte(EXTEND_HD2_REG));
  164.  
  165.  
  166. BLANK_LINE
  167. /***************************/
  168. /* TIME, DATE, AND CENTURY */
  169. /***************************/
  170. #define  CENTURY_REG       0x32
  171. #define  CLOCK_STATUS_REG  0x0B
  172. century = ReadByte(CENTURY_REG)
  173. printf("Century is: %d%d00\n",Bits(century,4,4),Bits(century,0,4))
  174. clock = ReadByte(CLOCK_STATUS_REG)
  175. printf("Daylight savings time is%s in effect.\n",Bits(clock,0,1) ? "" : " not" )
  176. printf("Time is kept in %d hour format.",Bits(clock,1,1) ? 24 : 12 )
  177.  
  178. /***************************************************************/
  179. /* All done; wait until a key is pressed or the program closed */
  180. /***************************************************************/
  181. if ( defined(_WINDOWS_) )
  182.    getch();
  183.  
  184. /******************************************/
  185. /* UTILITY FUNCTIONS USED IN THIS PROGRAM */
  186. /******************************************/
  187.  
  188. Bits(ByteValue,BitOffset,BitCount)
  189.    // return specific bits in a byte, and shift them to the right.
  190. {
  191.    // clear all bits above BitCount
  192.    for ( mask = 0, i = 0; i < BitCount; i++ )
  193.       mask |= 1 << i
  194.    return((ByteValue >> BitOffset) & mask)
  195. }
  196.  
  197. ReadByte(RegisterAddress)
  198. {
  199.    outport(CLOCK_ADDRESS_REG,RegisterAddress)
  200.    return(inport(CLOCK_READ_REG))
  201. }
  202.  
  203. ReadWord(RegisterAddress)
  204. {
  205.    return( ReadByte(RegisterAddress) | ( ReadByte(RegisterAddress+1) << 8 ) )
  206. }
  207.  
  208.