?? menuetos.htm
字號:
;
;
; When using system colours, the window colours are read from the
; SYSTEM COLOURS TABLE
;
draw_window:
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,1 ; 1, start of draw
int 0x40
call get_system_colours ; fetches system colours from os
; DRAW WINDOW
mov eax,0 ; function 0 : define and draw window
mov ebx,100*65536+window_size_X ; [x start] *65536 + [x size]
mov ecx,100*65536+window_size_Y ; [y start] *65536 + [y size]
mov edx,[w_work] ; color of work area 0xRRGGBB
or edx,0x02000000 ; 0x02000000 = window type II
; 0x03000000 = skinned window
mov esi,[w_grab] ; color of grab bar 0xRRGGBB
or esi,0x80000000 ; 0x80000000 = colour glide
mov edi,[w_frames] ; color of frames 0xRRGGBB
int 0x40
; WINDOW LABEL
mov eax,4 ; function 4 : write text to window
mov ebx,8*65536+8 ; [x start] *65536 + [y start]
mov ecx,[w_grab_text] ; color of text RRGGBB
mov edx,labelt ; pointer to text beginning
mov esi,labellen-labelt ; text length
int 0x40
mov ebx,25*65536+35 ; draw info text with function 4
mov ecx,[w_work_text]
mov edx,text
mov esi,40
newline: ; text from the DATA AREA
mov eax,4
int 0x40
add ebx,10
add edx,40
cmp [edx],byte 'x'
jne newline
; CLOSE BUTTON
mov eax,8 ; function 8 : define and draw button
mov ebx,window_size_X
sub ebx,19
shl ebx,16
mov bx,12 ; ebx = [x start] *65536 + [x size]
mov ecx,5*65536+12 ; [y start] *65536 + [y size]
mov edx,1 ; button id
mov esi,[w_grab_button] ; button color RRGGBB
int 0x40
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,2 ; 2, end of draw
int 0x40
ret
; *********************************************
; ************* DATA AREA *****************
; *********************************************
;
; Data can be freely mixed with code to any parts of the image.
; Only the header information is required at the beginning of the image.
text: db 'THIS PROGRAM USES UNIFORM SYSTEM COLOURS'
db 'RETURNED TO A TABLE '
db 'x <- END MARKER, DONT DELETE '
labelt: db 'EXAMPLE APPLICATION'
labellen:
I_END:
1d) Freeform window
===================
In this example we concentrate on shaping the window from rectangle
to any form desired by the programmer. New fuction in this example
is shape_window.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ;
; FREEFORM EXAMPLE APPLICATION ;
; ;
; Compile with FASM for Menuet ;
; ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; The header
use32 ; compiler to use 32 bit instructions
org 0x0 ; the base address of code, always 0x0
db 'MENUET01' ; 8 byte id for application
dd 0x01 ; header version
dd START ; start of execution
dd I_END ; size of image
dd 0x100000 ; Amount of memory to use
; You can access memory from 0x0 to
; value defined here. The relocation
; of the code is done with selectors
; set by the OS.
dd 0x7fff0 ; stack position in memory area
dd 0x0 ; Parameter passing area
; if set to other than zero, poss
; parameters are transferred at start
dd 0x0 ; Reserved for icon
START: ; start of execution
call shape_window ; function for shaping
call draw_window ; at first, draw the window
still:
mov eax,10 ; wait here for event
int 0x40
cmp eax,1 ; redraw request ?
je red
cmp eax,2 ; key in buffer ?
je key
cmp eax,3 ; button in buffer ?
je button
jmp still
red: ; redraw
call draw_window
jmp still
key: ; key
mov eax,2 ; just read it and ignore
int 0x40
jmp still
button: ; button
mov eax,17 ; get id
int 0x40
cmp ah,1 ; button id=1 ?
jne noclose
mov eax,-1 ; close this program
int 0x40
noclose:
jmp still
shape_window:
pusha
mov eax,50 ; give the shape reference area
mov ebx,0
mov ecx,shape_reference
int 0x40
mov eax,50 ; give the shape scale 32 x 32 -> 128 x 128
mov ebx,1 ; you dont have to give this, scale is 1:1 by default
mov ecx,2 ; scale is set to 2^ecx
int 0x40
popa
ret
shape_reference: ; 32 x 32 ( window_size_X + 1 ) * ( window_size_Y + 1 )
db 0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,1,1,1,1,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0,0,0,0
db 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0
db 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0
db 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0
db 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0
db 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0
db 0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0
db 0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0
db 0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0
db 0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0
db 0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0
db 0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0
db 0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0
; *********************************************
; ******* WINDOW DEFINITIONS AND DRAW ********
; *********************************************
draw_window:
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,1 ; 1, start of draw
int 0x40
; DRAW WINDOW
mov eax,0 ; function 0 : define and draw window
mov ebx,100*65536 ; [x start] *65536 + [x size]
mov ecx,100*65536 ; [y start] *65536 + [y size]
mov bx,word [x_size]
mov cx,word [y_size]
mov edx,0x00cccc00 ; color of work area RRGGBB,8->color glide
mov esi,0x00cccc00 ; color of grab bar RRGGBB,8->color glide
mov edi,0x00cccc00 ; color of frames RRGGBB
int 0x40
; CLOSE BUTTON
mov eax,8 ; function 8 : define and draw button
mov ebx,78*65536+12 ; [x start] *65536 + [x size]
mov ecx,20*65536+12 ; [y start] *65536 + [y size]
mov edx,1 ; button id
mov esi,0x5599cc ; button color RRGGBB
int 0x40
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,2 ; 2, end of draw
int 0x40
ret
; DATA
x_size dd 127
y_size dd 127
I_END:
1e) Threads
===========
MenuetOS assembly threading has some great advantages over higher
level languages. If you keep all the variables in registers, you can
start as meny threads as desired with the _same_ code, since
no memory is affected and needs no saving. The registers are saved
to Task Switch Segments by MenuetOS. All you have to do is to
set a new stack.
Threads have no difference with the main process and use the same
memory area as the process which starts it. They can have their own
independent windows etc. In the closing of application, all threads
have to be terminated with the default (eax = -1) system call.
New function in this example is create_thread.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ;
; THREAD 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 0x100000 ; memory for app
dd 0x80000 ; esp
dd 0x0 , 0x0 ; I_Param , I_Icon
START: ; start of execution
call draw_window ; at first, draw the window
event_wait:
mov eax,10 ; wait here for event
int 0x40
cmp eax,1 ; redraw request ?
je red
cmp eax,2 ; key in buffer ?
je key
cmp eax,3 ; button in buffer ?
je button
jmp event_wait
red: ; redraw
call draw_window
jmp event_wait
key: ; key
mov eax,2 ; just read it and ignore
int 0x40
jmp event_wait
button: ; button
mov eax,17 ; get id
int 0x40
cmp ah,1 ; button id=1 ?
jne noclose
mov eax,-1 ; close this program (thread)
int 0x40
noclose:
cmp ah,2 ; call create_thread
jne no_thread
call create_thread
jmp event_wait
no_thread:
jmp event_wait
; THREAD CREATION
;
; All we have to do is to give the thread entry address in ecx and
; a new stack postition in edx with function eax=51, ebx=1
create_thread:
cmp [thread_stack],0xf0000
jge no_new_thread
add [thread_stack],0x1000
mov eax,51 ; thread_create system call
mov ebx,1
mov ecx,START
mov edx,[thread_stack]
int 0x40
no_new_thread:
ret
thread_stack dd 0x80000
; *********************************************
; ******* WINDOW DEFINITIONS AND DRAW ********
; *********************************************
draw_window:
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,1 ; 1, start of draw
int 0x40
; DRAW WINDOW
mov eax,0 ; function 0 : define and draw window
mov ebx,10*65536+300 ; [x start] *65536 + [x size]
mov ecx,10*65536+140 ; [y start] *65536 + [y size]
mov esi,[thread_stack]
sub esi,0x80000
shr esi,11
shl esi,16
add ebx,esi
add ecx,esi
mov edx,0x02ffffff ; color of work area RRGGBB,8->color glide
mov esi,0x808899ff ; color of grab bar RRGGBB,8->color glide
mov edi,0x008899ff ; color of frames RRGGBB
int 0x40
; WINDOW LABEL
mov eax,4 ; function 4 : write text to window
mov ebx,8*65536+8 ; [x start] *65536 + [y start]
mov ecx,0x00ddeeff ; color of text RRGGBB
mov edx,labelt ; pointer to text beginning
mov esi,labellen-labelt ; text length
int 0x40
; CLOSE BUTTON
mov eax,8 ; function 8 : define and draw button
mov ebx,(300-19)*65536+12 ; [x start] *65536 + [x size]
mov ecx,5*65536+12 ; [y start] *65536 + [y size]
mov edx,1 ; button id
mov esi,0x6677cc ; button color RRGGBB
int 0x40
mov eax,8 ; NEW THREAD BUTTON
mov ebx,25*65536+128
mov ecx,88*65536+20
mov edx,2
mov esi,0x6677cc
int 0x40
mov ebx,25*65536+35 ; draw info text with function 4
mov ecx,0x224466
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 'THIS EXAMPLE CREATES THREADS BY RUNNING '
db 'THE SAME CODE MULTIPLE TIMES. ALL WE '
db 'NEED IS A NEW STACK FOR EACH THREAD. '
db 'ALL THREADS SHARE THE SAME MEMORY. '
db ' '
db ' '
db ' CREATE NEW THREAD '
db 'x <- END MARKER, DONT DELETE '
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -