; *************************************************************************** ; CTime Display Code ; ; Version 0.4 ; ; Just add this code to your program to display a clock at the bottom of the ; screen. If you include this file, make sure you include the standard TI-86 ; include files first. ; ; NOTE: Don't forget to check that (ctime_code) equals $C461 before using ; this routine! ; ; *************************************************************************** ; Call this section of code every now and again (I recommend placing it in an ; interrupt) ld a,(time_changed) or a call nz,ShowClock ; Here is the main display routine - It can probably be optimised a lot ShowClock: show_time: xor a ld (time_changed),a ld hl,$FF80 ; Clear bottom part of screen ld de,$FF81 xor a ld (hl),a ld bc,$007F ldir ld de,clock_sprite ; Draw clock sprite ld hl,$FF90 ld bc,16 draw_clock_sprite: ld a,(de) inc de ld (hl),a add hl,bc or a jr nz,draw_clock_sprite ld a,$39 ; Set position to draw date and time ld (_penRow),a ld a,$0A ld (_penCol),a ld a,(edit_time) ; Store edit status in B ld b,a ld a,1 cp b jr nz,no_set_edit_1 set textInverse,(iy+textflags) no_set_edit_1: ld a,(clock_days) ld h,0 ld l,a ld d,h ld e,l call V_D_A_DECI add hl,hl add hl,de ld de,day_endings-3 add hl,de call _vputs res textInverse,(iy+textflags) ld a,(_penCol) add a,4 ld (_penCol),a ld a,2 cp b jr nz,no_set_edit_2 set textInverse,(iy+textflags) no_set_edit_2: ld a,(clock_months) ld h,0 ld l,a add hl,hl add hl,hl ld de,month_names-4 add hl,de call _vputs res textInverse,(iy+textflags) ld a,(_penCol) add a,4 ld (_penCol),a ld a,3 cp b jr nz,no_set_edit_3 set textInverse,(iy+textflags) no_set_edit_3: ld hl,(clock_years) call V_D_HL_DECI res textInverse,(iy+textflags) ld a,(_penCol) add a,8 ld (_penCol),a ld a,4 cp b jr nz,no_set_edit_4 set textInverse,(iy+textflags) no_set_edit_4: ld a,(clock_hours) ; Show time call V_D_A_DECI res textInverse,(iy+textflags) ld hl,time_sep call _vputs ld a,5 cp b jr nz,no_set_edit_5 set textInverse,(iy+textflags) no_set_edit_5: ld a,(clock_mins) call V_D_A_DECI res textInverse,(iy+textflags) ld hl,time_sep call _vputs ld a,6 cp b jr nz,no_set_edit_6 set textInverse,(iy+textflags) no_set_edit_6: ld a,(clock_secs) call V_D_A_DECI res textInverse,(iy+textflags) ret ; ***** Display number in A using variable width font - Destroys A V_D_A_DECI: push hl push de push bc ld h,0 ; Set-up registers - HL holds value, ld l,a ; DE holds address of place for ld de,disp_data+2 ; unpacked value, B number of digits xor a ld (de),a dec de ld b,2 ld_a_deci: call UNPACK_HL add a,'0' ld (de),a dec de djnz ld_a_deci ld hl,disp_data ; Filter zeros from start of value show_a_deci: call _vputs pop bc pop de pop hl ret ; ***** Display number in HL using variable width font - Destroys A V_D_HL_DECI: push hl push de push bc ld de,disp_data+4 xor a ld (de),a dec de ld b,4 ld_hl_deci: call UNPACK_HL add a,'0' ld (de),a dec de djnz ld_hl_deci ld hl,disp_data ; Filter zeros from start of value show_hl_deci: call _vputs pop bc pop de pop hl ret ; ***** String Vars time_sep: .db ":",0 clock_sprite: .db %00111000 .db %01010100 .db %10010010 .db %10110010 .db %10000010 .db %01000100 .db %00111000 .db 0 day_endings: .db "st",0 .db "nd",0 .db "rd",0 .db "th",0 .db "th",0 .db "th",0 .db "th",0 .db "th",0 .db "th",0 .db "th",0 .db "th",0 .db "th",0 .db "th",0 .db "th",0 .db "th",0 .db "th",0 .db "th",0 .db "th",0 .db "th",0 .db "th",0 .db "st",0 .db "nd",0 .db "rd",0 .db "th",0 .db "th",0 .db "th",0 .db "th",0 .db "th",0 .db "th",0 .db "th",0 .db "st",0 month_names: .db "Jan",0 .db "Feb",0 .db "Mar",0 .db "Apr",0 .db "May",0 .db "Jun",0 .db "Jul",0 .db "Aug",0 .db "Sep",0 .db "Oct",0 .db "Nov",0 .db "Dec",0 disp_data: .db 0,0,0,0,0 ; ***** Vars ctime_code equ $D617 ; Code indicating CTime installed time_changed equ $D619 ; Set when time changed clock_years equ $D61A ; Current year clock_months equ $D61C ; Current month clock_days equ $D61D ; Days passed since start of month clock_hours equ $D61E ; Hours passed clock_mins equ $D61F ; Minutes passed clock_secs equ $D620 ; Seconds passed