int main (void) { unsigned char XSize, YSize; /* Set screen colors */ (void) textcolor (COLOR_WHITE); (void) bordercolor (COLOR_BLACK); (void) bgcolor (COLOR_BLACK); /* Clear the screen, put cursor in upper left corner */ clrscr (); /* Ask for the screen size */ screensize (&XSize, &YSize); /* Draw a border around the screen */ /* Top line */ cputc (CH_ULCORNER); chline (XSize - 2); cputc (CH_URCORNER); /* Vertical line, left side */ cvlinexy (0, 1, YSize - 2); /* Bottom line */ cputc (CH_LLCORNER); chline (XSize - 2); cputc (CH_LRCORNER); /* Vertical line, right side */ cvlinexy (XSize - 1, 1, YSize - 2); /* Write the greeting in the mid of the screen */ gotoxy ((XSize - strlen (Text)) / 2, YSize / 2); cprintf ("%s", Text); #if defined(__NES__) || defined(__PCE__) || defined(__GAMATE__) || defined(__ATARI5200__) /* Wait for the user to press a button */ joy_install (joy_static_stddrv); while (!joy_read (JOY_1)) ; joy_uninstall (); #else /* Wait for the user to press a key */ cgetc (); #endif /* Clear the screen again */ clrscr (); /* Done */ return EXIT_SUCCESS; }
static void DrawFrame (register FrameDesc* F, char Active) /* Draw one window frame */ { TextDesc* T; unsigned char Count; unsigned char tl, tr, bl, br; unsigned char x1, y1, width; unsigned char OldColor; /* Determine the characters for the corners, set frame color */ if (Active) { OldColor = textcolor (COLOR_FRAMEHIGH); tl = CH_ULCORNER; tr = CH_URCORNER; bl = CH_LLCORNER; br = CH_LRCORNER; } else { OldColor = textcolor (COLOR_FRAMELOW); tl = F->fd_tl; tr = F->fd_tr; bl = F->fd_bl; br = F->fd_br; } /* Get the coordinates into locals for faster access */ x1 = F->fd_x1; y1 = F->fd_y1; width = F->fd_width; /* Top line */ cputcxy (x1, y1, tl); chline (width); cputc (tr); /* Left line */ cvlinexy (x1, ++y1, F->fd_height); /* Bottom line */ cputc (bl); chline (width); cputc (br); /* Right line */ cvlinexy (F->fd_x2, y1, F->fd_height); /* If the window has static text associated, print the text */ (void) textcolor (COLOR_TEXTLOW); Count = F->fd_textcount; T = F->fd_text; while (Count--) { cputsxy (x1 + T->x, y1 + T->y, T->text); ++T; } /* Set the old color */ (void) textcolor (OldColor); }
/*-----------------------------------------------------------------------------------*/ static void s_ctk_draw_dialog(struct ctk_window *dialog) { unsigned char x, y; unsigned char i; unsigned char x1, y1, x2, y2; (void)textcolor(DIALOGCOLOR); x = dialog->x; y = dialog->y + 1; x1 = x + 1; y1 = y + 1; x2 = x1 + dialog->w; y2 = y1 + dialog->h; /* Draw dialog frame. */ cvlinexy(x, y1, dialog->h); cvlinexy(x2, y1, dialog->h); chlinexy(x1, y, dialog->w); chlinexy(x1, y2, dialog->w); cputcxy(x, y, CH_ULCORNER); cputcxy(x, y2, CH_LLCORNER); cputcxy(x2, y, CH_URCORNER); cputcxy(x2, y2, CH_LRCORNER); /* Clear dialog contents. */ for(i = y1; i < y2; ++i) { cclearxy(x1, i, dialog->w); } draw_window_contents(dialog, CTK_FOCUS_DIALOG, 0, sizey, x1, x2, y1, y2); }
/*-----------------------------------------------------------------------------------*/ static void draw_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 wfocus; #if CTK_CONF_ICONS unsigned char len; #endif /* CTK_CONF_ICONS */ wfocus = 0; if(focus & CTK_FOCUS_WINDOW) { (void)textcolor(WIDGETCOLOR_FWIN); if(focus & CTK_FOCUS_WIDGET) { (void)textcolor(WIDGETCOLOR_FOCUS); wfocus = 1; } #if CTK_CONF_WINDOWS } else if(focus & CTK_FOCUS_DIALOG) { (void)textcolor(WIDGETCOLOR_DIALOG); if(focus & CTK_FOCUS_WIDGET) { (void)textcolor(WIDGETCOLOR_FOCUS); wfocus = 1; } #endif /* CTK_CONF_WINDOWS */ } else { (void)textcolor(WIDGETCOLOR); } 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) { revers(wfocus != 0); cputcxy(xpos, ypos, '['); cputsn(w->widget.button.text, w->w); cputc(']'); revers(0); } break; case CTK_WIDGET_HYPERLINK: if(ypos >= clipy1 && ypos < clipy2) { revers(wfocus == 0); gotoxy(xpos, ypos); (void)textcolor(WIDGETCOLOR_HLINK); 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]; } revers(i == w->widget.textentry.xpos - xscroll); if(c == 0) { cputc(' '); } else { cputc(c); } } revers(0); cputc('<'); } else { revers(wfocus != 0 && j == w->widget.textentry.ypos); 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; #if CTK_CONF_ICONS case CTK_WIDGET_ICON: if(ypos >= clipy1 && ypos < clipy2) { revers(wfocus != 0); #if CTK_CONF_ICON_TEXTMAPS if(w->widget.icon.textmap != NULL) { for(i = 0; i < 3; ++i) { gotoxy(xpos, ypos); if(ypos >= clipy1 && ypos < clipy2) { cputc(w->widget.icon.textmap[0 + 3 * i]); cputc(w->widget.icon.textmap[1 + 3 * i]); cputc(w->widget.icon.textmap[2 + 3 * i]); } ++ypos; } } #endif /* CTK_CONF_ICON_TEXTMAPS */ len = (unsigned char)strlen(w->widget.icon.title); if(xpos + len >= sizex) { xpos = sizex - len; } gotoxy(xpos, ypos); if(ypos >= clipy1 && ypos < clipy2) { cputs(w->widget.icon.title); } revers(0); } break; #endif /* CTK_CONF_ICONS */ default: break; } }
/*-----------------------------------------------------------------------------------*/ void ctk_draw_window(struct ctk_window *window, unsigned char focus, unsigned char clipy1, unsigned char clipy2, unsigned char draw_borders) { #if CTK_CONF_WINDOWS unsigned char x, y; unsigned char x1, y1, x2, y2; unsigned char h; if(window->y + CTK_CONF_MENUS >= clipy2) { return; } x = window->x; y = window->y + CTK_CONF_MENUS; x1 = x + 1; y1 = y + 1; x2 = x1 + window->w; y2 = y1 + window->h; if(draw_borders) { /* Draw window frame. */ if(focus & CTK_FOCUS_WINDOW) { (void)textcolor(WINDOWCOLOR_FOCUS); } else { (void)textcolor(WINDOWCOLOR); } if(y >= clipy1) { cputcxy(x, y, (char)CH_ULCORNER); gotoxy(wherex() + window->titlelen + CTK_CONF_WINDOWMOVE * 2, wherey()); chline(window->w - (wherex() - x) - 2); cputcxy(x2, y, (char)CH_URCORNER); } h = window->h; if(clipy1 > y1) { if(clipy1 - y1 < h) { h = clipy1 - y1; y1 = clipy1; } else { h = 0; } } if(clipy2 < y1 + h) { if(y1 >= clipy2) { h = 0; } else { h = clipy2 - y1; } } cvlinexy(x, y1, h); cvlinexy(x2, y1, h); if(y + window->h >= clipy1 && y + window->h < clipy2) { cputcxy(x, y2, (char)CH_LLCORNER); chlinexy(x1, y2, window->w); cputcxy(x2, y2, (char)CH_LRCORNER); } } draw_window_contents(window, focus, clipy1, clipy2, x1, x2, y + 1, y2); #else /* CTK_CONF_WINDOWS */ draw_window_contents(window, focus, clipy1, clipy2, 0, window->w, 0, window->h); #endif /* CTK_CONF_WINDOWS */ }
/* ** There is a delay between when the VIC sends its signal, and when the display ** shows that signal. There is another delay between the display and when ** the lightpen says that it saw that signal. Each display and pen is different. ** Therefore, the driver must be calibrated to them. A white bar is painted on ** the screen; and, a line is drawn down the middle of it. When the user clicks ** on that line, the difference between its position and where the VIC thinks ** that the pen is pointing becomes an offset that is subtracted from what the ** VIC sees. */ void __fastcall__ pen_calibrate (unsigned char *XOffset) { unsigned char oldBg = bgcolor (COLOR_BLUE); unsigned char oldText = textcolor (COLOR_GRAY3); unsigned char oldRev = revers (1); unsigned char sprite0Color = VIC.spr_color[0]; unsigned char width, width2, height, height4, height8; struct mouse_info info; screensize (&width, &height); width2 = width / 2; height4 = height / 4; height8 = height4 * 8; /* Draw a bar and line. */ clrscr (); cclearxy (0, height4, height4 * width); cvlinexy (width2, height4 + 1, height4 - 2); revers (0); /* Print instructions. */ cputsxy (width2 - (sizeof COMMAND1) / 2, height / 2 + 1, COMMAND1); cputsxy (width2 - (sizeof COMMAND2) / 2, height / 2 + 3, COMMAND2); VIC.spr_color[0] = COLOR_GRAY2; mouse_show (); mouse_move (width2 * 8, height8 / 2); for (;;) { /* Wait for the main button to be released. */ do ; while ((mouse_buttons () & MOUSE_BTN_LEFT)); /* Wait for the main button to be pressed. */ do { mouse_info (&info); } while (!(info.buttons & MOUSE_BTN_LEFT)); /* Find out if the pen is on or off the bar. */ if (info.pos.y < height8 || info.pos.y >= height8 * 2) { break; } /* On the bar; adjust the offset. */ /* Characters are eight pixels wide. ** The VIC-II sees every other pixel; ** so, we use half of the difference. */ *XOffset += (info.pos.x - (width2 * 8 + 8/2)) / 2; } /* Off the bar; wait for the main button to be released. */ do ; while ((mouse_buttons () & MOUSE_BTN_LEFT)); mouse_hide (); VIC.spr_color[0] = sprite0Color; revers (oldRev); textcolor (oldText); bgcolor (oldBg); clrscr (); }
/*-----------------------------------------------------------------------------------*/ static void draw_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; unsigned char iconnum; char c, *text; unsigned char len; /* if(focus & CTK_FOCUS_WINDOW) { textcolor(WIDGETCOLOR_FWIN); if(focus & CTK_FOCUS_WIDGET) { textcolor(WIDGETCOLOR_FOCUS); } } else if(focus & CTK_FOCUS_DIALOG) { textcolor(WIDGETCOLOR_DIALOG); if(focus & CTK_FOCUS_WIDGET) { textcolor(WIDGETCOLOR_FOCUS); } } else { textcolor(WIDGETCOLOR); } */ xpos = x + w->x; ypos = y + w->y; switch(w->type) { case CTK_WIDGET_SEPARATOR: textcolor(VNC_OUT_SEPARATORCOLOR + focus); if(ypos >= clipy1 && ypos < clipy2) { /* chlinexy(xpos, ypos, w->w);*/ gotoxy(xpos, ypos); for(i = 0; i < w->w; ++i) { cputc(CH_SEPARATOR); } } break; case CTK_WIDGET_LABEL: textcolor(VNC_OUT_LABELCOLOR + focus); 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: textcolor(VNC_OUT_BUTTONCOLOR + focus); if(ypos >= clipy1 && ypos < clipy2) { if(focus & CTK_FOCUS_WIDGET) { revers(1); } else { revers(0); } cputcxy(xpos, ypos, CH_BUTTONLEFT); cputsn(w->widget.button.text, w->w); cputc(CH_BUTTONRIGHT); revers(0); } break; case CTK_WIDGET_HYPERLINK: textcolor(VNC_OUT_HYPERLINKCOLOR + focus); if(ypos >= clipy1 && ypos < clipy2) { /* if(focus & CTK_FOCUS_WIDGET) { textcolor(WIDGETCOLOR_HLINK_FOCUS); revers(0); } else { textcolor(WIDGETCOLOR_HLINK); revers(1); }*/ gotoxy(xpos, ypos); cputsn(w->widget.button.text, w->w); revers(0); } break; case CTK_WIDGET_TEXTENTRY: textcolor(VNC_OUT_TEXTENTRYCOLOR + focus); 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) { textcolor(VNC_OUT_TEXTENTRYCOLOR + (focus ^ 0x01)); revers(1); } else { revers(0); } if(c == 0) { cputc(' '); } else { cputc(c); } revers(0); textcolor(VNC_OUT_TEXTENTRYCOLOR + focus); } cputc('<'); } else { if(focus & CTK_FOCUS_WIDGET && 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; #if CTK_CONF_ICONS case CTK_WIDGET_ICON: if(ypos >= clipy1 && ypos < clipy2) { textcolor(VNC_OUT_ICONCOLOR + focus); if(focus & 1) { revers(1); } else { revers(0); } x = xpos; len = strlen(w->widget.icon.title); if(x + len >= sizex) { x = sizex - len; } gotoxy(x, ypos + 3); if(ypos >= clipy1 && ypos < clipy2) { cputs(w->widget.icon.title); } #if CTK_CONF_ICON_BITMAPS if(w->widget.icon.bitmap != NULL) { iconnum = vnc_out_add_icon((struct ctk_icon *)w); textcolor(iconnum | (focus << 6)); gotoxy(xpos, ypos); cputc(0x80); cputc(0x81); cputc(0x82); cputc(0x83); ++ypos; gotoxy(xpos, ypos); cputc(0x90); cputc(0x91); cputc(0x92); cputc(0x93); ++ypos; gotoxy(xpos, ypos); cputc(0xa0); cputc(0xa1); cputc(0xa2); cputc(0xa3); ++ypos; textcolor(0); /* for(i = 0; i < 3; ++i) { if(ypos >= clipy1 && ypos < clipy2) { cputc(w->widget.icon.textmap[0 + 3 * i]); cputc(w->widget.icon.textmap[1 + 3 * i]); cputc(w->widget.icon.textmap[2 + 3 * i]); } ++ypos; }*/ } #endif /* CTK_CONF_ICON_BITMAPS */ revers(0); } break; #endif /* CTK_CONF_ICONS */ default: break; } }
void main(void) { int i, j, n; unsigned char xsize, ysize, tcol, bgcol, bcol, inpos = 0; clrscr(); screensize(&xsize, &ysize); cputs("cc65 conio test\n\rInput: [ ]"); cputsxy(0, 2, "Colors:" ); tcol = textcolor(0); /* remember original textcolor */ bgcol = bgcolor(0); /* remember original background color */ bcol = bordercolor(0); /* remember original border color */ bgcolor(bgcol);bordercolor(bcol); for (i = 0; i < 3; ++i) { gotoxy(i,3 + i); for (j = 0; j < 16; ++j) { textcolor(j); cputc('X'); } } textcolor(tcol); cprintf("\n\n\r Screensize is: %dx%d", xsize, ysize ); chlinexy(0,6,xsize); cvlinexy(0,6,3); chlinexy(0,8,xsize); cvlinexy(xsize-1,6,3); cputcxy(0,6,CH_ULCORNER); cputcxy(xsize-1,6,CH_URCORNER); cputcxy(0,8,CH_LLCORNER); cputcxy(xsize-1,8,CH_LRCORNER); for (i = 0; i < 5; ++i) { gotoxy(xsize - 5,i); for (j = 0; j < 5; ++j) { cputc(grid[i][j]); } } gotoxy(0,ysize - 2 - ((256 + xsize) / xsize)); revers(1); for (i = 0; i < xsize; ++i) { cputc('0' + i % 10); } revers(0); for (i = 0; i < 256; ++i) { if ((i != '\n') && (i != '\r')) { cputc(i); } else { cputc(' '); } } while(wherex() > 0) { cputc('#'); } revers(1); for (i = 0; i < xsize; ++i) { cputc('0' + i % 10); } revers(0); cursor(1); for(;;) { gotoxy(8, 2); j = n & 1; revers(j); cputc(j ? 'R' : ' '); revers(j ^ 1); cputs(" revers"); revers(0); gotoxy(8 + inpos,1); i = cgetc(); if ((i >= '0') && (i<='9')) { textcolor(i - '0'); } else if (i == CH_CURS_LEFT) { inpos = (inpos - 1) & 7; } else if (i == CH_CURS_RIGHT) { inpos = (inpos + 1) & 7; } else if (i == CH_F5) { bgcol = (bgcol + 1) & 0x0f; bordercolor(bgcol); } else if (i == CH_F6) { bgcol = (bgcol - 1) & 0x0f; bordercolor(bgcol); } else if (i == CH_F7) { bgcol = (bgcol + 1) & 0x0f; bgcolor(bgcol); } else if (i == CH_F8) { bgcol = (bgcol - 1) & 0x0f; bgcolor(bgcol); } else { cputc(i); inpos = (inpos + 1) & 7; } ++n; } for(;;); }