Chk3
Listing index
Clock
Routine:        Clkset  
Function:       User sets clock
Called by:      Main
Calls:          Keyb
Entry:          None
Exit:           New time is in clksec,  clkmin, clkhrs, and 50Hz counter is reset
Preserved:      None


CLKSET  LD      IX,PRIBUF
        LD      IY,CLKSEC
        LD      B,6
        LD      C,8
        XOR     A
CLKST0  OUT     (C),A
        INC     C
        LD      (IX),A
        LD      (IY),A
        INC     IX
        INC     IY
        DJNZ    CLKST0
; Use Pribuf as temporary storage space and initialise all the time digits to zero, i.e midnight.
        LD      IY,CLKFLG
        LD      (IY),2
CLKST1  LD      A,(CLKDOT)
; Use of the Clkdot variable allows the current digit to be flashed at 1 Hz, similar to a cursor, using the digit blanking register, out 144.
        OR      A
        LD      A,54
        JR      NZ,CLKST2
        DEC     A
        DEC     A
CLKST2  OUT     (144),A
        CALL    KEYB
        CP      21
        JP      Z,CLKSTF
; If the Enter key is pressed, jump to the end.
        LD      E,10
        CP      2
        JR      NZ,CLKST3
        LD      E,4
; Use of the E register here allows the Hours to be checked according to the 10s of hours entered: if 2 is entered then the Hours must be less than 4, otherwise less than ten. The other digits are entered and checked in a similar way.
CLKST3  CP      3
        JR      NC,CLKST1
        OUT     (12),A
        LD      (CLKHRS+1),A
        OR      A
        LD      A,54
        JR      NZ,CLKST4
        DEC     A
        DEC     A
CLKST4  LD      (IX),A
CLKST5  LD      A,(CLKDOT)
        OR      A
        LD      A,(IX)
        JR      NZ,CLKST6
        SUB     A,4
CLKST6  OUT     (144),A
        CALL    KEYB
        CP      19
        JR      Z,CLKST1
; If the Clr key is pressed, move to the 10s of hours digit again.
        CP      21
        JP      Z,CLKSTF
        CP      E
        JR      NC,CLKST5
        OUT     (11),A
        LD      (CLKHRS),A
CLKST7  LD      A,(CLKDOT)
        OR      A
        LD      A,(IX)
        JR      NZ,CLKST8
        SUB     A,16
CLKST8  OUT     (144),A
        CALL    KEYB
        CP      19
        JR      Z,CLKST1
        CP      21
        JR      Z,CLKSTF
        CP      6
        JR      NC,CLKST7
        OUT     (9),A
        LD      (CLKMIN+1),A
CLKST9  LD      A,(CLKDOT)
        OR      A
        LD      A,(IX)
        JR      NZ,CLKSTA
        SUB     A,32
CLKSTA  OUT     (144),A
        CALL    KEYB
        CP      19
        JP      Z,CLKST1
        CP      21
        JP      Z,CLKSTF
        CP      10
        JR      NC,CLKST9
        OUT     (8),A
        LD      (CLKMIN),A
        LD      A,10
        OUT     (13),A
        INC     (IX)
CLKSTB  LD      A,(CLKDOT)
        OR      A
        LD      A,(IX)
        JR      NZ,CLKSTC
        DEC     A
CLKSTC  OUT     (144),A
; Get the time display format: an A entered here (default) will put the clock in Hours . Minutes mode, while B puts it in Hours.Minutes.Seconds mode.
        CALL    KEYB
        CP      19
        JP      Z,CLKST1
        CP      21
        JP      Z,CLKSTF
        CP      10
        JR      NZ,CLKSTD
        OUT     (13),A
        LD      (IY),2
        JR      CLKSTE
CLKSTD  CP      11
        JR      NZ,CLKSTB
        OUT     (13),A
        LD      (IY),1
        JR      CLKSTE
CLKSTE  JP      CLKST1
; Go back to the 10s of hours digit in case any digit needs to be changed by the user.
CLKSTF  IN      A,(6)
        LD      (CLK50),A
        XOR     A
        LD      (CLKSEC),A
        LD      (CLKSEC+1),A
; Reset the 50 Hz counter and initialise the seconds and tens of seconds to zero, then return.
        RET
 
Chk3
Listing index
Clock