Routine: Alarm
Function: Check to see if next
measurement is due yet
Called by: pb3
Calls: None
Entry: None
Exit: Nxtsec adjusted if necessary; Z flag set if due
Preserved: None
ALARM LD IX,NXTSEC
LD IY,CLKSEC
LD B,6
ALM1 LD A,(IX)
CP (IY)
RET NZ
; Compare the alarm time with the current time and return with NZ flag set if they are not yet equal.
INC IX
INC IY
DJNZ ALM1
; If a measurement is due then compute the next alarm time.
ALM2 LD IX,NXTSEC
LD IY,CLKSEC
LD HL,LMMIN
LD A,(IY)
LD (IX),A
INC IX
INC IY
LD A,(IY)
LD (IX),A
; The next alarm time has the same seconds value as the current time. Now the alarm period minutes and hours (held in Lmmin and Lmhrs respectively) are added to the current time. Checks are made to ensure that the if the number of minutes overflows then ten is subtracted and the 10s of minutes variable adjusted accordingly, and so on for the other numbers.
INC IX
INC IY
LD A,(IY)
ADD A,(HL)
CP 10
JR C,ALM3
SUB A,10
ALM3 CCF
LD (IX),A
INC IX
INC IY
INC HL
LD A,(IY)
ADC A,(HL)
CP 6
JR C,ALM4
SUB A,6
ALM4 CCF
LD (IX),A
INC IX
INC IY
INC HL
LD A,(IY)
ADC A,(HL)
LD C,A
INC IY
INC HL
LD E,0
LD A,(IY)
ADD A,(HL)
; The hours addition is complicated by the fact that hours are counted in base 24. This is allowed for by computing the new alarm time in one byte, taking modulus 24, and then extracting the 10s of hours.
JR Z,ALM8
CP 1
JR NZ,ALM5
LD A,10
JR ALM8
ALM5 CP 2
JR NZ,ALM6
LD A,20
JR ALM8
ALM6 CP 3
JR NZ,ALM7
LD A,30
JR ALM8
ALM7 LD A,40
ALM8 ADD A,C
CP 24
JR C,ALM9
SUB A,24
ALM9 LD B,0
ALM10 CP 10
JR C,ALM11
SUB A,10
INC B
JR ALM10
ALM11 LD (IX),A
LD (IX+1),B
XOR A
; The zero flag is set if the measurement period has expired and a reading is due.
RET