[原创] MicroWindows学习笔记之对底层设备的管理
MicroWindows对每个相关的设备提供了一个数据结构,并有一个全局的上下文设备对象,通过它来屏蔽与底层之间的联系,上层代码通过调用这个全局变量提供的方法来打开、关闭、读取这些设备。如果想将MicroWindows移植到其他的环境中,需要配置这个全局变量,并且实现相关的方法。MicroWindows对底层的屏蔽层(针对各个系统的驱动)放在\src\drivers中。

键盘
数据结构KBDDEVICE
/* Interface to Keyboard Device Driver*/
typedef struct _kbddevice {
int (*Open)(struct _kbddevice *pkd);
void (*Close)(void);
void (*GetModifierInfo)(MWKEYMOD *modifiers, MWKEYMOD *curmodifiers);
int (*Read)(MWKEY *buf,MWKEYMOD *modifiers,MWSCANCODE *scancode);
int (*Poll)(void); /* not required if have select()*/
} KBDDEVICE;
所在文件:\include\Device.h
全局变量
KBDDEVICE kbddev = {
NUL_Open,
NUL_Close,
NUL_GetModifierInfo,
NUL_Read,
NUL_Poll
};
所在文件:drivers\Kdb_null.c
默认都是空实现。
鼠标
数据结构MOUSEDEVICE
/* Interface to Mouse Device Driver*/
typedef struct _mousedevice {
int (*Open)(struct _mousedevice *);
void (*Close)(void);
int (*GetButtonInfo)(void);
void (*GetDefaultAccel)(int *pscale,int *pthresh);
int (*Read)(MWCOORD *dx,MWCOORD *dy,MWCOORD *dz,int *bp);
int (*Poll)(void); /* not required if have select()*/
int flags; /* raw, normal, transform flags*/
} MOUSEDEVICE;
所在文件:\include\Device.h
全局变量
MOUSEDEVICE mousedev = {
NUL_Open,
NUL_Close,
NUL_GetButtonInfo,
NUL_GetDefaultAccel,
NUL_Read,
NUL_Poll
};
所在文件:drivers\Mou_null.c
屏幕
数据结构SCREENDEVICE
/*
* Interface to Screen Device Driver
* This structure is also allocated for memory (offscreen) drawing and blitting.
*/
typedef struct _mwscreendevice {
MWCOORD xres; /* X screen res (real) */
MWCOORD yres; /* Y screen res (real) */
MWCOORD xvirtres; /* X drawing res (will be flipped in portrait mode) */
MWCOORD yvirtres; /* Y drawing res (will be flipped in portrait mode) */
int planes; /* # planes*/
int bpp; /* # bpp*/
int linelen; /* line length in bytes for bpp 1,2,4,8*/
/* line length in pixels for bpp 16, 24, 32*/
int size; /* size of memory allocated*/
long ncolors; /* # screen colors*/
int pixtype; /* format of pixel value*/
int flags; /* device flags*/
void * addr; /* address of memory allocated (memdc or fb)*/
PSD (*Open)(PSD psd);
void (*Close)(PSD psd);
void (*GetScreenInfo)(PSD psd,PMWSCREENINFO psi);
void (*SetPalette)(PSD psd,int first,int count,MWPALENTRY *pal);
void (*DrawPixel)(PSD psd,MWCOORD x,MWCOORD y,MWPIXELVAL c);
MWPIXELVAL (*ReadPixel)(PSD psd,MWCOORD x,MWCOORD y);
void (*DrawHorzLine)(PSD psd, MWCOORD x1, MWCOORD x2, MWCOORD y, MWPIXELVAL c);
void (*DrawVertLine)(PSD psd, MWCOORD x, MWCOORD y1, MWCOORD y2, MWPIXELVAL c);
void (*FillRect)(PSD psd, MWCOORD x1, MWCOORD y1, MWCOORD x2, MWCOORD y2, MWPIXELVAL c);
PMWCOREFONT builtin_fonts;
/* *void (*DrawText)(PSD psd,MWCOORD x,MWCOORD y,const MWUCHAR *str,
int count, MWPIXELVAL fg, PMWFONT pfont);***/
void (*Blit)(PSD destpsd, MWCOORD destx, MWCOORD desty, MWCOORD w, MWCOORD h, PSD srcpsd, MWCOORD srcx, MWCOORD srcy, long op);
void (*PreSelect)(PSD psd);
void (*DrawArea)(PSD psd, driver_gc_t *gc, int op);
int (*SetIOPermissions)(PSD psd);
PSD (*AllocateMemGC)(PSD psd);
MWBOOL (*MapMemGC)(PSD mempsd, MWCOORD w, MWCOORD h, int planes, int bpp, int linelen, int size, void *addr);
void (*FreeMemGC)(PSD mempsd);
void (*StretchBlit)(PSD destpsd, MWCOORD destx, MWCOORD desty, MWCOORD destw, MWCOORD desth, PSD srcpsd, MWCOORD srcx, MWCOORD srcy, MWCOORD srcw, MWCOORD srch, long op);
void (*SetPortrait)(PSD psd,int portraitmode);
int portrait; /* screen portrait mode*/
PSUBDRIVER orgsubdriver; /* original subdriver for portrait modes*/
void (*StretchBlitEx) (PSD dstpsd, PSD srcpsd, MWCOORD dest_x_start, MWCOORD dest_y_start, MWCOORD width, MWCOORD height, int x_denominator, int y_denominator, int src_x_fraction, int src_y_fraction, int x_step_fraction, int y_step_fraction, long op);
} SCREENDEVICE;
所在文件:\include\Device.h
全局变量
SCREENDEVICE scrdev = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL,
DBG_open,
DBG_close,
DBG_getscreeninfo,
DBG_setpalette,
DBG_drawpixel,
DBG_readpixel,
DBG_drawhline,
DBG_drawvline,
DBG_fillrect,
gen_fonts,
DBG_blit,
NULL, /* PreSelect*/
NULL, /* DrawArea subdriver*/
NULL, /* SetIOPermissions*/
gen_allocatememgc,
NULL, /* MapMemGC*/
NULL /* FreeMemGC*/
};
所在文件:drivers\Scr_debug.c
浙公网安备 33010602011771号