Subversion Repositories Kolibri OS

Rev

Rev 7724 | 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 design 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. ret
  160.  
  161. check_midnight:
  162.     mov   ebx,[datestr]
  163.     mcall 29
  164.         cmp   eax,ebx
  165.         je   end_check_midnight
  166.           call get_current_date
  167.           call draw_days
  168.     end_check_midnight:
  169. ret
  170.  
  171. ;===============================================================
  172.  
  173. START:
  174.     call get_current_date
  175.         m2m [Year], [curYear]
  176.         m2m [Month], [curMonth]
  177.         m2m [day_sel], [curDay]
  178.     call calculate
  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. update_clock:
  404.     mcall 22,0x00000000
  405.     call draw_clock    
  406.     jmp  still
  407.  
  408. reset:
  409.     mcall 3
  410.     mov  ecx,eax
  411.     shl  ecx,16
  412.     shr  ecx,16
  413.     jmp  update_clock
  414.  
  415. plus_hd:
  416.     mcall 3
  417.     mov  ecx,eax
  418.     add  ecx,1
  419.     jmp  update_clock
  420.  
  421. plus_he:
  422.     mcall 3
  423.     mov  ecx,eax
  424.     add  ecx,16
  425.     jmp  update_clock
  426.  
  427. minus_hd:
  428.     mcall 3
  429.     mov  ecx,eax
  430.     sub  ecx,1
  431.     jmp  update_clock
  432.  
  433. minus_he:
  434.     mcall 3
  435.     mov  ecx,eax
  436.     sub  ecx,16
  437.     jmp  update_clock
  438.  
  439. plus_md:
  440.     mcall 3
  441.     mov  ecx,eax
  442.     add  ecx,256
  443.     jmp  update_clock
  444.  
  445. plus_me:
  446.     mcall 3
  447.     mov  ecx,eax
  448.     add  ecx,4096
  449.     jmp  update_clock
  450.  
  451. minus_md:
  452.     mcall 3
  453.     mov  ecx,eax
  454.     sub  ecx,256
  455.     jmp  update_clock
  456.  
  457. minus_me:
  458.     mcall 3
  459.     mov  ecx,eax
  460.     sub  ecx,4096
  461.     jmp  update_clock
  462.  
  463. set_date:
  464.     mov  eax,0x00000000
  465.     mov ebx,[day_sel]
  466.     call additem
  467.     shl  eax,8
  468.     mov  ebx,[Month]
  469.     add  ebx,1
  470.     call additem
  471.     shl  eax,8
  472.     mov  ebx,[Year]
  473.     call additem
  474.     mov  ecx,eax
  475.     mcall 22,1
  476.     jmp  START
  477.  
  478. additem:
  479.     add  eax,1
  480.     daa
  481.     sub  ebx,1
  482.     cmp  ebx,0
  483.     jne  additem
  484.     ret
  485.  
  486.  
  487. ;   *********************************************
  488. ;   *******          DRAW WINDOW          *******
  489. ;   *********************************************
  490.  
  491. draw_clock:
  492.  
  493.     mcall 3
  494.     mov  ecx,eax
  495.     mcall 47,0x00020100, ,195*65536+298,0x50CCCCCC,COL_TOOLBAR_BG
  496.  
  497.     shr  ecx,8
  498.     add  edx,22*65536
  499.     mcall
  500.  
  501.     shr  ecx,8
  502.     add  edx,22*65536
  503.     mcall
  504.     ret
  505.  
  506. define_window:
  507.  
  508.     mcall 12,1
  509.         mcall 48, 5     ; GetClientTop, fix for case when @patel in the top
  510.         shr ebx, 16
  511.         mov ecx,ebx
  512.         shl ecx,16
  513.         cmp ecx,0
  514.         jne  panel_top
  515.         ; panel bottom
  516.         mcall 48,5 ;get screen size
  517.         mov ecx, ebx
  518.         sub ecx, WIN_H
  519.         shl ecx, 16
  520. panel_top:
  521.         add ecx, WIN_H   ; [y start] *65536 + [y size]
  522.         mov ebx, eax
  523.         sub eax, WIN_W
  524.         shl ebx, 16
  525.         add ebx, WIN_W 
  526.     mcall 0,,,COL_WINDOW_BG, ,title ; define window
  527.         mcall 12,2
  528.         GetSkinHeight
  529.         mov ecx, eax
  530.         shl ecx, 16
  531.         add ecx, 43
  532.         mcall 13,B_WBAR_X, ,COL_TOOLBAR_BG ; draw toolbar background
  533.         mcall 13,B_WBAR_X,BT_WBAR_Y,COL_TOOLBAR_BG ; draw toolbar background
  534.         mcall 13,0*65536+B_WBAR_X,84*65536+199,0xE7E7E7
  535.        
  536. draw_window:
  537.     call draw_clock
  538.     call draw_week
  539.     mcall 8,193*65536+8,285*65536+10,72,COL_TOOLBAR_BG
  540.     mov  ebx,202*65536+8
  541.     inc  edx ;73
  542.     mcall
  543.     mov  ebx,193*65536+8
  544.     mov  ecx,315*65536+10
  545.     inc  edx ;74
  546.     mcall
  547.     mov  ebx,202*65536+8
  548.     inc  edx ;75
  549.     mcall
  550.     mov  ebx,215*65536+8
  551.     mov  ecx,285*65536+10
  552.     inc  edx ;76
  553.     mcall
  554.     mov  ebx,224*65536+8
  555.     inc  edx ;77
  556.     mcall
  557.     mov  ebx,215*65536+8
  558.     mov  ecx,315*65536+10
  559.     inc  edx ;78
  560.     mcall
  561.     mov  ebx,224*65536+8
  562.     inc  edx ;79
  563.     mcall
  564.     mov  ebx,25*65536+110
  565.     mov  ecx,293*65536+22
  566.     mov  esi,COL_TOOLBAR_BG
  567.     mov  edx,81
  568.     mcall
  569.  
  570.     mov  esi,COL_MONTH_YEAR_B   ; new style
  571.     mov  edx,10
  572.     or   edx,1 shl 29+1 shl 30
  573.     mov  ebx,B_NS_X
  574.     mov  ecx,B_NS_Y
  575.     mcall
  576.     add  edx,1-1 shl 29
  577.     mov  ebx,B_TODAY_X+8*(today_end-today_msg)
  578.     mov  ecx,B_TODAY_Y
  579.     mcall
  580.     mov  ecx,B_Y
  581.     mov  ebx,B_MONTH_X
  582.     mov  edx,2
  583.     mcall
  584.     mov  ebx,B_SPIN_X ; <
  585.     inc  edx
  586.     mcall
  587.     add  ebx,55 shl 16 ; >
  588.     inc  edx
  589.     mcall
  590.     call draw_days
  591.  
  592.         ; draw text in window
  593.     mcall 4,157*65536+301,0x80CCCCCC,sys_text
  594.     mcall  ,211*65536+301,,separator
  595.     mcall  ,233*65536+301
  596.     mcall  ,185*65536+287, ,plus
  597.     mcall  ,185*65536+317, ,minus
  598.     mcall  , 35*65536+300,0x00CCCCCC,set_date_t,15 ;set date text
  599.  
  600.     mov  ecx,COL_GO_TODAY_T
  601.     mov  edx,today_msg
  602.     mov  ebx,B_TODAY
  603.     mov  esi,today_end-today_msg
  604.     mcall
  605.  
  606.     mov  ebx,B_SPIN
  607.     mov  edx,spinner
  608.     mov  esi,8
  609.     mov  ecx,COL_DROPDOWN_T
  610.     mcall
  611.  
  612.     mov  edx,[Month]
  613.     movzx  esi,byte[month_name]
  614.     imul edx,esi
  615.     add  edx,month_name+1
  616.     mov  ebx,B_MONTH
  617.     ShowFocus 2
  618.     mcall
  619.  
  620.     call draw_year
  621.     mov  [dropped],0
  622.     ret
  623.  
  624. draw_year:
  625.     ShowFocus 3,esi
  626.     mcall 47,0x40001,Year,B_YEAR
  627.     ret
  628.  
  629. draw_dropdown:
  630.     mov  [dropped],1
  631.     push [Month]
  632.     pop  [focus]
  633.     add  [focus],100
  634.     mov  ecx,12
  635.     mov  edx,100
  636.     push dword month_name+1
  637.     push dword B_DROP
  638.     push dword B_Y+16 shl 16
  639.   .ddd_loop:
  640.     mov  edi,edx
  641.     push ecx
  642.     mov  esi,COL_DROPDOWN_BG
  643.     mcall 8,B_MONTH_X,[esp+4]
  644.     mov eax,4
  645.     mov  ebx,[esp+8]
  646.     xchg edx,[esp+12]
  647.     movzx esi,byte[month_name]
  648.     ShowFocus edi
  649.     mcall
  650.     add  edx,esi
  651.     xchg edx,[esp+12]
  652.     add  dword[esp+8],16
  653.     add  dword[esp+4],16 shl 16
  654.     inc  edx
  655.     pop  ecx
  656.     loop .ddd_loop
  657.     add  esp,12
  658.     ret
  659.  
  660. draw_week:
  661.     mov  eax,13
  662.     mov  ebx,B_WBAR_X
  663.     mov  ecx,B_WBAR_Y
  664.     mov  edx,COL_WEEKDAY_BG
  665.     mcall
  666.     movzx esi,byte[week_days]
  667.     movzx edi,byte[week_days+1]
  668.     mov  ebx,B_WEEK
  669.     mov  ecx,7
  670.     mov  edx,week_days+2
  671.     mov  eax,4
  672.   .week:
  673.     push ecx
  674.     cmp  ecx,edi
  675.     je   .holiday
  676.     mov  ecx,0x10000000
  677.     jmp  .noholiday
  678.   .holiday:
  679.     mov  ecx,0x10cc1010
  680.   .noholiday:
  681.     mcall
  682.     add  edx,esi
  683.     add  ebx,B_WX_SHIFT
  684.     pop  ecx
  685.     loop .week
  686.     ret
  687.  
  688. draw_days:
  689.     call count_days
  690.     cmp  ecx,[day_sel]
  691.     jae  .ok
  692.     mov  [day_sel],ecx
  693.   .ok:
  694.     mov  [number],0
  695.     mov  eax,47
  696.     mov  edx,B_DAYS_Y
  697.     mov  ebx,0x10001
  698.     mov  edi,[firstday]
  699.     push ecx
  700.   .dayloop:
  701.     movzx edx,dx
  702.     mov  esi,edi
  703.     shl  esi,21
  704.     lea  edx,[edx+esi+34 shl 16]
  705.     mov  ecx,edi
  706.     add  cl,[week_days+1]
  707.     cmp  ecx,7
  708.     je   .holiday
  709.     mov  esi,0x10313138 ; COL_DATE_TEXT
  710.     jmp  .noholiday
  711.   .holiday:
  712.     mov  esi,0x10cc1010
  713.   .noholiday:
  714.     mov  ecx,number
  715.     inc  dword[ecx]
  716.     pusha
  717.     sub  edx,8 shl 16 + 8
  718.     mov  ebx,edx
  719.     mov  bx,DATE_BUTTON_WIDTH-1
  720.     shrd ecx,edx,16
  721.     mov  cx,DATE_BUTTON_HEIGHT-1
  722.     mov  edx,[number]
  723.     cmp  edx,[day_sel]
  724.     je   .draw_sel
  725.     mov  esi,COL_DATE_BUTTONS
  726.     jmp  .draw_but
  727. .draw_sel:                                  ;draw selected button
  728.         add  edx,1 shl 30
  729.         add  edx,200+1 shl 29
  730.         mcall 8
  731.     cmp  [focus],4
  732.     jne  .not_active
  733.         DrawRect COL_DATE_ACTIVE_1,COL_DATE_ACTIVE_2,COL_DATE_ACTIVE_3,COL_DATE_ACTIVE_4
  734.         jmp .out
  735. .not_active:
  736.         DrawRect COL_DATE_INACTIVE_1,COL_DATE_INACTIVE_2,COL_DATE_INACTIVE_3,COL_DATE_INACTIVE_4
  737.         jmp .out
  738. .draw_but:                                   ;draw non selected button
  739.     add  edx,200+1 shl 29
  740.     mcall 8
  741.         DrawRect COL_DATE_1,COL_DATE_2,COL_DATE_3,COL_DATE_4
  742.         mov eax,[Year]
  743.         cmp [curYear],eax
  744.         jne .out
  745.         mov eax,[Month]
  746.         cmp [curMonth],eax
  747.         jne .out
  748.         mov eax,[number]
  749.         cmp [curDay],eax
  750.         jne .out
  751.         mov edx,0xff0000
  752.         mov bx,DATE_BUTTON_WIDTH-1
  753.         mov cx,3
  754.         sub ebx,2 shl 16
  755.         sub ecx,1 shl 16
  756.         mcall 13
  757. .out:
  758.         mov     eax, [number]
  759.         xor     edx, edx
  760.         mov     ecx, 10
  761.         div     ecx
  762.         mov     [remainder], edx
  763.         mov     [quotient],  eax
  764.         popa
  765.  
  766. ; first number
  767.         mov     ecx,quotient
  768.         mcall
  769.         add     edx,1 shl 16
  770.         mcall
  771. ; second number
  772.         mov     ecx,remainder
  773.         add     edx,8 shl 16
  774.         mcall
  775.         add     edx,1 shl 16
  776.         mcall
  777.         sub     edx,10 shl 16
  778.         inc     edi
  779.         cmp     edi,7
  780.         jne     .nowrap
  781.         xor     edi,edi
  782.         add     dx,B_DAYS_SHIFT
  783. .nowrap:
  784.         dec     dword [esp]
  785.         jnz     .dayloop
  786.         pop     ecx
  787.         ret
  788.  
  789. count_days:    ; ecx -days in month
  790.     call is_leap_year
  791.     mov  ecx,[Month]
  792.     mov  eax,1
  793.     movzx ecx,byte[day_count+ecx]
  794.     add  ecx,28
  795.     cmp  eax,[leap_year]
  796.     jne  .noleap
  797.     cmp  eax,[Month]
  798.     jne  .noleap
  799.     inc  ecx
  800.   .noleap:
  801.     mov  [day_bounds+3],cl
  802.     mov  [day_bounds+7],cl
  803.     ret
  804.  
  805. is_leap_year:
  806.     mov  [leap_year],0
  807.     mov  eax,[Year]
  808.     mov  bl,100
  809.     div  bl          ; ah=Year mod 100, al=Year%100
  810.     test ah,ah
  811.     jz  .century
  812.     shr  ax,8        ; ax - last 2 digits
  813.   .century:
  814.     test al,11b
  815.     jnz  .noleap
  816.     inc  [leap_year]
  817.   .noleap:
  818.     ret
  819.  
  820. calculate:
  821.     mov  ebx,[Year]
  822.     mov  eax,[Month]
  823.     sub  eax,2
  824.     jge  .nojf
  825.     dec  ebx
  826.     add  eax,12
  827.   .nojf:
  828.     add  eax,4
  829.     xor  edx,edx
  830.     mov  ecx,153
  831.     imul cx
  832.     mov  ecx,5
  833.     div  cx
  834.     inc  eax
  835.     mov  ecx,365
  836.     imul ecx,ebx
  837.     add  eax,ecx
  838.     mov  ecx,ebx
  839.     shr  ecx,2
  840.     add  eax,ecx
  841.     dec  eax
  842.     add  eax,2
  843.     xchg eax,ebx
  844.     mov  ecx,100
  845.     xor  edx,edx
  846.     div  cx
  847.     sub  ebx,eax
  848.     shr  eax,2
  849.     add  ebx,eax
  850.     add  ebx,5
  851.     mov  eax,ebx
  852.     xor  edx,edx
  853.     movzx ebx,byte[week_days+1]
  854.     sub  eax,ebx
  855.     inc  eax
  856.     mov  ebx,7
  857.     div  bx
  858.     mov  [firstday],edx
  859.     ret
  860.  
  861. I_END:
  862.