Subversion Repositories Kolibri OS

Compare Revisions

No changes between revisions

Regard whitespace Rev 30 → Rev 31

/programs/example2/trunk/build_en.bat
0,0 → 1,4
@erase lang.inc
@echo lang fix en >lang.inc
@fasm example2.asm example2
@pause
/programs/example2/trunk/build_ru.bat
0,0 → 1,4
@erase lang.inc
@echo lang fix ru >lang.inc
@fasm example2.asm example2
@pause
/programs/example2/trunk/dialogs1.inc
0,0 → 1,597
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ;
; DIALOGS1.INC ;
; ;
; COMPILE WITH FASM for MENUET ;
; ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 
menus dd 3 ; number of menus
m_x dd 0x5 ; x start
m_y dd 20 ; y start
m_xs dd 290 ; x size
m_ys dd 14 ; y size
g_stack dd 0xf000 ; thread stack - required
 
 
menu:; AB C D E F G
 
db '*D FILE +Save File +Load File +- +Quit '
db '*B EDIT +Copy +Paste '
db '*B HELP +Setup +About.. '
db '@' ; end mark
 
; A : Data type '*' -> New menu , '+' -> menu selection
; B : Number of selections in menu (A+)
; C : Menu header text
; D-G : Menu selection text
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; DATA BELOW IS FOR DIALOGS1.INC INTERNALS
 
menu_action dd '----'
 
window_on db 0
 
g_n dd -1
g_x dd 0x0
g_t dd 0x0
g_1 dd 0x0
g_l dd 0x0
closet db 0
 
table: times 1024 db 0
 
last_mouse dd 0x0
 
mo_x dd 0x0
mo_y dd 0x0
 
 
check_mouse:
 
pusha
 
cmp [window_on],1
je no_open
 
mov eax,37
mov ebx,2
int 0x40
 
cmp [window_on],0
jne openw2
 
cmp eax,0
je no_open
 
openw2:
 
waitformouse:
 
mov eax,23
mov ebx,2
int 0x40
 
cmp eax,0
jne no_open
 
mov eax,37
mov ebx,2
int 0x40
 
cmp eax,0
jne waitformouse
 
 
mov eax,37
mov ebx,1
int 0x40
 
mov esi,eax
 
shr eax,16
xor edx,edx
mov ebx,50
div ebx
mov edx,eax
cmp edx,[g_n]
je no_open
cmp edx,[menus]
jge no_open
mov eax,esi
 
and eax,0xffff
 
mov ebx,[m_y]
cmp eax,ebx
jbe no_open
add ebx,[m_ys]
cmp eax,ebx
jge no_open
 
cmp [window_on],0
je noww
 
mov [closet],1
mov ecx,100
waitm:
mov eax,5
mov ebx,1
int 0x40
dec ecx
jz no_open
cmp [window_on],0
jne waitm
noww:
 
mov eax,edx
jmp cll
 
no_open:
 
mov [last_mouse],esi
 
popa
 
ret
 
cll:
 
mov [window_on],2
 
mov [g_n],eax
mov [g_x],96
mov [g_t],0
mov [g_1],1
 
mov eax,9
mov ebx,table
mov ecx,-1
int 0x40
 
mov eax,[table+34]
mov [mo_x],eax
mov eax,[table+38]
mov [mo_y],eax
 
mov eax,51
mov ebx,1
mov ecx,alert_entry
mov edx,[g_stack]
int 0x40
 
mov [esp+28],dword 0 ; clear button entry
 
mov [menu_action],'MD '
 
check_gr:
 
popa
 
ret
 
 
draw_menu:
 
mov eax,9
mov ebx,table
mov ecx,-1
int 0x40
 
cmp [table+46],dword 30
jb drmr
 
mov eax,13 ; white background
mov ebx,[m_x]
shl ebx,16
add ebx,[m_xs]
inc ebx
mov ecx,[m_y]
shl ecx,16
add ecx,[m_ys]
mov edx,0xf0f8ff
int 0x40
 
mov eax,38 ; egde lines
mov ebx,[m_x]
shl ebx,16
add ebx,[m_x]
add ebx,[m_xs]
mov ecx,[m_y]
shl ecx,16
add ecx,[m_y]
mov edx,0x000000
int 0x40
mov eax,38
mov ecx,[m_y]
add ecx,[m_ys]
shl ecx,16
add ecx,[m_y]
add ecx,[m_ys]
int 0x40
 
