; EMXGTPLS.MAC - Clock routine is for CP/M Plus by George Peace 6/84 ; Based on a routine written by Simon Ewins ; ; Routine must exit with labels TIME and DATE filled with ASCII time and ; and date strings. ; ; The labels, TIME, DATE, GETTIM, BTIME and BDATE must be public so that ; L80 and the EMXSUBS.REL files can find them. ; ;------------------- WARNING -- do not change -------------------------- ; ; .Z80 ; TIME:: DB 'HH:MM:SS',0 ; <<-- do not change DATE:: DB 'MM/DD/YY',0 ; <<-- do not change BDATE:: DB 0,0,0 ; <<-- do not change BTIME:: DB 0,0,0 ; <<-- do not change ; GETTIM:: ; <<-- do not change ; ;----------------- Start your clock routine here ----------------------- ; MVI C,105 LXI D,DATTIM CALL 5 ; LXI D,DATTIM+2 LXI H,TIME CALL @TCVRT ; LHLD DATTIM CALL @DCVRT ; RET ; DATTIM::DS 4 ; ;TIME.ASM ; ; This module will take the time in BCD format and change it into human- ; readable form. ; ; Input: DE points to a three byte area containing hours, minutes, and ; seconds in BCD (like in DR's SCB). HL points to an eight byte area to ; receive the time output. The area pointed to by HL will contain the ; time in format HH:MM:SS ; @TCVRT: PUSH H ; Save the caller's environment PUSH D PUSH B PUSH PSW ; ; Insert time into buffer at HL ; MVI B,2 ; TIME1: LDAX D INX D CALL PUTBCD ; Insert hh:mm: MVI M,':' INX H DCR B JNZ TIME1 LDAX D CALL PUTBCD ; Insert seconds POP PSW ; Restore the caller's environment POP B POP D POP H RET ; ; Convert BCD in A to two ASCII charcters at HL ; PUTBCD: PUSH PSW RRC RRC RRC RRC ; Get high nibble CALL PUTNIB POP PSW CALL PUTNIB RET ; ; make ASCII and put into buffer ; PUTNIB: ANI 0FH ORI '0' MOV M,A INX H ; Next buffer location RET ; ;DATE.ASM v 1.10 10/26/83 ; ; This module will take the date in Digital Research format and change ; it into human-readable form. ; ; Input: The number of days since 01/01/78. DATE must be defined in the ; main module and be a structure of format "mm/dd/yy$" ; ; Output: The structure at DATE will contain the date in ASCII. ; ; The routine works, don't ask me why. If you think it's too kludgy or ; too big, feel free to change it. Just don't leave my name off the ASM ; file, ok? ; ; Enter with the number of days since 1-1-78 in HL ; @DCVRT: SHLD DRTIME ; Save it for now MVI B,78 ; Set years counter ; LOOP: CALL CKLEAP LXI D,-365 ; Set up for subtract JNZ NOLPY ; Skip if no leap year DCX D ; Set for leap year ; NOLPY: DAD D ; Subtract JNC YDONE ; Continue if years done MOV A,H ORA L JZ YDONE SHLD DRTIME ; Else save days count INR B ; Increment years count JMP LOOP ; And do again ; ; The years are now finished, the years count is in B and drtime holds ; the days (HL is invalid). ; YDONE: CALL CKLEAP ; Check if leap year MVI A,-28 JNZ FEBNO ; February not 29 days MVI A,-29 ; Leap year ; FEBNO: STA FEB ; Set february MOV A,B ; Get years count LXI H,DATE+7 ; Point to years field CALL STASHA ; Stash A into years field LHLD DRTIME ; Get days count LXI D,MTABLE ; Point to months table MVI B,0FFH ; Set up b for subtract MVI A,0 ; Set a for # of months ; MLOOP: PUSH PSW LDAX D ; Get month MOV C,A ; Put in C for subtract POP PSW SHLD DRTIME ; Save days count DAD B ; Subtract INX D ; Increment months counter INR A JC MLOOP ; And loop for next month ; ; The months are finished, days count is on stack. First, calculate the ; month. ; MDONE: MOV B,A ; Save months LHLD DRTIME MOV A,H ORA L JNZ NZD DCX D DCX D LDAX D CMA INR A MOV L,A SHLD DRTIME DCR B ; NZD: MOV A,B PUSH H LXI H,DATE+1 ; Point to months field CALL STASHA ; Put a into months field POP H ; Get days count back MOV A,L ; Into a LXI H,DATE+4 ; Point to day field ; ; Plug the accumulator into as decimal ; STASHA: PUSH B ; Save bc as counter MVI B,0 ; Initialize tens ; STL: CPI 10 ; > 10? JC GOT10 ; No, done SUI 10 ; Subtract 10 from A INR B ; Increment tens JMP STL ; And loop ; ; B has the tens, A has the units. Store the units first ; GOT10: ADI '0' ; Make ASCII MOV M,A ; Stash units MOV A,B ; Get tens ADI '0' ; Make ASCII DCX H ; Point to tens MOV M,A POP B ; Restore BC RET ; ; This routine checks for leap years. ; CKLEAP: MOV A,B ANI 0FCH CMP B RET ; ; This is the months table ; MTABLE: DB -31 ; January ; FEB: DB -28 ; February DB -31,-30,-31,-30 ; Mar-Jun DB -31,-31,-30 ; Jul-Sep DB -31,-30,-31 ; Oct-Dec ; DRTIME: DW 0 ; Temporary storage ; ;--------------------- End of your routine -----------------------------