123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713 |
- #include "memmap.i65"
- #include "dma.i65"
- timebox_data
- ; string offset, selection width, bcdtime offset, 1s limit, 10s limit
- .byt 0, 4, 9
- .byt 5, 2, 8
- .byt 8, 2, 6
- .byt 11, 2, 4
- .byt 14, 2, 2
- .byt 17, 2, 0
- time_month
- .byt 3, 1
- .byt 2, 8
- .byt 3, 1
- .byt 3, 0
- .byt 3, 1
- .byt 3, 0
- .byt 3, 1
- .byt 3, 1
- .byt 3, 0
- .byt 3, 1
- .byt 3, 0
- .byt 3, 1
- time_init:
- php
- sep #$20 : .as
- ; save text area
- jsr backup_screen
- ; draw window + current time setting
- lda #^text_clkset
- sta window_tbank
- ldx #!text_clkset
- stx window_taddr
- lda @time_win_x
- sta window_x
- lda @time_win_w
- sta window_w
- lda @time_win_y
- sta window_y
- lda @time_win_h
- sta window_h
- jsr draw_window
- jsr gettime
- stz time_sel
- stz time_exit
- lda #^text_buttonB
- sta print_bank
- ldx #!text_buttonB
- stx print_src
- lda @time_win_x
- inc
- inc
- sta print_x
- lda @time_win_y
- clc
- adc #$5
- sta print_y
- lda #$01
- sta print_pal
- jsr hiprint
- time_update
- jsr rendertime
- lda #^stringbuf
- sta print_bank
- ldx #!stringbuf
- stx print_src
- lda @time_win_x
- clc
- adc #$04
- sta print_x
- lda @time_win_y
- clc
- adc #$03
- sta print_y
- stz print_pal
- jsr hiprint
- lda time_sel
- asl
- clc
- adc time_sel
- xba
- lda #$00
- xba
- tax
- lda !timebox_data, x
- clc
- adc #$04
- adc @time_win_x
- sta bar_xl
- lda @time_win_y
- adc #$02
- sta bar_yl
- inx
- lda !timebox_data, x
- sta bar_wl
- inx
- lda !timebox_data, x
- sta time_ptr
- timeloop1
- lda isr_done
- lsr
- bcc timeloop1
- stz isr_done
- jsr read_pad
- lda #$01
- and pad1trig+1
- bne tkey_right
- lda #$02
- and pad1trig+1
- bne tkey_left
- lda #$04
- and pad1trig+1
- bne tkey_down
- lda #$08
- and pad1trig+1
- bne tkey_up
- lda #$80
- and pad1trig+1
- bne tkey_b
- ; do stuff
- lda time_exit
- beq timeloop1
- ; set clock
- jsr settime
- ; restore text area
- jsr restore_screen
- plp
- rtl
- tkey_b
- inc time_exit
- jmp time_update
- tkey_left
- jsr time_key_left
- jmp time_update
- tkey_right
- jsr time_key_right
- jmp time_update
- tkey_up
- jsr time_key_up
- jmp time_update
- tkey_down
- jsr time_key_down
- jmp time_update
- time_key_left
- lda time_sel
- beq +
- dec time_sel
- +
- rts
- time_key_right
- lda time_sel
- cmp #5
- beq +
- inc time_sel
- +
- rts
- time_key_up
- lda time_ptr
- cmp #4
- beq time_inc_hour_jmp
- cmp #6
- beq time_inc_day_jmp
- cmp #8
- beq time_inc_mon_jmp
- cmp #9
- beq time_inc_year_jmp
- xba
- lda #$00
- xba
- tax
- lda !time_s1, x
- inc
- cmp #$0a
- bmi time_inc_minsec1_normal
- stz !time_s1, x
- lda !time_s10, x
- inc
- cmp #$06
- bmi time_inc_minsec10_normal
- stz !time_s10, x
- bra +
- time_inc_minsec10_normal
- sta !time_s10, x
- bra +
- time_inc_minsec1_normal
- sta !time_s1, x
- +
- rts
- time_inc_hour_jmp
- jsr time_inc_hour
- rts
- time_inc_day_jmp
- jsr time_inc_day
- rts
- time_inc_mon_jmp
- jsr time_inc_mon
- rts
- time_inc_year_jmp
- jsr time_inc_year
- lda time_mon
- jsr time_adjust_mon
- rts
- time_inc_hour
- lda time_h10
- cmp #$02
- bne time_inc_hour_normal
- lda time_h1
- inc
- cmp #$04
- bmi +
- stz time_h1
- stz time_h10
- rts
- +
- sta time_h1
- rts
- time_inc_hour_normal
- lda time_h1
- inc
- cmp #$0a
- bmi +
- stz time_h1
- inc time_h10
- rts
- +
- sta time_h1
- rts
- time_inc_day
- lda time_mon
- dec
- asl
- xba
- lda #$00
- xba
- tax
- lda !time_month, x
- cmp time_d10
- bne time_inc_day_normal
- inx
- jsr is_leapyear_feb
- lda !time_month, x
- dec
- adc #$00
- cmp time_d1
- bpl +
- stz time_d1
- stz time_d10
- +
- inc time_d1
- rts
- time_inc_day_normal
- lda time_d1
- inc
- cmp #$0a
- bmi +
- stz time_d1
- inc time_d10
- rts
- +
- sta time_d1
- rts
- time_inc_mon
- lda time_mon
- inc
- cmp #13
- bmi +
- lda #$01
- +
- jsr time_adjust_mon
- rts
- time_adjust_mon
- sta time_mon
- dec
- asl
- xba
- lda #$00
- xba
- tax
- lda time_d10
- cmp !time_month, x
- bcs time_mon_adjust
- rts
- time_mon_adjust
- php
- inx
- lda !time_month, x
- pha
- jsr is_leapyear_feb ; c=1 -> a leapyear february
- pla
- adc #$00
- plp
- bne time_mon_doadjust
- cmp time_d1
- bcs +
- time_mon_doadjust
- sta time_d1
- dex
- lda !time_month, x
- sta time_d10
- +
- rts
- time_inc_year
- lda time_y1
- inc
- cmp #$0a
- bmi time_inc_y1_normal
- stz time_y1
- lda time_y10
- inc
- cmp #$0a
- bmi time_inc_y10_normal
- stz time_y10
- inc time_y100
- rts
- time_inc_y10_normal
- sta time_y10
- rts
- time_inc_y1_normal
- sta time_y1
- rts
- time_key_down
- lda time_ptr
- cmp #4
- beq time_dec_hour_jmp
- cmp #6
- beq time_dec_day_jmp
- cmp #8
- beq time_dec_mon_jmp
- cmp #9
- beq time_dec_year_jmp
- xba
- lda #$00
- xba
- tax
- lda !time_s1, x
- dec
- cmp #$ff
- bne time_dec_minsec1_normal
- lda #$09
- sta !time_s1, x
- lda !time_s10, x
- dec
- cmp #$ff
- bne time_dec_minsec10_normal
- lda #$05
- sta !time_s10, x
- bra +
- time_dec_minsec10_normal
- sta !time_s10, x
- bra +
- time_dec_minsec1_normal
- sta !time_s1, x
- +
- rts
- time_dec_hour_jmp
- jsr time_dec_hour
- rts
- time_dec_day_jmp
- jsr time_dec_day
- rts
- time_dec_mon_jmp
- jsr time_dec_mon
- rts
- time_dec_year_jmp
- jsr time_dec_year
- lda time_mon
- jsr time_adjust_mon
- rts
- time_dec_hour
- lda time_h1
- dec
- cmp #$ff
- bne time_dec_h1_normal
- lda time_h10
- bne time_dec_h10_normal
- lda #$02
- sta time_h10
- lda #$03
- sta time_h1
- rts
- time_dec_h10_normal
- lda #$09
- sta time_h1
- dec time_h10
- rts
- time_dec_h1_normal
- sta time_h1
- rts
- time_dec_day
- lda time_d10
- beq +
- lda time_d1
- dec
- cmp #$ff
- bne time_dec_d1_normal
- bra time_dec_cont
- + lda time_d1
- dec
- bne time_dec_d1_normal
- time_dec_cont
- lda time_d10
- bne time_dec_d10_normal
- lda time_mon
- dec
- asl
- ldx #$0000
- tax
- lda !time_month, x
- sta time_d10
- inx
- lda !time_month, x
- pha
- jsr is_leapyear_feb
- pla
- adc #$00
- sta time_d1
- rts
- time_dec_d10_normal
- lda #$09
- sta time_d1
- dec time_d10
- rts
- time_dec_d1_normal
- sta time_d1
- rts
- time_dec_mon
- lda time_mon
- dec
- bne +
- lda #12
- +
- jsr time_adjust_mon
- rts
- time_dec_year
- lda time_y1
- dec
- cmp #$ff
- bne time_dec_y1_normal
- lda #$09
- sta time_y1
- lda time_y10
- dec
- cmp #$ff
- bne time_dec_y10_normal
- lda #$09
- sta time_y10
- dec time_y100
- rts
- time_dec_y10_normal
- sta time_y10
- rts
- time_dec_y1_normal
- sta time_y1
- rts
- rts
- gettime
- lda #$0d
- sta $2801
- lda $2800
- lda $2800
- sta time_s1
- lda $2800
- sta time_s10
- lda $2800
- sta time_m1
- lda $2800
- sta time_m10
- lda $2800
- sta time_h1
- lda $2800
- sta time_h10
- lda $2800
- sta time_d1
- lda $2800
- sta time_d10
- lda $2800
- sta time_mon
- lda $2800
- sta time_y1
- lda $2800
- sta time_y10
- lda $2800
- sta time_y100
- rts
- rendertime
- ldx #!stringbuf
- lda time_y100
- and #$0f
- cmp #$0a
- bpl y_skip1
- clc
- adc #$30
- sta !1,x
- lda #$31
- sta !0,x
- bra y_skip2
- y_skip1
- clc
- adc #$26
- sta !1,x
- lda #$32
- sta !0,x
- y_skip2
- inx
- inx
- lda time_y10
- and #$0f
- clc
- adc #$30
- sta !0,x
- inx
- lda time_y1
- and #$0f
- clc
- adc #$30
- sta !0,x
- inx
- lda #$2d
- sta !0,x
- inx
- lda time_mon
- and #$0f
- cmp #$0a
- bpl mon_skip1
- clc
- adc #$30
- sta !1,x
- lda #$30
- sta !0,x
- bra mon_skip2
- mon_skip1
- clc
- adc #$26
- sta !1,x
- lda #$31
- sta !0,x
- mon_skip2
- inx
- inx
- lda #$2d
- sta !0,x
- inx
- lda time_d10
- clc
- adc #$30
- sta !0,x
- inx
- lda time_d1
- clc
- adc #$30
- sta !0,x
- inx
- lda #$20
- sta !0,x
- inx
- lda time_h10
- clc
- adc #$30
- sta !0,x
- inx
- lda time_h1
- clc
- adc #$30
- sta !0,x
- inx
- lda #$3a
- sta !0,x
- inx
- lda time_m10
- clc
- adc #$30
- sta !0,x
- inx
- lda time_m1
- clc
- adc #$30
- sta !0,x
- inx
- lda #$3a
- sta !0,x
- inx
- lda time_s10
- clc
- adc #$30
- sta !0,x
- inx
- lda time_s1
- clc
- adc #$30
- sta !0,x
- stz !1,x
- rts
- is_leapyear_feb
- lda time_mon
- cmp #$02
- bne is_leapyear_feb_no
- lda time_y10
- asl
- sta time_tmp
- asl
- asl
- clc
- adc time_tmp
- clc
- adc time_y1
- sta time_tmp
- and #$03
- beq is_leapyear_4th ; every 4th year
- is_leapyear_feb_no
- clc
- rts
- is_leapyear_4th ; leapyear candidate
- lda time_tmp ; year=00?
- beq + ; then check century
- sec ; else it's always a leapyear
- rts
- +
- lda time_y100 ; century divisible by 4?
- clc
- adc #10
- and #$03
- beq is_leapyear_400th
- clc
- rts
- is_leapyear_400th
- sec
- rts
- settime
- lda time_y100
- sta @AVR_PARAM
- lda time_y10
- sta @AVR_PARAM+1
- lda time_y1
- sta @AVR_PARAM+2
- lda time_mon
- sta @AVR_PARAM+3
- lda time_d10
- sta @AVR_PARAM+4
- lda time_d1
- sta @AVR_PARAM+5
- lda time_h10
- sta @AVR_PARAM+6
- lda time_h1
- sta @AVR_PARAM+7
- lda time_m10
- sta @AVR_PARAM+8
- lda time_m1
- sta @AVR_PARAM+9
- lda time_s10
- sta @AVR_PARAM+10
- lda time_s1
- sta @AVR_PARAM+11
- lda #$02 ; set clock
- sta @AVR_CMD
- rts
- printtime:
- jsr gettime
- jsr rendertime
- lda listdisp
- clc
- adc #$0a
- clc
- adc vidmode
- sta print_y
- lda #$2b
- sta print_x
- lda #$40
- sta print_count
- lda #^stringbuf
- sta print_bank
- ldx #!stringbuf
- stx print_src
- stz print_pal
- jsr hiprint
- rts
|