用来在MEOS里抓取屏幕,不过这个版本并不完善。
在这个版本里,程序所用的方法是扫描屏幕上的点然后再写到缓存最后写到文件,这样就会导致速度很慢。
BMP格式文档可以去我的网络硬盘下载http://osdev.ys168.com
;=======================================
; HotCats
; Ver : 0.1
; BLOG: http://hotheart.go.3322.org
;=======================================
bits 32
org 0×0
db ‘MENUET01′ ; 8 byte id
dd 0×01 ; header version
dd START ; start of code
dd I_END ; size of image
dd 0×300000 ; memory for app
dd 0xffff ; esp
dd 0×0 , 0×0 ; I_Param , I_Icon
START: ; start of execution
mov eax,14 ; 获取屏幕分辨率
int 0×40
xor ebx,ebx
mov bx,ax
shr eax,16
inc eax ; X size
inc ebx ; Y size
mov [scr_x],eax
mov [scr_y],ebx
mov [img_w],eax
mov [img_h],ebx
imul ebx
imul eax,3 ; image data size
mov [img_s],eax
add eax,0×36 ; BMP header size
mov [imgf_s],eax
mov [f_s],eax
mov esi,bminfo ; fill the header
mov edi,filestart
mov ecx,0×36/4
cld
repz movsd
call draw_window ; draw the window
still:
mov eax,10 ; wait here for event
int 0×40
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 0×40
jmp still
button: ; button
mov eax,17 ; get id
int 0×40
cmp ah,1 ; button id=1 ?
jne .cmdcap
mov eax,-1 ; close this program
int 0×40
.cmdcap:
cmp ah,cmdcap ; is the Capture button ?
jne .cmdsave
call capall ; capture the whole screen
jmp still
.cmdsave:
cmp ah,cmdsave ; is the save button
jne .end
call savefile ; save the file
jmp still
.end:
jmp still
; *********************************************
; ******* WINDOW DEFINITIONS AND DRAW ********
; *********************************************
draw_window:
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,1 ; 1, start of draw
int 0×40
; DRAW WINDOW
mov eax,0
mov ebx,[scr_x]
sub ebx,win_w+5
imul ebx,65536
add ebx,win_w
mov ecx,[scr_y]
sub ecx,win_h+25
imul ecx,65536
add ecx,win_h
mov edx,0x03ffffff
mov esi,0x40ffffff
mov edi,0x00ffffff
int 0×40
; WINDOW LABEL
mov eax,4 ; function 4 : write text to window
mov ebx,8*65536+8 ; [x start] *65536 + [y start]
mov ecx,0x10ddeeff ; font 1 & color ( 0xF0RRGGBB )
mov edx,labelt ; pointer to text beginning
mov esi,labellen-labelt ; text length
int 0×40
; Button Capture
mov eax,8
mov ebx,10*65536+40
mov ecx,(win_h-10-14)*65536+14
mov edx,cmdcap
mov esi,0xaabbcc
int 0×40
; Button Save
mov eax,8
mov ebx,(10+40+10)*65536+40
mov ecx,(win_h-10-14)*65536+14
mov edx,cmdsave
mov esi,0xaabbcc
int 0×40
; Button Text
mov eax,4 ; function 4 : write text to window
mov ebx,18*65536+(win_h-10-14+4); [x start] *65536 + [y start]
mov ecx,0×00444444 ; font 1 & color ( 0xF0RRGGBB )
mov edx,btext ; pointer to text beginning
mov esi,btexte-btext ; text length
int 0×40
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,2 ; 2, end of draw
int 0×40
ret
mov eax,47 ; display the screen size
mov ebx,4*65536
mov ecx,[scr_x]
mov edx,120*65536+30
mov esi,0×0
int 0×40
mov eax,47
mov ebx,4*65536
mov ecx,[scr_y]
mov edx,120*65536+40
mov esi,0×0
int 0×40
capall:
mov edi,imgarea
mov ecx,[scr_y]
cld
.nextline:
mov ebx,ecx
dec ebx
imul ebx,[scr_x]
push ecx
mov ecx,[scr_x]
.capline:
push edi
push ebx
mov eax,35 ; get pixel
int 0×40
stosd
pop ebx
pop edi
inc ebx
add edi,3
loop .capline
pop ecx
loop .nextline
.end:
ret
savefile: ; save the file
mov eax,58
mov ebx,fileinfo
int 0×40
ret
; DATA AREA
win_w equ 250
win_h equ 50
cmdcap equ 2
cmdsave equ 3
filestart equ 0×20000
imgarea equ filestart+0×36
scr_x dd 0
scr_y dd 0
zoom dd 2
fileinfo:
dd 1 ; 1=WRITE
dd 0×0 ; not used
f_s dd 800*600*3+0×36 ; bytes to write
dd filestart ; source data pointer
dd 0×10000 ; work area for os - 16384 bytes
db ‘/HD/1/TEST.BMP’,0 ; ASCIIZ dir & filename
btext: db ‘ Cat Save ’
btexte:
labelt:
db ‘HotCats 0.1 - HotHeart HotWorks 2005′
labellen:
bminfo:
db ‘BM’ ; 0000-0001 位图标志
imgf_s dd 800*600*3+0×36 ; 0002-0005 文件大小
dd 0×0 ; 0006-0009 保留
db 0×36,0×0,0×0,0×0; 000A-000D 文件头信息块大小,图像描述信息块的大小,图像颜色表的大小,保留(为01)
dd 0×28 ; 000E-0011 图像描述信息块的大小,常为28H。
img_w dd 800 ; 0012-0015 图像宽度。
img_h dd 600 ; 0016-0019 图像高度。
dw 0×1 ; 001A-001B 图像的plane总数(恒为1)。
dw 24 ; 001C-001D 数据压缩方式(数值位0:不压缩;1:8位压缩;2:4位压缩)。
dd 0 ; 001E-0021 记录像素的位数,很重要的数值,图像的颜色数由该值决定。
img_s dd 800*600*3 ; 0022-0025 图像区数据的大小。
dd 0×0 ; 0026-0029 水平每米有多少像素,在设备无关位图(.DIB)中,每字节以00H填写。
dd 0×0 ; 002A-002D 垂直每米有多少像素,在设备无关位图(.DIB)中,每字节以00H填写。
dd 0×0 ; 002E-0031 此图像所用的颜色数,如值为0,表示所有颜色一样重要。
dd 0×0 ; 0032-0035 未用
I_END:
Monthly Archives: July 2005
[MenuetOS] HotRun 0.4 代码分析
Posted by Xu Jiwei
on July 22, 2005
No comments
; Made by HotHeart
; http://www.xujiwei.com
; vipxjw@tom.com
; MENUET RUN 0.4
; 1) 缺省目录 /RD/1/
; 2) 可以更改程序目录,在SETUP里设置硬盘后可以运行
; 硬盘上的程序
; 3) 只能访问根目录
; 4) 自动根据屏幕大小调整窗口位置(限任务栏为文字模式)
use32
org 0×0
db ‘MENUET01′ ; 8 byte id
dd 0×01 ; header version
dd START ; start of code
dd I_END ; size of image
dd 0×100000 ; memory for app
dd 0x7fff0 ; esp
dd 0×0 , 0×0 ; I_Param , I_Icon
START: ; start of execution
; 计算窗口位置
mov eax,14
int 0×40
mov [screenysize],ax
xor eax,eax
mov ax,[screenysize]
sub eax,116+20
imul eax,65536
add eax,116
mov [winy],eax
; 初始化变量
mov [filestr],dword runprogram
mov [dir],dword rundir
mov [ya],dword 53
mov [yb],dword 69
call draw_window
still:
mov eax,23 ; wait here for event
int 0×40
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 0×40
jmp still
button: ; button
mov eax,17 ; get id
int 0×40
cmp ah,4 ; id=4 结束
je close
cmp ah,1
je close
cmp ah,2 ; id=2 输入文件名
je inputfile
cmp ah,5 ; id=5 输入路径
je inputdir
cmp ah,3 ; id=3 运行程序
je runp
jmp still
file_start: dd 16
dd 0,0,0,0×10000
rundir: db ‘/RD/1/’ ; 缺省目录
runprogram: db ‘RUN’,0 ; 缺省程序
times 60 db 0
filestr dd 0×0
dir dd 0×0
addr dd 0×0
ya dd 0×0
yb dd 0×0
;==========================================================
close:
;结束程序
mov eax,-1
int 0×40
inputfile:
;输入文件名
call read_string_file
jmp still
inputdir:
;输入路径
call read_string_dir
jmp still
;==========================================================
runp:
;运行程序
mov eax,58 ;运行
mov ebx,file_start
int 0×40
jmp still
;==========================================================
read_string_file:
;输入文件名
mov edi,[filestr]
mov eax,0
mov ecx,40
cld
rep stosb
call print_file
mov edi,[filestr]
file_fun:
mov eax,23 ; 等待事件
mov ebx,100 ; 延时100毫秒
int 0×40
cmp eax,0 ; eax=0 无事件
je file_fun ; 继续等待事件过程
cmp eax,2 ; eax=2 按钮事件
jne file_read_done ; 跳到读取键盘事件结束
mov eax,2 ; 获取击键 ascii 码
int 0×40
shr eax,8
cmp eax,13 ; 是否为回车键
je file_read_done ; 是则跳到读取结束
cmp eax,8 ; 是否为退格键
jnz file_nobsl ; 不是则跳到 nobsl
cmp edi,[filestr]
jz file_fun
sub edi,1 ; 字符数量减 1
mov [edi],byte 32 ; 退格
call print_file ; 显示字符串
jmp file_fun ; 继续读取
file_nobsl:
cmp al,95 ; 判断是否为小写
jbe file_cok ; 是则跳到 cok
sub al,32 ; 不是则将 ascii 减去 32
file_cok:
mov [edi],al ; 添加到字符串
call print_file ; 显示字符串
add edi,1 ; 已读取字符数量
mov esi,[filestr] ; 读入字符串地址
add esi,30 ; 加上 30
cmp esi,edi ; 比较
jnz file_fun ; 未到最大长度
file_read_done: ; 读取结束
mov [edi],byte 0 ; 结束标志
call print_file ; 显示字符串
jmp still ; 事件循环
;==========================================================
read_string_dir:
mov edi,[dir]
mov eax,0
mov ecx,6
cld
rep stosb
call print_dir
mov edi,[dir]
dir_fun:
mov eax,23 ; 等待事件
mov ebx,100 ; 延时100毫秒
int 0×40
cmp eax,0 ; eax=0 无事件
je dir_fun ; 继续等待事件过程
cmp eax,2 ; eax=2 按钮事件
jne dir_read_done ; 跳到读取键盘事件结束
mov eax,2 ; 获取击键 ascii 码
int 0×40
shr eax,8
cmp eax,13 ; 是否为回车键
je dir_read_done ; 是则跳到读取结束
cmp eax,8 ; 是否为退格键
jnz dir_nobsl ; 不是则跳到 nobsl
cmp edi,[filestr]
jz dir_fun
sub edi,1
mov [edi],byte 32
call print_dir ; 显示字符串
jmp dir_fun ; 继续读取
dir_nobsl:
cmp al,95 ; 判断是否为小写
jbe dir_cok ; 是则跳到 cok
sub al,32 ; 不是则将 ascii 减去 32
dir_cok:
mov [edi],al ; 添加到字符串
call print_dir ; 显示字符串
add edi,1 ; 已读取字符数量
mov esi,[dir] ; 读入字符串地址
add esi,6 ; 加上 6
cmp esi,edi ; 比较
jnz dir_fun ; 未到最大长度
dir_read_done: ; 读取结束
call print_dir ; 显示字符串
jmp still ; 事件循环
;==========================================================
print_dir:
;显示路径
pusha
mov eax,13 ; 画底纹
mov ebx,55*65536+31*6
mov ecx,[ya]
shl ecx,16
mov cx,12
sub ecx,2*65536
mov edx,0xeeeeee
int 0×40
mov eax,4 ; 显示路径
mov edx,[dir]
mov ebx,56*65536
add ebx,[ya]
mov ecx,0×444444
mov esi,6
int 0×40
popa
ret
;==========================================================
print_file:
;显示文件名
pusha
mov eax,13 ; 画底纹
mov ebx,55*65536+31*6
mov ecx,[yb]
shl ecx,16
mov cx,12
sub ecx,2*65536
mov edx,0xeeeeee
int 0×40
mov eax,4 ; 显示文件名
mov edx,[filestr]
mov ebx,56*65536
add ebx,[yb]
mov ecx,0×444444
mov esi,30
int 0×40
popa
ret
;==========================================================
; *********************************************
; ******* WINDOW DEFINITIONS AND DRAW ********
; *********************************************
draw_window:
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,1 ; 1, start of draw
int 0×40
; DRAW WINDOW
mov eax,0 ; function 0 : define and draw window
mov ebx,1*65536+250 ; [x start] *65536 + [x size]
mov ecx,[winy] ; [y start] *65536 + [y size]
mov edx,0x03ffffff ; color of work area RRGGBB,8->color gl
mov esi,0x805080d0 ; color of grab bar RRGGBB,8->color gl
mov edi,0x005080d0 ; color of frames RRGGBB
int 0×40
; WINDOW LABEL
mov eax,4 ; function 4 : write text to window
mov ebx,8*65536+8 ; [x start] *65536 + [y start]
mov ecx,0x10ddeeff ; font 1 & color ( 0xF0RRGGBB )
mov edx,labelt ; pointer to text beginning
mov esi,labellen-labelt; text length
int 0×40
mov eax,8 ; 路径输入 id=5
mov ebx,13*65536+40
mov ecx,50*65536+12
mov edx,5
mov esi,0xaabbcc
int 0×40
mov eax,8 ; 文件名输入 id=2
mov ebx,13*65536+40
mov ecx,66*65536+12
mov edx,2
mov esi,0xaabbcc
int 0×40
mov eax,8 ; 确定 id=3
mov ebx,128*65536+48
mov ecx,84*65536+18
mov edx,3
mov esi,0xaabbcc
int 0×40
mov eax,8 ; 取消 id=4
mov ebx,182*65536+48
mov ecx,84*65536+18
mov edx,4
mov esi,0xaabbcc
int 0×40
mov ebx,13*65536+34 ; 提示信息
mov ecx,0×666666
mov edx,txttxt
mov esi,30
mov eax,4
int 0×40
mov eax,4 ; Path按钮文本
mov ebx,21*65536+53
mov ecx,0×666666
mov edx,txtdir
mov esi,4
int 0×40
mov ebx,21*65536+69 ; File按钮文本
mov ecx,0×444444
mov edx,txtfile
mov esi,4
mov eax,4
int 0×40
mov ebx,140*65536+89 ; 确定取消按钮文本
mov ecx,0×444444
mov edx,txtbutton
mov esi,13
mov eax,4
int 0×40
call print_dir
call print_file
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,2 ; 2, end of draw
int 0×40
ret
; DATA AREA
tcolor dd 0×000000
txttxt db ‘请输入要运行程序的路径和文件名’,‘x’
txtdir db ‘Path’,‘x’
txtfile db ‘File’,‘x’
txtbutton db ‘确定 取消’,‘x’
screenysize dw 0×0
winy dd 0×0
labelt:
db ‘运行’
labellen:
I_END:
[本日志由 xujiwei 于 2005-07-22 06:24 PM 编辑]
Comments (0), Views (2955), Pings (0), Leave a response!
Recent Comments