3529H
"CLOCKZ"
LD DE,3593H
LET Register Pair DE = 3593H to point to the exit address.
352CH
PUSH DE
Save the contents of Register Pair DE to the top of the STACK.
352DH
IN A,(ECH)
Reset the clock latch by polling Port ECH and put the results into A.
NOTE: Port ECH is the Miscellaneous Controls port, which covers clock on/off (Bit 0), cassette motor on or off (Bit 1), double size video on or off (Bit 2), and special character set select of Kana or misc (Bit 3). Higher bits are used for the Model 4 only.
352FH
LD A,(4022H)
Check to see if the Cursor is on by loading (4022H) into A.
NOTE: 4022H holds the Cursor ON/OFF Flag and will be 0 if the cursor is off, or the the underscore character otherwise.
3532H
OR A
Since a LD command does not affect the flags, an OR A is necessary to the flags based on the contents Register A.
3533H
If A was zero, then the cursor is off and we do not need to blink it, so JUMP down to 3556H.
3535H
LD A,(401CH)
We need to blink th cursor but first check to see if the cursor is to blink by loading (401CH) into A.
NOTE: 401CH holds the Cursor Blink Switch and will be 0 for Blink, and anything else for No Blink.
3538H
OR A
Since a LD command does not affect the flags, an OR A is necessary to the flags based on the contents Register A.
3539H
If the system is set for BLINK MODE OFF, then JUMP down to 3556H.
353BH
LD HL,401AH
Load HL with 401AH.
NOTE: 401AH is the memory location that stores the cursor blink count.
353EH
DEC (HL)
Reduce the memory contents of (401AH) by one to lower the blink count.
NOTE: 401AH is the memory location that stores the cursor blink count.
353FH
If that reduced count is still not zero, don't blink and instead JUMP down to 3556H.
3541H
LD (HL),07H
If the reduced count is ZERO, then put an 07H into (401AH) to reset the blink counter.
3543H
Check to see if we are 2Mhz or 4 MHz by GOSUBing to 36A2H which checks to see if we are 2Mhz or 4 MHz, and if we are at 4 MHz - rotate the memory contents of (HL) left one bit. In either case, then RETurn.
3546H
INC HL
Bump HL. This will increase HL from 401AH to 401BH (the cursor blink flag: 0 = Off, Anything Else = On).
3547H
LD A,(HL)
Fetch the value of the CURSOR BLINK FLAG (pointed to by HL) into Register A.
3548H
XOR 01H
Whatever the CURSOR BLINK FLAG IS (on or off), flip it.
354AH
LD (HL),A
Put the toggled cursor blink status into the appropriate memory location.
354BH
LD HL,(4020H)
Poll (4020H) and put the result into HL.
NOTE: 4020H holds the current cursor position.
354EH
LD A,(4023H)
Fetch the memory contents of (4023H) into Register A.
NOTE: 4023H holds the cursor character.
3551H
If the CURSOR CHARACTER is NOT ZERO then skip the next instruction (i.e., don't change the cursor character to a space).
3553H
LD A,20H
LET Register A = the ASCII character for a SPACE (since the CURSOR CHARACTER is ZERO).
3555H
"CLOCK4"
LD (HL),A
Put the contents of Register A into the current cursor position (i.e., show the cursor).
3556H
"CLOCK5"
LD HL,4216H
LET Register Pair HL = 4216H.
NOTE: 4216H is the heartbeat counter.
3559H
DEC (HL)
Decrement the value held in memory at the location pointed to by Register Pair HL (i.e., the heartbeat counter of 30) by 1.
355AH
RET NZ
If the reduced heartbeat counter is NOT zero, then just RETURN.
355BH
LD (HL),1EH
If we're here, then the heartbeat counter was reduced to Zero. Put a 1EH (Decimal: 30) into the heatbeat counter.
NOTE: 30 is for a 60 Hertz system. If this was expressly going into a 50 Hertz system this would be 25 instead of 30.
355DH
Adjust for 2Mhz vs 4 MHz by GOSUBing to 36A2H which checks to see if we are 2Mhz or 4 MHz, and if we are at 4 MHz - rotate the memory contents of (HL) left one bit. In either case, then RETurn.
3560H
INC HL
Bump HL by 1. HL will now point to 4217H, which is the memory location that holds the SECONDS.
3561H
LD DE,0266H
Load DE with 0266H.
NOTE: 0266H points to the TIME DATA of the number of seconds in a minute, the number of minutes in an hour, and the number of hours in a day.
3564H
LD B,03H
Load B with a 03H, to set up a loop where we test seconds, minutes, and hours against their maximums.
3566H
"TIMLOP"
INC (HL)
Bump the number currently held in HL to increase the number stored there 1.
NOTE: If HL is 4217H then it is seconds, 4218H then it is minutes, 4217H then it is hours.
3567H
LD A,(DE)
Fetch the memory contents held at (DE) to get the maximum possible units for each time measure and put the result into A.
NOTE: 0266H points to the TIME DATA of the number of seconds in a minute, 0267H points to the number of mnutes in an hour, and 0268H points to the number of hours in a day.
3568H
SUB (HL)
Compare the maximum to what we have by subtracting that maximum from the value pointed at in (HL).
3569H
RET NZ
If there is no difference between what we have and the maximum then we are done and just RETURN.
356AH
LD (HL),A
If there is a difference, then put a 0 into HL and then continue on to bump the next highest thing (seconds to minutes, minutes to hours, hours to days).
356BH
INC HL
Bump HL.
NOTE: If HL is 4217H then it is seconds, 4218H then it is minutes, 4219H then it is hours, and 421AH then it is YEARS.
356CH
INC DE
Bump DE.
NOTE: 0266H points to the TIME DATA of the number of seconds in a minute, 0267H points to the number of mnutes in an hour, and 0268H points to the number of hours in a day.
356DH
Loop back to 3566H until the loop of 3 has been met, meaning that we have processed seconds, minutes, and hours.
If we are here, then HL is greater than or equal to the year, meaning it is a new day
356FH
INC HL
Bump HL one more time, to 421BH for the day.
NOTE: 421BH holds the current DAY portion of the date.
3570H
INC (HL)
Bump the DAY portion of the date.
3571H
INC HL
Bump HL one more time, to 421CH (which holds the current MONTH portion of the date).
3572H
LD A,(HL)
Get the month from memory location 421CH and put it into Register A.
3573H
DEC HL
Decrease HL back to to 421BH (to point to the DAY portion of the date).
3574H
DEC A
Decrease A by one to correct for 1's offset.
3575H
ADD A,E
LET A = A + E to get an offset to the maximum number of days in a month table.
3576H
LD E,A
LET E = A so that DE will point to the specific month's maximum number of days.
3577H
LD A,(DE)
Fetch the number of days in the specific month and put the result into A.
3578H
CP (HL)
Now that A holds the maximum number of days in this specific month, ComPare A to it to see if we are at the maximum. Results:
- If Register A equals that value, the Z FLAG is set.
- If A < that value, the CARRY FLAG will be set
- if A >= that value, the NO CARRY FLAG will be set.
3579H
RET NC
If all of this shows that the current day of the month is less than the maximum number of days in a month, then RETURN because we don't need to bump anything more.
357AH
LD A,(HL)
Load A with the current day of the month, as HL was pushed back to point to the day of the month at instruction 3571H.
357BH
CP 1EH
Compare A to 1E (Decimal: 30) to see if we are at the end of the month. Results:
- If Register A equals 30 (Decimal), the Z FLAG is set.
- If A < 30 (Decimal), the CARRY FLAG will be set
- if A >= 30 (Decimal), the NO CARRY FLAG will be set.
357DH
If A >= 30 (Decimal), then JUMP to 3585H to update the MONTH, but not the YEAR.
357FH
DEC HL
Decrement the value held in Register Pair HL by 1 to now point to 421AH (the current year).
3580H
LD A,(HL)
Fetch the value stored in the memory location pointed to by Register Pair HL (i.e., the current year) into Register A.
3581H
INC HL
Bump HL to 421BH (the current DAY).
3582H
AND 03H
Mask A (which is holding the year) with 03H (Binary: 00000011) to test for a leap year.
3584H
RET Z
If Z is set, then we are not in a leap year (because 04 and higher are turned off).
3585H
"DAYRST"
LD (HL),01H
Set to the first day of the month by putting a 1 into the memory location pointed to by HL (which is DAY).
3587H
INC HL
Bump HL to 421CH (i.e., the current month).
3588H
INC (HL)
Increase whatever is held in (HL) (the current month) by 1.
3589H
LD A,(HL)
Put the current MONTH into A.
358AH
SUB 0DH
Subract 0DH (Decimal: 13) from A to see if we are past December.
NOTE: This will test against a month 13. If A is < 13, then the CARRY FLAG will be set.
358CH
RET C
If it is NOT month 13 then RETURN to skip the next code which increases the YEAR.
358DH
LD (HL),01H
If we are here, then MONTH = 13, so set MONTH to 1.
358FH
DEC HL
Decrement HL to 421BH (i.e., the current day).
3590H
DEC HL
Decrement HL to 421AH (i.e., the current year).
3591H
INC (HL)
Increase whatever is held in (HL) (i.e., the current year), by 1.