SMOLNET PORTAL home about changes
     TEXAS 2-STEP 2.0 TO CALCULATE THE DAY FOR ALL DATES A.D.2*2 TO 2y2k-2
               - utilising Hans Lachman's Method of Conversion -


 Strictly adhering to Lachman's Maxim (Complexity is a diseconomy of scale)
 this method was designed to run sublimely as a stand-alone function, when
 your only recourse is to call a 68k Asm program via AMS on TI calculators:
 i.e. no values looked up in tables, files or libraries when executing, no
 kernel, no system calls, no exception processing, minimal registers to be
 used, nor the need to save any. It is valid for Julian dates as of 4 A.D.
 and for Gregorian ones as of 1582 A.D. 
   
 Although using a processor more sophisticated than found on four-function
 calculators, this method is simple to execute using Hans' original Method.
 It succeeds where other Methods do not on the lowliest 68k device, while
 needing just 2 registers to compute the day of the week in less than 2
 dozen arithmetic operations. 
        
 The function below returns a day-number compatible with ISO 8601 when
 called with three inputs at their corresponding locations: 
    
 ;  WDN, an address - for storing result d0
 ; FLAG, 0 or 2 - to choose between Julian or Gregorian, respectively
 ; DATE, year0mDA - date stamp as binary word&byte&byte in basic ISO format
 ;
 move.l DATE,d0
 move.l d0,d1
      ;
      ;    APPLY STEP 1 - LACHMAN'S CONGRUENCE--MOD 100
      andi.l #$f00,d0
      divu #100,d0
      addi.w #93,d0
      andi.l #$ff,d0
      divu #100,d0 ; MonthIndex in the upper word (mod100)
      ;
      ;        APPLY STEP 2 - USING SPQR AS A JULIAN YLLD
      swap d0 ; MI
      add.w DATE,d0 ; + year
      andi.l #$fff,d0 
      add.b d1,d0 ; + DA
      subi.l #$300,d1
      lsr  #2,d1
      swap d1
      add.w d1,d0 ; + SPQR/4 
      ;
      ;         (APPLY STEP ".0" - GREGORIAN ADJUSTMENT)
      mulu FLAG,d1
      divu #50,d1
      mulu #25,d1
      lsr  #2,d1 
      add.w d1,d0  ; + SP00div16
      add.w FLAG,d0 ; (SP32div16) + SPQR/4 + year + MI + DA
      ;
      ;
      divu #7,d0 
      swap d0  ;  d0.w becomes the day-number
 ;
 move.w d0,WDN ; returns the day-number to address WDN
 rts
 ;
 ;        Days of the week correspond to day-numbers as:
 ;        Sun=0  Mon=1  Tue=2  Wed=3  Thu=4  Fri=5  Sat=6

 The 2-Step is designed such that parameters are to be passed in the
 proper formats. Thus, one must pass 2 as a word for a Gregorian date
 as of 15.oct.1582, and 0 as of 1.iii.IV for a Julian date where a year 
 is to start in January and is leap if divisible by 4. Some historians
 believe that IV A.D. was a leap year, such that a FLAG of 0 may be
 likewise applied as early as 1.iii.I. It applies historically as well 
 to 29.ii.MCM--a valid date for Orthodox countries like Russia--and
 will continue to give valid conversions for dates on such Orthodox
 calendars for some time. The routine accordingly gives compleat, valid,
 historical continuity in converting (non-Old-Style) A.D. dates from
 1.iii.IV (Julian) and from the Ides of October 1582 (Gregorian) until
 January, 3998 (Gregorian or non-Old-Style Julian).


--

       REFERENCES

gopher://gopherite.org/0/users/retroburrowers/TemporalRetrology/QL/JG 
gopher://gopherite.org/0/users/retroburrowers/TemporalRetrology/cc/g4
Response: text/plain
Original URLgopher://sdf.org/0/users/retroburrowers/TemporalRetrology/68k/y4k
Content-Typetext/plain; charset=utf-8