📄 device.h
字号:
/** Platform Driver** 2001-02-14: ndc, created*//** TODO: draw a simple chart about it* TODO: doc: every routine must have a ANSI C code for console and/or unimplemented or compatible code* TODO: explain: makefile with ofbis & svga drivers (how to create and link different drivers)* TODO: doc: the device.c is shell of osd routines for the unimplemented & common code* TODO: explain: how the 3 drivers are working (dev_palm.c, dev_uvga.c, dev_ufb.c)* TODO: HOW-TO create a new driver* TODO: too much todos :)*/#if !defined(_device_h)#define _device_h#include <stdarg.h>#if defined(__cplusplus)extern "C" {#endif#include "sys.h"#include "keys.h" // Keyboard codes#if !defined(SCAN_MODULE)#include "var.h"#endif#if defined(_UnixOS)#include <termios.h>#endif/* ===========================================================================================================================** colors - VGA16 compatible** There are 16 colors. The second set of 8 colors its the high-light of the first set.* Example:* dark gray its CLR_BLACK+8* light green its CLR_GREEN+8* yellow its CLR_BROWN+8*/#define CLR_BLACK 0#define CLR_BLUE 1#define CLR_GREEN 2#define CLR_CYAN 3#define CLR_RED 4#define CLR_MAGENTA 5#define CLR_BROWN 6#define CLR_GRAY 7#define CLR_WHITE 15/** Libraries (value of os_graphics)*/#define DEVDRV_CONSOLE 0 /* ANSI C */#define DEVDRV_PALMOS 1 /* also, any emulator like BCB IDE */#define DEVDRV_SVGALIB 2 /* svgalib */#define DEVDRV_WIN32 3 /* GUI - Win32 API */#define DEVDRV_XWIN 4 /* GUI - X windows API */#define DEVDRV_OFBIS 5 /* ofbis library (framebuffer) */#define DEVDRV_SDL 6 /* SDL - cross platform graphics library *//** OS Global Information Variables** Globals are needed for speed (Unix is fast, but PalmOS is not)*/enum os_charset_codes { enc_utf8, // 8bit - All European languages - default enc_sjis, // Japanese characters support enc_big5, // Chinese characters support enc_gmb, // Generic multibyte enc_unicode // Unicode };#if !defined(DEVICE_MODULE)extern word os_ver; // OS version (ex: 0x330 for PalmOS 3.3)extern byte os_charset;extern byte os_color; // true if the output has real colors (256+ colors)extern dword os_color_depth; // the number of bits of the supported colors // (ex: 8 for 256 colors, 15 or 16 for 64K, 24 or 32 for 1.6M)extern byte os_graphics; // non-zero if the driver supports graphicsextern int os_graf_mx; // graphic mode: maximum x extern int os_graf_my; // graphic mode: maximum y// graphics - window (x1clip,y1clip,x2clip,y2clip)extern int dev_x1clip;extern int dev_y1clip;extern int dev_x2clip;extern int dev_y2clip;// graphics - origin xorg,yorgextern int dev_xorg;extern int dev_yorg;// graphics - current colorsextern int dev_fgcolor;extern int dev_bgcolor;// cacheextern word os_cclabs1;extern word os_ccpass2;#endif/* ===========================================================================================================================** Driver basics**/int dev_init(int mode, int flags) SEC(BIO); // driver initializationint dev_restore(void) SEC(BIO); // driver (close the driver & restore computer mode)/* ===========================================================================================================================** System basics**/void dev_pushkey(word ch) SEC(BIO); // Internal keyboard buffer: store a key into the bufferint dev_kbhit(void) SEC(BIO); // Internal keyboard buffer: returns true if there is a keyvoid dev_clrkb(void) SEC(BIO); // Internal keyboard buffer: clearint dev_run(const char *prog) SEC(BIO); // system()////////////////////// Check's the system events queue//// a) stores keys into the keyboard buffer// b) store pen/mouse events// c) any other supported device//// Returns 0 if there is not new events in the queue// Returns >0 the number of the new events// Returns -1 that means BREAK (brun_break() it was called)// Returns -2 that means BREAK (executor displays "BREAK" message)//// if dead_loop is zero, the dev_events() will checks the events and then will return immediatly.// if dead_loop is true, the dev_events() will wait for a new event.//int dev_events(int dead_loop);void dev_delay(dword ms);////////////////////// Mouse & lightpen!// Since 1988 the mouse was an new device for PC's, there is no mouse support on QB.// We shall use the PEN(x) to support the mouse, and we must maintain the Palm compatibility.//// PalmOS PEN, Lightpen & Mouse API// ================================// PEN(0) -> true (non zero) if there is a new pen or mouse event// PEN(1) -> PEN: last pen-down x; MOUSE: last mouse button down x // PEN(2) -> PEN: last pen-down y; MOUSE: last mouse button down y// PEN(3) -> QB compatiblity, don't use it// PEN(4) -> PEN: last/current x, MOUSE: the current x position only if the left mouse button is pressed (like PEN is down)// PEN(5) -> PEN: last/current y, MOUSE: the current y position only if the left mouse button is pressed (like PEN is down)// PEN(6) -> QB compatiblity, don't use it// PEN(7) -> QB compatiblity, don't use it// PEN(8) -> QB compatiblity, don't use it// PEN(9) -> QB compatiblity, don't use it// Mouse buttons:// PEN(10) -> current mouse x position// PEN(11) -> current mouse y position// PEN(12) -> true if the left mouse button is pressed// PEN(13) -> true if the right mouse button is pressed// PEN(14) -> true if the middle mouse button is pressed//void dev_setpenmode(int enable) SEC(BIO); // enables or disables pen/mouse driver (PEN ON|OFF)int dev_getpen(int code) SEC(BIO); // returns the pen/mouse status (PEN(code))/* ===========================================================================================================================** terminal input/output**/void dev_print(const char *str) SEC(BIO); // write a string to the consolevoid dev_printf(const char *fmt, ...); // write a formated string to the consolevoid dev_cls(void) SEC(BIO); // clear the screenvoid dev_clreol(void) SEC(BIO); // clear the console line from the current pos. until the end of the linevoid dev_setxy(int x, int y) SEC(BIO); // set cursor position. parameters in pixels.int dev_getx(void) SEC(BIO); // returns the current cursor x position (in pixels)int dev_gety(void) SEC(BIO); // returns the current cursor y position (in pixels)void dev_settextcolor(int fg, int bg) SEC(BIO); // set the text colors. (fg = foreground, bg = background)int dev_getch(void) SEC(BIO); // waits until a key is pressed and returns its codechar *dev_gets(char *buf, int size) SEC(BIO); // the real INPUT command. Gets a string from the console/* ===========================================================================================================================** Graphics**/int dev_textwidth(const char *str) SEC(BIO);int dev_textheight(const char *str) SEC(BIO);void dev_setcolor(int color) SEC(BIO);void dev_setpixel(int x, int y) SEC(BIO);void dev_line(int x1, int y1, int x2, int y2) SEC(BIO);void dev_rect(int x1, int y1, int x2, int y2, int fill) SEC(BIO);void dev_ellipse(int xc, int yc, int xr, int yr, double aspect, int fill) SEC(BIO);void dev_arc(int xc, int yc, double r, double as, double ae, double aspect) SEC(BIO);/* ===========================================================================================================================** Sound**/void dev_beep(void) SEC(BIO); // just a BEEP! :)void dev_sound(int freq, int dur_ms, int vol_prc, int bgplay) SEC(BIO); // note: duration in ms, volume in percent, bgplay = play on background/* ===========================================================================================================================** FILE SYSTEM BASICS**/int dev_initfs() SEC(BIO);void dev_closefs() SEC(BIO);int dev_fexists(const char *file) SEC(BIO);int dev_fcopy(const char *file, const char *newfile) SEC(BIO);int dev_frename(const char *file, const char *newname) SEC(BIO);int dev_fremove(const char *file) SEC(BIO);//int dev_findfirst(char *pattern, struct dev_findfile_t *block) SEC(BIO);//int dev_findnext(struct dev_findfile_t *block) SEC(BIO);/* ===========================================================================================================================** FILE I/O**/// file typestypedef enum { ft_stream, ft_random, ft_serial_port1, ft_serial_port2, ft_irda_port, ft_printer_port, ft_memo_t, ft_pdoc_t, ft_ztxt_t } dev_ftype_t;// file_t structuretypedef struct {#if defined(_PalmOS) char name[64];#elif defined(_DOS) char name[256]; // 64 is the right, but under Win95 there is undocumented bigger paths (I think)#else char name[1024]; // full pathname for Unix & Win32#endif dev_ftype_t type; int port; int devspeed;#if defined(_UnixOS) struct termios oldtio,newtio;#endif#if defined(_PalmOS) UInt16 libHandle;// DmOpenRef ref; FileHand handle; Err last_error;#else int handle; int last_error;#endif int open_flags; } dev_file_t;// flags for dev_fopen()#define DEV_FILE_INPUT 1#define DEV_FILE_OUTPUT 2 // create#define DEV_FILE_APPEND 4 // (if its not exists then create) & open for append#define DEV_FILE_EXCL 8 // open exclusive int dev_freefilehandle() SEC(BIO);dev_file_t* dev_getfileptr(int handle) SEC(BIO);int dev_fstatus(int handle) SEC(BIO);int dev_fopen(int SBHandle, const char *name, int flags) SEC(BIO);dword dev_flength(int SBHandle) SEC(BIO);int dev_fclose(int SBHandle) SEC(BIO);dword dev_fseek(int SBHandle, dword offset) SEC(BIO);dword dev_ftell(int SBHandle) SEC(BIO);int dev_feof(int SBHandle) SEC(BIO);int dev_fwrite(int SBHandle, byte *buff, dword size) SEC(BIO);int dev_fread(int SBHandle, byte *buff, dword size) SEC(BIO);#if defined(__cplusplus)}#endif#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -