home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / GENASM / SPTTIM10.AQM / SPTTIM10.ASM
Assembly Source File  |  2000-06-30  |  7KB  |  386 lines

  1. *  PROGRAM:  SPTTIME.ASM
  2. *  AUTHOR:  RICHARD CONN
  3. *  VERSION:  1.0
  4. *  DATE:  7 MAR 82
  5. *  PREVIOUS VERSIONS:  None
  6.  
  7. VERS    EQU    10    ;Version Number
  8.  
  9. *
  10. *  SPTTIME is a Support Package which provides Clock Interface Support
  11. *  to programs which generally require it for enhanced performance
  12. *  (i.e., Time included in their outputs).  SPTTIME consists of two
  13. *  Modules:
  14. *    1.  ENDIT -- Returns address of next available page after SPTTIME
  15. *        in HL
  16. *    2.  GETTIME -- Returns a pointer to an ASCII text string (vector
  17. *        of characters ending in a binary 0) which represents the
  18. *        Time, Day of Week, and Date read from a clock.  This pointer
  19. *        is returned in HL, and a condition code (0 if clock not
  20. *        supported and 0FFH if clock supported, which is usually the
  21. *        case, with the Zero Flag set appropriately) is returned in A.
  22. *
  23. *    Both routines may affect only HL and A/PSW Registers.
  24. *
  25.  
  26. *
  27. *  This SPTTIME Support Package is implemented for the DC Hayes Chronograph
  28. *  which is wired into the system to be commanded thru the PUN: device and
  29. *  read thru the RDR: device.
  30. *
  31.  
  32. *
  33. *  Basic Equates
  34. *
  35. BDOS    equ    5    ; BDOS Entry
  36. CR    equ    0dh    ; <CR>
  37.  
  38. *
  39. *  Program Equates
  40. *    Set the desired program to TRUE and all others FALSE
  41. *
  42. FALSE    equ    0    ; FALSE Definition
  43. TRUE    equ    NOT FALSE
  44.  
  45. PRINT2    equ    TRUE
  46. CAT2    equ    FALSE
  47.  
  48. *
  49. *  Origin Table -- this should be set up for each program supported
  50. *
  51.     IF    PRINT2
  52. BASE    EQU    1500H    ; BASE ADDRESS
  53.     ENDIF
  54.  
  55.     IF    CAT2
  56. BASE    EQU    2000H    ; BASE ADDRESS
  57.     ENDIF
  58.  
  59. *
  60. *  SPTTIME Modules --
  61. *
  62.     org    BASE    ; Origin
  63.  
  64.     jmp    endit    ; Return Page After Support Package in HL
  65.     jmp    gettime    ; Return Time Pted to by HL and A <> 0 with flag set
  66.  
  67. *
  68. *  Return Page Address after Support Package in HL
  69. *
  70. endit:
  71.     lxi    h,endall    ; Address in HL
  72.     ret
  73.  
  74. *
  75. *  Return Time as String Pted to by HL
  76. *
  77. gettime:
  78.     push    d    ; Save DE, BC
  79.     push    b
  80.  
  81. *
  82. *  Extract Data from Clock
  83. *
  84.     call    readclock
  85.  
  86. *
  87. *  Load Time/Date/Weekday into buffer 'String'
  88. *
  89.     call    prclock
  90.  
  91.     lxi    h,string    ; Pt to Buffer
  92.  
  93.     mvi    a,0ffh        ; OK
  94.     ora    a        ; Clear Flags
  95.  
  96.     pop    b        ; Restore BC, DE
  97.     pop    d
  98.     ret
  99.  
  100. *
  101. *  Clock Input/Output Entry Routines
  102. *
  103. ciclk:
  104.     push    h    ; Save regs
  105.     push    d
  106.     push    b
  107.     mvi    c,3    ; RDR: Input
  108.     call    bdos
  109.     ani    7fh    ; Mask out MSB if Set
  110.     pop    b    ; Restore regs
  111.     pop    d
  112.     pop    h
  113.     ret
  114.  
  115. coclk:
  116.     push    h    ; Save regs
  117.     push    d
  118.     push    b
  119.     push    psw
  120.     mvi    c,4    ; PUN: Output
  121.     mov    e,a    ; Char in E
  122.     call    bdos
  123.     pop    psw    ; Restore regs
  124.     pop    b
  125.     pop    d
  126.     pop    h
  127.     ret
  128.  
  129. *
  130. *  Print Time/Date/Weekday on String
  131. *
  132. prclock:
  133.     call    prinit    ;Initialize Print
  134.     call    prtime    ;Print Time
  135.     call    space    ;Space
  136.     call    space
  137.     call    prmonth    ;Print Month Name
  138.     call    space
  139.     call    prday    ;Print Day Number
  140.     call    pryear    ;Print Year
  141.     call    prdone    ;Close Print
  142.     ret
  143.  
  144. *
  145. *  Read Time, Date, and Weekday from Clock
  146. *
  147. readclock:
  148.     lxi    h,time    ;Point to Time Buffer
  149.     call    command
  150.     db    'RT'    ;Read Time
  151.     lxi    h,date    ;Point to Date Buffer
  152.     call    command
  153.     db    'RD'    ;Read Date
  154.     ret
  155.  
  156. *
  157. *  Print Time on String
  158. *
  159. prtime:
  160.     lxi    h,time    ;Print Time Info
  161.     call    pr2s    ;Print 2 digits
  162.     call    colon    ;Print :
  163.     call    pr2    ;Print 2 digits
  164.     call    colon    ;Print :
  165.     call    pr2    ;Print 2 digits
  166.     call    space    ;Space
  167.     mov    a,m    ;Get A or P
  168.     call    cpout
  169.     mvi    a,'M'    ;Print M
  170.     call    cpout
  171.     ret
  172.  
  173. *
  174. *  Print Month Name
  175. *
  176. prmonth:
  177.     lxi    h,date+2    ;Convert month number
  178.     mov    a,m    ;Get first digit
  179.     sui    '0'    ;Convert to Binary
  180.     mov    b,a    ;Save in B
  181.     add    a    ;*2
  182.     add    a    ;*4
  183.     add    b    ;*5
  184.     add    a    ;*10
  185.     inx    h    ;Point to next digit
  186.     mov    b,a    ;Value in B
  187.     mov    a,m    ;Get Digit
  188.     sui    '0'    ;Convert to Binary
  189.     add    b    ;Add in
  190.     lxi    d,mlen    ;Length of Month Strings
  191.     lxi    h,months    ;Beginning of Month Strings
  192.     call    offset    ;Compute Offset to Desired String
  193.     call    cpstr    ;Print Month Name
  194.     ret
  195.  
  196. *
  197. *  Print Day Number
  198. *
  199. prday:
  200.     lxi    h,date+4    ;Point to Day Digits
  201.     call    pr2s    ;Print as 2 Digits
  202.     ret
  203.  
  204. *
  205. *  Print Year
  206. *
  207. pryear:
  208.     call    cprint    ;Print Year Prefix
  209.     db    ', 19',0
  210.     lxi    h,date    ;Point to Year
  211.     call    pr2    ;Print 2 Digits
  212.     ret
  213.  
  214. *
  215. *  Print colon or space
  216. *
  217. colon:
  218.     mvi    a,':'    ;Print colon
  219.     jmp    cpout
  220. space:
  221.     mvi    a,' '    ;Print space
  222.     jmp    cpout
  223.  
  224. *
  225. *  Command -- Issue 2-letter command pointed to by Return Address to Clock
  226. *    and copy response into buffer pointed to by HL; affect all registers
  227. *
  228. command:
  229.     mvi    a,'A'    ;Send 'AT'
  230.     call    coclk    ;Send to Clock
  231.     mvi    a,'T'
  232.     call    coclk
  233.     xthl        ;Pt to command letters and save HL
  234.     mov    a,m    ;Get it
  235.     call    coclk    ;Send to Clock
  236.     inx    h    ;Pt to next char
  237.     mov    a,m    ;Get it
  238.     call    coclk    ;Send to Clock
  239.     inx    h    ;Pt to ret adr
  240.     xthl        ;Get HL and save ret adr
  241.     mvi    a,CR    ;Send <CR>
  242.     call    coclk    ;Send to Clock
  243.  
  244. *  Collect Response Chars
  245. cmdloop:
  246.     call    ciclk    ;Get letter
  247.     cpi    CR    ;End of Response?
  248.     jz    cmddone
  249.     mov    m,a    ;Store in Buffer
  250.     inx    h    ;Point to next position
  251.     jmp    cmdloop
  252. cmddone:
  253.     mvi    m,0    ;Store ending zero
  254.     ret
  255.  
  256. *
  257. *  PR2S -- Print chars pointed to by HL and HL+1; if first character is '0',
  258. *    print only one char; affect all registers; on exit, HL points to byte
  259. *    after 2nd char printed
  260. *  PR2 -- PR2S but always print 2 digits
  261. *
  262. pr2:
  263.     mov    a,m    ;Get first char
  264.     jmp    pr2a
  265. pr2s:
  266.     mov    a,m    ;Get first char
  267.     cpi    '0'    ;Leading zero?
  268.     jz    pr2b
  269. pr2a:
  270.     call    cpout    ;Print char
  271. pr2b:
  272.     inx    h    ;Point to next
  273.     mov    a,m    ;Get it
  274.     call    cpout
  275.     inx    h    ;Point to next
  276.     ret
  277.  
  278. *
  279. *  Compute Offset to selected string; on input, HL points to first
  280. *    string, DE=string length, A=Number of String desired (first string = 1)
  281. *
  282. offset:
  283.     dcr    a    ;Count down
  284.     rz
  285.     dad    d    ;Point to next
  286.     jmp    offset
  287.  
  288. *
  289. *  Initialize Buffer Output
  290. *
  291. prinit:
  292.     lxi    h,string    ; Pt to first byte of string
  293.     shld    bptr        ; Set ptr
  294.     ret
  295.  
  296. *
  297. *  Close Buffer Output
  298. *
  299. prdone:
  300.     push    h    ; save HL
  301.     lhld    bptr    ; Get ptr
  302.     mvi    m,0    ; Store ending 0
  303.     pop    h    ; restore HL
  304.     ret
  305.  
  306. *
  307. *  Send char in A to String
  308. *
  309. cpout:
  310.     push    h    ; save HL
  311.     lhld    bptr    ; Pt to next char location
  312.     mov    m,a    ; Put char
  313.     inx    h    ; Incr ptr
  314.     shld    bptr
  315.     pop    h
  316.     ret
  317.  
  318. *
  319. *  Print string pted to by return address into String
  320. *
  321. cprint:
  322.     xthl        ;Pt to string
  323. cpr1:
  324.     mov    a,m    ;Get char
  325.     inx    h    ;Pt to next
  326.     ora    a    ;Done?
  327.     jz    cpr2
  328.     call    cpout    ;Print to CON: or LST:
  329.     jmp    cpr1
  330. cpr2:
  331.     xthl        ;Restore HL and Ret Adr
  332.     ret
  333.  
  334. *
  335. *  Print string pted to by HL into String
  336. *
  337. cpstr:
  338.     push    h    ;Save ptr
  339.     push    psw    ;Save char
  340. cpstr1:
  341.     mov    a,m    ;Get next char
  342.     inx    h    ;Pt to next char
  343.     ora    a    ;Done?
  344.     jz    cpstr2
  345.     call    cpout    ;Print char
  346.     jmp    cpstr1
  347. cpstr2:
  348.     pop    psw    ;Get char
  349.     pop    h    ;Get ptr
  350.     ret
  351.  
  352. *
  353. *  Month Strings
  354. *
  355. months:
  356.     db    'January',0,0,0
  357. month1:
  358.     db    'February',0,0
  359.     db    'March',0,0,0,0,0
  360.     db    'April',0,0,0,0,0
  361.     db    'May',0,0,0,0,0,0,0
  362.     db    'June',0,0,0,0,0,0
  363.     db    'July',0,0,0,0,0,0
  364.     db    'August',0,0,0,0
  365.     db    'September',0
  366.     db    'October',0,0,0
  367.     db    'November',0,0
  368.     db    'December',0,0
  369. mlen    equ    month1-months    ;Number of Bytes in Each Entry
  370.  
  371. *
  372. *  Input Buffers
  373. *
  374. bptr:
  375.     ds    2    ; Pointer to next char position in String Buffer
  376. time:
  377.     ds    10    ; Time Buffer
  378. date:
  379.     ds    10    ; Date Buffer
  380. string:
  381.     ds    80    ; Output String Buffer
  382.  
  383. endall    equ    $/256*256+256    ; End of Support Package
  384.  
  385.     end
  386.