# HG changeset patch # User boisy # Date 1093000257 0 # Node ID 00d6e3a479876c4344cda100e053c17a69278b44 # Parent 34bf8b64353a8a5659f63b61819047cf374561e2 Clock2 modules are now in separate files diff -r 34bf8b64353a -r 00d6e3a47987 level1/modules/clock2.asm --- a/level1/modules/clock2.asm Fri Aug 20 11:10:20 2004 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1243 +0,0 @@ -******************************************************************** -* Clock2 - Real-Time Clock Subroutines -* -* $Id$ -* -* -* RTC Specific Notes: -* -* Dallas Semiconductor DS1216 SmartWatch -* -* Wakeup sequence $C5 3A A3 5C C5 3A A3 5C -* -* Time byte sequence in Binary Coded Decimal -* -* byte bit 7 6 5 4 3 2 1 0 -* 0 | 0.1 sec MSB | 0.1 sec LSB | -* 1 | 0 | 10 sec | seconds | -* 2 | 0 | 10 min | minutes | -* 3 |12/24| 0 | AM/PM | HR | Hour | -* | 10 HR | Hour | -* 0=12, 1=24 0=AM, 1=PM -* 4 | 0 | 0 | OSC |RESET| 0 | Weekday | -* 5 | 0 | 0 | 10 Date | Date | -* 6 | 0 | 0 | 0 |10 Month| Month | -* 7 | 10 Year | Year | -* -* OSC = 1; turns off clock to save battery. RESET not used in Coco circuit. -* -* When inserted in external ROM socket, the clock is addressed at: -* $C000 bit = 0 -* $C001 bit = 1 -* $C004 read byte to wakeup then send wakeup sequence to bit toggles. -* Then either read or send time. -* -* -* Edt/Rev YYYY/MM/DD Modified by -* Comment -* ------------------------------------------------------------------ -* 1 2003/08/18 Boisy G. Pitre -* Stripped from clock.asm in order to modularize clocks. -* -* 2004/07/13 Robert Gault -* Added Vavasour/Collyer emulator & MESS (Disto) versions and relocated -* 'GetTime equ' statement so it is not within a chip heading. -* -* 2004/07/28 Robert Gault -* Complete rewrite of SmartWatch segment which would never have worked. -* See previous versions for old code if desired. Routine now will search -* through all MPI slots to find clock and accept either AM/PM or military -* time. User notified if clock not found or data memory not available. -* -* Initialization routine contains code that bypasses OS-9 system calls to -* acquire needed low RAM that can't become ROM. This type of code is not -* recommended in most cases but nothing else was usable. -* 2004/07/31 Robert Gault -* Added a settime routine and changed "no clock found" routine. If the -* clock is not found, the D.Time entries are cleared but no message is sent. -* Date -t will never get passed one minute. -* 2004/07/31 Rodney Hamilton -* Improved RTCJVEmu code, conditionalized RTC type comments. -* 2004/08/2 Robert Gault -* Alphabetized all clock listings so things can be found much more easily. -* Placed list of clock types at beginning of source for record keeping. - - nam Clock2 - ttl Real-Time Clock Subroutines - - ifp1 - use defsfile - endc - -*--------------------------------------------------------------------------- -* Setup for specific RTC chip -* -* CHIP TYPES INCLUDED: -* -* RTCBB+RTCCloud9 -* RTCDriveWire -* RTCDsto2+RTCDsto4 -* RTCElim -* RTCHarrs -* RTCJVEmu -* RTCMESSEmu -* RTCSmart -* RTCSoft - - IFNE RTCBB+RTCCloud9 - IFNE RTCBB -RTC.Base equ $FF5C In SCS* Decode - ELSE -RTC.Base equ $FF7C Fully decoded RTC - ENDC -RTC.Zero equ -4 Send zero bit by writing this offset -RTC.One equ -3 Send one bit by writing this offset -RTC.Read equ 0 Read data from this offset - ENDC - - IFNE RTCDriveWire -RTC.Base equ $0000 - ENDC - - IFNE RTCDsto2+RTCDsto4 -RTC.Base equ $FF50 Base address of clock - ENDC - - IFNE RTCElim -RTC.Sped equ $20 32.768 KHz, rate=0 -RTC.Strt equ $06 binary, 24 Hour, DST disabled -RTC.Stop equ $86 bit 7 set stops clock to allow setting time -RTC.Base equ $FF72 I don't know base for this chip. - ENDC - - IFNE RTCHarrs -RTC.Base equ $FF60 Base address for clock - ENDC - - IFNE RTCJVEmu -RTC.Base equ $FFC0 - ENDC - - IFNE RTCMESSEmu -RTC.Base equ $FF50 - ENDC - - IFNE RTCSmart -RTC.Base equ $C000 clock mapped to $C000-$DFFF; $FFA6 MMU slot -RTC.Zero equ 0 Send zero bit -RTC.One equ 1 Send ones bit -RTC.Read equ 4 -*D.SWPage on system DP; Refer to os9defs. -D.RTCSlt equ 0 on SmartWatch ?data? page -D.RTCFlg equ 1 on SW page -D.RTCMod equ 2 -D.Temp equ 3 on SW page, holds "clock" data -D.Start equ 4 on SW page, code starts here - ENDC - - IFNE RTCSoft -RTC.Base equ 0 Have to have one defined. - ENDC - -*------------------------------------------------------------ -* -* Start of module -* - mod len,name,Sbrtn+Objct,ReEnt+0,JmpTable,RTC.Base - -name fcs "Clock2" - fcb 1 - - IFNE MPIFlag -SlotSlct fcb MPI.Slot-1 Slot constant for MPI select code - ENDC - -* Jump table for RTC -* -* Entry points: -* - Init -* - SetTime -* - GetTime -JmpTable - lbra Init - bra GetTime - nop - lbra SetTime - -*-------------------------------------------------------------------------- -* GetTime Subroutine -* -* This subroutine is called by the main clock module. -* - -GetTime equ * - - IFNE RTCBB+RTCCloud9 -* -* Update time from B&B RTC -* - pshs u,y,cc - leay ReadBCD,pcr Read bytes of clock - -TfrTime orcc #IntMasks turn off interrupts - ldu M$Mem,pcr Get base address - - IFNE MPIFlag - ldb >MPI.Slct Select slot - pshs b - andb #$F0 - orb SlotSlct,pcr - stb >MPI.Slct - ENDC - - lbsr SendMsg Initialize clock - ldx #D.Sec - ldb #8 Tfr 8 bytes - -tfrloop jsr ,y Tfr 1 byte - - bitb #$03 - beq skipstuf Skip over day-of-week, etc. - leax -1,x -skipstuf decb - bne tfrloop - - IFNE MPIFlag - puls b - stb >MPI.Slct restore MPAK slot - ENDC - - puls u,y,cc,pc - -ClkMsg fcb $C5,$3A,$A3,$5C,$C5,$3A,$A3,$5C -* Enable clock with message $C53AA35CC53AA35C -SendMsg lda RTC.Read,u Send Initialization message to clock - leax $FFD9 2 MHz (Really should check $A0 first) - puls cc,b - - IFNE MPIFlag - stb >MPI.Slct Restore saved "currently" selected MPak slot - ENDC - - clrb - rts - -RTCPre orcc #IntMasks - - IFNE MPIFlag - ldb >MPI.Slct Save currently selected MPak slot on stack - stb 3,s - andb #$F0 - orb >SlotSlct,pcr Get slot to select - stb >MPI.Slct Select MPak slot for clock - ENDC - - ldy #D.Time - ldx M$Mem,pcr - clr 1,x - ldb #12 - clr >$FFD8 1 MHz - rts - -GetVal stb 2,x - decb - lda ,x read tens digit from clock - anda #$0f -GetVal1 pshs b save b - ldb #10 - mul multiply by 10 to get value - stb ,y save 10s value - puls b set up clock for ones digit - stb 2,x - decb - lda ,x read ones digit from clock - anda #$0f - adda ,y add ones + tens - sta ,y+ store clock value into time packet - rts - - ENDC - - IFNE RTCDsto4 -* -* Disto 4-in-1 RTC time update -* - IFNE MPIFlag - pshs cc Save old interrupt status and mask IRQs - orcc #IntMasks - ldb >MPI.Slct Save currently selected MPak slot on stack - pshs b - andb #$F0 - orb >SlotSlct,pcr Select MPak slot for clock - stb >MPI.Slct - ENDC - - ldx M$Mem,pcr - ldy #D.Time Start with seconds - - ldb #11 - bsr GetVal Get Year - bsr GetVal Get Month - bsr GetVal Get Day - lda #3 Mask tens digit of hour to remove AM/PM bit - bsr GetVal1 Get Hour - bsr GetVal Get Minute - bsr GetVal Get Second - - IFNE MPIFlag - puls b Restore saved "currently" selected MPak slot - stb >MPI.Slct - puls cc,pc Restore previous IRQ status - ELSE - rts No MPI, don't need to mess with slot, CC - ENDC - -GetVal lda #$0f Mask to apply to tens digit -GetVal1 stb 1,x - decb - anda ,x read ones digit from clock - pshs b save b - ldb #10 - mul multiply by 10 to get value - stb ,y Add to ones digit - puls b - stb 1,x - decb - lda ,x read tens digit from clock and mask it - anda #$0f - adda ,y - sta ,y+ - rts - ENDC - - IFNE RTCElim -* -* Eliminator time update (lacks MPI slot select ability) -* - ldx M$Mem,pcr get RTC base address from fake memory requirement - ldb #$0A UIP status register address - stb ,x generate address strobe - lda 1,x get UIP status - bpl NoUIP Update In Progress, go shift next RTC read - lda #TkPerSec/2 set up next RTC read attempt in 1/2 second - sta xx70 then its 19xx - bhi not20 - adda #100 - sta -1,y -not20 bsr getval month - bsr getval day - lda #7 AM/PM mask - stb 1,x - anda ,x - bitb #4 - pshs cc - anda #3 - bsr getval1 - puls cc - beq AM - lda #12 convert to 24hr time as it is PM - adda -1,y - sta -1,y -AM bsr getval minute -* and now fall through into get second -getval lda #$0f - stb 1,x - anda ,x -getval1 decb - pshs b - ldb #10 - mul - stb ,y - puls b - stb 1,x - decb - lda ,x - anda #$0f - adda ,y - sta ,y+ -* rts fall thru to Setime/Init rts - ENDC - - IFNE RTCSmart -* -* Update time from Smartwatch RTC -* - - pshs cc,d,x,y,u - orcc #$50 - lda D.SWPage - clrb - tfr d,u point to working space - lda $FF7F - pshs a - lda D.RTCSlt,u info for MPI slot - sta $FF7F - clr D.RTCMod,u set for read time - jsr D.Start,u jsr to it - lbra exit - ENDC - - IFNE RTCSoft -* -* -* Software time update -* -* - lda MPI.Slct Save currently selected MPak slot - pshs b - andb #$F0 - orb >SlotSlct,pcr Get slot to select - stb >MPI.Slct Select MPak slot for clock - ENDC - - ldy #D.Time+6 - ldx M$Mem,pcr - clrb - bsr SetVal Set Second - bsr SetVal Set Minute - bsr SetVal Set Hour - bsr SetVal Set Day - bsr SetVal Set Month - bsr SetVal Set Year - - IFNE MPIFlag - puls b Restore old MPAK slot - stb >MPI.Slct - ENDC - - puls cc - clrb No error - rts - -SetVal clr ,-s Create variable for tens digit - lda ,-y Get current value -DvLoop suba #10 Get Tens digit on stack, ones digit in A - bcs DvDone - inc ,s - bra DvLoop -DvDone adda #10 - stb 1,x Set Clock address - incb - sta ,x Store ones digit - stb 1,x - incb - puls a - sta ,x Store tens digit - rts - ENDC - - IFNE RTCElim -* -* Set Eliminator RTC from D.Time -* - pshs cc save interrupt status - orcc #IntMasks disable IRQs - ldx M$Mem,pcr get RTC base address from fake memory requirement - ldy #D.Time point [Y] to time variables in DP - ldd #$0B*256+RTC.Stop - bsr UpdatCk0 stop clock before setting it - ldb #RTC.Sped - bsr UpdatCk0 set crystal speed, output rate - bsr UpdatClk go set year - bsr UpdatClk go set month - bsr UpdatClk go set day of month - bsr UpdatCk0 go set day of week (value doesn't matter) - bsr UpdatCk0 go set hours alarm (value doesn't matter) - bsr UpdatClk go set hour - bsr UpdatCk0 go set minutes alarm (value doesn't matter) - bsr UpdatClk go set minute - bsr UpdatCk0 go set seconds alarm (value doesn't matter) - bsr UpdatClk go set second - ldd #$0B*256+RTC.Strt - bsr UpdatCk0 go start clock - puls cc Recover IRQ status - clrb - rts - -UpdatClk ldb ,y+ get data from D.Time variables in DP -UpdatCk0 std ,x generate address strobe, save data - deca set [A] to next register down - rts - - IFGT Level-1 -* OS-9 Level Two code only (for now) -NewSvc fcb F$NVRAM Eliminator adds one new service call - fdb F.NVRAM-*-2 - fcb $80 end of service call installation table - -*------------------------------------------------------------ -* read/write RTC Non Volatile RAM (NVRAM) -* -* INPUT: [U] = pointer to caller's register stack -* R$A = access mode (1 = read, 2 = write, other = error) -* R$B = byte count (1 through 50 here, but in other implementations -* may be 1 through 256 where 0 implies 256) -* R$X = address of buffer in user map -* R$Y = start address in NVRAM -* -* OUTPUT: RTC NVRAM read/written -* -* ERROR OUTPUT: [CC] = Carry set -* [B] = error code -F.NVRAM tfr u,y copy caller's register stack pointer - ldd #$0100 ask for one page - os9 F$SRqMem - bcs NVR.Exit go report error... - pshs y,u save caller's stack and data buffer pointers - ldx R$Y,y get NVRAM start address - cmpx #50 too high? - bhs Arg.Err yes, go return error... - ldb R$B,y get NVRAM byte count - beq Arg.Err - abx check end address - cmpx #50 too high? - bhi Arg.Err yes, go return error... - lda R$A,y get direction flag - cmpa #WRITE. put caller's data into NVRAM? - bne ChkRead no, go check if read... - clra [D]=byte count - pshs d save it... - ldx D.Start+alrtend-reloc,y point to end of wakeup code - lda ,-x get D.Time data and store it - ldb #4 convert tenths sec, sec, min, hours - bsr binbcd to binary coded decimal - IFGT Level-1 - lda D.Daywk - ELSE - clra - ENDC - sta ,y+ set day of week if present - lda ,x - ldb #3 convert day of month, month, year - bsr binbcd to BCD - jsr >D.Start,u send data to clock - lbra exit - -binbcd pshs b -bcd3 clrb -bcd1 cmpa #10 - bcs bcd2 - addd #$f610 decrease bin regA by 10 add bcd $10 to regB - bra bcd1 -bcd2 pshs a - addb ,s+ add in remainder; BCD = binary when less than 10 - stb ,y+ place in message to clock - lda ,-x get next byte of D.Time - dec ,s decrease counter - bne bcd3 - puls b,pc - -* This becomes D.Start -reloc equ * - IFGT Level-1 - lda D.HINIT - anda #$CC - sta $FF90 - ENDC - ldb $FFA6 choose to use normal location - pshs b - ldb #$3E - stb $FFA6 reset MMU for clock - sta $FFDE - ldd #RTC.Base - tfr a,dp DP now points to clock - tst D.RTCMod,u are we reading the clock or setting it? - beq findclk go if reading - lbsr wakeup we are setting a found clock - lbra found -findclk lda #-1 - sta alrtend,pcr - lbsr wakeup wakeup the clock - ldx #D.Sec one incoming byte dropped - lda #8 bytes to get - pshs a -L0050 ldb #8 bits to get -L0052 lsr