;STNDTE.M68               Convert Julian Date to MMDDYY Subroutine
;
; Author..............  Jalal E. Raissi
; Installation........  Mini-Microcomputer Consultants
; Last Date Modified..  April 14, 1984
; Reason for Change...  Added the System Date routine. JER
;
; Purpose.............  To edit dates in days since 01/01/00 form and return
;                       their value in MMDDYY format!
;
;       XCALL STNDTE,SNDDTE,RCVDTE,FLGDTE
;
; Where:
;       MAP1 SNDDTE,S,6
;       MAP1 RCVDTE,F,6
;       MAP1 FLGDTE,B,1
;
; And:
;       A4 = address of SNDDTE
;       A5 = address of RCVDTE
;       A2 = address of FLGDTE
;       D5 = RCVDTE
;

       SEARCH  SYS
       SEARCH  SYSSYM
       SEARCH  MMCRT
       SEARCH  TRM

VMAJOR=1.
VMINOR=1.
VSUB=0.
VEDIT=0.
VWHO=0.

       OBJNAM  .SBR

       PHDR    -1,PV$RSM,PH$REE!PH$REU

       CLR     D0              ; clear D0
       CLR     D1              ; clear D1
       CLR     D2              ; clear D2
       MOV     A3,A1           ; move A3 to A1
       MOVW    @A1,D1          ; look at the argument count
       CMPB    D1,#3           ; three arguments must be passed
       JLT     LESARG          ; if less, let'm know
       CLR     D4              ; clear index register
       MOVW    2(A1)[D4],D1    ; move argument type to D1
       CMPB    D1,#2           ; is it string?
       JNE     NOSTR           ; no, let'm know
       MOVL    4(A1)[D4],A4    ; move address of SNDDTE to A4
       MOVL    10(A1)[D4],D1   ; move size of SNDDTE to D1
       CMPB    D1,#6           ; must be at least 6 bytes
       JLT     SERROR          ; if less, let'm know
       ADD     #12,D4          ; step to the next argument passed
       MOVW    2(A1)[D4],D1    ; move argument type to D1
       CMPB    D1,#4           ; is it floating point?
       JNE     NOFLT           ; no, let'm know
       MOV     4(A1)[D4],A5    ; move address of RCVDTE to A5
       FFTOL   @A5,D5          ; move the 'JULIAN' date to D5
       ADD     #12,D4          ; step to the next argument passed
       MOVW    2(A1)[D4],D1    ; move argument type to D1
       CMPB    D1,#6           ; is it binary?
       JNE     NOBIN           ; no, let'm know
       MOV     4(A1)[D4],A2    ; move the address of FLGDTE to A2
       MOVB    @A2,D1          ; move FLGDTE to D1
       CMPB    D1,#2           ; System Date wished?
       BNE     FNDYER          ; if not, go to FNDYER
;:::::::::::::::::::::::::::
;       System Date        :
;:::::::::::::::::::::::::::
       CLR     D2              ; clear D2
       CLR     D3              ; clear D3
       CLR     D5              ; clear D5
       GDATES  D2              ; get System Date
       SWAP    D2              ; exchange halves
       MOVB    D2,D5           ; move month to D5
       MOV     D2,D3           ; move entire word to D3
       RORW    D3,#10          ; rotate 8 bits
       AND     #377,D3         ; get DAY
       SWAP    D2              ; exchange again
       AND     #377,D2         ; get YEAR
       JMP     ENDRTN          ; go to ENDRTN
;:::::::::::::::::::::::
;       FIND YEAR      :
;:::::::::::::::::::::::
FNDYER: CLR     D3              ; clear D3
       CMP     D5,#1           ; compare RCVDTE to 1!
       JLT     JERROR          ; if less, let'm know
       CMP     D5,#107254      ; compare RCVDTE to 36524.  YY=99!
       JGT     JERROR          ; if greater, let'm know
       MOV     D5,D0           ; move RCVDTE to work area
       MUL     D0,#144         ; multiply it by 100
       DIV     D0,#107255      ; divide by 36525 to get the year
       MOVB    D0,D2           ; save the year
       MOV     D2,D0           ; move it to work area
       DIV     D0,#4           ; divide it by 4
       MOVB    D0,D3           ; save the leap days
       MUL     D0,#4           ; multiply it by 4
       MOV     D0,D1           ; store in D1
       MOV     D2,D0           ; move the year to D0
       MUL     D0,#555         ; multiply it by 365
       CMP     D1,D2           ; is it a leap year?
       BNE     SKPDEC          ; if not, go to SKPDEC
       DEC     D3              ; why?
SKPDEC: ADD     D3,D0           ; add the leap days
       MOV     D5,D3           ; move RCVDTE to D3
       SUB     D0,D3           ; get days into this year
;:::::::::::::::::::::::::::::::::::
;       check for LEAP YEAR        :
;:::::::::::::::::::::::::::::::::::
       CMP     D1,D2           ; is it a leap year?
       BNE     MONTH           ; if not, go to MONTH
       CMP     D3,#75          ; past February?
       BGE     DECONE          ; skip fiddling!
       CMP     D3,#74          ; February 29?
       BNE     MONTH           ; if not, go to MONTH
       MOVB    #2,D5           ; month is February
       MOVB    #35,D3          ; number of days is 29
       JMP     ENDRTN          ; go to ENDRTN
DECONE: DEC     D3              ; subtract 1 for leap year
;::::::::::::::::::::::::::::::::
;       SORT OUT THE MONTH      :
;::::::::::::::::::::::::::::::::
MONTH:  MOV     D3,D4           ; store number of days in D4
       MOV     #1,D5           ; assume it is January
       SUB     #37,D4          ; take out 31 days
       CMP     D4,#1           ; anything left?
       JLT     ENDRTN          ; if not, go to ENDRTN
       MOV     D4,D3           ; update number of days left
       MOV     #2,D5           ; assume it is February
       SUB     #34,D4          ; take out 28 days
       CMP     D4,#1           ; anything left?
       JLT     ENDRTN          ; if not, go to ENDRTN
       MOV     D4,D3           ; update number of days left
       MOV     #3,D5           ; assume it is March
       SUB     #37,D4          ; take out 31 days
       CMP     D4,#1           ; anything left?
       JLT     ENDRTN          ; if not, go to ENDRTN
       MOV     D4,D3           ; update number of days left
       MOV     #4,D5           ; assume it is April
       SUB     #36,D4          ; take out 30 days
       CMP     D4,#1           ; anything left?
       JLT     ENDRTN          ; if not, go to ENDRTN
       MOV     D4,D3           ; update number of days left
       MOV     #5,D5           ; assume it is May
       SUB     #37,D4          ; take out 31 days
       CMP     D4,#1           ; anything left?
       JLT     ENDRTN          ; if not, go to ENDRTN
       MOV     D4,D3           ; update number of days left
       MOV     #6,D5           ; assume it is June
       SUB     #36,D4          ; take out 30 days
       CMP     D4,#1           ; anything left?
       JLT     ENDRTN          ; if not, go to ENDRTN
       MOV     D4,D3           ; update number of days left
       MOV     #7,D5           ; assume it is July
       SUB     #37,D4          ; take out 31 days
       CMP     D4,#1           ; anything left?
       JLT     ENDRTN          ; if not, go to ENDRTN
       MOV     D4,D3           ; update number of days left
       MOV     #10,D5          ; assume it is August
       SUB     #37,D4          ; take out 31 days
       CMP     D4,#1           ; anything left?
       JLT     ENDRTN          ; if not, go to ENDRTN
       MOV     D4,D3           ; update number of days left
       MOV     #11,D5          ; assume it is September
       SUB     #36,D4          ; take out 30 days
       CMP     D4,#1           ; anything left?
       JLT     ENDRTN          ; if no, go to ENDRTN
       MOV     D4,D3           ; update number of days left
       MOV     #12,D5          ; assume it is October
       SUB     #37,D4          ; take out 31 days
       CMP     D4,#1           ; anything left?
       JLT     ENDRTN          ; if not, go to ENDRTN
       MOV     D4,D3           ; update number of days left
       MOV     #13,D5          ; assume it is November
       SUB     #36,D4          ; take out 30 days
       CMP     D4,#1           ; anything left?
       JLT     ENDRTN          ; if not, go to ENDRTN
       MOV     D4,D3           ; update number of days left
       MOV     #14,D5          ; it must be December, then!
;::::::::::::::::::::::::::
;       END ROUTINE       :
;::::::::::::::::::::::::::
ENDRTN: CMPB    D5,#12          ; is it October?
       BLT     ZEROM           ; if less, go to ZEROM
       MOVB    #61,D0          ; set MONTH's 1st digit to 1
       MOV     D5,D1           ; move MONTH to work area
       SUBB    #12,D1          ; get MONTH's 2nd digit
       BR      FSTMM           ; go to FSTMM
