Subversion Repositories Kolibri OS

Rev

Rev 6950 | Rev 7724 | 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
7717 leency 87
	mov cx,DATE_BUTTON_HEIGHT-3
3891 leency 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
 
7717 leency 143
get_current_date:
31 halyavin 144
    mcall 29
145
    mov  [datestr],eax
146
    mov  esi,datestr
147
    call str2int
148
    add  eax,1900
7717 leency 149
    mov  [curYear],eax
31 halyavin 150
    call str2int
151
    dec  eax
7717 leency 152
    mov  [curMonth],eax
31 halyavin 153
    call str2int
7717 leency 154
    mov  [curDay],eax
31 halyavin 155
    test byte[esi],0
156
    jnz  .no2000
7717 leency 157
    add  [curYear],100
31 halyavin 158
  .no2000:
7717 leency 159
    call calculate
160
ret
161
 
162
check_midnight:
163
    mov   ebx,[datestr]
164
    mcall 29
165
	cmp   eax,ebx
166
	je   end_check_midnight
167
	  call get_current_date
168
	  call draw_days
169
    end_check_midnight:
170
ret
171
 
172
;===============================================================
173
 
174
START:
175
    call get_current_date
176
	m2m [Year], [curYear]
177
	m2m [Month], [curMonth]
178
	m2m [day_sel], [curDay]
3891 leency 179
red:
4735 leency 180
    call define_window
31 halyavin 181
 
3891 leency 182
still:
31 halyavin 183
 
3889 leency 184
    mcall 23,50     ; wait here for event
31 halyavin 185
  .evt:
186
    mov  ebp,[focus]
3891 leency 187
    cmp  eax,1
188
    je	 red
189
    cmp  eax,2
190
    je	 key
191
    cmp  eax,3
192
    je	 button
31 halyavin 193
 
7717 leency 194
    call check_midnight
452 heavyiron 195
    call draw_clock
196
 
3891 leency 197
    jmp  still
31 halyavin 198
 
3889 leency 199
  key:
200
    mcall 2		; get pressed key
31 halyavin 201
    cmp  ah,9
202
    jne  no_tab
203
  .tab:
204
    cmp  ebp,FOCUSABLE
5880 pathoswith 205
    JAE  foc_cycle
31 halyavin 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
135 diamond 228
    je	 noclose.drop
31 halyavin 229
    jmp  still
230
  .nomonth:
231
    cmp  ebp,3
135 diamond 232
    je	 noy_up.year_evt
3890 leency 233
    cmp  ebp,4
31 halyavin 234
    jne  still
235
    mov  ebx,[day_sel]
135 diamond 236
    cmp  ah,176 	; left arrow
6002 veliant 237
    jg	 still
31 halyavin 238
    cmp  ah,179
6002 veliant 239
    jl	 still
31 halyavin 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
135 diamond 246
    jz	 .chk0
31 halyavin 247
    cmp  ecx,eax
135 diamond 248
    ja	 still
31 halyavin 249
  .ok:
250
    mov  [day_sel],ecx
251
    call draw_days
3891 leency 252
    jmp  still
31 halyavin 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
 
3889 leency 260
  button:
3891 leency 261
    mcall 17
31 halyavin 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:
3890 leency 272
    mov  [focus],4
31 halyavin 273
    jmp  red
274
  nodayselect:
275
    cmp  ah,100
135 diamond 276
    jb	 no_list
31 halyavin 277
    sub  ah,100
278
    mov  byte[Month],ah
279
    mov  [focus],2
280
    jmp  upd
281
  no_list:
3891 leency 282
    cmp  ah,1
283
    jne  noclose
31 halyavin 284
  close:
3891 leency 285
    mcall -1		; clore programm
31 halyavin 286
 
287
  noclose:
452 heavyiron 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
 
485 heavyiron 316
    cmp  ah,81
317
    je	 set_date
452 heavyiron 318
 
135 diamond 319
    cmp  ah,2		; drop down list
31 halyavin 320
    jne  no_dropdn
321
  .drop:
322
    mov  [focus],2
135 diamond 323
    cmp  [dropped],al	; ==0
31 halyavin 324
    jne  red
325
    call draw_window
326
    mov  edx,1 shl 31+231
327
    mov  ecx,31
328
    mov  eax,8
329
  .bremove:
452 heavyiron 330
    mcall
31 halyavin 331
    dec  edx
332
    loop .bremove
333
    call draw_dropdown
334
    jmp  still
335
  no_dropdn:
135 diamond 336
    cmp  ah,3		; year -1
31 halyavin 337
    jne  noy_dn
338
  year_dec:
339
    dec  [Year]
3890 leency 340
    mov  [focus],3
31 halyavin 341
    jmp  upd
342
  noy_dn:
135 diamond 343
    cmp  ah,4		; year+1
31 halyavin 344
    jne  noy_up
345
  year_inc:
346
    inc  [Year]
3890 leency 347
    mov  [focus],3
31 halyavin 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:
3890 leency 360
    cmp  ah,176
361
    je	 year_dec
362
    cmp  ah,179
363
    je	 year_inc
364
 
31 halyavin 365
    mov  ebx,10
366
    cmp  ah,9
135 diamond 367
    je	 key.tab
368
    cmp  ah,8		; backspace
31 halyavin 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:
135 diamond 378
    cmp  ah,13		; enter
379
    je	 upd
31 halyavin 380
    cmp  ah,182
135 diamond 381
    jne  .noclear	; del
31 halyavin 382
    xor  eax,eax
383
    jmp  .ch_year
384
  .noclear:
385
    cmp  ah,48
135 diamond 386
    jb	 .still
31 halyavin 387
    cmp  ah,57
135 diamond 388
    ja	 .still
31 halyavin 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
3891 leency 399
    jne  START
31 halyavin 400
    xor  [new_style],1
401
    jmp  upd
402
 
403
 
452 heavyiron 404
reset:
3890 leency 405
    mcall 3
452 heavyiron 406
    mov  ecx,eax
407
    shl  ecx,16
408
    shr  ecx,16
3890 leency 409
    mcall 22,0x00000000
452 heavyiron 410
    jmp  still
411
 
412
plus_hd:
3889 leency 413
    mcall 3
452 heavyiron 414
    mov  ecx,eax
415
    add  ecx,1
3889 leency 416
    mcall 22,0x00000000
452 heavyiron 417
    jmp  still
418
 
419
plus_he:
3889 leency 420
    mcall 3
452 heavyiron 421
    mov  ecx,eax
422
    add  ecx,16
3889 leency 423
    mcall 22,0x00000000
452 heavyiron 424
    jmp  still
425
 
426
minus_hd:
3889 leency 427
    mcall 3
452 heavyiron 428
    mov  ecx,eax
429
    sub  ecx,1
3890 leency 430
	mcall 22,0x00000000
452 heavyiron 431
    jmp  still
432
 
433
minus_he:
3890 leency 434
    mcall 3
452 heavyiron 435
    mov  ecx,eax
436
    sub  ecx,16
3890 leency 437
	mcall 22,0x00000000
452 heavyiron 438
    jmp  still
439
 
440
plus_md:
3890 leency 441
    mcall 3
452 heavyiron 442
    mov  ecx,eax
443
    add  ecx,256
3890 leency 444
	mcall 22,0x00000000
452 heavyiron 445
    jmp  still
446
 
447
plus_me:
3887 leency 448
    mcall 3
452 heavyiron 449
    mov  ecx,eax
450
    add  ecx,4096
3887 leency 451
    mcall 22,0x00000000
452 heavyiron 452
    jmp  still
453
 
454
minus_md:
3887 leency 455
    mcall 3
452 heavyiron 456
    mov  ecx,eax
457
    sub  ecx,256
3887 leency 458
    mcall 22,0x00000000
452 heavyiron 459
    jmp  still
460
 
461
minus_me:
3887 leency 462
    mcall 3
452 heavyiron 463
    mov  ecx,eax
