Subversion Repositories Kolibri OS

Rev

Rev 6002 | Rev 7717 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ; Calendar for KolibriOS
  2. ;
  3. ; v1.5 - time redesign by Heavyiron
  4. ; v1.2 - v1.55 - new desighn and functionality by Leency
  5. ; v1.1 - add change time support by DedOK
  6. ; v1.0 - written in pure assembler by Ivushkin Andrey aka Willow
  7. ; also - diamond, spraid, fedesco
  8. ;
  9. ; Created: November 1, 2004
  10.  
  11.  
  12. use32
  13.  
  14.   org    0x0
  15.  
  16.   db     'MENUET01'
  17.   dd     0x01
  18.   dd     START
  19.   dd     I_END
  20.   dd     0x1000
  21.   dd     0x1000
  22.   dd     0x0
  23.   dd     0x0
  24. include '..\..\..\macros.inc'
  25. include 'lang.inc'
  26. include 'data.inc'
  27.  
  28.  
  29.  
  30. macro ShowFocus field,reg
  31. {
  32.    local  .nofocus, .exit
  33.      cmp  [focus],field
  34.      jne  .nofocus
  35.    if reg eq
  36.      mov  ecx,COL_ACTIVE_TEXT
  37.    else
  38.      mov  reg,COL_ACTIVE_TEXT
  39.    end if
  40.      jmp  .exit
  41.    .nofocus:
  42.    if reg eq
  43.      mov  ecx,COL_DROPDOWN_T
  44.    else
  45.      mov  reg,COL_DROPDOWN_T
  46.    end if
  47.    .exit:
  48. }
  49.  
  50. macro GetSkinHeight
  51. {
  52.         mov  eax,48
  53.         mov  ebx,4
  54.         int 0x40
  55. }
  56.  
  57. macro DrawRect color1,color2,color3,color4 ; pizdec... but optimized well
  58. {
  59.         ; top border-outer
  60.         push ebx
  61.         push ecx
  62.         mov eax,13
  63.         mov bx,DATE_BUTTON_WIDTH
  64.         mov edx,color1
  65.         mov cx,1
  66.         mcall
  67.         ; left border-outer
  68.         mov bx,1
  69.         mov cx,DATE_BUTTON_HEIGHT
  70.         mcall
  71.         ; top border-inner
  72.         mov edx,color2
  73.         add ebx,1 shl 16
  74.         add ecx,1 shl 16
  75.         mov bx,DATE_BUTTON_WIDTH-1
  76.         mov cx,1
  77.         ; left border-inner
  78.         mcall
  79.         mov bx,1
  80.         mov cx,DATE_BUTTON_HEIGHT-2
  81.         mcall
  82.         ; inner
  83.         mov edx,color3
  84.         add ebx,1 shl 16
  85.         add ecx,1 shl 16
  86.         mov bx,DATE_BUTTON_WIDTH-4
  87.         mov cx,DATE_BUTTON_HEIGHT-4
  88.         mcall
  89.         ; bottom border-inner
  90.         mov edx,color4
  91.         add ebx,DATE_BUTTON_WIDTH shl 16
  92.         sub ebx,4 shl 16
  93.         mov bx,1
  94.         mov cx,DATE_BUTTON_HEIGHT-3
  95.         mcall
  96.         ; right border-outer
  97.         mov edx,color2
  98.         add ebx,1 shl 16
  99.         sub ecx,1 shl 16
  100.         add cx,1
  101.         mcall
  102.         ; right border-outer 2
  103.         mov edx,color1
  104.         add ebx,1 shl 16
  105.         sub ecx,1 shl 16
  106.         add cx,2
  107.         add cx,1
  108.         mcall
  109.         ; bottom border-outer
  110.         mov edx,color2
  111.         pop ecx
  112.         pop ebx
  113.         add ecx,DATE_BUTTON_HEIGHT shl 16
  114.         sub ecx,1 shl 16
  115.         add ebx,1 shl 16
  116.         mov cx,1
  117.         mcall
  118.         ; bottom border-outer 2
  119.         mov edx,color1
  120.         add ecx,1 shl 16
  121.         mcall
  122.         add ebx,1 shl 16
  123.         sub ecx,1 shl 16
  124.         ; left border-outer
  125.         mov edx,color4
  126.         add ebx,1 shl 16
  127.         sub ecx,1 shl 16
  128.         sub bx,2
  129.         mcall
  130. }
  131.  
  132.  
  133. str2int:
  134.     xor  eax,eax
  135.     lodsb
  136.     mov  ebx,eax
  137.     shr  ebx,4
  138.     and  eax,0xf
  139.     imul ebx,10
  140.     add  al,bl
  141.     ret
  142.  
  143. START:
  144.     mcall 29
  145.     mov  [datestr],eax
  146.     mov  esi,datestr
  147.     call str2int
  148.     add  eax,1900
  149.     mov  [Year],eax
  150.     call str2int
  151.     dec  eax
  152.     mov  [Month],eax
  153.     call str2int
  154.     mov  [day_sel],eax
  155.     test byte[esi],0
  156.     jnz  .no2000
  157.     add  [Year],100
  158.         mov eax,[Year]
  159.         mov [curYear], eax
  160.         mov eax,[Month]
  161.         mov [curMonth], eax
  162.         mov eax,[day_sel]
  163.         mov [curDay], eax
  164.   .no2000:
  165.     jmp  upd
  166. red:
  167.  
  168.     call define_window
  169.  
  170. still:
  171.  
  172.     mcall 23,50     ; wait here for event
  173.   .evt:
  174.     mov  ebp,[focus]
  175.     cmp  eax,1
  176.     je   red
  177.     cmp  eax,2
  178.     je   key
  179.     cmp  eax,3
  180.     je   button
  181.  
  182.     call draw_clock
  183.  
  184.     jmp  still
  185.  
  186.   key:
  187.     mcall 2             ; get pressed key
  188.     cmp  ah,9
  189.     jne  no_tab
  190.   .tab:
  191.     cmp  ebp,FOCUSABLE
  192.     JAE  foc_cycle
  193.     inc  [focus]
  194.   upd:
  195.     call calculate
  196.     jmp  red
  197.   foc_cycle:
  198.     mov  [focus],2
  199.     jmp  upd
  200.   no_tab:
  201.     push eax
  202.     shr  eax,8
  203.     mov  ecx,12
  204.     mov  edi,Fkeys
  205.     repne scasb
  206.     pop  eax
  207.     jnz  .noFkey
  208.     sub  edi,Fkeys+1
  209.     mov  [Month],edi
  210.     jmp  upd
  211.   .noFkey:
  212.     cmp  ebp,2
  213.     jne  .nomonth
  214.     cmp  ah,177
  215.     je   noclose.drop
  216.     jmp  still
  217.   .nomonth:
  218.     cmp  ebp,3
  219.     je   noy_up.year_evt
  220.     cmp  ebp,4
  221.     jne  still
  222.     mov  ebx,[day_sel]
  223.     cmp  ah,176         ; left arrow
  224.     jg   still
  225.     cmp  ah,179
  226.     jl   still
  227.     shr  eax,8
  228.     sub  eax,176
  229.     movsx ecx,byte[day_bounds+eax*2]
  230.     movzx eax,byte[day_bounds+eax*2+1]
  231.     add  ecx,ebx
  232.     test eax,eax
  233.     jz   .chk0
  234.     cmp  ecx,eax
  235.     ja   still
  236.   .ok:
  237.     mov  [day_sel],ecx
  238.     call draw_days
  239.     jmp  still
  240.   .chk0:
  241.     cmp  ecx,eax
  242.     jle  still
  243.     jmp  .ok
  244.  
  245. day_bounds db -1,0,7,0,-7,0,1,0 ; left,down,up,right
  246.  
  247.   button:
  248.     mcall 17
  249.     movzx ebx,ah
  250.     cmp  ah,200
  251.     jbe  nodayselect
  252.     sub  ah,200
  253.     mov  byte[day_sel],ah
  254.     cmp  ebp,5
  255.     jne  .redraw
  256.     call draw_days
  257.     jmp  still
  258.   .redraw:
  259.     mov  [focus],4
  260.     jmp  red
  261.   nodayselect:
  262.     cmp  ah,100
  263.     jb   no_list
  264.     sub  ah,100
  265.     mov  byte[Month],ah
  266.     mov  [focus],2
  267.     jmp  upd
  268.   no_list:
  269.     cmp  ah,1
  270.     jne  noclose
  271.   close:
  272.     mcall -1            ; clore programm
  273.  
  274.   noclose:
  275.  
  276.     cmp  ah,72
  277.     je   plus_he
  278.  
  279.     cmp  ah,73
  280.     je   plus_hd
  281.  
  282.     cmp  ah,74
  283.     je   minus_he
  284.  
  285.     cmp  ah,75
  286.     je   minus_hd
  287.  
  288.     cmp  ah,76
  289.     je   plus_me
  290.  
  291.     cmp  ah,77
  292.     je   plus_md
  293.  
  294.     cmp  ah,78
  295.     je   minus_me
  296.  
  297.     cmp  ah,79
  298.     je   minus_md
  299.  
  300.     cmp  ah,80
  301.     je   reset
  302.  
  303.     cmp  ah,81
  304.     je   set_date
  305.  
  306.     cmp  ah,2           ; drop down list
  307.     jne  no_dropdn
  308.   .drop:
  309.     mov  [focus],2
  310.     cmp  [dropped],al   ; ==0
  311.     jne  red
  312.     call draw_window
  313.     mov  edx,1 shl 31+231
  314.     mov  ecx,31
  315.     mov  eax,8
  316.   .bremove:
  317.     mcall
  318.     dec  edx
  319.     loop .bremove
  320.     call draw_dropdown
  321.     jmp  still
  322.   no_dropdn:
  323.     cmp  ah,3           ; year -1
  324.     jne  noy_dn
  325.   year_dec:
  326.     dec  [Year]
  327.     mov  [focus],3
  328.     jmp  upd
  329.   noy_dn:
  330.     cmp  ah,4           ; year+1
  331.     jne  noy_up
  332.   year_inc:
  333.     inc  [Year]
  334.     mov  [focus],3
  335.     jmp  upd
  336.   noy_up:
  337.     cmp  ah,5
  338.     jne  noy_click
  339.     mov  [focus],3
  340.     call draw_window
  341.   .still:
  342.     mcall 10
  343.     cmp  eax,2
  344.     jne  still.evt
  345.     mcall 2
  346.   .year_evt:
  347.     cmp  ah,176
  348.     je   year_dec
  349.     cmp  ah,179
  350.     je   year_inc
  351.        
  352.     mov  ebx,10
  353.     cmp  ah,9
  354.     je   key.tab
  355.     cmp  ah,8           ; backspace
  356.     jne  .nobsp
  357.     mov  eax,[Year]
  358.     xor  edx,edx
  359.     div  ebx
  360.   .ch_year:
  361.     mov  [Year],eax
  362.     call draw_year
  363.     jmp  .still
  364.   .nobsp:
  365.     cmp  ah,13          ; enter
  366.     je   upd
  367.     cmp  ah,182
  368.     jne  .noclear       ; del
  369.     xor  eax,eax
  370.     jmp  .ch_year
  371.   .noclear:
  372.     cmp  ah,48
  373.     jb   .still
  374.     cmp  ah,57
  375.     ja   .still
  376.     cmp  [Year],1000
  377.     jae  .still
  378.     shr  eax,8
  379.     lea  ecx,[eax-48]
  380.     mov  eax,[Year]
  381.     imul eax,ebx
  382.     add  eax,ecx
  383.     jmp  .ch_year
  384.   noy_click:
  385.     cmp  ah,10
  386.     jne  START
  387.     xor  [new_style],1
  388.     jmp  upd
  389.  
  390.  
  391. reset:
  392.     mcall 3
  393.     mov  ecx,eax
  394.     shl  ecx,16
  395.     shr  ecx,16
  396.     mcall 22,0x00000000
  397.     jmp  still
  398.  
  399. plus_hd:
  400.     mcall 3
  401.     mov  ecx,eax
  402.     add  ecx,1
  403.     mcall 22,0x00000000
  404.     jmp  still
  405.  
  406. plus_he:
  407.     mcall 3
  408.     mov  ecx,eax
  409.     add  ecx,16
  410.     mcall 22,0x00000000
  411.     jmp  still
  412.  
  413. minus_hd:
  414.     mcall 3
  415.     mov  ecx,eax
  416.     sub  ecx,1
  417.         mcall 22,0x00000000
  418.     jmp  still
  419.  
  420. minus_he:
  421.     mcall 3
  422.     mov  ecx,eax
  423.     sub  ecx,16
  424.         mcall 22,0x00000000
  425.     jmp  still
  426.  
  427. plus_md:
  428.     mcall 3
  429.     mov  ecx,eax
  430.     add  ecx,256
  431.         mcall 22,0x00000000
  432.     jmp  still
  433.  
  434. plus_me:
  435.     mcall 3
  436.     mov  ecx,eax
  437.     add  ecx,4096
  438.     mcall 22,0x00000000
  439.     jmp  still
  440.  
  441. minus_md:
  442.     mcall 3
  443.     mov  ecx,eax
  444.     sub  ecx,256
  445.     mcall 22,0x00000000
  446.     jmp  still
  447.  
  448. minus_me:
  449.     mcall 3
  450.     mov  ecx,eax
  451.     sub  ecx,4096
  452.     mcall 22,0x00000000
  453.     jmp  still
  454.  
  455. set_date:
  456.     mov  eax,0x00000000
  457.     mov ebx,[day_sel]
  458.     call additem
  459.     shl  eax,8
  460.     mov  ebx,[Month]
  461.     add  ebx,1
  462.     call additem
  463.     shl  eax,8
  464.     mov  ebx,[Year]
  465.     call additem
  466.     mov  ecx,eax
  467.     mcall 22,1
  468.     jmp  START
  469.  
  470. additem:
  471.     add  eax,1
  472.     daa
  473.     sub  ebx,1
  474.     cmp  ebx,0
  475.     jne  additem
  476.     ret
  477.  
  478.  
  479. ;   *********************************************
  480. ;   *******          DRAW WINDOW          *******
  481. ;   *********************************************
  482.  
  483. draw_clock:
  484.  
  485.     mcall 3
  486.     mov  ecx,eax
  487.     mcall 47,0x00020100, ,195*65536+298,0x50CCCCCC,COL_TOOLBAR_BG
  488.  
  489.     shr  ecx,8
  490.     add  edx,22*65536
  491.     mcall
  492.  
  493.     shr  ecx,8
  494.     add  edx,22*65536
  495.     mcall
  496.     ret
  497.  
  498. define_window:
  499.  
  500.     mcall 12,1
  501.         mcall 48, 5     ; GetClientTop, fix for case when @patel in the top
  502.         shr ebx, 16
  503.         mov ecx,ebx
  504.         shl ecx,16
  505.         cmp ecx,0
  506.         jne  panel_top
  507.         ; panel bottom
  508.         mcall 48,5 ;get screen size
  509.         mov ecx, ebx
  510.         sub ecx, WIN_H
  511.         shl ecx, 16
  512. panel_top:
  513.         add ecx, WIN_H   ; [y start] *65536 + [y size]
  514.         mov ebx, eax
  515.         sub eax, WIN_W
  516.         shl ebx, 16
  517.         add ebx, WIN_W 
  518.     mcall 0,,,COL_WINDOW_BG, ,title ; define window
  519.         mcall 12,2
  520.         GetSkinHeight
  521.         mov ecx, eax
  522.         shl ecx, 16
  523.         add ecx, 43
  524.         mcall 13,B_WBAR_X, ,COL_TOOLBAR_BG ; draw toolbar background
  525.         mcall 13,B_WBAR_X,BT_WBAR_Y,COL_TOOLBAR_BG ; draw toolbar background
  526.         mcall 13,0*65536+B_WBAR_X,84*65536+199,0xE7E7E7
  527.        
  528. draw_window:
  529.     call draw_clock
  530.     call draw_week
  531.     mcall 8,193*65536+8,285*65536+10,72,COL_TOOLBAR_BG
  532.     mov  ebx,202*65536+8
  533.     inc  edx ;73
  534.     mcall
  535.     mov  ebx,193*65536+8
  536.     mov  ecx,315*65536+10
  537.     inc  edx ;74
  538.     mcall
  539.     mov  ebx,202*65536+8
  540.     inc  edx ;75
  541.     mcall
  542.     mov  ebx,215*65536+8
  543.     mov  ecx,285*65536+10
  544.     inc  edx ;76
  545.     mcall
  546.     mov  ebx,224*65536+8
  547.     inc  edx ;77
  548.     mcall
  549.     mov  ebx,215*65536+8
  550.     mov  ecx,315*65536+10
  551.     inc  edx ;78
  552.     mcall
  553.     mov  ebx,224*65536+8
  554.     inc  edx ;79
  555.     mcall
  556.     mov  ebx,25*65536+110
  557.     mov  ecx,293*65536+22
  558.     mov  esi,COL_TOOLBAR_BG
  559.     mov  edx,81
  560.     mcall
  561.  
  562.     mov  esi,COL_MONTH_YEAR_B   ; new style
  563.     mov  edx,10
  564.     or   edx,1 shl 29+1 shl 30
  565.     mov  ebx,B_NS_X
  566.     mov  ecx,B_NS_Y
  567.     mcall
  568.     add  edx,1-1 shl 29
  569.     mov  ebx,B_TODAY_X+8*(today_end-today_msg)
  570.     mov  ecx,B_TODAY_Y
  571.     mcall
  572.     mov  ecx,B_Y
  573.     mov  ebx,B_MONTH_X
  574.     mov  edx,2
  575.     mcall
  576.     mov  ebx,B_SPIN_X ; <
  577.     inc  edx
  578.     mcall
  579.     add  ebx,55 shl 16 ; >
  580.     inc  edx
  581.     mcall
  582.     call draw_days
  583.  
  584.         ; draw text in window
  585.     mcall 4,157*65536+301,0x80CCCCCC,sys_text
  586.     mcall  ,211*65536+301,,separator
  587.     mcall  ,233*65536+301
  588.     mcall  ,185*65536+287, ,plus
  589.     mcall  ,185*65536+317, ,minus
  590.     mcall  , 35*65536+300,0x00CCCCCC,set_date_t,15 ;set date text
  591.  
  592.     mov  ecx,COL_GO_TODAY_T
  593.     mov  edx,today_msg
  594.     mov  ebx,B_TODAY
  595.     mov  esi,today_end-today_msg
  596.     mcall
  597.  
  598.     mov  ebx,B_SPIN
  599.     mov  edx,spinner
  600.     mov  esi,8
  601.     mov  ecx,COL_DROPDOWN_T
  602.     mcall
  603.  
  604.     mov  edx,[Month]
  605.     movzx  esi,byte[month_name]
  606.     imul edx,esi
  607.     add  edx,month_name+1
  608.     mov  ebx,B_MONTH
  609.     ShowFocus 2
  610.     mcall
  611.  
  612.     call draw_year
  613.     mov  [dropped],0
  614.     ret
  615.  
  616. draw_year:
  617.     ShowFocus 3,esi
  618.     mcall 47,0x40001,Year,B_YEAR
  619.     ret
  620.  
  621. draw_dropdown:
  622.     mov  [dropped],1
  623.     push [Month]
  624.     pop  [focus]
  625.     add  [focus],100
  626.     mov  ecx,12
  627.     mov  edx,100
  628.     push dword month_name+1
  629.     push dword B_DROP
  630.     push dword B_Y+16 shl 16
  631.   .ddd_loop:
  632.     mov  edi,edx
  633.     push ecx
  634.     mov  esi,COL_DROPDOWN_BG
  635.     mcall 8,B_MONTH_X,[esp+4]
  636.     mov eax,4
  637.     mov  ebx,[esp+8]
  638.     xchg edx,[esp+12]
  639.     movzx esi,byte[month_name]
  640.     ShowFocus edi
  641.     mcall
  642.     add  edx,esi
  643.     xchg edx,[esp+12]
  644.     add  dword[esp+8],16
  645.     add  dword[esp+4],16 shl 16
  646.     inc  edx
  647.     pop  ecx
  648.     loop .ddd_loop
  649.     add  esp,12
  650.     ret
  651.  
  652. draw_week:
  653.     mov  eax,13
  654.     mov  ebx,B_WBAR_X
  655.     mov  ecx,B_WBAR_Y
  656.     mov  edx,COL_WEEKDAY_BG
  657.     mcall
  658.     movzx esi,byte[week_days]
  659.     movzx edi,byte[week_days+1]
  660.     mov  ebx,B_WEEK
  661.     mov  ecx,7
  662.     mov  edx,week_days+2
  663.     mov  eax,4
  664.   .week:
  665.     push ecx
  666.     cmp  ecx,edi
  667.     je   .holiday
  668.     mov  ecx,0x10000000
  669.     jmp  .noholiday
  670.   .holiday:
  671.     mov  ecx,0x10cc1010
  672.   .noholiday:
  673.     mcall
  674.     add  edx,esi
  675.     add  ebx,B_WX_SHIFT
  676.     pop  ecx
  677.     loop .week
  678.     ret
  679.  
  680. draw_days:
  681.     call count_days
  682.     cmp  ecx,[day_sel]
  683.     jae  .ok
  684.     mov  [day_sel],ecx
  685.   .ok:
  686.     mov  [number],0
  687.     mov  eax,47
  688.     mov  edx,B_DAYS_Y
  689.     mov  ebx,0x10001
  690.     mov  edi,[firstday]
  691.     push ecx
  692.   .dayloop:
  693.     movzx edx,dx
  694.     mov  esi,edi
  695.     shl  esi,21
  696.     lea  edx,[edx+esi+34 shl 16]
  697.     mov  ecx,edi
  698.     add  cl,[week_days+1]
  699.     cmp  ecx,7
  700.     je   .holiday
  701.     mov  esi,0x10313138 ; COL_DATE_TEXT
  702.     jmp  .noholiday
  703.   .holiday:
  704.     mov  esi,0x10cc1010
  705.   .noholiday:
  706.     mov  ecx,number
  707.     inc  dword[ecx]
  708.     pusha
  709.     sub  edx,8 shl 16 + 8
  710.     mov  ebx,edx
  711.     mov  bx,DATE_BUTTON_WIDTH-1
  712.     shrd ecx,edx,16
  713.     mov  cx,DATE_BUTTON_HEIGHT-1
  714.     mov  edx,[number]
  715.     cmp  edx,[day_sel]
  716.     je   .draw_sel
  717.     mov  esi,COL_DATE_BUTTONS
  718.     jmp  .draw_but
  719. .draw_sel:                                  ;draw selected button
  720.         add  edx,1 shl 30
  721.         add  edx,200+1 shl 29
  722.         mcall 8
  723.     cmp  [focus],4
  724.     jne  .not_active
  725.         DrawRect COL_DATE_ACTIVE_1,COL_DATE_ACTIVE_2,COL_DATE_ACTIVE_3,COL_DATE_ACTIVE_4
  726.         jmp .out
  727. .not_active:
  728.         DrawRect COL_DATE_INACTIVE_1,COL_DATE_INACTIVE_2,COL_DATE_INACTIVE_3,COL_DATE_INACTIVE_4
  729.         jmp .out
  730. .draw_but:                                   ;draw non selected button
  731.     add  edx,200+1 shl 29
  732.     mcall 8
  733.         DrawRect COL_DATE_1,COL_DATE_2,COL_DATE_3,COL_DATE_4
  734.         mov eax,[Year]
  735.         cmp [curYear],eax
  736.         jne .out
  737.         mov eax,[Month]
  738.         cmp [curMonth],eax
  739.         jne .out
  740.         mov eax,[number]
  741.         cmp [curDay],eax
  742.         jne .out
  743.         mov edx,0xff0000
  744.         mov bx,DATE_BUTTON_WIDTH-1
  745.         mov cx,3
  746.         sub ebx,2 shl 16
  747.         sub ecx,1 shl 16
  748.         mcall 13
  749. .out:
  750.         mov     eax, [number]
  751.         xor     edx, edx
  752.         mov     ecx, 10
  753.         div     ecx
  754.         mov     [remainder], edx
  755.         mov     [quotient],  eax
  756.         popa
  757.  
  758. ; first number
  759.         mov     ecx,quotient
  760.         mcall
  761.         add     edx,1 shl 16
  762.         mcall
  763. ; second number
  764.         mov     ecx,remainder
  765.         add     edx,8 shl 16
  766.         mcall
  767.         add     edx,1 shl 16
  768.         mcall
  769.         sub     edx,10 shl 16
  770.         inc     edi
  771.         cmp     edi,7
  772.         jne     .nowrap
  773.         xor     edi,edi
  774.         add     dx,B_DAYS_SHIFT
  775. .nowrap:
  776.         dec     dword [esp]
  777.         jnz     .dayloop
  778.         pop     ecx
  779.         ret
  780.  
  781. count_days:    ; ecx -days in month
  782.     call is_leap_year
  783.     mov  ecx,[Month]
  784.     mov  eax,1
  785.     movzx ecx,byte[day_count+ecx]
  786.     add  ecx,28
  787.     cmp  eax,[leap_year]
  788.     jne  .noleap
  789.     cmp  eax,[Month]
  790.     jne  .noleap
  791.     inc  ecx
  792.   .noleap:
  793.     mov  [day_bounds+3],cl
  794.     mov  [day_bounds+7],cl
  795.     ret
  796.  
  797. is_leap_year:
  798.     mov  [leap_year],0
  799.     mov  eax,[Year]
  800.     mov  bl,100
  801.     div  bl          ; ah=Year mod 100, al=Year%100
  802.     test ah,ah
  803.     jz  .century
  804.     shr  ax,8        ; ax - last 2 digits
  805.   .century:
  806.     test al,11b
  807.     jnz  .noleap
  808.     inc  [leap_year]
  809.   .noleap:
  810.     ret
  811.  
  812. calculate:
  813.     mov  ebx,[Year]
  814.     mov  eax,[Month]
  815.     sub  eax,2
  816.     jge  .nojf
  817.     dec  ebx
  818.     add  eax,12
  819.   .nojf:
  820.     add  eax,4
  821.     xor  edx,edx
  822.     mov  ecx,153
  823.     imul cx
  824.     mov  ecx,5
  825.     div  cx
  826.     inc  eax
  827.     mov  ecx,365
  828.     imul ecx,ebx
  829.     add  eax,ecx
  830.     mov  ecx,ebx
  831.     shr  ecx,2
  832.     add  eax,ecx
  833.     dec  eax
  834.     add  eax,2
  835.     xchg eax,ebx
  836.     mov  ecx,100
  837.     xor  edx,edx
  838.     div  cx
  839.     sub  ebx,eax
  840.     shr  eax,2
  841.     add  ebx,eax
  842.     add  ebx,5
  843.     mov  eax,ebx
  844.     xor  edx,edx
  845.     movzx ebx,byte[week_days+1]
  846.     sub  eax,ebx
  847.     inc  eax
  848.     mov  ebx,7
  849.     div  bx
  850.     mov  [firstday],edx
  851.     ret
  852.  
  853. I_END:
  854.