home *** CD-ROM | disk | FTP | other *** search
/ ticalc.org / ticalc_org_rev_b.iso / archives / 86 / asm / source / routines / clock.asm < prev    next >
Encoding:
Assembly Source File  |  2001-07-01  |  4.5 KB  |  271 lines

  1. ; ***************************************************************************
  2. ; CTime Display Code
  3. ;
  4. ; Version 0.4
  5. ;
  6. ; Just add this code to your program to display a clock at the bottom of the
  7. ; screen.  If you include this file, make sure you include the standard TI-86
  8. ; include files first.
  9. ;
  10. ; NOTE: Don't forget to check that (ctime_code) equals $C461 before using
  11. ;       this routine!
  12. ;
  13. ; ***************************************************************************
  14.  
  15. ; Call this section of code every now and again (I recommend placing it in an
  16. ; interrupt)
  17.     ld    a,(time_changed)
  18.     or    a
  19.     call    nz,ShowClock
  20.  
  21.  
  22. ; Here is the main display routine - It can probably be optimised a lot
  23. ShowClock:
  24.  
  25. show_time:
  26.     xor    a
  27.     ld    (time_changed),a
  28.  
  29.     ld    hl,$FF80        ; Clear bottom part of screen
  30.     ld    de,$FF81
  31.     xor    a
  32.     ld    (hl),a
  33.     ld    bc,$007F
  34.     ldir
  35.  
  36.     ld    de,clock_sprite        ; Draw clock sprite
  37.     ld    hl,$FF90
  38.     ld    bc,16
  39. draw_clock_sprite:
  40.     ld    a,(de)
  41.     inc    de
  42.     ld    (hl),a
  43.     add    hl,bc
  44.     or    a
  45.     jr    nz,draw_clock_sprite
  46.  
  47.     ld    a,$39            ; Set position to draw date and time
  48.     ld    (_penRow),a
  49.     ld    a,$0A
  50.     ld    (_penCol),a
  51.  
  52.     ld    a,(edit_time)        ; Store edit status in B
  53.     ld    b,a
  54.  
  55.     ld    a,1
  56.     cp    b
  57.     jr    nz,no_set_edit_1
  58.     set    textInverse,(iy+textflags)
  59. no_set_edit_1:
  60.     ld    a,(clock_days)
  61.     ld    h,0
  62.     ld    l,a
  63.     ld    d,h
  64.     ld    e,l
  65.     call    V_D_A_DECI
  66.     add    hl,hl
  67.     add    hl,de
  68.     ld    de,day_endings-3
  69.     add    hl,de
  70.     call    _vputs
  71.     res    textInverse,(iy+textflags)
  72.  
  73.     ld    a,(_penCol)
  74.     add    a,4
  75.     ld    (_penCol),a
  76.  
  77.     ld    a,2
  78.     cp    b
  79.     jr    nz,no_set_edit_2
  80.     set    textInverse,(iy+textflags)
  81. no_set_edit_2:
  82.     ld    a,(clock_months)
  83.     ld    h,0
  84.     ld    l,a
  85.     add    hl,hl
  86.     add    hl,hl
  87.     ld    de,month_names-4
  88.     add    hl,de
  89.     call    _vputs
  90.     res    textInverse,(iy+textflags)
  91.  
  92.     ld    a,(_penCol)
  93.     add    a,4
  94.     ld    (_penCol),a
  95.  
  96.     ld    a,3
  97.     cp    b
  98.     jr    nz,no_set_edit_3
  99.     set    textInverse,(iy+textflags)
  100. no_set_edit_3:
  101.     ld    hl,(clock_years)
  102.     call    V_D_HL_DECI
  103.     res    textInverse,(iy+textflags)
  104.  
  105.     ld    a,(_penCol)
  106.     add    a,8
  107.     ld    (_penCol),a
  108.  
  109.     ld    a,4
  110.     cp    b
  111.     jr    nz,no_set_edit_4
  112.     set    textInverse,(iy+textflags)
  113. no_set_edit_4:
  114.     ld    a,(clock_hours)        ; Show time
  115.     call    V_D_A_DECI
  116.     res    textInverse,(iy+textflags)
  117.     ld    hl,time_sep
  118.     call    _vputs
  119.  
  120.     ld    a,5
  121.     cp    b
  122.     jr    nz,no_set_edit_5
  123.     set    textInverse,(iy+textflags)
  124. no_set_edit_5:
  125.     ld    a,(clock_mins)
  126.     call    V_D_A_DECI
  127.     res    textInverse,(iy+textflags)
  128.     ld    hl,time_sep
  129.     call    _vputs
  130.  
  131.     ld    a,6
  132.     cp    b
  133.     jr    nz,no_set_edit_6
  134.     set    textInverse,(iy+textflags)
  135. no_set_edit_6:
  136.     ld    a,(clock_secs)
  137.     call    V_D_A_DECI
  138.     res    textInverse,(iy+textflags)
  139.     ret
  140.  
  141.  
  142. ; ***** Display number in A using variable width font - Destroys A
  143. V_D_A_DECI:
  144.     push    hl
  145.     push    de
  146.     push    bc
  147.  
  148.     ld    h,0            ; Set-up registers - HL holds value,
  149.     ld    l,a            ; DE holds address of place for
  150.     ld    de,disp_data+2        ; unpacked value, B number of digits
  151.     xor    a
  152.     ld    (de),a
  153.     dec    de
  154.     ld    b,2
  155. ld_a_deci:
  156.     call    UNPACK_HL
  157.     add    a,'0'
  158.     ld    (de),a
  159.     dec    de
  160.     djnz    ld_a_deci
  161.  
  162.     ld    hl,disp_data        ; Filter zeros from start of value
  163. show_a_deci:
  164.     call    _vputs
  165.  
  166.     pop    bc
  167.     pop    de
  168.     pop    hl
  169.     ret
  170.     
  171.  
  172. ; ***** Display number in HL using variable width font - Destroys A
  173. V_D_HL_DECI:
  174.     push    hl
  175.     push    de
  176.     push    bc
  177.  
  178.     ld    de,disp_data+4
  179.     xor    a
  180.     ld    (de),a
  181.     dec    de
  182.     ld    b,4
  183. ld_hl_deci:
  184.     call    UNPACK_HL
  185.     add    a,'0'
  186.     ld    (de),a
  187.     dec    de
  188.     djnz    ld_hl_deci
  189.  
  190.     ld    hl,disp_data        ; Filter zeros from start of value
  191. show_hl_deci:
  192.     call    _vputs
  193.  
  194.     pop    bc
  195.     pop    de
  196.     pop    hl
  197.     ret
  198.  
  199.  
  200. ; ***** String Vars
  201. time_sep:
  202.     .db    ":",0
  203. clock_sprite:
  204.     .db    %00111000
  205.     .db    %01010100
  206.     .db    %10010010
  207.     .db    %10110010
  208.     .db    %10000010
  209.     .db    %01000100
  210.     .db    %00111000
  211.     .db    0
  212. day_endings:
  213.     .db    "st",0
  214.     .db    "nd",0
  215.     .db    "rd",0
  216.     .db    "th",0
  217.     .db    "th",0
  218.     .db    "th",0
  219.     .db    "th",0
  220.     .db    "th",0
  221.     .db    "th",0
  222.     .db    "th",0
  223.     .db    "th",0
  224.     .db    "th",0
  225.     .db    "th",0
  226.     .db    "th",0
  227.     .db    "th",0
  228.     .db    "th",0
  229.     .db    "th",0
  230.     .db    "th",0
  231.     .db    "th",0
  232.     .db    "th",0
  233.     .db    "st",0
  234.     .db    "nd",0
  235.     .db    "rd",0
  236.     .db    "th",0
  237.     .db    "th",0
  238.     .db    "th",0
  239.     .db    "th",0
  240.     .db    "th",0
  241.     .db    "th",0
  242.     .db    "th",0
  243.     .db    "st",0
  244. month_names:
  245.     .db    "Jan",0
  246.     .db    "Feb",0
  247.     .db    "Mar",0
  248.     .db    "Apr",0
  249.     .db    "May",0
  250.     .db    "Jun",0
  251.     .db    "Jul",0
  252.     .db    "Aug",0
  253.     .db    "Sep",0
  254.     .db    "Oct",0
  255.     .db    "Nov",0
  256.     .db    "Dec",0
  257. disp_data:
  258.     .db    0,0,0,0,0
  259.  
  260.  
  261. ; ***** Vars
  262. ctime_code    equ    $D617        ; Code indicating CTime installed
  263. time_changed    equ    $D619        ; Set when time changed
  264. clock_years    equ    $D61A        ; Current year
  265. clock_months    equ    $D61C        ; Current month
  266. clock_days    equ    $D61D        ; Days passed since start of month
  267. clock_hours    equ    $D61E        ; Hours passed
  268. clock_mins    equ    $D61F        ; Minutes passed
  269. clock_secs    equ    $D620        ; Seconds passed
  270.  
  271.