1 /* $NetBSD: pram.c,v 1.11 1996/10/21 05:42:29 scottr Exp $ */ 2 3 /*- 4 * Copyright (C) 1993 Allen K. Briggs, Chris P. Caputo, 5 * Michael L. Finch, Bradley A. Grantham, and 6 * Lawrence A. Kesteloot 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. All advertising materials mentioning features or use of this software 18 * must display the following acknowledgement: 19 * This product includes software developed by the Alice Group. 20 * 4. The names of the Alice Group or any of its members may not be used 21 * to endorse or promote products derived from this software without 22 * specific prior written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE ALICE GROUP ``AS IS'' AND ANY EXPRESS OR 25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 27 * IN NO EVENT SHALL THE ALICE GROUP BE LIABLE FOR ANY DIRECT, INDIRECT, 28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 */ 35 36 37 /* #include "stand.h" */ 38 #include <sys/types.h> 39 #ifdef DEBUG 40 #include <sys/systm.h> 41 #endif 42 #include <machine/viareg.h> 43 #include "pram.h" 44 #include "macrom.h" 45 46 #if DEBUG 47 static char *convtime(unsigned long t) 48 { 49 static long daypmon[] = { 31,28,31,30,31,30,31,31,30,31,30,31 }; 50 static char *monstr[] = {"January","February","March","April","May","June", 51 "July","August","September","October","November","December" }; 52 static char s[200]; 53 long year,month,day,hour,minute,seconds,i,dayperyear; 54 55 year=1904; 56 month=0; /* Jan */ 57 day=1; 58 hour=0; 59 minute=0; 60 seconds=0; 61 62 if(t == 0xffffffff) 63 return("<time value is -1>"); 64 65 while (t > 0) 66 { 67 if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) 68 { 69 dayperyear=366; 70 daypmon[1]=29; 71 } 72 else 73 { 74 dayperyear=365; 75 daypmon[1]=28; 76 } 77 i=dayperyear*60*60*24; 78 if (t >= i) 79 { 80 t-=i; 81 year++; 82 continue; 83 } 84 i=daypmon[month]*60*60*24; 85 if (t >= i) 86 { 87 t-=i; 88 month++; 89 continue; 90 } 91 i=60*60*24; 92 if (t >= i) 93 { 94 t-=i; 95 day++; 96 continue; 97 } 98 i=60*60; 99 if (t >= i) 100 { 101 t-=i; 102 hour++; 103 continue; 104 } 105 i=60; 106 if (t >= i) 107 { 108 t-=i; 109 minute++; 110 continue; 111 } 112 seconds=t; 113 t=0; 114 } 115 116 sprintf(s,"%s %ld, %ld %ld:%ld:%ld",monstr[month],day,year,hour,minute,seconds); 117 118 return s; 119 } 120 #endif 121 122 unsigned long 123 pram_readtime(void) 124 { 125 unsigned long timedata; 126 127 if (0 == jClkNoMem) 128 timedata = 0; /* cause comparision of MacOS boottime */ 129 /* and PRAM time to fail */ 130 else 131 timedata = getPramTime(); 132 #if DEBUG 133 printf("time read from PRAM: 0x%lx\n", timedata); 134 printf("Date and time: %s\n",convtime(timedata)); 135 #endif 136 137 return(timedata); 138 } 139 140 void 141 pram_settime(unsigned long time) 142 { 143 if (0 == jClkNoMem) 144 return; 145 else 146 return setPramTime(time); 147 } 148