| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- XDEF Wall
- XREF __SEG_END_SSTACK,display_time,display_string,disp
- ;counters and variables
- XREF current_year,current_month,current_day,current_hour,current_minute,current_second
-
- ;events
- XREF second_passed
-
- ;debug
- XREF byte_out,word_out
-
- clock_digits: Section
- ;digits to display
- seconds_tens ds.b 1
- seconds_ones ds.b 1
- minutes_tens ds.b 1
- minutes_ones ds.b 1
- hours_tens ds.b 1
- hours_ones ds.b 1
- clock_code: Section
- Wall: ;push register and accumulator values for retention
- PSHA
- PSHB
- PSHD
- PSHX
- PSHY
-
- ;handle the event that fires evey second
- LDAA second_passed
- CMPA #$FF
- LBNE PrintWall ;display time between seconds
-
- ;if a second has passed
- LDAA current_second
- INCA ;increment the seconds counter
- STAA current_second
- CMPA #60 ;less than a minute has passed
- LBLT PrintWall ;display the time if required
- CLR current_second ;resest the seconds counter to zero
-
- ;one minute has passed
- LDAA current_minute
- INCA
- STAA current_minute
- CMPA #60
- LBLT PrintWall
- CLR current_minute
-
- ;one hour has passed
- LDAA current_hour
- INCA
- STAA current_hour
- CMPA #24
- LBLT PrintWall
- CLR current_hour
-
- ;one day has passed (30 days in a month)
- LDAA current_day
- INCA
- STAA current_day
- CMPA #30
- LBLT PrintWall
- MOVB #$01,current_day
-
- ;one month has passed
- LDAA current_month
- INCA
- STAA current_month
- CMPA #12
- LBLT PrintWall
- MOVB #$01,current_month
-
- ;one year has passed
- LDX current_year
- INX
- STX current_year
- ;no need to do anything else, years counts up indefinitely
-
- SetWall:
- movb #'M',disp
- movb #'M',disp+1
- movb #'/',disp+2
- movb #'D',disp+3
- movb #'D',disp+4
- movb #'/',disp+5
- movb #'Y',disp+6
- movb #'Y',disp+7
- movb #'Y',disp+8
- movb #'Y',disp+9
- movb #' ',disp+10
- movb #'h',disp+11
- movb #'h',disp+12
- movb #':',disp+13
- movb #'m',disp+14
- movb #'m',disp+15
- ;
- ;next line
- ;
- movb #'_',disp+16
- movb #'_',disp+17
- movb #'/',disp+18
- movb #'_',disp+19
- movb #'_',disp+20
- movb #'/',disp+21
- movb #'_',disp+22
- movb #'_',disp+23
- movb #'_',disp+24
- movb #'_',disp+25
- movb #' ',disp+26
- movb #'_',disp+27
- movb #'_',disp+28
- movb #':',disp+29
-
- movb #'_',disp+30
- movb #'_',disp+31
- movb #0,disp+32 ;string terminator, acts like '\0'
-
-
- PrintWall:
- ;check if the time should show
- LDAA display_time
- CMPA #$00
- LBEQ Return
-
- ;if the time should show, calculate the ASCII values
- ; (seconds)
- LDX #10 ;load the bottom part of the divide (forget what it's called)
- LDD current_second ;two-digit seconds number
- IDIV ;D / X -> X (remainder D) (D has the one's place and X has the 10's)
-
- ADDD #$30 ;convert the one's place to ascii
- STAB seconds_ones
- XGDX
- ADDD #$30
- STAB seconds_tens
-
- ;from lab 6.3
- ;XGDX ;X <-> D, X will now have the 1's and D has the 10's
- ;ADDD #$30 ;convert to ASCII
- ;STAB seconds_tens ;lower byte of d has the 10's place for the seconds
- ;STAB word_out
- ;XGDX ;swap back X and D (X still has the 1's)
- ;ADDD #$30 ;conver the ones place to ASCII
- ;STAB seconds_ones ;X has the remainer, i.e. the one's place
- ;STAB byte_out
-
- ;STAB byte_out
- ;STX word_out
-
- ; (minutes)
- ;LDX #10 ;load the bottom part of the divide (forget what it's called)
- ;LDD current_minute ;two-digit minutes number
- ;IDIV ;D / X -> X (remainder D)
- ;XGDX ;X <-> D, X now has remainder and D has quotient
- ;ADDD #$30 ;convert to ASCII
- ;STAB minutes_tens ;lower byte of d has the 10's place for the seconds
- ;STX minutes_ones ;X has the remainer, i.e. the one's place
-
- ;print the time and date (includes placeholders)
- movb #'D',disp
- movb #'a',disp+1
- movb #'t',disp+2
- movb #'e',disp+3
- movb #':',disp+4
- movb #' ',disp+5
- ;month
- movb #'1',disp+6
- movb #'2',disp+7
- movb #'/',disp+8
- ;day
- movb #'0',disp+9
- movb #'2',disp+10
- movb #'/',disp+11
- ;year
- movb #'1',disp+12
- movb #'9',disp+13
- movb #'9',disp+14
- movb #'3',disp+15
- ;
- ;next line
- ;
- movb #'T',disp+16
- movb #'i',disp+17
- movb #'m',disp+18
- movb #'e',disp+19
- movb #':',disp+20
- movb #' ',disp+21
-
- ;hour
- movb #'1',disp+22
- movb #'1',disp+23
-
- movb #':',disp+24
- ;minute
- movb #'1',disp+25
- movb #'1',disp+26
-
- movb #':',disp+27
- ;seconds
- ;movb #'1',disp+28
- ;movb #'8',disp+29
-
- movb #' ',disp+30
- movb #' ',disp+31
- movb #0,disp+32 ;string terminator, acts like '\0'
-
- ;store out calculated ascii values in the appropriate places in the display
- MOVB seconds_tens,disp+28
- MOVB seconds_ones,disp+29
-
- ;MOVB minutes_tens,disp+25
- ;MOVB minutes_ones,disp+26
-
- LDD #disp ;both of these steps are necessary to
- jsr display_string ;print to the LCD screen
- Return:
- ;clear the flag that is set evey second
- CLR second_passed
-
- ;restore registers and accumulators
- PULY
- PULX
- PULD
- PULB
- PULA
-
- RTS
-
-
-
|