Subversion Repositories Kolibri OS

Rev

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