void display_board(board *b) { int x, y; if (alt_video_page) { outpage(2); } else { outpage(4); } textcolour(7); clearscr(); movecur(30, 7); os_long_int_to_string(&score, 10, conv_buffer); strout("Score: "); strout(conv_buffer); for (y = 0; y < brd_h; y++) { movecur(30, y * 2 + 8); strout(seperator); movecur(30, y * 2 + 9); for (x = 0; x < brd_w; x++) { charout('|'); if ((*b)[y][x] < 10000) charout(' '); if ((*b)[y][x] < 1000) charout(' '); if ((*b)[y][x] < 100) charout(' '); if ((*b)[y][x] < 10) charout(' '); if ((*b)[y][x] == 0) { charout(' '); } else { strout(os_int_to_string((*b)[y][x])); } } charout('|'); } movecur(30, 16); strout(seperator); if (alt_video_page) { viewpage(2); alt_video_page = 0; } else { viewpage(4); alt_video_page = 1; } }
int printf(char *fmt, ...) { int i = 0; int printed = 0; char *arg = (char*)&fmt + sizeof(char*); char *str; if (fmt[0] == '\0') { return 0; } do { if (fmt[i] == '\n') { os_print_newline(); printed += 2; continue; } else if (fmt[i] != '%') { os_print_char(fmt[i]); printed++; continue; } switch (fmt[++i]) { case 'd': case 'i': str = os_sint_to_string(*(int*)arg); printed += os_string_length(str); os_print_string(str); arg += sizeof(int); break; case 'u': str = os_int_to_string(*(int*)arg); printed += os_string_length(str); os_print_string(str); arg += sizeof(int); break; case 'x': case 'X': os_print_4hex(*(int*)arg); printed += 4; arg += sizeof(int); break; case 'c': os_print_char(*arg); printed++; arg += sizeof(int); break; case 's': str = *(char**)arg; printed += os_string_length(str); os_print_string(str); arg += sizeof(char*); break; case 'p': os_print_string("0x"); os_print_4hex(*(int*)arg); printed += 6; arg += sizeof(int); break; case 'n': *(int*)arg = printed; arg += sizeof(int*); break; case '%': os_print_char('%'); printed++; break; } } while (fmt[++i]); return printed; }