Guest User

Untitled

a guest
Aug 28th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. HALT    MACRO
  2.     MOVE.B  #9,D0
  3.     TRAP    #15
  4.     ENDM
  5.  
  6. NOON    EQU 12*60*60*100    noon in 100's of a second
  7.  
  8. * Delay for hundredths of a second in param 1
  9. DELAY   MACRO
  10.     move.b  #23,d0          trap task 23
  11.     move.l  #\1,d1          delay amount
  12.     trap    #15
  13.     ENDM
  14.  
  15.  
  16. *-------------------------- PROGRAM START ---------------------------
  17.     ORG $1000
  18.  
  19. START
  20.     * initialize
  21.     clr.w   seconds
  22.     move.b  #32,d0          trap task to get address of hardware
  23.     move.b  #0,d1
  24.     trap    #15             display hardware window
  25.     move.b  #1,d1
  26.     trap    #15             get address of 7-segment display
  27.     move.l  d1,a4           A4 = Address of 7-segment display
  28.     move.b  #2,d1
  29.     trap    #15             get address of LEDs
  30.     move.l  d1,a3           A3 = Address of LEDs
  31.  
  32. loop
  33.     move.l  a4,a2
  34.     repeat
  35.         move.b  #8,d0           Read timer, get 100ths of a second since midnight in D1.L
  36.         trap    #15
  37.         if.l d1 <hs> #NOON then.s
  38.             sub.l #NOON,d1      time = time - NOON
  39.         endi
  40.         * Calculate total minutes (D5), minutes this hour (D6), seconds (D7)
  41.         divu    #100,d1         convert to seconds
  42.         move.l  d1,d4           save fractional seconds
  43.         andi.l  #$0000ffff,d1   discard fractional seconds
  44.         divu    #60,d1          convert to minutes
  45.         move.l  d1,d7
  46.         move.l  #16,d0 
  47.         lsr.l   d0,d7           d7 = seconds
  48.         andi.l  #$0000ffff,d1   discard seconds from d1
  49.         move.l  d1,d5           d5 = total minutes
  50.         divu    #60,d1          convert to hours
  51.         move.l  d1,d6
  52.         move.l  #16,d0
  53.         lsr.l   d0,d6           minutes this hour to d6
  54.         swap    d4              display fractional seconds on LEDs
  55.         move.b  d4,(a3)
  56.         DELAY   1               1/100 sec delay to reduce CPU workload
  57.     until.w d7 <ne> seconds do  until a second has elapsed
  58.  
  59. * update the display on the 7-segment readouts
  60.  
  61. * display hour as digits
  62.     divu    #60,d5          hours as 1-11 with 0 for 12
  63.     if.w d5 <eq> #0 then.s  if hours = 0
  64.         move.w  #12,d5      hours as 1-12
  65.     endi
  66.     move.b  #10,d3          blank digit code
  67.     if.b d5 <hi> #9 then.s  if hours > 9
  68.         sub #10,d5     
  69.         move.b  #1,d3       display a 1
  70.     endi
  71.     bsr segment7            hour 10s digit
  72.     move.w  d5,d3
  73.     bsr segment7            hour 1s digit
  74.  
  75. * dash after hours
  76.     move.b  #11,d3          dash digit code
  77.     bsr segment7            display dash
  78.  
  79. * display minutes as digits
  80.     move.b  d6,d0
  81.     bsr Hex2BCD
  82.     move.b  #0,d3           0 digit code
  83.     if.b d0 <hi> #9 then.s  if minutes > 9
  84.         move.b  d0,d3
  85.         lsr.b   #4,d3       10's minute digit
  86.     endi
  87.     bsr segment7
  88.     move.b  d0,d3
  89.     and.b   #$F,d3          1's minute digit
  90.     bsr segment7
  91.  
  92. * dash after minutes
  93.     move.b  #11,d3          dash digit code
  94.     bsr segment7            display dash
  95.  
  96. * display seconds as digits
  97.     move.w  d7,seconds      save seconds
  98.     move.w  d7,d0
  99.     bsr Hex2BCD
  100.     move.b  #0,d3           0 digit code
  101.     if.b d0 <hi> #9 then.s
  102.         move.b  d0,d3
  103.         lsr.b   #4,d3       10's seconds digit
  104.     endi
  105.     bsr segment7
  106.     move.b  d0,d3
  107.     and.b   #$F,d3          1's second digit
  108.     bsr segment7
  109.  
  110.     bra loop                loop forever
  111.  
  112.     * Halt the Simulator
  113.     HALT
  114.  
  115.  
  116. *-----------------------------------------------------------
  117. *         A
  118. *       -----
  119. *     F|     |B
  120. *      |  G  |
  121. *       -----
  122. *     E|     |C
  123. *      |  D  |
  124. *       -----   .H
  125. *
  126. * Bit Number  7 6 5 4 3 2 1 0
  127. * Segment     H G F E D C B A
  128.  
  129. * bit patterns to form digits on readout
  130. digits:
  131.     dc.b  $3F           digit 0
  132.     dc.b  $06           digit 1
  133.     dc.b  $5B           digit 2
  134.     dc.b  $4F           digit 3
  135.     dc.b  $66           digit 4
  136.     dc.b  $6D           digit 5
  137.     dc.b  $7D           digit 6
  138.     dc.b  $07           digit 7
  139.     dc.b  $7F           digit 8
  140.     dc.b  $6F           digit 9
  141.     dc.b  $00           digit off
  142.     dc.b  $40           dash
  143.  
  144.     ds.w  0             force word boundary
  145.  
  146. *----------------------------------------------------------
  147. * Display a digit on the 7-segment display
  148. * Pre:  D3.B contains 1 digit to display
  149. *       A2 points to 7-segment LED to use
  150. * Post: A2 points to next 7-segment LED
  151.  
  152. segment7:
  153.     movem.l d3/a0,-(a7)     save registers
  154.     lea digits,a0           bit pattern table
  155.     and.l   #$00ff,d3
  156.     move.b  (a0,d3),(a2)    display digit
  157.     adda.l  #2,a2
  158.     movem.l (a7)+,d3/a0     restore registers
  159.     rts
  160.  
  161.  
  162. *-----------------------------------
  163. * Convert 2 digit Hex to 2 digit BCD
  164. * Pre:  D0.B 2 digit Hex
  165. * Post: D0.B 2 digit BCD
  166. Hex2BCD:
  167.     movem.l d1,-(a7)        save registers
  168.     clr d1
  169.     and.l   #$00FF,d0
  170.     divu    #10,d0
  171.     move.l  d0,d1
  172.     asl.w   #4,d0           shift tens to proper location
  173.     swap    d1              put units in proper location
  174.     or.b    d1,d0           combine units with tens
  175.     movem.l (a7)+,d1        restore registers
  176.     rts
  177.  
  178. * variables
  179. seconds ds.w    1
  180.  
  181.     END START
Add Comment
Please, Sign In to add comment