464
    sub  ecx,4096
3887 leency 465
    mcall 22,0x00000000
452 heavyiron 466
    jmp  still
467
 
485 heavyiron 468
set_date:
469
    mov  eax,0x00000000
470
    mov ebx,[day_sel]
471
    call additem
472
    shl  eax,8
473
    mov  ebx,[Month]
474
    add  ebx,1
475
    call additem
476
    shl  eax,8
477
    mov  ebx,[Year]
478
    call additem
479
    mov  ecx,eax
3890 leency 480
    mcall 22,1
3895 leency 481
    jmp  START
485 heavyiron 482
 
483
additem:
484
    add  eax,1
485
    daa
486
    sub  ebx,1
487
    cmp  ebx,0
488
    jne  additem
489
    ret
490
 
491
 
31 halyavin 492
;   *********************************************
5880 pathoswith 493
;   *******	     DRAW WINDOW	  *******
31 halyavin 494
;   *********************************************
495
 
452 heavyiron 496
draw_clock:
497
 
3887 leency 498
    mcall 3
452 heavyiron 499
    mov  ecx,eax
5880 pathoswith 500
    mcall 47,0x00020100, ,195*65536+298,0x50CCCCCC,COL_TOOLBAR_BG
452 heavyiron 501
 
502
    shr  ecx,8
3894 heavyiron 503
    add  edx,22*65536
452 heavyiron 504
    mcall
505
 
506
    shr  ecx,8
3894 heavyiron 507
    add  edx,22*65536
452 heavyiron 508
    mcall
509
    ret
510
 
4735 leency 511
define_window:
31 halyavin 512
 
3889 leency 513
    mcall 12,1
5880 pathoswith 514
	mcall 48, 5	; GetClientTop, fix for case when @patel in the top
4880 leency 515
	shr ebx, 16
516
	mov ecx,ebx
517
	shl ecx,16
518
	cmp ecx,0
519
	jne  panel_top
520
	; panel bottom
3895 leency 521
	mcall 48,5 ;get screen size
522
	mov ecx, ebx
523
	sub ecx, WIN_H
524
	shl ecx, 16
4880 leency 525
panel_top:
5880 pathoswith 526
	add ecx, WIN_H	 ; [y start] *65536 + [y size]
3895 leency 527
	mov ebx, eax
528
	sub eax, WIN_W
529
	shl ebx, 16
530
	add ebx, WIN_W
531
    mcall 0,,,COL_WINDOW_BG, ,title ; define window
4735 leency 532
	mcall 12,2
3889 leency 533
	GetSkinHeight
534
	mov ecx, eax
535
	shl ecx, 16
536
	add ecx, 43
537
	mcall 13,B_WBAR_X, ,COL_TOOLBAR_BG ; draw toolbar background
4196 Akyltist 538
	mcall 13,B_WBAR_X,BT_WBAR_Y,COL_TOOLBAR_BG ; draw toolbar background
4735 leency 539
	mcall 13,0*65536+B_WBAR_X,84*65536+199,0xE7E7E7
540
 
541
draw_window:
5880 pathoswith 542
    call draw_clock
31 halyavin 543
    call draw_week
5880 pathoswith 544
    mcall 8,193*65536+8,285*65536+10,72,COL_TOOLBAR_BG
3895 leency 545
    mov  ebx,202*65536+8
546
    inc  edx ;73
452 heavyiron 547
    mcall
3895 leency 548
    mov  ebx,193*65536+8
5880 pathoswith 549
    mov  ecx,315*65536+10
3895 leency 550
    inc  edx ;74
452 heavyiron 551
    mcall
3895 leency 552
    mov  ebx,202*65536+8
553
    inc  edx ;75
452 heavyiron 554
    mcall
3895 leency 555
    mov  ebx,215*65536+8
5880 pathoswith 556
    mov  ecx,285*65536+10
3895 leency 557
    inc  edx ;76
452 heavyiron 558
    mcall
3895 leency 559
    mov  ebx,224*65536+8
560
    inc  edx ;77
452 heavyiron 561
    mcall
3895 leency 562
    mov  ebx,215*65536+8
5880 pathoswith 563
    mov  ecx,315*65536+10
3895 leency 564
    inc  edx ;78
452 heavyiron 565
    mcall
3895 leency 566
    mov  ebx,224*65536+8
567
    inc  edx ;79
452 heavyiron 568
    mcall
3895 leency 569
    mov  ebx,25*65536+110
4196 Akyltist 570
    mov  ecx,293*65536+22
571
    mov  esi,COL_TOOLBAR_BG
3894 heavyiron 572
    mov  edx,81
485 heavyiron 573
    mcall
574
 
5880 pathoswith 575
    mov  esi,COL_MONTH_YEAR_B	; new style
31 halyavin 576
    mov  edx,10
135 diamond 577
    or	 edx,1 shl 29+1 shl 30
31 halyavin 578
    mov  ebx,B_NS_X
579
    mov  ecx,B_NS_Y
452 heavyiron 580
    mcall
31 halyavin 581
    add  edx,1-1 shl 29
582
    mov  ebx,B_TODAY_X+8*(today_end-today_msg)
583
    mov  ecx,B_TODAY_Y
452 heavyiron 584
    mcall
31 halyavin 585
    mov  ecx,B_Y
586
    mov  ebx,B_MONTH_X
587
    mov  edx,2
452 heavyiron 588
    mcall
3889 leency 589
    mov  ebx,B_SPIN_X ; <
31 halyavin 590
    inc  edx
452 heavyiron 591
    mcall
6950 leency 592
    add  ebx,55 shl 16 ; >
31 halyavin 593
    inc  edx
452 heavyiron 594
    mcall
31 halyavin 595
    call draw_days
596
 
3891 leency 597
	; draw text in window
4197 Akyltist 598
    mcall 4,157*65536+301,0x80CCCCCC,sys_text
4196 Akyltist 599
    mcall  ,211*65536+301,,separator
600
    mcall  ,233*65536+301
5880 pathoswith 601
    mcall  ,185*65536+287, ,plus
602
    mcall  ,185*65536+317, ,minus
4196 Akyltist 603
    mcall  , 35*65536+300,0x00CCCCCC,set_date_t,15 ;set date text
452 heavyiron 604
 
3887 leency 605
    mov  ecx,COL_GO_TODAY_T
31 halyavin 606
    mov  edx,today_msg
607
    mov  ebx,B_TODAY
608
    mov  esi,today_end-today_msg
452 heavyiron 609
    mcall
31 halyavin 610
 
611
    mov  ebx,B_SPIN
612
    mov  edx,spinner
5880 pathoswith 613
    mov  esi,8
614
    mov  ecx,COL_DROPDOWN_T
452 heavyiron 615
    mcall
31 halyavin 616
 
617
    mov  edx,[Month]
618
    movzx  esi,byte[month_name]
619
    imul edx,esi
620
    add  edx,month_name+1
621
    mov  ebx,B_MONTH
622
    ShowFocus 2
452 heavyiron 623
    mcall
31 halyavin 624
 
625
    call draw_year
626
    mov  [dropped],0
3889 leency 627
    ret
31 halyavin 628
 
629
draw_year:
630
    ShowFocus 3,esi
631
    mcall 47,0x40001,Year,B_YEAR
632
    ret
633
 
634
draw_dropdown:
635
    mov  [dropped],1
636
    push [Month]
637
    pop  [focus]
638
    add  [focus],100
639
    mov  ecx,12
640
    mov  edx,100
641
    push dword month_name+1
642
    push dword B_DROP
643
    push dword B_Y+16 shl 16
644
  .ddd_loop:
645
    mov  edi,edx
646
    push ecx
3889 leency 647
    mov  esi,COL_DROPDOWN_BG
648
    mcall 8,B_MONTH_X,[esp+4]
6950 leency 649
    mov eax,4
31 halyavin 650
    mov  ebx,[esp+8]
