⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dev_palm.c

📁 smallbasic for linux
💻 C
📖 第 1 页 / 共 2 页
字号:
/**	low-level device driver for PALM OS**	ndc: 2001-02-13*/#include "sys.h"#include "device.h"#include "osd.h"#include "pmem.h"#include "pproc.h"#include "smbas.h"#include <PenMgr.h>#define sysVersion30    sysMakeROMVersion(3,0,0,sysROMStageRelease,0)#define sysVersion31    sysMakeROMVersion(3,1,0,sysROMStageRelease,0)#define sysVersion35    sysMakeROMVersion(3,5,0,sysROMStageRelease,0)static int	pdev_prev_keymask;static word	pdev_keydelay[3];static byte pdev_keyq;static dword	TPS;static dbt_t audio_queue;static int	audio_qhead;static int	audio_qtail;struct audio_node_s	{	word	frq;	word	dur;	byte	vol;	dword	start;	dword	end;	byte	status;	};typedef struct audio_node_s audio_node;#define	AUDIO_QSIZE		256static int	cur_y = 0;		// current y positionstatic int	cur_x = 0;		// current x positionstatic int maxline = (160/11);	// max. console line  ((160-15)/11 = 13.18 = 0..12)static int useinvert = 0;	// use invert routines static int tabsize = 32;	// tab size in pixels (160/32 = 5)static int font_h = 11;		// font height// PEN STATUS (used with do_events/PEN() function)static int16	pen_x;static int16	pen_y;static int16	pen_down_x;static int16	pen_down_y;static int16	pen_update;static byte		pen_down = 0;	// booleanstatic int16	pen_state = 0;/**	PalmOS device initialization*/int		osd_devinit(){	dword	romVersion;	dword	sup_depth;//	word	keydelay[3];//	byte	keyq;	/* OS INFO */    FtrGet(sysFtrCreator, sysFtrNumROMVersion, &romVersion);	if	( romVersion >= sysVersion35 )		os_ver = 0x350;	else if	( romVersion > sysVersion31 )		os_ver = 0x330;	else if	( romVersion == sysVersion31 )		os_ver = 0x310;	else		os_ver = 0x300;	/* initialize keyboard (hardware keys) */	pdev_prev_keymask = KeySetMask(0x7E);	KeyRates(0, &pdev_keydelay[0], &pdev_keydelay[1], &pdev_keydelay[2], &pdev_keyq);//	keydelay[0] = keydelay[1] = keydelay[2] = 0; keyq = 0;//	KeyRates(-1, &keydelay[0], &keydelay[1], &keydelay[2], &keyq);	/* initialize colors */    if ( os_ver < 0x310 ) {        os_color_depth = 1;  // no system support for gray or colors.        os_color = 0;        }    else {		ScrDisplayMode(scrDisplayModeGetSupportedDepths, NULL, NULL, &sup_depth, NULL);		if      (sup_depth & 0x0080) os_color_depth = 8;		else if (sup_depth & 0x0008) os_color_depth = 4;		else if (sup_depth & 0x0002) os_color_depth = 2;		else                         os_color_depth = 1;        WinScreenMode(winScreenModeSet, 0, 0, &os_color_depth, 0);        os_color = (os_color_depth==8);        }	TPS = SysTicksPerSecond();	audio_queue = dbt_create("AUDIO.VMT");	dbt_prealloc(audio_queue, AUDIO_QSIZE, sizeof(audio_node));	audio_qhead = audio_qtail = 0;	pen_state = 0;	pen_update = 0;	cur_x = cur_y = 0;	FntSetFont(stdFont);	font_h = FntCharHeight();	maxline = 160/font_h;	osd_setcolor(0);	dev_clrkb();	dev_cls();	return 1;}/**	PalmOS device - restore to defaults*/int		osd_devrestore(){	FntSetFont(stdFont);	osd_settextcolor(0, 15);	font_h = FntCharHeight();	maxline = 160/font_h;	osd_setcolor(0);	cur_x = cur_y = 0;	audio_qhead = audio_qtail = 0;	dbt_close(audio_queue);	/* restore keyboard */	KeySetMask(pdev_prev_keymask);	KeyRates(-1, &pdev_keydelay[0], &pdev_keydelay[1], &pdev_keydelay[2], &pdev_keyq);	return 1;}/**/void	osd_realsound(int frq, int ms, int vol) SEC(BIO);void	osd_realsound(int frq, int ms, int vol){	SndCommandType	beepPB;	beepPB.cmd = sndCmdFrqOn;	beepPB.param1 = frq;	beepPB.param2 = ms;	// in ms	beepPB.param3 = (sndMaxAmp * vol) / 100;	SndDoCmd(NULL, &beepPB, 1);}/**/void	osd_backsound(dword dif)	SEC(BIO);void	osd_backsound(dword dif){	audio_node	node;	dword		now;	if	( audio_qhead != audio_qtail )	{		dbt_read(audio_queue, audio_qhead, &node, sizeof(audio_node));		if	( node.status == 1 )	{	// I am playing			now = TimGetTicks();			if	( now >= node.end )	{				osd_realsound(0, 0, 0);	// stop				audio_qhead ++;				if	( audio_qhead >= AUDIO_QSIZE )					audio_qhead = 0;				if	( now > node.end )					osd_backsound(now - node.end);	// read next NOW				else					osd_backsound(0);	// read next NOW				}			}		else	{	// next cmd			node.start = TimGetTicks() + dif;			node.end = node.start + ((node.dur * TPS) / 1000);			if	( node.frq )				osd_realsound(node.frq, node.dur, node.vol);	// start play			else				osd_realsound(0, 0, 0);	// stop			node.status = 1;			dbt_write(audio_queue, audio_qhead, &node, sizeof(audio_node));			}		}}/**	events*/int		BRUNHandleEvent(EventPtr e);Boolean ApplicationHandleEvent(EventPtr e);/**/int		osd_catch(EventType *ev){	dword	state;	int		r = 0;	if	( ev->eType == penUpEvent )			pen_down = 0;	else if	( ev->eType == penMoveEvent || ev->eType == penDownEvent )	{		if	( ev->screenY <= 160 )	{			pen_x = ev->screenX;			pen_y = ev->screenY;			if	( (ev->eType == penDownEvent) && (pen_down == 0) )	{				pen_down_x = pen_x;				pen_down_y = pen_y;				pen_down = 1;				}			pen_update = pen_state;			}		}	if	( ev->eType == keyDownEvent )	{		state = KeyCurrentState();		if	( state & keyBitHard4 )	{			pen_state = 0;								return -2;			}		if	( state & keyBitHard1 )	{			dev_pushkey(SB_KEY_PALM_BTN1);			return 1;			}		if	( state & keyBitHard2 )	{			dev_pushkey(SB_KEY_PALM_BTN2);			return 1;			}		if	( state & keyBitHard3 )	{			dev_pushkey(SB_KEY_PALM_BTN3);			return 1;			}		if ( ev->data.keyDown.modifiers & commandKeyMask )	{			switch ( ev->data.keyDown.chr )	{			case	pageUpChr:				dev_pushkey(SB_KEY_PGUP);				r ++;				return r;			case	pageDownChr:				dev_pushkey(SB_KEY_PGDN);				r ++;				return r;			case vchrLaunch:				pen_state = 0;									EvtAddEventToQueue(ev);				return -2;			case vchrLowBattery:			case vchrAlarm:                       // back to for alarm events			case vchrMenu:				break;			case vchrFind:				dev_pushkey(SB_KEY_PALM_FIND);				r ++;				return r;			case vchrCalc:				dev_pushkey(SB_KEY_PALM_CALC);				r ++;				return r;			case vchrKeyboard:			case vchrKeyboardAlpha:			case vchrKeyboardNumeric:				// popup keyboard				break;			case vchrGraffitiReference:           // popup the Graffiti reference				break;                }			}		else	{			if	( (word) ev->data.keyDown.chr >= 32 )					dev_pushkey(ev->data.keyDown.chr);				if	( ev->data.keyDown.chr == '\b' || ev->data.keyDown.chr == '\t' || ev->data.keyDown.chr == '\n' )					dev_pushkey(ev->data.keyDown.chr);			r ++;			return r;			}		}	return r;}/**	system event-loop*	returns -1,-2 if stop rq.*	returns the number of events*/int		osd_events(int wait_flag){	EventType	ev;	Err			err;	int			retcode = 0;	osd_backsound(0);	EvtGetEvent(&ev, (wait_flag) ? -1 : 0);	if	( ev.eType != nilEvent )	{			retcode ++;		if	( (retcode = osd_catch(&ev)) )				return retcode;		if	( !SysHandleEvent(&ev) )	{			if	( !MenuHandleEvent(NULL, &ev, &err) )	{				if	( !ApplicationHandleEvent(&ev) )	{					if	( BRUNHandleEvent(&ev) )							return -1;					} // app				} // menu			} // sys		}	return retcode;}//	returns the current position in pixelsint		osd_getx()	{ return cur_x; }int		osd_gety()	{ return cur_y; }/**	enable or disable PEN code*/void	osd_setpenmode(int enable){	if	( enable )			pen_state = 2;	else		pen_state = 0;}/**	returns the pen events*	(see device.h)*/int		osd_getpen(int code){	int		r = 0;	if	( pen_state == 0 )		return 0;	switch ( code )	{	case 	0:	// bool: status changed		if	( pen_update == 0 )	{			r = osd_events(0);			if	( r < 0 )	{				brun_break();				return 0;				}			}		if ( pen_update && pen_state == 2 )	{	// after PEN ON			pen_down_x = pen_x;			pen_down_y = pen_y;			pen_state = 1;			}		r = pen_update;		break;			case	1:	// last pen-down x		r = pen_down_x;		break;			case	2:	// last pen-down y		r = pen_down_y;		break;			case	3:	// vert. 1 = down, 0 = up		r = pen_down;		break;	case	4:	// last x		r = pen_x;		break;	case	5:	// last y		r = pen_y;		break;		}	pen_update = 0;	return	r;}/**	Clear Screen*/void	osd_cls(){	RectangleType	r;	r.topLeft.x = 0;	r.topLeft.y = 0; 	r.extent.x = 160;	r.extent.y = 160;	WinEraseRectangle(&r, 0);	cur_x = cur_y = 0;	useinvert = 0;	FntSetFont(stdFont);	WinSetUnderlineMode(noUnderline);}/**	set text x,y (in pixels)*/void	osd_setxy(int x, int y){	cur_y = y;	cur_x = x;}/**	osd_write: next line*/void	osd_nextln() SEC(BIO);void	osd_nextln(){	RectangleType	r;	int				dy;	cur_x = 0;	if	( cur_y < ((maxline-1) * font_h) )	{		cur_y += font_h;		}	else	{		// scroll		dy = font_h;		r.topLeft.x = 0;		r.topLeft.y = 0;		r.extent.x = 160;		r.extent.y = 160;		WinScrollRectangle(&r, winUp, dy, &r);		cur_y = (maxline-1) * font_h;		r.topLeft.x = 0;		r.topLeft.y = cur_y;		r.extent.x = 160;		r.extent.y = 160 - cur_y;		WinEraseRectangle(&r, 0);		}}/**	osd_write: calc next tab position*/int		osd_calctab(int x) SEC(BIO);int		osd_calctab(int x){	int		c = 1;	while ( x > tabsize )	{		x -= tabsize;		c ++;		}	return c * tabsize;}/**	osd_write: basic output**	Supported control codes:*	\t		tab (20 px)*	\a		beep*	\r		return*	\n		next line*	\xC		clear screen*	\e[K	clear to end of line*	\e[0m	reset all attributes to their defaults*	\e[1m	set bold on*	\e[4m	set underline on*	\e[7m	reverse video*	\e[21m	set bold off*	\e[24m	set underline off*	\e[27m	set reverse off*/void	osd_write(const char *str){	int		len, cx, esc_val, esc_cmd;	byte	*p, buf[3];	int		ch, char_len = 1, mbf;	RectangleType	r;	len = strlen(str);	if	( len <= 0 )		return;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -