Subversion Repositories Kolibri OS

Rev

Rev 4197 | Rev 4880 | 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.         ; rgiht 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.         ; bottom border-outer
  103.         mov edx,color2
  104.         pop ecx
  105.         pop ebx
  106.         add ecx,DATE_BUTTON_HEIGHT shl 16
  107.         sub ecx,1 shl 16
  108.         add ebx,1 shl 16
  109.         mov cx,1
  110.         mcall
  111.         ; left border-outer
  112.         mov edx,color4
  113.         add ebx,1 shl 16
  114.         sub ecx,1 shl 16
  115.         sub bx,2
  116.         mcall
  117. }
  118.  
  119.  
  120. str2int:
  121.     xor  eax,eax
  122.     lodsb
  123.     mov  ebx,eax
  124.     shr  ebx,4
  125.     and  eax,0xf
  126.     imul ebx,10
  127.     add  al,bl
  128.     ret
  129.  
  130. START:
  131.     mcall 29
  132.     mov  [datestr],eax
  133.     mov  esi,datestr
  134.     call str2int
  135.     add  eax,1900
  136.     mov  [Year],eax
  137.     call str2int
  138.     dec  eax
  139.     mov  [Month],eax
  140.     call str2int
  141.     mov  [day_sel],eax
  142.     test byte[esi],0
  143.     jnz  .no2000
  144.     add  [Year],100
  145.         mov eax,[Year]
  146.         mov [curYear], eax
  147.         mov eax,[Month]
  148.         mov [curMonth], eax
  149.         mov eax,[day_sel]
  150.         mov [curDay], eax
  151.   .no2000:
  152.     jmp  upd
  153. red:
  154.  
  155.     call define_window
  156.  
  157. still:
  158.  
  159.     mcall 23,50     ; wait here for event
  160.   .evt:
  161.     mov  ebp,[focus]
  162.     cmp  eax,1
  163.     je   red
  164.     cmp  eax,2
  165.     je   key
  166.     cmp  eax,3
  167.     je   button
  168.  
  169.     call draw_clock
  170.  
  171.     jmp  still
  172.  
  173.   key:
  174.     mcall 2             ; get pressed key
  175.     cmp  ah,9
  176.     jne  no_tab
  177.   .tab:
  178.     cmp  ebp,FOCUSABLE
  179.     JAE  foc_cycle
  180.     inc  [focus]
  181.   upd:
  182.     call calculate
  183.     jmp  red
  184.   foc_cycle:
  185.     mov  [focus],2
  186.     jmp  upd
  187.   no_tab:
  188.     push eax
  189.     shr  eax,8
  190.     mov  ecx,12
  191.     mov  edi,Fkeys
  192.     repne scasb
  193.     pop  eax
  194.     jnz  .noFkey
  195.     sub  edi,Fkeys+1
  196.     mov  [Month],edi
  197.     jmp  upd
  198.   .noFkey:
  199.     cmp  ebp,2
  200.     jne  .nomonth
  201.     cmp  ah,177
  202.     je   noclose.drop
  203.     jmp  still
  204.   .nomonth:
  205.     cmp  ebp,3
  206.     je   noy_up.year_evt
  207.     cmp  ebp,4
  208.     jne  still
  209.     mov  ebx,[day_sel]
  210.     cmp  ah,176         ; left arrow
  211.     jb   still
  212.     cmp  ah,179
  213.     ja   still
  214.     shr  eax,8
  215.     sub  eax,176
  216.     movsx ecx,byte[day_bounds+eax*2]
  217.     movzx eax,byte[day_bounds+eax*2+1]
  218.     add  ecx,ebx
  219.     test eax,eax
  220.     jz   .chk0
  221.     cmp  ecx,eax
  222.     ja   still
  223.   .ok:
  224.     mov  [day_sel],ecx
  225.     call draw_days
  226.     jmp  still
  227.   .chk0:
  228.     cmp  ecx,eax
  229.     jle  still
  230.     jmp  .ok
  231.  
  232. day_bounds db -1,0,7,0,-7,0,1,0 ; left,down,up,right
  233.  
  234.   button:
  235.     mcall 17
  236.     movzx ebx,ah
  237.     cmp  ah,200
  238.     jbe  nodayselect
  239.     sub  ah,200
  240.     mov  byte[day_sel],ah
  241.     cmp  ebp,5
  242.     jne  .redraw
  243.     call draw_days
  244.     jmp  still
  245.   .redraw:
  246.     mov  [focus],4
  247.     jmp  red
  248.   nodayselect:
  249.     cmp  ah,100
  250.     jb   no_list
  251.     sub  ah,100
  252.     mov  byte[Month],ah
  253.     mov  [focus],2
  254.     jmp  upd
  255.   no_list:
  256.     cmp  ah,1
  257.     jne  noclose
  258.   close:
  259.     mcall -1            ; clore programm
  260.  
  261.   noclose:
  262.  
  263.     cmp  ah,72
  264.     je   plus_he
  265.  
  266.     cmp  ah,73
  267.     je   plus_hd
  268.  
  269.     cmp  ah,74
  270.     je   minus_he
  271.  
  272.     cmp  ah,75
  273.     je   minus_hd
  274.  
  275.     cmp  ah,76
  276.     je   plus_me
  277.  
  278.     cmp  ah,77
  279.     je   plus_md
  280.  
  281.     cmp  ah,78
  282.     je   minus_me
  283.  
  284.     cmp  ah,79
  285.     je   minus_md
  286.  
  287.     cmp  ah,80
  288.     je   reset
  289.  
  290.     cmp  ah,81
  291.     je   set_date
  292.  
  293.     cmp  ah,2           ; drop down list
  294.     jne  no_dropdn
  295.   .drop:
  296.     mov  [focus],2
  297.     cmp  [dropped],al   ; ==0
  298.     jne  red
  299.     call draw_window
  300.     mov  edx,1 shl 31+231
  301.     mov  ecx,31
  302.     mov  eax,8
  303.   .bremove:
  304.     mcall
  305.     dec  edx
  306.     loop .bremove
  307.     call draw_dropdown
  308.     jmp  still
  309.   no_dropdn:
  310.     cmp  ah,3           ; year -1
  311.     jne  noy_dn
  312.   year_dec:
  313.     dec  [Year]
  314.     mov  [focus],3
  315.     jmp  upd
  316.   noy_dn:
  317.     cmp  ah,4           ; year+1
  318.     jne  noy_up
  319.   year_inc:
  320.     inc  [Year]
  321.     mov  [focus],3
  322.     jmp  upd
  323.   noy_up:
  324.     cmp  ah,5
  325.     jne  noy_click
  326.     mov  [focus],3
  327.     call draw_window
  328.   .still:
  329.     mcall 10
  330.     cmp  eax,2
  331.     jne  still.evt
  332.     mcall 2
  333.   .year_evt:
  334.     cmp  ah,176
  335.     je   year_dec
  336.     cmp  ah,179
  337.     je   year_inc
  338.        
  339.     mov  ebx,10
  340.     cmp  ah,9
  341.     je   key.tab
  342.     cmp  ah,8           ; backspace
  343.     jne  .nobsp
  344.     mov  eax,[Year]
  345.     xor  edx,edx
  346.     div  ebx
  347.   .ch_year:
  348.     mov  [Year],eax
  349.     call draw_year
  350.     jmp  .still
  351.   .nobsp:
  352.     cmp  ah,13          ; enter
  353.     je   upd
  354.     cmp  ah,182
  355.     jne  .noclear       ; del
  356.     xor  eax,eax
  357.     jmp  .ch_year
  358.   .noclear:
  359.     cmp  ah,48
  360.     jb   .still
  361.     cmp  ah,57
  362.     ja   .still
  363.     cmp  [Year],1000
  364.     jae  .still
  365.     shr  eax,8
  366.     lea  ecx,[eax-48]
  367.     mov  eax,[Year]
  368.     imul eax,ebx
  369.     add  eax,ecx
  370.     jmp  .ch_year
  371.   noy_click:
  372.     cmp  ah,10
  373.     jne  START
  374.     xor  [new_style],1
  375.     jmp  upd
  376.  
  377.  
  378. reset:
  379.     mcall 3
  380.     mov  ecx,eax
  381.     shl  ecx,16
  382.     shr  ecx,16
  383.     mcall 22,0x00000000
  384.     jmp  still
  385.  
  386. plus_hd:
  387.     mcall 3
  388.     mov  ecx,eax
  389.     add  ecx,1
  390.     mcall 22,0x00000000
  391.     jmp  still
  392.  
  393. plus_he:
  394.     mcall 3
  395.     mov  ecx,eax
  396.     add  ecx,16
  397.     mcall 22,0x00000000
  398.     jmp  still
  399.  
  400. minus_hd:
  401.     mcall 3
  402.     mov  ecx,eax
  403.     sub  ecx,1
  404.         mcall 22,0x00000000
  405.     jmp  still
  406.  
  407. minus_he:
  408.     mcall 3
  409.     mov  ecx,eax
  410.     sub  ecx,16
  411.         mcall 22,0x00000000
  412.     jmp  still
  413.  
  414. plus_md:
  415.     mcall 3
  416.     mov  ecx,eax
  417.     add  ecx,256
  418.         mcall 22,0x00000000
  419.     jmp  still
  420.  
  421. plus_me:
  422.     mcall 3
  423.     mov  ecx,eax
  424.     add  ecx,4096
  425.     mcall 22,0x00000000
  426.     jmp  still
  427.  
  428. minus_md:
  429.     mcall 3
  430.     mov  ecx,eax
  431.     sub  ecx,256
  432.     mcall 22,0x00000000
  433.     jmp  still
  434.  
  435. minus_me:
  436.     mcall 3
  437.     mov  ecx,eax
  438.     sub  ecx,4096
  439.     mcall 22,0x00000000
  440.     jmp  still
  441.  
  442. set_date:
  443.     mov  eax,0x00000000
  444.     mov ebx,[day_sel]
  445.     call additem
  446.     shl  eax,8
  447.     mov  ebx,[Month]
  448.     add  ebx,1
  449.     call additem
  450.     shl  eax,8
  451.     mov  ebx,[Year]
  452.     call additem
  453.     mov  ecx,eax
  454.     mcall 22,1
  455.     jmp  START
  456.  
  457. additem:
  458.     add  eax,1
  459.     daa
  460.     sub  ebx,1
  461.     cmp  ebx,0
  462.     jne  additem
  463.     ret
  464.  
  465.  
  466. ;   *********************************************
  467. ;   *******          DRAW WINDOW          *******
  468. ;   *********************************************
  469.  
  470. draw_clock:
  471.  
  472.     mcall 3
  473.     mov  ecx,eax
  474.     mcall 47,0x00020100, ,195*65536+301,0x50CCCCCC,COL_TOOLBAR_BG
  475.  
  476.     shr  ecx,8
  477.     add  edx,22*65536
  478.     mcall
  479.  
  480.     shr  ecx,8
  481.     add  edx,22*65536
  482.     mcall
  483.     ret
  484.  
  485. define_window:
  486.  
  487.     mcall 12,1
  488.         mcall 48,5 ;get screen size
  489.         mov ecx, ebx
  490.         sub ecx, WIN_H
  491.         shl ecx, 16
  492.         add ecx, WIN_H
  493.         mov ebx, eax
  494.         sub eax, WIN_W
  495.         shl ebx, 16
  496.         add ebx, WIN_W 
  497.     mcall 0,,,COL_WINDOW_BG, ,title ; define window
  498.         mcall 12,2
  499.         GetSkinHeight
  500.         mov ecx, eax
  501.         shl ecx, 16
  502.         add ecx, 43
  503.         mcall 13,B_WBAR_X, ,COL_TOOLBAR_BG ; draw toolbar background
  504.         mcall 13,B_WBAR_X,BT_WBAR_Y,COL_TOOLBAR_BG ; draw toolbar background
  505.         mcall 13,0*65536+B_WBAR_X,84*65536+199,0xE7E7E7
  506.        
  507. draw_window:
  508.  
  509.     call draw_week
  510.     mcall 8,193*65536+8,287*65536+10,72,COL_TOOLBAR_BG
  511.     mov  ebx,202*65536+8
  512.     inc  edx ;73
  513.     mcall
  514.     mov  ebx,193*65536+8
  515.     mov  ecx,311*65536+10
  516.     inc  edx ;74
  517.     mcall
  518.     mov  ebx,202*65536+8
  519.     inc  edx ;75
  520.     mcall
  521.     mov  ebx,215*65536+8
  522.     mov  ecx,287*65536+10
  523.     inc  edx ;76
  524.     mcall
  525.     mov  ebx,224*65536+8
  526.     inc  edx ;77
  527.     mcall
  528.     mov  ebx,215*65536+8
  529.     mov  ecx,311*65536+10
  530.     inc  edx ;78
  531.     mcall
  532.     mov  ebx,224*65536+8
  533.     inc  edx ;79
  534.     mcall
  535.     ;mov  ebx,237*65536+21
  536.     ;mov  ecx,281*65536+35
  537.     ;inc  edx ;80
  538.     ;or   edx,0x40CCFF44
  539.     ;mcall
  540.     mov  ebx,25*65536+110
  541.     mov  ecx,293*65536+22
  542.     mov  esi,COL_TOOLBAR_BG
  543.     mov  edx,81
  544.     mcall
  545.  
  546.     mov  esi,COL_MONTH_YEAR_B   ; new style
  547.     mov  edx,10
  548.     or   edx,1 shl 29+1 shl 30
  549.     mov  ebx,B_NS_X
  550.     mov  ecx,B_NS_Y
  551.     mcall
  552.     add  edx,1-1 shl 29
  553.     mov  ebx,B_TODAY_X+8*(today_end-today_msg)
  554.     mov  ecx,B_TODAY_Y
  555.     mcall
  556.     mov  ecx,B_Y
  557.     mov  ebx,B_MONTH_X
  558.     mov  edx,2
  559.     mcall
  560.     mov  ebx,B_SPIN_X ; <
  561.     inc  edx
  562.     mcall
  563.     add  ebx,61 shl 16 ; >
  564.     inc  edx
  565.     mcall
  566.     call draw_days
  567.  
  568.         ; draw text in window
  569.     mcall 4,157*65536+301,0x80CCCCCC,sys_text
  570.     mcall  ,211*65536+301,,separator
  571.     mcall  ,233*65536+301
  572.     mcall  ,185*65536+289, ,plus
  573.     mcall  ,185*65536+313, ,minus
  574.     mcall  , 35*65536+300,0x00CCCCCC,set_date_t,15 ;set date text
  575.  
  576.  
  577.     mov  ecx,0x10ddeeff
  578.     mov  edx,n_style
  579.     mov  esi,ns_end-n_style
  580.     mov  ebx,B_NS
  581.     cmp  [new_style],1
  582.     je   .high
  583.     mov  ecx,0xa0a0a0
  584.     jmp  .int
  585.   .high:
  586.     mov  ecx,COL_NEW_STYLE_T
  587.   .int:
  588.     mcall
  589.  
  590.     mov  ecx,COL_GO_TODAY_T
  591.     mov  edx,today_msg
  592.     mov  ebx,B_TODAY
  593.     mov  esi,today_end-today_msg
  594.     mcall
  595.  
  596.     mov  ebx,B_SPIN
  597.     mov  edx,spinner
  598.     mov  esi,12
  599.         mov  ecx,COL_DROPDOWN_T
  600.     mcall
  601.  
  602.     mov  edx,[Month]
  603.     movzx  esi,byte[month_name]
  604.     imul edx,esi
  605.     add  edx,month_name+1
  606.     mov  ebx,B_MONTH
  607.     ShowFocus 2
  608.     mcall
  609.  
  610.     call draw_year
  611.     call draw_clock
  612.     mov  [dropped],0
  613.     ret
  614.  
  615. draw_year:
  616.     mcall 8,B_YEAR_X,B_Y,5,COL_MONTH_YEAR_B
  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.     shr  eax,1
  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.   .dayloop:
  692.     push ecx
  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.     mov  ebx,edx
  710.     mov  bx,DATE_BUTTON_WIDTH-1
  711.     sub  ebx,8 shl 16
  712.     shrd ecx,edx,16
  713.     mov  cx,DATE_BUTTON_HEIGHT-1
  714.     sub  ecx,12 shl 16
  715.     mov  edx,[number]
  716.     cmp  edx,[day_sel]
  717.     je   .draw_sel
  718.     mov  esi,COL_DATE_BUTTONS
  719.     jmp  .draw_but
  720. .draw_sel:                                  ;draw selected button
  721.         add  edx,1 shl 30
  722.         add  edx,200+1 shl 29
  723.         mcall 8
  724.     cmp  [focus],4
  725.     jne  .not_active
  726.         DrawRect COL_DATE_ACTIVE_1,COL_DATE_ACTIVE_2,COL_DATE_ACTIVE_3,COL_DATE_ACTIVE_4
  727.         jmp .out
  728. .not_active:
  729.         DrawRect COL_DATE_INACTIVE_1,COL_DATE_INACTIVE_2,COL_DATE_INACTIVE_3,COL_DATE_INACTIVE_4
  730.         jmp .out
  731. .draw_but:                                   ;draw non selected button
  732.     add  edx,200+1 shl 29
  733.     mcall 8
  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-2
  745.         mov cx,2
  746.         add ebx,1 shl 16
  747.         add ecx,27 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.         sub edx,1 shl 16
  764.        
  765.         ;second number
  766.         mov ecx,remainder
  767.         add edx,9 shl 16
  768.     mcall
  769.         add edx,1 shl 16
  770.         mcall
  771.         sub edx,10 shl 16
  772.        
  773.        
  774.     pop  ecx
  775.     inc  edi
  776.     cmp  edi,7
  777.     jne  .nowrap
  778.     xor  edi,edi
  779.     add  dx,B_DAYS_SHIFT
  780.   .nowrap:
  781.     loop .eloop
  782.     jmp  .ex
  783.   .eloop:
  784.     jmp  .dayloop
  785.   .ex:
  786.     ret
  787.  
  788. count_days:    ; ecx -days in month
  789.     call is_leap_year
  790.     mov  ecx,[Month]
  791.     mov  eax,1
  792.     movzx ecx,byte[day_count+ecx]
  793.     add  ecx,28
  794.     cmp  eax,[leap_year]
  795.     jne  .noleap
  796.     cmp  eax,[Month]
  797.     jne  .noleap
  798.     inc  ecx
  799.   .noleap:
  800.     mov  [day_bounds+3],cl
  801.     mov  [day_bounds+7],cl
  802.     ret
  803.  
  804. is_leap_year:
  805.     mov  [leap_year],0
  806.     mov  eax,[Year]
  807.     mov  bl,100
  808.     div  bl          ; ah=Year mod 100, al=Year%100
  809.     test ah,ah
  810.     jz  .century
  811.     shr  ax,8        ; ax - last 2 digits
  812.   .century:
  813.     test al,11b
  814.     jnz  .noleap
  815.     inc  [leap_year]
  816.   .noleap:
  817.     ret
  818.  
  819. calculate:
  820.     mov  ebx,[Year]
  821.     mov  eax,[Month]
  822.     sub  eax,2
  823.     jge  .nojf
  824.     dec  ebx
  825.     add  eax,12
  826.   .nojf:
  827.     add  eax,4
  828.     xor  edx,edx
  829.     mov  ecx,153
  830.     imul cx
  831.     mov  ecx,5
  832.     div  cx
  833.     inc  eax
  834.     mov  ecx,365
  835.     imul ecx,ebx
  836.     add  eax,ecx
  837.     mov  ecx,ebx
  838.     shr  ecx,2
  839.     add  eax,ecx
  840.     dec  eax
  841.     cmp  [new_style],0
  842.     je   .nonew
  843.     add  eax,2
  844.     xchg eax,ebx
  845.     mov  ecx,100
  846.     xor  edx,edx
  847.     div  cx
  848.     sub  ebx,eax
  849.     shr  eax,2
  850.     add  ebx,eax
  851.   .nonew:
  852.     add  ebx,5
  853.     mov  eax,ebx
  854.     xor  edx,edx
  855.     movzx ebx,byte[week_days+1]
  856.     sub  eax,ebx
  857.     inc  eax
  858.     mov  ebx,7
  859.     div  bx
  860.     mov  [firstday],edx
  861.     ret
  862.  
  863. I_END:
  864.