1 /* $NetBSD: pram.c,v 1.5 1995/02/15 23:55:54 briggs 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 "via.h" 39 #include "pram.h" 40 41 #if DEBUG 42 char *convtime(unsigned long t) 43 { 44 static long daypmon[] = { 31,28,31,30,31,30,31,31,30,31,30,31 }; 45 static char *monstr[] = {"January","February","March","April","May","June", 46 "July","August","September","October","November","December" }; 47 static char s[200]; 48 long year,month,day,hour,minute,seconds,i,dayperyear; 49 50 year=1904; 51 month=0; /* Jan */ 52 day=1; 53 hour=0; 54 minute=0; 55 seconds=0; 56 57 if(t == 0xffffffff) 58 return("<time value is -1>"); 59 60 while (t > 0) 61 { 62 if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) 63 { 64 dayperyear=366; 65 daypmon[1]=29; 66 } 67 else 68 { 69 dayperyear=365; 70 daypmon[1]=28; 71 } 72 i=dayperyear*60*60*24; 73 if (t >= i) 74 { 75 t-=i; 76 year++; 77 continue; 78 } 79 i=daypmon[month]*60*60*24; 80 if (t >= i) 81 { 82 t-=i; 83 month++; 84 continue; 85 } 86 i=60*60*24; 87 if (t >= i) 88 { 89 t-=i; 90 day++; 91 continue; 92 } 93 i=60*60; 94 if (t >= i) 95 { 96 t-=i; 97 hour++; 98 continue; 99 } 100 i=60; 101 if (t >= i) 102 { 103 t-=i; 104 minute++; 105 continue; 106 } 107 seconds=t; 108 t=0; 109 } 110 111 sprintf(s,"%s %d, %d %d:%d:%d",monstr[month],day,year,hour,minute,seconds); 112 113 return s; 114 } 115 #endif 116 117 unsigned long 118 pram_readtime(void) 119 { 120 unsigned long timedata; 121 122 timedata = getPramTime(); 123 #if DEBUG 124 printf("time read from PRAM: 0x%x\n", timedata); 125 printf("Date and time: %s\n",convtime(timedata)); 126 #endif 127 128 return(timedata); 129 } 130 131 void 132 pram_settime(unsigned long time) 133 { 134 return setPramTime(time); 135 } 136