651
    xchg edx,[esp+12]
652
    movzx esi,byte[month_name]
653
    ShowFocus edi
452 heavyiron 654
    mcall
31 halyavin 655
    add  edx,esi
656
    xchg edx,[esp+12]
657
    add  dword[esp+8],16
658
    add  dword[esp+4],16 shl 16
659
    inc  edx
660
    pop  ecx
661
    loop .ddd_loop
662
    add  esp,12
663
    ret
664
 
665
draw_week:
666
    mov  eax,13
667
    mov  ebx,B_WBAR_X
668
    mov  ecx,B_WBAR_Y
3887 leency 669
    mov  edx,COL_WEEKDAY_BG
452 heavyiron 670
    mcall
31 halyavin 671
    movzx esi,byte[week_days]
672
    movzx edi,byte[week_days+1]
673
    mov  ebx,B_WEEK
674
    mov  ecx,7
675
    mov  edx,week_days+2
676
    mov  eax,4
677
  .week:
678
    push ecx
679
    cmp  ecx,edi
135 diamond 680
    je	 .holiday
31 halyavin 681
    mov  ecx,0x10000000
682
    jmp  .noholiday
683
  .holiday:
684
    mov  ecx,0x10cc1010
685
  .noholiday:
452 heavyiron 686
    mcall
31 halyavin 687
    add  edx,esi
688
    add  ebx,B_WX_SHIFT
689
    pop  ecx
690
    loop .week
691
    ret
692
 
693
draw_days:
694
    call count_days
695
    cmp  ecx,[day_sel]
696
    jae  .ok
697
    mov  [day_sel],ecx
698
  .ok:
699
    mov  [number],0
700
    mov  eax,47
701
    mov  edx,B_DAYS_Y
3889 leency 702
    mov  ebx,0x10001
31 halyavin 703
    mov  edi,[firstday]
5880 pathoswith 704
    push ecx
31 halyavin 705
  .dayloop:
706
    movzx edx,dx
707
    mov  esi,edi
708
    shl  esi,21
3889 leency 709
    lea  edx,[edx+esi+34 shl 16]
31 halyavin 710
    mov  ecx,edi
711
    add  cl,[week_days+1]
712
    cmp  ecx,7
135 diamond 713
    je	 .holiday
3891 leency 714
    mov  esi,0x10313138 ; COL_DATE_TEXT
31 halyavin 715
    jmp  .noholiday
716
  .holiday:
717
    mov  esi,0x10cc1010
718
  .noholiday:
719
    mov  ecx,number
720
    inc  dword[ecx]
721
    pusha
5880 pathoswith 722
    sub  edx,8 shl 16 + 8
31 halyavin 723
    mov  ebx,edx
3891 leency 724
    mov  bx,DATE_BUTTON_WIDTH-1
31 halyavin 725
    shrd ecx,edx,16
3891 leency 726
    mov  cx,DATE_BUTTON_HEIGHT-1
31 halyavin 727
    mov  edx,[number]
728
    cmp  edx,[day_sel]
135 diamond 729
    je	 .draw_sel
3887 leency 730
    mov  esi,COL_DATE_BUTTONS
31 halyavin 731
    jmp  .draw_but
5880 pathoswith 732
.draw_sel:				    ;draw selected button
3891 leency 733
	add  edx,1 shl 30
734
	add  edx,200+1 shl 29
735
	mcall 8
3890 leency 736
    cmp  [focus],4
3891 leency 737
    jne  .not_active
738
	DrawRect COL_DATE_ACTIVE_1,COL_DATE_ACTIVE_2,COL_DATE_ACTIVE_3,COL_DATE_ACTIVE_4
3892 leency 739
	jmp .out
3891 leency 740
.not_active:
741
	DrawRect COL_DATE_INACTIVE_1,COL_DATE_INACTIVE_2,COL_DATE_INACTIVE_3,COL_DATE_INACTIVE_4
3892 leency 742
	jmp .out
5880 pathoswith 743
.draw_but:				     ;draw non selected button
31 halyavin 744
    add  edx,200+1 shl 29
