Subversion Repositories Kolibri OS

Rev

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