Calc+ v0.2β: add "^" operator, bugfixes, optimization.

git-svn-id: svn://kolibrios.org@4875 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
eAndrew 2014-04-22 16:45:27 +00:00
parent 846fce0120
commit 1922dd81c6
2 changed files with 312 additions and 137 deletions

View File

@ -1,5 +1,4 @@
VERSION equ "0.1Å" VERSION equ "0.2Å"
use32 use32
org 0 org 0
db 'MENUET01' db 'MENUET01'
@ -10,11 +9,12 @@
include "../../dll.inc" include "../../dll.inc"
include "../../develop/libraries/box_lib/trunk/box_lib.mac" include "../../develop/libraries/box_lib/trunk/box_lib.mac"
include "parser.inc" include "parser.inc"
;include "../../debug.inc"
;=============================== ;===============================
sz_head db "Calc+ [v", VERSION, "]", 0 sz_head db "Calc+ [v", VERSION, "]", 0
buttons db "1234567890.%-+*/()" buttons db "123456789()%^-+/*0"
edb1 edit_box 184, 8, 12, 0, 0, 0, 0, 0, 500, \ edb1 edit_box 184, 8, 12, 0, 0, 0, 0, 0, 500, \
exp, group, ed_always_focus + ed_focus, 0, 0 exp, group, ed_always_focus + ed_focus, 0, 0
@ -44,7 +44,7 @@
;---------------------- ;----------------------
update: update:
mcall 23, 50 mcall 23, 5
cmp eax, EV_REDRAW cmp eax, EV_REDRAW
je ev_redraw je ev_redraw
@ -68,87 +68,42 @@
or edx, 0x34 shl 24 or edx, 0x34 shl 24
mcall 0, <100, 236>, <100, 164>, , , sz_head mcall 0, <100, 236>, <100, 164>, , , sz_head
mcall 13, < 4, 220>, < 8, 23>, [scn.gui_frame] call draw_textbox
mov edx, [scn.gui_face]
cmp [error_n], 0
je @f
mov edx, 0xFFAAAA
@@:
mcall 13, < 5, 218>, < 9, 21>
mcall , < 5, 218>, < 9, 1>, [scn.3d_face]
mcall , < 5, 1>, < 10, 20>
mcall , < 5, 218>, < 31, 1>, [scn.3d_light]
mov ebx, 224
sub ebx, [ans.size]
shl ebx, 16
inc ebx
mcall , , < 9, 21>, [scn.gui_frame]
add ebx, [ans.size]
add ebx, 1 shl 16
sub ebx, 3
mcall , , , [scn.3d_light]
add ebx, 1 shl 16
add ecx, 1 shl 16
dec ebx
dec ecx
mcall , , , [scn.win_face]
shr ecx, 16
mov bx, cx
add ebx, 3 shl 16 + 6
mov ecx, [scn.win_text]
or ecx, 1b shl 31
mcall 4, , , ans.buffer
mcall 1, 4, 8, [scn.win_body]
mcall , 223
mcall , , 30, [scn.3d_light]
mcall , 4
mov ebx, 214
sub ebx, [ans.size]
cmp ebx, 24
jg @f
mov ebx, 24
@@:
mov [edb1.width], ebx
m2m [edb1.color], [scn.gui_face]
m2m [edb1.focus_border_color], [scn.gui_face]
cmp [error_n], 0
je @f
mov [edb1.color], 0xFFAAAA
mov [edb1.focus_border_color], 0xFFAAAA
@@:
invoke editbox.draw, edb1
mov [but_id], 0x4000000A mov [but_id], 0x4000000A
stdcall draw_button, 4, 38, 42, buttons + 00, 15 mov [txt_id], buttons
stdcall draw_button, 46, 38, 42, buttons + 01, 15 mov [txt_x], 16
stdcall draw_button, 88, 38, 42, buttons + 02, 15 mov [but_w], 38
stdcall draw_button, 4, 38, 66, buttons + 03, 15 stdcall draw_button, 4, 42
stdcall draw_button, 46, 38, 66, buttons + 04, 15 stdcall draw_button, 46, 42
stdcall draw_button, 88, 38, 66, buttons + 05, 15 stdcall draw_button, 88, 42
stdcall draw_button, 4, 38, 90, buttons + 06, 15 stdcall draw_button, 4, 66
stdcall draw_button, 46, 38, 90, buttons + 07, 15 stdcall draw_button, 46, 66
stdcall draw_button, 88, 38, 90, buttons + 08, 15 stdcall draw_button, 88, 66
stdcall draw_button, 4, 80, 114, buttons + 09, 35 stdcall draw_button, 4, 90
stdcall draw_button, 88, 38, 114, buttons + 10, 15 stdcall draw_button, 46, 90
stdcall draw_button, 88, 90
stdcall draw_button, 88, 114
stdcall draw_button, 144, 38, 42, buttons + 11, 15 stdcall draw_button, 144, 42
stdcall draw_button, 186, 38, 42, buttons + 12, 15 stdcall draw_button, 186, 42
stdcall draw_button, 144, 38, 66, buttons + 13, 15 stdcall draw_button, 144, 66
stdcall draw_button, 186, 38, 66, buttons + 14, 15 stdcall draw_button, 186, 66
stdcall draw_button, 144, 38, 90, buttons + 15, 15 stdcall draw_button, 144, 90
stdcall draw_button, 186, 38, 90, buttons + 16, 15 stdcall draw_button, 186, 90
stdcall draw_button, 144, 38, 114, buttons + 17, 15 stdcall draw_button, 144, 114
stdcall draw_button, 186, 38, 114, buttons + 18, 15 stdcall draw_button, 186, 114
mov [txt_x], 37
mov [but_w], 80
stdcall draw_button, 4, 114
jmp update jmp update
;---------------------- ;----------------------
ev_key: ev_key:
mov [timer], 1 mov [timer], 10
mcall 2 mcall 2
cmp ah, 27 cmp ah, 27
@ -159,16 +114,43 @@
;---------------------- ;----------------------
ev_button: ev_button:
mov [timer], 1 mov [timer], 10
mcall 17 mcall 17
cmp ah, 1 cmp ah, 1
je exit je exit
cmp ah, 22 cmp ah, 2
jne .not_copy
.copy:
mov eax, exp
mov ebx, ans.buffer
mov ecx, 0
@@:
mov dl, [ebx]
mov [eax], dl
inc eax
inc ebx
inc ecx
cmp [eax - 1], byte 0
jne @b
dec ecx
mov [edb1.size], ecx
m2m [edb1.pos], [edb1.size]
jmp .redraw
.not_copy:
cmp ah, 19
jne .not_del jne .not_del
.del:
cmp [edb1.pos], 0 cmp [edb1.pos], 0
je update je update
mov eax, exp mov eax, exp
@ -188,7 +170,7 @@
dec [edb1.pos] dec [edb1.pos]
dec [edb1.size] dec [edb1.size]
m2m [edb1.shift], [edb1.pos] m2m [edb1.shift], [edb1.pos]
jmp ev_redraw jmp .redraw
.not_del: .not_del:
@ -219,7 +201,9 @@
inc [edb1.size] inc [edb1.size]
inc [edb1.pos] inc [edb1.pos]
jmp ev_redraw .redraw:
call draw_textbox
jmp update
;---------------------- ;----------------------
@ -245,24 +229,50 @@
imul eax, 6 imul eax, 6
add eax, 9 add eax, 9
mov [ans.size], eax mov [ans.size], eax
jmp ev_redraw jmp .redraw
.error: .error:
cmp [error_n], 1 cmp [error_n], 1
je .err_1 je .err_1
jmp ev_redraw cmp [error_n], 4
je .err_4
mov [ans.buffer + 0], dword "Expe"
mov [ans.buffer + 4], dword "cted"
mov [ans.buffer + 8], dword " ')'"
mov [ans.buffer + 12], byte 0
mov [ans.size], 81
cmp [error_n], 2
je .redraw
cmp [error_n], 3
je .err_3
.err_1: .err_1:
mov [ans.buffer + 0], dword "Div." mov [ans.buffer + 0], dword "Div."
mov [ans.buffer + 4], dword " by " mov [ans.buffer + 4], dword " by "
mov [ans.buffer + 8], dword "zero" mov [ans.buffer + 8], byte "0"
mov [ans.buffer + 9], byte 0
mov [ans.size], 63
jmp .redraw
.err_4:
mov [ans.buffer + 0], dword "Inpu"
mov [ans.buffer + 4], dword "t er"
mov [ans.buffer + 8], dword "rror"
mov [ans.buffer + 12], byte 0 mov [ans.buffer + 12], byte 0
mov [ans.size], 81 mov [ans.size], 81
jmp ev_redraw jmp .redraw
.err_3:
mov [ans.buffer + 10], byte "("
jmp .redraw
.redraw:
call draw_textbox
jmp update
;---------------------- ;----------------------
proc draw_button, x, w, y, txt, txtx proc draw_button, x, y
mcall 13, <[x], [w]>, <[y], 20>, [scn.gui_frame] mcall 13, <[x], [but_w]>, <[y], 20>, [scn.gui_frame]
add ebx, 1 shl 16 add ebx, 1 shl 16
add ecx, 1 shl 16 add ecx, 1 shl 16
@ -282,7 +292,7 @@
mcall 1, [x], [y], [scn.win_body] mcall 1, [x], [y], [scn.win_body]
add ebx, [w] add ebx, [but_w]
dec ebx dec ebx
mcall mcall
@ -290,14 +300,14 @@
dec ecx dec ecx
mcall mcall
sub ebx, [w] sub ebx, [but_w]
inc ebx inc ebx
mcall mcall
mov ebx, [x] mov ebx, [x]
inc ebx inc ebx
shl ebx, 16 shl ebx, 16
add ebx, [w] add ebx, [but_w]
sub ebx, 3 sub ebx, 3
mov ecx, [y] mov ecx, [y]
inc ecx inc ecx
@ -306,14 +316,79 @@
sub ecx, 3 sub ecx, 3
mov edx, [but_id] mov edx, [but_id]
mcall 8 mcall 8
inc dword[but_id]
mov ebx, [x] mov ebx, [x]
add ebx, [txtx] add ebx, [txt_x]
shl ebx, 16 shl ebx, 16
add ebx, [y] add ebx, [y]
add ebx, 7 add ebx, 7
mcall 4, , [scn.win_text], [txt], 1 mcall 4, , [scn.win_text], [txt_id], 1
inc dword [txt_id]
inc dword [but_id]
ret
endp
;----------------------
proc draw_textbox
mcall 13, < 4, 220>, < 8, 23>, [scn.gui_frame]
mov edx, [scn.gui_face]
cmp [error_n], 0
je @f
mov edx, 0xFFAAAA
@@:
mcall 13, < 5, 218>, < 9, 21>
mcall , < 5, 218>, < 9, 1>, [scn.3d_face]
mcall , < 5, 1>, < 10, 20>
mcall , < 5, 218>, < 31, 1>, [scn.3d_light]
mov ebx, 224
sub ebx, [ans.size]
shl ebx, 16
inc ebx
mcall , , < 9, 21>, [scn.gui_frame]
add ebx, [ans.size]
add ebx, 1 shl 16
sub ebx, 3
mcall , , , [scn.3d_light]
cmp [error_n], 0
jne .btn_not
mcall 8, , , 0x40000002
.btn_not:
add ebx, 1 shl 16
add ecx, 1 shl 16
dec ebx
dec ecx
mcall 13, , , [scn.win_face]
shr ecx, 16
mov bx, cx
add ebx, 3 shl 16 + 6
mov ecx, [scn.win_text]
or ecx, 1b shl 31
mcall 4, , , ans.buffer
mcall 1, 4, 8, [scn.win_body]
mcall , 223
mcall , , 30, [scn.3d_light]
mcall , 4
mov ebx, 214
sub ebx, [ans.size]
cmp ebx, 24
jg @f
mov ebx, 24
@@:
mov [edb1.width], ebx
m2m [edb1.color], [scn.gui_face]
m2m [edb1.focus_border_color], [scn.gui_face]
cmp [error_n], 0
je @f
mov [edb1.color], 0xFFAAAA
mov [edb1.focus_border_color], 0xFFAAAA
@@:
invoke editbox.draw, edb1
ret ret
endp endp
@ -339,5 +414,8 @@
scn sys_colors_new scn sys_colors_new
timer rd 1 timer rd 1
but_id rd 1 but_id rd 1
but_w rd 1
txt_id rd 1
txt_x rd 1
memory: memory:

View File

@ -12,48 +12,25 @@
ret ret
} }
proc convert_to_str uses ebx ecx edx esi edi, _num, _str
mov eax, [_num]
mov esi, [_str]
mov edi, 0
mov ecx, eax
and ecx, 1 shl 31
cmp ecx, 0
je @f
mov [esi], byte "-"
inc esi
inc edi
not eax
inc eax
@@:
mov ebx, 10
xor ecx, ecx
@@:
xor edx, edx
div ebx
push edx
inc ecx
inc edi
cmp eax, 0
jne @b
@@:
pop eax
add al, "0"
mov [esi], al
inc esi
loop @b
mov [esi], byte 0
mov eax, edi
ret
endp
; --------------------------- ; ---------------------------
proc parse proc parse
mov [exp_pos], 0 mov [exp_pos], 0
stdcall skip_spaces
mov ebx, exp
add ebx, [exp_pos]
cmp [ebx], byte 0
je .null_exp
mov [exp_lvl], 0
mov [error_n], 0 mov [error_n], 0
stdcall parse_lvl0 stdcall parse_lvl0
ret ret
.null_exp:
mov eax, 0
ret
endp endp
; --------------------------- ; ---------------------------
@ -68,7 +45,7 @@
cmp [ebx], byte 0 cmp [ebx], byte 0
je .end je .end
cmp [ebx], byte ")" cmp [ebx], byte ")"
je .end je .brk_end
inc [exp_pos] inc [exp_pos]
cmp [ebx], byte "+" cmp [ebx], byte "+"
jne .not_add jne .not_add
@ -79,15 +56,23 @@
jmp @b jmp @b
.not_add: .not_add:
cmp [ebx], byte "-" cmp [ebx], byte "-"
jne @b jne .unexp_char
mov ecx, eax mov ecx, eax
stdcall parse_lvl1 stdcall parse_lvl1
test_err test_err
sub ecx, eax sub ecx, eax
mov eax, ecx mov eax, ecx
jmp @b jmp @b
.brk_end:
cmp [exp_lvl], 0
jne @f
set_err 3
@@:
dec [exp_lvl]
.end: .end:
ret ret
.unexp_char:
set_err 4
endp endp
; --------------------------- ; ---------------------------
@ -101,9 +86,9 @@
add ebx, [exp_pos] add ebx, [exp_pos]
cmp [ebx], byte 0 cmp [ebx], byte 0
je .end je .end
inc [exp_pos]
cmp [ebx], byte "*" cmp [ebx], byte "*"
jne .not_mul jne .not_mul
inc [exp_pos]
mov ecx, eax mov ecx, eax
stdcall parse_lvl2 stdcall parse_lvl2
test_err test_err
@ -117,6 +102,7 @@
je .div_or_mod je .div_or_mod
jmp .end jmp .end
.div_or_mod: .div_or_mod:
inc [exp_pos]
mov ecx, eax mov ecx, eax
stdcall parse_lvl2 stdcall parse_lvl2
test_err test_err
@ -134,13 +120,35 @@
mov eax, edx mov eax, edx
jmp @b jmp @b
.end: .end:
dec [exp_pos]
ret ret
endp endp
; --------------------------- ; ---------------------------
proc parse_lvl2 uses ebx proc parse_lvl2 uses ebx ecx edx
test_err
stdcall parse_lvl3
test_err
@@:
mov ebx, exp
add ebx, [exp_pos]
cmp [ebx], byte 0
je .end
cmp [ebx], byte "^"
jne .end
inc [exp_pos]
mov ecx, eax
stdcall parse_lvl2
test_err
stdcall c_power
jmp @b
.end:
ret
endp
; ---------------------------
proc parse_lvl3 uses ebx
test_err test_err
stdcall skip_spaces stdcall skip_spaces
mov ebx, exp mov ebx, exp
@ -149,36 +157,73 @@
jl @f jl @f
cmp [ebx], byte 57 cmp [ebx], byte 57
jg @f jg @f
stdcall parse_lvl3 stdcall parse_lvl4
jmp .end jmp .end
@@: @@:
inc [exp_pos] inc [exp_pos]
cmp [ebx], byte "(" cmp [ebx], byte "("
jne @f jne @f
inc [exp_lvl]
stdcall parse_lvl0 stdcall parse_lvl0
test_err test_err
mov ebx, exp
add ebx, [exp_pos]
cmp [ebx], byte ")"
je .brk_ok
set_err 2
.brk_ok:
inc [exp_pos] inc [exp_pos]
jmp .end jmp .end
@@: @@:
cmp [ebx], byte "+" cmp [ebx], byte "+"
jne @f jne @f
stdcall parse_lvl2 stdcall parse_lvl3
test_err test_err
jmp .end jmp .end
@@: @@:
cmp [ebx], byte "-" cmp [ebx], byte "-"
jne .end jne .unexp_char
stdcall parse_lvl2 stdcall parse_lvl3
test_err test_err
neg eax neg eax
.end: .end:
stdcall skip_spaces stdcall skip_spaces
ret ret
.unexp_char:
set_err 4
endp endp
; --------------------------- ; ---------------------------
proc parse_lvl3 uses ebx ecx proc parse_lvl4 uses ebx ecx
stdcall parse_lvl5
@@:
mov ebx, exp
add ebx, [exp_pos]
cmp [ebx], byte 0
je .end
cmp [ebx], byte "^"
jne .end
inc [exp_pos]
mov ecx, eax
mov ebx, exp
add ebx, [exp_pos]
cmp [ebx], byte 48
jl .unexp_char
cmp [ebx], byte 57
jg .unexp_char
stdcall parse_lvl4
stdcall c_power
jmp @b
.end:
ret
.unexp_char:
set_err 4
endp
; ---------------------------
proc parse_lvl5 uses ebx ecx
sub eax, eax sub eax, eax
sub ecx, ecx sub ecx, ecx
mov ebx, exp mov ebx, exp
@ -215,3 +260,55 @@
@@: @@:
ret ret
endp endp
; ---------------------------
proc c_power uses ebx
mov ebx, eax
mov eax, 1
@@:
cmp ebx, 0
je @f
imul eax, ecx
dec ebx
jmp @b
@@:
ret
endp
; ---------------------------
proc convert_to_str uses ebx ecx edx esi edi, _num, _str
mov eax, [_num]
mov esi, [_str]
mov edi, 0
mov ecx, eax
and ecx, 1 shl 31
cmp ecx, 0
je @f
mov [esi], byte "-"
inc esi
inc edi
not eax
inc eax
@@:
mov ebx, 10
xor ecx, ecx
@@:
xor edx, edx
div ebx
push edx
inc ecx
inc edi
cmp eax, 0
jne @b
@@:
pop eax
add al, "0"
mov [esi], al
inc esi
loop @b
mov [esi], byte 0
mov eax, edi
ret
endp