Subversion Repositories Kolibri OS

Rev

Rev 6002 | Rev 7717 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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