Windows NT 4.0 source code leak
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

415 lines
8.9 KiB

4 years ago
  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. jztime.c
  5. Abstract:
  6. This module contains the code to set the Jazz time.
  7. Author:
  8. David M. Robinson (davidro) 25-Oct-1991
  9. Revision History:
  10. --*/
  11. #include "jzsetup.h"
  12. //
  13. // Static Data
  14. //
  15. PVOID JzEisaControlBase;
  16. PVOID JzRealTimeClockBase;
  17. ULONG LastTime = 0;
  18. UCHAR
  19. JzReadClockRegister (
  20. UCHAR Register
  21. )
  22. /*++
  23. Routine Description:
  24. This routine reads the specified realtime clock register.
  25. Arguments:
  26. Register - Supplies the number of the register whose value is read.
  27. Return Value:
  28. The value of the register is returned as the function value.
  29. --*/
  30. {
  31. UCHAR DataByte;
  32. //
  33. // Read the EISA NMI enable register, insert the realtime clock register
  34. // number, and write the value back to the EISA NMI enable register. This
  35. // selects the realtime clock register that is read.
  36. //
  37. DataByte = READ_REGISTER_UCHAR((PUCHAR)JzEisaControlBase + EISA_NMI);
  38. DataByte = (DataByte & 0x80) | Register;
  39. WRITE_REGISTER_UCHAR((PUCHAR)JzEisaControlBase + EISA_NMI, DataByte);
  40. //
  41. // Read the realtime clock register value.
  42. //
  43. DataByte = READ_REGISTER_UCHAR((PUCHAR)JzRealTimeClockBase);
  44. return DataByte;
  45. }
  46. VOID
  47. JzWriteClockRegister (
  48. UCHAR Register,
  49. UCHAR Value
  50. )
  51. /*++
  52. Routine Description:
  53. This routine writes the specified value to the specified realtime
  54. clock register.
  55. Arguments:
  56. Register - Supplies the number of the register whose value is written.
  57. Value - Supplies the value that is written to the specified register.
  58. Return Value:
  59. The value of the register is returned as the function value.
  60. --*/
  61. {
  62. UCHAR DataByte;
  63. //
  64. // Read the EISA NMI enable register, insert the realtime clock register
  65. // number, and write the value back to the EISA NMI enable register. This
  66. // selects the realtime clock register that is written.
  67. //
  68. DataByte = READ_REGISTER_UCHAR((PUCHAR)JzEisaControlBase + EISA_NMI);
  69. DataByte = (DataByte & 0x80) | Register;
  70. WRITE_REGISTER_UCHAR((PUCHAR)JzEisaControlBase + EISA_NMI, DataByte);
  71. //
  72. // Write the realtime clock register value.
  73. //
  74. WRITE_REGISTER_UCHAR((PUCHAR)JzRealTimeClockBase, Value);
  75. return;
  76. }
  77. VOID
  78. JzWriteTime (
  79. IN PTIME_FIELDS TimeFields
  80. )
  81. /*++
  82. Routine Description:
  83. This routine sets the realtime clock.
  84. N.B. This routine assumes that the caller has provided any required
  85. synchronization to set the realtime clock information.
  86. Arguments:
  87. TimeFields - Supplies a pointer to a time structure that specifies the
  88. realtime clock information.
  89. Return Value:
  90. If the power to the realtime clock has not failed, then the time
  91. values are written to the realtime clock and a value of TRUE is
  92. returned. Otherwise, a value of FALSE is returned.
  93. --*/
  94. {
  95. UCHAR DataByte;
  96. //
  97. // If the realtime clock battery is still functioning, then write
  98. // the realtime clock values, and return a function value of TRUE.
  99. // Otherwise, return a function value of FALSE.
  100. //
  101. DataByte = JzReadClockRegister(RTC_CONTROL_REGISTERD);
  102. if (((PRTC_CONTROL_REGISTER_D)(&DataByte))->ValidTime == 1) {
  103. //
  104. // Set the realtime clock control to set the time.
  105. //
  106. DataByte = 0;
  107. ((PRTC_CONTROL_REGISTER_B)(&DataByte))->HoursFormat = 1;
  108. ((PRTC_CONTROL_REGISTER_B)(&DataByte))->DataMode = 1;
  109. ((PRTC_CONTROL_REGISTER_B)(&DataByte))->SetTime = 1;
  110. JzWriteClockRegister(RTC_CONTROL_REGISTERB, DataByte);
  111. //
  112. // Write the realtime clock values.
  113. //
  114. JzWriteClockRegister(RTC_YEAR, (UCHAR)(TimeFields->Year - 1980));
  115. JzWriteClockRegister(RTC_MONTH, (UCHAR)TimeFields->Month);
  116. JzWriteClockRegister(RTC_DAY_OF_MONTH, (UCHAR)TimeFields->Day);
  117. JzWriteClockRegister(RTC_DAY_OF_WEEK, (UCHAR)(TimeFields->Weekday + 1));
  118. JzWriteClockRegister(RTC_HOUR, (UCHAR)TimeFields->Hour);
  119. JzWriteClockRegister(RTC_MINUTE, (UCHAR)TimeFields->Minute);
  120. JzWriteClockRegister(RTC_SECOND, (UCHAR)TimeFields->Second);
  121. //
  122. // Set the realtime clock control to update the time.
  123. //
  124. ((PRTC_CONTROL_REGISTER_B)(&DataByte))->SetTime = 0;
  125. JzWriteClockRegister(RTC_CONTROL_REGISTERB, DataByte);
  126. return;
  127. } else {
  128. return;
  129. }
  130. }
  131. VOID
  132. JzSetTime (
  133. VOID
  134. )
  135. /*++
  136. Routine Description:
  137. Arguments:
  138. Return Value:
  139. --*/
  140. {
  141. UCHAR Character;
  142. ULONG Count;
  143. PTIME_FIELDS TimeFields;
  144. TIME Time;
  145. CHAR TimeString[80];
  146. CHAR DateString[80];
  147. PCHAR StartToken;
  148. PCHAR EndToken;
  149. GETSTRING_ACTION Action;
  150. //
  151. // Set addresses for RTC access.
  152. //
  153. JzEisaControlBase = (PVOID)EISA_IO_VIRTUAL_BASE;
  154. JzRealTimeClockBase = (PVOID)RTC_VIRTUAL_BASE;
  155. JzSetPosition( 3, 5);
  156. JzPrint(JZ_ENTER_DATE_MSG);
  157. do {
  158. Action = FwGetString( DateString,
  159. sizeof(DateString),
  160. NULL,
  161. 3,
  162. 5 + strlen(JZ_ENTER_DATE_MSG));
  163. if (Action == GetStringEscape) {
  164. return;
  165. }
  166. } while ( Action != GetStringSuccess );
  167. JzSetPosition( 4, 5);
  168. JzPrint(JZ_ENTER_TIME_MSG);
  169. do {
  170. Action = FwGetString( TimeString,
  171. sizeof(TimeString),
  172. NULL,
  173. 4,
  174. 5 + strlen(JZ_ENTER_TIME_MSG));
  175. if (Action == GetStringEscape) {
  176. return;
  177. }
  178. } while ( Action != GetStringSuccess );
  179. //
  180. // Get time
  181. //
  182. TimeFields = ArcGetTime();
  183. StartToken = DateString;
  184. if (*StartToken != 0) {
  185. EndToken = strchr(StartToken, '-');
  186. if (EndToken != NULL) {
  187. *EndToken = 0;
  188. TimeFields->Month = atoi(StartToken);
  189. StartToken = EndToken + 1;
  190. }
  191. EndToken = strchr(StartToken, '-');
  192. if (EndToken != NULL) {
  193. *EndToken = 0;
  194. TimeFields->Day = atoi(StartToken);
  195. StartToken = EndToken + 1;
  196. TimeFields->Year = atoi(StartToken);
  197. if (TimeFields->Year < 100) {
  198. if (TimeFields->Year < 80) {
  199. TimeFields->Year += 2000;
  200. } else {
  201. TimeFields->Year += 1900;
  202. }
  203. }
  204. }
  205. }
  206. StartToken = TimeString;
  207. if (*StartToken != 0) {
  208. EndToken = strchr(StartToken, ':');
  209. if (EndToken != NULL) {
  210. *EndToken = 0;
  211. TimeFields->Hour = atoi(StartToken);
  212. StartToken = EndToken + 1;
  213. }
  214. EndToken = strchr(StartToken, ':');
  215. if (EndToken != NULL) {
  216. *EndToken = 0;
  217. TimeFields->Minute = atoi(StartToken);
  218. StartToken = EndToken + 1;
  219. TimeFields->Second = atoi(StartToken);
  220. } else {
  221. TimeFields->Minute = atoi(StartToken);
  222. TimeFields->Second = 0;
  223. }
  224. }
  225. if (!RtlTimeFieldsToTime(TimeFields, &Time)) {
  226. JzSetPosition( 5, 5);
  227. JzPrint(JZ_ILLEGAL_TIME_MSG);
  228. JzPrint(JZ_PRESS_KEY2_MSG);
  229. ArcRead(ARC_CONSOLE_INPUT, &Character, 1, &Count);
  230. } else {
  231. RtlTimeToTimeFields( &Time, TimeFields);
  232. JzWriteTime(TimeFields);
  233. }
  234. }
  235. VOID
  236. JzShowTime (
  237. BOOLEAN First
  238. )
  239. /*++
  240. Routine Description:
  241. Arguments:
  242. First - If TRUE then don't check LastTime.
  243. Return Value:
  244. --*/
  245. {
  246. PTIME_FIELDS TimeFields;
  247. TIME Time;
  248. BOOLEAN Pm;
  249. ULONG ThisTime;
  250. //
  251. // Set addresses for RTC access.
  252. //
  253. JzEisaControlBase = (PVOID)EISA_IO_VIRTUAL_BASE;
  254. JzRealTimeClockBase = (PVOID)RTC_VIRTUAL_BASE;
  255. //
  256. // See if the time has changed since last time we were called. This is
  257. // for when the display is over the serial port, so we don't blast
  258. // characters out all the time.
  259. //
  260. ThisTime = ArcGetRelativeTime();
  261. if (!First && (ThisTime == LastTime)) {
  262. //
  263. // Stall to get rid of the "whistle" on Jazz.
  264. //
  265. JzStallExecution(1000);
  266. return;
  267. }
  268. LastTime = ThisTime;
  269. //
  270. // Get and display time.
  271. //
  272. TimeFields = ArcGetTime();
  273. JzSetPosition( 0, 44);
  274. JzPrint("%s, ", Weekday[TimeFields->Weekday]);
  275. JzPrint("%d-", TimeFields->Month);
  276. JzPrint("%d-", TimeFields->Day);
  277. JzPrint("%d ", TimeFields->Year);
  278. if (TimeFields->Hour >= 12) {
  279. Pm = TRUE;
  280. } else {
  281. Pm = FALSE;
  282. }
  283. if (TimeFields->Hour > 12) {
  284. TimeFields->Hour -= 12;
  285. } else if (TimeFields->Hour == 0) {
  286. TimeFields->Hour = 12;
  287. }
  288. JzPrint("%d:", TimeFields->Hour);
  289. JzPrint("%02d:", TimeFields->Minute);
  290. JzPrint("%02d ", TimeFields->Second);
  291. if (Pm) {
  292. JzPrint(JZ_PM);
  293. } else {
  294. JzPrint(JZ_AM);
  295. }
  296. //
  297. // Clear anything to the end of the line.
  298. //
  299. JzPrint("%cK", ASCII_CSI);
  300. return;
  301. }