Subversion Repositories Kolibri OS

Rev

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

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