home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / jsage / znode3 / uploads / swtime10.lbr / SWTIME.ZZ0 / SWTIME.Z80
Encoding:
Text File  |  1993-06-07  |  43.0 KB  |  1,656 lines

  1. ;
  2. ;
  3. ;              SWTIME01.Z80 07/07/87
  4. ;
  5. ;
  6. ;      This  program  is  designed  to    interface  to  the   Dallas
  7. ; Semiconductor   SmartWatch/TimeKeeper  family of Real Time  Clock
  8. ; (RTC) parts.
  9. ;
  10. ;      The    SmartWatch  includes its own  crystal time  base    and
  11. ; lithium  battery.   The  SmartWatch maintains  time  information,
  12. ; including hundredths of a seconds,  seconds, minutes, hours,    day
  13. ; of week,  day of month,  month and year.   The date at the end of
  14. ; the month is automatically adjusted for months with fewer than 31
  15. ; days,  including correction  for leap year.  Hours of the day can
  16. ; be tracked in either 12- or 24-hour format.
  17. ;
  18. ;      These   time  keeping devices are offered in several socket-
  19. ; style  hybrid   versions   of  the  DS1215--"TimeKeeper".   These
  20. ; clock/calendar  devices,  fit into 28-pin 0.6-inch-wide DIP (Dual
  21. ; In-line  Package) memory sockets.   The following summarizes    the
  22. ; different devices:
  23. ;
  24. ;
  25. ; DS1216:  Intended for a 2K or 8K byte low power CMOS static  RAM.
  26. ; When system power is    lost, the RAM draws power from the DS1216's
  27. ; battery.
  28. ;
  29. ; DS1216C: Intended for a 8K or 32K byte low power CMOS static RAM.
  30. ; When system power is    lost, the RAM draws power from the DS1216's
  31. ; battery.
  32. ;
  33. ; DS1216E: Intended for a 8K or larger EPROM.
  34. ;
  35. ;      The SmartWatch requires no interfacing,    it merely plugs  in
  36. ; between a existing 28 pin socket and a existing 24 or 28  pin RAM
  37. ; or EPROM.
  38. ;
  39. ;
  40. ; ACCURACY:
  41. ;
  42. ;      The  data  sheet  for the SmartWatch rates the  part  to  be
  43. ; "Accurate to within one minute per month @ 25'C".   However there
  44. ; are  two things that the data sheet doesn't tell you,  that  will
  45. ; cause the SmartWatch to lose time (appear to run slowly):
  46. ;
  47. ;      The  first  problem is related only to the  nonvolatile    RAM
  48. ; type device.     On these devices the voltage powering the RAM must
  49. ; not go below three (3) volts.
  50. ;
  51. ;      The other problem, that effects all types of SmartWatchs, is
  52. ; that    the  voltage at the Write* input,  (pin-27 on  all  devices
  53. ; except the DS1216E, which has Write* on pin-8), must not go above
  54. ; the  Vcc voltage (pin-28).   This usually only happens if you are
  55. ; driving  the SmartWatch with a CMOS logic level,  and the  Write*
  56. ; voltage 'over-shoots' Vcc.
  57. ;
  58. ;      There  are  two    disadvantage of  inserting  the  SmartWatch
  59. ; between  the existing socket and the existing devices:
  60. ;
  61. ;      The  main  disadvantage is that it raises the hight  of    the
  62. ; RAM,    or  EPROM,  by about one-half inch.   So if  your  existing
  63. ; socket has low head room, the SmartWatch may not be the clock for
  64. ; you.
  65. ;
  66. ;      The   other disadvantage is that there is a slight  increase
  67. ; in  memory  access  time,  in most situations this is  of  little
  68. ; concern.
  69. ;
  70. ;
  71. ;
  72. ;      Be careful when trying to plug the SmartWatch-Socket into an
  73. ; other socket.  Some types of sockets, such as machine-contact-pin
  74. ; sockets,  may   not    readily   accept the  flat   pins   of    the
  75. ; SmartWatch.
  76. ;
  77. ;      Contact Dallas Semiconductor directly for data sheets,    and
  78. ; to find out who distributes the SmartWatch in your area.
  79. ;
  80. ;        Dallas Semiconductor Corporation
  81. ;          4350 Beltwood  Parkway South
  82. ;            Dallas, TX 75244
  83. ;
  84. ;             (214) 450-0400
  85. ;            FAX# 214-450-0470
  86. ;            TELEX# 6502441669
  87. ;
  88. ;
  89. ;      [Information  pertaining to Dallas Semiconductor  components
  90. ; are reprinted by permission.]
  91. ;
  92. ;      {By  the way I have no connection to  Dallas  Semiconductor,
  93. ; other than being a user of their parts.}
  94. ;
  95. ;
  96. ;
  97. ;  NOTE:
  98. ;      This program is "Copyright (C) 1986-1987 by Robert Paddock".
  99. ; All rights reserved.     Users are hereby granted a limited license
  100. ; to  copy this program for personal use only.     The program may be
  101. ; distributed  unmodified  to all interested parties.    No  fee  or
  102. ; other consideration shall be    accepted by  any party or  parties.
  103. ; In  accordance with the Copyright Law of 1978,  form    TX has been
  104. ; sent to the U.S. Government Copyright Office.
  105. ;
  106. ;
  107. ;      If   you  have  changes    that you would like  to  see  in  a
  108. ; forthcoming    general   release,    please   forward     them    for
  109. ; consideration.
  110. ;
  111. ;    Send/call any suggestions or requests for help to:
  112. ;
  113. ;
  114. ;               Z-NODE #38
  115. ;             (814) 437-5647
  116. ;            24 hours/ 7 days
  117. ;            300/1200/2400 Baud, 8/N/1
  118. ;          Robert Paddock, KA8BMT, SYSOP
  119. ;
  120. ;
  121. ;         May time be on your side................
  122. ;
  123. ;
  124. MAIN    EQU    1    ; Main version number
  125. VERS    EQU    0    ; Revision number
  126. ;
  127. VMONTH    EQU    07    ; Date of revision
  128. VDAY    EQU    07
  129. VYEAR    EQU    87
  130. ;
  131. ;
  132. ; -------------------------------------------------------------
  133. ;
  134. NO    EQU    0
  135. YES    EQU    NOT NO
  136. ;
  137. ;
  138. SB180    EQU    NO    ; 'YES', if using a SB180
  139. SB180FX    EQU    YES    ; 'YES', if using a SB180FX
  140. ;
  141. ;      If using a SB180,  or SB180FX, then we must deal with the
  142. ; Memory  Management Unit,  of the 64180.   Also we can set  the
  143. ; BIOS clock from the SmartWatch.
  144. ;
  145. ;
  146.     IF    SB180 AND SB180FX
  147. ERROR:    Select only SB180, or SB180FX, not both.
  148.     ENDIF ; SB180 AND SB180FX
  149. ;
  150. ;
  151. USEEI    EQU    NO    ; 'NO' if your system doesn't want the
  152. ;            ; interrupts turned on.
  153. ;
  154. INTEI    EQU    USEEI OR SB180 OR SB180FX
  155. ;
  156. ;      Since some systems need the interrupts on (like the SB180)
  157. ; and  some need them off,  it is best that we put the    interrupt
  158. ; enable bit back the way the system wants it.
  159. ;
  160. ;
  161. ;
  162. EDATE    EQU    NO    ; NO=Month/Date/Year, YES=Date/Month/Year.
  163. WEKDAY    EQU    YES    ; Print 'SUN,MON,.....SAT'.
  164. ;
  165. ;
  166. BASE    EQU    0000H    ; BASE of CP/M
  167. ;
  168. BIOS    EQU    BASE
  169. BDOS    EQU    BASE+5
  170. FCB    EQU    BASE+5CH
  171. TBUFF    EQU    BASE+80H
  172. TPA    EQU    BASE+100H
  173. ;
  174. LF    EQU    0AH     ; Line Feed
  175. CR    EQU    0DH     ; Carriage Return
  176. ;
  177. ;
  178. ;
  179. ; From SYSLIB 3.6:
  180.     EXTRN    COUT,CONDIN,PSTR,PRINT,PA2HC,CATH,CRLF
  181. ;
  182. ; To assemble and link, using SLR's assembler/linker:
  183. ;
  184. ; SLR180 SWTIME
  185. ; LNK180 SWTIME/A:100,SYSLIB/S,SWTIME/N/E
  186. ;
  187. ;
  188. ;           SmartWatch and TimeKeeper,
  189. ;         are trademarks of Dallas Semiconductor.
  190. ;
  191. ;    'SB180' and 'SB180FX' are trademark's of Micromint Inc.
  192. ;
  193. ;          Z80 and Z180 are trademark's of Zilog.
  194. ;
  195. ;           HD64180 is a trademark of Hitachi.
  196. ;
  197. ; -------------------------------------------------------------
  198. ;
  199.      .Z80      ; For M80 (SLR180 ignores it)
  200.      .SALL     ; Don't list expanded macros.
  201. ;
  202. ;
  203. SWAP     MACRO        ; Exchange nibbles.
  204.     RLCA
  205.     RLCA
  206.     RLCA
  207.     RLCA
  208.      ENDM
  209. ;
  210. ; -------------------------------------------------------------
  211. ;
  212.     IF    SB180 OR SB180FX
  213. ;
  214. ;      If  SB180 or SB180FX then we must relocate the program so
  215. ; it is not within the first 4K of RAM (40000H-40FFFH),  so that
  216. ; when we access the SmartWatch at address 00000H,  we don't get
  217. ; lost.
  218. ;
  219. ;    .XLIST            ; Don't list these
  220. ;    MACLIB PORTS.LIB    ; .LIB file(s)
  221. ;
  222. ;
  223.     .XLIST            ; Don't list .LIB's
  224. ;
  225.     MACLIB    PORTS.LIB    ; 64180 (and SB180) ports.
  226. ;                ; [Supplied with the SB180(FX)]
  227. ;
  228. ;    MACLIB    OP-CODES    ; 64180 OP-CODE MACROS (For M80)
  229. ;                ; [Can be found in the BYE5
  230. ;                ;  insert for the SB180(FX)]
  231. ;
  232. ;    .HD64            ; (For ZAS)
  233. ;                ; (SLR180 doesn't need either)
  234. ;
  235.     .LIST            ; Listing back on
  236. ;
  237. ;
  238. ; -------------------------------------------------------------
  239. ;
  240. ;
  241. RUNADR    EQU    3000H ; Could be any RAM address below the CCP,
  242. ;              ; and above 40FFFH; on the SB180(FX).
  243. ;
  244. ;
  245.     LD    HL,FSTADR    ; Relocate the program
  246.     LD    DE,RUNADR    ; so that it is not
  247.     LD    BC,LSTADR-FSTADR
  248.     LDIR            ; in the first 4K of RAM.
  249. ;
  250.     ENDIF    ; SB180 OR SB180FX
  251. ;
  252. ;
  253.     JP    START    ; Ok, lets get some useful work done now.
  254. ;
  255. ; -------------------------------------------------------------
  256. ;
  257. FSTADR    EQU    $    ; Start of section that may need relocated.
  258. ;
  259. ;
  260.     IF    SB180 OR SB180FX
  261. ;
  262.     .PHASE    RUNADR    ; Generate code at the current location
  263. ;            ; for later transfer and execution at
  264. ;            ; RUNADR.
  265.     ENDIF    ; SB180 OR SB180FX
  266. ;
  267. ;
  268. ;      Since  you  most likely want to see how to  deal  with  the
  269. ; SmartWatch,  the code for doing just that, is listed here in the
  270. ; beginning:
  271. ;
  272. ;
  273. ; $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
  274. ;
  275. ;      Because    EPROMs don't have write (WE*) inputs and  your data
  276. ; bus  may  not  be bidirectional at the EPROM    data  output  pins,
  277. ; address  lines  A0 and A2 serve as the DS1216E's data input    and
  278. ; WE* pins, respectively.
  279. ;
  280. ;
  281. DS1216    EQU    NO    ; Nonvolatile RAM type SmartWatch
  282. DSEPRM    EQU    YES    ; EPROM type SmartWatch [DS1216E]
  283. ;
  284.     IF    DS1216 AND DSEPRM
  285. ERROR:    Select only DS1216 or DSEPRM not both.
  286.     ENDIF ; DS1216 AND DSEPRM
  287. ;
  288. ; NOTE: The above equates only affect the way that the device
  289. ;     is written, they both use the same read routine.
  290. ;
  291. ;
  292. WATCH    EQU    0000H    ; Base address of the SmartWatch.
  293. ;
  294. ;
  295. ; *** NOTE: The WATCH equate above MUST match the hardware address
  296. ;        of the SmartWatch, other-wise this program will not be
  297. ;        able to access the SmartWatch.    ***
  298. ;
  299. ;      Most   systems have a boot-strap-EPROM at address zero,    so
  300. ; this seems  like the most logically place to put the SmartWatch.
  301. ; This boot-strap-EPROM can usually be switched  in  and  out    of
  302. ; memory, so make sure you account for this switching.
  303. ;
  304. ;      If  you are using a 64180 be aware of what the 64180  Memory
  305. ; Management Unit is doing.
  306. ;
  307. ;
  308. SWWRB0    EQU    WATCH    ; Address to write a zero bit. (DS1216E)
  309. SWWRB1    EQU    WATCH+1    ; Address to write a one  bit. (DS1216E)
  310. SWRDD0    EQU    WATCH+4    ; Address to read a  bit from. (DS1216[E])
  311. ;
  312. ;
  313. ; OSCILLATOR AND RESET BITS:
  314. ;
  315. ;     Bits  4 and 5 of the day    register are used to control  the
  316. ; reset and oscillator function.    Bit 4 controls the reset (pin
  317. ; 1).    When the reset bit is set to a logical 1, the reset input
  318. ; pin is ignored.   When the reset bit is set to logical 0, a low
  319. ; input on the reset pin will cause the SmartWatch to abort  data
  320. ; transfer  without changing data in the watch register.   Bit    5
  321. ; controls  the oscillator.    This  bit is shipped  from  Dallas
  322. ; Semiconductor set to logical 1, which turns the oscillator off.
  323. ; When    set to logical 0,  the oscillator turns on and the  watch
  324. ; becomes operational.
  325. ;
  326. ;
  327. RSTPIN    EQU    00010000B     ; We want to ignore the reset pin.
  328. ;
  329. OSCOFF    EQU    00100000B     ; Bit 5 is high if not set.
  330. OSCON    EQU    NOT OSCOFF AND 0FFH ; Bit 5 is low if set.
  331. ;
  332. OSCRST    EQU    OSCOFF OR RSTPIN    ; OSC off, and ignore the
  333. ;                    ; reset pin.
  334. ;
  335. ;
  336. ; -------------------------------------------------------------
  337. ;
  338. ;
  339. ACCESS:    DI ; We must turn the interrupts off!
  340. ;
  341. ;
  342. ;      If  the interrupt service routine (assuming there is  one),
  343. ; would  happen  to  read or write to the MEMORY location  of  the
  344. ; SmartWatch,  while  we  are trying to read or  write    the  CLOCK
  345. ; section  of  the SmartWatch it is possible that  the    SmartWatch
  346. ; and/or the interrupt routine could get confused,  since  neither
  347. ; know about  the other.
  348. ;
  349. ;      Cycles  to  other  locations outside of    the  SmartWatch's
  350. ; memory block,  (ie.  the SmartWatch's Chip-Enable [pin 20]  not
  351. ; active)  can    be  interleaved with  SmartWatch  cycles  without
  352. ; interrupting    the pattern recognition sequence or data transfer
  353. ; sequence.
  354. ;
  355. ;      Since some systems need the interrupts on (like the SB180)
  356. ; and  some need them off,  it is best that we put the    interrupt
  357. ; enable bit back the way we found it, before we turned it off.
  358. ;
  359. ;      Unfortunately some other type of interrupt, such as a Non-
  360. ; Maskable-Interrupt  (NMI),  could  still come  along    and  mess
  361. ; everything up, if it accesses a SmartWatch address. Oh well, at
  362. ; least we tried....
  363. ;
  364. ;      Probability  says  that nothing bad will happen.   On  the
  365. ; other  hand  Murphy's law says that the  worst  possible  thing
  366. ; will happen at the worst possible moment.
  367. ;
  368. ;
  369. ; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  370. ;
  371.     IF    SB180 OR SB180FX
  372. ;
  373. ;     We  have  to  turn  the  DRAM    hardware  refresh off,    to
  374. ; prevent spurious EPROM chip selects.
  375. ;
  376.     IF    SB180
  377. ;
  378.     XOR    A        ; Do a software refresh
  379.     LD    B,A        ; so that we will have a whole
  380.     LD    L,A        ; 4 mS to deal with the SmartWatch,
  381.     LD    H, HIGH    $    ; before we have to worry about
  382. ;                ; the DRAM refresh again.
  383. ;
  384. REFIT:    LD    C,(HL)        ; We do this by reading 256
  385.     INC    HL        ; bytes of the 256k DRAM.
  386.     DJNZ    REFIT
  387. ;
  388. ;
  389.     ELSE ; SB180FX
  390. ;
  391.     XOR    A        ; Do a software refresh
  392.     LD    B,A        ; so that we will have a whole
  393.     LD    L,A        ; 4 mS to deal with the SmartWatch,
  394.     LD    H, HIGH    $    ; before we have to worry about
  395.     LD    D,A        ; the DRAM refresh again.
  396.     LD    E,A
  397. ;
  398. REFIT:    LD    C,(HL)        ; We do this by reading 512
  399.     LD    A,(DE)        ; bytes of the 512k DRAM.
  400.     INC    DE
  401.     INC    HL
  402.     DJNZ    REFIT
  403. ;
  404.     ENDIF ; SB180
  405. ;
  406. ; -------------------------------------------------------------
  407. ;
  408.     IN0    A,(RCR)        ; We have to turn the DRAM
  409.     LD    (SVRCR),A    ; hardware refresh off, to
  410.     AND    7FH        ; prevent spurious EPROM chip
  411. ;                ; selects.
  412.     OUT0    (RCR),A        ; Turn the hardware refresh off, now
  413. ;                ; that the software refresh is    done.
  414. ;
  415. ; -------------------------------------------------------------
  416. ;
  417.     IF    SB180FX
  418.     LD    HL,(BIOS+1)    ; Get the BIOS's page address, then
  419.     LD    L,3FH        ; point to the BIOS LATCH stuff.
  420.     LD    (BIOSLATCH),HL
  421. ;
  422.     XOR    A        ; Read the FX latch.
  423.     CALL    LATCHVAL
  424.     LD    (LTCHIMG),BC    ; Save the latch image.
  425.     RES    3,B        ; Select EPROM [RAM/ROM*].
  426.     CALL    SETLATCH    ; Set the FX latch.
  427.     ENDIF ; SB180FX
  428. ;
  429. ; -------------------------------------------------------------
  430. ;
  431.     IN0    A,(CBAR)    ; Save the current CBAR value,
  432.     LD    (SVCBAR),A    ; then map the first for 4K
  433.     AND    0F0H        ; of ROM into Common Area 0.
  434.     OR    01H
  435.     OUT0    (CBAR),A
  436. ;
  437.     ENDIF    ; SB180 OR SB180FX
  438. ;
  439. ; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  440. ;
  441. ;      Communication   with  the  SmartWatch  is  established  by
  442. ; pattern  recognition    of a serial bit stream of 64  bits  which
  443. ; must    be  matched  by executing  64  consecutive  write  cycles
  444. ; containing the proper data on the Data In pin (D) [D=D0 (pin 11
  445. ; of  the 28 pin socket) for the DS1216,  D=A0 (pin 10 of the  28
  446. ; pin socket) for the DS1216E]. All accesses which occur prior to
  447. ; recognition of the 64 bit pattern are directed to memory.
  448. ;
  449. ;
  450. ;      A  read    cycle to any memory location  of  the  SmartWatch
  451. ; starts  the pattern recognition sequence by moving a pointer to
  452. ; the first bit of the 64 bit comparison register.
  453. ;
  454. ;
  455.     LD    A,(SWRDD0)    ; Initialize the access pointer
  456. ;                ; in the SmartWatch.
  457. ;
  458. ;     Next,  64 consecutive write cycles are executed.    These 64
  459. ; write cycles are used only to gain access to the SmartWatch.
  460. ;
  461.     LD    B,2        ; Make two passes.
  462. UNLOCK:    PUSH    BC
  463. ;
  464.     LD    A,0C5H        ; Begin the unlock sequence.
  465.     CALL    WRTCLK        ; The odds of this pattern being
  466.     LD    A,3AH        ; accidentally duplicated and
  467.     CALL    WRTCLK        ; causing inadvertent entry to
  468.     LD    A,0A3H        ; the SmartWatch is less than
  469.     CALL    WRTCLK        ; 1 in 10^19.
  470.     LD    A,05CH
  471.     CALL    WRTCLK
  472. ;
  473.     POP    BC
  474.     DJNZ    UNLOCK        ; Repeat one more time if needed.
  475. ;
  476.     RET
  477. ;
  478. ; -------------------------------------------------------------
  479. ;
  480.       DB 'Copyright (C) 1986-1987 Robert Paddock.'
  481. ;
  482. ; -------------------------------------------------------------
  483. ;
  484. ;
  485. WRTCLK:    LD    B,8    ; We must deal with 8 bits at a time.
  486. ;
  487. ;
  488. ; -------------------------------------------------------------
  489. ;
  490.     IF    DS1216    ; If we are using the SmartWatch
  491. ;            ; with nonvolatile RAM then we
  492. ;            ; do thus:
  493. ;
  494.     LD    HL,SWRDD0
  495. ;
  496. RTCWR:    LD    (HL),A        ; Send out a bit on D0
  497.     RRCA            ; shift right one place
  498.     DJNZ    RTCWR        ; do all 8 bits.
  499. ;
  500.     ENDIF    ; DS1216
  501. ;
  502. ; -------------------------------------------------------------
  503. ;
  504.     IF    DSEPRM    ; If we are using the EPROM version
  505. ;            ; of the SmartWatch [DS1216E] then
  506. ;            ; we do thus:
  507.     LD    C,A
  508. ;
  509. ;
  510. RTCWR:    RRC    C    ; Is this bit a one or zero?
  511.     JR    C,WRTONE; Jump if its a one.
  512. ;
  513.     LD    A,(SWWRB0)    ; Write a zero by reading.
  514.     JR    RTCWRL
  515. ;
  516. WRTONE:    LD    A,(SWWRB1)    ; Write a one by reading.
  517. ;
  518. RTCWRL:    DJNZ    RTCWR        ; Do all 8 bits.
  519. ;
  520. ;
  521.     ENDIF    ; DSEPRM
  522. ;
  523. ; -------------------------------------------------------------
  524. ;
  525.     RET
  526. ;
  527. ; *************************************************************
  528. ;
  529. ;
  530. ; NOTE:  This read routine will work for all of the devices
  531. ;     as  long  as  address line A2 is high when reading
  532. ;     the DS1216E.
  533. ;
  534. ;
  535. RDCLK:    LD    HL,SWRDD0
  536.     XOR    A        ; Set all bits to zero.
  537.     LD    B,8        ; 8 bits make one byte.
  538. ;
  539. RTCRD:    BIT    0,(HL)        ; Does bit D0=0?
  540.     JR    Z,RDBITL    ; Jump if the bit is
  541. ;                ; already zero.
  542.     SET    0,A        ; Set the bit.
  543. ;
  544. RDBITL:    RRCA            ; Rotate right one bit.
  545.     DJNZ    RTCRD        ; Do all of the bits.
  546. ;
  547.     RET
  548. ;
  549. ; -------------------------------------------------------------
  550. ;
  551. ;         Smartwatch Register Information
  552. ;
  553. ;      The SmartWatch information is contained in 8 registers, of 8
  554. ; bits    each,  which  are sequentially accessed one bit at a   time
  555. ; after  the   64-bit    pattern  recognition   sequence   has  been
  556. ; completed.   When updating the SmartWatch registers, each must be
  557. ; handled in groups of 8 bits.    Writing and reading individual bits
  558. ; within a register could produce erroneous results.
  559. ;
  560. ;
  561. ;      Data  contained    in the SmartWatch registers are  always  in
  562. ; binary  coded  decimal format (BCD).      Reading and  writing    the
  563. ; registers  is   always  accomplished by stepping through   all  8
  564. ; registers,   starting  with bit 0 of register 0 and ending   with
  565. ; bit 7 of register 7.
  566. ;
  567. ;
  568. ;      These read/write registers are defined below:
  569. ;
  570. ;
  571. ;  Register, range (BCD), and bit number:
  572. ;
  573. ; 0: 00-99    7 = 0, 6-4 = 0.1 SEC,    3-0 = 0.01 SEC
  574. ;
  575. ; 1: 00-59    7 = 0, 6-4 = 10 SEC,    3-0 = SECONDS
  576. ;
  577. ; 2: 00-59    7 = 0, 6-4 = 10 MIN,    3-0 = MINUTES
  578. ;
  579. ; 3: 01-12/00-23 7 = 12/24, 6 = 0, 5 = 10|A/P, 4 = HR, 3-0 = HOUR
  580. ;
  581. ; 4: 01-07    7,6 & 3 = 0, 5 = OSC, 4 = RST, 2-0 = DAY
  582. ;
  583. ; 5: 01-31    7 & 6 = 0, 5-4 = 10 DATE, 3-0 = DATE
  584. ;
  585. ; 6: 01-12    7,6 & 5 = 0, 4 = 10 MONTH, 3-0 = MONTH
  586. ;
  587. ; 7: 00-99    7-4, 10 YEAR, 3-0 = YEAR
  588. ;
  589. ;
  590. ; ZERO BITS:
  591. ;
  592. ;      Registers  one trough six, contain  one or more bits which
  593. ; will    always    read  logical  0.  When writing  these locations,
  594. ; either a logical 1 or 0 is acceptable.
  595. ;
  596. ; *************************************************************
  597. ;
  598. ;
  599. GETCLK:
  600.     IF    DS1216
  601.     LD    A,(SWRDD0)    ; Preserve the byte at
  602.     LD    (SVRAM),A    ; 'SWRDD0'
  603.     ENDIF ; DS1216
  604. ;
  605.     CALL    ACCESS          ; Select the clock, put 8
  606.     LD    DE,FRACT      ; bytes of data in the
  607. ;                  ; following order:
  608. ;
  609.     CALL    RDCLK          ; Fractions of a second,
  610.     LD    (DE),A
  611.     INC    DE
  612.     CALL    RDCLK          ; Seconds,
  613.     LD    (DE),A
  614.     INC    DE
  615.     CALL    RDCLK          ; Minutes,
  616.     LD    (DE),A
  617.     INC    DE
  618.     CALL    RDCLK          ; AM/PM, Hours,
  619.     LD    (DE),A
  620.     INC    DE
  621.     CALL    RDCLK          ; OSC,RST,DAY,
  622.     LD    (DE),A
  623.     INC    DE
  624.     CALL    RDCLK          ; Date (Day of month),
  625.     LD    (DE),A
  626.     INC    DE
  627.     CALL    RDCLK          ; Month,
  628.     LD    (DE),A
  629.     INC    DE
  630.     CALL    RDCLK          ; Years.
  631.     LD    (DE),A
  632.     INC    DE
  633. ;
  634.     IF    DS1216
  635.     LD    A,(SVRAM)    ; Restore the byte
  636.     LD    (SWRDD0),A    ; at 'SWRDD0'.
  637.     ENDIF ; DS1216
  638. ;
  639. ; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  640. ;
  641.     IF    SB180FX
  642.     LD    BC,(LTCHIMG)    ; Get back original latch
  643.     CALL    SETLATCH    ; image, then write it.
  644.     ENDIF ; SB180FX
  645. ;
  646. ; -------------------------------------------------------------
  647. ;
  648.     IF    SB180 OR SB180FX
  649.     LD    A,(SVCBAR)    ;  Back to the normal memory map.
  650.     OUT0    (CBAR),A
  651. ;
  652. ; -------------------------------------------------------------
  653. ;
  654.     LD    A,(SVRCR)    ; Turn the hardware DRAM
  655.     OUT0    (RCR),A        ; refresh back on.
  656.     ENDIF    ; SB180 OR SB180FX
  657. ;
  658. ; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  659. ;
  660. ;      Since some systems need the interrupts on (like the SB180)
  661. ; and  some need them off,  it is best that we put the    interrupt
  662. ; enable bit back the way the system wants it.
  663. ;
  664.     IF    INTEI
  665.     EI
  666.     ENDIF ; INTEI
  667. ;
  668. ; -------------------------------------------------------------
  669. ;
  670.     LD    A,(DAYS)    ; Make sure there really is a
  671. ;                ; SmartWatch present.
  672. ;
  673.     LD    HL,FRACT    ; Point to BCD    time.
  674. ;
  675.     CP    0FFH        ; All of the bits will be the same
  676.     RET    Z        ; if there is no SmartWatch.
  677.     OR    A        ; Return with the 'Z'-flag set
  678.     RET    Z        ; if no SmartWatch is found.
  679. ;
  680.     AND    OSCOFF    ; See if the SmartWatch has been set,
  681.     CPL        ; '0DFH' means that the SmartWatch is present
  682.     OR    A    ; but not set.
  683. ;            ; '0FFH', and the 'Z'-flag clear, means
  684. ;            ; the SmartWatch is present and set.
  685. ;
  686.     RET
  687. ;
  688. ; -------------------------------------------------------------
  689. ;
  690. PUTCLK:
  691.     IF    DS1216
  692.     LD    A,(SWRDD0)    ; Preserve the byte at
  693.     LD    (SVRAM),A    ; 'SWRDD0'
  694.     ENDIF ; DS1216
  695. ;
  696.     CALL    ACCESS        ; Select the SmartWatch.
  697.     LD    DE,FRACT
  698. ;
  699.     LD    A,(DE)        ; Fractions of a second,
  700.     CALL    WRTCLK
  701.     INC    DE
  702.     LD    A,(DE)        ; Seconds,
  703.     CALL    WRTCLK
  704.     INC    DE
  705.     LD    A,(DE)        ; Minutes,
  706.     CALL    WRTCLK
  707.     INC    DE
  708.     LD    A,(DE)        ; AM/PM, Hours,
  709.     CALL    WRTCLK
  710.     INC    DE
  711.     LD    A,(DE)        ; OSC,RST,Days,
  712.     CALL    WRTCLK
  713.     INC    DE
  714.     LD    A,(DE)        ; Date,
  715.     CALL    WRTCLK
  716.     INC    DE
  717.     LD    A,(DE)        ; Month,
  718.     CALL    WRTCLK
  719.     INC    DE
  720.     LD    A,(DE)        ; Year.
  721.     CALL    WRTCLK
  722. ;
  723.     IF    DS1216
  724.     LD    A,(SVRAM)    ; Restore the byte
  725.     LD    (SWRDD0),A    ; at 'SWRDD0'.
  726.     ENDIF ; DS1216
  727. ;
  728. ; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  729. ;
  730.     IF    SB180FX
  731.     LD    BC,(LTCHIMG)    ; Get back original latch
  732.     CALL    SETLATCH    ; image, then write it.
  733.     ENDIF ; SB180FX
  734. ;
  735. ; -------------------------------------------------------------
  736. ;
  737.     IF    SB180 OR SB180FX
  738.     LD    A,(SVCBAR)    ; Back to the normal memory map.
  739.     OUT0    (CBAR),A
  740. ;
  741. ; -------------------------------------------------------------
  742. ;
  743.     LD    A,(SVRCR)    ; DRAM Hardware refresh back on.
  744.     OUT0    (RCR),A
  745.     ENDIF    ; SB180 OR SB180FX
  746. ;
  747. ; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  748. ;
  749.     IF    INTEI
  750.     EI
  751.     ENDIF ; INTEI
  752. ;
  753. ; -------------------------------------------------------------
  754. ;
  755.     RET
  756. ;
  757. ; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  758. ;
  759. ;
  760.     IF    SB180FX
  761. SETLATCH:XOR    A        ; Indicate that we want to
  762.      DEC    A        ; write to the latch.
  763. ;
  764. LATCHVAL:LD    HL,(BIOSLATCH)    ; Go to the BIOS LATCHVAL
  765.      JP    (HL)        ; routine.
  766.     ENDIF ; SB180FX
  767. ;
  768. ;
  769. ;
  770. ;
  771. ; $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
  772. ; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  773. ; $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
  774. ;
  775. ;
  776. ;    The command section of SWTIME:
  777. ;
  778. START:    LD    HL,0        ; Save the stack pointer.
  779.     ADD    HL,SP        ;  (We can't use Z80
  780.     LD    (STACK),HL    ;   instructions yet.)
  781. ;
  782.     LD    A,7FH        ; Test for Z80 CPU.
  783.     ADD    A,A
  784.     LD    HL,Z80MSG    ; Z80 Only error message.
  785.     JP    PO,MSGEXT    ; Jump if not a Z80.
  786. ;
  787. ;
  788. ; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  789. ;
  790.     IF    SB180 OR SB180FX
  791. ;
  792. ;      If  this  is a real Z-80 CPU,  and not a  HD64180/Z180  CPU.
  793. ; Then    we can't run this version of SWTIME,  because of the IO/MMU
  794. ; instructions.
  795. ;
  796. ;
  797.     LD    HL,Z180MSG    ; Point to '180 only' message.
  798.     SCF              ; Set the carry flag.
  799.     TST    A          ; This will clear the carry flag
  800. ;                  ; on the HD64180/Z180, but it will
  801.     JP    C,MSGEXT      ; remain set on the Z-80.
  802. ;
  803. ;
  804. ;      On a  Zilog Z-80,  the 'TST A' (ED3CH) instruction is a NOP.
  805. ; The ED3CH op-code is an undocumented Z-80 instruction,   so it is
  806. ; a  gamble using it.    Does any one  have any other  ideas,   that
  807. ; don't need to resort    to  'tricks'?
  808. ;
  809. ;      Keep   in  mind    this  code may only be    a  problem  if    the
  810. ; SB180(FX) equate is set when the code is assembled,    AND THEN we
  811. ; try  to run this program on a Z-80.     [I kept erroneously  doing
  812. ; this when I was developing this program,  that is why the code is
  813. ; here at all.]
  814. ;
  815. ;
  816.     ENDIF ; SB180 OR SB180FX
  817. ;
  818. ;
  819. ; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  820. ;
  821. ;    At long last we can get down to doing some useful work.
  822. ;
  823.     LD    SP,STACK    ; Set up our own stack.
  824. ;
  825. ;
  826.     CALL    GETCLK        ; Get all of the info from the
  827. ;                ; SmartWatch.
  828. ;
  829.     LD    HL,NOSWPR    ; Jump if no SmartWatch is present
  830.     JP    Z,MSGEXT    ; in the system.
  831. ;
  832.     LD    C,A        ; Save the watch status code.
  833. ;
  834.     LD    A,(FCB+1)    ; What should we do?
  835. ;
  836.     AND    01011111B    ; Make it upper case.
  837. ;
  838.     CP    'S'        ; Command to set the
  839.     JP    Z,SETTIM    ; SmartWatch?
  840. ;
  841.     LD    B,A        ; Save the command for a while.
  842. ;
  843.     LD    A,C        ; If the command was not the set command
  844.     LD    HL,SWNSET    ; then check to see that the
  845.     CP    OSCON        ; SmartWatch is already set, if
  846.     JP    Z,MSGEXT    ; it is not set, then print an error
  847. ;                ; message, then the help message.
  848. ;
  849.     LD    A,B        ; Get back the users command.
  850.     OR    A        ; print out the time?
  851.     JP    Z,TELTIM    ; Jump if yes.
  852.     CP    'R'        ; Print out the time continuously.
  853.     JP    Z,REPTIM    ; Jump if yes.
  854.     CP    'O'        ; Turn the SmartWatch off?
  855.     JP    Z,TUROFF    ; Jump if yes.
  856. ;
  857. ; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  858. ;
  859.     IF    SB180 OR SB180FX
  860.     CP    'C'        ; Clear the elapsed time clock.
  861.     JP    Z,CLRETM
  862.     CP    'X'        ; Display the elapsed time clock.
  863.     JP    Z,DISETM
  864.     CP    'T'        ; Transfer the SmartWatch time
  865.     JP    Z,TRNSFR    ; to the BIOS clock.
  866.     ENDIF    ; SB180 OR SB180FX
  867. ;
  868. ; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  869. ;
  870. HELP:    LD    HL,HLPMSG    ; HELP !!!
  871. ;
  872. MSGEXT:    CALL    PSTR        ; Print the string pointed to
  873. ;                ; by HL.
  874. ;
  875. EXIT:    LD    HL,(STACK)    ; (Only use 8080 instructions
  876.     LD    SP,HL        ;  here.)
  877.     RET
  878. ;
  879. ; *************************************************************
  880. ;
  881. GETTIM:    LD    A,(HL)
  882.     INC    HL
  883.     SUB    '0'        ; Remove the ASCII bias.
  884.     CP    9+1        ; 0->9?
  885.     JP    NC,HELP        ; If it is not, then print
  886. ;                ; the help message.
  887.     SWAP            ; Swap the nibbles,
  888.     AND    0F0H        ; and do the other nibble.
  889.     LD    C,A        ; Save this binary nibble.
  890. ;
  891.     LD    A,(HL)        ; Do the same as above.
  892.     INC    HL
  893.     SUB    '0'
  894.     CP    9+1
  895.     JP    NC,HELP
  896. ;
  897.     OR    C        ; Make the two BCD digits,
  898. ;                ; one 8 bit binary value.
  899.     RET
  900. ;
  901. ; -------------------------------------------------------------
  902. ;
  903. ; Set the time:
  904. ;
  905. SETTIM:    LD    A,(TBUFF)    ; Read the command buffer.
  906.     CP    18        ; ' S hhmmssMMDDYYdm'?
  907.     JP    NC,HELP
  908.     LD    HL,TBUFF+4
  909.     CALL    GETTIM
  910.     CP    23H+1     ; Check for valid range
  911.     JP    NC,HELP     ; (We'll check 12-hours latter).
  912.     LD    (HRS),A     ; Store the Hours.
  913. ;
  914.     CALL    GETTIM     ; Minutes
  915.     CP    59H+1
  916.     JP    NC,HELP
  917.     LD    (MIN),A
  918. ;
  919.     CALL    GETTIM     ; Seconds
  920.     CP    59H+1
  921.     JP    NC,HELP
  922.     LD    (SEC),A
  923. ;
  924.     CALL    GETTIM     ; Month
  925.     CP    12H+1
  926.     JP    NC,HELP
  927.     LD    (MON),A
  928. ;
  929.     CALL    GETTIM     ; Day of month
  930.     CP    31H+1
  931.     JP    NC,HELP
  932.     LD    (DATE),A
  933. ;
  934.     CALL    GETTIM     ; Year
  935.     CP    99H+1
  936.     JP    NC,HELP
  937.     LD    (YEAR),A
  938. ;
  939.     LD    A,(HL)     ; Days
  940.     INC    HL
  941.     CALL    CATH     ; Convert ASCII to HEX.
  942.     CP    7+1
  943.     JP    NC,HELP
  944.     OR    RSTPIN     ; Ignore the reset pin (Pin #1).
  945.     LD    (DAYS),A
  946. ;
  947. ; AM-PM/12/24/ MODE:
  948. ;
  949. ;      Bit  7 of the hours register is defined as the 12- or  24-
  950. ; hour mode select bit.  When high, the 12-hour mode is selected.
  951. ; In  the 12-hour mode,  bit 5 is the AM/PM bit with  logic  high
  952. ; being  PM.   In the 24-hour mode,  bit 5 is the second 10-hours
  953. ; bit (00-23 hours).
  954. ;
  955.     LD    A,(HL)          ; 'A'm,'P'm or 24-hour?
  956.     AND    01011111B     ; Make it upper case.
  957.     JR    Z,IS24HR      ; Jump if it is 24 hour time.
  958. ;
  959.     CP    'A'          ; AM?
  960.     JR    NZ,TRYPM
  961.     LD    C,10000000B   ; Yes: Set the 12-hour mode
  962.     JR    IS12HR          ; bit.
  963. ;
  964. TRYPM:    CP    'P'          ; PM?
  965.     JP    NZ,HELP
  966.     LD    C,10100000B   ; Yes: Set the 12-hour, and the
  967. ;                  ; PM mode bits.
  968. ;
  969. IS12HR:    LD    A,(HRS)          ; Now we'll check the 12 hour
  970.     CP    12H+1          ; time.
  971.     JP    NC,HELP
  972.     OR    C          ; Put the mode bits, and the hours
  973.     LD    (HRS),A          ; together, and save them.
  974. ;
  975. IS24HR:    CALL    PUTCLK          ; Write all of the info to the
  976. ;                  ; SmartWatch.
  977. ;
  978. ; Fall trough to Tell Time.
  979. ;
  980. ; -------------------------------------------------------------
  981. ;
  982. ; Tell the Time:
  983. ;
  984. TELTIM:    CALL    GETCLK           ; Get  the  info  from  the
  985. ;                   ; SmartWatch.
  986.     CALL    ASCTIM           ; Print out the time
  987.     JP    MSGEXT           ; on the way back to the
  988. ;                   ; operating system.
  989. ;
  990. ; -------------------------------------------------------------
  991. ;
  992. ;
  993. ;
  994. REPTIM:    XOR    A        ; Print the time now!
  995.     DEC    A
  996.     LD    (LSTSEC),A    ; Not a second from now.
  997. ;
  998. TREPLP:    CALL    CONDIN        ; Check for abort by the user,
  999.     JP    NZ,EXIT        ; on the console.
  1000.                 ; If there was a abort request then
  1001. ;                ; go back to the operating system.
  1002. ;
  1003.     CALL    GETCLK        ; Get  the  time  from    the
  1004. ;                ; SmartWatch.
  1005. ;
  1006.     LD    A,(LSTSEC)    ; Is this a new second?
  1007.     LD    C,A
  1008.     LD    A,(SEC)        ; Read the current second
  1009.     CP    C
  1010.     JR    Z,TREPLP    ; Jump if its not.
  1011. ;
  1012.     LD    (LSTSEC),A    ; Save for the next second.
  1013. ;
  1014.     CALL    ASCTIM        ; Convert from BCD to ASCII
  1015.     CALL    PSTR        ; and  print  it  on  the
  1016. ;                ; console.
  1017. ;
  1018.     LD    A,CR        ; Get ready to over-write
  1019.     CALL    COUT        ; this time, with the time
  1020. ;                ; a second from now.
  1021. ;
  1022.     JR    TREPLP        ; On to the next second.
  1023. ;
  1024. ;
  1025. ; -------------------------------------------------------------
  1026. ;
  1027. ;    Turn off, the SmartWatch for long term storage.
  1028. ;
  1029. TUROFF:    LD    A,(DAYS)
  1030.     OR    OSCRST        ; Turn the SmartWatch off.
  1031.     LD    (DAYS),A
  1032.     CALL    PUTCLK        ; Write the info.
  1033. ;
  1034.     LD    HL,SWSOFF    ; Tell'em that the SmartWatch
  1035.     JP    MSGEXT        ; is now off.
  1036. ;
  1037. ;
  1038. ; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  1039. ;
  1040. ;      The   following     are  to maintain compatibility  with    the
  1041. ; SB180(FX)'s, software clock.
  1042. ;
  1043.     IF    SB180 OR SB180FX
  1044. ;
  1045. TRNSFR:    CALL    GETCLK          ; Get the info from the SmartWatch.
  1046. ;
  1047.     LD    A,(HRS)          ; If in the 24 hour mode, then we
  1048.     BIT    7,A          ; have no problem.
  1049.     JR    Z,XFERTM
  1050. ;
  1051.     AND    3FH          ; 12 hour mode. Now things get messy.
  1052. ;
  1053.     CP    12H          ; 12 AM ?
  1054.     JR    NZ,NO12AM
  1055. ;
  1056.     XOR    A          ; YES: 12 AM = 00 HOURS
  1057.     JR    XFERTM
  1058. ;
  1059. NO12AM:    BIT    5,A          ; If it is 01-11 AM then it is ok
  1060.     JR    Z,XFERTM      ; as it is.
  1061. ;
  1062.     CP    32H          ; 12 PM ?
  1063.     JR    NZ,NO12PM
  1064. ;
  1065.     AND    1FH          ; YES: 12 PM = 12 HOURS
  1066.     JR    XFERTM
  1067. ;
  1068. NO12PM:    AND    1FH          ; We now know it is PM.
  1069.     ADD    A,12          ; Convert to 13-23
  1070.     DAA              ; Back to BCD.
  1071.     AND    3FH
  1072. ;
  1073. XFERTM:    CALL    BCD2BIN          ; Transfer the time from
  1074. ;                  ; the SmartWatch to
  1075.     LD    (WHOUR),A     ; the BIOS clock.
  1076. ;
  1077.     LD    A,(MIN)          ; The SmartWatch time is in
  1078.     CALL    BCD2BIN          ; BCD, the BIOS clock wants
  1079.     LD    (WMIN),A      ; the time in binary.
  1080.     LD    A,(SEC)
  1081.     CALL    BCD2BIN
  1082.     LD    (WSEC),A
  1083.     CALL    WRWALL          ; Write the date to the BIOS clock.
  1084.     JP    TELTIM          ; Confirm that it was done.
  1085. ;
  1086. ; #############################################################
  1087. ;
  1088. ;     NOTE:   This   section   of  code (appearing  between  the
  1089. ; '###'  lines)  is  taken  from the  file  'TIME.Z80',  by  Joe
  1090. ; Wright, as supplied with the SB180.  It is used by permission.
  1091. ;     'TIME.Z80' is copyrighted by Joe Wright, 1985.
  1092. ;
  1093. ;
  1094. CLRETM:
  1095.     XOR    A
  1096.     LD    (EHOURS),A
  1097.     LD    (EMINS),A
  1098.     LD    (ESECS),A
  1099.     CALL    WRREAL
  1100. ;
  1101. DISETM:
  1102.     CALL    RDREAL
  1103. ;
  1104.     CALL    PRINT
  1105.     DB    CR,' RTC:  ',0
  1106.     LD    HL,EHOURS
  1107. ;
  1108. TIMEOUT:
  1109.     LD    A,(HL)
  1110.     DEC    HL
  1111.     CALL    BIN2BCD
  1112.     CALL    PA2HC
  1113. ;
  1114.     LD    A,':'        ; I (RLP) added these two
  1115.     CALL    COUT        ; lines.  Comment, or NOP them
  1116. ;                ; to be 100% compatible with
  1117. ;                ; 'TIME.Z80'.
  1118.     LD    A,(HL)
  1119.     DEC    HL
  1120.     CALL    BIN2BCD
  1121.     CALL    PA2HC
  1122.     LD    A,':'
  1123.     CALL    COUT
  1124.     LD    A,(HL)
  1125.     CALL    BIN2BCD
  1126.     CALL    PA2HC
  1127. ;
  1128.     JP    EXIT
  1129. ;
  1130. TIME:
  1131.     LD    HL,(BIOS+1)
  1132.     LD    L,36H        ; Offset to the BIOS clock.
  1133.     JP    (HL)
  1134.  
  1135. RDREAL:
  1136.     OR    255        ; Read flag.
  1137.     PUSH    AF
  1138.     LD    BC,3
  1139.     PUSH    BC
  1140.     LD    DE,1
  1141.     JR    CLOCK
  1142. WRREAL:
  1143.     XOR    A        ; Write flag.
  1144.     PUSH    AF
  1145.     LD    BC,3
  1146.     PUSH    BC
  1147.     LD    DE,1
  1148.     JR    CLOCK
  1149. RDWALL:
  1150.     OR    255        ; Read flag.
  1151.     PUSH    AF
  1152.     LD    BC,3        ; Three bytes.
  1153.     PUSH    BC
  1154.     LD    DE,4        ; Offset to wallclock.
  1155.     JR    CLOCK
  1156. WRWALL:
  1157.     XOR    A        ; Write flag.
  1158.     PUSH    AF
  1159.     LD    BC,3        ; Three bytes.
  1160.     PUSH    BC
  1161.     LD    DE,4        ; Offset to wallclock.
  1162. CLOCK:
  1163.     LD    HL,ETENTHS
  1164.     ADD    HL,DE        ; Add offset.
  1165.     PUSH    HL
  1166.     CALL    TIME        ; Point HL to timer string
  1167.     ADD    HL,DE        ; add offset.
  1168.     POP    DE
  1169.     POP    BC        ; Get byte count,
  1170.     POP    AF        ; get direction.
  1171.     JR    NZ,CLOCK0
  1172.     EX    DE,HL
  1173. CLOCK0:
  1174.     DI
  1175.     LDIR            ; Move it.
  1176.     EI
  1177.     RET
  1178. ;
  1179. ;
  1180. ; BIN2BCD will convert a 0-99 binary number to 0-99 BCD number.
  1181. ; call with (A)=binary number 0-99. (A)=0-99 BCD on exit.
  1182. ;
  1183. BIN2BCD:OR    A    ; BCD 0 = Binary 0,
  1184.     RET    Z    ; so return.
  1185.     LD    B,A    ; Conversion counter.
  1186.     XOR    A    ; Clear 'A'.
  1187. ;
  1188. BINLOP:    INC    A    ; Add one.
  1189.     DAA        ; Binary to BCD.
  1190.     DJNZ    BINLOP    ; All converted?
  1191. ;
  1192.     RET
  1193. ;
  1194. ; #############################################################
  1195. ;
  1196. ;
  1197. ;             BCD to binary converter
  1198. ;              [from BYE504]
  1199. ;
  1200. ; This routine will convert an 8 bit BCD number (0-99) to binary.
  1201. ; the routine returns with the binary number in the 'A' register.
  1202. ;
  1203. BCD2BIN:
  1204.     LD    E,A        ; Save original byte.
  1205.     AND    0FH
  1206.     LD    D,A        ; Save low nibble.
  1207.     LD    A,E
  1208.     AND    0F0H        ; Mask LSN.
  1209.     RRCA            ; x2
  1210.     LD    E,A
  1211.     RRCA            ; x4
  1212.     RRCA            ; x8
  1213.     ADD    A,E        ; x10
  1214.     ADD    A,D        ; Low nibble.
  1215.     RET
  1216. ;
  1217. ;
  1218. ; -------------------------------------------------------------
  1219. ;
  1220.     ENDIF    ; SB180 OR SB180FX
  1221. ;
  1222. ; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  1223. ;
  1224. ;    Convert SmartWatch BCD info to ASCII text.
  1225. ;
  1226. ASCTIM:    LD    HL,TIMSTR    ; Point to the ASCII time.
  1227. ;
  1228. ;
  1229.     LD    A,(HRS)
  1230.     BIT    7,A        ; 12 or 24 time?
  1231.     JR    Z,MILTIM    ; Jump if using 24 time.
  1232. ;
  1233.     AND    1FH        ; Strip unneeded bits, 12 hr mode.
  1234. ;
  1235. MILTIM:    AND    3FH        ; Strip unneeded bits, 24 hr mode.
  1236.     CALL    BCDASC
  1237.     LD    (HL),':'
  1238.     INC    HL
  1239.     LD    A,(MIN)
  1240.     CALL    BCDASC
  1241.     LD    (HL),':'
  1242.     INC    HL
  1243.     LD    A,(SEC)
  1244.     CALL    BCDASC
  1245.     LD    (HL),' '
  1246.     INC    HL
  1247. ;
  1248.     LD    A,(HRS)        ; If in 24 mode
  1249.     BIT    7,A        ; then don't print
  1250.     JR    Z,NOAMPM    ; 'AM' or 'PM'.
  1251. ;
  1252.     LD    (HL),'A'    ; Assume its AM.
  1253.     BIT    5,A        ; Find out if it is really
  1254.     JR    Z,WASAM        ; AM.
  1255.     LD    (HL),'P'    ; No, its PM.
  1256. ;
  1257. WASAM:    INC    HL
  1258.     LD    (HL),'M'
  1259.     INC    HL
  1260.     LD    (HL),' '
  1261.     INC    HL
  1262. ;
  1263. NOAMPM:
  1264.     IF    EDATE
  1265. ;
  1266.     LD    A,(DATE)       ; dd/mm
  1267.     CALL    BCDASC
  1268.     LD    (HL),'/'
  1269.     INC    HL
  1270.     LD    A,(MON)
  1271.     CALL    BCDASC
  1272. ;
  1273.     ELSE
  1274. ;
  1275.     LD    A,(MON)           ; mm/dd
  1276.     CALL    BCDASC
  1277.     LD    (HL),'/'
  1278.     INC    HL
  1279.     LD    A,(DATE)
  1280.     CALL    BCDASC
  1281. ;
  1282.     ENDIF    ; EDATE
  1283. ;
  1284. ;
  1285.     LD    (HL),'/'       ; /yy
  1286.     INC    HL
  1287.     LD    A,(YEAR)
  1288.     CALL    BCDASC
  1289. ;
  1290. ;
  1291.     IF    WEKDAY ; Print the day of the week 'Sun, Mon...'
  1292.     LD    (HL),' '
  1293.     INC    HL
  1294.     PUSH    HL
  1295.     LD    A,(DAYS)
  1296.     AND    7
  1297.     DEC    A        ; Adjust for 0-6.
  1298.     LD    E,A
  1299.     LD    D,0        ; Clear top.
  1300.     LD    HL,DAYTAB    ; Get address of table,
  1301.     ADD    HL,DE        ; table + 3 * (HL) = name.
  1302.     ADD    HL,DE
  1303.     ADD    HL,DE
  1304.     LD    BC,3        ; Move name into buffer.
  1305.     POP    DE
  1306.     LDIR
  1307.     EX    DE,HL
  1308.     ENDIF    ; WEKDAY
  1309. ;
  1310.     LD    (HL),0          ; End marker for string print.
  1311. ;
  1312.     LD    HL,TIMSTR     ; Send the start of the string
  1313.     RET              ; then back to the caller.
  1314. ;
  1315. ; -------------------------------------------------------------
  1316. ;
  1317. ;    Convert a BCD number to ASCII.
  1318. ;
  1319. BCDASC:    PUSH    AF
  1320. ;
  1321.     SWAP               ; Do the upper nibble first
  1322.     AND    0FH
  1323.     OR    '0'           ; Add in the ASCII bias.
  1324.     LD    (HL),A
  1325.     INC    HL
  1326. ;
  1327.     POP    AF           ; Now the lower nibble
  1328.     AND    0FH
  1329.     OR    '0'
  1330.     LD    (HL),A
  1331.     INC    HL
  1332. ;
  1333.     RET
  1334. ;
  1335. ; -------------------------------------------------------------
  1336. ;
  1337. Z80MSG:    DB CR,LF,CR,LF
  1338.     DB '*** SWTIME, will not work on the 8080 or the 8085'
  1339.     DB ', sorry... ***'
  1340.     DB CR,LF,CR,LF,0
  1341. ;
  1342. ; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  1343. ;
  1344.     IF    SB180 OR SB180FX
  1345. Z180MSG:DB CR,LF,CR,LF
  1346.     DB '*** This version of SWTIME is configured for '
  1347.     DB 'the HD64180/Z180.',CR,LF
  1348.     DB '    Reassemble to use on the Z80. ***'
  1349.     DB CR,LF,CR,LF,0
  1350.     ENDIF ; SB180 OR SB180FX
  1351. ;
  1352. ; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  1353. ;
  1354. SWSOFF:    DB CR,LF,CR,LF
  1355.     DB '***  The SmartWatch is now turned off.  ***'
  1356.     DB CR,LF,CR,LF,0
  1357. ;
  1358. ; -------------------------------------------------------------
  1359. ;
  1360. NOSWPR:    DB CR,LF,CR,LF
  1361.     DB '***  No  SmartWatch is present.  ***'
  1362. ;
  1363. ;      Fall  trough  to  the "Not Set" message.   If  there  is  no
  1364. ; SmartWatch present then by default it won't be set.
  1365. ;
  1366. ;
  1367. SWNSET:    DB CR,LF
  1368.     DB '***  The SmartWatch is not set.  ***'
  1369.     DB CR,LF
  1370. ;
  1371. ;      If  the    SmartWatch  is "Not Set" then fall  trough  to    the
  1372. ; "Help" screen,  so that we can get instructions on how to set the
  1373. ; SmartWatch.
  1374. ;
  1375. HLPMSG:    DB CR,LF
  1376.     DB '                          SWTIME VER:'
  1377. ;
  1378.     DB MAIN         +'0',               '.'
  1379.     DB VERS      /10+'0', VERS      MOD 10+'0', ' - '
  1380.     DB VMONTH /10+'0', VMONTH MOD 10+'0', '/'
  1381.     DB VDAY      /10+'0', VDAY      MOD 10+'0', '/'
  1382.     DB VYEAR  /10+'0', VYEAR  MOD 10+'0'
  1383. ;
  1384.     DB CR,LF
  1385.     DB '                   Copyright (C) 1986-1987 by Robert Paddock.'
  1386. ;
  1387.     DB CR,LF,CR,LF
  1388.     DB '                This program allows setting and reading of the:'
  1389.     DB CR,LF
  1390.     DB '                       Dallas Semiconductor "SmartWatch".'
  1391.     DB CR,LF,CR,LF
  1392. ;
  1393.     DB ' Usage:',CR,LF,CR,LF
  1394. ;
  1395.     DB '  SWTIME<CR> Will display the date and time of day.'
  1396. ;
  1397.     DB CR,LF
  1398.     DB '  SWTIME R<CR> Displays the time & date repeatedly.'
  1399. ;
  1400.     DB CR,LF
  1401.     DB '  SWTIME O<CR> Turn the SmartWatch off, for long term storage.'
  1402. ;
  1403.     DB CR,LF
  1404.     DB '  SWTIME S hhmmssMMDDYYdm<CR> Will set the time, date and day.'
  1405.     DB CR,LF,CR,LF
  1406.     DB '     Where:  hh=Hours (00-23/00-12), '
  1407.     DB 'mm=Minutes (00-59), '
  1408.     DB 'ss=Seconds (00-59), '
  1409.     DB CR,LF
  1410.     DB '             MM=Months (01-12), '
  1411.     DB 'DD=Day of month (01-31), '
  1412.     DB 'YY=Year (00-99),'
  1413.     DB CR,LF
  1414.     DB '              d=Day of week (1=Sunday, 7=Saturday),'
  1415.     DB CR,LF
  1416.     DB '              m=Mode: "A" = AM, "P" = PM, '
  1417.     DB 'omit for 24 hour format.'
  1418.     DB CR,LF,CR,LF
  1419. ;
  1420. ; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  1421. ;
  1422.     IF    SB180 OR SB180FX
  1423.     DB '  SWTIME C<CR> Clear the elapsed time clock.'
  1424.     DB CR,LF
  1425.     DB '  SWTIME X<CR> Display the elapsed time clock.'
  1426.     DB CR,LF
  1427.     DB '  SWTIME T<CR> Transfer the time of day from the'
  1428.     DB CR,LF
  1429.     DB '               SmartWatch to the SB180 BIOS clock.'
  1430.     DB CR,LF
  1431.     ENDIF  ; SB180 OR SB180FX
  1432. ;
  1433. ; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  1434. ;
  1435.     DB 0    ; end marker for string print
  1436. ;
  1437. ;
  1438. ; -------------------------------------------------------------
  1439. ;
  1440.     IF    WEKDAY
  1441. DAYTAB:    DB    'SUN'    ; Day of week table.
  1442.     DB    'MON'
  1443.     DB    'TUE'
  1444.     DB    'WED'
  1445.     DB    'THU'
  1446.     DB    'FRI'
  1447.     DB    'SAT'
  1448.     ENDIF ; WEKDAY
  1449. ;
  1450. ; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  1451. ;
  1452.     IF    SB180FX
  1453. LTCHIMG:   DS    2    ; Image of SB180FX latch
  1454. BIOSLATCH: DS    2    ; Address of BIOS LATCHVAL routine
  1455.     ENDIF  ; SB180FX
  1456. ;
  1457. ; -------------------------------------------------------------
  1458. ;
  1459.     IF    SB180 OR SB180FX
  1460. SVCBAR:    DS    1    ; Save the MMU register CBAR.
  1461. SVRCR:    DS    1    ; Save the refresh register RCR.
  1462. ;
  1463. ETENTHS:DS    1    ; Elapsed time clock.
  1464. ESECS:    DS    1
  1465. EMINS:    DS    1
  1466. EHOURS:    DS    1
  1467. ;
  1468. WSEC:    DS    1    ; 'Wall clock' (Real time of day).
  1469. WMIN:    DS    1
  1470. WHOUR:    DS    1
  1471.     ENDIF    ; SB180 OR SB180FX
  1472. ;
  1473. ; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  1474. ;
  1475.     IF    DS1216
  1476. SVRAM:    DS    1    ; Place to save the RAM byte at SWRDD0.
  1477.     ENDIF ; DS1216
  1478. ;
  1479. ;
  1480. LSTSEC:    DS    1    ; Place to save the 'Last Second'.
  1481. ;
  1482. FRACT:    DS    1    ; Fractions of a second
  1483. SEC:    DS    1    ; Seconds
  1484. MIN:    DS    1    ; Minutes
  1485. HRS:    DS    1    ; Hours
  1486. DAYS:    DS    1    ; Days
  1487. DATE:    DS    1    ; Date
  1488. MON:    DS    1    ; Month
  1489. YEAR:    DS    1    ; Years
  1490. ;
  1491. TIMSTR:    DS    128    ; Place to store the ASCII time string,
  1492. ;            ; (and stack head room).
  1493. STACK:    DS    2    ; Place to save the operating systems
  1494. ;            ; stack pointer.
  1495. ;
  1496. ; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  1497. ;
  1498.     IF    SB180 OR SB180FX
  1499.     .DEPHASE    ; End of logical phase block.
  1500.     ENDIF    ; SB180 OR SB180FX
  1501. ;
  1502. ; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  1503. ;
  1504. LSTADR    EQU    $    ; Last address of code that may
  1505. ;            ; need transferred.
  1506. ;
  1507. ;
  1508. ; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1509. ; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  1510. ; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1511. ;
  1512. ;
  1513. ;      Here are some interesting things related to 'Time':
  1514. ;
  1515. ;      Exactly what is this thing called 'Time' anyway?
  1516. ;
  1517. ;    The    following  documents  are   available   from    the
  1518. ; National Technical  Information  Service  (NTIS),  an agency    of
  1519. ; the U.S. Department of Commerce:
  1520. ;
  1521. ;             5285 Port    Royal  Road,
  1522. ;              Springfield, VA 22161:
  1523. ;              (703) 487-4650
  1524. ;
  1525. ;             JPRS: 45238, 2 May 1968
  1526. ;
  1527. ; "The possibility of the Experimental Study of the  Properties
  1528. ;              of Time; by N. Kozyrev"
  1529. ;
  1530. ;               $9.95 + $3 Shipping
  1531. ;
  1532. ; -----------------------------------------------------------------
  1533. ;
  1534. ;      Cesium  atoms,  which  are  used in  Atomic-Clocks,  have  a
  1535. ; resonant frequency of 9.192631770  GHz.
  1536. ;
  1537. ; -----------------------------------------------------------------
  1538. ;
  1539. ; The speed of light according to  by Dr.  Taylor of the  National
  1540. ; Bureau of Standards (USA) [on 11/14/85, at 8:35 AM]  was:
  1541. ;
  1542. ;          299,792,458 Meters per Second
  1543. ;         [186,282.3971 Miles per second]
  1544. ;
  1545. ;      These measurements were made in October of 1983.
  1546. ;
  1547. ;
  1548. ;     "The   Meter   has   been  redefined  using   this   number
  1549. ; [299,792,458]."
  1550. ;
  1551. ;      From  the  Sixth  Edition of "Modern College  Physics"  by
  1552. ; Harvey E. White:
  1553. ;
  1554. ;      The  standard  meter  {1},is  defined  in  terms  of   the
  1555. ; wavelength  of  light  from  a source  containing  KRYPTON  GAS
  1556. ; (chemical element 36):
  1557. ;
  1558. ;        1 meter = 1,650,763.73 wavelengths
  1559. ;          (For orange light of krypton)
  1560. ;
  1561. ;      {1}:  Adopted  as  the  International  legal  standard  of
  1562. ; length,  October 14, 1960, by the General Conference on Weights
  1563. ; and Measures in Paris, France.
  1564. ;
  1565. ; ----------------------------------------------------------------
  1566. ;
  1567. ;    Light-year:  The distance traveled by light in one year.
  1568. ;
  1569. ;      There  are 9.454254955 * 10^12 millimeters in  one  light-
  1570. ; year.
  1571. ;
  1572. ; -----------------------------------------------------------------
  1573. ;
  1574. ;      A  large  (6' by 4') multi-color  map showing  all  25  time
  1575. ; zones  of   the   planet  Earth,   is  available  from  the  U.S.
  1576. ; Defense Mapping Agency, request:
  1577. ;
  1578. ;         "Standard Time Zone Chart of the World"
  1579. ;          Chart #76; DMA Stock #WOBZC76
  1580. ;                  $5.50
  1581. ;
  1582. ;      Information  on    maps  and charts produced  by  the  Defense
  1583. ; Mapping Agency, is available from:
  1584. ;
  1585. ;
  1586. ;              Defense Mapping Agency
  1587. ;   Office of Distribution Services, U.S. Department of Defense
  1588. ;               Attn: DDCP
  1589. ;            Washington, DC 20315-0020
  1590. ;              (202)-227-2816
  1591. ;
  1592. ;          All orders must be pre-paid:
  1593. ;    Make checks payable to "Treasurer of the United States"
  1594. ;
  1595. ;      [  The  quality of this map,  is well worth the    price.     It
  1596. ; takes about ten weeks to get it.  The DMA is cheep, not fast. ]
  1597. ;
  1598. ; -------------------------------------------------------------
  1599. ;
  1600. ;      00:00:00  and 24:00:00 are interchangeable.   24:00:00  is
  1601. ; associated with the date of the day ending,  00:00:00 with  the
  1602. ; day just starting.
  1603. ;
  1604. ;
  1605. ; -------------------------------------------------------------
  1606. ;
  1607. ;         One Side Real Day = 23:56:04
  1608. ;
  1609. ; -------------------------------------------------------------
  1610. ;
  1611. ;      At  a Horological Exhibit you could see examples of clocks
  1612. ; and watches representing  America,  England,    France,  Austria,
  1613. ; Japan,  Holland  and    others during the 18th,  19th,    and  20th
  1614. ; Century.
  1615. ;
  1616. ;      You might see the work of:  Ely Terry, Abel Chandler, Aron
  1617. ; Crane, Livi and Able Hutchins, Joseph Ives, Chauncy Jerome, Asa
  1618. ; Munger,  Chas Kirk,  Henri Robert, Antide Janvier, Seth Thomas,
  1619. ; Abner Jones,    Geo.  Solliday, David Wood, Simon Willard Jr, The
  1620. ; Howards.
  1621. ;
  1622. ; -------------------------------------------------------------
  1623. ;
  1624. ;      Julian  Dates:    Julian dates as used by  astronomers  take
  1625. ; noon,  1  January 4713 B.C.  as the base date (astronomers count
  1626. ; days from noon to noon).   CP/M-3 uses a base data of 1  January
  1627. ; 1978.
  1628. ;
  1629. ;      Julian Dates, can be usefully applied in computer programs.
  1630. ; Particularly    for  real-time control of processes that  need    to
  1631. ; handle long term event scheduling.
  1632. ;
  1633. ;
  1634. ;      See  "Julian Dates For Microcomputers" by Gordon  King;    Dr
  1635. ; Dobb's  Journal,  Number 80,    June 1983,  for code on how to use
  1636. ; Julian Dates.
  1637. ;
  1638. ; -------------------------------------------------------------
  1639. ;
  1640. ;             Ephemeris Time:
  1641. ;
  1642. ;     "Ephemeris Time is based on idealized motions of the Sun    and
  1643. ; Moon    and was introduced into the astronomical tables on  January
  1644. ; 1,  1960  to    free astronomical calculations from the  effect  of
  1645. ; irregularities  of  the  Earth's  rotation.    The  irregularities
  1646. ; apparently  show  up    in GMT(UT) but not UTC which  is  based  on
  1647. ; atomic  clocks  and broadcast by WWV.   Not to worry - all  these
  1648. ; times differ from each other by less than a second."
  1649. ;
  1650. ;            -- 03/11/87 SYSOP [ of NOAA]
  1651. ;
  1652. ; -------------------------------------------------------------
  1653. ;
  1654. ;    The
  1655.     END
  1656.