Subversion Repositories Kolibri OS

Rev

Rev 3892 | Rev 3895 | 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, ,198*65536+287,0x50000000,COL_WINDOW_BG
  474.  
  475.     shr  ecx,8
  476.     add  edx,22*65536
  477.     mcall
  478.  
  479.     shr  ecx,8
  480.     add  edx,22*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,196*65536+8,272*65536+10,72,COL_DATE_BUTTONS
  496.  
  497.     mov  ebx,205*65536+8
  498.     inc  edx
  499.     mcall
  500.  
  501.     mov  ebx,196*65536+8
  502.     mov  ecx,298*65536+10
  503.     inc  edx
  504.     mcall
  505.  
  506.     mov  ebx,205*65536+8
  507.     inc  edx
  508.     mcall
  509.  
  510.     mov  ebx,218*65536+8
  511.     mov  ecx,272*65536+10
  512.     inc  edx
  513.     mcall
  514.  
  515.     mov  ebx,227*65536+8
  516.     inc  edx
  517.     mcall
  518.  
  519.     mov  ebx,218*65536+8
  520.     mov  ecx,298*65536+10
  521.     inc  edx
  522.     mcall
  523.  
  524.     mov  ebx,227*65536+8
  525.     inc  edx
  526.     mcall
  527.  
  528.     mov  ebx,240*65536+21
  529.     mov  ecx,273*65536+35
  530.     inc  edx
  531.     or   edx,0x40000000
  532.     mcall
  533.  
  534.     mov  ebx,14*65536+110
  535.     mov  ecx,285*65536+22
  536.     mov  esi,COL_DATE_BUTTONS
  537.     mov  edx,81
  538.     mcall
  539.  
  540.     mov  esi,COL_MONTH_YEAR_B   ; new style
  541.     mov  edx,10
  542.     or   edx,1 shl 29+1 shl 30
  543.     mov  ebx,B_NS_X
  544.     mov  ecx,B_NS_Y
  545.     mcall
  546.     add  edx,1-1 shl 29
  547.     mov  ebx,B_TODAY_X+8*(today_end-today_msg)
  548.     mov  ecx,B_TODAY_Y
  549.     mcall
  550.     mov  ecx,B_Y
  551.     mov  ebx,B_MONTH_X
  552.     mov  edx,2
  553.     mcall
  554.     mov  ebx,B_SPIN_X ; <
  555.     inc  edx
  556.     mcall
  557.     add  ebx,61 shl 16 ; >
  558.     inc  edx
  559.     mcall
  560.     call draw_days
  561.  
  562.         ; draw text in window
  563.     mcall 4,153*65536+287,0x80000000,sys_text
  564.     mcall 4,183*65536+287, ,separator
  565.     mcall  ,214*65536+287
  566.     mcall  ,236*65536+287
  567.     mcall  ,188*65536+274, ,plus
  568.     mcall  ,188*65536+300, ,minus
  569.     mcall  , 24*65536+292,0x00000000,set_date_t,15 ;set date text
  570.  
  571.  
  572.     mov  ecx,0x10ddeeff
  573.     mov  edx,n_style
  574.     mov  esi,ns_end-n_style
  575.     mov  ebx,B_NS
  576.     cmp  [new_style],1
  577.     je   .high
  578.     mov  ecx,0xa0a0a0
  579.     jmp  .int
  580.   .high:
  581.     mov  ecx,COL_NEW_STYLE_T
  582.   .int:
  583.     mcall
  584.  
  585.     mov  ecx,COL_GO_TODAY_T
  586.     mov  edx,today_msg
  587.     mov  ebx,B_TODAY
  588.     mov  esi,today_end-today_msg
  589.     mcall
  590.  
  591.     mov  ebx,B_SPIN
  592.     mov  edx,spinner
  593.     mov  esi,12
  594.         mov  ecx,COL_DROPDOWN_T
  595.     mcall
  596.  
  597.     mov  edx,[Month]
  598.     movzx  esi,byte[month_name]
  599.     imul edx,esi
  600.     add  edx,month_name+1
  601.     mov  ebx,B_MONTH
  602.     ShowFocus 2
  603.     mcall
  604.  
  605.     call draw_year
  606.     mov  [dropped],0
  607.     mcall 12,2
  608.     ret
  609.  
  610. draw_year:
  611.     mcall 8,B_YEAR_X,B_Y,5,COL_MONTH_YEAR_B
  612.     ShowFocus 3,esi
  613.     mcall 47,0x40001,Year,B_YEAR
  614.     ret
  615.  
  616. draw_dropdown:
  617.     mov  [dropped],1
  618.     push [Month]
  619.     pop  [focus]
  620.     add  [focus],100
  621.     mov  ecx,12
  622.     mov  edx,100
  623.     push dword month_name+1
  624.     push dword B_DROP
  625.     push dword B_Y+16 shl 16
  626.   .ddd_loop:
  627.     mov  edi,edx
  628.     push ecx
  629.     mov  esi,COL_DROPDOWN_BG
  630.     mcall 8,B_MONTH_X,[esp+4]
  631.     shr  eax,1
  632.     mov  ebx,[esp+8]
  633.     xchg edx,[esp+12]
  634.     movzx esi,byte[month_name]
  635.     ShowFocus edi
  636.     mcall
  637.     add  edx,esi
  638.     xchg edx,[esp+12]
  639.     add  dword[esp+8],16
  640.     add  dword[esp+4],16 shl 16
  641.     inc  edx
  642.     pop  ecx
  643.     loop .ddd_loop
  644.     add  esp,12
  645.     ret
  646.  
  647. draw_week:
  648.     mov  eax,13
  649.     mov  ebx,B_WBAR_X
  650.     mov  ecx,B_WBAR_Y
  651.     mov  edx,COL_WEEKDAY_BG
  652.     mcall
  653.     movzx esi,byte[week_days]
  654.     movzx edi,byte[week_days+1]
  655.     mov  ebx,B_WEEK
  656.     mov  ecx,7
  657.     mov  edx,week_days+2
  658.     mov  eax,4
  659.   .week:
  660.     push ecx
  661.     cmp  ecx,edi
  662.     je   .holiday
  663.     mov  ecx,0x10000000
  664.     jmp  .noholiday
  665.   .holiday:
  666.     mov  ecx,0x10cc1010
  667.   .noholiday:
  668.     mcall
  669.     add  edx,esi
  670.     add  ebx,B_WX_SHIFT
  671.     pop  ecx
  672.     loop .week
  673.     ret
  674.  
  675. draw_days:
  676.     call count_days
  677.     cmp  ecx,[day_sel]
  678.     jae  .ok
  679.     mov  [day_sel],ecx
  680.   .ok:
  681.     mov  [number],0
  682.     mov  eax,47
  683.     mov  edx,B_DAYS_Y
  684.     mov  ebx,0x10001
  685.     mov  edi,[firstday]
  686.   .dayloop:
  687.     push ecx
  688.     movzx edx,dx
  689.     mov  esi,edi
  690.     shl  esi,21
  691.     lea  edx,[edx+esi+34 shl 16]
  692.     mov  ecx,edi
  693.     add  cl,[week_days+1]
  694.     cmp  ecx,7
  695.     je   .holiday
  696.     mov  esi,0x10313138 ; COL_DATE_TEXT
  697.     jmp  .noholiday
  698.   .holiday:
  699.     mov  esi,0x10cc1010
  700.   .noholiday:
  701.     mov  ecx,number
  702.     inc  dword[ecx]
  703.     pusha
  704.     mov  ebx,edx
  705.     mov  bx,DATE_BUTTON_WIDTH-1
  706.     sub  ebx,8 shl 16
  707.     shrd ecx,edx,16
  708.     mov  cx,DATE_BUTTON_HEIGHT-1
  709.     sub  ecx,12 shl 16
  710.     mov  edx,[number]
  711.     cmp  edx,[day_sel]
  712.     je   .draw_sel
  713.     mov  esi,COL_DATE_BUTTONS
  714.     jmp  .draw_but
  715. .draw_sel:                                  ;draw selected button
  716.         add  edx,1 shl 30
  717.         add  edx,200+1 shl 29
  718.         mcall 8
  719.     cmp  [focus],4
  720.     jne  .not_active
  721.         DrawRect COL_DATE_ACTIVE_1,COL_DATE_ACTIVE_2,COL_DATE_ACTIVE_3,COL_DATE_ACTIVE_4
  722.         jmp .out
  723. .not_active:
  724.         DrawRect COL_DATE_INACTIVE_1,COL_DATE_INACTIVE_2,COL_DATE_INACTIVE_3,COL_DATE_INACTIVE_4
  725.         jmp .out
  726. .draw_but:                                   ;draw non selected button
  727.     add  edx,200+1 shl 29
  728.     mcall 8
  729.         mov eax,[Year]
  730.         cmp [curYear],eax
  731.         jne .out
  732.         mov eax,[Month]
  733.         cmp [curMonth],eax
  734.         jne .out
  735.         mov eax,[number]
  736.         cmp [curDay],eax
  737.         jne .out
  738.         mov edx,0xff0000
  739.         mov bx,DATE_BUTTON_WIDTH-2
  740.         mov cx,2
  741.         add ebx,1 shl 16
  742.         add ecx,27 shl 16
  743.         mcall 13
  744. .out:
  745.         mov    eax, [number]
  746.     xor    edx, edx
  747.     mov    ecx, 10
  748.     div    ecx
  749.     mov    [remainder], edx
  750.     mov    [quotient],  eax
  751.         popa
  752.        
  753.         ;first number
  754.         mov ecx,quotient
  755.     mcall
  756.         add edx,1 shl 16
  757.         mcall
  758.         sub edx,1 shl 16
  759.        
  760.         ;second number
  761.         mov ecx,remainder
  762.         add edx,9 shl 16
  763.     mcall
  764.         add edx,1 shl 16
  765.         mcall
  766.         sub edx,10 shl 16
  767.        
  768.        
  769.     pop  ecx
  770.     inc  edi
  771.     cmp  edi,7
  772.     jne  .nowrap
  773.     xor  edi,edi
  774.     add  dx,B_DAYS_SHIFT
  775.   .nowrap:
  776.     loop .eloop
  777.     jmp  .ex
  778.   .eloop:
  779.     jmp  .dayloop
  780.   .ex:
  781.     ret
  782.  
  783. count_days:    ; ecx -days in month
  784.     call is_leap_year
  785.     mov  ecx,[Month]
  786.     mov  eax,1
  787.     movzx ecx,byte[day_count+ecx]
  788.     add  ecx,28
  789.     cmp  eax,[leap_year]
  790.     jne  .noleap
  791.     cmp  eax,[Month]
  792.     jne  .noleap
  793.     inc  ecx
  794.   .noleap:
  795.     mov  [day_bounds+3],cl
  796.     mov  [day_bounds+7],cl
  797.     ret
  798.  
  799. is_leap_year:
  800.     mov  [leap_year],0
  801.     mov  eax,[Year]
  802.     mov  bl,100
  803.     div  bl          ; ah=Year mod 100, al=Year%100
  804.     test ah,ah
  805.     jz  .century
  806.     shr  ax,8        ; ax - last 2 digits
  807.   .century:
  808.     test al,11b
  809.     jnz  .noleap
  810.     inc  [leap_year]
  811.   .noleap:
  812.     ret
  813.  
  814. calculate:
  815.     mov  ebx,[Year]
  816.     mov  eax,[Month]
  817.     sub  eax,2
  818.     jge  .nojf
  819.     dec  ebx
  820.     add  eax,12
  821.   .nojf:
  822.     add  eax,4
  823.     xor  edx,edx
  824.     mov  ecx,153
  825.     imul cx
  826.     mov  ecx,5
  827.     div  cx
  828.     inc  eax
  829.     mov  ecx,365
  830.     imul ecx,ebx
  831.     add  eax,ecx
  832.     mov  ecx,ebx
  833.     shr  ecx,2
  834.     add  eax,ecx
  835.     dec  eax
  836.     cmp  [new_style],0
  837.     je   .nonew
  838.     add  eax,2
  839.     xchg eax,ebx
  840.     mov  ecx,100
  841.     xor  edx,edx
  842.     div  cx
  843.     sub  ebx,eax
  844.     shr  eax,2
  845.     add  ebx,eax
  846.   .nonew:
  847.     add  ebx,5
  848.     mov  eax,ebx
  849.     xor  edx,edx
  850.     movzx ebx,byte[week_days+1]
  851.     sub  eax,ebx
  852.     inc  eax
  853.     mov  ebx,7
  854.     div  bx
  855.     mov  [firstday],edx
  856.     ret
  857.  
  858. I_END:
  859.  
  860. firstday  dd ?
  861. Year dd   ?
  862. Month dd  ?
  863. day_sel   dd ?
  864.  
  865. datestr   dd  ?
  866. leap_year dd ?
  867. number    dd ?
  868.