mov esi,menu-1
mov edi,[m_x]
mov ebp,1
new_menu:
inc esi
 
cmp [esi],byte '*'
jne drmnl1
push esi
mov eax,4
mov ebx,edi
shl ebx,16
add ebx,[m_y]
add ebx,0x00050004
mov ecx,0x000000
mov edx,esi
add edx,3
mov esi,12
int 0x40 ; draw text
pop esi
add esi,2
add edi,50
inc ebp
 
drmnl1:
cmp [esi],byte '@'
jne new_menu
 
drmr:
 
ret
 
alert_box:
 
; eax : x size - min 200
; ebx : pointer to ASCIIZ - max 128 character text
; ecx : button 1 id ( OK or YES )
; edx : button 2 id or zero ( NO )
 
 
cmp [window_on],0
jne alert_box_return
 
mov [window_on],1
 
cmp eax,100
jg size_ok
mov eax,100
size_ok:
 
mov [g_x],eax
mov [g_t],ebx
mov [g_1],ecx
 
mov ecx,0
new_search:
cmp [ebx],byte 0
je found_len
inc ebx
inc ecx
cmp ecx,128
jbe new_search
found_len:
mov [g_l],ecx
 
mov eax,51
mov ebx,1
mov ecx,alert_entry
mov edx,[g_stack]
int 0x40
 
mov [menu_action],'MA '
 
alert_box_return:
 
ret
 
alert_entry:
 
call alert_draw_window
 
alert_still:
 
mov eax,23 ; wait here for event
mov ebx,1
int 0x40
 
cmp eax,1 ; redraw request ?
je alert_red
cmp eax,2 ; key in buffer ?
je alert_key
cmp eax,3 ; button in buffer ?
je alert_button
 
cmp [closet],0
jne ccc
 
mov eax,9
mov ebx,table
mov ecx,-1
int 0x40
 
cmp ax,[table+4]
je no_close
ccc:
mov [closet],0
mov [g_n],-1
mov [menu_action],'----'
mov [window_on],0
mov eax,-1
int 0x40
no_close:
 
jmp alert_still
 
alert_red: ; redraw
call alert_draw_window
jmp alert_still
 
alert_key: ; key
mov eax,2 ; just read it and ignore
int 0x40
jmp alert_still
 
alert_button: ; button
mov eax,17 ; get id
int 0x40
 
shr eax,8
cmp eax,3
jg no_action1
dec eax
shl eax,2
mov eax,dword [eax+rtext]
mov [menu_action],eax
jmp action_done
no_action1:
sub eax,16
add eax,65
shl eax,8
mov ebx,[g_n]
add ebx,65
add eax,ebx
mov [menu_action],eax
 
action_done:
 
mov [closet],0
mov [g_n],-1
mov [window_on],0
mov eax,-1 ; close this program
int 0x40
 
rtext db 'NO YES OK '
 
jmp alert_still
 
 
; *********************************************
; ******* WINDOW DEFINITIONS AND DRAW ********
; *********************************************
 
 
alert_draw_window:
 
 
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,1 ; 1, start of draw
int 0x40
 
cmp [window_on],2
jne no_win_type_2
 
mov edx,menu-1
mov ecx,[g_n]
add ecx,1
find_menu:
inc edx
cmp [edx],byte '*'
je menu_loop
jmp find_menu
menu_loop:
loop find_menu
movzx ebp,byte [edx+1]
sub ebp,64
push edx
; DRAW WINDOW
mov eax,0 ; function 0 : define and draw window
mov ebx,[g_n]
imul ebx,50
add ebx,[mo_x]
add ebx,[m_x]
shl ebx,16
add ebx,[g_x]
mov ecx,[mo_y]
add ecx,[m_y]
add ecx,[m_ys]
shl ecx,16
mov edx,14
imul edx,ebp
add edx,7
add ecx,edx
mov edx,0x00ffffff ; color of work area RRGGBB,8->color gl
mov esi,0x00ffffff ; color of grab bar RRGGBB,8->color gl
mov edi,0x000000cc ; color of frames RRGGBB
int 0x40
 
