Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
4943 eAndrew 1
VERSION equ "0.5"
4939 eAndrew 2
 
4865 eAndrew 3
    use32
4
    org     0
5
    db	    'MENUET01'
6
    dd	    1, main, dataend, memory, stacktop, 0, 0
7
 
8
    include "../../proc32.inc"
9
    include "../../macros.inc"
10
    include "../../dll.inc"
11
    include "../../develop/libraries/box_lib/trunk/box_lib.mac"
4943 eAndrew 12
  ;  include "../../debug.inc"
4865 eAndrew 13
    include "parser.inc"
14
 
15
 ;===============================
16
 
4943 eAndrew 17
    LIST_ITEM_SIZE   equ 16
18
    LIST_ITEM_COUNT  equ 6
19
    LIST_SIZE	     equ LIST_ITEM_SIZE * LIST_ITEM_COUNT
20
    LIST_ITEM_COLOR1 equ dword [scn.btn_face]
21
    LIST_ITEM_COLOR2 equ dword [scn.win_face]
22
    LIST_ITEM_TEXT1  equ dword [scn.btn_text]
23
    LIST_ITEM_TEXT2  equ dword [scn.win_text]
24
    LIST_ITEM_Y      equ LIST_ITEM_SIZE / 2 - 3
25
 
26
    KEYB_SIZE	     equ 140
27
 
28
    sz_cont db "Keyboard ", 0x10
4865 eAndrew 29
    sz_head db "Calc+ [v", VERSION, "]", 0
4943 eAndrew 30
    btn_clr db ""
31
    buttons db "|%^*/-+)(=7894561230"
32
    edb1    edit_box 0, 8, 12, 0, 0, 0, 0, 0, 480, \
4865 eAndrew 33
		     exp, group, ed_always_focus + ed_focus, 0, 0
34
 
35
 imports:
36
    library gui, "box_lib.obj"
37
    import  gui, editbox.draw,	"edit_box",	\
38
		 editbox.key,	"edit_box_key", \
39
		 editbox.mouse, "edit_box_mouse"
40
 
41
 ;===============================
42
 
43
 main:
4939 eAndrew 44
    mov     [ans.buffer], dword "= 0"
45
    mov     [ans.size], 3 * 6 + 9
4865 eAndrew 46
 
47
    mcall   40, 100111b
48
    mcall   48, 3, scn, 192
49
 
4939 eAndrew 50
 
4865 eAndrew 51
    m2m     [edb1.color],	       [scn.gui_face]
52
    m2m     [edb1.shift_color],        [scn.gui_select]
53
    m2m     [edb1.focus_border_color], [scn.gui_face]
4939 eAndrew 54
    m2m     [edb1.text_color],	       [scn.gui_text]
4865 eAndrew 55
 
56
    mcall   68, 11
57
    stdcall dll.Load, imports
58
 
59
 ;----------------------
60
 
61
 update:
4875 eAndrew 62
    mcall   23, 5
4865 eAndrew 63
 
64
    cmp     eax, EV_REDRAW
65
    je	    ev_redraw
66
    cmp     eax, EV_KEY
67
    je	    ev_key
68
    cmp     eax, EV_BUTTON
69
    je	    ev_button
70
    cmp     eax, EV_MOUSE
71
    je	    ev_mouse
72
 
73
    jmp     update
74
 
75
 ;----------------------
76
 
77
 ev_redraw:
4943 eAndrew 78
    mcall   12, 1
79
 
80
 ; WINDOW
81
    mov     edx, [scn.win_face]
4865 eAndrew 82
    or	    edx, 0x34 shl 24
4943 eAndrew 83
    mcall   0, <100, 236 + 100 - 50 - 25>, <100, 66 + LIST_SIZE>, , , sz_head
4865 eAndrew 84
 
4943 eAndrew 85
 ; TOOLBAR
86
    mov     ebx, (275 - 50 - 25 - 50) shl 16 + 64
87
    cmp     [keyb], byte 1
88
    jne     @f
89
    add     ebx, KEYB_SIZE shl 16
90
  @@:
91
    mcall   8, , <-17, 12>, 2 + 1 shl 30
92
    add     ebx, 4 shl 16 - (64 + 14)
93
    mcall   4, , [scn.win_title], sz_cont, 10
4939 eAndrew 94
 
4943 eAndrew 95
 ; CONTENT
4875 eAndrew 96
    call    draw_textbox
4943 eAndrew 97
    call    draw_keyb
98
    call    draw_list
4865 eAndrew 99
 
4943 eAndrew 100
    mcall   12, 2
4865 eAndrew 101
 
102
    jmp     update
103
 
104
 ;----------------------
105
 
106
 ev_key:
107
    mcall   2
108
    cmp     ah, 27
109
    je	    exit
4939 eAndrew 110
    cmp     ah, 13
111
    je	    calc
4865 eAndrew 112
    invoke  editbox.key, edb1
113
    jmp     update
114
 
115
 ;----------------------
116
 
117
 ev_button:
118
    mcall   17
119
 
4943 eAndrew 120
 ; EXIT
4865 eAndrew 121
    cmp     ah, 1
122
    je	    exit
123
 
4943 eAndrew 124
 ; DELETE
125
    cmp     ah, 4
4865 eAndrew 126
    jne     .not_del
127
    cmp     [edb1.pos], 0
128
    je	    update
129
    mov     eax, exp
130
    add     eax, [edb1.pos]
131
    dec     eax
132
    mov     ebx, exp
133
    add     ebx, [edb1.size]
134
    inc     ebx
135
  @@:
136
    cmp     eax, ebx
137
    je	    @f
138
    mov     cl, [eax + 1]
139
    mov     [eax], cl
140
    inc     eax
141
    jmp     @b
142
  @@:
143
    dec     [edb1.pos]
144
    dec     [edb1.size]
145
    m2m     [edb1.shift], [edb1.pos]
4875 eAndrew 146
    jmp     .redraw
4865 eAndrew 147
 .not_del:
148
 
4943 eAndrew 149
 ; SHOW/HIDE KEYBOARD
150
    cmp     ah, 2
151
    jne     .not_keyb
4865 eAndrew 152
 
4943 eAndrew 153
    cmp     [keyb], byte 0
154
    je	    .open
155
 
156
    mcall   67, -1, -1, 286 - 25, -1
157
    mov     [keyb], 0
158
    mov     [sz_cont + 9], byte 0x10
159
    jmp     ev_redraw
160
 
161
 .open:
162
    mcall   67, -1, -1, 286 - 25 + KEYB_SIZE, -1
163
    mov     [keyb], 1
164
    mov     [sz_cont + 9], byte 0x11
165
    jmp     ev_redraw
166
 
167
    jmp     update
168
 .not_keyb:
169
 
170
 ; CALCULATE
171
    cmp     ah, 19
172
    je	    calc
173
 
174
 ; LIST
175
    cmp     ah, 0x60
176
    jl	    .not_list
177
 
178
    sub     ah, 0x60
179
    movzx   ebx, ah
180
    imul    ebx, 512
181
    add     ebx, history
182
    add     ebx, 482
183
    stdcall str_len, ebx
184
 
185
    mov     edx, exp
186
    add     edx, [edb1.size]
187
    add     edx, eax
188
    mov     edi, exp
189
    add     edi, [edb1.pos]
190
  @@:
191
    cmp     edx, edi
192
    je	    @f
193
    mov     esi, edx
194
    sub     esi, eax
195
    push    eax
196
    mov     al, [esi]
197
    mov     [edx], al
198
    pop     eax
199
    dec     edx
200
    jmp     @b
201
  @@:
202
    add     [edb1.size], eax
203
 
204
  @@:
205
    cmp     eax, 0
206
    je	    @f
207
    mov     cl, [ebx]
208
    mov     [edi], cl
209
    inc     edi
210
    inc     ebx
211
    dec     eax
212
    inc     [edb1.pos]
213
    jmp     @b
214
  @@:
215
 
216
    jmp     .redraw
217
 .not_list:
218
 
219
 ; KEYBOARD
220
    cmp     ah, 10
221
    jl	    update
222
    cmp     ah, 50
223
    jg	    update
224
    mov     dh, ah
225
 
226
    mov     ebx, exp
227
    add     ebx, [edb1.size]
228
    mov     ecx, exp
229
    add     ecx, [edb1.pos]
230
    cmp     dh, 30
231
    jl	    @f
232
    add     ebx, 2
233
  @@:
234
    cmp     ebx, ecx
235
    je	    @f
236
    mov     dl, [ebx - 1]
237
    mov     [ebx], dl
238
    dec     ebx
239
    jmp     @b
240
  @@:
241
 
242
    movzx   eax, dh
243
    add     eax, buttons
244
    sub     eax, 10
245
    mov     al, [eax]
246
 
247
    mov     [ebx], al
248
    inc     [edb1.size]
249
    inc     [edb1.pos]
250
    cmp     dh, 30
251
    jl	    @f
252
    add     [edb1.size], 2
253
    add     [edb1.pos], 2
254
  @@:
4875 eAndrew 255
 .redraw:
256
    call    draw_textbox
257
    jmp     update
4865 eAndrew 258
 
259
 ;----------------------
260
 
261
 ev_mouse:
262
    mcall   2
263
 
264
    invoke  editbox.mouse, edb1
265
    jmp     update
266
 
267
 ;----------------------
268
 
269
 exit:
270
    mcall   -1
271
 
272
 ;----------------------
273
 
274
 calc:
275
    stdcall parse
276
    cmp     [error_n], 0
277
    jne     .error
278
 
4939 eAndrew 279
    mov     [ans.buffer], word "= "
280
 
281
    stdcall convert_to_str, eax, ans.buffer + 2
282
    add     eax, 2
4943 eAndrew 283
    mov     edi, eax
4865 eAndrew 284
    imul    eax, 6
285
    add     eax, 9
286
    mov     [ans.size], eax
4943 eAndrew 287
 
288
 ; HISTORY
289
    mov     ecx, LIST_ITEM_COUNT - 1
290
    mov     eax, history
291
    add     eax, (LIST_ITEM_COUNT - 1) * 512
292
  @@:
293
    mov     ebx, eax
294
    sub     ebx, 512
295
    stdcall str_cpy, ebx, eax
296
    add     ebx, 480
297
    add     eax, 480
298
    stdcall str_cpy, ebx, eax
299
    sub     ebx, 480
300
    sub     eax, 480
301
    mov     esi, [ebx + 508]
302
    mov     [eax + 508], esi
303
    sub     eax, 512
304
    loop    @b
305
 
306
    stdcall str_cpy, exp, history
307
    stdcall str_cpy, ans.buffer, history + 480
308
    mov     esi, [ans.size]
309
    mov     dword[history + 508], esi
310
    not     [his_even]
311
 
312
 ; Check length
313
    mov     esi, 37
314
    sub     esi, edi
315
    stdcall str_len, exp
316
    sub     esi, eax
317
    cmp     esi, 0
318
    jg	    .redraw
319
 
320
    mov     ebx, history
321
    add     ebx, eax
322
    add     ebx, esi
323
    mov     [ebx], dword ".."
324
 
4875 eAndrew 325
    jmp     .redraw
4865 eAndrew 326
 
4943 eAndrew 327
 ; ERRORS
328
 
4865 eAndrew 329
 .error:
330
    cmp     [error_n], 1
331
    je	    .err_1
4875 eAndrew 332
    cmp     [error_n], 4
333
    je	    .err_4
334
 
335
    mov     [ans.buffer +  0], dword "Expe"
336
    mov     [ans.buffer +  4], dword "cted"
337
    mov     [ans.buffer +  8], dword " ')'"
338
    mov     [ans.buffer + 12], byte 0
339
    mov     [ans.size], 81
340
 
341
    cmp     [error_n], 2
342
    je	    .redraw
343
    cmp     [error_n], 3
344
    je	    .err_3
4943 eAndrew 345
    cmp     [error_n], 5
346
    je	    .err_5
4865 eAndrew 347
 .err_1:
348
    mov     [ans.buffer +  0], dword "Div."
349
    mov     [ans.buffer +  4], dword " by "
4875 eAndrew 350
    mov     [ans.buffer +  8], byte  "0"
351
    mov     [ans.buffer +  9], byte 0
352
    mov     [ans.size], 63
353
    jmp     .redraw
354
 .err_4:
355
    mov     [ans.buffer +  0], dword "Inpu"
356
    mov     [ans.buffer +  4], dword "t er"
357
    mov     [ans.buffer +  8], dword "rror"
4865 eAndrew 358
    mov     [ans.buffer + 12], byte 0
359
    mov     [ans.size], 81
4875 eAndrew 360
    jmp     .redraw
361
 .err_3:
362
    mov     [ans.buffer + 10], byte "("
363
    jmp     .redraw
4943 eAndrew 364
 .err_5:
365
    mov     [ans.buffer + 10], byte "|"
366
    jmp     .redraw
4865 eAndrew 367
 
4875 eAndrew 368
 .redraw:
369
    call    draw_textbox
4943 eAndrew 370
    call    draw_list
4875 eAndrew 371
    jmp     update
372
 
4865 eAndrew 373
 ;----------------------
374
 
4943 eAndrew 375
 proc draw_button, x, y
376
    mcall   8, <[x], 30>, <[y], 21>, [but_id], [but_c]
4865 eAndrew 377
 
4943 eAndrew 378
    mov     ebx, [x]
379
    mov     esi, [txt_size]
380
    imul    esi, 3
381
    mov     edi, 16
382
    sub     edi, esi
383
    add     ebx, edi
384
    shl     ebx, 16
385
    add     ebx, [y]
386
    add     ebx, 7
387
    mcall   4, , [but_tc], [txt_id], [txt_size]
388
 
389
    mov     eax, [txt_size]
390
    add     [txt_id], eax
391
    inc     dword [but_id]
392
 
393
    ret
394
 endp
395
 
4865 eAndrew 396
 ;----------------------
397
 
4875 eAndrew 398
 proc draw_textbox
4943 eAndrew 399
    mcall   13, <4, 320 - 50 - 25>, <  8,  23>, [scn.gui_frame]
4875 eAndrew 400
    mov     edx, [scn.gui_face]
401
    cmp     [error_n], 0
402
    je	    @f
403
    mov     edx, 0xFFAAAA
404
  @@:
4943 eAndrew 405
    mcall   13, <  5, 318 - 50 - 25>, <  9, 21>
406
    mcall     , <  5, 318 - 50 - 25>, <  9,  1>, [scn.3d_face]
4875 eAndrew 407
    mcall     , <  5,	1>, < 10, 20>
4943 eAndrew 408
    mcall     , <  5, 318 - 50 - 25>, < 31,  1>, [scn.3d_light]
4875 eAndrew 409
 
4943 eAndrew 410
    mov      ebx, 328 - 16 - 50 - 25
4939 eAndrew 411
    sub      ebx, [ans.size]
412
    shl      ebx, 16
413
    add      ebx, 16
414
    mov      ecx, [scn.gui_intext]
415
    or	     ecx, 1 shl 31
416
    mcall    4, , , ans.buffer
4875 eAndrew 417
 
4943 eAndrew 418
    mov      ecx, [scn.gui_text]
419
    mcall     , <310 - 50 - 25, 16>, , btn_clr, 1
420
    add      ebx, 1 shl 16
421
    mcall
422
 
423
    mcall    8, <305 - 50 - 25, 17>, <9, 20>, 0x40000004
424
 
4875 eAndrew 425
    mcall    1,   4,  8, [scn.win_body]
4943 eAndrew 426
    mcall     , 323 - 50 - 25
4875 eAndrew 427
    mcall     ,    , 30, [scn.3d_light]
428
    mcall     ,   4
429
 
4943 eAndrew 430
    mov     ebx, 318 - 16 - 50 - 25
4875 eAndrew 431
    sub     ebx, [ans.size]
432
    cmp     ebx, 24
433
    jg	    @f
434
    mov     ebx, 24
435
  @@:
436
    mov     [edb1.width], ebx
437
    m2m     [edb1.color],	       [scn.gui_face]
438
    m2m     [edb1.focus_border_color], [scn.gui_face]
439
    cmp     [error_n],	0
440
    je	    @f
441
    mov     [edb1.color],	       0xFFAAAA
442
    mov     [edb1.focus_border_color], 0xFFAAAA
443
  @@:
444
    invoke  editbox.draw, edb1
445
 
446
    ret
447
 endp
448
 
449
 ;----------------------
450
 
4943 eAndrew 451
 proc draw_keyb
452
    cmp     [keyb], byte 0
453
    je	    @f
454
 
455
    mov     [txt_size], 1
456
    mov     [but_id], 0x0000000A
457
    mov     [txt_id], buttons
458
 
459
    mov     eax, [scn.win_face]
460
    mov     [but_c], eax
461
    mov     eax, [scn.win_text]
462
    mov     [but_tc], eax
463
    stdcall draw_button,   4 + 278 - 25,  42 - 25 - 8
464
    stdcall draw_button,  37 + 278 - 25,  42 - 25 - 8
465
    stdcall draw_button,  70 + 278 - 25,  42 - 25 - 8
466
    stdcall draw_button, 103 + 278 - 25,  42 - 25 - 8
467
    stdcall draw_button, 103 + 278 - 25,  66 - 25 - 8
468
    stdcall draw_button, 103 + 278 - 25,  90 - 25 - 8
469
    stdcall draw_button, 103 + 278 - 25, 114 - 25 - 8
470
    stdcall draw_button,  70 + 278 - 25, 139 - 25 - 8
471
    stdcall draw_button,  37 + 278 - 25, 139 - 25 - 8
472
 
473
    mov     eax, [scn.btn_inface]
474
    mov     [but_c], eax
475
    mov     eax, [scn.btn_intext]
476
    mov     [but_tc], eax
477
    stdcall draw_button, 103 + 278 - 25, 139 - 25 - 8
478
 
479
    mov     eax, [scn.btn_face]
480
    mov     [but_c], eax
481
    mov     eax, [scn.btn_text]
482
    mov     [but_tc], eax
483
    stdcall draw_button,   4 + 278 - 25,  66 - 25 - 8
484
    stdcall draw_button,  37 + 278 - 25,  66 - 25 - 8
485
    stdcall draw_button,  70 + 278 - 25,  66 - 25 - 8
486
    stdcall draw_button,   4 + 278 - 25,  90 - 25 - 8
487
    stdcall draw_button,  37 + 278 - 25,  90 - 25 - 8
488
    stdcall draw_button,  70 + 278 - 25,  90 - 25 - 8
489
    stdcall draw_button,   4 + 278 - 25, 114 - 25 - 8
490
    stdcall draw_button,  37 + 278 - 25, 114 - 25 - 8
491
    stdcall draw_button,  70 + 278 - 25, 114 - 25 - 8
492
    stdcall draw_button,   4 + 278 - 25, 139 - 25 - 8
493
 
494
  @@:
495
    ret
496
 endp
497
 
498
 ;----------------------
499
 
500
 proc draw_list
501
  ; BACKGROUND
502
    mov     edi, LIST_ITEM_COUNT
503
    mov     eax, 13
504
    mov     ebx, 4 shl 16 + 320 - 50 - 25
505
    mov     ecx, 37 shl 16 + LIST_ITEM_SIZE
506
    mov     edx, LIST_ITEM_COLOR1
507
    cmp     [his_even], byte 0
508
    je	    @f
509
    mov     edx, LIST_ITEM_COLOR2
510
  @@:
511
    mcall
512
    add     ecx, LIST_ITEM_SIZE shl 16
513
    cmp     edx, LIST_ITEM_COLOR1
514
    je	    .set_color_to_2
515
    mov     edx, LIST_ITEM_COLOR1
516
    jmp     .next
517
 .set_color_to_2:
518
    mov     edx, LIST_ITEM_COLOR2
519
 .next:
520
    dec     edi
