void CUI_PEVol::draw(Drawable *S) { int i; if (S->lock()==0) { int window_width = 40 * col(1); int window_height = 12 * row(1); int start_x = (RESOLUTION_X / 2) - (window_width / 2); for(;start_x % 8;start_x--); int start_y = (RESOLUTION_Y / 2) - (window_height / 2); for(;start_y % 8;start_y--); S->fillRect(start_x,start_y,start_x + window_width,start_y + window_height,COLORS.Background); printline(start_x,start_y + window_height - row(1) + 1,148,window_width / 8, COLORS.Lowlight,S); for (i = start_y / row(1); i < (start_y + window_height) / row(1);i++) { printchar(start_x,row(i),145,COLORS.Highlight,S); printchar(start_x + window_width - row(1) + 1,row(i),146,COLORS.Lowlight,S); } printline(start_x,start_y,143,window_width / 8,COLORS.Highlight,S); print(col(textcenter("Volume Set for Block")),start_y + row(2),"Volume Set for Block",COLORS.Text,S); print(start_x + col(1), start_y + window_height / 2," Percent:",COLORS.Text,S); UI->draw(S); S->unlock(); need_refresh = need_popup_refresh = 0; updated++; } }
void render_end_sw( struct machine *oric ) { int i; Uint32 char_pitch; Uint8 *dst_pixel; char_pitch = 8 * pixel_size; if( oric->emu_mode == EM_RUNNING ) { if( oric->popupstr[0] ) { dst_pixel = (Uint8*)screen->pixels; dst_pixel += 320 * pixel_size; for( i=0; oric->popupstr[i]; i++, dst_pixel += char_pitch ) printchar( dst_pixel, oric->popupstr[i], gpal[1], gpal[0], SDL_TRUE ); } if( oric->statusstr[0] ) { dst_pixel = (Uint8*)screen->pixels; dst_pixel += 466 * screen->pitch; for( i=0; oric->statusstr[i]; i++, dst_pixel += char_pitch ) printchar( dst_pixel, oric->statusstr[i], gpal[1], 0, SDL_FALSE ); } } if( SDL_MUSTLOCK( screen ) ) SDL_UnlockSurface( screen ); SDL_COMPAT_Flip( screen ); }
void dumpcode(unsigned char *buff, int len) { int i; printk("----------BEGIN DUMP----------\n"); for(i=0;i<len;i++) { if(i%16==0) printk("0x%08X ",(int)&buff[i]); printk("%02X ",buff[i]); if(i%16-15==0) { int j; printk(" "); for(j=i-15;j<=i;j++) printchar(buff[j]); printk("\n"); } } if(i%16!=0) { int j; int spaces=(len-i+16-i%16)*3+2; for(j=0;j<spaces;j++) printk(" "); for(j=i-i%16;j<len;j++) printchar(buff[j]); } printk("\n"); printk("---------END DUMP----------\n"); }
/*when return is pressed, it returns with the finished buffer*/ void readstring(char* buffer) { int index=0; char c=0x00; /*wait for ENTER (0xd)*/ while (c!=0xd) { /*read a character from the keyboard*/ c=readchar(); /*if not backspace, put it in the buffer & print it*/ if (c!=8) { printchar(c); buffer[index]=c; index++; } /*if it is backspace, space over the last character*/ else if (index>0) { printchar(c); printchar(0x20); printchar(c); index--; } } /*put in a line feed and print it*/ buffer[index]=0xa; printchar(buffer[index]); /*terminate with a 0*/ buffer[index+1]=0; }
void main() { int x; a[0] = 12; a[1] = 10; a[2] = 8; a[3] = 6; a[4] = 4; a[5] = 2; x = a[5]; printint(x); // 2 printchar(10); printint(a[0]); // 12 printchar(10); printint(10+a[1]); // 20 printchar(10); x = a[2]*10 + a[3] + a[4]; printint(x); // should be 90 printchar(10); }
static int prints(char **out, const char *string, int width, int pad) { register int pc = 0, padchar = ' '; if (width > 0) { register int len = 0; register const char *ptr; for (ptr = string; *ptr; ++ptr) ++len; if (len >= width) width = 0; else width -= len; if (pad & PAD_ZERO) padchar = '0'; } if (!(pad & PAD_RIGHT)) { for ( ; width > 0; --width) { printchar (out, padchar); ++pc; } } for ( ; *string ; ++string) { printchar (out, *string); ++pc; } for ( ; width > 0; --width) { printchar (out, padchar); ++pc; } return pc; }
/* print a string and an int */ void simple_serial_print_strint(char *s, uint16_t i) { uint8_t intprinted = 0; char c = 'A'; while(c != 0) { c = *s++; if(c == '\\' && *s == 'n') { /* print line return and continue */ printchar('\n'); s++; } else if(c == '\\' && *s == 't') { printchar('\t'); s++; } else if(c == '%' && *s == 'u') { intprinted = 1; simple_serial_print_u16(i); } else { printchar(c); } } if(intprinted == 0) { simple_serial_print_u16(i); } printchar('\n'); }
watchdog_interrupt(void) { #ifdef CONTIKI_TARGET_SKY #if PRINT_STACK_ON_REBOOT uint8_t dummy; static uint8_t *ptr; static int i; ptr = &dummy; printstring("Watchdog reset"); printstring("\nStack at $"); hexprint(((int)ptr) >> 8); hexprint(((int)ptr) & 0xff); printstring(":\n"); for(i = 0; i < 64; ++i) { hexprint(ptr[i]); printchar(' '); if((i & 0x0f) == 0x0f) { printchar('\n'); } } printchar('\n'); #endif /* PRINT_STACK_ON_REBOOT */ #endif /* CONTIKI_TARGET_SKY */ watchdog_reboot(); }
int vprintk(const int8 * format, char * ap) { int pc; //printf的返回值 pc = 0; for (; *format != '\0'; ++format) { if (*format == '%') { ++format; if ((*format) == 'c') { printchar(va_arg(ap, int)); pc++; } else if (*format == 'd') { printi(va_arg(ap, int)); pc++; } else if (*format == 's') { prints((va_arg(ap, char*))); pc++; } else if (*format == 'x') { printx((va_arg(ap, int))); pc++; } else { printchar(*format); pc++; } } else { printchar(*format); pc++; } } return pc; }
int mycompare(const char *student, const char *model, char *infostr) { int i = 0, line = 1; char bufS[16] = { 0 }; char bufM[16] = { 0 }; while(*student) { printchar(bufS, *student); printchar(bufM, *model); if (!(*model)) { sprintf(infostr, "your output is longer than expected: character: '%s', position: %d, line: %d\n", bufS, i+1, line); return -1; } if (*student != *model) { sprintf(infostr, "position: %d, line: %d, your output: '%s' , expected: '%s'\n", i+1, line, bufS, bufM); return -1; } if (*student == '\n') { line++; i = -1; } student++; model++; i++; } if (*model) { printchar(bufM, *model); sprintf(infostr, "output correct until position: %d, line: %d, but shorter than expected. Next character should be '%s'\n", i+1, line, bufM); return -1; } return 0; }
static int prints(char **out, const char *string, int width, int pad, int printlimit, bool IsNumber) { register int pc = 0, padchar = ' '; int i,len; if (width > 0) { register int len = 0; register const char *ptr; for (ptr = string; *ptr; ++ptr) ++len; if (len >= width) width = 0; else width -= len; if (pad & PAD_ZERO) padchar = '0'; } if (!(pad & PAD_RIGHT)) { for ( ; width > 0; --width) { printchar (out, padchar); ++pc; } } if( false == IsNumber ) { // The string to print is not the result of a number conversion to ascii. /* For a string, printlimit is the max number of characters to display. */ for ( ; printlimit && *string ; ++string, --printlimit) { printchar (out, *string); ++pc; } } if( true == IsNumber ) { // The string to print represents an integer number. /* In this case, printlimit is the min number of digits to print. */ /* If the length of the number to print is less than the min nb of i digits to display, we add 0 before printing the number. */ len = strlen(string); if( len < printlimit ) { i = printlimit - len; for(; i; i--) { printchar (out, '0'); ++pc; } } } /* Else: The string to print is not the result of a number conversion to ascii. * For a string, printlimit is the max number of characters to display. */ for ( ; printlimit && *string ; ++string, --printlimit) { printchar (out, *string); ++pc; } for ( ; width > 0; --width) { printchar (out, padchar); ++pc; } return pc; }
// Assuming n is in [0, 15]. static void printHexDigit(uint8 n) { if (n < 10) { printchar((char)('0' + n)); } else { printchar((char)(('a' - 10) + n)); } }
static void printulhex(unsigned long addr) { unsigned long lu = addr / 0x10; if (lu) printulhex(lu); lu = addr % 0x10; if (lu < 10) printchar(lu + '0'); else printchar(lu % 10 + 'A'); }
void PrintInfo(char *name, unsigned long int sernum, unsigned long int RegNum) { int x; char temp[201]; printchar(ESC); printchar('E'); printchar(ESC); printstring("(10U"); // Ascii characters printchar(ESC); printstring("(s14V"); // 12 points printchar(ESC); printstring(")10U"); // Ascii characters printchar(ESC); printstring(")s14V"); // 12 points printchar(ESC); printstring("&l0O"); // print orientation 0=norm 1=portrait 2=rev norm 3= rev port for(x=0;x<59;x++) printstring("\n\r"); printstring( " ���������������������������������������������������������������Ŀ\n\r"); sprintf(temp," � User Name: %30s �\n\r",name); printstring(temp); sprintf(temp," � Serial Number: %30lu �\n\r",sernum); printstring(temp); sprintf(temp," � Registration Number: %30lu �\n\r",RegNum); printstring(temp); printstring( " �����������������������������������������������������������������\n\r"); printstring("\n\r"); printchar(ESC); // reset printer command printchar('E'); // ie. Form Feed }
int printf(const char *format, ...) { char const *p = format; char buf[20]; void *args = (&format + 1); int argn = 0; bool isfmt = false; int len = 0; do { if(*p == '\0') break; if(!isfmt && *p != '%') { printchar(*p); len++; } else if(isfmt) { switch(*p) { case 'c': printchar(((char*)args)[argn++]); len++; break; case 's': printstr(((char**)args)[argn]); len += (int)strlen(((char**)args)[argn++]); break; case 'd': len += (int)strlen(itoa(((int*)args)[argn++], buf, 10)); printstr(buf); break; case 'u': len += (int)strlen(utoa(((uint*)args)[argn++], buf, 10)); printstr(buf); break; case 'o': len += (int)strlen(utoa(((uint*)args)[argn++], buf, 8)); printstr(buf); break; case 'x': case 'p': len += (int)strlen(utoa(((uint*)args)[argn++], buf, 16)); printstr(buf); break; case '%': printchar('%'); len++; break; default: return -1; } isfmt = false; } else if(*p == '%') { isfmt = true; } } while(*p++); return len; }
int main(void) { /* Start led connected to P1.29 and P1.18 */ LPC_GPIO1->FIODIR |= 0x20040000; LPC_GPIO1->FIOSET |= (1 << 29); LPC_GPIO1->FIOCLR |= (1 << 18); SystemInit(); // lpc1768_startup.c SystemCoreClockUpdate(); GPIOInit(); TimerInit(); ValueInit(); ADCInit(); comm_init(); // welcomeMsg(); set_echo(); easyWEB_init(); printchar("at+ndhcp=1\r"); printchar("at+wa=greenet\r"); printchar("at+nstcp=20\r"); printchar(" \b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); while(1) { easyWEB_s_loop(); //handle_command(); //UART command if(UpdateChannel >= 3) { UpdateChannel = -1; ADCRead(0); if (mode ==1) //decide which ADC channel to read when the converter is working in different direction { Vout = ADCValues(0); Vin = ADCValues(1); } else { Vout = ADCValues(1); Vin = ADCValues(0); } Iref = ADCValues(2); Il = abs (ADCValues(3) - Iref); //get the correct inductor current MeanValues(); BangBang(); LPC_GPIO1->FIOPIN ^= (1 << 29); LPC_GPIO1->FIOPIN ^= (1 << 18); } } return 0; }
int length_greater_than_one(char c, int length, int n){ int i, j; for (i = 0; i < n; i++) { //turn for(j=1; j<=length; j++){ printchar(c,j); } for(j=length-1; j>=2; j--){ printchar(c,j); } } return 0; }
int mycompare_new(const char *student, const char *model, char *infostr, size_t n) { int i = 0, line = 1; char bufS[16] = { 0 }; char bufM[16] = { 0 }; const char *origs = student; const char *origm = model; char sturef[80]; char modref[80]; while(*student) { printchar(bufS, *student); printchar(bufM, *model); if (!(*model)) { showref(sturef, origs, student, 80); showref(modref, origm, model, 80); snprintf(infostr, n, "your output is longer than expected at position: %d, line: %d (char: '%s')\n" "Your string: ...\"%s\"...\n" "Reference string: ...\"%s\"...", i+1, line, bufS, sturef, modref); return -1; } if (*student != *model) { showref(sturef, origs, student, 80); showref(modref, origm, model, 80); snprintf(infostr, n, "difference on position: %d, line: %d (char: '%s' vs. '%s')\n" "Your string: ...\"%s\"...\n" "Reference string: ...\"%s\"...", i+1, line, bufS, bufM, sturef, modref); return -1; } if (*student == '\n') { line++; i = -1; } student++; model++; i++; } if (*model) { printchar(bufM, *model); showref(sturef, origs, student, 80); showref(modref, origm, model, 80); snprintf(infostr, n, "output correct until position: %d, line: %d, but shorter than expected (missing char: '%s').\n" "Your string: ...\"%s\"...\n" "Reference string: ...\"%s\"...", i+1, line, bufM, sturef, modref); return -1; } return 0; }
/*---------------------------------------------------------------------------*/ static void printstring(char *s) { while(*s) { printchar(*s++); } }
/*---------------------------------------------------------------------------*/ static void hexprint(uint8_t v) { const char hexconv[] = "0123456789abcdef"; printchar(hexconv[v >> 4]); printchar(hexconv[v & 0x0f]); }
/*{{{ printstr*/ void printstr(int x, int y, const char *s) { while (*s) { printchar(x, y, *s++); x += font->head.wide; } }
void console_write_line(const char* str) { console_write(str); unsigned space_count = WIDTH - ((scr_count/2) % WIDTH); for (; space_count; space_count--) printchar(' '); }
static void printul(unsigned long ul) { unsigned long lu = ul / 10; if (lu) printul(lu); lu = ul % 10; printchar(lu + '0'); }
/* Handles the keyboard interrupt */ void keyboard_handler(struct regs *r) { unsigned char scancode; /* Read from the keyboard's data buffer */ scancode = inportb(0x60); /* If the top bit of the byte we read from the keyboard is * set, that means that a key has just been released */ if (scancode & 0x80) { /* You can use this one to see if the user released the * shift, alt, or control keys... */ } else { /* Here, a key was just pressed. Please note that if you * hold a key down, you will get repeated key press * interrupts. */ /* Just to show you how this works, we simply translate * the keyboard scancode into an ASCII value, and then * display it to the screen. You can get creative and * use some flags to see if a shift is pressed and use a * different layout, or you can add another 128 entries * to the above layout to correspond to 'shift' being * held. If shift is held using the larger lookup table, * you would add 128 to the scancode when you look for it */ printchar(kbdus[scancode]); } }
void main() { int n,m,i,hash[26]={0}; char str1[50],str2[50]; gets(str1); gets(str2); n=strlen(str1); m=strlen(str2); for(i=0;i<n;i++) { if(str1[i]!='\0') { hash[str1[i]-'a']++;//Acii value of a=65 } } for(i=0;i<m;i++) { if(str2[i]!='\0') { hash[str2[i]-'a']++; } } for(i=0;i<26;i++) { printchar(i+'a',hash[i]); //reconverting from acii value } return 0; }
void clearLine(){ int oldpos = typeOffset; do{ printchar(' '); }while(typeOffset/2%VGA_W!=0); typeOffset = oldpos; }
void do_intr_keyboard(void) { unsigned char keycode; unsigned char keymapcol = NO_SHIFT; /* NO_SHIFT = 0 */ unsigned char scan_code = inb(0x60); /* 读取扫描码 */ if ((scan_code & 0x80) == MAKE) { if ((scan_code != SHIFT_L) && (scan_code != SHIFT_R)) { if ((keycode = headqueue()) == SHIFT_L || keycode == SHIFT_R) keymapcol = WITH_SHIFT; printchar(keymap[scan_code*MAP_COL+keymapcol]); /* MAP_COL=3 */ } else if ((scan_code == SHIFT_L) || (scan_code == SHIFT_R)) { enqueue(scan_code); } else /* do nothing */; } else if ((scan_code & 0x80) == BREAK) { if (((scan_code & 0x7F) == SHIFT_L) || ((scan_code & 0x7F) == SHIFT_R)) dequeue(); } else /* do nothing */; /* 复位 8259A 的正在服务寄存器(ISR)。 因为在 setup 中设置 8259A 工作在非自动结束方式,主芯片 IRQ2 连接从芯片, 所以复位时要把 IRQ2 置位,其余的都复位。8259A 主芯片的端口地址是 0x20 */ outb_p(0x20, 0x20); /* outb_p(value, port) */ }
VOID util_hexdmp(FILE *fp, UINT8 *ptr, INT32 count, INT32 off, CHAR obase) { INT32 whole_lines; INT32 num_last; INT32 line, byte, base; CHAR *format; INT32 bytes_per_line = 16; switch (obase) { case 'x': format = hex_format; break; case 'X': format = heX_format; break; case 'd': case 'D': format = dec_format; break; case 'o': case 'O': format = oct_format; break; default: format = hex_format; } num_last = count % bytes_per_line; whole_lines = (count - num_last) / bytes_per_line; for (line = 0; line < whole_lines; line++) { fprintf(fp, format, off); base = line*bytes_per_line; for (byte = 0; byte < bytes_per_line; byte++) { fprintf(fp, " %02x",ptr[byte+base]); } fprintf(fp, " | "); for (byte = 0; byte < bytes_per_line; byte++) { fprintf(fp, "%c",printchar(ptr[byte+base])); } off += bytes_per_line; fprintf(fp, "\n"); } if (num_last != 0) { fprintf(fp, format, off); base = line*bytes_per_line; for (byte = 0; byte < num_last; byte++) { fprintf(fp, " %02x",ptr[byte+base]); } for (byte = num_last; byte < bytes_per_line; byte++) { fprintf(fp, " "); } fprintf(fp, " | "); for (byte = 0; byte < num_last; byte++) { fprintf(fp, "%c",printchar(ptr[byte+base])); } fprintf(fp, "\n"); } }
static void print(const char* str, uint8_t color) { const char* s; for(s=str; *s; s++) { printchar(*s, color, false); } }
void printCharToConsole(char c){ printchar(c); if(((typeOffset/2)/VGA_W)==VGA_H){ scroll(); typeOffset = typeOffset-VGA_W*2; } updateCursor(typeOffset/2); }