ctk-80col.c
来自「伟大的Contiki工程, 短小精悍 的操作系统, 学习编程不可不看」· C语言 代码 · 共 1,191 行 · 第 1/3 页
C
1,191 行
asm("inx"); asm("stx $dff9"); asm("pla"); asm("sta $01"); asm("cli"); /* Fill hires memory with 0. */ memset((char *)0xe000, 0, 8000); for(i = 0; i < 256; ++i) {#if 0 ctk_80col_lefttab[i] = ((i & 0x40) << 1) | ((i & 0x20) << 1) | ((i & 0x08) << 2) | ((i & 0x02) << 3); ctk_80col_righttab[i] = ((i & 0x40) >> 3) | ((i & 0x20) >> 3) | ((i & 0x08) >> 2) | ((i & 0x02) >> 1);#else ctk_80col_lefttab[i] = ((i & 0x40) << 1) | ((i & 0x10) << 2) | ((i & 0x04) << 3) | ((i & 0x01) << 4); ctk_80col_righttab[i] = ((i & 0x40) >> 3) | ((i & 0x10) >> 2) | ((i & 0x04) >> 1) | ((i & 0x01));#endif } #if 0 /* Setup mouse pointer sprite. */ asm("lda %v+%w", ctk_80col_theme, offsetof(struct ctk_80col_theme, pointermaskcolor)); asm("sta $d027"); asm("lda %v+%w", ctk_80col_theme, offsetof(struct ctk_80col_theme, pointercolor)); asm("sta $d028"); ptr1 = ctk_80col_theme.pointer; ptr2 = (unsigned char *)0xff40; for(i = 0; i < 0x80; ++i) { *ptr2++ = *ptr1++; }#endif return;}#pragma optimize(pop)/*---------------------------------------------------------------------------*//*static unsigned char cursx, cursy; static unsigned char reversed;*//*-----------------------------------------------------------------------------------*/static void CC_FASTCALL cputc(char c) { /* ctk_arch_draw_char(c, cursx, cursy, reversed, 0);*/ ctk_80col_cputc(c); /* ++cursx;*/}/*-----------------------------------------------------------------------------------*/unsigned charwherex(void){ return ctk_80col_cursx;}/*-----------------------------------------------------------------------------------*/unsigned charwherey(void){ return ctk_80col_cursy;}/*-----------------------------------------------------------------------------------*//*voidclrscr(void){ unsigned char x, y; for(x = 0; x < SCREEN_WIDTH; ++x) { for(y = 0; y < SCREEN_HEIGHT; ++y) { gotoxy(x, y); cputc(' '); } }}*//*-----------------------------------------------------------------------------------*/#define revers(c) ctk_80col_reversed = c/*-----------------------------------------------------------------------------------*/static void CC_FASTCALL _cputs(char *str){ char *ptr = str; while(*ptr != 0) { cputc(*ptr++); } /* int i; for(i = 0; i < strlen(str); ++i) { cputc(str[i]); }*/}/*-----------------------------------------------------------------------------------*/static void CC_FASTCALLcclear(unsigned char length){ int i; for(i = 0; i < length; ++i) { cputc(' '); } }/*-----------------------------------------------------------------------------------*/void CC_FASTCALLchline(unsigned char length){ int i; for(i = 0; i < length; ++i) { cputc('-'); }}/*-----------------------------------------------------------------------------------*/void CC_FASTCALLcvline(unsigned char length){ int i; for(i = 0; i < length; ++i) { cputc('|'); --ctk_80col_cursx; ++ctk_80col_cursy; }}/*-----------------------------------------------------------------------------------*/void CC_FASTCALLgotoxy(unsigned char x, unsigned char y){ ctk_80col_cursx = x; ctk_80col_cursy = y;}/*-----------------------------------------------------------------------------------*/void CC_FASTCALLcclearxy(unsigned char x, unsigned char y, unsigned char length){ gotoxy(x, y); cclear(length);}/*-----------------------------------------------------------------------------------*/void CC_FASTCALLchlinexy(unsigned char x, unsigned char y, unsigned char length){ gotoxy(x, y); chline(length);}/*-----------------------------------------------------------------------------------*/void CC_FASTCALLcvlinexy(unsigned char x, unsigned char y, unsigned char length){ gotoxy(x, y); cvline(length);}/*-----------------------------------------------------------------------------------*/void CC_FASTCALL_cputsxy(unsigned char x, unsigned char y, char *str){ gotoxy(x, y); _cputs(str);}/*-----------------------------------------------------------------------------------*/void CC_FASTCALLcputcxy(unsigned char x, unsigned char y, char c){ gotoxy(x, y); cputc(c);}/*-----------------------------------------------------------------------------------*//*void CC_FASTCALLscreensize(unsigned char *x, unsigned char *y){ *x = SCREEN_WIDTH; *y = SCREEN_HEIGHT;}*//*-----------------------------------------------------------------------------------*//*static unsigned char sizex, sizey;*//*-----------------------------------------------------------------------------------*/static void_cputsn(char *str, unsigned char len){ /* char c; while(len > 0) { --len; c = *str; if(c == 0) { break; } cputc(c); ++str; }*/ ctk_80col_cputsn(str, len);}/*-----------------------------------------------------------------------------------*/static voids_ctk_draw_init(void){ ctk_80col_init(); /* screensize(&sizex, &sizey);*/ ctk_draw_clear(0, SCREEN_HEIGHT);}/*-----------------------------------------------------------------------------------*/static voiddraw_widget(struct ctk_widget *w, unsigned char x, unsigned char y, unsigned char clipx, unsigned char clipy, unsigned char clipy1, unsigned char clipy2, unsigned char focus){ unsigned char xpos, ypos, xscroll; unsigned char i, j; char c, *text; unsigned char len, wfocus; wfocus = 0; if(focus & CTK_FOCUS_WINDOW) { if(focus & CTK_FOCUS_WIDGET) { wfocus = 1; } } else if(focus & CTK_FOCUS_DIALOG) { if(focus & CTK_FOCUS_WIDGET) { wfocus = 1; } } else { } xpos = x + w->x; ypos = y + w->y; switch(w->type) { case CTK_WIDGET_SEPARATOR: if(ypos >= clipy1 && ypos < clipy2) { chlinexy(xpos, ypos, w->w); } break; case CTK_WIDGET_LABEL: text = w->widget.label.text; for(i = 0; i < w->h; ++i) { if(ypos >= clipy1 && ypos < clipy2) { gotoxy(xpos, ypos); _cputsn(text, w->w); if(w->w - (wherex() - xpos) > 0) { cclear(w->w - (wherex() - xpos)); } } ++ypos; text += w->w; } break; case CTK_WIDGET_BUTTON: if(ypos >= clipy1 && ypos < clipy2) { if(wfocus != 0) { revers(1); } else { revers(0); } cputcxy(xpos, ypos, '['); _cputsn(w->widget.button.text, w->w); cputc(']'); revers(0); } break; case CTK_WIDGET_HYPERLINK: if(ypos >= clipy1 && ypos < clipy2) { if(wfocus != 0) { revers(0); } else { revers(1); } gotoxy(xpos, ypos); _cputsn(w->widget.button.text, w->w); revers(0); } break; case CTK_WIDGET_TEXTENTRY: text = w->widget.textentry.text; xscroll = 0; if(w->widget.textentry.xpos >= w->w - 1) { xscroll = w->widget.textentry.xpos - w->w + 1; } for(j = 0; j < w->h; ++j) { if(ypos >= clipy1 && ypos < clipy2) { if(w->widget.textentry.state == CTK_TEXTENTRY_EDIT && w->widget.textentry.ypos == j) { revers(0); cputcxy(xpos, ypos, '>'); c = 1; for(i = 0; i < w->w; ++i) { if(c != 0) { c = text[i + xscroll]; } if(i == w->widget.textentry.xpos - xscroll) { revers(1); } else { revers(0); } if(c == 0) { cputc(' '); } else { cputc(c); } revers(0); } cputc('<'); } else { if(wfocus != 0 && j == w->widget.textentry.ypos) { revers(1); } else { revers(0); } cvlinexy(xpos, ypos, 1); gotoxy(xpos + 1, ypos); _cputsn(text, w->w); i = wherex(); if(i - xpos - 1 < w->w) { cclear(w->w - (i - xpos) + 1); } cvline(1); } } ++ypos; text += w->widget.textentry.len + 1; } revers(0); break; case CTK_WIDGET_ICON: if(ypos >= clipy1 && ypos < clipy2) { color(ctk_80col_theme.iconcolors[focus]); /* if(focus & 1) { revers(1); } else { revers(0); }*/ /* gotoxy(xpos, ypos);*/ if(xpos >= 73) { xpos = 73; } if(xpos <= 2) { xpos = 2; } if(w->widget.icon.textmap != NULL) { ctk_80col_bitmapptr = w->widget.icon.bitmap; for(i = 0; i < 3; ++i) { if(ypos >= clipy1 && ypos < clipy2) { gotoxy(xpos, ypos); ctk_80col_draw_bitmapline(3); } ctk_80col_bitmapptr += 3 * 8; ++ypos; } } x = xpos; len = strlen(w->widget.icon.title); if(x + len >= SCREEN_WIDTH) { x = SCREEN_WIDTH - len; } if(ypos >= clipy1 && ypos < clipy2) { len = strlen(w->widget.icon.title); gotoxy((x & 0xfe) + 1, ypos); ctk_80col_cclear((len - 1)/ 2); gotoxy(x, ypos); ctk_80col_cputsn(w->widget.icon.title, len); } revers(0); } break; default: break; }}/*-----------------------------------------------------------------------------------*/static voids_ctk_draw_widget(struct ctk_widget *w, unsigned char focus, unsigned char clipy1, unsigned char clipy2)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?