521
    cmp     edi, 0
522
    jne     @b
523
 
524
  ; BUTTONS
525
    mov     edi, LIST_ITEM_COUNT
526
    mov     eax, 8
527
    mov     ebx, 4 shl 16 + 320 - 50 - 25
528
    mov     ecx, 37 shl 16 + LIST_ITEM_SIZE
529
    mov     edx, 0x40000060
530
  @@:
531
    mcall
532
    add     ecx, LIST_ITEM_SIZE shl 16
533
    inc     edx
534
    dec     edi
535
    cmp     edi, 0
536
    jne     @b
537
 
538
  ; TEXT
539
    mov     edi, LIST_ITEM_COUNT
540
    mov     eax, 4
541
    mov     ebx, 8 shl 16 + 37 + LIST_ITEM_Y
542
    mov     ecx, LIST_ITEM_TEXT1
543
    cmp     [his_even], byte 0
544
    je	    @f
545
    mov     ecx, LIST_ITEM_TEXT2
546
  @@:
547
    or	    ecx, 1 shl 31
548
    mov     edx, history
549
  @@:
550
    mcall
551
 
552
    push    ebx
553
    add     ebx, (320 - 50 - 25) shl 16
554
    mov     esi, [edx + 508]
555
    shl     esi, 16
556
    sub     ebx, esi
557
    add     edx, 480
558
    mcall
559
    pop     ebx
560
 
561
    add     edx, 32
562
    add     ebx, LIST_ITEM_SIZE
563
 
564
    and     ecx, 0xFFFFFF
565
    cmp     ecx, LIST_ITEM_TEXT2
566
    je	    .set_color_to_2_txt
567
    mov     ecx, LIST_ITEM_TEXT2
568
    jmp     .next_txt
569
 .set_color_to_2_txt:
570
    mov     ecx, LIST_ITEM_TEXT1
571
 .next_txt:
572
    or	    ecx, 1 shl 31
573
 
574
    dec     edi
575
    cmp     edi, 0
576
    jne     @b
577
 
578
    ret
579
 endp
580
 
581
 ;----------------------
582
 
583
 proc str_len uses ebx, str
584
    xor     eax, eax
585
    mov     ebx, [str]
586
  @@:
587
    cmp     [ebx], byte 0
588
    je	    @f
589
    inc     eax
590
    inc     ebx
591
    jmp     @b
592
  @@:
593
 
594
    ret
595
 endp
596
 
597
 ;----------------------
598
 
599
 proc str_cpy uses eax ebx ecx, from, to
600
    mov     eax, [from]
601
    mov     ebx, [to]
602
  @@:
603
    cmp     [eax], byte 0
604
    je	    @f
605
    mov     cl, [eax]
606
    mov     [ebx], cl
607
    inc     eax
608
    inc     ebx
609
    jmp     @b
610
  @@:
611
    mov     [ebx], byte 0
612
    ret
613
 endp
614
 
615
 ;----------------------
616
 
4865 eAndrew 617
 dataend:
618
 
619
 ;===============================
620
 
621
	    rb 2048
622
 stacktop:
623
 
4943 eAndrew 624
 exp	    rb 480
4865 eAndrew 625
 exp_pos    rd 1
626
 exp_lvl    rd 1
4943 eAndrew 627
 abs_lvl    rd 1
4865 eAndrew 628
 group	    rd 1
629
 
4943 eAndrew 630
 ans.buffer:rb 480
4865 eAndrew 631
 ans.size   rd 1
632
 error_n    rd 1
633
 
634
 scn	    sys_colors_new
635
 timer	    rd 1
636
 but_id     rd 1
4943 eAndrew 637
 but_c	    rd 1
638
 but_tc     rd 1
4875 eAndrew 639
 txt_id     rd 1
4943 eAndrew 640
 txt_size   rd 1
641
 keyb	    rb 1
4865 eAndrew 642
 
4943 eAndrew 643
 his_even   rb 1
644
 history    rb 512 * LIST_ITEM_COUNT
645
	    rb 512
646
 
4939 eAndrew 647
 memory: