📄 mpanel.asm
字号:
;
; PANEL APPLICATION
;
; 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 ; could be much less
dd 0x100000 ; memory for app
dd 0x7fff0 ; esp
dd 0x0 , 0x0 ; I_Param , I_Icon
; Constants
OSWORKAREA equ I_END ; Place for OS work area, 16KB
BPP equ 3 ; Number of bytes per pixel
BMPHEADER equ 18*3 ; Header part of bmp file
PANEL_DEPTH equ 42 ; Number of rows in panel image
PANEL_MAX_WIDTH equ 1280 ; Maximum width of Panel image
; This is also a temporary work area for building the free-form
; window data
PANEL_AREA equ OSWORKAREA + 0x4000
; memory location of 'constructed' image prior to display
PANEL_IMAGE equ PANEL_AREA + ( PANEL_DEPTH * PANEL_MAX_WIDTH )
; memory location of main bmp image read in from ram disk
BMP_1 equ PANEL_IMAGE + ( BPP * PANEL_DEPTH * PANEL_MAX_WIDTH )
BMP_1_WIDTH equ 140 ; The width of the original image
BMP_1_DEPTH equ PANEL_DEPTH ; The height of the panel image
BMP_SCL equ 1024 + BMP_1 + BMPHEADER + (BPP * BMP_1_DEPTH \
* BMP_1_WIDTH)
BMP_SCL_WIDTH equ 14 ; The width of the original image
BMP_SCL_DEPTH equ 26 ; The height of the panel image
BMP_SCC equ 1024 + BMP_SCL + BMPHEADER + (BPP * BMP_SCL_DEPTH \
* (BMP_SCL_WIDTH+3))
BMP_SCC_WIDTH equ 6 ; The width of the original image
BMP_SCC_DEPTH equ 26 ; The height of the panel image
BMP_SCR equ 1024 + BMP_SCC + BMPHEADER + (BPP * BMP_SCC_DEPTH \
* (BMP_SCC_WIDTH+3))
BMP_SCR_WIDTH equ 18 ; The width of the original image
BMP_SCR_DEPTH equ 26 ; The height of the panel image
BMP_BC equ 1024 + BMP_SCR + BMPHEADER + (BPP * BMP_SCR_DEPTH \
* (BMP_SCR_WIDTH+3))
BMP_BC_WIDTH equ 47 ; The width of the original image
BMP_BC_DEPTH equ 34 ; The height of the panel image
; Reserve 13 bytes for each entry - the 12 bytes of the appname plus 1 null
RUNNINGAPPS equ 1024 + BMP_BC + BMPHEADER + (BPP * BMP_BC_DEPTH \
* (BMP_BC_WIDTH+3))
CLOCK_X equ 155
CLOCK_Y equ 6
CLOCK_COLOUR equ 0x00000000
APP_X equ 217
APP_Y equ 6
APP_INC equ 32
APP_COLOUR equ 0x00808080
;***************************************************************************
; Function
; START
;
; Description
; Entry point of the application
;
;***************************************************************************
START:
; Get the screen resolution
mov eax,14
int 0x40
movzx ebx, ax
mov [scrSizeY], ebx
shr eax, 16
mov [scrSizeX], eax
; Read the Panel bitmaps
call readBitmaps
; Calculate how many processes are running
call numRunningApps
; Read the name strings of running apps
call readAppNames
; Create the panel image
call buildDefaultPanel
; Create the free-form window definition, and apply it
call setWindowForm
call draw_window
still:
mov eax,23 ; wait here for event
mov ebx, 10
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
; Just redraw the clock, and check for a change in running apps
call numRunningApps
cmp ebx, 0
je showclock
; Redraw the panel bar.
call readAppNames
call buildDefaultPanel
call draw_window
call showTime
jmp still
showclock:
mov eax, 3 ; Get time
int 0x40
and eax, 0x00FF0000
cmp [lastsecs], eax
je still
call showTime
jmp still
red:
; Mouse button pressed?
mov eax, 37
mov ebx, 2
int 0x40
cmp eax, 0
je nomenu
; get mouse x/y
mov eax, 37
mov ebx, 1
int 0x40
mov ebx, eax
shr ebx, 16 ; ebx = x
; Is the mouse in the window?
cmp ebx, BMP_1_WIDTH - 10
jae nomenu
; Yes, so convert the y position to an index
; into the menu
mov ecx, eax
and ecx, 0xFFFF ; ecx = y
cmp ecx, BMP_1_DEPTH - 5
jae nomenu
mov eax, 0
jmp dored
nomenu:
mov eax, -1
dored:
push eax
call draw_window
pop eax
cmp eax, 0
je dobutton
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 still
dobutton:
; Mouse button released?
red001:
mov eax, 37
mov ebx, 2
int 0x40
cmp eax, 0
jne red001
call closeMenus
; Did we actually close any?
cmp eax, 0
jne still ; We closed some, so dont open
; Run the menu application
mov eax,58
mov ebx,startfile
int 0x40
jmp still
;***************************************************************************
; Function
; numRunningApps
;
; Description
; Reads the number of running apps. If it is different to last time,
; ebx == 1, else ebx == 0
;
;***************************************************************************
numRunningApps:
mov eax, 9
mov ebx, OSWORKAREA ; Temporary work area
mov ecx, -1
int 0x40
mov ecx, eax
mov eax, 0
nra000:
push ecx
push eax
mov ebx, OSWORKAREA
mov eax, 9
int 0x40
pop eax
pop ecx
mov esi, OSWORKAREA + 10 ; App name string
cmp [esi], dword ' '
je nra001
inc eax
nra001:
loop nra000
xor ebx, ebx
cmp eax, [numApps]
je @f
mov [numApps], eax
inc ebx
@@:
ret
;***************************************************************************
; Function
; readAppNames
;
; Description
; Reads the names of the first 20 valid applications that are running
; These will be displayed on the Panel bar.
; Some running apps are ignored, because they are system apps;
; eg mpanel, mmenu, icon
;
;***************************************************************************
readAppNames:
mov ebx, [numApps]
xor edx, edx ; edx counts app entries
mov ecx, edx
mov edi, RUNNINGAPPS
inc ecx
ran001:
pusha
mov ebx, OSWORKAREA
mov eax, 9
int 0x40
popa
; if app name is not acceptable, skip
; save ecx, edx, edi
mov esi, OSWORKAREA + 10 ; App name string
cmp [esi], dword 'ICON'
je ran002
cmp [esi], dword 'PANE'
je ran002
cmp [esi], dword 'MPAN'
je ran002
cmp [esi], dword 'SELE'
je ran002
cmp [esi], dword 'MENU'
je ran002
cmp [esi], dword 'MMEN'
je ran002
cmp [esi], dword 'OS/I'
je ran002
cmp [esi], dword ' '
jne ran003
inc ebx
jmp ran002
ran003:
push ecx
mov ecx, 12
mov esi, OSWORKAREA + 10 ; App name string
cld
rep movsb
mov [edi], byte 0
inc edi
pop ecx
inc edx
cmp edx, 20
je ranexit
ran002:
inc ecx
cmp ecx, ebx
; jne ran001
jna ran001
ranexit:
mov [numDisplayApps], edx
ret
;***************************************************************************
; Function
; closeMenus
;
; Description
; searches the process table for MMENU apps, and closes them
; returns eax = 1 if any closed, otehrwise eax = 0
;
;***************************************************************************
closeMenus:
mov eax, 9
mov ebx, OSWORKAREA ; Temporary work area
mov ecx, -1
int 0x40
mov ecx, eax ; Get number of apps
xor eax, eax ; Return value; 0 = no menus closed
cm001:
pusha
mov eax, 9
mov ebx, OSWORKAREA ; Temporary work area
int 0x40 ; get process info
popa
; Is this 'me'? If it is, dont kill me yet!
cmp [OSWORKAREA + 30], ebx
je cm002
; Is this a MMENU app to kill?
push ecx
mov edi, appname
mov esi, OSWORKAREA + 10
mov ecx, 12
repe cmpsb
cmp ecx, 0
pop ecx
jne cm002
; Close the app
push eax
mov ebx, 2
mov eax, 18
int 0x40
pop eax
mov eax, 1 ; Indicate that we closed a menu
cm002:
loop cm001
ret
;***************************************************************************
; Function
; buildDefaultPanel
;
; Description
; Constructs the panel picture by copying in small bits of the image
; from pre-loaded bmp files
;
;***************************************************************************
buildDefaultPanel:
mov ecx, BMP_1_DEPTH
mov esi, BMP_1 + BMPHEADER
mov edi, PANEL_IMAGE
cld
fill1:
push ecx
; Copy the image..
mov ecx, BMP_1_WIDTH * BPP
rep movsb
; Now fill to right hand side of screen
; This copied not just the image, but the
; 'shape' of the image ( the black part )
mov ecx, [scrSizeX]
sub ecx, BMP_1_WIDTH
mov eax, [edi-3]
fill2:
mov [edi], eax
add edi, 3
loop fill2
pop ecx
loop fill1
mov edi, PANEL_IMAGE + (BMP_1_WIDTH * BPP)
; Display the slot for the time
mov ecx, 5
call drawSlot
; Calculate where the last slot can be displayed
mov ebx, [scrSizeX] ; The length of each screen line, in bytes
imul ebx, BPP
mov edx, PANEL_IMAGE
add edx, ebx ; The top righthand pos
sub edx, (BMP_BC_WIDTH+BMP_SCL_WIDTH+(8*BMP_SCC_WIDTH)+ \
BMP_SCR_WIDTH) * BPP
mov ecx, 0
mov esi, RUNNINGAPPS
bdp000:
cmp ecx, [numDisplayApps]
je bdp001 ; Displaying all apps, so finish
push ecx
push edx
push esi
call strLen
call drawSlot
pop esi
pop edx
pop ecx
inc ecx
add esi, 13
cmp edi, edx
jbe bdp000 ; Run out of space to display
bdp001:
mov [displayedApps], ecx
; Now the closing part of the big curve
mov ecx, BMP_BC_DEPTH
mov esi, BMP_BC + BMPHEADER
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -