home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / utils / asmutl / asmlib.lbr / SBCMON.AZM / SBCMON.ASM
Encoding:
Assembly Source File  |  1991-06-25  |  12.3 KB  |  544 lines

  1. ;----------------------------------------------------------------
  2. ; This program reads 4 digital input lines on an SBC-800 board
  3. ; parallel port lines and uses them to count external events.
  4. ; It is assumed that the lines will be low, going high, then low
  5. ; again. The leading edge is detected and when the falling edge is
  6. ; found then a counter is incermented. 
  7. ;
  8. ;            Written        R.C.H.     23/10/83
  9. ;            Last Update     R.C.H.     08/12/83
  10. ;----------------------------------------------------------------
  11. ;
  12.     extrn    prolog,inline,cie,coe,cst,cursor,clkrd,bell
  13.     extrn    bell,setxy,pmenu,quit,clear,caps,crlf
  14.     extrn    nolzb,lzb,blzb,phacc,pdde,phde,dispatch,hexbcd
  15.     extrn    curon,curoff,clkrd,xyinline
  16. ;
  17. data    equ    080h        ; data port to read for the 4 switches
  18. stat    equ    data+3        ; status port for the data port
  19. cntmax    equ    030        ; loops between time check & print
  20. timx    equ    22        ; time x column screen address
  21. timy    equ    22        ; time y row address
  22. ;
  23.     call    prolog
  24.     call    clear
  25.     lxi    d,display    ; display a message
  26.     call    pmenu
  27.     call    curoff        ; disable the cursor
  28.     call    blzb        ; nice blanking is required
  29. ; Clear all the counts next
  30.     call    clear0
  31.     call    clear1
  32.     call    clear2
  33.     call    clear3        ; all set to 00, status also
  34. ; Now we set up a default status of the on / off switches by setting them on
  35.     mvi    c,0ffh        ; all switches on
  36.     call    check4
  37.     call    check5
  38.     call    check6
  39.     call    check7
  40. ;
  41. ; Set up the 8255 to be an input device on channel A
  42.     mvi    a,090h        ; a inputs, b&c outputs
  43.     out    stat
  44. ;
  45.     mvi    a,1        ; display time soonest possible 
  46.     sta    counts        ; save a loop counter
  47. ;
  48. ; Now go straight into the loop.
  49. ; Read the input port PA0 and detect which switches are on and off
  50. ; Use this to detect switch transitions.
  51. ;
  52. loop:
  53.     in    data
  54.     mov    c,a        ; save the data byte
  55.     call    check0        ; bits 0--7 are counters
  56.     call    check1
  57.     call    check2
  58.     call    check3
  59.     call    check4        ; bits 4--7 are on / off switches
  60.     call    check5
  61.     call    check6
  62.     call    check7
  63.     call    chk$counts    ; check the loop counter
  64.     call    do$bell        ; ring bell only if a changed counter
  65.     call    cst        ; character typed ?
  66.     jz    loop
  67.     call    cie
  68.     call    caps
  69.     cpi    'Q'
  70.     jz    finish
  71.     lxi    h,loop
  72.     push    h        ; put a return address on stack
  73.     cpi    '0'
  74.     jz      clear0
  75.     cpi    '1'
  76.     jz      clear1
  77.     cpi    '2'
  78.     jz      clear2
  79.     cpi    '3'
  80.     jz      clear3
  81.     cpi    'T'
  82.     jz    tog$bell    ; toggle the bell
  83.     jmp    bell        ; all else was an illegal character
  84. ;
  85. finish:
  86.     lxi    d,21        ; line 22
  87.     call    cursor
  88.     call    crlf
  89.     call    curon        ; restore the cursor
  90.     jmp    quit
  91. ;
  92. ;----------------------------------------------------------------
  93. ; This routine must get the count of the number of times the
  94. ; program has looped and when it is 00 it prints the time
  95. ; on the screen where it is set up for.
  96. ;----------------------------------------------------------------
  97. ;
  98. chk$counts:
  99.     lda    counts
  100.     dcr    a
  101.     sta    counts
  102.     ora    a
  103.     rnz            ; exit if not end of loop
  104. ;
  105.     mvi    a,cntmax    ; get maximum count value
  106.     sta    counts
  107. ; Now get the time
  108.     lxi    d,tbuff        ; point to time buffer
  109.     call    clkrd        ; read the clock into it
  110. ; Now check the validity of the time
  111.  
  112.  
  113. ; Now we check if the seconds has changed since the last time we were here
  114.     lda    old$secs
  115.     mov    c,a        ; save
  116.     lda    secs        ; get current seconds value
  117.     cmp    c        ; same ??
  118.     rz            ; return now if the same
  119.     sta    old$secs    ; save the seconds
  120. ;
  121. ; Since time is ok, print it after x,y addressing
  122. prnt$time:
  123.     mvi    d,timx + 7
  124.     mvi    e,timy
  125.     call    cursor        ; do the set up
  126. ;
  127.     call    nolzb
  128.     lda    hrs    
  129.     call    phacc        ; display it
  130.     mvi    a,':'
  131.     call    dispatch
  132.     lda    mins
  133.     call    phacc
  134.     mvi    a,':'
  135.     call    dispatch
  136.     lda    secs
  137.     call    phacc
  138.     call    blzb        ; back to blank filled lzb again
  139. ;
  140. ; Now print the loops counter. This = the number of seconds we have run.
  141.     lhld    loops
  142.     inx    h
  143.     shld    loops
  144.     xchg            ; load into DE
  145.     call    inline
  146.     db    '  $'
  147.     call    pdde
  148.     ret
  149. ;
  150. ;----------------------------------------------------------------
  151. ; The following four routines use the byte passed in and use
  152. ; it to detect a switch transition. A switch transition occurrs
  153. ; when an input goes high then low.
  154. ;----------------------------------------------------------------
  155. ;
  156. check0:
  157.     mov    a,c        ; fetch input byte
  158.     ani    1        ; make it a 1 or a 0 only
  159.     mov    e,a        ; put into e
  160.     lda    status0
  161.     cmp    e        ; is the previous value the same ??
  162.     rz            ; exit if so
  163. ; We have gone high-> low or low-> high if here
  164.     jnc    c0fall        ; no carry means a falling edge
  165. ; Here and there is a rising edge.
  166.     mvi    a,1
  167.     sta    status0        ; save it
  168.     ret
  169. ; Here and a falling edge detected.
  170. c0fall:
  171.     xra    a
  172.     sta    status0
  173.     lhld    s0        ; load the count value
  174.     inx    h
  175.     shld    s0
  176. ; set up cursor and display
  177. dsp0:    ; The entry to display hl on the screen
  178.     lxi    d,0a06h
  179.     call    cursor
  180.     xchg
  181.     call     pdde
  182.     mvi    a,0ffh
  183.     sta    ring        ; flag a change in a counter
  184.     ret
  185. ;
  186. ; Second counter exactly the same way
  187. ;
  188. check1:
  189.     mov    a,c        ; fetch input byte
  190.     ani    2        ; make it a 1 or a 0 only
  191.     mov    e,a        ; put into e
  192.     lda    status1
  193.     cmp    e        ; is the previous value the same ??
  194.     rz            ; exit if so
  195. ; We have gone high-> low or low-> high if here
  196.     jnc    c1fall        ; no carry means a falling edge
  197. ; Here and there is a rising edge.
  198.     mvi    a,2        ; save the bit number
  199.     sta    status1        ; save it
  200.     ret
  201. ; Here and a falling edge detected.
  202. c1fall:
  203.     xra    a
  204.     sta    status1
  205.     lhld    s1        ; load the count value
  206.     inx    h
  207.     shld    s1
  208. ; set up cursor and display
  209. dsp1:    ; The entry to display hl on the screen
  210.     lxi    d,0a08h
  211.     call    cursor
  212.     xchg
  213.     call     pdde
  214.     mvi    a,0ffh
  215.     sta    ring
  216.     ret
  217. ;
  218. ; Third counter
  219. ;
  220. check2:
  221.     mov    a,c        ; fetch input byte
  222.     ani    4        ; make it a 1 or a 0 only
  223.     mov    e,a        ; put into e
  224.     lda    status2
  225.     cmp    e        ; is the previous value the same ??
  226.     rz            ; exit if so
  227. ; We have gone high-> low or low-> high if here
  228.     jnc    c2fall        ; no carry means a falling edge
  229. ; Here and there is a rising edge.
  230.     mvi    a,4
  231.     sta    status2        ; save it
  232.     ret
  233. ; Here and a falling edge detected.
  234. c2fall:
  235.     xra    a
  236.     sta    status2
  237.     lhld    s2        ; load the count value
  238.     inx    h
  239.     shld    s2
  240. ; set up cursor and display
  241. dsp2:    ; The entry to display hl on the screen
  242.     lxi    d,0a0ah
  243.     call    cursor
  244.     xchg
  245.     call     pdde
  246.     mvi    a,0ffh
  247.     sta    ring
  248.     ret
  249. ;
  250. ; Fourth and last counter
  251. ;
  252. check3:
  253.     mov    a,c        ; fetch input byte
  254.     ani    8        ; make it a 1 or a 0 only
  255.     mov    e,a        ; put into e
  256.     lda    status3
  257.     cmp    e        ; is the previous value the same ??
  258.     rz            ; exit if so
  259. ; We have gone high-> low or low-> high if here
  260.     jnc    c3fall        ; no carry means a falling edge
  261. ; Here and there is a rising edge.
  262.     mvi    a,8
  263.     sta    status3        ; save it
  264.     ret
  265. ; Here and a falling edge detected.
  266. c3fall:
  267.     xra    a
  268.     sta    status3
  269.     lhld    s3        ; load the count value
  270.     inx    h
  271.     shld    s3
  272. ; set up cursor and display
  273. dsp3:    ; The entry to display hl on the screen
  274.     lxi    d,0a0ch
  275.     call    cursor
  276.     xchg
  277.     call     pdde
  278.     mvi    a,0ffh
  279.     sta    ring
  280.     ret
  281. ;
  282. ;----------------------------------------------------------------
  283. ; These routines display the status of the on / off switches 
  284. ; connected to bits 4 to 7 inclusive. 
  285. ; The only time the switch has its message changed is when there is a 
  286. ; transition from one state to another. All else causes a return.
  287. ; On entry register C = the input byte. Each routine checks its bit
  288. ; to see if there is a change from the bit saved in memory. If a 
  289. ; difference then the message is changed and the bit saved.
  290. ;----------------------------------------------------------------
  291. ;
  292. check4:
  293.     mov    a,c        ; fetch the bit
  294.     ani    010h        ; test bit 4
  295.     mov    e,a        ; save it back
  296.     lda    s4
  297.     cmp    e        ; is the original equal to the new ?
  298.     rz        ; This is the immediate exit if no change
  299. ;
  300. ; Here we do a conditional bell.
  301. ; Now write the new bit back to memory then test is the message should be 
  302. ; an on or off message, print it then return.
  303.     mov    a,e        ; restore masked / tested bit
  304.     sta    s4
  305.     ora    a
  306.     jz    c4off        ; display check 4 off message
  307. ; Here display the on message
  308.     lxi    d,0c0eh
  309.     call    cursor
  310.     call    inline
  311.     db    ' ON$'
  312.     ret
  313. c4off:
  314.     lxi    d,0c0eh
  315.     call    cursor
  316.     call    inline    
  317.     db    'OFF$'
  318.     ret
  319. ;
  320. ; Check the second switch status
  321. ;
  322. check5:
  323.     mov    a,c        ; fetch the bit
  324.     ani    020h        ; test bit 5
  325.     mov    e,a        ; save it back
  326.     lda    s5
  327.     cmp    e        ; is the original equal to the new ?
  328.     rz        ; This is the immediate exit if no change
  329. ;
  330. ; Here we do a conditional bell.
  331. ; Now write the new bit back to memory then test is the message should be 
  332. ; an on or off message, print it then return.
  333.     mov    a,e        ; restore masked / tested bit
  334.     sta    s5
  335.     ora    a
  336.     jz    c5off        ; display check 4 off message
  337. ; Here display the on message
  338.     lxi    d,0c10h
  339.     call    cursor
  340.     call    inline
  341.     db    ' ON$'
  342.     ret
  343. c5off:
  344.     lxi    d,0c10h
  345.     call    cursor
  346.     call    inline    
  347.     db    'OFF$'
  348.     ret
  349. ;
  350. ; Check the tried switch
  351. ;
  352. check6:
  353.     mov    a,c        ; fetch the bit
  354.     ani    040h        ; test bit 6
  355.     mov    e,a        ; save it back
  356.     lda    s6
  357.     cmp    e        ; is the original equal to the new ?
  358.     rz        ; This is the immediate exit if no change
  359. ;
  360. ; Here we do a conditional bell.
  361. ; Now write the new bit back to memory then test is the message should be 
  362. ; an on or off message, print it then return.
  363.     mov    a,e        ; restore masked / tested bit
  364.     sta    s6
  365.     ora    a
  366.     jz    c6off        ; display check 4 off message
  367. ; Here display the on message
  368.     lxi    d,0c12h
  369.     call    cursor
  370.     call    inline
  371.     db    ' ON$'
  372.     ret
  373. c6off:
  374.     lxi    d,0c12h
  375.     call    cursor
  376.     call    inline    
  377.     db    'OFF$'
  378.     ret
  379. ;
  380. ; Check the last (bottom) switch
  381. ;
  382. check7:
  383.     mov    a,c        ; fetch the bit
  384.     ani    080h        ; test bit 4
  385.     mov    e,a        ; save it back
  386.     lda    s7
  387.     cmp    e        ; is the original equal to the new ?
  388.     rz        ; This is the immediate exit if no change
  389. ;
  390. ; Here we do a conditional bell.
  391. ; Now write the new bit back to memory then test is the message should be 
  392. ; an on or off message, print it then return.
  393.     mov    a,e        ; restore masked / tested bit
  394.     sta    s7
  395.     ora    a
  396.     jz    c7off        ; display check 4 off message
  397. ; Here display the on message
  398.     lxi    d,0c14h
  399.     call    cursor
  400.     call    inline
  401.     db    ' ON$'
  402.     ret
  403. c7off:
  404.     lxi    d,0c14h
  405.     call    cursor
  406.     call    inline    
  407.     db    'OFF$'
  408.     ret
  409. ;
  410. ; Clear the counters. This is called at program start and when
  411. ; keystroke options are entered
  412. ;
  413. clear0:
  414.     xra    a
  415.     lxi    h,0
  416.     shld    s0
  417.     sta    status0
  418.     jmp    dsp0        ; display this new value
  419. ;
  420. clear1:
  421.     xra    a
  422.     lxi    h,0
  423.     shld    s1
  424.     sta    status1
  425.     jmp    dsp1
  426. ;
  427. clear2:
  428.     xra    a
  429.     lxi    h,0
  430.     shld    s2
  431.     sta    status2
  432.     jmp    dsp2
  433. ;
  434. clear3:
  435.     xra    a
  436.     lxi    h,0
  437.     shld    s3
  438.     sta    status3
  439.     jmp    dsp3
  440. ;
  441. ; This is the conditional bell ringer. If the bell status flag is
  442. ; 00 then the bell is not sounded else if non zero then it is rung.
  443. ;
  444. do$bell:
  445.     lda    bell$stat
  446.     ora    a
  447.     rz
  448. ; Now we check the bell code in ring. If this is not 00 then we clear it
  449. ; then ring the bell. This byte really only is used to indicate
  450. ; a changed counter.
  451.     lda    ring
  452.     ora    a
  453.     rz                ; exit since no counters tripped
  454.     xra    a
  455.     sta    ring            ; clear the byte if it is set
  456.     jmp    bell            ; return after ringing the bell
  457. ;
  458. ; This simple routine toggles the bell in and out. The bell is 
  459. ; in when the bell stat byte is not 00.
  460. ;
  461. tog$bell:
  462.     lxi    d,0340ah        ; col 53, lin 10
  463.     call    cursor
  464. ;
  465.     lda    bell$stat
  466.     xri    0ffh            ; toggle it
  467.     sta    bell$stat
  468. ;
  469.     ora    a            ; 00 and bell off
  470.     jz    tog$bell2
  471. ; here and the bell is on, next time we toggle off
  472.     call    inline
  473.     db    'OFF$'
  474.     ret
  475. ; here and the bell is disabled so we toggle it on next time
  476. tog$bell2:
  477.     call    inline
  478.     db    'ON $'
  479.     ret
  480. ;
  481. ; Message display area next
  482. ;
  483. display:
  484.     db    12,00,'SBC-800 Switch Transition Counter  V1.0$'
  485.     db    00,06,' Count 0$'
  486.     db    00,08,' Count 1$'
  487.     db    00,10,' Count 2$'
  488.     db    00,12,' Count 3$'
  489.     db    00,14,'Switch 0 $'
  490.     db    00,16,'Switch 1 $'
  491.     db    00,18,'Switch 2 $'
  492.     db    00,20,'Switch 3 $'
  493.     db    36,04,'------Options----$'
  494.     db    36,06,'0 = Clear Count 0$'
  495.     db    36,07,'1 = Clear Count 1$'
  496.     db    36,08,'2 = Clear Count 2$'
  497.     db    36,09,'3 = Clear Count 3$'
  498.     db    36,10,'T = Toggle bell ON$'
  499.     db    36,12,'Q = Quit$'
  500.     db    timx,timy,'Time$'
  501.     db    timx+24,timy,'Total Seconds$'
  502.     db    0ffh
  503. ;
  504.     dseg
  505. ;
  506. ; The next 8 sections are used to detect leading edges and to
  507. ; count switch transitions.
  508. ;
  509. s0    db    00,00
  510. status0    db    00
  511. s1    db    00,00
  512. status1    db    00
  513. s2    db    00,00
  514. status2    db    00
  515. s3    db    00,00
  516. status3    db    00
  517. ;
  518. ; The next 4 locations are for the switches
  519. ;
  520. s4    db    00
  521. s5    db    00
  522. s6    db    00
  523. s7    db    00
  524. ;
  525. ; Status flags
  526. ;
  527. bell$stat:
  528.     db    00            ; 00 = bell off, else bell on
  529. ring    db    00            ; 00 = no ring, 0ffh = change so ring
  530. ;
  531. ; A buffer to read the time into
  532. ;
  533. loops    db    00,00            ; loop counter = total seconds run
  534. counts    db    00            ; count program loops
  535. old$secs    
  536.     db    00            ; Save to check time against
  537. ;
  538. tbuff:    db    00,00,00,00        ; year, month, day, dow
  539. hrs    db    00
  540. mins    db    00
  541. secs    db    00
  542. ;
  543.     end
  544.