ZEROM:  MOVB    #60,D0          ; set MONTH's 1st digit to 0
       MOV     D5,D1           ; move MONTH to work area
FSTMM:  MOVB    D0,(A4)+        ; move MONTH's 1st digit to SNDDTE[1,1]
       ADDB    #60,D1          ; ASCII 2nd digit
       MOVB    D1,(A4)+        ; move MONTH's 2nd digit to SNDDTE[2,2]
       CLR     D0              ; clear work area
       CMPB    D3,#12          ; is DAY 10?
       BLT     ZEROD           ; if not, go to ZEROD
       MOVB    D3,D0           ; move number of days this month to D0
       DIV     D0,#12          ; single out 1st digit
       MOVB    D0,D4           ; store it in D4
       MUL     D4,#12          ; multiply it by 10
       SUB     D4,D3           ; get DAY's 2nd digit
       MOV     D3,D1           ; put it in D1
       ADDB    #60,D0          ; ASCII DAY's 1st digit
       BR      FSTDD           ; go to FSTDD
ZEROD:  MOVB    #60,D0          ; set DAY's 1st digit to 0
       MOV     D3,D1           ; move DAY's 2nd digit to D1
FSTDD:  MOVB    D0,(A4)+        ; move DAY's 1st digit to SNDDTE[3,3]
       ADDB    #60,D1          ; ASCII 2nd digit
       MOVB    D1,(A4)+        ; move DAY's 2nd digit to SNDDTE[4,4]
       CLR     D0              ; clear work area
       CMPB    D2,#12          ; is YEAR 10?
       BLT     ZEROY           ; if less, go to ZEROY
       MOV     D2,D0           ; move YEAR to D0
       DIV     D0,#12          ; single out YEAR's 1st digit
       MOV     D0,D4           ; move it to D4
       MUL     D4,#12          ; multiply it by 10
       SUB     D4,D2           ; get YEAR's 2nd digit
       MOV     D2,D1           ; put it in D1
       ADDB    #60,D0          ; ASCII YEAR's 1st digit
       BR      FSTYY           ; go to FSTYY
ZEROY:  MOVB    #60,D0          ; set YEAR's 1st digit to 0
       MOV     D2,D1           ; move YEAR's 2nd digit to D1
FSTYY:  MOVB    D0,(A4)+        ; move YEAR's 1st digit to SNDDTE[5,5]
       ADDB    #60,D1          ; ASCII 2nd digit!
       MOVB    D1,(A4)+        ; move YEAR's 2nd digit to SNDDTE[6,6]
;:::::::::::::::::::::::::::::::
;       go back to BASIC       :
;:::::::::::::::::::::::::::::::
EXT:    MOVB    #0,@A2          ; all went ok
       RTN                     ; return to BASIC
;::::::::::::::::::::::::::::::
;       error routines        :
;::::::::::::::::::::::::::::::
LESARG: CALL    SETUP
       TYPE    <Arguments are LT 3.>
       JMP     PROMPT
NOSTR:  CALL    SETUP
       TYPE    <SNDDTE is not string.>
       JMP     PROMPT
SERROR: CALL    SETUP
       TYPE    <SNDDTE is LT 6 bytes.>
       JMP     PROMPT
NOFLT:  CALL    SETUP
       TYPE    <RCVDTE is not floating point.>
       JMP     PROMPT
NOBIN:  CALL    SETUP
       TYPE    <FLGDTE not binary.>
       BR      PROMPT
JERROR: CALL    SETUP
       TYPE    <RCVDTE is <1 or >36524.>
PROMPT: MMCRT   #30,#63         ; ? TAB(24,51);
       TYPE    <Press [RETURN] to redo!>
       TIN                     ; get a key stroke
       MMCRT   #30,#1          ; ? TAB(24,1);
       MOV     #177411,D1      ; ? TAB(-1,9);
       TCRT                    ; do it!
       MOVB    #1,@A2          ; all did not go ok!
       RTN                     ; return to BASIC
SETUP:  MOV     #7,D1           ; ding!
       TTY                     ; do it!
       MMCRT   #30,#1          ; ? TAB(24,1);
       RTN                     ; fetch next instruction from PC
       END                     ; end of source program