?? menuetos.htm
字號:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0044)http://www.menuetos.org/www/eng/menuetos.htm -->
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content="MSHTML 6.00.2600.0" name=GENERATOR></HEAD>
<BODY>
<TABLE cellSpacing=0 cellPadding=0 width=700 align=center border=0>
<TBODY>
<TR>
<TD width=700><PRE>
Programming with MenuetOS
=========================
1) Application programming
1a) Structure of an application
1b) Assembly example
1c) Using uniform system colours
1d) Free form window
1e) Threads
1f) Real-Time data
1) APPLICATION PROGRAMMING FOR MENUET-OS
========================================
1a) Structure of an application
===============================
Programming for Menuet is easy as you first learn the basic
structure of an application. At this point I assume you have some
experience in assembly language.
The MenuetOS API (Application Programming Interface) is a easy-to-learn
set of functions with practically no hierarchial accesses.
The operating of an application is based on events.
The application is notified by the OS with the event type and the application
acts accordingly. There are three event types an application is expected to
handle by default: window redraw, keypress and buttonpress.
Flow chart and structure of an application with default events:
;;;;;;;;;;;;;;;;;;;;;;;;;
; ;
; HEADER DATA ;
; ;
;;;;;;::;;;;;;;;;;;;;;;;;
START:
call draw_window
;;;;;;;;;;;;;;;;::;;;;;;;
; ;
; WAIT UNTIL EVENT ; <-----------------------------------------------I
; ; I
;;;;;::;;;;;;;;;;;;;;;;;; I
I I
;;;;;;;::;;;;;;;;;;;;;;;; I
; ; redraw -> call draw_window -> I
; READ EVENT TYPE ; -> key -> read keypress -> process -> I
; ; button -> read buttonpress -> process -> I
;;;;;::;;;;;;;;;;;;;;;;;;
draw_window:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ;
; DRAW STATIC WINDOW PARTS ;
; ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ret
DATA AREA:
;;;;;;;;;;;;;;;;;;;;;;;;
; ;
; STATIC DATA ;
; ;
;;;;;;;;;;;;;;;;;;;;;;;;
(end of image)
1b) Assembly example
====================
A heavily commented assembly language realization of the above structure (1a).
Menuet system calls are executed with the 'int 0x40' command with function
number in register eax and other registers are used if necessary.
Details of all currently available system calls are at the section (1g)
System functions.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ;
; 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 code is done with selectors
; set by the OS.
dd 0x7fff0 ; stack position in memory area
dd 0x0 ; Parameter passing value
; if set to other than zero, possible
; parameters are transferred at start.
dd 0x0 ; Reserved for icon
; The code area
START: ; start of execution
call draw_window ; draw the window
; After the window is drawn, it's practical to have the main loop.
; Events are distributed from here.
event_wait:
mov eax,10 ; function 10 : wait until event
int 0x40
; event type is returned in eax
cmp eax,1 ; Event redraw request ?
je red ; Expl.: there has been activity on screen and
; parts of the applications has to be redrawn.
cmp eax,2 ; Event key in buffer ?
je key ; Expl.: User has pressed a key while the
; app is at the top of the window stack.
cmp eax,3 ; Event button in buffer ?
je button ; Expl.: User has pressed one of the
; applications buttons.
jmp event_wait
; The next section reads the event and processes data.
red: ; Redraw event handler
call draw_window ; We call the window_draw function and
jmp event_wait ; jump back to event_wait
key: ; Keypress event handler
mov eax,2 ; The key is returned in ah. The key must be
int 0x40 ; read and cleared from the system queue.
jmp event_wait ; Just read the key, ignore it and jump to
; event_wait.
button: ; Buttonpress event handler
mov eax,17 ; The button number defined in window_draw
int 0x40 ; is returned to ah.
cmp ah,1 ; button id=1 ?
jne noclose
mov eax,-1 ; Function -1 : close this program
int 0x40
noclose:
jmp event_wait ; This is for ignored events, useful
; at development
; *********************************************
; ****** WINDOW DEFINITIONS AND DRAW ********
; *********************************************
;
; The static window parts are drawn in this function. The window canvas can
; be accessed later from any parts of this code (thread) for displaying
; processes or recorded data, for example.
;
; The static parts *must* be placed within the fn 12 , ebx = 1 and ebx = 2.
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+300 ; [x start] *65536 + [x size]
mov ecx,100*65536+120 ; [y start] *65536 + [y size]
mov edx,0x02ffffff ; color of work area RRGGBB
; 0x02000000 = window type 2
mov esi,0x808899ff ; color of grab bar RRGGBB
; 0x80000000 = 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 ebx,25*65536+35 ; draw info text with function 4
mov ecx,0x224466
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
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 IS AN EXAMPLE PROGRAM YOU COULD '
db 'USE, A:\EXAMPLE.ASM CODE IS COMMENTED '
db 'AND CLEAR. SYSTEM FUNCTIONS ARE IN FILE '
db 'SYSFUNCS.TXT AND COMMANDS IN CMD.TXT '
db 'x <- END MARKER, DONT DELETE '
labelt: db 'EXAMPLE APPLICATION'
labellen:
I_END:
; The area after I_END is free for use as the application memory,
; just avoid the stack.
;
; Application memory structure, according to the used header, 1 Mb.
;
; 0x00000 - Start of compiled image
; I_END - End of compiled image
;
; + Free for use in the application
;
; 0x7ff00 - Start of stack area
; 0x7fff0 - End of stack area - defined in the header
;
; + Free for use in the application
;
; 0xFFFFF - End of freely useable memory - defined in the header
;
; All of the the areas can be modified within the application with a
; direct reference.
; For example, mov [0x80000],byte 1 moves a byte above the stack area.
Menuet's application structure is not specifically reserved for
asm programming, the header can be produced with practically
any other language. However, the overall application programming
design is intended for easy 32 bit asm programming. The GUI is
extremely easy to handle with especially asm language.
1c) Using uniform system colours
================================
While previous example concentrated on creating a basic application,
in this section more attention is paid on the outlook of the window.
You can use uniform desktop colors defined by a colour setup application.
New fuction in this example is get_system_colours.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ;
; UNIFORM SYSTEM COLOURS EXAMPLE ;
; ;
; 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 relocatn of
; of the code is done with selectors
; set by the OS.
dd 0x7fff0 ; stack position in memory area
dd 0x0 ; Parameter passing value
; if set to other than zero, possible
; parameters are transferred at start.
dd 0x0 ; Reserved for icon
; The code area
window_size_X equ 300
window_size_Y equ 150
START: ; start of execution
call draw_window ; draw the window
; After the window is drawn, it's practical to have the main loop.
; Events are distributed from here.
event_wait:
mov eax,10 ; function 10 : wait until event
int 0x40
; event type is returned in eax
cmp eax,1 ; Event redraw request ?
je red ; Expl.: there has been activity on screen and
; parts of the applications has to be redrawn.
cmp eax,2 ; Event key in buffer ?
je key ; Expl.: User has pressed a key while the
; app is at the top of the window stack.
cmp eax,3 ; Event button in buffer ?
je button ; Expl.: User has pressed one of the
; applications buttons.
jmp event_wait
; The next section reads the event and processes data.
red: ; Redraw event handler
call draw_window ; We call the window_draw function and
jmp event_wait ; jump back to event_wait
key: ; Keypress event handler
mov eax,2 ; The key is returned in ah. The key must be
int 0x40 ; read and cleared from the system queue.
jmp event_wait ; Just read the key, ignore it and jump to
; event_wait.
button: ; Buttonpress event handler
mov eax,17 ; The button number defined in window_draw
int 0x40 ; is returned to ah.
cmp ah,1 ; button id=1 ?
jne noclose
mov eax,-1 ; Function -1 : close this program
int 0x40
noclose:
jmp event_wait ; This is for ignored events, useful
; at development
get_system_colours:
pusha
mov eax,48 ; fn 48 system colours
mov ebx,3 ; subfn 3 : get
mov ecx,app_colours ; pointer to return area
mov edx,10*4 ; number of bytes to return
int 0x40
popa
ret
app_colours: ; SYSTEM COLOURS TABLE
w_frames dd 0x0 ; - frames
w_grab dd 0x0 ; - GRAB AREA
w_grab_button dd 0x0 ; grab area button
w_grab_button_text dd 0x0 ; grab area button text
w_grab_text dd 0x0 ; grab area text
w_work dd 0x0 ; - WORK AREA
w_work_button dd 0x0 ; work area button
w_work_button_text dd 0x0 ; work area button text
w_work_text dd 0x0 ; work area text
w_work_graph dd 0x0 ; work area graphics
; *********************************************
; ****** WINDOW DEFINITIONS AND DRAW ********
; *********************************************
;
; The static window parts are drawn in this function. The window canvas can
; be accessed later from any parts of this code (thread) for displaying
; processed or recorded data, for example.
;
; The static parts *must* be placed within the fn 12 , ebx = 1 and ebx = 2.
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -