home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / vol226 / date.asm < prev    next >
Encoding:
Assembly Source File  |  1986-02-13  |  2.7 KB  |  126 lines

  1. ;DATE.ASM v 1.10   10/26/83
  2. ; S. Kluger El Paso RCPM
  3. ;
  4. ; This module will take the date in Digital Research
  5. ; format and change it into human-readable form.
  6. ;
  7. ;Input: The number of days since 01/01/78. @DCFLD
  8. ;    must be defined in the main module and be
  9. ;    a structure of format "mm/dd/yy$"
  10. ;Output:The structure at @DCFLD will contain the
  11. ;    date in ASCII.
  12. ;
  13. ; The routine works, don't ask me why. If you think it's
  14. ; too kludgy or too big, feel free to change it. Just
  15. ; don't leave my name off the ASM file, ok?
  16. ;
  17.     PUBLIC    @DCVRT
  18.     EXTRN    @DCFLD
  19. ;
  20.     CSEG
  21. ;
  22. ; Enter with the number of days since 1-1-78 in HL
  23. ;
  24. @dcvrt:    shld    drtime        ;save it for now
  25.     mvi    b,78        ;set years counter
  26. loop:    call    ckleap
  27.     lxi    d,-365        ;set up for subtract
  28.     jnz    nolpy        ;skip if no leap year
  29.     dcx    d        ;set for leap year
  30. nolpy:    dad    d        ;subtract
  31.     jnc    ydone        ;continue if years done
  32.     mov    a,h
  33.     ora    l
  34.     jz    ydone
  35.     shld    drtime        ;else save days count
  36.     inr    b        ;increment years count
  37.     jmp    loop        ;and do again
  38. ;
  39. ; The years are now finished, the years count is in B
  40. ; and drtime holds the days (HL is invalid)
  41. ;
  42. ydone:    call    ckleap        ;check if leap year
  43.     mvi    a,-28
  44.     jnz    febno        ;february not 29 days
  45.     mvi    a,-29        ;leap year
  46. febno    sta    feb        ;set february
  47.     mov    a,b        ;get years count
  48.     lxi    h,@dcfld+7    ;point to years field
  49.     call    stasha        ;stash A into years field
  50.     lhld    drtime        ;get days count
  51.     lxi    d,mtable    ;point to months table
  52.     mvi    b,0ffh        ;set up b for subtract
  53.     mvi    a,0        ;set a for # of months
  54. mloop:    push    psw
  55.     ldax    d        ;get month
  56.     mov    c,a        ;put in C for subtract
  57.     pop    psw
  58.     shld    drtime        ;save days count
  59.     dad    b        ;subtract
  60.     inx    d        ;increment months counter
  61.     inr    a
  62.     jc    mloop        ;and loop for next month
  63. ;
  64. ; The months are finished, days count is on stack.
  65. ; First, calculate month.
  66. ;
  67. mdone:    mov    b,a        ;save months
  68.     lhld    drtime
  69.     mov    a,h
  70.     ora    l
  71.     jnz    nzd
  72.     dcx d ! dcx d
  73.     ldax    d
  74.     cma ! inr a
  75.     mov    l,a
  76.     shld    drtime
  77.     dcr    b
  78. nzd:    mov    a,b
  79.     push    h
  80.     lxi    h,@dcfld+1    ;point to months field
  81.     call    stasha        ;put a into months field
  82.     pop    h        ;get days count back
  83.     mov    a,l        ;into a
  84.     lxi    h,@dcfld+4    ;point to day field
  85. ;
  86. ; Plug the accumulator into <HL> as decimal
  87. ;
  88. stasha:    push    b        ;save bc as counter
  89.     mvi    b,0        ;initialize tens
  90. stl:    cpi    10        ; > 10?
  91.     jc    got10        ;no, done
  92.     sui    10        ;subtract 10 from A
  93.     inr    b        ;increment tens
  94.     jmp    stl        ;and loop
  95. ;
  96. ; B has the tens, A has the units. Store the units first
  97. ;
  98. got10:    adi    '0'        ;make ascii
  99.     mov    m,a        ;stash units
  100.     mov    a,b        ;get tens
  101.     adi    '0'        ;make ascii
  102.     dcx    h        ;point to tens
  103.     mov    m,a
  104.     pop    b        ;restore bc
  105.     ret
  106. ;
  107. ; This routine checks for leap years.
  108. ;
  109. ckleap:    mov    a,b
  110.     ani    0fch
  111.     cmp    b
  112.     ret
  113. ;
  114. ; This is the months table
  115. ;
  116. mtable:    db    -31        ;January
  117. feb:    db    -28        ;February
  118.     db    -31,-30,-31,-30    ;Mar-Jun
  119.     db    -31,-31,-30    ;Jul-Sep
  120.     db    -31,-30,-31    ;Oct-Dec
  121. ;
  122. drtime:    dw    0        ;temporary storage
  123. ;
  124.     end
  125.  
  126.