minivmac4ios/Mini vMac/mnvm_core/RTCEMDEV.c

1 line
10 KiB
C
Raw Normal View History

2016-05-01 17:05:36 +00:00
/* 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) #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 #endif typedef struct { /* RTC VIA Flags */ ui3b WrProtect; ui3b DataOut; ui3b DataNextOut; /* RTC Data */ ui3b ShiftData; ui3b Counter; ui3b Mode; ui3b SavedCmd; #if HaveXPRAM ui3b Sector; #endif /* RTC Registers */ ui3b Seconds_1[4]; ui3b PARAMRAM[PARAMRAMSize]; } RTC_Ty; LOCALVAR RTC_Ty RTC; /* RTC Functions */ LOCALVAR ui5b LastRealDate; #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 && 0 EXPORTPROC DumpRTC(void); GLOBALPROC DumpRTC(void) { int Counter; dbglog_writeln("RTC Parameter RAM"); for (Counter = 0; Counter < PARAMRAMSize; Counter++) { dbglog_writeNum(Counter); dbglog_writeCStr(", "); dbglog_writeHex(RTC.PARAMRAM[Counter]); dbglog_writeReturn(); } } #endif GLOBALFUNC blnr RTC_Init(void) { int Counter; ui5b secs; 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 RTCinitPRAM RTC.PARAMRAM[0 + Group1Base] = 168; /* valid */ #if (CurEmMd == kEmMd_II) || (CurEmMd == kEmMd_IIx) RTC.PARAMRAM[2 + Group1Base] = 1; /* node id hint for printer port (AppleTalk) */ #endif RTC.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 == kEmMd_IIx) RTC.PARAMRAM[15 + Group1Base] = 1;