wall.asm 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. XDEF Wall
  2. XREF __SEG_END_SSTACK,display_time,display_string,disp
  3. ;counters and variables
  4. XREF current_year,current_month,current_day,current_hour,current_minute,current_second
  5. ;events
  6. XREF second_passed
  7. ;debug
  8. XREF byte_out,word_out
  9. clock_digits: Section
  10. ;digits to display
  11. seconds_tens ds.b 1
  12. seconds_ones ds.b 1
  13. minutes_tens ds.b 1
  14. minutes_ones ds.b 1
  15. hours_tens ds.b 1
  16. hours_ones ds.b 1
  17. clock_code: Section
  18. Wall: ;push register and accumulator values for retention
  19. PSHA
  20. PSHB
  21. PSHD
  22. PSHX
  23. PSHY
  24. ;handle the event that fires evey second
  25. LDAA second_passed
  26. CMPA #$FF
  27. LBNE PrintWall ;display time between seconds
  28. ;if a second has passed
  29. LDAA current_second
  30. INCA ;increment the seconds counter
  31. STAA current_second
  32. CMPA #60 ;less than a minute has passed
  33. LBLT PrintWall ;display the time if required
  34. CLR current_second ;resest the seconds counter to zero
  35. ;one minute has passed
  36. LDAA current_minute
  37. INCA
  38. STAA current_minute
  39. CMPA #60
  40. LBLT PrintWall
  41. CLR current_minute
  42. ;one hour has passed
  43. LDAA current_hour
  44. INCA
  45. STAA current_hour
  46. CMPA #24
  47. LBLT PrintWall
  48. CLR current_hour
  49. ;one day has passed (30 days in a month)
  50. LDAA current_day
  51. INCA
  52. STAA current_day
  53. CMPA #30
  54. LBLT PrintWall
  55. MOVB #$01,current_day
  56. ;one month has passed
  57. LDAA current_month
  58. INCA
  59. STAA current_month
  60. CMPA #12
  61. LBLT PrintWall
  62. MOVB #$01,current_month
  63. ;one year has passed
  64. LDX current_year
  65. INX
  66. STX current_year
  67. ;no need to do anything else, years counts up indefinitely
  68. SetWall:
  69. movb #'M',disp
  70. movb #'M',disp+1
  71. movb #'/',disp+2
  72. movb #'D',disp+3
  73. movb #'D',disp+4
  74. movb #'/',disp+5
  75. movb #'Y',disp+6
  76. movb #'Y',disp+7
  77. movb #'Y',disp+8
  78. movb #'Y',disp+9
  79. movb #' ',disp+10
  80. movb #'h',disp+11
  81. movb #'h',disp+12
  82. movb #':',disp+13
  83. movb #'m',disp+14
  84. movb #'m',disp+15
  85. ;
  86. ;next line
  87. ;
  88. movb #'_',disp+16
  89. movb #'_',disp+17
  90. movb #'/',disp+18
  91. movb #'_',disp+19
  92. movb #'_',disp+20
  93. movb #'/',disp+21
  94. movb #'_',disp+22
  95. movb #'_',disp+23
  96. movb #'_',disp+24
  97. movb #'_',disp+25
  98. movb #' ',disp+26
  99. movb #'_',disp+27
  100. movb #'_',disp+28
  101. movb #':',disp+29
  102. movb #'_',disp+30
  103. movb #'_',disp+31
  104. movb #0,disp+32 ;string terminator, acts like '\0'
  105. PrintWall:
  106. ;check if the time should show
  107. LDAA display_time
  108. CMPA #$00
  109. LBEQ Return
  110. ;if the time should show, calculate the ASCII values
  111. ; (seconds)
  112. LDX #10 ;load the bottom part of the divide (forget what it's called)
  113. LDD current_second ;two-digit seconds number
  114. IDIV ;D / X -> X (remainder D) (D has the one's place and X has the 10's)
  115. ADDD #$30 ;convert the one's place to ascii
  116. STAB seconds_ones
  117. XGDX
  118. ADDD #$30
  119. STAB seconds_tens
  120. ;from lab 6.3
  121. ;XGDX ;X <-> D, X will now have the 1's and D has the 10's
  122. ;ADDD #$30 ;convert to ASCII
  123. ;STAB seconds_tens ;lower byte of d has the 10's place for the seconds
  124. ;STAB word_out
  125. ;XGDX ;swap back X and D (X still has the 1's)
  126. ;ADDD #$30 ;conver the ones place to ASCII
  127. ;STAB seconds_ones ;X has the remainer, i.e. the one's place
  128. ;STAB byte_out
  129. ;STAB byte_out
  130. ;STX word_out
  131. ; (minutes)
  132. ;LDX #10 ;load the bottom part of the divide (forget what it's called)
  133. ;LDD current_minute ;two-digit minutes number
  134. ;IDIV ;D / X -> X (remainder D)
  135. ;XGDX ;X <-> D, X now has remainder and D has quotient
  136. ;ADDD #$30 ;convert to ASCII
  137. ;STAB minutes_tens ;lower byte of d has the 10's place for the seconds
  138. ;STX minutes_ones ;X has the remainer, i.e. the one's place
  139. ;print the time and date (includes placeholders)
  140. movb #'D',disp
  141. movb #'a',disp+1
  142. movb #'t',disp+2
  143. movb #'e',disp+3
  144. movb #':',disp+4
  145. movb #' ',disp+5
  146. ;month
  147. movb #'1',disp+6
  148. movb #'2',disp+7
  149. movb #'/',disp+8
  150. ;day
  151. movb #'0',disp+9
  152. movb #'2',disp+10
  153. movb #'/',disp+11
  154. ;year
  155. movb #'1',disp+12
  156. movb #'9',disp+13
  157. movb #'9',disp+14
  158. movb #'3',disp+15
  159. ;
  160. ;next line
  161. ;
  162. movb #'T',disp+16
  163. movb #'i',disp+17
  164. movb #'m',disp+18
  165. movb #'e',disp+19
  166. movb #':',disp+20
  167. movb #' ',disp+21
  168. ;hour
  169. movb #'1',disp+22
  170. movb #'1',disp+23
  171. movb #':',disp+24
  172. ;minute
  173. movb #'1',disp+25
  174. movb #'1',disp+26
  175. movb #':',disp+27
  176. ;seconds
  177. ;movb #'1',disp+28
  178. ;movb #'8',disp+29
  179. movb #' ',disp+30
  180. movb #' ',disp+31
  181. movb #0,disp+32 ;string terminator, acts like '\0'
  182. ;store out calculated ascii values in the appropriate places in the display
  183. MOVB seconds_tens,disp+28
  184. MOVB seconds_ones,disp+29
  185. ;MOVB minutes_tens,disp+25
  186. ;MOVB minutes_ones,disp+26
  187. LDD #disp ;both of these steps are necessary to
  188. jsr display_string ;print to the LCD screen
  189. Return:
  190. ;clear the flag that is set evey second
  191. CLR second_passed
  192. ;restore registers and accumulators
  193. PULY
  194. PULX
  195. PULD
  196. PULB
  197. PULA
  198. RTS