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 / KAYPRO / K10TIME.LBR / K10TIME.AQM / K10TIME.ASM
Assembly Source File  |  2000-06-30  |  10KB  |  463 lines

  1. ;********************  K10TIME.ASM **********************
  2. ;
  3. ; TIME PROGRAM FOR THE LEGACY COMPUTER SYSTEMS REAL TIME CLOCK
  4. ;
  5. ; Modified for Kaypro 10, prints time/date string on the
  6. ; 25th status line in inverse video.  - Steve Sanders
  7. ;
  8. ; Use:  A0>time       print time/date on 25th line
  9. ;
  10. ;       A0>time set   set the clock mode, can also be
  11. ;       A0>time s
  12. ;
  13. ; pio stuff
  14. ;
  15. BDATA    EQU    079h        ; port B data
  16. BCMND    EQU    07bh        ; port B command
  17. HOLD    EQU    16        ; Hold 5832 to set up read/write
  18. WR    EQU    64        ; Read 5832
  19. RD    EQU    32        ; Write 5832
  20. MODE0    EQU    0FH        ; pio output mode
  21. MODE3    EQU    0CFH        ; Pio control mode
  22. ;
  23. ; bdos equates
  24. ;
  25. BDOS    EQU    5        ; CP/M entry point
  26. CONO    EQU    2        ; Console output function
  27. CPRT    EQU    9        ; Print string to console function
  28. RCONS    EQU    10        ; Read console buffer function
  29. FCB    EQU    5CH        ; Default file control block
  30. CBUF    EQU    80H        ; console buffer
  31. TPA    EQU    100H        ; Transient Program Area
  32. ;
  33. ; ascii equates
  34. ;
  35. CR    EQU    13        ; Carriage return code
  36. LF    EQU    10        ; Line feed code
  37. ;
  38. ; program code begins
  39. ;
  40.     ORG    TPA        ; Transient Program Area
  41.  
  42. START:    LXI    H,0        ; clear it
  43.     DAD    SP        ; put stack ptr in it
  44.     SHLD    STACK        ; save it for exit
  45.     LXI    SP,STACK    ; set local stack
  46.  
  47. ; set port to output mode
  48. ;
  49. BEGIN:    MVI    A,MODE0        ; output mode
  50.     OUT    BCMND        ; command port
  51.     MVI    A,3        ; disable interrupts
  52.     OUT    BCMND        ; command port
  53. ;
  54. ; main program
  55. ;
  56.     LXI    H,TIME        ; clock buffer
  57.     MVI    C,13        ; read 13 bytes
  58.     MVI    A,1
  59. CL1:    MOV    M,A        ; move em to buffer
  60.     INX    H
  61.     DCR    C        ; dec register
  62.     JNZ    CL1        ; if not zero, loop
  63.  
  64.     LDA    FCB+1        ; check the fcb for set option
  65.     ANI    5FH        ; force upper case
  66.     CPI    'S'        ; is it 's' or 'S'
  67.     JNZ    TIM        ; if not, tell time and exit
  68.     CALL    SETTIM        ; or do the set clock routines
  69. ;
  70. ; display the time/date on 25th (status) line
  71. ;
  72. TIM:    call     ilprt        ; print to Kaypro 10 CRT
  73.     db    1bh,'C7'    ; disable 25th line
  74.     db    1ah        ; clear screen/25th line
  75.     db    1bh,'B7'    ; enable 25th line
  76.     db    1bh,'=8 '    ; load cursor to 25,0
  77.     db    1bh,'B0'    ; inverse video ON
  78.     db    1bh,'B1'    ; dim video on
  79.     db    ' Time ',0    ; print time/date string on 25th line
  80.     CALL    TELTIM        ; tell the time
  81.     JMP    EXIT        ; and exit
  82.  
  83. ;
  84. ; read the clock digits from the buffer
  85. ;
  86. TELTIM:
  87.     CALL    RDMOD        ; set chb to read mode
  88.     LXI    H,TIME        ; clock buffer
  89.     MVI    C,13        ; # bytes to read
  90. TTLP:    MOV    A,L
  91.     ANI    0FH        ; mask off high nybble
  92.     CALL    RDCLK
  93.     MOV    M,A        ; store it in clock buffer
  94.     INX    H        ; bump buffer ptr
  95.     DCR    C        ; finished?
  96.     JNZ    TTLP        ; guess not
  97. ;
  98. ; output clock buffer to screen
  99. ;
  100. ;    hh:mm:ss  format
  101. ;
  102.     LHLD    HOUR        ; hours
  103.     MOV    A,H        ; 10's digit
  104.     ANI    3        ; mask hi bits
  105.     CALL    ASCII        ; to screen
  106.     MOV    A,L        ; 1's digit
  107.     CALL    ASCII        ; to screen
  108.     mvi    a,':'        ; seperator
  109.     call    type        ; to screen
  110.     LHLD    MIN        ; minutes
  111.     MOV    A,H        ; 10's digit
  112.     CALL    ASCII        ; to screen
  113.     MOV    A,L        ; 1's digit
  114.     CALL    ASCII        ; to screen
  115.     MVI    A,':'        ; separator
  116.     CALL    TYPE        ; to screen
  117.     LHLD    SEC        ; seconds
  118.     MOV    A,H        ; 10's digit
  119.     CALL    ASCII        ; to screen
  120.     MOV    A,L        ; 1's digit
  121.     CALL    ASCII        ; to screen
  122.     MVI    A,' '        ; space
  123.     CALL    TYPE        ; to screen
  124.     mvi     a,' '        ; turn up a 
  125.     call    type        ; blank space
  126.     mvi    a,' '        ; ditto
  127.     call    type
  128. ;
  129. ; day of the week
  130.     LDA    DAY        ; varies from 0 - 6
  131.     ANI    7        ; mask hi bits
  132.     MOV    L,A        ; preset hl
  133.     MVI    H,0
  134.     DAD    H        ; day * 2 for table offset
  135.     LXI    D,DAYS        ; point to days table
  136.     DAD    D        ; point to day of week
  137.     MOV    E,M        ; move pointer to de
  138.     INX    H
  139.     MOV    D,M
  140.     MVI    C,CPRT        ; print string
  141.     CALL    BDOS        ; print day of week
  142.     mvi    a,' '        ; print a
  143.     call     type        ; blank space
  144. ;
  145. ; month of the year (varies from 1 to 12)
  146.     LDA    MONTH+1        ; 10's digit
  147.     ANI    1        ; is it October or later?
  148.     JZ    MONT        ; guess not
  149.     MVI    A,10
  150. MONT:    MOV    L,A        ; A = 0 or 10
  151.     MVI    H,0
  152.     LDA    MONTH        ; 1's digit
  153.     ANI    0FH        ; mask hi bits
  154.     ADD    L
  155.     MOV    L,A        ; month in hl
  156.     DCX    H        ; rel zero for months table
  157.     DAD    H        ; times 2 for offset
  158.     LXI    D,MONTHS    ; point to table
  159.     DAD    D        ; point to month
  160.     MOV    E,M        ; move pointer to de
  161.     INX    H
  162.     MOV    D,M
  163.     MVI    C,CPRT
  164.     CALL    BDOS        ; month to console
  165. ; date of the month
  166.     LHLD    DATE        ; date of month
  167.     MOV    A,H        ; 10's digit
  168.     ORA    A        ; is it zero?
  169.     JZ    DATL        ; if so
  170.     CALL    ASCII        ; to screen if not
  171. DATL:    MOV    A,L        ; 1's digit
  172.     CALL    ASCII        ; to screen
  173.     MVI    A,','        ; space
  174.     CALL    TYPE        ; to screen
  175.     mvi    a,' '        ; print a
  176.     call    type        ; blank space
  177. ; print year to console
  178.     CALL    ILPRT
  179.     DB    '19',0        ; print century
  180.     LDA    YEAR+1        ; 10's digit
  181.     CALL    ASCII        ; to screen
  182.     LDA    YEAR        ; 1's digit
  183.     CALL    ASCII        ; to screen
  184.     call    ilprt        ; print
  185.     db    ' ',1bh,'C0'    ; inverse video OFF
  186.     db    1bh,'C1'    ; dim video off
  187.     db    1ah,0        ; home cursor/clear screen
  188.     RET            ; to exit
  189.  
  190. SETTIM:
  191. ;
  192. ; Ask 'What time is it?'
  193. ;
  194.     MVI    A,80H        ; max console buffer length
  195.     STA    CBUF        ; init buffer length
  196.     CALL    ILPRT        ; print setting message
  197.     db    1ah,1bh,'B0'    ; clr screen/inverse video on
  198.     db    '  Set Kaypro 10 Legacy Clock.    CTRL-C to Exit  '
  199.     db    1bh,'C0'    ; inverse video off
  200.     DB    CR,LF,lf
  201.     db    1bh,'B1'    ; dim mode on
  202.     db    'Enter the year? (e.g. 84): '
  203.     db    1bh,'C1',0    ; dim mode off
  204.     LXI    D,CBUF        ; console buffer
  205.     MVI    C,RCONS        ; read console buffer
  206.     CALL    BDOS
  207.     LDA    CBUF+1        ; length
  208.     ORA    A        ; no entry?
  209.     JZ    SMONTH        ; next
  210.     LXI    H,CBUF+2    ; first digit
  211.     MOV    A,M
  212.     ANI    0FH        ; strip ascii
  213.     STA    YEAR+1        ; store it
  214.     INX    H        ; next digit
  215.     MOV    A,M
  216.     ANI    0FH        ; strip ascii
  217.     STA    YEAR        ; store it
  218.  
  219. SMONTH:
  220.     CALL    ILPRT
  221.     DB    CR,LF
  222.     db    1bh,'B1'    ; dim video on
  223.     db    'Enter month? (Jan = 01, Feb = 02, etc.): '
  224.     db    1bh,'C1',0    ; dim video off
  225.     LXI    D,CBUF
  226.     MVI    C,RCONS
  227.     CALL    BDOS
  228.     LDA    CBUF+1
  229.     ORA    A
  230.     JZ    SDATE        ; no month specified
  231.  
  232.     LDA    CBUF+2
  233.     ANI    0FH
  234.     STA    MONTH+1
  235.     LDA    CBUF+3
  236.     ANI    0FH
  237.     STA    MONTH
  238.  
  239. SDATE:    CALL    ILPRT        ; in-line print
  240.     DB    CR,LF
  241.     db    1bh,'B1'    ; dim video on
  242.     db    'Enter today''s date? (i.e. 01 to 31): '
  243.     db    1bh,'C1',0    ; dim video off
  244.     LXI    D,CBUF        ; console buffer
  245.     MVI    C,RCONS
  246.     CALL    BDOS
  247.     LDA    CBUF+1
  248.     ORA    A
  249.     JZ    SDAY
  250.  
  251.     LDA    CBUF+2        ; 10's digit
  252.     ANI    0FH        ; mask hi nybble
  253.     STA    DATE+1
  254.     LDA    CBUF+3
  255.     ANI    0FH
  256.     STA    DATE
  257.  
  258. SDAY:    CALL    ILPRT
  259.     DB    CR,LF
  260.     db    1bh,'B1'    ; dim video on
  261.     db    'Enter the day (Sun = 1, Mon = 2, etc.): '
  262.     db    1bh,'C1',0    ; dim video off
  263.     LXI    D,CBUF
  264.     MVI    C,RCONS
  265.     CALL    BDOS
  266.     LDA    CBUF+1
  267.     ORA    A
  268.     JZ    STIME        ; no day specified
  269.     LDA    CBUF+2
  270.     ANI    0FH
  271.     DCR    A        ; rel 0
  272.     STA    DAY
  273.  
  274. STIME:    CALL    ILPRT
  275.     DB    CR,LF
  276.     db    1bh,'B1'
  277.     db    'Enter current time (24-hour mode 1545 = 3:45p): '
  278.     db    1bh,'C1',0
  279.     LXI    D,CBUF
  280.     MVI    C,RCONS
  281.     CALL    BDOS
  282.     LDA    CBUF+1
  283.     ORA    A
  284.     JZ    SETCLK        ; no time specified
  285.     LDA    CBUF+2
  286.     ANI    0FH
  287.     ORI    8        ; 24 hour format
  288.     STA    HOUR+1
  289.     LDA    CBUF+3
  290.     ANI    0FH
  291.     STA    HOUR
  292.     LDA    CBUF+4
  293.     ANI    0FH
  294.     STA    MIN+1
  295.     LDA    CBUF+5
  296.     ANI    0FH
  297.     STA    MIN
  298.  
  299. SETCLK:
  300. ;
  301. ; write the time buffer to the clock
  302. ;
  303.     CALL    WRMOD
  304.     LXI    H,TIME
  305.     MVI    C,13
  306. STCLK1:    MOV    E,M
  307.     MOV    A,L
  308.     ANI    0FH
  309.     CALL    WRCLK
  310.     INX    H
  311.     DCR    C
  312.     JNZ    STCLK1
  313.     RET
  314.  
  315. ILPRT:    POP    H        ; hl points to string
  316. ILP1:    MOV    A,M        ; get the character
  317.     INX    H        ; point to next character
  318.     ORA    A        ; is this the zero terminator?
  319.     JZ    ILEX        ; yep. we'RE DONE
  320.     CALL    TYPE        ; to screen
  321.     JMP    ILP1        ; do it again
  322. ILEX:    PCHL            ; jump to instruction following string
  323.  
  324. ASCII:    ADI    30H        ; binary to ascii
  325. TYPE:    PUSH    PSW        ; out to screen, saving all registers
  326.     PUSH    H
  327.     PUSH    D
  328.     PUSH    B
  329.     MOV    E,A
  330.     MVI    C,CONO        ; console output
  331.     CALL    BDOS
  332.     POP    B
  333.     POP    D
  334.     POP    H
  335.     POP    PSW
  336.     RET
  337.  
  338. RDCLK:        ; FOR KCLOCK
  339.     push    psw        ; save address
  340.     call    wrmod        ; setup pio
  341.     pop    psw
  342.     ori    hold+80h    ; add hold and address gate bit
  343.     out    bdata        ; set address and gate
  344.     ani    7fh        ; reset gate bit
  345.     out    bdata        ; address is now latched
  346.     call    wait        ; 150 usec to establish hold
  347.     call    rdmod        ; setup to read lo nybble
  348.     mvi    a,hold+rd    ; add read command to hold
  349.     out    bdata
  350.     call    wait1        ; wait 6 usec
  351.     in    bdata        ; read clock
  352.     ani    0fh        ; mask hi nybble
  353.     push    psw        ; save it
  354.     xra    a        ; clear a
  355.     out    bdata        ; release hold
  356.     pop    psw        ; restore clock data
  357.     ret
  358.  
  359. wrclk:        ; for KClock
  360.     push    psw        ; save address
  361.     call    wrmod
  362.     pop    psw
  363.     ori    hold+80h    ; hold plus address gate bit
  364.     out    bdata
  365.     ANI    7FH        ; reset gate bit
  366.     out    bdata
  367.     call    wait        ; wait 150 usec to establish hold
  368.     mvi    a,hold+wr    ; add write command to hold
  369.     ORA    e        ; data to write
  370.     out    bdata
  371.     PUSH    PSW
  372.     call    wait1        ; wait 6 usec
  373.     POP    PSW
  374.     XRI    WR        ; turn off write command
  375.     OUT    BDATA
  376.     xra    a        ; clear a
  377.     out    bdata        ; release hold
  378.     ret
  379.  
  380. ; set port b to write the clock
  381. WRMOD:    MVI    A,MODE3        ; control mode
  382.     OUT    BCMND
  383.     MVI    A,0        ; write to clock
  384.     OUT    BCMND
  385.     RET
  386.  
  387. ; set port b to read the clock
  388. RDMOD:    MVI    A,MODE3        ; control mode
  389.     OUT    BCMND
  390.     MVI    A,0FH        ; to read clock
  391.     OUT    BCMND
  392.     RET
  393.  
  394. wait:        ; 150 usec timing loop
  395.     mvi    a,54        ; loop control
  396. w0:    dcr    a
  397.     jnz    w0
  398.     ret
  399.  
  400. wait1:        ; 6 usec timing loop
  401.     mvi    a,3
  402.     jmp    w0
  403.  
  404.  
  405. EXIT:    LHLD    STACK
  406.     SPHL
  407.     RET
  408.  
  409. TIME:    EQU    $+15 AND 0FFF0H    ; 16-byte boundary
  410.     ORG    TIME
  411. SEC:    DS    2        ; seconds
  412. MIN:    DS    2        ; minutes
  413. HOUR:    DS    2
  414. DAY:    DS    1        ; day of week
  415. DATE:    DS    2
  416. MONTH:    DS    2
  417. YEAR:    DS    2
  418.  
  419. DAYS:    DW    SUN
  420.     DW    MON
  421.     DW    TUE
  422.     DW    WED
  423.     DW    THU
  424.     DW    FRI
  425.     DW    SAT
  426.  
  427. SUN    DB    'Sunday $'
  428. MON    DB    'Monday $'
  429. TUE    DB    'Tuesday $'
  430. WED    DB    'Wednesday $'
  431. THU    DB    'Thursday $'
  432. FRI    DB    'Friday $'
  433. SAT    DB    'Saturday $'
  434.  
  435. MONTHS:    DW    JAN
  436.     DW    FEB
  437.     DW    MAR
  438.     DW    APR
  439.     DW    MAY
  440.     DW    JUN
  441.     DW    JUL
  442.     DW    AUG
  443.     DW    SEP
  444.     DW    OCT
  445.     DW    NOV
  446.     DW    DEC
  447.  
  448. JAN    DB    'January $'
  449. FEB    DB    'February $'
  450. MAR    DB    'March $'
  451. APR    DB    'April $'
  452. MAY    DB    'May $'
  453. JUN    DB    'June $'
  454. JUL    DB    'July $'
  455. AUG    DB    'August $'
  456. SEP    DB    'September $'
  457. OCT    DB    'October $'
  458. NOV    DB    'November $'
  459. DEC    DB    'December $'
  460.  
  461.     DS    32
  462. STACK:    END    START
  463.