home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / mbug / mbug060.arc / CPM#005.LBR / SCDATE.ASM < prev    next >
Assembly Source File  |  1979-12-31  |  5KB  |  217 lines

  1. ;SCDATE.ASM v1.0 06/18/85
  2. ; Carl Efird
  3. ;
  4. ; This program reads the CP/M+ system date,
  5. ; sets the SuperCalc (tm) date and chains SC2.COM 
  6. ; with the command line if provided. It will work
  7. ; the same way with SC.COM if you change the name
  8. ; below.
  9. ;
  10. ; The SuperCalc (tm) date is stored in BCD starting 
  11. ; at 10h in month, day, year order.
  12. ;
  13.     org    100h
  14. reset    equ    0
  15. bdos    equ    5
  16. prtstr    equ    9
  17. versn    equ    12
  18. setdma    equ    26
  19. chain    equ    47
  20. getdat    equ    105
  21. ;
  22. dcfld    equ    10h
  23. month    equ    10h
  24. day    equ    11h
  25. year    equ    12h
  26. ;
  27.     jmp    start
  28. ;
  29.     db    'SCDATE v1.0 -  SuperCalc (tm) date set for CP/M+ - '
  30.     db    'Carl Efird 06/85',1ah
  31.     ds    40
  32. ;
  33. start:    lhld    start-1
  34.     sphl            ; set up stack
  35.     mvi    c,versn
  36.     call    bdos        ; get CP/M version number
  37.     mov    a,l
  38.     ani    0f0h        ; strip off lower 4 bits
  39.     cpi    30h
  40.     jz    cpm30
  41. ;
  42. ; Must be CP/M 3.0 or higher
  43. ;
  44.     lxi    d,not30
  45.     mvi    c,prtstr
  46.     call    bdos
  47.     mvi    c,reset
  48.     call    bdos
  49. ;
  50. not30:    db    'Must be CP/M 3.0 or higher$'
  51. ;
  52. ; OK - proceed to get the system date
  53. ;
  54. cpm30:    lxi    d,date    
  55.     mvi    c,getdat
  56.     call    bdos        ; get the system date
  57.     lhld    date
  58.     call    dcvrt        ; convert date
  59. ;
  60. ; insert command at begining of command tail in default dma
  61. ;
  62.     lxi    h,80h        ; load default dma address
  63.     mvi    a,' '
  64.     mov    m,a        ; replace length with a blank
  65.     lxi    d,cmd        ; load end of command address
  66. insert:    lxi    h,80h        ; start at begining of dma
  67.     dcx    d        ; back up 1 character in command
  68.     ldax    d        ; load character
  69.     cpi    0
  70.     jz    scalc        ; done if 0
  71. move:    mov    b,m        ; get character from dma
  72.     mov    m,a        ; replace with preceeding character
  73.     inx    h        ; point to next character
  74.     mov    a,b        ; new preceeding character
  75.     cpi    0
  76.     jnz    move        ; continue if not 0
  77.     mov    m,a        ; save the 0
  78.     jmp    insert
  79. ;
  80. scalc:    mvi    e,0
  81.     mvi    c,chain
  82.     call    bdos        ; chain to SC2.COM
  83. ;
  84. date:    db    0,0,0,0,0
  85.     db    'SC2.COM'    ; name of command to chain
  86. cmd:    db    0
  87. ;
  88. ;------------------------------------------------------
  89. ;DATE.ASM v1.10 10/26/83
  90. ; S. Kluger El Paso RCPM
  91. ;
  92. ; This module will take the date in Digital Research
  93. ; format and change it into human-readable form.
  94. ;
  95. ;Input: The number of days since 01/01/78. DCFLD
  96. ;    must be defined in the main module and be
  97. ;    3 bytes.
  98. ;Output:The structure at DCFLD will contain the
  99. ;    date in BCD.
  100. ;
  101. ; The routine works, don't ask me why. If you think it's
  102. ; too kludgy or too big, feel free to change it. Just
  103. ; don't leave my name off the ASM file, ok?
  104. ;
  105. ; Enter with the number of days since 1-1-78 in HL
  106. ;
  107. ; Modified 06/18/85 - cre
  108. ;   returns decoded date as BCD rather than ASCII
  109. ;   for compatability with SuperCalc (tm)
  110. ;
  111. dcvrt:    shld    drtime        ;save it for now
  112.     mvi    b,78        ;set years counter
  113. loop:    call    ckleap
  114.     lxi    d,-365        ;set up for subtract
  115.     jnz    nolpy        ;skip if no leap year
  116.     dcx    d        ;set for leap year
  117. nolpy:    dad    d        ;subtract
  118.     jnc    ydone        ;continue if years done
  119.     mov    a,h
  120.     ora    l
  121.     jz    ydone
  122.     shld    drtime        ;else save days count
  123.     inr    b        ;increment years count
  124.     jmp    loop        ;and do again
  125. ;
  126. ; The years are now finished, the years count is in B
  127. ; and drtime holds the days (HL is invalid)
  128. ;
  129. ydone:    call    ckleap        ;check if leap year
  130.     mvi    a,-28
  131.     jnz    febno        ;february not 29 days
  132.     mvi    a,-29        ;leap year
  133. febno:    sta    feb        ;set february
  134.     mov    a,b        ;get years count
  135.     lxi    h,dcfld+2    ;point to years field
  136.     call    stasha        ;stash A into years field
  137.     lhld    drtime        ;get days count
  138.     lxi    d,mtable    ;point to months table
  139.     mvi    b,0ffh        ;set up b for subtract
  140.     mvi    a,0        ;set a for # of months
  141. mloop:    push    psw
  142.     ldax    d        ;get month
  143.     mov    c,a        ;put in C for subtract
  144.     pop    psw
  145.     shld    drtime        ;save days count
  146.     dad    b        ;subtract
  147.     inx    d        ;increment months counter
  148.     inr    a
  149.     jc    mloop        ;and loop for next month
  150. ;
  151. ; The months are finished, days count is on stack.
  152. ; First, calculate month.
  153. ;
  154. mdone:    mov    b,a        ;save months
  155.     lhld    drtime
  156.     mov    a,h
  157.     ora    l
  158.     jnz    nzd
  159.     dcx    d
  160.     dcx    d
  161.     ldax    d
  162.     cma
  163.     inr    a
  164.     mov    l,a
  165.     shld    drtime
  166.     dcr    b
  167. nzd:    mov    a,b
  168.     push    h
  169.     lxi    h,dcfld        ;point to months field
  170.     call    stasha        ;put a into months field
  171.     pop    h        ;get days count back
  172.     mov    a,l        ;into a
  173.     lxi    h,dcfld+1    ;point to day field
  174. ;
  175. ; Plug the accumulator into <HL> as decimal
  176. ;
  177. stasha:    push    b        ;save bc as counter
  178.     mvi    b,0        ;initialize tens
  179. stl:    cpi    10        ; > 10?
  180.     jc    got10        ;no, done
  181.     sui    10        ;subtract 10 from A
  182.     inr    b        ;increment tens
  183.     jmp    stl        ;and loop
  184. ;
  185. ; B has the tens, A has the units.
  186. ;
  187. got10:    mov    c,a        ;save units
  188.     mov    a,b        ;get tens
  189.     rlc
  190.     rlc
  191.     rlc
  192.     rlc            ;move tens to upper nibble
  193.     add    c        ;combine tens and units
  194.     mov    m,a        ;store value
  195.     pop    b        ;restore bc
  196.     ret
  197. ;
  198. ; This routine checks for leap years.
  199. ;
  200. ckleap:    mov    a,b
  201.     ani    0fch
  202.     cmp    b
  203.     ret
  204. ;
  205. ; This is the months table
  206. ;
  207. mtable:    db    -31        ;January
  208. feb:    db    -28        ;February
  209.     db    -31,-30,-31,-30    ;Mar-Jun
  210.     db    -31,-31,-30    ;Jul-Sep
  211.     db    -31,-30,-31    ;Oct-Dec
  212. ;
  213. drtime:    dw    0        ;temporary storage
  214. ;
  215.     end
  216. db    -31,-30,-31,-30    ;Mar-Jun
  217.     db