试验了两天,已经在1024*768 32位真彩色模式下实现这个功能,以下是小驱动的源码:
;填充显示缓冲区,显示一幅bmp图片的小驱动 作者:盛玉增 (www.aogosoft.com 电子管)
;2010年10月20日 WinXP masm32v8 kmdkit1.8下调试通过。
;@echo off
;goto make
.386
.model flat, stdcall
option casemap:none
include \masm32\include\w2k\ntstatus.inc
include \masm32\include\w2k\ntddk.inc
include \masm32\include\w2k\ntoskrnl.inc
includelib \masm32\lib\w2k\ntoskrnl.lib
.code
DriverEntry proc pDriverObject:PDRIVER_OBJECT, pusRegistryPath:PUNICODE_STRING
pushad
invoke MmMapIoSpace,0d0000000h,0,4*1024*1024,MmNonCached ;物理地址映射为线性地址,长度4M,返回值在eax
cmp eax,0 ;eax==0,失败
jz ta_1
cli
mov edi,eax ;eax是显示缓冲区的首地址
mov ecx,320 ;共320行,每行240个像素
mov esi,offset bmp_2 ;bmp文件中的像素数据开始地址
ta_2: push ecx
mov ecx,960 ;每像素4个字节,240*4=960,图片一行送显示缓冲区
rep movsb
add edi,1024*4-960 ;1024*768显示模式
;320*240的bmp图片,每行占用960个字节
pop ecx
loop ta_2
sti
ta_1:
popad
mov eax, STATUS_DEVICE_CONFIGURATION_ERROR
ret
DriverEntry endp;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
.data
; 以下为bmp格式的320*240的bmp图片文件数据 长度307254 bytes
bmp_1 db 66,77,54,176,4,0,0,0,0,0,54,0,0,0,40,0 ;bmp文件头占用54个字节
db 0,0,240,0,0,0,64,1,0,0,1,0,32,0,0,0
db 0,0,0,176,4,0,0,0,0,0,0,0,0,0,0,0
db 0,0,0,0,0,0
bmp_2 db 229,211,248,0,131,125,242,0,74,103 ;bmp_2为像素数据开始位置,每个像素占用4个字节,顺序为蓝、绿、红、保留,保留字节都为0
db 248,0,45,88,251,0,40,66,255,0,48,71,247,0,63,103
db 251,0,67,127,251,0,69,106,252,0,42,68,252,0,31,57
db 255,0,41,76,250,0,44,86,247,0,41,74,254,0,32,57
db 255,0,30,53,253,0,21,55,245,0,39,78,255,0,51,102
db 249,0,43,100,233,0,28,74,239,0,27,63,255,0,24,60
;......数据省略