80-Bus News

  

November–December 1984, Volume 3, Issue 6

Page 47 of 55

memory store REGS. The ‘C’ register of the Z80 points to the first clock port, and they are read in via an ‘INI’ instruction, which automatically increments ‘C’ and ‘HL’, decrements ‘B‘, and loops until ‘B’ is Zero. The values read are then ‘scanned’in turn, and ‘ANDed’ with 0FH to mask off the four high order bits, which are not determined by the R.T.C. chip. The data is then compared with 0FH. If it is equal to this value, then the clock register in question was updating when it was read. If the clock was updating, then REGS contains at least one invalid reading, so the registers are all read again. If the data is valid, it is converted to ASCII by adding 30H, and then it is put back into the same memory location in REGS again. All bytes in REGS are checked in this way. When all data is valid, the program then just has to set the data up in a printable form. Unfortunately, the order of the registers as read from the clock does not match too well the type of format that we normally use in the U.K. How the data is presented is a matter of preference, but I have chosen output in the format :–

Sat 25/04/84 18:33:55             i.e. – Day Name – Date – Time

If the day name is to be processed, the ‘DE’ register is pointed to the start of the name table, ‘BC’ is set to three, since the names are three characters long, and the ‘day of week’ value stored in REGS is read. The value read is then ‘multiplied’ by three and added to ‘HL’. Finally ‘DE’ is added to ‘HL’ so that the latter points to the correct name. If the value read back is either 0 or greater than 7, due to some error, the blank name of DAY0 is used. ‘DE’ is then set to point to the start of STRING, which will hold the formatted data for printing. The three byte name is then copied into STRING using ‘LDIR’, and ‘DE’ is incremented once more to point to the units of the day of the month. (i.e. To STRNG1.)

If the day name was not processed however, (i.e. NKBD was TRUE), then ‘DE’ is set to this value as a definite instruction. Two very similar routines follow, that move the two byte data values associated with Day of month, Month, Hour, Minutes and Seconds into the appropriate place in STRNG1. The ‘DE’ registers act as a pointer into the string, and ‘HL’ points to the data source in REGS. ‘B’ and ‘C’ act as counters. The code is commented and fairly straightforward, so it will not be described in greater detail here.

On completion of this code, the data will be in STRNG1, and possibly also STRING, ready to be printed on the screen. Before printing, the cursor must be set to the right place. SYS provides a store in its workspace called CURSOR that can be used to save the location of the cursor. To play safe, I decided to save whatever was in this store before I used it, in case it was holding data relevant to some other program that might be running when the clock is updated. The data in ‘CURSOR’ is copied to HL and then ‘PUSH’ed on to the stack. The current cursor location is then saved, using the ‘SAVCUR’ routine, The cursor is then temporarily turned off, using an IVC command, to stop it flashing as the clock display is updated.

The ‘SETCUR’ routine is then used to place the cursor at the clock display position in the top line of the screen. Thes position depends on whether the Day name is to be displayed. The ‘H’ register holds the row data, and ‘L’ the column. The data is then printed on the screen, using ‘HL’ to point to the source of the data to be printed from STRING/​STRNG1, and the SYS ‘CRTX’ routine is used to send each byte to the IVC. The routine stops when it finds the ‘0’ character that is used to mark the end of the output string.

Page 47 of 55