void update_data(void){ unit++; lastime++; if (unit >= Freq){ unit = 0; cnt = cnt + 1 ; if (cnt >= 9){ cnt = 0; level ++; } if (level < 10) cputint(level, 7, 30, white); else cputint(level, 7, 29, white); sec++; if (sec >= 60){ sec = 0; min++; } if (min < 10){ cputc('0', 10, 27, white); cputint(min, 10, 28, white); } else cputint(min, 10, 27, white); cputc(':', 10, 29, white); if (sec < 10){ cputc('0', 10, 30, white); cputc(sec+'0', 10, 31, white); } else cputint(sec, 10, 30, white); } }
/* the only characters that have special meaning in a code block are * `<' and `&' , which are /always/ expanded to < and & */ static void code(int escape, MMIOT *f) { int c; if ( escape && (peek(f,1) == ' ') ) shift(f,1); while ( (c = pull(f)) != EOF ) { switch (c) { case ' ': if ( peek(f,1) == '`' && endofcode(escape, 1, f) ) return; Qchar(c, f); break; case '`': if ( endofcode(escape, 0, f) ) return; Qchar(c, f); break; case '\\': cputc(c, f); if ( peek(f,1) == '>' || (c = pull(f)) == EOF ) break; default: cputc(c, f); break; } } } /* code */
void __fastcall drawBox( unsigned char x, unsigned char y, unsigned char w, unsigned char h, unsigned char color, unsigned reverse) { unsigned char i; //textcolor(color); revers(reverse); // draw frame #ifdef __APPLE2ENH__ textframexy(x, y, w + 1, h + 1, TEXTFRAME_TALL); #else for(i=x+w-1; i>x; i--) { gotoxy(i, y); cputc('-'); gotoxy(i, y+h); cputc('-'); } for(i=y+h-1; i>y; i--) { gotoxy(x, i); cputc('!'); if(x+w < size_x) gotoxy(x+w, i); cputc('!'); } #endif // draw body for(i=y+1; i<y+h; ++i) { cclearxy(x + 1, i, w - 1); } }
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); }
// helper function to put the string out - string will be modified and is // expected to be 256 chars in length int fmt_print(char *s, int zero, int width, int left, int precis, int plus) { int cnt = 0; int i = strlen(s); int pad = ' '; if (zero) pad = '0'; if ((precis > 0) && (i >= precis)) { i = precis; if (plus) --i; } if ((plus) && (width > 0)) --width; if (width <= 0) { if (plus) { cputc('+'); ++cnt; } for (int idx=0; idx<i; ++idx) { cputc(*(s++)); ++cnt; } } else { if (left) { if (plus) { cputc('+'); ++cnt; } for (int idx=0; idx<i; ++idx) { cputc(*(s++)); ++cnt; } for (int idx=0; idx<width-i; ++idx) { cputc(' '); ++cnt; } } else { if ((plus)&&(zero)) { cputc('+'); plus = 0; ++cnt; } for (int idx=0; idx<width-i; ++idx) { cputc(pad); ++cnt; } if (plus) { cputc('+'); ++cnt; } for (int idx=0; idx<i; ++idx) { cputc(*(s++)); ++cnt; } } } return cnt; }
void stack_size(void) { static unsigned char *c; static unsigned int s; c = (unsigned char *)(0xBF00 - STACK_SIZE); while(*c++ == 0xA2) { } s = (unsigned char *)0xBF00 - c; clrscr(); cputc('0' + s / 100 % 10); cputc('0' + s / 10 % 10); cputc('0' + s % 10); cgetc(); }
/* test which outputs every possible char, reads it back ** from screen memory, outputs again at the next char position ** and compares the two screen memory bytes on identity */ int testCPeekC(char ch){ /* Test the given charcode on special characters NEWLINE,LINEFEED and ** TAB */ if ( ('\n' !=ch) && ('\r' !=ch) && ('\t' != ch) ){ /* go on if not special char according to prev comment */ unsigned char ch2_a, ch2_b; /* output char to the screen */ cputc(ch); /* move cursorpos to previous output */ chBack(); /* get back written char including the translation scrcode->asc */ ch2_a = cpeekc(); /* get back written char without translation */ ch2_b = peekChWithoutTranslation(); /* move cursor to following writing position */ chForth(); /* output again the char which was read back by cpeekc */ cputc(ch2_a); /* move cursorpos to previous output */ chBack(); /* get back second written char without translation and compare it to ** the previously written char without translation */ if ( peekChWithoutTranslation() == ch2_b ){ /* test succesful * move cursor to following writing position */ chForth(); return EXIT_SUCCESS; } /* test NOT succesful ** output diagnostic and return FAILURE */ cprintf("\n\rError on char: 0x%x. was 0x%x instead", ch, ch2_a); return EXIT_FAILURE; } cputc('.'); cputc('.'); return EXIT_SUCCESS; }
void renderMenu(uint8_t current) { uint8_t idx = 0; textcolor(1); revers(1); gotoxy(0, 0); for (idx = 0; idx < menuSize; idx++) { if (idx == current) { textcolor(3); cputs(menu[idx]); /*****************/ cputsxy(0, 1, "\xf0\xc0\xc0\xc0\xc0\xee"); gotoxy(0, 2); cprintf("\xdd%s\xdd", fileMenu[0]); gotoxy(0, 3); cprintf("\xdd%s\xdd", fileMenu[1]); gotoxy(0, 4); cprintf("\xdd%s\xdd", fileMenu[2]); gotoxy(0, 5); cprintf("\xdd%s\xdd", fileMenu[3]); cputsxy(0, 6, "\xed\xc0\xc0\xc0\xc0\xfd"); /*****************/ } else { cputs(menu[idx]); } textcolor(1); cputs(" "); } for (idx = wherex(); idx < 40; idx++) { cputc(' '); } }
int main() { clrscr(); bordercolor(0); bgcolor(6); renderMenu(100); textcolor(7); gotoxy(0, 1); updateStatus(' '); cursor(1); while(1) { char c; /* uint8_t row; uint8_t col; for (row = 0; row < 16; row++) { gotoxy(0, row + 3); cprintf("%3d ", row * 16); for (col = 0; col < 16; col++) { cputc(row * 16 + col); cputc(' '); } } */ c = cgetc(); if (c == 20) { // backspace } else if (c == 13) { // Return } else if (c == 157) { // Left uint8_t xpos = wherex() - 1; gotox(xpos); } else if (c == 29) { // Right uint8_t xpos = wherex() + 1; gotox(xpos); } else if (c == 17) { // Down uint8_t ypos = wherey() + 1; gotoy(ypos); } else if (c == 145) { // Up uint8_t ypos = wherey() - 1; gotoy(ypos); } else if (c == 19) { // Pos1 } else if (c == 3) { // ESC -> Menu processMenu(); } else { cputc(c); } updateStatus(c); } }
/* * get_input_terminated_by() reads input (handling backspace correctly) until * a terminator of |terminators| is encountered or |out| is full (outlen-1 * characters were read). * * get_input_terminated_by() returns the terminator it encountered. * */ input_terminator_t get_input_terminated_by(input_terminator_mask_t terminators, char *out, BYTE outlen) { BYTE i = strlen(out); BYTE c, x, y; x = wherex() - i; y = wherey(); while (1) { c = cgetc(); if (((terminators & INPUT_TERMINATOR_RETURN) == INPUT_TERMINATOR_RETURN) && (c == PETSCII_CR)) { return INPUT_TERMINATOR_RETURN; } else if (((terminators & INPUT_TERMINATOR_SPACE) == INPUT_TERMINATOR_SPACE) && (c == PETSCII_SP)) { return INPUT_TERMINATOR_SPACE; } else if (c == PETSCII_DEL) { /* If you are at the left-most position, do nothing */ if (i == 0) continue; out[--i] = '\0'; cputcxy(x+i, y, ' '); gotoxy(x+i, y); continue; } if (i == (outlen-1)) { continue; } cputc(c); out[i++] = c; } }
/*-----------------------------------------------------------------------------------*/ void ctk_draw_menus(struct ctk_menus *menus) { struct ctk_menu *m; /* Draw menus */ (void)textcolor(MENUCOLOR); gotoxy(0, 0); revers(1); cputc(' '); for(m = menus->menus->next; m != NULL; m = m->next) { draw_menu(m, m == menus->open); } /* Draw desktopmenu */ if(wherex() + strlen(menus->desktopmenu->title) + 1 >= sizex) { gotoxy(sizex - (unsigned char)strlen(menus->desktopmenu->title) - 1, 0); } else { cclear(sizex - wherex() - (unsigned char)strlen(menus->desktopmenu->title) - 1); } draw_menu(menus->desktopmenu, menus->desktopmenu == menus->open); revers(0); }
char *interactively_read_line(const char *prompt) { const char DELETE = '\x7f'; const char BACKSPACE = '\x08'; bool line_is_complete = false; char c; size_t count = 0; cputs(prompt); while (! line_is_complete) { c = interactively_read_char(); if (count > 0 && (c == DELETE || c == BACKSPACE)) { erase_backward(1); count--; } else if (c == '\r') { line[count] = '\0'; line_is_complete = true; } else if (count < LINE_CAPACITY - 1) { cputc(c); line[count++] = c; } else { line[count] = '\0'; line_is_complete = true; } } cputs("\r\n"); return line; }
void draw_menu(struct ctk_menu *m, struct ctk_menu *open) { #if CC_CONF_UNSIGNED_CHAR_BUGS unsigned char x2; unsigned int x, y; #else unsigned char x2; unsigned char x, y; #endif x = cursx; cputs(m->title); cputc(CH_SPACE); if (m == open) { x2 = cursx; if(x + CTK_CONF_MENUWIDTH > SCREEN_WIDTH) { x = SCREEN_WIDTH - CTK_CONF_MENUWIDTH; } for(y = 0; y < m->nitems; y++) { if(y == m->active) { revers(0); } gotoxy(x, y + 1); if(m->items[y].title[0] == '-') { chline(CTK_CONF_MENUWIDTH); } else { cputs(m->items[y].title); } clearTo(x + CTK_CONF_MENUWIDTH); revers(1); } gotoxy(x2, 0); } }
/*---------------------------------------------------------------------------*/ void cputsn(char *str, unsigned char len) { while ((len > 0) && (*str != 0)) { cputc(*str); str++; len--; } }
/* Clear part of a line (write length spaces). */ void __fastcall__ cclear( unsigned char length ) { while( length ) { cputc( ' ' ); --length; } }
char interactively_read_char() { unsigned char x; char c; x = wherex(); revers(true); cputc(' '); gotox(x); c = cgetc(); revers(false); cputc(' '); gotox(x); return c; }
void cvline(unsigned char length) { while (length > 0) { cputc(CH_VERTLINE); ++cursy; --cursx; length--; } }
void platform_dputc(char c) { #if WITH_CGA_CONSOLE cputc(c); #else uart_putc(c); #endif }
void print_nibble(U8 val) { static const U8 hextab[] = { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46 }; cputc(hextab[val]); }
/* Output a horizontal line with the given length starting at the current * cursor position. */ void __fastcall__ chline( unsigned char length ) { while( length ) { cputc( 0 ); --length; } }
/*-----------------------------------------------------------------------------------*/ void cclear(unsigned char length) { int i; for(i = 0; i < length; ++i) { cputc(' '); } }
void cputs(char *s) { char c; while (*s != '\0') { c = *s++; cputc(c); } }
/*-----------------------------------------------------------------------------------*/ void chline(unsigned char length) { int i; for(i = 0; i < length; ++i) { cputc('-'); } }
void pciscan(Console c) { for (u8 bus = 0; bus < 255; bus++) { for (u8 dev = 0; dev < 32; dev++) { PciConf conf = pciconfread(bus, dev); if ((conf.device_id == 0xffff) || (conf.vendor_id == 0xffff)) { continue; } cprint(c, "pci(bus,dev): ("), cprintint(c, bus, 16, 0), cputc(c, ','), cprintint(c, dev, 16, 0), cputc(c, ')'), cnl(c); cprint(c, "device id: "), cprintint(c, conf.device_id, 16, 0), cnl(c); cprint(c, "vendor id: "), cprintint(c, conf.vendor_id, 16, 0), cnl(c); for (int i = 0; i < 6; ++i) { u64 size = conf.dev.base_address_register[i].size; if (size) { switch (conf.dev.base_address_register[i].tag) { case PciBarInvalid: { cprint(c, " Invalid bar:"); break; } case PciBarM16: { cprint(c, " M16 Bar:"); break; } case PciBarM32: { cprint(c, " M32 Bar:"); break; } case PciBarM64: { cprint(c, " M64 Bar:"); break; } case PciBarIO: { cprint(c, " IO Bar:"); break; } } cprintint(c, conf.dev.base_address_register[i].size, 16, 0); } } cnl(c); } } }
/*-----------------------------------------------------------------------------------*/ void ctk_draw_menus(struct ctk_menus *menus) { struct ctk_menu *m; /* Draw menus */ textcolor(VNC_OUT_MENUCOLOR); gotoxy(0, 0); revers(1); cputc(' '); for(m = menus->menus->next; m != NULL; m = m->next) { if(m != menus->open) { update_area(wherex(), 0, strlen(m->title) + 1, 1); cputs(m->title); cputc(' '); } else { draw_menu(m); } } if(wherex() + strlen(menus->desktopmenu->title) + 1>= sizex) { gotoxy(sizex - strlen(menus->desktopmenu->title) - 1, 0); } else { cclear(sizex - wherex() - strlen(menus->desktopmenu->title) - 1); update_area(wherex(), 0, sizex - wherex() - strlen(menus->desktopmenu->title) - 1, 1); } /* Draw desktopmenu */ if(menus->desktopmenu != menus->open) { update_area(wherex(), 0, strlen(menus->desktopmenu->title) + 1, 1); cputs(menus->desktopmenu->title); cputc(' '); } else { draw_menu(menus->desktopmenu); } revers(0); }
/* Output a NUL-terminated string at the current cursor position */ void __fastcall__ cputs( const char* s ) { while( *(unsigned char *)(s) != 0 ) { cputc( *(unsigned char *)s++ ); } }
/*---------------------------------------------------------------------------*/ void draw_window_sub(struct ctk_window *window, unsigned char focus) { unsigned char x, y; unsigned char x1, y1, x2; struct ctk_widget *w; unsigned char wfocus; x = window->x; y = window->y + 1; x1 = x + 1; y1 = y + 1; x2 = x1 + window->w; // |_ gotoxy(x, y1); cvline(window->h); cputc(CH_LLCORNER); chline(window->w); cputc(CH_LRCORNER); // - gotoxy(x, y); cputc(CH_ULCORNER); chline(window->w); cputc(CH_URCORNER); // | gotoxy(x2, y1); cvline(window->h); /* Draw inactive widgets. */ for(w = window->inactive; w != NULL; w = w->next) { draw_widget(w, x1, y1, focus); } /* Draw active widgets. */ for(w = window->active; w != NULL; w = w->next) { wfocus = focus; if(w == window->focused) { wfocus |= CTK_FOCUS_WIDGET; } draw_widget(w, x1, y1, wfocus); } }
void platform_dputc(char c) { if (c == '\n') platform_dputc('\r'); #if WITH_CGA_CONSOLE cputc(c); #else uart_putc(c); #endif }
void main() { clrscr(); cputs(get_machine_hardware_name()); cputc(' '); cputs(get_cpu_name()); cputs("\r\n"); getchar(); }