Exemplo n.º 1
0
int putc_IOBuf(IOBuf *ob, int c) {
	if (ob->redirect != NULL)
		return gputc(ob->redirect, c);

	if (ob->out_idx >= OUTPUTBUF_SIZE)
		if (flush_IOBuf(ob) == -1)
			return -1;

	ob->outbuf[ob->out_idx++] = c;
	return 0;
}
Exemplo n.º 2
0
Arquivo: graph.c Projeto: chain78/none
int main(void){
    PMInfoBlock *pm = NULL;
    installGDT(0xa000 >> 3,0xa0000,0xffff,0,0,1,0,1,2);
    installGDT(0xb000 >> 3,0xb0000,0xffff,0,0,1,0,1,2);
    memcpy(VGABASE,(void*)(0xc0000),VGALIMIT);
    pm = getPMInfo();
    pm->biosDataSel = 0x10;
    entry = pm->entryPoint;


    memcpy((void*)0x1000,(void*)_int10,0x100);
    selectMode(M640x480x8);
#if 0
    drawX(0,640,0,480,33);
    drawX(40,600,40,440,60);
    drawX(40,600,40,60,150);
    drawX(60,580,60,420,200);
#endif

    BMPRGB c = {0xff,0xff,0xff};
    for(int i = 1;i < 140;i++){
        drawCircle(320,240,i,0,i);
        setPalett(c,i);
    }
    for(int i = 1,ver = 1;;c.red += 131,c.green += 13,c.blue += 17){
        do{
            i += ver;
            for(int delay = 0xfff;delay--;);
            setPalett(c,i - ver);
        } while((i > 1)&& (i < 140));
        ver = -ver;
    }
#if 0
    drawX(0,640,460,480,43);
    drawCircle(20,470,10,1,40);
    drawX(600,640,460,480,60);
#endif
#ifdef  PRINT_TEXT
    for(int i = 'A';i < 127;i++) gputc(i);
#endif
    //while(1);
    return 0;
}
Exemplo n.º 3
0
int main(int argc, char **argv)
{
	int i, n;
	char *s;
	char *bad = NULL;
	int c;

	int width = 0, height = 0, bpp = 8, gray = 192, attributes = 0;

	char *name, *testname;
	GrFontHeader *hdr;
	FILE *f;
	char buffer[210];
	GrEvent ev;
	int key;

	/* unfortunately not all systems support getopt() */
	for(i = 1; i < argc; i++) {
	    s = argv[i];
	    if(*s != '-' || ((c = *++s) == '\0') || *++s != '\0') break;
	    if(c == '-') {
		i++;
		break;
	    }
	    if(++i == argc) {
		fprintf(stderr, "-%c: argument required\n", c);
		return(1);
	    }
	    if(sscanf(argv[i], "%d", &n) != 1 || n < 0) {
		fprintf(stderr, "%s: invalid argument\n", argv[i]);
		exit(1);
	    }
	    switch(c) {
		case 'x' : width = n; break;
		case 'y' : height = n; break;
		case 'b' : if((bpp = n) < 2 || bpp > 32) bad = "bpp"; break;
		case 'g' : if((gray = n) > 255) bad = "gray"; break;
		case 'X' : if((deltax = n) > 31) bad = "deltax"; break;
		case 'Y' : if((deltax = n) > 31) bad = "deltay"; break;
		case 'a' : if((attributes = n) > 3) bad = "attributes"; break;
		default  : {
		    fprintf(stderr, "-%c: invalid option\n", c);
		    return(1);
		}
	    }
	    if(bad) {
		fprintf(stderr, "%d: %s out of range\n", n, bad);
		return(1);
	    }
	}

	if(i == argc) {
	    printf(
		"usage:\tfontdemo [-x WIDTH] [-y HEIGHT] [-b BPP] [-g COMPONENT]\n"
		      "\t[-X DELTAX] [-Y DELTAY] [-a ATTRIBUTES] FONT [FILE...]\n"
	    );
	    return(0);
	}

	name = argv[i++];
	opt.txo_font = GrLoadFont(name);
        if(opt.txo_font == NULL && (testname = malloc(strlen(name) + 10)) != NULL) {
            /* try again, this is a test and the path can not been set yet */
#if defined(__MSDOS__) || defined(__WIN32__)
            sprintf( testname,"..\\fonts\\%s",name );
#else
            sprintf( testname,"../fonts/%s",name );
#endif
            opt.txo_font = GrLoadFont(testname);
	    free(testname);
        }
	if(opt.txo_font == NULL) {
	    fprintf(stderr, "%s: load error\n", name);
	    return(1);
	}
	hdr = &opt.txo_font->h;

	if(height == 0) {
	    if(width == 0) {
		switch(hdr->height) {
		    case 8 :
		    case 14 : height = 400; break;
		    case 16 : height = 480; break;
		    case 20 : height = 600; break;
		    case 24 : height = 768; break;
		    default : height = hdr->height < 20 ? 480 : 768;
		}
	    }
	    else height = width * 3 / 4;
	}
	if(width == 0) width = height == 400 ? 640 : height * 4 / 3;

	GrSetMode(GR_width_height_bpp_graphics, width, height, bpp);
	if(!gray || (opt.txo_fgcolor.v = GrAllocColor(gray, gray, gray)) == GrNOCOLOR) opt.txo_fgcolor.v = GrWhite();
	if(attributes & 0x02) opt.txo_fgcolor.v |= GR_UNDERLINE_TEXT;
	opt.txo_bgcolor.v = GrBlack();
	if(attributes & 0x01) revert();
	opt.txo_chrtype = GR_BYTE_TEXT;
	opt.txo_direct = GR_TEXT_RIGHT;
	opt.txo_xalign = GR_ALIGN_LEFT;
	opt.txo_yalign = GR_ALIGN_TOP;

	sprintf(buffer, "Font name:%s %dx%d", hdr->name, GrCharWidth('A', &opt), GrCharHeight('A', &opt));
        if (hdr->proportional)
	    strcat(buffer, " proportional");
	else
	    strcat(buffer, " fixed");
	gputs(buffer);
	sprintf(buffer, "Font family: %s", hdr->family);
	gputs(buffer);
	sprintf(buffer, "Min char, num chars: %d, %d", hdr->minchar,hdr->numchars);
	gputs(buffer);
	sprintf(buffer, "Screen res: %dx%d@%lu", GrSizeX(), GrSizeY(), (unsigned long) GrNumColors());
	gputs(buffer);
	gnewl();

	gputs("THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG");
	gputs("the quick brown fox jumps over the lazy dog");
	gnewl();

//	if(hdr->minchar <= 0xC0 && hdr->minchar + hdr->numchars >= 0x100) {
//	    gputs("������� ��� ���� ���� ��");
//	    gputs("������� ��� ���� ���� ��");
//	    gnewl();
//	}

	/* ascii table, or to be precise, a full table of the current font */
	opt.txo_chrtype = GR_WORD_TEXT;
	for(c = 0; c < hdr->numchars; c++) {
	    gputc(hdr->minchar + c);
	    if(c % 0x20 == 0x1F) gnewl();
	}
	gnewl();
	if(c % 0x20 != 0) gnewl();
	opt.txo_chrtype = GR_BYTE_TEXT;

	while(i < argc) {
	    name = argv[i++];
	    if((f = fopen(name, "r")) == NULL) {
		perror(name);
		return(1);
	    }
	    while((c = getc(f)) != EOF) if(c != '\n') gputc(c); else gnewl();
	    if(ferror(f) != 0 || fclose(f) != 0) {
		perror(name);
		return(1);
	    }
	}

	/* enter and esc are < 0x100 and displayed 1:1 */
	gputs("F1-new line  F5-toggle reverse  F7-toggle underline  F10-exit");
	gnewl();

	GrEventInit();
	while(1) {
	    GrEventWait(&ev);
	    if(ev.type == GREV_KEY) {
		key = ev.p1;
		if( key == GrKey_F10) break;
		if(key == GrKey_F1) gnewl();
		else if(key == GrKey_F5) revert();
		else if(key == GrKey_F7) opt.txo_fgcolor.v ^= GR_UNDERLINE_TEXT;
		else if(key < 0x100) gputc(key);
	    }
	}
	GrEventUnInit();

	GrUnloadFont(opt.txo_font);

	return(0);
}
Exemplo n.º 4
0
static void gputs(const char *s)
{
	while(*s != '\0') gputc((unsigned char) *s++);
	gnewl();
}