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

📄 parse.c

📁 A MP3 Player Source Code, Enjoy it!
💻 C
字号:
#include "as31glue.h"#include "printf.h"#include "parse.h"static idata unsigned char state_next, state_prev, state_play, state_quit;static idata unsigned char state_dbug, state_rand, state_inc, state_dec;static idata unsigned char state_plst, state_nlst, state_up, state_down;static idata unsigned char state_left, state_right, state_enter, state_fwd;static idata unsigned char state_rev, state_display1, state_volup;static idata unsigned char state_voldwn;static data char ch;struct lexcfg {	idata unsigned char *state;	char string[12];};static code struct lexcfg next =	{&state_next,     "NEXT        "};static code struct lexcfg prev =	{&state_prev,     "PREVIOUS    "};static code struct lexcfg play =	{&state_play,     "PLAY        "};static code struct lexcfg rand =	{&state_rand,     "RANDOM      "};static code struct lexcfg quit =	{&state_quit,     "QUIT        "};static code struct lexcfg dbug =	{&state_dbug,     "DEBUG       "};static code struct lexcfg inc =		{&state_inc,      "INC         "};static code struct lexcfg dec =		{&state_dec,      "DEC         "};static code struct lexcfg nlst =	{&state_nlst,     "NXT_LIST    "};static code struct lexcfg plst =	{&state_plst,     "PRV_LIST    "};static code struct lexcfg up =		{&state_up,       "UP          "};static code struct lexcfg down =	{&state_down,     "DOWN        "};static code struct lexcfg right =	{&state_right,    "RIGHT       "};static code struct lexcfg left =	{&state_left,     "LEFT        "};static code struct lexcfg enter =	{&state_enter,    "ENTER       "};static code struct lexcfg fwd =		{&state_fwd,      "FORWARD     "};static code struct lexcfg rev =		{&state_rev,      "REVERSE     "};static code struct lexcfg volup =	{&state_volup,    "VOL+        "};static code struct lexcfg voldwn =	{&state_voldwn,   "VOL-        "};static code struct lexcfg display1 =	{&state_display1, "VERSION1    "};char parse_cin(void);void parse_cout(char c);char lexer(code struct lexcfg *pattern);void quit_immediately(void);void parse_init(void){		state_next = state_prev = state_play = state_quit = \	state_dbug = state_rand = state_inc = state_dec = \	state_plst = state_nlst = state_up = state_down = \	state_left = state_right = state_enter = state_fwd = \	state_rev = state_volup = state_voldwn = state_display1 = 0;}void parse_serial_input(void){   while(1)   {	ch = parse_cin();	if (ch == 0) return;	if (lexer(&quit)) quit_immediately();	if (lexer(&dbug)) _asm cpl _debug _endasm;	if (lexer(&next)) add_new_event(E_NEXT);	if (lexer(&prev)) add_new_event(E_PREV);	if (lexer(&play)) add_new_event(E_PLAY_PAUSE);	if (lexer(&rand)) add_new_event(E_RANDOM);	if (lexer(&inc)) add_new_event(E_INC);	if (lexer(&dec)) add_new_event(E_DEC);	if (lexer(&nlst)) add_new_event(E_NEXT_LIST);	if (lexer(&plst)) add_new_event(E_PREV_LIST);	if (lexer(&up)) add_new_event(E_UP);	if (lexer(&down)) add_new_event(E_DOWN);	if (lexer(&right)) add_new_event(E_RIGHT);	if (lexer(&left)) add_new_event(E_LEFT);	if (lexer(&enter)) add_new_event(E_ENTER);	if (lexer(&fwd)) add_new_event(E_FWD);	if (lexer(&rev)) add_new_event(E_REV);	if (lexer(&volup)) add_new_event(E_VOL_UP);	if (lexer(&voldwn)) add_new_event(E_VOL_DOWN);	if (lexer(&display1)) add_new_event(E_DISPLAY1);	parse_cout(ch);	/* added while(1) in relation to next comment - TP 27Aug01 */	/* should this be a loop that drains the receive buffer ?? */	/* as it is now, only byte is taken out for each call, and */	/* who knows how rapidly the main loop will end up calling */	/* here, depending on what state it's in and what it's doing */   }}/* get the next character of serial input and put it into _ch */char parse_cin(void){	_asm	lcall	0x2032        cjne    a, #97, upper2upper2: jc      upper4          ;end if acc < 97        cjne    a, #123, upper3upper3: jnc     upper4          ;end if acc >= 123        add     a, #224         ;convert to uppercaseupper4:        mov     dpl, a	_endasm;}/* print a character by passing it to cout */void parse_cout(char c){	c;	_asm	mov	a, dpl	ljmp	0x2030;	_endasm;}#define PHEX 0x2034/* return 1 if the pattern has matched, 0 if not */char lexer(code struct lexcfg *pattern){	pattern;	_asm		;A simple fixed-string lexer.  For each character received from an	;input stream, this routine is called once for every string which	;is to be recognized within the input stream.	;  Input registers:	;    r0    Memory location to the index variable for this	;          particular string.	;    r2    The character we received.	;    dptr  Pointer to the string pattern we want to match.	;  Output registers:	;    c     Carry set if complete string found, clear if no match yet.	;    mem   Value @r0 adjusted appropriately for the next call.	lexer:	clr	a	movc	a, @a+dptr	;fetch pointer to state variable	mov	r0, a		;r0 points to this patterns state var        mov     a, @r0	inc	a		;dont look at state pointer        movc    a, @a+dptr      ;get character from string        clr     c        subb    a, _ch        jnz     lex_nope           ;at this point, it matches the string, so now           ;the question becomes "are we at the end?"        inc     @r0             ;advance index	mov	a, @r0	inc	a	movc	a, @a+dptr	;get next character of string	jz	lex_match	;match if end of string        cjne    a, #0x20, lex_cont	sjmp    lex_matchlex_cont:           ;were not at the end of the string yet	mov	dpl, #0        ;clr     c        retlex_match: ;weve found all of the string now        mov     @r0, a          ;reset index automatically	mov	dpl, #1        ;setb    c        retlex_nope:  ;the received character doesnt match the string           ;so we set the index back to zero, and return with           ;carry clear        mov     @r0, #0	mov	dpl, #0        ;clr     c        ret	_endasm;}/* immediately abort the player application */void quit_immediately(void){	_asm	clr	ea        ljmp    0x006D		;return to PM2	_endasm;}void parse_event_setup(){   printf("\\H0%s", inc.string);	// button 0 down = INC   print("\\H@            ");		// button 0 up = <nothing>   printf("\\HP%s", inc.string);	// button 0 repeat = INC   printf("\\H1%s", dec.string);	// button 1 down = DEC   print("\\HA            ");		// button 1 up = <nothing>   printf("\\HQ%s", dec.string);	// button 1 repeat = DEC   printf("\\H2%s", plst.string);	// button 2 down = PRV_PLAYLIST   print("\\HB            ");		// button 2 up = <nothing>   printf("\\HR%s", plst.string);	// button 2 repeat = PRV_PLAYLIST   printf("\\H3%s", nlst.string);	// button 3 down = NXT_PLAYLIST   print("\\HC            ");		// button 3 up = <nothing>   printf("\\HS%s", nlst.string);	// button 3 repeat = NXT_PLAYLIST   print("\\H4            ");		// button 4 down = <nothing>   printf("\\HD%s", prev.string);	// button 4 up = PREVIOUS   printf("\\HT%s", rev.string);	// button 4 repeat = REVERSE   printf("\\H5%s", play.string);	// button 5 down = PLAY   print("\\HE            ");		// button 5 up = <nothing>   print("\\HU            ");		// button 5 repeat = <nothing>   print("\\H6            ");		// button 6 down = <nothing>   printf("\\HF%s", next.string);	// button 6 up = NEXT   printf("\\HV%s", fwd.string);	// button 6 repeat = FORWARD   printf("\\H7%s", up.string);		// button 7 down = UP   print("\\HG            ");		// button 7 up = <nothing>   printf("\\HW%s", up.string);		// button 7 repeat = UP   printf("\\H8%s", left.string);	// button 8 down = LEFT   print("\\HH            ");		// button 8 up = <nothing>   printf("\\HX%s", left.string);	// button 8 repeat = LEFT   printf("\\H9%s", right.string);	// button 9 down = RIGHT   print("\\HI            ");		// button 9 up = <nothing>   printf("\\HY%s", right.string);	// button 9 repeat = RIGHT   printf("\\H:%s", down.string);	// button 10 down = DOWN   print("\\HJ            ");		// button 10 up = <nothing>   printf("\\HZ%s", down.string);	// button 10 repeat = DOWN   printf("\\H;%s", enter.string);	// button 11 down = ENTER   print("\\HK            ");		// button 11 up = <nothing>   printf("\\H[%s", enter.string);	// button 11 repeat = ENTER}   

⌨️ 快捷键说明

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