pop edx
 
mov ebx,5*65536+7 ; draw info text with function 4
mov ecx,0x10000000
mov esi,12
mov ebp,16
no_d_found:
inc edx
cmp [edx],byte '*'
je d_drawed
cmp [edx],byte '@'
je d_drawed
cmp [edx],byte '+'
jne no_d_found
inc edx
pusha ; draw button
mov eax,8
mov ecx,ebx
mov ebx,[g_x]
add ebx,0x0000fffe
shl ecx,16
add ecx,0xfffc0000+14
mov edx,0x40000000
add edx,ebp
mov esi,0
int 0x40
popa
mov eax,4 ; draw text
int 0x40
inc ebp
add ebx,14
jmp no_d_found
d_drawed:
 
no_win_type_2:
 
 
cmp [window_on],1
jne no_win_1
 
mov eax,14 ; to middle of screen
int 0x40
mov ecx,eax
and ecx,0xffff
shr ecx,1
shr eax,1
mov ebx,[g_x]
shr ebx,1
shl ebx,16
sub eax,ebx
mov ebx,eax
 
mov eax,0 ; function 0 : define and draw window
mov bx,word [g_x]
sub ecx,80
shl ecx,16
mov cx,110 ; [y start] *65536 + [y size]
mov edx,0x02ffffff ; color of work area RRGGBB,8->color gl
mov esi,0x80d05050 ; color of grab bar RRGGBB,8->color gl
mov edi,0x00d05050 ; color of frames RRGGBB
int 0x40
 
 
mov eax,4 ; label
mov ebx,8*65536+8
mov ecx,0x10ddeeff
mov edx,alert_labelt1
mov esi,alert_label1len-alert_labelt1
int 0x40
 
mov eax,4
mov ebx,10*65536+43
mov ecx,0x10000000
mov edx,[g_t]
mov esi,[g_l]
int 0x40
 
cmp [g_1],1
jne gadgets_no_1
 
mov eax,8
mov ebx,[g_x]
sub ebx,100
shr ebx,1
shl ebx,16
add ebx,30*65536+40
mov ecx,75*65536+16
mov edx,3
mov esi,0x446688
int 0x40
 
mov eax,4
mov ebx,[g_x]
sub ebx,100
shr ebx,1
shl ebx,16
add ebx,31*65536+80
mov ecx,0x10ffffff
mov edx,alert_t2
mov esi,alert_t2len-alert_t2
int 0x40
 
gadgets_no_1:
 
cmp [g_1],2
jne gadgets_no_2
 
mov eax,8
mov ebx,[g_x]
sub ebx,100
shr ebx,1
shl ebx,16
add ebx,0*65536+40
mov ecx,75*65536+16
mov edx,1
mov esi,0x446688
int 0x40
 
mov eax,8
mov ebx,[g_x]
sub ebx,100
shr ebx,1
shl ebx,16
add ebx,57*65536+40
mov ecx,75*65536+16
mov edx,2
mov esi,0x446688
int 0x40
 
mov eax,4
mov ebx,[g_x]
sub ebx,100
shr ebx,1
shl ebx,16
add ebx,1*65536+80
mov ecx,0x10ffffff
mov edx,alert_t1
mov esi,alert_t1len-alert_t1
int 0x40
 
gadgets_no_2:
 
no_win_1:
 
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,2 ; 2, end of draw
int 0x40
 
ret
 
 
; DATA AREA
 
 
alert_t1:
db ' No Yes'
alert_t1len:
 
 
alert_t2:
db ' OK'
alert_t2len:
 
 
alert_labelt1:
db 'ALERT'
alert_label1len:
 
 
 
 
 
 
 
 
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/programs/example2/trunk/example2.asm
0,0 → 1,201
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; MENU / DIALOG EXAMPLE
;
; Compile with FASM for Menuet
;
 
use32
 
org 0x0
 
db 'MENUET01' ; 8 byte id
dd 0x01 ; header version
dd START ; start of code
dd I_END ; size of image
dd 0x10000 ; memory for app
dd 0x10000 ; esp
dd 0x0 , 0x0 ; I_Param , I_Icon
 
include 'lang.inc'
include 'macros.inc'
include 'dialogs1.inc'
 
menu_history dd 0x0
 
START: ; start of execution
 
call draw_window_main
 
still: ; wait here for event
 
mov eax,23
mov ebx,2
int 0x40
 
cmp eax,1 ; process events
je red
cmp eax,2
je key
cmp eax,3
je button
 
call check_mouse ; DIALOG CHECK
 
mov eax,[menu_action]
cmp eax,[menu_history]
je nodisplay
 
mov [menu_history],eax
 
mov eax,13
mov ebx,220*65536+6*4
mov ecx,70*65536+8
mov edx,0xffffff
int 0x40
 
mov eax,4 ; show menu selections
mov ebx,220*65536+70
mov ecx,0x000000
mov edx,menu_action
mov esi,4
int 0x40
 
nodisplay:
 
cmp word [menu_action],word 'AD' ; user requests close
jne no_menu_close
mov eax,-1
int 0x40
no_menu_close:
 
jmp still
 
red: ; redraw
call draw_window_main
jmp still
 
key:
mov eax,2 ; key in buffer
int 0x40
jmp still
 
button: ; button in buffer
mov eax,17
int 0x40
 
cmp ah,1 ; close application
jne noclose
mov eax,-1
int 0x40
noclose:
 
cmp ah,2
jne no_alert_box ; ALERT BOX
mov eax,170 ; window width
mov ebx,alert_text ; asciiz string
mov ecx,1 ; OK button
call alert_box ; function call
jmp still
no_alert_box:
 
cmp ah,3
jne no_choose_box ; CHOOSE BOX
mov eax,220 ; window width
mov ebx,choose_text ; asciiz string
mov ecx,2 ; YES/NO buttons
call alert_box ; function call
jmp still
no_choose_box:
 
 
jmp still
 
 
 
 
; *********************************************
; ******* WINDOW DEFINITIONS AND DRAW ********
; *********************************************
 
draw_window_main:
 
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,1 ; 1, start of draw
int 0x40
 
mov eax,0 ; open window
mov ebx,100*65536+300
mov ecx,100*65536+120
mov edx,0x02ffffff
mov esi,0x805080d0
mov edi,0x005080d0
int 0x40
 
call draw_menu ; DRAW MENU
 
mov eax,4 ; window label
mov ebx,8*65536+8
mov ecx,0x10ddeeff
mov edx,labelt
mov esi,labellen-labelt
int 0x40
 
mov eax,8 ; close button
mov ebx,(300-17)*65536+10
mov ecx,5*65536+10
mov edx,1
mov esi,0x4466bb
int 0x40
 
mov eax,8 ; button : OPEN ALERT BOX
mov ebx,25*65536+150
mov ecx,61*65536+14
mov edx,2
mov esi,0x4466aa
int 0x40
 
mov eax,8 ; button : OPEN CHOOSE BOX
mov ebx,25*65536+150
mov ecx,81*65536+14
mov edx,3
mov esi,0x4466aa
int 0x40
 
mov ebx,20*65536+55 ; draw info text with function 4
mov ecx,0xffffff
mov edx,text
mov esi,40
newline:
mov eax,4
int 0x40
add ebx,10
add edx,40
cmp [edx],byte 'x'
jne newline
 
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,2 ; 2, end of draw
int 0x40
 
ret
 
 
; DATA AREA
 
text:
db ' '
db ' OPEN ALERT BOX '
db ' '
db ' OPEN CHOOSE BOX '
 
db 'x <- END MARKER, DONT DELETE '
 
labelt:
db 'EXAMPLE APPLICATION'
labellen:
 
alert_text db ' File not found !',0
choose_text db ' Save file before exit ? ',0
 
I_END:
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/programs/example2/trunk/macros.inc
0,0 → 1,267
; new application structure
macro meos_app_start
{
use32
org 0x0
 
db 'MENUET01'
dd 0x01
dd __start
dd __end
dd __memory
dd __stack
 
if used __params & ~defined __params
dd __params
else
dd 0x0
end if
 
dd 0x0
}
MEOS_APP_START fix meos_app_start
 
macro code
{
__start:
}
CODE fix code
 
macro data
{
__data:
}
DATA fix data
 
macro udata
{
if used __params & ~defined __params
__params:
db 0
__end:
rb 255
else
__end:
end if
__udata:
}
UDATA fix udata
 
macro meos_app_end
{
align 32
rb 2048
__stack:
__memory:
}
MEOS_APP_END fix meos_app_end
 
 
; macro for defining multiline text data
struc mstr [sstring]
{
forward
local ssize
virtual at 0
db sstring
ssize = $
end virtual
dd ssize
db sstring
common
dd -1
}
 
 
; strings
macro sz name,[data] { ; from MFAR [mike.dld]
common
if used name
label name
end if
forward
if used name
db data
end if
common
if used name
.size = $-name
end if
}
 
macro lsz name,[lng,data] { ; from MFAR [mike.dld]
common
if used name
label name
end if
forward
if (used name)&(lang eq lng)
db data
end if
common
if used name
.size = $-name
end if
}
 
 
 
; easy system call macro
macro mpack dest, hsrc, lsrc
{
if (hsrc eqtype 0) & (lsrc eqtype 0)
mov dest, (hsrc) shl 16 + lsrc
else
if (hsrc eqtype 0) & (~lsrc eqtype 0)
mov dest, (hsrc) shl 16
add dest, lsrc
else
mov dest, hsrc
shl dest, 16
add dest, lsrc
end if
end if
}
 
macro __mov reg,a,b { ; mike.dld
if (~a eq)&(~b eq)
mpack reg,a,b
else if (~a eq)&(b eq)
mov reg,a
end if
}
 
macro mcall a,b,c,d,e,f { ; mike.dld
__mov eax,a
__mov ebx,b
__mov ecx,c
__mov edx,d
__mov esi,e
__mov edi,f
int 0x40
}
 
 
 
 
 
 
 
; optimize the code for size
__regs fix <eax,ebx,ecx,edx,esi,edi,ebp,esp>
 
macro add arg1,arg2
{
if (arg2 eqtype 0)
if (arg2) = 1
inc arg1
else
add arg1,arg2
end if
else
add arg1,arg2
end if
}
 
macro sub arg1,arg2
{
if (arg2 eqtype 0)
if (arg2) = 1
dec arg1
else
sub arg1,arg2
end if
else
sub arg1,arg2
end if
}
 
macro mov arg1,arg2
{
if (arg1 in __regs) & (arg2 eqtype 0)
if (arg2) = 0
xor arg1,arg1
else if (arg2) = 1
xor arg1,arg1
inc arg1
else if (arg2) = -1
or arg1,-1
else if (arg2) > -128 & (arg2) < 128
push arg2
pop arg1
else
mov arg1,arg2
end if
else
mov arg1,arg2
end if
}
 
 
macro struct name
{
virtual at 0
name name
sizeof.#name = $ - name
end virtual
}
 
; structures used in MeOS
struc process_information
{
.cpu_usage dd ? ; +0
.window_stack_position dw ? ; +4
.window_stack_value dw ? ; +6
.not_used1 dw ? ; +8
.process_name rb 12 ; +10
.memory_start dd ? ; +22
.used_memory dd ? ; +26
.PID dd ? ; +30
.x_start dd ? ; +34
.y_start dd ? ; +38
.x_size dd ? ; +42
.y_size dd ? ; +46
.slot_state dw ? ; +50
rb (1024-52)
}
struct process_information
 
struc system_colors
{
.frame dd ?
.grab dd ?
.grab_button dd ?
.grab_button_text dd ?
.grab_text dd ?
.work dd ?
.work_button dd ?
.work_button_text dd ?
.work_text dd ?
.work_graph dd ?
}
struct system_colors
 
 
; constants
 
; events
EV_IDLE = 0
EV_TIMER = 0
EV_REDRAW = 1
EV_KEY = 2
EV_BUTTON = 3
EV_EXIT = 4
EV_BACKGROUND = 5
EV_MOUSE = 6
EV_IPC = 7
EV_STACK = 8
 
; event mask bits for function 40
EVM_REDRAW = 1b
EVM_KEY = 10b
EVM_BUTTON = 100b
EVM_EXIT = 1000b
EVM_BACKGROUND = 10000b
EVM_MOUSE = 100000b
EVM_IPC = 1000000b
EVM_STACK = 10000000b
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property