3889 leency 745
    mcall 8
6950 leency 746
	DrawRect COL_DATE_1,COL_DATE_2,COL_DATE_3,COL_DATE_4
3891 leency 747
	mov eax,[Year]
748
	cmp [curYear],eax
749
	jne .out
750
	mov eax,[Month]
751
	cmp [curMonth],eax
752
	jne .out
753
	mov eax,[number]
754
	cmp [curDay],eax
755
	jne .out
3892 leency 756
	mov edx,0xff0000
6950 leency 757
	mov bx,DATE_BUTTON_WIDTH-1
758
	mov cx,3
759
	sub ebx,2 shl 16
760
	sub ecx,1 shl 16
3892 leency 761
	mcall 13
3891 leency 762
.out:
5880 pathoswith 763
	mov	eax, [number]
764
	xor	edx, edx
765
	mov	ecx, 10
766
	div	ecx
767
	mov	[remainder], edx
768
	mov	[quotient],  eax
3889 leency 769
	popa
5880 pathoswith 770
 
771
; first number
772
	mov	ecx,quotient
3887 leency 773
	mcall
5880 pathoswith 774
	add	edx,1 shl 16
3889 leency 775
	mcall
5880 pathoswith 776
; second number
777
	mov	ecx,remainder
778
	add	edx,8 shl 16
779
	mcall
780
	add	edx,1 shl 16
781
	mcall
782
	sub	edx,10 shl 16
783
	inc	edi
784
	cmp	edi,7
785
	jne	.nowrap
786
	xor	edi,edi
787
	add	dx,B_DAYS_SHIFT
788
.nowrap:
789
	dec	dword [esp]
790
	jnz	.dayloop
791
	pop	ecx
792
	ret
31 halyavin 793
 
794
count_days:    ; ecx -days in month
795
    call is_leap_year
796
    mov  ecx,[Month]
797
    mov  eax,1
798
    movzx ecx,byte[day_count+ecx]
799
    add  ecx,28
800
    cmp  eax,[leap_year]
801
    jne  .noleap
802
    cmp  eax,[Month]
803
    jne  .noleap
804
    inc  ecx
805
  .noleap:
806
    mov  [day_bounds+3],cl
807
    mov  [day_bounds+7],cl
808
    ret
809
 
810
is_leap_year:
811
    mov  [leap_year],0
812
    mov  eax,[Year]
813
    mov  bl,100
135 diamond 814
    div  bl	     ; ah=Year mod 100, al=Year%100
31 halyavin 815
    test ah,ah
135 diamond 816
    jz	.century
817
    shr  ax,8	     ; ax - last 2 digits
31 halyavin 818
  .century:
819
    test al,11b
820
    jnz  .noleap
821
    inc  [leap_year]
822
  .noleap:
823
    ret
824
 
825
calculate:
826
    mov  ebx,[Year]
827
    mov  eax,[Month]
828
    sub  eax,2
829
    jge  .nojf
830
    dec  ebx
831
    add  eax,12
832
  .nojf:
833
    add  eax,4
834
    xor  edx,edx
835
    mov  ecx,153
836
    imul cx
837
    mov  ecx,5
838
    div  cx
839
    inc  eax
840
    mov  ecx,365
841
    imul ecx,ebx
842
    add  eax,ecx
843
    mov  ecx,ebx
844
    shr  ecx,2
845
    add  eax,ecx
846
    dec  eax
847
    add  eax,2
848
    xchg eax,ebx
849
    mov  ecx,100
850
    xor  edx,edx
851
    div  cx
852
    sub  ebx,eax
853
    shr  eax,2
854
    add  ebx,eax
855
    add  ebx,5
856
    mov  eax,ebx
857
    xor  edx,edx
858
    movzx ebx,byte[week_days+1]
859
    sub  eax,ebx
860
    inc  eax
861
    mov  ebx,7
862
    div  bx
863
    mov  [firstday],edx
864
    ret
865
 
3889 leency 866
I_END: