/*
RTCEMDEV.c
Copyright (C) 2003 Philip Cummins, Paul C. Pratt
You can redistribute this file and/or modify it under the terms
of version 2 of the GNU General Public License as published by
the Free Software Foundation. You should have received a copy
of the license along with this file; see the file COPYING.
This file is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
license for more details.
*//*
Real Time Clock EMulated DEVice
Emulates the RTC found in the Mac Plus.
This code adapted from "RTC.c" in vMac by Philip Cummins.
*/#ifndef AllFiles#include"SYSDEPNS.h"#include"MYOSGLUE.h"#include"ENDIANAC.h"#include"EMCONFIG.h"#include"GLOBGLUE.h"#endif/* define _RTC_Debug */#ifdef _RTC_Debug#include<stdio.h>#endif#include"RTCEMDEV.h"#define HaveXPRAM (CurEmMd >= kEmMd_Plus)/*
ReportAbnormalID unused 0x0805 - 0x08FF
*/#if HaveXPRAM#define PARAMRAMSize 256#else#define PARAMRAMSize 20#endif#if HaveXPRAM#define Group1Base 0x10#define Group2Base 0x08#else#define Group1Base 0x00#define Group2Base 0x10#endiftypedefstruct{/* RTC VIA Flags */ui3bWrProtect;ui3bDataOut;ui3bDataNextOut;/* RTC Data */ui3bShiftData;ui3bCounter;ui3bMode;ui3bSavedCmd;#if HaveXPRAMui3bSector;#endif/* RTC Registers */ui3bSeconds_1[4];ui3bPARAMRAM[PARAMRAMSize];}RTC_Ty;LOCALVARRTC_TyRTC;/* RTC Functions */LOCALVARui5bLastRealDate;#ifndef RTCinitPRAM#define RTCinitPRAM 1#endif#ifndef TrackSpeed /* in 0..4 */#define TrackSpeed 0#endif#ifndef AlarmOn /* in 0..1 */#define AlarmOn 0#endif#ifndef DiskCacheSz /* in 1,2,3,4,6,8,12 *//* actual cache size is DiskCacheSz * 32k */#if (CurEmMd == kEmMd_II) || (CurEmMd == kEmMd_IIx)#define DiskCacheSz 1#else#define DiskCacheSz 4#endif#endif#ifndef StartUpDisk /* in 0..1 */#define StartUpDisk 0#endif#ifndef DiskCacheOn /* in 0..1 */#define DiskCacheOn 0#endif#ifndef MouseScalingOn /* in 0..1 */#define MouseScalingOn 0#endif#define prb_fontHi 0#define prb_fontLo 2#define prb_kbdPrintHi (AutoKeyRate + (AutoKeyThresh << 4))#define prb_kbdPrintLo 0#define prb_volClickHi (SpeakerVol + (TrackSpeed << 3) + (AlarmOn << 7))#define prb_volClickLo (CaretBlinkTime + (DoubleClickTime << 4))#define prb_miscHi DiskCacheSz#define prb_miscLo \ ((MenuBlink << 2) + (StartUpDisk << 4) \ + (DiskCacheOn << 5) + (MouseScalingOn << 6))#if dbglog_HAVE && 0EXPORTPROCDumpRTC(void);GLOBALPROCDumpRTC(void){intCounter;dbglog_writeln("RTC Parameter RAM");for(Counter=0;Counter<PARAMRAMSize;Counter++){dbglog_writeNum(Counter);dbglog_writeCStr(", ");dbglog_writeHex(RTC.PARAMRAM[Counter]);dbglog_writeReturn();}}#endifGLOBALFUNCblnrRTC_Init(void){intCounter;ui5bsecs;RTC.Mode=RTC.ShiftData=RTC.Counter=0;RTC.DataOut=RTC.DataNextOut=0;RTC.WrProtect=falseblnr;secs=CurMacDateInSeconds;LastRealDate=secs;RTC.Seconds_1[0]=secs&0xFF;RTC.Seconds_1[1]=(secs&0xFF00)>>8;RTC.Seconds_1[2]=(secs&0xFF0000)>>16;RTC.Seconds_1[3]=(secs&0xFF000000)>>24;for(Counter=0;Counter<PARAMRAMSize;Counter++){RTC.PARAMRAM[Counter]=0;}#if RTCinitPRAMRTC.PARAMRAM[0+Group1Base]=168;/* valid */#if (CurEmMd == kEmMd_II) || (CurEmMd == kEmMd_IIx)RTC.PARAMRAM[2+Group1Base]=1;/* node id hint for printer port (AppleTalk) */#endifRTC.PARAMRAM[3+Group1Base]=34;/*
serial ports config bits: 4-7 A, 0-3 B
useFree 0 Use undefined
useATalk 1 AppleTalk
useAsync 2 Async
useExtClk 3 externally clocked
*/RTC.PARAMRAM[4+Group1Base]=204;/* portA, high */RTC.PARAMRAM[5+Group1Base]=10;/* portA, low */RTC.PARAMRAM[6+Group1Base]=204;/* portB, high */RTC.PARAMRAM[7+Group1Base]=10;/* portB, low */RTC.PARAMRAM[13+Group1Base]=prb_fontLo;RTC.PARAMRAM[14+Group1Base]=prb_kbdPrintHi;#if (CurEmMd == kEmMd_II) || (CurEmMd ==