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 / BEEHIVE / UTILITYS / BEERTC.ARC / SETCLOCK.MAC < prev    next >
Text File  |  1990-07-21  |  7KB  |  430 lines

  1. ;02/05/87 age
  2.     TITLE    'Set MicroBee RTC'
  3.  
  4.     .Z80
  5.     ASEG
  6.     page    80        ;() sets compressed print, 8 lines/inch
  7.  
  8.     org    100h
  9.     .phase    100h
  10.  
  11. addr_port    equ    04h    ;register selection port
  12. data_out    equ    06h    ;data output port to rtc
  13. data_in        equ    07h    ;data input port to read data from rtc
  14.  
  15. bdos    equ    005h
  16. coninf    equ    001h
  17. cnoutf    equ    002h
  18. printf    equ    009h
  19. constf    equ    00bh
  20.  
  21. bell    equ    000h
  22. tab    equ    009h
  23. lf    equ    00ah
  24. cr    equ    00dh
  25. clr    equ    01ah
  26.  
  27. ; registers
  28. hour    equ    4
  29. min    equ    2
  30. sec    equ    0
  31. day    equ    7
  32. month    equ    8
  33. year    equ    9    
  34.  
  35. ;macros
  36. rdport    macro
  37.     out    (addr_port),a
  38.     in    a,(data_in)
  39.     endm
  40.  
  41. begin:    ld    de,signon
  42.     ld    c,printf
  43.     call    bdos
  44.  
  45. ; set up register 10
  46.     ld    a,00ah            ; address register 10
  47.     out    (addr_port),a
  48.     ld    a,00101111B        ; 32.768 KHz crystal, 500ms interrupt
  49.     out    (data_out),a        ;  rate
  50.  
  51. ; stop clock by disabling updates
  52.     di                ; no interrupts
  53.     ld    a,00bh            ; address register 11
  54.     out    (addr_port),a
  55.     ld    a,10000010B        ; no update, BCD data, no DSE
  56.     out    (data_out),a
  57.  
  58. ;now fill the rtc registers with correct values
  59. ; YEAR
  60. qy:    ld    de,qyear        ; find year
  61.     ld    c,printf
  62.     call    bdos
  63.     ld    c,coninf
  64.     call    bdos
  65.     cp    030h            ; check between 0 and 9
  66.     jr    c,qy
  67.     cp    03ah
  68.     jp    p,qy
  69.     sub    030h            ; change to BCD
  70.     sla    a            ; shift to top 4 bits
  71.     sla    a
  72.     sla    a
  73.     sla    a
  74.     ld    (temp),a        ; save
  75.  
  76.     ld    c,coninf
  77.     call    bdos
  78.     cp    030h            ; check between 0 and 9
  79.     jr    c,qy
  80.     cp    03ah
  81.     jp    p,qy
  82.     sub    030h            ; change to BCD
  83.     ld    hl,temp
  84.     or    (hl)
  85.     ld    (hl),a            ; save combined BCD values
  86.     ld    a,009h            ; year register
  87.     out    (addr_port),a
  88.     ld    a,(hl)
  89.     out    (data_out),a
  90.  
  91. ;MONTH
  92. qm:    ld    de,qmonth
  93.     ld    c,printf
  94.     call    bdos
  95.  
  96.     ld    c,coninf        ; get tens of month
  97.     call    bdos
  98.     cp    030h
  99.     jr    c,qm
  100.     cp    032h
  101.     jp    p,qm
  102.     sub    030h            ; change to BCD
  103.     sla    a            ; shift to top 4 bits
  104.     sla    a
  105.     sla    a
  106.     sla    a
  107.     ld    (temp),a        ; save
  108.  
  109.     ld    c,coninf        ; get units of month
  110.     call    bdos
  111.     cp    030h
  112.     jr    c,qm
  113.     cp    03ah
  114.     jp    p,qm
  115.     sub    030h            ; change to BCD
  116.     ld    hl,temp
  117.     or    (hl)
  118.     ld    (hl),a            ; save combined BCD values
  119.     ld    a,008h            ; month register
  120.     out    (addr_port),a
  121.     ld    a,(hl)
  122.     out    (data_out),a
  123.  
  124. ;DAY OF THE WEEK
  125. qwd:    ld    de,qwday
  126.     ld    c,printf
  127.     call    bdos
  128.  
  129.     ld    c,coninf        ; get day of the week
  130.     call    bdos
  131.     cp    031h
  132.     jr    c,qwd
  133.     cp    038h
  134.     jp    p,qwd
  135.     sub    030h            ; change to BCD
  136.     push    af
  137.     ld    a,006h            ; day of week register
  138.     out    (addr_port),a
  139.     pop    af
  140.     out    (data_out),a
  141.  
  142. ;DAY
  143. qd:    ld    de,qday
  144.     ld    c,printf
  145.     call    bdos
  146.  
  147.     ld    c,coninf        ; get tens of day
  148.     call    bdos
  149.     cp    030h
  150.     jr    c,qd
  151.     cp    034h
  152.     jp    p,qd
  153.     sub    030h            ; change to BCD
  154.     sla    a            ; shift to top 4 bits
  155.     sla    a
  156.     sla    a
  157.     sla    a
  158.     ld    (temp),a        ; save
  159.  
  160.     ld    c,coninf        ; get units of day
  161.     call    bdos
  162.     cp    030h
  163.     jr    c,qd
  164.     cp    03ah
  165.     jp    p,qd
  166.     sub    030h            ; change to BCD
  167.     ld    hl,temp
  168.     or    (hl)
  169.     ld    (hl),a            ; save combined BCD values
  170.     ld    a,007h            ; day of month register
  171.     out    (addr_port),a
  172.     ld    a,(hl)
  173.     out    (data_out),a
  174.  
  175.  
  176. ;HOUR
  177. qh:    ld    de,qhour
  178.     ld    c,printf
  179.     call    bdos
  180.  
  181.     ld    c,coninf        ; get tens of hour
  182.     call    bdos
  183.     cp    030h
  184.     jr    c,qh
  185.     cp    036h
  186.     jp    p,qh
  187.     sub    030h            ; change to BCD
  188.     sla    a            ; shift to top 4 bits
  189.     sla    a
  190.     sla    a
  191.     sla    a
  192.     ld    (temp),a        ; save
  193.  
  194.     ld    c,coninf        ; get units of hour
  195.     call    bdos
  196.     cp    030h
  197.     jr    c,qh
  198.     cp    03ah
  199.     jp    p,qh
  200.     sub    030h            ; change to BCD
  201.     ld    hl,temp
  202.     or    (hl)
  203.     ld    (hl),a            ; save combined BCD values
  204.     ld    a,004h            ; hour register
  205.     out    (addr_port),a
  206.     ld    a,(hl)
  207.     out    (data_out),a
  208.  
  209. ;MINUTES
  210. qmn:    ld    de,qmin
  211.     ld    c,printf
  212.     call    bdos
  213.  
  214.     ld    c,coninf        ; get tens of minutes
  215.     call    bdos
  216.     cp    030h
  217.     jr    c,qmn
  218.     cp    036h
  219.     jp    p,qmn
  220.     sub    030h            ; change to BCD
  221.     sla    a            ; shift to top 4 bits
  222.     sla    a
  223.     sla    a
  224.     sla    a
  225.     ld    (temp),a        ; save
  226.  
  227.     ld    c,coninf        ; get units of minute
  228.     call    bdos
  229.     cp    030h
  230.     jr    c,qmn
  231.     cp    03ah
  232.     jp    p,qmn
  233.     sub    030h            ; change to BCD
  234.     ld    hl,temp
  235.     or    (hl)
  236.     ld    (hl),a            ; save combined BCD values
  237.     ld    a,002h            ; mins register
  238.     out    (addr_port),a
  239.     ld    a,(hl)
  240.     out    (data_out),a
  241.  
  242. ;SECONDS
  243. qsecs:    ld    de,qsec
  244.     ld    c,printf
  245.     call    bdos
  246.  
  247.     ld    c,coninf        ; get tens of minutes
  248.     call    bdos
  249.     cp    030h
  250.     jr    c,qsecs
  251.     cp    036h
  252.     jp    p,qsecs
  253.     sub    030h            ; change to BCD
  254.     sla    a            ; shift to top 4 bits
  255.     sla    a
  256.     sla    a
  257.     sla    a
  258.     ld    (temp),a        ; save
  259.  
  260.     ld    c,coninf        ; get units of minute
  261.     call    bdos
  262.     cp    030h
  263.     jr    c,qsecs
  264.     cp    03ah
  265.     jp    p,qsecs
  266.     sub    030h            ; change to BCD
  267.     ld    hl,temp
  268.     or    (hl)
  269.     ld    (hl),a            ; save combined BCD values
  270.     ld    a,000h            ; secs register
  271.     out    (addr_port),a
  272.     ld    a,(hl)
  273.     out    (data_out),a
  274.  
  275. ; now set the clock ticking
  276.     ld    a,00bh            ; register 11
  277.     out    (addr_port),a
  278.     in    a,(data_in)
  279.     and    07fh
  280.     push    af
  281.     ld    a,00bh            ; register 11
  282.     out    (addr_port),a
  283.     pop    af
  284.     out    (data_out),a
  285.  
  286. ; ask if time ok
  287.     ld    de,ok
  288.     ld    c,printf
  289.     call    bdos
  290.  
  291. ; hide the cursor
  292.     ld    b,00fh
  293.     ld    a,000h
  294.     ld    hl,0fa00h
  295. hide:    ld    (hl),a
  296.     inc    hl
  297.     djnz    hide
  298.  
  299. ; show the time incrementing
  300. ;read the data from the rtc
  301. read_rtc:
  302.     ld    de,space
  303.     ld    c,printf
  304.     call    bdos
  305.     ld    a,hour
  306.     rdport        ;get value for hours
  307.     call    split    ;convert to msb and lsb in H, L
  308.     ld    (hours),hl
  309.  
  310.     ld    a,min
  311.     rdport    
  312.     call    split
  313.     ld    (mins),hl
  314.  
  315.     ld    a,sec
  316.     rdport    
  317.     call    split
  318.     ld    (secs),hl
  319.  
  320.     ld    a,day
  321.     rdport    
  322.     call    split
  323.     ld    (days),hl
  324.  
  325.     ld    a,month
  326.     rdport    
  327.     call    split
  328.     ld    (months),hl
  329.  
  330.     ld    a,year
  331.     rdport    
  332.     call    split
  333.     ld    (years),hl
  334.  
  335. pr_time:
  336.     ld    hl,hours
  337.     ld    b,15h
  338. pr1:    ld    a,(hl)
  339.     call    con
  340.     inc    hl
  341.     djnz    pr1
  342.  
  343. ; wait for next 1 second
  344. loop:    ld    a,00ch            ; status register
  345.     rdport    
  346.     and    010h            ; update bit
  347.     jp    nz,read_rtc
  348.     ld    c,06h            ; swallow key
  349.     ld    e,0ffh
  350.     call    bdos
  351.     and    01011111B        ; make upper case
  352.     cp    'Y'
  353.     jp    z,cpm
  354.     cp    'N'
  355.     jp    z,begin
  356.     jr    loop
  357.  
  358. ; return to CP/M
  359. cpm:    ei                ; enable interrupts
  360.     ld    de,poscur
  361.     ld    c,printf
  362.     call    bdos
  363.     jp    0            ; warm boot
  364.  
  365. ;subroutines
  366. ;subroutine to take the packed BCD number in A and split it into a tens and
  367. ;a units digit in L and H.
  368. split:    push    af
  369.     and    0f0h    ;mask out units
  370.     ld    l,a    ;L contains tens
  371.     pop    af
  372.     sub    l
  373.     add    a,'0'    ;convert to ascii
  374.     ld    h,a    ;get units into H
  375.     srl    l    ;divide by 16 to get true 0-9 value
  376.     srl    l
  377.     srl    l
  378.     srl    l
  379.     ld    a,l
  380.     add    a,'0'    ;convert to ascii
  381.     ld    l,a
  382.     ret
  383.  
  384. ;console print subroutine
  385. con:    push    af
  386.     push    bc
  387.     push    hl
  388.     ld    e,a
  389.     ld    c,cnoutf
  390.     call    bdos
  391.     pop    hl
  392.     pop    bc
  393.     pop    af
  394.     ret
  395.  
  396. ;messages
  397. signon:    db    clr,lf,lf,tab,'Set MicroBee Real Time Clock'
  398.     db    '  (add leading zeros if needed)','$'
  399.  
  400. qyear:    db    cr,lf,lf,tab,'Year (last two digits only)? ',bell,'$'
  401.  
  402. qmonth:    db    cr,lf,lf,tab,'Month? ',bell,'$'
  403.  
  404. qwday:    db    cr,lf,lf,tab,'Day of week (1 - 7)? ',bell,'$'
  405.  
  406. qday:    db    cr,lf,lf,tab,'Day of month? ',bell,'$'
  407.  
  408. qhour:    db    cr,lf,lf,tab,'Hour (24 hour format)? ',bell,'$'
  409.  
  410. qmin:    db    cr,lf,lf,tab,'Minutes? ',bell,'$'
  411.  
  412. qsec:    db    cr,lf,lf,tab,'Seconds? ',bell,'$'
  413.  
  414. ok:    db    cr,lf,lf,lf,lf,tab,'Is the time correct (y/n)? _',00bh,00bh,'$'
  415.  
  416. space:    db    cr,'        ','$'
  417.  
  418. poscur:    db    cr,lf,lf,lf,'$'
  419.  
  420. ;data storage
  421. hours:    db    '00:'
  422. mins:    db    '00:'
  423. secs:    db    '00   '
  424. days:    db    '00/'
  425. months:    db    '00/19'
  426. years:    db    '00'
  427. temp:    ds    1
  428.  
  429.     end
  430.