⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vgagraph.c

📁 一个小型的操作系统,采用gcc进行开发,几千行的代码,方便初学者学习
💻 C
字号:
/**  Snixos Project version 1.0, 2003.6*  (C) Copyright 2003,2004,2005 Jockeyson,KeqiangGao <Snallie@tom.com>*  All Rights Reserved.*  Distributed under the terms of the GNU General Public License.**  This program is a free and open source software and you can redistribute *  it and/or modify it under the terms of the GNU General Public License as*  published by the Free Software Foundation. As no any liability is assumed *  for any incidental or consequential damages in connection with the *  information or program fragments contained herein,so any exception arised*  is at your own risk. It is ABSOLUTELY WITHOUT ANY WARRANTY.*  Bug report please send to Snallie@tom.com .*//*  vga.c   : VGA display management for 640*480 mono mode in SNIXOS project  Author  : snallie@tom.com  Time    : 2004.5*/#include "font_8x16.c"#include "fatfs.h"#include "stdio.h"#define VGAMEM 0x0a0000#define TEXTMALE 1#define TEXTFEMALE 0#define CHARHEIGHT (16+2)#define ROWS 25#define COLS 80#define CURSOR_ICON 0XFFunsigned char *vgamem;int textCursorX, textCursorY;void VGAScrInit(void);void VGAPutChar_8x16(int x, int y, unsigned char ch, int mode);void VGAPutCursor();void VGAScrGotoxy(int x, int y);void VGAscrollup(void);void VGAWriteChar(char c);void VGAHideCursor();void VGAScrInit(void){    int i, j;    vgamem = (unsigned char *) VGAMEM;    for (i = 0; i < 80; i++) {	for (j = 0; j < 25; j++) {	    VGAPutChar_8x16(j, i, ' ', TEXTMALE);	}    }    VGAScrGotoxy(0, 0);}/* putchar for ascii 0~255 */void VGAPutChar_8x16(int x, int y, unsigned char ch, int mode){    int i;    char *font;    font = fontdata_8x16 + (ch % 256) * 16;    /* x = x % 25; */    y = y % 80;    for (i = 0; i < 16; i++) {	vgamem[(x * CHARHEIGHT) * 80 + 80 * i + y] =	    (mode == TEXTMALE) ? font[i] : ~font[i];    }}/* void VGAPutChinese_16X16(int x, int y, char *font) *//* print 16x16 hz on x,y in 640*480 graph mode , monochrome *//* x range:0~24,y range:0~39 */void VGAPutChinese_16X16(int x, int y, char *ch, int mode){    int i, j, col, seam;    int qh, wh;    unsigned char font[32];    FILE *fp;    int location;    char *vgamem = (char *) VGAMEM;    x = x % 25;    y = y % 40;    qh = (unsigned char) ch[0] - 0xa0;    wh = (unsigned char) ch[1] - 0xa0;    if ((fp = fopen("hzk16", "r")) == NULL) {	printf("Can't open hzk16!\n");	return;    }    /* seek font */    location = (94 * (qh - 1) + (wh - 1)) * 32L;    fseek(fp, location, 0);    {	int i = 0;	unsigned char c;	while (i < 32) {	    font[i] = fgetc(fp);	    i++;	}    }    for (i = 0; i < 16; i++) {	for (col = 0; col < 2; col++) {	    /* 2 free lines for interval between rows */	    vgamem[(x * CHARHEIGHT) * 80 + 80 * i + y * 2 + col] =		(mode ==		 TEXTMALE) ? font[i * 2 + col] : ~font[i * 2 + col];	    /* font[i * 2 + col]; */	}    }    fclose(fp);}/* print ascii(0~255) string at screen (x,y),where x=0~24, y=0~79, mode=0(textMale) 1=testFemale */VGAPrintStr_8x16(int x, int y, char *str, int mode){    int i = 0;    while (str[i]) {	VGAPutChar_8x16(x, y, str[i], mode);	i++;	y++;    }}void VGAPutCursor(){    VGAPutChar_8x16(textCursorX, textCursorY, CURSOR_ICON, TEXTFEMALE);}void VGAScrGotoxy(int x, int y){    textCursorX = x;    textCursorY = y;    VGAPutCursor();}void VGAscrollup(void){    unsigned int org = VGAMEM + CHARHEIGHT * COLS;    unsigned int dst = VGAMEM;    unsigned int cnt = CHARHEIGHT * COLS * (ROWS - 1) / 2;    unsigned int cnt2 = CHARHEIGHT * COLS / 2;    unsigned int dst2 = VGAMEM + CHARHEIGHT * COLS * (ROWS - 1);    asm("cld\n\t" "rep\n\t" "movsw\n\t"::"c"(cnt), "D"(dst), "S"(org));    asm("cld\n\t" "rep\n\t" "stosw\n\t"::"a"(0x00), "c"(cnt2), "D"(dst2));}void VGAWriteChar(char c){    if (c == '\n') {		/* CR LF */	VGAPutChar_8x16(textCursorX, textCursorY, CURSOR_ICON, TEXTMALE);	/* hide cursor */	VGAScrGotoxy(++textCursorX, 0);	/* VGAScrGotoxy(xcord,ycord) */    } else if (c == '\t') {	/* horizontal Tab */	VGAPutChar_8x16(textCursorX, textCursorY, CURSOR_ICON, TEXTMALE);	/* hide cursor */	VGAScrGotoxy(textCursorX, textCursorY += 4);    } else if (c == '\b') {	/* backspace */	VGAPutChar_8x16(textCursorX, textCursorY, CURSOR_ICON, TEXTMALE);	/* hide cursor */	VGAScrGotoxy(textCursorX, textCursorY -= 1);	VGAWriteChar(' ');	VGAPutChar_8x16(textCursorX, textCursorY, CURSOR_ICON, TEXTMALE);	/* hide cursor */	VGAScrGotoxy(textCursorX, textCursorY -= 1);	return;    } else {	VGAPutChar_8x16(textCursorX, textCursorY, (unsigned char) c,			TEXTMALE);	if (textCursorY == 79) {	    VGAScrGotoxy(++textCursorX, 0);	} else {	    VGAScrGotoxy(textCursorX, ++textCursorY);	}    }    /* off right edge */    if (textCursorY > 79) {	textCursorX++;	VGAScrGotoxy(textCursorX, 0);	/* VGAScrGotoxy( ++textCursorX,0); */    }    /* off bottom */    if (textCursorX > 24) {	VGAscrollup();	VGAScrGotoxy(24, textCursorY);    }}void VGAHideCursor(){    VGAPutChar_8x16(textCursorX, textCursorY, CURSOR_ICON, TEXTMALE);}/*void VGADrawDot(int x,int y,int color)args: x, y coordinate for the dot to be drawn, y: 0~639 x:0~479      color: 0-black,1-white*/void VGADrawDot(int x, int y, int color){    int VGAoffset, byteBits;    char bitsMap[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80    };    x = x % 480;    y = y % 640;    VGAoffset = (x * 640 + y) / 8;    byteBits = (x * 640 + y) % 8;    *(vgamem + VGAoffset) =	(color ==	 1) ? vgamem[VGAoffset] | bitsMap[byteBits] : vgamem[VGAoffset] &	(~bitsMap[byteBits]);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -