static void print_statement(void) { uint8_t nonl; uint8_t t; uint8_t nv = 0; do { t = current_token; nonl = 0; DEBUG_PRINTF("Print loop\n"); if (nv == 0) { if(t == TOKENIZER_STRING) { /* Handle string const specially - length rules */ tokenizer_string_func(charout, NULL); tokenizer_next(); nv = 1; continue; } else if(TOKENIZER_STRINGEXP(t)) { charoutstr(stringexpr()); nv = 1; continue; } else if(TOKENIZER_NUMEXP(t)) { intout(intexpr()); nv = 1; continue; } else if(t == TOKENIZER_TAB) { nv = 1; accept_tok(TOKENIZER_TAB); chartab(bracketed_intexpr()); continue; } else if(t == TOKENIZER_AT) { int x,y; nv = 1; accept_tok(TOKENIZER_AT); y = intexpr(); accept_tok(TOKENIZER_COMMA); x = intexpr(); if (move_cursor(x,y)) chpos = x; continue; } } nv = 0; if(t == TOKENIZER_COMMA) { charout('\t', NULL); nonl = 1; tokenizer_next(); } else if(t == TOKENIZER_SEMICOLON) { nonl = 1; tokenizer_next(); } else if (!statement_end()) { syntax_error(); break; } } while(!statement_end()); if (!nonl) charout('\n', 0); DEBUG_PRINTF("End of print\n"); }
static void input_statement(void) { struct typevalue r; var_t v; char buf[129]; uint8_t t; uint8_t first = 1; int l; t = current_token; if (t == TOKENIZER_STRING) { tokenizer_string_func(charout, NULL); tokenizer_next(); t = current_token; accept_either(TOKENIZER_COMMA, TOKENIZER_SEMICOLON); } else { charout('?', NULL); charout(' ', NULL); } begin_input(); /* Consider the single var allowed version of INPUT - it's saner for strings by far ? */ do { int n = 0; struct typevalue s[MAX_SUBSCRIPT]; if (!first) accept_either(TOKENIZER_COMMA, TOKENIZER_SEMICOLON); first = 0; t = current_token; v = tokenizer_variable_num(); accept_either(TOKENIZER_INTVAR, TOKENIZER_STRINGVAR); if (current_token == TOKENIZER_LEFTPAREN) n = parse_subscripts(s); /* FIXME: this works for stdin but not files .. */ if ((l = read(0, buf + 1, 128)) <= 0) { write(2, "EOF\n", 4); exit(1); } charreset(); /* Newline input so move to left */ if (t == TOKENIZER_INTVAR) { r.type = TYPE_INTEGER; /* For now */ r.d.i = atoi(buf + 1); /* FIXME: error checking */ } else { /* Turn a C string into a BASIC one */ r.type = TYPE_STRING; if (buf[l-1] == '\n') l--; *((uint8_t *)buf) = l; r.d.p = (uint8_t *)buf; } ubasic_set_variable(v, &r, n, s); } while(!statement_end()); end_input(); }
static void charout(unsigned char c) { if (c == 7) { do_beep(); return; } if (c == 8) { cursorx--; goto fix; } if (c == 9) { do { charout(' '); } while (cursorx%8); goto fix; } if (c == 10) { cursory++; goto fix; } if (c == 13) { cursorx = 0; return; } if (c == 0x1b) { vtmode = 1; return; } plot_char(cursory, cursorx, c); cursorx++; fix: cursor_fix(); }
static INLINE void foundstr (address pc, address ltemp) { charout ('s'); #ifdef DEBUG printf (" * FOUND STRING AT %x - %x \n", pc, ltemp); #endif regist_label (pc, DATLABEL | STRING); }
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; } }
static void charout(char c, void *unused) { if (c == '\t') { do { charout(' ', NULL); } while(chpos%8); return; } /* FIMXE: line buffer ! */ write(1, &c, 1); if ((c == 8 || c== 127) && chpos) chpos--; else if (c == '\r' || c == '\n') chpos = 0; else chpos++; }
void encode(unsigned int c) { Ceor ^= c; Csum += c; Csum += 1; if ((Crot & (unsigned long)0x80000000)) { Crot <<= 1; Crot += 1; } else { Crot <<= 1; } Crot += c; input <<= 8; input |= c; if (pos == 3) /* This fills up the input word */ { if (input == 0) { charout('z' - '!'); /* little z marks 4 consecutive nulls */ charsout += 4; } else { charout(input / EXP85_4); input %= EXP85_4; charout(input / EXP85_3); input %= EXP85_3; charout(input / EXP85_2); input %= EXP85_2; charout(input / EXP85_1); input %= EXP85_1; charout(input); } pos = 0; } else pos++; }
void romanout(char thischar) { stringout("{\\roman "); charout(thischar); charout('}'); }
void processtamil() { char ch; int newsyl; newsyl=true; for (tamilflag=true; tamilflag==true; ) { ch = getc(input); if (ch == EOF) abort(); if (ch == switcher) changestate(); else if (isspace(ch)) { stringout(tspace); charout(ch); for ( ch=getc(input); isspace(ch); ch=getc(input)) charout(ch); pushback(ch); newsyl=true; } else if (ispunct(ch) ) { if (ch == 125) printf("\nCharacter } encountered while scanning tamil -- probable error.\n"); romanout(ch); newsyl=true; } else { switch (ch) { case 'a': case 'e': case 'i': case 'o': case 'u': if (newsyl==true) { charout(tdelim); newsyl=false; } charout(ch); break; case 'c': case 't': case 'p': case 'm': case 'y': case 'r': case 'l': case 'v': case 's': case 'j': case 'x': case 'h': charout(tdelim); charout(ch); newsyl=false; break; case 'k': charout(tdelim); ch=getc(input); if (ch=='4') charout('X'); else { charout('k'); pushback(ch); } newsyl=false; break; case '2': charout(tdelim); charout('N'); newsyl=false; break; case '3': charout(tdelim); stringout("NN"); newsyl=false; break; case '4': charout(tdelim); charout('S'); newsyl=false; break; case '5': charout(tdelim); stringout("NY"); newsyl=false; break; case '6': charout(tdelim); charout('R'); newsyl=false; break; case '7': charout(tdelim); charout('Z'); newsyl=false; break; case '8': charout(tdelim); charout('T'); newsyl=false; break; case '9': charout(tdelim); charout('L'); newsyl=false; break; case 'n': charout(tdelim); ch=getc(input); if (ch=='g') stringout("ng"); else { charout('n'); pushback(ch); } newsyl=false; break; default : transcribe_err(ch); newsyl=true; } /* endcase */ } /* endif */ } /* endfor*/ }
static void intout(value_t v) { const char *p = _itoa(v); while(*p) charout(*p++, NULL); }
static void charoutstr(uint8_t *p) { int len =*p++; while(len--) charout(*p++, NULL); }
static void chartab(value_t v) { while(chpos < v) charout(' ', NULL); }
/* VT52 alike functionality */ void vtoutput(unsigned char *p, unsigned int len) { irqflags_t irq; uint8_t cq; /* We can get re-entry into the vt code from tty echo. This is one of the few places in Fuzix interrupts bite us this way. If we have a clash then we queue the echoed symbol and print it in the thread of execution it interrupted. We only queue one so in theory might lose the odd echo - but the same occurs with real uarts. If anyone actually has printing code slow enough this is a problem then vtpend can turn into a small queue */ irq = di(); if (vtbusy) { vtpend = *p; irqrestore(irq); return; } vtbusy = 1; irqrestore(irq); cursor_off(); do { while (len--) { unsigned char c = *p++; if (vtmode == 0) { charout(c); continue; } if (vtmode == 1) { vtmode = escout(c); continue; } if (vtmode == 2) { ncursory = c - ' '; vtmode++; continue; } else if (vtmode == 3) { int ncursorx = c - ' '; if (ncursory >= 0 && ncursorx <= VT_BOTTOM) cursory = ncursory; if (ncursorx >= 0 && ncursorx <= VT_RIGHT) cursorx = ncursorx; vtmode = 0; } else { vtattr = c; vtmode = 0; continue; } } /* Copy the pending symbol and clear the buffer */ cq = vtpend; vtpend = 0; /* Any loops print the single byte in cq */ p = &cq; len = 1; /* Until we don't get interrupted */ } while(cq); cursor_on(cursory, cursorx); vtbusy = 0; }