📄 dev_palm.c
字号:
p = (byte *) str; while ( *p ) { switch ( *p ) { case '\a': // beep osd_beep(); break; case '\t': cur_x = osd_calctab(cur_x+1); break; case '\xC': osd_cls(); break; case '\033': // ESC ctrl chars (man console_codes) if ( *(p+1) == '[' ) { p += 2; esc_val = esc_cmd = 0; if ( is_digit(*p) ) { esc_val = (*p - '0'); p ++; if ( is_digit(*p) ) { esc_val = (esc_val * 10) + (*p - '0'); p ++; } esc_cmd = *p; } else esc_cmd = *p; // control characters switch ( esc_cmd ) { case 'K': // \e[K - clear to eol r.topLeft.x = cur_x; r.topLeft.y = cur_y; r.extent.x = 160 - cur_x; r.extent.y = font_h; WinEraseRectangle(&r, 0); break; case 'm': // \e[...m - ANSI terminal switch ( esc_val ) { case 0: // reset FntSetFont(stdFont); WinSetUnderlineMode(noUnderline); font_h = FntCharHeight(); maxline = 160/font_h; useinvert = 0; osd_setcolor(0); osd_settextcolor(0, 15); break; case 1: // set bold on FntSetFont(boldFont); break; case 4: // set underline on WinSetUnderlineMode(solidUnderline); break; case 7: // reverse video on useinvert = 1; break; case 21: // set bold off FntSetFont(stdFont); break; case 24: // set underline off WinSetUnderlineMode(noUnderline); break; case 27: // reverse video off useinvert = 0; break; // colors - 30..37 foreground, 40..47 background case 30: // set black fg osd_setcolor(0); break; case 31: // set red fg osd_setcolor(4); break; case 32: // set green fg osd_setcolor(2); break; case 33: // set brown fg osd_setcolor(6); break; case 34: // set blue fg osd_setcolor(1); break; case 35: // set magenta fg osd_setcolor(5); break; case 36: // set cyan fg osd_setcolor(3); break; case 37: // set white fg osd_setcolor(7); break; case 40: // set black bg osd_settextcolor(dev_fgcolor, 0); break; case 41: // set red bg osd_settextcolor(dev_fgcolor, 4); break; case 42: // set green bg osd_settextcolor(dev_fgcolor, 2); break; case 43: // set brown bg osd_settextcolor(dev_fgcolor, 6); break; case 44: // set blue bg osd_settextcolor(dev_fgcolor, 1); break; case 45: // set magenta bg osd_settextcolor(dev_fgcolor, 5); break; case 46: // set cyan bg osd_settextcolor(dev_fgcolor, 3); break; case 47: // set white bg osd_settextcolor(dev_fgcolor, 7); break; // extra palmos case 80: // select font 1 std case 81: // select font 2 bold case 82: // select font 3 large case 83: // select font 4 symbol case 84: // select font 5 symbol 11 case 85: // select font 6 symbol 7 case 86: // select font 7 led case 87: // select font 8 large bold FntSetFont(esc_val-80); font_h = FntCharHeight(); maxline = 160/font_h; break; case 90: // select custon font 1 case 91: // select custom font 2 case 92: // select custom font 3 case 93: // select custom font 4 if ( os_charset == enc_utf8 ) { FntSetFont(128+(esc_val-90)); font_h = FntCharHeight(); maxline = 160/font_h; } break; }; break; } } break; case '\n': // new line osd_nextln(); break; case '\r': // return r.topLeft.x = 0; r.topLeft.y = cur_y; r.extent.x = 160; r.extent.y = font_h; WinEraseRectangle(&r, 0); cur_x = 0; break; default: // // PRINT THE CHARACTER // buf[0] = *p; mbf = 0; switch ( os_charset ) { case enc_sjis: // Japan if ( IsJIS1Font(*p) ) { ch = (*p << 8) + *(p + 1); mbf = IsJISFont(ch); } break; case enc_big5: // China if ( IsBig51Font(*p) ) { ch = (*p << 8) + *(p + 1); mbf = IsBig5Font(ch); } break; case enc_gmb: // Generic multibyte if ( IsGMB1Font(*p) ) { ch = (*p << 8) + *(p + 1); mbf = IsGMBFont(ch); } break; case enc_unicode: // Unicode mbf = 1; ch = (*p << 8) + *(p + 1); break; } if ( mbf ) { // its a multibyte char p ++; // skip one character (needed for the loop) cx = FntCharsWidth((byte *) &ch, 2); buf[1] = *p; buf[2] = '\0'; char_len = 2; } else { cx = FntCharWidth(*p); buf[1] = '\0'; char_len = 1; } // new line ? if ( cur_x + cx >= /* dev_x2clip */ 160 ) osd_nextln(); // draw if ( !useinvert ) WinDrawChars(buf, char_len, cur_x, cur_y); else WinDrawInvertedChars(buf, char_len, cur_x, cur_y); // advance cur_x += cx; }; if ( *p == '\0' ) break; p ++; }}/**/void osd_spec_setcolor(int color, int bg) SEC(BIO);void osd_spec_setcolor(int color, int bg){ RGBColorType rgb; if ( color > 15 ) color = 15; if ( color < 0 ) color = 0; if ( bg ) dev_bgcolor = color; else dev_fgcolor = color; if ( os_ver < 0x310 ) return; MemSet(&rgb, sizeof(rgb), 0); switch ( color ) { case 0: if ( bg ) WinSetColors(0, 0, &rgb, 0); else WinSetColors(&rgb, 0, 0, 0); break; case 15: rgb.r = rgb.g = rgb.b = 0xFF; if ( bg ) WinSetColors(0, 0, &rgb, 0); else WinSetColors(&rgb, 0, 0, 0); break; default: if ( os_color_depth == 2 ) { // PalmOS ver 3.1+ // 2bit GRAY if ( color < 7 || color == 8 ) { rgb.r = rgb.g = rgb.b = 0x55; } else { rgb.r = rgb.g = rgb.b = 0xAA; } if ( bg ) WinSetColors(0, 0, &rgb, 0); else WinSetColors(&rgb, 0, 0, 0); } else if ( os_color_depth == 4 ) { // PalmOS ver 3.3+ // 4bit GRAY if ( color == 8 ) rgb.r = rgb.g = rgb.b = 119; else if ( color == 7 ) rgb.r = rgb.g = rgb.b = 136; else rgb.r = rgb.g = rgb.b = color * 255/15; if ( bg ) WinSetColors(0, 0, &rgb, 0); else WinSetColors(&rgb, 0, 0, 0); } else if ( os_ver >= 0x350 ) { // PalmOS ver 3.5+ int co; int lo, hi; // COLOR if ( color > 8 ) ( hi = 1, lo = color & 0x7 ); else ( hi = 0, lo = color ); if ( color == 8 ) rgb.r = rgb.g = rgb.b = 0x55; else if ( color == 7 ) rgb.r = rgb.g = rgb.b = 0xAA; else { /* TODO: hi-colors (>7) are not working on POSE with Gary's ROM */ if ( lo == CLR_BLUE || lo == CLR_CYAN || lo == CLR_MAGENTA || lo == CLR_BLACK ) rgb.b = (hi) ? 0xFF : 0x7F; if ( lo == CLR_GREEN || lo == CLR_CYAN || lo == CLR_BROWN || lo == CLR_BLACK ) rgb.g = (hi) ? 0xFF : 0x7F; if ( lo == CLR_RED || lo == CLR_MAGENTA || lo == CLR_BROWN || lo == CLR_BLACK ) rgb.r = (hi) ? 0xFF : 0x7F; } co = WinRGBToIndex(&rgb); if ( bg ) WinSetBackColor(co); else { WinSetTextColor(co); WinSetForeColor(co); } } };}/** set current color*/void osd_setcolor(int color){ osd_spec_setcolor(color, 0);}/** set text color (fg used for graphics too)*/void osd_settextcolor(int fg, int bg){ osd_spec_setcolor(fg, 0); if ( bg != -1 ) osd_spec_setcolor(bg, 1);}/** draw line*/void osd_line(int x1, int y1, int x2, int y2){ switch ( dev_fgcolor ) { case 0: /* black */ WinDrawLine(x1, y1, x2, y2); break; case 15: /* white */ if ( os_color_depth > 1 ) WinDrawLine(x1, y1, x2, y2); else WinEraseLine(x1, y1, x2, y2); break; default: if ( os_ver >= 0x310 ) WinDrawLine(x1, y1, x2, y2); else WinDrawGrayLine(x1, y1, x2, y2); }}/** draw pixel*/void osd_setpixel(int x, int y){ if ( os_ver >= 0x350 ) WinDrawPixel(x, y); else osd_line(x, y, x, y);}/** draw rect*/void osd_rect(int x1, int y1, int x2, int y2, int fill){ int y; RectangleType r; r.topLeft.x = x1; r.topLeft.y = y1; r.extent.x = (x2 - x1)+1; r.extent.y = (y2 - y1)+1; switch ( dev_fgcolor ) { case 0: /* black */ if ( fill ) WinDrawRectangle(&r, 0); else { osd_line(x1, y1, x1, y2); osd_line(x1, y2, x2, y2); osd_line(x2, y2, x2, y1); osd_line(x2, y1, x1, y1); } break; case 15: /* white */ if ( fill ) WinEraseRectangle(&r, 0); else { osd_line(x1, y1, x1, y2); osd_line(x1, y2, x2, y2); osd_line(x2, y2, x2, y1); osd_line(x2, y1, x1, y1); } break; default: if ( fill ) { for ( y = y1; y <= y2; y ++ ) osd_line(x1, y, x2, y); } else { osd_line(x1, y1, x2, y2); osd_line(x1, y1, x1, y2); osd_line(x1, y2, x2, y2); osd_line(x2, y2, x2, y1); osd_line(x2, y1, x1, y1); } }}/** BEEP :)*/void osd_beep(){ SndCommandType beepPB; int vol; vol = PrefGetPreference(prefSysSoundVolume); if ( vol ) { beepPB.cmd = sndCmdFreqDurationAmp; beepPB.param1 = 440; beepPB.param2 = 125; // in ms beepPB.param3 = vol; SndDoCmd(NULL, &beepPB, true); // true=nowait }}/** play a tone.*/void osd_sound(int frq, int ms, int vol, int bgplay){ if ( bgplay ) { audio_node node; node.status = 0; node.frq = frq; node.dur = ms; node.vol = vol; dbt_write(audio_queue, audio_qtail, &node, sizeof(audio_node)); audio_qtail ++; if ( audio_qtail >= AUDIO_QSIZE ) audio_qtail = 0; } else { if ( frq ) { SndCommandType beepPB; beepPB.cmd = sndCmdFreqDurationAmp; beepPB.param1 = frq; beepPB.param2 = ms; // in ms beepPB.param3 = (sndMaxAmp * vol) / 100; SndDoCmd(NULL, &beepPB, 0); // true=nowait } else { dev_delay(ms); } }}int osd_textwidth(const char *str){ return FntCharsWidth(str, strlen(str));}int osd_textheight(const char *str){ // TODO: count \n return font_h;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -